nftables: difference between "meta l4proto tcp" and "ip protocol tcp"
Hello,
I noticed that I can not use "ip protocol tcp" for IPv6, I assume that this is due to IPv6 packets not having a protocol field. However, I also noticed that "meta l4proto tcp" works for IPv4 and it seems to match exactly the same packets as "ip protocol tcp".
The only relevant piece of information that I could gather is a message
(https://patchwork.ozlabs.org/patch/593221/) stating that (for "meta l4proto" and "ip protocol") "However, the two statements are redundants... the second implies the first".
If those expressions are different, what exactly do they use to match packets? Is one more efficient?
I am writing a script that works with both IPv4 and IPv6, is it reasonable to always use "meta l4proto" to avoid duplicating some code?
Please CC me in replies as I am not subscribed to the list.
Kind regards,
Louis
Quoted 7 lines · Louis Sautier
Hello,
I noticed that I can not use "ip protocol tcp" for IPv6, I assume that this is due to IPv6 packets not having a protocol field. However, I also noticed that "meta l4proto tcp" works for IPv4 and it seems to match exactly the same packets as "ip protocol tcp".
Quoted 9 lines
The only relevant piece of information that I could gather is a message
(https://patchwork.ozlabs.org/patch/593221/) stating that (for "meta l4proto" and "ip protocol") "However, the two statements are redundants... the second implies the first".If those expressions are different, what exactly do they use to match packets? Is one more efficient?
Both are similar in term os efficiency.
ip protocol tcp checks the IPv4 header looking for the l4 protocol number. meta l4proto tcp checks packet meta information (not header) to know about the l4 protocol, regardless of l3 protocol.
Obviously, meta l4proto tcp can be used in IPv4/IPv6 while the first only makes sense in IPv4.
You should read 'ip protocol tcp' as if it was explicit about l3 protocol, like 'ipv4 protocol tcp': this wont match any IPv6 packet.
Quoted 21 lines · Arturo Borrero Gonzalez
Quoted 7 lines · Louis Sautier
Hello,
I noticed that I can not use "ip protocol tcp" for IPv6, I assume that this is due to IPv6 packets not having a protocol field. However, I also noticed that "meta l4proto tcp" works for IPv4 and it seems to match exactly the same packets as "ip protocol tcp".
Quoted 9 lines
The only relevant piece of information that I could gather is a message
(https://patchwork.ozlabs.org/patch/593221/) stating that (for "meta l4proto" and "ip protocol") "However, the two statements are redundants... the second implies the first".If those expressions are different, what exactly do they use to match packets? Is one more efficient?
Both are similar in term os efficiency.
Quoted 9 lines
ip protocol tcp checks the IPv4 header looking for the l4 protocol number. meta l4proto tcp checks packet meta information (not header) to know about the l4 protocol, regardless of l3 protocol.
Obviously, meta l4proto tcp can be used in IPv4/IPv6 while the first only makes sense in IPv4.
You should read 'ip protocol tcp' as if it was explicit about l3 protocol, like 'ipv4 protocol tcp': this wont match any IPv6 packet.
Thanks for the reply.
So if I understand correctly, "ip protocol" refers to an actual IPv4 packet field whereas "meta" refers to metadata that does not necessarily have an associated packet field (such as all the unqualified meta expressions like "skuid").
I guess in the case of IPv4, "meta l4proto" is obtained from the protocol field whereas in the case of IPv6 it is obtained from the "next header" field. But it doesn't matter to us because we use this "meta" abstraction, is that right?
Quoted 31 lines · Louis Sautier
Quoted 21 lines · Arturo Borrero Gonzalez
Quoted 7 lines · Louis Sautier
Hello,
I noticed that I can not use "ip protocol tcp" for IPv6, I assume that this is due to IPv6 packets not having a protocol field. However, I also noticed that "meta l4proto tcp" works for IPv4 and it seems to match exactly the same packets as "ip protocol tcp".
Quoted 9 lines
The only relevant piece of information that I could gather is a message
(https://patchwork.ozlabs.org/patch/593221/) stating that (for "meta l4proto" and "ip protocol") "However, the two statements are redundants... the second implies the first".If those expressions are different, what exactly do they use to match packets? Is one more efficient?
Both are similar in term os efficiency.
Quoted 9 lines
ip protocol tcp checks the IPv4 header looking for the l4 protocol number. meta l4proto tcp checks packet meta information (not header) to know about the l4 protocol, regardless of l3 protocol.
Obviously, meta l4proto tcp can be used in IPv4/IPv6 while the first only makes sense in IPv4.
You should read 'ip protocol tcp' as if it was explicit about l3 protocol, like 'ipv4 protocol tcp': this wont match any IPv6 packet.
Quoted 5 lines
Thanks for the reply.
So if I understand correctly, "ip protocol" refers to an actual IPv4 packet field whereas "meta" refers to metadata that does not necessarily have an associated packet field (such as all the unqualified meta expressions like "skuid").
Yes.
Quoted 5 lines
I guess in the case of IPv4, "meta l4proto" is obtained from the protocol field whereas in the case of IPv6 it is obtained from the "next header" field. But it doesn't matter to us because we use this "meta" abstraction, is that right?
In case you want concrete details, here a few pointers in the source code.
meta l4proto fetching into a register:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/netfilter/nft_meta.c#n53
In case of IPv6 packet, here is how the metainformation is filled:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree//include/net/netfilter/nf_tables_ipv6.h#n8
At the end, we are using ipv6_find_hdr()
http://elixir.free-electrons.com/linux/latest/source/net/ipv6/exthdrs_core.c#L185
Searching for the packet metainformation is happening per packet at runtime, not matter your ruleset, just when a packet enters a hook:
http://elixir.free-electrons.com/linux/latest/source/net/ipv6/netfilter/nf_tables_ipv6.c#L19