From f55ccf9ea1061f8e50065c0cc6b3ed93523f0b97 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Sun, 16 Oct 2016 22:08:25 +0200 Subject: meta: permit numeric interface type 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 Acked-by: Pablo Neira Ayuso --- src/meta.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/meta.c b/src/meta.c index 87eafeea..34f9ee8e 100644 --- a/src/meta.c +++ b/src/meta.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -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, -- cgit v1.2.3