From owner-svn-src-all@FreeBSD.ORG Mon Dec 28 14:09:46 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 C18051065695; Mon, 28 Dec 2009 14:09:46 +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 A64A58FC34; Mon, 28 Dec 2009 14:09:46 +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 nBSE9kjl092226; Mon, 28 Dec 2009 14:09:46 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBSE9kUt092224; Mon, 28 Dec 2009 14:09:46 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912281409.nBSE9kUt092224@svn.freebsd.org> From: Luigi Rizzo Date: Mon, 28 Dec 2009 14:09:46 +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: r201125 - 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:09:46 -0000 Author: luigi Date: Mon Dec 28 14:09:46 2009 New Revision: 201125 URL: http://svn.freebsd.org/changeset/base/201125 Log: + remove an unused #define print_ip; + remove two unnecessary initializations in ip_output; + localize 'len'; + introduce a temporary variable n to count the number of fragments, the compiler seems unable to identify a common subexpression (written 3 times, used twice); + document some assumptions on ip_len and ip_hl Modified: head/sys/netinet/ip_output.c Modified: head/sys/netinet/ip_output.c ============================================================================== --- head/sys/netinet/ip_output.c Mon Dec 28 12:29:13 2009 (r201124) +++ head/sys/netinet/ip_output.c Mon Dec 28 14:09:46 2009 (r201125) @@ -84,12 +84,6 @@ __FBSDID("$FreeBSD$"); #include -#define print_ip(x, a, y) printf("%s %d.%d.%d.%d%s",\ - x, (ntohl(a.s_addr)>>24)&0xFF,\ - (ntohl(a.s_addr)>>16)&0xFF,\ - (ntohl(a.s_addr)>>8)&0xFF,\ - (ntohl(a.s_addr))&0xFF, y); - VNET_DEFINE(u_short, ip_id); #ifdef MBUF_STRESS_TEST @@ -108,6 +102,7 @@ extern struct protosw inetsw[]; /* * IP output. The packet in mbuf chain m contains a skeletal IP * header (with len, off, ttl, proto, tos, src, dst). + * ip_len and ip_off are in host format. * The mbuf chain containing the packet will be freed. * The mbuf opt, if present, will not be freed. * In the IP forwarding case, the packet will arrive with options already @@ -118,13 +113,14 @@ ip_output(struct mbuf *m, struct mbuf *o struct ip_moptions *imo, struct inpcb *inp) { struct ip *ip; - struct ifnet *ifp = NULL; /* keep compiler happy */ + struct ifnet *ifp; struct mbuf *m0; int hlen = sizeof (struct ip); int mtu; - int len, error = 0; + int n; /* scratchpad */ + int error = 0; int nortfree = 0; - struct sockaddr_in *dst = NULL; /* keep compiler happy */ + struct sockaddr_in *dst; struct in_ifaddr *ia = NULL; int isbroadcast, sw_csum; struct route iproute; @@ -163,10 +159,10 @@ ip_output(struct mbuf *m, struct mbuf *o } if (opt) { - len = 0; + int len = 0; m = ip_insertoptions(m, opt, &len); if (len != 0) - hlen = len; + hlen = len; /* ip->ip_hl is updated above */ } ip = mtod(m, struct ip *); @@ -187,6 +183,7 @@ ip_output(struct mbuf *m, struct mbuf *o ip->ip_id = ip_newid(); IPSTAT_INC(ips_localout); } else { + /* Header already set, fetch hlen from there */ hlen = ip->ip_hl << 2; } @@ -425,18 +422,15 @@ again: * packet or packet fragments, unless ALTQ is enabled on the given * interface in which case packetdrop should be done by queueing. */ + n = ip->ip_len / mtu + 1; /* how many fragments ? */ + if ( #ifdef ALTQ - if ((!ALTQ_IS_ENABLED(&ifp->if_snd)) && - ((ifp->if_snd.ifq_len + ip->ip_len / mtu + 1) >= - ifp->if_snd.ifq_maxlen)) -#else - if ((ifp->if_snd.ifq_len + ip->ip_len / mtu + 1) >= - ifp->if_snd.ifq_maxlen) + (!ALTQ_IS_ENABLED(&ifp->if_snd)) && #endif /* ALTQ */ - { + (ifp->if_snd.ifq_len + n) >= ifp->if_snd.ifq_maxlen ) { error = ENOBUFS; IPSTAT_INC(ips_odropped); - ifp->if_snd.ifq_drops += (ip->ip_len / ifp->if_mtu + 1); + ifp->if_snd.ifq_drops += n; goto bad; }