svn commit: r249894 - head/sys/netinet

Gleb Smirnoff glebius at FreeBSD.org
Thu Apr 25 12:42:09 UTC 2013


Author: glebius
Date: Thu Apr 25 12:42:09 2013
New Revision: 249894
URL: http://svnweb.freebsd.org/changeset/base/249894

Log:
  Introduce a pointer to const variable gw, which points either at the
  same place as dst, or to the sockaddr in the routing table.
  
  The const constraint of gw makes us safe from modifing routing table
  accidentially. And "onstantness" of dst allows us to remove several
  bandaids, when we switched it back at &ro->ro_dst, now it always
  points there.
  
  Reviewed by:	rrs

Modified:
  head/sys/netinet/ip_output.c

Modified: head/sys/netinet/ip_output.c
==============================================================================
--- head/sys/netinet/ip_output.c	Thu Apr 25 12:05:17 2013	(r249893)
+++ head/sys/netinet/ip_output.c	Thu Apr 25 12:42:09 2013	(r249894)
@@ -123,6 +123,7 @@ ip_output(struct mbuf *m, struct mbuf *o
 	int n;	/* scratchpad */
 	int error = 0;
 	struct sockaddr_in *dst;
+	const struct sockaddr_in *gw;
 	struct in_ifaddr *ia;
 	int isbroadcast;
 	uint16_t ip_len, ip_off;
@@ -196,8 +197,8 @@ ip_output(struct mbuf *m, struct mbuf *o
 		hlen = ip->ip_hl << 2;
 	}
 
+	gw = dst = (struct sockaddr_in *)&ro->ro_dst;
 again:
-	dst = (struct sockaddr_in *)&ro->ro_dst;
 	ia = NULL;
 	/*
 	 * If there is a cached route,
@@ -297,11 +298,11 @@ again:
 		ifp = rte->rt_ifp;
 		rte->rt_rmx.rmx_pksent++;
 		if (rte->rt_flags & RTF_GATEWAY)
-			dst = (struct sockaddr_in *)rte->rt_gateway;
+			gw = (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);
+			isbroadcast = in_broadcast(gw->sin_addr, ifp);
 	}
 	/*
 	 * Calculate MTU.  If we have a route that is up, use that,
@@ -327,12 +328,6 @@ again:
 	if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
 		m->m_flags |= M_MCAST;
 		/*
-		 * IP destination address is multicast.  Make sure "dst"
-		 * still points to the address in "ro".  (It may have been
-		 * changed to point to a gateway address, above.)
-		 */
-		dst = (struct sockaddr_in *)&ro->ro_dst;
-		/*
 		 * See if the caller provided any multicast options
 		 */
 		if (imo != NULL) {
@@ -559,7 +554,6 @@ sendit:
 	/* Or forward to some other address? */
 	if ((m->m_flags & M_IP_NEXTHOP) &&
 	    (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) {
-		dst = (struct sockaddr_in *)&ro->ro_dst;
 		bcopy((fwd_tag+1), dst, sizeof(struct sockaddr_in));
 		m->m_flags |= M_SKIP_FIREWALL;
 		m->m_flags &= ~M_IP_NEXTHOP;
@@ -628,8 +622,7 @@ passout:
 		 * to avoid confusing lower layers.
 		 */
 		m->m_flags &= ~(M_PROTOFLAGS);
-		error = (*ifp->if_output)(ifp, m,
-		    		(struct sockaddr *)dst, ro);
+		error = (*ifp->if_output)(ifp, m, (struct sockaddr *)gw, ro);
 		goto done;
 	}
 
@@ -663,7 +656,7 @@ passout:
 			m->m_flags &= ~(M_PROTOFLAGS);
 
 			error = (*ifp->if_output)(ifp, m,
-			    (struct sockaddr *)dst, ro);
+			    (struct sockaddr *)gw, ro);
 		} else
 			m_freem(m);
 	}


More information about the svn-src-head mailing list