Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Jan 2009 07:23:02 +0000 (UTC)
From:      Kip Macy <kmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r186923 - user/kmacy/HEAD_fast_net/sys/net
Message-ID:  <200901090723.n097N2OI045902@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kmacy
Date: Fri Jan  9 07:23:02 2009
New Revision: 186923
URL: http://svn.freebsd.org/changeset/base/186923

Log:
  Add kernel support for weighting routes

Modified:
  user/kmacy/HEAD_fast_net/sys/net/radix_mpath.c
  user/kmacy/HEAD_fast_net/sys/net/route.c
  user/kmacy/HEAD_fast_net/sys/net/route.h
  user/kmacy/HEAD_fast_net/sys/net/rtsock.c

Modified: user/kmacy/HEAD_fast_net/sys/net/radix_mpath.c
==============================================================================
--- user/kmacy/HEAD_fast_net/sys/net/radix_mpath.c	Fri Jan  9 04:38:22 2009	(r186922)
+++ user/kmacy/HEAD_fast_net/sys/net/radix_mpath.c	Fri Jan  9 07:23:02 2009	(r186923)
@@ -80,14 +80,14 @@ rn_mpath_next(struct radix_node *rn)
 u_int32_t
 rn_mpath_count(struct radix_node *rn)
 {
-	u_int32_t i;
+	uint32_t i = 0;
 	struct rtentry *rt;
 	
 	i = 1;
 	while ((rn = rn_mpath_next(rn)) != NULL) {
 		rt = (struct rtentry *)rn;
 		if ((rt->rt_flags & RTF_SHUTDOWN) == 0)
-			i++;
+			i += rt->rt_rmx.rmx_weight;
 	}
 	return (i);
 }
@@ -260,11 +260,12 @@ different:
 }
 
 void
-rtalloc_mpath_fib(struct route *ro, u_int32_t hash, u_int fibnum)
+rtalloc_mpath_fib(struct route *ro, uint32_t hash, u_int fibnum)
 {
 	struct radix_node *rn0, *rn;
 	u_int32_t n;
 	struct rtentry *rt;
+	uint64_t total_weight = 0;
 	
 	/*
 	 * XXX we don't attempt to lookup cached route again; what should
@@ -289,12 +290,15 @@ rtalloc_mpath_fib(struct route *ro, u_in
 	/* gw selection by Modulo-N Hash (RFC2991) XXX need improvement? */
 	hash += hashjitter;
 	hash %= n;
-	while (hash-- > 0 && rn) {
+	while (rn) {
 		rt = (struct rtentry *)rn;
-		if (rt->rt_flags & RTF_SHUTDOWN) {
-			hash++;
+		if (rt->rt_flags & RTF_SHUTDOWN)
 			continue;
-		}
+
+		total_weight += rt->rt_rmx.rmx_weight;
+		if (total_weight >= hash)
+			break;
+
 		/* stay within the multipath routes */
 		if (rn->rn_dupedkey && rn->rn_mask != rn->rn_dupedkey->rn_mask)
 			break;

Modified: user/kmacy/HEAD_fast_net/sys/net/route.c
==============================================================================
--- user/kmacy/HEAD_fast_net/sys/net/route.c	Fri Jan  9 04:38:22 2009	(r186922)
+++ user/kmacy/HEAD_fast_net/sys/net/route.c	Fri Jan  9 07:23:02 2009	(r186923)
@@ -805,7 +805,7 @@ bad:
 
 #ifdef RADIX_MPATH
 static int
-rn_mpath_delete(int req, struct rt_addrinfo *info,
+rn_mpath_update(int req, struct rt_addrinfo *info,
     struct radix_node_head *rnh, struct rtentry **ret_nrt)
 {
 	/*
@@ -855,6 +855,9 @@ rn_mpath_delete(int req, struct rt_addri
 		 * use the normal delete code to remove
 		 * the first entry
 		 */
+		if (req != RTM_DELETE) 
+			goto nondelete;
+
 		error = ENOENT;
 		goto done;
 	}
@@ -875,9 +878,12 @@ rn_mpath_delete(int req, struct rt_addri
 		 */
 		V_rttrash++;
 		
-	} else if (req == RTM_SHUTDOWN)
+	}
+	
+nondelete:
+	if (req == RTM_SHUTDOWN)
 		rt->rt_flags |= RTF_SHUTDOWN;
-	else
+	else if (req != RTM_DELETE)
 		panic("unrecognized request %d", req);
 	
 
@@ -934,9 +940,9 @@ rtrequest1_fib(int req, struct rt_addrin
 	switch (req) {
 	case RTM_DELETE:
 #ifdef RADIX_MPATH
-	case RTM_SHUTDOWN:		
+	case RTM_SHUTDOWN:
 		if (rn_mpath_capable(rnh)) {
-			error = rn_mpath_delete(req, info, rnh, ret_nrt);
+			error = rn_mpath_update(req, info, rnh, ret_nrt);
 			/*
 			 * "bad" holds true for the success case
 			 * as well
@@ -992,11 +998,13 @@ rtrequest1_fib(int req, struct rt_addrin
 	case RTM_ADD:
 		if ((flags & RTF_GATEWAY) && !gateway)
 			senderr(EINVAL);
-		if (dst && gateway && (dst->sa_family != gateway->sa_family) && 
-		    (gateway->sa_family != AF_UNSPEC) && (gateway->sa_family != AF_LINK))
+		if (dst && gateway && (dst->sa_family != gateway->sa_family) 
+		    && (gateway->sa_family != AF_UNSPEC)
+		    && (gateway->sa_family != AF_LINK))
 			senderr(EINVAL);
 
-		if (info->rti_ifa == NULL && (error = rt_getifa_fib(info, fibnum)))
+		if (info->rti_ifa == NULL &&
+		    (error = rt_getifa_fib(info, fibnum)))
 			senderr(error);
 		ifa = info->rti_ifa;
 		rt = uma_zalloc(rtzone, M_NOWAIT | M_ZERO);
@@ -1037,6 +1045,7 @@ rtrequest1_fib(int req, struct rt_addrin
 		IFAREF(ifa);
 		rt->rt_ifa = ifa;
 		rt->rt_ifp = ifa->ifa_ifp;
+		rt->rt_rmx.rmx_weight = 1;
 
 #ifdef RADIX_MPATH
 		/* do not permit exactly the same dst/mask/gw pair */

Modified: user/kmacy/HEAD_fast_net/sys/net/route.h
==============================================================================
--- user/kmacy/HEAD_fast_net/sys/net/route.h	Fri Jan  9 04:38:22 2009	(r186922)
+++ user/kmacy/HEAD_fast_net/sys/net/route.h	Fri Jan  9 07:23:02 2009	(r186923)
@@ -60,6 +60,7 @@ struct rt_metrics_lite {
 	u_long	rmx_mtu;	/* MTU for this path */
 	u_long	rmx_expire;	/* lifetime for route, e.g. redirect */
 	u_long	rmx_pksent;	/* packets sent using this route */
+	u_long	rmx_weight;	/* absolute weight */ 
 };
 
 struct rt_metrics {
@@ -73,7 +74,8 @@ struct rt_metrics {
 	u_long	rmx_rtt;	/* estimated round trip time */
 	u_long	rmx_rttvar;	/* estimated rtt variance */
 	u_long	rmx_pksent;	/* packets sent using this route */
-	u_long	rmx_filler[4];	/* will be used for T/TCP later */
+	u_long	rmx_weight;	/* route weight */
+	u_long	rmx_filler[3];	/* will be used for T/TCP later */
 };
 
 /*
@@ -232,7 +234,7 @@ struct rt_msghdr {
 	struct	rt_metrics rtm_rmx; /* metrics themselves */
 };
 
-#define RTM_VERSION	5	/* Up the ante and ignore older versions */
+#define RTM_VERSION	6	/* Up the ante and ignore older versions */
 
 /*
  * Message types.
@@ -268,6 +270,7 @@ struct rt_msghdr {
 #define RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
 #define RTV_RTT		0x40	/* init or lock _rtt */
 #define RTV_RTTVAR	0x80	/* init or lock _rttvar */
+#define RTV_WEIGHT	0x100	/* init or lock _rttvar */
 
 /*
  * Bitmask values for rtm_addrs.
@@ -275,7 +278,7 @@ struct rt_msghdr {
 #define RTA_DST		0x1	/* destination sockaddr present */
 #define RTA_GATEWAY	0x2	/* gateway sockaddr present */
 #define RTA_NETMASK	0x4	/* netmask sockaddr present */
-#define RTA_GENMASK	0x8	/* cloning mask sockaddr present */
+#define RTA_SPARE	0x8	/* unused */
 #define RTA_IFP		0x10	/* interface name sockaddr present */
 #define RTA_IFA		0x20	/* interface addr sockaddr present */
 #define RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
@@ -287,7 +290,7 @@ struct rt_msghdr {
 #define RTAX_DST	0	/* destination sockaddr present */
 #define RTAX_GATEWAY	1	/* gateway sockaddr present */
 #define RTAX_NETMASK	2	/* netmask sockaddr present */
-#define RTAX_GENMASK	3	/* cloning mask sockaddr present */
+#define RTAX_SPARE	3	/* spare field */
 #define RTAX_IFP	4	/* interface name sockaddr present */
 #define RTAX_IFA	5	/* interface addr sockaddr present */
 #define RTAX_AUTHOR	6	/* sockaddr for author of redirect */
@@ -295,11 +298,11 @@ struct rt_msghdr {
 #define RTAX_MAX	8	/* size of array to allocate */
 
 struct rt_addrinfo {
-	int	rti_addrs;
-	struct	sockaddr *rti_info[RTAX_MAX];
-	int	rti_flags;
-	struct	ifaddr *rti_ifa;
-	struct	ifnet *rti_ifp;
+	int		rti_addrs;
+	struct sockaddr	*rti_info[RTAX_MAX];
+	int		rti_flags;
+	struct ifaddr 	*rti_ifa;
+	struct ifnet 	*rti_ifp;
 };
 
 /*

Modified: user/kmacy/HEAD_fast_net/sys/net/rtsock.c
==============================================================================
--- user/kmacy/HEAD_fast_net/sys/net/rtsock.c	Fri Jan  9 04:38:22 2009	(r186922)
+++ user/kmacy/HEAD_fast_net/sys/net/rtsock.c	Fri Jan  9 07:23:02 2009	(r186923)
@@ -614,7 +614,6 @@ route_output(struct mbuf *m, struct sock
 			info.rti_info[RTAX_DST] = rt_key(rt);
 			info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
 			info.rti_info[RTAX_NETMASK] = rt_mask(rt);
-			info.rti_info[RTAX_GENMASK] = 0;
 			if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) {
 				ifp = rt->rt_ifp;
 				if (ifp) {
@@ -792,6 +791,7 @@ rt_setmetrics(u_long which, const struct
 	 * of tcp hostcache. The rest is ignored.
 	 */
 	metric(RTV_MTU, rmx_mtu);
+	metric(RTV_WEIGHT, rmx_weight);
 	/* Userland -> kernel timebase conversion. */
 	if (which & RTV_EXPIRE)
 		out->rmx_expire = in->rmx_expire ?
@@ -1260,7 +1260,6 @@ sysctl_dumpentry(struct radix_node *rn, 
 	info.rti_info[RTAX_DST] = rt_key(rt);
 	info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
 	info.rti_info[RTAX_NETMASK] = rt_mask(rt);
-	info.rti_info[RTAX_GENMASK] = 0;
 	if (rt->rt_ifp) {
 		info.rti_info[RTAX_IFP] = rt->rt_ifp->if_addr->ifa_addr;
 		info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;



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