xt_percpu_counter_alloc(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… xt_percpu_counter_alloc(9) β€” the kernel API manual, bestie edition πŸŽ€

okay so picture this: it's a 9 manual page, kernel API manual energy, and the star of the show is xt_percpu_counter_alloc ✨ she allocates x_tables rule counters and she does it well. let's get into it 🫢


✨ NAME ✨

xt_percpu_counter_alloc β€” allocate x_tables rule counter πŸ‘‘


🌸 SYNOPSIS 🌸

bool xt_percpu_counter_alloc (struct xt_percpu_counter_alloc_state
*state , struct xt_counters *counter );

literally just those two args, no cap πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • state β€” pointer to xt_percpu allocation state. she's the vibe keeper of where everything's at πŸ“
  • counter β€” pointer to the counter struct inside the ip(6)/arpt_entry struct. iykyk, it lives nested in there πŸͺ†

πŸ’– DESCRIPTION πŸ’–

On SMP, the packet counter [ ip(6)t_entry->counters.pcnt ] will then contain the address of the real (percpu) counter. yes bestie, it's holding an address now, not the number itself β€” the plot twist of it all 😭

Rule evaluation needs to use the xt_get_this_cpu_counter helper to fetch the real percpu counter. don't forget the helper, she's essential πŸ”‘

To speed up allocation and improve data locality, a 4kb block is allocated β€” efficiency queen 🌈

⚠️ and this is the big one: freeing any counter may free an entire block, so all counters allocated using the same state must be freed at the same time. like, all of them, together, at once, no stragglers πŸ’€ this is a group project where everyone actually has to leave at the same time fr fr

xt_percpu_counter_alloc_state contains the base address of the allocated page and the current sub-offset. that's it, that's the whole struct's personality πŸŽ€

returns false on error πŸ™ˆ so check your return value, bestie, always.


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./net/netfilter/x_tables.c, plus the whole friend group: xt_check_proc_name(9), xt_check_entry_offsets(9), xt_alloc_entry_offsets(9), xt_find_jump_offset(9), xt_copy_counters(9), xt_unregister_table_pre_exit(9), xt_unregister_table_exit(9), xt_hook_ops_alloc(9) 🌟 go say hi to all of them.


and that's the page!! 🧚 source/version lives at ./net/netfilter, dated October 2026, and the header/footer both already told you it's xt_percpu_counter_alloc(9) β€” slay, you're caught up πŸ’œπŸ“

πŸ“¦ where this page comes from