]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
add support for VRF device
authorDavid Ahern <dsa@cumulusnetworks.com>
Thu, 13 Aug 2015 20:59:11 +0000 (14:59 -0600)
committerStephen Hemminger <shemming@brocade.com>
Sun, 23 Aug 2015 17:14:16 +0000 (10:14 -0700)
Allow user to create a vrf device and specify its table binding.
Based on the iplink_vlan implementation.

Signed-off-by: Shrijeet Mukherjee <shm@cumulusnetworks.com>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
ip/Makefile
ip/iplink.c
ip/iplink_vrf.c [new file with mode: 0644]

index 77653ecc5785ec7dfdb2f6b9f11c100530f925f4..d8b38ac2e44bda740eba4a7df74aa682fe9e79c8 100644 (file)
@@ -7,7 +7,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
     iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
     link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o \
     iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o \
-    iplink_geneve.o
+    iplink_geneve.o iplink_vrf.o
 
 RTMONOBJ=rtmon.o
 
index d648c7ba34a7150d37c3b814c048a25c8a2f3f91..8bc9f49763fcc29175630ffc89ac99d3195707a2 100644 (file)
@@ -94,7 +94,7 @@ void iplink_usage(void)
                fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
                fprintf(stderr, "          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |\n");
                fprintf(stderr, "          gre | gretap | ip6gre | ip6gretap | vti | nlmon |\n");
-               fprintf(stderr, "          bond_slave | ipvlan | geneve | bridge_slave }\n");
+               fprintf(stderr, "          bond_slave | ipvlan | geneve | bridge_slave | vrf }\n");
        }
        exit(-1);
 }
diff --git a/ip/iplink_vrf.c b/ip/iplink_vrf.c
new file mode 100644 (file)
index 0000000..913a289
--- /dev/null
@@ -0,0 +1,86 @@
+/* iplink_vrf.c        VRF device support
+ *
+ *              This program is free software; you can redistribute it and/or
+ *              modify it under the terms of the GNU General Public License
+ *              as published by the Free Software Foundation; either version
+ *              2 of the License, or (at your option) any later version.
+ *
+ * Authors:     Shrijeet Mukherjee <shm@cumulusnetworks.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <linux/if_link.h>
+
+#include "rt_names.h"
+#include "utils.h"
+#include "ip_common.h"
+
+static void vrf_explain(FILE *f)
+{
+       fprintf(f, "Usage: ... vrf table TABLEID \n");
+}
+
+static void explain(void)
+{
+       vrf_explain(stderr);
+}
+
+static int table_arg(void)
+{
+       fprintf(stderr,"Error: argument of \"table\" must be 0-32767 and currently unused\n");
+       return -1;
+}
+
+static int vrf_parse_opt(struct link_util *lu, int argc, char **argv,
+                           struct nlmsghdr *n)
+{
+       while (argc > 0) {
+               if (matches(*argv, "table") == 0) {
+                       __u32 table;
+
+                       NEXT_ARG();
+
+                       table = atoi(*argv);
+                       if (table > 32767)
+                               return table_arg();
+                       addattr32(n, 1024, IFLA_VRF_TABLE, table);
+               } else if (matches(*argv, "help") == 0) {
+                       explain();
+                       return -1;
+               } else {
+                       fprintf(stderr, "vrf: unknown option \"%s\"?\n",
+                               *argv);
+                       explain();
+                       return -1;
+               }
+               argc--, argv++;
+       }
+
+       return 0;
+}
+
+static void vrf_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+{
+       if (!tb)
+               return;
+
+       if (tb[IFLA_VRF_TABLE])
+               fprintf(f, "table %u ", rta_getattr_u32(tb[IFLA_VRF_TABLE]));
+}
+
+static void vrf_print_help(struct link_util *lu, int argc, char **argv,
+                             FILE *f)
+{
+       vrf_explain(f);
+}
+
+struct link_util vrf_link_util = {
+       .id             = "vrf",
+       .maxattr        = IFLA_VRF_MAX,
+       .parse_opt      = vrf_parse_opt,
+       .print_opt      = vrf_print_opt,
+       .print_help     = vrf_print_help,
+};