Skip to contentSkip to conversation

: Introduce tc monitor

IPROUTE jamal 2 participants 3 messages Jul 2, 2006 – Jul 4, 2006

Subsystems (2)
lore
Share & tools
lore

jamal

author
#0 lore raw

Speaking of events reminded me of this.. Managed to get some quality time, so heres a patch against current iproute2 git that adds something useful.

Stephen, please apply.

cheers,
jamal

This patch adds ability to monitor tc events similar to ipmonitor. User runs "tc monitor" (without quotes) and watches events of addition, deletion and updates from qdiscs, classes, filters and actions as they happen.

---
commit 00f2ad46f0040769f0d4e4541fe0731f20164664
tree 0b2f8dc690d5fd90269a4c4fc34dbf7fc005f4bc
parent 8f8a36487119a3cd1afe86a9649704aca088567b
author Jamal Hadi Salim <hadi@jzny2.(none)> Sun, 02 Jul 2006 13:12:51 -0400 committer Jamal Hadi Salim <hadi@jzny2.(none)> Sun, 02 Jul 2006 13:12:51 -0400

 tc/Makefile     |    4 +-
 tc/m_action.c   |    8 ++--
 tc/tc.c         |    5 ++-
 tc/tc_class.c   |    2 +
 tc/tc_common.h  |    5 +++
 tc/tc_filter.c  |    2 +
 tc/tc_monitor.c |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tc/tc_qdisc.c   |    2 +
 8 files changed, 128 insertions(+), 10 deletions(-)
tc/Makefile +2 -2
index 9d618ff..7640c58 100644
@@ -1,6 +1,6 @@
 TCOBJ= tc.o tc_qdisc.o tc_class.o tc_filter.o tc_util.o \
-       m_police.o m_estimator.o m_action.o m_ematch.o \
-       emp_ematch.yacc.o emp_ematch.lex.o
+       tc_monitor.o m_police.o m_estimator.o m_action.o \
+       m_ematch.o emp_ematch.yacc.o emp_ematch.lex.o
 
 include ../Config
 
tc/m_action.c +4 -4
index 2d2b0ed..a7efe72 100644
@@ -293,7 +293,7 @@ tc_print_action(FILE * f, const struct r
 	return 0;
 }
 
-static int do_print_action(const struct sockaddr_nl *who,
+int print_action(const struct sockaddr_nl *who,
 			   struct nlmsghdr *n,
 			   void *arg)
 {
@@ -313,7 +313,7 @@ static int do_print_action(const struct 
 
 	if (NULL == tb[TCA_ACT_TAB]) {
 		if (n->nlmsg_type != RTM_GETACTION)
-			fprintf(stderr, "do_print_action: NULL kind\n");
+			fprintf(stderr, "print_action: NULL kind\n");
 		return -1;
 	}     
 
@@ -434,7 +434,7 @@ int tc_action_gd(int cmd, unsigned flags
 		return 1;
 	}
 
-	if (ans && do_print_action(NULL, &req.n, (void*)stdout) < 0) {
+	if (ans && print_action(NULL, &req.n, (void*)stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return 1;
 	}
@@ -536,7 +536,7 @@ #endif
 			perror("Cannot send dump request");
 			return 1;
 		}
-		ret = rtnl_dump_filter(&rth, do_print_action, stdout, NULL, NULL);
+		ret = rtnl_dump_filter(&rth, print_action, stdout, NULL, NULL);
 	}
 
 	if (event == RTM_DELACTION) { 
tc/tc.c +4 -1
index fa36ee0..789f6f6 100644
@@ -181,7 +181,7 @@ static void usage(void)
 {
 	fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
 			"       tc [-force] -batch file\n"
-	                "where  OBJECT := { qdisc | class | filter | action }\n"
+	                "where  OBJECT := { qdisc | class | filter | action | monitor }\n"
 	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -b[atch] [file] }\n");
 }
 
@@ -199,6 +199,9 @@ static int do_cmd(int argc, char **argv)
 	if (matches(*argv, "actions") == 0)
 		return do_action(argc-1, argv+1);
 
+	if (matches(*argv, "monitor") == 0)
+		return do_tcmonitor(argc-1, argv+1);
+
 	if (matches(*argv, "help") == 0) {
 		usage();
 		return 0;
tc/tc_class.c +1 -1
index 894caa1..049584e 100644
@@ -147,7 +147,7 @@ int tc_class_modify(int cmd, unsigned fl
 int filter_ifindex;
 __u32 filter_qdisc;
 
-static int print_class(const struct sockaddr_nl *who, 
+int print_class(const struct sockaddr_nl *who, 
 		       struct nlmsghdr *n, void *arg)
 {
 	FILE *fp = (FILE*)arg;
tc/tc_common.h +5 -0
index 7e13582..5bfc43e 100644
@@ -6,6 +6,11 @@ extern int do_qdisc(int argc, char **arg
 extern int do_class(int argc, char **argv);
 extern int do_filter(int argc, char **argv);
 extern int do_action(int argc, char **argv);
+extern int do_tcmonitor(int argc, char **argv);
+extern int print_action(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+extern int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+extern int print_qdisc(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
+ extern int print_class(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
 
 struct tc_estimator;
 extern int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est);
tc/tc_filter.c +1 -1
index f6de840..3341b13 100644
@@ -176,7 +176,7 @@ static int filter_ifindex;
 static __u32 filter_prio;
 static __u32 filter_protocol;
 
-static int print_filter(const struct sockaddr_nl *who,
+int print_filter(const struct sockaddr_nl *who,
 			struct nlmsghdr *n, 
 			void *arg)
 {
tc/tc_monitor.c new file +110 -0

110 lines not on this page · raw message

tc/tc_qdisc.c +1 -1
index e9174ab..76c78f2 100644
@@ -162,7 +162,7 @@ #endif
 
 static int filter_ifindex;
 
-static int print_qdisc(const struct sockaddr_nl *who, 
+int print_qdisc(const struct sockaddr_nl *who, 
 		       struct nlmsghdr *n, 
 		       void *arg)
 {
#1 lore raw
Quoted 8 lines · jamal

Speaking of events reminded me of this.. Managed to get some quality time, so heres a patch against current iproute2 git that adds something useful.

This patch adds ability to monitor tc events similar to ipmonitor. User runs "tc monitor" (without quotes) and watches events of addition, deletion and updates from qdiscs, classes, filters and actions as they happen.

Looks good to me. Speaking of actions, do you have any plans to add help-texts? Currently the output is very confusing, whenever I use them I need to google for examples.

$ tc action help
action usage improper
$ tc action add mirred help
mirred not supported help
bad action parsing
parse_action: bad value (2:mirred)!
Illegal "action"
Command "add" is unknown, try "tc action help".
author
#2 lore raw
Quoted 4 lines · Patrick McHardy

Speaking of actions, do you have any plans to
add help-texts? Currently the output is very confusing, whenever I use them I need to google for examples.

Thanks for reminding me. There are examples in the doc/ directory of iproute2, but they may be insufficient.
In any case, I wont have time today or the rest of the week but will get some patch after that.

[Actually, I have about half a day off but I want to spend time reviewing the qdisc_is_running thing in a test environment( It takes me at least 2 hours to steal hardware and set it up)].

cheers,
jamal