]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: Replace getaddrinfo() by internal lookup table
authorElise Lennion <elise.lennion@gmail.com>
Mon, 6 Feb 2017 15:53:40 +0000 (13:53 -0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 6 Feb 2017 21:14:23 +0000 (22:14 +0100)
Nftables uses a internal service table to print service names. This
table should be used when parsing new rules, to avoid conflicts between
nft service table and the local /etc/services, when loading an exported
ruleset.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1118
Fixes: ccc5da4 ("datatype: Replace getnameinfo() by internal lookup table")
Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/datatype.c

index d697a075c5c92cc9238533f2d29435db7e9614d0..f1388dc52d968a461116f391784bccfe01e1a96b 100644 (file)
@@ -597,10 +597,9 @@ static void inet_service_type_print(const struct expr *expr)
 static struct error_record *inet_service_type_parse(const struct expr *sym,
                                                    struct expr **res)
 {
-       struct addrinfo *ai;
+       const struct symbolic_constant *s;
        uint16_t port;
        uintmax_t i;
-       int err;
        char *end;
 
        errno = 0;
@@ -611,13 +610,16 @@ static struct error_record *inet_service_type_parse(const struct expr *sym,
 
                port = htons(i);
        } else {
-               err = getaddrinfo(NULL, sym->identifier, NULL, &ai);
-               if (err != 0)
-                       return error(&sym->location, "Could not resolve service: %s",
-                                    gai_strerror(err));
+               for (s = inet_service_tbl.symbols; s->identifier != NULL; s++) {
+                       if (!strcmp(sym->identifier, s->identifier))
+                               break;
+               }
 
-               port = ((struct sockaddr_in *)ai->ai_addr)->sin_port;
-               freeaddrinfo(ai);
+               if (s->identifier == NULL)
+                       return error(&sym->location, "Could not resolve service: "
+                                    "Servname not found in nft services list");
+
+               port = s->value;
        }
 
        *res = constant_expr_alloc(&sym->location, &inet_service_type,