From c992153402c78d91e8beba791171bced21c62d3f Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 27 Jul 2016 14:34:53 +0200 Subject: ct: allow resolving ct keys at run time ... and remove those keywords we no longer need. Signed-off-by: Florian Westphal Acked-by: Pablo Neira Ayuso --- src/ct.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/ct.c') diff --git a/src/ct.c b/src/ct.c index a6829389..81918764 100644 --- a/src/ct.c +++ b/src/ct.c @@ -306,6 +306,41 @@ struct error_record *ct_dir_parse(const struct location *loc, const char *str, return error(loc, "Could not parse direction %s", str); } +struct error_record *ct_key_parse(const struct location *loc, const char *str, + unsigned int *key) +{ + int ret, len, offset = 0; + const char *sep = ""; + unsigned int i; + char buf[1024]; + size_t size; + + for (i = 0; i < array_size(ct_templates); i++) { + if (!ct_templates[i].token || strcmp(ct_templates[i].token, str)) + continue; + + *key = i; + return NULL; + } + + len = (int)sizeof(buf); + size = sizeof(buf); + + for (i = 0; i < array_size(ct_templates); i++) { + if (!ct_templates[i].token) + continue; + + if (offset) + sep = ", "; + + ret = snprintf(buf+offset, len, "%s%s", sep, ct_templates[i].token); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + assert(offset < (int)sizeof(buf)); + } + + return error(loc, "syntax error, unexpected %s, known keys are %s", str, buf); +} + struct expr *ct_expr_alloc(const struct location *loc, enum nft_ct_keys key, int8_t direction) { -- cgit v1.2.3