diff options
author | Mark Johnston <markj@FreeBSD.org> | 2022-11-02 17:05:14 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2022-11-02 17:46:24 +0000 |
commit | a152dd863418638c3eb08b5c101b10b82f8072f5 (patch) | |
tree | a675731aa0d761888bfeaafc210f72826d290372 | |
parent | ac1750dd143e53225c518bc1ca0462c3fffe10f6 (diff) | |
download | src-a152dd863418638c3eb08b5c101b10b82f8072f5.tar.gz src-a152dd863418638c3eb08b5c101b10b82f8072f5.zip |
inpcb: Remove a PCB from its LB group upon a subsequent error
If a memory allocation failure causes bind to fail, we should take the
inpcb back out of its LB group since it's not prepared to handle
connections.
Reviewed by: glebius
MFC after: 2 weeks
Sponsored by: Modirum MDPay
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37027
-rw-r--r-- | sys/netinet/in_pcb.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 39d147464cfa..af3f8d8d9d4d 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -2404,7 +2404,6 @@ in_pcbinshash(struct inpcb *inp) struct inpcbporthead *pcbporthash; struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; struct inpcbport *phd; - int so_options; INP_WLOCK_ASSERT(inp); INP_HASH_WLOCK_ASSERT(pcbinfo); @@ -2428,13 +2427,10 @@ in_pcbinshash(struct inpcb *inp) * Add entry to load balance group. * Only do this if SO_REUSEPORT_LB is set. */ - so_options = inp_so_options(inp); - if (so_options & SO_REUSEPORT_LB) { - int ret = in_pcbinslbgrouphash(inp, M_NODOM); - if (ret) { - /* pcb lb group malloc fail (ret=ENOBUFS). */ - return (ret); - } + if ((inp->inp_flags2 & INP_REUSEPORT_LB) != 0) { + int error = in_pcbinslbgrouphash(inp, M_NODOM); + if (error != 0) + return (error); } /* @@ -2444,13 +2440,16 @@ in_pcbinshash(struct inpcb *inp) if (phd->phd_port == inp->inp_lport) break; } + /* * If none exists, malloc one and tack it on. */ if (phd == NULL) { phd = uma_zalloc_smr(pcbinfo->ipi_portzone, M_NOWAIT); if (phd == NULL) { - return (ENOBUFS); /* XXX */ + if ((inp->inp_flags2 & INP_REUSEPORT_LB) != 0) + in_pcbremlbgrouphash(inp); + return (ENOMEM); } phd->phd_port = inp->inp_lport; CK_LIST_INIT(&phd->phd_pcblist); |