From: Elise Lennion <elise.lennion@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] datatype: Replace getaddrinfo() by internal lookup table
Date: Mon, 6 Feb 2017 13:53:40 -0200 [thread overview]
Message-ID: <20170206155339.GA9984@lennorien.com> (raw)
Nftables uses a internal service table to print service names. This
very 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.
Complements the commit:
(ccc5da4: datatype: Replace getnameinfo() by internal lookup table)
Fixes(Bug 1118 - nft: nft -f and nft list ruleset use different sets of
service -> port mappings)
Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
src/datatype.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/datatype.c b/src/datatype.c
index d697a07..f1388dc 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -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,
--
2.7.4
next reply other threads:[~2017-02-06 15:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-06 15:53 Elise Lennion [this message]
2017-02-06 21:13 ` [PATCH nft] datatype: Replace getaddrinfo() by internal lookup table 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=20170206155339.GA9984@lennorien.com \
--to=elise.lennion@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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;
as well as URLs for NNTP newsgroup(s).