]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/m_action.c
tc: enable json output for actions
[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 int gact_ld; /* f*ckin backward compatibility */
34 #endif
35 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, "usage: tc actions <ACTSPECOP>*\n");
47 fprintf(stderr,
48 "Where: \tACTSPECOP := ACR | GD | FL\n"
49 "\tACR := add | change | replace <ACTSPEC>*\n"
50 "\tGD := get | delete | <ACTISPEC>*\n"
51 "\tFL := ls | list | flush | <ACTNAMESPEC>\n"
52 "\tACTNAMESPEC := action <ACTNAME>\n"
53 "\tACTISPEC := <ACTNAMESPEC> <INDEXSPEC>\n"
54 "\tACTSPEC := action <ACTDETAIL> [INDEXSPEC]\n"
55 "\tINDEXSPEC := index <32 bit indexvalue>\n"
56 "\tACTDETAIL := <ACTNAME> <ACTPARAMS>\n"
57 "\t\tExample ACTNAME is gact, mirred, bpf, etc\n"
58 "\t\tEach 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, TCA_ACT_OPTIONS,
218 n);
219
220 if (ret < 0) {
221 fprintf(stderr, "bad action parsing\n");
222 goto bad_val;
223 }
224
225 if (*argv && strcmp(*argv, "cookie") == 0) {
226 size_t slen;
227
228 NEXT_ARG();
229 slen = strlen(*argv);
230 if (slen > TC_COOKIE_MAX_SIZE * 2) {
231 char cookie_err_m[128];
232
233 snprintf(cookie_err_m, 128,
234 "%zd Max allowed size %d",
235 slen, TC_COOKIE_MAX_SIZE*2);
236 invarg(cookie_err_m, *argv);
237 }
238
239 if (hex2mem(*argv, act_ck, slen / 2) < 0)
240 invarg("cookie must be a hex string\n",
241 *argv);
242
243 act_ck_len = slen / 2;
244 argc--;
245 argv++;
246 }
247
248 if (act_ck_len)
249 addattr_l(n, MAX_MSG, TCA_ACT_COOKIE,
250 &act_ck, act_ck_len);
251
252 addattr_nest_end(n, tail);
253 ok++;
254 }
255 }
256
257 if (eap > 0) {
258 fprintf(stderr, "bad action empty %d\n", eap);
259 goto bad_val;
260 }
261
262 addattr_nest_end(n, tail2);
263
264 done:
265 *argc_p = argc;
266 *argv_p = argv;
267 return 0;
268 bad_val:
269 /* no need to undo things, returning from here should
270 * cause enough pain
271 */
272 fprintf(stderr, "parse_action: bad value (%d:%s)!\n", argc, *argv);
273 return -1;
274 }
275
276 static int tc_print_one_action(FILE *f, struct rtattr *arg)
277 {
278
279 struct rtattr *tb[TCA_ACT_MAX + 1];
280 int err = 0;
281 struct action_util *a = NULL;
282
283 if (arg == NULL)
284 return -1;
285
286 parse_rtattr_nested(tb, TCA_ACT_MAX, arg);
287
288 if (tb[TCA_ACT_KIND] == NULL) {
289 fprintf(stderr, "NULL Action!\n");
290 return -1;
291 }
292
293
294 a = get_action_kind(RTA_DATA(tb[TCA_ACT_KIND]));
295 if (a == NULL)
296 return err;
297
298 err = a->print_aopt(a, f, tb[TCA_ACT_OPTIONS]);
299
300 if (err < 0)
301 return err;
302
303 if (show_stats && tb[TCA_ACT_STATS]) {
304 print_string(PRINT_FP, NULL, "\tAction statistics:\n", NULL);
305 open_json_object("stats");
306 print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL);
307 close_json_object();
308 print_string(PRINT_FP, NULL, "\n", NULL);
309 }
310 if (tb[TCA_ACT_COOKIE]) {
311 int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]);
312 char b1[strsz * 2 + 1];
313
314 print_string(PRINT_ANY, "cookie", "\tcookie %s\n",
315 hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),
316 strsz, b1, sizeof(b1)));
317 }
318
319 return 0;
320 }
321
322 static int
323 tc_print_action_flush(FILE *f, const struct rtattr *arg)
324 {
325
326 struct rtattr *tb[TCA_MAX + 1];
327 int err = 0;
328 struct action_util *a = NULL;
329 __u32 *delete_count = 0;
330
331 parse_rtattr_nested(tb, TCA_MAX, arg);
332
333 if (tb[TCA_KIND] == NULL) {
334 fprintf(stderr, "NULL Action!\n");
335 return -1;
336 }
337
338 a = get_action_kind(RTA_DATA(tb[TCA_KIND]));
339 if (a == NULL)
340 return err;
341
342 delete_count = RTA_DATA(tb[TCA_FCNT]);
343 fprintf(f, " %s (%d entries)\n", a->id, *delete_count);
344 tab_flush = 0;
345 return 0;
346 }
347
348 int
349 tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)
350 {
351
352 int i;
353
354 if (arg == NULL)
355 return 0;
356
357 if (!tot_acts)
358 tot_acts = TCA_ACT_MAX_PRIO;
359
360 struct rtattr *tb[tot_acts + 1];
361
362 parse_rtattr_nested(tb, tot_acts, arg);
363
364 if (tab_flush && NULL != tb[0] && NULL == tb[1])
365 return tc_print_action_flush(f, tb[0]);
366
367 open_json_object(NULL);
368 open_json_array(PRINT_JSON, "actions");
369 for (i = 0; i <= tot_acts; i++) {
370 if (tb[i]) {
371 open_json_object(NULL);
372 print_uint(PRINT_ANY, "order",
373 "\n\taction order %u: ", i);
374 if (tc_print_one_action(f, tb[i]) < 0) {
375 print_string(PRINT_FP, NULL,
376 "Error printing action\n", NULL);
377 }
378 close_json_object();
379 }
380
381 }
382 close_json_array(PRINT_JSON, NULL);
383 close_json_object();
384
385 return 0;
386 }
387
388 int print_action(const struct sockaddr_nl *who,
389 struct nlmsghdr *n,
390 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 close_json_object();
414 if (tb[TCA_ACT_TAB] == NULL) {
415 if (n->nlmsg_type != RTM_GETACTION)
416 fprintf(stderr, "print_action: NULL kind\n");
417 return -1;
418 }
419
420 if (n->nlmsg_type == RTM_DELACTION) {
421 if (n->nlmsg_flags & NLM_F_ROOT) {
422 fprintf(fp, "Flushed table ");
423 tab_flush = 1;
424 } else {
425 fprintf(fp, "Deleted action ");
426 }
427 }
428
429 if (n->nlmsg_type == RTM_NEWACTION) {
430 if ((n->nlmsg_flags & NLM_F_CREATE) &&
431 !(n->nlmsg_flags & NLM_F_REPLACE)) {
432 fprintf(fp, "Added action ");
433 } else if (n->nlmsg_flags & NLM_F_REPLACE) {
434 fprintf(fp, "Replaced action ");
435 }
436 }
437
438
439 tc_print_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0);
440
441 return 0;
442 }
443
444 static int tc_action_gd(int cmd, unsigned int flags,
445 int *argc_p, char ***argv_p)
446 {
447 char k[FILTER_NAMESZ];
448 struct action_util *a = NULL;
449 int argc = *argc_p;
450 char **argv = *argv_p;
451 int prio = 0;
452 int ret = 0;
453 __u32 i = 0;
454 struct rtattr *tail;
455 struct rtattr *tail2;
456 struct nlmsghdr *ans = NULL;
457
458 struct {
459 struct nlmsghdr n;
460 struct tcamsg t;
461 char buf[MAX_MSG];
462 } req = {
463 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
464 .n.nlmsg_flags = NLM_F_REQUEST | flags,
465 .n.nlmsg_type = cmd,
466 .t.tca_family = AF_UNSPEC,
467 };
468
469 argc -= 1;
470 argv += 1;
471
472
473 tail = addattr_nest(&req.n, MAX_MSG, TCA_ACT_TAB);
474
475 while (argc > 0) {
476 if (strcmp(*argv, "action") == 0) {
477 argc--;
478 argv++;
479 continue;
480 } else if (strcmp(*argv, "help") == 0) {
481 return -1;
482 }
483
484 strncpy(k, *argv, sizeof(k) - 1);
485 a = get_action_kind(k);
486 if (a == NULL) {
487 fprintf(stderr, "Error: non existent action: %s\n", k);
488 ret = -1;
489 goto bad_val;
490 }
491 if (strcmp(a->id, k) != 0) {
492 fprintf(stderr, "Error: non existent action: %s\n", k);
493 ret = -1;
494 goto bad_val;
495 }
496
497 argc -= 1;
498 argv += 1;
499 if (argc <= 0) {
500 fprintf(stderr,
501 "Error: no index specified action: %s\n", k);
502 ret = -1;
503 goto bad_val;
504 }
505
506 if (matches(*argv, "index") == 0) {
507 NEXT_ARG();
508 if (get_u32(&i, *argv, 10)) {
509 fprintf(stderr, "Illegal \"index\"\n");
510 ret = -1;
511 goto bad_val;
512 }
513 argc -= 1;
514 argv += 1;
515 } else {
516 fprintf(stderr,
517 "Error: no index specified action: %s\n", k);
518 ret = -1;
519 goto bad_val;
520 }
521
522 tail2 = addattr_nest(&req.n, MAX_MSG, ++prio);
523 addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
524 if (i > 0)
525 addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i);
526 addattr_nest_end(&req.n, tail2);
527
528 }
529
530 addattr_nest_end(&req.n, tail);
531
532 req.n.nlmsg_seq = rth.dump = ++rth.seq;
533
534 if (rtnl_talk(&rth, &req.n, cmd == RTM_DELACTION ? NULL : &ans) < 0) {
535 fprintf(stderr, "We have an error talking to the kernel\n");
536 return 1;
537 }
538
539 if (cmd == RTM_GETACTION) {
540 new_json_obj(json);
541 ret = print_action(NULL, ans, stdout);
542 if (ret < 0) {
543 fprintf(stderr, "Dump terminated\n");
544 free(ans);
545 delete_json_obj();
546 return 1;
547 }
548 delete_json_obj();
549 }
550 free(ans);
551
552 *argc_p = argc;
553 *argv_p = argv;
554 bad_val:
555 return ret;
556 }
557
558 struct tc_action_req {
559 struct nlmsghdr n;
560 struct tcamsg t;
561 char buf[MAX_MSG];
562 };
563
564 static int tc_action_modify(int cmd, unsigned int flags,
565 int *argc_p, char ***argv_p,
566 void *buf, size_t buflen)
567 {
568 struct tc_action_req *req, action_req;
569 char **argv = *argv_p;
570 struct rtattr *tail;
571 int argc = *argc_p;
572 struct iovec iov;
573 int ret = 0;
574
575 if (buf) {
576 req = buf;
577 if (buflen < sizeof (struct tc_action_req)) {
578 fprintf(stderr, "buffer is too small: %zu\n", buflen);
579 return -1;
580 }
581 } else {
582 memset(&action_req, 0, sizeof (struct tc_action_req));
583 req = &action_req;
584 }
585
586 req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
587 req->n.nlmsg_flags = NLM_F_REQUEST | flags;
588 req->n.nlmsg_type = cmd;
589 req->t.tca_family = AF_UNSPEC;
590 tail = NLMSG_TAIL(&req->n);
591
592 argc -= 1;
593 argv += 1;
594 if (parse_action(&argc, &argv, TCA_ACT_TAB, &req->n)) {
595 fprintf(stderr, "Illegal \"action\"\n");
596 return -1;
597 }
598 tail->rta_len = (void *) NLMSG_TAIL(&req->n) - (void *) tail;
599
600 *argc_p = argc;
601 *argv_p = argv;
602
603 if (buf)
604 return 0;
605
606 iov.iov_base = &req->n;
607 iov.iov_len = req->n.nlmsg_len;
608 if (rtnl_talk_iov(&rth, &iov, 1, NULL) < 0) {
609 fprintf(stderr, "We have an error talking to the kernel\n");
610 ret = -1;
611 }
612
613 return ret;
614 }
615
616 static int tc_act_list_or_flush(int *argc_p, char ***argv_p, int event)
617 {
618 struct rtattr *tail, *tail2, *tail3, *tail4;
619 int ret = 0, prio = 0, msg_size = 0;
620 struct action_util *a = NULL;
621 struct nla_bitfield32 flag_select = { 0 };
622 char **argv = *argv_p;
623 __u32 msec_since = 0;
624 int argc = *argc_p;
625 char k[FILTER_NAMESZ];
626 struct {
627 struct nlmsghdr n;
628 struct tcamsg t;
629 char buf[MAX_MSG];
630 } req = {
631 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
632 .t.tca_family = AF_UNSPEC,
633 };
634
635 tail = addattr_nest(&req.n, MAX_MSG, TCA_ACT_TAB);
636 tail2 = NLMSG_TAIL(&req.n);
637
638 strncpy(k, *argv, sizeof(k) - 1);
639 #ifdef CONFIG_GACT
640 if (!gact_ld)
641 get_action_kind("gact");
642
643 #endif
644 a = get_action_kind(k);
645 if (a == NULL) {
646 fprintf(stderr, "bad action %s\n", k);
647 goto bad_val;
648 }
649 if (strcmp(a->id, k) != 0) {
650 fprintf(stderr, "bad action %s\n", k);
651 goto bad_val;
652 }
653 strncpy(k, *argv, sizeof(k) - 1);
654
655 argc -= 1;
656 argv += 1;
657
658 if (argc && (strcmp(*argv, "since") == 0)) {
659 NEXT_ARG();
660 if (get_u32(&msec_since, *argv, 0))
661 invarg("dump time \"since\" is invalid", *argv);
662 }
663
664 addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
665 addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
666 tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
667 addattr_nest_end(&req.n, tail);
668
669 tail3 = NLMSG_TAIL(&req.n);
670 flag_select.value |= TCA_FLAG_LARGE_DUMP_ON;
671 flag_select.selector |= TCA_FLAG_LARGE_DUMP_ON;
672 addattr_l(&req.n, MAX_MSG, TCA_ROOT_FLAGS, &flag_select,
673 sizeof(struct nla_bitfield32));
674 tail3->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail3;
675 if (msec_since) {
676 tail4 = NLMSG_TAIL(&req.n);
677 addattr32(&req.n, MAX_MSG, TCA_ROOT_TIME_DELTA, msec_since);
678 tail4->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail4;
679 }
680 msg_size = NLMSG_ALIGN(req.n.nlmsg_len)
681 - NLMSG_ALIGN(sizeof(struct nlmsghdr));
682
683 if (event == RTM_GETACTION) {
684 if (rtnl_dump_request(&rth, event,
685 (void *)&req.t, msg_size) < 0) {
686 perror("Cannot send dump request");
687 return 1;
688 }
689 new_json_obj(json);
690 ret = rtnl_dump_filter(&rth, print_action, stdout);
691 delete_json_obj();
692 }
693
694 if (event == RTM_DELACTION) {
695 req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len);
696 req.n.nlmsg_type = RTM_DELACTION;
697 req.n.nlmsg_flags |= NLM_F_ROOT;
698 req.n.nlmsg_flags |= NLM_F_REQUEST;
699 if (rtnl_talk(&rth, &req.n, NULL) < 0) {
700 fprintf(stderr, "We have an error flushing\n");
701 return 1;
702 }
703
704 }
705
706 bad_val:
707
708 *argc_p = argc;
709 *argv_p = argv;
710 return ret;
711 }
712
713 int do_action(int argc, char **argv, void *buf, size_t buflen)
714 {
715
716 int ret = 0;
717
718 while (argc > 0) {
719
720 if (matches(*argv, "add") == 0) {
721 ret = tc_action_modify(RTM_NEWACTION,
722 NLM_F_EXCL | NLM_F_CREATE,
723 &argc, &argv, buf, buflen);
724 } else if (matches(*argv, "change") == 0 ||
725 matches(*argv, "replace") == 0) {
726 ret = tc_action_modify(RTM_NEWACTION,
727 NLM_F_CREATE | NLM_F_REPLACE,
728 &argc, &argv, buf, buflen);
729 } else if (matches(*argv, "delete") == 0) {
730 argc -= 1;
731 argv += 1;
732 ret = tc_action_gd(RTM_DELACTION, 0, &argc, &argv);
733 } else if (matches(*argv, "get") == 0) {
734 argc -= 1;
735 argv += 1;
736 ret = tc_action_gd(RTM_GETACTION, 0, &argc, &argv);
737 } else if (matches(*argv, "list") == 0 ||
738 matches(*argv, "show") == 0 ||
739 matches(*argv, "lst") == 0) {
740 if (argc <= 2) {
741 act_usage();
742 return -1;
743 }
744
745 argc -= 2;
746 argv += 2;
747 return tc_act_list_or_flush(&argc, &argv,
748 RTM_GETACTION);
749 } else if (matches(*argv, "flush") == 0) {
750 if (argc <= 2) {
751 act_usage();
752 return -1;
753 }
754
755 argc -= 2;
756 argv += 2;
757 return tc_act_list_or_flush(&argc, &argv,
758 RTM_DELACTION);
759 } else if (matches(*argv, "help") == 0) {
760 act_usage();
761 return -1;
762 } else {
763 fprintf(stderr,
764 "Command \"%s\" is unknown, try \"tc actions help\".\n",
765 *argv);
766 return -1;
767 }
768
769 if (ret < 0)
770 return -1;
771 }
772
773 return 0;
774 }