lib/nlattr.c
Source file repositories/reference/linux-study-clean/lib/nlattr.c
File Facts
- System
- Linux kernel
- Corpus path
lib/nlattr.c- Extension
.c- Size
- 28561 bytes
- Lines
- 1170
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/export.hlinux/kernel.hlinux/errno.hlinux/jiffies.hlinux/nospec.hlinux/skbuff.hlinux/string.hlinux/types.hnet/netlink.h
Detected Declarations
function validate_nla_bitfield32function nla_validate_arrayfunction nla_for_each_attrfunction nla_get_range_unsignedfunction nla_validate_range_unsignedfunction nla_get_range_signedfunction nla_validate_int_range_signedfunction nla_validate_int_rangefunction nla_validate_maskfunction validate_nlafunction __nla_validate_parsefunction nla_for_each_attrfunction __nla_validatefunction nla_policy_lenfunction __nla_parsefunction strscpyfunction nla_memcpyfunction nla_memcmpfunction nla_strcmpfunction __nla_putfunction __nla_put_64bitfunction __nla_put_nohdrfunction nla_putfunction nla_put_64bitfunction nla_put_nohdrfunction nla_appendexport __nla_validateexport nla_policy_lenexport __nla_parseexport nla_findexport nla_strscpyexport nla_strdupexport nla_memcpyexport nla_memcmpexport nla_strcmpexport __nla_reserveexport __nla_reserve_64bitexport __nla_reserve_nohdrexport nla_reserveexport nla_reserve_64bitexport nla_reserve_nohdrexport __nla_putexport __nla_put_64bitexport __nla_put_nohdrexport nla_putexport nla_put_64bitexport nla_put_nohdrexport nla_append
Annotated Snippet
if (nla_len(entry) < NLA_HDRLEN) {
NL_SET_ERR_MSG_ATTR_POL(extack, entry, policy,
"Array element too short");
return -ERANGE;
}
ret = __nla_validate_parse(nla_data(entry), nla_len(entry),
maxtype, policy, validate, extack,
NULL, depth + 1);
if (ret < 0)
return ret;
}
return 0;
}
void nla_get_range_unsigned(const struct nla_policy *pt,
struct netlink_range_validation *range)
{
WARN_ON_ONCE(pt->validation_type != NLA_VALIDATE_RANGE_PTR &&
(pt->min < 0 || pt->max < 0));
range->min = 0;
switch (pt->type) {
case NLA_U8:
range->max = U8_MAX;
break;
case NLA_U16:
case NLA_BE16:
case NLA_BINARY:
range->max = U16_MAX;
break;
case NLA_U32:
case NLA_BE32:
range->max = U32_MAX;
break;
case NLA_U64:
case NLA_UINT:
case NLA_MSECS:
range->max = U64_MAX;
break;
default:
WARN_ON_ONCE(1);
return;
}
switch (pt->validation_type) {
case NLA_VALIDATE_RANGE:
case NLA_VALIDATE_RANGE_WARN_TOO_LONG:
range->min = pt->min;
range->max = pt->max;
break;
case NLA_VALIDATE_RANGE_PTR:
*range = *pt->range;
break;
case NLA_VALIDATE_MIN:
range->min = pt->min;
break;
case NLA_VALIDATE_MAX:
range->max = pt->max;
break;
default:
break;
}
}
static int nla_validate_range_unsigned(const struct nla_policy *pt,
const struct nlattr *nla,
struct netlink_ext_ack *extack,
unsigned int validate)
{
struct netlink_range_validation range;
u64 value;
switch (pt->type) {
case NLA_U8:
value = nla_get_u8(nla);
break;
case NLA_U16:
value = nla_get_u16(nla);
break;
case NLA_U32:
value = nla_get_u32(nla);
break;
case NLA_U64:
value = nla_get_u64(nla);
break;
case NLA_UINT:
value = nla_get_uint(nla);
Annotation
- Immediate include surface: `linux/export.h`, `linux/kernel.h`, `linux/errno.h`, `linux/jiffies.h`, `linux/nospec.h`, `linux/skbuff.h`, `linux/string.h`, `linux/types.h`.
- Detected declarations: `function validate_nla_bitfield32`, `function nla_validate_array`, `function nla_for_each_attr`, `function nla_get_range_unsigned`, `function nla_validate_range_unsigned`, `function nla_get_range_signed`, `function nla_validate_int_range_signed`, `function nla_validate_int_range`, `function nla_validate_mask`, `function validate_nla`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
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.