From c7641205e4ae82bc50a1d81891429f8f9639dbed Mon Sep 17 00:00:00 2001 From: bluhm Date: Wed, 29 Nov 2023 18:30:48 +0000 Subject: [PATCH] Document inp_socket as immutable and remove NULL checks. Struct inpcb field inp_socket is initialized in in_pcballoc(). It is not NULL and never changed. OK mvs@ --- sys/netinet/in_pcb.c | 5 ++--- sys/netinet/in_pcb.h | 4 ++-- sys/netinet/tcp_subr.c | 8 +++----- sys/netinet/udp_usrreq.c | 4 ++-- sys/netinet6/in6_pcb.c | 4 +--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index d4fa9bdce38..41cfebc6b41 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.278 2023/11/12 23:19:14 bluhm Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.279 2023/11/29 18:30:48 bluhm Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -730,8 +730,7 @@ in_pcbnotifyall(struct inpcbtable *table, struct sockaddr *dst, u_int rtable, continue; #endif if (inp->inp_faddr.s_addr != faddr.s_addr || - rtable_l2(inp->inp_rtableid) != rdomain || - inp->inp_socket == NULL) { + rtable_l2(inp->inp_rtableid) != rdomain) { continue; } in_pcbref(inp); diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 088d59c4885..0bb4bac28a9 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.139 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.140 2023/11/29 18:30:48 bluhm Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -115,7 +115,7 @@ struct inpcb { #define inp_laddr6 inp_laddru.iau_addr6 u_int16_t inp_fport; /* foreign port */ u_int16_t inp_lport; /* local port */ - struct socket *inp_socket; /* back pointer to socket */ + struct socket *inp_socket; /* [I] back pointer to socket */ caddr_t inp_ppcb; /* pointer to per-protocol pcb */ union { /* Route (notice increased size). */ struct route ru_route; diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index bc78132a7ee..8da9975386f 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_subr.c,v 1.193 2023/11/26 22:08:10 bluhm Exp $ */ +/* $OpenBSD: tcp_subr.c,v 1.194 2023/11/29 18:30:48 bluhm Exp $ */ /* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */ /* @@ -691,8 +691,7 @@ tcp6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d) } if (inp) { seq = ntohl(th.th_seq); - if (inp->inp_socket && - (tp = intotcpcb(inp)) && + if ((tp = intotcpcb(inp)) && SEQ_GEQ(seq, tp->snd_una) && SEQ_LT(seq, tp->snd_max)) notify(inp, inet6ctlerrmap[cmd]); @@ -816,8 +815,7 @@ tcp_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *v) rdomain); if (inp) { seq = ntohl(th->th_seq); - if (inp->inp_socket && - (tp = intotcpcb(inp)) && + if ((tp = intotcpcb(inp)) && SEQ_GEQ(seq, tp->snd_una) && SEQ_LT(seq, tp->snd_max)) notify(inp, errno); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index f4250a833ce..6c40f766a21 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.309 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.310 2023/11/29 18:30:48 bluhm Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -898,7 +898,7 @@ udp_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *v) inp = in_pcblookup(&udbtable, ip->ip_dst, uhp->uh_dport, ip->ip_src, uhp->uh_sport, rdomain); - if (inp && inp->inp_socket != NULL) + if (inp != NULL) notify(inp, errno); in_pcbunref(inp); } else diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index dc7e6144801..8933b493e97 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.125 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.126 2023/11/29 18:30:48 bluhm Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -512,14 +512,12 @@ in6_pcbnotify(struct inpcbtable *table, struct sockaddr_in6 *dst, * as usual. */ if (lport == 0 && fport == 0 && flowinfo && - inp->inp_socket != NULL && flowinfo == (inp->inp_flowinfo & IPV6_FLOWLABEL_MASK) && IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &sa6_src.sin6_addr)) goto do_notify; else if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &dst->sin6_addr) || rtable_l2(inp->inp_rtableid) != rdomain || - inp->inp_socket == NULL || (lport && inp->inp_lport != lport) || (!IN6_IS_ADDR_UNSPECIFIED(&sa6_src.sin6_addr) && !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, -- 2.20.1