naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0169-tc-clsact-add-clsact-frontend.patch

4aca6e
From cca177ccfd0b5ae01ed8954f36c913fd95ef4b84 Mon Sep 17 00:00:00 2001
4aca6e
From: Ivan Vecera <ivecera@redhat.com>
4aca6e
Date: Wed, 31 May 2017 15:45:54 +0200
4aca6e
Subject: [PATCH 169/169] tc, clsact: add clsact frontend
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1435624
4aca6e
Upstream status: iproute2.git commit 8f9afdd531560
4aca6e
Upstream divergences: Only partially backported to provide 'ingress' keyword
4aca6e
   for 'tc filter' command. The commit itself provides support for 'clsact'
4aca6e
   qdisc that is not supported on RHEL.
4aca6e
4aca6e
commit 8f9afdd531560c1534be44424669add2e19deeec
4aca6e
Author: Daniel Borkmann <daniel@iogearbox.net>
4aca6e
Date:   Tue Jan 12 01:42:20 2016 +0100
4aca6e
4aca6e
    tc, clsact: add clsact frontend
4aca6e
4aca6e
    Add the tc part for the kernel commit 1f211a1b929c ("net, sched: add
4aca6e
    clsact qdisc"). Quoting example usage from that commit description:
4aca6e
4aca6e
      Example, adding qdisc:
4aca6e
4aca6e
      # tc qdisc add dev foo clsact
4aca6e
      # tc qdisc show dev foo
4aca6e
      qdisc mq 0: root
4aca6e
      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
4aca6e
      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
4aca6e
      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
4aca6e
      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
4aca6e
      qdisc clsact ffff: parent ffff:fff1
4aca6e
4aca6e
      Adding filters (deleting, etc works analogous by specifying ingress/egress):
4aca6e
4aca6e
      # tc filter add dev foo ingress bpf da obj bar.o sec ingress
4aca6e
      # tc filter add dev foo egress  bpf da obj bar.o sec egress
4aca6e
      # tc filter show dev foo ingress
4aca6e
      filter protocol all pref 49152 bpf
4aca6e
      filter protocol all pref 49152 bpf handle 0x1 bar.o:[ingress] direct-action
4aca6e
      # tc filter show dev foo egress
4aca6e
      filter protocol all pref 49152 bpf
4aca6e
      filter protocol all pref 49152 bpf handle 0x1 bar.o:[egress] direct-action
4aca6e
4aca6e
    The ingress parent alias can also be used with ingress qdisc.
4aca6e
4aca6e
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
4aca6e
4aca6e
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
4aca6e
---
4aca6e
 tc/tc_filter.c | 46 ++++++++++++++++++++++++++++++++++++++--------
4aca6e
 tc/tc_qdisc.c  |  3 ---
4aca6e
 2 files changed, 38 insertions(+), 11 deletions(-)
4aca6e
4aca6e
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
4aca6e
index e76d616f..2a303c04 100644
4aca6e
--- a/tc/tc_filter.c
4aca6e
+++ b/tc/tc_filter.c
4aca6e
@@ -26,25 +26,21 @@
4aca6e
 #include "tc_util.h"
4aca6e
 #include "tc_common.h"
4aca6e
 
4aca6e
-static void usage(void);
4aca6e
-
4aca6e
 static void usage(void)
4aca6e
 {
4aca6e
 	fprintf(stderr, "Usage: tc filter [ add | del | change | replace | show ] dev STRING\n");
4aca6e
 	fprintf(stderr, "       [ pref PRIO ] protocol PROTO\n");
4aca6e
 	fprintf(stderr, "       [ estimator INTERVAL TIME_CONSTANT ]\n");
4aca6e
-	fprintf(stderr, "       [ root | classid CLASSID ] [ handle FILTERID ]\n");
4aca6e
-	fprintf(stderr, "       [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n");
4aca6e
+	fprintf(stderr, "       [ root | ingress | egress | parent CLASSID ]\n");
4aca6e
+	fprintf(stderr, "       [ handle FILTERID ] [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n");
4aca6e
 	fprintf(stderr, "\n");
4aca6e
-	fprintf(stderr, "       tc filter show [ dev STRING ] [ root | parent CLASSID ]\n");
4aca6e
+	fprintf(stderr, "       tc filter show [ dev STRING ] [ root | ingress | egress | parent CLASSID ]\n");
4aca6e
 	fprintf(stderr, "Where:\n");
4aca6e
 	fprintf(stderr, "FILTER_TYPE := { rsvp | u32 | fw | route | etc. }\n");
4aca6e
 	fprintf(stderr, "FILTERID := ... format depends on classifier, see there\n");
4aca6e
 	fprintf(stderr, "OPTIONS := ... try tc filter add <desired FILTER_KIND> help\n");
4aca6e
-	return;
4aca6e
 }
4aca6e
 
4aca6e
-
4aca6e
 static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
4aca6e
 {
4aca6e
 	struct {
4aca6e
@@ -87,6 +83,20 @@ static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
4aca6e
 				return -1;
4aca6e
 			}
4aca6e
 			req.t.tcm_parent = TC_H_ROOT;
4aca6e
+		} else if (strcmp(*argv, "ingress") == 0) {
4aca6e
+			if (req.t.tcm_parent) {
4aca6e
+				fprintf(stderr, "Error: \"ingress\" is duplicate parent ID\n");
4aca6e
+				return -1;
4aca6e
+			}
4aca6e
+			req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
4aca6e
+						     TC_H_MIN_INGRESS);
4aca6e
+		} else if (strcmp(*argv, "egress") == 0) {
4aca6e
+			if (req.t.tcm_parent) {
4aca6e
+				fprintf(stderr, "Error: \"egress\" is duplicate parent ID\n");
4aca6e
+				return -1;
4aca6e
+			}
4aca6e
+			req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
4aca6e
+						     TC_H_MIN_EGRESS);
4aca6e
 		} else if (strcmp(*argv, "parent") == 0) {
4aca6e
 			__u32 handle;
4aca6e
 			NEXT_ARG();
4aca6e
@@ -220,11 +230,16 @@ int print_filter(const struct sockaddr_nl *who,
4aca6e
 	if (!filter_parent || filter_parent != t->tcm_parent) {
4aca6e
 		if (t->tcm_parent == TC_H_ROOT)
4aca6e
 			fprintf(fp, "root ");
4aca6e
+		else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS))
4aca6e
+			fprintf(fp, "ingress ");
4aca6e
+		else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_EGRESS))
4aca6e
+			fprintf(fp, "egress ");
4aca6e
 		else {
4aca6e
 			print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
4aca6e
 			fprintf(fp, "parent %s ", abuf);
4aca6e
 		}
4aca6e
 	}
4aca6e
+
4aca6e
 	if (t->tcm_info) {
4aca6e
 		f_proto = TC_H_MIN(t->tcm_info);
4aca6e
 		__u32 prio = TC_H_MAJ(t->tcm_info)>>16;
4aca6e
@@ -259,7 +274,6 @@ int print_filter(const struct sockaddr_nl *who,
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
-
4aca6e
 static int tc_filter_list(int argc, char **argv)
4aca6e
 {
4aca6e
 	struct tcmsg t;
4aca6e
@@ -284,6 +298,22 @@ static int tc_filter_list(int argc, char **argv)
4aca6e
 				return -1;
4aca6e
 			}
4aca6e
 			filter_parent = t.tcm_parent = TC_H_ROOT;
4aca6e
+		} else if (strcmp(*argv, "ingress") == 0) {
4aca6e
+			if (t.tcm_parent) {
4aca6e
+				fprintf(stderr, "Error: \"ingress\" is duplicate parent ID\n");
4aca6e
+				return -1;
4aca6e
+			}
4aca6e
+			filter_parent = TC_H_MAKE(TC_H_CLSACT,
4aca6e
+						  TC_H_MIN_INGRESS);
4aca6e
+			t.tcm_parent = filter_parent;
4aca6e
+		} else if (strcmp(*argv, "egress") == 0) {
4aca6e
+			if (t.tcm_parent) {
4aca6e
+				fprintf(stderr, "Error: \"egress\" is duplicate parent ID\n");
4aca6e
+				return -1;
4aca6e
+			}
4aca6e
+			filter_parent = TC_H_MAKE(TC_H_CLSACT,
4aca6e
+						  TC_H_MIN_EGRESS);
4aca6e
+			t.tcm_parent = filter_parent;
4aca6e
 		} else if (strcmp(*argv, "parent") == 0) {
4aca6e
 			__u32 handle;
4aca6e
 			NEXT_ARG();
4aca6e
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
4aca6e
index c31ae8d2..61aec4f8 100644
4aca6e
--- a/tc/tc_qdisc.c
4aca6e
+++ b/tc/tc_qdisc.c
4aca6e
@@ -26,8 +26,6 @@
4aca6e
 #include "tc_util.h"
4aca6e
 #include "tc_common.h"
4aca6e
 
4aca6e
-static int usage(void);
4aca6e
-
4aca6e
 static int usage(void)
4aca6e
 {
4aca6e
 	fprintf(stderr, "Usage: tc qdisc [ add | del | replace | change | show ] dev STRING\n");
4aca6e
@@ -277,7 +275,6 @@ int print_qdisc(const struct sockaddr_nl *who,
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
-
4aca6e
 static int tc_qdisc_list(int argc, char **argv)
4aca6e
 {
4aca6e
 	struct tcmsg t;
4aca6e
-- 
4aca6e
2.13.0
4aca6e