osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * tc.c "tc" utility frontend. |
| 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 | * Fixes: |
| 12 | * |
| 13 | * Petri Mattila <petri@prihateam.fi> 990308: wrong memset's resulted in faults |
| 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <syslog.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <dlfcn.h> |
| 22 | #include <sys/socket.h> |
| 23 | #include <netinet/in.h> |
| 24 | #include <arpa/inet.h> |
| 25 | #include <string.h> |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include "SNAPSHOT.h" |
| 29 | #include "utils.h" |
| 30 | #include "tc_util.h" |
| 31 | #include "tc_common.h" |
Vadim Kochan | 67e1d73 | 2014-12-24 23:04:11 +0200 | [diff] [blame] | 32 | #include "namespace.h" |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 33 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 34 | int show_stats; |
| 35 | int show_details; |
| 36 | int show_raw; |
| 37 | int show_pretty; |
| 38 | int show_graph; |
Eric Dumazet | 32a6fbe | 2015-09-23 16:40:04 -0700 | [diff] [blame] | 39 | int timestamp; |
Stephen Hemminger | 44dcfe8 | 2008-05-09 15:42:34 -0700 | [diff] [blame] | 40 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 41 | int batch_mode; |
| 42 | int resolve_hosts; |
| 43 | int use_iec; |
| 44 | int force; |
| 45 | bool use_names; |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 46 | |
| 47 | static char *conf_file; |
| 48 | |
osdl.net!shemminger | 7901660 | 2005-03-14 19:34:12 +0000 | [diff] [blame] | 49 | struct rtnl_handle rth; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 50 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 51 | static void *BODY; /* cached handle dlopen(NULL) */ |
| 52 | static struct qdisc_util *qdisc_list; |
| 53 | static struct filter_util *filter_list; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 54 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 55 | static int print_noqopt(struct qdisc_util *qu, FILE *f, |
osdl.net!shemminger | 1798c9d | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 56 | struct rtattr *opt) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 57 | { |
| 58 | if (opt && RTA_PAYLOAD(opt)) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 59 | fprintf(f, "[Unknown qdisc, optlen=%u] ", |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 60 | (unsigned int) RTA_PAYLOAD(opt)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 65 | { |
| 66 | if (argc) { |
| 67 | fprintf(stderr, "Unknown qdisc \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv); |
| 68 | return -1; |
| 69 | } |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int print_nofopt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 fhandle) |
| 74 | { |
| 75 | if (opt && RTA_PAYLOAD(opt)) |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 76 | fprintf(f, "fh %08x [Unknown filter, optlen=%u] ", |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 77 | fhandle, (unsigned int) RTA_PAYLOAD(opt)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 78 | else if (fhandle) |
| 79 | fprintf(f, "fh %08x ", fhandle); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int parse_nofopt(struct filter_util *qu, char *fhandle, int argc, char **argv, struct nlmsghdr *n) |
| 84 | { |
| 85 | __u32 handle; |
| 86 | |
| 87 | if (argc) { |
| 88 | fprintf(stderr, "Unknown filter \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv); |
| 89 | return -1; |
| 90 | } |
| 91 | if (fhandle) { |
| 92 | struct tcmsg *t = NLMSG_DATA(n); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 93 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 94 | if (get_u32(&handle, fhandle, 16)) { |
| 95 | fprintf(stderr, "Unparsable filter ID \"%s\"\n", fhandle); |
| 96 | return -1; |
| 97 | } |
| 98 | t->tcm_handle = handle; |
| 99 | } |
| 100 | return 0; |
| 101 | } |
| 102 | |
osdl.org!shemminger | 4094db7 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 103 | struct qdisc_util *get_qdisc_kind(const char *str) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 104 | { |
| 105 | void *dlh; |
| 106 | char buf[256]; |
| 107 | struct qdisc_util *q; |
| 108 | |
| 109 | for (q = qdisc_list; q; q = q->next) |
| 110 | if (strcmp(q->id, str) == 0) |
| 111 | return q; |
| 112 | |
Stephen Hemminger | aa27f88 | 2007-06-20 15:27:22 -0700 | [diff] [blame] | 113 | snprintf(buf, sizeof(buf), "%s/q_%s.so", get_tc_lib(), str); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 114 | dlh = dlopen(buf, RTLD_LAZY); |
osdl.net!shemminger | b7a4515 | 2004-07-02 17:47:53 +0000 | [diff] [blame] | 115 | if (!dlh) { |
| 116 | /* look in current binary, only open once */ |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 117 | dlh = BODY; |
| 118 | if (dlh == NULL) { |
| 119 | dlh = BODY = dlopen(NULL, RTLD_LAZY); |
| 120 | if (dlh == NULL) |
| 121 | goto noexist; |
| 122 | } |
| 123 | } |
| 124 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 125 | snprintf(buf, sizeof(buf), "%s_qdisc_util", str); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 126 | q = dlsym(dlh, buf); |
| 127 | if (q == NULL) |
| 128 | goto noexist; |
| 129 | |
| 130 | reg: |
| 131 | q->next = qdisc_list; |
| 132 | qdisc_list = q; |
| 133 | return q; |
| 134 | |
| 135 | noexist: |
Phil Sutter | f89bb02 | 2016-07-18 16:48:43 +0200 | [diff] [blame] | 136 | q = calloc(1, sizeof(*q)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 137 | if (q) { |
Phil Sutter | f89bb02 | 2016-07-18 16:48:43 +0200 | [diff] [blame] | 138 | q->id = strdup(str); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 139 | q->parse_qopt = parse_noqopt; |
| 140 | q->print_qopt = print_noqopt; |
| 141 | goto reg; |
| 142 | } |
| 143 | return q; |
| 144 | } |
| 145 | |
| 146 | |
osdl.org!shemminger | 4094db7 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 147 | struct filter_util *get_filter_kind(const char *str) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 148 | { |
| 149 | void *dlh; |
| 150 | char buf[256]; |
| 151 | struct filter_util *q; |
| 152 | |
| 153 | for (q = filter_list; q; q = q->next) |
| 154 | if (strcmp(q->id, str) == 0) |
| 155 | return q; |
| 156 | |
Stephen Hemminger | aa27f88 | 2007-06-20 15:27:22 -0700 | [diff] [blame] | 157 | snprintf(buf, sizeof(buf), "%s/f_%s.so", get_tc_lib(), str); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 158 | dlh = dlopen(buf, RTLD_LAZY); |
| 159 | if (dlh == NULL) { |
| 160 | dlh = BODY; |
| 161 | if (dlh == NULL) { |
| 162 | dlh = BODY = dlopen(NULL, RTLD_LAZY); |
| 163 | if (dlh == NULL) |
| 164 | goto noexist; |
| 165 | } |
| 166 | } |
| 167 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 168 | snprintf(buf, sizeof(buf), "%s_filter_util", str); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 169 | q = dlsym(dlh, buf); |
| 170 | if (q == NULL) |
| 171 | goto noexist; |
| 172 | |
| 173 | reg: |
| 174 | q->next = filter_list; |
| 175 | filter_list = q; |
| 176 | return q; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 177 | noexist: |
Phil Sutter | f89bb02 | 2016-07-18 16:48:43 +0200 | [diff] [blame] | 178 | q = calloc(1, sizeof(*q)); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 179 | if (q) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 180 | strncpy(q->id, str, 15); |
| 181 | q->parse_fopt = parse_nofopt; |
| 182 | q->print_fopt = print_nofopt; |
| 183 | goto reg; |
| 184 | } |
| 185 | return q; |
| 186 | } |
| 187 | |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 188 | static void usage(void) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 189 | { |
| 190 | fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n" |
Petr Jediný | 10494d2 | 2008-08-07 16:45:33 +0200 | [diff] [blame] | 191 | " tc [-force] -batch filename\n" |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 192 | "where OBJECT := { qdisc | class | filter | action | monitor | exec }\n" |
| 193 | " OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n" |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 194 | " -nm | -nam[es] | { -cf | -conf } path }\n"); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static int do_cmd(int argc, char **argv) |
| 198 | { |
| 199 | if (matches(*argv, "qdisc") == 0) |
| 200 | return do_qdisc(argc-1, argv+1); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 201 | if (matches(*argv, "class") == 0) |
| 202 | return do_class(argc-1, argv+1); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 203 | if (matches(*argv, "filter") == 0) |
| 204 | return do_filter(argc-1, argv+1); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 205 | if (matches(*argv, "actions") == 0) |
| 206 | return do_action(argc-1, argv+1); |
Jamal Hadi Salim | 5bec348 | 2006-08-08 11:55:15 -0700 | [diff] [blame] | 207 | if (matches(*argv, "monitor") == 0) |
| 208 | return do_tcmonitor(argc-1, argv+1); |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 209 | if (matches(*argv, "exec") == 0) |
| 210 | return do_exec(argc-1, argv+1); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 211 | if (matches(*argv, "help") == 0) { |
| 212 | usage(); |
| 213 | return 0; |
| 214 | } |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 215 | |
| 216 | fprintf(stderr, "Object \"%s\" is unknown, try \"tc help\".\n", |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 217 | *argv); |
osdl.net!shemminger | 044ebf3 | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 218 | return -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 219 | } |
| 220 | |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 221 | static int batch(const char *name) |
| 222 | { |
| 223 | char *line = NULL; |
| 224 | size_t len = 0; |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 225 | int ret = 0; |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 226 | |
Stephen Hemminger | a3aa47a | 2013-07-16 10:04:05 -0700 | [diff] [blame] | 227 | batch_mode = 1; |
shemminger | dd3e908 | 2005-06-23 17:32:22 +0000 | [diff] [blame] | 228 | if (name && strcmp(name, "-") != 0) { |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 229 | if (freopen(name, "r", stdin) == NULL) { |
Stephen Hemminger | 84d6688 | 2008-02-07 22:10:14 -0800 | [diff] [blame] | 230 | fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n", |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 231 | name, strerror(errno)); |
| 232 | return -1; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | tc_core_init(); |
| 237 | |
| 238 | if (rtnl_open(&rth, 0) < 0) { |
| 239 | fprintf(stderr, "Cannot open rtnetlink\n"); |
| 240 | return -1; |
| 241 | } |
| 242 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 243 | cmdlineno = 0; |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 244 | while (getcmdline(&line, &len, stdin) != -1) { |
| 245 | char *largv[100]; |
| 246 | int largc; |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 247 | |
| 248 | largc = makeargs(line, largv, 100); |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 249 | if (largc == 0) |
| 250 | continue; /* blank line */ |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 251 | |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 252 | if (do_cmd(largc, largv)) { |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 253 | fprintf(stderr, "Command failed %s:%d\n", name, cmdlineno); |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 254 | ret = 1; |
| 255 | if (!force) |
| 256 | break; |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 257 | } |
| 258 | } |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 259 | if (line) |
| 260 | free(line); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 261 | |
| 262 | rtnl_close(&rth); |
| 263 | return ret; |
| 264 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 265 | |
| 266 | |
| 267 | int main(int argc, char **argv) |
| 268 | { |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 269 | int ret; |
Stephen Hemminger | a3aa47a | 2013-07-16 10:04:05 -0700 | [diff] [blame] | 270 | char *batch_file = NULL; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 271 | |
| 272 | while (argc > 1) { |
| 273 | if (argv[1][0] != '-') |
| 274 | break; |
| 275 | if (matches(argv[1], "-stats") == 0 || |
osdl.net!shemminger | 3ea2bf4 | 2004-06-28 20:42:59 +0000 | [diff] [blame] | 276 | matches(argv[1], "-statistics") == 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 277 | ++show_stats; |
| 278 | } else if (matches(argv[1], "-details") == 0) { |
| 279 | ++show_details; |
| 280 | } else if (matches(argv[1], "-raw") == 0) { |
| 281 | ++show_raw; |
Stephen Hemminger | 44dcfe8 | 2008-05-09 15:42:34 -0700 | [diff] [blame] | 282 | } else if (matches(argv[1], "-pretty") == 0) { |
| 283 | ++show_pretty; |
Vadim Kochan | d954b34 | 2014-12-26 02:10:06 +0200 | [diff] [blame] | 284 | } else if (matches(argv[1], "-graph") == 0) { |
| 285 | show_graph = 1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 286 | } else if (matches(argv[1], "-Version") == 0) { |
| 287 | printf("tc utility, iproute2-ss%s\n", SNAPSHOT); |
osdl.net!shemminger | 044ebf3 | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 288 | return 0; |
osdl.net!shemminger | 3ea2bf4 | 2004-06-28 20:42:59 +0000 | [diff] [blame] | 289 | } else if (matches(argv[1], "-iec") == 0) { |
| 290 | ++use_iec; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 291 | } else if (matches(argv[1], "-help") == 0) { |
| 292 | usage(); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 293 | return 0; |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 294 | } else if (matches(argv[1], "-force") == 0) { |
| 295 | ++force; |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 296 | } else if (matches(argv[1], "-batch") == 0) { |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 297 | argc--; argv++; |
Stephen Hemminger | a3aa47a | 2013-07-16 10:04:05 -0700 | [diff] [blame] | 298 | if (argc <= 1) |
| 299 | usage(); |
| 300 | batch_file = argv[1]; |
Vadim Kochan | 67e1d73 | 2014-12-24 23:04:11 +0200 | [diff] [blame] | 301 | } else if (matches(argv[1], "-netns") == 0) { |
| 302 | NEXT_ARG(); |
| 303 | if (netns_switch(argv[1])) |
| 304 | return -1; |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 305 | } else if (matches(argv[1], "-names") == 0 || |
| 306 | matches(argv[1], "-nm") == 0) { |
| 307 | use_names = true; |
| 308 | } else if (matches(argv[1], "-cf") == 0 || |
| 309 | matches(argv[1], "-conf") == 0) { |
| 310 | NEXT_ARG(); |
| 311 | conf_file = argv[1]; |
Eric Dumazet | 32a6fbe | 2015-09-23 16:40:04 -0700 | [diff] [blame] | 312 | } else if (matches(argv[1], "-timestamp") == 0) { |
| 313 | timestamp++; |
| 314 | } else if (matches(argv[1], "-tshort") == 0) { |
| 315 | ++timestamp; |
| 316 | ++timestamp_short; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 317 | } else { |
| 318 | fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]); |
osdl.net!shemminger | 044ebf3 | 2005-03-14 19:02:41 +0000 | [diff] [blame] | 319 | return -1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 320 | } |
| 321 | argc--; argv++; |
| 322 | } |
| 323 | |
Stephen Hemminger | a3aa47a | 2013-07-16 10:04:05 -0700 | [diff] [blame] | 324 | if (batch_file) |
| 325 | return batch(batch_file); |
osdl.net!shemminger | 08856f0 | 2005-03-18 19:40:55 +0000 | [diff] [blame] | 326 | |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 327 | if (argc <= 1) { |
| 328 | usage(); |
| 329 | return 0; |
| 330 | } |
| 331 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 332 | tc_core_init(); |
osdl.net!shemminger | 7901660 | 2005-03-14 19:34:12 +0000 | [diff] [blame] | 333 | if (rtnl_open(&rth, 0) < 0) { |
| 334 | fprintf(stderr, "Cannot open rtnetlink\n"); |
| 335 | exit(1); |
| 336 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 337 | |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 338 | if (use_names && cls_names_init(conf_file)) { |
| 339 | ret = -1; |
| 340 | goto Exit; |
| 341 | } |
| 342 | |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 343 | ret = do_cmd(argc-1, argv+1); |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 344 | Exit: |
osdl.net!shemminger | 7901660 | 2005-03-14 19:34:12 +0000 | [diff] [blame] | 345 | rtnl_close(&rth); |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 346 | |
Vadim Kochan | 4612d04 | 2015-03-03 18:41:18 +0200 | [diff] [blame] | 347 | if (use_names) |
| 348 | cls_names_uninit(); |
| 349 | |
site!shemminger | c2f3a0f | 2005-03-14 22:19:16 +0000 | [diff] [blame] | 350 | return ret; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 351 | } |