netfilter: bridge: introduce broute meta statement
Subsystems (3)
PATCH 1/1 netfilter: bridge: introduce broute meta statement
nftables equivalent for ebtables -t broute.
Implement a new meta statement 'broute' to set br_netfilter_broute flag in skb to force a packet to be routed instead of being bridged.
--- include/uapi/linux/netfilter/nf_tables.h | 2 + net/bridge/netfilter/nft_meta_bridge.c | 60 +++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -931,6 +931,7 @@ enum nft_exthdr_attributes {* @NFT_META_TIME_HOUR: hour of day (in seconds) * @NFT_META_SDIF: slave device interface index * @NFT_META_SDIFNAME: slave device interface name +* @NFT_META_BRI_BROUTE: packet br_netfilter_broute bit */ enum nft_meta_keys {NFT_META_LEN ,
@@ -969,6 +970,7 @@ enum nft_meta_keys {NFT_META_TIME_HOUR ,NFT_META_SDIF ,NFT_META_SDIFNAME , +NFT_META_BRI_BROUTE , __NFT_META_IIFTYPE, };
net/bridge/netfilter/nft_meta_bridge.c +58 -2
78 lines not on this page · raw message
Signature · 1 line
2.34.1
net/bridge/netfilter/nft_meta_bridge.c line 11
Quoted 6 lines · Sriram Yagnaraman
+++
b/net/bridge/netfilter/nft_meta_bridge.cnet/bridge/netfilter/nft_meta_bridge.c +1
-0@@ -8,6 +8,7 @@#include <net/netfilter/nf_tables.h> #include <net/netfilter/nft_meta.h> #include <linux/if_bridge.h> +#include <../br_private.h>
This hurts my eye. At least, let's have "../br_private.h"?
Florian Westphal
maintainernet/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 108
Quoted 3 lines · Sriram Yagnaraman
net/bridge/netfilter/nft_meta_bridge.c +3
-0+void nft_meta_bridge_set_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt)
static?
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 129
Quoted 6 lines
net/bridge/netfilter/nft_meta_bridge.c +6
-0+{ + dest =eth_hdr (skb)->h_dest; +if (skb->pkt_type ==PACKET_HOST && + !ether_addr_equal (skb->dev->dev_addr, dest) && +ether_addr_equal (p->br->dev->dev_addr, dest)) + skb->pkt_type =PACKET_OTHERHOST ;
We already support override of skb->pkt_type, I would prefer if users to this explicitly from their ruleset if they need it.
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 144
Quoted 1 line
net/bridge/netfilter/nft_meta_bridge.c +1
-0+ priv->key =ntohl (nla_get_be32 (tb[NFTA_META_KEY ]));
I think you need to check for !tb[NFTA_META_KEY] and bail out before this line.
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 148
Quoted 4 lines
net/bridge/netfilter/nft_meta_bridge.c +4
-0+switch (priv->key) { +case NFT_META_BRI_BROUTE : + len =sizeof (u8); +break ;
Can you bail out if this is called from something else than PREROUTING hook?
You can look at nft_tproxy.c or similar on how to do this.
Hi Florian,
Quoted 16 lines
-----Original Message-----
From: Florian Westphal <[email protected]>
Sent: Friday, 24 February 2023 00:02
To: Sriram Yagnaraman <[email protected]>
Cc: [email protected]; Florian Westphal <[email protected]>; Pablo Neira Ayuso <[email protected]>
Subject: Re: [PATCH nf-next] netfilter: bridge: introduce broute meta statementnet/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 108
Quoted 3 lines · Sriram Yagnaraman
net/bridge/netfilter/nft_meta_bridge.c +3
-0+void nft_meta_bridge_set_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt)static?
Quoted 9 lines
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 129
Quoted 6 lines
net/bridge/netfilter/nft_meta_bridge.c +6
-0+{ + dest =eth_hdr (skb)->h_dest; +if (skb->pkt_type ==PACKET_HOST && + !ether_addr_equal (skb->dev->dev_addr, dest) && +ether_addr_equal (p->br->dev->dev_addr, dest)) + skb->pkt_type =PACKET_OTHERHOST ;We already support override of
skb->pkt_type, I would prefer if users to this explicitly from their ruleset if they need it.
Ok, that is better, I will remove this chunk.
Quoted 5 lines
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 144
Quoted 2 lines
net/bridge/netfilter/nft_meta_bridge.c +1
-0+ priv->key =ntohl (nla_get_be32 (tb[NFTA_META_KEY ]));I think you need to check for !tb[NFTA_META_KEY] and bail out before this line.
We already validate this in nft_meta_bridge_select_ops(), isn’t that enough?
Quoted 9 lines
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 148
Quoted 5 lines
net/bridge/netfilter/nft_meta_bridge.c +4
-0+switch (priv->key) { +case NFT_META_BRI_BROUTE : + len =sizeof (u8); +break ;Can you bail out if this is called from something else than PREROUTING hook?
You can look at
nft_tproxy.cor similar on how to do this.
nft_meta_set_validate() already checks meta statements can only be used in the PREROUTING hook. Isn't that enough?
Florian Westphal
maintainerQuoted 29 lines · Sriram Yagnaraman
Quoted 16 lines
-----Original Message-----
From: Florian Westphal <[email protected]>
Sent: Friday, 24 February 2023 00:02
To: Sriram Yagnaraman <[email protected]>
Cc: [email protected]; Florian Westphal <[email protected]>; Pablo Neira Ayuso <[email protected]>
Subject: Re: [PATCH nf-next] netfilter: bridge: introduce broute meta statementnet/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 108
Quoted 3 lines · Sriram Yagnaraman
net/bridge/netfilter/nft_meta_bridge.c +3
-0+void nft_meta_bridge_set_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt)static?
Quoted 9 lines
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 129
Quoted 6 lines
net/bridge/netfilter/nft_meta_bridge.c +6
-0+{ + dest =eth_hdr (skb)->h_dest; +if (skb->pkt_type ==PACKET_HOST && + !ether_addr_equal (skb->dev->dev_addr, dest) && +ether_addr_equal (p->br->dev->dev_addr, dest)) + skb->pkt_type =PACKET_OTHERHOST ;We already support override of
skb->pkt_type, I would prefer if users to this explicitly from their ruleset if they need it.Ok, that is better, I will remove this chunk.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 144
Quoted 1 line
net/bridge/netfilter/nft_meta_bridge.c +1
-0+ priv->key =ntohl (nla_get_be32 (tb[NFTA_META_KEY ]));I think you need to check for !tb[NFTA_META_KEY] and bail out before this line.
We already validate this in
nft_meta_bridge_select_ops(), isn’t that enough?
Right, thats enough.
Quoted 10 lines
Quoted 8 lines
net/bridge/netfilter/nft_meta_bridge.c static const struct nft_expr_ops nft_meta_bridge_get_ops = { · line 148
Quoted 4 lines
net/bridge/netfilter/nft_meta_bridge.c +4
-0+switch (priv->key) { +case NFT_META_BRI_BROUTE : + len =sizeof (u8); +break ;Can you bail out if this is called from something else than PREROUTING hook?
You can look at
nft_tproxy.cor similar on how to do this.
nft_meta_set_validate()already checks meta statements can only be used in the PREROUTING hook. Isn't that enough?
It only restricts NFT_META_PKTTYPE.