svn commit: r356559 - in head/sys: net netinet netinet6 sys

Alexander V. Chernikov melifaro at FreeBSD.org
Thu Jan 9 17:21:02 UTC 2020


Author: melifaro
Date: Thu Jan  9 17:21:00 2020
New Revision: 356559
URL: https://svnweb.freebsd.org/changeset/base/356559

Log:
  Add fibnum, family and vnet pointer to each rib head.
  
  Having metadata such as fibnum or vnet in the struct rib_head
   is handy as it eases building functionality in the routing space.
  This change is required to properly bring back route redirect support.
  
  Reviewed by:	bz
  MFC after:	3 weeks
  Differential Revision:	https://reviews.freebsd.org/D23047

Modified:
  head/sys/net/radix_mpath.c
  head/sys/net/radix_mpath.h
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route_var.h
  head/sys/netinet/in_proto.c
  head/sys/netinet/in_rmx.c
  head/sys/netinet6/in6_proto.c
  head/sys/netinet6/in6_rmx.c
  head/sys/sys/domain.h

Modified: head/sys/net/radix_mpath.c
==============================================================================
--- head/sys/net/radix_mpath.c	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/net/radix_mpath.c	Thu Jan  9 17:21:00 2020	(r356559)
@@ -290,17 +290,17 @@ rtalloc_mpath_fib(struct route *ro, uint32_t hash, u_i
 	RT_UNLOCK(ro->ro_rt);
 }
 
-extern int	in6_inithead(void **head, int off);
-extern int	in_inithead(void **head, int off);
+extern int	in6_inithead(void **head, int off, u_int fibnum);
+extern int	in_inithead(void **head, int off, u_int fibnum);
 
 #ifdef INET
 int
-rn4_mpath_inithead(void **head, int off)
+rn4_mpath_inithead(void **head, int off, u_int fibnum)
 {
 	struct rib_head *rnh;
 
 	hashjitter = arc4random();
-	if (in_inithead(head, off) == 1) {
+	if (in_inithead(head, off, fibnum) == 1) {
 		rnh = (struct rib_head *)*head;
 		rnh->rnh_multipath = 1;
 		return 1;
@@ -311,12 +311,12 @@ rn4_mpath_inithead(void **head, int off)
 
 #ifdef INET6
 int
-rn6_mpath_inithead(void **head, int off)
+rn6_mpath_inithead(void **head, int off, u_int fibnum)
 {
 	struct rib_head *rnh;
 
 	hashjitter = arc4random();
-	if (in6_inithead(head, off) == 1) {
+	if (in6_inithead(head, off, fibnum) == 1) {
 		rnh = (struct rib_head *)*head;
 		rnh->rnh_multipath = 1;
 		return 1;

Modified: head/sys/net/radix_mpath.h
==============================================================================
--- head/sys/net/radix_mpath.h	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/net/radix_mpath.h	Thu Jan  9 17:21:00 2020	(r356559)
@@ -57,8 +57,8 @@ int rt_mpath_conflict(struct rib_head *, struct rtentr
 void rtalloc_mpath_fib(struct route *, u_int32_t, u_int);
 struct rtentry *rt_mpath_select(struct rtentry *, uint32_t);
 int rt_mpath_deldup(struct rtentry *, struct rtentry *);
-int	rn4_mpath_inithead(void **, int);
-int	rn6_mpath_inithead(void **, int);
+int	rn4_mpath_inithead(void **, int, u_int);
+int	rn6_mpath_inithead(void **, int, u_int);
 
 #endif
 

Modified: head/sys/net/route.c
==============================================================================
--- head/sys/net/route.c	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/net/route.c	Thu Jan  9 17:21:00 2020	(r356559)
@@ -304,7 +304,7 @@ vnet_route_init(const void *unused __unused)
 			rnh = rt_tables_get_rnh_ptr(table, fam);
 			if (rnh == NULL)
 				panic("%s: rnh NULL", __func__);
-			dom->dom_rtattach((void **)rnh, 0);
+			dom->dom_rtattach((void **)rnh, 0, table);
 		}
 	}
 }
@@ -345,7 +345,7 @@ VNET_SYSUNINIT(vnet_route_uninit, SI_SUB_PROTO_DOMAIN,
 #endif
 
 struct rib_head *
-rt_table_init(int offset)
+rt_table_init(int offset, int family, u_int fibnum)
 {
 	struct rib_head *rh;
 
@@ -356,6 +356,13 @@ rt_table_init(int offset)
 	rn_inithead_internal(&rh->head, rh->rnh_nodes, offset);
 	rn_inithead_internal(&rh->rmhead.head, rh->rmhead.mask_nodes, 0);
 	rh->head.rnh_masks = &rh->rmhead;
+
+	/* Save metadata associated with this routing table. */
+	rh->rib_family = family;
+	rh->rib_fibnum = fibnum;
+#ifdef VIMAGE
+	rh->rib_vnet = curvnet;
+#endif
 
 	/* Init locks */
 	RIB_LOCK_INIT(rh);

Modified: head/sys/net/route.h
==============================================================================
--- head/sys/net/route.h	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/net/route.h	Thu Jan  9 17:21:00 2020	(r356559)
@@ -455,7 +455,7 @@ int	 rt_routemsg_info(int, struct rt_addrinfo *, int);
 void	 rt_newmaddrmsg(int, struct ifmultiaddr *);
 int	 rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *);
 void 	 rt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *);
-struct rib_head *rt_table_init(int);
+struct rib_head *rt_table_init(int, int, u_int);
 void	rt_table_destroy(struct rib_head *);
 u_int	rt_tables_get_gen(int table, int fam);
 

Modified: head/sys/net/route_var.h
==============================================================================
--- head/sys/net/route_var.h	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/net/route_var.h	Thu Jan  9 17:21:00 2020	(r356559)
@@ -46,6 +46,9 @@ struct rib_head {
 	struct radix_node	rnh_nodes[3];	/* empty tree for common case */
 	struct rmlock		rib_lock;	/* config/data path lock */
 	struct radix_mask_head	rmhead;		/* masks radix head */
+	struct vnet		*rib_vnet;	/* vnet pointer */
+	int			rib_family;	/* AF of the rtable */
+	u_int			rib_fibnum;	/* fib number */
 };
 
 #define	RIB_RLOCK_TRACKER	struct rm_priotracker _rib_tracker

Modified: head/sys/netinet/in_proto.c
==============================================================================
--- head/sys/netinet/in_proto.c	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/netinet/in_proto.c	Thu Jan  9 17:21:00 2020	(r356559)
@@ -297,7 +297,7 @@ IPPROTOSPACER,
 },
 };
 
-extern int in_inithead(void **, int);
+extern int in_inithead(void **, int, u_int);
 extern int in_detachhead(void **, int);
 
 struct domain inetdomain = {

Modified: head/sys/netinet/in_rmx.c
==============================================================================
--- head/sys/netinet/in_rmx.c	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/netinet/in_rmx.c	Thu Jan  9 17:21:00 2020	(r356559)
@@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/ip_icmp.h>
 #include <netinet/ip_var.h>
 
-extern int	in_inithead(void **head, int off);
+extern int	in_inithead(void **head, int off, u_int fibnum);
 #ifdef VIMAGE
 extern int	in_detachhead(void **head, int off);
 #endif
@@ -116,11 +116,11 @@ static int _in_rt_was_here;
  * Initialize our routing tree.
  */
 int
-in_inithead(void **head, int off)
+in_inithead(void **head, int off, u_int fibnum)
 {
 	struct rib_head *rh;
 
-	rh = rt_table_init(32);
+	rh = rt_table_init(32, AF_INET, fibnum);
 	if (rh == NULL)
 		return (0);
 

Modified: head/sys/netinet6/in6_proto.c
==============================================================================
--- head/sys/netinet6/in6_proto.c	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/netinet6/in6_proto.c	Thu Jan  9 17:21:00 2020	(r356559)
@@ -336,7 +336,7 @@ IP6PROTOSPACER,
 },
 };
 
-extern int in6_inithead(void **, int);
+extern int in6_inithead(void **, int, u_int);
 #ifdef VIMAGE
 extern int in6_detachhead(void **, int);
 #endif

Modified: head/sys/netinet6/in6_rmx.c
==============================================================================
--- head/sys/netinet6/in6_rmx.c	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/netinet6/in6_rmx.c	Thu Jan  9 17:21:00 2020	(r356559)
@@ -96,7 +96,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/tcp_timer.h>
 #include <netinet/tcp_var.h>
 
-extern int	in6_inithead(void **head, int off);
+extern int	in6_inithead(void **head, int off, u_int fibnum);
 #ifdef VIMAGE
 extern int	in6_detachhead(void **head, int off);
 #endif
@@ -157,11 +157,12 @@ in6_addroute(void *v_arg, void *n_arg, struct radix_he
  */
 
 int
-in6_inithead(void **head, int off)
+in6_inithead(void **head, int off, u_int fibnum)
 {
 	struct rib_head *rh;
 
-	rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3);
+	rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3,
+	    AF_INET6, fibnum);
 	if (rh == NULL)
 		return (0);
 

Modified: head/sys/sys/domain.h
==============================================================================
--- head/sys/sys/domain.h	Thu Jan  9 16:47:59 2020	(r356558)
+++ head/sys/sys/domain.h	Thu Jan  9 17:21:00 2020	(r356559)
@@ -60,7 +60,7 @@ struct domain {
 	struct	protosw *dom_protosw, *dom_protoswNPROTOSW;
 	struct	domain *dom_next;
 	int	(*dom_rtattach)		/* initialize routing table */
-		(void **, int);
+		(void **, int, u_int);
 	int	(*dom_rtdetach)		/* clean up routing table */
 		(void **, int);
 	void	*(*dom_ifattach)(struct ifnet *);


More information about the svn-src-head mailing list