net/netlabel/netlabel_mgmt.c
Source file repositories/reference/linux-study-clean/net/netlabel/netlabel_mgmt.c
File Facts
- System
- Linux kernel
- Corpus path
net/netlabel/netlabel_mgmt.c- Extension
.c- Size
- 22039 bytes
- Lines
- 843
- 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/socket.hlinux/string.hlinux/skbuff.hlinux/in.hlinux/in6.hlinux/slab.hnet/sock.hnet/netlink.hnet/genetlink.hnet/ip.hnet/ipv6.hnet/netlabel.hnet/cipso_ipv4.hnet/calipso.hlinux/atomic.hnetlabel_calipso.hnetlabel_domainhash.hnetlabel_user.hnetlabel_mgmt.h
Detected Declarations
struct netlbl_domhsh_walk_argfunction netlbl_mgmt_add_commonfunction netlbl_mgmt_listentryfunction netlbl_af4list_foreach_rcufunction netlbl_af6list_foreach_rcufunction netlbl_mgmt_addfunction netlbl_mgmt_removefunction netlbl_domhsh_walkfunction netlbl_mgmt_listallfunction netlbl_mgmt_adddeffunction netlbl_mgmt_removedeffunction netlbl_mgmt_listdeffunction netlbl_mgmt_protocolsfunction netlbl_mgmt_protocolsfunction netlbl_mgmt_versionfunction netlbl_mgmt_genl_init
Annotated Snippet
struct netlbl_domhsh_walk_arg {
struct netlink_callback *nl_cb;
struct sk_buff *skb;
u32 seq;
};
/* NetLabel Generic NETLINK CIPSOv4 family */
static struct genl_family netlbl_mgmt_gnl_family;
/* NetLabel Netlink attribute policy */
static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = {
[NLBL_MGMT_A_DOMAIN] = { .type = NLA_NUL_STRING },
[NLBL_MGMT_A_PROTOCOL] = { .type = NLA_U32 },
[NLBL_MGMT_A_VERSION] = { .type = NLA_U32 },
[NLBL_MGMT_A_CV4DOI] = { .type = NLA_U32 },
[NLBL_MGMT_A_FAMILY] = { .type = NLA_U16 },
[NLBL_MGMT_A_CLPDOI] = { .type = NLA_U32 },
};
/*
* Helper Functions
*/
/**
* netlbl_mgmt_add_common - Handle an ADD message
* @info: the Generic NETLINK info block
* @audit_info: NetLabel audit information
*
* Description:
* Helper function for the ADD and ADDDEF messages to add the domain mappings
* from the message to the hash table. See netlabel.h for a description of the
* message format. Returns zero on success, negative values on failure.
*
*/
static int netlbl_mgmt_add_common(struct genl_info *info,
struct netlbl_audit *audit_info)
{
void *pmap = NULL;
int ret_val = -EINVAL;
struct netlbl_domaddr_map *addrmap = NULL;
struct cipso_v4_doi *cipsov4 = NULL;
#if IS_ENABLED(CONFIG_IPV6)
struct calipso_doi *calipso = NULL;
#endif
u32 tmp_val;
struct netlbl_dom_map *entry = kzalloc_obj(*entry);
if (!entry)
return -ENOMEM;
entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
entry->domain = kmalloc(tmp_size, GFP_KERNEL);
if (entry->domain == NULL) {
ret_val = -ENOMEM;
goto add_free_entry;
}
nla_strscpy(entry->domain,
info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
}
/* NOTE: internally we allow/use a entry->def.type value of
* NETLBL_NLTYPE_ADDRSELECT but we don't currently allow users
* to pass that as a protocol value because we need to know the
* "real" protocol */
switch (entry->def.type) {
case NETLBL_NLTYPE_UNLABELED:
entry->family =
nla_get_u16_default(info->attrs[NLBL_MGMT_A_FAMILY],
AF_UNSPEC);
break;
case NETLBL_NLTYPE_CIPSOV4:
if (!info->attrs[NLBL_MGMT_A_CV4DOI])
goto add_free_domain;
tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
cipsov4 = cipso_v4_doi_getdef(tmp_val);
if (cipsov4 == NULL)
goto add_free_domain;
entry->family = AF_INET;
entry->def.cipso = cipsov4;
break;
#if IS_ENABLED(CONFIG_IPV6)
case NETLBL_NLTYPE_CALIPSO:
if (!info->attrs[NLBL_MGMT_A_CLPDOI])
goto add_free_domain;
tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CLPDOI]);
calipso = calipso_doi_getdef(tmp_val);
Annotation
- Immediate include surface: `linux/types.h`, `linux/socket.h`, `linux/string.h`, `linux/skbuff.h`, `linux/in.h`, `linux/in6.h`, `linux/slab.h`, `net/sock.h`.
- Detected declarations: `struct netlbl_domhsh_walk_arg`, `function netlbl_mgmt_add_common`, `function netlbl_mgmt_listentry`, `function netlbl_af4list_foreach_rcu`, `function netlbl_af6list_foreach_rcu`, `function netlbl_mgmt_add`, `function netlbl_mgmt_remove`, `function netlbl_domhsh_walk`, `function netlbl_mgmt_listall`, `function netlbl_mgmt_adddef`.
- 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.