From 02e922b0087950a54812b307acddb99258c95cb3 Mon Sep 17 00:00:00 2001 From: mvs Date: Tue, 20 Aug 2024 07:47:25 +0000 Subject: [PATCH] Unlock etherip_sysctl(). - ETHERIPCTL_ALLOW - atomically accessed integer; - ETHERIPCTL_STATS - per-CPU counters ok bluhm --- sys/net/if_etherip.c | 21 +++++++++++---------- sys/netinet/in_proto.c | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sys/net/if_etherip.c b/sys/net/if_etherip.c index dd4e90c595d..0dc3614b723 100644 --- a/sys/net/if_etherip.c +++ b/sys/net/if_etherip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_etherip.c,v 1.55 2024/02/13 12:22:09 bluhm Exp $ */ +/* $OpenBSD: if_etherip.c,v 1.56 2024/08/20 07:47:25 mvs Exp $ */ /* * Copyright (c) 2015 Kazuya GODA * @@ -55,6 +55,11 @@ #include +/* + * Locks used to protect data: + * a atomic + */ + union etherip_addr { struct in_addr in4; struct in6_addr in6; @@ -97,7 +102,7 @@ struct etherip_softc { * We can control the acceptance of EtherIP packets by altering the sysctl * net.inet.etherip.allow value. Zero means drop them, all else is acceptance. */ -int etherip_allow = 0; +int etherip_allow = 0; /* [a] */ struct cpumem *etheripcounters; @@ -628,7 +633,8 @@ etherip_input(struct etherip_tunnel *key, struct mbuf *m, uint8_t tos, struct etherip_header *eip; int rxprio; - if (!etherip_allow && (m->m_flags & (M_AUTH|M_CONF)) == 0) { + if (atomic_load_int(ðerip_allow) == 0 && + (m->m_flags & (M_AUTH|M_CONF)) == 0) { etheripstat_inc(etherips_pdrops); goto drop; } @@ -799,19 +805,14 @@ int etherip_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; switch (name[0]) { case ETHERIPCTL_ALLOW: - NET_LOCK(); - error = sysctl_int_bounded(oldp, oldlenp, newp, newlen, - ðerip_allow, 0, 1); - NET_UNLOCK(); - return (error); + return (sysctl_int_bounded(oldp, oldlenp, newp, newlen, + ðerip_allow, 0, 1)); case ETHERIPCTL_STATS: return (etherip_sysctl_etheripstat(oldp, oldlenp, newp)); default: diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 558123df7ef..e4e00015ce9 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.109 2024/08/20 07:46:27 mvs Exp $ */ +/* $OpenBSD: in_proto.c,v 1.110 2024/08/20 07:47:25 mvs Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -366,7 +366,7 @@ const struct protosw inetsw[] = { .pr_type = SOCK_RAW, .pr_domain = &inetdomain, .pr_protocol = IPPROTO_ETHERIP, - .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET|PR_MPSYSCTL, .pr_input = ip_etherip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreqs = &rip_usrreqs, -- 2.20.1