From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH 2/3] ip: macvlan: support MACVLAN_FLAG_NOPROMISC flag
Date: Fri, 25 Sep 2015 14:09:50 +0200 [thread overview]
Message-ID: <1443182991-4628-3-git-send-email-phil@nwl.cc> (raw)
In-Reply-To: <1443182991-4628-1-git-send-email-phil@nwl.cc>
This flag is allowed for devices in passthru mode to prevent forcing the
underlying interface into promiscuous mode.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
ip/iplink_macvlan.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/ip/iplink_macvlan.c b/ip/iplink_macvlan.c
index d759f0e..f195e81 100644
--- a/ip/iplink_macvlan.c
+++ b/ip/iplink_macvlan.c
@@ -29,7 +29,7 @@
static void print_explain(struct link_util *lu, FILE *f)
{
fprintf(f,
- "Usage: ... %s mode { private | vepa | bridge | passthru }\n",
+ "Usage: ... %s mode { private | vepa | bridge | passthru [nopromisc] }\n",
lu->id
);
}
@@ -49,9 +49,11 @@ static int mode_arg(const char *arg)
static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n)
{
+ __u32 mode = 0;
+ __u16 flags = 0;
+
while (argc > 0) {
if (matches(*argv, "mode") == 0) {
- __u32 mode = 0;
NEXT_ARG();
if (strcmp(*argv, "private") == 0)
@@ -64,7 +66,8 @@ static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
mode = MACVLAN_MODE_PASSTHRU;
else
return mode_arg(*argv);
- addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
+ } else if (matches(*argv, "nopromisc") == 0) {
+ flags |= MACVLAN_FLAG_NOPROMISC;
} else if (matches(*argv, "help") == 0) {
explain(lu);
return -1;
@@ -76,12 +79,25 @@ static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv,
argc--, argv++;
}
+ if (mode)
+ addattr32(n, 1024, IFLA_MACVLAN_MODE, mode);
+
+ if (flags) {
+ if (flags & MACVLAN_FLAG_NOPROMISC &&
+ mode != MACVLAN_MODE_PASSTHRU) {
+ pfx_err(lu, "nopromisc flag only valid in passthru mode");
+ explain(lu);
+ return -1;
+ }
+ addattr16(n, 1024, IFLA_MACVLAN_FLAGS, flags);
+ }
return 0;
}
static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
__u32 mode;
+ __u16 flags;
if (!tb)
return;
@@ -97,6 +113,14 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
: mode == MACVLAN_MODE_BRIDGE ? "bridge"
: mode == MACVLAN_MODE_PASSTHRU ? "passthru"
: "unknown");
+
+ if (!tb[IFLA_MACVLAN_FLAGS] ||
+ RTA_PAYLOAD(tb[IFLA_MACVLAN_FLAGS]) < sizeof(__u16))
+ return;
+
+ flags = rta_getattr_u16(tb[IFLA_MACVLAN_FLAGS]);
+ if (flags & MACVLAN_FLAG_NOPROMISC)
+ fprintf(f, "nopromisc ");
}
static void macvlan_print_help(struct link_util *lu, int argc, char **argv,
--
2.1.2
next prev parent reply other threads:[~2015-09-25 12:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-25 12:09 [iproute PATCH 0/3] improve MACVLAN/MACVTAP support Phil Sutter
2015-09-25 12:09 ` [iproute PATCH 1/3] ip: link: consolidate macvlan and macvtap Phil Sutter
2015-09-25 12:09 ` Phil Sutter [this message]
2015-09-25 12:09 ` [iproute PATCH 3/3] man: ip-link: document MACVLAN/MACVTAP interface types Phil Sutter
2015-10-12 16:48 ` [iproute PATCH 0/3] improve MACVLAN/MACVTAP support Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443182991-4628-3-git-send-email-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).