From owner-svn-src-all@FreeBSD.ORG Tue May 12 07:41:21 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 15ECB106564A; Tue, 12 May 2009 07:41:21 +0000 (UTC) (envelope-from qingli@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 03FF48FC0A; Tue, 12 May 2009 07:41:21 +0000 (UTC) (envelope-from qingli@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4C7fKIu014804; Tue, 12 May 2009 07:41:20 GMT (envelope-from qingli@svn.freebsd.org) Received: (from qingli@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4C7fK8o014803; Tue, 12 May 2009 07:41:20 GMT (envelope-from qingli@svn.freebsd.org) Message-Id: <200905120741.n4C7fK8o014803@svn.freebsd.org> From: Qing Li Date: Tue, 12 May 2009 07:41:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192011 - head/sys/netinet X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 May 2009 07:41:21 -0000 Author: qingli Date: Tue May 12 07:41:20 2009 New Revision: 192011 URL: http://svn.freebsd.org/changeset/base/192011 Log: This patch adds a host route to an interface address (that is assigned to a non loopback/ppp link types) through the loopback interface. Prior to the new L2/L3 rewrite, this host route is implicitly added by the L2 code during RTM_RESOLVE of that interface address. This host route is deleted when that interface is removed. Reviewed by: kmacy Modified: head/sys/netinet/in.c Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Tue May 12 05:49:02 2009 (r192010) +++ head/sys/netinet/in.c Tue May 12 07:41:20 2009 (r192011) @@ -45,12 +45,15 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include +#include #include #include #include +#include #include #include @@ -814,6 +817,9 @@ in_ifinit(struct ifnet *ifp, struct in_i INIT_VNET_INET(ifp->if_vnet); register u_long i = ntohl(sin->sin_addr.s_addr); struct sockaddr_in oldaddr; + struct rtentry *rt = NULL; + struct rt_addrinfo info; + static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; int s = splimp(), flags = RTF_UP, error = 0; oldaddr = ia->ia_addr; @@ -900,6 +906,29 @@ in_ifinit(struct ifnet *ifp, struct in_i if ((error = in_addprefix(ia, flags)) != 0) return (error); + /* + * add a loopback route to self + */ + if (!(ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { + 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, "in_ifinit: insertion failed\n"); + } + return (error); } @@ -979,10 +1008,28 @@ in_scrubprefix(struct in_ifaddr *target) struct in_ifaddr *ia; struct in_addr prefix, mask, p; int error; + struct rt_addrinfo info; + struct sockaddr_dl null_sdl; if ((target->ia_flags & IFA_ROUTE) == 0) return (0); + if (!(target->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { + 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 = target->ia_flags | RTF_HOST | RTF_STATIC; + info.rti_info[RTAX_DST] = (struct sockaddr *)&target->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, "in_scrubprefix: deletion failed\n"); + } + if (rtinitflags(target)) prefix = target->ia_dstaddr.sin_addr; else { @@ -1136,7 +1183,6 @@ in_purgemaddrs(struct ifnet *ifp) IN_MULTI_UNLOCK(); } -#include #include #include