diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if_gif.c | 104 | ||||
-rw-r--r-- | sys/net/if_gif.h | 6 | ||||
-rw-r--r-- | sys/netinet/in_gif.c | 5 | ||||
-rw-r--r-- | sys/netinet/ip_ether.c | 30 | ||||
-rw-r--r-- | sys/netinet6/in6_gif.c | 5 |
5 files changed, 94 insertions, 56 deletions
diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index d790dcb256d..87d64d5ed2d 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gif.c,v 1.28 2003/05/03 21:15:11 deraadt Exp $ */ +/* $OpenBSD: if_gif.c,v 1.29 2003/12/03 14:51:05 markus Exp $ */ /* $KAME: if_gif.c,v 1.43 2001/02/20 08:51:07 itojun Exp $ */ /* @@ -63,44 +63,86 @@ extern int ifqmaxlen; -int ngif; -void gifattach(int); +void gifattach(int); +int gif_clone_create(struct if_clone *, int); +void gif_clone_destroy(struct ifnet *); /* * gif global variable definitions */ -struct gif_softc *gif_softc = 0; +struct gif_softc_head gif_softc_list; +struct if_clone gif_cloner = + IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy); +/* ARGSUSED */ void -gifattach(n) - int n; +gifattach(count) + int count; { - register struct gif_softc *sc; - register int i; - - ngif = n; - gif_softc = sc = malloc (ngif * sizeof(struct gif_softc), - M_DEVBUF, M_WAIT); - bzero(sc, ngif * sizeof(struct gif_softc)); - for (i = 0; i < ngif; sc++, i++) { - snprintf(sc->gif_if.if_xname, sizeof sc->gif_if.if_xname, - "gif%d", i); - sc->gif_if.if_mtu = GIF_MTU; - sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; - sc->gif_if.if_ioctl = gif_ioctl; - sc->gif_if.if_start = gif_start; - sc->gif_if.if_output = gif_output; - sc->gif_if.if_type = IFT_GIF; - sc->gif_if.if_snd.ifq_maxlen = ifqmaxlen; - sc->gif_if.if_softc = sc; - if_attach(&sc->gif_if); - if_alloc_sadl(&sc->gif_if); + LIST_INIT(&gif_softc_list); + if_clone_attach(&gif_cloner); +} + +int +gif_clone_create(ifc, unit) + struct if_clone *ifc; + int unit; +{ + struct gif_softc *sc; + int s; + + sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); + if (!sc) + return (ENOMEM); + bzero(sc, sizeof(*sc)); + + snprintf(sc->gif_if.if_xname, sizeof sc->gif_if.if_xname, + "%s%d", ifc->ifc_name, unit); + sc->gif_if.if_mtu = GIF_MTU; + sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; + sc->gif_if.if_ioctl = gif_ioctl; + sc->gif_if.if_start = gif_start; + sc->gif_if.if_output = gif_output; + sc->gif_if.if_type = IFT_GIF; + sc->gif_if.if_snd.ifq_maxlen = ifqmaxlen; + sc->gif_if.if_softc = sc; + if_attach(&sc->gif_if); + if_alloc_sadl(&sc->gif_if); #if NBPFILTER > 0 - bpfattach(&sc->gif_if.if_bpf, &sc->gif_if, DLT_NULL, - sizeof(u_int)); + bpfattach(&sc->gif_if.if_bpf, &sc->gif_if, DLT_NULL, + sizeof(u_int)); #endif - } + s = splnet(); + LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list); + splx(s); + + return (0); +} + +void +gif_clone_destroy(ifp) + struct ifnet *ifp; +{ + struct gif_softc *sc = ifp->if_softc; + int s; + + s = splnet(); + LIST_REMOVE(sc, gif_list); + splx(s); + +#if NBPFILTER > 0 + bpfdetach(ifp); +#endif + if_detach(ifp); + + if (sc->gif_psrc) + free((caddr_t)sc->gif_psrc, M_IFADDR); + sc->gif_psrc = NULL; + if (sc->gif_pdst) + free((caddr_t)sc->gif_pdst, M_IFADDR); + sc->gif_pdst = NULL; + free(sc, M_DEVBUF); } void @@ -245,7 +287,6 @@ gif_ioctl(ifp, cmd, data) int error = 0, size; struct sockaddr *dst, *src; struct sockaddr *sa; - int i; int s; struct gif_softc *sc2; @@ -360,8 +401,7 @@ gif_ioctl(ifp, cmd, data) break; } - for (i = 0; i < ngif; i++) { - sc2 = gif_softc + i; + LIST_FOREACH(sc2, &gif_softc_list, gif_list) { if (sc2 == sc) continue; if (!sc2->gif_pdst || !sc2->gif_psrc) diff --git a/sys/net/if_gif.h b/sys/net/if_gif.h index d65ff2775a5..88cd1810f84 100644 --- a/sys/net/if_gif.h +++ b/sys/net/if_gif.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gif.h,v 1.8 2002/03/14 01:27:09 millert Exp $ */ +/* $OpenBSD: if_gif.h,v 1.9 2003/12/03 14:51:05 markus Exp $ */ /* $KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $ */ /* @@ -52,6 +52,7 @@ struct gif_softc { #endif } gifsc_gifscr; int gif_flags; + LIST_ENTRY(gif_softc) gif_list; /* list of all gifs */ }; #define gif_ro gifsc_gifscr.gifscr_ro @@ -63,8 +64,7 @@ struct gif_softc { #define GIF_MTU_MIN (1280) /* Minimum MTU */ #define GIF_MTU_MAX (8192) /* Maximum MTU */ -extern int ngif; -extern struct gif_softc *gif_softc; +extern LIST_HEAD(gif_softc_head, gif_softc) gif_softc_list; /* Prototypes */ int gif_output(struct ifnet *, struct mbuf *, diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index ea4e24de774..39ddb5ada66 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_gif.c,v 1.28 2003/07/28 10:10:16 markus Exp $ */ +/* $OpenBSD: in_gif.c,v 1.29 2003/12/03 14:51:05 markus Exp $ */ /* $KAME: in_gif.c,v 1.50 2001/01/22 07:27:16 itojun Exp $ */ /* @@ -159,7 +159,6 @@ in_gif_input(struct mbuf *m, ...) struct gif_softc *sc; struct ifnet *gifp = NULL; struct ip *ip; - int i; va_list ap; va_start(ap, m); @@ -176,7 +175,7 @@ in_gif_input(struct mbuf *m, ...) /* this code will be soon improved. */ #define satosin(sa) ((struct sockaddr_in *)(sa)) - for (i = 0, sc = gif_softc; i < ngif; i++, sc++) { + LIST_FOREACH(sc, &gif_softc_list, gif_list) { if (sc->gif_psrc == NULL || sc->gif_pdst == NULL || sc->gif_psrc->sa_family != AF_INET || sc->gif_pdst->sa_family != AF_INET) { diff --git a/sys/netinet/ip_ether.c b/sys/netinet/ip_ether.c index 419bf3f4942..97e47e3bdeb 100644 --- a/sys/netinet/ip_ether.c +++ b/sys/netinet/ip_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ether.c,v 1.45 2003/08/14 19:00:12 jason Exp $ */ +/* $OpenBSD: ip_ether.c,v 1.46 2003/12/03 14:51:05 markus Exp $ */ /* * The author of this code is Angelos D. Keromytis (kermit@adk.gr) * @@ -86,7 +86,7 @@ etherip_input(struct mbuf *m, ...) va_list ap; #if NGIF > 0 - int i; + struct gif_softc *sc; #if NBRIDGE > 0 int s; #endif /* NBRIDGE */ @@ -222,27 +222,27 @@ etherip_input(struct mbuf *m, ...) #if NGIF > 0 /* Find appropriate gif(4) interface */ - for (i = 0; i < ngif; i++) { - if ((gif_softc[i].gif_psrc == NULL) || - (gif_softc[i].gif_pdst == NULL) || - !(gif_softc[i].gif_if.if_flags & (IFF_UP|IFF_RUNNING))) + LIST_FOREACH(sc, &gif_softc_list, gif_list) { + if ((sc->gif_psrc == NULL) || + (sc->gif_pdst == NULL) || + !(sc->gif_if.if_flags & (IFF_UP|IFF_RUNNING))) continue; - if (!bcmp(gif_softc[i].gif_psrc, &sdst, gif_softc[i].gif_psrc->sa_len) && - !bcmp(gif_softc[i].gif_pdst, &ssrc, gif_softc[i].gif_pdst->sa_len) && - gif_softc[i].gif_if.if_bridge != NULL) + if (!bcmp(sc->gif_psrc, &sdst, sc->gif_psrc->sa_len) && + !bcmp(sc->gif_pdst, &ssrc, sc->gif_pdst->sa_len) && + sc->gif_if.if_bridge != NULL) break; } /* None found. */ - if (i >= ngif) { + if (sc == NULL) { DPRINTF(("etherip_input(): no interface found\n")); etheripstat.etherip_noifdrops++; m_freem(m); return; } #if NBPFILTER > 0 - if (gif_softc[i].gif_if.if_bpf) { + if (sc->gif_if.if_bpf) { struct mbuf m0; u_int32_t af = sdst.sa.sa_family; @@ -251,7 +251,7 @@ etherip_input(struct mbuf *m, ...) m0.m_len = 4; m0.m_data = (char *)⁡ - bpf_mtap(gif_softc[i].gif_if.if_bpf, &m0); + bpf_mtap(sc->gif_if.if_bpf, &m0); } #endif @@ -261,12 +261,12 @@ etherip_input(struct mbuf *m, ...) * NULL if it has consumed the packet. In the case of gif's, * bridge_input() returns non-NULL when an error occurs. */ - m->m_pkthdr.rcvif = &gif_softc[i].gif_if; + m->m_pkthdr.rcvif = &sc->gif_if; if (m->m_flags & (M_BCAST|M_MCAST)) - gif_softc[i].gif_if.if_imcasts++; + sc->gif_if.if_imcasts++; s = splnet(); - m = bridge_input(&gif_softc[i].gif_if, &eh, m); + m = bridge_input(&sc->gif_if, &eh, m); splx(s); if (m == NULL) return; diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c index 143ed123b9a..578bdd8a3b7 100644 --- a/sys/netinet6/in6_gif.c +++ b/sys/netinet6/in6_gif.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_gif.c,v 1.21 2002/05/30 04:19:44 itojun Exp $ */ +/* $OpenBSD: in6_gif.c,v 1.22 2003/12/03 14:51:05 markus Exp $ */ /* $KAME: in6_gif.c,v 1.43 2001/01/22 07:27:17 itojun Exp $ */ /* @@ -206,7 +206,6 @@ int in6_gif_input(mp, offp, proto) struct gif_softc *sc; struct ifnet *gifp = NULL; struct ip6_hdr *ip6; - int i; /* XXX What if we run transport-mode IPsec to protect gif tunnel ? */ if (m->m_flags & (M_AUTH | M_CONF)) @@ -215,7 +214,7 @@ int in6_gif_input(mp, offp, proto) ip6 = mtod(m, struct ip6_hdr *); #define satoin6(sa) (((struct sockaddr_in6 *)(sa))->sin6_addr) - for (i = 0, sc = gif_softc; i < ngif; i++, sc++) { + LIST_FOREACH(sc, &gif_softc_list, gif_list) { if (sc->gif_psrc == NULL || sc->gif_pdst == NULL || sc->gif_psrc->sa_family != AF_INET6 || sc->gif_pdst->sa_family != AF_INET6) { |