From owner-p4-projects@FreeBSD.ORG Sat Apr 12 21:31:32 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E63121065671; Sat, 12 Apr 2008 21:31:31 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7D49106566C for ; Sat, 12 Apr 2008 21:31:31 +0000 (UTC) (envelope-from qingli@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 7F6EC8FC18 for ; Sat, 12 Apr 2008 21:31:31 +0000 (UTC) (envelope-from qingli@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m3CLVVVA018490 for ; Sat, 12 Apr 2008 21:31:31 GMT (envelope-from qingli@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m3CLVV0r018488 for perforce@freebsd.org; Sat, 12 Apr 2008 21:31:31 GMT (envelope-from qingli@freebsd.org) Date: Sat, 12 Apr 2008 21:31:31 GMT Message-Id: <200804122131.m3CLVV0r018488@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to qingli@freebsd.org using -f From: Qing Li To: Perforce Change Reviews Cc: Subject: PERFORCE change 139936 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Apr 2008 21:31:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=139936 Change 139936 by qingli@FreeBSD-newarp on 2008/04/12 21:30:34 Take care of address aliases when an interface route has the interface address that is at the top of the address list. Also cleaned up code according to code reviews. Affected files ... .. //depot/projects/qingli_mpath/src/sys/net/radix_mpath.c#4 edit .. //depot/projects/qingli_mpath/src/sys/net/radix_mpath.h#3 edit .. //depot/projects/qingli_mpath/src/sys/net/route.c#5 edit Differences ... ==== //depot/projects/qingli_mpath/src/sys/net/radix_mpath.c#4 (text+ko) ==== @@ -52,16 +52,14 @@ static u_int32_t hashjitter; int -rn_mpath_capable(rnh) - struct radix_node_head *rnh; +rn_mpath_capable(struct radix_node_head *rnh) { return rnh->rnh_multipath; } struct radix_node * -rn_mpath_next(rn) - struct radix_node *rn; +rn_mpath_next(struct radix_node *rn) { struct radix_node *next; @@ -75,8 +73,7 @@ } int -rn_mpath_count(rn) - struct radix_node *rn; +rn_mpath_count(struct radix_node *rn) { int i; @@ -87,9 +84,7 @@ } struct rtentry * -rt_mpath_matchgate(rt, gate) - struct rtentry *rt; - struct sockaddr *gate; +rt_mpath_matchgate(struct rtentry *rt, struct sockaddr *gate) { struct radix_node *rn; @@ -103,7 +98,7 @@ rn = (struct radix_node *)rt; do { rt = (struct rtentry *)rn; - /* qingli: + /* * we are removing an address alias that has * the same prefix as another address * we need to compare the interface address because @@ -118,20 +113,16 @@ break; } } while ((rn = rn_mpath_next(rn)) != NULL); - if (!rn) - return NULL; return (struct rtentry *)rn; } -/* qingli: +/* * go through the chain and unlink "rt" from the list * the caller will free "rt" */ int -rt_mpath_deldup(headrt, rt) - struct rtentry *headrt; - struct rtentry *rt; +rt_mpath_deldup(struct rtentry *headrt, struct rtentry *rt) { struct radix_node *t, *tt; @@ -157,10 +148,8 @@ * check if we have the same key/mask/gateway on the table already. */ int -rt_mpath_conflict(rnh, rt, netmask) - struct radix_node_head *rnh; - struct rtentry *rt; - struct sockaddr *netmask; +rt_mpath_conflict(struct radix_node_head *rnh, struct rtentry *rt, + struct sockaddr *netmask) { struct radix_node *rn, *rn1; struct rtentry *rt1; @@ -262,9 +251,7 @@ } void -rtalloc_mpath(ro, hash) - struct route *ro; - int hash; +rtalloc_mpath(struct route *ro, int hash) { struct radix_node *rn0, *rn; int n; @@ -312,13 +299,11 @@ RT_UNLOCK(ro->ro_rt); } -extern int in6_inithead __P((void **head, int off)); -extern int in_inithead __P((void **head, int off)); +extern int in6_inithead(void **head, int off); +extern int in_inithead(void **head, int off); int -rn4_mpath_inithead(head, off) - void **head; - int off; +rn4_mpath_inithead(void **head, int off) { struct radix_node_head *rnh; @@ -332,9 +317,7 @@ } int -rn6_mpath_inithead(head, off) - void **head; - int off; +rn6_mpath_inithead(void **head, int off) { struct radix_node_head *rnh; ==== //depot/projects/qingli_mpath/src/sys/net/radix_mpath.h#3 (text+ko) ==== @@ -43,22 +43,18 @@ struct route; struct rtentry; struct sockaddr; -int rn_mpath_capable __P((struct radix_node_head *)); -struct radix_node *rn_mpath_next __P((struct radix_node *)); -int rn_mpath_count __P((struct radix_node *)); -struct rtentry *rt_mpath_matchgate __P((struct rtentry *, struct sockaddr *)); -int rt_mpath_conflict __P((struct radix_node_head *, struct rtentry *, - struct sockaddr *)); -void rtalloc_mpath __P((struct route *, int)); -struct radix_node *rn_mpath_lookup __P((void *, void *, - struct radix_node_head *)); -int rt_mpath_deldup __P((struct rtentry *, struct rtentry *)); -int rn4_mpath_inithead __P((void **, int)); -int rn6_mpath_inithead __P((void **, int)); - -/* for compatibility with NetBSD */ -#define rn_p rn_parent -#define rn_b rn_bit +int rn_mpath_capable(struct radix_node_head *); +struct radix_node *rn_mpath_next(struct radix_node *); +int rn_mpath_count(struct radix_node *); +struct rtentry *rt_mpath_matchgate(struct rtentry *, struct sockaddr *); +int rt_mpath_conflict(struct radix_node_head *, struct rtentry *, + struct sockaddr *); +void rtalloc_mpath(struct route *, int); +struct radix_node *rn_mpath_lookup(void *, void *, + struct radix_node_head *); +int rt_mpath_deldup(struct rtentry *, struct rtentry *); +int rn4_mpath_inithead(void **, int); +int rn6_mpath_inithead(void **, int); #endif ==== //depot/projects/qingli_mpath/src/sys/net/route.c#5 (text+ko) ==== @@ -735,10 +735,12 @@ RT_UNLOCK(rto); } else if (rt->rt_flags & RTF_GATEWAY) { /* - * For gateway routes, we need to make sure that we - * we are deleting the correct gateway. - * rt_mpath_matchgate() does not check the case when - * there is only one route in the chain. + * For gateway routes, we need to + * make sure that we we are deleting + * the correct gateway. + * rt_mpath_matchgate() does not + * check the case when there is only + * one route in the chain. */ if (gateway && (rt->rt_gateway->sa_len != gateway->sa_len || @@ -1298,9 +1300,10 @@ else { rt = RNTORT(rn); /* - * for interface route the rt->rt_gateway is sockaddr_intf - * for cloning ARP entries, so rt_mpath_matchgate - * must use the interface address + * for interface route the rt->rt_gateway is + * sockaddr_intf for cloning ARP entries, so + * rt_mpath_matchgate must use the interface + * address */ rt = rt_mpath_matchgate(rt, ifa->ifa_addr); if (!rt) @@ -1337,6 +1340,21 @@ * notify any listening routing agents of the change */ RT_LOCK(rt); +#ifdef RADIX_MPATH + /* + * in case address alias finds the first address + * e.g. ifconfig bge0 192.103.54.246/24 + * e.g. ifconfig bge0 192.103.54.247/24 + * the address set in the route is 192.103.54.246 + * so we need to replace it with 192.103.54.247 + */ + if (memcmp(rt->rt_ifa->ifa_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len)) { + IFAFREE(rt->rt_ifa); + IFAREF(ifa); + rt->rt_ifp = ifa->ifa_ifp; + rt->rt_ifa = ifa; + } +#endif rt_newaddrmsg(cmd, ifa, error, rt); if (cmd == RTM_DELETE) { /*