aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2026-04-12 18:30:44 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2026-04-12 18:30:44 +0000
commit202370905f11be4e2c7afa18e73d374204fda08e (patch)
treec0cb3cff1a8adabfac60be3c2954cc001a8ce4da
parent817e6995a19cb6f35851d0191bb1099a73d98bb9 (diff)
inpcb: apply smr_advance(9)/smr_wait(9) trick only to reusable sockets
The protocols marked with PR_CONNREQUIRED can never go through pr_connect after being disconnected. This is a tiny improvement of fdb987bebddf0. While here push clearing of the addresses under the same condition. Although this clearing originates from pre-FreeBSD times, it actually makes sense only for protocols that can reconnect. Reviewed by: pouria, markj Differential Revision: https://reviews.freebsd.org/D55661
-rw-r--r--sys/netinet/in_pcb.c12
-rw-r--r--sys/netinet6/in6_pcb.c15
2 files changed, 15 insertions, 12 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index a997c643e8be..98421a7f2232 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -1433,11 +1433,13 @@ in_pcbdisconnect(struct inpcb *inp)
in_pcbremhash_locked(inp);
- /* See the comment in in_pcbinshash(). */
- inp->inp_smr = smr_advance(inp->inp_pcbinfo->ipi_smr);
- inp->inp_laddr.s_addr = INADDR_ANY;
- inp->inp_faddr.s_addr = INADDR_ANY;
- inp->inp_fport = 0;
+ if ((inp->inp_socket->so_proto->pr_flags & PR_CONNREQUIRED) == 0) {
+ /* See the comment in in_pcbinshash(). */
+ inp->inp_smr = smr_advance(inp->inp_pcbinfo->ipi_smr);
+ inp->inp_laddr.s_addr = INADDR_ANY;
+ inp->inp_faddr.s_addr = INADDR_ANY;
+ inp->inp_fport = 0;
+ }
}
#endif /* INET */
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index f8ce64a65998..2d6e860a72ba 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -510,13 +510,14 @@ in6_pcbdisconnect(struct inpcb *inp)
in_pcbremhash_locked(inp);
- /* See the comment in in_pcbinshash(). */
- inp->inp_smr = smr_advance(inp->inp_pcbinfo->ipi_smr);
-
- /* XXX-MJ torn writes are visible to SMR lookup */
- memset(&inp->in6p_laddr, 0, sizeof(inp->in6p_laddr));
- memset(&inp->in6p_faddr, 0, sizeof(inp->in6p_faddr));
- inp->inp_fport = 0;
+ if ((inp->inp_socket->so_proto->pr_flags & PR_CONNREQUIRED) == 0) {
+ /* See the comment in in_pcbinshash(). */
+ inp->inp_smr = smr_advance(inp->inp_pcbinfo->ipi_smr);
+ /* XXX-MJ torn writes are visible to SMR lookup */
+ memset(&inp->in6p_laddr, 0, sizeof(inp->in6p_laddr));
+ memset(&inp->in6p_faddr, 0, sizeof(inp->in6p_faddr));
+ inp->inp_fport = 0;
+ }
/* clear flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
inp->inp_flow &= ~IPV6_FLOWLABEL_MASK;
}