Skip to contentSkip to conversation

netfilter: nf_tables: add NFT_CHAIN_BINDING

PATCH New Pablo Neira Ayuso 1 participant 1 message Jul 1, 2020

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 6/6 netfilter: nf_tables: add NFT_CHAIN_BINDING

This new chain flag specifies that:

* the kernel dynamically allocates the chain name, if no chain name is specified.

* If the immediate expression that refers to this chain is removed, then this bound chain (and its content) is destroyed.

---
v2: fix NFTA_CHAIN_FLAGS netlink dumping.

 include/net/netfilter/nf_tables.h        | 13 +++-
 include/uapi/linux/netfilter/nf_tables.h |  1 +
 net/netfilter/nf_tables_api.c            | 78 ++++++++++++++++++++----
 net/netfilter/nft_immediate.c            | 51 ++++++++++++++++
 4 files changed, 130 insertions(+), 13 deletions(-)
include/net/netfilter/nf_tables.h +12 -1
index 6d1e7da6e00a..0ebbe000bb0a 100644
@@ -899,6 +899,8 @@ static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
 	return (void *)&rule->data[rule->dlen];
 }
 
+void nf_tables_rule_destroy(const struct nft_ctx *ctx, struct nft_rule *rule);
+
 static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,
 					    struct nft_regs *regs,
 					    const struct nft_pktinfo *pkt)
@@ -944,7 +946,8 @@ struct nft_chain {
 	struct nft_table		*table;
 	u64				handle;
 	u32				use;
-	u8				flags:6,
+	u8				flags:5,
+					bound:1,
 					genmask:2;
 	char				*name;
 
@@ -989,6 +992,14 @@ int nft_chain_validate_dependency(const struct nft_chain *chain,
 int nft_chain_validate_hooks(const struct nft_chain *chain,
                              unsigned int hook_flags);
 
+static inline bool nft_chain_is_bound(struct nft_chain *chain)
+{
+	return (chain->flags & NFT_CHAIN_BINDING) && chain->bound;
+}
+
+void nft_chain_del(struct nft_chain *chain);
+void nf_tables_chain_destroy(struct nft_ctx *ctx);
+
 struct nft_stats {
 	u64			bytes;
 	u64			pkts;
include/uapi/linux/netfilter/nf_tables.h +1 -0
index 2cf7cc3b50c1..e00b4ae6174e 100644
@@ -187,6 +187,7 @@ enum nft_table_attributes {
 enum nft_chain_flags {
 	NFT_CHAIN_BASE		= (1 << 0),
 	NFT_CHAIN_HW_OFFLOAD	= (1 << 1),
+	NFT_CHAIN_BINDING	= (1 << 2),
 };
 
 /**
net/netfilter/nf_tables_api.c +66 -12

168 lines not on this page · raw message

net/netfilter/nft_immediate.c +51 -0

69 lines not on this page · raw message

Signature · 1 line
2.20.1