netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
@ 2017-05-24 12:31 Shyam Saini
  2017-05-24 15:43 ` Florian Westphal
  2017-05-24 15:44 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 7+ messages in thread
From: Shyam Saini @ 2017-05-24 12:31 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, arturo, fw, Shyam Saini

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
  2017-05-24 12:31 [PATCH 1/1] extensions: libxt_cluster: Add translation to nft Shyam Saini
@ 2017-05-24 15:43 ` Florian Westphal
  2017-05-25 10:10   ` Shyam Saini
  2017-05-24 15:44 ` Pablo Neira Ayuso
  1 sibling, 1 reply; 7+ messages in thread
From: Florian Westphal @ 2017-05-24 15:43 UTC (permalink / raw)
  To: Shyam Saini, g; +Cc: netfilter-devel, pablo, arturo, fw

Shyam Saini <mayhs11saini@gmail.com> wrote:
> 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

Can you explain why ct expression is needed in this way?

afaics translation would be (untested):

nft add rule ip mangle PREROUTING iifname eth1 mark set jhash ct saddr mod 2 seed 0xdeadbeef offset 1 counter meta mark set 0xffff fib saddr type multicast meta pkttype set host

we might need to implement "ct master-saddr" to deal with ct->master use
in xt_cluster as well, but we could do that later as a followup.

fib saddr type is needed to not set real mutlicast traffic to unicast
type and only catch l3-unicast-in-l2-multicast.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
  2017-05-24 12:31 [PATCH 1/1] extensions: libxt_cluster: Add translation to nft Shyam Saini
  2017-05-24 15:43 ` Florian Westphal
@ 2017-05-24 15:44 ` Pablo Neira Ayuso
  2017-05-24 15:46   ` Florian Westphal
  2017-05-25 10:12   ` Shyam Saini
  1 sibling, 2 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2017-05-24 15:44 UTC (permalink / raw)
  To: Shyam Saini; +Cc: netfilter-devel, arturo, fw

On Wed, May 24, 2017 at 06:01:51PM +0530, Shyam Saini wrote:
> Add translation for cluster to nft

I think this should be:

        -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef

should be translated to:

        jhash ct original saddr mod 2 seed 0xdeadbeef eq 0

if --cluster-local-node is 2, then:

        jhash ct original saddr mod 2 seed 0xdeadbeef eq 1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Florian Westphal @ 2017-05-24 15:46 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Shyam Saini, netfilter-devel, arturo, fw

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Wed, May 24, 2017 at 06:01:51PM +0530, Shyam Saini wrote:
> > Add translation for cluster to nft
> 
> I think this should be:
> 
>         -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef
> 
> should be translated to:
> 
>         jhash ct original saddr mod 2 seed 0xdeadbeef eq 0
> 
> if --cluster-local-node is 2, then:
> 
>         jhash ct original saddr mod 2 seed 0xdeadbeef eq 1

Looks good.  But I think we need to take care of mangling pkttype as
well, right?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
  2017-05-24 15:46   ` Florian Westphal
@ 2017-05-24 16:05     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2017-05-24 16:05 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Shyam Saini, netfilter-devel, arturo

On Wed, May 24, 2017 at 05:46:15PM +0200, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Wed, May 24, 2017 at 06:01:51PM +0530, Shyam Saini wrote:
> > > Add translation for cluster to nft
> > 
> > I think this should be:
> > 
> >         -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef
> > 
> > should be translated to:
> > 
> >         jhash ct original saddr mod 2 seed 0xdeadbeef eq 0
> > 
> > if --cluster-local-node is 2, then:
> > 
> >         jhash ct original saddr mod 2 seed 0xdeadbeef eq 1
> 
> Looks good.  But I think we need to take care of mangling pkttype as
> well, right?

We should if we want to 1:1 translation, yes.

Actually, if we rely on the nft arp mac address mangling (to use
multicast ethernet address, ie. RFC violation to cheat dummy switch
just in case you need this to get a packet flooded to two ports), we
could just do this upfront in the ruleset, ie.

        ether daddr 01:00:5e:00:01:01 meta set pkttype host

Using the mac address that we set to arp replies, instead of blind
mangling the mac address.

Anyway, yes, something like:

         jhash ct original saddr mod 2 seed 0xdeadbeef eq 0 meta pkttype set host

should be good enough.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
  2017-05-24 15:43 ` Florian Westphal
@ 2017-05-25 10:10   ` Shyam Saini
  0 siblings, 0 replies; 7+ messages in thread
From: Shyam Saini @ 2017-05-25 10:10 UTC (permalink / raw)
  To: Florian Westphal
  Cc: g, netfilter-devel, Pablo Neira Ayuso, Arturo Borrero Gonzalez

>> 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
>
> Can you explain why ct expression is needed in this way?

ct original is to get original direction

After your explanation,
i realised adding "ct state {new,established, related, untracked}"  was mistake.

> afaics translation would be (untested):
>
> nft add rule ip mangle PREROUTING iifname eth1 mark set jhash ct saddr mod 2 seed 0xdeadbeef offset 1 counter meta mark set 0xffff fib saddr type multicast meta pkttype set host
>
> we might need to implement "ct master-saddr" to deal with ct->master use
> in xt_cluster as well, but we could do that later as a followup.
> fib saddr type is needed to not set real mutlicast traffic to unicast
> type and only catch l3-unicast-in-l2-multicast.

Thanks a lot for explanation.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] extensions: libxt_cluster: Add translation to nft
  2017-05-24 15:44 ` Pablo Neira Ayuso
  2017-05-24 15:46   ` Florian Westphal
@ 2017-05-25 10:12   ` Shyam Saini
  1 sibling, 0 replies; 7+ messages in thread
From: Shyam Saini @ 2017-05-25 10:12 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: netfilter-devel, Arturo Borrero Gonzalez, Florian Westphal

On Wed, May 24, 2017 at 9:14 PM, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Wed, May 24, 2017 at 06:01:51PM +0530, Shyam Saini wrote:
>> Add translation for cluster to nft
>
> I think this should be:
>
>         -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef
>
> should be translated to:
>
>         jhash ct original saddr mod 2 seed 0xdeadbeef eq 0
>
> if --cluster-local-node is 2, then:
>
>         jhash ct original saddr mod 2 seed 0xdeadbeef eq 1

Thanks for correcting me.

I will send the version 2 of this patch

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-25 10:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24 12:31 [PATCH 1/1] extensions: libxt_cluster: Add translation to nft Shyam Saini
2017-05-24 15:43 ` 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

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).