PERFORCE change 113517 for review

Marko Zec zec at FreeBSD.org
Thu Jan 25 17:30:40 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=113517

Change 113517 by zec at zec_tca51 on 2007/01/25 17:30:26

	Let arptimer() run in all vnets, not only in the default
	one.
	
	While there, virtualize a few arp-related sysctls.

Affected files ...

.. //depot/projects/vimage/src/sys/netinet/if_ether.c#7 edit
.. //depot/projects/vimage/src/sys/netinet/vinet.h#8 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#13 edit

Differences ...

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

@@ -83,13 +83,15 @@
 SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
 
 /* timer values */
-static int arpt_prune = (5*60*1); /* walk list every 5 minutes */
-static int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
+#ifndef VIMAGE
+static int arpt_prune;
+static int arpt_keep;
+#endif
 
-SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW,
-	   &arpt_prune, 0, "ARP table prune interval in seconds");
-SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, 
-	   &arpt_keep, 0, "ARP entry lifetime in seconds");
+SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, prune_intvl,
+	CTLFLAG_RW, arpt_prune, 0, "ARP table prune interval in seconds");
+SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, max_age,
+	CTLFLAG_RW, arpt_keep, 0, "ARP entry lifetime in seconds");
 
 #define	rt_expire rt_rmx.rmx_expire
 
@@ -101,26 +103,28 @@
 	u_short	la_asked;	/* # requests sent */
 };
 
+static struct	ifqueue arpintrq;
+
 #ifndef VIMAGE
 static	LIST_HEAD(, llinfo_arp) llinfo_arp;
+static int	arp_maxtries;
+static int	useloopback;
+static int	arp_proxyall;
+static struct callout arp_callout;
 #endif
 
-static struct	ifqueue arpintrq;
-static int	arp_allocated;
-
-static int	arp_maxtries = 5;
-static int	useloopback = 1; /* use loopback interface for local traffic */
-static int	arp_proxyall = 0;
-static struct callout arp_callout;
-
-SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW,
-	   &arp_maxtries, 0, "ARP resolution attempts before returning error");
-SYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW,
-	   &useloopback, 0, "Use the loopback interface for local traffic");
-SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
-	   &arp_proxyall, 0, "Enable proxy ARP for all suitable requests");
+SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, maxtries,
+	CTLFLAG_RW, arp_maxtries, 0,
+	"ARP resolution attempts before returning error");
+SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, useloopback,
+	CTLFLAG_RW, useloopback, 0,
+	"Use the loopback interface for local traffic");
+SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, proxyall,
+	CTLFLAG_RW, arp_proxyall, 0,
+	"Enable proxy ARP for all suitable requests");
 
 static void	arp_init(void);
+static int	arp_iattach(void);
 static void	arp_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
 static void	arprequest(struct ifnet *,
 			struct in_addr *, struct in_addr *, u_char *);
@@ -132,6 +136,17 @@
 static void	in_arpinput(struct mbuf *);
 #endif
 
+#ifdef VIMAGE
+static struct vnet_modinfo vnet_arp_modinfo = {
+	.id             = VNET_MOD_ARP,
+	.flags          = VNET_MFLAG_ORDER_2ND,
+	.name           = "arp",
+	.symmap         = NULL,
+	.i_attach       = arp_iattach,
+	.i_detach       = NULL,
+};
+#endif
+
 /*
  * Timeout routine.  Age arp_tab entries periodically.
  */
@@ -173,7 +188,7 @@
 	RADIX_NODE_HEAD_UNLOCK(V_rt_tables[AF_INET]);
 	CURVNETB_RESTORE();
 
-	callout_reset(&arp_callout, arpt_prune * hz, arptimer, arg);
+	callout_reset(&V_arp_callout, V_arpt_prune * hz, arptimer, arg);
 }
 
 /*
@@ -253,7 +268,6 @@
 			log(LOG_DEBUG, "%s: malloc failed\n", __func__);
 			break;
 		}
-		arp_allocated++;
 		/*
 		 * We are storing a route entry outside of radix tree. So,
 		 * it can be found and accessed by other means than radix
@@ -308,7 +322,7 @@
 			rt->rt_expire = 0;
 			bcopy(IF_LLADDR(rt->rt_ifp), LLADDR(SDL(gate)),
 			      SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen);
-			if (useloopback) {
+			if (V_useloopback) {
 				rt->rt_ifp = V_loif;
 				rt->rt_rmx.rmx_mtu = V_loif->if_mtu;
 			}
@@ -400,6 +414,7 @@
 arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
 	struct sockaddr *dst, u_char *desten)
 {
+	INIT_VNET_INET(ifp->if_vnetb);
 	struct llinfo_arp *la = NULL;
 	struct rtentry *rt = NULL;
 	struct sockaddr_dl *sdl;
@@ -504,7 +519,7 @@
 	 * if we have already sent arp_maxtries ARP requests. Retransmit the
 	 * ARP request, but not faster than one request per second.
 	 */
-	if (la->la_asked < arp_maxtries)
+	if (la->la_asked < V_arp_maxtries)
 		error = EWOULDBLOCK;	/* First request. */
 	else
 		error = (rt == rt0) ? EHOSTDOWN : EHOSTUNREACH;
@@ -809,9 +824,9 @@
 		th->rcf = trld->trld_rcf;
 	}
 	if (rt->rt_expire)
-		rt->rt_expire = time_uptime + arpt_keep;
+		rt->rt_expire = time_uptime + V_arpt_keep;
 	la->la_asked = 0;
-	la->la_preempt = arp_maxtries;
+	la->la_preempt = V_arp_maxtries;
 	hold = la->la_hold;
 	la->la_hold = NULL;
 	RT_UNLOCK(rt);
@@ -830,7 +845,7 @@
 		if (rt == NULL) {
 			struct sockaddr_in sin;
 
-			if (!arp_proxyall)
+			if (!V_arp_proxyall)
 				goto drop;
 
 			bzero(&sin, sizeof sin);
@@ -993,18 +1008,35 @@
 	ifa->ifa_flags |= RTF_CLONING;
 }
 
+static int
+arp_iattach(void)
+{
+	INIT_VNET_INET(curvnetb);
+
+	V_arpt_prune = (5*60*1); /* walk list every 5 minutes */
+	V_arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
+	V_arp_maxtries = 5;
+	V_useloopback = 1; /* use loopback interface for local traffic */
+	V_arp_proxyall = 0;
+
+	LIST_INIT(&V_llinfo_arp);
+	callout_init(&V_arp_callout, CALLOUT_MPSAFE);
+	callout_reset(&V_arp_callout, hz, arptimer, curvnetb);
+
+	return 0;
+}
+
 static void
 arp_init(void)
 {
-	INIT_VNET_INET(curvnetb);	/* XXX should panic here! */
-printf("arp_init\n");
-
+#ifdef VIMAGE
+	vnet_mod_register(&vnet_arp_modinfo);
+#else
+	arp_iattach();
+#endif
 	arpintrq.ifq_maxlen = 50;
 	mtx_init(&arpintrq.ifq_mtx, "arp_inq", NULL, MTX_DEF);
-	LIST_INIT(&V_llinfo_arp); /* XXX */
-	callout_init(&arp_callout, CALLOUT_MPSAFE);
 	netisr_register(NETISR_ARP, arpintr, &arpintrq, NETISR_MPSAFE);
-	callout_reset(&arp_callout, hz, arptimer, curvnetb);
 }
 
 SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0);

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

@@ -62,6 +62,12 @@
 	struct	in_multihead _in_multihead;
 
 	LIST_HEAD(, llinfo_arp) _llinfo_arp;
+	struct	callout _arp_callout;
+	int	_arpt_prune;
+	int	_arpt_keep;
+	int	_arp_maxtries;
+	int	_useloopback;
+	int	_arp_proxyall;
 
 	int	_ipforwarding;
 
@@ -118,6 +124,12 @@
 #define V_in_multihead		VNET_INET(in_multihead)
 
 #define V_llinfo_arp		VNET_INET(llinfo_arp)
+#define V_arp_callout		VNET_INET(arp_callout)
+#define V_arpt_prune		VNET_INET(arpt_prune)
+#define V_arpt_keep		VNET_INET(arpt_keep)
+#define V_arp_maxtries		VNET_INET(arp_maxtries)
+#define V_useloopback		VNET_INET(useloopback)
+#define V_arp_proxyall		VNET_INET(arp_proxyall)
 
 #define V_ipforwarding		VNET_INET(ipforwarding)
 

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

@@ -68,6 +68,7 @@
 #define VNET_MOD_IPX		 4
 #define VNET_MOD_ATALK		 5
 #define VNET_MOD_IPFW		 8
+#define VNET_MOD_ARP		29
 #define VNET_MOD_RTABLE		30
 #define VNET_MOD_LOIF		31
 #define VNET_MOD_DYNAMIC_START	32


More information about the p4-projects mailing list