Skip to contentSkip to conversation

clsact frontend

PATCH In review Daniel Borkmann 2 participants 4 messages Jan 12, 2016 – Jan 18, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover clsact frontend

Cleanup on ingress and addition of clsact frontend. There's no man-page for ingress nor for clsact, will follow-up with one to document both.

The patch requires a header update and is against your current net-next branch (pre master merge).

Thanks!

Daniel Borkmann (2):
tc, ingress: clean up ingress handling a bit
tc, clsact: add clsact frontend

 tc/Makefile    |  1 +
 tc/q_clsact.c  | 34 ++++++++++++++++++++++++++++++++++
 tc/q_ingress.c | 20 +++++---------------
 tc/tc_filter.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 tc/tc_qdisc.c  | 32 ++++++++++++++++++--------------
 5 files changed, 96 insertions(+), 37 deletions(-)
 create mode 100644 tc/q_clsact.c
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/2 tc, ingress: clean up ingress handling a bit

Clean it up a bit, we can also get rid of some ugly ifdefs as in our case TC_H_INGRESS is always defined.

---
 tc/q_ingress.c | 20 +++++---------------
 tc/tc_qdisc.c  | 11 +++--------
 2 files changed, 8 insertions(+), 23 deletions(-)
tc/q_ingress.c +5 -15
index 30b24e7..c3c9b40 100644
@@ -1,5 +1,4 @@
 /*
- *
  * q_ingress.c             INGRESS.
  *
  *              This program is free software; you can redistribute it and/or
@@ -8,20 +7,9 @@
  *              2 of the License, or (at your option) any later version.
  *
  * Authors:    J Hadi Salim
- *
- * This is here just in case it is needed
- * useless right now; might be useful in the future
- *
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
 #include <string.h>
 
 #include "utils.h"
@@ -29,10 +17,11 @@
 
 static void explain(void)
 {
-	fprintf(stderr, "Usage: ... ingress \n");
+	fprintf(stderr, "Usage: ... ingress\n");
 }
 
-static int ingress_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
+static int ingress_parse_opt(struct qdisc_util *qu, int argc, char **argv,
+			     struct nlmsghdr *n)
 {
 	while (argc > 0) {
 		if (strcmp(*argv, "handle") == 0) {
@@ -49,7 +38,8 @@ static int ingress_parse_opt(struct qdisc_util *qu, int argc, char **argv, struc
 	return 0;
 }
 
-static int ingress_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
+static int ingress_print_opt(struct qdisc_util *qu, FILE *f,
+			     struct rtattr *opt)
 {
 	fprintf(f, "---------------- ");
 	return 0;
tc/tc_qdisc.c +3 -8
index c31ae8d..96b8085 100644
@@ -91,20 +91,17 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_ROOT;
-#ifdef TC_H_INGRESS
 		} else if (strcmp(*argv, "ingress") == 0) {
 			if (req.t.tcm_parent) {
 				fprintf(stderr, "Error: \"ingress\" is a duplicate parent ID\n");
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_INGRESS;
-			strncpy(k, "ingress", sizeof(k)-1);
+			strncpy(k, "ingress", sizeof(k) - 1);
 			q = get_qdisc_kind(k);
-			req.t.tcm_handle = 0xffff0000;
-
-			argc--; argv++;
+			req.t.tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0);
+			NEXT_ARG_FWD();
 			break;
-#endif
 		} else if (strcmp(*argv, "parent") == 0) {
 			__u32 handle;
 			NEXT_ARG();
@@ -291,14 +288,12 @@ static int tc_qdisc_list(int argc, char **argv)
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			strncpy(d, *argv, sizeof(d)-1);
-#ifdef TC_H_INGRESS
                 } else if (strcmp(*argv, "ingress") == 0) {
                              if (t.tcm_parent) {
                                      fprintf(stderr, "Duplicate parent ID\n");
                                      usage();
                              }
                              t.tcm_parent = TC_H_INGRESS;
-#endif
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/2 tc, clsact: add clsact frontend

In reply to Daniel Borkmann

Add the tc part for the kernel commit 1f211a1b929c ("net, sched: add clsact qdisc"). Quoting example usage from that commit description:

Example, adding qdisc:

  # tc qdisc add dev foo clsact
  # tc qdisc show dev foo
  qdisc mq 0: root
  qdisc pfifo_fast 0: parent :1 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
  qdisc pfifo_fast 0: parent :2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
  qdisc pfifo_fast 0: parent :3 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
  qdisc pfifo_fast 0: parent :4 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
  qdisc clsact ffff: parent ffff:fff1

Adding filters (deleting, etc works analogous by specifying ingress/egress):

  # tc filter add dev foo ingress bpf da obj bar.o sec ingress
  # tc filter add dev foo egress  bpf da obj bar.o sec egress
  # tc filter show dev foo ingress
  filter protocol all pref 49152 bpf
  filter protocol all pref 49152 bpf handle 0x1 bar.o:[ingress] direct-action
  # tc filter show dev foo egress
  filter protocol all pref 49152 bpf
  filter protocol all pref 49152 bpf handle 0x1 bar.o:[egress] direct-action

The ingress parent alias can also be used with ingress qdisc.

---
 tc/Makefile    |  1 +
 tc/q_clsact.c  | 34 ++++++++++++++++++++++++++++++++++
 tc/tc_filter.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 tc/tc_qdisc.c  | 21 +++++++++++++++------
 4 files changed, 88 insertions(+), 14 deletions(-)
 create mode 100644 tc/q_clsact.c
tc/Makefile +1 -0
index 56acbaa..f5bea87 100644
@@ -64,6 +64,7 @@ TCMODULES += q_fq_codel.o
 TCMODULES += q_fq.o
 TCMODULES += q_pie.o
 TCMODULES += q_hhf.o
+TCMODULES += q_clsact.o
 TCMODULES += e_bpf.o
 
 ifeq ($(TC_CONFIG_IPSET), y)
tc/q_clsact.c new file +34 -0
new file mode 100644
index 0000000..0c05dbd
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "utils.h"
+#include "tc_util.h"
+
+static void explain(void)
+{
+	fprintf(stderr, "Usage: ... clsact\n");
+}
+
+static int clsact_parse_opt(struct qdisc_util *qu, int argc, char **argv,
+			    struct nlmsghdr *n)
+{
+	if (argc > 0) {
+		fprintf(stderr, "What is \"%s\"?\n", *argv);
+		explain();
+		return -1;
+	}
+
+	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
+	return 0;
+}
+
+static int clsact_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
+{
+	return 0;
+}
+
+struct qdisc_util clsact_qdisc_util = {
+	.id		= "clsact",
+	.parse_qopt	= clsact_parse_opt,
+	.print_qopt	= clsact_print_opt,
+};
tc/tc_filter.c +38 -8

93 lines not on this page · raw message

tc/tc_qdisc.c +15 -6
index 96b8085..cb861e0 100644
@@ -26,17 +26,15 @@
 #include "tc_util.h"
 #include "tc_common.h"
 
-static int usage(void);
-
 static int usage(void)
 {
 	fprintf(stderr, "Usage: tc qdisc [ add | del | replace | change | show ] dev STRING\n");
-	fprintf(stderr, "       [ handle QHANDLE ] [ root | ingress | parent CLASSID ]\n");
+	fprintf(stderr, "       [ handle QHANDLE ] [ root | ingress | clsact | parent CLASSID ]\n");
 	fprintf(stderr, "       [ estimator INTERVAL TIME_CONSTANT ]\n");
 	fprintf(stderr, "       [ stab [ help | STAB_OPTIONS] ]\n");
 	fprintf(stderr, "       [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n");
 	fprintf(stderr, "\n");
-	fprintf(stderr, "       tc qdisc show [ dev STRING ] [ingress]\n");
+	fprintf(stderr, "       tc qdisc show [ dev STRING ] [ ingress | clsact ]\n");
 	fprintf(stderr, "Where:\n");
 	fprintf(stderr, "QDISC_KIND := { [p|b]fifo | tbf | prio | cbq | red | etc. }\n");
 	fprintf(stderr, "OPTIONS := ... try tc qdisc add <desired QDISC_KIND> help\n");
@@ -91,6 +89,17 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_ROOT;
+		} else if (strcmp(*argv, "clsact") == 0) {
+			if (req.t.tcm_parent) {
+				fprintf(stderr, "Error: \"clsact\" is a duplicate parent ID\n");
+				return -1;
+			}
+			req.t.tcm_parent = TC_H_CLSACT;
+			strncpy(k, "clsact", sizeof(k) - 1);
+			q = get_qdisc_kind(k);
+			req.t.tcm_handle = TC_H_MAKE(TC_H_CLSACT, 0);
+			NEXT_ARG_FWD();
+			break;
 		} else if (strcmp(*argv, "ingress") == 0) {
 			if (req.t.tcm_parent) {
 				fprintf(stderr, "Error: \"ingress\" is a duplicate parent ID\n");
@@ -274,7 +283,6 @@ int print_qdisc(const struct sockaddr_nl *who,
 	return 0;
 }
 
-
 static int tc_qdisc_list(int argc, char **argv)
 {
 	struct tcmsg t;
@@ -288,7 +296,8 @@ static int tc_qdisc_list(int argc, char **argv)
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			strncpy(d, *argv, sizeof(d)-1);
-                } else if (strcmp(*argv, "ingress") == 0) {
+                } else if (strcmp(*argv, "ingress") == 0 ||
+			   strcmp(*argv, "clsact") == 0) {
                              if (t.tcm_parent) {
                                      fprintf(stderr, "Duplicate parent ID\n");
                                      usage();
Signature · 1 line
1.9.3
#3 lore raw
In reply to Daniel Borkmann
Quoted 12 lines · On Tue, 12 Jan 2016 01:42:18 +0100 Daniel Borkmann <[email protected]> wrote:

Cleanup on ingress and addition of clsact frontend. There's no man-page for ingress nor for clsact, will follow-up with one to document both.

The patch requires a header update and is against your current net-next branch (pre master merge).

Thanks!

Daniel Borkmann (2):
tc, ingress: clean up ingress handling a bit
tc, clsact: add clsact frontend

Quoted 8 lines
 tc/Makefile    |  1 +
 tc/q_clsact.c  | 34 ++++++++++++++++++++++++++++++++++
 tc/q_ingress.c | 20 +++++---------------
 tc/tc_filter.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 tc/tc_qdisc.c  | 32 ++++++++++++++++++--------------
 5 files changed, 96 insertions(+), 37 deletions(-)
 create mode 100644 tc/q_clsact.c

Applied (to master).