From owner-svn-src-all@FreeBSD.ORG Mon Dec 28 14:48:32 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 97C29106568D; Mon, 28 Dec 2009 14:48:32 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 862F98FC15; Mon, 28 Dec 2009 14:48:32 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBSEmWRZ093353; Mon, 28 Dec 2009 14:48:32 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBSEmWmB093351; Mon, 28 Dec 2009 14:48:32 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912281448.nBSEmWmB093351@svn.freebsd.org> From: Luigi Rizzo Date: Mon, 28 Dec 2009 14:48:32 +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: r201131 - 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: Mon, 28 Dec 2009 14:48:32 -0000 Author: luigi Date: Mon Dec 28 14:48:32 2009 New Revision: 201131 URL: http://svn.freebsd.org/changeset/base/201131 Log: introduce a local variable rte acting as a cache of ro->ro_rt within ip_output, achieving (in random order of importance): - a reduction of the number of 'r's in the source code; - improved legibility; - a reduction of 64 bytes in the .text Modified: head/sys/netinet/ip_output.c Modified: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Mon Dec 28 14:47:25 2009 (r201130) +++ head/sys/netinet/ip_output.c Mon Dec 28 14:48:32 2009 (r201131) @@ -124,6 +124,7 @@ ip_output(struct mbuf *m, struct mbuf *o struct in_ifaddr *ia = NULL; int isbroadcast, sw_csum; struct route iproute; + struct rtentry *rte; /* cache for ro->ro_rt */ struct in_addr odst; #ifdef IPFIREWALL_FORWARD struct m_tag *fwd_tag = NULL; @@ -196,18 +197,19 @@ again: * The address family should also be checked in case of sharing the * cache with IPv6. */ - if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 || + rte = ro->ro_rt; + if (rte && ((rte->rt_flags & RTF_UP) == 0 || dst->sin_family != AF_INET || dst->sin_addr.s_addr != ip->ip_dst.s_addr)) { if (!nortfree) - RTFREE(ro->ro_rt); - ro->ro_rt = (struct rtentry *)NULL; + RTFREE(rte); + rte = ro->ro_rt = (struct rtentry *)NULL; ro->ro_lle = (struct llentry *)NULL; } #ifdef IPFIREWALL_FORWARD - if (ro->ro_rt == NULL && fwd_tag == NULL) { + if (rte == NULL && fwd_tag == NULL) { #else - if (ro->ro_rt == NULL) { + if (rte == NULL) { #endif bzero(dst, sizeof(*dst)); dst->sin_family = AF_INET; @@ -257,7 +259,7 @@ again: * as this is probably required in all cases for correct * operation (as it is for ARP). */ - if (ro->ro_rt == NULL) + if (rte == NULL) { #ifdef RADIX_MPATH rtalloc_mpath_fib(ro, ntohl(ip->ip_src.s_addr ^ ip->ip_dst.s_addr), @@ -266,7 +268,9 @@ again: in_rtalloc_ign(ro, 0, inp ? inp->inp_inc.inc_fibnum : M_GETFIB(m)); #endif - if (ro->ro_rt == NULL) { + rte = ro->ro_rt; + } + if (rte == NULL) { #ifdef IPSEC /* * There is no route for this packet, but it is @@ -280,14 +284,14 @@ again: error = EHOSTUNREACH; goto bad; } - ia = ifatoia(ro->ro_rt->rt_ifa); + ia = ifatoia(rte->rt_ifa); ifa_ref(&ia->ia_ifa); - ifp = ro->ro_rt->rt_ifp; - ro->ro_rt->rt_rmx.rmx_pksent++; - if (ro->ro_rt->rt_flags & RTF_GATEWAY) - dst = (struct sockaddr_in *)ro->ro_rt->rt_gateway; - if (ro->ro_rt->rt_flags & RTF_HOST) - isbroadcast = (ro->ro_rt->rt_flags & RTF_BROADCAST); + ifp = rte->rt_ifp; + rte->rt_rmx.rmx_pksent++; + if (rte->rt_flags & RTF_GATEWAY) + dst = (struct sockaddr_in *)rte->rt_gateway; + if (rte->rt_flags & RTF_HOST) + isbroadcast = (rte->rt_flags & RTF_BROADCAST); else isbroadcast = in_broadcast(dst->sin_addr, ifp); } @@ -295,7 +299,7 @@ again: * Calculate MTU. If we have a route that is up, use that, * otherwise use the interface's MTU. */ - if (ro->ro_rt != NULL && (ro->ro_rt->rt_flags & (RTF_UP|RTF_HOST))) { + if (rte != NULL && (rte->rt_flags & (RTF_UP|RTF_HOST))) { /* * This case can happen if the user changed the MTU * of an interface after enabling IP on it. Because @@ -303,9 +307,9 @@ again: * them, there is no way for one to update all its * routes when the MTU is changed. */ - if (ro->ro_rt->rt_rmx.rmx_mtu > ifp->if_mtu) - ro->ro_rt->rt_rmx.rmx_mtu = ifp->if_mtu; - mtu = ro->ro_rt->rt_rmx.rmx_mtu; + if (rte->rt_rmx.rmx_mtu > ifp->if_mtu) + rte->rt_rmx.rmx_mtu = ifp->if_mtu; + mtu = rte->rt_rmx.rmx_mtu; } else { mtu = ifp->if_mtu; }