* [PATCH nft] meta: permit numeric interface type
@ 2016-10-17 8:53 Florian Westphal
2016-10-17 9:42 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2016-10-17 8:53 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH nft] meta: permit numeric interface type
2016-10-17 8:53 [PATCH nft] meta: permit numeric interface type Florian Westphal
@ 2016-10-17 9:42 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2016-10-17 9:42 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Mon, Oct 17, 2016 at 10:53:37AM +0200, Florian Westphal wrote:
> 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>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-17 9:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-17 8:53 [PATCH nft] meta: permit numeric interface type Florian Westphal
2016-10-17 9:42 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.