* [PATCH v3] netfilter: nf_tables: delete table via table handle
@ 2018-01-09 8:53 Harsha Sharma
0 siblings, 0 replies; only message in thread
From: Harsha Sharma @ 2018-01-09 8:53 UTC (permalink / raw)
To: pablo, harshasharmaiitr; +Cc: netfilter-devel
This patch add code to delete table via unique table handle and table
family.
Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
---
Changes in v3:
-Remove __nft_table_lookup_byhandle
Changes in v2:
- Remove nf_tables_afinfo_lookup_byhandle
- Change log message
net/netfilter/nf_tables_api.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index dabdd2ed66c8..f12671e0ec48 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -367,6 +367,20 @@ static struct nft_table *nft_table_lookup(const struct nft_af_info *afi,
return NULL;
}
+static struct nft_table *nft_table_lookup_byhandle(const struct nft_af_info *afi,
+ const struct nlattr *nla,
+ u8 genmask)
+{
+ struct nft_table *table;
+
+ list_for_each_entry(table, &afi->tables, list) {
+ if (be64_to_cpu(nla_get_be64(nla)) == table->handle &&
+ nft_active_genmask(table, genmask))
+ return table;
+ }
+ return NULL;
+}
+
static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,
const struct nlattr *nla,
u8 genmask)
@@ -383,6 +397,22 @@ static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,
return ERR_PTR(-ENOENT);
}
+static struct nft_table *nf_tables_table_lookup_byhandle(const struct nft_af_info *afi,
+ const struct nlattr *nla,
+ u8 genmask)
+{
+ struct nft_table *table;
+
+ if (nla == NULL)
+ return ERR_PTR(-EINVAL);
+
+ table = nft_table_lookup_byhandle(afi, nla, genmask);
+ if (table != NULL)
+ return table;
+
+ return ERR_PTR(-ENOENT);
+}
+
static inline u64 nf_tables_alloc_handle(struct nft_table *table)
{
return ++table->hgenerator;
@@ -854,14 +884,18 @@ static int nf_tables_deltable(struct net *net, struct sock *nlsk,
struct nft_ctx ctx;
nft_ctx_init(&ctx, net, skb, nlh, NULL, NULL, NULL, nla);
- if (family == AF_UNSPEC || nla[NFTA_TABLE_NAME] == NULL)
+ if (family == AF_UNSPEC ||
+ (!nla[NFTA_TABLE_NAME] && !nla[NFTA_TABLE_HANDLE]))
return nft_flush(&ctx, family);
afi = nf_tables_afinfo_lookup(net, family, false);
if (IS_ERR(afi))
return PTR_ERR(afi);
+ if (nla[NFTA_TABLE_HANDLE])
+ table = nf_tables_table_lookup_byhandle(afi, nla[NFTA_TABLE_HANDLE], genmask);
+ else
+ table = nf_tables_table_lookup(afi, nla[NFTA_TABLE_NAME], genmask);
- table = nf_tables_table_lookup(afi, nla[NFTA_TABLE_NAME], genmask);
if (IS_ERR(table))
return PTR_ERR(table);
--
2.11.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-01-09 8:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-09 8:53 [PATCH v3] netfilter: nf_tables: delete table via table handle Harsha Sharma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).