meta: introduce meta ibrhwdr support
PATCH 1/1 meta: introduce meta ibrhwdr support
Can be used in bridge prerouting hook to redirect the packet to the receiving physical device for processing.
table bridge nat {
chain PREROUTING {
type filter hook prerouting priority 0; policy accept;
ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr accept
}
}--- include/linux/netfilter/nf_tables.h | 2 ++ src/meta.c | 4 ++++ tests/py/bridge/meta.t | 1 + tests/py/bridge/pass_up.t | 6 ++++++ tests/py/bridge/pass_up.t.json | 19 +++++++++++++++++++ tests/py/bridge/pass_up.t.payload | 4 ++++ 6 files changed, 36 insertions(+) create mode 100644 tests/py/bridge/pass_up.t create mode 100644 tests/py/bridge/pass_up.t.json create mode 100644 tests/py/bridge/pass_up.t.payload
include/linux/netfilter/nf_tables.h +2 -0
@@ -949,6 +949,7 @@ enum nft_exthdr_attributes {* @NFT_META_SDIF: slave device interface index * @NFT_META_SDIFNAME: slave device interface name * @NFT_META_BRI_BROUTE: packet br_netfilter_broute bit +* @NFT_META_BRI_IIFHWADDR: packet input bridge interface ethernet address */ enum nft_meta_keys {NFT_META_LEN ,
@@ -989,6 +990,7 @@ enum nft_meta_keys {NFT_META_SDIFNAME ,NFT_META_BRI_BROUTE , __NFT_META_IIFTYPE, + NFT_META_BRI_IIFHWADDR, };/**
src/meta.c +4 -0
@@ -23,6 +23,7 @@#include <arpa/inet.h> #include <linux/netfilter.h> #include <linux/pkt_sched.h> +#include <linux/if_ether.h> #include <linux/if_packet.h> #include <time.h>
@@ -704,6 +705,9 @@ const struct meta_template meta_templates[] = { BYTEORDER_HOST_ENDIAN), [NFT_META_BRI_BROUTE ] =META_TEMPLATE ("broute" , &integer_type, 1 , BYTEORDER_HOST_ENDIAN), + [NFT_META_BRI_IIFHWADDR ] =META_TEMPLATE ("ibrhwdr" , ðeraddr_type, +ETH_ALEN *BITS_PER_BYTE , + BYTEORDER_BIG_ENDIAN), };static bool meta_key_is_unqualified (enum nft_meta_keys key)
tests/py/bridge/meta.t +1 -0
@@ -11,3 +11,4 @@ meta protocol ip udp dport 67;ok meta protocol ip6 udp dport 67;ok meta broute set 1;fail +meta ibrhwdr;fail
tests/py/bridge/pass_up.t new file +6 -0
@@ -0,0 +1,6 @@ +:prerouting;type filter hook prerouting priority 0 + +*bridge;test-bridge;prerouting + +ether daddr set meta ibrhwdr;ok +meta ibrhwdr set 00:1a:2b:3c:4d:5e;fail
tests/py/bridge/pass_up.t.json new file +19 -0
@@ -0,0 +1,19 @@ +# ether daddr set meta ibrhwdr +[ + { + "mangle": { + "key": { + "payload": { + "field": "daddr", + "protocol": "ether" + } + }, + "value": { + "meta": { + "key": "ibrhwdr" + } + } + } + } +] +
tests/py/bridge/pass_up.t.payload new file +4 -0
@@ -0,0 +1,4 @@ +# ether daddr set meta ibrhwdr +bridge test-bridge prerouting + [ meta load ibrhwdr => reg 1 ] + [ payload write reg 1 => 6b @ link header + 0 csum_type 0 csum_off 0 csum_flags 0x0 ]
Signature · 1 line
2.51.0
Florian Westphal
maintainerQuoted 9 lines · Fernando Fernandez Mancera
Can be used in bridge prerouting hook to redirect the packet to the receiving physical device for processing.
table bridge nat { chain PREROUTING { type filter hook prerouting priority 0; policy accept; ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr accept } }
Pablo, does the above ok to you?
I am not sure about 'ibrhwdr'.
Will there be an 'obrhwdr'? Or is it for consistency because its envisioned to be used in incoming direction?
Patch LGTM, I would apply this and the libnftnl dependency.
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 11 lines · Florian Westphal
Quoted 9 lines · Fernando Fernandez Mancera
Can be used in bridge prerouting hook to redirect the packet to the receiving physical device for processing.
table bridge nat { chain PREROUTING { type filter hook prerouting priority 0; policy accept; ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr accept } }
Quoted 2 lines
Pablo, does the above ok to you?
I am not sure about 'ibrhwdr'.
I'd suggest: ibrhwaddr, for consistency with other existing ibr selectors and anything that relates to address uses the suffix 'addr'.
Quoted 1 line
Will there be an 'obrhwdr'?
No usecase for this so far.
Quoted 2 lines
Or is it for consistency because its envisioned to be used in incoming direction?
Using the input device where this frame came from, which is a bridge port, fetch the address of the upper bridge device on top of it.
It is a bit unix-like looking acronym, arguably not so intuitive, but I don't have a better idea.
Quoted 1 line
Patch LGTM, I would apply this and the libnftnl dependency.
Quoted 14 lines · Pablo Neira Ayuso
Hi Florian,
Quoted 11 lines · Florian Westphal
Quoted 9 lines · Fernando Fernandez Mancera
Can be used in bridge prerouting hook to redirect the packet to the receiving physical device for processing.
table bridge nat { chain PREROUTING { type filter hook prerouting priority 0; policy accept; ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr accept } }
Quoted 6 lines
Quoted 2 lines
Pablo, does the above ok to you?
I am not sure about 'ibrhwdr'.I'd suggest: ibrhwaddr, for consistency with other existing ibr selectors and anything that relates to address uses the suffix 'addr'.
Fine for me! If it looks good to you Florian I can send a v2 quickly and also adjust the test.
Quoted 15 lines
Quoted 1 line
Will there be an 'obrhwdr'?
No usecase for this so far.
Quoted 2 lines
Or is it for consistency because its envisioned to be used in incoming direction?
Using the input device where this frame came from, which is a bridge port, fetch the address of the upper bridge device on top of it.
It is a bit unix-like looking acronym, arguably not so intuitive, but I don't have a better idea.
Quoted 1 line
Patch LGTM, I would apply this and the libnftnl dependency.
Florian Westphal
maintainerQuoted 2 lines · Fernando Fernandez Mancera
Fine for me! If it looks good to you Florian I can send a v2 quickly and also adjust the test.
Sure, sounds good, thanks Fernando!