iplink: implement "set promisc on|off". Closes 4682

function                                             old     new   delta
do_iplink                                           1232    1269     +37
packed_usage                                       31337   31327     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-04-06 16:06:04 +02:00
parent a7386bb35b
commit 2d4823b65b
2 changed files with 13 additions and 22 deletions

View File

@ -154,8 +154,8 @@
//usage:#define iplink_trivial_usage //usage:#define iplink_trivial_usage
//usage: "set IFACE [up|down] [arp on|off] | show [IFACE]" //usage: "set IFACE [up|down] [arp on|off] | show [IFACE]"
//usage:#define iplink_full_usage "\n\n" //usage:#define iplink_full_usage "\n\n"
//usage: "iplink set IFACE [up|down] [arp on|off] [multicast on|off] [mtu MTU]\n" //usage: "iplink set IFACE [up|down] [arp on|off] [multicast on|off] [promisc on|off]\n"
//usage: " [name NAME] [qlen NUM] [address MAC]\n" //usage: " [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n"
//usage: "iplink show [IFACE]" //usage: "iplink show [IFACE]"
//usage: //usage:
//usage:#define iproute_trivial_usage //usage:#define iproute_trivial_usage

View File

@ -210,10 +210,10 @@ static int do_set(char **argv)
/* If you add stuff here, update iplink_full_usage */ /* If you add stuff here, update iplink_full_usage */
static const char keywords[] ALIGN1 = static const char keywords[] ALIGN1 =
"up\0""down\0""name\0""mtu\0""qlen\0""multicast\0" "up\0""down\0""name\0""mtu\0""qlen\0""multicast\0"
"arp\0""address\0" "arp\0""promisc\0""address\0"
"dev\0" /* must be last */; "dev\0" /* must be last */;
enum { ARG_up = 0, ARG_down, ARG_name, ARG_mtu, ARG_qlen, ARG_multicast, enum { ARG_up = 0, ARG_down, ARG_name, ARG_mtu, ARG_qlen, ARG_multicast,
ARG_arp, ARG_addr, ARG_arp, ARG_promisc, ARG_addr,
ARG_dev }; ARG_dev };
enum { PARM_on = 0, PARM_off }; enum { PARM_on = 0, PARM_off };
smalluint key; smalluint key;
@ -237,6 +237,7 @@ static int do_set(char **argv)
duparg("mtu", *argv); duparg("mtu", *argv);
mtu = get_unsigned(*argv, "mtu"); mtu = get_unsigned(*argv, "mtu");
} else if (key == ARG_qlen) { } else if (key == ARG_qlen) {
//TODO: txqueuelen, txqlen are synonyms to qlen
NEXT_ARG(); NEXT_ARG();
if (qlen != -1) if (qlen != -1)
duparg("qlen", *argv); duparg("qlen", *argv);
@ -273,6 +274,14 @@ static int do_set(char **argv)
flags &= ~IFF_NOARP; flags &= ~IFF_NOARP;
else else
flags |= IFF_NOARP; flags |= IFF_NOARP;
} else if (key == ARG_promisc) {
if (param < 0)
die_must_be_on_off("promisc");
mask |= IFF_PROMISC;
if (param == PARM_on)
flags |= IFF_PROMISC;
else
flags &= ~IFF_PROMISC;
} }
} }
@ -285,15 +294,6 @@ static int do_set(char **argv)
if (len < 0) if (len < 0)
return -1; return -1;
addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len); 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) { } else if (strcmp(*argv, "netns") == 0) {
NEXT_ARG(); NEXT_ARG();
if (netns != -1) if (netns != -1)
@ -313,15 +313,6 @@ static int do_set(char **argv)
req->i.ifi_flags &= ~IFF_ALLMULTI; req->i.ifi_flags &= ~IFF_ALLMULTI;
} else } else
return on_off("allmulticast", *argv); 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) { } else if (strcmp(*argv, "trailers") == 0) {
NEXT_ARG(); NEXT_ARG();
req->i.ifi_change |= IFF_NOTRAILERS; req->i.ifi_change |= IFF_NOTRAILERS;