Lines Matching +full:nested +full:- +full:attributes

1 /* SPDX-License-Identifier: GPL-2.0 */
11 * Netlink Messages and Attributes Interface (As Seen On TV)
12 * ------------------------------------------------------------------------
14 * ------------------------------------------------------------------------
17 * <--- nlmsg_total_size(payload) --->
18 * <-- nlmsg_msg_size(payload) ->
19 * +----------+- - -+-------------+- - -+-------- - -
21 * +----------+- - -+-------------+- - -+-------- - -
22 * nlmsg_data(nlh)---^ ^
23 * nlmsg_next(nlh)-----------------------+
26 * <---------------------- nlmsg_len(nlh) --------------------->
27 * <------ hdrlen ------> <- nlmsg_attrlen(nlh, hdrlen) ->
28 * +----------------------+- - -+--------------------------------+
29 * | Family Header | Pad | Attributes |
30 * +----------------------+- - -+--------------------------------+
31 * nlmsg_attrdata(nlh, hdrlen)---^
60 * nlmsg_attrdata(nlh, hdrlen) head of attributes data
61 * nlmsg_attrlen(nlh, hdrlen) length of attributes data
66 * nlmsg_parse() parse attributes of a message
70 * nlmsg_for_each_attr() loop over all attributes
75 * ------------------------------------------------------------------------
76 * Attributes Interface
77 * ------------------------------------------------------------------------
80 * <------- nla_total_size(payload) ------->
81 * <---- nla_attr_size(payload) ----->
82 * +----------+- - -+- - - - - - - - - +- - -+-------- - -
84 * +----------+- - -+- - - - - - - - - +- - -+-------- - -
85 * <- nla_len(nla) -> ^
86 * nla_data(nla)----^ |
87 * nla_next(nla)-----------------------------'
117 * Nested Attributes Construction:
118 * nla_nest_start(skb, type) start a nested attribute
119 * nla_nest_end(skb, nla) finalize a nested attribute
120 * nla_nest_cancel(skb, nla) cancel nested attribute construction
157 * nla_validate() validate a stream of attributes
158 * nla_validate_nested() validate a stream of nested attributes
159 * nla_find() find attribute in stream of attributes
160 * nla_find_nested() find attribute in nested attributes
162 * nla_parse_nested() parse nested attributes
163 * nla_for_each_attr() loop over all attributes
164 * nla_for_each_attr_type() loop over all attributes with the
166 * nla_for_each_nested() loop over the nested attributes
167 * nla_for_each_nested_type() loop over the nested attributes with
201 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
223 * struct nla_policy - attribute validation policy
226 * type-specific validation (e.g. range, function call), see
241 * nested header (or empty); len field is used if
243 * number in the nested policy.
258 * NLA_BITFIELD32 This is a 32-bit bitmap/bitselector attribute and
263 * NLA_NESTED `nested_policy' to a nested policy to validate, must
267 * parse, the nested sub-policies.
268 * NLA_NESTED_ARRAY `nested_policy' points to a nested policy to validate,
272 * NLA_NESTED has the nested attributes directly inside
273 * while an array has the nested attributes at another
294 * of s16 - do that using the NLA_POLICY_FULL_RANGE()
321 * All other Unused - but note that it's a union
325 * All other Unused - but note that it's a union
359 * validation is enforced for all attributes. For existing ones
360 * it should be set at least when new attributes are added to
389 _NLA_POLICY_NESTED(ARRAY_SIZE(policy) - 1, policy)
391 _NLA_POLICY_NESTED_ARRAY(ARRAY_SIZE(policy) - 1, policy)
478 * struct nl_info - netlink source information
483 * @skip_notify_kernel: Skip selected in-kernel notifications
494 * enum netlink_validation - netlink message/attribute validation levels
495 * @NL_VALIDATE_LIBERAL: Old-style "be liberal" validation, not caring about
496 * extra data at the end of the message, attributes being longer than
497 * they should be, or unknown attributes being present.
499 * @NL_VALIDATE_MAXTYPE: Reject attributes > max type; Together with _TRAILING
501 * @NL_VALIDATE_UNSPEC: Reject attributes with NLA_UNSPEC in the policy.
570 * nlmsg_msg_size - length of netlink message not including padding
579 * nlmsg_total_size - length of netlink message including padding
588 * nlmsg_padlen - length of padding at the message's tail
593 return nlmsg_total_size(payload) - nlmsg_msg_size(payload); in nlmsg_padlen()
597 * nlmsg_data - head of message payload
606 * nlmsg_len - length of message payload
611 return nlh->nlmsg_len - NLMSG_HDRLEN; in nlmsg_len()
615 * nlmsg_attrdata - head of attributes data
627 * nlmsg_attrlen - length of attributes data
633 return nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen); in nlmsg_attrlen()
637 * nlmsg_ok - check if the netlink message fits into the remaining bytes
644 nlh->nlmsg_len >= sizeof(struct nlmsghdr) && in nlmsg_ok()
645 nlh->nlmsg_len <= remaining); in nlmsg_ok()
649 * nlmsg_next - next netlink message in message stream
659 int totlen = NLMSG_ALIGN(nlh->nlmsg_len); in nlmsg_next()
661 *remaining -= totlen; in nlmsg_next()
667 * nla_parse - Parse a stream of attributes into a tb buffer
675 * Parses a stream of attributes and stores a pointer to each attribute in
676 * the tb array accessible via the attribute type. Attributes with a type
677 * exceeding maxtype will be rejected, policy must be specified, attributes
692 * nla_parse_deprecated - Parse a stream of attributes into a tb buffer
700 * Parses a stream of attributes and stores a pointer to each attribute in
701 * the tb array accessible via the attribute type. Attributes with a type
702 * exceeding maxtype will be ignored and attributes from the policy are not
703 * always strictly validated (only for new attributes).
717 * nla_parse_deprecated_strict - Parse a stream of attributes into a tb buffer
725 * Parses a stream of attributes and stores a pointer to each attribute in
726 * the tb array accessible via the attribute type. Attributes with a type
728 * policy is not completely strictly validated (only for new attributes).
743 * __nlmsg_parse - parse attributes of a netlink message
760 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) { in __nlmsg_parse()
762 return -EINVAL; in __nlmsg_parse()
771 * nlmsg_parse - parse attributes of a netlink message
791 * nlmsg_parse_deprecated - parse attributes of a netlink message
811 * nlmsg_parse_deprecated_strict - parse attributes of a netlink message
832 * nlmsg_find_attr - find a specific attribute in a netlink message
847 * nla_validate_deprecated - Validate a stream of attributes
854 * Validates all attributes in the specified attribute stream against the
870 * nla_validate - Validate a stream of attributes
877 * Validates all attributes in the specified attribute stream against the
892 * nlmsg_validate_deprecated - validate a netlink message including attributes
904 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) in nlmsg_validate_deprecated()
905 return -EINVAL; in nlmsg_validate_deprecated()
915 * nlmsg_report - need to report back to application?
922 return nlh ? !!(nlh->nlmsg_flags & NLM_F_ECHO) : 0; in nlmsg_report()
926 * nlmsg_seq - return the seq number of netlink message
933 return nlh ? nlh->nlmsg_seq : 0; in nlmsg_seq()
937 * nlmsg_for_each_attr - iterate over a stream of attributes
948 * nlmsg_put - Add a new netlink message to an skb
969 * nlmsg_append - Add more data to a nlmsg in a skb
974 * with multiple fixed-format headers (which is rare).
983 if (NLMSG_ALIGN(size) - size) in nlmsg_append()
985 NLMSG_ALIGN(size) - size); in nlmsg_append()
990 * nlmsg_put_answer - Add a new callback based netlink message to an skb
1005 return nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, in nlmsg_put_answer()
1010 * nlmsg_new - Allocate a new netlink message
1023 * nlmsg_new_large - Allocate a new netlink message with non-contiguous
1027 * The allocated skb is unable to have frag page for shinfo->frags*,
1028 * as the NULL setting for skb->head in netlink_skb_destructor() will
1037 * nlmsg_end - Finalize a netlink message
1042 * attributes. Only necessary if attributes have been added to
1047 nlh->nlmsg_len = skb_tail_pointer(skb) - (unsigned char *)nlh; in nlmsg_end()
1051 * nlmsg_get_pos - return current position in netlink message
1062 * nlmsg_trim - Trim message to a mark
1071 WARN_ON((unsigned char *) mark < skb->data); in nlmsg_trim()
1072 skb_trim(skb, (unsigned char *) mark - skb->data); in nlmsg_trim()
1077 * nlmsg_cancel - Cancel construction of a netlink message
1082 * attributes from the socket buffer again.
1090 * nlmsg_free - drop a netlink message
1099 * nlmsg_consume - free a netlink message
1108 * nlmsg_multicast_filtered - multicast a netlink message with filter function
1138 * nlmsg_multicast - multicast a netlink message
1153 * nlmsg_unicast - unicast a netlink message
1170 * nlmsg_for_each_msg - iterate over a stream of messages
1182 * nl_dump_check_consistent - check if sequence is consistent and advertise if not
1189 * The correct way to use it is to set cb->seq to the generation counter when
1200 if (cb->prev_seq && cb->seq != cb->prev_seq) in nl_dump_check_consistent()
1201 nlh->nlmsg_flags |= NLM_F_DUMP_INTR; in nl_dump_check_consistent()
1202 cb->prev_seq = cb->seq; in nl_dump_check_consistent()
1206 * Netlink Attributes
1210 * nla_attr_size - length of attribute not including padding
1219 * nla_total_size - total length of attribute including padding
1228 * nla_padlen - length of padding at the tail of attribute
1233 return nla_total_size(payload) - nla_attr_size(payload); in nla_padlen()
1237 * nla_type - attribute type
1242 return nla->nla_type & NLA_TYPE_MASK; in nla_type()
1246 * nla_data - head of payload
1255 * nla_len - length of payload
1260 return nla->nla_len - NLA_HDRLEN; in nla_len()
1264 * nla_ok - check if the netlink attribute fits into the remaining bytes
1271 nla->nla_len >= sizeof(*nla) && in nla_ok()
1272 nla->nla_len <= remaining; in nla_ok()
1276 * nla_next - next netlink attribute in attribute stream
1285 unsigned int totlen = NLA_ALIGN(nla->nla_len); in nla_next()
1287 *remaining -= totlen; in nla_next()
1292 * nla_find_nested - find attribute in a set of nested attributes
1293 * @nla: attribute containing the nested attributes
1305 * nla_parse_nested - parse nested attributes
1308 * @nla: attribute containing the nested attributes
1319 if (!(nla->nla_type & NLA_F_NESTED)) { in nla_parse_nested()
1321 return -EINVAL; in nla_parse_nested()
1329 * nla_parse_nested_deprecated - parse nested attributes
1332 * @nla: attribute containing the nested attributes
1348 * nla_put_u8 - Add a u8 netlink attribute to a socket buffer
1355 /* temporary variables to work around GCC PR81715 with asan-stack=1 */ in nla_put_u8()
1362 * nla_put_u16 - Add a u16 netlink attribute to a socket buffer
1375 * nla_put_be16 - Add a __be16 netlink attribute to a socket buffer
1388 * nla_put_net16 - Add 16-bit network byte order netlink attribute to a socket buffer
1401 * nla_put_le16 - Add a __le16 netlink attribute to a socket buffer
1414 * nla_put_u32 - Add a u32 netlink attribute to a socket buffer
1427 * nla_put_uint - Add a variable-size unsigned int to a socket buffer
1443 * nla_put_be32 - Add a __be32 netlink attribute to a socket buffer
1456 * nla_put_net32 - Add 32-bit network byte order netlink attribute to a socket buffer
1469 * nla_put_le32 - Add a __le32 netlink attribute to a socket buffer
1482 * nla_put_u64_64bit - Add a u64 netlink attribute to a skb and align it
1497 * nla_put_be64 - Add a __be64 netlink attribute to a socket buffer and align it
1512 * nla_put_net64 - Add 64-bit network byte order nlattr to a skb and align it
1528 * nla_put_le64 - Add a __le64 netlink attribute to a socket buffer and align it
1543 * nla_put_s8 - Add a s8 netlink attribute to a socket buffer
1556 * nla_put_s16 - Add a s16 netlink attribute to a socket buffer
1569 * nla_put_s32 - Add a s32 netlink attribute to a socket buffer
1582 * nla_put_s64 - Add a s64 netlink attribute to a socket buffer and align it
1597 * nla_put_sint - Add a variable-size signed int to a socket buffer
1613 * nla_put_string - Add a string netlink attribute to a socket buffer
1625 * nla_put_flag - Add a flag netlink attribute to a socket buffer
1635 * nla_put_msecs - Add a msecs netlink attribute to a skb and align it
1650 * nla_put_in_addr - Add an IPv4 address netlink attribute to a socket
1665 * nla_put_in6_addr - Add an IPv6 address netlink attribute to a socket
1678 * nla_put_bitfield32 - Add a bitfield32 netlink attribute to a socket buffer
1693 * nla_get_u32 - return payload of u32 attribute
1702 * nla_get_u32_default - return payload of u32 attribute or default
1716 * nla_get_be32 - return payload of __be32 attribute
1725 * nla_get_be32_default - return payload of be32 attribute or default
1740 * nla_get_le32 - return payload of __le32 attribute
1749 * nla_get_le32_default - return payload of le32 attribute or default
1764 * nla_get_u16 - return payload of u16 attribute
1773 * nla_get_u16_default - return payload of u16 attribute or default
1787 * nla_get_be16 - return payload of __be16 attribute
1796 * nla_get_be16_default - return payload of be16 attribute or default
1811 * nla_get_le16 - return payload of __le16 attribute
1820 * nla_get_le16_default - return payload of le16 attribute or default
1835 * nla_get_u8 - return payload of u8 attribute
1844 * nla_get_u8_default - return payload of u8 attribute or default
1858 * nla_get_u64 - return payload of u64 attribute
1871 * nla_get_u64_default - return payload of u64 attribute or default
1885 * nla_get_uint - return payload of uint attribute
1896 * nla_get_uint_default - return payload of uint attribute or default
1910 * nla_get_be64 - return payload of __be64 attribute
1923 * nla_get_be64_default - return payload of be64 attribute or default
1938 * nla_get_le64 - return payload of __le64 attribute
1947 * nla_get_le64_default - return payload of le64 attribute or default
1962 * nla_get_s32 - return payload of s32 attribute
1971 * nla_get_s32_default - return payload of s32 attribute or default
1985 * nla_get_s16 - return payload of s16 attribute
1994 * nla_get_s16_default - return payload of s16 attribute or default
2008 * nla_get_s8 - return payload of s8 attribute
2017 * nla_get_s8_default - return payload of s8 attribute or default
2031 * nla_get_s64 - return payload of s64 attribute
2044 * nla_get_s64_default - return payload of s64 attribute or default
2058 * nla_get_sint - return payload of uint attribute
2069 * nla_get_sint_default - return payload of sint attribute or default
2083 * nla_get_flag - return payload of flag attribute
2092 * nla_get_msecs - return payload of msecs attribute
2105 * nla_get_msecs_default - return payload of msecs attribute or default
2120 * nla_get_in_addr - return payload of IPv4 address attribute
2129 * nla_get_in_addr_default - return payload of be32 attribute or default
2144 * nla_get_in6_addr - return payload of IPv6 address attribute
2156 * nla_get_bitfield32 - return payload of 32 bitfield attribute
2168 * nla_memdup - duplicate attribute memory (kmemdup)
2179 * nla_nest_start_noflag - Start a new level of nested attributes
2180 * @skb: socket buffer to add attributes to
2184 * marked their nest attributes with NLA_F_NESTED flag. New APIs should use
2201 * nla_nest_start - Start a new level of nested attributes, with NLA_F_NESTED
2202 * @skb: socket buffer to add attributes to
2216 * nla_nest_end - Finalize nesting of attributes
2217 * @skb: socket buffer the attributes are stored in
2221 * appended attributes.
2227 start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start; in nla_nest_end()
2228 return skb->len; in nla_nest_end()
2232 * nla_nest_cancel - Cancel nesting of attributes
2236 * Removes the container attribute and including all nested
2237 * attributes. Returns -EMSGSIZE
2245 * nla_put_empty_nest - Create an empty nest
2251 * Returns: 0 when successful or -EMSGSIZE on failure.
2255 return nla_nest_start(skb, attrtype) ? 0 : -EMSGSIZE; in nla_put_empty_nest()
2259 * __nla_validate_nested - Validate a stream of nested attributes
2266 * Validates all attributes in the nested attribute stream against the
2267 * specified policy. Attributes with a type exceeding maxtype will be
2300 * nla_need_padding_for_64bit - test 64-bit alignment of the next attribute
2304 * a 64-bit aligned area.
2310 * if the skb->data _is_ aligned. A NOP attribute, plus in nla_need_padding_for_64bit()
2312 * 8-byte aligned. in nla_need_padding_for_64bit()
2321 * nla_align_64bit - 64-bit align the nla_data() of next attribute
2326 * the next attribute we emit have a 64-bit aligned nla_data() area.
2336 return -EMSGSIZE; in nla_align_64bit()
2342 * nla_total_size_64bit - total length of attribute including padding
2355 * nla_for_each_attr - iterate over a stream of attributes
2367 * nla_for_each_attr_type - iterate over a stream of attributes
2379 * nla_for_each_nested - iterate over nested attributes
2381 * @nla: attribute containing the nested attributes
2388 * nla_for_each_nested_type - iterate over nested attributes
2391 * @nla: attribute containing the nested attributes
2399 * nla_is_last - Test if attribute is last in stream
2405 return nla->nla_len == rem; in nla_is_last()