Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Jan 2007 01:40:26 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 113585 for review
Message-ID:  <200701270140.l0R1eQZW014765@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=113585

Change 113585 by zec@zec_tca51 on 2007/01/27 01:40:23

	Refactor gif(4) virtualization.

Affected files ...

.. //depot/projects/vimage/src/sys/net/if_gif.c#2 edit
.. //depot/projects/vimage/src/sys/net/if_gif.h#2 edit
.. //depot/projects/vimage/src/sys/netinet/in_gif.c#3 edit
.. //depot/projects/vimage/src/sys/netinet/in_gif.h#2 edit
.. //depot/projects/vimage/src/sys/netinet6/in6_gif.c#4 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#14 edit

Differences ...

==== //depot/projects/vimage/src/sys/net/if_gif.c#2 (text+ko) ====

@@ -33,6 +33,7 @@
 #include "opt_inet.h"
 #include "opt_inet6.h"
 #include "opt_mac.h"
+#include "opt_vimage.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,6 +49,8 @@
 #include <sys/syslog.h>
 #include <sys/protosw.h>
 #include <sys/conf.h>
+#include <sys/vimage.h>
+
 #include <machine/cpu.h>
 
 #include <net/if.h>
@@ -92,7 +95,9 @@
  */
 static struct mtx gif_mtx;
 static MALLOC_DEFINE(M_GIF, "gif", "Generic Tunnel Interface");
+#ifndef VIMAGE
 static LIST_HEAD(, gif_softc) gif_softc_list;
+#endif
 
 void	(*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp, int af);
 void	(*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m, int af);
@@ -102,6 +107,8 @@
 static void	gif_start(struct ifnet *);
 static int	gif_clone_create(struct if_clone *, int, caddr_t);
 static void	gif_clone_destroy(struct ifnet *);
+static int	vnet_gif_iattach(void);
+static int	vnet_gif_idetach(void);
 
 IFC_SIMPLE_DECLARE(gif, 0);
 
@@ -121,22 +128,37 @@
  */
 #define MAX_GIF_NEST 1
 #endif
-static int max_gif_nesting = MAX_GIF_NEST;
-SYSCTL_INT(_net_link_gif, OID_AUTO, max_nesting, CTLFLAG_RW,
-    &max_gif_nesting, 0, "Max nested tunnels");
+#ifndef VIMAGE
+static int max_gif_nesting;
+#endif
+SYSCTL_V_INT(V_NET, vnet_gif, _net_link_gif, OID_AUTO, max_nesting,
+	CTLFLAG_RW, max_gif_nesting, 0, "Max nested tunnels");
 
 /*
  * By default, we disallow creation of multiple tunnels between the same
  * pair of addresses.  Some applications require this functionality so
  * we allow control over this check here.
  */
+#ifndef VIMAGE
 #ifdef XBONEHACK
 static int parallel_tunnels = 1;
 #else
 static int parallel_tunnels = 0;
 #endif
-SYSCTL_INT(_net_link_gif, OID_AUTO, parallel_tunnels, CTLFLAG_RW,
-    &parallel_tunnels, 0, "Allow parallel tunnels?");
+#endif
+SYSCTL_V_INT(V_NET, vnet_gif, _net_link_gif, OID_AUTO, parallel_tunnels,
+	CTLFLAG_RW, parallel_tunnels, 0, "Allow parallel tunnels?");
+
+#ifdef VIMAGE
+static struct vnet_modinfo vnet_gif_modinfo = {
+	.id		= VNET_MOD_GIF,
+	.flags		= VNET_MFLAG_ORDER_2ND,
+	.name		= "gif",
+	.symmap		= NULL,
+	.i_attach	= vnet_gif_iattach,
+	.i_detach	= vnet_gif_idetach
+};
+#endif
 
 static int
 gif_clone_create(ifc, unit, params)
@@ -144,6 +166,7 @@
 	int unit;
 	caddr_t params;
 {
+	INIT_VNET_GIF(curvnetb);
 	struct gif_softc *sc;
 
 	sc = malloc(sizeof(struct gif_softc), M_GIF, M_WAITOK | M_ZERO);
@@ -177,7 +200,7 @@
 		(*ng_gif_attach_p)(GIF2IFP(sc));
 
 	mtx_lock(&gif_mtx);
-	LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list);
+	LIST_INSERT_HEAD(&V_gif_softc_list, sc, gif_list);
 	mtx_unlock(&gif_mtx);
 
 	return (0);
@@ -219,6 +242,41 @@
 	free(sc, M_GIF);
 }
 
+static int vnet_gif_iattach(void)
+{
+#ifdef VIMAGE
+	struct vnet_gif *vnet_gif;
+
+	vnet_gif = malloc(sizeof(*vnet_gif), M_GIF, M_NOWAIT | M_ZERO);
+	if (vnet_gif == NULL) 
+		panic("couldn't allocate memory for vnet_gif");
+	curvnetb->mod_data[vnet_gif_modinfo.id] = vnet_gif;
+	vnet_gif->parent_vnetb = curvnetb;
+#endif
+
+	LIST_INIT(&V_gif_softc_list);
+	V_max_gif_nesting = MAX_GIF_NEST;
+        V_ip_gif_ttl = GIF_TTL;
+
+#ifdef INET6
+	V_ip6_gif_hlim = GIF_HLIM;
+#endif
+
+	return 0;
+}
+
+static int vnet_gif_idetach(void)
+{
+	INIT_VNET_GIF(curvnetb);
+
+#ifdef VIMAGE
+	curvnetb->mod_data[vnet_gif_modinfo.id] = NULL;
+	free(vnet_gif, M_GIF);
+#endif
+
+	return 0;
+}
+
 static int
 gifmodevent(mod, type, data)
 	module_t mod;
@@ -229,20 +287,21 @@
 	switch (type) {
 	case MOD_LOAD:
 		mtx_init(&gif_mtx, "gif_mtx", NULL, MTX_DEF);
-		LIST_INIT(&gif_softc_list);
+#ifdef VIMAGE
+		vnet_mod_register(&vnet_gif_modinfo);
+#else
+		vnet_gif_iattach();
+#endif
 		if_clone_attach(&gif_cloner);
-
-#ifdef INET6
-		ip6_gif_hlim = GIF_HLIM;
-#endif
-
 		break;
 	case MOD_UNLOAD:
 		if_clone_detach(&gif_cloner);
+#ifdef VIMAGE
+		vnet_mod_deregister(&vnet_gif_modinfo);
+#else
+		vnet_gif_idetach();
+#endif
 		mtx_destroy(&gif_mtx);
-#ifdef INET6
-		ip6_gif_hlim = 0;
-#endif
 		break;
 	default:
 		return EOPNOTSUPP;
@@ -353,6 +412,7 @@
 	struct sockaddr *dst;
 	struct rtentry *rt;	/* added in net2 */
 {
+	INIT_VNET_GIF(ifp->if_vnetb);
 	struct gif_softc *sc = ifp->if_softc;
 	struct m_tag *mtag;
 	int error = 0;
@@ -388,7 +448,7 @@
 		mtag = m_tag_locate(m, MTAG_GIF, MTAG_GIF_CALLED, mtag);
 		gif_called++;
 	}
-	if (gif_called > max_gif_nesting) {
+	if (gif_called > V_max_gif_nesting) {
 		log(LOG_NOTICE,
 		    "gif_output: recursively called too many times(%d)\n",
 		    gif_called);
@@ -822,13 +882,14 @@
 	struct sockaddr *src;
 	struct sockaddr *dst;
 {
+	INIT_VNET_GIF(ifp->if_vnetb);
 	struct gif_softc *sc = ifp->if_softc;
 	struct gif_softc *sc2;
 	struct sockaddr *osrc, *odst, *sa;
 	int error = 0; 
 
 	mtx_lock(&gif_mtx);
-	LIST_FOREACH(sc2, &gif_softc_list, gif_list) {
+	LIST_FOREACH(sc2, &V_gif_softc_list, gif_list) {
 		if (sc2 == sc)
 			continue;
 		if (!sc2->gif_pdst || !sc2->gif_psrc)
@@ -843,7 +904,7 @@
 		 * Disallow parallel tunnels unless instructed
 		 * otherwise.
 		 */
-		if (!parallel_tunnels &&
+		if (!V_parallel_tunnels &&
 		    bcmp(sc2->gif_pdst, dst, dst->sa_len) == 0 &&
 		    bcmp(sc2->gif_psrc, src, src->sa_len) == 0) {
 			error = EADDRNOTAVAIL;

==== //depot/projects/vimage/src/sys/net/if_gif.h#2 (text+ko) ====

@@ -109,6 +109,31 @@
 void gif_delete_tunnel(struct ifnet *);
 int gif_encapcheck(const struct mbuf *, int, int, void *);
 
+/*
+ * Virtualization support
+ */
+
+#define INIT_VNET_GIF(vnetb) \
+	INIT_FROM_VNET_BASE(vnetb, VNET_MOD_GIF, struct vnet_gif, vnet_gif)
+
+#define VNET_GIF(sym)		VSYM(vnet_gif, sym)
+
+struct vnet_gif {
+	struct  vnet_base *parent_vnetb;
+
+	LIST_HEAD(, gif_softc) _gif_softc_list;
+	int	_max_gif_nesting;
+	int	_parallel_tunnels;
+	int	_ip_gif_ttl;
+	int	_ip6_gif_hlim;
+};
+
+#define V_gif_softc_list	VNET_GIF(gif_softc_list)
+#define V_max_gif_nesting	VNET_GIF(max_gif_nesting)
+#define V_parallel_tunnels	VNET_GIF(parallel_tunnels)
+#define V_ip_gif_ttl		VNET_GIF(ip_gif_ttl)
+#define V_ip6_gif_hlim		VNET_GIF(ip6_gif_hlim)
+
 #endif /* _KERNEL */
 
 #endif /* _NET_IF_GIF_H_ */

==== //depot/projects/vimage/src/sys/netinet/in_gif.c#3 (text+ko) ====

@@ -72,7 +72,6 @@
 
 static int gif_validate4(const struct ip *, struct gif_softc *,
 	struct ifnet *);
-static void in_gif_init(void);
 
 extern  struct domain inetdomain;
 struct protosw in_gif_protosw = {
@@ -83,31 +82,22 @@
 	.pr_input =		in_gif_input,
 	.pr_output =		(pr_output_t*)rip_output,
 	.pr_ctloutput =		rip_ctloutput,
-	.pr_init =		in_gif_init,
 	.pr_usrreqs =		&rip_usrreqs
 };
 
 #ifndef VIMAGE
 static int ip_gif_ttl;
 #endif
-SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_ip, IPCTL_GIF_TTL, gifttl,
+SYSCTL_V_INT(V_NET, vnet_gif, _net_inet_ip, IPCTL_GIF_TTL, gifttl,
 	CTLFLAG_RW, ip_gif_ttl,	0, "");
 
-static void
-in_gif_init(void)
-{
-	INIT_VNET_INET(curvnetb);
-
-	V_ip_gif_ttl = GIF_TTL;
-}
-
 int
 in_gif_output(ifp, family, m)
 	struct ifnet	*ifp;
 	int		family;
 	struct mbuf	*m;
 {
-	INIT_VNET_INET(ifp->if_vnetb);
+	INIT_VNET_GIF(ifp->if_vnetb);
 	struct gif_softc *sc = ifp->if_softc;
 	struct sockaddr_in *dst = (struct sockaddr_in *)&sc->gif_ro.ro_dst;
 	struct sockaddr_in *sin_src = (struct sockaddr_in *)sc->gif_psrc;

==== //depot/projects/vimage/src/sys/netinet/in_gif.h#2 (text+ko) ====


==== //depot/projects/vimage/src/sys/netinet6/in6_gif.c#4 (text+ko) ====

@@ -88,6 +88,7 @@
 	int family; /* family of the packet to be encapsulate. */
 	struct mbuf *m;
 {
+	INIT_VNET_GIF(ifp->if_vnetb);
 	struct gif_softc *sc = ifp->if_softc;
 	struct sockaddr_in6 *dst = (struct sockaddr_in6 *)&sc->gif_ro6.ro_dst;
 	struct sockaddr_in6 *sin6_src = (struct sockaddr_in6 *)sc->gif_psrc;
@@ -176,7 +177,7 @@
 	ip6->ip6_vfc	|= IPV6_VERSION;
 	ip6->ip6_plen	= htons((u_short)m->m_pkthdr.len);
 	ip6->ip6_nxt	= proto;
-	ip6->ip6_hlim	= ip6_gif_hlim;
+	ip6->ip6_hlim	= V_ip6_gif_hlim;
 	ip6->ip6_src	= sin6_src->sin6_addr;
 	/* bidirectional configured tunnel mode */
 	if (!IN6_IS_ADDR_UNSPECIFIED(&sin6_dst->sin6_addr))

==== //depot/projects/vimage/src/sys/sys/vimage.h#14 (text+ko) ====

@@ -67,7 +67,10 @@
 #define VNET_MOD_INET6		 3
 #define VNET_MOD_IPX		 4
 #define VNET_MOD_ATALK		 5
+
 #define VNET_MOD_IPFW		 8
+#define VNET_MOD_GIF		 9
+
 #define VNET_MOD_ARP		29
 #define VNET_MOD_RTABLE		30
 #define VNET_MOD_LOIF		31
@@ -80,6 +83,7 @@
 #define V_MOD_vnet_inet		VNET_MOD_INET
 #define V_MOD_vnet_inet6	VNET_MOD_INET6
 #define V_MOD_vnet_ipfw		VNET_MOD_IPFW
+#define V_MOD_vnet_gif		VNET_MOD_GIF
 
 struct vnet_base {
 	LIST_ENTRY(vnet_base) vnetb_le;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200701270140.l0R1eQZW014765>