From: Shivani Bhardwaj <shivanib134@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] extensions: libxt_connmark: Add translation to nft
Date: Tue, 22 Dec 2015 16:25:47 +0530 [thread overview]
Message-ID: <20151222105547.GA5130@gmail.com> (raw)
Add translation for connmark to nftables.
Examples:
$ sudo iptables-translate -A INPUT -m connmark --mark 1
nft add rule ip filter INPUT ct mark 0x1 counter
$ sudo iptables-translate -A INPUT -m connmark --mark 10/10 -j ACCEPT
nft add rule ip filter INPUT ct mark and 0xa == 0xa counter accept
$ sudo sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 40 -m connmark --mark 0x40
nft add rule ip mangle PREROUTING tcp dport 40 ct mark 0x40 counter
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
---
extensions/libxt_connmark.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/extensions/libxt_connmark.c b/extensions/libxt_connmark.c
index 95477de..1865dcb 100644
--- a/extensions/libxt_connmark.c
+++ b/extensions/libxt_connmark.c
@@ -89,7 +89,8 @@ connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
}
static void
-connmark_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
+connmark_mt_print(const void *ip, const struct xt_entry_match *match,
+ int numeric)
{
const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
@@ -122,6 +123,46 @@ connmark_mt_save(const void *ip, const struct xt_entry_match *match)
print_mark(info->mark, info->mask);
}
+static void
+print_mark_xlate(unsigned int mark, unsigned int mask,
+ struct xt_buf *buf)
+{
+ if (mask != 0xffffffffU)
+ xt_buf_add(buf, " and 0x%x == 0x%x ", mark, mask);
+ else
+ xt_buf_add(buf, " 0x%x ", mark);
+}
+
+static int
+connmark_xlate(const struct xt_entry_match *match,
+ struct xt_buf *buf, int numeric)
+{
+ const struct xt_connmark_info *info = (const void *)match->data;
+
+ if (info->invert)
+ xt_buf_add(buf, " !=");
+
+ xt_buf_add(buf, "ct mark");
+ print_mark_xlate(info->mark, info->mask, buf);
+
+ return 1;
+}
+
+static int
+connmark_mt_xlate(const struct xt_entry_match *match,
+ struct xt_buf *buf, int numeric)
+{
+ const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
+
+ if (info->invert)
+ xt_buf_add(buf, " !=");
+
+ xt_buf_add(buf, "ct mark");
+ print_mark_xlate(info->mark, info->mask, buf);
+
+ return 1;
+}
+
static struct xtables_match connmark_mt_reg[] = {
{
.family = NFPROTO_UNSPEC,
@@ -135,6 +176,7 @@ static struct xtables_match connmark_mt_reg[] = {
.save = connmark_save,
.x6_parse = connmark_parse,
.x6_options = connmark_mt_opts,
+ .xlate = connmark_xlate,
},
{
.version = XTABLES_VERSION,
@@ -148,6 +190,7 @@ static struct xtables_match connmark_mt_reg[] = {
.save = connmark_mt_save,
.x6_parse = connmark_mt_parse,
.x6_options = connmark_mt_opts,
+ .xlate = connmark_mt_xlate,
},
};
--
1.9.1
next reply other threads:[~2015-12-22 10:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-22 10:55 Shivani Bhardwaj [this message]
2015-12-22 16:47 ` [PATCH] extensions: libxt_connmark: Add translation to nft Pablo Neira Ayuso
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=20151222105547.GA5130@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