From: mvs Date: Tue, 13 Sep 2022 09:05:02 +0000 (+0000) Subject: Do soreceive() with shared netlock for raw sockets. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d0e7fa22981fb5ffbfc2e72b37b65cd04796c339;p=openbsd Do soreceive() with shared netlock for raw sockets. ok bluhm@ --- diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 0e9402139be..49b2f67fdb2 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.104 2022/09/03 22:43:38 mvs Exp $ */ +/* $OpenBSD: ip_var.h,v 1.105 2022/09/13 09:05:02 mvs Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -258,6 +258,8 @@ int rip_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); int rip_attach(struct socket *, int); int rip_detach(struct socket *); +void rip_lock(struct socket *); +void rip_unlock(struct socket *); int rip_bind(struct socket *so, struct mbuf *, struct proc *); int rip_connect(struct socket *, struct mbuf *); int rip_disconnect(struct socket *); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index cc449212770..a00d922e37a 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.147 2022/09/03 22:43:38 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.148 2022/09/13 09:05:02 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -106,6 +106,8 @@ struct inpcbtable rawcbtable; const struct pr_usrreqs rip_usrreqs = { .pru_attach = rip_attach, .pru_detach = rip_detach, + .pru_lock = rip_lock, + .pru_unlock = rip_unlock, .pru_bind = rip_bind, .pru_connect = rip_connect, .pru_disconnect = rip_disconnect, @@ -220,12 +222,19 @@ rip_input(struct mbuf **mp, int *offp, int proto, int af) else n = m_copym(m, 0, M_COPYALL, M_NOWAIT); if (n != NULL) { + int ret; + if (inp->inp_flags & INP_CONTROLOPTS || inp->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(inp, &opts, ip, n); - if (sbappendaddr(inp->inp_socket, + + mtx_enter(&inp->inp_mtx); + ret = sbappendaddr(inp->inp_socket, &inp->inp_socket->so_rcv, - sintosa(&ripsrc), n, opts) == 0) { + sintosa(&ripsrc), n, opts); + mtx_leave(&inp->inp_mtx); + + if (ret == 0) { /* should notify about lost packet */ m_freem(n); m_freem(opts); @@ -500,6 +509,24 @@ rip_detach(struct socket *so) return (0); } +void +rip_lock(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + NET_ASSERT_LOCKED(); + mtx_enter(&inp->inp_mtx); +} + +void +rip_unlock(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + NET_ASSERT_LOCKED(); + mtx_leave(&inp->inp_mtx); +} + int rip_bind(struct socket *so, struct mbuf *nam, struct proc *p) { diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index f501eb023c8..c3c1d13824d 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.102 2022/09/03 22:43:38 mvs Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.103 2022/09/13 09:05:02 mvs Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -353,6 +353,8 @@ int rip6_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); int rip6_attach(struct socket *, int); int rip6_detach(struct socket *); +void rip6_lock(struct socket *); +void rip6_unlock(struct socket *); int rip6_bind(struct socket *, struct mbuf *, struct proc *); int rip6_connect(struct socket *, struct mbuf *); int rip6_disconnect(struct socket *); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 1d8c2709839..b87f83df98c 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.168 2022/09/03 22:43:38 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.169 2022/09/13 09:05:02 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -108,6 +108,8 @@ struct cpumem *rip6counters; const struct pr_usrreqs rip6_usrreqs = { .pru_attach = rip6_attach, .pru_detach = rip6_detach, + .pru_lock = rip6_lock, + .pru_unlock = rip6_unlock, .pru_bind = rip6_bind, .pru_connect = rip6_connect, .pru_disconnect = rip6_disconnect, @@ -261,13 +263,20 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af) else n = m_copym(m, 0, M_COPYALL, M_NOWAIT); if (n != NULL) { + int ret; + if (in6p->inp_flags & IN6P_CONTROLOPTS) ip6_savecontrol(in6p, n, &opts); /* strip intermediate headers */ m_adj(n, *offp); - if (sbappendaddr(in6p->inp_socket, + + mtx_enter(&in6p->inp_mtx); + ret = sbappendaddr(in6p->inp_socket, &in6p->inp_socket->so_rcv, - sin6tosa(&rip6src), n, opts) == 0) { + sin6tosa(&rip6src), n, opts); + mtx_leave(&in6p->inp_mtx); + + if (ret == 0) { /* should notify about lost packet */ m_freem(n); m_freem(opts); @@ -629,6 +638,24 @@ rip6_detach(struct socket *so) return (0); } +void +rip6_lock(struct socket *so) +{ + struct inpcb *in6p = sotoinpcb(so); + + NET_ASSERT_LOCKED(); + mtx_enter(&in6p->inp_mtx); +} + +void +rip6_unlock(struct socket *so) +{ + struct inpcb *in6p = sotoinpcb(so); + + NET_ASSERT_LOCKED(); + mtx_leave(&in6p->inp_mtx); +} + int rip6_bind(struct socket *so, struct mbuf *nam, struct proc *p) {