net/netlabel/netlabel_unlabeled.c
Source file repositories/reference/linux-study-clean/net/netlabel/netlabel_unlabeled.c
File Facts
- System
- Linux kernel
- Corpus path
net/netlabel/netlabel_unlabeled.c- Extension
.c- Size
- 42103 bytes
- Lines
- 1538
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/rcupdate.hlinux/list.hlinux/spinlock.hlinux/socket.hlinux/string.hlinux/skbuff.hlinux/audit.hlinux/in.hlinux/in6.hlinux/ip.hlinux/ipv6.hlinux/notifier.hlinux/netdevice.hlinux/security.hlinux/slab.hnet/sock.hnet/netlink.hnet/genetlink.hnet/ip.hnet/ipv6.hnet/net_namespace.hnet/netlabel.hasm/bug.hlinux/atomic.hnetlabel_user.hnetlabel_addrlist.hnetlabel_domainhash.hnetlabel_unlabeled.hnetlabel_mgmt.h
Detected Declarations
struct netlbl_unlhsh_tblstruct netlbl_unlhsh_addr4struct netlbl_unlhsh_addr6struct netlbl_unlhsh_ifacestruct netlbl_unlhsh_walk_argfunction call_rcufunction netlbl_af4list_foreach_safefunction netlbl_unlhsh_hashfunction netlbl_unlhsh_add_addr4function netlbl_unlhsh_add_addr6function netlbl_unlhsh_addfunction netlbl_unlhsh_remove_addr4function netlbl_unlhsh_remove_addr6function netlbl_unlhsh_condremove_ifacefunction netlbl_unlhsh_removefunction netlbl_unlhsh_netdev_handlerfunction netlbl_unlabel_acceptflg_setfunction netlbl_unlabel_addrinfo_getfunction netlbl_unlabel_acceptfunction netlbl_unlabel_listfunction netlbl_unlabel_staticaddfunction netlbl_unlabel_staticadddeffunction netlbl_unlabel_staticremovefunction netlbl_unlabel_staticremovedeffunction netlbl_unlabel_staticlist_genfunction netlbl_unlabel_staticlistfunction list_for_each_entry_rcufunction netlbl_af4list_foreach_rcufunction netlbl_af6list_foreach_rcufunction netlbl_unlabel_staticlistdeffunction netlbl_af4list_foreach_rcufunction netlbl_unlabel_genl_initfunction netlbl_unlabel_initfunction netlbl_unlabel_getattrfunction netlbl_unlabel_defconf
Annotated Snippet
struct netlbl_unlhsh_tbl {
struct list_head *tbl;
u32 size;
};
#define netlbl_unlhsh_addr4_entry(iter) \
container_of(iter, struct netlbl_unlhsh_addr4, list)
struct netlbl_unlhsh_addr4 {
u32 secid;
struct netlbl_af4list list;
struct rcu_head rcu;
};
#define netlbl_unlhsh_addr6_entry(iter) \
container_of(iter, struct netlbl_unlhsh_addr6, list)
struct netlbl_unlhsh_addr6 {
u32 secid;
struct netlbl_af6list list;
struct rcu_head rcu;
};
struct netlbl_unlhsh_iface {
int ifindex;
struct list_head addr4_list;
struct list_head addr6_list;
u32 valid;
struct list_head list;
struct rcu_head rcu;
};
/* Argument struct for netlbl_unlhsh_walk() */
struct netlbl_unlhsh_walk_arg {
struct netlink_callback *nl_cb;
struct sk_buff *skb;
u32 seq;
};
/* Unlabeled connection hash table */
/* updates should be so rare that having one spinlock for the entire
* hash table should be okay */
static DEFINE_SPINLOCK(netlbl_unlhsh_lock);
#define netlbl_unlhsh_rcu_deref(p) \
rcu_dereference_check(p, lockdep_is_held(&netlbl_unlhsh_lock))
static struct netlbl_unlhsh_tbl __rcu *netlbl_unlhsh;
static struct netlbl_unlhsh_iface __rcu *netlbl_unlhsh_def;
/* Accept unlabeled packets flag */
static u8 netlabel_unlabel_acceptflg;
/* NetLabel Generic NETLINK unlabeled family */
static struct genl_family netlbl_unlabel_gnl_family;
/* NetLabel Netlink attribute policy */
static const struct nla_policy netlbl_unlabel_genl_policy[NLBL_UNLABEL_A_MAX + 1] = {
[NLBL_UNLABEL_A_ACPTFLG] = { .type = NLA_U8 },
[NLBL_UNLABEL_A_IPV6ADDR] =
NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
[NLBL_UNLABEL_A_IPV6MASK] =
NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
[NLBL_UNLABEL_A_IPV4ADDR] =
NLA_POLICY_EXACT_LEN(sizeof(struct in_addr)),
[NLBL_UNLABEL_A_IPV4MASK] =
NLA_POLICY_EXACT_LEN(sizeof(struct in_addr)),
[NLBL_UNLABEL_A_IFACE] = { .type = NLA_NUL_STRING,
.len = IFNAMSIZ - 1 },
[NLBL_UNLABEL_A_SECCTX] = { .type = NLA_BINARY }
};
/*
* Unlabeled Connection Hash Table Functions
*/
/**
* netlbl_unlhsh_free_iface - Frees an interface entry from the hash table
* @entry: the entry's RCU field
*
* Description:
* This function is designed to be used as a callback to the call_rcu()
* function so that memory allocated to a hash table interface entry can be
* released safely. It is important to note that this function does not free
* the IPv4 and IPv6 address lists contained as part of an interface entry. It
* is up to the rest of the code to make sure an interface entry is only freed
* once it's address lists are empty.
*
*/
static void netlbl_unlhsh_free_iface(struct rcu_head *entry)
{
struct netlbl_unlhsh_iface *iface;
struct netlbl_af4list *iter4;
struct netlbl_af4list *tmp4;
Annotation
- Immediate include surface: `linux/types.h`, `linux/rcupdate.h`, `linux/list.h`, `linux/spinlock.h`, `linux/socket.h`, `linux/string.h`, `linux/skbuff.h`, `linux/audit.h`.
- Detected declarations: `struct netlbl_unlhsh_tbl`, `struct netlbl_unlhsh_addr4`, `struct netlbl_unlhsh_addr6`, `struct netlbl_unlhsh_iface`, `struct netlbl_unlhsh_walk_arg`, `function call_rcu`, `function netlbl_af4list_foreach_safe`, `function netlbl_unlhsh_hash`, `function netlbl_unlhsh_add_addr4`, `function netlbl_unlhsh_add_addr6`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.