Skip to contentSkip to conversation

netfilter: nf_tables: add support to destroy operation

PATCH Superseded Fernando Fernandez Mancera 2 participants 3 messages Oct 28, 2022 – Oct 29, 2022

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: nf_tables: add support to destroy operation

Introduce NFT_MSG_DESTROY* message type. The destroy operation performs a delete operation but ignoring the ENOENT errors.

---
v1: initial patch
v2: fix bug on rule destroy without handle

---
 include/uapi/linux/netfilter/nf_tables.h | 14 ++++++
 net/netfilter/nf_tables_api.c            | 63 ++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +14 -0
index 466fd3f4447c..0442335693fe 100644
@@ -97,6 +97,13 @@ enum nft_verdicts {
  * @NFT_MSG_NEWFLOWTABLE: add new flow table (enum nft_flowtable_attributes)
  * @NFT_MSG_GETFLOWTABLE: get flow table (enum nft_flowtable_attributes)
  * @NFT_MSG_DELFLOWTABLE: delete flow table (enum nft_flowtable_attributes)
+ * @NFT_MSG_DESTROYTABLE: destroy a table (enum nft_table_attributes)
+ * @NFT_MSG_DESTROYCHAIN: destroy a chain (enum nft_chain_attributes)
+ * @NFT_MSG_DESTROYRULE: destroy a rule (enum nft_rule_attributes)
+ * @NFT_MSG_DESTROYSET: destroy a set (enum nft_set_attributes)
+ * @NFT_MSG_DESTROYSETELEM: destroy a set element (enum nft_set_elem_attributes)
+ * @NFT_MSG_DESTROYOBJ: destroy a stateful object (enum nft_object_attributes)
+ * @NFT_MSG_DESTROYFLOWTABLE: destroy flow table (enum nft_flowtable_attributes)
  */
 enum nf_tables_msg_types {
 	NFT_MSG_NEWTABLE,
@@ -124,6 +131,13 @@ enum nf_tables_msg_types {
 	NFT_MSG_NEWFLOWTABLE,
 	NFT_MSG_GETFLOWTABLE,
 	NFT_MSG_DELFLOWTABLE,
+	NFT_MSG_DESTROYTABLE,
+	NFT_MSG_DESTROYCHAIN,
+	NFT_MSG_DESTROYRULE,
+	NFT_MSG_DESTROYSET,
+	NFT_MSG_DESTROYSETELEM,
+	NFT_MSG_DESTROYOBJ,
+	NFT_MSG_DESTROYFLOWTABLE,
 	NFT_MSG_MAX,
 };
 
net/netfilter/nf_tables_api.c +63 -0

147 lines not on this page · raw message

Signature · 1 line
2.30.2
reviewer
#1 lore raw

Hi,

On Fri, Oct 28, 2022 at 12:05:31PM +0200, Fernando Fernandez Mancera wrote:
[...]

net/netfilter/nf_tables_api.c static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info, · line 3650

Quoted 10 lines
net/netfilter/nf_tables_api.c +3 -0
@@ -3636,6 +3642,9 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
 		if (nla[NFTA_RULE_HANDLE]) {
 			rule = nft_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
 			if (IS_ERR(rule)) {
+				if (PTR_ERR(rule) == -ENOENT &&
+				    NFNL_MSG_TYPE(info->nlh->nlmsg_type) == NFT_MSG_DESTROYRULE)
+					return 0;
 				NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_HANDLE]);
 				return PTR_ERR(rule);
 			}

I guess you're exceeding the 80 column limit here? Doesn't checkpatch.pl complain?

Cheers, Phil

#2 lore raw

Hi,

Quoted 4 lines · Phil Sutter

Hi,

On Fri, Oct 28, 2022 at 12:05:31PM +0200, Fernando Fernandez Mancera wrote:
[...]

Quoted 14 lines

net/netfilter/nf_tables_api.c static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info, · line 3650

Quoted 10 lines
net/netfilter/nf_tables_api.c +3 -0
@@ -3636,6 +3642,9 @@ static int nf_tables_delrule(struct sk_buff *skb, const struct nfnl_info *info,
  		if (nla[NFTA_RULE_HANDLE]) {
  			rule = nft_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
  			if (IS_ERR(rule)) {
+				if (PTR_ERR(rule) == -ENOENT &&
+				    NFNL_MSG_TYPE(info->nlh->nlmsg_type) == NFT_MSG_DESTROYRULE)
+					return 0;
  				NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_HANDLE]);
  				return PTR_ERR(rule);
  			}

I guess you're exceeding the 80 column limit here? Doesn't checkpatch.pl complain?

Nope, checkpatch.pl checks for a 100 column limit. Anyway, let me send a v3 as I prefer the 80 column limit.

Thanks,
Fernando.

Quoted 1 line

Cheers, Phil