Skip to contentSkip to conversation

proper ICMPv6 syntax for specific daddr

DISCUSSION Tom 3 participants 6 messages Sep 7, 2022

lore
Share & tools
lore

Tom

author
#0 lore raw

I can successfully enable ping for IPv6 using this rule:

nft add rule ip6 filter input ip6 nexthdr icmpv6 counter limit rate 5/second accept

I have one physical ethernet card which is assigned five IPv6 addresses. What I want to do is enable it for only 2 of 5 IPv6 addresses, like so:

nft add rule ip6 filter input ip6 daddr xxxx:43:a:83::5 ip6 nexthdr icmpv6 counter limit rate 5/second accept nft add rule ip6 filter input ip6 daddr xxxx:43:a:83::6 ip6 nexthdr icmpv6 counter limit rate 5/second accept

...but what happens is that the first IPv6 will work, but not the second. If I reverse the order, sometimes the second rule still works but now the first doesn't. I've tried using sets like so:

nft add rule ip6 filter input ip6 daddr @trusted ip6 nexthdr icmpv6 counter limit rate 5/second accept nft add rule ip6 filter input ip6 daddr @admin ip6 nexthdr icmpv6 counter limit rate 5/second accept

... with the same result: the second rule is ignored. What am I doing wrong? Is there something about ICMP and multiple IP addresses

on one interface that I'm not aware of? How do I write multiple rules that each enable one daddr?

#1 lore raw
Quoted 9 lines · Tom

I can successfully enable ping for IPv6 using this rule:

nft add rule ip6 filter input ip6 nexthdr icmpv6 counter limit rate 5/second accept

I have one physical ethernet card which is assigned five IPv6 addresses. What I want to do is enable it for only 2 of 5 IPv6 addresses, like so:

nft add rule ip6 filter input ip6 daddr xxxx:43:a:83::5 ip6 nexthdr icmpv6 counter limit rate 5/second accept nft add rule ip6 filter input ip6 daddr xxxx:43:a:83::6 ip6 nexthdr icmpv6 counter limit rate 5/second accept

Please, don't use "ip6 nexthdr", this strictly means "check for the IPv6 nexthdr field of the IPv6 header", which is not what you might need. See:

https://wiki.nftables.org/wiki-nftables/index.php/Matching_packet_headers#Matching_IPv6_headers

Instead, use "meta l4proto" which already parses the IPv6 extension headers up to the layer 4 header.

Quoted 5 lines

...but what happens is that the first IPv6 will work, but not the second. If I reverse the order, sometimes the second rule still works but now the first doesn't. I've tried using sets like so:

nft add rule ip6 filter input ip6 daddr @trusted ip6 nexthdr icmpv6 counter limit rate 5/second accept nft add rule ip6 filter input ip6 daddr @admin ip6 nexthdr icmpv6 counter limit rate 5/second accept

OK, this is using sets, but still looking like iptables+ipset.

Better use concatenations and sets:

table ip6 x {
        set y {
                typeof ip6 daddr . meta l4proto
                limit rate 5/second
                elements = { aaaa:43:a:83::5 . icmpv6 limit rate 5/second,
                             aaaa:43:a:83::6 . icmpv6 limit rate 5/second }
        }

        chain m {
                type filter hook prerouting priority filter; policy drop;
                ip6 daddr . meta l4proto @y accept
        }
}

Probably, nft -o/--optimize might offer more of these transformations in the future.

#3 lore raw
In reply to Tom
Quoted 3 lines · Tom

I can successfully enable ping for IPv6 using this rule:

nft add rule ip6 filter input ip6 nexthdr icmpv6 counter limit rate 5/second accept

This is not related to ping, this ratelimits ALL of icmpv6.

Please use 'icmpv6 type { echo-request, echo-reply}'.

Quoted 5 lines

nft add rule ip6 filter input ip6 daddr xxxx:43:a:83::5 ip6 nexthdr icmpv6 counter limit rate 5/second accept nft add rule ip6 filter input ip6 daddr xxxx:43:a:83::6 ip6 nexthdr icmpv6 counter limit rate 5/second accept

...but what happens is that the first IPv6 will work, but not the second. If I reverse the order, sometimes the second rule still works but now the first doesn't. I've tried using sets like so:

icmpv6 is integral part of ipv6, the above will ratelimit neighbour solicitations, pmtu updates and so on as well.

author
#2 lore raw
In reply to Pablo Neira Ayuso
Quoted 6 lines · Pablo Neira Ayuso

Please, don't use "ip6 nexthdr", this strictly means "check for the IPv6 nexthdr field of the IPv6 header", which is not what you might need. See:
https://wiki.nftables.org/wiki-nftables/index.php/Matching_packet_headers#Matching_IPv6_headers
Instead, use "meta l4proto" which already parses the IPv6 extension headers up to the layer 4 header.

OK thanks. WillCo.

Quoted 13 lines

Better use concatenations and sets:

table ip6 x {
         set y {
                 typeof ip6 daddr . meta l4proto
                 limit rate 5/second
                 elements = { aaaa:43:a:83::5 . icmpv6 limit rate 5/second,
                              aaaa:43:a:83::6 . icmpv6 limit rate 5/second }
         }
         chain m {
                 type filter hook prerouting priority filter; policy drop;
                 ip6 daddr . meta l4proto @y accept
         }
}

Worked like a charm. Thanks again.

Quoted 2 lines

Probably, nft -o/--optimize might offer more of these transformations in the future.

Good to know!

author
#4 lore raw
In reply to Florian Westphal
Quoted 6 lines · Florian Westphal
Quoted 1 line · Tom

nft add rule ip6 filter input ip6 nexthdr icmpv6 counter limit rate 5/second accept

This is not related to ping, this ratelimits ALL of icmpv6. Please use 'icmpv6 type { echo-request, echo-reply}'. icmpv6 is integral part of ipv6, the above will ratelimit neighbour solicitations, pmtu updates and so on as well.

Ooh, that's not good. What about this, recommended by Pablo:

table ip6 filter {
	set ping6 {
		typeof ip6 daddr . meta l4proto
		limit rate 5/second
		elements = { xxxx:43:a:83::2 . ipv6-icmp limit rate 5/second,
			     xxxx:43:a:83::3 . ipv6-icmp limit rate 5/second,
			     xxxx:43:a:83::4 . ipv6-icmp limit rate 5/second }
	}
	chain input {
		type filter hook input priority filter; policy drop;
		ip6 daddr . meta l4proto @ping6 accept
	}

Is this OK?

#5 lore raw
Quoted 23 lines · Tom
Quoted 6 lines · Florian Westphal
Quoted 1 line · Tom

nft add rule ip6 filter input ip6 nexthdr icmpv6 counter limit rate 5/second accept

This is not related to ping, this ratelimits ALL of icmpv6. Please use 'icmpv6 type { echo-request, echo-reply}'. icmpv6 is integral part of ipv6, the above will ratelimit neighbour solicitations, pmtu updates and so on as well.

Ooh, that's not good. What about this, recommended by Pablo:

table ip6 filter {
	set ping6 {
		typeof ip6 daddr . meta l4proto
		limit rate 5/second
		elements = { xxxx:43:a:83::2 . ipv6-icmp limit rate 5/second,
			     xxxx:43:a:83::3 . ipv6-icmp limit rate 5/second,
			     xxxx:43:a:83::4 . ipv6-icmp limit rate 5/second }
	}
	chain input {
		type filter hook input priority filter; policy drop;
		ip6 daddr . meta l4proto @ping6 accept
	}
Quoted 1 line

Is this OK?

My recommendation is to use concatenations and sets, not to ratelimit _all_ icmpv6 traffic ;-)