History

netfilter: nf_tables: add rule blob layout

This patch adds a blob layout per chain to represent the ruleset in the packet datapath. size (unsigned long) struct nft_rule_dp struct nft_expr ... struct nft_rule_dp struct nft_expr ... struct nft_rule_dp (is_last=1) The new structure nft_rule_dp represents the rule in a more compact way (smaller memory footprint) compared to the control-plane nft_rule structure. The ruleset blob is a read-only data structure. The first field contains the blob size, then the rules containing expressions. There is a trailing rule which is used by the tracing infrastructure which is equivalent to the NULL rule marker in the previous representation. The blob size field does not include the size of this trailing rule marker. The ruleset blob is generated from the commit path. This patch reuses the infrastructure available since 0cbc06b3faba ("netfilter: nf_tables: remove synchronize_rcu in commit phase") to build the array of rules per chain.

Pablo Neira Ayuso committed 4 years ago

Commit 2c865a81 parent 3b9e2ea4 files · +147 −67Browse files

Showing the changes to include (1 of 4 files). Show all

Unified · Split

include/net/netfilter/nf_tables.h+18−4
@@ -974,6 +974,20 @@ static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext, · 973 unmodified lines
974974
975975 #define NFT_CHAIN_POLICY_UNSET U8_MAX
976976
977+struct nft_rule_dp {
978+ u64 is_last:1,
979+ dlen:12,
980+ handle:42; /* for tracing */
981+ unsigned char data[]
982+ __attribute__((aligned(__alignof__(struct nft_expr))));
983+};
984+
985+struct nft_rule_blob {
986+ unsigned long size;
987+ unsigned char data[]
988+ __attribute__((aligned(__alignof__(struct nft_rule_dp))));
989+};
990+
977991 /**
978992 * struct nft_chain - nf_tables chain
979993 *
@@ -987,8 +1001,8 @@ static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext, · 7 unmodified lines
9871001 * @name: name of the chain
9881002 */
9891003 struct nft_chain {
990− struct nft_rule *__rcu *rules_gen_0;
991− struct nft_rule *__rcu *rules_gen_1;
1004+ struct nft_rule_blob __rcu *blob_gen_0;
1005+ struct nft_rule_blob __rcu *blob_gen_1;
9921006 struct list_head rules;
9931007 struct list_head list;
9941008 struct rhlist_head rhlhead;
@@ -1003,7 +1017,7 @@ struct nft_chain { · 8 unmodified lines
10031017 u8 *udata;
10041018
10051019 /* Only used during control plane commit phase: */
1006− struct nft_rule **rules_next;
1020+ struct nft_rule_blob *blob_next;
10071021 };
10081022
10091023 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
@@ -1321,7 +1335,7 @@ struct nft_traceinfo { · 311 unmodified lines
13211335 const struct nft_pktinfo *pkt;
13221336 const struct nft_base_chain *basechain;
13231337 const struct nft_chain *chain;
1324− const struct nft_rule *rule;
1338+ const struct nft_rule_dp *rule;
13251339 const struct nft_verdict *verdict;
13261340 enum nft_trace_types type;
13271341 bool packet_dumped;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t