From: Shyam Saini <mayhs11saini@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org, arturo@debian.org, fw@strlen.de,
Shyam Saini <mayhs11saini@gmail.com>
Subject: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
Date: Wed, 24 May 2017 18:01:51 +0530 [thread overview]
Message-ID: <1495629111-8206-1-git-send-email-mayhs11saini@gmail.com> (raw)
Add translation for cluster to nft
$ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed
0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 ct state {new,established, related, untracked} ct direction original mark set jhash ip saddr mod 2 seed 0xdeadbeef offset 1 counter meta mark set 0xffff
$ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 2 --cluster-local-nodemask 1 --cluster-hash-seed
0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 ct state {new,established, related, untracked} ct direction original mark set jhash ip saddr mod 2 seed 0xdeadbeef offset 1 counter meta mark set 0xffff
--debug=netlink result
__set%d mangle 3
__set%d mangle 0
element 00000008 : 0 [end] element 00000002 : 0 [end]
element 00000004 : 0 [end] element 00000040 : 0 [end]
ip mangle PREROUTING
[ meta load iifname => reg 1 ]
[ cmp eq reg 1 0x31687465 0x00000000 0x00000000 0x00000000 ]
[ ct load state => reg 1 ]
[ lookup reg 1 set __set%d ]
[ ct load direction => reg 1 ]
[ cmp eq reg 1 0x00000000 ]
[ payload load 4b @ network header + 12 => reg 2 ]
[ hash reg 1 = jhash(reg 2, 4, 0xdeadbeef) % mod 2 offset 1 ]
[ meta set mark with reg 1 ]
[ counter pkts 0 bytes 0 ]
[ immediate reg 1 0x0000ffff ]
[ meta set mark with reg 1 ]
Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
---
extensions/libxt_cluster.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/extensions/libxt_cluster.c b/extensions/libxt_cluster.c
index 3adff12..8891f47 100644
--- a/extensions/libxt_cluster.c
+++ b/extensions/libxt_cluster.c
@@ -126,6 +126,17 @@ cluster_save(const void *ip, const struct xt_entry_match *match)
info->total_nodes, info->hash_seed);
}
+static int
+cluster_xlate(struct xt_xlate *xl, const struct xt_entry_match *match, int numeric)
+{
+ char ct_statement[256] = "ct state {new,established, related, untracked} ct direction original";
+ const struct xt_cluster_match_info *info = (void *)match->data;
+ xt_xlate_add(xl, "%s mark set jhash ip saddr mod %u seed 0x%x offset %u",
+ ct_statement, info->total_nodes, info->hash_seed, info->node_mask);
+ return 1;
+
+}
+
static struct xtables_match cluster_mt_reg = {
.family = NFPROTO_UNSPEC,
.name = "cluster",
@@ -138,6 +149,7 @@ static struct xtables_match cluster_mt_reg = {
.x6_parse = cluster_parse,
.x6_fcheck = cluster_check,
.x6_options = cluster_opts,
+ .xlate = cluster_xlate,
};
void _init(void)
--
1.9.1
next reply other threads:[~2017-05-24 12:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 12:31 Shyam Saini [this message]
2017-05-24 15:43 ` [PATCH 1/1] extensions: libxt_cluster: Add translation to nft Florian Westphal
2017-05-25 10:10 ` Shyam Saini
2017-05-24 15:44 ` Pablo Neira Ayuso
2017-05-24 15:46 ` Florian Westphal
2017-05-24 16:05 ` Pablo Neira Ayuso
2017-05-25 10:12 ` Shyam Saini
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=1495629111-8206-1-git-send-email-mayhs11saini@gmail.com \
--to=mayhs11saini@gmail.com \
--cc=arturo@debian.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).