2 * f_cgroup.c Control Group Classifier
4 * This program is free software; you can distribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Thomas Graf <tgraf@infradead.org>
19 static void explain(void)
21 fprintf(stderr
, "Usage: ... cgroup [ match EMATCH_TREE ] [ police POLICE_SPEC ]\n");
22 fprintf(stderr
, " [ action ACTION_SPEC ]\n");
25 static int cgroup_parse_opt(struct filter_util
*qu
, char *handle
,
26 int argc
, char **argv
, struct nlmsghdr
*n
)
28 struct tcmsg
*t
= NLMSG_DATA(n
);
33 h
= strtol(handle
, NULL
, 0);
34 if (h
== LONG_MIN
|| h
== LONG_MAX
) {
35 fprintf(stderr
, "Illegal handle \"%s\", must be numeric.\n",
43 tail
= (struct rtattr
*)(((void*)n
)+NLMSG_ALIGN(n
->nlmsg_len
));
44 addattr_l(n
, MAX_MSG
, TCA_OPTIONS
, NULL
, 0);
47 if (matches(*argv
, "match") == 0) {
49 if (parse_ematch(&argc
, &argv
, TCA_CGROUP_EMATCHES
, n
)) {
50 fprintf(stderr
, "Illegal \"ematch\"\n");
54 } else if (matches(*argv
, "action") == 0) {
56 if (parse_action(&argc
, &argv
, TCA_CGROUP_ACT
, n
)) {
57 fprintf(stderr
, "Illegal \"action\"\n");
62 } else if (matches(*argv
, "police") == 0) {
64 if (parse_police(&argc
, &argv
, TCA_CGROUP_POLICE
, n
)) {
65 fprintf(stderr
, "Illegal \"police\"\n");
69 } else if (strcmp(*argv
, "help") == 0) {
73 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
79 tail
->rta_len
= (((void*)n
)+n
->nlmsg_len
) - (void*)tail
;
83 static int cgroup_print_opt(struct filter_util
*qu
, FILE *f
,
84 struct rtattr
*opt
, __u32 handle
)
86 struct rtattr
*tb
[TCA_CGROUP_MAX
+1];
91 parse_rtattr_nested(tb
, TCA_CGROUP_MAX
, opt
);
94 fprintf(f
, "handle 0x%x ", handle
);
96 if (tb
[TCA_CGROUP_EMATCHES
])
97 print_ematch(f
, tb
[TCA_CGROUP_EMATCHES
]);
99 if (tb
[TCA_CGROUP_POLICE
]) {
101 tc_print_police(f
, tb
[TCA_CGROUP_POLICE
]);
104 if (tb
[TCA_CGROUP_ACT
])
105 tc_print_action(f
, tb
[TCA_CGROUP_ACT
]);
110 struct filter_util cgroup_filter_util
= {
112 .parse_fopt
= cgroup_parse_opt
,
113 .print_fopt
= cgroup_print_opt
,