diff options
author | Gleb Smirnoff <glebius@FreeBSD.org> | 2022-10-13 16:03:38 +0000 |
---|---|---|
committer | Gleb Smirnoff <glebius@FreeBSD.org> | 2022-10-13 16:03:38 +0000 |
commit | 3ba34b07a4c031245362602e1d057c19c992bad2 (patch) | |
tree | 12b3a582927aa14fe1caa80855112c50134b4996 /sys | |
parent | 07b1ea961af77d728dfef4d0a11f98a8ab2fe226 (diff) | |
download | src-3ba34b07a4c031245362602e1d057c19c992bad2.tar.gz src-3ba34b07a4c031245362602e1d057c19c992bad2.zip |
inpcb: provide in_pcbremhash() to reduce copy-paste
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/in_pcb.c | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 75889b2011ac..25c8d70843d5 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -258,6 +258,8 @@ in_pcbhashseed_init(void) VNET_SYSINIT(in_pcbhashseed_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, in_pcbhashseed_init, 0); +static void in_pcbremhash(struct inpcb *); + /* * in_pcb.c: manage the Protocol Control Blocks. * @@ -1839,22 +1841,8 @@ in_pcbfree(struct inpcb *inp) CK_LIST_REMOVE(inp, inp_list); INP_INFO_WUNLOCK(pcbinfo); - if (inp->inp_flags & INP_INHASHLIST) { - struct inpcbport *phd = inp->inp_phd; - - INP_HASH_WLOCK(pcbinfo); - /* XXX: Only do if SO_REUSEPORT_LB set? */ - in_pcbremlbgrouphash(inp); - - CK_LIST_REMOVE(inp, inp_hash); - CK_LIST_REMOVE(inp, inp_portlist); - if (CK_LIST_FIRST(&phd->phd_pcblist) == NULL) { - CK_LIST_REMOVE(phd, phd_hash); - uma_zfree_smr(pcbinfo->ipi_portzone, phd); - } - INP_HASH_WUNLOCK(pcbinfo); - inp->inp_flags &= ~INP_INHASHLIST; - } + if (inp->inp_flags & INP_INHASHLIST) + in_pcbremhash(inp); RO_INVALIDATE_CACHE(&inp->inp_route); #ifdef MAC @@ -1936,25 +1924,9 @@ in_pcbdrop(struct inpcb *inp) MPASS(inp->inp_refcount > 1); #endif - /* - * XXXRW: Possibly we should protect the setting of INP_DROPPED with - * the hash lock...? - */ inp->inp_flags |= INP_DROPPED; - if (inp->inp_flags & INP_INHASHLIST) { - struct inpcbport *phd = inp->inp_phd; - - INP_HASH_WLOCK(inp->inp_pcbinfo); - in_pcbremlbgrouphash(inp); - CK_LIST_REMOVE(inp, inp_hash); - CK_LIST_REMOVE(inp, inp_portlist); - if (CK_LIST_FIRST(&phd->phd_pcblist) == NULL) { - CK_LIST_REMOVE(phd, phd_hash); - uma_zfree_smr(inp->inp_pcbinfo->ipi_portzone, phd); - } - INP_HASH_WUNLOCK(inp->inp_pcbinfo); - inp->inp_flags &= ~INP_INHASHLIST; - } + if (inp->inp_flags & INP_INHASHLIST) + in_pcbremhash(inp); } #ifdef INET @@ -2534,6 +2506,27 @@ in_pcbinshash(struct inpcb *inp) return (0); } +static void +in_pcbremhash(struct inpcb *inp) +{ + struct inpcbport *phd = inp->inp_phd; + + INP_WLOCK_ASSERT(inp); + MPASS(inp->inp_flags & INP_INHASHLIST); + + INP_HASH_WLOCK(inp->inp_pcbinfo); + /* XXX: Only do if SO_REUSEPORT_LB set? */ + in_pcbremlbgrouphash(inp); + CK_LIST_REMOVE(inp, inp_hash); + CK_LIST_REMOVE(inp, inp_portlist); + if (CK_LIST_FIRST(&phd->phd_pcblist) == NULL) { + CK_LIST_REMOVE(phd, phd_hash); + uma_zfree_smr(inp->inp_pcbinfo->ipi_portzone, phd); + } + INP_HASH_WUNLOCK(inp->inp_pcbinfo); + inp->inp_flags &= ~INP_INHASHLIST; +} + /* * Move PCB to the proper hash bucket when { faddr, fport } have been * changed. NOTE: This does not handle the case of the lport changing (the |