Commit f59a4c6e authored by Jan Luebbe's avatar Jan Luebbe
Browse files

ffbs: add vrf support

parent a9e0e723
From: Jan Luebbe <jluebbe@lasnet.de>
Date: Wed, 29 Aug 2018 18:44:34 +0200
Subject: kernel: enable VRF support
Signed-off-by: Jan Luebbe <jluebbe@lasnet.de>
diff --git a/target/linux/generic/config-4.9 b/target/linux/generic/config-4.9
index 83abfdc8ff1493c9f5f1e453e23266f658a4e0fb..cfec5f2b328f42b0dd95de345e55632bb18f5438 100644
--- a/target/linux/generic/config-4.9
+++ b/target/linux/generic/config-4.9
@@ -2844,7 +2844,7 @@ CONFIG_NET_IPGRE_BROADCAST=y
# CONFIG_NET_IP_TUNNEL is not set
# CONFIG_NET_KEY is not set
# CONFIG_NET_KEY_MIGRATE is not set
-# CONFIG_NET_L3_MASTER_DEV is not set
+CONFIG_NET_L3_MASTER_DEV=y
# CONFIG_NET_MPLS_GSO is not set
# CONFIG_NET_NCSI is not set
# CONFIG_NET_PACKET_ENGINE is not set
@@ -2945,7 +2945,7 @@ CONFIG_NET_VENDOR_VIA=y
CONFIG_NET_VENDOR_WIZNET=y
CONFIG_NET_VENDOR_XILINX=y
CONFIG_NET_VENDOR_XIRCOM=y
-# CONFIG_NET_VRF is not set
+CONFIG_NET_VRF=y
# CONFIG_NET_XGENE is not set
CONFIG_NEW_LEDS=y
# CONFIG_NFC is not set
From: Jan Luebbe <jluebbe@lasnet.de>
Date: Wed, 29 Aug 2018 20:51:18 +0200
Subject: busybox: add VRF support
Signed-off-by: Jan Luebbe <jluebbe@lasnet.de>
diff --git a/package/utils/busybox/patches/0001-ip-link-support-add-TYPE-vrf-improve-help.patch b/package/utils/busybox/patches/0001-ip-link-support-add-TYPE-vrf-improve-help.patch
new file mode 100644
index 0000000000000000000000000000000000000000..8a79d2deb2c0ee19939645a6890dfd3b297daf2a
--- /dev/null
+++ b/package/utils/busybox/patches/0001-ip-link-support-add-TYPE-vrf-improve-help.patch
@@ -0,0 +1,149 @@
+From 79cda9522ad390f1bdb7ba1025b1c81bbd1613e6 Mon Sep 17 00:00:00 2001
+From: Jan Luebbe <jluebbe@debian.org>
+Date: Tue, 20 Feb 2018 19:28:02 +0100
+Subject: [PATCH 1/2] 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>
+---
+ networking/ip.c | 57 +++++++++++++++++++++++++++++++++++++++---
+ networking/libiproute/iplink.c | 24 +++++++++++++++++-
+ 2 files changed, 76 insertions(+), 5 deletions(-)
+
+diff --git a/networking/ip.c b/networking/ip.c
+index 0bc0edc57..665f9bcce 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 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;
+ }
+--
+2.11.0
+
diff --git a/package/utils/busybox/patches/0002-iplink-implement-support-for-selecting-a-master-inte.patch b/package/utils/busybox/patches/0002-iplink-implement-support-for-selecting-a-master-inte.patch
new file mode 100644
index 0000000000000000000000000000000000000000..ef81c66469b04bee9ffd56b6610843efd25c73e4
--- /dev/null
+++ b/package/utils/busybox/patches/0002-iplink-implement-support-for-selecting-a-master-inte.patch
@@ -0,0 +1,141 @@
+From e789c3bea18181723c4ae7d761ec30926d182cfb Mon Sep 17 00:00:00 2001
+From: Jan Luebbe <jluebbe@debian.org>
+Date: Wed, 14 Feb 2018 14:05:27 +0100
+Subject: [PATCH 2/2] iplink: implement support for selecting a master
+ interface
+
+Attaching an interface to a VRF is done by setting the interface's
+master. Besides VRF, this can also be used for bridges.
+
+function old new delta
+set_master - 142 +142
+do_iplink 1262 1357 +95
+packed_usage 32546 32539 -7
+------------------------------------------------------------------------------
+(add/remove: 1/0 grow/shrink: 1/1 up/down: 237/-7) Total: 230 bytes
+
+Signed-off-by: Jan Luebbe <jluebbe@debian.org>
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+---
+ networking/ip.c | 3 ++-
+ networking/libiproute/iplink.c | 38 ++++++++++++++++++++++++++++++++++++++
+ networking/tcpudp.c | 2 +-
+ 3 files changed, 41 insertions(+), 2 deletions(-)
+
+diff --git a/networking/ip.c b/networking/ip.c
+index 665f9bcce..accf90759 100644
+--- a/networking/ip.c
++++ b/networking/ip.c
+@@ -156,7 +156,8 @@
+ //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
+ //usage:#define iplink_trivial_usage
+ //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]"
++//usage: " [promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n"
++//usage: " [master IFACE | nomaster]\n"
+ // * short help shows only "set" command, long help continues (with just one "\n")
+ // * and shows all other commands:
+ //usage:#define iplink_full_usage "\n"
+diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
+index 312283318..2aa8b683b 100644
+--- a/networking/libiproute/iplink.c
++++ b/networking/libiproute/iplink.c
+@@ -128,6 +128,31 @@ static void set_mtu(char *dev, int mtu)
+ }
+
+ /* Exits on error */
++static void set_master(char *dev, int master)
++{
++ struct rtnl_handle rth;
++ struct {
++ struct nlmsghdr n;
++ struct ifinfomsg i;
++ char buf[1024];
++ } req;
++
++ memset(&req, 0, sizeof(req));
++
++ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
++ req.n.nlmsg_flags = NLM_F_REQUEST;
++ req.n.nlmsg_type = RTM_NEWLINK;
++ req.i.ifi_family = preferred_family;
++
++ xrtnl_open(&rth);
++ req.i.ifi_index = xll_name_to_index(dev);
++ //printf("master %i for %i\n", master, req.i.ifi_index);
++ addattr_l(&req.n, sizeof(req), IFLA_MASTER, &master, 4);
++ if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
++ xfunc_die();
++}
++
++/* Exits on error */
+ static int get_address(char *dev, int *htype)
+ {
+ struct ifreq ifr;
+@@ -200,6 +225,7 @@ static int do_set(char **argv)
+ uint32_t flags = 0;
+ int qlen = -1;
+ int mtu = -1;
++ int master = -1;
+ char *newaddr = NULL;
+ char *newbrd = NULL;
+ struct ifreq ifr0, ifr1;
+@@ -209,9 +235,11 @@ static int do_set(char **argv)
+ static const char keywords[] ALIGN1 =
+ "up\0""down\0""name\0""mtu\0""qlen\0""multicast\0"
+ "arp\0""promisc\0""address\0"
++ "master\0""nomaster\0"
+ "dev\0" /* must be last */;
+ enum { ARG_up = 0, ARG_down, ARG_name, ARG_mtu, ARG_qlen, ARG_multicast,
+ ARG_arp, ARG_promisc, ARG_addr,
++ ARG_master, ARG_nomaster,
+ ARG_dev };
+ enum { PARM_on = 0, PARM_off };
+ smalluint key;
+@@ -243,6 +271,11 @@ static int do_set(char **argv)
+ } else if (key == ARG_addr) {
+ NEXT_ARG();
+ newaddr = *argv;
++ } else if (key == ARG_master) {
++ NEXT_ARG();
++ master = xll_name_to_index(*argv);
++ } else if (key == ARG_nomaster) {
++ master = 0;
+ } else if (key >= ARG_dev) {
+ /* ^^^^^^ ">=" here results in "dev IFACE" treated as default */
+ if (key == ARG_dev) {
+@@ -427,6 +460,9 @@ static int do_set(char **argv)
+ if (mtu != -1) {
+ set_mtu(dev, mtu);
+ }
++ if (master != -1) {
++ set_master(dev, master);
++ }
+ if (mask)
+ do_chflags(dev, flags, mask);
+ return 0;
+@@ -673,6 +709,8 @@ int FAST_FUNC do_iplink(char **argv)
+ {
+ static const char keywords[] ALIGN1 =
+ "add\0""delete\0""set\0""show\0""lst\0""list\0";
++
++ xfunc_error_retval = 2; //TODO: move up to "ip"? Is it the common rule for all "ip" tools?
+ if (*argv) {
+ int key = index_in_substrings(keywords, *argv);
+ if (key < 0) /* invalid argument */
+diff --git a/networking/tcpudp.c b/networking/tcpudp.c
+index d4c69e0f7..2feb63a01 100644
+--- a/networking/tcpudp.c
++++ b/networking/tcpudp.c
+@@ -318,7 +318,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
+ sslser = user;
+ client = 0;
+ if ((getuid() == 0) && !(opts & OPT_u)) {
+- xfunc_exitcode = 100;
++ xfunc_error_retval = 100;
+ bb_error_msg_and_die(bb_msg_you_must_be_root);
+ }
+ if (opts & OPT_u)
+--
+2.11.0
+
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment