naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0052-iplink-add-support-for-bonding-netlink.patch

049c96
From c8b98b78222a1eef506d3e3e9e7dc7da9db0984c Mon Sep 17 00:00:00 2001
049c96
From: Phil Sutter <psutter@redhat.com>
049c96
Date: Tue, 23 Feb 2016 18:24:51 +0100
049c96
Subject: [PATCH] iplink: add support for bonding netlink
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1269528
049c96
Upstream Status: iproute2.git commit cc26a8909ff31
049c96
049c96
commit cc26a8909ff31388ca0b3703b08605e116e490bb
049c96
Author: Jiri Pirko <jiri@resnulli.us>
049c96
Date:   Fri Oct 18 17:50:01 2013 +0200
049c96
049c96
    iplink: add support for bonding netlink
049c96
049c96
    Signed-off-by: Jiri Pirko <jiri@resnulli.us>
049c96
---
049c96
 ip/Makefile           |  2 +-
049c96
 ip/iplink.c           |  4 +--
049c96
 ip/iplink_bond.c      | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++
049c96
 man/man8/ip-link.8.in |  4 +++
049c96
 4 files changed, 99 insertions(+), 3 deletions(-)
049c96
 create mode 100644 ip/iplink_bond.c
049c96
049c96
diff --git a/ip/Makefile b/ip/Makefile
049c96
index f377c37..76878fb 100644
049c96
--- a/ip/Makefile
049c96
+++ b/ip/Makefile
049c96
@@ -5,7 +5,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
049c96
     iplink_vlan.o link_veth.o link_gre.o iplink_can.o \
049c96
     iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o link_vti6.o \
049c96
     iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
049c96
-    link_iptnl.o link_gre6.o
049c96
+    link_iptnl.o link_gre6.o iplink_bond.o
049c96
 
049c96
 RTMONOBJ=rtmon.o
049c96
 
049c96
diff --git a/ip/iplink.c b/ip/iplink.c
049c96
index 5a9ed57..3024e99 100644
049c96
--- a/ip/iplink.c
049c96
+++ b/ip/iplink.c
049c96
@@ -90,8 +90,8 @@ void iplink_usage(void)
049c96
 		fprintf(stderr, "       ip link help [ TYPE ]\n");
049c96
 		fprintf(stderr, "\n");
049c96
 		fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
049c96
-		fprintf(stderr, "          can | bridge | ipoib | ip6tnl | ipip | sit | vxlan |\n");
049c96
-		fprintf(stderr, "          gre | gretap | ip6gre | ip6gretap | vti }\n");
049c96
+		fprintf(stderr, "          can | bridge | bond | ipoib | ip6tnl | ipip | sit |\n");
049c96
+		fprintf(stderr, "          vxlan | gre | gretap | ip6gre | ip6gretap | vti }\n");
049c96
 	}
049c96
 	exit(-1);
049c96
 }
049c96
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
049c96
new file mode 100644
049c96
index 0000000..3fb7f4f
049c96
--- /dev/null
049c96
+++ b/ip/iplink_bond.c
049c96
@@ -0,0 +1,92 @@
049c96
+/*
049c96
+ * iplink_bond.c	Bonding device support
049c96
+ *
049c96
+ *              This program is free software; you can redistribute it and/or
049c96
+ *              modify it under the terms of the GNU General Public License
049c96
+ *              as published by the Free Software Foundation; either version
049c96
+ *              2 of the License, or (at your option) any later version.
049c96
+ *
049c96
+ * Authors:     Jiri Pirko <jiri@resnulli.us>
049c96
+ */
049c96
+
049c96
+#include <stdio.h>
049c96
+#include <stdlib.h>
049c96
+#include <string.h>
049c96
+#include <linux/if_link.h>
049c96
+#include <net/if.h>
049c96
+
049c96
+#include "rt_names.h"
049c96
+#include "utils.h"
049c96
+#include "ip_common.h"
049c96
+
049c96
+static void explain(void)
049c96
+{
049c96
+	fprintf(stderr,
049c96
+		"Usage: ... bond [ mode BONDMODE ] [ active_slave SLAVE_DEV ]\n"
049c96
+		"                [ clear_active_slave ]\n"
049c96
+		"\n"
049c96
+		"BONDMODE := 0-6\n"
049c96
+	);
049c96
+}
049c96
+
049c96
+static int bond_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
+			  struct nlmsghdr *n)
049c96
+{
049c96
+	__u8 mode;
049c96
+	unsigned ifindex;
049c96
+
049c96
+	while (argc > 0) {
049c96
+		if (matches(*argv, "mode") == 0) {
049c96
+			NEXT_ARG();
049c96
+			if (get_u8(&mode, *argv, 0)) {
049c96
+				invarg("mode %s is invalid", *argv);
049c96
+				return -1;
049c96
+			}
049c96
+			addattr8(n, 1024, IFLA_BOND_MODE, mode);
049c96
+		} else if (matches(*argv, "active_slave") == 0) {
049c96
+			NEXT_ARG();
049c96
+			ifindex = if_nametoindex(*argv);
049c96
+			if (!ifindex)
049c96
+				return -1;
049c96
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
049c96
+		} else if (matches(*argv, "clear_active_slave") == 0) {
049c96
+			addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0);
049c96
+		} else {
049c96
+			fprintf(stderr, "bond: unknown command \"%s\"?\n", *argv);
049c96
+			explain();
049c96
+			return -1;
049c96
+		}
049c96
+		argc--, argv++;
049c96
+	}
049c96
+
049c96
+	return 0;
049c96
+}
049c96
+
049c96
+static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
049c96
+{
049c96
+	unsigned ifindex;
049c96
+
049c96
+	if (!tb)
049c96
+		return;
049c96
+
049c96
+	if (tb[IFLA_BOND_MODE])
049c96
+		fprintf(f, "mode %u ", rta_getattr_u8(tb[IFLA_BOND_MODE]));
049c96
+
049c96
+	if (tb[IFLA_BOND_ACTIVE_SLAVE] &&
049c96
+	    (ifindex = rta_getattr_u32(tb[IFLA_BOND_ACTIVE_SLAVE]))) {
049c96
+		char buf[IFNAMSIZ];
049c96
+		const char *n = if_indextoname(ifindex, buf);
049c96
+
049c96
+		if (n)
049c96
+			fprintf(f, "active_slave %s ", n);
049c96
+		else
049c96
+			fprintf(f, "active_slave %u ", ifindex);
049c96
+	}
049c96
+}
049c96
+
049c96
+struct link_util bond_link_util = {
049c96
+	.id		= "bond",
049c96
+	.maxattr	= IFLA_BOND_MAX,
049c96
+	.parse_opt	= bond_parse_opt,
049c96
+	.print_opt	= bond_print_opt,
049c96
+};
049c96
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
049c96
index ef90738..d69c930 100644
049c96
--- a/man/man8/ip-link.8.in
049c96
+++ b/man/man8/ip-link.8.in
049c96
@@ -52,6 +52,7 @@ ip-link \- network device configuration
049c96
 .ti -8
049c96
 .IR TYPE " := [ "
049c96
 .BR bridge " | "
049c96
+.BR bond " ]"
049c96
 .BR can " | "
049c96
 .BR dummy " | "
049c96
 .BR ifb " | "
049c96
@@ -160,6 +161,9 @@ Link types:
049c96
 .B bridge
049c96
 - Ethernet Bridge device
049c96
 .sp
049c96
+.B bond
049c96
+- Bonding device
049c96
+.sp
049c96
 .B can
049c96
 - Controller Area Network interface
049c96
 .sp
049c96
-- 
049c96
1.8.3.1
049c96