summaryrefslogtreecommitdiffstats
path: root/iptables/nft.c
diff options
context:
space:
mode:
authorPablo M. Bermudo Garay <pablombg@gmail.com>2016-08-02 16:29:47 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2016-08-09 10:41:14 +0200
commita44bee8c3582cb72868a3b7f703494dd2b24bf7d (patch)
tree2cdfbc1527e110fdb704d75acd9ea46b299fe4bd /iptables/nft.c
parent175a0148eb53289691b757358b84f5c3b31b72ea (diff)
xtables-compat: fix comments listing
ip[6]tables-compat -L was not printing the comments since commit d64ef34a9961 ("iptables-compat: use nft built-in comments support"). This patch solves the issue. Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables/nft.c')
-rw-r--r--iptables/nft.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/iptables/nft.c b/iptables/nft.c
index c81bb0e6..05ba57a3 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1033,6 +1033,38 @@ int add_comment(struct nftnl_rule *r, const char *comment)
return 0;
}
+static int parse_udata_cb(const struct nftnl_udata *attr, void *data)
+{
+ unsigned char *value = nftnl_udata_get(attr);
+ uint8_t type = nftnl_udata_type(attr);
+ uint8_t len = nftnl_udata_len(attr);
+ const struct nftnl_udata **tb = data;
+
+ switch (type) {
+ case UDATA_TYPE_COMMENT:
+ if (value[len - 1] != '\0')
+ return -1;
+ break;
+ default:
+ return 0;
+ }
+ tb[type] = attr;
+ return 0;
+}
+
+char *get_comment(const void *data, uint32_t data_len)
+{
+ const struct nftnl_udata *tb[UDATA_TYPE_MAX + 1] = {};
+
+ if (nftnl_udata_parse(data, data_len, parse_udata_cb, tb) < 0)
+ return NULL;
+
+ if (!tb[UDATA_TYPE_COMMENT])
+ return NULL;
+
+ return nftnl_udata_get(tb[UDATA_TYPE_COMMENT]);
+}
+
void add_compat(struct nftnl_rule *r, uint32_t proto, bool inv)
{
nftnl_rule_set_u32(r, NFTNL_RULE_COMPAT_PROTO, proto);