osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ip.c "ip" 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> |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <unistd.h> |
| 15 | #include <syslog.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <sys/socket.h> |
| 18 | #include <netinet/in.h> |
| 19 | #include <string.h> |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 20 | #include <errno.h> |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 21 | |
| 22 | #include "SNAPSHOT.h" |
| 23 | #include "utils.h" |
| 24 | #include "ip_common.h" |
Vadim Kochan | 52700d4 | 2014-12-24 23:04:09 +0200 | [diff] [blame] | 25 | #include "namespace.h" |
Mathias Nyman | d7bd2db | 2015-04-28 13:18:21 +0300 | [diff] [blame] | 26 | #include "color.h" |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 27 | |
| 28 | int preferred_family = AF_UNSPEC; |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 29 | int human_readable; |
| 30 | int use_iec; |
| 31 | int show_stats; |
| 32 | int show_details; |
| 33 | int resolve_hosts; |
| 34 | int oneline; |
Andy Gospodarek | 5d295bb | 2015-08-28 13:45:41 -0400 | [diff] [blame] | 35 | int brief; |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 36 | int timestamp; |
| 37 | const char *_SL_; |
| 38 | int force; |
Ben Greear | 64c7956 | 2010-12-01 11:13:51 -0800 | [diff] [blame] | 39 | int max_flush_loops = 10; |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 40 | int batch_mode; |
| 41 | bool do_all; |
Ben Greear | 64c7956 | 2010-12-01 11:13:51 -0800 | [diff] [blame] | 42 | |
Stephen Hemminger | 3bfa73f | 2006-09-26 10:41:57 -0700 | [diff] [blame] | 43 | struct rtnl_handle rth = { .fd = -1 }; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 44 | |
| 45 | static void usage(void) __attribute__((noreturn)); |
| 46 | |
| 47 | static void usage(void) |
| 48 | { |
| 49 | fprintf(stderr, |
| 50 | "Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n" |
Petr Jediný | 10494d2 | 2008-08-07 16:45:33 +0200 | [diff] [blame] | 51 | " ip [ -force ] -batch filename\n" |
Phil Sutter | 7a53aa5 | 2016-03-02 19:19:49 +0100 | [diff] [blame] | 52 | "where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |\n" |
Pavel Šimerda | 142434d | 2015-08-12 22:04:06 +0200 | [diff] [blame] | 53 | " tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |\n" |
Tom Herbert | ec71cae | 2016-08-04 13:34:54 -0700 | [diff] [blame] | 54 | " netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila }\n" |
Patrick McHardy | 1d93483 | 2007-08-22 10:49:01 -0700 | [diff] [blame] | 55 | " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" |
Stephen Hemminger | 1e264ab | 2014-11-02 12:49:19 -0800 | [diff] [blame] | 56 | " -h[uman-readable] | -iec |\n" |
Eric W. Biederman | dacc5d4 | 2015-03-15 14:53:45 -0500 | [diff] [blame] | 57 | " -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |\n" |
Eric W. Biederman | f480917 | 2013-03-11 14:59:55 -0700 | [diff] [blame] | 58 | " -4 | -6 | -I | -D | -B | -0 |\n" |
Andy Gospodarek | 5d295bb | 2015-08-28 13:45:41 -0400 | [diff] [blame] | 59 | " -l[oops] { maximum-addr-flush-attempts } | -br[ief] |\n" |
Vadim Kochan | a925535 | 2014-12-28 11:47:43 +0200 | [diff] [blame] | 60 | " -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n" |
Mathias Nyman | d7bd2db | 2015-04-28 13:18:21 +0300 | [diff] [blame] | 61 | " -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}\n"); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 62 | exit(-1); |
| 63 | } |
| 64 | |
shemminger | fc57a9d | 2005-09-07 17:43:00 +0000 | [diff] [blame] | 65 | static int do_help(int argc, char **argv) |
| 66 | { |
| 67 | usage(); |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 68 | return 0; |
shemminger | fc57a9d | 2005-09-07 17:43:00 +0000 | [diff] [blame] | 69 | } |
| 70 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 71 | static const struct cmd { |
| 72 | const char *cmd; |
| 73 | int (*func)(int argc, char **argv); |
| 74 | } cmds[] = { |
Stephen Hemminger | 4806867 | 2014-02-17 10:56:31 -0800 | [diff] [blame] | 75 | { "address", do_ipaddr }, |
YOSHIFUJI Hideaki / 吉藤英明 | 4759758 | 2008-02-14 03:20:12 +1100 | [diff] [blame] | 76 | { "addrlabel", do_ipaddrlabel }, |
shemminger | ede7239 | 2005-11-22 17:30:43 +0000 | [diff] [blame] | 77 | { "maddress", do_multiaddr }, |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 78 | { "route", do_iproute }, |
| 79 | { "rule", do_iprule }, |
shemminger | ede7239 | 2005-11-22 17:30:43 +0000 | [diff] [blame] | 80 | { "neighbor", do_ipneigh }, |
| 81 | { "neighbour", do_ipneigh }, |
shemminger | 09954dc | 2006-01-10 18:43:32 +0000 | [diff] [blame] | 82 | { "ntable", do_ipntable }, |
| 83 | { "ntbl", do_ipntable }, |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 84 | { "link", do_iplink }, |
Stephen Hemminger | 5aa08f6 | 2012-01-20 08:16:02 -0800 | [diff] [blame] | 85 | { "l2tp", do_ipl2tp }, |
Tom Herbert | 6928747 | 2014-11-05 10:06:24 -0800 | [diff] [blame] | 86 | { "fou", do_ipfou }, |
Tom Herbert | ec71cae | 2016-08-04 13:34:54 -0700 | [diff] [blame] | 87 | { "ila", do_ipila }, |
Sabrina Dubroca | b26fc59 | 2016-06-08 09:34:21 -0700 | [diff] [blame] | 88 | { "macsec", do_ipmacsec }, |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 89 | { "tunnel", do_iptunnel }, |
shemminger | ede7239 | 2005-11-22 17:30:43 +0000 | [diff] [blame] | 90 | { "tunl", do_iptunnel }, |
David Woodhouse | 580fbd8 | 2009-09-19 09:48:43 -0700 | [diff] [blame] | 91 | { "tuntap", do_iptuntap }, |
| 92 | { "tap", do_iptuntap }, |
Daniel Borkmann | 191b60b | 2013-04-30 06:22:50 +0000 | [diff] [blame] | 93 | { "token", do_iptoken }, |
Julian Anastasov | ea63a69 | 2012-10-03 12:07:39 +0000 | [diff] [blame] | 94 | { "tcpmetrics", do_tcp_metrics }, |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 95 | { "tcp_metrics", do_tcp_metrics }, |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 96 | { "monitor", do_ipmonitor }, |
| 97 | { "xfrm", do_xfrm }, |
shemminger | 84616f8 | 2005-10-07 16:41:34 +0000 | [diff] [blame] | 98 | { "mroute", do_multiroute }, |
Patrick McHardy | b6c8e80 | 2010-06-09 17:41:10 +0200 | [diff] [blame] | 99 | { "mrule", do_multirule }, |
Eric W. Biederman | 0dc34c7 | 2011-07-13 09:48:26 -0700 | [diff] [blame] | 100 | { "netns", do_netns }, |
Nicolas Dichtel | 9d0efc1 | 2012-12-12 09:09:23 -0800 | [diff] [blame] | 101 | { "netconf", do_ipnetconf }, |
shemminger | fc57a9d | 2005-09-07 17:43:00 +0000 | [diff] [blame] | 102 | { "help", do_help }, |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 103 | { 0 } |
| 104 | }; |
| 105 | |
| 106 | static int do_cmd(const char *argv0, int argc, char **argv) |
| 107 | { |
shemminger | e25d697 | 2005-12-02 20:02:26 +0000 | [diff] [blame] | 108 | const struct cmd *c; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 109 | |
shemminger | ede7239 | 2005-11-22 17:30:43 +0000 | [diff] [blame] | 110 | for (c = cmds; c->cmd; ++c) { |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 111 | if (matches(argv0, c->cmd) == 0) |
Stephen Hemminger | 7397944 | 2011-10-13 08:38:33 -0700 | [diff] [blame] | 112 | return -(c->func(argc-1, argv+1)); |
shemminger | ede7239 | 2005-11-22 17:30:43 +0000 | [diff] [blame] | 113 | } |
| 114 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 115 | fprintf(stderr, "Object \"%s\" is unknown, try \"ip help\".\n", argv0); |
Stephen Hemminger | 7397944 | 2011-10-13 08:38:33 -0700 | [diff] [blame] | 116 | return EXIT_FAILURE; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static int batch(const char *name) |
| 120 | { |
| 121 | char *line = NULL; |
| 122 | size_t len = 0; |
Stephen Hemminger | 7397944 | 2011-10-13 08:38:33 -0700 | [diff] [blame] | 123 | int ret = EXIT_SUCCESS; |
Antti Paila | 531d5da | 2015-07-31 13:55:31 +0300 | [diff] [blame] | 124 | int orig_family = preferred_family; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 125 | |
Stephen Hemminger | a3aa47a | 2013-07-16 10:04:05 -0700 | [diff] [blame] | 126 | batch_mode = 1; |
| 127 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 128 | if (name && strcmp(name, "-") != 0) { |
| 129 | if (freopen(name, "r", stdin) == NULL) { |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 130 | fprintf(stderr, |
| 131 | "Cannot open file \"%s\" for reading: %s\n", |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 132 | name, strerror(errno)); |
Stephen Hemminger | 7397944 | 2011-10-13 08:38:33 -0700 | [diff] [blame] | 133 | return EXIT_FAILURE; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | if (rtnl_open(&rth, 0) < 0) { |
| 138 | fprintf(stderr, "Cannot open rtnetlink\n"); |
Stephen Hemminger | 7397944 | 2011-10-13 08:38:33 -0700 | [diff] [blame] | 139 | return EXIT_FAILURE; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Stephen Hemminger | 3e4f6a3 | 2010-03-03 16:31:09 -0800 | [diff] [blame] | 142 | cmdlineno = 0; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 143 | while (getcmdline(&line, &len, stdin) != -1) { |
| 144 | char *largv[100]; |
| 145 | int largc; |
| 146 | |
Antti Paila | 531d5da | 2015-07-31 13:55:31 +0300 | [diff] [blame] | 147 | preferred_family = orig_family; |
| 148 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 149 | largc = makeargs(line, largv, 100); |
| 150 | if (largc == 0) |
| 151 | continue; /* blank line */ |
| 152 | |
| 153 | if (do_cmd(largv[0], largc, largv)) { |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 154 | fprintf(stderr, "Command failed %s:%d\n", |
| 155 | name, cmdlineno); |
Stephen Hemminger | 7397944 | 2011-10-13 08:38:33 -0700 | [diff] [blame] | 156 | ret = EXIT_FAILURE; |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 157 | if (!force) |
| 158 | break; |
| 159 | } |
| 160 | } |
shemminger | 8ed63ab | 2005-09-21 19:33:17 +0000 | [diff] [blame] | 161 | if (line) |
| 162 | free(line); |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 163 | |
| 164 | rtnl_close(&rth); |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 169 | int main(int argc, char **argv) |
| 170 | { |
| 171 | char *basename; |
Stephen Hemminger | a3aa47a | 2013-07-16 10:04:05 -0700 | [diff] [blame] | 172 | char *batch_file = NULL; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 173 | |
| 174 | basename = strrchr(argv[0], '/'); |
| 175 | if (basename == NULL) |
| 176 | basename = argv[0]; |
| 177 | else |
| 178 | basename++; |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 179 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 180 | while (argc > 1) { |
| 181 | char *opt = argv[1]; |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 182 | |
| 183 | if (strcmp(opt, "--") == 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 184 | argc--; argv++; |
| 185 | break; |
| 186 | } |
| 187 | if (opt[0] != '-') |
| 188 | break; |
| 189 | if (opt[1] == '-') |
| 190 | opt++; |
Ben Greear | 64c7956 | 2010-12-01 11:13:51 -0800 | [diff] [blame] | 191 | if (matches(opt, "-loops") == 0) { |
| 192 | argc--; |
| 193 | argv++; |
| 194 | if (argc <= 1) |
| 195 | usage(); |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 196 | max_flush_loops = atoi(argv[1]); |
| 197 | } else if (matches(opt, "-family") == 0) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 198 | argc--; |
| 199 | argv++; |
| 200 | if (argc <= 1) |
| 201 | usage(); |
Eric W. Biederman | 45c90d1 | 2015-03-15 14:50:03 -0500 | [diff] [blame] | 202 | if (strcmp(argv[1], "help") == 0) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 203 | usage(); |
| 204 | else |
Eric W. Biederman | 45c90d1 | 2015-03-15 14:50:03 -0500 | [diff] [blame] | 205 | preferred_family = read_family(argv[1]); |
| 206 | if (preferred_family == AF_UNSPEC) |
Dan Kenigsberg | f1675d6 | 2012-08-16 02:25:56 +0000 | [diff] [blame] | 207 | invarg("invalid protocol family", argv[1]); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 208 | } else if (strcmp(opt, "-4") == 0) { |
| 209 | preferred_family = AF_INET; |
| 210 | } else if (strcmp(opt, "-6") == 0) { |
| 211 | preferred_family = AF_INET6; |
| 212 | } else if (strcmp(opt, "-0") == 0) { |
| 213 | preferred_family = AF_PACKET; |
| 214 | } else if (strcmp(opt, "-I") == 0) { |
| 215 | preferred_family = AF_IPX; |
| 216 | } else if (strcmp(opt, "-D") == 0) { |
| 217 | preferred_family = AF_DECnet; |
Eric W. Biederman | dacc5d4 | 2015-03-15 14:53:45 -0500 | [diff] [blame] | 218 | } else if (strcmp(opt, "-M") == 0) { |
| 219 | preferred_family = AF_MPLS; |
Stephen Hemminger | 27bca61 | 2012-09-17 15:50:27 -0700 | [diff] [blame] | 220 | } else if (strcmp(opt, "-B") == 0) { |
| 221 | preferred_family = AF_BRIDGE; |
Christian Hesse | b68d983 | 2014-10-31 22:33:13 +0100 | [diff] [blame] | 222 | } else if (matches(opt, "-human") == 0 || |
| 223 | matches(opt, "-human-readable") == 0) { |
| 224 | ++human_readable; |
Stephen Hemminger | 1e264ab | 2014-11-02 12:49:19 -0800 | [diff] [blame] | 225 | } else if (matches(opt, "-iec") == 0) { |
| 226 | ++use_iec; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 227 | } else if (matches(opt, "-stats") == 0 || |
| 228 | matches(opt, "-statistics") == 0) { |
| 229 | ++show_stats; |
Patrick McHardy | 1d93483 | 2007-08-22 10:49:01 -0700 | [diff] [blame] | 230 | } else if (matches(opt, "-details") == 0) { |
| 231 | ++show_details; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 232 | } else if (matches(opt, "-resolve") == 0) { |
| 233 | ++resolve_hosts; |
| 234 | } else if (matches(opt, "-oneline") == 0) { |
| 235 | ++oneline; |
shemminger | 90f9302 | 2005-06-07 21:55:55 +0000 | [diff] [blame] | 236 | } else if (matches(opt, "-timestamp") == 0) { |
| 237 | ++timestamp; |
Vadim Kochan | 79aa79d | 2014-12-23 00:13:58 +0200 | [diff] [blame] | 238 | } else if (matches(opt, "-tshort") == 0) { |
| 239 | ++timestamp; |
| 240 | ++timestamp_short; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 241 | #if 0 |
| 242 | } else if (matches(opt, "-numeric") == 0) { |
| 243 | rtnl_names_numeric++; |
| 244 | #endif |
| 245 | } else if (matches(opt, "-Version") == 0) { |
| 246 | printf("ip utility, iproute2-ss%s\n", SNAPSHOT); |
| 247 | exit(0); |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 248 | } else if (matches(opt, "-force") == 0) { |
| 249 | ++force; |
| 250 | } else if (matches(opt, "-batch") == 0) { |
| 251 | argc--; |
| 252 | argv++; |
| 253 | if (argc <= 1) |
| 254 | usage(); |
| 255 | batch_file = argv[1]; |
Andy Gospodarek | 5d295bb | 2015-08-28 13:45:41 -0400 | [diff] [blame] | 256 | } else if (matches(opt, "-brief") == 0) { |
| 257 | ++brief; |
Patrick McHardy | 7f03191 | 2009-10-28 20:50:48 +0100 | [diff] [blame] | 258 | } else if (matches(opt, "-rcvbuf") == 0) { |
| 259 | unsigned int size; |
| 260 | |
| 261 | argc--; |
| 262 | argv++; |
| 263 | if (argc <= 1) |
| 264 | usage(); |
| 265 | if (get_unsigned(&size, argv[1], 0)) { |
| 266 | fprintf(stderr, "Invalid rcvbuf size '%s'\n", |
| 267 | argv[1]); |
| 268 | exit(-1); |
| 269 | } |
| 270 | rcvbuf = size; |
Mathias Nyman | d7bd2db | 2015-04-28 13:18:21 +0300 | [diff] [blame] | 271 | } else if (matches(opt, "-color") == 0) { |
| 272 | enable_color(); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 273 | } else if (matches(opt, "-help") == 0) { |
| 274 | usage(); |
Vadim Kochan | 52700d4 | 2014-12-24 23:04:09 +0200 | [diff] [blame] | 275 | } else if (matches(opt, "-netns") == 0) { |
| 276 | NEXT_ARG(); |
| 277 | if (netns_switch(argv[1])) |
| 278 | exit(-1); |
Vadim Kochan | b13ba03 | 2015-01-18 16:10:18 +0200 | [diff] [blame] | 279 | } else if (matches(opt, "-all") == 0) { |
| 280 | do_all = true; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 281 | } else { |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 282 | fprintf(stderr, |
| 283 | "Option \"%s\" is unknown, try \"ip -help\".\n", |
| 284 | opt); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 285 | exit(-1); |
| 286 | } |
| 287 | argc--; argv++; |
| 288 | } |
| 289 | |
Stephen Hemminger | ec7aff5 | 2015-07-26 21:46:44 -0700 | [diff] [blame] | 290 | _SL_ = oneline ? "\\" : "\n"; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 291 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 292 | if (batch_file) |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 293 | return batch(batch_file); |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 294 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 295 | if (rtnl_open(&rth, 0) < 0) |
| 296 | exit(1); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 297 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 298 | if (strlen(basename) > 2) |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 299 | return do_cmd(basename+2, argc, argv); |
| 300 | |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 301 | if (argc > 1) |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 302 | return do_cmd(argv[1], argc-1, argv+1); |
| 303 | |
| 304 | rtnl_close(&rth); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 305 | usage(); |
| 306 | } |