From owner-svn-src-head@FreeBSD.ORG Mon Jul 27 17:08:09 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB5541065670; Mon, 27 Jul 2009 17:08:08 +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 BEA238FC0A; Mon, 27 Jul 2009 17:08:08 +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 n6RH87YT006778; Mon, 27 Jul 2009 17:08:07 GMT (envelope-from qingli@svn.freebsd.org) Received: (from qingli@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6RH87PJ006773; Mon, 27 Jul 2009 17:08:07 GMT (envelope-from qingli@svn.freebsd.org) Message-Id: <200907271708.n6RH87PJ006773@svn.freebsd.org> From: Qing Li Date: Mon, 27 Jul 2009 17:08:07 +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: r195914 - in head/sys: net netinet netinet6 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jul 2009 17:08:09 -0000 Author: qingli Date: Mon Jul 27 17:08:06 2009 New Revision: 195914 URL: http://svn.freebsd.org/changeset/base/195914 Log: This patch does the following: - Allow loopback route to be installed for address assigned to interface of IFF_POINTOPOINT type. - Install loopback route for an IPv4 interface addreess when the "useloopback" sysctl variable is enabled. Similarly, install loopback route for an IPv6 interface address when the sysctl variable "nd6_useloopback" is enabled. Deleting loopback routes for interface addresses is unconditional in case these sysctl variables were disabled after an interface address has been assigned. Reviewed by: bz Approved by: re Modified: head/sys/net/if_var.h head/sys/netinet/if_ether.c head/sys/netinet/in.c head/sys/netinet6/in6.c Modified: head/sys/net/if_var.h ============================================================================== --- head/sys/net/if_var.h Mon Jul 27 16:11:44 2009 (r195913) +++ head/sys/net/if_var.h Mon Jul 27 17:08:06 2009 (r195914) @@ -784,11 +784,13 @@ VNET_DECLARE(struct ifnethead, ifnet); VNET_DECLARE(struct ifgrouphead, ifg_head); VNET_DECLARE(int, if_index); VNET_DECLARE(struct ifnet *, loif); /* first loopback interface */ +VNET_DECLARE(int, useloopback); #define V_ifnet VNET(ifnet) #define V_ifg_head VNET(ifg_head) #define V_if_index VNET(if_index) #define V_loif VNET(loif) +#define V_useloopback VNET(useloopback) extern int ifqmaxlen; Modified: head/sys/netinet/if_ether.c ============================================================================== --- head/sys/netinet/if_ether.c Mon Jul 27 16:11:44 2009 (r195913) +++ head/sys/netinet/if_ether.c Mon Jul 27 17:08:06 2009 (r195914) @@ -81,17 +81,17 @@ __FBSDID("$FreeBSD$"); SYSCTL_DECL(_net_link_ether); SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, ""); +VNET_DEFINE(int, useloopback) = 1; /* use loopback interface for + * local traffic */ + /* timer values */ static VNET_DEFINE(int, arpt_keep) = (20*60); /* once resolved, good for 20 * minutes */ static VNET_DEFINE(int, arp_maxtries) = 5; -static VNET_DEFINE(int, useloopback) = 1; /* use loopback interface for - * local traffic */ static VNET_DEFINE(int, arp_proxyall); #define V_arpt_keep VNET(arpt_keep) #define V_arp_maxtries VNET(arp_maxtries) -#define V_useloopback VNET(useloopback) #define V_arp_proxyall VNET(arp_proxyall) SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Mon Jul 27 16:11:44 2009 (r195913) +++ head/sys/netinet/in.c Mon Jul 27 17:08:06 2009 (r195914) @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -918,7 +919,7 @@ in_ifinit(struct ifnet *ifp, struct in_i /* * add a loopback route to self */ - if (!(ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { + if (V_useloopback && !(ifp->if_flags & IFF_LOOPBACK)) { bzero(&info, sizeof(info)); info.rti_ifp = V_loif; info.rti_flags = ia->ia_flags | RTF_HOST | RTF_STATIC; @@ -1027,8 +1028,18 @@ in_scrubprefix(struct in_ifaddr *target) if ((target->ia_flags & IFA_ROUTE) == 0) return (0); + /* + * Remove the loopback route to the interface address. + * The "useloopback" setting is not consulted because if the + * user configures an interface address, turns off this + * setting, and then tries to delete that interface address, + * checking the current setting of "useloopback" would leave + * that interface address loopback route untouched, which + * would be wrong. Therefore the interface address loopback route + * deletion is unconditional. + */ if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) && - !(target->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { + !(target->ia_ifp->if_flags & IFF_LOOPBACK)) { bzero(&null_sdl, sizeof(null_sdl)); null_sdl.sdl_len = sizeof(null_sdl); null_sdl.sdl_family = AF_LINK; Modified: head/sys/netinet6/in6.c ============================================================================== --- head/sys/netinet6/in6.c Mon Jul 27 16:11:44 2009 (r195913) +++ head/sys/netinet6/in6.c Mon Jul 27 17:08:06 2009 (r195914) @@ -1191,7 +1191,11 @@ in6_purgeaddr(struct ifaddr *ifa) ifa_ref(ifa0); IF_ADDR_UNLOCK(ifp); - if (!(ia->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { + /* + * Remove the loopback route to the interface address. + * The check for the current setting of "nd6_useloopback" is not needed. + */ + if (!(ia->ia_ifp->if_flags & IFF_LOOPBACK)) { struct rt_addrinfo info; struct sockaddr_dl null_sdl; @@ -1773,7 +1777,7 @@ in6_ifinit(struct ifnet *ifp, struct in6 /* * add a loopback route to self */ - if (!(ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) { + if (V_nd6_useloopback && !(ifp->if_flags & IFF_LOOPBACK)) { struct rt_addrinfo info; struct rtentry *rt = NULL; static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};