expr: meta: Add cpu support for meta expresion
Subsystems (2)
PATCH 1/1 expr: meta: Add cpu support for meta expresion
The cpu attribute does not set.
--- include/linux/netfilter/nf_tables.h | 2 ++ src/expr/meta.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
include/linux/netfilter/nf_tables.h +2 -0
@@ -572,6 +572,7 @@ enum nft_exthdr_attributes {* @NFT_META_BRI_IIFNAME: packet input bridge interface name * @NFT_META_BRI_OIFNAME: packet output bridge interface name * @NFT_META_PKTTYPE: Packet type +* @NFT_META_CPU: Packet cpu */ enum nft_meta_keys {NFT_META_LEN ,
@@ -594,6 +595,7 @@ enum nft_meta_keys {NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME ,NFT_META_PKTTYPE , + NFT_META_CPU, };/**
src/expr/meta.c +3 -2
@@ -23,7 +23,7 @@#include "expr_ops.h" #ifndef NFT_META_MAX -#define NFT_META_MAX (NFT_META_PKTTYPE + 1) +#define NFT_META_MAX (NFT_META_CPU + 1)#endif struct nft_expr_meta {
@@ -153,7 +153,8 @@ 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_PKTTYPE] = "pkttype" + [NFT_META_PKTTYPE] = "pkttype", + [NFT_META_CPU] = "cpu", };static const char *meta_key2str (uint8_t key)
Signature · 1 line
1.7.10.4
PATCH 1/1 netfilter: nf_tables: Add cpu attribute support to meta expresion.
Add cpu support to meta expresion.
This allows you to match packets with cpu number.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_meta.c | 5 +++++ 2 files changed, 7 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -572,6 +572,7 @@ enum nft_exthdr_attributes {* @NFT_META_BRI_IIFNAME: packet input bridge interface name * @NFT_META_BRI_OIFNAME: packet output bridge interface name * @NFT_META_PKTTYPE: Packet type +* @NFT_META_CPU: Packet cpu */ enum nft_meta_keys {NFT_META_LEN ,
@@ -594,6 +595,7 @@ enum nft_meta_keys {NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME ,NFT_META_PKTTYPE , + NFT_META_CPU, };/**
net/netfilter/nft_meta.c +5 -0
@@ -17,6 +17,7 @@#include <linux/in.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <linux/smp.h> #include <net/dst.h> #include <net/sock.h> #include <net/tcp_states.h> /* for TCP_TIME_WAIT */
@@ -150,6 +151,9 @@ void nft_meta_get_eval(const struct nft_expr *expr, goto err; }break ; +case NFT_META_CPU : + dest->data[0 ] =smp_processor_id (); +break ;default :WARN_ON (1 ); goto err;
@@ -222,6 +226,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,case NFT_META_SECMARK :#endif case NFT_META_PKTTYPE : +case NFT_META_CPU :break ;default :return -EOPNOTSUPP ;
Signature · 1 line
1.7.10.4
PATCH 1/1 src: Add support for cpu in meta expresion
In reply to Ana ReyThis allows you to match cpu handling with a packet.
This is an example of the syntax for this new attribute:
nft add rule ip test input meta cpu 1 counter nft add rule ip test input meta cpu 1-3 counter nft add rule ip test input meta cpu { 1, 3} counter
--- include/linux/netfilter/nf_tables.h | 2 ++ src/meta.c | 3 +++ src/parser.y | 2 ++ src/scanner.l | 1 + 4 files changed, 8 insertions(+)
include/linux/netfilter/nf_tables.h +2 -0
@@ -536,6 +536,7 @@ enum nft_exthdr_attributes {* @NFT_META_BRI_IIFNAME: packet input bridge interface name * @NFT_META_BRI_OIFNAME: packet output bridge interface name * @NFT_META_PKTTYPE: packet type +* @NFT_META_CPU: packet cpu */ enum nft_meta_keys {NFT_META_LEN ,
@@ -558,6 +559,7 @@ enum nft_meta_keys {NFT_META_BRI_IIFNAME ,NFT_META_BRI_OIFNAME ,NFT_META_PKTTYPE , + NFT_META_CPU, };/**
src/meta.c +3 -0
@@ -393,6 +393,9 @@ static const struct meta_template meta_templates[] = { [NFT_META_PKTTYPE ] =META_TEMPLATE ("pkttype" , &pkttype_type,BITS_PER_BYTE , BYTEORDER_HOST_ENDIAN), + [NFT_META_CPU ] =META_TEMPLATE ("cpu" , &integer_type, +BITS_PER_BYTE , + 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 IBRIPORT "ibriport" %token OBRIPORT "obriport" %token PKTTYPE "pkttype" +%token CPU "cpu" %token CT "ct" %token DIRECTION "direction"
@@ -1786,6 +1787,7 @@ meta_key_unqualified : MARK { $$ = NFT_META_MARK; } | IBRIPORT { $$ = NFT_META_BRI_IIFNAME; } | OBRIPORT { $$ = NFT_META_BRI_OIFNAME; } | PKTTYPE { $$ = NFT_META_PKTTYPE; } + | CPU { $$ = NFT_META_CPU; } ; meta_stmt : META meta_key SET expr
src/scanner.l +1 -0
@@ -407,6 +407,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "ibriport" { return IBRIPORT; } "obriport" { return OBRIPORT; } "pkttype" { return PKTTYPE; } +"cpu" { return CPU; } "ct" { return CT; } "direction" { return DIRECTION; }
Signature · 1 line
1.7.10.4
PATCH 1/1 tests: Add tests for cpu attribute of meta expresion.
In reply to Ana ReyAdd some tests to check the cpu attribute of meta expresion.
--- tests/any/meta.t | 8 ++++++++ 1 file changed, 8 insertions(+)
tests/any/meta.t +8 -0
@@ -164,3 +164,11 @@ meta pkttype != unicast;ok;pkttype != unicast meta pkttype != multicast;ok;pkttype != multicast meta pkttype broadcastttt;fail -meta pkttype { broadcast, multicast} accept;ok + +meta cpu 1;ok;cpu 1 +meta cpu != 1;ok;cpu != 1 +meta cpu 1-3;ok;cpu >= 1 cpu <= 3 +# BUG: there is not matching of packets with this rule. +meta cpu != 1-2;ok;cpu < 1 cpu > 2 +meta cpu { 2,3};ok;cpu { 2, 3} +-meta cpu != { 2,3};ok
Signature · 1 line
1.7.10.4
Re: [PATCH] [nft] src: Add support for cpu in meta expresion
In reply to Ana ReyQuoted 7 lines · Ana Rey
This allows you to match cpu handling with a packet.
This is an example of the syntax for this new attribute:
nft add rule ip test input meta cpu 1 counter nft add rule ip test input meta cpu 1-3 counter nft add rule ip test input meta cpu { 1, 3} counter
Applied, thanks Ana.
Re: [PATCH] netfilter: nf_tables: Add cpu attribute support to meta expresion.
In reply to Ana ReyQuoted 3 lines · Ana Rey
Add cpu support to meta expresion.
This allows you to match packets with cpu number.
Applied, thanks.
Pablo Neira Ayuso
maintainerApplied with minor change in the doc area of nf_tables.h
Thanks.