summaryrefslogtreecommitdiff
path: root/networking/libiproute
diff options
context:
space:
mode:
authorDenys Vlasenko2017-04-06 15:55:29 +0200
committerDenys Vlasenko2017-04-06 15:55:29 +0200
commita7386bb35b474987f0e82337b7fe524220336d32 (patch)
tree13df04c6938ddcc20b2e7c2f4749539147d7caa6 /networking/libiproute
parent4f0b540d08f5912b273c427218cc665512b12de5 (diff)
downloadbusybox-a7386bb35b474987f0e82337b7fe524220336d32.zip
busybox-a7386bb35b474987f0e82337b7fe524220336d32.tar.gz
ip link: tidying up
Misplaced comment. --help was wrong: dynamic on|off is not supported. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/libiproute')
-rw-r--r--networking/libiproute/iplink.c309
1 files changed, 144 insertions, 165 deletions
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
index ae3ef0c..f00c402 100644
--- a/networking/libiproute/iplink.c
+++ b/networking/libiproute/iplink.c
@@ -52,6 +52,9 @@ struct ifla_vlan_flags {
# define dbg(...) ((void)0)
#endif
+
+#define str_on_off "on\0""off\0"
+
/* Exits on error */
static int get_ctl_fd(void)
{
@@ -204,12 +207,14 @@ static int do_set(char **argv)
struct ifreq ifr0, ifr1;
char *newname = NULL;
int htype, halen;
+ /* If you add stuff here, update iplink_full_usage */
static const char keywords[] ALIGN1 =
"up\0""down\0""name\0""mtu\0""qlen\0""multicast\0"
- "arp\0""address\0""dev\0";
+ "arp\0""address\0"
+ "dev\0" /* must be last */;
enum { ARG_up = 0, ARG_down, ARG_name, ARG_mtu, ARG_qlen, ARG_multicast,
- ARG_arp, ARG_addr, ARG_dev };
- static const char str_on_off[] ALIGN1 = "on\0""off\0";
+ ARG_arp, ARG_addr,
+ ARG_dev };
enum { PARM_on = 0, PARM_off };
smalluint key;
@@ -240,6 +245,7 @@ static int do_set(char **argv)
NEXT_ARG();
newaddr = *argv;
} else if (key >= ARG_dev) {
+ /* ^^^^^^ ">=" here results in "dev IFACE" treated as default */
if (key == ARG_dev) {
NEXT_ARG();
}
@@ -247,6 +253,7 @@ static int do_set(char **argv)
duparg2("dev", *argv);
dev = *argv;
} else {
+ /* "on|off" options */
int param;
NEXT_ARG();
param = index_in_strings(str_on_off, *argv);
@@ -268,6 +275,140 @@ static int do_set(char **argv)
flags |= IFF_NOARP;
}
}
+
+/* Other keywords recognized by iproute2-3.12.0: */
+#if 0
+ } else if (matches(*argv, "broadcast") == 0 ||
+ strcmp(*argv, "brd") == 0) {
+ NEXT_ARG();
+ len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
+ if (len < 0)
+ return -1;
+ addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len);
+ } else if (matches(*argv, "txqueuelen") == 0 ||
+ strcmp(*argv, "qlen") == 0 ||
+ matches(*argv, "txqlen") == 0) {
+ NEXT_ARG();
+ if (qlen != -1)
+ duparg("txqueuelen", *argv);
+ if (get_integer(&qlen, *argv, 0))
+ invarg_1_to_2(*argv, "txqueuelen");
+ addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4);
+ } else if (strcmp(*argv, "netns") == 0) {
+ NEXT_ARG();
+ if (netns != -1)
+ duparg("netns", *argv);
+ if ((netns = get_netns_fd(*argv)) >= 0)
+ addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4);
+ else if (get_integer(&netns, *argv, 0) == 0)
+ addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
+ else
+ invarg_1_to_2(*argv, "netns");
+ } else if (strcmp(*argv, "allmulticast") == 0) {
+ NEXT_ARG();
+ req->i.ifi_change |= IFF_ALLMULTI;
+ if (strcmp(*argv, "on") == 0) {
+ req->i.ifi_flags |= IFF_ALLMULTI;
+ } else if (strcmp(*argv, "off") == 0) {
+ req->i.ifi_flags &= ~IFF_ALLMULTI;
+ } else
+ return on_off("allmulticast", *argv);
+ } else if (strcmp(*argv, "promisc") == 0) {
+ NEXT_ARG();
+ req->i.ifi_change |= IFF_PROMISC;
+ if (strcmp(*argv, "on") == 0) {
+ req->i.ifi_flags |= IFF_PROMISC;
+ } else if (strcmp(*argv, "off") == 0) {
+ req->i.ifi_flags &= ~IFF_PROMISC;
+ } else
+ return on_off("promisc", *argv);
+ } else if (strcmp(*argv, "trailers") == 0) {
+ NEXT_ARG();
+ req->i.ifi_change |= IFF_NOTRAILERS;
+ if (strcmp(*argv, "off") == 0) {
+ req->i.ifi_flags |= IFF_NOTRAILERS;
+ } else if (strcmp(*argv, "on") == 0) {
+ req->i.ifi_flags &= ~IFF_NOTRAILERS;
+ } else
+ return on_off("trailers", *argv);
+ } else if (strcmp(*argv, "vf") == 0) {
+ struct rtattr *vflist;
+ NEXT_ARG();
+ if (get_integer(&vf, *argv, 0)) {
+ invarg_1_to_2(*argv, "vf");
+ }
+ vflist = addattr_nest(&req->n, sizeof(*req),
+ IFLA_VFINFO_LIST);
+ len = iplink_parse_vf(vf, &argc, &argv, req);
+ if (len < 0)
+ return -1;
+ addattr_nest_end(&req->n, vflist);
+ } else if (matches(*argv, "master") == 0) {
+ int ifindex;
+ NEXT_ARG();
+ ifindex = ll_name_to_index(*argv);
+ if (!ifindex)
+ invarg_1_to_2(*argv, "master");
+ addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
+ &ifindex, 4);
+ } else if (matches(*argv, "nomaster") == 0) {
+ int ifindex = 0;
+ addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
+ &ifindex, 4);
+ } else if (matches(*argv, "dynamic") == 0) {
+ NEXT_ARG();
+ req->i.ifi_change |= IFF_DYNAMIC;
+ if (strcmp(*argv, "on") == 0) {
+ req->i.ifi_flags |= IFF_DYNAMIC;
+ } else if (strcmp(*argv, "off") == 0) {
+ req->i.ifi_flags &= ~IFF_DYNAMIC;
+ } else
+ return on_off("dynamic", *argv);
+ } else if (matches(*argv, "alias") == 0) {
+ NEXT_ARG();
+ addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS,
+ *argv, strlen(*argv));
+ argc--; argv++;
+ break;
+ } else if (strcmp(*argv, "group") == 0) {
+ NEXT_ARG();
+ if (*group != -1)
+ duparg("group", *argv);
+ if (rtnl_group_a2n(group, *argv))
+ invarg_1_to_2(*argv, "group");
+ } else if (strcmp(*argv, "mode") == 0) {
+ int mode;
+ NEXT_ARG();
+ mode = get_link_mode(*argv);
+ if (mode < 0)
+ invarg_1_to_2(*argv, "mode");
+ addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode);
+ } else if (strcmp(*argv, "state") == 0) {
+ int state;
+ NEXT_ARG();
+ state = get_operstate(*argv);
+ if (state < 0)
+ invarg_1_to_2(*argv, "state");
+ addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state);
+ } else if (matches(*argv, "numtxqueues") == 0) {
+ NEXT_ARG();
+ if (numtxqueues != -1)
+ duparg("numtxqueues", *argv);
+ if (get_integer(&numtxqueues, *argv, 0))
+ invarg_1_to_2(*argv, "numtxqueues");
+ addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES,
+ &numtxqueues, 4);
+ } else if (matches(*argv, "numrxqueues") == 0) {
+ NEXT_ARG();
+ if (numrxqueues != -1)
+ duparg("numrxqueues", *argv);
+ if (get_integer(&numrxqueues, *argv, 0))
+ invarg_1_to_2(*argv, "numrxqueues");
+ addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES,
+ &numrxqueues, 4);
+ }
+#endif
+
argv++;
}
@@ -322,10 +463,6 @@ static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size)
"802.1q\0"
"802.1ad\0"
;
- static const char str_on_off[] ALIGN1 =
- "on\0"
- "off\0"
- ;
enum {
ARG_id = 0,
ARG_reorder_hdr,
@@ -520,164 +657,6 @@ static int do_add_or_delete(char **argv, const unsigned rtm)
return 0;
}
-/* Other keywords recognized by iproute2-3.12.0: */
-#if 0
- } else if (matches(*argv, "broadcast") == 0 ||
- strcmp(*argv, "brd") == 0) {
- NEXT_ARG();
- len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
- if (len < 0)
- return -1;
- addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len);
- } else if (matches(*argv, "txqueuelen") == 0 ||
- strcmp(*argv, "qlen") == 0 ||
- matches(*argv, "txqlen") == 0) {
- NEXT_ARG();
- if (qlen != -1)
- duparg("txqueuelen", *argv);
- if (get_integer(&qlen, *argv, 0))
- invarg_1_to_2(*argv, "txqueuelen");
- addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4);
- } else if (strcmp(*argv, "mtu") == 0) {
- NEXT_ARG();
- if (mtu != -1)
- duparg("mtu", *argv);
- if (get_integer(&mtu, *argv, 0))
- invarg_1_to_2(*argv, "mtu");
- addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4);
- } else if (strcmp(*argv, "netns") == 0) {
- NEXT_ARG();
- if (netns != -1)
- duparg("netns", *argv);
- if ((netns = get_netns_fd(*argv)) >= 0)
- addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4);
- else if (get_integer(&netns, *argv, 0) == 0)
- addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
- else
- invarg_1_to_2(*argv, "netns");
- } else if (strcmp(*argv, "multicast") == 0) {
- NEXT_ARG();
- req->i.ifi_change |= IFF_MULTICAST;
- if (strcmp(*argv, "on") == 0) {
- req->i.ifi_flags |= IFF_MULTICAST;
- } else if (strcmp(*argv, "off") == 0) {
- req->i.ifi_flags &= ~IFF_MULTICAST;
- } else
- return on_off("multicast", *argv);
- } else if (strcmp(*argv, "allmulticast") == 0) {
- NEXT_ARG();
- req->i.ifi_change |= IFF_ALLMULTI;
- if (strcmp(*argv, "on") == 0) {
- req->i.ifi_flags |= IFF_ALLMULTI;
- } else if (strcmp(*argv, "off") == 0) {
- req->i.ifi_flags &= ~IFF_ALLMULTI;
- } else
- return on_off("allmulticast", *argv);
- } else if (strcmp(*argv, "promisc") == 0) {
- NEXT_ARG();
- req->i.ifi_change |= IFF_PROMISC;
- if (strcmp(*argv, "on") == 0) {
- req->i.ifi_flags |= IFF_PROMISC;
- } else if (strcmp(*argv, "off") == 0) {
- req->i.ifi_flags &= ~IFF_PROMISC;
- } else
- return on_off("promisc", *argv);
- } else if (strcmp(*argv, "trailers") == 0) {
- NEXT_ARG();
- req->i.ifi_change |= IFF_NOTRAILERS;
- if (strcmp(*argv, "off") == 0) {
- req->i.ifi_flags |= IFF_NOTRAILERS;
- } else if (strcmp(*argv, "on") == 0) {
- req->i.ifi_flags &= ~IFF_NOTRAILERS;
- } else
- return on_off("trailers", *argv);
- } else if (strcmp(*argv, "arp") == 0) {
- NEXT_ARG();
- req->i.ifi_change |= IFF_NOARP;
- if (strcmp(*argv, "on") == 0) {
- req->i.ifi_flags &= ~IFF_NOARP;
- } else if (strcmp(*argv, "off") == 0) {
- req->i.ifi_flags |= IFF_NOARP;
- } else
- return on_off("noarp", *argv);
- } else if (strcmp(*argv, "vf") == 0) {
- struct rtattr *vflist;
- NEXT_ARG();
- if (get_integer(&vf, *argv, 0)) {
- invarg_1_to_2(*argv, "vf");
- }
- vflist = addattr_nest(&req->n, sizeof(*req),
- IFLA_VFINFO_LIST);
- len = iplink_parse_vf(vf, &argc, &argv, req);
- if (len < 0)
- return -1;
- addattr_nest_end(&req->n, vflist);
- } else if (matches(*argv, "master") == 0) {
- int ifindex;
- NEXT_ARG();
- ifindex = ll_name_to_index(*argv);
- if (!ifindex)
- invarg_1_to_2(*argv, "master");
- addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
- &ifindex, 4);
- } else if (matches(*argv, "nomaster") == 0) {
- int ifindex = 0;
- addattr_l(&req->n, sizeof(*req), IFLA_MASTER,
- &ifindex, 4);
- } else if (matches(*argv, "dynamic") == 0) {
- NEXT_ARG();
- req->i.ifi_change |= IFF_DYNAMIC;
- if (strcmp(*argv, "on") == 0) {
- req->i.ifi_flags |= IFF_DYNAMIC;
- } else if (strcmp(*argv, "off") == 0) {
- req->i.ifi_flags &= ~IFF_DYNAMIC;
- } else
- return on_off("dynamic", *argv);
- } else if (matches(*argv, "alias") == 0) {
- NEXT_ARG();
- addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS,
- *argv, strlen(*argv));
- argc--; argv++;
- break;
- } else if (strcmp(*argv, "group") == 0) {
- NEXT_ARG();
- if (*group != -1)
- duparg("group", *argv);
- if (rtnl_group_a2n(group, *argv))
- invarg_1_to_2(*argv, "group");
- } else if (strcmp(*argv, "mode") == 0) {
- int mode;
- NEXT_ARG();
- mode = get_link_mode(*argv);
- if (mode < 0)
- invarg_1_to_2(*argv, "mode");
- addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode);
- } else if (strcmp(*argv, "state") == 0) {
- int state;
- NEXT_ARG();
- state = get_operstate(*argv);
- if (state < 0)
- invarg_1_to_2(*argv, "state");
- addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state);
- } else if (matches(*argv, "numtxqueues") == 0) {
- NEXT_ARG();
- if (numtxqueues != -1)
- duparg("numtxqueues", *argv);
- if (get_integer(&numtxqueues, *argv, 0))
- invarg_1_to_2(*argv, "numtxqueues");
- addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES,
- &numtxqueues, 4);
- } else if (matches(*argv, "numrxqueues") == 0) {
- NEXT_ARG();
- if (numrxqueues != -1)
- duparg("numrxqueues", *argv);
- if (get_integer(&numrxqueues, *argv, 0))
- invarg_1_to_2(*argv, "numrxqueues");
- addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES,
- &numrxqueues, 4);
- }
-#endif
-
/* Return value becomes exitcode. It's okay to not return at all */
int FAST_FUNC do_iplink(char **argv)
{