blob: c5ba294aae03b350a4f38d34ab519c4fc629104d [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00002/*
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +00003 * iplink.c "ip link".
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00004 *
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +00005 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00008 */
Eric Andersenab4e19a2003-01-14 08:54:08 +00009#include <net/if.h>
10#include <net/if_packet.h>
11#include <netpacket/packet.h>
Eric Andersenab4e19a2003-01-14 08:54:08 +000012#include <net/ethernet.h>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000013
Denis Vlasenko9a7d38f2007-05-31 22:42:12 +000014#include "ip_common.h" /* #include "libbb.h" is inside */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000015#include "rt_names.h"
16#include "utils.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000017
Denys Vlasenkob276e412010-08-22 10:02:55 +020018#ifndef IFLA_LINKINFO
19# define IFLA_LINKINFO 18
Denys Vlasenkoc71ec702010-08-30 19:20:09 +020020# define IFLA_INFO_KIND 1
Denys Vlasenkob276e412010-08-22 10:02:55 +020021#endif
Denys Vlasenkoc71ec702010-08-30 19:20:09 +020022
Denis Vlasenko540a2a12007-04-07 01:14:45 +000023/* taken from linux/sockios.h */
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +020024#define SIOCSIFNAME 0x8923 /* set interface name */
Eric Andersenab4e19a2003-01-14 08:54:08 +000025
Denis Vlasenko540a2a12007-04-07 01:14:45 +000026/* Exits on error */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000027static int get_ctl_fd(void)
28{
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000029 int fd;
30
31 fd = socket(PF_INET, SOCK_DGRAM, 0);
32 if (fd >= 0)
33 return fd;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000034 fd = socket(PF_PACKET, SOCK_DGRAM, 0);
35 if (fd >= 0)
36 return fd;
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +000037 return xsocket(PF_INET6, SOCK_DGRAM, 0);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000038}
39
Denis Vlasenko540a2a12007-04-07 01:14:45 +000040/* Exits on error */
41static void do_chflags(char *dev, uint32_t flags, uint32_t mask)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000042{
43 struct ifreq ifr;
44 int fd;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000045
Denis Vlasenko360d9662008-12-02 18:18:50 +000046 strncpy_IFNAMSIZ(ifr.ifr_name, dev);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000047 fd = get_ctl_fd();
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000048 xioctl(fd, SIOCGIFFLAGS, &ifr);
Denis Vlasenko540a2a12007-04-07 01:14:45 +000049 if ((ifr.ifr_flags ^ flags) & mask) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000050 ifr.ifr_flags &= ~mask;
Denis Vlasenko540a2a12007-04-07 01:14:45 +000051 ifr.ifr_flags |= mask & flags;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000052 xioctl(fd, SIOCSIFFLAGS, &ifr);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000053 }
54 close(fd);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000055}
56
Denis Vlasenko540a2a12007-04-07 01:14:45 +000057/* Exits on error */
58static void do_changename(char *dev, char *newdev)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000059{
60 struct ifreq ifr;
61 int fd;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000062
Denis Vlasenko360d9662008-12-02 18:18:50 +000063 strncpy_IFNAMSIZ(ifr.ifr_name, dev);
64 strncpy_IFNAMSIZ(ifr.ifr_newname, newdev);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000065 fd = get_ctl_fd();
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000066 xioctl(fd, SIOCSIFNAME, &ifr);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000067 close(fd);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000068}
69
Denis Vlasenko540a2a12007-04-07 01:14:45 +000070/* Exits on error */
71static void set_qlen(char *dev, int qlen)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000072{
73 struct ifreq ifr;
74 int s;
75
76 s = get_ctl_fd();
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000077 memset(&ifr, 0, sizeof(ifr));
Denis Vlasenko360d9662008-12-02 18:18:50 +000078 strncpy_IFNAMSIZ(ifr.ifr_name, dev);
Eric Andersenc7bda1c2004-03-15 08:29:22 +000079 ifr.ifr_qlen = qlen;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000080 xioctl(s, SIOCSIFTXQLEN, &ifr);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000081 close(s);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000082}
83
Denis Vlasenko540a2a12007-04-07 01:14:45 +000084/* Exits on error */
85static void set_mtu(char *dev, int mtu)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000086{
87 struct ifreq ifr;
88 int s;
89
90 s = get_ctl_fd();
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000091 memset(&ifr, 0, sizeof(ifr));
Denis Vlasenko360d9662008-12-02 18:18:50 +000092 strncpy_IFNAMSIZ(ifr.ifr_name, dev);
Eric Andersenc7bda1c2004-03-15 08:29:22 +000093 ifr.ifr_mtu = mtu;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000094 xioctl(s, SIOCSIFMTU, &ifr);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000095 close(s);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000096}
97
Denis Vlasenko540a2a12007-04-07 01:14:45 +000098/* Exits on error */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000099static int get_address(char *dev, int *htype)
100{
101 struct ifreq ifr;
102 struct sockaddr_ll me;
Eric Andersend78aea82006-01-30 18:00:02 +0000103 socklen_t alen;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000104 int s;
105
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000106 s = xsocket(PF_PACKET, SOCK_DGRAM, 0);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000107
108 memset(&ifr, 0, sizeof(ifr));
Denis Vlasenko360d9662008-12-02 18:18:50 +0000109 strncpy_IFNAMSIZ(ifr.ifr_name, dev);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000110 xioctl(s, SIOCGIFINDEX, &ifr);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000111
112 memset(&me, 0, sizeof(me));
113 me.sll_family = AF_PACKET;
114 me.sll_ifindex = ifr.ifr_ifindex;
115 me.sll_protocol = htons(ETH_P_LOOP);
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000116 xbind(s, (struct sockaddr*)&me, sizeof(me));
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000117 alen = sizeof(me);
Denis Vlasenkoa771e7c2009-04-21 23:48:38 +0000118 getsockname(s, (struct sockaddr*)&me, &alen);
119 //never happens:
120 //if (getsockname(s, (struct sockaddr*)&me, &alen) == -1)
121 // bb_perror_msg_and_die("getsockname");
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000122 close(s);
123 *htype = me.sll_hatype;
124 return me.sll_halen;
125}
126
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000127/* Exits on error */
128static void parse_address(char *dev, int hatype, int halen, char *lla, struct ifreq *ifr)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000129{
130 int alen;
131
132 memset(ifr, 0, sizeof(*ifr));
Denis Vlasenko360d9662008-12-02 18:18:50 +0000133 strncpy_IFNAMSIZ(ifr->ifr_name, dev);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000134 ifr->ifr_hwaddr.sa_family = hatype;
Bernhard Reutner-Fischer51a06c02008-05-16 17:19:03 +0000135
136 alen = hatype == 1/*ARPHRD_ETHER*/ ? 14/*ETH_HLEN*/ : 19/*INFINIBAND_HLEN*/;
137 alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), alen, lla);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000138 if (alen < 0)
Bernhard Reutner-Fischer51a06c02008-05-16 17:19:03 +0000139 exit(EXIT_FAILURE);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000140 if (alen != halen) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000141 bb_error_msg_and_die("wrong address (%s) length: expected %d bytes", lla, halen);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000142 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000143}
144
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000145/* Exits on error */
146static void set_address(struct ifreq *ifr, int brd)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000147{
148 int s;
149
150 s = get_ctl_fd();
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000151 if (brd)
152 xioctl(s, SIOCSIFHWBROADCAST, ifr);
153 else
154 xioctl(s, SIOCSIFHWADDR, ifr);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000155 close(s);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000156}
157
158
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000159static void die_must_be_on_off(const char *msg) NORETURN;
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000160static void die_must_be_on_off(const char *msg)
161{
162 bb_error_msg_and_die("argument of \"%s\" must be \"on\" or \"off\"", msg);
163}
164
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000165/* Return value becomes exitcode. It's okay to not return at all */
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000166static int do_set(char **argv)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000167{
168 char *dev = NULL;
Denis Vlasenko98ee06d2006-12-31 18:57:37 +0000169 uint32_t mask = 0;
170 uint32_t flags = 0;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000171 int qlen = -1;
172 int mtu = -1;
173 char *newaddr = NULL;
174 char *newbrd = NULL;
175 struct ifreq ifr0, ifr1;
176 char *newname = NULL;
177 int htype, halen;
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000178 static const char keywords[] ALIGN1 =
Bernhard Reutner-Fischerab0e4122010-05-25 16:57:08 +0200179 "up\0""down\0""name\0""mtu\0""qlen\0""multicast\0"
Denis Vlasenko44d5dce2008-11-01 00:10:51 +0000180 "arp\0""address\0""dev\0";
Bernhard Reutner-Fischerab0e4122010-05-25 16:57:08 +0200181 enum { ARG_up = 0, ARG_down, ARG_name, ARG_mtu, ARG_qlen, ARG_multicast,
Denis Vlasenko44d5dce2008-11-01 00:10:51 +0000182 ARG_arp, ARG_addr, ARG_dev };
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000183 static const char str_on_off[] ALIGN1 = "on\0""off\0";
184 enum { PARM_on = 0, PARM_off };
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000185 smalluint key;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000186
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000187 while (*argv) {
Denis Vlasenko44d5dce2008-11-01 00:10:51 +0000188 /* substring search ensures that e.g. "addr" and "address"
189 * are both accepted */
190 key = index_in_substrings(keywords, *argv);
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000191 if (key == ARG_up) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000192 mask |= IFF_UP;
193 flags |= IFF_UP;
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200194 } else if (key == ARG_down) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000195 mask |= IFF_UP;
196 flags &= ~IFF_UP;
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200197 } else if (key == ARG_name) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000198 NEXT_ARG();
199 newname = *argv;
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200200 } else if (key == ARG_mtu) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000201 NEXT_ARG();
202 if (mtu != -1)
203 duparg("mtu", *argv);
Denis Vlasenko76140a72009-03-05 09:21:57 +0000204 mtu = get_unsigned(*argv, "mtu");
Bernhard Reutner-Fischerab0e4122010-05-25 16:57:08 +0200205 } else if (key == ARG_qlen) {
206 NEXT_ARG();
207 if (qlen != -1)
208 duparg("qlen", *argv);
209 qlen = get_unsigned(*argv, "qlen");
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200210 } else if (key == ARG_addr) {
Rob Landley483027f2005-12-15 05:29:48 +0000211 NEXT_ARG();
212 newaddr = *argv;
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200213 } else if (key >= ARG_dev) {
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000214 if (key == ARG_dev) {
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000215 NEXT_ARG();
216 }
217 if (dev)
218 duparg2("dev", *argv);
219 dev = *argv;
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200220 } else {
221 int param;
222 NEXT_ARG();
223 param = index_in_strings(str_on_off, *argv);
224 if (key == ARG_multicast) {
225 if (param < 0)
226 die_must_be_on_off("multicast");
227 mask |= IFF_MULTICAST;
228 if (param == PARM_on)
229 flags |= IFF_MULTICAST;
230 else
231 flags &= ~IFF_MULTICAST;
232 } else if (key == ARG_arp) {
233 if (param < 0)
234 die_must_be_on_off("arp");
235 mask |= IFF_NOARP;
236 if (param == PARM_on)
237 flags &= ~IFF_NOARP;
238 else
239 flags |= IFF_NOARP;
240 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000241 }
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000242 argv++;
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000243 }
244
245 if (!dev) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000246 bb_error_msg_and_die(bb_msg_requires_arg, "\"dev\"");
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000247 }
248
249 if (newaddr || newbrd) {
250 halen = get_address(dev, &htype);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000251 if (newaddr) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000252 parse_address(dev, htype, halen, newaddr, &ifr0);
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200253 set_address(&ifr0, 0);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000254 }
255 if (newbrd) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000256 parse_address(dev, htype, halen, newbrd, &ifr1);
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200257 set_address(&ifr1, 1);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000258 }
259 }
260
261 if (newname && strcmp(dev, newname)) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000262 do_changename(dev, newname);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000263 dev = newname;
264 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000265 if (qlen != -1) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000266 set_qlen(dev, qlen);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000267 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000268 if (mtu != -1) {
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000269 set_mtu(dev, mtu);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000270 }
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000271 if (mask)
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000272 do_chflags(dev, flags, mask);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000273 return 0;
274}
275
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000276static int ipaddr_list_link(char **argv)
Glenn L McGrath2626ef62002-12-02 01:40:05 +0000277{
278 preferred_family = AF_PACKET;
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000279 return ipaddr_list_or_flush(argv, 0);
Glenn L McGrath2626ef62002-12-02 01:40:05 +0000280}
281
Bernhard Reutner-Fischer6faebfa2010-05-25 10:34:27 +0200282#ifndef NLMSG_TAIL
283#define NLMSG_TAIL(nmsg) \
284 ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
285#endif
286/* Return value becomes exitcode. It's okay to not return at all */
287static int do_change(char **argv, const unsigned rtm)
288{
289 static const char keywords[] ALIGN1 =
290 "link\0""name\0""type\0""dev\0";
291 enum {
292 ARG_link,
293 ARG_name,
294 ARG_type,
295 ARG_dev,
296 };
297 struct rtnl_handle rth;
298 struct {
299 struct nlmsghdr n;
300 struct ifinfomsg i;
301 char buf[1024];
302 } req;
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200303 smalluint arg;
Bernhard Reutner-Fischer6faebfa2010-05-25 10:34:27 +0200304 char *name_str = NULL, *link_str = NULL, *type_str = NULL, *dev_str = NULL;
305
306 memset(&req, 0, sizeof(req));
307
308 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
309 req.n.nlmsg_flags = NLM_F_REQUEST;
310 req.n.nlmsg_type = rtm;
311 req.i.ifi_family = preferred_family;
312 if (rtm == RTM_NEWLINK)
313 req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
314
315 while (*argv) {
316 arg = index_in_substrings(keywords, *argv);
317 if (arg == ARG_link) {
318 NEXT_ARG();
319 link_str = *argv;
320 } else if (arg == ARG_name) {
321 NEXT_ARG();
322 name_str = *argv;
323 } else if (arg == ARG_type) {
324 NEXT_ARG();
325 type_str = *argv;
326 } else {
327 if (arg == ARG_dev) {
328 if (dev_str)
329 duparg(*argv, "dev");
330 NEXT_ARG();
331 }
332 dev_str = *argv;
333 }
334 argv++;
335 }
336 xrtnl_open(&rth);
337 ll_init_map(&rth);
338 if (type_str) {
339 struct rtattr *linkinfo = NLMSG_TAIL(&req.n);
340
341 addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
342 addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type_str,
343 strlen(type_str));
344 linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo;
345 }
346 if (rtm != RTM_NEWLINK) {
347 if (!dev_str)
348 return 1; /* Need a device to delete */
349 req.i.ifi_index = xll_name_to_index(dev_str);
350 } else {
351 if (!name_str)
352 name_str = dev_str;
353 if (link_str) {
354 int idx = xll_name_to_index(link_str);
355 addattr_l(&req.n, sizeof(req), IFLA_LINK, &idx, 4);
356 }
357 }
358 if (name_str) {
359 const size_t name_len = strlen(name_str) + 1;
360 if (name_len < 2 || name_len > IFNAMSIZ)
361 invarg(name_str, "name");
362 addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name_str, name_len);
363 }
364 if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
365 return 2;
366 return 0;
367}
368
Denis Vlasenko540a2a12007-04-07 01:14:45 +0000369/* Return value becomes exitcode. It's okay to not return at all */
Denys Vlasenko2e9b5512010-07-24 23:27:38 +0200370int FAST_FUNC do_iplink(char **argv)
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000371{
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000372 static const char keywords[] ALIGN1 =
Bernhard Reutner-Fischer6faebfa2010-05-25 10:34:27 +0200373 "add\0""delete\0""set\0""show\0""lst\0""list\0";
Bernhard Reutner-Fischerd148e482010-05-25 16:16:28 +0200374 if (*argv) {
375 smalluint key = index_in_substrings(keywords, *argv);
376 if (key > 5) /* invalid argument */
377 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
378 argv++;
379 if (key <= 1) /* add/delete */
380 return do_change(argv, key ? RTM_DELLINK : RTM_NEWLINK);
381 else if (key == 2) /* set */
382 return do_set(argv);
383 }
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000384 /* show, lst, list */
385 return ipaddr_list_link(argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000386}