summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_output.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2013-04-25 12:42:09 +0000
committerglebius <glebius@FreeBSD.org>2013-04-25 12:42:09 +0000
commitdd30d87e8d858834352b3936fe169ce0163247ef (patch)
tree5c1e150c0ae9a03198c60921b88214b266d2e8a2 /sys/netinet/ip_output.c
parent882f8cda19f255874002de3051ca5fc93f8f78ac (diff)
downloadFreeBSD-src-dd30d87e8d858834352b3936fe169ce0163247ef.zip
FreeBSD-src-dd30d87e8d858834352b3936fe169ce0163247ef.tar.gz
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
Diffstat (limited to 'sys/netinet/ip_output.c')
-rw-r--r--sys/netinet/ip_output.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 120fe22..5770ae7 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -123,6 +123,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
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 *opt, struct route *ro, int flags,
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);
}
OpenPOWER on IntegriCloud