* [Iptables Patch V3] extensions: libxt_cluster: Add translation to nft
@ 2018-01-15 5:59 Shyam Saini
2018-01-16 0:59 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Shyam Saini @ 2018-01-15 5:59 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, Shyam Saini
Add translation for cluster to nft
$ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
--cluster-total-nodes 7 --cluster-local-node 5 --cluster-hash-seed
0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
mod 7 seed 0xdeadbeef eq 5 meta pkttype set host counter meta mark set
0xffff
$ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
--cluster-total-nodes 7 --cluster-local-nodemask 5 --cluster-hash-seed
0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
mod 7 seed 0xdeadbeef eq { 0, 2 } meta pkttype set host counter meta
mark set 0xffff
Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
---
extensions/libxt_cluster.c | 52 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/extensions/libxt_cluster.c b/extensions/libxt_cluster.c
index 3adff12..800e3ae 100644
--- a/extensions/libxt_cluster.c
+++ b/extensions/libxt_cluster.c
@@ -71,7 +71,6 @@ static void cluster_check(struct xt_fcheck_call *cb)
{
const struct xt_cluster_match_info *info = cb->data;
unsigned int test;
-
test = F_CL_TOTAL_NODES | F_CL_LOCAL_NODE | F_CL_HASH_SEED;
if ((cb->xflags & test) == test) {
if (info->node_mask >= (1ULL << info->total_nodes))
@@ -126,6 +125,56 @@ 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_xlate_mt_params *params)
+{
+ int node, shift_value = 1, comma_needed = 0;
+ uint32_t temp_node_mask, node_id = 0, needs_set = 0;
+ const struct xt_cluster_match_info *info = params->match->data;
+ const char jhash_st[28] = "jhash ct original saddr mod";
+ const char pkttype_st[22] = "meta pkttype set host";
+
+ if (!(info->node_mask & (info->node_mask - 1))) {
+ if (info->node_mask <= 2)
+ xt_xlate_add(xl, "%s %u seed 0x%08x eq %u %s", jhash_st,
+ info->total_nodes, info->hash_seed,
+ info->node_mask, pkttype_st);
+ else {
+ temp_node_mask = info->node_mask;
+ while (1) {
+ temp_node_mask = temp_node_mask >> shift_value;
+ node_id++;
+ if (temp_node_mask == 0)
+ break;
+ }
+ xt_xlate_add(xl, "%s %u seed 0x%08x eq %u %s", jhash_st,
+ info->total_nodes, info->hash_seed,
+ node_id, pkttype_st);
+ }
+ } else {
+ xt_xlate_add(xl, "%s %u seed 0x%08x eq ", jhash_st,
+ info->total_nodes, info->hash_seed);
+ for (node = 0; node < 32; node++) {
+ if (info->node_mask & (1 << node)) {
+ if (needs_set == 0) {
+ xt_xlate_add(xl, "{ ");
+ needs_set = 1;
+ }
+
+ if (comma_needed)
+ xt_xlate_add(xl, ", ");
+ xt_xlate_add(xl, "%u", node);
+ comma_needed++;
+ }
+ }
+ if (needs_set)
+ xt_xlate_add(xl, " }");
+ xt_xlate_add(xl, " %s", pkttype_st);
+ }
+
+ return 1;
+}
+
static struct xtables_match cluster_mt_reg = {
.family = NFPROTO_UNSPEC,
.name = "cluster",
@@ -138,6 +187,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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Iptables Patch V3] extensions: libxt_cluster: Add translation to nft
2018-01-15 5:59 [Iptables Patch V3] extensions: libxt_cluster: Add translation to nft Shyam Saini
@ 2018-01-16 0:59 ` Pablo Neira Ayuso
2018-01-16 5:52 ` Shyam Saini
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2018-01-16 0:59 UTC (permalink / raw)
To: Shyam Saini; +Cc: netfilter-devel
Hi Shyam,
On Mon, Jan 15, 2018 at 11:29:28AM +0530, Shyam Saini wrote:
> Add translation for cluster to nft
>
> $ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
> --cluster-total-nodes 7 --cluster-local-node 5 --cluster-hash-seed
> 0xdeadbeef -j MARK --set-mark 0xffff
>
> nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
> mod 7 seed 0xdeadbeef eq 5 meta pkttype set host counter meta mark set
> 0xffff
>
> $ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
> --cluster-total-nodes 7 --cluster-local-nodemask 5 --cluster-hash-seed
> 0xdeadbeef -j MARK --set-mark 0xffff
>
> nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
> mod 7 seed 0xdeadbeef eq { 0, 2 } meta pkttype set host counter meta
> mark set 0xffff
Looks good, applied, thanks!
Would you also send us a test for this?
Have a look at extensions/*.txlate
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Iptables Patch V3] extensions: libxt_cluster: Add translation to nft
2018-01-16 0:59 ` Pablo Neira Ayuso
@ 2018-01-16 5:52 ` Shyam Saini
0 siblings, 0 replies; 3+ messages in thread
From: Shyam Saini @ 2018-01-16 5:52 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Netfilter Development Mailing list
> Hi Shyam,
Hi Pablo,
> On Mon, Jan 15, 2018 at 11:29:28AM +0530, Shyam Saini wrote:
>> Add translation for cluster to nft
>>
>> $ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
>> --cluster-total-nodes 7 --cluster-local-node 5 --cluster-hash-seed
>> 0xdeadbeef -j MARK --set-mark 0xffff
>>
>> nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
>> mod 7 seed 0xdeadbeef eq 5 meta pkttype set host counter meta mark set
>> 0xffff
>>
>> $ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
>> --cluster-total-nodes 7 --cluster-local-nodemask 5 --cluster-hash-seed
>> 0xdeadbeef -j MARK --set-mark 0xffff
>>
>> nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
>> mod 7 seed 0xdeadbeef eq { 0, 2 } meta pkttype set host counter meta
>> mark set 0xffff
>
> Looks good, applied, thanks!
>
> Would you also send us a test for this?
>
> Have a look at extensions/*.txlate
>
> Thanks.
I will send the test for this.
Thanks,
Shyam
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-16 5:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-15 5:59 [Iptables Patch V3] extensions: libxt_cluster: Add translation to nft Shyam Saini
2018-01-16 0:59 ` Pablo Neira Ayuso
2018-01-16 5:52 ` Shyam Saini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.