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
156 * nla_validate() validate a stream of attributes
157 * nla_validate_nested() validate a stream of nested attributes
158 * nla_find() find attribute in stream of attributes
159 * nla_find_nested() find attribute in nested attributes
161 * nla_parse_nested() parse nested attributes
162 * nla_for_each_attr() loop over all attributes
163 * nla_for_each_attr_type() loop over all attributes with the
165 * nla_for_each_nested() loop over the nested attributes
166 * nla_for_each_nested_type() loop over the nested attributes with
200 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
222 * struct nla_policy - attribute validation policy
225 * type-specific validation (e.g. range, function call), see
240 * nested header (or empty); len field is used if
242 * number in the nested policy.
257 * NLA_BITFIELD32 This is a 32-bit bitmap/bitselector attribute and
262 * NLA_NESTED `nested_policy' to a nested policy to validate, must
266 * parse, the nested sub-policies.
267 * NLA_NESTED_ARRAY `nested_policy' points to a nested policy to validate,
271 * NLA_NESTED has the nested attributes directly inside
272 * while an array has the nested attributes at another
293 * of s16 - do that using the NLA_POLICY_FULL_RANGE()
320 * All other Unused - but note that it's a union
324 * All other Unused - but note that it's a union
358 * validation is enforced for all attributes. For existing ones
359 * it should be set at least when new attributes are added to
388 _NLA_POLICY_NESTED(ARRAY_SIZE(policy) - 1, policy)
390 _NLA_POLICY_NESTED_ARRAY(ARRAY_SIZE(policy) - 1, policy)
477 * struct nl_info - netlink source information
482 * @skip_notify_kernel: Skip selected in-kernel notifications
493 * enum netlink_validation - netlink message/attribute validation levels
494 * @NL_VALIDATE_LIBERAL: Old-style "be liberal" validation, not caring about
495 * extra data at the end of the message, attributes being longer than
496 * they should be, or unknown attributes being present.
498 * @NL_VALIDATE_MAXTYPE: Reject attributes > max type; Together with _TRAILING
500 * @NL_VALIDATE_UNSPEC: Reject attributes with NLA_UNSPEC in the policy.
569 * nlmsg_msg_size - length of netlink message not including padding
578 * nlmsg_total_size - length of netlink message including padding
587 * nlmsg_padlen - length of padding at the message's tail
592 return nlmsg_total_size(payload) - nlmsg_msg_size(payload); in nlmsg_padlen()
596 * nlmsg_data - head of message payload
605 * nlmsg_len - length of message payload
610 return nlh->nlmsg_len - NLMSG_HDRLEN; in nlmsg_len()
614 * nlmsg_attrdata - head of attributes data
626 * nlmsg_attrlen - length of attributes data
632 return nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen); in nlmsg_attrlen()
636 * nlmsg_ok - check if the netlink message fits into the remaining bytes
643 nlh->nlmsg_len >= sizeof(struct nlmsghdr) && in nlmsg_ok()
644 nlh->nlmsg_len <= remaining); in nlmsg_ok()
648 * nlmsg_next - next netlink message in message stream
658 int totlen = NLMSG_ALIGN(nlh->nlmsg_len); in nlmsg_next()
660 *remaining -= totlen; in nlmsg_next()
666 * nla_parse - Parse a stream of attributes into a tb buffer
674 * Parses a stream of attributes and stores a pointer to each attribute in
675 * the tb array accessible via the attribute type. Attributes with a type
676 * exceeding maxtype will be rejected, policy must be specified, attributes
691 * nla_parse_deprecated - Parse a stream of attributes into a tb buffer
699 * Parses a stream of attributes and stores a pointer to each attribute in
700 * the tb array accessible via the attribute type. Attributes with a type
701 * exceeding maxtype will be ignored and attributes from the policy are not
702 * always strictly validated (only for new attributes).
716 * nla_parse_deprecated_strict - Parse a stream of attributes into a tb buffer
724 * Parses a stream of attributes and stores a pointer to each attribute in
725 * the tb array accessible via the attribute type. Attributes with a type
727 * policy is not completely strictly validated (only for new attributes).
742 * __nlmsg_parse - parse attributes of a netlink message
759 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) { in __nlmsg_parse()
761 return -EINVAL; in __nlmsg_parse()
770 * nlmsg_parse - parse attributes of a netlink message
790 * nlmsg_parse_deprecated - parse attributes of a netlink message
810 * nlmsg_parse_deprecated_strict - parse attributes of a netlink message
831 * nlmsg_find_attr - find a specific attribute in a netlink message
846 * nla_validate_deprecated - Validate a stream of attributes
853 * Validates all attributes in the specified attribute stream against the
869 * nla_validate - Validate a stream of attributes
876 * Validates all attributes in the specified attribute stream against the
891 * nlmsg_validate_deprecated - validate a netlink message including attributes
903 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) in nlmsg_validate_deprecated()
904 return -EINVAL; in nlmsg_validate_deprecated()
914 * nlmsg_report - need to report back to application?
921 return nlh ? !!(nlh->nlmsg_flags & NLM_F_ECHO) : 0; in nlmsg_report()
925 * nlmsg_seq - return the seq number of netlink message
932 return nlh ? nlh->nlmsg_seq : 0; in nlmsg_seq()
936 * nlmsg_for_each_attr - iterate over a stream of attributes
947 * nlmsg_put - Add a new netlink message to an skb
968 * nlmsg_append - Add more data to a nlmsg in a skb
973 * with multiple fixed-format headers (which is rare).
982 if (NLMSG_ALIGN(size) - size) in nlmsg_append()
984 NLMSG_ALIGN(size) - size); in nlmsg_append()
989 * nlmsg_put_answer - Add a new callback based netlink message to an skb
1004 return nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, in nlmsg_put_answer()
1009 * nlmsg_new - Allocate a new netlink message
1022 * nlmsg_new_large - Allocate a new netlink message with non-contiguous
1026 * The allocated skb is unable to have frag page for shinfo->frags*,
1027 * as the NULL setting for skb->head in netlink_skb_destructor() will
1036 * nlmsg_end - Finalize a netlink message
1041 * attributes. Only necessary if attributes have been added to
1046 nlh->nlmsg_len = skb_tail_pointer(skb) - (unsigned char *)nlh; in nlmsg_end()
1050 * nlmsg_get_pos - return current position in netlink message
1061 * nlmsg_trim - Trim message to a mark
1070 WARN_ON((unsigned char *) mark < skb->data); in nlmsg_trim()
1071 skb_trim(skb, (unsigned char *) mark - skb->data); in nlmsg_trim()
1076 * nlmsg_cancel - Cancel construction of a netlink message
1081 * attributes from the socket buffer again.
1089 * nlmsg_free - drop a netlink message
1098 * nlmsg_consume - free a netlink message
1107 * nlmsg_multicast_filtered - multicast a netlink message with filter function
1137 * nlmsg_multicast - multicast a netlink message
1152 * nlmsg_unicast - unicast a netlink message
1169 * nlmsg_for_each_msg - iterate over a stream of messages
1181 * nl_dump_check_consistent - check if sequence is consistent and advertise if not
1188 * The correct way to use it is to set cb->seq to the generation counter when
1199 if (cb->prev_seq && cb->seq != cb->prev_seq) in nl_dump_check_consistent()
1200 nlh->nlmsg_flags |= NLM_F_DUMP_INTR; in nl_dump_check_consistent()
1201 cb->prev_seq = cb->seq; in nl_dump_check_consistent()
1205 * Netlink Attributes
1209 * nla_attr_size - length of attribute not including padding
1218 * nla_total_size - total length of attribute including padding
1227 * nla_padlen - length of padding at the tail of attribute
1232 return nla_total_size(payload) - nla_attr_size(payload); in nla_padlen()
1236 * nla_type - attribute type
1241 return nla->nla_type & NLA_TYPE_MASK; in nla_type()
1245 * nla_data - head of payload
1254 * nla_len - length of payload
1259 return nla->nla_len - NLA_HDRLEN; in nla_len()
1263 * nla_ok - check if the netlink attribute fits into the remaining bytes
1270 nla->nla_len >= sizeof(*nla) && in nla_ok()
1271 nla->nla_len <= remaining; in nla_ok()
1275 * nla_next - next netlink attribute in attribute stream
1284 unsigned int totlen = NLA_ALIGN(nla->nla_len); in nla_next()
1286 *remaining -= totlen; in nla_next()
1291 * nla_find_nested - find attribute in a set of nested attributes
1292 * @nla: attribute containing the nested attributes
1304 * nla_parse_nested - parse nested attributes
1307 * @nla: attribute containing the nested attributes
1318 if (!(nla->nla_type & NLA_F_NESTED)) { in nla_parse_nested()
1320 return -EINVAL; in nla_parse_nested()
1328 * nla_parse_nested_deprecated - parse nested attributes
1331 * @nla: attribute containing the nested attributes
1347 * nla_put_u8 - Add a u8 netlink attribute to a socket buffer
1354 /* temporary variables to work around GCC PR81715 with asan-stack=1 */ in nla_put_u8()
1361 * nla_put_u16 - Add a u16 netlink attribute to a socket buffer
1374 * nla_put_be16 - Add a __be16 netlink attribute to a socket buffer
1387 * nla_put_net16 - Add 16-bit network byte order netlink attribute to a socket buffer
1400 * nla_put_le16 - Add a __le16 netlink attribute to a socket buffer
1413 * nla_put_u32 - Add a u32 netlink attribute to a socket buffer
1426 * nla_put_uint - Add a variable-size unsigned int to a socket buffer
1442 * nla_put_be32 - Add a __be32 netlink attribute to a socket buffer
1455 * nla_put_net32 - Add 32-bit network byte order netlink attribute to a socket buffer
1468 * nla_put_le32 - Add a __le32 netlink attribute to a socket buffer
1481 * nla_put_u64_64bit - Add a u64 netlink attribute to a skb and align it
1496 * nla_put_be64 - Add a __be64 netlink attribute to a socket buffer and align it
1511 * nla_put_net64 - Add 64-bit network byte order nlattr to a skb and align it
1527 * nla_put_le64 - Add a __le64 netlink attribute to a socket buffer and align it
1542 * nla_put_s8 - Add a s8 netlink attribute to a socket buffer
1555 * nla_put_s16 - Add a s16 netlink attribute to a socket buffer
1568 * nla_put_s32 - Add a s32 netlink attribute to a socket buffer
1581 * nla_put_s64 - Add a s64 netlink attribute to a socket buffer and align it
1596 * nla_put_sint - Add a variable-size signed int to a socket buffer
1612 * nla_put_string - Add a string netlink attribute to a socket buffer
1624 * nla_put_flag - Add a flag netlink attribute to a socket buffer
1634 * nla_put_msecs - Add a msecs netlink attribute to a skb and align it
1649 * nla_put_in_addr - Add an IPv4 address netlink attribute to a socket
1664 * nla_put_in6_addr - Add an IPv6 address netlink attribute to a socket
1677 * nla_put_bitfield32 - Add a bitfield32 netlink attribute to a socket buffer
1692 * nla_get_u32 - return payload of u32 attribute
1701 * nla_get_u32_default - return payload of u32 attribute or default
1715 * nla_get_be32 - return payload of __be32 attribute
1724 * nla_get_be32_default - return payload of be32 attribute or default
1739 * nla_get_le32 - return payload of __le32 attribute
1748 * nla_get_le32_default - return payload of le32 attribute or default
1763 * nla_get_u16 - return payload of u16 attribute
1772 * nla_get_u16_default - return payload of u16 attribute or default
1786 * nla_get_be16 - return payload of __be16 attribute
1795 * nla_get_be16_default - return payload of be16 attribute or default
1810 * nla_get_le16 - return payload of __le16 attribute
1819 * nla_get_le16_default - return payload of le16 attribute or default
1834 * nla_get_u8 - return payload of u8 attribute
1843 * nla_get_u8_default - return payload of u8 attribute or default
1857 * nla_get_u64 - return payload of u64 attribute
1870 * nla_get_u64_default - return payload of u64 attribute or default
1884 * nla_get_uint - return payload of uint attribute
1895 * nla_get_uint_default - return payload of uint attribute or default
1909 * nla_get_be64 - return payload of __be64 attribute
1922 * nla_get_be64_default - return payload of be64 attribute or default
1937 * nla_get_le64 - return payload of __le64 attribute
1946 * nla_get_le64_default - return payload of le64 attribute or default
1961 * nla_get_s32 - return payload of s32 attribute
1970 * nla_get_s32_default - return payload of s32 attribute or default
1984 * nla_get_s16 - return payload of s16 attribute
1993 * nla_get_s16_default - return payload of s16 attribute or default
2007 * nla_get_s8 - return payload of s8 attribute
2016 * nla_get_s8_default - return payload of s8 attribute or default
2030 * nla_get_s64 - return payload of s64 attribute
2043 * nla_get_s64_default - return payload of s64 attribute or default
2057 * nla_get_sint - return payload of uint attribute
2068 * nla_get_sint_default - return payload of sint attribute or default
2082 * nla_get_flag - return payload of flag attribute
2091 * nla_get_msecs - return payload of msecs attribute
2104 * nla_get_msecs_default - return payload of msecs attribute or default
2119 * nla_get_in_addr - return payload of IPv4 address attribute
2128 * nla_get_in_addr_default - return payload of be32 attribute or default
2143 * nla_get_in6_addr - return payload of IPv6 address attribute
2155 * nla_get_bitfield32 - return payload of 32 bitfield attribute
2167 * nla_memdup - duplicate attribute memory (kmemdup)
2178 * nla_nest_start_noflag - Start a new level of nested attributes
2179 * @skb: socket buffer to add attributes to
2183 * marked their nest attributes with NLA_F_NESTED flag. New APIs should use
2200 * nla_nest_start - Start a new level of nested attributes, with NLA_F_NESTED
2201 * @skb: socket buffer to add attributes to
2215 * nla_nest_end - Finalize nesting of attributes
2216 * @skb: socket buffer the attributes are stored in
2220 * appended attributes.
2226 start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start; in nla_nest_end()
2227 return skb->len; in nla_nest_end()
2231 * nla_nest_cancel - Cancel nesting of attributes
2235 * Removes the container attribute and including all nested
2236 * attributes. Returns -EMSGSIZE
2244 * __nla_validate_nested - Validate a stream of nested attributes
2251 * Validates all attributes in the nested attribute stream against the
2252 * specified policy. Attributes with a type exceeding maxtype will be
2285 * nla_need_padding_for_64bit - test 64-bit alignment of the next attribute
2289 * a 64-bit aligned area.
2295 * if the skb->data _is_ aligned. A NOP attribute, plus in nla_need_padding_for_64bit()
2297 * 8-byte aligned. in nla_need_padding_for_64bit()
2306 * nla_align_64bit - 64-bit align the nla_data() of next attribute
2311 * the next attribute we emit have a 64-bit aligned nla_data() area.
2321 return -EMSGSIZE; in nla_align_64bit()
2327 * nla_total_size_64bit - total length of attribute including padding
2340 * nla_for_each_attr - iterate over a stream of attributes
2352 * nla_for_each_attr_type - iterate over a stream of attributes
2364 * nla_for_each_nested - iterate over nested attributes
2366 * @nla: attribute containing the nested attributes
2373 * nla_for_each_nested_type - iterate over nested attributes
2376 * @nla: attribute containing the nested attributes
2384 * nla_is_last - Test if attribute is last in stream
2390 return nla->nla_len == rem; in nla_is_last()