From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft] meta: permit numeric interface type
Date: Mon, 17 Oct 2016 10:53:37 +0200 [thread overview]
Message-ID: <1476694417-14583-1-git-send-email-fw@strlen.de> (raw)
If we can't translate an interface index back to a name
we just print the number.
This change allows using a number instead of an interface index to
make this symmetric.
If we can't find an interface with the given name check
if its a numeric string and then use it instead.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/meta.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/meta.c b/src/meta.c
index 87eafeead389..34f9ee8e36e2 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -11,6 +11,7 @@
*/
#include <errno.h>
+#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
@@ -166,8 +167,18 @@ static struct error_record *ifindex_type_parse(const struct expr *sym,
int ifindex;
ifindex = nft_if_nametoindex(sym->identifier);
- if (ifindex == 0)
- return error(&sym->location, "Interface does not exist");
+ if (ifindex == 0) {
+ char *end;
+ long res;
+
+ errno = 0;
+ res = strtol(sym->identifier, &end, 10);
+
+ if (res < 0 || res > INT_MAX || *end || errno)
+ return error(&sym->location, "Interface does not exist");
+
+ ifindex = (int)res;
+ }
*res = constant_expr_alloc(&sym->location, sym->dtype,
BYTEORDER_HOST_ENDIAN,
--
2.7.3
next reply other threads:[~2016-10-17 8:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-17 8:53 Florian Westphal [this message]
2016-10-17 9:42 ` [PATCH nft] meta: permit numeric interface type Pablo Neira Ayuso
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=1476694417-14583-1-git-send-email-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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