Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Dec 2009 14:09:46 +0000 (UTC)
From:      Luigi Rizzo <luigi@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r201125 - head/sys/netinet
Message-ID:  <200912281409.nBSE9kUt092224@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <security/mac/mac_framework.h>
 
-#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;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912281409.nBSE9kUt092224>