Add suport for bridge if dev name meta expression keys
Subsystems (3)
v4 cover Add suport for bridge if dev name meta expression keys
Here is the patch-set to add meta keys NFT_META_BRI_IIFNAME and NFT_META_BRI_OIFNAME.
Changes against
v3:
- Applied Pablo's comment so CONFIG_NF_TABLES_BRIDGE and CONFIG_BRIDGE_NF_EBTABLES are interdependent with CONFIG_BRIDGE_NETFILTER in order to properly add netfilter sub-directory when building.
v2:
- Applied Pablo's comment on patch 3
- Applied human readable names on patch 5 according to Pablo and Patrick comments. v1:
- Rebased the kernel patch set against Patrick's nft_meta.c get/set init function split up.
Last 2 patches are about user-space support.
Tomasz Bursztyka (5):
kernel:
netfilter: nf_tables: Stack expression type depending on their family
netfilter: nf_tables: Make meta expression core functions public
netfilter: nf_tables: Add meta expression key for bridge interface
name
libnftnl:
meta: Add support for input and output bridge interface name
nftables:
meta: Add support for input and output bridge interface name
Signature · 1 line
1.8.3.2
PATCH v4 1/5 netfilter: nf_tables: Stack expression type depending on their family
To ensure family tight expression gets selected in priority to family agnostic ones.
--- net/netfilter/nf_tables_api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +4 -1
@@ -1093,7 +1093,10 @@ static void nft_ctx_init(struct nft_ctx *ctx,int nft_register_expr (struct nft_expr_type *type) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); -list_add_tail (&type->list, &nf_tables_expressions); +if (type->family ==NFPROTO_UNSPEC ) +list_add_tail (&type->list, &nf_tables_expressions); +else +list_add (&type->list, &nf_tables_expressions);nfnl_unlock (NFNL_SUBSYS_NFTABLES );return 0 ; }
Signature · 1 line
1.8.3.2
PATCH v4 2/5 netfilter: nf_tables: Make meta expression core functions public
In reply to Tomasz Bursztyka This will be useful to create network family dedicated META expression as for NFPROTO_BRIDGE for instance.
--- include/net/netfilter/nft_meta.h | 36 +++++++++++++++++++++++++++++ net/netfilter/nft_meta.c | 50 ++++++++++++++++++++-------------------- 2 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 include/net/netfilter/nft_meta.h
include/net/netfilter/nft_meta.h new file +36 -0
@@ -0,0 +1,36 @@ +#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_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt); + +void nft_meta_set_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt); + +#endif
net/netfilter/nft_meta.c +25 -25
103 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v4 3/5 netfilter: nf_tables: Add meta expression key for bridge interface name
In reply to Tomasz BursztykaNFT_META_BRI_IIFNAME to get packet input bridge interface name NFT_META_BRI_OIFNAME to get packet output bridge interface name
Such meta key are accessible only through NFPROTO_BRIDGE family, on a dedicated nft meta module: nft_meta_bridge.
--- include/uapi/linux/netfilter/nf_tables.h | 4 + net/bridge/Makefile | 2 +- net/bridge/netfilter/Kconfig | 14 +++- net/bridge/netfilter/Makefile | 1 + net/bridge/netfilter/nft_meta_bridge.c | 139 +++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 net/bridge/netfilter/nft_meta_bridge.c
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -536,6 +536,8 @@ enum nft_exthdr_attributes {* @NFT_META_SECMARK: packet secmark (skb->secmark) * @NFT_META_NFPROTO: netfilter protocol * @NFT_META_L4PROTO: layer 4 protocol number +* @NFT_META_BRI_IIFNAME: packet input bridge interface name +* @NFT_META_BRI_OIFNAME: packet output bridge interface name */ enum nft_meta_keys {NFT_META_LEN ,
@@ -555,6 +557,8 @@ enum nft_meta_keys {NFT_META_SECMARK ,NFT_META_NFPROTO ,NFT_META_L4PROTO , +NFT_META_BRI_IIFNAME , + NFT_META_BRI_OIFNAME, };/**
net/bridge/Makefile +1 -1
@@ -16,4 +16,4 @@ bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o -obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/ +obj-$(CONFIG_BRIDGE_NETFILTER) += netfilter/
net/bridge/netfilter/Kconfig +13 -1
@@ -2,13 +2,25 @@ # Bridge netfilter configuration # # -config NF_TABLES_BRIDGE +menuconfig NF_TABLES_BRIDGE depends on NF_TABLES + select BRIDGE_NETFILTER tristate "Ethernet Bridge nf_tables support" +if NF_TABLES_BRIDGE + +config NFT_BRIDGE_META + tristate "Netfilter nf_table bridge meta support" + depends on NFT_META + help + Add support for bridge dedicated meta key. + +endif # NF_TABLES_BRIDGE + menuconfig BRIDGE_NF_EBTABLES tristate "Ethernet Bridge tables (ebtables) support" depends on BRIDGE && NETFILTER + select BRIDGE_NETFILTER select NETFILTER_XTABLES help ebtables is a general, extensible frame/packet identification
net/bridge/netfilter/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-$(CONFIG_NF_TABLES_BRIDGE) += nf_tables_bridge.o +obj-$(CONFIG_NFT_BRIDGE_META) += nft_meta_bridge.o obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
net/bridge/netfilter/nft_meta_bridge.c new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Pablo Neira Ayuso
maintainerRe: [PATCH 3/5] netfilter: nf_tables: Add meta expression key for bridge interface name
Hi Tomasz,
Quoted 2 lines · Tomasz Bursztyka
NFT_META_BRI_IIFNAMEto get packet input bridge interface nameNFT_META_BRI_OIFNAMEto get packet output bridge interface name
I'm going to take this patchset and enqueue to the nftables tree (net-next), but before doing so, I'm going to rename NFT_META_BRI_IIFNAME to NFT_META_IBRIPORT, the original name is a bit long and I think the proposal to change the name also applies to this.
I'm attaching the mangled patch here.
Quoted 1 line
From
d3090dfe18931781debfd6596b81b9af84a9b8aaMon Sep 17 00:00:00 2001
From: Tomasz Bursztyka <[email protected]>
Date: Mon, 14 Apr 2014 15:41:28 +0300
Subject: [PATCH] netfilter: nf_tables: Add meta expression key for bridge
interface name
NFT_META_IBRIPORT to get packet input bridge interface name NFT_META_OBRIPORT to get packet output bridge interface name
Such meta key are accessible only through NFPROTO_BRIDGE family, on a dedicated nft meta module: nft_meta_bridge.
--- include/uapi/linux/netfilter/nf_tables.h | 4 + net/bridge/Makefile | 2 +- net/bridge/netfilter/Kconfig | 14 ++- net/bridge/netfilter/Makefile | 1 + net/bridge/netfilter/nft_meta_bridge.c | 139 ++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 net/bridge/netfilter/nft_meta_bridge.c
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -563,6 +563,8 @@ enum nft_exthdr_attributes {* @NFT_META_SECMARK: packet secmark (skb->secmark) * @NFT_META_NFPROTO: netfilter protocol * @NFT_META_L4PROTO: layer 4 protocol number +* @NFT_META_IBRIPORT: packet input bridge interface name +* @NFT_META_OBRIPORT: packet output bridge interface name */ enum nft_meta_keys {NFT_META_LEN ,
@@ -582,6 +584,8 @@ enum nft_meta_keys {NFT_META_SECMARK ,NFT_META_NFPROTO ,NFT_META_L4PROTO , +NFT_META_IBRIPORT , + NFT_META_OBRIPORT, };/**
net/bridge/Makefile +1 -1
@@ -16,4 +16,4 @@ bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o -obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/ +obj-$(CONFIG_BRIDGE_NETFILTER) += netfilter/
net/bridge/netfilter/Kconfig +13 -1
@@ -2,13 +2,25 @@ # Bridge netfilter configuration # # -config NF_TABLES_BRIDGE +menuconfig NF_TABLES_BRIDGE depends on NF_TABLES + select BRIDGE_NETFILTER tristate "Ethernet Bridge nf_tables support" +if NF_TABLES_BRIDGE + +config NFT_BRIDGE_META + tristate "Netfilter nf_table bridge meta support" + depends on NFT_META + help + Add support for bridge dedicated meta key. + +endif # NF_TABLES_BRIDGE + menuconfig BRIDGE_NF_EBTABLES tristate "Ethernet Bridge tables (ebtables) support" depends on BRIDGE && NETFILTER + select BRIDGE_NETFILTER select NETFILTER_XTABLES help ebtables is a general, extensible frame/packet identification
net/bridge/netfilter/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-$(CONFIG_NF_TABLES_BRIDGE) += nf_tables_bridge.o +obj-$(CONFIG_NFT_BRIDGE_META) += nft_meta_bridge.o obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
net/bridge/netfilter/nft_meta_bridge.c new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH 3/5] netfilter: nf_tables: Add meta expression key for bridge interface name
Hi Pablo,
Quoted 2 lines
I'm going to rename
NFT_META_BRI_IIFNAMEtoNFT_META_IBRIPORT,
As you want. I took the name proposed by Patrick here, and since it's an API there is less concerns about having a really short human-writable name as for the nftables tool.
Tomasz
Pablo Neira Ayuso
maintainerRe: [PATCH 3/5] netfilter: nf_tables: Add meta expression key for bridge interface name
Quoted 8 lines · Tomasz Bursztyka
Hi Pablo,
Quoted 2 lines
I'm going to rename
NFT_META_BRI_IIFNAMEtoNFT_META_IBRIPORT,As you want. I took the name proposed by Patrick here, and since it's an API there is less concerns about having a really short human-writable name as for the nftables tool.
Right, I just found that email. I just wanted to make sure everybody is happy with the current naming approach, so let's leave it as is.
Series applies, thanks Tomasz.
PATCH v4 4/5 meta: Add support for input and output bridge interface name
In reply to Tomasz BursztykaAdd support for dedicated bridge meta key, related to device names:
- NFT_META_BRI_IIFNAME
- NFT_META_BRI_OIFNAME
--- include/linux/netfilter/nf_tables.h | 4 ++++ src/expr/meta.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/netfilter/nf_tables.h +4 -0
@@ -536,6 +536,8 @@ enum nft_exthdr_attributes {* @NFT_META_SECMARK: packet secmark (skb->secmark) * @NFT_META_NFPROTO: netfilter protocol * @NFT_META_L4PROTO: layer 4 protocol number +* @NFT_META_BRI_IIFNAME: packet input bridge interface name +* @NFT_META_BRI_OIFNAME: packet output bridge interface name */ enum nft_meta_keys {NFT_META_LEN ,
@@ -555,6 +557,8 @@ enum nft_meta_keys {NFT_META_SECMARK ,NFT_META_NFPROTO ,NFT_META_L4PROTO , +NFT_META_BRI_IIFNAME , + NFT_META_BRI_OIFNAME, };/**
src/expr/meta.c +3 -1
@@ -23,7 +23,7 @@#include "expr_ops.h" #ifndef NFT_META_MAX -#define NFT_META_MAX (NFT_META_L4PROTO + 1) +#define NFT_META_MAX (NFT_META_BRI_OIFNAME + 1)#endif struct nft_expr_meta {
@@ -153,6 +153,8 @@ static const char *meta_key2str_array[NFT_META_MAX] = { [NFT_META_NFTRACE] = "nftrace", [NFT_META_RTCLASSID] = "rtclassid", [NFT_META_SECMARK] = "secmark", + [NFT_META_BRI_IIFNAME] = "bri_iifname", + [NFT_META_BRI_OIFNAME] = "bri_oifname", };static const char *meta_key2str (uint8_t key)
Signature · 1 line
1.8.3.2
PATCH v4 5/5 meta: Add support for input and output bridge interface name
In reply to Tomasz BursztykaAdd support to get an input or output bridge interface name through the relevant meta keys.
--- include/linux/netfilter/nf_tables.h | 4 ++++ src/meta.c | 6 ++++++ src/parser.y | 4 ++++ src/scanner.l | 2 ++ 4 files changed, 16 insertions(+)
include/linux/netfilter/nf_tables.h +4 -0
@@ -533,6 +533,8 @@ enum nft_exthdr_attributes {* @NFT_META_SECMARK: packet secmark (skb->secmark) * @NFT_META_NFPROTO: netfilter protocol * @NFT_META_L4PROTO: layer 4 protocol number +* @NFT_META_BRI_IIFNAME: packet input bridge interface name +* @NFT_META_BRI_OIFNAME: packet output bridge interface name */ enum nft_meta_keys {NFT_META_LEN ,
@@ -552,6 +554,8 @@ enum nft_meta_keys {NFT_META_SECMARK ,NFT_META_NFPROTO ,NFT_META_L4PROTO , +NFT_META_BRI_IIFNAME , + NFT_META_BRI_OIFNAME, };/**
src/meta.c +6 -0
@@ -332,6 +332,12 @@ static const struct meta_template meta_templates[] = { 1 , BYTEORDER_HOST_ENDIAN), [NFT_META_RTCLASSID ] =META_TEMPLATE ("rtclassid" , &realm_type, 4 * 8, BYTEORDER_HOST_ENDIAN), + [NFT_META_BRI_IIFNAME ] =META_TEMPLATE ("ibriport" , &string_type, +IFNAMSIZ *BITS_PER_BYTE , + BYTEORDER_HOST_ENDIAN), + [NFT_META_BRI_OIFNAME ] =META_TEMPLATE ("obriport" , &string_type, +IFNAMSIZ *BITS_PER_BYTE , + BYTEORDER_HOST_ENDIAN), };static void meta_expr_print (const struct expr *expr)
src/parser.y +4 -0
@@ -304,6 +304,8 @@ static void location_update(struct location *loc, struct location *rhs, int n) %token SKGID "skgid" %token NFTRACE "nftrace" %token RTCLASSID "rtclassid" +%token IBRIPORT "ibriport" +%token OBRIPORT "obriport" %token CT "ct" %token DIRECTION "direction"
@@ -1563,6 +1565,8 @@ meta_key_unqualified : MARK { $$ = NFT_META_MARK; } | SKGID { $$ = NFT_META_SKGID; } | NFTRACE { $$ = NFT_META_NFTRACE; } | RTCLASSID { $$ = NFT_META_RTCLASSID; } + | IBRIPORT { $$ = NFT_META_BRI_IIFNAME; } + | OBRIPORT { $$ = NFT_META_BRI_OIFNAME; } ; meta_stmt : META meta_key SET expr
src/scanner.l +2 -0
@@ -402,6 +402,8 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "skgid" { return SKGID; } "nftrace" { return NFTRACE; } "rtclassid" { return RTCLASSID; } +"ibriport" { return IBRIPORT; } +"obriport" { return OBRIPORT; } "ct" { return CT; } "direction" { return DIRECTION; }
Signature · 1 line
1.8.3.2