STA INFORMATION LIFETIME RULES(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… STA information lifetime rules β€” a sta_info tell-all (section 9, Kernel API Manual)

okay so bestie, this is from the Kernel API Manual, section 9, and it's literally the whole lore of how struct sta_info stays alive (and gets yeeted) inside mac80211. grab a strawberry drink πŸ“ and let's get into it.


πŸ¦‹ DESCRIPTION πŸ¦‹

So. STA info structures (struct sta_info) aren't just vibing alone β€” they're managed in a hash table for faster lookup and a list for iteration. Two whole homes. Main character energy fr. πŸ‘‘

And how are they managed? With RCU, bestie. Like, access to the list and the hash table is protected by RCU. that's the vibe check that keeps everything safe πŸ’«


✨ the allocation era (ownership arc begins)

When you allocate a STA info structure with sta_info_alloc, the caller owns that structure. periodt. it's yours. 🫢

Then you must insert it into the hash table using either:

  • sta_info_insert
  • sta_info_insert_rcu

and here's the tea πŸ‘€ β€” only in the latter case will the pointer still be valid after the call. And heads up, sta_info_insert_rcu acquires an RCU read section but must not be called from within one. like, don't do that. πŸ™ˆ

Also, ngl, the caller may not do much with the STA info before inserting it. In particular:

  • it may not start any mesh peer link management
  • it may not add encryption keys
😭 WARNING bestie: when the insertion fails (sta_info_insert returns non-zero), the structure will have been freed by sta_info_insert! like it's gone. don't touch it. no cap.

🌸 how station entries get added (by mac80211, not you)

Station entries are added by mac80211 when you establish a link with a peer. And because we support different types of interfaces, this means different things depending on the vibe:

  • Regular station β€” we add the AP sta when we receive an association response from the AP. πŸ’Œ
  • IBSS β€” this occurs when we get to know about a peer on the same IBSS.
  • WDS β€” we add the sta for the peer immediately upon device open.
  • AP mode β€” we add stations for each respective station upon request from userspace through nl80211.

πŸ’€ the removal era

In order to remove a STA info structure, various sta_info_destroy_*() calls are available. that's the whole lineup, iconically vague but it's giving options πŸ’…


πŸ‘‘ the ownership plot twist

There is no concept of ownership on a STA entry. plot twist!! 😭 each structure is owned by the global hash table/list until it is removed. it belongs to the collective now.

And every single user of the structure needs to be RCU protected, so that the structure won't be freed before they are done using it. that's the rule, bestie, we don't break it. πŸ”₯


πŸŽ€ SEE ALSO πŸŽ€

go read those too, iykyk 🧚


okay that's the page!! 🌈 this lil masterpiece lives in ./net/mac80211, dropped October 2026, under the Kernel API Manual banner β€” mwah, slay, go protect your pointers responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from