Add translation for connlabel to nftables.
Full translation for this match awaits the support for --set option.

Examples:

$ sudo iptables-translate -A INPUT -m connlabel --label eth0-in
nft add rule ip filter INPUT ct label eth0-in counter

$ sudo iptables-translate -A INPUT -m connlabel ! --label eth0-out
nft add rule ip filter INPUT ct label != eth0-out counter

Signed-off-by: Shivani Bhardwaj <shivanib...@gmail.com>
---
 extensions/libxt_connlabel.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/extensions/libxt_connlabel.c b/extensions/libxt_connlabel.c
index 1f83095..c3a96a6 100644
--- a/extensions/libxt_connlabel.c
+++ b/extensions/libxt_connlabel.c
@@ -118,6 +118,28 @@ connlabel_mt_save(const void *ip, const struct 
xt_entry_match *match)
        connlabel_mt_print_op(info, "--");
 }
 
+static int
+connlabel_mt_xlate(const struct xt_entry_match *match,
+                  struct xt_xlate *xl, int numeric)
+{
+       const struct xt_connlabel_mtinfo *info = (const void *)match->data;
+       const char *name = connlabel_get_name(info->bit);
+
+       if (name)
+               xt_xlate_add(xl, "ct label %s%s ",
+                            info->options & XT_CONNLABEL_OP_INVERT ? "!= " : 
"",
+                            name);
+       else
+               xt_xlate_add(xl, "ct label %s%u ",
+                            info->options & XT_CONNLABEL_OP_INVERT ? "!= " : 
"",
+                            info->bit);
+
+       if (info->options & XT_CONNLABEL_OP_SET)
+               return 0;
+
+       return 1;
+}
+
 static struct xtables_match connlabel_mt_reg = {
        .family        = NFPROTO_UNSPEC,
        .name          = "connlabel",
@@ -129,6 +151,7 @@ static struct xtables_match connlabel_mt_reg = {
        .save          = connlabel_mt_save,
        .x6_parse      = connlabel_mt_parse,
        .x6_options    = connlabel_mt_opts,
+       .xlate         = connlabel_mt_xlate,
 };
 
 void _init(void)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to