[patch v3, iproute2 version 3.2.0] Source mode for macvlan interface

STALE5231d

4 messages, 2 authors, 2012-04-25 · open the first message on its own page

[patch v3, iproute2 version 3.2.0] Source mode for macvlan interface

From: Stefan Gula <hidden>
Date: 2012-01-30 13:17:29

From: Stefan Gula <redacted>

Adjusting iproute2 utility to support new macvlan link type mode
called "source". Example of commands that can be applied:
 ip link add link eth0 name macvlan0 type macvlan mode source
 ip link set link macvlan0 type macvlan macaddr add 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr del 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr flush

Signed-off-by: Stefan Gula <redacted>

---

V2 changes: - removed more bogus lines from if_link.h not related to this patch

diff -uprN iproute2-3.2.0/Config iproute2-3.2.0-my/Config
--- iproute2-3.2.0/Config	1970-01-01 00:00:00.000000000 +0000
+++ iproute2-3.2.0-my/Config	2012-01-27 14:31:53.000000000 +0000
@@ -0,0 +1,3 @@
+# Generated config based on /usr/src/iproute2-3.2.0/include
+TC_CONFIG_XT_OLD_H:=y
+IPT_LIB_DIR:=/lib/xtables
diff -uprN iproute2-3.2.0/include/linux/if_link.h iproute2-3.2.0-my/include/linux/if_link.h
--- iproute2-3.2.0/include/linux/if_link.h	2012-01-05 16:34:31.000000000 +0000
+++ iproute2-3.2.0-my/include/linux/if_link.h	2012-01-30 13:15:40.000000000 +0000
@@ -250,6 +250,9 @@ struct ifla_vlan_qos_mapping {
 enum {
 	IFLA_MACVLAN_UNSPEC,
 	IFLA_MACVLAN_MODE,
+	IFLA_MACVLAN_MACADDR_MODE,
+	IFLA_MACVLAN_MACADDR,
+	IFLA_MACVLAN_MACADDR_DATA,
 	__IFLA_MACVLAN_MAX,
 };
 
@@ -260,6 +263,13 @@ enum macvlan_mode {
 	MACVLAN_MODE_VEPA    = 2, /* talk to other ports through ext bridge */
 	MACVLAN_MODE_BRIDGE  = 4, /* talk to bridge ports directly */
 	MACVLAN_MODE_PASSTHRU = 8,/* take over the underlying device */
+	MACVLAN_MODE_SOURCE  = 16,/* use source MAC address list to assign */
+};
+
+enum macvlan_macaddr_mode {
+	MACVLAN_MACADDR_ADD,
+	MACVLAN_MACADDR_DEL,
+	MACVLAN_MACADDR_FLUSH,
 };
 
 /* SR-IOV virtual function management section */
diff -uprN iproute2-3.2.0/ip/iplink_macvlan.c iproute2-3.2.0-my/ip/iplink_macvlan.c
--- iproute2-3.2.0/ip/iplink_macvlan.c	2012-01-05 16:34:31.000000000 +0000
+++ iproute2-3.2.0-my/ip/iplink_macvlan.c	2012-01-30 12:57:19.000000000 +0000
@@ -22,15 +22,16 @@
 
 static void explain(void)
 {
-	fprintf(stderr,
-		"Usage: ... macvlan mode { private | vepa | bridge | passthru }\n"
-	);
+	fprintf(stderr, "Usage: ... macvlan mode MODE MODE_OPTS\n"
+		"MODE: private | vepa | bridge | passthru | source\n"
+		"MODE_OPTS: for mode \"source\":\n"
+		"\tmacaddr { add <macaddr> | del <macaddr> | flush }\n");
 }
 
 static int mode_arg(void)
 {
         fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
-		"\"vepa\", \"bridge\" or \"passthru\" \n");
+		"\"vepa\", \"bridge\", \"passthru\" or \"source\"\n");
         return -1;
 }
 
@@ -50,10 +51,40 @@ static int macvlan_parse_opt(struct link
 				mode = MACVLAN_MODE_BRIDGE;
 			else if (strcmp(*argv, "passthru") == 0)
 				mode = MACVLAN_MODE_PASSTHRU;
+			else if (strcmp(*argv, "source") == 0)
+				mode = MACVLAN_MODE_SOURCE;
 			else
 				return mode_arg();
 
 			addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
+		} else if (matches(*argv, "macaddr") == 0) {
+			int len;
+			__u32 mac_mode = 0;
+			char abuf[32];
+
+			NEXT_ARG();
+
+			if (strcmp(*argv, "add") == 0) {
+				mac_mode = MACVLAN_MACADDR_ADD;
+			} else if (strcmp(*argv, "del") == 0) {
+				mac_mode = MACVLAN_MACADDR_DEL;
+			} else if (strcmp(*argv, "flush") == 0) {
+				mac_mode = MACVLAN_MACADDR_FLUSH;
+			} else {
+				explain();
+				return -1;
+			}
+			addattr32(n, 1024, IFLA_MACVLAN_MACADDR_MODE, mac_mode);
+
+			if (mac_mode != MACVLAN_MACADDR_FLUSH) {
+				NEXT_ARG();
+
+				len = ll_addr_a2n(abuf, sizeof(abuf), *argv);
+				if (len < 0)
+					return -1;
+				addattr_l(n, 1024, IFLA_MACVLAN_MACADDR, abuf,
+					  len);
+			}
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -85,6 +116,7 @@ static void macvlan_print_opt(struct lin
 		: mode == MACVLAN_MODE_VEPA    ? "vepa"
 		: mode == MACVLAN_MODE_BRIDGE  ? "bridge"
 		: mode == MACVLAN_MODE_PASSTHRU  ? "passthru"
+		: mode == MACVLAN_MODE_SOURCE  ? "source"
 		:				 "unknown");
 }
 

Re: [patch v3, iproute2 version 3.2.0] Source mode for macvlan interface

From: Stephen Hemminger <hidden>
Date: 2012-01-30 16:40:06

On Mon, 30 Jan 2012 14:14:00 +0100 (CET)
Stefan Gula [off-list ref] wrote:
From: Stefan Gula <redacted>

Adjusting iproute2 utility to support new macvlan link type mode
called "source". Example of commands that can be applied:
 ip link add link eth0 name macvlan0 type macvlan mode source
 ip link set link macvlan0 type macvlan macaddr add 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr del 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr flush

Signed-off-by: Stefan Gula <redacted>
Documentation update?

Re: [patch v3, iproute2 version 3.2.0] Source mode for macvlan interface

From: Štefan Gula <hidden>
Date: 2012-01-31 07:30:05

2012/1/30 Stephen Hemminger [off-list ref]:
On Mon, 30 Jan 2012 14:14:00 +0100 (CET)
Stefan Gula [off-list ref] wrote:
quoted
From: Stefan Gula <redacted>

Adjusting iproute2 utility to support new macvlan link type mode
called "source". Example of commands that can be applied:
 ip link add link eth0 name macvlan0 type macvlan mode source
 ip link set link macvlan0 type macvlan macaddr add 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr del 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr flush

Signed-off-by: Stefan Gula <redacted>
Documentation update?
Good point... I have checked whole package iproute2 where macvlan or
vepa is mentioned. Especially documentation files. It turns out that
the only other file not changed was man/man8/ip-link.8. But there is
missing documentation even for other modes like "vepa, bridge
,private, passthru"... so where do you suggest adding the
documentation? Help message in the code was already modified - try:
/ip/ip link add type macvlan help

Re: [patch v3, iproute2 version 3.2.0] Source mode for macvlan interface

From: Stephen Hemminger <hidden>
Date: 2012-04-25 20:17:58

On Mon, 30 Jan 2012 14:14:00 +0100 (CET)
Stefan Gula [off-list ref] wrote:
From: Stefan Gula <redacted>

Adjusting iproute2 utility to support new macvlan link type mode
called "source". Example of commands that can be applied:
 ip link add link eth0 name macvlan0 type macvlan mode source
 ip link set link macvlan0 type macvlan macaddr add 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr del 00:11:11:11:11:11
 ip link set link macvlan0 type macvlan macaddr flush

Signed-off-by: Stefan Gula <redacted>
Please resubmit with man page, after the kernel header changes are in
Linus's tree (ie. 3.5 merge window).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help