mirror of
https://github.com/openbsd/src.git
synced 2024-12-22 07:27:59 -08:00
Unlock carp_sysctl().
This is the statistics implemented with per-CPU counters and the `carp_opts' array of atomically accessed integers. Replace the `carp_opts' array with individual `carpctl_*' variables and use sysctl_bounded_arr() instead of sysctl_int(). Keep current `carpctl_*' variables bounds as is, they would be adjusted with separate diff. ok bluhm
This commit is contained in:
parent
3d8e7e8c72
commit
10d5b13ebf
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: in_proto.c,v 1.116 2024/12/04 22:48:41 mvs Exp $ */
|
||||
/* $OpenBSD: in_proto.c,v 1.117 2024/12/19 22:10:35 mvs Exp $ */
|
||||
/* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */
|
||||
|
||||
/*
|
||||
@ -331,7 +331,7 @@ const struct protosw inetsw[] = {
|
||||
.pr_type = SOCK_RAW,
|
||||
.pr_domain = &inetdomain,
|
||||
.pr_protocol = IPPROTO_CARP,
|
||||
.pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET,
|
||||
.pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET|PR_MPSYSCTL,
|
||||
.pr_input = carp_proto_input,
|
||||
.pr_ctloutput = rip_ctloutput,
|
||||
.pr_usrreqs = &rip_usrreqs,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: ip_carp.c,v 1.364 2024/12/07 01:14:45 yasuoka Exp $ */
|
||||
/* $OpenBSD: ip_carp.c,v 1.365 2024/12/19 22:10:35 mvs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
|
||||
@ -88,6 +88,11 @@
|
||||
|
||||
#include <netinet/ip_carp.h>
|
||||
|
||||
/*
|
||||
* Locks used to protect data:
|
||||
* a atomic
|
||||
*/
|
||||
|
||||
struct carp_mc_entry {
|
||||
LIST_ENTRY(carp_mc_entry) mc_entries;
|
||||
union {
|
||||
@ -189,14 +194,23 @@ void carp_sc_unref(void *, void *);
|
||||
struct srpl_rc carp_sc_rc =
|
||||
SRPL_RC_INITIALIZER(carp_sc_ref, carp_sc_unref, NULL);
|
||||
|
||||
int carp_opts[CARPCTL_MAXID] = { 0, 1, 0, LOG_CRIT }; /* XXX for now */
|
||||
int carpctl_allow = 1; /* [a] */
|
||||
int carpctl_preempt = 0; /* [a] */
|
||||
int carpctl_log = LOG_CRIT; /* [a] */
|
||||
|
||||
const struct sysctl_bounded_args carpctl_vars[] = {
|
||||
{CARPCTL_ALLOW, &carpctl_allow, INT_MIN, INT_MAX},
|
||||
{CARPCTL_PREEMPT, &carpctl_preempt, INT_MIN, INT_MAX},
|
||||
{CARPCTL_LOG, &carpctl_log, INT_MIN, INT_MAX},
|
||||
};
|
||||
|
||||
struct cpumem *carpcounters;
|
||||
|
||||
int carp_send_all_recur = 0;
|
||||
|
||||
#define CARP_LOG(l, sc, s) \
|
||||
do { \
|
||||
if (carp_opts[CARPCTL_LOG] >= l) { \
|
||||
if ((int)atomic_load_int(&carpctl_log) >= l) { \
|
||||
if (sc) \
|
||||
log(l, "%s: ", \
|
||||
(sc)->sc_if.if_xname); \
|
||||
@ -451,7 +465,7 @@ carp_proto_input_if(struct ifnet *ifp, struct mbuf **mp, int *offp, int proto)
|
||||
|
||||
carpstat_inc(carps_ipackets);
|
||||
|
||||
if (!carp_opts[CARPCTL_ALLOW]) {
|
||||
if (!atomic_load_int(&carpctl_allow)) {
|
||||
m_freem(m);
|
||||
return IPPROTO_DONE;
|
||||
}
|
||||
@ -550,7 +564,7 @@ carp6_proto_input_if(struct ifnet *ifp, struct mbuf **mp, int *offp, int proto)
|
||||
|
||||
carpstat_inc(carps_ipackets6);
|
||||
|
||||
if (!carp_opts[CARPCTL_ALLOW]) {
|
||||
if (!atomic_load_int(&carpctl_allow)) {
|
||||
m_freem(m);
|
||||
return IPPROTO_DONE;
|
||||
}
|
||||
@ -707,7 +721,7 @@ carp_proto_input_c(struct ifnet *ifp, struct mbuf *m, struct carp_header *ch,
|
||||
* and do not have a better demote count, treat them as down.
|
||||
*
|
||||
*/
|
||||
if (carp_opts[CARPCTL_PREEMPT] &&
|
||||
if (atomic_load_int(&carpctl_preempt) &&
|
||||
timercmp(&sc_tv, &ch_tv, <) &&
|
||||
ch->carp_demote >= carp_group_demote_count(sc)) {
|
||||
carp_master_down(vhe);
|
||||
@ -765,8 +779,6 @@ int
|
||||
carp_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);
|
||||
@ -775,13 +787,8 @@ carp_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
|
||||
case CARPCTL_STATS:
|
||||
return (carp_sysctl_carpstat(oldp, oldlenp, newp));
|
||||
default:
|
||||
if (name[0] <= 0 || name[0] >= CARPCTL_MAXID)
|
||||
return (ENOPROTOOPT);
|
||||
NET_LOCK();
|
||||
error = sysctl_int(oldp, oldlenp, newp, newlen,
|
||||
&carp_opts[name[0]]);
|
||||
NET_UNLOCK();
|
||||
return (error);
|
||||
return (sysctl_bounded_arr(carpctl_vars, nitems(carpctl_vars),
|
||||
name, namelen, oldp, oldlenp, newp, newlen));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: in6_proto.c,v 1.120 2024/12/04 22:48:41 mvs Exp $ */
|
||||
/* $OpenBSD: in6_proto.c,v 1.121 2024/12/19 22:10:35 mvs Exp $ */
|
||||
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */
|
||||
|
||||
/*
|
||||
@ -278,7 +278,7 @@ const struct protosw inet6sw[] = {
|
||||
.pr_type = SOCK_RAW,
|
||||
.pr_domain = &inet6domain,
|
||||
.pr_protocol = IPPROTO_CARP,
|
||||
.pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET,
|
||||
.pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET|PR_MPSYSCTL,
|
||||
.pr_input = carp6_proto_input,
|
||||
.pr_ctloutput = rip6_ctloutput,
|
||||
.pr_usrreqs = &rip6_usrreqs,
|
||||
|
Loading…
Reference in New Issue
Block a user