History

netfilter: ipset: add and use mtype_del_cidr_all helper

Reduces size of upcoming rhashtable conversion.

Florian Westphal committed 3 months ago

Commit cdd97fa1 parent c2667691 file · +16 −18Browse files

Unified · Split

net/netfilter/ipset/ip_set_hash_gen.h+16−18
@@ -195,6 +195,7 @@ static const union nf_inet_addr zeromask = {}; · 194 unmodified lines
195195 #undef mtype_ext_cleanup
196196 #undef mtype_add_cidr
197197 #undef mtype_del_cidr
198+#undef mtype_del_cidr_all
198199 #undef mtype_ahash_memsize
199200 #undef mtype_flush
200201 #undef mtype_destroy
@@ -242,6 +243,7 @@ static const union nf_inet_addr zeromask = {}; · 41 unmodified lines
242243 #define mtype_ext_cleanup IPSET_TOKEN(MTYPE, _ext_cleanup)
243244 #define mtype_add_cidr IPSET_TOKEN(MTYPE, _add_cidr)
244245 #define mtype_del_cidr IPSET_TOKEN(MTYPE, _del_cidr)
246+#define mtype_del_cidr_all IPSET_TOKEN(MTYPE, _del_cidr_all)
245247 #define mtype_ahash_memsize IPSET_TOKEN(MTYPE, _ahash_memsize)
246248 #define mtype_flush IPSET_TOKEN(MTYPE, _flush)
247249 #define mtype_destroy IPSET_TOKEN(MTYPE, _destroy)
@@ -410,6 +412,17 @@ unlock: · 162 unmodified lines
410412 }
411413 #endif
412414
415+static void
416+mtype_del_cidr_all(struct ip_set *set, struct htype *h, const struct mtype_elem *data)
417+{
418+#ifdef IP_SET_HASH_WITH_NETS
419+ int k;
420+
421+ for (k = 0; k < IPSET_NET_COUNT; k++)
422+ mtype_del_cidr(set, h, DCIDR_GET(data->cidr, k), k);
423+#endif
424+}
425+
413426 /* Calculate the actual memory size of the set data */
414427 static size_t
415428 mtype_ahash_memsize(const struct htype *h, const struct htable *t)
@@ -551,9 +564,6 @@ mtype_gc_do(struct ip_set *set, struct htype *h, struct htable *t, u32 r) · 135 unmodified lines
551564 struct mtype_elem *data;
552565 u32 i, j, d;
553566 size_t dsize = set->dsize;
554−#ifdef IP_SET_HASH_WITH_NETS
555− u8 k;
556−#endif
557567 u8 pos, htable_bits = t->htable_bits;
558568
559569 spin_lock_bh(&t->hregion[r].lock);
@@ -574,11 +584,7 @@ mtype_gc_do(struct ip_set *set, struct htype *h, struct htable *t, u32 r) · 14 unmodified lines
574584 pr_debug("expired %u/%u\n", i, j);
575585 clear_bit(j, n->used);
576586 smp_mb__after_atomic();
577−#ifdef IP_SET_HASH_WITH_NETS
578− for (k = 0; k < IPSET_NET_COUNT; k++)
579− mtype_del_cidr(set, h,
580− DCIDR_GET(data->cidr, k), k);
581−#endif
587+ mtype_del_cidr_all(set, h, data);
582588 t->hregion[r].elements--;
583589 ip_set_ext_destroy(set, data);
584590 d++;
@@ -1004,11 +1010,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, · 419 unmodified lines
10041010 j = 0;
10051011 data = ahash_data(n, j, set->dsize);
10061012 if (!deleted) {
1007−#ifdef IP_SET_HASH_WITH_NETS
1008− for (i = 0; i < IPSET_NET_COUNT; i++)
1009− mtype_del_cidr(set, h,
1010− DCIDR_GET(data->cidr, i), i);
1011−#endif
1013+ mtype_del_cidr_all(set, h, data);
10121014 ip_set_ext_destroy(set, data);
10131015 t->hregion[r].elements--;
10141016 }
@@ -1163,11 +1165,7 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, · 148 unmodified lines
11631165 if (i + 1 == pos)
11641166 smp_store_release(&n->pos, --pos);
11651167 t->hregion[r].elements--;
1166−#ifdef IP_SET_HASH_WITH_NETS
1167− for (j = 0; j < IPSET_NET_COUNT; j++)
1168− mtype_del_cidr(set, h,
1169− DCIDR_GET(d->cidr, j), j);
1170−#endif
1168+ mtype_del_cidr_all(set, h, d);
11711169 ip_set_ext_destroy(set, data);
11721170
11731171 if (t->resizing && ext && ext->target) {

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