netfilter: separate bridge meta key from nft_meta into meta_bridge
Subsystems (4)
PATCH v2 1/7 netfilter: separate bridge meta key from nft_meta into meta_bridge
From: wenxu <[email protected]>
Separate bridge meta key from nft_meta to meta_bridge for other key support. So there is n dependency between nft_meta and the bridge module
--- include/net/netfilter/nft_meta.h | 44 ++++++++++++ net/bridge/netfilter/Kconfig | 6 ++ net/bridge/netfilter/Makefile | 1 + net/bridge/netfilter/nft_meta_bridge.c | 127 +++++++++++++++++++++++++++++++++ net/netfilter/nf_tables_core.c | 1 + net/netfilter/nft_meta.c | 81 ++++++++------------- 6 files changed, 207 insertions(+), 53 deletions(-) create mode 100644 include/net/netfilter/nft_meta.h create mode 100644 net/bridge/netfilter/nft_meta_bridge.c
include/net/netfilter/nft_meta.h new file +44 -0
@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NFT_META_H_ +#define _NFT_META_H_ + +struct nft_meta { +enum nft_meta_keys key:8 ; +union { +enum nft_registers dreg:8 ; +enum nft_registers sreg:8 ; + }; +}; + +extern const struct nla_policy nft_meta_policy[]; + +int nft_meta_get_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]); + +int nft_meta_set_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]); + +int nft_meta_get_dump (struct sk_buff *skb, +const struct nft_expr *expr); + +int nft_meta_set_dump (struct sk_buff *skb, +const struct nft_expr *expr); + +void nft_meta_get_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt); + +void nft_meta_set_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt); + +void nft_meta_set_destroy (const struct nft_ctx *ctx, +const struct nft_expr *expr); + +int nft_meta_set_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nft_data **data); + +#endif
net/bridge/netfilter/Kconfig +6 -0
@@ -9,6 +9,12 @@ menuconfig NF_TABLES_BRIDGE bool "Ethernet Bridge nf_tables support" if NF_TABLES_BRIDGE + +config NFT_BRIDGE_META + tristate "Netfilter nf_table bridge meta support" + help + Add support for bridge dedicated meta key. + config NFT_BRIDGE_REJECT tristate "Netfilter nf_tables bridge reject support" depends on NFT_REJECT && NFT_REJECT_IPV4 && NFT_REJECT_IPV6
net/bridge/netfilter/Makefile +1 -0
@@ -3,6 +3,7 @@ # Makefile for the netfilter modules for Link Layer filtering on a bridge. # +obj-$(CONFIG_NFT_BRIDGE_META) += nft_meta_bridge.o obj-$(CONFIG_NFT_BRIDGE_REJECT) += nft_reject_bridge.o # connection tracking
net/bridge/netfilter/nft_meta_bridge.c new file +127 -0
127 lines not on this page · raw message
net/netfilter/nf_tables_core.c +1 -0
@@ -19,6 +19,7 @@#include <net/netfilter/nf_tables_core.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_log.h> +#include <net/netfilter/nft_meta.h> static noinline void __nft_trace_packet(struct nft_traceinfo *info, const struct nft_chain *chain,
net/netfilter/nft_meta.c +28 -53
175 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/7 netfilter: nft_meta_bridge: Remove the br_private.h header
From: wenxu <[email protected]>
Mkae the nft_bridge_meta can't direct access the bridge internal API.
--- net/bridge/netfilter/nft_meta_bridge.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
net/bridge/netfilter/nft_meta_bridge.c +14 -5
@@ -8,7 +8,14 @@#include <net/netfilter/nf_tables.h> #include <net/netfilter/nft_meta.h> -#include "../br_private.h" +static const struct net_device * +nft_meta_get_bridge (const struct net_device *dev) +{ +if (dev &&netif_is_bridge_port (dev)) +return netdev_master_upper_dev_get_rcu ((struct net_device *)dev); + +return NULL ; +} static void nft_meta_bridge_get_eval(const struct nft_expr *expr, struct nft_regs *regs,
@@ -17,22 +24,24 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,const struct nft_meta *priv =nft_expr_priv (expr);const struct net_device *in =nft_in (pkt), *out =nft_out (pkt);u32 *dest = ®s->data[priv->dreg]; -const struct net_bridge_port *p; +const struct net_device *br_dev;switch (priv->key) {case NFT_META_BRI_IIFNAME : -if (in ==NULL || (p =br_port_get_rcu (in)) ==NULL ) + br_dev =nft_meta_get_bridge (in); +if (!br_dev) goto err;break ;case NFT_META_BRI_OIFNAME : -if (out ==NULL || (p =br_port_get_rcu (out)) ==NULL ) + br_dev =nft_meta_get_bridge (out); +if (!br_dev) goto err;break ;default : goto out; } -strncpy ((char *)dest, p->br->dev->name,IFNAMSIZ ); +strncpy ((char *)dest, br_dev->name,IFNAMSIZ );return ; out:return nft_meta_get_eval (expr, regs, pkt);
Signature · 1 line
1.8.3.1
Re: [Bridge] [PATCH 2/7 nf-next v2] netfilter: nft_meta_bridge: Remove the br_private.h header
Quoted 4 lines · On Fri, Jul 05, 2019 at 09:16:33PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
Mkae the
nft_bridge_metacan't direct access the bridge internal API.
Applied, thanks.
PATCH v2 3/7 bridge: add br_vlan_get_pvid_rcu()
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This new function allows you to fetch bridge pvid from packet path.
--- include/linux/if_bridge.h | 6 ++++++ net/bridge/br_vlan.c | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-)
include/linux/if_bridge.h +6 -0
@@ -88,6 +88,7 @@ static inline bool br_multicast_router(const struct net_device *dev)#if IS_ENABLED (CONFIG_BRIDGE ) &&IS_ENABLED (CONFIG_BRIDGE_VLAN_FILTERING )bool br_vlan_enabled (const struct net_device *dev);int br_vlan_get_pvid (const struct net_device *dev,u16 *p_pvid); +int br_vlan_get_pvid_rcu (const struct net_device *dev,u16 *p_pvid);int br_vlan_get_info (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo);#else
@@ -101,6 +102,11 @@ static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)return -EINVAL ; } +static inline int br_vlan_get_pvid_rcu (const struct net_device *dev,u16 *p_pvid) +{ +return -EINVAL ; +} +static inline int br_vlan_get_info (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo) {
net/bridge/br_vlan.c +15 -4
@@ -1227,13 +1227,11 @@ void br_vlan_get_stats(const struct net_bridge_vlan *v, } } -int br_vlan_get_pvid (const struct net_device *dev,u16 *p_pvid) +static int __br_vlan_get_pvid (const struct net_device *dev, +struct net_bridge_port *p,u16 *p_pvid) {struct net_bridge_vlan_group *vg; -struct net_bridge_port *p; -ASSERT_RTNL (); - p =br_port_get_check_rtnl (dev);if (p) vg =nbp_vlan_group (p);else if (netif_is_bridge_master (dev))
@@ -1244,8 +1242,21 @@ int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid) *p_pvid =br_get_pvid (vg);return 0 ; } + +int br_vlan_get_pvid (const struct net_device *dev,u16 *p_pvid) +{ +ASSERT_RTNL (); + +return __br_vlan_get_pvid (dev,br_port_get_check_rtnl (dev), p_pvid); +}EXPORT_SYMBOL_GPL (br_vlan_get_pvid); +int br_vlan_get_pvid_rcu (const struct net_device *dev,u16 *p_pvid) +{ +return __br_vlan_get_pvid (dev,br_port_get_check_rcu (dev), p_pvid); +} +EXPORT_SYMBOL_GPL (br_vlan_get_pvid_rcu); +int br_vlan_get_info (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo) {
Signature · 1 line
2.11.0
Re: [Bridge] [PATCH 3/7 nf-next v2] bridge: add br_vlan_get_pvid_rcu()
Quoted 3 lines · On Fri, Jul 05, 2019 at 09:16:34PM +0800, [email protected] wrote:
From: Pablo Neira Ayuso <[email protected]>
This new function allows you to fetch bridge pvid from packet path.
Applied, thanks.
PATCH v2 4/7 netfilter: nft_meta_bridge: add NFT_META_BRI_IIFPVID support
In reply to [email protected]From: wenxu <[email protected]>
nft add table bridge firewall
nft add chain bridge firewall zones { type filter hook prerouting priority - 300 \; } nft add rule bridge firewall zones counter ct zone set vlan id map { 100 : 1, 200 : 2 }
As above set the bridge port with pvid, the received packet don't contain the vlan tag which means the packet should belong to vlan 200 through pvid. With this pacth user can get the pvid of bridge ports.
So add the following rule for as the first rule in the chain of zones.
nft add rule bridge firewall zones counter meta vlan set meta briifpvid
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/bridge/netfilter/nft_meta_bridge.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -795,6 +795,7 @@ enum nft_exthdr_attributes {* @NFT_META_SECPATH: boolean, secpath_exists (!!skb->sp) * @NFT_META_IIFKIND: packet input interface kind name (dev->rtnl_link_ops->kind) * @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind) +* @NFT_META_BRI_IIFPVID: packet input bridge port pvid */ enum nft_meta_keys {NFT_META_LEN ,
@@ -825,6 +826,7 @@ enum nft_meta_keys {NFT_META_SECPATH ,NFT_META_IIFKIND ,NFT_META_OIFKIND , + NFT_META_BRI_IIFPVID, };/**
net/bridge/netfilter/nft_meta_bridge.c +15 -0
@@ -7,6 +7,7 @@#include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nft_meta.h> +#include <linux/if_bridge.h> static const struct net_device *nft_meta_get_bridge (const struct net_device *dev)
@@ -37,6 +38,17 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,if (!br_dev) goto err;break ; +case NFT_META_BRI_IIFPVID : { +u16 p_pvid; + + br_dev =nft_meta_get_bridge (in); +if (!br_dev || !br_vlan_enabled (br_dev)) + goto err; + +br_vlan_get_pvid_rcu (in, &p_pvid); +nft_reg_store16 (dest, p_pvid); +return ; + }default : goto out; }
@@ -62,6 +74,9 @@ static int nft_meta_bridge_get_init(const struct nft_ctx *ctx,case NFT_META_BRI_OIFNAME : len =IFNAMSIZ ;break ; +case NFT_META_BRI_IIFPVID : + len =sizeof (u16); +break ;default :return nft_meta_get_init (ctx, expr, tb); }
Signature · 1 line
1.8.3.1
Re: [Bridge] [PATCH 4/7 nf-next v2] netfilter: nft_meta_bridge: add NFT_META_BRI_IIFPVID support
Quoted 6 lines · On Fri, Jul 05, 2019 at 09:16:35PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
nft add table bridge firewall
nft add chain bridge firewall zones { type filter hook prerouting priority - 300 \; } nft add rule bridge firewall zones counter ct zone set vlan id map { 100 : 1, 200 : 2 }
Quoted 7 lines
As above set the bridge port with pvid, the received packet don't contain the vlan tag which means the packet should belong to vlan 200 through pvid. With this pacth user can get the pvid of bridge ports.
So add the following rule for as the first rule in the chain of zones.
nft add rule bridge firewall zones counter meta vlan set meta briifpvid
Applied, thanks.
A message that is not in the archive (sent off-list or not yet received): 20190813195427.vmootvj5rmxgihml@salvia
Pablo Neira Ayuso
maintainerRe: [PATCH 4/7 nf-next v2] netfilter: nft_meta_bridge: add NFT_META_BRI_IIFPVID support
Quoted 6 lines · On Fri, Jul 05, 2019 at 09:16:35PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
nft add table bridge firewall
nft add chain bridge firewall zones { type filter hook prerouting priority - 300 \; } nft add rule bridge firewall zones counter ct zone set vlan id map { 100 : 1, 200 : 2 }
Quoted 7 lines
As above set the bridge port with pvid, the received packet don't contain the vlan tag which means the packet should belong to vlan 200 through pvid. With this pacth user can get the pvid of bridge ports.
So add the following rule for as the first rule in the chain of zones.
nft add rule bridge firewall zones counter meta vlan set meta briifpvid
No patches for libnftnl and nftables to support for this?
PATCH v2 5/7 bridge: add br_vlan_get_proto()
In reply to [email protected]From: wenxu <[email protected]>
This new function allows you to fetch bridge vlan proto.
--- include/linux/if_bridge.h | 6 ++++++ net/bridge/br_vlan.c | 10 ++++++++++ 2 files changed, 16 insertions(+)
include/linux/if_bridge.h +6 -0
@@ -89,6 +89,7 @@ static inline bool br_multicast_router(const struct net_device *dev)bool br_vlan_enabled (const struct net_device *dev);int br_vlan_get_pvid (const struct net_device *dev,u16 *p_pvid);int br_vlan_get_pvid_rcu (const struct net_device *dev,u16 *p_pvid); +int br_vlan_get_proto (const struct net_device *dev,u16 *p_proto);int br_vlan_get_info (const struct net_device *dev,u16 vid,struct bridge_vlan_info *p_vinfo);#else
@@ -102,6 +103,11 @@ static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)return -EINVAL ; } +static inline int br_vlan_get_proto (const struct net_device *dev,u16 *p_proto) +{ +return -EINVAL ; +} +static inline int br_vlan_get_pvid_rcu (const struct net_device *dev,u16 *p_pvid) {return -EINVAL ;
net/bridge/br_vlan.c +10 -0
@@ -797,6 +797,16 @@ bool br_vlan_enabled(const struct net_device *dev) }EXPORT_SYMBOL_GPL (br_vlan_enabled); +int br_vlan_get_proto (const struct net_device *dev,u16 *p_proto) +{ +struct net_bridge *br =netdev_priv (dev); + + *p_proto =ntohs (br->vlan_proto); + +return 0 ; +} +EXPORT_SYMBOL_GPL (br_vlan_get_proto); +int __br_vlan_set_proto (struct net_bridge *br,__be16 proto) {int err =0 ;
Signature · 1 line
1.8.3.1
Re: [Bridge] [PATCH 5/7 nf-next v2] bridge: add br_vlan_get_proto()
Quoted 3 lines · On Fri, Jul 05, 2019 at 09:16:36PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
This new function allows you to fetch bridge vlan proto.
Applied, thanks.
PATCH v2 6/7 netfilter: nft_meta_bridge: Add NFT_META_BRI_IIFVPROTO support
In reply to [email protected]From: wenxu <[email protected]>
This patch provide a meta to get the bridge vlan proto
nft add rule bridge firewall zones counter meta br_vlan_proto 0x8100
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/bridge/netfilter/nft_meta_bridge.c | 12 ++++++++++++ 2 files changed, 14 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -796,6 +796,7 @@ enum nft_exthdr_attributes {* @NFT_META_IIFKIND: packet input interface kind name (dev->rtnl_link_ops->kind) * @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind) * @NFT_META_BRI_IIFPVID: packet input bridge port pvid +* @NFT_META_BRI_IIFVPROTO: packet input bridge vlan proto */ enum nft_meta_keys {NFT_META_LEN ,
@@ -827,6 +828,7 @@ enum nft_meta_keys {NFT_META_IIFKIND ,NFT_META_OIFKIND ,NFT_META_BRI_IIFPVID , + NFT_META_BRI_IIFVPROTO, };/**
net/bridge/netfilter/nft_meta_bridge.c +12 -0
@@ -49,6 +49,17 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,nft_reg_store16 (dest, p_pvid);return ; } +case NFT_META_BRI_IIFVPROTO : { +u16 p_proto; + + br_dev =nft_meta_get_bridge (in); +if (!br_dev || !br_vlan_enabled (br_dev)) + goto err; + +br_vlan_get_proto (br_dev, &p_proto); +nft_reg_store16 (dest, p_proto); +return ; + }default : goto out; }
@@ -75,6 +86,7 @@ static int nft_meta_bridge_get_init(const struct nft_ctx *ctx, len =IFNAMSIZ ;break ;case NFT_META_BRI_IIFPVID : +case NFT_META_BRI_IIFVPROTO : len =sizeof (u16);break ;default :
Signature · 1 line
1.8.3.1
Re: [Bridge] [PATCH 6/7 nf-next v2] netfilter: nft_meta_bridge: Add NFT_META_BRI_IIFVPROTO support
Quoted 5 lines · On Fri, Jul 05, 2019 at 09:16:37PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
This patch provide a meta to get the bridge vlan proto
nft add rule bridge firewall zones counter meta
br_vlan_proto0x8100
Applied, thanks.
PATCH v2 1/1 netfilter:nft_meta: add NFT_META_VLAN support
In reply to [email protected]From: wenxu <[email protected]>
This patch provide a meta vlan to set the vlan tag of the packet.
for q-in-q outer vlan id 20:
meta vlan set 0x88a8:20
set the default 0x8100 vlan type with vlan id 20
meta vlan set 20
--- include/net/netfilter/nft_meta.h | 5 ++++- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
include/net/netfilter/nft_meta.h +4 -1
@@ -6,7 +6,10 @@ struct nft_meta { enum nft_meta_keys key:8;union {enum nft_registers dreg:8 ; -enum nft_registers sreg:8 ; +struct { +enum nft_registers sreg:8 ; +enum nft_registers sreg2:8 ; + }; }; };
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -797,6 +797,7 @@ enum nft_exthdr_attributes {* @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind) * @NFT_META_BRI_IIFPVID: packet input bridge port pvid * @NFT_META_BRI_IIFVPROTO: packet input bridge vlan proto +* @NFT_META_VLAN: packet vlan metadata */ enum nft_meta_keys {NFT_META_LEN ,
@@ -829,6 +830,7 @@ enum nft_meta_keys {NFT_META_OIFKIND ,NFT_META_BRI_IIFPVID ,NFT_META_BRI_IIFVPROTO , + NFT_META_VLAN, };/**
@@ -895,12 +897,14 @@ enum nft_hash_attributes {* @NFTA_META_DREG: destination register (NLA_U32) * @NFTA_META_KEY: meta data item to load (NLA_U32: nft_meta_keys) * @NFTA_META_SREG: source register (NLA_U32) +* @NFTA_META_SREG2: source register (NLA_U32) */ enum nft_meta_attributes {NFTA_META_UNSPEC ,NFTA_META_DREG ,NFTA_META_KEY ,NFTA_META_SREG , +NFTA_META_SREG2 , __NFTA_META_MAX };#define NFTA_META_MAX (__NFTA_META_MAX - 1)
net/netfilter/nft_meta.c +25 -0
@@ -271,6 +271,20 @@ void nft_meta_set_eval(const struct nft_expr *expr, skb->secmark = value;break ;#endif +case NFT_META_VLAN : { +u32 *sreg2 = ®s->data[meta->sreg2]; +u16 vlan_proto; +u16 vlan_tci; + + vlan_tci =nft_reg_load16 (sreg); + vlan_proto =nft_reg_load16 (sreg2); + +if (vlan_proto !=ETH_P_8021Q && vlan_proto !=ETH_P_8021AD ) +return ; + +__vlan_hwaccel_put_tag (skb,htons (vlan_proto), vlan_tci &VLAN_VID_MASK ); +break ; + }default :WARN_ON (1 ); }
@@ -281,6 +295,7 @@ void nft_meta_set_eval(const struct nft_expr *expr, [NFTA_META_DREG] = { .type = NLA_U32 }, [NFTA_META_KEY] = { .type = NLA_U32 }, [NFTA_META_SREG] = { .type = NLA_U32 }, + [NFTA_META_SREG2 ] = { .type =NLA_U32 }, };EXPORT_SYMBOL_GPL (nft_meta_policy );
@@ -432,6 +447,13 @@ int nft_meta_set_init(const struct nft_ctx *ctx,case NFT_META_PKTTYPE : len =sizeof (u8);break ; +case NFT_META_VLAN : + len =sizeof (u16); + priv->sreg2 =nft_parse_register (tb[NFTA_META_SREG2 ]); + err =nft_validate_register_load (priv->sreg2, len); +if (err <0 ) +return err; +break ;default :return -EOPNOTSUPP ; }
@@ -457,6 +479,9 @@ int nft_meta_get_dump(struct sk_buff *skb, goto nla_put_failure;if (nft_dump_register (skb,NFTA_META_DREG , priv->dreg)) goto nla_put_failure; +if (priv->key ==NFT_META_VLAN && +nft_dump_register (skb,NFTA_META_SREG2 , priv->sreg2)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.8.3.1
Re: [Bridge] [PATCH nf-next v2] netfilter:nft_meta: add NFT_META_VLAN support
Quoted 10 lines · On 05/07/2019 16:16, [email protected] wrote:
From: wenxu <[email protected]>
This patch provide a meta vlan to set the vlan tag of the packet.
for q-in-q outer vlan id 20:
meta vlan set 0x88a8:20set the default
0x8100vlan type with vlan id 20
meta vlan set 20
Quoted 7 lines
Signed-off-by wenxu <[email protected]>--- include/net/netfilter/nft_meta.h | 5 ++++- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
The patch looks fine, just a note: you'll only be able to work with the outer tag, so guessing to achieve a double-tagged frame you'll have to add another NFT_META_VLAN_INNER(?) and will have to organize them one after another.
Quoted 109 lines
include/net/netfilter/nft_meta.h +4
-1@@ -6,7 +6,10 @@ struct nft_meta { enum nft_meta_keys key:8;union {enum nft_registers dreg:8 ; -enum nft_registers sreg:8 ; +struct { +enum nft_registers sreg:8 ; +enum nft_registers sreg2:8 ; + }; }; };include/uapi/linux/netfilter/nf_tables.h +4
-0@@ -797,6 +797,7 @@ enum nft_exthdr_attributes {* @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind) * @NFT_META_BRI_IIFPVID: packet input bridge port pvid * @NFT_META_BRI_IIFVPROTO: packet input bridge vlan proto +* @NFT_META_VLAN: packet vlan metadata */ enum nft_meta_keys {NFT_META_LEN ,@@ -829,6 +830,7 @@ enum nft_meta_keys {NFT_META_OIFKIND ,NFT_META_BRI_IIFPVID ,NFT_META_BRI_IIFVPROTO , + NFT_META_VLAN, };/** @@ -895,12 +897,14 @@ enum nft_hash_attributes {* @NFTA_META_DREG: destination register (NLA_U32) * @NFTA_META_KEY: meta data item to load (NLA_U32: nft_meta_keys) * @NFTA_META_SREG: source register (NLA_U32) +* @NFTA_META_SREG2: source register (NLA_U32) */ enum nft_meta_attributes {NFTA_META_UNSPEC ,NFTA_META_DREG ,NFTA_META_KEY ,NFTA_META_SREG , +NFTA_META_SREG2 , __NFTA_META_MAX };#define NFTA_META_MAX (__NFTA_META_MAX - 1)net/netfilter/nft_meta.c +25
-0@@ -271,6 +271,20 @@ void nft_meta_set_eval(const struct nft_expr *expr, skb->secmark = value;break ;#endif +case NFT_META_VLAN : { +u32 *sreg2 = ®s->data[meta->sreg2]; +u16 vlan_proto; +u16 vlan_tci; + + vlan_tci =nft_reg_load16 (sreg); + vlan_proto =nft_reg_load16 (sreg2); + +if (vlan_proto !=ETH_P_8021Q && vlan_proto !=ETH_P_8021AD ) +return ; + +__vlan_hwaccel_put_tag (skb,htons (vlan_proto), vlan_tci &VLAN_VID_MASK ); +break ; + }default :WARN_ON (1 ); }@@ -281,6 +295,7 @@ void nft_meta_set_eval(const struct nft_expr *expr, [NFTA_META_DREG] = { .type = NLA_U32 }, [NFTA_META_KEY] = { .type = NLA_U32 }, [NFTA_META_SREG] = { .type = NLA_U32 }, + [NFTA_META_SREG2 ] = { .type =NLA_U32 }, };EXPORT_SYMBOL_GPL (nft_meta_policy );@@ -432,6 +447,13 @@ int nft_meta_set_init(const struct nft_ctx *ctx,case NFT_META_PKTTYPE : len =sizeof (u8);break ; +case NFT_META_VLAN : + len =sizeof (u16); + priv->sreg2 =nft_parse_register (tb[NFTA_META_SREG2 ]); + err =nft_validate_register_load (priv->sreg2, len); +if (err <0 ) +return err; +break ;default :return -EOPNOTSUPP ; }@@ -457,6 +479,9 @@ int nft_meta_get_dump(struct sk_buff *skb, goto nla_put_failure;if (nft_dump_register (skb,NFTA_META_DREG , priv->dreg)) goto nla_put_failure; +if (priv->key ==NFT_META_VLAN && +nft_dump_register (skb,NFTA_META_SREG2 , priv->sreg2)) + goto nla_put_failure;return 0 ; nla_put_failure:
Re: [Bridge] [PATCH nf-next v2] netfilter:nft_meta: add NFT_META_VLAN support
Quoted 18 lines · Nikolay Aleksandrov
Quoted 10 lines · On 05/07/2019 16:16, [email protected] wrote:
From: wenxu <[email protected]>
This patch provide a meta vlan to set the vlan tag of the packet.
for q-in-q outer vlan id 20:
meta vlan set 0x88a8:20set the default
0x8100vlan type with vlan id 20
meta vlan set 20Quoted 7 lines
Signed-off-by wenxu <[email protected]>--- include/net/netfilter/nft_meta.h | 5 ++++- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
Quoted 4 lines
The patch looks fine, just a note: you'll only be able to work with the outer tag, so guessing to achieve a double-tagged frame you'll have to add another
NFT_META_VLAN_INNER(?)and will have to organize them one after another.
yes, It's just set/mangle the meta vlan data.
I think it's a good idear for stacked tagged with NFT_META_VLAN_INNER, in
this case it should check the the proto of vlan tag already on packet
There are three case:
1. packet already contain a vlan header with proto 0x88a8, it should push the inner vlan tag
2. there is no outer vlan tag, maybe we should add a inner 0x8100 tag
and outer 0x88a8 tag?
3. packet already contain a vlan tag with proto 0x8100, push the vlan tag and add outer 0x88a8 tag ?
Quoted 3 lines
Re: [Bridge] [PATCH nf-next v2] netfilter:nft_meta: add NFT_META_VLAN support
Quoted 25 lines · wenxu
Quoted 18 lines · Nikolay Aleksandrov
Quoted 10 lines · On 05/07/2019 16:16, [email protected] wrote:
From: wenxu <[email protected]>
This patch provide a meta vlan to set the vlan tag of the packet.
for q-in-q outer vlan id 20:
meta vlan set 0x88a8:20set the default
0x8100vlan type with vlan id 20
meta vlan set 20Quoted 7 lines
Signed-off-by wenxu <[email protected]>--- include/net/netfilter/nft_meta.h | 5 ++++- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)Quoted 4 lines
The patch looks fine, just a note: you'll only be able to work with the outer tag, so guessing to achieve a double-tagged frame you'll have to add another
NFT_META_VLAN_INNER(?)and will have to organize them one after another.
Quoted 9 lines
yes, It's just set/mangle the meta vlan data.
I think it's a good idear for stacked tagged withNFT_META_VLAN_INNER, in
this case it should check the the proto of vlan tag already on packet
There are three case:
1. packet already contain a vlan header with proto0x88a8, it should push the inner vlan tag
2. there is no outer vlan tag, maybe we should add a inner0x8100tag
and outer0x88a8tag?
3. packet already contain a vlan tag with proto0x8100, push the vlan tag and add outer0x88a8tag ?
I'm more inclined to make it simpler, i.e. always push inner vlan. That way you can arrange them anyway you like, also skb_vlan_push() already takes care of all that. It'll push the vlan if hwaccel is present or make it hwaccel if it isn't.
In fact I'd suggest using skb_vlan_push(), so you don't need another NFT_META_VLAN_INNER, this one can be re-used. If you chain 2 of these you'll get properly double-tagged frame.
Re: [Bridge] [PATCH nf-next v2] netfilter:nft_meta: add NFT_META_VLAN support
Quoted 36 lines · Nikolay Aleksandrov
Quoted 25 lines · wenxu
Quoted 18 lines · Nikolay Aleksandrov
Quoted 10 lines · On 05/07/2019 16:16, [email protected] wrote:
From: wenxu <[email protected]>
This patch provide a meta vlan to set the vlan tag of the packet.
for q-in-q outer vlan id 20:
meta vlan set 0x88a8:20set the default
0x8100vlan type with vlan id 20
meta vlan set 20Quoted 7 lines
Signed-off-by wenxu <[email protected]>--- include/net/netfilter/nft_meta.h | 5 ++++- include/uapi/linux/netfilter/nf_tables.h | 4 ++++ net/netfilter/nft_meta.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)Quoted 4 lines
The patch looks fine, just a note: you'll only be able to work with the outer tag, so guessing to achieve a double-tagged frame you'll have to add another
NFT_META_VLAN_INNER(?)and will have to organize them one after another.Quoted 9 lines
yes, It's just set/mangle the meta vlan data.
I think it's a good idear for stacked tagged withNFT_META_VLAN_INNER, in
this case it should check the the proto of vlan tag already on packet
There are three case:
1. packet already contain a vlan header with proto0x88a8, it should push the inner vlan tag
2. there is no outer vlan tag, maybe we should add a inner0x8100tag
and outer0x88a8tag?
3. packet already contain a vlan tag with proto0x8100, push the vlan tag and add outer0x88a8tag ?
Quoted 7 lines
I'm more inclined to make it simpler, i.e. always push inner vlan. That way you can arrange them anyway you like, also
skb_vlan_push()already takes care of all that. It'll push the vlan if hwaccel is present or make it hwaccel if it isn't.In fact I'd suggest using
skb_vlan_push(), so you don't need anotherNFT_META_VLAN_INNER, this one can be re-used. If you chain 2 of these you'll get properly double-tagged frame.
You just need to be careful because skb_vlan_push expects skb->data to be at the mac header.
Quoted 5 lines · On Fri, Jul 05, 2019 at 09:16:32PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
Separate bridge meta key from
nft_metatometa_bridgefor other key support. So there is n dependency betweennft_metaand the bridge module
Applied, thanks.