Subject: kern/14821: clonified ppp(4)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ura@hiru.aoba.yokoham.jp>
List: netbsd-bugs
Date: 12/03/2001 22:02:04
>Number:         14821
>Category:       kern
>Synopsis:       clonified ppp(4)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 03 05:03:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     URA Hiroshi
>Release:        NetBSD 1.5Z (2001/12/02)
>Organization:
>Environment:
System: NetBSD minazuki.hiru.aoba.yokohama.jp 1.5Z NetBSD 1.5Z (MINAZUKI) #83: Sun Dec 2 03:57:49 JST 2001 ura@minazuki.hiru.aoba.yokohama.jp:/usr/local/src/NetBSD/current/src/sys/arch/i386/compile/MINAZUKI i386
Architecture: i386
Machine: i386
>Description:
The ppp(4) nterface configs statically when kernel compiles.
Thus you MUST recompile your kernel in order to change #s of one.

>How-To-Repeat:

>Fix:
apply this patch.

Index: if_ppp.c
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/net/if_ppp.c,v
retrieving revision 1.73
diff -u -u -r1.73 if_ppp.c
--- if_ppp.c	2001/11/13 00:49:35	1.73
+++ if_ppp.c	2001/12/03 12:56:29
@@ -108,6 +108,7 @@
 #include <sys/systm.h>
 #include <sys/time.h>
 #include <sys/malloc.h>
+#include <sys/queue.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
@@ -164,6 +165,14 @@
 #endif
 void		pppintr(void *);
 
+struct ppp_softc_head ppp_softc_list;
+
+int		ppp_clone_create __P((struct if_clone *, int));
+void		ppp_clone_destroy __P((struct ifnet *));
+
+struct if_clone ppp_cloner =
+    IF_CLONE_INITIALIZER("ppp", ppp_clone_create, ppp_clone_destroy);
+
 /*
  * Some useful mbuf macros not in mbuf.h.
  */
@@ -213,32 +222,57 @@
 void
 pppattach()
 {
+	LIST_INIT(&ppp_softc_list);
+	if_clone_attach(&ppp_cloner);
+}
+
+int
+ppp_clone_create(ifc, unit)
+	struct if_clone *ifc;
+	int unit;
+{
     struct ppp_softc *sc;
-    int i = 0;
 
-    for (sc = ppp_softc; i < NPPP; sc++) {
-	sc->sc_unit = i;	/* XXX */
-	sprintf(sc->sc_if.if_xname, "ppp%d", i++);
-	callout_init(&sc->sc_timo_ch);
-	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_dlt = DLT_NULL;
-	sc->sc_if.if_ioctl = pppsioctl;
-	sc->sc_if.if_output = pppoutput;
-	IFQ_SET_MAXLEN(&sc->sc_if.if_snd, IFQ_MAXLEN);
-	sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
-	sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
-	sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
-	IFQ_SET_READY(&sc->sc_if.if_snd);
-	if_attach(&sc->sc_if);
-	if_alloc_sadl(&sc->sc_if);
+    sc = malloc(sizeof(struct ppp_softc), M_DEVBUF, M_WAITOK);
+    memset(sc, 0, sizeof(struct ppp_softc));
+
+    sc->sc_unit = unit;	/* XXX */
+    sprintf(sc->sc_if.if_xname, "%s%d", ifc->ifc_name, unit);
+    callout_init(&sc->sc_timo_ch);
+    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_dlt = DLT_NULL;
+    sc->sc_if.if_ioctl = pppsioctl;
+    sc->sc_if.if_output = pppoutput;
+    IFQ_SET_MAXLEN(&sc->sc_if.if_snd, IFQ_MAXLEN);
+    sc->sc_inq.ifq_maxlen = IFQ_MAXLEN;
+    sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN;
+    sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN;
+    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_if, DLT_NULL, 0);
+    bpfattach(&sc->sc_if, DLT_NULL, 0);
 #endif
-    }
+    LIST_INSERT_HEAD(&ppp_softc_list, sc, sc_list);
+    return (0);
+}
+
+void
+ppp_clone_destroy(ifp)
+	struct ifnet *ifp;
+{
+	struct ppp_softc *sc = ifp->if_softc;
+
+	LIST_REMOVE(sc, sc_list);
+#if NBPFILTER > 0
+	bpfdetach(ifp);
+#endif
+	if_detach(ifp);
+	free(sc, M_DEVBUF);
 }
 
 /*
@@ -248,18 +282,18 @@
 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;
 
 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
@@ -1172,8 +1206,7 @@
 	struct ppp_softc *sc;
 	int i;
 
-	for (i = 0; i < NPPP; i++) {
-		sc = &ppp_softc[i];
+	LIST_FOREACH(sc, &ppp_softc_list, sc_list) {
 		pppintr(sc);
 	}
 }
Index: if_pppvar.h
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/net/if_pppvar.h,v
retrieving revision 1.13
diff -u -u -r1.13 if_pppvar.h
--- if_pppvar.h	2001/01/15 16:33:31	1.13
+++ if_pppvar.h	2001/12/03 12:56:29
@@ -61,6 +61,7 @@
  */
 struct ppp_softc {
 	struct	ifnet sc_if;		/* network-visible interface */
+	LIST_ENTRY(ppp_softc) sc_list;
 	int	sc_unit;		/* XXX unit number */
 	u_int	sc_flags;		/* control/status bits; see if_ppp.h */
 	void	*sc_devp;		/* pointer to device-dep structure */
@@ -115,7 +116,8 @@
 };
 
 #ifdef _KERNEL
-struct	ppp_softc ppp_softc[NPPP];
+LIST_HEAD(ppp_softc_head, ppp_softc);
+extern struct ppp_softc_head ppp_softc_list;
 
 struct	ppp_softc *pppalloc __P((pid_t pid));
 void	pppdealloc __P((struct ppp_softc *sc));

>Release-Note:
>Audit-Trail:
>Unformatted: