Subject: kern/14823: clonified ipip(4)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ura@hiru.aoba.yokohama.jp>
List: netbsd-bugs
Date: 12/03/2001 22:09:40
>Number: 14823
>Category: kern
>Synopsis: clonified ipip(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:11: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 ipip(4) interface configs statically when kernel compiles.
Thus you MUST recompile your kernel in order to change #s of one.
The clonified ipip(4) isn't tested yet.
>How-To-Repeat:
>Fix:
apply this patch.
Index: ip_ipip.c
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/netinet/ip_ipip.c,v
retrieving revision 1.16
diff -u -u -r1.16 ip_ipip.c
--- ip_ipip.c 2001/11/13 00:32:38 1.16
+++ ip_ipip.c 2001/12/03 12:57:17
@@ -59,6 +59,7 @@
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/ioctl.h>
+#include <sys/queue.h>
#include <net/if.h>
#include <net/if_types.h>
@@ -80,9 +81,6 @@
#include <machine/stdarg.h>
-struct ipip_softc *ipip_softc;
-int ipip_nsoftc;
-
static int ipip_encapcheck __P((const struct mbuf *, int, int, void *));
void ipipattach __P((int));
int ipip_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
@@ -92,6 +90,14 @@
extern struct protosw ipip_protosw;
+struct ipip_softc_head ipip_softc_list;
+
+int ipip_clone_create __P((struct if_clone *, int));
+void ipip_clone_destroy __P((struct ifnet *));
+
+struct if_clone ipip_cloner =
+ IF_CLONE_INITIALIZER("ipip", ipip_clone_create, ipip_clone_destroy);
+
/*
* Note this is a common IP-in-IP input for both ipip `interfaces'
* and the multicast routing code's IP-in-IP needs.
@@ -183,46 +189,64 @@
ipipattach(count)
int count;
{
+
+ LIST_INIT(&ipip_softc_list);
+ if_clone_attach(&ipip_cloner);
+}
+
+int
+ipip_clone_create(ifc, unit)
+ struct if_clone *ifc;
+ int unit;
+{
struct ipip_softc *sc;
- size_t size;
- int i;
- ipip_nsoftc = count;
- size = sizeof(struct ipip_softc) * count;
- ipip_softc = malloc(size, M_DEVBUF, M_WAITOK);
- memset(ipip_softc, 0, size);
-
- for (i = 0; i < ipip_nsoftc; i++) {
- sc = &ipip_softc[i];
-
- sprintf(sc->sc_if.if_xname, "ipip%d", i);
-
- sc->sc_cookie = encap_attach_func(AF_INET, IPPROTO_IPIP,
- ipip_encapcheck, &ipip_protosw, sc);
- if (sc->sc_cookie == NULL) {
- printf("%s: attach failed\n", sc->sc_if.if_xname);
- continue;
- }
+ sc = malloc(sizeof(struct ipip_softc), M_DEVBUF, M_WAITOK);
+ memset(sc, 0, sizeof(struct ipip_softc));
+
+ sprintf(sc->sc_if.if_xname, "%s%d", ifc->ifc_name, unit);
+ sc->sc_cookie = encap_attach_func(AF_INET, IPPROTO_IPIP,
+ ipip_encapcheck, &ipip_protosw, sc);
+ if (sc->sc_cookie == NULL) {
+ printf("%s: attach failed\n", sc->sc_if.if_xname);
+ return (1);
+ }
- sc->sc_if.if_softc = sc;
- sc->sc_if.if_type = IFT_OTHER;
- sc->sc_if.if_dlt = DLT_NULL;
- sc->sc_if.if_addrlen = sizeof(struct in_addr);
- sc->sc_if.if_hdrlen = sizeof(struct ip);
- sc->sc_if.if_mtu = 0; /* filled in later */
- sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
- sc->sc_if.if_output = ipip_output;
- sc->sc_if.if_ioctl = ipip_ioctl;
+ sc->sc_if.if_softc = sc;
+ sc->sc_if.if_type = IFT_OTHER;
+ sc->sc_if.if_dlt = DLT_NULL;
+ sc->sc_if.if_addrlen = sizeof(struct in_addr);
+ sc->sc_if.if_hdrlen = sizeof(struct ip);
+ sc->sc_if.if_mtu = 0; /* filled in later */
+ sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
+ sc->sc_if.if_output = ipip_output;
+ sc->sc_if.if_ioctl = ipip_ioctl;
- sc->sc_src.s_addr = INADDR_ANY;
- sc->sc_dst.s_addr = INADDR_ANY;
+ sc->sc_src.s_addr = INADDR_ANY;
+ sc->sc_dst.s_addr = INADDR_ANY;
- if_attach(&sc->sc_if);
- if_alloc_sadl(&sc->sc_if);
+ if_attach(&sc->sc_if);
+ if_alloc_sadl(&sc->sc_if);
#if NBPFILTER > 0
- bpfattach(&sc->sc_if, DLT_NULL, sc->sc_if.if_hdrlen);
+ bpfattach(&sc->sc_if, DLT_NULL, sc->sc_if.if_hdrlen);
#endif
- }
+
+ LIST_INSERT_HEAD(&ipip_softc_list, sc, sc_list);
+ return (0);
+}
+
+void
+ipip_clone_destroy(ifp)
+ struct ifnet *ifp;
+{
+ struct ipip_softc *sc = ifp->if_softc;
+
+ LIST_REMOVE(sc, sc_list);
+#if NBPFILTER > 0
+ bpfdetach(ifp);
+#endif
+ if_detach(ifp);
+ free(sc, M_DEVBUF);
}
int
Index: ip_ipip.h
===================================================================
RCS file: /cvsroot/netbsd/syssrc/sys/netinet/ip_ipip.h,v
retrieving revision 1.2
diff -u -u -r1.2 ip_ipip.h
--- ip_ipip.h 2000/04/19 06:30:55 1.2
+++ ip_ipip.h 2001/12/03 12:57:17
@@ -44,6 +44,7 @@
struct ipip_softc {
struct ifnet sc_if; /* our ifnet structure */
+ LIST_ENTRY(ipip_softc) sc_list;
struct in_addr sc_src; /* tunnel source address */
struct in_addr sc_dst; /* tunnel destination address */
struct route sc_route; /* route to destination */
@@ -51,6 +52,9 @@
};
#ifdef _KERNEL
+LIST_HEAD(ipip_softc_head, ipip_softc);
+extern struct ipip_softc_head ipip_softc_list;
+
void ipip_input __P((struct mbuf *, ...));
#endif
>Release-Note:
>Audit-Trail:
>Unformatted: