]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/m_action.c
Merge branch 'iproute2-master' into iproute2-next
[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 tail = tail2 = NLMSG_TAIL(n);
170
171 addattr_l(n, MAX_MSG, tca_id, NULL, 0);
172
173 while (argc > 0) {
174
175 memset(k, 0, sizeof(k));
176
177 if (strcmp(*argv, "action") == 0) {
178 argc--;
179 argv++;
180 eap = 1;
181 #ifdef CONFIG_GACT
182 if (!gact_ld)
183 get_action_kind("gact");
184 #endif
185 continue;
186 } else if (strcmp(*argv, "flowid") == 0) {
187 break;
188 } else if (strcmp(*argv, "classid") == 0) {
189 break;
190 } else if (strcmp(*argv, "help") == 0) {
191 return -1;
192 } else if (new_cmd(argv)) {
193 goto done0;
194 } else {
195 struct action_util *a = NULL;
196
197 if (!action_a2n(*argv, NULL, false))
198 strncpy(k, "gact", sizeof(k) - 1);
199 else
200 strncpy(k, *argv, sizeof(k) - 1);
201 eap = 0;
202 if (argc > 0) {
203 a = get_action_kind(k);
204 } else {
205 done0:
206 if (ok)
207 break;
208 else
209 goto done;
210 }
211
212 if (a == NULL)
213 goto bad_val;
214
215
216 tail = NLMSG_TAIL(n);
217 addattr_l(n, MAX_MSG, ++prio, NULL, 0);
218 addattr_l(n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
219
220 ret = a->parse_aopt(a, &argc, &argv, TCA_ACT_OPTIONS,
221 n);
222
223 if (ret < 0) {
224 fprintf(stderr, "bad action parsing\n");
225 goto bad_val;
226 }
227
228 if (*argv && strcmp(*argv, "cookie") == 0) {
229 size_t slen;
230
231 NEXT_ARG();
232 slen = strlen(*argv);
233 if (slen > TC_COOKIE_MAX_SIZE * 2) {
234 char cookie_err_m[128];
235
236 snprintf(cookie_err_m, 128,
237 "%zd Max allowed size %d",
238 slen, TC_COOKIE_MAX_SIZE*2);
239 invarg(cookie_err_m, *argv);
240 }
241
242 if (hex2mem(*argv, act_ck, slen / 2) < 0)
243 invarg("cookie must be a hex string\n",
244 *argv);
245
246 act_ck_len = slen / 2;
247 argc--;
248 argv++;
249 }
250
251 if (act_ck_len)
252 addattr_l(n, MAX_MSG, TCA_ACT_COOKIE,
253 &act_ck, act_ck_len);
254
255 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
256 ok++;
257 }
258 }
259
260 if (eap > 0) {
261 fprintf(stderr, "bad action empty %d\n", eap);
262 goto bad_val;
263 }
264
265 tail2->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail2;
266
267 done:
268 *argc_p = argc;
269 *argv_p = argv;
270 return 0;
271 bad_val:
272 /* no need to undo things, returning from here should
273 * cause enough pain
274 */
275 fprintf(stderr, "parse_action: bad value (%d:%s)!\n", argc, *argv);
276 return -1;
277 }
278
279 static int tc_print_one_action(FILE *f, struct rtattr *arg)
280 {
281
282 struct rtattr *tb[TCA_ACT_MAX + 1];
283 int err = 0;
284 struct action_util *a = NULL;
285
286 if (arg == NULL)
287 return -1;
288
289 parse_rtattr_nested(tb, TCA_ACT_MAX, arg);
290
291 if (tb[TCA_ACT_KIND] == NULL) {
292 fprintf(stderr, "NULL Action!\n");
293 return -1;
294 }
295
296
297 a = get_action_kind(RTA_DATA(tb[TCA_ACT_KIND]));
298 if (a == NULL)
299 return err;
300
301 err = a->print_aopt(a, f, tb[TCA_ACT_OPTIONS]);
302
303 if (err < 0)
304 return err;
305
306 if (show_stats && tb[TCA_ACT_STATS]) {
307 print_string(PRINT_FP, NULL, "\tAction statistics:\n", NULL);
308 open_json_object("stats");
309 print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL);
310 close_json_object();
311 print_string(PRINT_FP, NULL, "\n", NULL);
312 }
313 if (tb[TCA_ACT_COOKIE]) {
314 int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]);
315 char b1[strsz * 2 + 1];
316
317 print_string(PRINT_ANY, "cookie", "\tcookie %s\n",
318 hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),
319 strsz, b1, sizeof(b1)));
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 && NULL != tb[0] && NULL == 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_uint(PRINT_ANY, "order",
375 "\n\taction order %u: ", i);
376 if (tc_print_one_action(f, tb[i]) < 0) {
377 print_string(PRINT_FP, NULL,
378 "Error printing action\n", NULL);
379 }
380 close_json_object();
381 }
382
383 }
384 close_json_array(PRINT_JSON, NULL);
385
386 return 0;
387 }
388
389 int print_action(const struct sockaddr_nl *who,
390 struct nlmsghdr *n,
391 void *arg)
392 {
393 FILE *fp = (FILE *)arg;
394 struct tcamsg *t = NLMSG_DATA(n);
395 int len = n->nlmsg_len;
396 __u32 *tot_acts = NULL;
397 struct rtattr *tb[TCA_ROOT_MAX+1];
398
399 len -= NLMSG_LENGTH(sizeof(*t));
400
401 if (len < 0) {
402 fprintf(stderr, "Wrong len %d\n", len);
403 return -1;
404 }
405
406 parse_rtattr(tb, TCA_ROOT_MAX, TA_RTA(t), len);
407
408 if (tb[TCA_ROOT_COUNT])
409 tot_acts = RTA_DATA(tb[TCA_ROOT_COUNT]);
410
411 fprintf(fp, "total acts %d\n", tot_acts ? *tot_acts:0);
412 if (tb[TCA_ACT_TAB] == NULL) {
413 if (n->nlmsg_type != RTM_GETACTION)
414 fprintf(stderr, "print_action: NULL kind\n");
415 return -1;
416 }
417
418 if (n->nlmsg_type == RTM_DELACTION) {
419 if (n->nlmsg_flags & NLM_F_ROOT) {
420 fprintf(fp, "Flushed table ");
421 tab_flush = 1;
422 } else {
423 fprintf(fp, "Deleted action ");
424 }
425 }
426
427 if (n->nlmsg_type == RTM_NEWACTION) {
428 if ((n->nlmsg_flags & NLM_F_CREATE) &&
429 !(n->nlmsg_flags & NLM_F_REPLACE)) {
430 fprintf(fp, "Added action ");
431 } else if (n->nlmsg_flags & NLM_F_REPLACE) {
432 fprintf(fp, "Replaced action ");
433 }
434 }
435
436
437 tc_print_action(fp, tb[TCA_ACT_TAB], tot_acts ? *tot_acts:0);
438
439 return 0;
440 }
441
442 static int tc_action_gd(int cmd, unsigned int flags,
443 int *argc_p, char ***argv_p)
444 {
445 char k[FILTER_NAMESZ];
446 struct action_util *a = NULL;
447 int argc = *argc_p;
448 char **argv = *argv_p;
449 int prio = 0;
450 int ret = 0;
451 __u32 i = 0;
452 struct rtattr *tail;
453 struct rtattr *tail2;
454 struct nlmsghdr *ans = NULL;
455
456 struct {
457 struct nlmsghdr n;
458 struct tcamsg t;
459 char buf[MAX_MSG];
460 } req = {
461 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
462 .n.nlmsg_flags = NLM_F_REQUEST | flags,
463 .n.nlmsg_type = cmd,
464 .t.tca_family = AF_UNSPEC,
465 };
466
467 argc -= 1;
468 argv += 1;
469
470
471 tail = NLMSG_TAIL(&req.n);
472 addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0);
473
474 while (argc > 0) {
475 if (strcmp(*argv, "action") == 0) {
476 argc--;
477 argv++;
478 continue;
479 } else if (strcmp(*argv, "help") == 0) {
480 return -1;
481 }
482
483 strncpy(k, *argv, sizeof(k) - 1);
484 a = get_action_kind(k);
485 if (a == NULL) {
486 fprintf(stderr, "Error: non existent action: %s\n", k);
487 ret = -1;
488 goto bad_val;
489 }
490 if (strcmp(a->id, k) != 0) {
491 fprintf(stderr, "Error: non existent action: %s\n", k);
492 ret = -1;
493 goto bad_val;
494 }
495
496 argc -= 1;
497 argv += 1;
498 if (argc <= 0) {
499 fprintf(stderr,
500 "Error: no index specified action: %s\n", k);
501 ret = -1;
502 goto bad_val;
503 }
504
505 if (matches(*argv, "index") == 0) {
506 NEXT_ARG();
507 if (get_u32(&i, *argv, 10)) {
508 fprintf(stderr, "Illegal \"index\"\n");
509 ret = -1;
510 goto bad_val;
511 }
512 argc -= 1;
513 argv += 1;
514 } else {
515 fprintf(stderr,
516 "Error: no index specified action: %s\n", k);
517 ret = -1;
518 goto bad_val;
519 }
520
521 tail2 = NLMSG_TAIL(&req.n);
522 addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
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 tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
527
528 }
529
530 tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) 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 && print_action(NULL, ans, stdout) < 0) {
540 fprintf(stderr, "Dump terminated\n");
541 free(ans);
542 return 1;
543 }
544 free(ans);
545
546 *argc_p = argc;
547 *argv_p = argv;
548 bad_val:
549 return ret;
550 }
551
552 struct tc_action_req {
553 struct nlmsghdr n;
554 struct tcamsg t;
555 char buf[MAX_MSG];
556 };
557
558 static int tc_action_modify(int cmd, unsigned int flags,
559 int *argc_p, char ***argv_p,
560 void *buf, size_t buflen)
561 {
562 struct tc_action_req *req, action_req;
563 char **argv = *argv_p;
564 struct rtattr *tail;
565 int argc = *argc_p;
566 struct iovec iov;
567 int ret = 0;
568
569 if (buf) {
570 req = buf;
571 if (buflen < sizeof (struct tc_action_req)) {
572 fprintf(stderr, "buffer is too small: %zu\n", buflen);
573 return -1;
574 }
575 } else {
576 memset(&action_req, 0, sizeof (struct tc_action_req));
577 req = &action_req;
578 }
579
580 req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
581 req->n.nlmsg_flags = NLM_F_REQUEST | flags;
582 req->n.nlmsg_type = cmd;
583 req->t.tca_family = AF_UNSPEC;
584 tail = NLMSG_TAIL(&req->n);
585
586 argc -= 1;
587 argv += 1;
588 if (parse_action(&argc, &argv, TCA_ACT_TAB, &req->n)) {
589 fprintf(stderr, "Illegal \"action\"\n");
590 return -1;
591 }
592 tail->rta_len = (void *) NLMSG_TAIL(&req->n) - (void *) tail;
593
594 *argc_p = argc;
595 *argv_p = argv;
596
597 if (buf)
598 return 0;
599
600 iov.iov_base = &req->n;
601 iov.iov_len = req->n.nlmsg_len;
602 if (rtnl_talk_iov(&rth, &iov, 1, NULL) < 0) {
603 fprintf(stderr, "We have an error talking to the kernel\n");
604 ret = -1;
605 }
606
607 return ret;
608 }
609
610 static int tc_act_list_or_flush(int *argc_p, char ***argv_p, int event)
611 {
612 struct rtattr *tail, *tail2, *tail3, *tail4;
613 int ret = 0, prio = 0, msg_size = 0;
614 struct action_util *a = NULL;
615 struct nla_bitfield32 flag_select = { 0 };
616 char **argv = *argv_p;
617 __u32 msec_since = 0;
618 int argc = *argc_p;
619 char k[FILTER_NAMESZ];
620 struct {
621 struct nlmsghdr n;
622 struct tcamsg t;
623 char buf[MAX_MSG];
624 } req = {
625 .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
626 .t.tca_family = AF_UNSPEC,
627 };
628
629 tail = NLMSG_TAIL(&req.n);
630 addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0);
631 tail2 = NLMSG_TAIL(&req.n);
632
633 strncpy(k, *argv, sizeof(k) - 1);
634 #ifdef CONFIG_GACT
635 if (!gact_ld)
636 get_action_kind("gact");
637
638 #endif
639 a = get_action_kind(k);
640 if (a == NULL) {
641 fprintf(stderr, "bad action %s\n", k);
642 goto bad_val;
643 }
644 if (strcmp(a->id, k) != 0) {
645 fprintf(stderr, "bad action %s\n", k);
646 goto bad_val;
647 }
648 strncpy(k, *argv, sizeof(k) - 1);
649
650 argc -= 1;
651 argv += 1;
652
653 if (argc && (strcmp(*argv, "since") == 0)) {
654 NEXT_ARG();
655 if (get_u32(&msec_since, *argv, 0))
656 invarg("dump time \"since\" is invalid", *argv);
657 }
658
659 addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
660 addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
661 tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
662 tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
663
664 tail3 = NLMSG_TAIL(&req.n);
665 flag_select.value |= TCA_FLAG_LARGE_DUMP_ON;
666 flag_select.selector |= TCA_FLAG_LARGE_DUMP_ON;
667 addattr_l(&req.n, MAX_MSG, TCA_ROOT_FLAGS, &flag_select,
668 sizeof(struct nla_bitfield32));
669 tail3->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail3;
670 if (msec_since) {
671 tail4 = NLMSG_TAIL(&req.n);
672 addattr32(&req.n, MAX_MSG, TCA_ROOT_TIME_DELTA, msec_since);
673 tail4->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail4;
674 }
675 msg_size = NLMSG_ALIGN(req.n.nlmsg_len)
676 - NLMSG_ALIGN(sizeof(struct nlmsghdr));
677
678 if (event == RTM_GETACTION) {
679 if (rtnl_dump_request(&rth, event,
680 (void *)&req.t, msg_size) < 0) {
681 perror("Cannot send dump request");
682 return 1;
683 }
684 ret = rtnl_dump_filter(&rth, print_action, stdout);
685 }
686
687 if (event == RTM_DELACTION) {
688 req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len);
689 req.n.nlmsg_type = RTM_DELACTION;
690 req.n.nlmsg_flags |= NLM_F_ROOT;
691 req.n.nlmsg_flags |= NLM_F_REQUEST;
692 if (rtnl_talk(&rth, &req.n, NULL) < 0) {
693 fprintf(stderr, "We have an error flushing\n");
694 return 1;
695 }
696
697 }
698
699 bad_val:
700
701 *argc_p = argc;
702 *argv_p = argv;
703 return ret;
704 }
705
706 int do_action(int argc, char **argv, void *buf, size_t buflen)
707 {
708
709 int ret = 0;
710
711 while (argc > 0) {
712
713 if (matches(*argv, "add") == 0) {
714 ret = tc_action_modify(RTM_NEWACTION,
715 NLM_F_EXCL | NLM_F_CREATE,
716 &argc, &argv, buf, buflen);
717 } else if (matches(*argv, "change") == 0 ||
718 matches(*argv, "replace") == 0) {
719 ret = tc_action_modify(RTM_NEWACTION,
720 NLM_F_CREATE | NLM_F_REPLACE,
721 &argc, &argv, buf, buflen);
722 } else if (matches(*argv, "delete") == 0) {
723 argc -= 1;
724 argv += 1;
725 ret = tc_action_gd(RTM_DELACTION, 0, &argc, &argv);
726 } else if (matches(*argv, "get") == 0) {
727 argc -= 1;
728 argv += 1;
729 ret = tc_action_gd(RTM_GETACTION, 0, &argc, &argv);
730 } else if (matches(*argv, "list") == 0 ||
731 matches(*argv, "show") == 0 ||
732 matches(*argv, "lst") == 0) {
733 if (argc <= 2) {
734 act_usage();
735 return -1;
736 }
737
738 argc -= 2;
739 argv += 2;
740 return tc_act_list_or_flush(&argc, &argv,
741 RTM_GETACTION);
742 } else if (matches(*argv, "flush") == 0) {
743 if (argc <= 2) {
744 act_usage();
745 return -1;
746 }
747
748 argc -= 2;
749 argv += 2;
750 return tc_act_list_or_flush(&argc, &argv,
751 RTM_DELACTION);
752 } else if (matches(*argv, "help") == 0) {
753 act_usage();
754 return -1;
755 } else {
756 fprintf(stderr,
757 "Command \"%s\" is unknown, try \"tc actions help\".\n",
758 *argv);
759 return -1;
760 }
761
762 if (ret < 0)
763 return -1;
764 }
765
766 return 0;
767 }