-/*
- * Copyright (c) 2007-2016 Apple Inc. All rights reserved.
+/*
+ * Copyright (c) 2007-2018 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <machine/endian.h>
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/mbuf.h>
#include <sys/filio.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <net/if_ether.h>
#include <net/ethernet.h>
#include <net/flowhash.h>
+#include <net/nat464_utils.h>
#include <net/pfvar.h>
#include <net/if_pflog.h>
struct pf_palist pf_pabuf;
struct pf_status pf_status;
-#if PF_ALTQ
-struct pf_altqqueue pf_altqs[2];
-struct pf_altqqueue *pf_altqs_active;
-struct pf_altqqueue *pf_altqs_inactive;
-u_int32_t ticket_altqs_active;
-u_int32_t ticket_altqs_inactive;
-int altqs_inactive_open;
-#endif /* PF_ALTQ */
u_int32_t ticket_pabuf;
static MD5_CTX pf_tcp_secret_ctx;
struct pool pf_src_tree_pl, pf_rule_pl, pf_pooladdr_pl;
struct pool pf_state_pl, pf_state_key_pl;
-#if PF_ALTQ
-struct pool pf_altq_pl;
-#endif /* PF_ALTQ */
typedef void (*hook_fn_t)(void *);
static void pf_add_threshold(struct pf_threshold *);
static int pf_check_threshold(struct pf_threshold *);
-static void pf_change_ap(int, struct mbuf *, struct pf_addr *,
+static void pf_change_ap(int, pbuf_t *, struct pf_addr *,
u_int16_t *, u_int16_t *, u_int16_t *,
struct pf_addr *, u_int16_t, u_int8_t, sa_family_t,
sa_family_t, int);
-static int pf_modulate_sack(struct mbuf *, int, struct pf_pdesc *,
+static int pf_modulate_sack(pbuf_t *, int, struct pf_pdesc *,
struct tcphdr *, struct pf_state_peer *);
#if INET6
static void pf_change_a6(struct pf_addr *, u_int16_t *,
u_int16_t, u_int16_t, u_int32_t, u_int32_t,
u_int8_t, u_int16_t, u_int16_t, u_int8_t, int,
u_int16_t, struct ether_header *, struct ifnet *);
-static void pf_send_icmp(struct mbuf *, u_int8_t, u_int8_t,
+static void pf_send_icmp(pbuf_t *, u_int8_t, u_int8_t,
sa_family_t, struct pf_rule *);
-static struct pf_rule *pf_match_translation(struct pf_pdesc *, struct mbuf *,
+static struct pf_rule *pf_match_translation(struct pf_pdesc *, pbuf_t *,
int, int, struct pfi_kif *, struct pf_addr *,
union pf_state_xport *, struct pf_addr *,
union pf_state_xport *, int);
static struct pf_rule *pf_get_translation_aux(struct pf_pdesc *,
- struct mbuf *, int, int, struct pfi_kif *,
+ pbuf_t *, int, int, struct pfi_kif *,
struct pf_src_node **, struct pf_addr *,
union pf_state_xport *, struct pf_addr *,
- union pf_state_xport *, union pf_state_xport *);
+ union pf_state_xport *, union pf_state_xport *
+ );
static void pf_attach_state(struct pf_state_key *,
struct pf_state *, int);
static void pf_detach_state(struct pf_state *, int);
static u_int32_t pf_tcp_iss(struct pf_pdesc *);
static int pf_test_rule(struct pf_rule **, struct pf_state **,
- int, struct pfi_kif *, struct mbuf *, int,
+ int, struct pfi_kif *, pbuf_t *, int,
void *, struct pf_pdesc *, struct pf_rule **,
struct pf_ruleset **, struct ifqueue *);
#if DUMMYNET
static int pf_test_dummynet(struct pf_rule **, int,
- struct pfi_kif *, struct mbuf **,
+ struct pfi_kif *, pbuf_t **,
struct pf_pdesc *, struct ip_fw_args *);
#endif /* DUMMYNET */
static int pf_test_fragment(struct pf_rule **, int,
- struct pfi_kif *, struct mbuf *, void *,
+ struct pfi_kif *, pbuf_t *, void *,
struct pf_pdesc *, struct pf_rule **,
struct pf_ruleset **);
static int pf_test_state_tcp(struct pf_state **, int,
- struct pfi_kif *, struct mbuf *, int,
+ struct pfi_kif *, pbuf_t *, int,
void *, struct pf_pdesc *, u_short *);
static int pf_test_state_udp(struct pf_state **, int,
- struct pfi_kif *, struct mbuf *, int,
+ struct pfi_kif *, pbuf_t *, int,
void *, struct pf_pdesc *, u_short *);
static int pf_test_state_icmp(struct pf_state **, int,
- struct pfi_kif *, struct mbuf *, int,
+ struct pfi_kif *, pbuf_t *, int,
void *, struct pf_pdesc *, u_short *);
static int pf_test_state_other(struct pf_state **, int,
struct pfi_kif *, struct pf_pdesc *);
-static int pf_match_tag(struct mbuf *, struct pf_rule *,
+static int pf_match_tag(struct pf_rule *,
struct pf_mtag *, int *);
static void pf_hash(struct pf_addr *, struct pf_addr *,
struct pf_poolhashkey *, sa_family_t);
struct pf_rule *, struct pf_addr *,
union pf_state_xport *, struct pf_addr *,
union pf_state_xport *, struct pf_addr *,
- union pf_state_xport *, struct pf_src_node **);
-static void pf_route(struct mbuf **, struct pf_rule *, int,
+ union pf_state_xport *, struct pf_src_node **
+ );
+static void pf_route(pbuf_t **, struct pf_rule *, int,
struct ifnet *, struct pf_state *,
struct pf_pdesc *);
#if INET6
-static void pf_route6(struct mbuf **, struct pf_rule *, int,
+static void pf_route6(pbuf_t **, struct pf_rule *, int,
struct ifnet *, struct pf_state *,
struct pf_pdesc *);
#endif /* INET6 */
-static u_int8_t pf_get_wscale(struct mbuf *, int, u_int16_t,
+static u_int8_t pf_get_wscale(pbuf_t *, int, u_int16_t,
sa_family_t);
-static u_int16_t pf_get_mss(struct mbuf *, int, u_int16_t,
+static u_int16_t pf_get_mss(pbuf_t *, int, u_int16_t,
sa_family_t);
static u_int16_t pf_calc_mss(struct pf_addr *, sa_family_t,
u_int16_t);
static void pf_set_rt_ifp(struct pf_state *,
struct pf_addr *, sa_family_t af);
-static int pf_check_proto_cksum(struct mbuf *, int, int,
+static int pf_check_proto_cksum(pbuf_t *, int, int,
u_int8_t, sa_family_t);
static int pf_addr_wrap_neq(struct pf_addr_wrap *,
struct pf_addr_wrap *);
{ &pfr_kentry_pl, PFR_KENTRY_HIWAT },
};
-struct mbuf *
-pf_lazy_makewritable(struct pf_pdesc *pd, struct mbuf *m, int len)
+void *
+pf_lazy_makewritable(struct pf_pdesc *pd, pbuf_t *pbuf, int len)
{
+ void *p;
+
if (pd->lmw < 0)
- return (0);
+ return (NULL);
- VERIFY(m == pd->mp);
+ VERIFY(pbuf == pd->mp);
+ p = pbuf->pb_data;
if (len > pd->lmw) {
- if (m_makewritable(&m, 0, len, M_DONTWAIT))
+ if ((p = pbuf_ensure_writable(pbuf, len)) == NULL)
len = -1;
pd->lmw = len;
- if (len >= 0 && m != pd->mp) {
- pd->mp = m;
- pd->pf_mtag = pf_find_mtag(m);
+ if (len >= 0) {
+ pd->pf_mtag = pf_find_mtag_pbuf(pbuf);
switch (pd->af) {
case AF_INET: {
- struct ip *h = mtod(m, struct ip *);
- pd->src = (struct pf_addr *)&h->ip_src;
- pd->dst = (struct pf_addr *)&h->ip_dst;
+ struct ip *h = p;
+ pd->src = (struct pf_addr *)(uintptr_t)&h->ip_src;
+ pd->dst = (struct pf_addr *)(uintptr_t)&h->ip_dst;
pd->ip_sum = &h->ip_sum;
break;
}
#if INET6
case AF_INET6: {
- struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
- pd->src = (struct pf_addr *)&h->ip6_src;
- pd->dst = (struct pf_addr *)&h->ip6_dst;
+ struct ip6_hdr *h = p;
+ pd->src = (struct pf_addr *)(uintptr_t)&h->ip6_src;
+ pd->dst = (struct pf_addr *)(uintptr_t)&h->ip6_dst;
break;
}
#endif /* INET6 */
}
}
- return (len < 0 ? 0 : m);
+ return (len < 0 ? NULL : p);
}
static const int *
#if INET
case AF_INET:
p.pfra_net = 32;
- p.pfra_ip4addr = (*state)->src_node->addr.v4;
+ p.pfra_ip4addr = (*state)->src_node->addr.v4addr;
break;
#endif /* INET */
#if INET6
case AF_INET6:
p.pfra_net = 128;
- p.pfra_ip6addr = (*state)->src_node->addr.v6;
+ p.pfra_ip6addr = (*state)->src_node->addr.v6addr;
break;
#endif /* INET6 */
}
u_int32_t end;
u_int32_t states;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
/* handle all PFTM_* > PFTM_MAX here */
if (state->timeout == PFTM_PURGE)
{
struct pf_src_node *cur, *next;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
for (cur = RB_MIN(pf_src_tree, &tree_src_tracking); cur; cur = next) {
next = RB_NEXT(pf_src_tree, &tree_src_tracking, cur);
{
u_int32_t t;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (s->src_node != NULL) {
if (s->src.tcp_est) {
void
pf_unlink_state(struct pf_state *cur)
{
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (cur->src.state == PF_TCPS_PROXY_DST) {
pf_send_tcp(cur->rule.ptr, cur->state_key->af_lan,
void
pf_free_state(struct pf_state *cur)
{
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
#if NPFSYNC
if (pfsyncif != NULL &&
(pfsyncif->sc_bulk_send_next == cur ||
static struct pf_state *cur = NULL;
struct pf_state *next;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
while (maxcheck--) {
/* wrap to start of list when we hit the end */
int
pf_tbladdr_setup(struct pf_ruleset *rs, struct pf_addr_wrap *aw)
{
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (aw->type != PF_ADDR_TABLE)
return (0);
void
pf_tbladdr_remove(struct pf_addr_wrap *aw)
{
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (aw->type != PF_ADDR_TABLE || aw->p.tbl == NULL)
return;
{
struct pfr_ktable *kt = aw->p.tbl;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (aw->type != PF_ADDR_TABLE || kt == NULL)
return;
u_int16_t
pf_cksum_fixup(u_int16_t cksum, u_int16_t old, u_int16_t new, u_int8_t udp)
{
- u_int32_t l;
-
- if (udp && !cksum)
- return (0);
- l = cksum + old - new;
- l = (l >> 16) + (l & 0xffff);
- l = l & 0xffff;
- if (udp && !l)
- return (0xffff);
- return (l);
+ return (nat464_cksum_fixup(cksum, old, new, udp));
}
/*
* only the checksum is recalculated & updated.
*/
static void
-pf_change_ap(int dir, struct mbuf *m, struct pf_addr *a, u_int16_t *p,
+pf_change_ap(int dir, pbuf_t *pbuf, struct pf_addr *a, u_int16_t *p,
u_int16_t *ic, u_int16_t *pc, struct pf_addr *an, u_int16_t pn,
u_int8_t u, sa_family_t af, sa_family_t afn, int ua)
{
ao.addr16[0], an->addr16[0], 0),
ao.addr16[1], an->addr16[1], 0);
*p = pn;
- /*
- * If the packet is originated from an ALG on the NAT gateway
- * (source address is loopback or local), in which case the
- * TCP/UDP checksum field contains the pseudo header checksum
- * that's not yet complemented. A packet generated locally
- * will have UDP/TCP CSUM flag set (gets set in protocol
- * output).
- */
- if (dir == PF_OUT && m != NULL &&
- (m->m_flags & M_PKTHDR) &&
- (m->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))) {
- /* Pseudo-header checksum does not include ports */
+ /*
+ * If the packet is originated from an ALG on the NAT gateway
+ * (source address is loopback or local), in which case the
+ * TCP/UDP checksum field contains the pseudo header checksum
+ * that's not yet complemented.
+ * In that case we do not need to fixup the checksum for port
+ * translation as the pseudo header checksum doesn't include ports.
+ *
+ * A packet generated locally will have UDP/TCP CSUM flag
+ * set (gets set in protocol output).
+ *
+ * It should be noted that the fixup doesn't do anything if the
+ * checksum is 0.
+ */
+ if (dir == PF_OUT && pbuf != NULL &&
+ (*pbuf->pb_csum_flags & (CSUM_TCP | CSUM_UDP))) {
+ /* Pseudo-header checksum does not include ports */
*pc = ~pf_cksum_fixup(pf_cksum_fixup(~*pc,
ao.addr16[0], an->addr16[0], u),
ao.addr16[1], an->addr16[1], u);
* will have UDP/TCP CSUM flag set (gets set in protocol
* output).
*/
- if (dir == PF_OUT && m != NULL &&
- (m->m_flags & M_PKTHDR) &&
- (m->m_pkthdr.csum_flags & (CSUM_TCPIPV6 |
+ if (dir == PF_OUT && pbuf != NULL &&
+ (*pbuf->pb_csum_flags & (CSUM_TCPIPV6 |
CSUM_UDPIPV6))) {
/* Pseudo-header checksum does not include ports */
*pc =
case AF_INET:
switch (afn) {
case AF_INET:
- pf_change_a(a, c, an->v4.s_addr, u);
+ pf_change_a(a, c, an->v4addr.s_addr, u);
break;
case AF_INET6:
*c = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(
* (credits to Krzysztof Pfaff for report and patch)
*/
static int
-pf_modulate_sack(struct mbuf *m, int off, struct pf_pdesc *pd,
+pf_modulate_sack(pbuf_t *pbuf, int off, struct pf_pdesc *pd,
struct tcphdr *th, struct pf_state_peer *dst)
{
int hlen = (th->th_off << 2) - sizeof (*th), thoptlen = hlen;
#define TCPOLEN_SACKLEN (TCPOLEN_SACK + 2)
if (hlen < TCPOLEN_SACKLEN ||
- !pf_pull_hdr(m, off + sizeof (*th), opts, hlen, NULL, NULL, pd->af))
+ !pf_pull_hdr(pbuf, off + sizeof (*th), opts, hlen, NULL, NULL, pd->af))
return (0);
while (hlen >= TCPOLEN_SACKLEN) {
}
if (copyback) {
- m = pf_lazy_makewritable(pd, m, copyback);
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf, copyback) == NULL)
return (-1);
- m_copyback(m, off + sizeof (*th), thoptlen, opts);
+ pbuf_copy_back(pbuf, off + sizeof (*th), thoptlen, opts);
}
return (copyback);
}
+/*
+ * XXX
+ *
+ * The following functions (pf_send_tcp and pf_send_icmp) are somewhat
+ * special in that they originate "spurious" packets rather than
+ * filter/NAT existing packets. As such, they're not a great fit for
+ * the 'pbuf' shim, which assumes the underlying packet buffers are
+ * allocated elsewhere.
+ *
+ * Since these functions are rarely used, we'll carry on allocating mbufs
+ * and passing them to the IP stack for eventual routing.
+ */
static void
pf_send_tcp(const struct pf_rule *r, sa_family_t af,
const struct pf_addr *saddr, const struct pf_addr *daddr,
if (m == NULL)
return;
- if ((pf_mtag = pf_get_mtag(m)) == NULL) {
- m_free(m);
+ if ((pf_mtag = pf_get_mtag(m)) == NULL)
return;
- }
if (tag)
pf_mtag->pftag_flags |= PF_TAG_GENERATED;
if (r != NULL && PF_RTABLEID_IS_VALID(r->rtableid))
pf_mtag->pftag_rtableid = r->rtableid;
-#if PF_ALTQ
- if (altq_allowed && r != NULL && r->qid)
- pf_mtag->pftag_qid = r->qid;
-#endif /* PF_ALTQ */
-
#if PF_ECN
/* add hints for ecn */
pf_mtag->pftag_hdr = mtod(m, struct ip *);
/* IP header fields included in the TCP checksum */
h->ip_p = IPPROTO_TCP;
h->ip_len = htons(tlen);
- h->ip_src.s_addr = saddr->v4.s_addr;
- h->ip_dst.s_addr = daddr->v4.s_addr;
+ h->ip_src.s_addr = saddr->v4addr.s_addr;
+ h->ip_dst.s_addr = daddr->v4addr.s_addr;
th = (struct tcphdr *)(void *)((caddr_t)h + sizeof (struct ip));
break;
/* IP header fields included in the TCP checksum */
h6->ip6_nxt = IPPROTO_TCP;
h6->ip6_plen = htons(tlen);
- memcpy(&h6->ip6_src, &saddr->v6, sizeof (struct in6_addr));
- memcpy(&h6->ip6_dst, &daddr->v6, sizeof (struct in6_addr));
+ memcpy(&h6->ip6_src, &saddr->v6addr, sizeof (struct in6_addr));
+ memcpy(&h6->ip6_dst, &daddr->v6addr, sizeof (struct in6_addr));
th = (struct tcphdr *)(void *)
((caddr_t)h6 + sizeof (struct ip6_hdr));
}
static void
-pf_send_icmp(struct mbuf *m, u_int8_t type, u_int8_t code, sa_family_t af,
+pf_send_icmp(pbuf_t *pbuf, u_int8_t type, u_int8_t code, sa_family_t af,
struct pf_rule *r)
{
struct mbuf *m0;
struct pf_mtag *pf_mtag;
- m0 = m_copy(m, 0, M_COPYALL);
+ m0 = pbuf_clone_to_mbuf(pbuf);
if (m0 == NULL)
return;
if (PF_RTABLEID_IS_VALID(r->rtableid))
pf_mtag->pftag_rtableid = r->rtableid;
-#if PF_ALTQ
- if (altq_allowed && r->qid)
- pf_mtag->pftag_qid = r->qid;
-#endif /* PF_ALTQ */
-
#if PF_ECN
/* add hints for ecn */
pf_mtag->pftag_hdr = mtod(m0, struct ip *);
}
static int
-pf_match_tag(struct mbuf *m, struct pf_rule *r, struct pf_mtag *pf_mtag,
+pf_match_tag(struct pf_rule *r, struct pf_mtag *pf_mtag,
int *tag)
{
-#pragma unused(m)
if (*tag == -1)
*tag = pf_mtag->pftag_tag;
}
int
-pf_tag_packet(struct mbuf *m, struct pf_mtag *pf_mtag, int tag,
+pf_tag_packet(pbuf_t *pbuf, struct pf_mtag *pf_mtag, int tag,
unsigned int rtableid, struct pf_pdesc *pd)
{
if (tag <= 0 && !PF_RTABLEID_IS_VALID(rtableid) &&
(pd == NULL || !(pd->pktflags & PKTF_FLOW_ID)))
return (0);
- if (pf_mtag == NULL && (pf_mtag = pf_get_mtag(m)) == NULL)
+ if (pf_mtag == NULL && (pf_mtag = pf_get_mtag_pbuf(pbuf)) == NULL)
return (1);
if (tag > 0)
if (PF_RTABLEID_IS_VALID(rtableid))
pf_mtag->pftag_rtableid = rtableid;
if (pd != NULL && (pd->pktflags & PKTF_FLOW_ID)) {
- m->m_pkthdr.pkt_flowsrc = pd->flowsrc;
- m->m_pkthdr.pkt_flowid = pd->flowhash;
- m->m_pkthdr.pkt_flags |= pd->pktflags;
- m->m_pkthdr.pkt_proto = pd->proto;
+ *pbuf->pb_flowsrc = pd->flowsrc;
+ *pbuf->pb_flowid = pd->flowhash;
+ *pbuf->pb_flags |= pd->pktflags;
+ *pbuf->pb_proto = pd->proto;
}
return (0);
if (f->child->match ||
(match != NULL && *match)) {
f->r->anchor->match = 1;
- *match = 0;
+ if (match)
+ *match = 0;
}
f->child = RB_NEXT(pf_anchor_node, f->parent, f->child);
if (f->child != NULL) {
pf_get_sport(struct pf_pdesc *pd, struct pfi_kif *kif, struct pf_rule *r,
struct pf_addr *saddr, union pf_state_xport *sxport, struct pf_addr *daddr,
union pf_state_xport *dxport, struct pf_addr *naddr,
- union pf_state_xport *nxport, struct pf_src_node **sn)
+ union pf_state_xport *nxport, struct pf_src_node **sn
+ )
{
#pragma unused(kif)
struct pf_state_key_cmp key;
return (0);
} else if (low == 0 && high == 0) {
key.gwy.xport = *nxport;
- if (pf_find_state_all(&key, PF_IN, NULL) == NULL)
+ if (pf_find_state_all(&key, PF_IN, NULL) == NULL
+ ) {
return (0);
+ }
} else if (low == high) {
key.gwy.xport.port = htons(low);
- if (pf_find_state_all(&key, PF_IN, NULL) == NULL) {
+ if (pf_find_state_all(&key, PF_IN, NULL) == NULL
+ ) {
nxport->port = htons(low);
return (0);
}
/* low <= cut <= high */
for (tmp = cut; tmp <= high; ++(tmp)) {
key.gwy.xport.port = htons(tmp);
- if (pf_find_state_all(&key, PF_IN, NULL) ==
- NULL) {
+ if (pf_find_state_all(&key, PF_IN, NULL) == NULL
+ ) {
nxport->port = htons(tmp);
return (0);
}
}
for (tmp = cut - 1; tmp >= low; --(tmp)) {
key.gwy.xport.port = htons(tmp);
- if (pf_find_state_all(&key, PF_IN, NULL) ==
- NULL) {
+ if (pf_find_state_all(&key, PF_IN, NULL) == NULL
+ ) {
nxport->port = htons(tmp);
return (0);
}
}
static struct pf_rule *
-pf_match_translation(struct pf_pdesc *pd, struct mbuf *m, int off,
+pf_match_translation(struct pf_pdesc *pd, pbuf_t *pbuf, int off,
int direction, struct pfi_kif *kif, struct pf_addr *saddr,
union pf_state_xport *sxport, struct pf_addr *daddr,
union pf_state_xport *dxport, int rs_num)
else if (dst && !pf_match_xport(r->proto, r->proto_variant,
&dst->xport, dxport))
r = r->skip[PF_SKIP_DST_PORT].ptr;
- else if (r->match_tag && !pf_match_tag(m, r, pd->pf_mtag, &tag))
+ else if (r->match_tag && !pf_match_tag(r, pd->pf_mtag, &tag))
r = TAILQ_NEXT(r, entries);
else if (r->os_fingerprint != PF_OSFP_ANY && (pd->proto !=
- IPPROTO_TCP || !pf_osfp_match(pf_osfp_fingerprint(pd, m,
+ IPPROTO_TCP || !pf_osfp_match(pf_osfp_fingerprint(pd, pbuf,
off, pd->hdr.tcp), r->os_fingerprint)))
r = TAILQ_NEXT(r, entries);
else {
pf_step_out_of_anchor(&asd, &ruleset, rs_num, &r,
NULL, NULL);
}
- if (pf_tag_packet(m, pd->pf_mtag, tag, rtableid, NULL))
+ if (pf_tag_packet(pbuf, pd->pf_mtag, tag, rtableid, NULL))
return (NULL);
if (rm != NULL && (rm->action == PF_NONAT ||
rm->action == PF_NORDR || rm->action == PF_NOBINAT ||
/*
* Get address translation information for NAT/BINAT/RDR
* pd : pf packet descriptor
- * m : mbuf holding the packet
+ * pbuf : pbuf holding the packet
* off : offset to protocol header
* direction : direction of packet
* kif : pf interface info obtained from the packet's recv interface
* pd->ndaddr
*/
static struct pf_rule *
-pf_get_translation_aux(struct pf_pdesc *pd, struct mbuf *m, int off,
+pf_get_translation_aux(struct pf_pdesc *pd, pbuf_t *pbuf, int off,
int direction, struct pfi_kif *kif, struct pf_src_node **sn,
struct pf_addr *saddr, union pf_state_xport *sxport, struct pf_addr *daddr,
- union pf_state_xport *dxport, union pf_state_xport *nsxport)
+ union pf_state_xport *dxport, union pf_state_xport *nsxport
+ )
{
struct pf_rule *r = NULL;
pd->naf = pd->af;
if (direction == PF_OUT) {
- r = pf_match_translation(pd, m, off, direction, kif, saddr,
+ r = pf_match_translation(pd, pbuf, off, direction, kif, saddr,
sxport, daddr, dxport, PF_RULESET_BINAT);
if (r == NULL)
- r = pf_match_translation(pd, m, off, direction, kif,
+ r = pf_match_translation(pd, pbuf, off, direction, kif,
saddr, sxport, daddr, dxport, PF_RULESET_RDR);
if (r == NULL)
- r = pf_match_translation(pd, m, off, direction, kif,
+ r = pf_match_translation(pd, pbuf, off, direction, kif,
saddr, sxport, daddr, dxport, PF_RULESET_NAT);
} else {
- r = pf_match_translation(pd, m, off, direction, kif, saddr,
+ r = pf_match_translation(pd, pbuf, off, direction, kif, saddr,
sxport, daddr, dxport, PF_RULESET_RDR);
if (r == NULL)
- r = pf_match_translation(pd, m, off, direction, kif,
+ r = pf_match_translation(pd, pbuf, off, direction, kif,
saddr, sxport, daddr, dxport, PF_RULESET_BINAT);
}
return (NULL);
if (pf_get_sport(pd, kif, r, saddr, sxport, daddr,
- dxport, nsaddr, nsxport, sn)) {
+ dxport, nsaddr, nsxport, sn
+ ))
+ {
DPFPRINTF(PF_DEBUG_MISC,
("pf: NAT proxy port allocation "
"(%u-%u) failed\n",
* from the last 32 bits of synthesized IPv6 address
*/
if (r->action == PF_NAT64) {
- ndaddr->v4.s_addr = daddr->addr32[3];
+ ndaddr->v4addr.s_addr = daddr->addr32[3];
pd->naf = AF_INET;
}
break;
switch (pd->af) {
#if INET
case AF_INET:
- inp = in_pcblookup_hash_exists(pi, saddr->v4, sport, daddr->v4, dport,
+ inp = in_pcblookup_hash_exists(pi, saddr->v4addr, sport, daddr->v4addr, dport,
0, &pd->lookup.uid, &pd->lookup.gid, NULL);
#if INET6
if (inp == 0) {
memset(&s6, 0, sizeof (s6));
s6.s6_addr16[5] = htons(0xffff);
- memcpy(&s6.s6_addr32[3], &saddr->v4,
- sizeof (saddr->v4));
+ memcpy(&s6.s6_addr32[3], &saddr->v4addr,
+ sizeof (saddr->v4addr));
memset(&d6, 0, sizeof (d6));
d6.s6_addr16[5] = htons(0xffff);
- memcpy(&d6.s6_addr32[3], &daddr->v4,
- sizeof (daddr->v4));
+ memcpy(&d6.s6_addr32[3], &daddr->v4addr,
+ sizeof (daddr->v4addr));
inp = in6_pcblookup_hash_exists(pi, &s6, sport,
&d6, dport, 0, &pd->lookup.uid, &pd->lookup.gid, NULL);
if (inp == 0) {
- inp = in_pcblookup_hash_exists(pi, saddr->v4, sport,
- daddr->v4, dport, INPLOOKUP_WILDCARD, &pd->lookup.uid, &pd->lookup.gid, NULL);
+ inp = in_pcblookup_hash_exists(pi, saddr->v4addr, sport,
+ daddr->v4addr, dport, INPLOOKUP_WILDCARD, &pd->lookup.uid, &pd->lookup.gid, NULL);
if (inp == 0) {
inp = in6_pcblookup_hash_exists(pi, &s6, sport,
&d6, dport, INPLOOKUP_WILDCARD,
}
#else
if (inp == 0) {
- inp = in_pcblookup_hash_exists(pi, saddr->v4, sport,
- daddr->v4, dport, INPLOOKUP_WILDCARD,
+ inp = in_pcblookup_hash_exists(pi, saddr->v4addr, sport,
+ daddr->v4addr, dport, INPLOOKUP_WILDCARD,
&pd->lookup.uid, &pd->lookup.gid, NULL);
if (inp == 0)
return (-1);
#endif /* INET */
#if INET6
case AF_INET6:
- inp = in6_pcblookup_hash_exists(pi, &saddr->v6, sport, &daddr->v6,
+ inp = in6_pcblookup_hash_exists(pi, &saddr->v6addr, sport, &daddr->v6addr,
dport, 0, &pd->lookup.uid, &pd->lookup.gid, NULL);
if (inp == 0) {
- inp = in6_pcblookup_hash_exists(pi, &saddr->v6, sport,
- &daddr->v6, dport, INPLOOKUP_WILDCARD,
+ inp = in6_pcblookup_hash_exists(pi, &saddr->v6addr, sport,
+ &daddr->v6addr, dport, INPLOOKUP_WILDCARD,
&pd->lookup.uid, &pd->lookup.gid, NULL);
if (inp == 0)
return (-1);
}
static u_int8_t
-pf_get_wscale(struct mbuf *m, int off, u_int16_t th_off, sa_family_t af)
+pf_get_wscale(pbuf_t *pbuf, int off, u_int16_t th_off, sa_family_t af)
{
int hlen;
u_int8_t hdr[60];
hlen = th_off << 2; /* hlen <= sizeof (hdr) */
if (hlen <= (int)sizeof (struct tcphdr))
return (0);
- if (!pf_pull_hdr(m, off, hdr, hlen, NULL, NULL, af))
+ if (!pf_pull_hdr(pbuf, off, hdr, hlen, NULL, NULL, af))
return (0);
opt = hdr + sizeof (struct tcphdr);
hlen -= sizeof (struct tcphdr);
}
static u_int16_t
-pf_get_mss(struct mbuf *m, int off, u_int16_t th_off, sa_family_t af)
+pf_get_mss(pbuf_t *pbuf, int off, u_int16_t th_off, sa_family_t af)
{
int hlen;
u_int8_t hdr[60];
hlen = th_off << 2; /* hlen <= sizeof (hdr) */
if (hlen <= (int)sizeof (struct tcphdr))
return (0);
- if (!pf_pull_hdr(m, off, hdr, hlen, NULL, NULL, af))
+ if (!pf_pull_hdr(pbuf, off, hdr, hlen, NULL, NULL, af))
return (0);
opt = hdr + sizeof (struct tcphdr);
hlen -= sizeof (struct tcphdr);
dst = (struct sockaddr_in *)(void *)&ro.ro_dst;
dst->sin_family = AF_INET;
dst->sin_len = sizeof (*dst);
- dst->sin_addr = addr->v4;
+ dst->sin_addr = addr->v4addr;
rtalloc(&ro);
rt = ro.ro_rt;
break;
dst6 = (struct sockaddr_in6 *)(void *)&ro6.ro_dst;
dst6->sin6_family = AF_INET6;
dst6->sin6_len = sizeof (*dst6);
- dst6->sin6_addr = addr->v6;
+ dst6->sin6_addr = addr->v6addr;
rtalloc((struct route *)&ro);
rt = ro6.ro_rt;
break;
}
if (rt && rt->rt_ifp) {
- mss = rt->rt_ifp->if_mtu - hlen - sizeof (struct tcphdr);
+ /* This is relevant only for PF SYN Proxy */
+ int interface_mtu = rt->rt_ifp->if_mtu;
+
+ if (af == AF_INET &&
+ INTF_ADJUST_MTU_FOR_CLAT46(rt->rt_ifp)) {
+ interface_mtu = IN6_LINKMTU(rt->rt_ifp);
+ /* Further adjust the size for CLAT46 expansion */
+ interface_mtu -= CLAT46_HDR_EXPANSION_OVERHD;
+ }
+ mss = interface_mtu - hlen - sizeof (struct tcphdr);
mss = max(tcp_mssdflt, mss);
rtfree(rt);
}
u_int32_t digest[4];
if (pf_tcp_secret_init == 0) {
- read_random(pf_tcp_secret, sizeof (pf_tcp_secret));
+ read_frandom(pf_tcp_secret, sizeof (pf_tcp_secret));
MD5Init(&pf_tcp_secret_ctx);
MD5Update(&pf_tcp_secret_ctx, pf_tcp_secret,
sizeof (pf_tcp_secret));
MD5Update(&ctx, (char *)&pd->hdr.tcp->th_sport, sizeof (u_short));
MD5Update(&ctx, (char *)&pd->hdr.tcp->th_dport, sizeof (u_short));
if (pd->af == AF_INET6) {
- MD5Update(&ctx, (char *)&pd->src->v6, sizeof (struct in6_addr));
- MD5Update(&ctx, (char *)&pd->dst->v6, sizeof (struct in6_addr));
+ MD5Update(&ctx, (char *)&pd->src->v6addr, sizeof (struct in6_addr));
+ MD5Update(&ctx, (char *)&pd->dst->v6addr, sizeof (struct in6_addr));
} else {
- MD5Update(&ctx, (char *)&pd->src->v4, sizeof (struct in_addr));
- MD5Update(&ctx, (char *)&pd->dst->v4, sizeof (struct in_addr));
+ MD5Update(&ctx, (char *)&pd->src->v4addr, sizeof (struct in_addr));
+ MD5Update(&ctx, (char *)&pd->dst->v4addr, sizeof (struct in_addr));
}
MD5Final((u_char *)digest, &ctx);
pf_tcp_iss_off += 4096;
/*
* This routine is called to perform address family translation on the
- * inner IP header (that may come as payload) of an ICMP(v4/6) error
+ * inner IP header (that may come as payload) of an ICMP(v4addr/6) error
* response.
*/
static int
-pf_change_icmp_af(struct mbuf *m, int off,
+pf_change_icmp_af(pbuf_t *pbuf, int off,
struct pf_pdesc *pd, struct pf_pdesc *pd2, struct pf_addr *src,
struct pf_addr *dst, sa_family_t af, sa_family_t naf)
{
- struct mbuf *n = NULL;
struct ip *ip4 = NULL;
struct ip6_hdr *ip6 = NULL;
- int hlen, olen, mlen;
+ void *hdr;
+ int hlen, olen;
if (af == naf || (af != AF_INET && af != AF_INET6) ||
(naf != AF_INET && naf != AF_INET6))
return (-1);
- /* split the mbuf chain on the inner ip/ip6 header boundary */
- if ((n = m_split(m, off, M_DONTWAIT)) == NULL)
- return (-1);
-
/* old header */
olen = pd2->off - off;
/* new header */
hlen = naf == AF_INET ? sizeof(*ip4) : sizeof(*ip6);
- /* trim old header */
- m_adj(n, olen);
-
- /* prepend a new one */
- if (M_PREPEND(n, hlen, M_DONTWAIT, 0) == NULL)
+ /* Modify the pbuf to accommodate the new header */
+ hdr = pbuf_resize_segment(pbuf, off, olen, hlen);
+ if (hdr == NULL)
return (-1);
/* translate inner ip/ip6 header */
switch (naf) {
case AF_INET:
- ip4 = mtod(n, struct ip *);
+ ip4 = hdr;
bzero(ip4, sizeof(*ip4));
ip4->ip_v = IPVERSION;
ip4->ip_hl = sizeof(*ip4) >> 2;
ip4->ip_len = htons(sizeof(*ip4) + pd2->tot_len - olen);
- ip4->ip_id = htons(ip_randomid());
+ ip4->ip_id = rfc6864 ? 0 : htons(ip_randomid());
ip4->ip_off = htons(IP_DF);
ip4->ip_ttl = pd2->ttl;
if (pd2->proto == IPPROTO_ICMPV6)
ip4->ip_p = IPPROTO_ICMP;
else
ip4->ip_p = pd2->proto;
- ip4->ip_src = src->v4;
- ip4->ip_dst = dst->v4;
- ip4->ip_sum = in_cksum(n, ip4->ip_hl << 2);
+ ip4->ip_src = src->v4addr;
+ ip4->ip_dst = dst->v4addr;
+ ip4->ip_sum = pbuf_inet_cksum(pbuf, 0, 0, ip4->ip_hl << 2);
break;
case AF_INET6:
- ip6 = mtod(n, struct ip6_hdr *);
+ ip6 = hdr;
bzero(ip6, sizeof(*ip6));
ip6->ip6_vfc = IPV6_VERSION;
ip6->ip6_plen = htons(pd2->tot_len - olen);
ip6->ip6_hlim = IPV6_DEFHLIM;
else
ip6->ip6_hlim = pd2->ttl;
- ip6->ip6_src = src->v6;
- ip6->ip6_dst = dst->v6;
+ ip6->ip6_src = src->v6addr;
+ ip6->ip6_dst = dst->v6addr;
break;
}
pd2->off += hlen - olen;
pd->tot_len += hlen - olen;
- /* merge modified inner packet with the original header */
- mlen = n->m_pkthdr.len;
- m_cat(m, n);
- m->m_pkthdr.len += mlen;
-
return (0);
}
return (0);
}
+/* Note: frees pbuf if PF_NAT64 is returned */
static int
-pf_nat64_ipv6(struct mbuf *m, int off, struct pf_pdesc *pd)
+pf_nat64_ipv6(pbuf_t *pbuf, int off, struct pf_pdesc *pd)
{
struct ip *ip4;
+ struct mbuf *m;
/*
* ip_input asserts for rcvif to be not NULL
* 2. If IPv6 stack in kernel internally generates a
* message destined for a synthesized IPv6 end-point.
*/
- if (m->m_pkthdr.rcvif == NULL)
+ if (pbuf->pb_ifp == NULL)
return (PF_DROP);
- /* trim the old header */
- m_adj(m, off);
-
- /* prepend the new one */
- if (M_PREPEND(m, sizeof(*ip4), M_DONTWAIT, 0) == NULL)
+ ip4 = (struct ip *)pbuf_resize_segment(pbuf, 0, off, sizeof(*ip4));
+ if (ip4 == NULL)
return (PF_DROP);
- ip4 = mtod(m, struct ip *);
ip4->ip_v = 4;
ip4->ip_hl = 5;
ip4->ip_tos = pd->tos & htonl(0x0ff00000);
ip4->ip_len = htons(sizeof(*ip4) + (pd->tot_len - off));
- ip4->ip_id = 0;
- ip4->ip_off = htons(IP_DF);
- ip4->ip_ttl = pd->ttl;
- ip4->ip_p = pd->proto;
+ ip4->ip_id = 0;
+ ip4->ip_off = htons(IP_DF);
+ ip4->ip_ttl = pd->ttl;
+ ip4->ip_p = pd->proto;
ip4->ip_sum = 0;
- ip4->ip_src = pd->naddr.v4;
- ip4->ip_dst = pd->ndaddr.v4;
- ip4->ip_sum = in_cksum(m, ip4->ip_hl << 2);
+ ip4->ip_src = pd->naddr.v4addr;
+ ip4->ip_dst = pd->ndaddr.v4addr;
+ ip4->ip_sum = pbuf_inet_cksum(pbuf, 0, 0, ip4->ip_hl << 2);
/* recalculate icmp checksums */
if (pd->proto == IPPROTO_ICMP) {
- struct mbuf *mp;
struct icmp *icmp;
- int moff, hlen = sizeof(*ip4);
+ int hlen = sizeof(*ip4);
- if ((mp = m_pulldown(m, hlen, ICMP_MINLEN, &moff)) == NULL)
+ icmp = (struct icmp *)pbuf_contig_segment(pbuf, hlen,
+ ICMP_MINLEN);
+ if (icmp == NULL)
return (PF_DROP);
- icmp = (struct icmp *)(void *)(mtod(mp, char *) + moff);
icmp->icmp_cksum = 0;
- icmp->icmp_cksum = inet_cksum(m, 0, hlen,
+ icmp->icmp_cksum = pbuf_inet_cksum(pbuf, 0, hlen,
ntohs(ip4->ip_len) - hlen);
}
- ip_input(m);
+ if ((m = pbuf_to_mbuf(pbuf, TRUE)) != NULL)
+ ip_input(m);
+
return (PF_NAT64);
}
static int
-pf_nat64_ipv4(struct mbuf *m, int off, struct pf_pdesc *pd)
+pf_nat64_ipv4(pbuf_t *pbuf, int off, struct pf_pdesc *pd)
{
struct ip6_hdr *ip6;
+ struct mbuf *m;
- if (m->m_pkthdr.rcvif == NULL)
+ if (pbuf->pb_ifp == NULL)
return (PF_DROP);
- m_adj(m, off);
- if (M_PREPEND(m, sizeof(*ip6), M_DONTWAIT, 0) == NULL)
+ ip6 = (struct ip6_hdr *)pbuf_resize_segment(pbuf, 0, off, sizeof(*ip6));
+ if (ip6 == NULL)
return (PF_DROP);
- ip6 = mtod(m, struct ip6_hdr *);
ip6->ip6_vfc = htonl((6 << 28) | (pd->tos << 20));
ip6->ip6_plen = htons(pd->tot_len - off);
ip6->ip6_nxt = pd->proto;
ip6->ip6_hlim = pd->ttl;
- ip6->ip6_src = pd->naddr.v6;
- ip6->ip6_dst = pd->ndaddr.v6;
+ ip6->ip6_src = pd->naddr.v6addr;
+ ip6->ip6_dst = pd->ndaddr.v6addr;
/* recalculate icmp6 checksums */
if (pd->proto == IPPROTO_ICMPV6) {
- struct mbuf *mp;
struct icmp6_hdr *icmp6;
- int moff, hlen = sizeof(*ip6);
+ int hlen = sizeof(*ip6);
- if ((mp = m_pulldown(m, hlen, sizeof(*icmp6), &moff)) == NULL)
+ icmp6 = (struct icmp6_hdr *)pbuf_contig_segment(pbuf, hlen,
+ sizeof(*icmp6));
+ if (icmp6 == NULL)
return (PF_DROP);
- icmp6 = (struct icmp6_hdr *)(void *)(mtod(mp, char *) + moff);
icmp6->icmp6_cksum = 0;
- icmp6->icmp6_cksum = inet6_cksum(m, IPPROTO_ICMPV6, hlen,
- ntohs(ip6->ip6_plen));
+ icmp6->icmp6_cksum = pbuf_inet6_cksum(pbuf,
+ IPPROTO_ICMPV6, hlen,
+ ntohs(ip6->ip6_plen));
} else if (pd->proto == IPPROTO_UDP) {
- struct mbuf *mp;
struct udphdr *uh;
- int moff, hlen = sizeof(*ip6);
- if ((mp = m_pulldown(m, hlen, sizeof(*uh), &moff)) == NULL)
+ int hlen = sizeof(*ip6);
+
+ uh = (struct udphdr *)pbuf_contig_segment(pbuf, hlen,
+ sizeof(*uh));
+ if (uh == NULL)
return (PF_DROP);
- uh = (struct udphdr *)(void *)(mtod(mp, char *) + moff);
+
if (uh->uh_sum == 0)
- uh->uh_sum = inet6_cksum(m, IPPROTO_UDP, hlen,
- ntohs(ip6->ip6_plen));
+ uh->uh_sum = pbuf_inet6_cksum(pbuf, IPPROTO_UDP,
+ hlen, ntohs(ip6->ip6_plen));
}
- ip6_input(m);
+ if ((m = pbuf_to_mbuf(pbuf, TRUE)) != NULL)
+ ip6_input(m);
+
return (PF_NAT64);
}
static int
pf_test_rule(struct pf_rule **rm, struct pf_state **sm, int direction,
- struct pfi_kif *kif, struct mbuf *m, int off, void *h,
+ struct pfi_kif *kif, pbuf_t *pbuf, int off, void *h,
struct pf_pdesc *pd, struct pf_rule **am, struct pf_ruleset **rsm,
struct ifqueue *ifq)
{
union pf_state_xport bxport, bdxport, nxport, sxport, dxport;
struct pf_state_key psk;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (direction == PF_IN && pf_check_congestion(ifq)) {
REASON_SET(&reason, PFRES_CONGEST);
icmptype = pd->hdr.icmp->icmp_type;
icmpcode = pd->hdr.icmp->icmp_code;
- if (icmptype == ICMP_UNREACH ||
- icmptype == ICMP_SOURCEQUENCH ||
- icmptype == ICMP_REDIRECT ||
- icmptype == ICMP_TIMXCEED ||
- icmptype == ICMP_PARAMPROB)
+ if (ICMP_ERRORTYPE(icmptype))
state_icmp++;
break;
#endif /* INET */
icmptype = pd->hdr.icmp6->icmp6_type;
icmpcode = pd->hdr.icmp6->icmp6_code;
- if (icmptype == ICMP6_DST_UNREACH ||
- icmptype == ICMP6_PACKET_TOO_BIG ||
- icmptype == ICMP6_TIME_EXCEEDED ||
- icmptype == ICMP6_PARAM_PROB)
+ if (ICMP6_ERRORTYPE(icmptype))
state_icmp++;
break;
#endif /* INET6 */
nxport = dxport;
/* check packet for BINAT/NAT/RDR */
- if ((nr = pf_get_translation_aux(pd, m, off, direction, kif, &nsn,
- saddr, &sxport, daddr, &dxport, &nxport)) !=
- NULL) {
+ if ((nr = pf_get_translation_aux(pd, pbuf, off, direction, kif, &nsn,
+ saddr, &sxport, daddr, &dxport, &nxport
+ )) != NULL) {
int ua;
u_int16_t dport;
* Will cross the bridge when it comes.
*/
if (PF_ANEQ(saddr, &pd->naddr, pd->af)) {
- pf_change_a(&saddr->v4.s_addr, pd->ip_sum,
- pd->naddr.v4.s_addr, 0);
+ pf_change_a(&saddr->v4addr.s_addr, pd->ip_sum,
+ pd->naddr.v4addr.s_addr, 0);
pd->hdr.icmp->icmp_cksum = pf_cksum_fixup(
pd->hdr.icmp->icmp_cksum, sxport.port,
nxport.port, 0);
}
if (PF_ANEQ(daddr, &pd->ndaddr, pd->af)) {
- pf_change_a(&daddr->v4.s_addr, pd->ip_sum,
- pd->ndaddr.v4.s_addr, 0);
+ pf_change_a(&daddr->v4addr.s_addr, pd->ip_sum,
+ pd->ndaddr.v4addr.s_addr, 0);
}
++rewrite;
break;
#if INET
case AF_INET:
if (PF_ANEQ(saddr, &pd->naddr, pd->af)) {
- pf_change_a(&saddr->v4.s_addr,
+ pf_change_a(&saddr->v4addr.s_addr,
pd->ip_sum,
- pd->naddr.v4.s_addr, 0);
+ pd->naddr.v4addr.s_addr, 0);
}
if (PF_ANEQ(daddr, &pd->ndaddr, pd->af)) {
- pf_change_a(&daddr->v4.s_addr,
+ pf_change_a(&daddr->v4addr.s_addr,
pd->ip_sum,
- pd->ndaddr.v4.s_addr, 0);
+ pd->ndaddr.v4addr.s_addr, 0);
}
break;
#endif /* INET */
#if INET
case AF_INET:
if (PF_ANEQ(saddr, &pd->naddr, pd->af)) {
- pf_change_a(&saddr->v4.s_addr,
- pd->ip_sum, pd->naddr.v4.s_addr, 0);
+ pf_change_a(&saddr->v4addr.s_addr,
+ pd->ip_sum, pd->naddr.v4addr.s_addr, 0);
}
if (PF_ANEQ(daddr, &pd->ndaddr, pd->af)) {
- pf_change_a(&daddr->v4.s_addr,
+ pf_change_a(&daddr->v4addr.s_addr,
pd->ip_sum,
- pd->ndaddr.v4.s_addr, 0);
+ pd->ndaddr.v4addr.s_addr, 0);
}
break;
#endif /* INET */
r = NULL;
pd->nat_rule = nr;
pd->af = pd->naf;
+ } else {
}
if (nr && nr->tag > 0)
r = TAILQ_NEXT(r, entries);
else if (r->prob && r->prob <= (RandomULong() % (UINT_MAX - 1) + 1))
r = TAILQ_NEXT(r, entries);
- else if (r->match_tag && !pf_match_tag(m, r, pd->pf_mtag, &tag))
+ else if (r->match_tag && !pf_match_tag(r, pd->pf_mtag, &tag))
r = TAILQ_NEXT(r, entries);
else if (r->os_fingerprint != PF_OSFP_ANY &&
(pd->proto != IPPROTO_TCP || !pf_osfp_match(
- pf_osfp_fingerprint(pd, m, off, th),
+ pf_osfp_fingerprint(pd, pbuf, off, th),
r->os_fingerprint)))
r = TAILQ_NEXT(r, entries);
else {
if (rewrite < off + hdrlen)
rewrite = off + hdrlen;
- m = pf_lazy_makewritable(pd, m, rewrite);
- if (!m) {
+ if (pf_lazy_makewritable(pd, pbuf, rewrite) == NULL) {
REASON_SET(&reason, PFRES_MEMORY);
return (PF_DROP);
}
- m_copyback(m, off, hdrlen, pd->hdr.any);
+ pbuf_copy_back(pbuf, off, hdrlen, pd->hdr.any);
}
- PFLOG_PACKET(kif, h, m, pd->af, direction, reason,
+ PFLOG_PACKET(kif, h, pbuf, pd->af, direction, reason,
r->log ? r : nr, a, ruleset, pd);
}
switch (af) {
#if INET
case AF_INET:
- pf_change_a(&saddr->v4.s_addr,
+ pf_change_a(&saddr->v4addr.s_addr,
pd->ip_sum,
- pd->baddr.v4.s_addr, 0);
+ pd->baddr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
switch (af) {
#if INET
case AF_INET:
- pf_change_a(&saddr->v4.s_addr,
+ pf_change_a(&saddr->v4addr.s_addr,
pd->ip_sum,
- pd->baddr.v4.s_addr, 0);
+ pd->baddr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
default:
switch (af) {
case AF_INET:
- pf_change_a(&saddr->v4.s_addr,
+ pf_change_a(&saddr->v4addr.s_addr,
pd->ip_sum,
- pd->baddr.v4.s_addr, 0);
+ pd->baddr.v4addr.s_addr, 0);
break;
case AF_INET6:
PF_ACPY(saddr, &pd->baddr, af);
switch (af) {
#if INET
case AF_INET:
- pf_change_a(&daddr->v4.s_addr,
+ pf_change_a(&daddr->v4addr.s_addr,
pd->ip_sum,
- pd->bdaddr.v4.s_addr, 0);
+ pd->bdaddr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
switch (af) {
#if INET
case AF_INET:
- pf_change_a(&daddr->v4.s_addr,
+ pf_change_a(&daddr->v4addr.s_addr,
pd->ip_sum,
- pd->bdaddr.v4.s_addr, 0);
+ pd->bdaddr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
default:
switch (af) {
case AF_INET:
- pf_change_a(&daddr->v4.s_addr,
+ pf_change_a(&daddr->v4addr.s_addr,
pd->ip_sum,
- pd->bdaddr.v4.s_addr, 0);
+ pd->bdaddr.v4addr.s_addr, 0);
break;
#if INET6
case AF_INET6:
switch (pd->af) {
case AF_INET:
- h4 = mtod(m, struct ip *);
+ h4 = pbuf->pb_data;
len = ntohs(h4->ip_len) - off;
break;
#if INET6
case AF_INET6:
- h6 = mtod(m, struct ip6_hdr *);
+ h6 = pbuf->pb_data;
len = ntohs(h6->ip6_plen) -
(off - sizeof (*h6));
break;
#endif /* INET6 */
}
- if (pf_check_proto_cksum(m, off, len, IPPROTO_TCP,
+ if (pf_check_proto_cksum(pbuf, off, len, IPPROTO_TCP,
pd->af))
REASON_SET(&reason, PFRES_PROTCKSUM);
else {
} else if (pd->proto != IPPROTO_ICMP && pd->af == AF_INET &&
pd->proto != IPPROTO_ESP && pd->proto != IPPROTO_AH &&
r->return_icmp)
- pf_send_icmp(m, r->return_icmp >> 8,
+ pf_send_icmp(pbuf, r->return_icmp >> 8,
r->return_icmp & 255, pd->af, r);
else if (pd->proto != IPPROTO_ICMPV6 && af == AF_INET6 &&
pd->proto != IPPROTO_ESP && pd->proto != IPPROTO_AH &&
r->return_icmp6)
- pf_send_icmp(m, r->return_icmp6 >> 8,
+ pf_send_icmp(pbuf, r->return_icmp6 >> 8,
r->return_icmp6 & 255, pd->af, r);
}
- if (r->action == PF_DROP)
+ if (r->action == PF_DROP) {
return (PF_DROP);
+ }
/* prepare state key, for flowhash and/or the state (if created) */
bzero(&psk, sizeof (psk));
* NAT64 requires protocol translation between ICMPv4
* and ICMPv6. TCP and UDP do not require protocol
* translation. To avoid adding complexity just to
- * handle ICMP(v4/v6), we always lookup for
+ * handle ICMP(v4addr/v6addr), we always lookup for
* proto = IPPROTO_ICMP on both LAN and WAN side
*/
psk.proto = IPPROTO_ICMP;
* NAT64 requires protocol translation between ICMPv4
* and ICMPv6. TCP and UDP do not require protocol
* translation. To avoid adding complexity just to
- * handle ICMP(v4/v6), we always lookup for
+ * handle ICMP(v4addr/v6addr), we always lookup for
* proto = IPPROTO_ICMP on both LAN and WAN side
*/
psk.proto = IPPROTO_ICMP;
pd->pktflags &= ~PKTF_FLOW_ADV;
}
- if (pf_tag_packet(m, pd->pf_mtag, tag, rtableid, pd)) {
+ if (pf_tag_packet(pbuf, pd->pf_mtag, tag, rtableid, pd)) {
REASON_SET(&reason, PFRES_MEMORY);
return (PF_DROP);
}
struct pf_ike_hdr ike;
if (pd->proto == IPPROTO_UDP) {
- size_t plen = m->m_pkthdr.len - off - sizeof (*uh);
+ size_t plen = pbuf->pb_packet_len - off - sizeof(*uh);
if (ntohs(uh->uh_sport) == PF_IKE_PORT &&
ntohs(uh->uh_dport) == PF_IKE_PORT &&
plen >= PF_IKE_PACKET_MINSIZE) {
if (plen > PF_IKE_PACKET_MINSIZE)
plen = PF_IKE_PACKET_MINSIZE;
- m_copydata(m, off + sizeof (*uh), plen, &ike);
+ pbuf_copy_data(pbuf, off + sizeof (*uh), plen,
+ &ike);
}
}
s->src.seqdiff = 0;
if (th->th_flags & TH_SYN) {
s->src.seqhi++;
- s->src.wscale = pf_get_wscale(m, off,
+ s->src.wscale = pf_get_wscale(pbuf, off,
th->th_off, af);
}
s->src.max_win = MAX(ntohs(th->th_win), 1);
}
if (pd->proto == IPPROTO_TCP) {
if ((pd->flags & PFDESC_TCP_NORM) &&
- pf_normalize_tcp_init(m, off, pd, th, &s->src,
+ pf_normalize_tcp_init(pbuf, off, pd, th, &s->src,
&s->dst)) {
REASON_SET(&reason, PFRES_MEMORY);
pf_src_tree_remove_state(s);
return (PF_DROP);
}
if ((pd->flags & PFDESC_TCP_NORM) && s->src.scrub &&
- pf_normalize_tcp_stateful(m, off, pd, &reason,
+ pf_normalize_tcp_stateful(pbuf, off, pd, &reason,
th, s, &s->src, &s->dst, &rewrite)) {
/* This really shouldn't happen!!! */
DPFPRINTF(PF_DEBUG_URGENT,
/* allocate state key and import values from psk */
if ((sk = pf_alloc_state_key(s, &psk)) == NULL) {
REASON_SET(&reason, PFRES_MEMORY);
+ /*
+ * XXXSCW: This will leak the freshly-allocated
+ * state structure 's'. Although it should
+ * eventually be aged-out and removed.
+ */
goto cleanup;
}
pf_set_rt_ifp(s, saddr, af); /* needs s->state_key set */
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
if (sk->app_state == 0) {
switch (pd->proto) {
STATE_DEC_COUNTERS(s);
pool_put(&pf_state_pl, s);
return (PF_DROP);
- } else
+ } else {
*sm = s;
+ }
if (tag > 0) {
pf_tag_ref(tag);
s->tag = tag;
}
s->src.seqhi = htonl(random());
/* Find mss option */
- mss = pf_get_mss(m, off, th->th_off, af);
+ mss = pf_get_mss(pbuf, off, th->th_off, af);
mss = pf_calc_mss(saddr, af, mss);
mss = pf_calc_mss(daddr, af, mss);
s->src.mss = mss;
REASON_SET(&reason, PFRES_MEMORY);
return (PF_DROP);
}
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
}
}
}
if (rewrite < off + hdrlen)
rewrite = off + hdrlen;
- m = pf_lazy_makewritable(pd, pd->mp, rewrite);
- if (!m) {
+ if (pf_lazy_makewritable(pd, pd->mp, rewrite) == NULL) {
REASON_SET(&reason, PFRES_MEMORY);
return (PF_DROP);
}
- m_copyback(m, off, hdrlen, pd->hdr.any);
+ pbuf_copy_back(pbuf, off, hdrlen, pd->hdr.any);
if (af == AF_INET6 && pd->naf == AF_INET)
- return pf_nat64_ipv6(m, off, pd);
+ return pf_nat64_ipv6(pbuf, off, pd);
else if (af == AF_INET && pd->naf == AF_INET6)
- return pf_nat64_ipv4(m, off, pd);
+ return pf_nat64_ipv4(pbuf, off, pd);
}
return (PF_PASS);
}
+boolean_t is_nlc_enabled_glb = FALSE;
+
+static inline boolean_t
+pf_is_dummynet_enabled(void)
+{
+#if DUMMYNET
+ if (__probable(!PF_IS_ENABLED))
+ return (FALSE);
+
+ if (__probable(!DUMMYNET_LOADED))
+ return (FALSE);
+
+ if (__probable(TAILQ_EMPTY(pf_main_ruleset.
+ rules[PF_RULESET_DUMMYNET].active.ptr)))
+ return (FALSE);
+
+ return (TRUE);
+#else
+ return (FALSE);
+#endif /* DUMMYNET */
+}
+
+boolean_t
+pf_is_nlc_enabled(void)
+{
+#if DUMMYNET
+ if (__probable(!pf_is_dummynet_enabled()))
+ return (FALSE);
+
+ if (__probable(!is_nlc_enabled_glb))
+ return (FALSE);
+
+ return (TRUE);
+#else
+ return (FALSE);
+#endif /* DUMMYNET */
+}
+
#if DUMMYNET
/*
* When pf_test_dummynet() returns PF_PASS, the rule matching parameter "rm"
*/
static int
pf_test_dummynet(struct pf_rule **rm, int direction, struct pfi_kif *kif,
- struct mbuf **m0, struct pf_pdesc *pd, struct ip_fw_args *fwa)
+ pbuf_t **pbuf0, struct pf_pdesc *pd, struct ip_fw_args *fwa)
{
- struct mbuf *m = *m0;
+ pbuf_t *pbuf = *pbuf0;
struct pf_rule *am = NULL;
struct pf_ruleset *rsm = NULL;
struct pf_addr *saddr = pd->src, *daddr = pd->dst;
struct pf_rule *prev_matching_rule = fwa ? fwa->fwa_pf_rule : NULL;
int found_prev_rule = (prev_matching_rule) ? 0 : 1;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
-
- if (!DUMMYNET_LOADED)
- return (PF_PASS);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
- if (TAILQ_EMPTY(pf_main_ruleset.rules[PF_RULESET_DUMMYNET].active.ptr))
+ if (!pf_is_dummynet_enabled())
return (PF_PASS);
bzero(&dnflow, sizeof(dnflow));
r = TAILQ_NEXT(r, entries);
else if (r->prob && r->prob <= (RandomULong() % (UINT_MAX - 1) + 1))
r = TAILQ_NEXT(r, entries);
- else if (r->match_tag && !pf_match_tag(m, r, pd->pf_mtag, &tag))
+ else if (r->match_tag && !pf_match_tag(r, pd->pf_mtag, &tag))
r = TAILQ_NEXT(r, entries);
else {
/*
REASON_SET(&reason, PFRES_DUMMYNET);
if (r->log) {
- PFLOG_PACKET(kif, h, m, af, direction, reason, r,
+ PFLOG_PACKET(kif, h, pbuf, af, direction, reason, r,
a, ruleset, pd);
}
return (PF_PASS);
}
- if (pf_tag_packet(m, pd->pf_mtag, tag, rtableid, pd)) {
+ if (pf_tag_packet(pbuf, pd->pf_mtag, tag, rtableid, pd)) {
REASON_SET(&reason, PFRES_MEMORY);
return (PF_DROP);
}
if (r->dnpipe && ip_dn_io_ptr != NULL) {
+ struct mbuf *m;
int dirndx = (direction == PF_OUT);
r->packets[dirndx]++;
switch (af) {
case AF_INET:
dnflow.fwa_id.addr_type = 4;
- dnflow.fwa_id.src_ip = ntohl(saddr->v4.s_addr);
- dnflow.fwa_id.dst_ip = ntohl(daddr->v4.s_addr);
+ dnflow.fwa_id.src_ip = ntohl(saddr->v4addr.s_addr);
+ dnflow.fwa_id.dst_ip = ntohl(daddr->v4addr.s_addr);
break;
case AF_INET6:
dnflow.fwa_id.addr_type = 6;
- dnflow.fwa_id.src_ip6 = saddr->v6;
- dnflow.fwa_id.dst_ip6 = saddr->v6;
+ dnflow.fwa_id.src_ip6 = saddr->v6addr;
+ dnflow.fwa_id.dst_ip6 = saddr->v6addr;
break;
}
}
if (af == AF_INET) {
- struct ip *iphdr = mtod(m, struct ip *);
+ struct ip *iphdr = pbuf->pb_data;
NTOHS(iphdr->ip_len);
NTOHS(iphdr->ip_off);
}
* Don't need to unlock pf_lock as NET_THREAD_HELD_PF
* allows for recursive behavior
*/
- ip_dn_io_ptr(m,
- dnflow.fwa_cookie,
- af == AF_INET ?
- direction == PF_IN ? DN_TO_IP_IN : DN_TO_IP_OUT :
- direction == PF_IN ? DN_TO_IP6_IN : DN_TO_IP6_OUT,
- &dnflow, DN_CLIENT_PF);
+ m = pbuf_to_mbuf(pbuf, TRUE);
+ if (m != NULL) {
+ ip_dn_io_ptr(m,
+ dnflow.fwa_cookie, (af == AF_INET) ?
+ ((direction==PF_IN) ? DN_TO_IP_IN : DN_TO_IP_OUT) :
+ ((direction==PF_IN) ? DN_TO_IP6_IN : DN_TO_IP6_OUT),
+ &dnflow, DN_CLIENT_PF);
+ }
/*
* The packet is siphoned out by dummynet so return a NULL
- * mbuf so the caller can still return success.
+ * pbuf so the caller can still return success.
*/
- *m0 = NULL;
+ *pbuf0 = NULL;
return (PF_PASS);
}
static int
pf_test_fragment(struct pf_rule **rm, int direction, struct pfi_kif *kif,
- struct mbuf *m, void *h, struct pf_pdesc *pd, struct pf_rule **am,
+ pbuf_t *pbuf, void *h, struct pf_pdesc *pd, struct pf_rule **am,
struct pf_ruleset **rsm)
{
#pragma unused(h)
r = TAILQ_NEXT(r, entries);
else if (r->prob && r->prob <= (RandomULong() % (UINT_MAX - 1) + 1))
r = TAILQ_NEXT(r, entries);
- else if (r->match_tag && !pf_match_tag(m, r, pd->pf_mtag, &tag))
+ else if (r->match_tag && !pf_match_tag(r, pd->pf_mtag, &tag))
r = TAILQ_NEXT(r, entries);
else {
if (r->anchor == NULL) {
REASON_SET(&reason, PFRES_MATCH);
if (r->log)
- PFLOG_PACKET(kif, h, m, af, direction, reason, r, a, ruleset,
+ PFLOG_PACKET(kif, h, pbuf, af, direction, reason, r, a, ruleset,
pd);
if (r->action != PF_PASS)
return (PF_DROP);
- if (pf_tag_packet(m, pd->pf_mtag, tag, -1, NULL)) {
+ if (pf_tag_packet(pbuf, pd->pf_mtag, tag, -1, NULL)) {
REASON_SET(&reason, PFRES_MEMORY);
return (PF_DROP);
}
u_int8_t *pac_state;
u_int8_t *pns_state;
enum { PF_PPTP_PASS, PF_PPTP_INSERT_GRE, PF_PPTP_REMOVE_GRE } op;
- struct mbuf *m;
+ pbuf_t *pbuf;
struct pf_state_key *sk;
struct pf_state_key *gsk;
struct pf_app_state *gas;
if (gs)
gs->expire = pf_time_second();
- m = pd->mp;
- plen = min(sizeof (cm), m->m_pkthdr.len - off);
+ pbuf = pd->mp;
+ plen = min(sizeof (cm), pbuf->pb_packet_len - off);
if (plen < PF_PPTP_CTRL_MSG_MINSIZE)
return;
tlen = plen - PF_PPTP_CTRL_MSG_MINSIZE;
- m_copydata(m, off, plen, &cm);
+ pbuf_copy_data(pbuf, off, plen, &cm);
if (ntohl(cm.hdr.magic) != PF_PPTP_MAGIC_NUMBER)
return;
gsk->lan.xport.call_id, gsk->gwy.xport.call_id, 0);
}
- m = pf_lazy_makewritable(pd, m, off + plen);
- if (!m) {
+ if (pf_lazy_makewritable(pd, pbuf, off + plen) == NULL) {
pptps->grev1_state = NULL;
STATE_DEC_COUNTERS(gs);
pool_put(&pf_state_pl, gs);
return;
}
- m_copyback(m, off, plen, &cm);
+ pbuf_copy_back(pbuf, off, plen, &cm);
}
switch (op) {
}
static int
-pf_do_nat64(struct pf_state_key *sk, struct pf_pdesc *pd, struct mbuf *m,
+pf_do_nat64(struct pf_state_key *sk, struct pf_pdesc *pd, pbuf_t *pbuf,
int off)
{
if (pd->af == AF_INET) {
pd->naddr = sk->gwy.addr;
pd->ndaddr = sk->ext_gwy.addr;
}
- return (pf_nat64_ipv4(m, off, pd));
+ return (pf_nat64_ipv4(pbuf, off, pd));
}
else if (pd->af == AF_INET6) {
if (pd->af != sk->af_lan) {
pd->naddr = sk->gwy.addr;
pd->ndaddr = sk->ext_gwy.addr;
}
- return (pf_nat64_ipv6(m, off, pd));
+ return (pf_nat64_ipv6(pbuf, off, pd));
}
return (PF_DROP);
}
static int
pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif,
- struct mbuf *m, int off, void *h, struct pf_pdesc *pd,
+ pbuf_t *pbuf, int off, void *h, struct pf_pdesc *pd,
u_short *reason)
{
#pragma unused(h)
if ((pd->flags & PFDESC_TCP_NORM || dst->scrub) &&
src->scrub == NULL) {
- if (pf_normalize_tcp_init(m, off, pd, th, src, dst)) {
+ if (pf_normalize_tcp_init(pbuf, off, pd, th, src, dst)) {
REASON_SET(reason, PFRES_MEMORY);
return (PF_DROP);
}
if (th->th_flags & TH_SYN) {
end++;
if (dst->wscale & PF_WSCALE_FLAG) {
- src->wscale = pf_get_wscale(m, off, th->th_off,
- pd->af);
+ src->wscale = pf_get_wscale(pbuf, off,
+ th->th_off, pd->af);
if (src->wscale & PF_WSCALE_FLAG) {
/*
* Remove scale factor from initial
* options anyway.
*/
if (dst->seqdiff && (th->th_off << 2) > (int)sizeof (struct tcphdr)) {
- copyback = pf_modulate_sack(m, off, pd, th, dst);
+ copyback = pf_modulate_sack(pbuf, off, pd, th, dst);
if (copyback == -1) {
REASON_SET(reason, PFRES_MEMORY);
return (PF_DROP);
}
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
}
/* Require an exact/+1 sequence match on resets when possible */
if (dst->scrub || src->scrub) {
- if (pf_normalize_tcp_stateful(m, off, pd, reason, th,
+ if (pf_normalize_tcp_stateful(pbuf, off, pd, reason, th,
*state, src, dst, ©back))
return (PF_DROP);
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
}
/* update max window */
}
if (dst->scrub || src->scrub) {
- if (pf_normalize_tcp_stateful(m, off, pd, reason, th,
+ if (pf_normalize_tcp_stateful(pbuf, off, pd, reason, th,
*state, src, dst, ©back))
return (PF_DROP);
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
}
/* update max window */
REASON_SET(reason, PFRES_MEMORY);
return (PF_DROP);
}
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
}
/* translate source/destination address, if necessary */
}
if (copyback) {
- m = pf_lazy_makewritable(pd, m, copyback);
- if (!m) {
+ if (pf_lazy_makewritable(pd, pbuf, copyback) == NULL) {
REASON_SET(reason, PFRES_MEMORY);
return (PF_DROP);
}
/* Copyback sequence modulation or stateful scrub changes */
- m_copyback(m, off, sizeof (*th), th);
+ pbuf_copy_back(pbuf, off, sizeof (*th), th);
if (sk->af_lan != sk->af_gwy)
- return (pf_do_nat64(sk, pd, m, off));
+ return (pf_do_nat64(sk, pd, pbuf, off));
}
return (PF_PASS);
}
static int
pf_test_state_udp(struct pf_state **state, int direction, struct pfi_kif *kif,
- struct mbuf *m, int off, void *h, struct pf_pdesc *pd, u_short *reason)
+ pbuf_t *pbuf, int off, void *h, struct pf_pdesc *pd, u_short *reason)
{
#pragma unused(h)
struct pf_state_peer *src, *dst;
if (ntohs(uh->uh_sport) == PF_IKE_PORT &&
ntohs(uh->uh_dport) == PF_IKE_PORT) {
struct pf_ike_hdr ike;
- size_t plen = m->m_pkthdr.len - off - sizeof (*uh);
+ size_t plen = pbuf->pb_packet_len - off - sizeof (*uh);
if (plen < PF_IKE_PACKET_MINSIZE) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: IKE message too small.\n"));
if (plen > sizeof (ike))
plen = sizeof (ike);
- m_copydata(m, off + sizeof (*uh), plen, &ike);
+ pbuf_copy_data(pbuf, off + sizeof (*uh), plen, &ike);
if (ike.initiator_cookie) {
key.app_state = &as;
REASON_SET(reason, PFRES_MEMORY);
return (PF_DROP);
}
- m = pd->mp;
+ pbuf = pd->mp; // XXXSCW: Why?
}
/* translate source/destination address, if necessary */
if (STATE_TRANSLATE(sk)) {
- m = pf_lazy_makewritable(pd, m, off + sizeof (*uh));
- if (!m) {
+ if (pf_lazy_makewritable(pd, pbuf, off + sizeof (*uh)) == NULL) {
REASON_SET(reason, PFRES_MEMORY);
return (PF_DROP);
}
}
}
- m_copyback(m, off, sizeof (*uh), uh);
+ pbuf_copy_back(pbuf, off, sizeof (*uh), uh);
if (sk->af_lan != sk->af_gwy)
- return (pf_do_nat64(sk, pd, m, off));
+ return (pf_do_nat64(sk, pd, pbuf, off));
}
return (PF_PASS);
}
static int
pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif,
- struct mbuf *m, int off, void *h, struct pf_pdesc *pd, u_short *reason)
+ pbuf_t *pbuf, int off, void *h, struct pf_pdesc *pd, u_short *reason)
{
#pragma unused(h)
struct pf_addr *saddr = pd->src, *daddr = pd->dst;
- struct in_addr srcv4_inaddr = saddr->v4;
- u_int16_t icmpid = 0, *icmpsum;
- u_int8_t icmptype;
+ struct in_addr srcv4_inaddr = saddr->v4addr;
+ u_int16_t icmpid = 0, *icmpsum = NULL;
+ u_int8_t icmptype = 0;
int state_icmp = 0;
struct pf_state_key_cmp key;
struct pf_state_key *sk;
icmpid = pd->hdr.icmp->icmp_id;
icmpsum = &pd->hdr.icmp->icmp_cksum;
- if (icmptype == ICMP_UNREACH ||
- icmptype == ICMP_SOURCEQUENCH ||
- icmptype == ICMP_REDIRECT ||
- icmptype == ICMP_TIMXCEED ||
- icmptype == ICMP_PARAMPROB)
+ if (ICMP_ERRORTYPE(icmptype))
state_icmp++;
break;
#endif /* INET */
icmpid = pd->hdr.icmp6->icmp6_id;
icmpsum = &pd->hdr.icmp6->icmp6_cksum;
- if (icmptype == ICMP6_DST_UNREACH ||
- icmptype == ICMP6_PACKET_TOO_BIG ||
- icmptype == ICMP6_TIME_EXCEEDED ||
- icmptype == ICMP6_PARAM_PROB)
+ if (ICMP6_ERRORTYPE(icmptype))
state_icmp++;
break;
#endif /* INET6 */
* NAT64 requires protocol translation between ICMPv4
* and ICMPv6. TCP and UDP do not require protocol
* translation. To avoid adding complexity just to
- * handle ICMP(v4/v6), we always lookup for
+ * handle ICMP(v4addr/v6addr), we always lookup for
* proto = IPPROTO_ICMP on both LAN and WAN side
*/
key.proto = IPPROTO_ICMP;
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&saddr->v4.s_addr,
+ pf_change_a(&saddr->v4addr.s_addr,
pd->ip_sum,
- sk->gwy.addr.v4.s_addr, 0);
+ sk->gwy.addr.v4addr.s_addr, 0);
pd->hdr.icmp->icmp_cksum =
pf_cksum_fixup(
pd->hdr.icmp->icmp_cksum, icmpid,
sk->gwy.xport.port, 0);
pd->hdr.icmp->icmp_id =
sk->gwy.xport.port;
- m = pf_lazy_makewritable(pd, m,
- off + ICMP_MINLEN);
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ off + ICMP_MINLEN) == NULL)
return (PF_DROP);
- m_copyback(m, off, ICMP_MINLEN,
+ pbuf_copy_back(pbuf, off, ICMP_MINLEN,
pd->hdr.icmp);
break;
#endif /* INET */
pf_change_a6(saddr,
&pd->hdr.icmp6->icmp6_cksum,
&sk->gwy.addr, 0);
- m = pf_lazy_makewritable(pd, m,
- off + sizeof (struct icmp6_hdr));
- if (!m)
+ if (pf_lazy_makewritable(pd, NULL,
+ off + sizeof (struct icmp6_hdr)) ==
+ NULL)
return (PF_DROP);
- m_copyback(m, off,
+ pbuf_copy_back(pbuf, off,
sizeof (struct icmp6_hdr),
pd->hdr.icmp6);
break;
} else {
- pf_change_a(&daddr->v4.s_addr,
+ pf_change_a(&daddr->v4addr.s_addr,
pd->ip_sum,
- sk->lan.addr.v4.s_addr, 0);
+ sk->lan.addr.v4addr.s_addr, 0);
pd->hdr.icmp->icmp_cksum =
pf_cksum_fixup(
sk->lan.xport.port;
}
- m = pf_lazy_makewritable(pd, m,
- off + ICMP_MINLEN);
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ off + ICMP_MINLEN) == NULL)
return (PF_DROP);
- m_copyback(m, off, ICMP_MINLEN,
+ pbuf_copy_back(pbuf, off, ICMP_MINLEN,
pd->hdr.icmp);
if (sk->af_lan != sk->af_gwy)
- return (pf_do_nat64(sk, pd, m,
- off));
+ return (pf_do_nat64(sk, pd,
+ pbuf, off));
break;
#endif /* INET */
#if INET6
&pd->hdr.icmp6->icmp6_cksum,
&sk->lan.addr, 0);
}
- m = pf_lazy_makewritable(pd, m,
- off + sizeof (struct icmp6_hdr));
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ off + sizeof (struct icmp6_hdr)) ==
+ NULL)
return (PF_DROP);
- m_copyback(m, off,
+ pbuf_copy_back(pbuf, off,
sizeof (struct icmp6_hdr),
pd->hdr.icmp6);
if (sk->af_lan != sk->af_gwy)
- return (pf_do_nat64(sk, pd, m,
- off));
+ return (pf_do_nat64(sk, pd,
+ pbuf, off));
break;
#endif /* INET6 */
}
/* offset of h2 in mbuf chain */
ipoff2 = off + ICMP_MINLEN;
- if (!pf_pull_hdr(m, ipoff2, &h2, sizeof (h2),
+ if (!pf_pull_hdr(pbuf, ipoff2, &h2, sizeof (h2),
NULL, reason, pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: ICMP error message too short "
case AF_INET6:
ipoff2 = off + sizeof (struct icmp6_hdr);
- if (!pf_pull_hdr(m, ipoff2, &h2_6, sizeof (h2_6),
+ if (!pf_pull_hdr(pbuf, ipoff2, &h2_6, sizeof (h2_6),
NULL, reason, pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: ICMP error message too short "
return (PF_DROP);
}
pd2.proto = h2_6.ip6_nxt;
- pd2.src = (struct pf_addr *)&h2_6.ip6_src;
- pd2.dst = (struct pf_addr *)&h2_6.ip6_dst;
+ pd2.src = (struct pf_addr *)(uintptr_t)&h2_6.ip6_src;
+ pd2.dst = (struct pf_addr *)(uintptr_t)&h2_6.ip6_dst;
pd2.ip_sum = NULL;
off2 = ipoff2 + sizeof (h2_6);
do {
/* get next header and header length */
struct ip6_ext opt6;
- if (!pf_pull_hdr(m, off2, &opt6,
+ if (!pf_pull_hdr(pbuf, off2, &opt6,
sizeof (opt6), NULL, reason,
pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
* expected. Don't access any TCP header fields after
* th_seq, an ackskew test is not possible.
*/
- if (!pf_pull_hdr(m, off2, &th, 8, NULL, reason,
+ if (!pf_pull_hdr(pbuf, off2, &th, 8, NULL, reason,
pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: ICMP error message too short "
if (pf_translate_icmp_af(pd->naf,
pd->hdr.icmp))
return (PF_DROP);
- m =
- pf_lazy_makewritable(pd, m, off2 + 8);
- if (!m)
+
+ if (pf_lazy_makewritable(pd, pbuf,
+ off2 + 8) == NULL)
return (PF_DROP);
- m_copyback(m, pd->off,
+ pbuf_copy_back(pbuf, pd->off,
sizeof(struct icmp6_hdr),
pd->hdr.icmp6);
* translate inner ip header within the
* ICMP message
*/
- if (pf_change_icmp_af(m, ipoff2, pd,
+ if (pf_change_icmp_af(pbuf, ipoff2, pd,
&pd2, &saddr2->addr, &daddr2->addr,
pd->af, pd->naf))
return (PF_DROP);
daddr2->xport.port, 0, pd2.af,
pd2.naf, 0);
- m_copyback(m, pd2.off, 8, &th);
+ pbuf_copy_back(pbuf, pd2.off, 8, &th);
/* translate outer ip header */
PF_ACPY(&pd->naddr, &daddr2->addr,
memcpy(&pd->naddr.addr32[3],
&srcv4_inaddr,
sizeof(pd->naddr.addr32[3]));
- return (pf_nat64_ipv4(m, off,
+ return (pf_nat64_ipv4(pbuf, off,
pd));
} else {
- return (pf_nat64_ipv6(m, off,
+ return (pf_nat64_ipv6(pbuf, off,
pd));
}
}
}
if (copyback) {
- m = pf_lazy_makewritable(pd, m, off2 + 8);
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf, off2 + 8) ==
+ NULL)
return (PF_DROP);
switch (pd2.af) {
#if INET
case AF_INET:
- m_copyback(m, off, ICMP_MINLEN,
+ pbuf_copy_back(pbuf, off, ICMP_MINLEN,
pd->hdr.icmp);
- m_copyback(m, ipoff2, sizeof (h2),
+ pbuf_copy_back(pbuf, ipoff2, sizeof(h2),
&h2);
break;
#endif /* INET */
#if INET6
case AF_INET6:
- m_copyback(m, off,
+ pbuf_copy_back(pbuf, off,
sizeof (struct icmp6_hdr),
pd->hdr.icmp6);
- m_copyback(m, ipoff2, sizeof (h2_6),
- &h2_6);
+ pbuf_copy_back(pbuf, ipoff2,
+ sizeof (h2_6), &h2_6);
break;
#endif /* INET6 */
}
- m_copyback(m, off2, 8, &th);
+ pbuf_copy_back(pbuf, off2, 8, &th);
}
return (PF_PASS);
case IPPROTO_UDP: {
struct udphdr uh;
int dx, action;
- if (!pf_pull_hdr(m, off2, &uh, sizeof (uh),
+ if (!pf_pull_hdr(pbuf, off2, &uh, sizeof (uh),
NULL, reason, pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: ICMP error message too short "
if (ntohs(uh.uh_sport) == PF_IKE_PORT &&
ntohs(uh.uh_dport) == PF_IKE_PORT) {
struct pf_ike_hdr ike;
- size_t plen =
- m->m_pkthdr.len - off2 - sizeof (uh);
+ size_t plen = pbuf->pb_packet_len - off2 -
+ sizeof (uh);
if (direction == PF_IN &&
plen < 8 /* PF_IKE_PACKET_MINSIZE */) {
DPFPRINTF(PF_DEBUG_MISC, ("pf: "
if (plen > sizeof (ike))
plen = sizeof (ike);
- m_copydata(m, off + sizeof (uh), plen, &ike);
+ pbuf_copy_data(pbuf, off + sizeof (uh), plen,
+ &ike);
key.app_state = &as;
as.compare_lan_ext = pf_ike_compare;
if (pf_translate_icmp_af(pd->naf,
pd->hdr.icmp))
return (PF_DROP);
- m =
- pf_lazy_makewritable(pd, m, off2 + 8);
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ off2 + 8) == NULL)
return (PF_DROP);
- m_copyback(m, pd->off,
+ pbuf_copy_back(pbuf, pd->off,
sizeof(struct icmp6_hdr),
pd->hdr.icmp6);
* translate inner ip header within the
* ICMP message
*/
- if (pf_change_icmp_af(m, ipoff2, pd,
+ if (pf_change_icmp_af(pbuf, ipoff2, pd,
&pd2, &saddr2->addr, &daddr2->addr,
pd->af, pd->naf))
return (PF_DROP);
daddr2->xport.port, 0, pd2.af,
pd2.naf, 0);
- m_copyback(m, pd2.off, sizeof(uh), &uh);
+ pbuf_copy_back(pbuf, pd2.off,
+ sizeof(uh), &uh);
/* translate outer ip header */
PF_ACPY(&pd->naddr, &daddr2->addr,
memcpy(&pd->naddr.addr32[3],
&srcv4_inaddr,
sizeof(pd->naddr.addr32[3]));
- return (pf_nat64_ipv4(m, off,
+ return (pf_nat64_ipv4(pbuf, off,
pd));
} else {
- return (pf_nat64_ipv6(m, off,
+ return (pf_nat64_ipv6(pbuf, off,
pd));
}
}
pd2.ip_sum, icmpsum,
pd->ip_sum, 1, pd2.af);
}
- m = pf_lazy_makewritable(pd, m,
- off2 + sizeof (uh));
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ off2 + sizeof (uh)) == NULL)
return (PF_DROP);
switch (pd2.af) {
#if INET
case AF_INET:
- m_copyback(m, off, ICMP_MINLEN,
+ pbuf_copy_back(pbuf, off, ICMP_MINLEN,
pd->hdr.icmp);
- m_copyback(m, ipoff2, sizeof (h2), &h2);
+ pbuf_copy_back(pbuf, ipoff2,
+ sizeof (h2), &h2);
break;
#endif /* INET */
#if INET6
case AF_INET6:
- m_copyback(m, off,
+ pbuf_copy_back(pbuf, off,
sizeof (struct icmp6_hdr),
pd->hdr.icmp6);
- m_copyback(m, ipoff2, sizeof (h2_6),
- &h2_6);
+ pbuf_copy_back(pbuf, ipoff2,
+ sizeof (h2_6), &h2_6);
break;
#endif /* INET6 */
}
- m_copyback(m, off2, sizeof (uh), &uh);
+ pbuf_copy_back(pbuf, off2, sizeof (uh), &uh);
}
return (PF_PASS);
case IPPROTO_ICMP: {
struct icmp iih;
- if (!pf_pull_hdr(m, off2, &iih, ICMP_MINLEN,
+ if (!pf_pull_hdr(pbuf, off2, &iih, ICMP_MINLEN,
NULL, reason, pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: ICMP error message too short i"
pd2.ip_sum, icmpsum,
pd->ip_sum, 0, AF_INET);
}
- m = pf_lazy_makewritable(pd, m,
- off2 + ICMP_MINLEN);
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ off2 + ICMP_MINLEN) == NULL)
return (PF_DROP);
- m_copyback(m, off, ICMP_MINLEN, pd->hdr.icmp);
- m_copyback(m, ipoff2, sizeof (h2), &h2);
- m_copyback(m, off2, ICMP_MINLEN, &iih);
+ pbuf_copy_back(pbuf, off, ICMP_MINLEN,
+ pd->hdr.icmp);
+ pbuf_copy_back(pbuf, ipoff2, sizeof (h2), &h2);
+ pbuf_copy_back(pbuf, off2, ICMP_MINLEN, &iih);
}
return (PF_PASS);
case IPPROTO_ICMPV6: {
struct icmp6_hdr iih;
- if (!pf_pull_hdr(m, off2, &iih,
+ if (!pf_pull_hdr(pbuf, off2, &iih,
sizeof (struct icmp6_hdr), NULL, reason, pd2.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: ICMP error message too short "
pd2.ip_sum, icmpsum,
pd->ip_sum, 0, AF_INET6);
}
- m = pf_lazy_makewritable(pd, m, off2 +
- sizeof (struct icmp6_hdr));
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf, off2 +
+ sizeof (struct icmp6_hdr)) == NULL)
return (PF_DROP);
- m_copyback(m, off, sizeof (struct icmp6_hdr),
- pd->hdr.icmp6);
- m_copyback(m, ipoff2, sizeof (h2_6), &h2_6);
- m_copyback(m, off2, sizeof (struct icmp6_hdr),
- &iih);
+ pbuf_copy_back(pbuf, off,
+ sizeof (struct icmp6_hdr), pd->hdr.icmp6);
+ pbuf_copy_back(pbuf, ipoff2, sizeof (h2_6),
+ &h2_6);
+ pbuf_copy_back(pbuf, off2,
+ sizeof (struct icmp6_hdr), &iih);
}
return (PF_PASS);
switch (pd2.af) {
#if INET
case AF_INET:
- m = pf_lazy_makewritable(pd, m,
- ipoff2 + sizeof (h2));
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ ipoff2 + sizeof (h2)) == NULL)
return (PF_DROP);
+ /*
+ * <XXXSCW>
+ * Xnu was missing the following...
+ */
+ pbuf_copy_back(pbuf, off, ICMP_MINLEN,
+ pd->hdr.icmp);
+ pbuf_copy_back(pbuf, ipoff2,
+ sizeof(h2), &h2);
+ break;
+ /*
+ * </XXXSCW>
+ */
#endif /* INET */
#if INET6
case AF_INET6:
- m = pf_lazy_makewritable(pd, m,
- ipoff2 + sizeof (h2_6));
- if (!m)
+ if (pf_lazy_makewritable(pd, pbuf,
+ ipoff2 + sizeof (h2_6)) == NULL)
return (PF_DROP);
- m_copyback(m, off,
- sizeof (struct icmp6_hdr),
- pd->hdr.icmp6);
- m_copyback(m, ipoff2, sizeof (h2_6),
- &h2_6);
+ pbuf_copy_back(pbuf, off,
+ sizeof (struct icmp6_hdr),
+ pd->hdr.icmp6);
+ pbuf_copy_back(pbuf, ipoff2,
+ sizeof (h2_6), &h2_6);
break;
#endif /* INET6 */
}
struct pf_state_peer *dst;
struct pf_state_key_cmp key;
struct pf_grev1_hdr *grev1 = pd->hdr.grev1;
- struct mbuf *m;
key.app_state = 0;
key.proto = IPPROTO_GRE;
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&pd->src->v4.s_addr,
+ pf_change_a(&pd->src->v4addr.s_addr,
pd->ip_sum,
- (*state)->state_key->gwy.addr.v4.s_addr, 0);
+ (*state)->state_key->gwy.addr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&pd->dst->v4.s_addr,
+ pf_change_a(&pd->dst->v4addr.s_addr,
pd->ip_sum,
- (*state)->state_key->lan.addr.v4.s_addr, 0);
+ (*state)->state_key->lan.addr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
}
}
- m = pf_lazy_makewritable(pd, pd->mp, off + sizeof (*grev1));
- if (!m)
+ if (pf_lazy_makewritable(pd, pd->mp, off + sizeof (*grev1)) ==
+ NULL)
return (PF_DROP);
- m_copyback(m, off, sizeof (*grev1), grev1);
+ pbuf_copy_back(pd->mp, off, sizeof (*grev1), grev1);
}
return (PF_PASS);
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&pd->src->v4.s_addr,
+ pf_change_a(&pd->src->v4addr.s_addr,
pd->ip_sum,
- (*state)->state_key->gwy.addr.v4.s_addr, 0);
+ (*state)->state_key->gwy.addr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&pd->dst->v4.s_addr,
+ pf_change_a(&pd->dst->v4addr.s_addr,
pd->ip_sum,
- (*state)->state_key->lan.addr.v4.s_addr, 0);
+ (*state)->state_key->lan.addr.v4addr.s_addr, 0);
break;
#endif /* INET */
#if INET6
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&pd->src->v4.s_addr,
+ pf_change_a(&pd->src->v4addr.s_addr,
pd->ip_sum,
- (*state)->state_key->gwy.addr.v4.s_addr,
+ (*state)->state_key->gwy.addr.v4addr.s_addr,
0);
break;
#endif /* INET */
switch (pd->af) {
#if INET
case AF_INET:
- pf_change_a(&pd->dst->v4.s_addr,
+ pf_change_a(&pd->dst->v4addr.s_addr,
pd->ip_sum,
- (*state)->state_key->lan.addr.v4.s_addr,
+ (*state)->state_key->lan.addr.v4addr.s_addr,
0);
break;
#endif /* INET */
* h must be at "ipoff" on the mbuf chain.
*/
void *
-pf_pull_hdr(struct mbuf *m, int off, void *p, int len,
+pf_pull_hdr(pbuf_t *pbuf, int off, void *p, int len,
u_short *actionp, u_short *reasonp, sa_family_t af)
{
switch (af) {
#if INET
case AF_INET: {
- struct ip *h = mtod(m, struct ip *);
+ struct ip *h = pbuf->pb_data;
u_int16_t fragoff = (ntohs(h->ip_off) & IP_OFFMASK) << 3;
if (fragoff) {
}
return (NULL);
}
- if (m->m_pkthdr.len < off + len ||
+ if (pbuf->pb_packet_len < (unsigned)(off + len) ||
ntohs(h->ip_len) < off + len) {
ACTION_SET(actionp, PF_DROP);
REASON_SET(reasonp, PFRES_SHORT);
#endif /* INET */
#if INET6
case AF_INET6: {
- struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
+ struct ip6_hdr *h = pbuf->pb_data;
- if (m->m_pkthdr.len < off + len ||
+ if (pbuf->pb_packet_len < (unsigned)(off + len) ||
(ntohs(h->ip6_plen) + sizeof (struct ip6_hdr)) <
(unsigned)(off + len)) {
ACTION_SET(actionp, PF_DROP);
}
#endif /* INET6 */
}
- m_copydata(m, off, len, p);
+ pbuf_copy_data(pbuf, off, len, p);
return (p);
}
dst = satosin(&ro.ro_dst);
dst->sin_family = AF_INET;
dst->sin_len = sizeof (*dst);
- dst->sin_addr = addr->v4;
+ dst->sin_addr = addr->v4addr;
break;
#if INET6
case AF_INET6:
dst6 = (struct sockaddr_in6 *)&ro.ro_dst;
dst6->sin6_family = AF_INET6;
dst6->sin6_len = sizeof (*dst6);
- dst6->sin6_addr = addr->v6;
+ dst6->sin6_addr = addr->v6addr;
break;
#endif /* INET6 */
default:
dst = satosin(&ro.ro_dst);
dst->sin_family = AF_INET;
dst->sin_len = sizeof (*dst);
- dst->sin_addr = addr->v4;
+ dst->sin_addr = addr->v4addr;
break;
#if INET6
case AF_INET6:
dst6 = (struct sockaddr_in6 *)&ro.ro_dst;
dst6->sin6_family = AF_INET6;
dst6->sin6_len = sizeof (*dst6);
- dst6->sin6_addr = addr->v6;
+ dst6->sin6_addr = addr->v6addr;
break;
#endif /* INET6 */
default:
#if INET
static void
-pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
+pf_route(pbuf_t **pbufp, struct pf_rule *r, int dir, struct ifnet *oifp,
struct pf_state *s, struct pf_pdesc *pd)
{
#pragma unused(pd)
struct pf_src_node *sn = NULL;
int error = 0;
uint32_t sw_csum;
-
+ int interface_mtu = 0;
bzero(&iproute, sizeof (iproute));
- if (m == NULL || *m == NULL || r == NULL ||
+ if (pbufp == NULL || !pbuf_is_valid(*pbufp) || r == NULL ||
(dir != PF_IN && dir != PF_OUT) || oifp == NULL)
panic("pf_route: invalid parameters");
if (pd->pf_mtag->pftag_routed++ > 3) {
- m0 = *m;
- *m = NULL;
+ pbuf_destroy(*pbufp);
+ *pbufp = NULL;
+ m0 = NULL;
goto bad;
}
- if (r->rt == PF_DUPTO) {
- if ((m0 = m_copym(*m, 0, M_COPYALL, M_NOWAIT)) == NULL)
- return;
- } else {
- if ((r->rt == PF_REPLYTO) == (r->direction == dir))
- return;
- m0 = *m;
+ /*
+ * Since this is something of an edge case and may involve the
+ * host stack (for routing, at least for now), we convert the
+ * incoming pbuf into an mbuf.
+ */
+ if (r->rt == PF_DUPTO)
+ m0 = pbuf_clone_to_mbuf(*pbufp);
+ else
+ if ((r->rt == PF_REPLYTO) == (r->direction == dir))
+ return;
+ else {
+ /* We're going to consume this packet */
+ m0 = pbuf_to_mbuf(*pbufp, TRUE);
+ *pbufp = NULL;
}
+ if (m0 == NULL)
+ goto bad;
+
+ /* We now have the packet in an mbuf (m0) */
+
if (m0->m_len < (int)sizeof (struct ip)) {
DPFPRINTF(PF_DEBUG_URGENT,
- ("pf_route: m0->m_len < sizeof (struct ip)\n"));
+ ("pf_route: packet length < sizeof (struct ip)\n"));
goto bad;
}
pf_map_addr(AF_INET, r, (struct pf_addr *)&ip->ip_src,
&naddr, NULL, &sn);
if (!PF_AZERO(&naddr, AF_INET))
- dst->sin_addr.s_addr = naddr.v4.s_addr;
+ dst->sin_addr.s_addr = naddr.v4addr.s_addr;
ifp = r->rpool.cur->kif ?
r->rpool.cur->kif->pfik_ifp : NULL;
} else {
if (!PF_AZERO(&s->rt_addr, AF_INET))
dst->sin_addr.s_addr =
- s->rt_addr.v4.s_addr;
+ s->rt_addr.v4addr.s_addr;
ifp = s->rt_kif ? s->rt_kif->pfik_ifp : NULL;
}
}
goto bad;
if (oifp != ifp) {
- if (pf_test(PF_OUT, ifp, &m0, NULL, NULL) != PF_PASS)
+ if (pf_test_mbuf(PF_OUT, ifp, &m0, NULL, NULL) != PF_PASS)
goto bad;
else if (m0 == NULL)
goto done;
if (m0->m_len < (int)sizeof (struct ip)) {
DPFPRINTF(PF_DEBUG_URGENT,
- ("pf_route: m0->m_len < sizeof (struct ip)\n"));
+ ("pf_route: packet length < sizeof (struct ip)\n"));
goto bad;
}
ip = mtod(m0, struct ip *);
ip_output_checksum(ifp, m0, ((ip->ip_hl) << 2), ntohs(ip->ip_len),
&sw_csum);
- if (ntohs(ip->ip_len) <= ifp->if_mtu || TSO_IPV4_OK(ifp, m0) ||
+ interface_mtu = ifp->if_mtu;
+
+ if (INTF_ADJUST_MTU_FOR_CLAT46(ifp)) {
+ interface_mtu = IN6_LINKMTU(ifp);
+ /* Further adjust the size for CLAT46 expansion */
+ interface_mtu -= CLAT46_HDR_EXPANSION_OVERHD;
+ }
+
+ if (ntohs(ip->ip_len) <= interface_mtu || TSO_IPV4_OK(ifp, m0) ||
(!(ip->ip_off & htons(IP_DF)) &&
(ifp->if_hwassist & CSUM_FRAGMENT))) {
ip->ip_sum = 0;
ipstat.ips_cantfrag++;
if (r->rt != PF_DUPTO) {
icmp_error(m0, ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG, 0,
- ifp->if_mtu);
+ interface_mtu);
goto done;
} else
goto bad;
NTOHS(ip->ip_off);
NTOHS(ip->ip_len);
#endif
- error = ip_fragment(m0, ifp, ifp->if_mtu, sw_csum);
+ error = ip_fragment(m0, ifp, interface_mtu, sw_csum);
if (error) {
m0 = NULL;
ipstat.ips_fragmented++;
done:
- if (r->rt != PF_DUPTO)
- *m = NULL;
-
ROUTE_RELEASE(&iproute);
return;
bad:
- m_freem(m0);
+ if (m0)
+ m_freem(m0);
goto done;
}
#endif /* INET */
#if INET6
static void
-pf_route6(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
+pf_route6(pbuf_t **pbufp, struct pf_rule *r, int dir, struct ifnet *oifp,
struct pf_state *s, struct pf_pdesc *pd)
{
#pragma unused(pd)
struct pf_src_node *sn = NULL;
int error = 0;
- if (m == NULL || *m == NULL || r == NULL ||
+ if (pbufp == NULL || !pbuf_is_valid(*pbufp) || r == NULL ||
(dir != PF_IN && dir != PF_OUT) || oifp == NULL)
panic("pf_route6: invalid parameters");
if (pd->pf_mtag->pftag_routed++ > 3) {
- m0 = *m;
- *m = NULL;
+ pbuf_destroy(*pbufp);
+ *pbufp = NULL;
+ m0 = NULL;
goto bad;
}
+ /*
+ * Since this is something of an edge case and may involve the
+ * host stack (for routing, at least for now), we convert the
+ * incoming pbuf into an mbuf.
+ */
if (r->rt == PF_DUPTO) {
- if ((m0 = m_copym(*m, 0, M_COPYALL, M_NOWAIT)) == NULL)
- return;
- } else {
- if ((r->rt == PF_REPLYTO) == (r->direction == dir))
- return;
- m0 = *m;
+ m0 = pbuf_clone_to_mbuf(*pbufp);
+ } else
+ if ((r->rt == PF_REPLYTO) == (r->direction == dir))
+ return;
+ else {
+ /* We're about to consume this packet */
+ m0 = pbuf_to_mbuf(*pbufp, TRUE);
+ *pbufp = NULL;
}
+ if (m0 == NULL)
+ goto bad;
+
if (m0->m_len < (int)sizeof (struct ip6_hdr)) {
DPFPRINTF(PF_DEBUG_URGENT,
("pf_route6: m0->m_len < sizeof (struct ip6_hdr)\n"));
dst->sin6_len = sizeof (*dst);
dst->sin6_addr = ip6->ip6_dst;
- /* Cheat. XXX why only in the v6 case??? */
+ /* Cheat. XXX why only in the v6addr case??? */
if (r->rt == PF_FASTROUTE) {
struct pf_mtag *pf_mtag;
goto bad;
}
if (s == NULL) {
- pf_map_addr(AF_INET6, r, (struct pf_addr *)&ip6->ip6_src,
+ pf_map_addr(AF_INET6, r, (struct pf_addr *)(uintptr_t)&ip6->ip6_src,
&naddr, NULL, &sn);
if (!PF_AZERO(&naddr, AF_INET6))
PF_ACPY((struct pf_addr *)&dst->sin6_addr,
goto bad;
if (oifp != ifp) {
- if (pf_test6(PF_OUT, ifp, &m0, NULL, NULL) != PF_PASS)
+ if (pf_test6_mbuf(PF_OUT, ifp, &m0, NULL, NULL) != PF_PASS)
goto bad;
else if (m0 == NULL)
goto done;
}
done:
- if (r->rt != PF_DUPTO)
- *m = NULL;
return;
bad:
- m_freem(m0);
+ if (m0)
+ m_freem(m0);
goto done;
}
#endif /* INET6 */
* returns 0 when the checksum is valid, otherwise returns 1.
*/
static int
-pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p,
+pf_check_proto_cksum(pbuf_t *pbuf, int off, int len, u_int8_t p,
sa_family_t af)
{
u_int16_t sum;
* is partially-computed (only 16-bit summation), do it in
* software below.
*/
- if ((m->m_pkthdr.csum_flags &
+ if ((*pbuf->pb_csum_flags &
(CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
(CSUM_DATA_VALID | CSUM_PSEUDO_HDR) &&
- (m->m_pkthdr.csum_data ^ 0xffff) == 0) {
+ (*pbuf->pb_csum_data ^ 0xffff) == 0) {
return (0);
}
break;
}
if (off < (int)sizeof (struct ip) || len < (int)sizeof (struct udphdr))
return (1);
- if (m->m_pkthdr.len < off + len)
+ if (pbuf->pb_packet_len < (unsigned)(off + len))
return (1);
switch (af) {
#if INET
case AF_INET:
if (p == IPPROTO_ICMP) {
+#if 0
if (m->m_len < off)
return (1);
m->m_data += off;
sum = in_cksum(m, len);
m->m_data -= off;
m->m_len += off;
+#else
+ if (pbuf->pb_contig_len < (unsigned)off)
+ return (1);
+ sum = pbuf_inet_cksum(pbuf, 0, off, len);
+#endif
} else {
- if (m->m_len < (int)sizeof (struct ip))
+ if (pbuf->pb_contig_len < (int)sizeof (struct ip))
return (1);
- sum = inet_cksum(m, p, off, len);
+ sum = pbuf_inet_cksum(pbuf, p, off, len);
}
break;
#endif /* INET */
#if INET6
case AF_INET6:
- if (m->m_len < (int)sizeof (struct ip6_hdr))
+ if (pbuf->pb_contig_len < (int)sizeof (struct ip6_hdr))
return (1);
- sum = inet6_cksum(m, p, off, len);
+ sum = pbuf_inet6_cksum(pbuf, p, off, len);
break;
#endif /* INET6 */
default:
#if INET
#define PF_APPLE_UPDATE_PDESC_IPv4() \
do { \
- if (m && pd.mp && m != pd.mp) { \
- m = pd.mp; \
- h = mtod(m, struct ip *); \
- pd.pf_mtag = pf_get_mtag(m); \
+ if (pbuf && pd.mp && pbuf != pd.mp) { \
+ pbuf = pd.mp; \
+ h = pbuf->pb_data; \
+ pd.pf_mtag = pf_get_mtag_pbuf(pbuf); \
} \
} while (0)
int
-pf_test(int dir, struct ifnet *ifp, struct mbuf **m0,
+pf_test_mbuf(int dir, struct ifnet *ifp, struct mbuf **m0,
+ struct ether_header *eh, struct ip_fw_args *fwa)
+{
+ pbuf_t pbuf_store, *pbuf;
+ int rv;
+
+ pbuf_init_mbuf(&pbuf_store, *m0, (*m0)->m_pkthdr.rcvif);
+ pbuf = &pbuf_store;
+
+ rv = pf_test(dir, ifp, &pbuf, eh, fwa);
+
+ if (pbuf_is_valid(pbuf)) {
+ *m0 = pbuf->pb_mbuf;
+ pbuf->pb_mbuf = NULL;
+ pbuf_destroy(pbuf);
+ } else
+ *m0 = NULL;
+
+ return (rv);
+}
+
+int
+pf_test(int dir, struct ifnet *ifp, pbuf_t **pbufp,
struct ether_header *eh, struct ip_fw_args *fwa)
{
#if !DUMMYNET
#endif
struct pfi_kif *kif;
u_short action = PF_PASS, reason = 0, log = 0;
- struct mbuf *m = *m0;
+ pbuf_t *pbuf = *pbufp;
struct ip *h = 0;
struct pf_rule *a = NULL, *r = &pf_default_rule, *tr, *nr;
struct pf_state *s = NULL;
struct pf_pdesc pd;
int off, dirndx, pqid = 0;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (!pf_status.running)
return (PF_PASS);
memset(&pd, 0, sizeof (pd));
- if ((pd.pf_mtag = pf_get_mtag(m)) == NULL) {
+ if ((pd.pf_mtag = pf_get_mtag_pbuf(pbuf)) == NULL) {
DPFPRINTF(PF_DEBUG_URGENT,
- ("pf_test: pf_get_mtag returned NULL\n"));
+ ("pf_test: pf_get_mtag_pbuf returned NULL\n"));
return (PF_DROP);
}
if (kif->pfik_flags & PFI_IFLAG_SKIP)
return (PF_PASS);
- VERIFY(m->m_flags & M_PKTHDR);
-
/* initialize enough of pd for the done label */
- h = mtod(m, struct ip *);
- pd.mp = m;
+ h = pbuf->pb_data;
+ pd.mp = pbuf;
pd.lmw = 0;
- pd.pf_mtag = pf_get_mtag(m);
+ pd.pf_mtag = pf_get_mtag_pbuf(pbuf);
pd.src = (struct pf_addr *)&h->ip_src;
pd.dst = (struct pf_addr *)&h->ip_dst;
PF_ACPY(&pd.baddr, pd.src, AF_INET);
pd.tot_len = ntohs(h->ip_len);
pd.eh = eh;
- if (m->m_pkthdr.len < (int)sizeof (*h)) {
+ if (pbuf->pb_packet_len < (int)sizeof (*h)) {
action = PF_DROP;
REASON_SET(&reason, PFRES_SHORT);
log = 1;
#endif /* DUMMYNET */
/* We do IP header normalization and packet reassembly here */
- action = pf_normalize_ip(m0, dir, kif, &reason, &pd);
- pd.mp = m = *m0;
+ action = pf_normalize_ip(pbuf, dir, kif, &reason, &pd);
if (action != PF_PASS || pd.lmw < 0) {
action = PF_DROP;
goto done;
#if DUMMYNET
nonormalize:
#endif /* DUMMYNET */
- m = *m0; /* pf_normalize messes with m0 */
- h = mtod(m, struct ip *);
+ /* pf_normalize can mess with pb_data */
+ h = pbuf->pb_data;
off = h->ip_hl << 2;
if (off < (int)sizeof (*h)) {
pd.ip_sum = &h->ip_sum;
pd.proto = h->ip_p;
pd.proto_variant = 0;
- pd.mp = m;
+ pd.mp = pbuf;
pd.lmw = 0;
- pd.pf_mtag = pf_get_mtag(m);
+ pd.pf_mtag = pf_get_mtag_pbuf(pbuf);
pd.af = AF_INET;
pd.tos = h->ip_tos;
pd.ttl = h->ip_ttl;
- pd.sc = MBUF_SCIDX(mbuf_get_service_class(m));
+ pd.sc = MBUF_SCIDX(pbuf_get_service_class(pbuf));
pd.tot_len = ntohs(h->ip_len);
pd.eh = eh;
- if (m->m_pkthdr.pkt_flags & PKTF_FLOW_ID) {
- pd.flowsrc = m->m_pkthdr.pkt_flowsrc;
- pd.flowhash = m->m_pkthdr.pkt_flowid;
- pd.pktflags = (m->m_pkthdr.pkt_flags & PKTF_FLOW_MASK);
+ if (*pbuf->pb_flags & PKTF_FLOW_ID) {
+ pd.flowsrc = *pbuf->pb_flowsrc;
+ pd.flowhash = *pbuf->pb_flowid;
+ pd.pktflags = *pbuf->pb_flags & PKTF_FLOW_MASK;
}
/* handle fragments that didn't get reassembled by normalization */
pd.flags |= PFDESC_IP_FRAG;
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_test_fragment(&r, dir, kif, m, h,
+ action = pf_test_fragment(&r, dir, kif, pbuf, h,
&pd, &a, &ruleset);
goto done;
}
case IPPROTO_TCP: {
struct tcphdr th;
pd.hdr.tcp = &th;
- if (!pf_pull_hdr(m, off, &th, sizeof (th),
+ if (!pf_pull_hdr(pbuf, off, &th, sizeof (th),
&action, &reason, AF_INET)) {
log = action != PF_PASS;
goto done;
pqid = 1;
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_normalize_tcp(dir, kif, m, 0, off, h, &pd);
+ action = pf_normalize_tcp(dir, kif, pbuf, 0, off, h, &pd);
if (pd.lmw < 0)
goto done;
PF_APPLE_UPDATE_PDESC_IPv4();
if (action == PF_DROP)
goto done;
- action = pf_test_state_tcp(&s, dir, kif, m, off, h, &pd,
+ action = pf_test_state_tcp(&s, dir, kif, pbuf, off, h, &pd,
&reason);
if (action == PF_NAT64)
goto done;
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct udphdr uh;
pd.hdr.udp = &uh;
- if (!pf_pull_hdr(m, off, &uh, sizeof (uh),
+ if (!pf_pull_hdr(pbuf, off, &uh, sizeof (uh),
&action, &reason, AF_INET)) {
log = action != PF_PASS;
goto done;
}
if (uh.uh_dport == 0 ||
- ntohs(uh.uh_ulen) > m->m_pkthdr.len - off ||
+ ntohs(uh.uh_ulen) > pbuf->pb_packet_len - off ||
ntohs(uh.uh_ulen) < sizeof (struct udphdr)) {
action = PF_DROP;
REASON_SET(&reason, PFRES_SHORT);
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_test_state_udp(&s, dir, kif, m, off, h, &pd,
+ action = pf_test_state_udp(&s, dir, kif, pbuf, off, h, &pd,
&reason);
if (action == PF_NAT64)
goto done;
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct icmp ih;
pd.hdr.icmp = &ih;
- if (!pf_pull_hdr(m, off, &ih, ICMP_MINLEN,
+ if (!pf_pull_hdr(pbuf, off, &ih, ICMP_MINLEN,
&action, &reason, AF_INET)) {
log = action != PF_PASS;
goto done;
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_test_state_icmp(&s, dir, kif, m, off, h, &pd,
+ action = pf_test_state_icmp(&s, dir, kif, pbuf, off, h, &pd,
&reason);
if (action == PF_NAT64)
goto done;
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct pf_esp_hdr esp;
pd.hdr.esp = &esp;
- if (!pf_pull_hdr(m, off, &esp, sizeof (esp), &action, &reason,
+ if (!pf_pull_hdr(pbuf, off, &esp, sizeof (esp), &action, &reason,
AF_INET)) {
log = action != PF_PASS;
goto done;
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
case IPPROTO_GRE: {
struct pf_grev1_hdr grev1;
pd.hdr.grev1 = &grev1;
- if (!pf_pull_hdr(m, off, &grev1, sizeof (grev1), &action,
+ if (!pf_pull_hdr(pbuf, off, &grev1, sizeof (grev1), &action,
&reason, AF_INET)) {
log = (action != PF_PASS);
goto done;
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
if ((ntohs(grev1.flags) & PF_GRE_FLAG_VERSION_MASK) == 1 &&
ntohs(grev1.protocol_type) == PF_GRE_PPP_ETHERTYPE) {
if (ntohs(grev1.payload_length) >
- m->m_pkthdr.len - off) {
+ pbuf->pb_packet_len - off) {
action = PF_DROP;
REASON_SET(&reason, PFRES_SHORT);
goto done;
log = s->log;
break;
} else if (s == NULL) {
- action = pf_test_rule(&r, &s, dir, kif, m, off,
- h, &pd, &a, &ruleset, NULL);
+ action = pf_test_rule(&r, &s, dir, kif, pbuf,
+ off, h, &pd, &a, &ruleset, NULL);
if (action == PF_PASS)
break;
}
default:
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
a = s->anchor.ptr;
log = s->log;
} else if (s == NULL)
- action = pf_test_rule(&r, &s, dir, kif, m, off, h,
+ action = pf_test_rule(&r, &s, dir, kif, pbuf, off, h,
&pd, &a, &ruleset, NULL);
break;
}
done:
if (action == PF_NAT64) {
- *m0 = NULL;
+ *pbufp = NULL;
return (action);
}
- *m0 = pd.mp;
+ *pbufp = pd.mp;
PF_APPLE_UPDATE_PDESC_IPv4();
if (action != PF_DROP) {
if ((s && s->tag) || PF_RTABLEID_IS_VALID(r->rtableid) ||
(pd.pktflags & PKTF_FLOW_ID))
- (void) pf_tag_packet(m, pd.pf_mtag, s ? s->tag : 0,
+ (void) pf_tag_packet(pbuf, pd.pf_mtag, s ? s->tag : 0,
r->rtableid, &pd);
if (action == PF_PASS) {
-#if PF_ALTQ
- if (altq_allowed && r->qid) {
- if (pqid || (pd.tos & IPTOS_LOWDELAY))
- pd.pf_mtag->pftag_qid = r->pqid;
- else
- pd.pf_mtag->pftag_qid = r->qid;
- }
-#endif /* PF_ALTQ */
#if PF_ECN
/* add hints for ecn */
pd.pf_mtag->pftag_hdr = h;
pd.pf_mtag->pftag_flags |= PF_TAG_HDR_INET;
#endif /* PF_ECN */
/* record protocol */
- m->m_pkthdr.pkt_proto = pd.proto;
+ *pbuf->pb_proto = pd.proto;
/*
* connections redirected to loopback should not match sockets
s->nat_rule.ptr != NULL &&
(s->nat_rule.ptr->action == PF_RDR ||
s->nat_rule.ptr->action == PF_BINAT) &&
- (ntohl(pd.dst->v4.s_addr) >> IN_CLASSA_NSHIFT)
+ (ntohl(pd.dst->v4addr.s_addr) >> IN_CLASSA_NSHIFT)
== IN_LOOPBACKNET)
pd.pf_mtag->pftag_flags |= PF_TAG_TRANSLATE_LOCALHOST;
}
lr = s->nat_rule.ptr;
else
lr = r;
- PFLOG_PACKET(kif, h, m, AF_INET, dir, reason, lr, a, ruleset,
+ PFLOG_PACKET(kif, h, pbuf, AF_INET, dir, reason, lr, a, ruleset,
&pd);
}
tr->dst.neg);
}
- VERIFY(m == NULL || pd.mp == NULL || pd.mp == m);
+ VERIFY(pbuf == NULL || pd.mp == NULL || pd.mp == pbuf);
- if (*m0) {
+ if (*pbufp) {
if (pd.lmw < 0) {
REASON_SET(&reason, PFRES_MEMORY);
action = PF_DROP;
}
if (action == PF_DROP) {
- m_freem(*m0);
- *m0 = NULL;
+ pbuf_destroy(*pbufp);
+ *pbufp = NULL;
return (PF_DROP);
}
- *m0 = m;
+ *pbufp = pbuf;
}
if (action == PF_SYNPROXY_DROP) {
- m_freem(*m0);
- *m0 = NULL;
+ pbuf_destroy(*pbufp);
+ *pbufp = NULL;
action = PF_PASS;
} else if (r->rt)
- /* pf_route can free the mbuf causing *m0 to become NULL */
- pf_route(m0, r, dir, kif->pfik_ifp, s, &pd);
+ /* pf_route can free the pbuf causing *pbufp to become NULL */
+ pf_route(pbufp, r, dir, kif->pfik_ifp, s, &pd);
return (action);
}
#if INET6
#define PF_APPLE_UPDATE_PDESC_IPv6() \
do { \
- if (m && pd.mp && m != pd.mp) { \
- if (n == m) \
- n = pd.mp; \
- m = pd.mp; \
- h = mtod(m, struct ip6_hdr *); \
+ if (pbuf && pd.mp && pbuf != pd.mp) { \
+ pbuf = pd.mp; \
} \
+ h = pbuf->pb_data; \
} while (0)
int
-pf_test6(int dir, struct ifnet *ifp, struct mbuf **m0,
+pf_test6_mbuf(int dir, struct ifnet *ifp, struct mbuf **m0,
+ struct ether_header *eh, struct ip_fw_args *fwa)
+{
+ pbuf_t pbuf_store, *pbuf;
+ int rv;
+
+ pbuf_init_mbuf(&pbuf_store, *m0, (*m0)->m_pkthdr.rcvif);
+ pbuf = &pbuf_store;
+
+ rv = pf_test6(dir, ifp, &pbuf, eh, fwa);
+
+ if (pbuf_is_valid(pbuf)) {
+ *m0 = pbuf->pb_mbuf;
+ pbuf->pb_mbuf = NULL;
+ pbuf_destroy(pbuf);
+ } else
+ *m0 = NULL;
+
+ return (rv);
+}
+
+int
+pf_test6(int dir, struct ifnet *ifp, pbuf_t **pbufp,
struct ether_header *eh, struct ip_fw_args *fwa)
{
#if !DUMMYNET
#endif
struct pfi_kif *kif;
u_short action = PF_PASS, reason = 0, log = 0;
- struct mbuf *m = *m0, *n = NULL;
+ pbuf_t *pbuf = *pbufp;
struct ip6_hdr *h;
struct pf_rule *a = NULL, *r = &pf_default_rule, *tr, *nr;
struct pf_state *s = NULL;
int off, terminal = 0, dirndx, rh_cnt = 0;
u_int8_t nxt;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (!pf_status.running)
return (PF_PASS);
memset(&pd, 0, sizeof (pd));
- if ((pd.pf_mtag = pf_get_mtag(m)) == NULL) {
+ if ((pd.pf_mtag = pf_get_mtag_pbuf(pbuf)) == NULL) {
DPFPRINTF(PF_DEBUG_URGENT,
- ("pf_test6: pf_get_mtag returned NULL\n"));
+ ("pf_test6: pf_get_mtag_pbuf returned NULL\n"));
return (PF_DROP);
}
if (kif->pfik_flags & PFI_IFLAG_SKIP)
return (PF_PASS);
- VERIFY(m->m_flags & M_PKTHDR);
-
- h = mtod(m, struct ip6_hdr *);
+ h = pbuf->pb_data;
nxt = h->ip6_nxt;
- off = ((caddr_t)h - m->m_data) + sizeof(struct ip6_hdr);
- pd.mp = m;
+ off = ((caddr_t)h - (caddr_t)pbuf->pb_data) + sizeof(struct ip6_hdr);
+ pd.mp = pbuf;
pd.lmw = 0;
- pd.pf_mtag = pf_get_mtag(m);
- pd.src = (struct pf_addr *)&h->ip6_src;
- pd.dst = (struct pf_addr *)&h->ip6_dst;
+ pd.pf_mtag = pf_get_mtag_pbuf(pbuf);
+ pd.src = (struct pf_addr *)(uintptr_t)&h->ip6_src;
+ pd.dst = (struct pf_addr *)(uintptr_t)&h->ip6_dst;
PF_ACPY(&pd.baddr, pd.src, AF_INET6);
PF_ACPY(&pd.bdaddr, pd.dst, AF_INET6);
pd.ip_sum = NULL;
pd.proto_variant = 0;
pd.tos = 0;
pd.ttl = h->ip6_hlim;
- pd.sc = MBUF_SCIDX(mbuf_get_service_class(m));
+ pd.sc = MBUF_SCIDX(pbuf_get_service_class(pbuf));
pd.tot_len = ntohs(h->ip6_plen) + sizeof(struct ip6_hdr);
pd.eh = eh;
- if (m->m_pkthdr.pkt_flags & PKTF_FLOW_ID) {
- pd.flowsrc = m->m_pkthdr.pkt_flowsrc;
- pd.flowhash = m->m_pkthdr.pkt_flowid;
- pd.pktflags = (m->m_pkthdr.pkt_flags & PKTF_FLOW_MASK);
+ if (*pbuf->pb_flags & PKTF_FLOW_ID) {
+ pd.flowsrc = *pbuf->pb_flowsrc;
+ pd.flowhash = *pbuf->pb_flowid;
+ pd.pktflags = (*pbuf->pb_flags & PKTF_FLOW_MASK);
}
- if (m->m_pkthdr.len < (int)sizeof (*h)) {
+ if (pbuf->pb_packet_len < (int)sizeof (*h)) {
action = PF_DROP;
REASON_SET(&reason, PFRES_SHORT);
log = 1;
#endif /* DUMMYNET */
/* We do IP header normalization and packet reassembly here */
- action = pf_normalize_ip6(m0, dir, kif, &reason, &pd);
- pd.mp = m = *m0;
+ action = pf_normalize_ip6(pbuf, dir, kif, &reason, &pd);
if (action != PF_PASS || pd.lmw < 0) {
action = PF_DROP;
goto done;
#if DUMMYNET
nonormalize:
#endif /* DUMMYNET */
- h = mtod(m, struct ip6_hdr *);
+ h = pbuf->pb_data;
#if 1
/*
}
#endif
- pd.src = (struct pf_addr *)&h->ip6_src;
- pd.dst = (struct pf_addr *)&h->ip6_dst;
+ pd.src = (struct pf_addr *)(uintptr_t)&h->ip6_src;
+ pd.dst = (struct pf_addr *)(uintptr_t)&h->ip6_dst;
PF_ACPY(&pd.baddr, pd.src, AF_INET6);
PF_ACPY(&pd.bdaddr, pd.dst, AF_INET6);
pd.ip_sum = NULL;
pd.tot_len = ntohs(h->ip6_plen) + sizeof (struct ip6_hdr);
pd.eh = eh;
- off = ((caddr_t)h - m->m_data) + sizeof (struct ip6_hdr);
+ off = ((caddr_t)h - (caddr_t)pbuf->pb_data) + sizeof (struct ip6_hdr);
pd.proto = h->ip6_nxt;
pd.proto_variant = 0;
- pd.mp = m;
+ pd.mp = pbuf;
pd.lmw = 0;
- pd.pf_mtag = pf_get_mtag(m);
+ pd.pf_mtag = pf_get_mtag_pbuf(pbuf);
do {
switch (nxt) {
struct ip6_frag ip6f;
pd.flags |= PFDESC_IP_FRAG;
- if (!pf_pull_hdr(m, off, &ip6f, sizeof ip6f, NULL,
+ if (!pf_pull_hdr(pbuf, off, &ip6f, sizeof ip6f, NULL,
&reason, pd.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: IPv6 short fragment header\n"));
pd.proto = nxt = ip6f.ip6f_nxt;
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd,
+ fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_test_fragment(&r, dir, kif, m, h, &pd, &a,
- &ruleset);
+ action = pf_test_fragment(&r, dir, kif, pbuf, h, &pd,
+ &a, &ruleset);
if (action == PF_DROP) {
REASON_SET(&reason, PFRES_FRAG);
log = 1;
/* get next header and header length */
struct ip6_ext opt6;
- if (!pf_pull_hdr(m, off, &opt6, sizeof(opt6),
+ if (!pf_pull_hdr(pbuf, off, &opt6, sizeof(opt6),
NULL, &reason, pd.af)) {
DPFPRINTF(PF_DEBUG_MISC,
("pf: IPv6 short opt\n"));
}
} while (!terminal);
- /* if there's no routing header, use unmodified mbuf for checksumming */
- if (!n)
- n = m;
switch (pd.proto) {
struct tcphdr th;
pd.hdr.tcp = &th;
- if (!pf_pull_hdr(m, off, &th, sizeof (th),
+ if (!pf_pull_hdr(pbuf, off, &th, sizeof (th),
&action, &reason, AF_INET6)) {
log = action != PF_PASS;
goto done;
pd.p_len = pd.tot_len - off - (th.th_off << 2);
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_normalize_tcp(dir, kif, m, 0, off, h, &pd);
+ action = pf_normalize_tcp(dir, kif, pbuf, 0, off, h, &pd);
if (pd.lmw < 0)
goto done;
PF_APPLE_UPDATE_PDESC_IPv6();
if (action == PF_DROP)
goto done;
- action = pf_test_state_tcp(&s, dir, kif, m, off, h, &pd,
+ action = pf_test_state_tcp(&s, dir, kif, pbuf, off, h, &pd,
&reason);
if (action == PF_NAT64)
goto done;
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct udphdr uh;
pd.hdr.udp = &uh;
- if (!pf_pull_hdr(m, off, &uh, sizeof (uh),
+ if (!pf_pull_hdr(pbuf, off, &uh, sizeof (uh),
&action, &reason, AF_INET6)) {
log = action != PF_PASS;
goto done;
}
if (uh.uh_dport == 0 ||
- ntohs(uh.uh_ulen) > m->m_pkthdr.len - off ||
+ ntohs(uh.uh_ulen) > pbuf->pb_packet_len - off ||
ntohs(uh.uh_ulen) < sizeof (struct udphdr)) {
action = PF_DROP;
REASON_SET(&reason, PFRES_SHORT);
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
- action = pf_test_state_udp(&s, dir, kif, m, off, h, &pd,
+ action = pf_test_state_udp(&s, dir, kif, pbuf, off, h, &pd,
&reason);
if (action == PF_NAT64)
goto done;
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct icmp6_hdr ih;
pd.hdr.icmp6 = &ih;
- if (!pf_pull_hdr(m, off, &ih, sizeof (ih),
+ if (!pf_pull_hdr(pbuf, off, &ih, sizeof (ih),
&action, &reason, AF_INET6)) {
log = action != PF_PASS;
goto done;
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
action = pf_test_state_icmp(&s, dir, kif,
- m, off, h, &pd, &reason);
+ pbuf, off, h, &pd, &reason);
if (action == PF_NAT64)
goto done;
if (pd.lmw < 0)
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct pf_esp_hdr esp;
pd.hdr.esp = &esp;
- if (!pf_pull_hdr(m, off, &esp, sizeof (esp), &action, &reason,
- AF_INET6)) {
+ if (!pf_pull_hdr(pbuf, off, &esp, sizeof (esp), &action,
+ &reason, AF_INET6)) {
log = action != PF_PASS;
goto done;
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
log = s->log;
} else if (s == NULL)
action = pf_test_rule(&r, &s, dir, kif,
- m, off, h, &pd, &a, &ruleset, NULL);
+ pbuf, off, h, &pd, &a, &ruleset, NULL);
break;
}
struct pf_grev1_hdr grev1;
pd.hdr.grev1 = &grev1;
- if (!pf_pull_hdr(m, off, &grev1, sizeof (grev1), &action,
+ if (!pf_pull_hdr(pbuf, off, &grev1, sizeof (grev1), &action,
&reason, AF_INET6)) {
log = (action != PF_PASS);
goto done;
}
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
if ((ntohs(grev1.flags) & PF_GRE_FLAG_VERSION_MASK) == 1 &&
ntohs(grev1.protocol_type) == PF_GRE_PPP_ETHERTYPE) {
if (ntohs(grev1.payload_length) >
- m->m_pkthdr.len - off) {
+ pbuf->pb_packet_len - off) {
action = PF_DROP;
REASON_SET(&reason, PFRES_SHORT);
goto done;
log = s->log;
break;
} else if (s == NULL) {
- action = pf_test_rule(&r, &s, dir, kif, m, off,
- h, &pd, &a, &ruleset, NULL);
+ action = pf_test_rule(&r, &s, dir, kif, pbuf,
+ off, h, &pd, &a, &ruleset, NULL);
if (action == PF_PASS)
break;
}
default:
#if DUMMYNET
/* Traffic goes through dummynet first */
- action = pf_test_dummynet(&r, dir, kif, &m, &pd, fwa);
- if (action == PF_DROP || m == NULL) {
- *m0 = NULL;
+ action = pf_test_dummynet(&r, dir, kif, &pbuf, &pd, fwa);
+ if (action == PF_DROP || pbuf == NULL) {
+ *pbufp = NULL;
return (action);
}
#endif /* DUMMYNET */
a = s->anchor.ptr;
log = s->log;
} else if (s == NULL)
- action = pf_test_rule(&r, &s, dir, kif, m, off, h,
+ action = pf_test_rule(&r, &s, dir, kif, pbuf, off, h,
&pd, &a, &ruleset, NULL);
break;
}
done:
if (action == PF_NAT64) {
- *m0 = NULL;
+ *pbufp = NULL;
return (action);
}
- *m0 = pd.mp;
+ *pbufp = pd.mp;
PF_APPLE_UPDATE_PDESC_IPv6();
- if (n != m) {
- m_freem(n);
- n = NULL;
- }
-
/* handle dangerous IPv6 extension headers. */
if (action != PF_DROP) {
if (action == PF_PASS && rh_cnt &&
REASON_SET(&reason, PFRES_IPOPTIONS);
log = 1;
DPFPRINTF(PF_DEBUG_MISC,
- ("pf: dropping packet with dangerous v6 headers\n"));
+ ("pf: dropping packet with dangerous v6addr headers\n"));
}
if ((s && s->tag) || PF_RTABLEID_IS_VALID(r->rtableid) ||
(pd.pktflags & PKTF_FLOW_ID))
- (void) pf_tag_packet(m, pd.pf_mtag, s ? s->tag : 0,
+ (void) pf_tag_packet(pbuf, pd.pf_mtag, s ? s->tag : 0,
r->rtableid, &pd);
if (action == PF_PASS) {
-#if PF_ALTQ
- if (altq_allowed && r->qid) {
- if (pd.tos & IPTOS_LOWDELAY)
- pd.pf_mtag->pftag_qid = r->pqid;
- else
- pd.pf_mtag->pftag_qid = r->qid;
- }
-#endif /* PF_ALTQ */
#if PF_ECN
/* add hints for ecn */
pd.pf_mtag->pftag_hdr = h;
pd.pf_mtag->pftag_flags |= PF_TAG_HDR_INET6;
#endif /* PF_ECN */
/* record protocol */
- m->m_pkthdr.pkt_proto = pd.proto;
+ *pbuf->pb_proto = pd.proto;
if (dir == PF_IN && (pd.proto == IPPROTO_TCP ||
pd.proto == IPPROTO_UDP) && s != NULL &&
s->nat_rule.ptr != NULL &&
(s->nat_rule.ptr->action == PF_RDR ||
s->nat_rule.ptr->action == PF_BINAT) &&
- IN6_IS_ADDR_LOOPBACK(&pd.dst->v6))
+ IN6_IS_ADDR_LOOPBACK(&pd.dst->v6addr))
pd.pf_mtag->pftag_flags |= PF_TAG_TRANSLATE_LOCALHOST;
}
}
lr = s->nat_rule.ptr;
else
lr = r;
- PFLOG_PACKET(kif, h, m, AF_INET6, dir, reason, lr, a, ruleset,
+ PFLOG_PACKET(kif, h, pbuf, AF_INET6, dir, reason, lr, a, ruleset,
&pd);
}
/* pf_route6 can free the mbuf causing *m0 to become NULL */
pf_route6(m0, r, dir, kif->pfik_ifp, s, &pd);
#else
- VERIFY(m == NULL || pd.mp == NULL || pd.mp == m);
+ VERIFY(pbuf == NULL || pd.mp == NULL || pd.mp == pbuf);
- if (*m0) {
+ if (*pbufp) {
if (pd.lmw < 0) {
REASON_SET(&reason, PFRES_MEMORY);
action = PF_DROP;
}
if (action == PF_DROP) {
- m_freem(*m0);
- *m0 = NULL;
+ pbuf_destroy(*pbufp);
+ *pbufp = NULL;
return (PF_DROP);
}
- *m0 = m;
+ *pbufp = pbuf;
}
if (action == PF_SYNPROXY_DROP) {
- m_freem(*m0);
- *m0 = NULL;
+ pbuf_destroy(*pbufp);
+ *pbufp = NULL;
action = PF_PASS;
} else if (r->rt) {
- if (action == PF_PASS) {
- m = *m0;
- h = mtod(m, struct ip6_hdr *);
- }
-
/* pf_route6 can free the mbuf causing *m0 to become NULL */
- pf_route6(m0, r, dir, kif->pfik_ifp, s, &pd);
+ pf_route6(pbufp, r, dir, kif->pfik_ifp, s, &pd);
}
#endif /* 0 */
{
void *buf;
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
if (pp->pool_count > pp->pool_limit) {
DPFPRINTF(PF_DEBUG_NOISY,
void
pool_put(struct pool *pp, void *v)
{
- lck_mtx_assert(pf_lock, LCK_MTX_ASSERT_OWNED);
+ LCK_MTX_ASSERT(pf_lock, LCK_MTX_ASSERT_OWNED);
zfree(pp->pool_zone, v);
VERIFY(pp->pool_count != 0);
pp->pool_count--;
}
+struct pf_mtag *
+pf_find_mtag_pbuf(pbuf_t *pbuf)
+{
+
+ return (pbuf->pb_pftag);
+}
+
struct pf_mtag *
pf_find_mtag(struct mbuf *m)
{
- if (!(m->m_flags & M_PKTHDR))
- return (NULL);
return (m_pftag(m));
}
return (pf_find_mtag(m));
}
+struct pf_mtag *
+pf_get_mtag_pbuf(pbuf_t *pbuf)
+{
+ return (pf_find_mtag_pbuf(pbuf));
+}
+
uint64_t
pf_time_second(void)
{