|
|
049c96 |
From ecbf839299f6156ebcc159a39b5fcb01b1273e42 Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Fri, 4 Mar 2016 17:46:07 +0100
|
|
|
049c96 |
Subject: [PATCH] ip: link: consolidate macvlan and macvtap
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1013584
|
|
|
049c96 |
Upstream Status: iproute2.git commit 541f1b3e1d101
|
|
|
049c96 |
|
|
|
049c96 |
commit 541f1b3e1d1011718cbef85adb284a72b183c676
|
|
|
049c96 |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
049c96 |
Date: Fri Sep 25 14:09:49 2015 +0200
|
|
|
049c96 |
|
|
|
049c96 |
ip: link: consolidate macvlan and macvtap
|
|
|
049c96 |
|
|
|
049c96 |
After eliminating the minor differences in both files which existed
|
|
|
049c96 |
solely because features/fixes were applied to only one of them and not
|
|
|
049c96 |
the other, the remaining differences were in function naming and error
|
|
|
049c96 |
messages. The latter is addressed by using the 'id' field of struct
|
|
|
049c96 |
link_util.
|
|
|
049c96 |
|
|
|
049c96 |
Fold both files into one in order to share common code and eliminate the
|
|
|
049c96 |
chance of having fixes/enhancements applied to only one of them.
|
|
|
049c96 |
|
|
|
049c96 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
049c96 |
---
|
|
|
049c96 |
ip/Makefile | 2 +-
|
|
|
049c96 |
ip/iplink_macvlan.c | 40 +++++++++++++-------
|
|
|
049c96 |
ip/iplink_macvtap.c | 105 ----------------------------------------------------
|
|
|
049c96 |
3 files changed, 28 insertions(+), 119 deletions(-)
|
|
|
049c96 |
delete mode 100644 ip/iplink_macvtap.c
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/ip/Makefile b/ip/Makefile
|
|
|
049c96 |
index 35065d6..e4f0507 100644
|
|
|
049c96 |
--- a/ip/Makefile
|
|
|
049c96 |
+++ b/ip/Makefile
|
|
|
049c96 |
@@ -3,7 +3,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
|
|
|
049c96 |
ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o iptuntap.o iptoken.o \
|
|
|
049c96 |
ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.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_macvlan.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 |
iplink_bridge.o iplink_bridge_slave.o
|
|
|
049c96 |
diff --git a/ip/iplink_macvlan.c b/ip/iplink_macvlan.c
|
|
|
049c96 |
index e080157..b972d0e 100644
|
|
|
049c96 |
--- a/ip/iplink_macvlan.c
|
|
|
049c96 |
+++ b/ip/iplink_macvlan.c
|
|
|
049c96 |
@@ -1,5 +1,5 @@
|
|
|
049c96 |
/*
|
|
|
049c96 |
- * iplink_vlan.c VLAN device support
|
|
|
049c96 |
+ * iplink_macvlan.c macvlan/macvtap 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 |
@@ -20,22 +20,29 @@
|
|
|
049c96 |
#include "utils.h"
|
|
|
049c96 |
#include "ip_common.h"
|
|
|
049c96 |
|
|
|
049c96 |
-static void print_explain(FILE *f)
|
|
|
049c96 |
+#define pfx_err(lu, ...) { \
|
|
|
049c96 |
+ fprintf(stderr, "%s: ", lu->id); \
|
|
|
049c96 |
+ fprintf(stderr, __VA_ARGS__); \
|
|
|
049c96 |
+ fprintf(stderr, "\n"); \
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static void print_explain(struct link_util *lu, FILE *f)
|
|
|
049c96 |
{
|
|
|
049c96 |
fprintf(f,
|
|
|
049c96 |
- "Usage: ... macvlan mode { private | vepa | bridge | passthru }\n"
|
|
|
049c96 |
+ "Usage: ... %s mode { private | vepa | bridge | passthru }\n",
|
|
|
049c96 |
+ lu->id
|
|
|
049c96 |
);
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
-static void explain(void)
|
|
|
049c96 |
+static void explain(struct link_util *lu)
|
|
|
049c96 |
{
|
|
|
049c96 |
- print_explain(stderr);
|
|
|
049c96 |
+ print_explain(lu, stderr);
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
-static int mode_arg(void)
|
|
|
049c96 |
+static int mode_arg(const char *arg)
|
|
|
049c96 |
{
|
|
|
049c96 |
fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
|
|
|
049c96 |
- "\"vepa\", \"bridge\" or \"passthru\" \n");
|
|
|
049c96 |
+ "\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg);
|
|
|
049c96 |
return -1;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
@@ -56,15 +63,14 @@ static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
049c96 |
else if (strcmp(*argv, "passthru") == 0)
|
|
|
049c96 |
mode = MACVLAN_MODE_PASSTHRU;
|
|
|
049c96 |
else
|
|
|
049c96 |
- return mode_arg();
|
|
|
049c96 |
-
|
|
|
049c96 |
+ return mode_arg(*argv);
|
|
|
049c96 |
addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
|
|
|
049c96 |
} else if (matches(*argv, "help") == 0) {
|
|
|
049c96 |
- explain();
|
|
|
049c96 |
+ explain(lu);
|
|
|
049c96 |
return -1;
|
|
|
049c96 |
} else {
|
|
|
049c96 |
- fprintf(stderr, "macvlan: unknown option \"%s\"?\n", *argv);
|
|
|
049c96 |
- explain();
|
|
|
049c96 |
+ pfx_err(lu, "unknown option \"%s\"?", *argv);
|
|
|
049c96 |
+ explain(lu);
|
|
|
049c96 |
return -1;
|
|
|
049c96 |
}
|
|
|
049c96 |
argc--, argv++;
|
|
|
049c96 |
@@ -96,7 +102,7 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
|
|
|
049c96 |
static void macvlan_print_help(struct link_util *lu, int argc, char **argv,
|
|
|
049c96 |
FILE *f)
|
|
|
049c96 |
{
|
|
|
049c96 |
- print_explain(f);
|
|
|
049c96 |
+ print_explain(lu, f);
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
struct link_util macvlan_link_util = {
|
|
|
049c96 |
@@ -106,3 +112,11 @@ struct link_util macvlan_link_util = {
|
|
|
049c96 |
.print_opt = macvlan_print_opt,
|
|
|
049c96 |
.print_help = macvlan_print_help,
|
|
|
049c96 |
};
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct link_util macvtap_link_util = {
|
|
|
049c96 |
+ .id = "macvtap",
|
|
|
049c96 |
+ .maxattr = IFLA_MACVLAN_MAX,
|
|
|
049c96 |
+ .parse_opt = macvlan_parse_opt,
|
|
|
049c96 |
+ .print_opt = macvlan_print_opt,
|
|
|
049c96 |
+ .print_help = macvlan_print_help,
|
|
|
049c96 |
+};
|
|
|
049c96 |
diff --git a/ip/iplink_macvtap.c b/ip/iplink_macvtap.c
|
|
|
049c96 |
deleted file mode 100644
|
|
|
049c96 |
index 9c2cd74..0000000
|
|
|
049c96 |
--- a/ip/iplink_macvtap.c
|
|
|
049c96 |
+++ /dev/null
|
|
|
049c96 |
@@ -1,105 +0,0 @@
|
|
|
049c96 |
-/*
|
|
|
049c96 |
- * iplink_macvtap.c macvtap 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 |
-
|
|
|
049c96 |
-#include <stdio.h>
|
|
|
049c96 |
-#include <stdlib.h>
|
|
|
049c96 |
-#include <string.h>
|
|
|
049c96 |
-#include <sys/socket.h>
|
|
|
049c96 |
-#include <linux/if_link.h>
|
|
|
049c96 |
-
|
|
|
049c96 |
-#include "rt_names.h"
|
|
|
049c96 |
-#include "utils.h"
|
|
|
049c96 |
-#include "ip_common.h"
|
|
|
049c96 |
-
|
|
|
049c96 |
-static void print_explain(FILE *f)
|
|
|
049c96 |
-{
|
|
|
049c96 |
- fprintf(stderr,
|
|
|
049c96 |
- "Usage: ... macvtap mode { private | vepa | bridge | passthru }\n"
|
|
|
049c96 |
- );
|
|
|
049c96 |
-}
|
|
|
049c96 |
-
|
|
|
049c96 |
-static void explain(void)
|
|
|
049c96 |
-{
|
|
|
049c96 |
- print_explain(stderr);
|
|
|
049c96 |
-}
|
|
|
049c96 |
-
|
|
|
049c96 |
-static int mode_arg(const char *arg)
|
|
|
049c96 |
-{
|
|
|
049c96 |
- fprintf(stderr, "Error: argument of \"mode\" must be \"private\", "
|
|
|
049c96 |
- "\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg);
|
|
|
049c96 |
- return -1;
|
|
|
049c96 |
-}
|
|
|
049c96 |
-
|
|
|
049c96 |
-static int macvtap_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
049c96 |
- struct nlmsghdr *n)
|
|
|
049c96 |
-{
|
|
|
049c96 |
- while (argc > 0) {
|
|
|
049c96 |
- if (matches(*argv, "mode") == 0) {
|
|
|
049c96 |
- __u32 mode = 0;
|
|
|
049c96 |
- NEXT_ARG();
|
|
|
049c96 |
-
|
|
|
049c96 |
- if (strcmp(*argv, "private") == 0)
|
|
|
049c96 |
- mode = MACVLAN_MODE_PRIVATE;
|
|
|
049c96 |
- else if (strcmp(*argv, "vepa") == 0)
|
|
|
049c96 |
- mode = MACVLAN_MODE_VEPA;
|
|
|
049c96 |
- else if (strcmp(*argv, "bridge") == 0)
|
|
|
049c96 |
- mode = MACVLAN_MODE_BRIDGE;
|
|
|
049c96 |
- else if (strcmp(*argv, "passthru") == 0)
|
|
|
049c96 |
- mode = MACVLAN_MODE_PASSTHRU;
|
|
|
049c96 |
- else
|
|
|
049c96 |
- return mode_arg(*argv);
|
|
|
049c96 |
-
|
|
|
049c96 |
- addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
|
|
|
049c96 |
- } else if (matches(*argv, "help") == 0) {
|
|
|
049c96 |
- explain();
|
|
|
049c96 |
- return -1;
|
|
|
049c96 |
- } else {
|
|
|
049c96 |
- fprintf(stderr, "macvtap: unknown command \"%s\"?\n", *argv);
|
|
|
049c96 |
- explain();
|
|
|
049c96 |
- return -1;
|
|
|
049c96 |
- }
|
|
|
049c96 |
- argc--, argv++;
|
|
|
049c96 |
- }
|
|
|
049c96 |
-
|
|
|
049c96 |
- return 0;
|
|
|
049c96 |
-}
|
|
|
049c96 |
-
|
|
|
049c96 |
-static void macvtap_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
|
|
049c96 |
-{
|
|
|
049c96 |
- __u32 mode;
|
|
|
049c96 |
-
|
|
|
049c96 |
- if (!tb)
|
|
|
049c96 |
- return;
|
|
|
049c96 |
-
|
|
|
049c96 |
- if (!tb[IFLA_MACVLAN_MODE] ||
|
|
|
049c96 |
- RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
|
|
|
049c96 |
- return;
|
|
|
049c96 |
-
|
|
|
049c96 |
- mode = rta_getattr_u32(tb[IFLA_VLAN_ID]);
|
|
|
049c96 |
- fprintf(f, " mode %s ",
|
|
|
049c96 |
- mode == MACVLAN_MODE_PRIVATE ? "private"
|
|
|
049c96 |
- : mode == MACVLAN_MODE_VEPA ? "vepa"
|
|
|
049c96 |
- : mode == MACVLAN_MODE_BRIDGE ? "bridge"
|
|
|
049c96 |
- : mode == MACVLAN_MODE_PASSTHRU ? "passthru"
|
|
|
049c96 |
- : "unknown");
|
|
|
049c96 |
-}
|
|
|
049c96 |
-
|
|
|
049c96 |
-static void macvtap_print_help(struct link_util *lu, int argc, char **argv,
|
|
|
049c96 |
- FILE *f)
|
|
|
049c96 |
-{
|
|
|
049c96 |
- print_explain(f);
|
|
|
049c96 |
-}
|
|
|
049c96 |
-
|
|
|
049c96 |
-struct link_util macvtap_link_util = {
|
|
|
049c96 |
- .id = "macvtap",
|
|
|
049c96 |
- .maxattr = IFLA_MACVLAN_MAX,
|
|
|
049c96 |
- .parse_opt = macvtap_parse_opt,
|
|
|
049c96 |
- .print_opt = macvtap_print_opt,
|
|
|
049c96 |
- .print_help = macvtap_print_help,
|
|
|
049c96 |
-};
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|