nlmsg_for_each_attr(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 nlmsg_for_each_attr (9) β€” Kernel API Manual energy 🌸

okay bestie, welcome to the Kernel API Manual page for nlmsg_for_each_attr. It's not the flashiest function in ./include/net/netlink.h, but she's the reason your netlink attribute loop isn't a hot mess, and honestly? She eats. πŸ’…


✨ NAME ✨

nlmsg_for_each_attr β€” iterate over a stream of attributes πŸ¦‹

Like, the whole entire job. Loop over attributes. That's it, that's the vibe.


🌈 SYNOPSIS 🌈

nlmsg_for_each_attr (pos , nlh , hdrlen , rem );

yes the spacing is exactly like that, don't @ me, it's giving kernel source πŸŽ€


πŸ’– ARGUMENTS πŸ’–

Four of them. Precious. Let's go:

  • pos β€” the loop counter, set to the current attribute as you go. She's the main character, she moves πŸŽ€
  • nlh β€” the netlink message header. The whole reason we're here, lowkey πŸ‘‘
  • hdrlen β€” length of the family specific header. Yes it's a real thing, yes you have to pass it πŸ¦‹
  • rem β€” initialized to len, holds the bytes currently remaining in the stream. Keep an eye on her, she shrinks as you loop 😭
fr fr, rem is not decorative β€” it's tracking what's left in the stream, so please actually pass it correctly 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

Literally the entire netlink squad, no cap. First up, this lives in the kernel file ./include/net/netlink.h:

struct nla_policy(9), struct nl_info(9), enum netlink_validation(9), nlmsg_msg_size(9), nlmsg_total_size(9), nlmsg_padlen(9), nlmsg_data(9), nlmsg_len(9), nlmsg_payload(9), nlmsg_attrdata(9), nlmsg_attrlen(9), nlmsg_ok(9), nlmsg_next(9), nla_parse(9), nla_parse_deprecated(9), nla_parse_deprecated_strict(9), __nlmsg_parse(9), nlmsg_parse(9), nlmsg_parse_deprecated(9), nlmsg_parse_deprecated_strict(9), nlmsg_find_attr(9), nla_validate_deprecated(9), nla_validate(9), nlmsg_validate_deprecated(9), nlmsg_report(9), nlmsg_seq(9), nlmsg_for_each_attr_type(9)

Then the put/append/get-pos girlies:

nlmsg_put(9), nlmsg_append(9), nlmsg_put_answer(9), nlmsg_new(9), nlmsg_new_large(9), nlmsg_end(9), nlmsg_get_pos(9), nlmsg_trim(9), nlmsg_cancel(9), nlmsg_free(9), nlmsg_consume(9), nlmsg_multicast_filtered(9), nlmsg_multicast(9), nlmsg_unicast(9), nlmsg_for_each_msg(9), nl_dump_check_consistent(9)

Attribute fundamentals, the ICONS:

nla_attr_size(9), nla_total_size(9), nla_padlen(9), nla_type(9), nla_data(9), nla_len(9), nla_ok(9), nla_next(9), nla_find_nested(9), nla_parse_nested(9), nla_parse_nested_deprecated(9)

The put squad (all of them, don't skip a single one, I'm serious πŸ’€):

nla_put_u8(9), nla_put_u16(9), nla_put_be16(9), nla_put_net16(9), nla_put_le16(9), nla_put_u32(9), nla_put_uint(9), nla_put_be32(9), nla_put_net32(9), nla_put_le32(9), nla_put_u64_64bit(9), nla_put_be64(9), nla_put_net64(9), nla_put_le64(9), nla_put_s8(9), nla_put_s16(9), nla_put_s32(9), nla_put_s64(9), nla_put_sint(9), nla_put_string(9), nla_put_flag(9), nla_put_msecs(9), nla_put_in_addr(9), nla_put_in6_addr(9), nla_put_bitfield32(9)

The get squad (the whole roster, and yes, defaults included 🌸):

nla_get_u32(9), nla_get_u32_default(9), nla_get_be32(9), nla_get_be32_default(9), nla_get_le32(9), nla_get_le32_default(9), nla_get_u16(9), nla_get_u16_default(9), nla_get_be16(9), nla_get_be16_default(9), nla_get_le16(9), nla_get_le16_default(9), nla_get_u8(9), nla_get_u8_default(9), nla_get_u64(9), nla_get_u64_default(9), nla_get_uint(9), nla_get_uint_default(9), nla_get_be64(9), nla_get_be64_default(9), nla_get_le64(9), nla_get_le64_default(9), nla_get_s32(9), nla_get_s32_default(9), nla_get_s16(9), nla_get_s16_default(9), nla_get_s8(9), nla_get_s8_default(9), nla_get_s64(9), nla_get_s64_default(9), nla_get_sint(9), nla_get_sint_default(9), nla_get_flag(9), nla_get_msecs(9), nla_get_msecs_default(9), nla_get_in_addr(9), nla_get_in_addr_default(9), nla_get_in6_addr(9), nla_get_bitfield32(9)

And the rest of the family, saving the best for last 🧚:

nla_memdup(9), nla_nest_start_noflag(9), nla_nest_start(9), nla_nest_end(9), nla_nest_end_safe(9), nla_nest_cancel(9), nla_put_empty_nest(9), __nla_validate_nested(9), nla_need_padding_for_64bit(9), nla_align_64bit(9), nla_total_size_64bit(9), nla_for_each_attr(9), nla_for_each_attr_type(9), nla_for_each_nested(9), nla_for_each_nested_type(9), nla_is_last(9)


that's the whole page, bestie!! go loop over those attributes and slay ✨

sign-off time 🫢 β€” this little masterpiece lives under ./include/net, and it's stamped October 2026, page nlmsg_for_each_attr(9). mwah, iykyk πŸ’œ

πŸ“¦ where this page comes from