-/* $OpenBSD: uipc_mbuf.c,v 1.258 2018/09/10 16:14:07 bluhm Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.259 2018/09/13 19:53:58 bluhm Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
{
/* delete all mbuf tags to reset the state */
m_tag_delete_chain(m);
-
#if NPF > 0
pf_mbuf_unlink_state_key(m);
+ pf_mbuf_unlink_inpcb(m);
#endif /* NPF > 0 */
memset(&m->m_pkthdr, 0, sizeof(m->m_pkthdr));
m_tag_delete_chain(m);
#if NPF > 0
pf_mbuf_unlink_state_key(m);
+ pf_mbuf_unlink_inpcb(m);
#endif /* NPF > 0 */
}
if (m->m_flags & M_EXT)
#if NPF > 0
to->m_pkthdr.pf.statekey = NULL;
pf_mbuf_link_state_key(to, from->m_pkthdr.pf.statekey);
+ to->m_pkthdr.pf.inp = NULL;
+ pf_mbuf_link_inpcb(to, from->m_pkthdr.pf.inp);
#endif /* NPF > 0 */
SLIST_INIT(&to->m_pkthdr.ph_tags);
-/* $OpenBSD: pf.c,v 1.1074 2018/09/11 07:53:38 sashan Exp $ */
+/* $OpenBSD: pf.c,v 1.1075 2018/09/13 19:53:58 bluhm Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
/* XXX make sure it's the same direction ?? */
(*state)->timeout = PFTM_PURGE;
*state = NULL;
- pd->m->m_pkthdr.pf.inp = inp;
+ pf_mbuf_link_inpcb(pd->m, inp);
return (PF_DROP);
} else if (dst->state >= TCPS_ESTABLISHED &&
src->state >= TCPS_ESTABLISHED) {
pf_pkt_addr_changed(struct mbuf *m)
{
pf_mbuf_unlink_state_key(m);
- m->m_pkthdr.pf.inp = NULL;
+ pf_mbuf_unlink_inpcb(m);
}
struct inpcb *
return ((sk != NULL) && (sk->removed == 0));
}
+void
+pf_mbuf_link_state_key(struct mbuf *m, struct pf_state_key *sk)
+{
+ KASSERT(m->m_pkthdr.pf.statekey == NULL);
+ m->m_pkthdr.pf.statekey = pf_state_key_ref(sk);
+}
+
void
pf_mbuf_unlink_state_key(struct mbuf *m)
{
}
void
-pf_mbuf_link_state_key(struct mbuf *m, struct pf_state_key *sk)
+pf_mbuf_link_inpcb(struct mbuf *m, struct inpcb *inp)
{
- KASSERT(m->m_pkthdr.pf.statekey == NULL);
- m->m_pkthdr.pf.statekey = pf_state_key_ref(sk);
+ KASSERT(m->m_pkthdr.pf.inp == NULL);
+ m->m_pkthdr.pf.inp = in_pcbref(inp);
+}
+
+void
+pf_mbuf_unlink_inpcb(struct mbuf *m)
+{
+ struct inpcb *inp = m->m_pkthdr.pf.inp;
+
+ if (inp != NULL) {
+ m->m_pkthdr.pf.inp = NULL;
+ in_pcbunref(inp);
+ }
}
void
pf_state_key_link_inpcb(struct pf_state_key *sk, struct inpcb *inp)
{
KASSERT(sk->inp == NULL);
- sk->inp = inp;
+ sk->inp = in_pcbref(inp);
KASSERT(inp->inp_pf_sk == NULL);
inp->inp_pf_sk = pf_state_key_ref(sk);
}
sk->inp = NULL;
inp->inp_pf_sk = NULL;
pf_state_key_unref(sk);
+ in_pcbunref(inp);
}
}
sk->inp = NULL;
inp->inp_pf_sk = NULL;
pf_state_key_unref(sk);
+ in_pcbunref(inp);
}
}
-/* $OpenBSD: pfvar.h,v 1.485 2018/09/11 07:53:38 sashan Exp $ */
+/* $OpenBSD: pfvar.h,v 1.486 2018/09/13 19:53:58 bluhm Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
void pf_mbuf_link_state_key(struct mbuf *,
struct pf_state_key *);
void pf_mbuf_unlink_state_key(struct mbuf *);
+void pf_mbuf_link_inpcb(struct mbuf *, struct inpcb *);
+void pf_mbuf_unlink_inpcb(struct mbuf *);
u_int8_t* pf_find_tcpopt(u_int8_t *, u_int8_t *, size_t,
u_int8_t, u_int8_t);
-/* $OpenBSD: in_pcb.c,v 1.243 2018/09/11 14:34:49 bluhm Exp $ */
+/* $OpenBSD: in_pcb.c,v 1.244 2018/09/13 19:53:58 bluhm Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
return (ENOBUFS);
inp->inp_table = table;
inp->inp_socket = so;
+ refcnt_init(&inp->inp_refcnt);
inp->inp_seclevel[SL_AUTH] = IPSEC_AUTH_LEVEL_DEFAULT;
inp->inp_seclevel[SL_ESP_TRANS] = IPSEC_ESP_TRANS_LEVEL_DEFAULT;
inp->inp_seclevel[SL_ESP_NETWORK] = IPSEC_ESP_NETWORK_LEVEL_DEFAULT;
LIST_REMOVE(inp, inp_hash);
TAILQ_REMOVE(&inp->inp_table->inpt_queue, inp, inp_queue);
inp->inp_table->inpt_count--;
- pool_put(&inpcb_pool, inp);
+ in_pcbunref(inp);
+}
+
+struct inpcb *
+in_pcbref(struct inpcb *inp)
+{
+ if (inp != NULL)
+ refcnt_take(&inp->inp_refcnt);
+ return inp;
+}
+
+void
+in_pcbunref(struct inpcb *inp)
+{
+ if (refcnt_rele(&inp->inp_refcnt)) {
+ KASSERT((LIST_NEXT(inp, inp_hash) == NULL) ||
+ (LIST_NEXT(inp, inp_hash) == _Q_INVALID));
+ KASSERT((LIST_NEXT(inp, inp_lhash) == NULL) ||
+ (LIST_NEXT(inp, inp_lhash) == _Q_INVALID));
+ KASSERT((TAILQ_NEXT(inp, inp_queue) == NULL) ||
+ (TAILQ_NEXT(inp, inp_queue) == _Q_INVALID));
+ pool_put(&inpcb_pool, inp);
+ }
}
void
-/* $OpenBSD: in_pcb.h,v 1.110 2018/09/11 14:34:49 bluhm Exp $ */
+/* $OpenBSD: in_pcb.h,v 1.111 2018/09/13 19:53:58 bluhm Exp $ */
/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */
/*
} inp_ru;
#define inp_route inp_ru.ru_route
#define inp_route6 inp_ru.ru_route6
+ struct refcnt inp_refcnt; /* refcount PCB, delay memory free */
int inp_flags; /* generic IP/datagram flags */
union { /* Header prototype. */
struct ip hu_ip;
struct proc *);
int in_pcbconnect(struct inpcb *, struct mbuf *);
void in_pcbdetach(struct inpcb *);
+struct inpcb *
+ in_pcbref(struct inpcb *);
+void in_pcbunref(struct inpcb *);
void in_pcbdisconnect(struct inpcb *);
struct inpcb *
in_pcbhashlookup(struct inpcbtable *, struct in_addr,
-/* $OpenBSD: raw_ip.c,v 1.111 2018/07/05 21:16:52 bluhm Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.112 2018/09/13 19:53:58 bluhm Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
#if NPF > 0
if (inp->inp_socket->so_state & SS_ISCONNECTED &&
ip->ip_p != IPPROTO_ICMP)
- m->m_pkthdr.pf.inp = inp;
+ pf_mbuf_link_inpcb(m, inp);
#endif
error = ip_output(m, inp->inp_options, &inp->inp_route, flags,
-/* $OpenBSD: tcp_output.c,v 1.125 2018/06/11 07:40:26 bluhm Exp $ */
+/* $OpenBSD: tcp_output.c,v 1.126 2018/09/13 19:53:58 bluhm Exp $ */
/* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */
/*
#include <sys/socketvar.h>
#include <sys/kernel.h>
+#include <net/if.h>
#include <net/route.h>
+#if NPF > 0
+#include <net/pfvar.h>
+#endif
#include <netinet/in.h>
#include <netinet/ip.h>
m->m_pkthdr.ph_rtableid = tp->t_inpcb->inp_rtableid;
#if NPF > 0
- m->m_pkthdr.pf.inp = tp->t_inpcb;
+ pf_mbuf_link_inpcb(m, tp->t_inpcb);
#endif
switch (tp->pf) {
-/* $OpenBSD: udp_usrreq.c,v 1.250 2018/07/05 21:16:52 bluhm Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.251 2018/09/13 19:53:58 bluhm Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
/*
#if NPF > 0
if (inp->inp_socket->so_state & SS_ISCONNECTED)
- m->m_pkthdr.pf.inp = inp;
+ pf_mbuf_link_inpcb(m, inp);
#endif
error = ip_output(m, inp->inp_options, &inp->inp_route,
-/* $OpenBSD: raw_ip6.c,v 1.129 2018/07/05 21:16:52 bluhm Exp $ */
+/* $OpenBSD: raw_ip6.c,v 1.130 2018/09/13 19:53:58 bluhm Exp $ */
/* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */
/*
#if NPF > 0
if (in6p->inp_socket->so_state & SS_ISCONNECTED &&
so->so_proto->pr_protocol != IPPROTO_ICMPV6)
- m->m_pkthdr.pf.inp = in6p;
+ pf_mbuf_link_inpcb(m, in6p);
#endif
error = ip6_output(m, optp, &in6p->inp_route6, flags,
-/* $OpenBSD: udp6_output.c,v 1.55 2017/08/11 19:53:02 bluhm Exp $ */
+/* $OpenBSD: udp6_output.c,v 1.56 2018/09/13 19:53:58 bluhm Exp $ */
/* $KAME: udp6_output.c,v 1.21 2001/02/07 11:51:54 itojun Exp $ */
/*
#include <net/if.h>
#include <net/if_var.h>
#include <net/route.h>
+#if NPF > 0
+#include <net/pfvar.h>
+#endif
#include <netinet/in.h>
#include <netinet6/in6_var.h>
#if NPF > 0
if (in6p->inp_socket->so_state & SS_ISCONNECTED)
- m->m_pkthdr.pf.inp = in6p;
+ pf_mbuf_link_inpcb(m, in6p);
#endif
error = ip6_output(m, optp, &in6p->inp_route6,