Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Jul 2009 19:20:55 +0000 (UTC)
From:      Qing Li <qingli@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r195643 - head/sys/netinet6
Message-ID:  <200907121920.n6CJKtf1092990@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: qingli
Date: Sun Jul 12 19:20:55 2009
New Revision: 195643
URL: http://svn.freebsd.org/changeset/base/195643

Log:
  This patch adds a host route to an interface address (that is assigned
  to a non loopback/ppp link type) through the loopback interface. Prior
  to the new L2/L3 rewrite, this host route was explicitly created when
  processing the IPv6 address assignment. This loopback host route is
  deleted when that IPv6 address is removed from the interface.
  
  Reviewed by:	bz, gnn
  Approved by:	re

Modified:
  head/sys/netinet6/in6.c

Modified: head/sys/netinet6/in6.c
==============================================================================
--- head/sys/netinet6/in6.c	Sun Jul 12 17:07:35 2009	(r195642)
+++ head/sys/netinet6/in6.c	Sun Jul 12 19:20:55 2009	(r195643)
@@ -1194,6 +1194,25 @@ in6_purgeaddr(struct ifaddr *ifa)
 		ifa_ref(ifa0);
 	IF_ADDR_UNLOCK(ifp);
 
+	if (!(ia->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
+		struct rt_addrinfo info;
+		struct sockaddr_dl null_sdl;
+
+		bzero(&null_sdl, sizeof(null_sdl));
+		null_sdl.sdl_len = sizeof(null_sdl);
+		null_sdl.sdl_family = AF_LINK;
+		null_sdl.sdl_type = V_loif->if_type;
+		null_sdl.sdl_index = V_loif->if_index;
+		bzero(&info, sizeof(info));
+		info.rti_flags = ia->ia_flags | RTF_HOST | RTF_STATIC;
+		info.rti_info[RTAX_DST] = (struct sockaddr *)&ia->ia_addr;
+		info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl;
+		error = rtrequest1_fib(RTM_DELETE, &info, NULL, 0);
+
+		if (error != 0)
+			log(LOG_INFO, "in6_purgeaddr: deletion failed\n");
+	}
+
 	/* stop DAD processing */
 	nd6_dad_stop(ifa);
 
@@ -1755,6 +1774,33 @@ in6_ifinit(struct ifnet *ifp, struct in6
 		ia->ia_flags |= IFA_ROUTE;
 	}
 
+	/*
+	 * add a loopback route to self
+	 */
+	if (!(ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
+		struct rt_addrinfo info;
+		struct rtentry *rt = NULL;
+		static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
+
+		bzero(&info, sizeof(info));
+		info.rti_ifp = V_loif;
+		info.rti_flags = ia->ia_flags | RTF_HOST | RTF_STATIC;
+		info.rti_info[RTAX_DST] = (struct sockaddr *)&ia->ia_addr;
+		info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl;
+		error = rtrequest1_fib(RTM_ADD, &info, &rt, 0);
+
+		if (error == 0 && rt != NULL) {
+			RT_LOCK(rt);
+			((struct sockaddr_dl *)rt->rt_gateway)->sdl_type  =
+				rt->rt_ifp->if_type;
+			((struct sockaddr_dl *)rt->rt_gateway)->sdl_index =
+				rt->rt_ifp->if_index;
+			RT_REMREF(rt);
+			RT_UNLOCK(rt);
+		} else if (error != 0)
+			log(LOG_INFO, "in6_ifinit: insertion failed\n");
+	}
+
 	/* Add ownaddr as loopback rtentry, if necessary (ex. on p2p link). */
 	if (newhost) {
 		struct llentry *ln;



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