diff options
author | Jan Luebbe | 2018-02-20 19:28:02 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-02-20 19:29:05 +0100 |
commit | 79cda9522ad390f1bdb7ba1025b1c81bbd1613e6 (patch) | |
tree | 3b990f1e4c9f948e1340221788671130c29fb51a /networking | |
parent | b083e8cc538ba6b27e19da541ca6a0f7ceb7daee (diff) | |
download | busybox-79cda9522ad390f1bdb7ba1025b1c81bbd1613e6.zip busybox-79cda9522ad390f1bdb7ba1025b1c81bbd1613e6.tar.gz |
ip link: support "add TYPE vrf", improve --help
VRF interfaces have a mandatory table parameter, which needs to be
specified using a RTNL attribute.
function old new delta
do_add_or_delete 1150 1254 +104
packed_usage 32444 32546 +102
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 206/0) Total: 206 bytes
Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/ip.c | 57 | ||||
-rw-r--r-- | networking/libiproute/iplink.c | 24 |
2 files changed, 76 insertions, 5 deletions
diff --git a/networking/ip.c b/networking/ip.c index 0bc0edc..665f9bc 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -155,11 +155,60 @@ //usage: //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79 //usage:#define iplink_trivial_usage -//usage: "set IFACE [up|down] [arp on|off] | show [IFACE]" -//usage:#define iplink_full_usage "\n\n" -//usage: "iplink set IFACE [up|down] [arp on|off] [multicast on|off] [promisc on|off]\n" -//usage: " [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n" +//usage: /*Usage:iplink*/"set IFACE [up|down] [arp on|off] [multicast on|off]\n" +//usage: " [promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC]" +// * short help shows only "set" command, long help continues (with just one "\n") +// * and shows all other commands: +//usage:#define iplink_full_usage "\n" +//usage: "iplink add [link IFACE] IFACE [address MAC] type TYPE [ARGS]\n" +//usage: "iplink delete IFACE type TYPE [ARGS]\n" +//usage: " TYPE ARGS := vlan VLANARGS | vrf table NUM\n" +//usage: " VLANARGS := id VLANID [protocol 802.1q|802.1ad] [reorder_hdr on|off]\n" +//usage: " [gvrp on|off] [mvrp on|off] [loose_binding on|off]\n" //usage: "iplink show [IFACE]" +//upstream man ip-link: +//===================== +//ip link add [link DEV] [ name ] NAME +// [ txqueuelen PACKETS ] +// [ address LLADDR ] +// [ broadcast LLADDR ] +// [ mtu MTU ] [index IDX ] +// [ numtxqueues QUEUE_COUNT ] +// [ numrxqueues QUEUE_COUNT ] +// type TYPE [ ARGS ] +// ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ] +// ip link set { DEVICE | dev DEVICE | group DEVGROUP } [ { up | down } ] +// [ arp { on | off } ] +// [ dynamic { on | off } ] +// [ multicast { on | off } ] +// [ allmulticast { on | off } ] +// [ promisc { on | off } ] +// [ trailers { on | off } ] +// [ txqueuelen PACKETS ] +// [ name NEWNAME ] +// [ address LLADDR ] +// [ broadcast LLADDR ] +// [ mtu MTU ] +// [ netns { PID | NAME } ] +// [ link-netnsid ID ] +// [ alias NAME ] +// [ vf NUM [ mac LLADDR ] +// [ vlan VLANID [ qos VLAN-QOS ] ] +// [ rate TXRATE ] +// [ spoofchk { on | off} ] +// [ query_rss { on | off} ] +// [ state { auto | enable | disable} ] ] +// [ trust { on | off} ] ] +// [ master DEVICE ] +// [ nomaster ] +// [ addrgenmode { eui64 | none | stable_secret | random } ] +// [ protodown { on | off } ] +// ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE] +// ip link help [ TYPE ] +//TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap | +// bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | +// gre | gretap | ip6gre | ip6gretap | vti | nlmon | +// bond_slave | ipvlan | geneve | bridge_slave | vrf } //usage: //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79 //usage:#define iproute_trivial_usage diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index f38fba0..3122833 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c @@ -525,6 +525,24 @@ static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) addattr_l(n, size, IFLA_VLAN_FLAGS, &flags, sizeof(flags)); } +static void vrf_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) +{ +/* IFLA_VRF_TABLE is an enum, not a define - + * can't test "defined(IFLA_VRF_TABLE)". + */ +#if !defined(IFLA_VRF_MAX) +# define IFLA_VRF_TABLE 1 +#endif + uint32_t table; + + if (strcmp(*argv, "table") != 0) + invarg_1_to_2(*argv, "type vrf"); + + NEXT_ARG(); + table = get_u32(*argv, "table"); + addattr_l(n, size, IFLA_VRF_TABLE, &table, sizeof(table)); +} + #ifndef NLMSG_TAIL #define NLMSG_TAIL(nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) @@ -563,6 +581,8 @@ static int do_add_or_delete(char **argv, const unsigned rtm) if (rtm == RTM_NEWLINK) req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL; + /* NB: update iplink_full_usage if you extend this code */ + while (*argv) { arg = index_in_substrings(keywords, *argv); if (arg == ARG_type) { @@ -582,7 +602,7 @@ static int do_add_or_delete(char **argv, const unsigned rtm) } else if (arg == ARG_address) { NEXT_ARG(); address_str = *argv; - dbg("address_str:'%s'", name_str); + dbg("address_str:'%s'", address_str); } else { if (arg == ARG_dev) { if (dev_str) @@ -609,6 +629,8 @@ static int do_add_or_delete(char **argv, const unsigned rtm) if (strcmp(type_str, "vlan") == 0) vlan_parse_opt(argv, &req.n, sizeof(req)); + else if (strcmp(type_str, "vrf") == 0) + vrf_parse_opt(argv, &req.n, sizeof(req)); data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data; } |