From: Shivani Bhardwaj <shivanib134@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] extensions: libxt_tos: Add translation to nft
Date: Sun, 14 Feb 2016 19:55:00 +0530 [thread overview]
Message-ID: <20160214142500.GA3397@gmail.com> (raw)
Add translation for match tos to nftables.
Examples:
$ sudo iptables-translate -A INPUT -m tos --tos 0x02 -j ACCEPT
nft add rule ip filter INPUT ip tos 0x02 counter accept
$ sudo iptables-translate -A INPUT -m tos --tos 0x02/0x04 -j ACCEPT
nft add rule ip filter INPUT ip tos and 0x02 == 0x04 counter accept
$ sudo iptables-translate -A INPUT -m tos ! --tos 0x02/0x04 -j ACCEPT
nft add rule ip filter INPUT ip tos and 0x02 != 0x04 counter accept
Details:
This patch was sent by Ana, Shivani modified it as per the current
nftables structure, applied it to the latest branch and tested it.
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Ana Rey <anarey@gmail.com>
---
extensions/libxt_tos.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/extensions/libxt_tos.c b/extensions/libxt_tos.c
index 81c096f..577e9cb 100644
--- a/extensions/libxt_tos.c
+++ b/extensions/libxt_tos.c
@@ -121,6 +121,23 @@ static void tos_mt_save(const void *ip, const struct xt_entry_match *match)
printf(" --tos 0x%02x/0x%02x", info->tos_value, info->tos_mask);
}
+static int tos_mt_xlate(const struct xt_entry_match *match,
+ struct xt_xlate *xl, int numeric)
+{
+ const struct xt_tos_match_info *info = (const void *)match->data;
+
+ xt_xlate_add(xl, "ip tos ");
+
+ if (info->tos_mask == 0xff)
+ xt_xlate_add(xl, "%s0x%02x ", info->invert ? "!= " : "",
+ info->tos_value);
+ else
+ xt_xlate_add(xl, "and 0x%02x %s 0x%02x ", info->tos_value,
+ info->invert ? "!=" : "==", info->tos_mask);
+
+ return 1;
+}
+
static struct xtables_match tos_mt_reg[] = {
{
.version = XTABLES_VERSION,
@@ -147,6 +164,7 @@ static struct xtables_match tos_mt_reg[] = {
.save = tos_mt_save,
.x6_parse = tos_mt_parse,
.x6_options = tos_mt_opts,
+ .xlate = tos_mt_xlate,
},
};
--
1.9.1
next reply other threads:[~2016-02-14 14:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-14 14:25 Shivani Bhardwaj [this message]
2016-02-16 11:26 ` [PATCH] extensions: libxt_tos: 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=20160214142500.GA3397@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).