netfilter: nf_tables: add vlan support
Subsystems (2)
PATCH 1/1 netfilter: nf_tables: add vlan support
From: wenxu <[email protected]>
This patch implements the vlan expr type that can be used to configure vlan tci and vlan proto
--- include/uapi/linux/netfilter/nf_tables.h | 24 +++++ net/netfilter/Kconfig | 6 ++ net/netfilter/Makefile | 1 + net/netfilter/nft_vlan.c | 152 +++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 net/netfilter/nft_vlan.c
include/uapi/linux/netfilter/nf_tables.h +24 -0
@@ -1796,4 +1796,28 @@ enum nft_tunnel_attributes { };#define NFTA_TUNNEL_MAX (__NFTA_TUNNEL_MAX - 1) +enum nft_vlan_action { +NFT_VLAN_ACTION_PUSH , +NFT_VLAN_ACTION_POP , +NFT_VLAN_ACTION_MODIFY , + __NFT_VLAN_ACTION_MAX +}; +#define NFT_VLAN_ACTION_MAX (__NFT_VLAN_ACTION_MAX - 1) + +/** +* enum nft_vlan_attributes - nf_tables vlan expression netlink attributes +* +* @NFTA_VLAN_ACTION: vlan data item to load (NLA_U32: nft_vlan_action) +* @NFTA_VLAN_SREG: source register (NLA_U16) +* @NFTA_VLAN_SREG2: source register (NLA_U16) +*/ +enum nft_vlan_attributes { +NFTA_VLAN_UNSPEC , +NFTA_VLAN_ACTION , +NFTA_VLAN_SREG , +NFTA_VLAN_SREG2 , + __NFTA_VLAN_MAX +}; +#define NFTA_VLAN_MAX (__NFTA_VLAN_MAX - 1) +#endif /* _LINUX_NF_TABLES_H */
net/netfilter/Kconfig +6 -0
@@ -556,6 +556,12 @@ config NFT_TUNNEL This option adds the "tunnel" expression that you can use to set tunneling policies. +config NFT_VLAN + tristate "Netfilter nf_tables vlan module" + help + This option adds the "vlan" expression that you can use to set + vlan policies. + config NFT_OBJREF tristate "Netfilter nf_tables stateful object reference module" help
net/netfilter/Makefile +1 -0
@@ -111,6 +111,7 @@ obj-$(CONFIG_NFT_OSF) += nft_osf.o obj-$(CONFIG_NFT_TPROXY) += nft_tproxy.o obj-$(CONFIG_NFT_XFRM) += nft_xfrm.o obj-$(CONFIG_NFT_SYNPROXY) += nft_synproxy.o +obj-$(CONFIG_NFT_VLAN) += nft_vlan.o obj-$(CONFIG_NFT_NAT) += nft_chain_nat.o
net/netfilter/nft_vlan.c new file +152 -0
152 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Florian Westphal
maintainerQuoted 4 lines · [email protected] <[email protected]> wrote:
From: wenxu <[email protected]>
This patch implements the vlan expr type that can be used to configure vlan tci and vlan proto
Looks like a very small module with no external dependencies, I think you could make this a nft-builtin feature and just add nft_vlan.o to 'nf_tables-objs' in net/netfilter/Makefile, similar to nft_rt.
What do you think?
If you plan to extend this in the future then I'm fine with keeping it as a module.
net/netfilter/nft_vlan.c line 82
Quoted 6 lines
net/netfilter/nft_vlan.c new file +6
-0+static int nft_vlan_set_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) +{ +struct nft_vlan *priv =nft_expr_priv (expr); +int err;
I think you need to add
if (!tb[NFTA_VLAN_ACTION] || !tb[NFTA_VLAN_SREG] || !tb[NFTA_VLAN_SREG2]) return -EINVAL;
Other than that this looks good to me.
Quoted 10 lines · Florian Westphal
Quoted 4 lines · [email protected] <[email protected]> wrote:
From: wenxu <[email protected]>
This patch implements the vlan expr type that can be used to configure vlan tci and vlan proto
Looks like a very small module with no external dependencies, I think you could make this a nft-builtin feature and just add nft_vlan.o to 'nf_tables-objs' in
net/netfilter/Makefile, similar tonft_rt.
Quoted 4 lines
What do you think?
If you plan to extend this in the future then I'm fine with keeping it as a module.
It can add vlan tci / proto "get" expr and It also can support offload things in the future.
Quoted 8 lines
net/netfilter/nft_vlan.c line 82
Quoted 6 lines
net/netfilter/nft_vlan.c new file +6
-0+static int nft_vlan_set_init (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nlattr *const tb[]) +{ +struct nft_vlan *priv =nft_expr_priv (expr); +int err;I think you need to add
Quoted 4 lines
if (!tb[NFTA_VLAN_ACTION] || !tb[NFTA_VLAN_SREG] || !tb[NFTA_VLAN_SREG2]) return -EINVAL;
Will do.
Quoted 3 lines
Other than that this looks good to me.
Florian Westphal
maintainerQuoted 3 lines · wenxu
Quoted 2 lines
If you plan to extend this in the future then I'm fine with keeping it as a module.
It can add vlan tci / proto "get" expr and It also can support offload things in the future.
Ok, lets keep it as a module then.