From: Sepherosa Ziehau Date: Thu, 20 Dec 2007 12:44:20 +0000 (+0000) Subject: In divert_packet(): X-Git-Tag: v2.0.1~1587 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/077c74e29e0c2e4bdff9b377b9867534e200f7ea In divert_packet(): - Since rcvif is checked on the main code path, we need to make sure that the mbuf contains pkthdr. - It is impossible for a mbuf that does not contain divert tag to sneak into divert_packet(); add assertion about it. - Rearrange code a little bit. --- diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index f6934a9e70..29632b264e 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_divert.c,v 1.42.2.6 2003/01/23 21:06:45 sam Exp $ - * $DragonFly: src/sys/netinet/ip_divert.c,v 1.32 2007/12/19 11:00:22 sephe Exp $ + * $DragonFly: src/sys/netinet/ip_divert.c,v 1.33 2007/12/20 12:44:20 sephe Exp $ */ #include "opt_inet.h" @@ -224,11 +224,7 @@ divert_packet(struct mbuf *m, int incoming, int port) /* Sanity check */ KASSERT(port != 0, ("%s: port=0", __func__)); - - if ((mtag = m_tag_find(m, PACKET_TAG_IPFW_DIVERT, NULL)) != NULL) - divsrc.sin_port = *(u_int16_t *)m_tag_data(mtag); - else - divsrc.sin_port = 0; + M_ASSERTPKTHDR(m); /* Assure header */ if (m->m_len < sizeof(struct ip) && @@ -236,6 +232,11 @@ divert_packet(struct mbuf *m, int incoming, int port) return; ip = mtod(m, struct ip *); + /* Locate the divert tag */ + mtag = m_tag_find(m, PACKET_TAG_IPFW_DIVERT, NULL); + KASSERT(mtag != NULL, ("%s no divert tag!", __func__)); + divsrc.sin_port = *(u_int16_t *)m_tag_data(mtag); + /* * Record receive interface address, if any. * But only for incoming packets. @@ -244,9 +245,6 @@ divert_packet(struct mbuf *m, int incoming, int port) if (incoming) { struct ifaddr *ifa; - /* Sanity check */ - KASSERT((m->m_flags & M_PKTHDR), ("%s: !PKTHDR", __func__)); - /* Find IP address for receive interface */ TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrhead, ifa_link) { if (ifa->ifa_addr == NULL)