diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2021-06-03 00:06:15 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2021-06-07 21:35:26 +0200 |
commit | ba863c4b07df03356e52748032984e5c67fd2675 (patch) | |
tree | ca3551b1588b2a0120e4b19dd18cb2b7369db8ca /iptables/xtables-translate.c | |
parent | 68ed965b35cdc7b55d4ebc0ba37c1ac078ccbafb (diff) |
libxtables: extend xlate infrastructure
This infrastructure extends the existing xlate infrastructure:
- Extensions can define set dependencies through .xlate. The resulting
set definition can be obtained through xt_xlate_set_get().
- Add xl_xlate_set_family() and xl_xlate_get_family() to store/fetch
the family.
The first client of this new xlate API is the connlimit extension,
which is added in a follow up patch.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables/xtables-translate.c')
-rw-r--r-- | iptables/xtables-translate.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/iptables/xtables-translate.c b/iptables/xtables-translate.c index 575fb320..33ba68ec 100644 --- a/iptables/xtables-translate.c +++ b/iptables/xtables-translate.c @@ -155,20 +155,33 @@ static int nft_rule_xlate_add(struct nft_handle *h, bool append) { struct xt_xlate *xl = xt_xlate_alloc(10240); + const char *set; int ret; + xl_xlate_set_family(xl, h->family); + ret = h->ops->xlate(cs, xl); + if (!ret) + goto err_out; + + set = xt_xlate_set_get(xl); + if (set[0]) { + printf("add set %s %s %s\n", family2str[h->family], p->table, + xt_xlate_set_get(xl)); + + if (!cs->restore && p->command != CMD_NONE) + printf("nft "); + } + if (append) { - xt_xlate_add(xl, "add rule %s %s %s ", - family2str[h->family], p->table, p->chain); + printf("add rule %s %s %s ", + family2str[h->family], p->table, p->chain); } else { - xt_xlate_add(xl, "insert rule %s %s %s ", - family2str[h->family], p->table, p->chain); + printf("insert rule %s %s %s ", + family2str[h->family], p->table, p->chain); } + printf("%s\n", xt_xlate_rule_get(xl)); - ret = h->ops->xlate(cs, xl); - if (ret) - printf("%s\n", xt_xlate_get(xl)); - +err_out: xt_xlate_free(xl); return ret; } |