net/ipv6/calipso.c
Source file repositories/reference/linux-study-clean/net/ipv6/calipso.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv6/calipso.c- Extension
.c- Size
- 39017 bytes
- Lines
- 1480
- 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/init.hlinux/types.hlinux/rcupdate.hlinux/list.hlinux/spinlock.hlinux/string.hlinux/jhash.hlinux/audit.hlinux/slab.hnet/ip.hnet/icmp.hnet/tcp.hnet/netlabel.hnet/calipso.hlinux/atomic.hlinux/bug.hlinux/unaligned.hlinux/crc-ccitt.h
Detected Declarations
struct calipso_map_cache_bktstruct calipso_map_cache_entryfunction calipso_cache_entry_freefunction calipso_map_cache_hashfunction calipso_cache_initfunction calipso_cache_invalidatefunction list_for_each_entry_safefunction calipso_cache_checkfunction calipso_cache_addfunction typefunction calipso_doi_freefunction call_rcufunction calipso_doi_removefunction calipso_doi_putdeffunction calipso_doi_getdeffunction calipso_doi_walkfunction optionfunction calipso_map_cat_htonfunction calipso_map_cat_ntohfunction calipso_pad_writefunction writtenfunction calipso_opt_updatefunction calipso_tlv_lenfunction optionfunction calipso_opt_insertfunction optionfunction calipso_opt_getattrfunction calipso_sock_getattrfunction calipso_sock_setattrfunction calipso_sock_delattrfunction calipso_req_setattrfunction calipso_req_delattrfunction calipso_skbuff_setattrfunction calipso_skbuff_delattrfunction calipso_initfunction calipso_exit
Annotated Snippet
struct calipso_map_cache_bkt {
spinlock_t lock;
u32 size;
struct list_head list;
};
struct calipso_map_cache_entry {
u32 hash;
unsigned char *key;
size_t key_len;
struct netlbl_lsm_cache *lsm_data;
u32 activity;
struct list_head list;
};
static struct calipso_map_cache_bkt *calipso_cache;
static void calipso_cache_invalidate(void);
static void calipso_doi_putdef(struct calipso_doi *doi_def);
/* Label Mapping Cache Functions
*/
/**
* calipso_cache_entry_free - Frees a cache entry
* @entry: the entry to free
*
* Description:
* This function frees the memory associated with a cache entry including the
* LSM cache data if there are no longer any users, i.e. reference count == 0.
*
*/
static void calipso_cache_entry_free(struct calipso_map_cache_entry *entry)
{
if (entry->lsm_data)
netlbl_secattr_cache_free(entry->lsm_data);
kfree(entry->key);
kfree(entry);
}
/**
* calipso_map_cache_hash - Hashing function for the CALIPSO cache
* @key: the hash key
* @key_len: the length of the key in bytes
*
* Description:
* The CALIPSO tag hashing function. Returns a 32-bit hash value.
*
*/
static u32 calipso_map_cache_hash(const unsigned char *key, u32 key_len)
{
return jhash(key, key_len, 0);
}
/**
* calipso_cache_init - Initialize the CALIPSO cache
*
* Description:
* Initializes the CALIPSO label mapping cache, this function should be called
* before any of the other functions defined in this file. Returns zero on
* success, negative values on error.
*
*/
static int __init calipso_cache_init(void)
{
u32 iter;
calipso_cache = kzalloc_objs(struct calipso_map_cache_bkt,
CALIPSO_CACHE_BUCKETS);
if (!calipso_cache)
return -ENOMEM;
for (iter = 0; iter < CALIPSO_CACHE_BUCKETS; iter++) {
spin_lock_init(&calipso_cache[iter].lock);
calipso_cache[iter].size = 0;
INIT_LIST_HEAD(&calipso_cache[iter].list);
}
return 0;
}
/**
* calipso_cache_invalidate - Invalidates the current CALIPSO cache
*
* Description:
* Invalidates and frees any entries in the CALIPSO cache. Returns zero on
* success and negative values on failure.
*
Annotation
- Immediate include surface: `linux/init.h`, `linux/types.h`, `linux/rcupdate.h`, `linux/list.h`, `linux/spinlock.h`, `linux/string.h`, `linux/jhash.h`, `linux/audit.h`.
- Detected declarations: `struct calipso_map_cache_bkt`, `struct calipso_map_cache_entry`, `function calipso_cache_entry_free`, `function calipso_map_cache_hash`, `function calipso_cache_init`, `function calipso_cache_invalidate`, `function list_for_each_entry_safe`, `function calipso_cache_check`, `function calipso_cache_add`, `function type`.
- 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.