diff options
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if_ppp.c | 84 | ||||
-rw-r--r-- | sys/net/if_pppvar.h | 3 | ||||
-rw-r--r-- | sys/net/if_sl.c | 78 | ||||
-rw-r--r-- | sys/net/if_slvar.h | 3 |
4 files changed, 103 insertions, 65 deletions
diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c index f165b1c41fc..42d7eb3633d 100644 --- a/sys/net/if_ppp.c +++ b/sys/net/if_ppp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ppp.c,v 1.36 2003/08/15 20:32:19 tedu Exp $ */ +/* $OpenBSD: if_ppp.c,v 1.37 2003/12/07 15:41:27 markus Exp $ */ /* $NetBSD: if_ppp.c,v 1.39 1997/05/17 21:11:59 christos Exp $ */ /* @@ -158,8 +158,6 @@ #include <net/ppp-comp.h> #endif -struct ppp_softc ppp_softc[NPPP]; - static int pppsioctl(struct ifnet *, u_long, caddr_t); static void ppp_requeue(struct ppp_softc *); static void ppp_ccp(struct ppp_softc *, struct mbuf *m, int rcvd); @@ -212,6 +210,11 @@ struct compressor *ppp_compressors[8] = { }; #endif /* PPP_COMPRESS */ +int ppp_clone_create(struct if_clone *, int); + +LIST_HEAD(, ppp_softc) ppp_softc_list; +struct if_clone ppp_cloner = + IF_CLONE_INITIALIZER("ppp", ppp_clone_create, NULL); /* * Called from boot code to establish ppp interfaces. @@ -219,34 +222,52 @@ struct compressor *ppp_compressors[8] = { void pppattach() { + LIST_INIT(&ppp_softc_list); + if_clone_attach(&ppp_cloner); +} + +int +ppp_clone_create(ifc, unit) + struct if_clone *ifc; + int unit; +{ extern int ifqmaxlen; register struct ppp_softc *sc; - register int i = 0; - - for (sc = ppp_softc; i < NPPP; sc++) { - sc->sc_unit = i; /* XXX */ - snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, "ppp%d", i++); - sc->sc_if.if_softc = sc; - sc->sc_if.if_mtu = PPP_MTU; - sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; - sc->sc_if.if_type = IFT_PPP; - sc->sc_if.if_hdrlen = PPP_HDRLEN; - sc->sc_if.if_ioctl = pppsioctl; - sc->sc_if.if_output = pppoutput; + int s; + + sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); + if (!sc) + return (ENOMEM); + bzero(sc, sizeof(*sc)); + + sc->sc_unit = unit; + snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, "%s%d", + ifc->ifc_name, unit); + sc->sc_if.if_softc = sc; + sc->sc_if.if_mtu = PPP_MTU; + sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; + sc->sc_if.if_type = IFT_PPP; + sc->sc_if.if_hdrlen = PPP_HDRLEN; + sc->sc_if.if_ioctl = pppsioctl; + sc->sc_if.if_output = pppoutput; #ifdef ALTQ - sc->sc_if.if_start = ppp_ifstart; + sc->sc_if.if_start = ppp_ifstart; #endif - IFQ_SET_MAXLEN(&sc->sc_if.if_snd, ifqmaxlen); - sc->sc_inq.ifq_maxlen = ifqmaxlen; - sc->sc_fastq.ifq_maxlen = ifqmaxlen; - sc->sc_rawq.ifq_maxlen = ifqmaxlen; - IFQ_SET_READY(&sc->sc_if.if_snd); - if_attach(&sc->sc_if); - if_alloc_sadl(&sc->sc_if); + IFQ_SET_MAXLEN(&sc->sc_if.if_snd, ifqmaxlen); + sc->sc_inq.ifq_maxlen = ifqmaxlen; + sc->sc_fastq.ifq_maxlen = ifqmaxlen; + sc->sc_rawq.ifq_maxlen = ifqmaxlen; + IFQ_SET_READY(&sc->sc_if.if_snd); + if_attach(&sc->sc_if); + if_alloc_sadl(&sc->sc_if); #if NBPFILTER > 0 - bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN); + bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN); #endif - } + s = splimp(); + LIST_INSERT_HEAD(&ppp_softc_list, sc, sc_list); + splx(s); + + return (0); } /* @@ -256,18 +277,18 @@ struct ppp_softc * pppalloc(pid) pid_t pid; { - int nppp, i; + int i; struct ppp_softc *sc; - for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) + LIST_FOREACH(sc, &ppp_softc_list, sc_list) if (sc->sc_xfer == pid) { sc->sc_xfer = 0; return sc; } - for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) + LIST_FOREACH(sc, &ppp_softc_list, sc_list) if (sc->sc_devp == NULL) break; - if (nppp >= NPPP) + if (sc == NULL) return NULL; sc->sc_flags = 0; @@ -1060,14 +1081,13 @@ void pppintr() { struct ppp_softc *sc; - int i, s, s2; + int s, s2; struct mbuf *m; splassert(IPL_SOFTNET); - sc = ppp_softc; s = splsoftnet(); /* XXX - what's the point of this? see comment above */ - for (i = 0; i < NPPP; ++i, ++sc) { + LIST_FOREACH(sc, &ppp_softc_list, sc_list) { if (!(sc->sc_flags & SC_TBUSY) && (IFQ_IS_EMPTY(&sc->sc_if.if_snd) == 0 || sc->sc_fastq.ifq_head)) { s2 = splimp(); diff --git a/sys/net/if_pppvar.h b/sys/net/if_pppvar.h index 835b0d37fa9..e25986d498f 100644 --- a/sys/net/if_pppvar.h +++ b/sys/net/if_pppvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pppvar.h,v 1.14 2003/02/12 14:41:07 jason Exp $ */ +/* $OpenBSD: if_pppvar.h,v 1.15 2003/12/07 15:41:27 markus Exp $ */ /* $NetBSD: if_pppvar.h,v 1.5 1997/01/03 07:23:29 mikel Exp $ */ /* * if_pppvar.h - private structures and declarations for PPP. @@ -130,6 +130,7 @@ struct ppp_softc { u_int16_t sc_outfcs; /* FCS so far for output packet */ u_char sc_rawin[16]; /* chars as received */ int sc_rawin_count; /* # in sc_rawin */ + LIST_ENTRY(ppp_softc) sc_list; /* all ppp interfaces */ }; #ifdef _KERNEL diff --git a/sys/net/if_sl.c b/sys/net/if_sl.c index 52841b2cc2e..e80da9b2155 100644 --- a/sys/net/if_sl.c +++ b/sys/net/if_sl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_sl.c,v 1.21 2003/08/15 20:32:19 tedu Exp $ */ +/* $OpenBSD: if_sl.c,v 1.22 2003/12/07 15:41:27 markus Exp $ */ /* $NetBSD: if_sl.c,v 1.39.4.1 1996/06/02 16:26:31 thorpej Exp $ */ /* @@ -174,8 +174,6 @@ Huh? SLMTU way too small. #define ABT_COUNT 3 /* count of escapes for abort */ #define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */ -struct sl_softc *sl_softc; -int nsl; #define FRAME_END 0xc0 /* Frame End */ #define FRAME_ESCAPE 0xdb /* Frame Esc */ @@ -185,6 +183,12 @@ int nsl; static int slinit(struct sl_softc *); static struct mbuf *sl_btom(struct sl_softc *, int); +int sl_clone_create(struct if_clone *, int); + +LIST_HEAD(, sl_softc) sl_softc_list; +struct if_clone sl_cloner = + IF_CLONE_INITIALIZER("sl", sl_clone_create, NULL); + /* * Called from boot code to establish sl interfaces. */ @@ -192,34 +196,46 @@ void slattach(n) int n; { - register struct sl_softc *sc; - register int i = 0; - - sl_softc = malloc(n * sizeof(struct sl_softc), M_DEVBUF, M_NOWAIT); - if (!sl_softc) - return; - nsl = n; - bzero(sl_softc, n * sizeof(struct sl_softc)); - for (sc = sl_softc; i < nsl; sc++) { - sc->sc_unit = i; /* XXX */ - snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, - "sl%d", i++); - sc->sc_if.if_softc = sc; - sc->sc_if.if_mtu = SLMTU; - sc->sc_if.if_flags = - IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST; - sc->sc_if.if_type = IFT_SLIP; - sc->sc_if.if_ioctl = slioctl; - sc->sc_if.if_output = sloutput; - IFQ_SET_MAXLEN(&sc->sc_if.if_snd, 50); - sc->sc_fastq.ifq_maxlen = 32; - IFQ_SET_READY(&sc->sc_if.if_snd); - if_attach(&sc->sc_if); - if_alloc_sadl(&sc->sc_if); + LIST_INIT(&sl_softc_list); + if_clone_attach(&sl_cloner); +} + +int +sl_clone_create(ifc, unit) + struct if_clone *ifc; + int unit; +{ + struct sl_softc *sc; + int s; + + sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); + if (!sc) + return (ENOMEM); + bzero(sc, sizeof(*sc)); + + sc->sc_unit = unit; /* XXX */ + snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, "%s%d", + ifc->ifc_name, unit); + sc->sc_if.if_softc = sc; + sc->sc_if.if_mtu = SLMTU; + sc->sc_if.if_flags = + IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST; + sc->sc_if.if_type = IFT_SLIP; + sc->sc_if.if_ioctl = slioctl; + sc->sc_if.if_output = sloutput; + IFQ_SET_MAXLEN(&sc->sc_if.if_snd, 50); + sc->sc_fastq.ifq_maxlen = 32; + IFQ_SET_READY(&sc->sc_if.if_snd); + if_attach(&sc->sc_if); + if_alloc_sadl(&sc->sc_if); #if NBPFILTER > 0 - bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_SLIP, SLIP_HDRLEN); + bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_SLIP, SLIP_HDRLEN); #endif - } + s = splimp(); + LIST_INSERT_HEAD(&sl_softc_list, sc, sc_list); + splx(s); + + return (0); } static int @@ -258,7 +274,7 @@ slopen(dev, tp) { struct proc *p = curproc; /* XXX */ register struct sl_softc *sc; - int i, error, s; + int error, s; if ((error = suser(p, 0)) != 0) return (error); @@ -266,7 +282,7 @@ slopen(dev, tp) if (tp->t_line == SLIPDISC) return (0); - for (i = nsl, sc = sl_softc; i--; sc++) + LIST_FOREACH(sc, &sl_softc_list, sc_list) if (sc->sc_ttyp == NULL) { if (slinit(sc) == 0) return (ENOBUFS); diff --git a/sys/net/if_slvar.h b/sys/net/if_slvar.h index 2108862eda0..97d946bdc44 100644 --- a/sys/net/if_slvar.h +++ b/sys/net/if_slvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_slvar.h,v 1.11 2003/06/02 23:28:12 millert Exp $ */ +/* $OpenBSD: if_slvar.h,v 1.12 2003/12/07 15:41:27 markus Exp $ */ /* $NetBSD: if_slvar.h,v 1.16 1996/05/07 02:40:46 thorpej Exp $ */ /*- @@ -66,6 +66,7 @@ struct sl_softc { #endif caddr_t sc_bpf; /* BPF data */ struct timeval sc_lastpacket; /* for watchdog */ + LIST_ENTRY(sl_softc) sc_list; /* all slip interfaces */ }; /* |