osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 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 | * |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 9 | * Authors: J Hadi Salim (hadi@cyberus.ca) |
| 10 | * |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 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 <unistd.h> |
| 19 | #include <syslog.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" |
site!shemminger | c1027a7 | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 28 | #include "tc_common.h" |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 29 | #include "tc_util.h" |
| 30 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 31 | static struct action_util *action_list; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_GACT |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 33 | int gact_ld; /* f*ckin backward compatibility */ |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 34 | #endif |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 35 | int tab_flush; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 36 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 37 | static void act_usage(void) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 38 | { |
jamal | f1e4f04 | 2006-08-04 10:59:34 -0700 | [diff] [blame] | 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 | * |
Stephen Hemminger | 302d3fb | 2006-09-25 17:08:40 -0700 | [diff] [blame] | 45 | */ |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 46 | fprintf(stderr, "usage: tc actions <ACTSPECOP>*\n"); |
jamal | f1e4f04 | 2006-08-04 10:59:34 -0700 | [diff] [blame] | 47 | fprintf(stderr, |
| 48 | "Where: \tACTSPECOP := ACR | GD | FL\n" |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 49 | "\tACR := add | change | replace <ACTSPEC>*\n" |
Stephen Hemminger | 302d3fb | 2006-09-25 17:08:40 -0700 | [diff] [blame] | 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" |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 57 | "\t\tExample ACTNAME is gact, mirred, bpf, etc\n" |
Stephen Hemminger | 302d3fb | 2006-09-25 17:08:40 -0700 | [diff] [blame] | 58 | "\t\tEach action has its own parameters (ACTPARAMS)\n" |
| 59 | "\n"); |
| 60 | |
Jamal Hadi Salim | ebf3208 | 2006-08-08 12:10:08 -0700 | [diff] [blame] | 61 | exit(-1); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static int print_noaopt(struct action_util *au, FILE *f, struct rtattr *opt) |
| 65 | { |
| 66 | if (opt && RTA_PAYLOAD(opt)) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 67 | fprintf(f, "[Unknown action, optlen=%u] ", |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 68 | (unsigned int) RTA_PAYLOAD(opt)); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static int parse_noaopt(struct action_util *au, int *argc_p, char ***argv_p, int code, struct nlmsghdr *n) |
| 73 | { |
| 74 | int argc = *argc_p; |
| 75 | char **argv = *argv_p; |
| 76 | |
| 77 | if (argc) { |
| 78 | fprintf(stderr, "Unknown action \"%s\", hence option \"%s\" is unparsable\n", au->id, *argv); |
| 79 | } else { |
| 80 | fprintf(stderr, "Unknown action \"%s\"\n", au->id); |
| 81 | } |
| 82 | return -1; |
| 83 | } |
| 84 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 85 | static struct action_util *get_action_kind(char *str) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 86 | { |
8!tgraf | cda4026 | 2005-01-18 00:09:02 +0000 | [diff] [blame] | 87 | static void *aBODY; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 88 | void *dlh; |
| 89 | char buf[256]; |
| 90 | struct action_util *a; |
| 91 | #ifdef CONFIG_GACT |
| 92 | int looked4gact = 0; |
| 93 | restart_s: |
| 94 | #endif |
| 95 | for (a = action_list; a; a = a->next) { |
| 96 | if (strcmp(a->id, str) == 0) |
| 97 | return a; |
| 98 | } |
| 99 | |
Andreas Henriksson | ab814d6 | 2010-04-12 20:24:23 +0200 | [diff] [blame] | 100 | snprintf(buf, sizeof(buf), "%s/m_%s.so", get_tc_lib(), str); |
Andreas Henriksson | 02833d1 | 2010-08-02 09:30:33 +0200 | [diff] [blame] | 101 | dlh = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 102 | if (dlh == NULL) { |
| 103 | dlh = aBODY; |
| 104 | if (dlh == NULL) { |
| 105 | dlh = aBODY = dlopen(NULL, RTLD_LAZY); |
| 106 | if (dlh == NULL) |
| 107 | goto noexist; |
| 108 | } |
| 109 | } |
| 110 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 111 | snprintf(buf, sizeof(buf), "%s_action_util", str); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 112 | a = dlsym(dlh, buf); |
| 113 | if (a == NULL) |
| 114 | goto noexist; |
| 115 | |
| 116 | reg: |
| 117 | a->next = action_list; |
| 118 | action_list = a; |
| 119 | return a; |
| 120 | |
| 121 | noexist: |
| 122 | #ifdef CONFIG_GACT |
| 123 | if (!looked4gact) { |
| 124 | looked4gact = 1; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 125 | strcpy(str, "gact"); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 126 | goto restart_s; |
| 127 | } |
| 128 | #endif |
Phil Sutter | f89bb02 | 2016-07-18 16:48:43 +0200 | [diff] [blame] | 129 | a = calloc(1, sizeof(*a)); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 130 | if (a) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 131 | strncpy(a->id, "noact", 15); |
| 132 | a->parse_aopt = parse_noaopt; |
| 133 | a->print_aopt = print_noaopt; |
| 134 | goto reg; |
| 135 | } |
| 136 | return a; |
| 137 | } |
| 138 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 139 | static int |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 140 | new_cmd(char **argv) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 141 | { |
| 142 | if ((matches(*argv, "change") == 0) || |
Stephen Hemminger | e9e9365 | 2016-03-27 10:47:46 -0700 | [diff] [blame] | 143 | (matches(*argv, "replace") == 0) || |
| 144 | (matches(*argv, "delete") == 0) || |
| 145 | (matches(*argv, "get") == 0) || |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 146 | (matches(*argv, "add") == 0)) |
| 147 | return 1; |
| 148 | |
| 149 | return 0; |
| 150 | |
| 151 | } |
| 152 | |
| 153 | int |
| 154 | parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) |
| 155 | { |
| 156 | int argc = *argc_p; |
| 157 | char **argv = *argv_p; |
| 158 | struct rtattr *tail, *tail2; |
| 159 | char k[16]; |
| 160 | int ok = 0; |
| 161 | int eap = 0; /* expect action parameters */ |
| 162 | |
| 163 | int ret = 0; |
| 164 | int prio = 0; |
| 165 | |
| 166 | if (argc <= 0) |
| 167 | return -1; |
| 168 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 169 | tail = tail2 = NLMSG_TAIL(n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 170 | |
| 171 | addattr_l(n, MAX_MSG, tca_id, NULL, 0); |
| 172 | |
| 173 | while (argc > 0) { |
| 174 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 175 | memset(k, 0, sizeof(k)); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 176 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 177 | if (strcmp(*argv, "action") == 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 178 | argc--; |
| 179 | argv++; |
| 180 | eap = 1; |
| 181 | #ifdef CONFIG_GACT |
| 182 | if (!gact_ld) { |
| 183 | get_action_kind("gact"); |
| 184 | } |
| 185 | #endif |
| 186 | continue; |
Jamal Hadi Salim | 9282d08 | 2014-05-24 08:48:41 -0400 | [diff] [blame] | 187 | } else if (strcmp(*argv, "flowid") == 0) { |
| 188 | break; |
| 189 | } else if (strcmp(*argv, "classid") == 0) { |
| 190 | break; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 191 | } else if (strcmp(*argv, "help") == 0) { |
| 192 | return -1; |
| 193 | } else if (new_cmd(argv)) { |
| 194 | goto done0; |
| 195 | } else { |
| 196 | struct action_util *a = NULL; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 197 | |
| 198 | strncpy(k, *argv, sizeof(k) - 1); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 199 | eap = 0; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 200 | if (argc > 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 201 | a = get_action_kind(k); |
| 202 | } else { |
| 203 | done0: |
| 204 | if (ok) |
| 205 | break; |
| 206 | else |
| 207 | goto done; |
| 208 | } |
| 209 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 210 | if (a == NULL) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 211 | goto bad_val; |
| 212 | } |
| 213 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 214 | tail = NLMSG_TAIL(n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 215 | addattr_l(n, MAX_MSG, ++prio, NULL, 0); |
| 216 | addattr_l(n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1); |
| 217 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 218 | ret = a->parse_aopt(a, &argc, &argv, TCA_ACT_OPTIONS, n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 219 | |
| 220 | if (ret < 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 221 | fprintf(stderr, "bad action parsing\n"); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 222 | goto bad_val; |
| 223 | } |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 224 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 225 | ok++; |
| 226 | } |
| 227 | |
| 228 | } |
| 229 | |
| 230 | if (eap > 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 231 | fprintf(stderr, "bad action empty %d\n", eap); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 232 | goto bad_val; |
| 233 | } |
| 234 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 235 | tail2->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail2; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 236 | |
| 237 | done: |
| 238 | *argc_p = argc; |
| 239 | *argv_p = argv; |
| 240 | return 0; |
| 241 | bad_val: |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 242 | /* no need to undo things, returning from here should |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 243 | * cause enough pain */ |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 244 | fprintf(stderr, "parse_action: bad value (%d:%s)!\n", argc, *argv); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 245 | return -1; |
| 246 | } |
| 247 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 248 | static int |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 249 | tc_print_one_action(FILE *f, struct rtattr *arg) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 250 | { |
| 251 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 252 | struct rtattr *tb[TCA_ACT_MAX + 1]; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 253 | int err = 0; |
| 254 | struct action_util *a = NULL; |
| 255 | |
| 256 | if (arg == NULL) |
| 257 | return -1; |
| 258 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 259 | parse_rtattr_nested(tb, TCA_ACT_MAX, arg); |
| 260 | |
| 261 | if (tb[TCA_ACT_KIND] == NULL) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 262 | fprintf(stderr, "NULL Action!\n"); |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 267 | a = get_action_kind(RTA_DATA(tb[TCA_ACT_KIND])); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 268 | if (a == NULL) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 269 | return err; |
| 270 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 271 | err = a->print_aopt(a, f, tb[TCA_ACT_OPTIONS]); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 272 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 273 | if (err < 0) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 274 | return err; |
| 275 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 276 | if (show_stats && tb[TCA_ACT_STATS]) { |
ch[shemminger]!tgraf | e5879dc | 2004-12-07 23:52:52 +0000 | [diff] [blame] | 277 | fprintf(f, "\tAction statistics:\n"); |
| 278 | print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL); |
osdl.net!shemminger | 3d327bf | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 279 | fprintf(f, "\n"); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 285 | static int |
| 286 | tc_print_action_flush(FILE *f, const struct rtattr *arg) |
| 287 | { |
| 288 | |
| 289 | struct rtattr *tb[TCA_MAX + 1]; |
| 290 | int err = 0; |
| 291 | struct action_util *a = NULL; |
| 292 | __u32 *delete_count = 0; |
| 293 | |
| 294 | parse_rtattr_nested(tb, TCA_MAX, arg); |
| 295 | |
| 296 | if (tb[TCA_KIND] == NULL) { |
| 297 | fprintf(stderr, "NULL Action!\n"); |
| 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | a = get_action_kind(RTA_DATA(tb[TCA_KIND])); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 302 | if (a == NULL) |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 303 | return err; |
| 304 | |
| 305 | delete_count = RTA_DATA(tb[TCA_FCNT]); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 306 | fprintf(f, " %s (%d entries)\n", a->id, *delete_count); |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 307 | tab_flush = 0; |
| 308 | return 0; |
| 309 | } |
| 310 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 311 | int |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 312 | tc_print_action(FILE *f, const struct rtattr *arg) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 313 | { |
| 314 | |
| 315 | int i; |
| 316 | struct rtattr *tb[TCA_ACT_MAX_PRIO + 1]; |
| 317 | |
| 318 | if (arg == NULL) |
| 319 | return 0; |
| 320 | |
8!tgraf | ac2fc2d | 2005-01-18 22:11:58 +0000 | [diff] [blame] | 321 | parse_rtattr_nested(tb, TCA_ACT_MAX_PRIO, arg); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 322 | |
Jamal Hadi Salim | 954de6c | 2014-09-21 12:29:14 -0400 | [diff] [blame] | 323 | if (tab_flush && NULL != tb[0] && NULL == tb[1]) |
| 324 | return tc_print_action_flush(f, tb[0]); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 325 | |
| 326 | for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { |
| 327 | if (tb[i]) { |
Jamal Hadi Salim | f24a7e7 | 2013-12-22 10:37:44 -0500 | [diff] [blame] | 328 | fprintf(f, "\n\taction order %d: ", i); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 329 | if (tc_print_one_action(f, tb[i]) < 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 330 | fprintf(f, "Error printing action\n"); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | } |
| 335 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 336 | return 0; |
| 337 | } |
| 338 | |
Jamal Hadi Salim | 5bec348 | 2006-08-08 11:55:15 -0700 | [diff] [blame] | 339 | int print_action(const struct sockaddr_nl *who, |
osdl.net!shemminger | 50772dc | 2004-12-07 21:48:29 +0000 | [diff] [blame] | 340 | struct nlmsghdr *n, |
osdl.net!shemminger | 3d327bf | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 341 | void *arg) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 342 | { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 343 | FILE *fp = (FILE *)arg; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 344 | struct tcamsg *t = NLMSG_DATA(n); |
| 345 | int len = n->nlmsg_len; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 346 | struct rtattr *tb[TCAA_MAX+1]; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 347 | |
| 348 | len -= NLMSG_LENGTH(sizeof(*t)); |
| 349 | |
| 350 | if (len < 0) { |
| 351 | fprintf(stderr, "Wrong len %d\n", len); |
| 352 | return -1; |
| 353 | } |
| 354 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 355 | parse_rtattr(tb, TCAA_MAX, TA_RTA(t), len); |
| 356 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 357 | if (tb[TCA_ACT_TAB] == NULL) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 358 | if (n->nlmsg_type != RTM_GETACTION) |
Jamal Hadi Salim | 5bec348 | 2006-08-08 11:55:15 -0700 | [diff] [blame] | 359 | fprintf(stderr, "print_action: NULL kind\n"); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 360 | return -1; |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 361 | } |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 362 | |
| 363 | if (n->nlmsg_type == RTM_DELACTION) { |
| 364 | if (n->nlmsg_flags & NLM_F_ROOT) { |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 365 | fprintf(fp, "Flushed table "); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 366 | tab_flush = 1; |
| 367 | } else { |
| 368 | fprintf(fp, "deleted action "); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | if (n->nlmsg_type == RTM_NEWACTION) |
| 373 | fprintf(fp, "Added action "); |
| 374 | tc_print_action(fp, tb[TCA_ACT_TAB]); |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 379 | static int tc_action_gd(int cmd, unsigned int flags, int *argc_p, char ***argv_p) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 380 | { |
| 381 | char k[16]; |
| 382 | struct action_util *a = NULL; |
| 383 | int argc = *argc_p; |
| 384 | char **argv = *argv_p; |
| 385 | int prio = 0; |
| 386 | int ret = 0; |
| 387 | __u32 i; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 388 | struct rtattr *tail; |
| 389 | struct rtattr *tail2; |
| 390 | struct nlmsghdr *ans = NULL; |
| 391 | |
| 392 | struct { |
| 393 | struct nlmsghdr n; |
| 394 | struct tcamsg t; |
| 395 | char buf[MAX_MSG]; |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 396 | } req = { |
Phil Sutter | d892aaf | 2016-07-18 16:48:41 +0200 | [diff] [blame] | 397 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)), |
| 398 | .n.nlmsg_flags = NLM_F_REQUEST | flags, |
| 399 | .n.nlmsg_type = cmd, |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 400 | .t.tca_family = AF_UNSPEC, |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 401 | }; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 402 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 403 | argc -= 1; |
| 404 | argv += 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 405 | |
| 406 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 407 | tail = NLMSG_TAIL(&req.n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 408 | addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0); |
| 409 | |
| 410 | while (argc > 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 411 | if (strcmp(*argv, "action") == 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 412 | argc--; |
| 413 | argv++; |
| 414 | continue; |
| 415 | } else if (strcmp(*argv, "help") == 0) { |
| 416 | return -1; |
| 417 | } |
| 418 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 419 | strncpy(k, *argv, sizeof(k) - 1); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 420 | a = get_action_kind(k); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 421 | if (a == NULL) { |
| 422 | fprintf(stderr, "Error: non existent action: %s\n", k); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 423 | ret = -1; |
| 424 | goto bad_val; |
| 425 | } |
| 426 | if (strcmp(a->id, k) != 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 427 | fprintf(stderr, "Error: non existent action: %s\n", k); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 428 | ret = -1; |
| 429 | goto bad_val; |
| 430 | } |
| 431 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 432 | argc -= 1; |
| 433 | argv += 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 434 | if (argc <= 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 435 | fprintf(stderr, "Error: no index specified action: %s\n", k); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 436 | ret = -1; |
| 437 | goto bad_val; |
| 438 | } |
| 439 | |
| 440 | if (matches(*argv, "index") == 0) { |
| 441 | NEXT_ARG(); |
| 442 | if (get_u32(&i, *argv, 10)) { |
| 443 | fprintf(stderr, "Illegal \"index\"\n"); |
| 444 | ret = -1; |
| 445 | goto bad_val; |
| 446 | } |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 447 | argc -= 1; |
| 448 | argv += 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 449 | } else { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 450 | fprintf(stderr, "Error: no index specified action: %s\n", k); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 451 | ret = -1; |
| 452 | goto bad_val; |
| 453 | } |
| 454 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 455 | tail2 = NLMSG_TAIL(&req.n); |
| 456 | addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0); |
| 457 | addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1); |
| 458 | addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i); |
| 459 | tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 460 | |
| 461 | } |
| 462 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 463 | tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 464 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 465 | req.n.nlmsg_seq = rth.dump = ++rth.seq; |
| 466 | if (cmd == RTM_GETACTION) |
| 467 | ans = &req.n; |
site!shemminger | c1027a7 | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 468 | |
Stephen Hemminger | c079e12 | 2015-05-27 12:26:14 -0700 | [diff] [blame] | 469 | if (rtnl_talk(&rth, &req.n, ans, MAX_MSG) < 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 470 | fprintf(stderr, "We have an error talking to the kernel\n"); |
osdl.net!shemminger | 52f337c | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 471 | return 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 474 | if (ans && print_action(NULL, &req.n, (void *)stdout) < 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 475 | fprintf(stderr, "Dump terminated\n"); |
osdl.net!shemminger | 52f337c | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 476 | return 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | *argc_p = argc; |
| 480 | *argv_p = argv; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 481 | bad_val: |
| 482 | return ret; |
| 483 | } |
| 484 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 485 | static int tc_action_modify(int cmd, unsigned int flags, int *argc_p, char ***argv_p) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 486 | { |
| 487 | int argc = *argc_p; |
| 488 | char **argv = *argv_p; |
| 489 | int ret = 0; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 490 | struct { |
| 491 | struct nlmsghdr n; |
| 492 | struct tcamsg t; |
| 493 | char buf[MAX_MSG]; |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 494 | } req = { |
Phil Sutter | d892aaf | 2016-07-18 16:48:41 +0200 | [diff] [blame] | 495 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)), |
| 496 | .n.nlmsg_flags = NLM_F_REQUEST | flags, |
| 497 | .n.nlmsg_type = cmd, |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 498 | .t.tca_family = AF_UNSPEC, |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 499 | }; |
Phil Sutter | d892aaf | 2016-07-18 16:48:41 +0200 | [diff] [blame] | 500 | struct rtattr *tail = NLMSG_TAIL(&req.n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 501 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 502 | argc -= 1; |
| 503 | argv += 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 504 | if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) { |
| 505 | fprintf(stderr, "Illegal \"action\"\n"); |
| 506 | return -1; |
| 507 | } |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 508 | tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 509 | |
Stephen Hemminger | c079e12 | 2015-05-27 12:26:14 -0700 | [diff] [blame] | 510 | if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 511 | fprintf(stderr, "We have an error talking to the kernel\n"); |
| 512 | ret = -1; |
| 513 | } |
| 514 | |
| 515 | *argc_p = argc; |
| 516 | *argv_p = argv; |
site!shemminger | c1027a7 | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 517 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 518 | return ret; |
| 519 | } |
| 520 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 521 | static int tc_act_list_or_flush(int argc, char **argv, int event) |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 522 | { |
| 523 | int ret = 0, prio = 0, msg_size = 0; |
| 524 | char k[16]; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 525 | struct rtattr *tail, *tail2; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 526 | struct action_util *a = NULL; |
| 527 | struct { |
| 528 | struct nlmsghdr n; |
| 529 | struct tcamsg t; |
| 530 | char buf[MAX_MSG]; |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 531 | } req = { |
| 532 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)), |
| 533 | .t.tca_family = AF_UNSPEC, |
Phil Sutter | a0a73b2 | 2016-06-16 00:50:38 +0200 | [diff] [blame] | 534 | }; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 535 | |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 536 | tail = NLMSG_TAIL(&req.n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 537 | addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0); |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 538 | tail2 = NLMSG_TAIL(&req.n); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 539 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 540 | strncpy(k, *argv, sizeof(k) - 1); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 541 | #ifdef CONFIG_GACT |
| 542 | if (!gact_ld) { |
| 543 | get_action_kind("gact"); |
| 544 | } |
| 545 | #endif |
| 546 | a = get_action_kind(k); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 547 | if (a == NULL) { |
| 548 | fprintf(stderr, "bad action %s\n", k); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 549 | goto bad_val; |
| 550 | } |
| 551 | if (strcmp(a->id, k) != 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 552 | fprintf(stderr, "bad action %s\n", k); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 553 | goto bad_val; |
| 554 | } |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 555 | strncpy(k, *argv, sizeof(k) - 1); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 556 | |
| 557 | addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0); |
| 558 | addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1); |
8!tgraf | 4a86fe1 | 2005-01-18 01:24:18 +0000 | [diff] [blame] | 559 | tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2; |
| 560 | tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 561 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 562 | msg_size = NLMSG_ALIGN(req.n.nlmsg_len) - NLMSG_ALIGN(sizeof(struct nlmsghdr)); |
| 563 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 564 | if (event == RTM_GETACTION) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 565 | if (rtnl_dump_request(&rth, event, (void *)&req.t, msg_size) < 0) { |
| 566 | perror("Cannot send dump request"); |
osdl.net!shemminger | 52f337c | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 567 | return 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 568 | } |
Stephen Hemminger | cd70f3f | 2011-12-28 10:37:12 -0800 | [diff] [blame] | 569 | ret = rtnl_dump_filter(&rth, print_action, stdout); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 572 | if (event == RTM_DELACTION) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 573 | req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len); |
| 574 | req.n.nlmsg_type = RTM_DELACTION; |
| 575 | req.n.nlmsg_flags |= NLM_F_ROOT; |
| 576 | req.n.nlmsg_flags |= NLM_F_REQUEST; |
Stephen Hemminger | c079e12 | 2015-05-27 12:26:14 -0700 | [diff] [blame] | 577 | if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) { |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 578 | fprintf(stderr, "We have an error flushing\n"); |
osdl.net!shemminger | 52f337c | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 579 | return 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | } |
| 583 | |
| 584 | bad_val: |
| 585 | |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | int do_action(int argc, char **argv) |
| 590 | { |
| 591 | |
| 592 | int ret = 0; |
| 593 | |
| 594 | while (argc > 0) { |
| 595 | |
| 596 | if (matches(*argv, "add") == 0) { |
| 597 | ret = tc_action_modify(RTM_NEWACTION, NLM_F_EXCL|NLM_F_CREATE, &argc, &argv); |
| 598 | } else if (matches(*argv, "change") == 0 || |
| 599 | matches(*argv, "replace") == 0) { |
| 600 | ret = tc_action_modify(RTM_NEWACTION, NLM_F_CREATE|NLM_F_REPLACE, &argc, &argv); |
| 601 | } else if (matches(*argv, "delete") == 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 602 | argc -= 1; |
| 603 | argv += 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 604 | ret = tc_action_gd(RTM_DELACTION, 0, &argc, &argv); |
| 605 | } else if (matches(*argv, "get") == 0) { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 606 | argc -= 1; |
| 607 | argv += 1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 608 | ret = tc_action_gd(RTM_GETACTION, 0, &argc, &argv); |
| 609 | } else if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0 |
| 610 | || matches(*argv, "lst") == 0) { |
| 611 | if (argc <= 2) { |
| 612 | act_usage(); |
| 613 | return -1; |
| 614 | } |
| 615 | return tc_act_list_or_flush(argc-2, argv+2, RTM_GETACTION); |
| 616 | } else if (matches(*argv, "flush") == 0) { |
| 617 | if (argc <= 2) { |
| 618 | act_usage(); |
| 619 | return -1; |
| 620 | } |
| 621 | return tc_act_list_or_flush(argc-2, argv+2, RTM_DELACTION); |
| 622 | } else if (matches(*argv, "help") == 0) { |
| 623 | act_usage(); |
| 624 | return -1; |
| 625 | } else { |
jamal | f1e4f04 | 2006-08-04 10:59:34 -0700 | [diff] [blame] | 626 | fprintf(stderr, "Command \"%s\" is unknown, try \"tc actions help\".\n", *argv); |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 627 | return -1; |
| 628 | } |
WANG Cong | 6fcf36c | 2016-08-08 16:24:45 -0700 | [diff] [blame] | 629 | |
| 630 | if (ret < 0) |
| 631 | return -1; |
osdl.net!shemminger | 68d5ba5 | 2004-08-13 23:54:55 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | return 0; |
| 635 | } |