]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: permit numeric interface type
authorFlorian Westphal <fw@strlen.de>
Sun, 16 Oct 2016 20:08:25 +0000 (22:08 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 17 Oct 2016 09:52:19 +0000 (11:52 +0200)
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>
src/meta.c

index 87eafeead389761290a3581b87a5451a75883604..34f9ee8e36e24699117a0350cde60c5ebcc019a6 100644 (file)
@@ -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,