From 79cda9522ad390f1bdb7ba1025b1c81bbd1613e6 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Tue, 20 Feb 2018 19:28:02 +0100 Subject: 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 Signed-off-by: Denys Vlasenko --- networking/libiproute/iplink.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'networking/libiproute') diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index f38fba055..312283318 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; } -- cgit v1.2.3