Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys pktqueue: Re-factor sysctl handling.
details: https://anonhg.NetBSD.org/src/rev/d171961c6643
branches: trunk
changeset: 369810:d171961c6643
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Sep 02 03:50:00 2022 +0000
description:
pktqueue: Re-factor sysctl handling.
Provide a new pktq_sysctl_setup() function that attaches standard
pktq sysctl nodes below a specified parent node, with either a
fixed node ID or CTL_CREATE to dynamically assign node IDs. Make
all of the sysctl handlers private to pktqueue.c, and remove the
INET- and INET6-specific pktqueue sysctl code from net/if.c.
diffstat:
sys/net/if.c | 113 +----------------------------------------------
sys/net/pktqueue.c | 78 ++++++++++++++++++++++++++++---
sys/net/pktqueue.h | 8 +--
sys/netinet/ip_input.c | 17 ++++--
sys/netinet6/ip6_input.c | 16 ++++--
5 files changed, 95 insertions(+), 137 deletions(-)
diffs (truncated from 416 to 300 lines):
diff -r c54bbed5339a -r d171961c6643 sys/net/if.c
--- a/sys/net/if.c Fri Sep 02 03:43:53 2022 +0000
+++ b/sys/net/if.c Fri Sep 02 03:50:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.520 2022/08/21 12:34:39 skrll Exp $ */
+/* $NetBSD: if.c,v 1.521 2022/09/02 03:50:00 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.520 2022/08/21 12:34:39 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.521 2022/09/02 03:50:00 thorpej Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -270,10 +270,6 @@
bool isd_trigger;
};
-#if defined(INET) || defined(INET6)
-static void sysctl_net_pktq_setup(struct sysctllog **, int);
-#endif
-
/*
* Hook for if_vlan - needed by if_agr
*/
@@ -4095,103 +4091,6 @@
return;
}
-#if defined(INET) || defined(INET6)
-
-#define SYSCTL_NET_PKTQ(q, cn, c) \
- static int \
- sysctl_net_##q##_##cn(SYSCTLFN_ARGS) \
- { \
- return sysctl_pktq_count(SYSCTLFN_CALL(rnode), q, c); \
- }
-
-#if defined(INET)
-static int
-sysctl_net_ip_pktq_maxlen(SYSCTLFN_ARGS)
-{
- return sysctl_pktq_maxlen(SYSCTLFN_CALL(rnode), ip_pktq);
-}
-SYSCTL_NET_PKTQ(ip_pktq, items, PKTQ_NITEMS)
-SYSCTL_NET_PKTQ(ip_pktq, drops, PKTQ_DROPS)
-#endif
-
-#if defined(INET6)
-static int
-sysctl_net_ip6_pktq_maxlen(SYSCTLFN_ARGS)
-{
- return sysctl_pktq_maxlen(SYSCTLFN_CALL(rnode), ip6_pktq);
-}
-SYSCTL_NET_PKTQ(ip6_pktq, items, PKTQ_NITEMS)
-SYSCTL_NET_PKTQ(ip6_pktq, drops, PKTQ_DROPS)
-#endif
-
-static void
-sysctl_net_pktq_setup(struct sysctllog **clog, int pf)
-{
- sysctlfn len_func = NULL, maxlen_func = NULL, drops_func = NULL;
- const char *pfname = NULL, *ipname = NULL;
- int ipn = 0, qid = 0;
-
- switch (pf) {
-#if defined(INET)
- case PF_INET:
- len_func = sysctl_net_ip_pktq_items;
- maxlen_func = sysctl_net_ip_pktq_maxlen;
- drops_func = sysctl_net_ip_pktq_drops;
- pfname = "inet", ipn = IPPROTO_IP;
- ipname = "ip", qid = IPCTL_IFQ;
- break;
-#endif
-#if defined(INET6)
- case PF_INET6:
- len_func = sysctl_net_ip6_pktq_items;
- maxlen_func = sysctl_net_ip6_pktq_maxlen;
- drops_func = sysctl_net_ip6_pktq_drops;
- pfname = "inet6", ipn = IPPROTO_IPV6;
- ipname = "ip6", qid = IPV6CTL_IFQ;
- break;
-#endif
- default:
- KASSERT(false);
- }
-
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT,
- CTLTYPE_NODE, pfname, NULL,
- NULL, 0, NULL, 0,
- CTL_NET, pf, CTL_EOL);
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT,
- CTLTYPE_NODE, ipname, NULL,
- NULL, 0, NULL, 0,
- CTL_NET, pf, ipn, CTL_EOL);
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT,
- CTLTYPE_NODE, "ifq",
- SYSCTL_DESCR("Protocol input queue controls"),
- NULL, 0, NULL, 0,
- CTL_NET, pf, ipn, qid, CTL_EOL);
-
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT,
- CTLTYPE_QUAD, "len",
- SYSCTL_DESCR("Current input queue length"),
- len_func, 0, NULL, 0,
- CTL_NET, pf, ipn, qid, IFQCTL_LEN, CTL_EOL);
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
- CTLTYPE_INT, "maxlen",
- SYSCTL_DESCR("Maximum allowed input queue length"),
- maxlen_func, 0, NULL, 0,
- CTL_NET, pf, ipn, qid, IFQCTL_MAXLEN, CTL_EOL);
- sysctl_createv(clog, 0, NULL, NULL,
- CTLFLAG_PERMANENT,
- CTLTYPE_QUAD, "drops",
- SYSCTL_DESCR("Packets dropped due to full input queue"),
- drops_func, 0, NULL, 0,
- CTL_NET, pf, ipn, qid, IFQCTL_DROPS, CTL_EOL);
-}
-#endif /* INET || INET6 */
-
static int
if_sdl_sysctl(SYSCTLFN_ARGS)
{
@@ -4242,12 +4141,4 @@
SYSCTL_DESCR("Get active link-layer address"),
if_sdl_sysctl, 0, NULL, 0,
CTL_NET, CTL_CREATE, CTL_EOL);
-
-#if defined(INET)
- sysctl_net_pktq_setup(NULL, PF_INET);
-#endif
-#ifdef INET6
- if (in6_present)
- sysctl_net_pktq_setup(NULL, PF_INET6);
-#endif
}
diff -r c54bbed5339a -r d171961c6643 sys/net/pktqueue.c
--- a/sys/net/pktqueue.c Fri Sep 02 03:43:53 2022 +0000
+++ b/sys/net/pktqueue.c Fri Sep 02 03:50:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pktqueue.c,v 1.18 2022/09/01 05:04:22 thorpej Exp $ */
+/* $NetBSD: pktqueue.c,v 1.19 2022/09/02 03:50:00 thorpej Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.18 2022/09/01 05:04:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.19 2022/09/02 03:50:00 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -201,7 +201,7 @@
splx(s);
}
-uint64_t
+static uint64_t
pktq_get_count(pktqueue_t *pq, pktq_count_t c)
{
pktq_counters_t sum;
@@ -585,11 +585,12 @@
return 0;
}
-int
-sysctl_pktq_maxlen(SYSCTLFN_ARGS, pktqueue_t *pq)
+static int
+sysctl_pktq_maxlen(SYSCTLFN_ARGS)
{
+ struct sysctlnode node = *rnode;
+ pktqueue_t * const pq = node.sysctl_data;
u_int nmaxlen = pktq_get_count(pq, PKTQ_MAXLEN);
- struct sysctlnode node = *rnode;
int error;
node.sysctl_data = &nmaxlen;
@@ -599,12 +600,71 @@
return pktq_set_maxlen(pq, nmaxlen);
}
-int
-sysctl_pktq_count(SYSCTLFN_ARGS, pktqueue_t *pq, u_int count_id)
+static int
+sysctl_pktq_count(SYSCTLFN_ARGS, u_int count_id)
{
+ struct sysctlnode node = *rnode;
+ pktqueue_t * const pq = node.sysctl_data;
uint64_t count = pktq_get_count(pq, count_id);
- struct sysctlnode node = *rnode;
node.sysctl_data = &count;
return sysctl_lookup(SYSCTLFN_CALL(&node));
}
+
+static int
+sysctl_pktq_nitems(SYSCTLFN_ARGS)
+{
+ return sysctl_pktq_count(SYSCTLFN_CALL(rnode), PKTQ_NITEMS);
+}
+
+static int
+sysctl_pktq_drops(SYSCTLFN_ARGS)
+{
+ return sysctl_pktq_count(SYSCTLFN_CALL(rnode), PKTQ_DROPS);
+}
+
+/*
+ * pktqueue_sysctl_setup: set up the sysctl nodes for a pktqueue
+ * using standardized names at the specified parent node and
+ * node ID (or CTL_CREATE).
+ */
+void
+pktq_sysctl_setup(pktqueue_t * const pq, struct sysctllog ** const clog,
+ const struct sysctlnode * const parent_node, const int qid)
+{
+ const struct sysctlnode *rnode = parent_node, *cnode;
+
+ KASSERT(pq != NULL);
+ KASSERT(parent_node != NULL);
+ KASSERT(qid == CTL_CREATE || qid >= 0);
+
+ /* Create the "ifq" node below the parent node. */
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "ifq",
+ SYSCTL_DESCR("Protocol input queue controls"),
+ NULL, 0, NULL, 0,
+ qid, CTL_EOL);
+
+ /* Now create the standard child nodes below "ifq". */
+ rnode = cnode;
+
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_QUAD, "len",
+ SYSCTL_DESCR("Current input queue length"),
+ sysctl_pktq_nitems, 0, (void *)pq, 0,
+ IFQCTL_LEN, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "maxlen",
+ SYSCTL_DESCR("Maximum allowed input queue length"),
+ sysctl_pktq_maxlen, 0, (void *)pq, 0,
+ IFQCTL_MAXLEN, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_QUAD, "drops",
+ SYSCTL_DESCR("Packets dropped due to full input queue"),
+ sysctl_pktq_drops, 0, (void *)pq, 0,
+ IFQCTL_DROPS, CTL_EOL);
+}
diff -r c54bbed5339a -r d171961c6643 sys/net/pktqueue.h
--- a/sys/net/pktqueue.h Fri Sep 02 03:43:53 2022 +0000
+++ b/sys/net/pktqueue.h Fri Sep 02 03:50:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pktqueue.h,v 1.6 2022/09/01 05:04:22 thorpej Exp $ */
+/* $NetBSD: pktqueue.h,v 1.7 2022/09/02 03:50:00 thorpej Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -60,11 +60,9 @@
const struct mbuf *);
extern const pktq_rps_hash_func_t pktq_rps_hash_default;
-uint64_t pktq_get_count(pktqueue_t *, pktq_count_t);
+void pktq_sysctl_setup(pktqueue_t *, struct sysctllog **,
+ const struct sysctlnode *, const int);
int sysctl_pktq_rps_hash_handler(SYSCTLFN_PROTO);
-int sysctl_pktq_maxlen(SYSCTLFN_PROTO, pktqueue_t *);
-int sysctl_pktq_count(SYSCTLFN_PROTO, pktqueue_t *, u_int);
-
#endif
diff -r c54bbed5339a -r d171961c6643 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c Fri Sep 02 03:43:53 2022 +0000
+++ b/sys/netinet/ip_input.c Fri Sep 02 03:50:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_input.c,v 1.401 2021/03/08 18:03:25 christos Exp $ */
+/* $NetBSD: ip_input.c,v 1.402 2022/09/02 03:50:00 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
Home |
Main Index |
Thread Index |
Old Index