From owner-svn-src-head@freebsd.org Thu Aug 18 22:59:01 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B2BF0BBEF94; Thu, 18 Aug 2016 22:59:01 +0000 (UTC) (envelope-from rstone@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8DCCD1249; Thu, 18 Aug 2016 22:59:01 +0000 (UTC) (envelope-from rstone@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7IMx0Ir001970; Thu, 18 Aug 2016 22:59:00 GMT (envelope-from rstone@FreeBSD.org) Received: (from rstone@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7IMx0bx001967; Thu, 18 Aug 2016 22:59:00 GMT (envelope-from rstone@FreeBSD.org) Message-Id: <201608182259.u7IMx0bx001967@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rstone set sender to rstone@FreeBSD.org using -f From: Ryan Stone Date: Thu, 18 Aug 2016 22:59:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304435 - head/sys/netinet X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 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: Thu, 18 Aug 2016 22:59:01 -0000 Author: rstone Date: Thu Aug 18 22:59:00 2016 New Revision: 304435 URL: https://svnweb.freebsd.org/changeset/base/304435 Log: Don't iterate over the ifnet addr list in ip_output() For almost every packet that is transmitted through ip_output(), a call to in_broadcast() was made to decide if the destination IP was a broadcast address. in_broadcast() iterates over the ifnet's address to find a source IP matching the subnet of the destination IP, and then checks if the IP is a broadcast in that subnet. This is completely redundant as we have already performed the route lookup, so the source IP is already known. Just use that address to directly check whether the destination IP is a broadcast address or not. MFC after: 2 months Sponsored By: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D7266 Modified: head/sys/netinet/in.c head/sys/netinet/in.h head/sys/netinet/ip_output.c Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Thu Aug 18 22:01:52 2016 (r304434) +++ head/sys/netinet/in.c Thu Aug 18 22:59:00 2016 (r304435) @@ -928,6 +928,25 @@ in_ifscrub_all(void) IFNET_RUNLOCK(); } +int +in_ifaddr_broadcast(struct in_addr in, struct in_ifaddr *ia) +{ + + return ((in.s_addr == ia->ia_broadaddr.sin_addr.s_addr || + /* + * Check for old-style (host 0) broadcast, but + * taking into account that RFC 3021 obsoletes it. + */ + (ia->ia_subnetmask != IN_RFC3021_MASK && + ntohl(in.s_addr) == ia->ia_subnet)) && + /* + * Check for an all one subnetmask. These + * only exist when an interface gets a secondary + * address. + */ + ia->ia_subnetmask != (u_long)0xffffffff); +} + /* * Return 1 if the address might be a local broadcast address. */ @@ -935,37 +954,21 @@ int in_broadcast(struct in_addr in, struct ifnet *ifp) { register struct ifaddr *ifa; - u_long t; if (in.s_addr == INADDR_BROADCAST || in.s_addr == INADDR_ANY) return (1); if ((ifp->if_flags & IFF_BROADCAST) == 0) return (0); - t = ntohl(in.s_addr); /* * Look through the list of addresses for a match * with a broadcast address. */ -#define ia ((struct in_ifaddr *)ifa) TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) if (ifa->ifa_addr->sa_family == AF_INET && - (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr || - /* - * Check for old-style (host 0) broadcast, but - * taking into account that RFC 3021 obsoletes it. - */ - (ia->ia_subnetmask != IN_RFC3021_MASK && - t == ia->ia_subnet)) && - /* - * Check for an all one subnetmask. These - * only exist when an interface gets a secondary - * address. - */ - ia->ia_subnetmask != (u_long)0xffffffff) + in_ifaddr_broadcast(in, (struct in_ifaddr *)ifa)) return (1); return (0); -#undef ia } /* Modified: head/sys/netinet/in.h ============================================================================== --- head/sys/netinet/in.h Thu Aug 18 22:01:52 2016 (r304434) +++ head/sys/netinet/in.h Thu Aug 18 22:59:00 2016 (r304435) @@ -637,8 +637,10 @@ int getsourcefilter(int, uint32_t, struc #ifdef _KERNEL struct ifnet; struct mbuf; /* forward declarations for Standard C */ +struct in_ifaddr; int in_broadcast(struct in_addr, struct ifnet *); +int in_ifaddr_broadcast(struct in_addr, struct in_ifaddr *); int in_canforward(struct in_addr); int in_localaddr(struct in_addr); int in_localip(struct in_addr); Modified: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Thu Aug 18 22:01:52 2016 (r304434) +++ head/sys/netinet/ip_output.c Thu Aug 18 22:59:00 2016 (r304435) @@ -350,7 +350,7 @@ again: have_ia_ref = 1; ifp = ia->ia_ifp; ip->ip_ttl = 1; - isbroadcast = in_broadcast(dst->sin_addr, ifp); + isbroadcast = in_ifaddr_broadcast(dst->sin_addr, ia); } else if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) && imo != NULL && imo->imo_multicast_ifp != NULL) { /* @@ -404,7 +404,7 @@ again: if (rte->rt_flags & RTF_HOST) isbroadcast = (rte->rt_flags & RTF_BROADCAST); else - isbroadcast = in_broadcast(gw->sin_addr, ifp); + isbroadcast = in_ifaddr_broadcast(gw->sin_addr, ia); } /*