Subject: kern/14822: clonified sl(4) and strip(4)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ura@hiru.aoba.yokohama.jp>
List: netbsd-bugs
Date: 12/03/2001 22:06:05
>Number:         14822
>Category:       kern
>Synopsis:       clonified sl(4) and strip(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:07: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 sl(4) and strip(4) interfaces config statically when kernel compiles.
Thus you MUST recompile your kernel in order to change #s of them.

The clonified strip(4) isn't test yet.

>How-To-Repeat:
>Fix:
apply this patch.

Index: if_sl.c
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/net/if_sl.c,v
retrieving revision 1.78
diff -u -u -r1.78 if_sl.c
--- if_sl.c	2001/11/12 23:49:42	1.78
+++ if_sl.c	2001/12/03 12:56:11
@@ -67,7 +67,6 @@
 __KERNEL_RCSID(0, "$NetBSD$");
 
 #include "sl.h"
-#if NSL > 0
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -84,6 +83,7 @@
 #include <sys/conf.h>
 #include <sys/tty.h>
 #include <sys/kernel.h>
+#include <sys/queue.h>
 #if __NetBSD__
 #include <sys/systm.h>
 #endif
@@ -182,8 +182,6 @@
 #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[NSL];
-
 #define FRAME_END	 	0xc0		/* Frame End */
 #define FRAME_ESCAPE		0xdb		/* Frame Esc */
 #define TRANS_FRAME_END	 	0xdc		/* transposed frame end */
@@ -197,36 +195,69 @@
 static int slinit __P((struct sl_softc *));
 static struct mbuf *sl_btom __P((struct sl_softc *, int));
 
+struct sl_softc_head sl_softc_list;
+
+int	sl_clone_create __P((struct if_clone *, int));
+void	sl_clone_destroy __P((struct ifnet *));
+
+struct if_clone sl_cloner =
+    IF_CLONE_INITIALIZER("sl", sl_clone_create, sl_clone_destroy);
+
 /*
  * Called from boot code to establish sl interfaces.
  */
 void
 slattach()
 {
+	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 i = 0;
+
+	sc = malloc(sizeof(struct sl_softc), M_DEVBUF, M_WAITOK);
+	memset(sc, 0, sizeof(struct sl_softc));
 
-	for (sc = sl_softc; i < NSL; sc++) {
-		sc->sc_unit = i;		/* XXX */
-		sprintf(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;
-		sc->sc_if.if_dlt = DLT_SLIP;
-		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);
+	sc->sc_unit = unit;		/* XXX */
+	sprintf(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;
+	sc->sc_if.if_dlt = DLT_SLIP;
+	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_if, DLT_SLIP, SLIP_HDRLEN);
+	bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
 #endif
-	}
+	LIST_INSERT_HEAD(&sl_softc_list, sc, sc_list);
+	return (0);
 }
 
+void
+sl_clone_destroy(ifp)
+	struct ifnet *ifp;
+{
+	struct sl_softc *sc = ifp->if_softc;
+
+	LIST_REMOVE(sc, sc_list);
+#if NBPFILTER > 0
+	bpfdetach(ifp);
+#endif
+	if_detach(ifp);
+	free(sc, M_DEVBUF);
+}
+
 static int
 slinit(sc)
 	struct sl_softc *sc;
@@ -258,7 +289,6 @@
 {
 	struct proc *p = curproc;		/* XXX */
 	struct sl_softc *sc;
-	int nsl;
 	int error;
 	int s;
 
@@ -268,7 +298,7 @@
 	if (tp->t_linesw->l_no == SLIPDISC)
 		return (0);
 
-	for (nsl = NSL, sc = sl_softc; --nsl >= 0; sc++)
+	LIST_FOREACH(sc, &sl_softc_list, sc_list) {
 		if (sc->sc_ttyp == NULL) {
 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 			sc->sc_si = softintr_establish(IPL_SOFTNET,
@@ -318,6 +348,7 @@
 #endif /* __NetBSD__ */
 			return (0);
 		}
+	}
 	return (ENXIO);
 }
 
@@ -675,10 +706,8 @@
 slnetisr(void)
 {
 	struct sl_softc *sc;
-	int i;
 
-	for (i = 0; i < NSL; i++) {
-		sc = &sl_softc[i];
+	LIST_FOREACH(sc, &sl_softc_list, sc_list) {
 		if (sc->sc_ttyp == NULL)
 			continue;
 		slintr(sc);
@@ -1072,4 +1101,3 @@
 	splx(s);
 	return (error);
 }
-#endif
Index: if_slvar.h
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/net/if_slvar.h,v
retrieving revision 1.24
diff -u -u -r1.24 if_slvar.h
--- if_slvar.h	2001/06/14 05:44:24	1.24
+++ if_slvar.h	2001/12/03 12:56:11
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_slvar.h,v 1.23 2001/01/15 16:33:31 thorpej Exp $	*/
+/*	$NetBSD: if_slvar.h,v 1.24 2001/06/14 05:44:24 itojun Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -46,6 +46,7 @@
  */
 struct sl_softc {
 	struct	ifnet sc_if;		/* network-visible interface */
+	LIST_ENTRY(sl_softc) sc_list;
 	int	sc_unit;		/* XXX unit number */
 	struct	ifqueue sc_fastq;	/* interactive output queue */
 	struct	ifqueue sc_inq;		/* input queue */
@@ -83,6 +84,9 @@
 #define	SC_AUTOCOMP	IFF_LINK2	/* auto-enable TCP compression */
 
 #ifdef _KERNEL
+LIST_HEAD(sl_softc_head, sl_softc);
+extern struct sl_softc_head sl_softc_list;
+
 void	slattach __P((void));
 void	slclose __P((struct tty *));
 void	slinput __P((int, struct tty *));
Index: if_strip.c
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/net/if_strip.c,v
retrieving revision 1.41
diff -u -u -r1.41 if_strip.c
--- if_strip.c	2001/11/13 00:49:35	1.41
+++ if_strip.c	2001/12/03 12:56:11
@@ -109,6 +109,7 @@
 #include <sys/conf.h>
 #include <sys/tty.h>
 #include <sys/kernel.h>
+#include <sys/queue.h>
 #if __NetBSD__
 #include <sys/systm.h>
 #include <sys/callout.h>
@@ -220,8 +221,6 @@
 #define	ABT_COUNT	3	/* count of escapes for abort */
 #define	ABT_WINDOW	(ABT_COUNT*2+2)	/* in seconds - time to count */
 
-struct strip_softc strip_softc[NSTRIP];
-
 #define STRIP_FRAME_END		0x0D		/* carriage return */
 
 #ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
@@ -279,6 +278,14 @@
 void	stripnetisr(void);
 void	stripintr(void *);
 
+struct strip_softc_head strip_softc_list;
+
+int	strip_clone_create __P((struct if_clone *, int));
+void	strip_clone_destroy __P((struct ifnet *));
+
+struct if_clone strip_cloner =
+    IF_CLONE_INITIALIZER("strip", strip_clone_create, strip_clone_destroy);
+
 #ifdef DEBUG
 #define DPRINTF(x)	printf x
 #else
@@ -345,34 +352,59 @@
 stripattach(n)
 	int n;
 {
+	LIST_INIT(&strip_softc_list);
+	if_clone_attach(&strip_cloner);
+}
+
+int
+strip_clone_create(ifc, unit)
+	struct if_clone *ifc;
+	int unit;
+{
 	struct strip_softc *sc;
-	int i = 0;
 
-	for (sc = strip_softc; i < NSTRIP; sc++) {
-		sc->sc_unit = i;		/* XXX */
-		sprintf(sc->sc_if.if_xname, "strip%d", i++);
-		callout_init(&sc->sc_timo_ch);
-		sc->sc_if.if_softc = sc;
-		sc->sc_if.if_mtu = SLMTU;
-		sc->sc_if.if_flags = 0;
-		sc->sc_if.if_type = IFT_OTHER;
+	sc = malloc(sizeof(struct strip_softc), M_DEVBUF, M_WAITOK);
+	memset(sc, 0, sizeof(struct strip_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 = SLMTU;
+	sc->sc_if.if_flags = 0;
+	sc->sc_if.if_type = IFT_OTHER;
 #if 0
-		sc->sc_if.if_flags |= SC_AUTOCOMP /* | IFF_POINTOPOINT | IFF_MULTICAST*/;
+	sc->sc_if.if_flags |= SC_AUTOCOMP /* | IFF_POINTOPOINT | IFF_MULTICAST*/;
 #endif
-		sc->sc_if.if_type = IFT_SLIP;
-		sc->sc_if.if_ioctl = stripioctl;
-		sc->sc_if.if_output = stripoutput;
-		sc->sc_if.if_dlt = DLT_SLIP;
-		sc->sc_fastq.ifq_maxlen = 32;
-		IFQ_SET_READY(&sc->sc_if.if_snd);
-
-		sc->sc_if.if_watchdog = strip_watchdog;
-		if_attach(&sc->sc_if);
-		if_alloc_sadl(&sc->sc_if);
+	sc->sc_if.if_type = IFT_SLIP;
+	sc->sc_if.if_ioctl = stripioctl;
+	sc->sc_if.if_output = stripoutput;
+	sc->sc_if.if_dlt = DLT_SLIP;
+	sc->sc_fastq.ifq_maxlen = 32;
+	IFQ_SET_READY(&sc->sc_if.if_snd);
+
+	sc->sc_if.if_watchdog = strip_watchdog;
+	if_attach(&sc->sc_if);
+	if_alloc_sadl(&sc->sc_if);
 #if NBPFILTER > 0
-		bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
+	bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN);
 #endif
-	}
+	LIST_INSERT_HEAD(&strip_softc_list, sc, sc_list);
+	return (0);
+}
+
+void
+strip_clone_destroy(ifp)
+	struct ifnet *ifp;
+{
+	struct strip_softc *sc = ifp->if_softc;
+
+	LIST_REMOVE(sc, sc_list);
+#if NBPFILTER > 0
+	bpfdetach(ifp);
+#endif
+	if_detach(ifp);
+	free(sc, M_DEVBUF);
 }
 
 static int
@@ -438,7 +470,6 @@
 {
 	struct proc *p = curproc;		/* XXX */
 	struct strip_softc *sc;
-	int nstrip;
 	int error;
 #ifdef __NetBSD__
 	int s;
@@ -450,7 +481,7 @@
 	if (tp->t_linesw->l_no == STRIPDISC)
 		return (0);
 
-	for (nstrip = NSTRIP, sc = strip_softc; --nstrip >= 0; sc++) {
+	LIST_FOREACH(sc, &strip_softc_list, sc_list) {
 		if (sc->sc_ttyp == NULL) {
 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 			sc->sc_si = softintr_establish(IPL_SOFTNET,
@@ -1067,10 +1098,8 @@
 stripnetisr(void)
 {
 	struct strip_softc *sc;
-	int i;
 
-	for (i = 0; i < NSTRIP; i++) {
-		sc = &strip_softc[i];
+	LIST_FOREACH(sc, &strip_softc_list, sc_list) {
 		if (sc->sc_ttyp == NULL)
 			continue;
 		stripintr(sc);
Index: if_stripvar.h
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/net/if_stripvar.h,v
retrieving revision 1.12
diff -u -u -r1.12 if_stripvar.h
--- if_stripvar.h	2001/06/14 05:44:25	1.12
+++ if_stripvar.h	2001/12/03 12:56:11
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stripvar.h,v 1.11 2001/01/15 16:33:32 thorpej Exp $	*/
+/*	$NetBSD: if_stripvar.h,v 1.12 2001/06/14 05:44:25 itojun Exp $	*/
 
 #ifndef _NET_IF_STRIPVAR_H_
 #define _NET_IF_STRIPVAR_H_
@@ -8,6 +8,7 @@
  */
 struct strip_softc {
 	struct	ifnet sc_if;		/* network-visible interface */
+	LIST_ENTRY(strip_softc) sc_list;
 	int	sc_unit;		/* XXX unit number */
 	struct	ifqueue sc_fastq;	/* interactive output queue */
 	struct	ifqueue sc_inq;		/* input queue */
@@ -55,6 +56,9 @@
 #define	SC_AUTOCOMP	IFF_LINK2	/* auto-enable TCP compression */
 
 #ifdef _KERNEL
+LIST_HEAD(strip_softc_head, strip_softc);
+extern struct strip_softc_head strip_softc_list;
+
 void	stripattach __P((int n));
 void	stripclose __P((struct tty *));
 void	stripinput __P((int, struct tty *));
>Release-Note:
>Audit-Trail:
>Unformatted: