|
|
049c96 |
From 6ec8ce797ff664a31494a1b9693465f1c545fb91 Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Wed, 24 Feb 2016 10:48:07 +0100
|
|
|
049c96 |
Subject: [PATCH] add bridge_slave device support
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1270759
|
|
|
049c96 |
Upstream Status: iproute2.git commit 8c39db391d21a
|
|
|
049c96 |
Conflicts: Context conflict due to missing HSR device support.
|
|
|
049c96 |
|
|
|
049c96 |
commit 8c39db391d21ad118e9f2fd6d35f097dea01cdf4
|
|
|
049c96 |
Author: Jiri Pirko <jiri@resnulli.us>
|
|
|
049c96 |
Date: Sun Sep 28 16:31:04 2014 -0700
|
|
|
049c96 |
|
|
|
049c96 |
add bridge_slave device support
|
|
|
049c96 |
|
|
|
049c96 |
Note this depends on "iproute2: allow to change slave options via
|
|
|
049c96 |
type_slave"
|
|
|
049c96 |
---
|
|
|
049c96 |
ip/Makefile | 3 +-
|
|
|
049c96 |
ip/iplink_bridge_slave.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
049c96 |
2 files changed, 183 insertions(+), 1 deletion(-)
|
|
|
049c96 |
create mode 100644 ip/iplink_bridge_slave.c
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/ip/Makefile b/ip/Makefile
|
|
|
049c96 |
index 080b079..8d4f128 100644
|
|
|
049c96 |
--- a/ip/Makefile
|
|
|
049c96 |
+++ b/ip/Makefile
|
|
|
049c96 |
@@ -5,7 +5,8 @@ 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 iplink_bond.o iplink_bond_slave.o
|
|
|
049c96 |
+ link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o \
|
|
|
049c96 |
+ iplink_bridge_slave.o
|
|
|
049c96 |
|
|
|
049c96 |
RTMONOBJ=rtmon.o
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..a285185
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/ip/iplink_bridge_slave.c
|
|
|
049c96 |
@@ -0,0 +1,181 @@
|
|
|
049c96 |
+/*
|
|
|
049c96 |
+ * iplink_bridge_slave.c Bridge slave 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 <sys/socket.h>
|
|
|
049c96 |
+#include <netinet/in.h>
|
|
|
049c96 |
+#include <linux/if_link.h>
|
|
|
049c96 |
+#include <linux/if_bridge.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: ... bridge_slave [ state STATE ] [ priority PRIO ] [cost COST ]\n"
|
|
|
049c96 |
+ " [ guard {on | off} ]\n"
|
|
|
049c96 |
+ " [ hairpin {on | off} ] \n"
|
|
|
049c96 |
+ " [ fastleave {on | off} ]\n"
|
|
|
049c96 |
+ " [ root_block {on | off} ]\n"
|
|
|
049c96 |
+ " [ learning {on | off} ]\n"
|
|
|
049c96 |
+ " [ flood {on | off} ]\n"
|
|
|
049c96 |
+ );
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static const char *port_states[] = {
|
|
|
049c96 |
+ [BR_STATE_DISABLED] = "disabled",
|
|
|
049c96 |
+ [BR_STATE_LISTENING] = "listening",
|
|
|
049c96 |
+ [BR_STATE_LEARNING] = "learning",
|
|
|
049c96 |
+ [BR_STATE_FORWARDING] = "forwarding",
|
|
|
049c96 |
+ [BR_STATE_BLOCKING] = "blocking",
|
|
|
049c96 |
+};
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void print_portstate(FILE *f, __u8 state)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (state <= BR_STATE_BLOCKING)
|
|
|
049c96 |
+ fprintf(f, "state %s ", port_states[state]);
|
|
|
049c96 |
+ else
|
|
|
049c96 |
+ fprintf(f, "state (%d) ", state);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void print_onoff(FILE *f, char *flag, __u8 val)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ fprintf(f, "%s %s ", flag, val ? "on" : "off");
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
|
|
|
049c96 |
+ struct rtattr *tb[])
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ if (!tb)
|
|
|
049c96 |
+ return;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_STATE])
|
|
|
049c96 |
+ print_portstate(f, rta_getattr_u8(tb[IFLA_BRPORT_STATE]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_PRIORITY])
|
|
|
049c96 |
+ fprintf(f, "priority %d ",
|
|
|
049c96 |
+ rta_getattr_u16(tb[IFLA_BRPORT_PRIORITY]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_COST])
|
|
|
049c96 |
+ fprintf(f, "cost %d ",
|
|
|
049c96 |
+ rta_getattr_u32(tb[IFLA_BRPORT_COST]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_MODE])
|
|
|
049c96 |
+ print_onoff(f, "hairpin",
|
|
|
049c96 |
+ rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_GUARD])
|
|
|
049c96 |
+ print_onoff(f, "guard",
|
|
|
049c96 |
+ rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_PROTECT])
|
|
|
049c96 |
+ print_onoff(f, "root_block",
|
|
|
049c96 |
+ rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_FAST_LEAVE])
|
|
|
049c96 |
+ print_onoff(f, "fastleave",
|
|
|
049c96 |
+ rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_LEARNING])
|
|
|
049c96 |
+ print_onoff(f, "learning",
|
|
|
049c96 |
+ rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (tb[IFLA_BRPORT_UNICAST_FLOOD])
|
|
|
049c96 |
+ print_onoff(f, "flood",
|
|
|
049c96 |
+ rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void bridge_slave_parse_on_off(char *arg_name, char *arg_val,
|
|
|
049c96 |
+ struct nlmsghdr *n, int type)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ __u8 val;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (strcmp(arg_val, "on") == 0)
|
|
|
049c96 |
+ val = 1;
|
|
|
049c96 |
+ else if (strcmp(arg_val, "off") == 0)
|
|
|
049c96 |
+ val = 0;
|
|
|
049c96 |
+ else
|
|
|
049c96 |
+ invarg("should be \"on\" or \"off\"", arg_name);
|
|
|
049c96 |
+
|
|
|
049c96 |
+ addattr8(n, 1024, type, val);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
049c96 |
+ struct nlmsghdr *n)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ __u8 state;
|
|
|
049c96 |
+ __u16 priority;
|
|
|
049c96 |
+ __u32 cost;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ while (argc > 0) {
|
|
|
049c96 |
+ if (matches(*argv, "state") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ if (get_u8(&state, *argv, 0))
|
|
|
049c96 |
+ invarg("state is invalid", *argv);
|
|
|
049c96 |
+ addattr8(n, 1024, IFLA_BRPORT_STATE, state);
|
|
|
049c96 |
+ } else if (matches(*argv, "priority") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ if (get_u16(&priority, *argv, 0))
|
|
|
049c96 |
+ invarg("priority is invalid", *argv);
|
|
|
049c96 |
+ addattr16(n, 1024, IFLA_BRPORT_PRIORITY, priority);
|
|
|
049c96 |
+ } else if (matches(*argv, "cost") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ if (get_u32(&cost, *argv, 0))
|
|
|
049c96 |
+ invarg("cost is invalid", *argv);
|
|
|
049c96 |
+ addattr32(n, 1024, IFLA_BRPORT_COST, cost);
|
|
|
049c96 |
+ } else if (matches(*argv, "hairpin") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ bridge_slave_parse_on_off("hairpin", *argv, n,
|
|
|
049c96 |
+ IFLA_BRPORT_MODE);
|
|
|
049c96 |
+ } else if (matches(*argv, "guard") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ bridge_slave_parse_on_off("guard", *argv, n,
|
|
|
049c96 |
+ IFLA_BRPORT_GUARD);
|
|
|
049c96 |
+ } else if (matches(*argv, "root_block") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ bridge_slave_parse_on_off("root_block", *argv, n,
|
|
|
049c96 |
+ IFLA_BRPORT_PROTECT);
|
|
|
049c96 |
+ } else if (matches(*argv, "fastleave") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ bridge_slave_parse_on_off("fastleave", *argv, n,
|
|
|
049c96 |
+ IFLA_BRPORT_FAST_LEAVE);
|
|
|
049c96 |
+ } else if (matches(*argv, "learning") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ bridge_slave_parse_on_off("learning", *argv, n,
|
|
|
049c96 |
+ IFLA_BRPORT_LEARNING);
|
|
|
049c96 |
+ } else if (matches(*argv, "flood") == 0) {
|
|
|
049c96 |
+ NEXT_ARG();
|
|
|
049c96 |
+ bridge_slave_parse_on_off("flood", *argv, n,
|
|
|
049c96 |
+ IFLA_BRPORT_UNICAST_FLOOD);
|
|
|
049c96 |
+ } else if (matches(*argv, "help") == 0) {
|
|
|
049c96 |
+ explain();
|
|
|
049c96 |
+ return -1;
|
|
|
049c96 |
+ } else {
|
|
|
049c96 |
+ fprintf(stderr, "bridge_slave: unknown option \"%s\"?\n",
|
|
|
049c96 |
+ *argv);
|
|
|
049c96 |
+ explain();
|
|
|
049c96 |
+ return -1;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ argc--, argv++;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct link_util bridge_slave_link_util = {
|
|
|
049c96 |
+ .id = "bridge",
|
|
|
049c96 |
+ .maxattr = IFLA_BRPORT_MAX,
|
|
|
049c96 |
+ .print_opt = bridge_slave_print_opt,
|
|
|
049c96 |
+ .parse_opt = bridge_slave_parse_opt,
|
|
|
049c96 |
+ .slave = true,
|
|
|
049c96 |
+};
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|