diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2023-12-15 00:24:57 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2023-12-15 00:24:57 +0000 |
commit | bba9ea53078ee65837f73d198100360aca204c76 (patch) | |
tree | 4cab7ce33904037cea02ed3ab9b0e6ddf8d5ae81 /sys | |
parent | 70156a9396485cb1e052359a2c421b7a2d71b260 (diff) |
Use inpcb table mutex to set addresses.
Protect all remaining write access to inp_faddr and inp_laddr with
inpcb table mutex. Document inpcb locking for foreign and local
address and port and routing table id. Reading will be made MP
safe by adding per socket rw-locks in a next step.
OK sashan@ mvs@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/in_pcb.h | 12 | ||||
-rw-r--r-- | sys/netinet/ip_gre.c | 4 | ||||
-rw-r--r-- | sys/netinet/raw_ip.c | 8 | ||||
-rw-r--r-- | sys/netinet6/in6_src.c | 4 | ||||
-rw-r--r-- | sys/netinet6/raw_ip6.c | 13 |
5 files changed, 28 insertions, 13 deletions
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 9c15b41382d..b618a2e804d 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.143 2023/12/07 16:08:30 bluhm Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.144 2023/12/15 00:24:56 bluhm Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -107,14 +107,14 @@ struct inpcb { TAILQ_ENTRY(inpcb) inp_queue; /* [t] inet PCB queue */ SIMPLEQ_ENTRY(inpcb) inp_notify; /* [y] notify or udp append */ struct inpcbtable *inp_table; /* [I] inet queue/hash table */ - union inpaddru inp_faddru; /* Foreign address. */ - union inpaddru inp_laddru; /* Local address. */ + union inpaddru inp_faddru; /* [t] Foreign address. */ + union inpaddru inp_laddru; /* [t] Local address. */ #define inp_faddr inp_faddru.iau_a4u.inaddr #define inp_faddr6 inp_faddru.iau_addr6 #define inp_laddr inp_laddru.iau_a4u.inaddr #define inp_laddr6 inp_laddru.iau_addr6 - u_int16_t inp_fport; /* foreign port */ - u_int16_t inp_lport; /* local port */ + u_int16_t inp_fport; /* [t] foreign port */ + u_int16_t inp_lport; /* [t] local port */ struct socket *inp_socket; /* [I] back pointer to socket */ caddr_t inp_ppcb; /* pointer to per-protocol pcb */ union { /* Route (notice increased size). */ @@ -159,7 +159,7 @@ struct inpcb { struct mbuf *(*inp_upcall)(void *, struct mbuf *, struct ip *, struct ip6_hdr *, void *, int); void *inp_upcall_arg; - u_int inp_rtableid; + u_int inp_rtableid; /* [t] */ int inp_pipex; /* pipex indication */ uint16_t inp_flowid; }; diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index aaecb6bfabd..840852b382a 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.86 2023/04/08 13:50:22 mvs Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.87 2023/12/15 00:24:56 bluhm Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -85,7 +85,7 @@ gre_send(struct socket *so, struct mbuf *m, struct mbuf *nam, if (inp->inp_pipex) { struct sockaddr_in *sin4; - struct in_addr *ina_dst; + const struct in_addr *ina_dst; ina_dst = NULL; if ((so->so_state & SS_ISCONNECTED) != 0) diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 72c9229979d..1e7e20b8c1a 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.152 2023/11/26 22:08:10 bluhm Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.153 2023/12/15 00:24:56 bluhm Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -545,7 +545,9 @@ rip_bind(struct socket *so, struct mbuf *nam, struct proc *p) ifa_ifwithaddr(sintosa(addr), inp->inp_rtableid))) return (EADDRNOTAVAIL); + mtx_enter(&rawcbtable.inpt_mtx); inp->inp_laddr = addr->sin_addr; + mtx_leave(&rawcbtable.inpt_mtx); return (0); } @@ -562,7 +564,9 @@ rip_connect(struct socket *so, struct mbuf *nam) if ((error = in_nam2sin(nam, &addr))) return (error); + mtx_enter(&rawcbtable.inpt_mtx); inp->inp_faddr = addr->sin_addr; + mtx_leave(&rawcbtable.inpt_mtx); soisconnected(so); return (0); @@ -579,7 +583,9 @@ rip_disconnect(struct socket *so) return (ENOTCONN); soisdisconnected(so); + mtx_enter(&rawcbtable.inpt_mtx); inp->inp_faddr.s_addr = INADDR_ANY; + mtx_leave(&rawcbtable.inpt_mtx); return (0); } diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 2272c828cb9..88ec081e954 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_src.c,v 1.89 2023/12/03 20:36:24 bluhm Exp $ */ +/* $OpenBSD: in6_src.c,v 1.90 2023/12/15 00:24:56 bluhm Exp $ */ /* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */ /* @@ -96,7 +96,7 @@ in6_pcbselsrc(const struct in6_addr **in6src, struct sockaddr_in6 *dstsock, { struct ip6_moptions *mopts = inp->inp_moptions6; struct route_in6 *ro = &inp->inp_route6; - struct in6_addr *laddr = &inp->inp_laddr6; + const struct in6_addr *laddr = &inp->inp_laddr6; u_int rtableid = inp->inp_rtableid; struct ifnet *ifp = NULL; struct sockaddr *ip6_source = NULL; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index afbb6c737f2..6379e79476e 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.177 2023/12/03 20:36:24 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.178 2023/12/15 00:24:56 bluhm Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -674,7 +674,10 @@ rip6_bind(struct socket *so, struct mbuf *nam, struct proc *p) if ((error = in6_pcbaddrisavail(inp, addr, 0, p))) return (error); + mtx_enter(&rawin6pcbtable.inpt_mtx); inp->inp_laddr6 = addr->sin6_addr; + mtx_leave(&rawin6pcbtable.inpt_mtx); + return (0); } @@ -696,9 +699,12 @@ rip6_connect(struct socket *so, struct mbuf *nam) if (error) return (error); + mtx_enter(&rawin6pcbtable.inpt_mtx); inp->inp_laddr6 = *in6a; inp->inp_faddr6 = addr->sin6_addr; + mtx_leave(&rawin6pcbtable.inpt_mtx); soisconnected(so); + return (0); } @@ -712,8 +718,11 @@ rip6_disconnect(struct socket *so) if ((so->so_state & SS_ISCONNECTED) == 0) return (ENOTCONN); - inp->inp_faddr6 = in6addr_any; so->so_state &= ~SS_ISCONNECTED; /* XXX */ + mtx_enter(&rawin6pcbtable.inpt_mtx); + inp->inp_faddr6 = in6addr_any; + mtx_leave(&rawin6pcbtable.inpt_mtx); + return (0); } |