diff options
author | Vitaliy Makkoveev <mvs@cvs.openbsd.org> | 2024-08-16 09:20:36 +0000 |
---|---|---|
committer | Vitaliy Makkoveev <mvs@cvs.openbsd.org> | 2024-08-16 09:20:36 +0000 |
commit | 629812f630595870cb04c698d25c1dc3c61ba269 (patch) | |
tree | 291b55975ba9de3a700842dbaa187c20edcc4912 /sys/netinet6 | |
parent | e0c985615762fa9c61296e5b2ef03d64ba954c57 (diff) |
Introduce PR_MPSYSCTL flag to mark mp-safe (*pr_sysctl)() handlers and
unlock both divert_sysctl() and divert6_sysctl(). Unlock them together,
because they are identical and pretty simple:
- DIVERTCTL_RECVSPACE and DIVERTCTL_SENDSPACE - atomically accessed
integers;
- DIVERTCTL_STATS - per-CPU counters;
ok bluhm
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/in6_proto.c | 4 | ||||
-rw-r--r-- | sys/netinet6/ip6_divert.c | 23 |
2 files changed, 14 insertions, 13 deletions
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 2d7343a52a3..d35cff479b6 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.117 2024/07/26 14:38:20 bluhm Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.118 2024/08/16 09:20:35 mvs Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -289,7 +289,7 @@ const struct protosw inet6sw[] = { .pr_type = SOCK_RAW, .pr_domain = &inet6domain, .pr_protocol = IPPROTO_DIVERT, - .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET|PR_MPSYSCTL, .pr_ctloutput = rip6_ctloutput, .pr_usrreqs = &divert6_usrreqs, .pr_init = divert6_init, diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 06111f6d3c8..dc815d5f8d8 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.96 2024/07/12 19:50:35 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.97 2024/08/16 09:20:35 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -44,17 +44,22 @@ #include <net/pfvar.h> +/* + * Locks used to protect data: + * a atomic + */ + struct inpcbtable divb6table; struct cpumem *div6counters; #ifndef DIVERT_SENDSPACE #define DIVERT_SENDSPACE (65536 + 100) #endif -u_int divert6_sendspace = DIVERT_SENDSPACE; +u_int divert6_sendspace = DIVERT_SENDSPACE; /* [a] */ #ifndef DIVERT_RECVSPACE #define DIVERT_RECVSPACE (65536 + 100) #endif -u_int divert6_recvspace = DIVERT_RECVSPACE; +u_int divert6_recvspace = DIVERT_RECVSPACE; /* [a] */ #ifndef DIVERTHASHSIZE #define DIVERTHASHSIZE 128 @@ -279,7 +284,8 @@ divert6_attach(struct socket *so, int proto, int wait) if (error) return (error); - error = soreserve(so, divert6_sendspace, divert6_recvspace); + error = soreserve(so, atomic_load_int(&divert6_sendspace), + atomic_load_int(&divert6_recvspace)); if (error) return (error); @@ -322,8 +328,6 @@ int divert6_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { - int error; - /* All sysctl names at this level are terminal. */ if (namelen != 1) return (ENOTDIR); @@ -332,12 +336,9 @@ divert6_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, case DIVERT6CTL_STATS: return (divert6_sysctl_div6stat(oldp, oldlenp, newp)); default: - NET_LOCK(); - error = sysctl_bounded_arr(divert6ctl_vars, + return (sysctl_bounded_arr(divert6ctl_vars, nitems(divert6ctl_vars), name, namelen, oldp, oldlenp, - newp, newlen); - NET_UNLOCK(); - return (error); + newp, newlen)); } /* NOTREACHED */ } |