]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/m_action.c
tc: add NLA_F_NESTED flag to all actions options nested block
[mirror_iproute2.git] / tc / m_action.c
1 /*
2 * m_action.c Action Management
3 *
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.
8 *
9 * Authors: J Hadi Salim (hadi@cyberus.ca)
10 *
11 * TODO:
12 * - parse to be passed a filedescriptor for logging purposes
13 *
14 */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <stdbool.h>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24 #include <string.h>
25 #include <dlfcn.h>
26
27 #include "utils.h"
28 #include "tc_common.h"
29 #include "tc_util.h"
30
31 static struct action_util *action_list;
32 #ifdef CONFIG_GACT
33 static int gact_ld; /* f*ckin backward compatibility */
34 #endif
35 static int tab_flush;
36
37 static void act_usage(void)
38 {
39 /*XXX: In the near future add a action->print_help to improve
40 * usability
41 * This would mean new tc will not be backward compatible
42 * with any action .so from the old days. But if someone really
43 * does that, they would know how to fix this ..
44 *
45 */
46 fprintf(stderr,
47 "usage: tc actions <ACTSPECOP>*\n"
48 "Where: ACTSPECOP := ACR | GD | FL\n"
49 " ACR := add | change | replace <ACTSPEC>*\n"
50 " GD := get | delete | <ACTISPEC>*\n"
51 " FL := ls | list | flush | <ACTNAMESPEC>\n"
52 " ACTNAMESPEC := action <ACTNAME>\n"
53 " ACTISPEC := <ACTNAMESPEC> <INDEXSPEC>\n"
54 " ACTSPEC := action <ACTDETAIL> [INDEXSPEC]\n"
55 " INDEXSPEC := index <32 bit indexvalue>\n"
56 " ACTDETAIL := <ACTNAME> <ACTPARAMS>\n"
57 " Example ACTNAME is gact, mirred, bpf, etc\n"
58 " Each action has its own parameters (ACTPARAMS)\n"
59 "\n");
60
61 exit(-1);
62 }
63
64 static int print_noaopt(struct action_util *au, FILE *f, struct rtattr *opt)
65 {
66 if (opt && RTA_PAYLOAD(opt))
67 fprintf(f, "[Unknown action, optlen=%u] ",
68 (unsigned int) RTA_PAYLOAD(opt));
69 return 0;
70 }
71
72 static int parse_noaopt(struct action_util *au, int *argc_p,
73 char ***argv_p, int code, struct nlmsghdr *n)
74 {
75 int argc = *argc_p;
76 char **argv = *argv_p;
77
78 if (argc)
79 fprintf(stderr,
80 "Unknown action \"%s\", hence option \"%s\" is unparsable\n",
81 au->id, *argv);
82 else
83 fprintf(stderr, "Unknown action \"%s\"\n", au->id);
84
85 return -1;
86 }
87
88 static struct action_util *get_action_kind(char *str)
89 {
90 static void *aBODY;
91 void *dlh;
92 char buf[256];
93 struct action_util *a;
94 #ifdef CONFIG_GACT
95 int looked4gact = 0;
96 restart_s:
97 #endif
98 for (a = action_list; a; a = a->next) {
99 if (strcmp(a->id, str) == 0)
100 return a;
101 }
102
103 snprintf(buf, sizeof(buf), "%s/m_%s.so", get_tc_lib(), str);
104 dlh = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
105 if (dlh == NULL) {
106 dlh = aBODY;
107 if (dlh == NULL) {
108 dlh = aBODY = dlopen(NULL, RTLD_LAZY);
109 if (dlh == NULL)
110 goto noexist;
111 }
112 }
113
114 snprintf(buf, sizeof(buf), "%s_action_util", str);
115 a = dlsym(dlh, buf);
116 if (a == NULL)
117 goto noexist;
118
119 reg:
120 a->next = action_list;
121 action_list = a;
122 return a;
123
124 noexist:
125 #ifdef CONFIG_GACT
126 if (!looked4gact) {
127 looked4gact = 1;
128 strcpy(str, "gact");
129 goto restart_s;
130 }
131 #endif
132 a = calloc(1, sizeof(*a));
133 if (a) {
134 strncpy(a->id, "noact", 15);
135 a->parse_aopt = parse_noaopt;
136 a->print_aopt = print_noaopt;
137 goto reg;
138 }
139 return a;
140 }
141
142 static bool
143 new_cmd(char **argv)
144 {
145 return (matches(*argv, "change") == 0) ||
146 (matches(*argv, "replace") == 0) ||
147 (matches(*argv, "delete") == 0) ||
148 (matches(*argv, "get") == 0) ||
149 (matches(*argv, "add") == 0);
150 }
151
152 int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
153 {
154 int argc = *argc_p;
155 char **argv = *argv_p;
156 struct rtattr *tail, *tail2;
157 char k[FILTER_NAMESZ];
158 int act_ck_len = 0;
159 int ok = 0;
160 int eap = 0; /* expect action parameters */
161
162 int ret = 0;
163 int prio = 0;
164 unsigned char act_ck[TC_COOKIE_MAX_SIZE];
165
166 if (argc <= 0)
167 return -1;
168
169 tail2 = addattr_nest(n, MAX_MSG, tca_id);
170
171 while (argc > 0) {
172
173 memset(k, 0, sizeof(k));
174
175 if (strcmp(*argv, "action") == 0) {
176 argc--;
177 argv++;
178 eap = 1;
179 #ifdef CONFIG_GACT
180 if (!gact_ld)
181 get_action_kind("gact");
182 #endif
183 continue;
184 } else if (strcmp(*argv, "flowid") == 0) {
185 break;
186 } else if (strcmp(*argv, "classid") == 0) {
187 break;
188 } else if (strcmp(*argv, "help") == 0) {
189 return -1;
190 } else if (new_cmd(argv)) {
191 goto done0;
192 } else {
193 struct action_util *a = NULL;
194
195 if (!action_a2n(*argv, NULL, false))
196 strncpy(k, "gact", sizeof(k) - 1);
197 else
198 strncpy(k, *argv, sizeof(k) - 1);
199 eap = 0;
200 if (argc > 0) {
201 a = get_action_kind(k);
202 } else {
203 done0:
204 if (ok)
205 break;
206 else
207 goto done;
208 }
209
210 if (a == NULL)
211 goto bad_val;
212
213
214 tail = addattr_nest(n, MAX_MSG, ++prio);
215 addattr_l(n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
216
217 ret = a->parse_aopt(a, &argc, &argv,
218 TCA_ACT_OPTIONS | NLA_F_NESTED,
219 n);
220
221 if (ret < 0) {
222 fprintf(stderr, "bad action parsing\n");
223 goto bad_val;
224 }
225
226 if (*argv && strcmp(*argv, "cookie") == 0) {
227 size_t slen;
228
229 NEXT_ARG();
230 slen = strlen(*argv);
231 if (slen > TC_COOKIE_MAX_SIZE * 2) {
232 char cookie_err_m[128];
233
234 snprintf(cookie_err_m, 128,
235 "%zd Max allowed size %d",
236 slen, TC_COOKIE_MAX_SIZE*2);
237 invarg(cookie_err_m, *argv);
238 }
239
240 if (hex2mem(*argv, act_ck, slen / 2) < 0)
241 invarg("cookie must be a hex string\n",
242 *argv);
243
244 act_ck_len = slen / 2;
245 argc--;
246 argv++;
247 }
248
249 if (act_ck_len)
250 addattr_l(n, MAX_MSG, TCA_ACT_COOKIE,
251 &act_ck, act_ck_len);
252
253 addattr_nest_end(n, tail);
254 ok++;
255 }
256 }
257
258 if (eap > 0) {
259 fprintf(stderr, "bad action empty %d\n", eap);
260 goto bad_val;
261 }
262
263 addattr_nest_end(n, tail2);
264
265 done:
266 *argc_p = argc;
267 *argv_p = argv;
268 return 0;
269 bad_val:
270 /* no need to undo things, returning from here should
271 * cause enough pain
272 */
273 fprintf(stderr, "parse_action: bad value (%d:%s)!\n", argc, *argv);
274 return -1;
275 }
276
277 static int tc_print_one_action(FILE *f, struct rtattr *arg)
278 {
279
280 struct rtattr *tb[TCA_ACT_MAX + 1];
281 int err = 0;
282 struct action_util *a = NULL;
283
284 if (arg == NULL)
285 return -1;
286
287 parse_rtattr_nested(tb, TCA_ACT_MAX, arg);
288
289 if (tb[TCA_ACT_KIND] == NULL) {
290 fprintf(stderr, "NULL Action!\n");
291 return -1;
292 }
293
294
295 a = get_action_kind(RTA_DATA(tb[TCA_ACT_KIND]));
296 if (a == NULL)
297 return err;
298
299 err = a->print_aopt(a, f, tb[TCA_ACT_OPTIONS]);
300
301 if (err < 0)
302 return err;
303
304 if (show_stats && tb[TCA_ACT_STATS]) {
305 print_string(PRINT_FP, NULL, "\tAction statistics:", NULL);
306 print_string(PRINT_FP, NULL, "%s", _SL_);
307 open_json_object("stats");
308 print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL);
309 close_json_object();
310 print_string(PRINT_FP, NULL, "%s", _SL_);
311 }
312 if (tb[TCA_ACT_COOKIE]) {
313 int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]);
314 char b1[strsz * 2 + 1];
315
316 print_string(PRINT_ANY, "cookie", "\tcookie %s",
317 hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),
318 strsz, b1, sizeof(b1)));
319 print_string(PRINT_FP, NULL, "%s", _SL_);
320 }
321
322 return 0;
323 }
324
325 static int
326 tc_print_action_flush(FILE *f, const struct rtattr *arg)
327 {
328
329 struct rtattr *tb[TCA_MAX + 1];
330 int err = 0;
331 struct action_util *a = NULL;
332 __u32 *delete_count = 0;
333
334 parse_rtattr_nested(tb, TCA_MAX, arg);
335
336 if (tb[TCA_KIND] == NULL) {
337 fprintf(stderr, "NULL Action!\n");
338 return -1;
339 }
340
341 a = get_action_kind(RTA_DATA(tb[TCA_KIND]));
342 if (a == NULL)
343 return err;
344
345 delete_count = RTA_DATA(tb[TCA_FCNT]);
346 fprintf(f, " %s (%d entries)\n", a->id, *delete_count);
347 tab_flush = 0;
348 return 0;
349 }
350
351 int
352 tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
353 {
354
355 int i;
356
357 if (arg == NULL)
358 return 0;
359
360 if (!tot_acts)
361 tot_acts = TCA_ACT_MAX_PRIO;
362
363 struct rtattr *tb[tot_acts + 1];
364
365 parse_rtattr_nested(tb, tot_acts, arg);
366
367 if (tab_flush && tb[0] && !tb[1])
368 return tc_print_action_flush(f, tb[0]);
369
370 open_json_array(PRINT_JSON, "actions");
371 for (i = 0; i <= tot_acts; i++) {
372 if (tb[i]) {
373 open_json_object(NULL);
374 print_string(PRINT_FP, NULL, "%s", _SL_);
375 print_uint(PRINT_ANY, "order",
376 "\taction order %u: ", i);
377 if (tc_print_one_action(f, tb[i]) < 0) {
378 print_string(PRINT_FP, NULL,
379 "Error printing action\n", NULL);
380 }
381 close_json_object();
382 }
383
384 }
385 close_json_array(PRINT_JSON, NULL);
386
387 return 0;
388 }
389
390 int print_action(struct nlmsghdr *n, void *arg)
391 {
392 FILE *fp = (FILE *)arg;
393 struct tcamsg *t = NLMSG_DATA(n);
394 int len = n->nlmsg_len;
395 __u32 *tot_acts = NULL;
396 struct rtattr *tb[TCA_ROOT_MAX+1];
397
398 len -= NLMSG_LENGTH(sizeof(*t));
399
400 if (len < 0) {
401 fprintf(stderr, "Wrong len %d\n", len);
402 return -1;
403 }
404
405 parse_rtattr(tb, TCA_ROOT_MAX, TA_RTA(t), len);
406
407 if (tb[TCA_ROOT_COUNT])
408 tot_acts = RTA_DATA(tb[TCA_ROOT_COUNT]);
409
410 open_json_object(NULL);
411 print_uint(PRINT_ANY, "total acts", "total acts %u",
412 tot_acts ? *tot_acts : 0);
413 print_string(PRINT_FP, NULL, "%s", _SL_);
414 close_json_object();
415 if (tb[TCA_ACT_TAB] == NULL) {
416 if (n->nlmsg_type != RTM_GETACTION)
417 fprintf(stderr, "print_action: NULL kind\n");
418 return -1;
419 }
420
421 if (n->nlmsg_type == RTM_DELACTION) {
422 if (n->nlmsg_flags & NLM_F_ROOT) {
423 fprintf(fp, "Flushed table ");
424 tab_flush = 1;
425 } else {
426 fprintf(fp, "Deleted action ");
427 }
428 }
429
430 if (n->nlmsg_type == RTM_NEWACTION) {
431 if ((n->nlmsg_flags & NLM_F_CREATE) &&
432 !(n->nlmsg_flags & NLM_F_REPLACE)) {
433 fprintf(fp, "Added action ");
434 } else if (n->nlmsg_flags & NLM_F_REPLACE) {
435 fprintf(fp, "Replaced action ");
436 }
437 }
438
439 open_json_object(NULL);
440 tc_print_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0);
441 close_json_object();
442
443 return 0;
444 }
445
446 static int tc_action_gd(int cmd, unsigned int flags,
447 int *argc_p, char ***argv_p)
448 {
449 char k[FILTER_NAMESZ];
450 struct action_util *a = NULL;
451 int argc = *argc_p;
452 char **argv = *argv_p;
453 int prio = 0;
454 int ret = 0;
455 __u32 i = 0;
456 struct rtattr *tail;
457 struct rtattr *tail2;
458 struct nlmsghdr *ans = NULL;
459
460 struct {
461 struct nlmsghdr n;
462 struct tcamsg t;
463 char buf[MAX_MSG];
464 } req = {
465 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
466 .n.nlmsg_flags = NLM_F_REQUEST | flags,
467 .n.nlmsg_type = cmd,
468 .t.tca_family = AF_UNSPEC,
469 };
470
471 argc -= 1;
472 argv += 1;
473
474
475 tail = addattr_nest(&req.n, MAX_MSG, TCA_ACT_TAB);
476
477 while (argc > 0) {
478 if (strcmp(*argv, "action") == 0) {
479 argc--;
480 argv++;
481 continue;
482 } else if (strcmp(*argv, "help") == 0) {
483 return -1;
484 }
485
486 strncpy(k, *argv, sizeof(k) - 1);
487 a = get_action_kind(k);
488 if (a == NULL) {
489 fprintf(stderr, "Error: non existent action: %s\n", k);
490 ret = -1;
491 goto bad_val;
492 }
493 if (strcmp(a->id, k) != 0) {
494 fprintf(stderr, "Error: non existent action: %s\n", k);
495 ret = -1;
496 goto bad_val;
497 }
498
499 argc -= 1;
500 argv += 1;
501 if (argc <= 0) {
502 fprintf(stderr,
503 "Error: no index specified action: %s\n", k);
504 ret = -1;
505 goto bad_val;
506 }
507
508 if (matches(*argv, "index") == 0) {
509 NEXT_ARG();
510 if (get_u32(&i, *argv, 10)) {
511 fprintf(stderr, "Illegal \"index\"\n");
512 ret = -1;
513 goto bad_val;
514 }
515 argc -= 1;
516 argv += 1;
517 } else {
518 fprintf(stderr,
519 "Error: no index specified action: %s\n", k);
520 ret = -1;
521 goto bad_val;
522 }
523
524 tail2 = addattr_nest(&req.n, MAX_MSG, ++prio);
525 addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
526 if (i > 0)
527 addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i);
528 addattr_nest_end(&req.n, tail2);
529
530 }
531
532 addattr_nest_end(&req.n, tail);
533
534 req.n.nlmsg_seq = rth.dump = ++rth.seq;
535
536 if (rtnl_talk(&rth, &req.n, cmd == RTM_DELACTION ? NULL : &ans) < 0) {
537 fprintf(stderr, "We have an error talking to the kernel\n");
538 return 1;
539 }
540
541 if (cmd == RTM_GETACTION) {
542 new_json_obj(json);
543 ret = print_action(ans, stdout);
544 if (ret < 0) {
545 fprintf(stderr, "Dump terminated\n");
546 free(ans);
547 delete_json_obj();
548 return 1;
549 }
550 delete_json_obj();
551 }
552 free(ans);
553
554 *argc_p = argc;
555 *argv_p = argv;
556 bad_val:
557 return ret;
558 }
559
560 struct tc_action_req {
561 struct nlmsghdr n;
562 struct tcamsg t;
563 char buf[MAX_MSG];
564 };
565
566 static int tc_action_modify(int cmd, unsigned int flags,
567 int *argc_p, char ***argv_p,
568 void *buf, size_t buflen)
569 {
570 struct tc_action_req *req, action_req;
571 char **argv = *argv_p;
572 struct rtattr *tail;
573 int argc = *argc_p;
574 struct iovec iov;
575 int ret = 0;
576
577 if (buf) {
578 req = buf;
579 if (buflen < sizeof (struct tc_action_req)) {
580 fprintf(stderr, "buffer is too small: %zu\n", buflen);
581 return -1;
582 }
583 } else {
584 memset(&action_req, 0, sizeof (struct tc_action_req));
585 req = &action_req;
586 }
587
588 req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
589 req->n.nlmsg_flags = NLM_F_REQUEST | flags;
590 req->n.nlmsg_type = cmd;
591 req->t.tca_family = AF_UNSPEC;
592 tail = NLMSG_TAIL(&req->n);
593
594 argc -= 1;
595 argv += 1;
596 if (parse_action(&argc, &argv, TCA_ACT_TAB, &req->n)) {
597 fprintf(stderr, "Illegal \"action\"\n");
598 return -1;
599 }
600 tail->rta_len = (void *) NLMSG_TAIL(&req->n) - (void *) tail;
601
602 *argc_p = argc;
603 *argv_p = argv;
604
605 if (buf)
606 return 0;
607
608 iov.iov_base = &req->n;
609 iov.iov_len = req->n.nlmsg_len;
610 if (rtnl_talk_iov(&rth, &iov, 1, NULL) < 0) {
611 fprintf(stderr, "We have an error talking to the kernel\n");
612 ret = -1;
613 }
614
615 return ret;
616 }
617
618 static int tc_act_list_or_flush(int *argc_p, char ***argv_p, int event)
619 {
620 struct rtattr *tail, *tail2, *tail3, *tail4;
621 int ret = 0, prio = 0, msg_size = 0;
622 struct action_util *a = NULL;
623 struct nla_bitfield32 flag_select = { 0 };
624 char **argv = *argv_p;
625 __u32 msec_since = 0;
626 int argc = *argc_p;
627 char k[FILTER_NAMESZ];
628 struct {
629 struct nlmsghdr n;
630 struct tcamsg t;
631 char buf[MAX_MSG];
632 } req = {
633 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
634 .t.tca_family = AF_UNSPEC,
635 };
636
637 tail = addattr_nest(&req.n, MAX_MSG, TCA_ACT_TAB);
638 tail2 = NLMSG_TAIL(&req.n);
639
640 strncpy(k, *argv, sizeof(k) - 1);
641 #ifdef CONFIG_GACT
642 if (!gact_ld)
643 get_action_kind("gact");
644
645 #endif
646 a = get_action_kind(k);
647 if (a == NULL) {
648 fprintf(stderr, "bad action %s\n", k);
649 goto bad_val;
650 }
651 if (strcmp(a->id, k) != 0) {
652 fprintf(stderr, "bad action %s\n", k);
653 goto bad_val;
654 }
655 strncpy(k, *argv, sizeof(k) - 1);
656
657 argc -= 1;
658 argv += 1;
659
660 if (argc && (strcmp(*argv, "since") == 0)) {
661 NEXT_ARG();
662 if (get_u32(&msec_since, *argv, 0))
663 invarg("dump time \"since\" is invalid", *argv);
664 }
665
666 addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
667 addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
668 tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
669 addattr_nest_end(&req.n, tail);
670
671 tail3 = NLMSG_TAIL(&req.n);
672 flag_select.value |= TCA_FLAG_LARGE_DUMP_ON;
673 flag_select.selector |= TCA_FLAG_LARGE_DUMP_ON;
674 addattr_l(&req.n, MAX_MSG, TCA_ROOT_FLAGS, &flag_select,
675 sizeof(struct nla_bitfield32));
676 tail3->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail3;
677 if (msec_since) {
678 tail4 = NLMSG_TAIL(&req.n);
679 addattr32(&req.n, MAX_MSG, TCA_ROOT_TIME_DELTA, msec_since);
680 tail4->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail4;
681 }
682 msg_size = NLMSG_ALIGN(req.n.nlmsg_len)
683 - NLMSG_ALIGN(sizeof(struct nlmsghdr));
684
685 if (event == RTM_GETACTION) {
686 if (rtnl_dump_request(&rth, event,
687 (void *)&req.t, msg_size) < 0) {
688 perror("Cannot send dump request");
689 return 1;
690 }
691 new_json_obj(json);
692 ret = rtnl_dump_filter(&rth, print_action, stdout);
693 delete_json_obj();
694 }
695
696 if (event == RTM_DELACTION) {
697 req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len);
698 req.n.nlmsg_type = RTM_DELACTION;
699 req.n.nlmsg_flags |= NLM_F_ROOT;
700 req.n.nlmsg_flags |= NLM_F_REQUEST;
701 if (rtnl_talk(&rth, &req.n, NULL) < 0) {
702 fprintf(stderr, "We have an error flushing\n");
703 return 1;
704 }
705
706 }
707
708 bad_val:
709
710 *argc_p = argc;
711 *argv_p = argv;
712 return ret;
713 }
714
715 int do_action(int argc, char **argv, void *buf, size_t buflen)
716 {
717
718 int ret = 0;
719
720 while (argc > 0) {
721
722 if (matches(*argv, "add") == 0) {
723 ret = tc_action_modify(RTM_NEWACTION,
724 NLM_F_EXCL | NLM_F_CREATE,
725 &argc, &argv, buf, buflen);
726 } else if (matches(*argv, "change") == 0 ||
727 matches(*argv, "replace") == 0) {
728 ret = tc_action_modify(RTM_NEWACTION,
729 NLM_F_CREATE | NLM_F_REPLACE,
730 &argc, &argv, buf, buflen);
731 } else if (matches(*argv, "delete") == 0) {
732 argc -= 1;
733 argv += 1;
734 ret = tc_action_gd(RTM_DELACTION, 0, &argc, &argv);
735 } else if (matches(*argv, "get") == 0) {
736 argc -= 1;
737 argv += 1;
738 ret = tc_action_gd(RTM_GETACTION, 0, &argc, &argv);
739 } else if (matches(*argv, "list") == 0 ||
740 matches(*argv, "show") == 0 ||
741 matches(*argv, "lst") == 0) {
742 if (argc <= 2) {
743 act_usage();
744 return -1;
745 }
746
747 argc -= 2;
748 argv += 2;
749 return tc_act_list_or_flush(&argc, &argv,
750 RTM_GETACTION);
751 } else if (matches(*argv, "flush") == 0) {
752 if (argc <= 2) {
753 act_usage();
754 return -1;
755 }
756
757 argc -= 2;
758 argv += 2;
759 return tc_act_list_or_flush(&argc, &argv,
760 RTM_DELACTION);
761 } else if (matches(*argv, "help") == 0) {
762 act_usage();
763 return -1;
764 } else {
765 fprintf(stderr,
766 "Command \"%s\" is unknown, try \"tc actions help\".\n",
767 *argv);
768 return -1;
769 }
770
771 if (ret < 0)
772 return -1;
773 }
774
775 return 0;
776 }