fprintf(stderr, "\n");
fprintf(stderr, " tc filter show [ dev STRING ] [ root | parent CLASSID ]\n");
fprintf(stderr, "Where:\n");
- fprintf(stderr, "FILTER_TYPE := { rsvp | u32 | fw | route | etc. }\n");
+ fprintf(stderr, "FILTER_TYPE := { rsvp | u32 | bpf | fw | route | etc. }\n");
fprintf(stderr, "FILTERID := ... format depends on classifier, see there\n");
fprintf(stderr, "OPTIONS := ... try tc filter add <desired FILTER_KIND> help\n");
return;
}
-int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
+static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
{
struct {
struct nlmsghdr n;
struct filter_util *q = NULL;
__u32 prio = 0;
__u32 protocol = 0;
+ int protocol_set = 0;
char *fhandle = NULL;
char d[16];
char k[16];
req.n.nlmsg_type = cmd;
req.t.tcm_family = AF_UNSPEC;
+ if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE)
+ protocol = htons(ETH_P_ALL);
+
while (argc > 0) {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
if (req.t.tcm_parent)
duparg("parent", *argv);
if (get_tc_classid(&handle, *argv))
- invarg(*argv, "Invalid parent ID");
+ invarg("Invalid parent ID", *argv);
req.t.tcm_parent = handle;
} else if (strcmp(*argv, "handle") == 0) {
NEXT_ARG();
NEXT_ARG();
if (prio)
duparg("priority", *argv);
- if (get_u32(&prio, *argv, 0))
- invarg(*argv, "invalid priority value");
+ if (get_u32(&prio, *argv, 0) || prio > 0xFFFF)
+ invarg("invalid priority value", *argv);
} else if (matches(*argv, "protocol") == 0) {
__u16 id;
NEXT_ARG();
- if (protocol)
+ if (protocol_set)
duparg("protocol", *argv);
if (ll_proto_a2n(&id, *argv))
- invarg(*argv, "invalid protocol");
+ invarg("invalid protocol", *argv);
protocol = id;
+ protocol_set = 1;
} else if (matches(*argv, "estimator") == 0) {
if (parse_estimator(&argc, &argv, &est) < 0)
return -1;
} else if (matches(*argv, "help") == 0) {
usage();
+ return 0;
} else {
strncpy(k, *argv, sizeof(k)-1);
argc--; argv++;
}
- if (!protocol) {
- fprintf(stderr, "\"protocol\" is required.\n");
- return -1;
- }
-
req.t.tcm_info = TC_H_MAKE(prio<<16, protocol);
if (k[0])
if (d[0]) {
- ll_init_map(&rth);
+ ll_init_map(&rth);
if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d);
}
}
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) {
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
fprintf(stderr, "We have an error talking to the kernel\n");
return 2;
}
static int filter_ifindex;
static __u32 filter_prio;
static __u32 filter_protocol;
+__u16 f_proto = 0;
int print_filter(const struct sockaddr_nl *who,
struct nlmsghdr *n,
}
}
if (t->tcm_info) {
- __u32 protocol = TC_H_MIN(t->tcm_info);
+ f_proto = TC_H_MIN(t->tcm_info);
__u32 prio = TC_H_MAJ(t->tcm_info)>>16;
- if (!filter_protocol || filter_protocol != protocol) {
- if (protocol) {
+ if (!filter_protocol || filter_protocol != f_proto) {
+ if (f_proto) {
SPRINT_BUF(b1);
fprintf(fp, "protocol %s ",
- ll_proto_n2a(protocol, b1, sizeof(b1)));
+ ll_proto_n2a(f_proto, b1, sizeof(b1)));
}
}
if (!filter_prio || filter_prio != prio) {
fprintf(fp, "pref %u ", prio);
}
}
- fprintf(fp, "%s ", (char*)RTA_DATA(tb[TCA_KIND]));
+ fprintf(fp, "%s ", rta_getattr_str(tb[TCA_KIND]));
q = get_filter_kind(RTA_DATA(tb[TCA_KIND]));
if (tb[TCA_OPTIONS]) {
if (q)
}
-int tc_filter_list(int argc, char **argv)
+static int tc_filter_list(int argc, char **argv)
{
struct tcmsg t;
char d[16];
if (t.tcm_parent)
duparg("parent", *argv);
if (get_tc_classid(&handle, *argv))
- invarg(*argv, "invalid parent ID");
+ invarg("invalid parent ID", *argv);
filter_parent = t.tcm_parent = handle;
} else if (strcmp(*argv, "handle") == 0) {
NEXT_ARG();
if (prio)
duparg("priority", *argv);
if (get_u32(&prio, *argv, 0))
- invarg(*argv, "invalid preference");
+ invarg("invalid preference", *argv);
filter_prio = prio;
} else if (matches(*argv, "protocol") == 0) {
__u16 res;
if (protocol)
duparg("protocol", *argv);
if (ll_proto_a2n(&res, *argv))
- invarg(*argv, "invalid protocol");
+ invarg("invalid protocol", *argv);
protocol = res;
filter_protocol = protocol;
} else if (matches(*argv, "help") == 0) {
t.tcm_info = TC_H_MAKE(prio<<16, protocol);
- ll_init_map(&rth);
+ ll_init_map(&rth);
if (d[0]) {
if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
filter_ifindex = t.tcm_ifindex;
}
- if (rtnl_dump_request(&rth, RTM_GETTFILTER, &t, sizeof(t)) < 0) {
+ if (rtnl_dump_request(&rth, RTM_GETTFILTER, &t, sizeof(t)) < 0) {
perror("Cannot send dump request");
return 1;
}
- if (rtnl_dump_filter(&rth, print_filter, stdout, NULL, NULL) < 0) {
+ if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
return 1;
}