Skip to content

Commit

Permalink
dummynet: pfil skip for IPv4 and IPv6
Browse files Browse the repository at this point in the history
Based on a patch originally found in m0n0wall, expanded
to IPv6 and aligned with FreeBSD's IP input path.
  • Loading branch information
fichtner committed Oct 3, 2016
1 parent 2d25ce2 commit 4036f87
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sys/netinet/ip_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,16 @@ ip_input(struct mbuf *m)
goto ours;
}

if (m->m_flags & M_SKIP_PFIL) {
m->m_flags &= ~M_SKIP_PFIL;
/* Set up some basics that will be used later. */
ip = mtod(m, struct ip *);
hlen = ip->ip_hl << 2;
ip_len = ntohs(ip->ip_len);
ifp = m->m_pkthdr.rcvif;
goto reinjected;
}

IPSTAT_INC(ips_total);

if (m->m_pkthdr.len < sizeof(struct ip))
Expand Down Expand Up @@ -594,6 +604,7 @@ ip_input(struct mbuf *m)
m->m_flags &= ~M_FASTFWD_OURS;
goto ours;
}
reinjected:
if (m->m_flags & M_IP_NEXTHOP) {
if (m_tag_find(m, PACKET_TAG_IPFORWARD, NULL) != NULL) {
/*
Expand Down
1 change: 1 addition & 0 deletions sys/netinet6/in6.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ struct ip6_mtuinfo {
#define M_LOOP M_PROTO6
#define M_AUTHIPDGM M_PROTO7
#define M_RTALERT_MLD M_PROTO8
#define M_SKIP_PFIL M_PROTO12 /* skip pfil processing */

#ifdef _KERNEL
struct cmsghdr;
Expand Down
11 changes: 11 additions & 0 deletions sys/netinet6/ip6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,16 @@ ip6_input(struct mbuf *m)
goto hbhcheck;
}

if (m->m_flags & M_SKIP_PFIL) {
/*
* Dummynet reinjected this packet.
*/
m->m_flags &= ~M_SKIP_PFIL;
deliverifp = m->m_pkthdr.rcvif;
ip6 = mtod(m, struct ip6_hdr *);
goto reinjected;
}

/*
* mbuf statistics
*/
Expand Down Expand Up @@ -725,6 +735,7 @@ ip6_input(struct mbuf *m)
ours = 1;
goto hbhcheck;
}
reinjected:
if ((m->m_flags & M_IP6_NEXTHOP) &&
m_tag_find(m, PACKET_TAG_IPFORWARD, NULL) != NULL) {
/*
Expand Down
4 changes: 4 additions & 0 deletions sys/netpfil/ipfw/ip_dn_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,15 @@ dummynet_send(struct mbuf *m)
break ;

case DIR_IN :
m_tag_delete(m, tag);
m->m_flags |= M_SKIP_PFIL;
netisr_dispatch(NETISR_IP, m);
break;

#ifdef INET6
case DIR_IN | PROTO_IPV6:
m_tag_delete(m, tag);
m->m_flags |= M_SKIP_PFIL;
netisr_dispatch(NETISR_IPV6, m);
break;

Expand Down

0 comments on commit 4036f87

Please sign in to comment.