Document inp_socket as immutable and remove NULL checks.
authorbluhm <bluhm@openbsd.org>
Wed, 29 Nov 2023 18:30:48 +0000 (18:30 +0000)
committerbluhm <bluhm@openbsd.org>
Wed, 29 Nov 2023 18:30:48 +0000 (18:30 +0000)
Struct inpcb field inp_socket is initialized in in_pcballoc().  It
is not NULL and never changed.

OK mvs@

sys/netinet/in_pcb.c
sys/netinet/in_pcb.h
sys/netinet/tcp_subr.c
sys/netinet/udp_usrreq.c
sys/netinet6/in6_pcb.c

index d4fa9bd..41cfebc 100644 (file)
@@ -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);
index 088d59c..0bb4bac 100644 (file)
@@ -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;
index bc78132..8da9975 100644 (file)
@@ -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);
index f4250a8..6c40f76 100644 (file)
@@ -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
index dc7e614..8933b49 100644 (file)
@@ -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,