nftables: add cpu attribute to nft_meta
Subsystems (2)
cover nftables: add cpu attribute to nft_meta
Hi,
this patchset adds the metainformation selector "cpu", which would be the nftables equivalent of xt_cpu for iptables.
The patchset contains the code for kernel, libnfnt and nftables. I created the kernel patch against the repositorygit://git.kernel.org/pub/scm/linux/kernel/git/pablo/nftables.git,
hopefully it's the right one, otherwise please let me know and I'll send the patch rebased on the correct repo.
Best Regards,
- Valentina Giusti
PATCH 1/3 netfilter: nft_meta: add attribute to match cpu handling the packet
Signed-off-by Valentina Giusti <[email protected]>
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_meta.c | 4 ++++ 2 files changed, 6 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -571,6 +571,7 @@ enum nft_exthdr_attributes {* @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 +* @NFT_META_CPU: cpu handling the packet */ enum nft_meta_keys {NFT_META_LEN ,
@@ -592,6 +593,7 @@ enum nft_meta_keys {NFT_META_L4PROTO ,NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME , + NFT_META_CPU, };/**
net/netfilter/nft_meta.c +4 -0
@@ -124,6 +124,9 @@ void nft_meta_get_eval(const struct nft_expr *expr, dest->data[0 ] = skb->secmark;break ;#endif +case NFT_META_CPU : + dest->data[0 ] =smp_processor_id (); +break ;default :WARN_ON (1 ); goto err;
@@ -195,6 +198,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,#ifdef CONFIG_NETWORK_SECMARK case NFT_META_SECMARK :#endif +case NFT_META_CPU :break ;default :return -EOPNOTSUPP ;
Signature · 1 line
2.0.0.rc2
PATCH 2/3 libnftnl: add attribute for cpu handling the packet
In reply to Valentina GiustiSigned-off-by Valentina Giusti <[email protected]>
--- include/linux/netfilter/nf_tables.h | 1 + src/expr/meta.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/netfilter/nf_tables.h +1 -0
@@ -592,6 +592,7 @@ enum nft_meta_keys {NFT_META_L4PROTO ,NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME , + NFT_META_CPU, };/**
src/expr/meta.c +2 -1
@@ -23,7 +23,7 @@#include "expr_ops.h" #ifndef NFT_META_MAX -#define NFT_META_MAX (NFT_META_BRI_OIFNAME + 1) +#define NFT_META_MAX (NFT_META_CPU + 1)#endif struct nft_expr_meta {
@@ -153,6 +153,7 @@ static const char *meta_key2str_array[NFT_META_MAX] = { [NFT_META_SECMARK] = "secmark", [NFT_META_BRI_IIFNAME] = "bri_iifname", [NFT_META_BRI_OIFNAME] = "bri_oifname", + [NFT_META_CPU] = "cpu", };static const char *meta_key2str (uint8_t key)
Signature · 1 line
2.0.0.rc2
PATCH 3/3 nftables: add support for cpu meta attribute
In reply to Valentina GiustiSigned-off-by Valentina Giusti <[email protected]>
--- include/linux/netfilter/nf_tables.h | 2 ++ src/meta.c | 2 ++ src/parser.y | 2 ++ src/scanner.l | 1 + 4 files changed, 7 insertions(+)
include/linux/netfilter/nf_tables.h +2 -0
@@ -535,6 +535,7 @@ enum nft_exthdr_attributes {* @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 +* @NFT_META_CPU: cpu handling the packet */ enum nft_meta_keys {NFT_META_LEN ,
@@ -556,6 +557,7 @@ enum nft_meta_keys {NFT_META_L4PROTO ,NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME , + NFT_META_CPU, };/**
src/meta.c +2 -0
@@ -338,6 +338,8 @@ static const struct meta_template meta_templates[] = { [NFT_META_BRI_OIFNAME ] =META_TEMPLATE ("obriport" , &string_type,IFNAMSIZ *BITS_PER_BYTE , BYTEORDER_HOST_ENDIAN), + [NFT_META_CPU ] =META_TEMPLATE ("cpu" , &integer_type, + 4 * 8, BYTEORDER_HOST_ENDIAN), };static void meta_expr_print (const struct expr *expr)
src/parser.y +2 -0
@@ -325,6 +325,7 @@ static int monitor_lookup_event(const char *event) %token RTCLASSID "rtclassid" %token IBRIPORT "ibriport" %token OBRIPORT "obriport" +%token CPU "cpu" %token CT "ct" %token DIRECTION "direction"
@@ -1838,6 +1839,7 @@ meta_key_unqualified : MARK { $$ = NFT_META_MARK; } | RTCLASSID { $$ = NFT_META_RTCLASSID; } | IBRIPORT { $$ = NFT_META_BRI_IIFNAME; } | OBRIPORT { $$ = NFT_META_BRI_OIFNAME; } + | CPU { $$ = NFT_META_CPU; } ; meta_stmt : META meta_key SET expr
src/scanner.l +1 -0
@@ -415,6 +415,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "rtclassid" { return RTCLASSID; } "ibriport" { return IBRIPORT; } "obriport" { return OBRIPORT; } +"cpu" { return CPU; } "ct" { return CT; } "direction" { return DIRECTION; }
Signature · 1 line
2.0.0.rc2