netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shivani Bhardwaj <shivanib134@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] extensions: libxt_connlabel: Add translation to nft
Date: Sun, 6 Mar 2016 03:17:46 +0530	[thread overview]
Message-ID: <20160305214746.GA16464@gmail.com> (raw)

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 <shivanib134@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


             reply	other threads:[~2016-03-05 21:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-05 21:47 Shivani Bhardwaj [this message]
2016-03-06  0:07 ` [PATCH] extensions: libxt_connlabel: Add translation to nft Florian Westphal
2016-03-07 13:05   ` Pablo Neira Ayuso
2016-03-07 13:25     ` Shivani Bhardwaj
2016-03-07 13:30       ` Florian Westphal
2016-03-07 13:33         ` Pablo Neira Ayuso
2016-03-07 13:32       ` Pablo Neira Ayuso
2016-03-07 13:33         ` Shivani Bhardwaj

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=20160305214746.GA16464@gmail.com \
    --to=shivanib134@gmail.com \
    --cc=netfilter-devel@vger.kernel.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).