net/netlabel/netlabel_domainhash.c
Source file repositories/reference/linux-study-clean/net/netlabel/netlabel_domainhash.c
File Facts
- System
- Linux kernel
- Corpus path
net/netlabel/netlabel_domainhash.c- Extension
.c- Size
- 28050 bytes
- Lines
- 971
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/rculist.hlinux/skbuff.hlinux/spinlock.hlinux/string.hlinux/audit.hlinux/slab.hnet/netlabel.hnet/cipso_ipv4.hnet/calipso.hasm/bug.hnetlabel_mgmt.hnetlabel_addrlist.hnetlabel_calipso.hnetlabel_domainhash.hnetlabel_user.h
Detected Declarations
struct netlbl_domhsh_tblfunction call_rcufunction netlbl_af4list_foreach_safefunction netlbl_af6list_foreach_safefunction netlbl_domhsh_hashfunction netlbl_family_matchfunction netlbl_domhsh_audit_addfunction netlbl_domhsh_validatefunction netlbl_af4list_foreachfunction netlbl_af6list_foreachfunction netlbl_user_initfunction handlerfunction netlbl_af4list_foreach_rcufunction netlbl_af6list_foreach_rcufunction netlbl_af4list_foreach_safefunction netlbl_af6list_foreach_safefunction handlerfunction handlerfunction netlbl_af6list_foreach_rcufunction netlbl_domhsh_remove_af4function netlbl_domhsh_remove_af6function handlerfunction netlbl_domhsh_remove_defaultfunction netlbl_domhsh_walkfunction list_for_each_entry_rcu
Annotated Snippet
struct netlbl_domhsh_tbl {
struct list_head *tbl;
u32 size;
};
/* Domain hash table */
/* updates should be so rare that having one spinlock for the entire hash table
* should be okay */
static DEFINE_SPINLOCK(netlbl_domhsh_lock);
#define netlbl_domhsh_rcu_deref(p) \
rcu_dereference_check(p, lockdep_is_held(&netlbl_domhsh_lock))
static struct netlbl_domhsh_tbl __rcu *netlbl_domhsh;
static struct netlbl_dom_map __rcu *netlbl_domhsh_def_ipv4;
static struct netlbl_dom_map __rcu *netlbl_domhsh_def_ipv6;
/*
* Domain Hash Table Helper Functions
*/
/**
* netlbl_domhsh_free_entry - Frees a domain hash table entry
* @entry: the entry's RCU field
*
* Description:
* This function is designed to be used as a callback to the call_rcu()
* function so that the memory allocated to a hash table entry can be released
* safely.
*
*/
static void netlbl_domhsh_free_entry(struct rcu_head *entry)
{
struct netlbl_dom_map *ptr;
struct netlbl_af4list *iter4;
struct netlbl_af4list *tmp4;
#if IS_ENABLED(CONFIG_IPV6)
struct netlbl_af6list *iter6;
struct netlbl_af6list *tmp6;
#endif /* IPv6 */
ptr = container_of(entry, struct netlbl_dom_map, rcu);
if (ptr->def.type == NETLBL_NLTYPE_ADDRSELECT) {
netlbl_af4list_foreach_safe(iter4, tmp4,
&ptr->def.addrsel->list4) {
netlbl_af4list_remove_entry(iter4);
kfree(netlbl_domhsh_addr4_entry(iter4));
}
#if IS_ENABLED(CONFIG_IPV6)
netlbl_af6list_foreach_safe(iter6, tmp6,
&ptr->def.addrsel->list6) {
netlbl_af6list_remove_entry(iter6);
kfree(netlbl_domhsh_addr6_entry(iter6));
}
#endif /* IPv6 */
kfree(ptr->def.addrsel);
}
kfree(ptr->domain);
kfree(ptr);
}
/**
* netlbl_domhsh_hash - Hashing function for the domain hash table
* @key: the domain name to hash
*
* Description:
* This is the hashing function for the domain hash table, it returns the
* correct bucket number for the domain. The caller is responsible for
* ensuring that the hash table is protected with either a RCU read lock or the
* hash table lock.
*
*/
static u32 netlbl_domhsh_hash(const char *key)
{
u32 iter;
u32 val;
u32 len;
/* This is taken (with slight modification) from
* security/selinux/ss/symtab.c:symhash() */
for (iter = 0, val = 0, len = strlen(key); iter < len; iter++)
val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter];
return val & (netlbl_domhsh_rcu_deref(netlbl_domhsh)->size - 1);
}
static bool netlbl_family_match(u16 f1, u16 f2)
{
return (f1 == f2) || (f1 == AF_UNSPEC) || (f2 == AF_UNSPEC);
}
/**
Annotation
- Immediate include surface: `linux/types.h`, `linux/rculist.h`, `linux/skbuff.h`, `linux/spinlock.h`, `linux/string.h`, `linux/audit.h`, `linux/slab.h`, `net/netlabel.h`.
- Detected declarations: `struct netlbl_domhsh_tbl`, `function call_rcu`, `function netlbl_af4list_foreach_safe`, `function netlbl_af6list_foreach_safe`, `function netlbl_domhsh_hash`, `function netlbl_family_match`, `function netlbl_domhsh_audit_add`, `function netlbl_domhsh_validate`, `function netlbl_af4list_foreach`, `function netlbl_af6list_foreach`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.