[PATCH nf-next v4] net: netfilter: nf_tables_api: Use id allocation.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In nf_tables_set_alloc_name function, remove get_zeroed_page
find_first_zero_bit and set_bit functions. Instead use ida_get_new_above
function as it simplifies the code.

Signed-off-by: Varsha Rao <rvarsha016@xxxxxxxxx>
---
Changes in v2:
- Modified the upper limit of page size.

Changes in v3:
- Used ida_get_new_above instead of ida_simple_get due to internal
  locking.
- Defined macro NFT_SET_IDA_SIZE.
- Modified commit message.

Changes in v4:
- Removed -EAGAIN return value.
- Updated NFT_SET_IDA_SIZE value.

 net/netfilter/nf_tables_api.c | 49 ++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index ca4c4d994ddb..7f6e164607a9 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2919,46 +2919,47 @@ struct nft_set *nft_set_lookup_global(const struct net *net,
 }
 EXPORT_SYMBOL_GPL(nft_set_lookup_global);
 
+#define NFT_SET_IDA_SIZE (8 * _BITUL(12))
+
 static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
 				    const char *name)
 {
 	const struct nft_set *i;
 	const char *p;
-	unsigned long *inuse;
-	unsigned int n = 0, min = 0;
+	int n = 0, id;
+	DEFINE_IDA(inuse);
 
 	p = strchr(name, '%');
 	if (p != NULL) {
 		if (p[1] != 'd' || strchr(p + 2, '%'))
 			return -EINVAL;
 
-		inuse = (unsigned long *)get_zeroed_page(GFP_KERNEL);
-		if (inuse == NULL)
-			return -ENOMEM;
-cont:
-		list_for_each_entry(i, &ctx->table->sets, list) {
-			int tmp;
+	list_for_each_entry(i, &ctx->table->sets, list) {
+		int tmp;
 
-			if (!nft_is_active_next(ctx->net, set))
-				continue;
-			if (!sscanf(i->name, name, &tmp))
-				continue;
-			if (tmp < min || tmp >= min + BITS_PER_BYTE * PAGE_SIZE)
-				continue;
+		if (!nft_is_active_next(ctx->net, set))
+			continue;
+		if (!sscanf(i->name, name, &tmp))
+			continue;
+		if (tmp < 0 || tmp >= NFT_SET_IDA_SIZE)
+			continue;
 
-			set_bit(tmp - min, inuse);
-		}
+		n = ida_get_new_above(&inuse, tmp, &id);
+		if ((n < 0) && (n != -EAGAIN))
+			return n;
+	}
+	n = ida_get_new_above(&inuse, 0, &id);
 
-		n = find_first_zero_bit(inuse, BITS_PER_BYTE * PAGE_SIZE);
-		if (n >= BITS_PER_BYTE * PAGE_SIZE) {
-			min += BITS_PER_BYTE * PAGE_SIZE;
-			memset(inuse, 0, PAGE_SIZE);
-			goto cont;
-		}
-		free_page((unsigned long)inuse);
+	if ((n < 0)  && (n != -EAGAIN)) {
+		if (n == -ENOSPC)
+			ida_destroy(&inuse);
+		return n;
+	}
+
+		ida_destroy(&inuse);
 	}
 
-	set->name = kasprintf(GFP_KERNEL, name, min + n);
+	set->name = kasprintf(GFP_KERNEL, name, id);
 	if (!set->name)
 		return -ENOMEM;
 
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux