From: Stephen Hemminger <stephen@networkplumber.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netdev@vger.kernel.org
Subject: Re: [iproute PATCH] ip-address: Fix filtering by negated address flags
Date: Wed, 14 Nov 2018 11:29:03 -0800 [thread overview]
Message-ID: <20181114112903.276a6737@shemminger-XPS-13-9360> (raw)
In-Reply-To: <20181114105251.GR6440@orbyte.nwl.cc>
On Wed, 14 Nov 2018 11:52:51 +0100
Phil Sutter <phil@nwl.cc> wrote:
> Hi Stephen,
>
> On Tue, Nov 13, 2018 at 02:47:59PM -0800, Stephen Hemminger wrote:
> > On Tue, 13 Nov 2018 16:12:01 +0100
> > Phil Sutter <phil@nwl.cc> wrote:
> >
> > > + if (arg[0] == '-') {
> > > + inv = true;
> > > + arg++;
> > > + }
> > The inverse logic needs to be moved into the loop handling filter names.
> >
> > Otherwise, you get weirdness like "-dynamic" being accepted and not
> > doing what was expected.
>
> I intentionally moved it there to allow for '-dynamic' and '-primary'
> as well. IMO this is consistent: 'dynamic' is the inverse of 'permanent'
> and 'primary' the inverse of 'secondary' but currently only '-permanent'
> and '-secondary' are allowed. With my patch applied, one may specify not
> only '-permanent' to get the same effect as 'dynamic' but also
> '-dynamic' to get the same effect as 'permanent'. Likewise for the other
> two. Did I miss something?
>
> > Also, please make sure the man page matches the code.
>
> Oh, right. Given the above is fine with you, I will add the man page
> change in v2.
>
> Thanks, Phil
I was thinking something like this which simplifies the logic.
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index cd8cc76a3473..3f1510383071 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1212,37 +1212,34 @@ static void print_ifa_flags(FILE *fp, const struct ifaddrmsg *ifa,
static int get_filter(const char *arg)
{
unsigned int i;
+ bool inv = false;
/* Special cases */
if (strcmp(arg, "dynamic") == 0) {
- filter.flags &= ~IFA_F_PERMANENT;
- filter.flagmask |= IFA_F_PERMANENT;
+ arg = "-permanent";
} else if (strcmp(arg, "primary") == 0) {
- filter.flags &= ~IFA_F_SECONDARY;
- filter.flagmask |= IFA_F_SECONDARY;
- } else if (*arg == '-') {
- for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
- if (strcmp(arg + 1, ifa_flag_names[i].name))
- continue;
+ arg = "-secondary";
+ }
- filter.flags &= ifa_flag_names[i].value;
- filter.flagmask |= ifa_flag_names[i].value;
- return 0;
- }
+ if (*arg == '-') {
+ inv = true;
+ ++arg;
+ }
- return -1;
- } else {
- for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
- if (strcmp(arg, ifa_flag_names[i].name))
- continue;
+ for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+ if (strcmp(arg, ifa_flag_names[i].name))
+ continue;
+
+ if (inv) {
+ filter.flags &= ~ifa_flag_names[i].value;
+ filter.flagmask |= ifa_flag_names[i].value;
+ } else {
filter.flags |= ifa_flag_names[i].value;
filter.flagmask |= ifa_flag_names[i].value;
- return 0;
}
- return -1;
+ return 0;
}
-
- return 0;
+ return -1;
}
static int ifa_label_match_rta(int ifindex, const struct rtattr *rta)
next prev parent reply other threads:[~2018-11-15 5:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-13 15:12 [iproute PATCH] ip-address: Fix filtering by negated address flags Phil Sutter
2018-11-13 22:47 ` Stephen Hemminger
2018-11-14 10:52 ` Phil Sutter
2018-11-14 19:29 ` Stephen Hemminger [this message]
2018-11-15 11:13 ` Phil Sutter
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=20181114112903.276a6737@shemminger-XPS-13-9360 \
--to=stephen@networkplumber.org \
--cc=netdev@vger.kernel.org \
--cc=phil@nwl.cc \
/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).