diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-09-13 19:53:59 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-09-13 19:53:59 +0000 |
commit | 8c7008393cd5f0e5ee72eb8ede944e35ef51ef98 (patch) | |
tree | 29db466f573fda8f38a3e6a3d33088fed213b56e /sys/net | |
parent | 945c2b44325f57f315b85412f5951c67e62fe6cb (diff) |
Add reference counting for inet pcb, this will be needed when we
start locking the socket. An inp can be referenced by the PCB queue
and hashes, by a pf mbuf header, or by a pf state key.
OK visa@
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/pf.c | 34 | ||||
-rw-r--r-- | sys/net/pfvar.h | 4 |
2 files changed, 30 insertions, 8 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c index 03f12f4be6b..76a351278f0 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $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 @@ -4805,7 +4805,7 @@ pf_test_state(struct pf_pdesc *pd, struct pf_state **state, u_short *reason, /* 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) { @@ -7286,7 +7286,7 @@ void 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 * @@ -7391,6 +7391,13 @@ pf_state_key_isvalid(struct pf_state_key *sk) } 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) { struct pf_state_key *sk = m->m_pkthdr.pf.statekey; @@ -7402,17 +7409,28 @@ 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); } @@ -7427,6 +7445,7 @@ pf_inpcb_unlink_state_key(struct inpcb *inp) sk->inp = NULL; inp->inp_pf_sk = NULL; pf_state_key_unref(sk); + in_pcbunref(inp); } } @@ -7440,6 +7459,7 @@ pf_state_key_unlink_inpcb(struct pf_state_key *sk) sk->inp = NULL; inp->inp_pf_sk = NULL; pf_state_key_unref(sk); + in_pcbunref(inp); } } diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index fb43fe0b166..476067e560c 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1,4 +1,4 @@ -/* $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 @@ -1961,6 +1961,8 @@ int pf_postprocess_addr(struct pf_state *); 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); |