Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Convert `gif' to be a cloning interface.
details: https://anonhg.NetBSD.org/src/rev/4cff29dedd5f
branches: trunk
changeset: 494108:4cff29dedd5f
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Jul 02 00:21:42 2000 +0000
description:
Convert `gif' to be a cloning interface.
diffstat:
sys/net/if_gif.c | 169 +++++++++++++++++++++++++++++++++---------------------
sys/net/if_gif.h | 4 +-
2 files changed, 107 insertions(+), 66 deletions(-)
diffs (253 lines):
diff -r 21edb3e40b68 -r 4cff29dedd5f sys/net/if_gif.c
--- a/sys/net/if_gif.c Sun Jul 02 00:20:48 2000 +0000
+++ b/sys/net/if_gif.c Sun Jul 02 00:21:42 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gif.c,v 1.11 2000/06/20 15:59:35 itojun Exp $ */
+/* $NetBSD: if_gif.c,v 1.12 2000/07/02 00:21:42 thorpej Exp $ */
/* $KAME: if_gif.c,v 1.28 2000/06/20 12:30:03 jinmei Exp $ */
/*
@@ -109,8 +109,15 @@
/*
* gif global variable definitions
*/
-static int ngif; /* number of interfaces */
-static struct gif_softc *gif = 0;
+LIST_HEAD(, gif_softc) gif_softc_list;
+
+int gif_clone_create __P((struct if_clone *, int));
+void gif_clone_destroy __P((struct ifnet *));
+
+struct if_clone gif_cloner =
+ IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy);
+
+void gif_delete_tunnel __P((struct gif_softc *));
#ifndef MAX_GIF_NEST
/*
@@ -125,68 +132,88 @@
#endif
static int max_gif_nesting = MAX_GIF_NEST;
+/* ARGSUSED */
void
-gifattach(dummy)
-#ifdef __FreeBSD__
- void *dummy;
-#else
- int dummy;
-#endif
+gifattach(count)
+ int count;
{
- register struct gif_softc *sc;
- register int i;
+
+ 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;
+
+ sc = malloc(sizeof(struct gif_softc), M_DEVBUF, M_WAIT);
+ bzero(sc, sizeof(struct gif_softc));
-#ifdef __NetBSD__
- ngif = dummy;
-#else
- ngif = NGIF;
+ sprintf(sc->gif_if.if_xname, "%s%d", ifc->ifc_name, unit);
+
+ sc->encap_cookie4 = sc->encap_cookie6 = NULL;
+#ifdef INET
+ sc->encap_cookie4 = encap_attach_func(AF_INET, -1,
+ gif_encapcheck, &in_gif_protosw, sc);
+ if (sc->encap_cookie4 == NULL) {
+ printf("%s: unable to attach encap4\n", if_name(&sc->gif_if));
+ return (EIO); /* XXX */
+ }
#endif
- gif = 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++) {
-#if defined(__NetBSD__) || defined(__OpenBSD__)
- sprintf(sc->gif_if.if_xname, "gif%d", i);
-#else
- sc->gif_if.if_name = "gif";
- sc->gif_if.if_unit = i;
+#ifdef INET6
+ sc->encap_cookie6 = encap_attach_func(AF_INET6, -1,
+ gif_encapcheck, (struct protosw *)&in6_gif_protosw, sc);
+ if (sc->encap_cookie6 == NULL) {
+ if (sc->encap_cookie4) {
+ encap_detach(sc->encap_cookie4);
+ sc->encap_cookie4 = NULL;
+ }
+ printf("%s: unable to attach encap6\n", if_name(&sc->gif_if));
+ return (EIO); /* XXX */
+ }
#endif
- sc->encap_cookie4 = sc->encap_cookie6 = NULL;
-#ifdef INET
- sc->encap_cookie4 = encap_attach_func(AF_INET, -1,
- gif_encapcheck, &in_gif_protosw, sc);
- if (sc->encap_cookie4 == NULL) {
- printf("%s: attach failed\n", if_name(&sc->gif_if));
- continue;
- }
+ 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_output = gif_output;
+ sc->gif_if.if_type = IFT_GIF;
+ if_attach(&sc->gif_if);
+#if NBPFILTER > 0
+#ifdef HAVE_OLD_BPF
+ bpfattach(&sc->gif_if, DLT_NULL, sizeof(u_int));
+#else
+ bpfattach(&sc->gif_if.if_bpf, &sc->gif_if, DLT_NULL, sizeof(u_int));
+#endif
#endif
+ LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list);
+ return (0);
+}
+
+void
+gif_clone_destroy(ifp)
+ struct ifnet *ifp;
+{
+ struct gif_softc *sc = (void *) ifp;
+
+ gif_delete_tunnel(sc);
+ LIST_REMOVE(sc, gif_list);
#ifdef INET6
- sc->encap_cookie6 = encap_attach_func(AF_INET6, -1,
- gif_encapcheck, (struct protosw *)&in6_gif_protosw, sc);
- if (sc->encap_cookie6 == NULL) {
- if (sc->encap_cookie4) {
- encap_detach(sc->encap_cookie4);
- sc->encap_cookie4 = NULL;
- }
- printf("%s: attach failed\n", if_name(&sc->gif_if));
- continue;
- }
+ encap_detach(sc->encap_cookie6);
+#endif
+#ifdef INET
+ encap_detach(sc->encap_cookie4);
#endif
- 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_output = gif_output;
- sc->gif_if.if_type = IFT_GIF;
- if_attach(&sc->gif_if);
#if NBPFILTER > 0
-#ifdef HAVE_OLD_BPF
- bpfattach(&sc->gif_if, DLT_NULL, sizeof(u_int));
-#else
- bpfattach(&sc->gif_if.if_bpf, &sc->gif_if, DLT_NULL, sizeof(u_int));
+ bpfdetach(ifp);
#endif
-#endif
- }
+ if_detach(ifp);
+
+ free(sc, M_DEVBUF);
}
#ifdef __FreeBSD__
@@ -444,7 +471,6 @@
int error = 0, size;
struct sockaddr *dst, *src;
struct sockaddr *sa;
- int i;
struct gif_softc *sc2;
switch (cmd) {
@@ -515,8 +541,8 @@
#endif
}
- for (i = 0; i < ngif; i++) {
- sc2 = gif + i;
+ for (sc2 = LIST_FIRST(&gif_softc_list); sc2 != NULL;
+ sc2 = LIST_NEXT(sc2, gif_list)) {
if (sc2 == sc)
continue;
if (!sc2->gif_pdst || !sc2->gif_psrc)
@@ -600,15 +626,7 @@
#ifdef SIOCDIFPHYADDR
case SIOCDIFPHYADDR:
- 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;
- }
- /* change the IFF_UP flag as well? */
+ gif_delete_tunnel(sc);
break;
#endif
@@ -683,4 +701,25 @@
bad:
return error;
}
+
+void
+gif_delete_tunnel(sc)
+ struct gif_softc *sc;
+{
+ int s;
+
+ s = splsoftnet();
+
+ 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;
+ }
+ /* change the IFF_UP flag as well? */
+
+ splx(s);
+}
#endif /*NGIF > 0*/
diff -r 21edb3e40b68 -r 4cff29dedd5f sys/net/if_gif.h
--- a/sys/net/if_gif.h Sun Jul 02 00:20:48 2000 +0000
+++ b/sys/net/if_gif.h Sun Jul 02 00:21:42 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gif.h,v 1.5 2000/04/19 06:30:53 itojun Exp $ */
+/* $NetBSD: if_gif.h,v 1.6 2000/07/02 00:21:42 thorpej Exp $ */
/* $KAME: if_gif.h,v 1.12 2000/04/19 06:20:11 itojun Exp $ */
/*
@@ -37,6 +37,7 @@
#ifndef _NET_IF_GIF_H_
#define _NET_IF_GIF_H_
+#include <sys/queue.h>
#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
#if defined(_KERNEL) && !defined(_LKM)
@@ -62,6 +63,7 @@
int gif_flags;
const struct encaptab *encap_cookie4;
const struct encaptab *encap_cookie6;
+ LIST_ENTRY(gif_softc) gif_list; /* list of all gifs */
};
#define gif_ro gifsc_gifscr.gifscr_ro
Home |
Main Index |
Thread Index |
Old Index