netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Ipv6 address in concatenation
@ 2020-02-27 16:21 Serguei Bezverkhi (sbezverk)
  2020-02-27 17:17 ` Phil Sutter
  2020-02-27 19:42 ` Florian Westphal
  0 siblings, 2 replies; 6+ messages in thread
From: Serguei Bezverkhi (sbezverk) @ 2020-02-27 16:21 UTC (permalink / raw)
  To: Phil Sutter, Florian Westphal; +Cc: netfilter-devel

Hello,

I started testing  nfproxy in ipv6 enabled kubernetes cluster and it seems ipv6 address cannot be a part of concatenation expression. Is there a known issue or it is me doing something incorrect?
From my side the code is the same, I just change ip4_addr to ip6_addr when I build sets.

        map no-endpoints {
                type inet_proto . ipv6_addr . inet_service : verdict
        }

        map do-mark-masq {
                type inet_proto . ipv6_addr . inet_service : verdict
        }

        map cluster-ip {
                type inet_proto . ipv6_addr . inet_service : verdict
        }

Thank you
Serguei


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

* Re: Ipv6 address in concatenation
  2020-02-27 16:21 Ipv6 address in concatenation Serguei Bezverkhi (sbezverk)
@ 2020-02-27 17:17 ` Phil Sutter
  2020-02-27 19:42 ` Florian Westphal
  1 sibling, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2020-02-27 17:17 UTC (permalink / raw)
  To: Serguei Bezverkhi (sbezverk); +Cc: Florian Westphal, netfilter-devel

Hi,

On Thu, Feb 27, 2020 at 04:21:40PM +0000, Serguei Bezverkhi (sbezverk) wrote:
> I started testing  nfproxy in ipv6 enabled kubernetes cluster and it seems ipv6 address cannot be a part of concatenation expression. Is there a known issue or it is me doing something incorrect?
> From my side the code is the same, I just change ip4_addr to ip6_addr when I build sets.
> 
>         map no-endpoints {
>                 type inet_proto . ipv6_addr . inet_service : verdict
>         }
> 
>         map do-mark-masq {
>                 type inet_proto . ipv6_addr . inet_service : verdict
>         }
> 
>         map cluster-ip {
>                 type inet_proto . ipv6_addr . inet_service : verdict
>         }

Works fine for me. Wrong table family?

Cheers, Phil

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

* Re: Ipv6 address in concatenation
  2020-02-27 16:21 Ipv6 address in concatenation Serguei Bezverkhi (sbezverk)
  2020-02-27 17:17 ` Phil Sutter
@ 2020-02-27 19:42 ` Florian Westphal
  2020-02-27 19:43   ` Florian Westphal
  2020-02-27 21:25   ` Serguei Bezverkhi (sbezverk)
  1 sibling, 2 replies; 6+ messages in thread
From: Florian Westphal @ 2020-02-27 19:42 UTC (permalink / raw)
  To: Serguei Bezverkhi (sbezverk)
  Cc: Phil Sutter, Florian Westphal, netfilter-devel

Serguei Bezverkhi (sbezverk) <sbezverk@cisco.com> wrote:
> Hello,
> 
> I started testing  nfproxy in ipv6 enabled kubernetes cluster and it seems ipv6 address cannot be a part of concatenation expression. Is there a known issue or it is me doing something incorrect?
> From my side the code is the same, I just change ip4_addr to ip6_addr when I build sets.

types are irrelvant for the kernel.  They are ONLY used by the nft tool
so it knows how to format output.

I suspect you need to fix up the generated payload expressions
for ipv6.  Essentially, in the ipv6 case, you have a concatenation

ipv4_addr . ipv4_addr . ip4_addr . ipv4_addr . inet_service

(ipv6 address needs 4 32-bit registers)

i.e., you need to use a different destination register when you store
the tcp/udp port, else you will clobber a part of the ipv6 address.


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

* Re: Ipv6 address in concatenation
  2020-02-27 19:42 ` Florian Westphal
@ 2020-02-27 19:43   ` Florian Westphal
  2020-02-27 21:25   ` Serguei Bezverkhi (sbezverk)
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2020-02-27 19:43 UTC (permalink / raw)
  To: Florian Westphal
  Cc: Serguei Bezverkhi (sbezverk), Phil Sutter, netfilter-devel

Florian Westphal <fw@strlen.de> wrote:
> Serguei Bezverkhi (sbezverk) <sbezverk@cisco.com> wrote:
> > Hello,
> > 
> > I started testing  nfproxy in ipv6 enabled kubernetes cluster and it seems ipv6 address cannot be a part of concatenation expression. Is there a known issue or it is me doing something incorrect?
> > From my side the code is the same, I just change ip4_addr to ip6_addr when I build sets.
> 
> types are irrelvant for the kernel.  They are ONLY used by the nft tool
> so it knows how to format output.
> 
> I suspect you need to fix up the generated payload expressions
> for ipv6.  Essentially, in the ipv6 case, you have a concatenation
> 
> ipv4_addr . ipv4_addr . ip4_addr . ipv4_addr . inet_service
> 
> (ipv6 address needs 4 32-bit registers)
> 
> i.e., you need to use a different destination register when you store
> the tcp/udp port, else you will clobber a part of the ipv6 address.

Addendum: you can check with

nft --debug=netlink list ruleset

to make sure the registers get populated as expected by lookup
expression.

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

* Re: Ipv6 address in concatenation
  2020-02-27 19:42 ` Florian Westphal
  2020-02-27 19:43   ` Florian Westphal
@ 2020-02-27 21:25   ` Serguei Bezverkhi (sbezverk)
  2020-02-27 21:45     ` Florian Westphal
  1 sibling, 1 reply; 6+ messages in thread
From: Serguei Bezverkhi (sbezverk) @ 2020-02-27 21:25 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Phil Sutter, netfilter-devel

Ok, I figured out the map issue, it was a length of the key in bits, damn copy/paste (

Appreciate if somebody could comment about the following:

sudo nft --debug=netlink insert rule ip6 kube-nfproxy-v6 k8s-nat-services ip6 nexthdr . ip6 daddr . th dport vmap @cluster-ip-set
ip6 kube-nfproxy-v6 k8s-nat-services 
  [ payload load 1b @ network header + 6 => reg 1 ]
  [ payload load 16b @ network header + 24 => reg 9 ].       < -- Is it loading reg 9 4-bytes, reg 10 4 bytes etc until reg 12? Or because the data 16 bytes long it has to skip 3 more register?
  [ payload load 2b @ transport header + 2 => reg 13 ]
  [ lookup reg 1 set cluster-ip-set dreg 0 ]

I am just trying to figure out how to calculate next register to use.    If there is algorithm for both ipv4 and ipv6 that would be awesome to know.

Thank you
Serguei

On 2020-02-27, 2:42 PM, "Florian Westphal" <fw@strlen.de> wrote:

    Serguei Bezverkhi (sbezverk) <sbezverk@cisco.com> wrote:
    > Hello,
    > 
    > I started testing  nfproxy in ipv6 enabled kubernetes cluster and it seems ipv6 address cannot be a part of concatenation expression. Is there a known issue or it is me doing something incorrect?
    > From my side the code is the same, I just change ip4_addr to ip6_addr when I build sets.
    
    types are irrelvant for the kernel.  They are ONLY used by the nft tool
    so it knows how to format output.
    
    I suspect you need to fix up the generated payload expressions
    for ipv6.  Essentially, in the ipv6 case, you have a concatenation
    
    ipv4_addr . ipv4_addr . ip4_addr . ipv4_addr . inet_service
    
    (ipv6 address needs 4 32-bit registers)
    
    i.e., you need to use a different destination register when you store
    the tcp/udp port, else you will clobber a part of the ipv6 address.
    
    


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

* Re: Ipv6 address in concatenation
  2020-02-27 21:25   ` Serguei Bezverkhi (sbezverk)
@ 2020-02-27 21:45     ` Florian Westphal
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2020-02-27 21:45 UTC (permalink / raw)
  To: Serguei Bezverkhi (sbezverk)
  Cc: Florian Westphal, Phil Sutter, netfilter-devel

Serguei Bezverkhi (sbezverk) <sbezverk@cisco.com> wrote:
> Ok, I figured out the map issue, it was a length of the key in bits, damn copy/paste (
> 
> Appreciate if somebody could comment about the following:
> 
> sudo nft --debug=netlink insert rule ip6 kube-nfproxy-v6 k8s-nat-services ip6 nexthdr . ip6 daddr . th dport vmap @cluster-ip-set
> ip6 kube-nfproxy-v6 k8s-nat-services 
>   [ payload load 1b @ network header + 6 => reg 1 ]
>   [ payload load 16b @ network header + 24 => reg 9 ].       < -- Is it loading reg 9 4-bytes, reg 10 4 bytes etc until reg 12? Or because the data 16 bytes long it has to skip 3 more register?
>   [ payload load 2b @ transport header + 2 => reg 13 ]

The 'registers' are adjacent in memory, so loading 16 bytes to reg9
will also store data to 10, 11 and 12.

In case there are not enough next registers kernel will reject the
transaction.

>   [ lookup reg 1 set cluster-ip-set dreg 0 ]
> 
> I am just trying to figure out how to calculate next register to use.    If there is algorithm for both ipv4 and ipv6 that would be awesome to know.

See netlink_gen_concat() in src/netlink_linearize.c in nftables.

Its basically enough to take the start register and then add the
length, rounded up to 4 (register is always 4 byte).

So for the above you need 1 + 1 * 4 + 1, i.e. 6 registers,
then pass the first/start register to the lookup expression.

The lookup expression takes the number of 'next registers' it
needs to look at from the set key length.


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

end of thread, other threads:[~2020-02-27 21:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 16:21 Ipv6 address in concatenation Serguei Bezverkhi (sbezverk)
2020-02-27 17:17 ` Phil Sutter
2020-02-27 19:42 ` Florian Westphal
2020-02-27 19:43   ` Florian Westphal
2020-02-27 21:25   ` Serguei Bezverkhi (sbezverk)
2020-02-27 21:45     ` Florian Westphal

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