[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <d2f62cd8503f40cce44ef0917989eab72f57d3b6.1590512905.git.petrm@mellanox.com>
Date: Tue, 26 May 2020 20:10:09 +0300
From: Petr Machata <petrm@...lanox.com>
To: netdev@...r.kernel.org
Cc: Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <eric.dumazet@...il.com>, jhs@...atatu.com,
jiri@...lanox.com, idosch@...lanox.com,
Petr Machata <petrm@...lanox.com>
Subject: [RFC PATCH iproute2-next 2/4] tc: Add helpers to support qevent parsing
Introduce a set of helpers to make it easy to add support for qevents into
qdisc.
The idea behind this is that qevent types will be generally reused between
qdiscs, rather than each having a completely idiosyncratic set of qevents.
The qevent module holds functions for parsing of these common qevent types,
and for dispatching to one of the parsers based on the qevent name.
Signed-off-by: Petr Machata <petrm@...lanox.com>
---
tc/Makefile | 1 +
tc/tc_qevent.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
tc/tc_qevent.h | 34 +++++++++++++++++++++
3 files changed, 118 insertions(+)
create mode 100644 tc/tc_qevent.c
create mode 100644 tc/tc_qevent.h
diff --git a/tc/Makefile b/tc/Makefile
index e31cbc12..10567f33 100644
--- a/tc/Makefile
+++ b/tc/Makefile
@@ -121,6 +121,7 @@ TCLIB += tc_red.o
TCLIB += tc_cbq.o
TCLIB += tc_estimator.o
TCLIB += tc_stab.o
+TCLIB += tc_qevent.o
CFLAGS += -DCONFIG_GACT -DCONFIG_GACT_PROB
ifneq ($(IPT_LIB_DIR),)
diff --git a/tc/tc_qevent.c b/tc/tc_qevent.c
new file mode 100644
index 00000000..f2b22778
--- /dev/null
+++ b/tc/tc_qevent.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+
+/*
+ * Helpers for handling qevents.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "tc_qevent.h"
+#include "utils.h"
+
+int qevent_parse(struct qevent_util *qevents, int *p_argc, char ***p_argv)
+{
+ char **argv = *p_argv;
+ int argc = *p_argc;
+ const char *name = *argv;
+ int err;
+
+ for (; qevents->id; qevents++) {
+ if (strcmp(name, qevents->id) == 0) {
+ NEXT_ARG();
+ err = qevents->parse_qevent(&argc, &argv,
+ qevents->data);
+ if (err)
+ return err;
+
+ *p_argc = argc;
+ *p_argv = argv;
+ return 0;
+ }
+ }
+
+ fprintf(stderr, "Unknown qevent `%s'\n", name);
+ return -1;
+}
+
+static int parse_block_idx(const char *arg, struct qevent_base *qeb)
+{
+ if (qeb->block_idx) {
+ fprintf(stderr, "Qevent block index already specified\n");
+ return -1;
+ }
+
+ if (get_unsigned(&qeb->block_idx, arg, 10) || !qeb->block_idx) {
+ fprintf(stderr, "Illegal qevent block index\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qevent_parse_plain(int *p_argc, char ***p_argv, void *p_data)
+{
+ struct qevent_plain *qe = p_data;
+ char **argv = *p_argv;
+ int argc = *p_argc;
+
+ if (qe->base.block_idx) {
+ fprintf(stderr, "Duplicate qevent\n");
+ return -1;
+ }
+
+ while (argc > 0) {
+ if (strcmp(*argv, "block") == 0) {
+ NEXT_ARG();
+ if (parse_block_idx(*argv, &qe->base))
+ return -1;
+ } else {
+ break;
+ }
+ NEXT_ARG_FWD();
+ }
+
+ if (!qe->base.block_idx) {
+ fprintf(stderr, "Unspecified qevent block index\n");
+ return -1;
+ }
+
+ *p_argc = argc;
+ *p_argv = argv;
+ return 0;
+}
diff --git a/tc/tc_qevent.h b/tc/tc_qevent.h
new file mode 100644
index 00000000..548f3fc6
--- /dev/null
+++ b/tc/tc_qevent.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _TC_QEVENT_H_
+#define _TC_QEVENT_H_
+
+#include <linux/types.h>
+
+struct qevent_base {
+ __u32 block_idx;
+};
+
+struct qevent_util {
+ const char *id;
+ int (*parse_qevent)(int *argc, char ***argv, void *data);
+ void *data;
+};
+
+#define QEVENT(_name, _parser, _data) \
+ { \
+ .id = _name, \
+ .parse_qevent = qevent_parse_##_parser, \
+ .data = ({ \
+ struct qevent_##_parser *__data = _data; \
+ __data; \
+ }), \
+ }
+
+int qevent_parse(struct qevent_util *qevents, int *p_argc, char ***p_argv);
+
+struct qevent_plain {
+ struct qevent_base base;
+};
+int qevent_parse_plain(int *p_argc, char ***p_argv, void *p_data);
+
+#endif
--
2.20.1
Powered by blists - more mailing lists