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                                             -     180    +180
do_iplink                                           1304    1377     +73
.rodata                                           149338  149364     +26
packed_usage                                       32437   32429      -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 279/-8)            Total: 271 bytes

Signed-off-by: Jan Luebbe <jlue...@debian.org>
---
 networking/ip.c                |  2 +-
 networking/libiproute/iplink.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/networking/ip.c b/networking/ip.c
index 0bc0edc57..5aa3e6470 100644
--- a/networking/ip.c
+++ b/networking/ip.c
@@ -158,7 +158,7 @@
 //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:       "       [mtu NUM] [name NAME] [qlen NUM] [address MAC] [master 
IFACE] [nomaster]\n"
 //usage:       "iplink show [IFACE]"
 //usage:
 
//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
index 61b18231d..e0bf21659 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)
+               exit(EXIT_FAILURE);
+}
+
+/* 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;
-- 
2.11.0

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to