]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/tc_filter.c
Merge branch 'master' into net-next
[mirror_iproute2.git] / tc / tc_filter.c
1 /*
2 * tc_filter.c "tc filter".
3 *
4 * This program is free software; you can redistribute 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.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 *
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <string.h>
21 #include <linux/if_ether.h>
22
23 #include "rt_names.h"
24 #include "utils.h"
25 #include "tc_util.h"
26 #include "tc_common.h"
27
28 static void usage(void)
29 {
30 fprintf(stderr,
31 "Usage: tc filter [ add | del | change | replace | show ] dev STRING\n"
32 "Usage: tc filter get dev STRING parent CLASSID protocol PROTO handle FILTERID pref PRIO FILTER_TYPE\n"
33 " [ pref PRIO ] protocol PROTO [ chain CHAIN_INDEX ]\n"
34 " [ estimator INTERVAL TIME_CONSTANT ]\n"
35 " [ root | ingress | egress | parent CLASSID ]\n"
36 " [ handle FILTERID ] [ [ FILTER_TYPE ] [ help | OPTIONS ] ]\n"
37 "\n"
38 " tc filter show [ dev STRING ] [ root | ingress | egress | parent CLASSID ]\n"
39 "Where:\n"
40 "FILTER_TYPE := { rsvp | u32 | bpf | fw | route | etc. }\n"
41 "FILTERID := ... format depends on classifier, see there\n"
42 "OPTIONS := ... try tc filter add <desired FILTER_KIND> help\n");
43 }
44
45 struct tc_filter_req {
46 struct nlmsghdr n;
47 struct tcmsg t;
48 char buf[MAX_MSG];
49 };
50
51 static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv,
52 void *buf, size_t buflen)
53 {
54 struct tc_filter_req *req, filter_req;
55 struct filter_util *q = NULL;
56 struct tc_estimator est = {};
57 char k[FILTER_NAMESZ] = {};
58 int chain_index_set = 0;
59 char d[IFNAMSIZ] = {};
60 int protocol_set = 0;
61 char *fhandle = NULL;
62 __u32 protocol = 0;
63 __u32 chain_index;
64 struct iovec iov;
65 __u32 prio = 0;
66 int ret;
67
68 if (buf) {
69 req = buf;
70 if (buflen < sizeof (struct tc_filter_req)) {
71 fprintf(stderr, "buffer is too small: %zu\n", buflen);
72 return -1;
73 }
74 } else {
75 memset(&filter_req, 0, sizeof (struct tc_filter_req));
76 req = &filter_req;
77 }
78
79 req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
80 req->n.nlmsg_flags = NLM_F_REQUEST | flags;
81 req->n.nlmsg_type = cmd;
82 req->t.tcm_family = AF_UNSPEC;
83
84 if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE)
85 protocol = htons(ETH_P_ALL);
86
87 while (argc > 0) {
88 if (strcmp(*argv, "dev") == 0) {
89 NEXT_ARG();
90 if (d[0])
91 duparg("dev", *argv);
92 strncpy(d, *argv, sizeof(d)-1);
93 } else if (strcmp(*argv, "root") == 0) {
94 if (req->t.tcm_parent) {
95 fprintf(stderr,
96 "Error: \"root\" is duplicate parent ID\n");
97 return -1;
98 }
99 req->t.tcm_parent = TC_H_ROOT;
100 } else if (strcmp(*argv, "ingress") == 0) {
101 if (req->t.tcm_parent) {
102 fprintf(stderr,
103 "Error: \"ingress\" is duplicate parent ID\n");
104 return -1;
105 }
106 req->t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
107 TC_H_MIN_INGRESS);
108 } else if (strcmp(*argv, "egress") == 0) {
109 if (req->t.tcm_parent) {
110 fprintf(stderr,
111 "Error: \"egress\" is duplicate parent ID\n");
112 return -1;
113 }
114 req->t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
115 TC_H_MIN_EGRESS);
116 } else if (strcmp(*argv, "parent") == 0) {
117 __u32 handle;
118
119 NEXT_ARG();
120 if (req->t.tcm_parent)
121 duparg("parent", *argv);
122 if (get_tc_classid(&handle, *argv))
123 invarg("Invalid parent ID", *argv);
124 req->t.tcm_parent = handle;
125 } else if (strcmp(*argv, "handle") == 0) {
126 NEXT_ARG();
127 if (fhandle)
128 duparg("handle", *argv);
129 fhandle = *argv;
130 } else if (matches(*argv, "preference") == 0 ||
131 matches(*argv, "priority") == 0) {
132 NEXT_ARG();
133 if (prio)
134 duparg("priority", *argv);
135 if (get_u32(&prio, *argv, 0) || prio > 0xFFFF)
136 invarg("invalid priority value", *argv);
137 } else if (matches(*argv, "protocol") == 0) {
138 __u16 id;
139
140 NEXT_ARG();
141 if (protocol_set)
142 duparg("protocol", *argv);
143 if (ll_proto_a2n(&id, *argv))
144 invarg("invalid protocol", *argv);
145 protocol = id;
146 protocol_set = 1;
147 } else if (matches(*argv, "chain") == 0) {
148 NEXT_ARG();
149 if (chain_index_set)
150 duparg("chain", *argv);
151 if (get_u32(&chain_index, *argv, 0))
152 invarg("invalid chain index value", *argv);
153 chain_index_set = 1;
154 } else if (matches(*argv, "estimator") == 0) {
155 if (parse_estimator(&argc, &argv, &est) < 0)
156 return -1;
157 } else if (matches(*argv, "help") == 0) {
158 usage();
159 return 0;
160 } else {
161 strncpy(k, *argv, sizeof(k)-1);
162
163 q = get_filter_kind(k);
164 argc--; argv++;
165 break;
166 }
167
168 argc--; argv++;
169 }
170
171 req->t.tcm_info = TC_H_MAKE(prio<<16, protocol);
172
173 if (chain_index_set)
174 addattr32(&req->n, sizeof(*req), TCA_CHAIN, chain_index);
175
176 if (k[0])
177 addattr_l(&req->n, sizeof(*req), TCA_KIND, k, strlen(k)+1);
178
179 if (d[0]) {
180 ll_init_map(&rth);
181
182 req->t.tcm_ifindex = ll_name_to_index(d);
183 if (req->t.tcm_ifindex == 0) {
184 fprintf(stderr, "Cannot find device \"%s\"\n", d);
185 return 1;
186 }
187 }
188
189 if (q) {
190 if (q->parse_fopt(q, fhandle, argc, argv, &req->n))
191 return 1;
192 } else {
193 if (fhandle) {
194 fprintf(stderr,
195 "Must specify filter type when using \"handle\"\n");
196 return -1;
197 }
198 if (argc) {
199 if (matches(*argv, "help") == 0)
200 usage();
201 fprintf(stderr,
202 "Garbage instead of arguments \"%s ...\". Try \"tc filter help\".\n",
203 *argv);
204 return -1;
205 }
206 }
207
208 if (est.ewma_log)
209 addattr_l(&req->n, sizeof(*req), TCA_RATE, &est, sizeof(est));
210
211 if (buf)
212 return 0;
213
214 iov.iov_base = &req->n;
215 iov.iov_len = req->n.nlmsg_len;
216 ret = rtnl_talk_iov(&rth, &iov, 1, NULL);
217 if (ret < 0) {
218 fprintf(stderr, "We have an error talking to the kernel, %d\n", ret);
219 return 2;
220 }
221
222 return 0;
223 }
224
225 static __u32 filter_parent;
226 static int filter_ifindex;
227 static __u32 filter_prio;
228 static __u32 filter_protocol;
229 static __u32 filter_chain_index;
230 static int filter_chain_index_set;
231 __u16 f_proto;
232
233 int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
234 {
235 FILE *fp = (FILE *)arg;
236 struct tcmsg *t = NLMSG_DATA(n);
237 int len = n->nlmsg_len;
238 struct rtattr *tb[TCA_MAX+1];
239 struct filter_util *q;
240 char abuf[256];
241
242 if (n->nlmsg_type != RTM_NEWTFILTER &&
243 n->nlmsg_type != RTM_GETTFILTER &&
244 n->nlmsg_type != RTM_DELTFILTER) {
245 fprintf(stderr, "Not a filter(cmd %d)\n", n->nlmsg_type);
246 return 0;
247 }
248 len -= NLMSG_LENGTH(sizeof(*t));
249 if (len < 0) {
250 fprintf(stderr, "Wrong len %d\n", len);
251 return -1;
252 }
253
254 parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
255
256 if (tb[TCA_KIND] == NULL) {
257 fprintf(stderr, "print_filter: NULL kind\n");
258 return -1;
259 }
260
261 open_json_object(NULL);
262
263 if (n->nlmsg_type == RTM_DELTFILTER)
264 print_bool(PRINT_ANY, "deleted", "deleted ", true);
265
266 if (n->nlmsg_type == RTM_NEWTFILTER &&
267 (n->nlmsg_flags & NLM_F_CREATE) &&
268 !(n->nlmsg_flags & NLM_F_EXCL))
269 print_bool(PRINT_ANY, "replaced", "replaced ", true);
270
271 if (n->nlmsg_type == RTM_NEWTFILTER &&
272 (n->nlmsg_flags & NLM_F_CREATE) &&
273 (n->nlmsg_flags & NLM_F_EXCL))
274 print_bool(PRINT_ANY, "added", "added ", true);
275
276 print_string(PRINT_FP, NULL, "filter ", NULL);
277 if (!filter_ifindex || filter_ifindex != t->tcm_ifindex)
278 print_string(PRINT_ANY, "dev", "dev %s ",
279 ll_index_to_name(t->tcm_ifindex));
280
281 if (!filter_parent || filter_parent != t->tcm_parent) {
282 if (t->tcm_parent == TC_H_ROOT)
283 print_bool(PRINT_ANY, "root", "root ", true);
284 else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS))
285 print_bool(PRINT_ANY, "ingress", "ingress ", true);
286 else if (t->tcm_parent == TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_EGRESS))
287 print_bool(PRINT_ANY, "egress", "egress ", true);
288 else {
289 print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
290 print_string(PRINT_ANY, "parent", "parent %s ", abuf);
291 }
292 }
293
294 if (t->tcm_info) {
295 f_proto = TC_H_MIN(t->tcm_info);
296 __u32 prio = TC_H_MAJ(t->tcm_info)>>16;
297
298 if (!filter_protocol || filter_protocol != f_proto) {
299 if (f_proto) {
300 SPRINT_BUF(b1);
301 print_string(PRINT_ANY, "protocol",
302 "protocol %s ",
303 ll_proto_n2a(f_proto, b1, sizeof(b1)));
304 }
305 }
306 if (!filter_prio || filter_prio != prio) {
307 if (prio)
308 print_uint(PRINT_ANY, "pref", "pref %u ", prio);
309 }
310 }
311 print_string(PRINT_ANY, "kind", "%s ", rta_getattr_str(tb[TCA_KIND]));
312
313 if (tb[TCA_CHAIN]) {
314 __u32 chain_index = rta_getattr_u32(tb[TCA_CHAIN]);
315
316 if (!filter_chain_index_set ||
317 filter_chain_index != chain_index)
318 print_uint(PRINT_ANY, "chain", "chain %u ",
319 chain_index);
320 }
321
322 q = get_filter_kind(RTA_DATA(tb[TCA_KIND]));
323 if (tb[TCA_OPTIONS]) {
324 open_json_object("options");
325 if (q)
326 q->print_fopt(q, fp, tb[TCA_OPTIONS], t->tcm_handle);
327 else
328 print_string(PRINT_FP, NULL,
329 "[cannot parse parameters]", NULL);
330 close_json_object();
331 }
332 print_string(PRINT_FP, NULL, "\n", NULL);
333
334 if (show_stats && (tb[TCA_STATS] || tb[TCA_STATS2])) {
335 print_tcstats_attr(fp, tb, " ", NULL);
336 print_string(PRINT_FP, NULL, "\n", NULL);
337 }
338
339 close_json_object();
340 fflush(fp);
341 return 0;
342 }
343
344 static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv)
345 {
346 struct {
347 struct nlmsghdr n;
348 struct tcmsg t;
349 char buf[MAX_MSG];
350 } req = {
351 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
352 /* NLM_F_ECHO is for backward compatibility. old kernels never
353 * respond without it and newer kernels will ignore it.
354 * In old kernels there is a side effect:
355 * In addition to a response to the GET you will receive an
356 * event (if you do tc mon).
357 */
358 .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ECHO | flags,
359 .n.nlmsg_type = cmd,
360 .t.tcm_parent = TC_H_UNSPEC,
361 .t.tcm_family = AF_UNSPEC,
362 };
363 struct nlmsghdr *answer;
364 struct filter_util *q = NULL;
365 __u32 prio = 0;
366 __u32 protocol = 0;
367 int protocol_set = 0;
368 __u32 chain_index;
369 int chain_index_set = 0;
370 __u32 parent_handle = 0;
371 char *fhandle = NULL;
372 char d[IFNAMSIZ] = {};
373 char k[FILTER_NAMESZ] = {};
374
375 while (argc > 0) {
376 if (strcmp(*argv, "dev") == 0) {
377 NEXT_ARG();
378 if (d[0])
379 duparg("dev", *argv);
380 strncpy(d, *argv, sizeof(d)-1);
381 } else if (strcmp(*argv, "root") == 0) {
382 if (req.t.tcm_parent) {
383 fprintf(stderr,
384 "Error: \"root\" is duplicate parent ID\n");
385 return -1;
386 }
387 req.t.tcm_parent = TC_H_ROOT;
388 } else if (strcmp(*argv, "ingress") == 0) {
389 if (req.t.tcm_parent) {
390 fprintf(stderr,
391 "Error: \"ingress\" is duplicate parent ID\n");
392 return -1;
393 }
394 req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
395 TC_H_MIN_INGRESS);
396 } else if (strcmp(*argv, "egress") == 0) {
397 if (req.t.tcm_parent) {
398 fprintf(stderr,
399 "Error: \"egress\" is duplicate parent ID\n");
400 return -1;
401 }
402 req.t.tcm_parent = TC_H_MAKE(TC_H_CLSACT,
403 TC_H_MIN_EGRESS);
404 } else if (strcmp(*argv, "parent") == 0) {
405
406 NEXT_ARG();
407 if (req.t.tcm_parent)
408 duparg("parent", *argv);
409 if (get_tc_classid(&parent_handle, *argv))
410 invarg("Invalid parent ID", *argv);
411 req.t.tcm_parent = parent_handle;
412 } else if (strcmp(*argv, "handle") == 0) {
413 NEXT_ARG();
414 if (fhandle)
415 duparg("handle", *argv);
416 fhandle = *argv;
417 } else if (matches(*argv, "preference") == 0 ||
418 matches(*argv, "priority") == 0) {
419 NEXT_ARG();
420 if (prio)
421 duparg("priority", *argv);
422 if (get_u32(&prio, *argv, 0) || prio > 0xFFFF)
423 invarg("invalid priority value", *argv);
424 } else if (matches(*argv, "protocol") == 0) {
425 __u16 id;
426
427 NEXT_ARG();
428 if (protocol_set)
429 duparg("protocol", *argv);
430 if (ll_proto_a2n(&id, *argv))
431 invarg("invalid protocol", *argv);
432 protocol = id;
433 protocol_set = 1;
434 } else if (matches(*argv, "chain") == 0) {
435 NEXT_ARG();
436 if (chain_index_set)
437 duparg("chain", *argv);
438 if (get_u32(&chain_index, *argv, 0))
439 invarg("invalid chain index value", *argv);
440 chain_index_set = 1;
441 } else if (matches(*argv, "help") == 0) {
442 usage();
443 return 0;
444 } else {
445 if (!**argv)
446 invarg("invalid filter name", *argv);
447
448 strncpy(k, *argv, sizeof(k)-1);
449
450 q = get_filter_kind(k);
451 argc--; argv++;
452 break;
453 }
454
455 argc--; argv++;
456 }
457
458 if (!protocol_set) {
459 fprintf(stderr, "Must specify filter protocol\n");
460 return -1;
461 }
462
463 if (!prio) {
464 fprintf(stderr, "Must specify filter priority\n");
465 return -1;
466 }
467
468 req.t.tcm_info = TC_H_MAKE(prio<<16, protocol);
469
470 if (chain_index_set)
471 addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
472
473 if (req.t.tcm_parent == TC_H_UNSPEC) {
474 fprintf(stderr, "Must specify filter parent\n");
475 return -1;
476 }
477
478 if (k[0])
479 addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1);
480 else {
481 fprintf(stderr, "Must specify filter type\n");
482 return -1;
483 }
484
485 if (d[0]) {
486 ll_init_map(&rth);
487
488 req.t.tcm_ifindex = ll_name_to_index(d);
489 if (req.t.tcm_ifindex == 0) {
490 fprintf(stderr, "Cannot find device \"%s\"\n", d);
491 return 1;
492 }
493 filter_ifindex = req.t.tcm_ifindex;
494 } else {
495 fprintf(stderr, "Must specify netdevice \"dev\"\n");
496 return -1;
497 }
498
499 if (q->parse_fopt(q, fhandle, argc, argv, &req.n))
500 return 1;
501
502 if (!fhandle) {
503 fprintf(stderr, "Must specify filter \"handle\"\n");
504 return -1;
505 }
506
507 if (argc) {
508 if (matches(*argv, "help") == 0)
509 usage();
510 fprintf(stderr,
511 "Garbage instead of arguments \"%s ...\". Try \"tc filter help\".\n",
512 *argv);
513 return -1;
514 }
515
516 if (rtnl_talk(&rth, &req.n, &answer) < 0) {
517 fprintf(stderr, "We have an error talking to the kernel\n");
518 return 2;
519 }
520
521 new_json_obj(json);
522 print_filter(NULL, answer, (void *)stdout);
523 delete_json_obj();
524
525 free(answer);
526 return 0;
527 }
528
529 static int tc_filter_list(int argc, char **argv)
530 {
531 struct {
532 struct nlmsghdr n;
533 struct tcmsg t;
534 char buf[MAX_MSG];
535 } req = {
536 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
537 .n.nlmsg_type = RTM_GETTFILTER,
538 .t.tcm_parent = TC_H_UNSPEC,
539 .t.tcm_family = AF_UNSPEC,
540 };
541 char d[IFNAMSIZ] = {};
542 __u32 prio = 0;
543 __u32 protocol = 0;
544 __u32 chain_index;
545 char *fhandle = NULL;
546
547 while (argc > 0) {
548 if (strcmp(*argv, "dev") == 0) {
549 NEXT_ARG();
550 if (d[0])
551 duparg("dev", *argv);
552 strncpy(d, *argv, sizeof(d)-1);
553 } else if (strcmp(*argv, "root") == 0) {
554 if (req.t.tcm_parent) {
555 fprintf(stderr,
556 "Error: \"root\" is duplicate parent ID\n");
557 return -1;
558 }
559 filter_parent = req.t.tcm_parent = TC_H_ROOT;
560 } else if (strcmp(*argv, "ingress") == 0) {
561 if (req.t.tcm_parent) {
562 fprintf(stderr,
563 "Error: \"ingress\" is duplicate parent ID\n");
564 return -1;
565 }
566 filter_parent = TC_H_MAKE(TC_H_CLSACT,
567 TC_H_MIN_INGRESS);
568 req.t.tcm_parent = filter_parent;
569 } else if (strcmp(*argv, "egress") == 0) {
570 if (req.t.tcm_parent) {
571 fprintf(stderr,
572 "Error: \"egress\" is duplicate parent ID\n");
573 return -1;
574 }
575 filter_parent = TC_H_MAKE(TC_H_CLSACT,
576 TC_H_MIN_EGRESS);
577 req.t.tcm_parent = filter_parent;
578 } else if (strcmp(*argv, "parent") == 0) {
579 __u32 handle;
580
581 NEXT_ARG();
582 if (req.t.tcm_parent)
583 duparg("parent", *argv);
584 if (get_tc_classid(&handle, *argv))
585 invarg("invalid parent ID", *argv);
586 filter_parent = req.t.tcm_parent = handle;
587 } else if (strcmp(*argv, "handle") == 0) {
588 NEXT_ARG();
589 if (fhandle)
590 duparg("handle", *argv);
591 fhandle = *argv;
592 } else if (matches(*argv, "preference") == 0 ||
593 matches(*argv, "priority") == 0) {
594 NEXT_ARG();
595 if (prio)
596 duparg("priority", *argv);
597 if (get_u32(&prio, *argv, 0))
598 invarg("invalid preference", *argv);
599 filter_prio = prio;
600 } else if (matches(*argv, "protocol") == 0) {
601 __u16 res;
602
603 NEXT_ARG();
604 if (protocol)
605 duparg("protocol", *argv);
606 if (ll_proto_a2n(&res, *argv))
607 invarg("invalid protocol", *argv);
608 protocol = res;
609 filter_protocol = protocol;
610 } else if (matches(*argv, "chain") == 0) {
611 NEXT_ARG();
612 if (filter_chain_index_set)
613 duparg("chain", *argv);
614 if (get_u32(&chain_index, *argv, 0))
615 invarg("invalid chain index value", *argv);
616 filter_chain_index_set = 1;
617 filter_chain_index = chain_index;
618 } else if (matches(*argv, "help") == 0) {
619 usage();
620 } else {
621 fprintf(stderr,
622 " What is \"%s\"? Try \"tc filter help\"\n",
623 *argv);
624 return -1;
625 }
626
627 argc--; argv++;
628 }
629
630 req.t.tcm_info = TC_H_MAKE(prio<<16, protocol);
631
632 ll_init_map(&rth);
633
634 if (d[0]) {
635 req.t.tcm_ifindex = ll_name_to_index(d);
636 if (req.t.tcm_ifindex == 0) {
637 fprintf(stderr, "Cannot find device \"%s\"\n", d);
638 return 1;
639 }
640 filter_ifindex = req.t.tcm_ifindex;
641 }
642
643 if (filter_chain_index_set)
644 addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index);
645
646 if (rtnl_dump_request_n(&rth, &req.n) < 0) {
647 perror("Cannot send dump request");
648 return 1;
649 }
650
651 new_json_obj(json);
652 if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
653 fprintf(stderr, "Dump terminated\n");
654 return 1;
655 }
656 delete_json_obj();
657
658 return 0;
659 }
660
661 int do_filter(int argc, char **argv, void *buf, size_t buflen)
662 {
663 if (argc < 1)
664 return tc_filter_list(0, NULL);
665 if (matches(*argv, "add") == 0)
666 return tc_filter_modify(RTM_NEWTFILTER, NLM_F_EXCL|NLM_F_CREATE,
667 argc-1, argv+1, buf, buflen);
668 if (matches(*argv, "change") == 0)
669 return tc_filter_modify(RTM_NEWTFILTER, 0, argc-1, argv+1,
670 buf, buflen);
671 if (matches(*argv, "replace") == 0)
672 return tc_filter_modify(RTM_NEWTFILTER, NLM_F_CREATE, argc-1,
673 argv+1, buf, buflen);
674 if (matches(*argv, "delete") == 0)
675 return tc_filter_modify(RTM_DELTFILTER, 0, argc-1, argv+1,
676 buf, buflen);
677 if (matches(*argv, "get") == 0)
678 return tc_filter_get(RTM_GETTFILTER, 0, argc-1, argv+1);
679 if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
680 || matches(*argv, "lst") == 0)
681 return tc_filter_list(argc-1, argv+1);
682 if (matches(*argv, "help") == 0) {
683 usage();
684 return 0;
685 }
686 fprintf(stderr, "Command \"%s\" is unknown, try \"tc filter help\".\n",
687 *argv);
688 return -1;
689 }