summaryrefslogtreecommitdiffhomepage
path: root/networking/libiproute
diff options
context:
space:
mode:
authorJan Luebbe <jluebbe@debian.org>2018-02-20 19:28:02 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-20 19:29:05 +0100
commit79cda9522ad390f1bdb7ba1025b1c81bbd1613e6 (patch)
tree3b990f1e4c9f948e1340221788671130c29fb51a /networking/libiproute
parentb083e8cc538ba6b27e19da541ca6a0f7ceb7daee (diff)
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/libiproute')
-rw-r--r--networking/libiproute/iplink.c24
1 files changed, 23 insertions, 1 deletions
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;
}