summaryrefslogtreecommitdiff
path: root/sys/netinet
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2023-12-15 00:24:57 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2023-12-15 00:24:57 +0000
commitbba9ea53078ee65837f73d198100360aca204c76 (patch)
tree4cab7ce33904037cea02ed3ab9b0e6ddf8d5ae81 /sys/netinet
parent70156a9396485cb1e052359a2c421b7a2d71b260 (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/netinet')
-rw-r--r--sys/netinet/in_pcb.h12
-rw-r--r--sys/netinet/ip_gre.c4
-rw-r--r--sys/netinet/raw_ip.c8
3 files changed, 15 insertions, 9 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);
}