Netlink Type-Length-Value (TLV) attribute: More...
Data Structures | |
struct | nla_policy |
Attribute validation policy. More... | |
Functions | |
uint16_t | mnl_attr_get_type (const struct nlattr *attr) |
mnl_attr_get_type - get type of netlink attribute More... | |
EXPORT_SYMBOL (mnl_attr_get_type) | |
uint16_t | mnl_attr_get_len (const struct nlattr *attr) |
mnl_attr_get_len - get length of netlink attribute More... | |
EXPORT_SYMBOL (mnl_attr_get_len) | |
uint16_t | mnl_attr_get_payload_len (const struct nlattr *attr) |
mnl_attr_get_payload_len - get the attribute payload-value length More... | |
EXPORT_SYMBOL (mnl_attr_get_payload_len) | |
void * | mnl_attr_get_payload (const struct nlattr *attr) |
mnl_attr_get_payload - get pointer to the attribute payload More... | |
EXPORT_SYMBOL (mnl_attr_get_payload) | |
bool | mnl_attr_ok (const struct nlattr *attr, int len) |
mnl_attr_ok - check if there is room for an attribute in a buffer More... | |
EXPORT_SYMBOL (mnl_attr_ok) | |
struct nlattr * | mnl_attr_next (const struct nlattr *attr) |
mnl_attr_next - get the next attribute in the payload of a netlink message More... | |
EXPORT_SYMBOL (mnl_attr_next) | |
int | mnl_attr_type_valid (const struct nlattr *attr, uint16_t max) |
mnl_attr_type_valid - check if the attribute type is valid More... | |
EXPORT_SYMBOL (mnl_attr_type_valid) | |
int | mnl_attr_validate (const struct nlattr *attr, enum mnl_attr_data_type type) |
mnl_attr_validate - validate netlink attribute (simplified version) More... | |
EXPORT_SYMBOL (mnl_attr_validate) | |
int | mnl_attr_validate2 (const struct nlattr *attr, enum mnl_attr_data_type type, size_t exp_len) |
mnl_attr_validate2 - validate netlink attribute (extended version) More... | |
EXPORT_SYMBOL (mnl_attr_validate2) | |
int | mnl_attr_parse (const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data) |
mnl_attr_parse - parse attributes More... | |
EXPORT_SYMBOL (mnl_attr_parse) | |
int | mnl_attr_parse_nested (const struct nlattr *nested, mnl_attr_cb_t cb, void *data) |
mnl_attr_parse_nested - parse attributes inside a nest More... | |
EXPORT_SYMBOL (mnl_attr_parse_nested) | |
int | mnl_attr_parse_payload (const void *payload, size_t payload_len, mnl_attr_cb_t cb, void *data) |
mnl_attr_parse_payload - parse attributes in payload of Netlink message More... | |
EXPORT_SYMBOL (mnl_attr_parse_payload) | |
uint8_t | mnl_attr_get_u8 (const struct nlattr *attr) |
mnl_attr_get_u8 - returns 8-bit unsigned integer attribute payload More... | |
EXPORT_SYMBOL (mnl_attr_get_u8) | |
uint16_t | mnl_attr_get_u16 (const struct nlattr *attr) |
mnl_attr_get_u16 - returns 16-bit unsigned integer attribute payload More... | |
EXPORT_SYMBOL (mnl_attr_get_u16) | |
uint32_t | mnl_attr_get_u32 (const struct nlattr *attr) |
mnl_attr_get_u32 - returns 32-bit unsigned integer attribute payload More... | |
EXPORT_SYMBOL (mnl_attr_get_u32) | |
uint64_t | mnl_attr_get_u64 (const struct nlattr *attr) |
mnl_attr_get_u64 - returns 64-bit unsigned integer attribute. More... | |
EXPORT_SYMBOL (mnl_attr_get_u64) | |
const char * | mnl_attr_get_str (const struct nlattr *attr) |
mnl_attr_get_str - returns pointer to string attribute. More... | |
EXPORT_SYMBOL (mnl_attr_get_str) | |
void | mnl_attr_put (struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data) |
mnl_attr_put - add an attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put) | |
void | mnl_attr_put_u8 (struct nlmsghdr *nlh, uint16_t type, uint8_t data) |
mnl_attr_put_u8 - add 8-bit unsigned integer attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u8) | |
void | mnl_attr_put_u16 (struct nlmsghdr *nlh, uint16_t type, uint16_t data) |
mnl_attr_put_u16 - add 16-bit unsigned integer attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u16) | |
void | mnl_attr_put_u32 (struct nlmsghdr *nlh, uint16_t type, uint32_t data) |
mnl_attr_put_u32 - add 32-bit unsigned integer attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u32) | |
void | mnl_attr_put_u64 (struct nlmsghdr *nlh, uint16_t type, uint64_t data) |
mnl_attr_put_u64 - add 64-bit unsigned integer attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u64) | |
void | mnl_attr_put_str (struct nlmsghdr *nlh, uint16_t type, const char *data) |
mnl_attr_put_str - add string attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_str) | |
void | mnl_attr_put_strz (struct nlmsghdr *nlh, uint16_t type, const char *data) |
mnl_attr_put_strz - add string attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_strz) | |
struct nlattr * | mnl_attr_nest_start (struct nlmsghdr *nlh, uint16_t type) |
mnl_attr_nest_start - start an attribute nest More... | |
EXPORT_SYMBOL (mnl_attr_nest_start) | |
bool | mnl_attr_put_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, size_t len, const void *data) |
mnl_attr_put_check - add an attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_check) | |
bool | mnl_attr_put_u8_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint8_t data) |
mnl_attr_put_u8_check - add 8-bit unsigned int attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u8_check) | |
bool | mnl_attr_put_u16_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint16_t data) |
mnl_attr_put_u16_check - add 16-bit unsigned int attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u16_check) | |
bool | mnl_attr_put_u32_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint32_t data) |
mnl_attr_put_u32_check - add 32-bit unsigned int attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u32_check) | |
bool | mnl_attr_put_u64_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint64_t data) |
mnl_attr_put_u64_check - add 64-bit unsigned int attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_u64_check) | |
bool | mnl_attr_put_str_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data) |
mnl_attr_put_str_check - add string attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_str_check) | |
bool | mnl_attr_put_strz_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data) |
mnl_attr_put_strz_check - add string attribute to netlink message More... | |
EXPORT_SYMBOL (mnl_attr_put_strz_check) | |
struct nlattr * | mnl_attr_nest_start_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type) |
mnl_attr_nest_start_check - start an attribute nest More... | |
EXPORT_SYMBOL (mnl_attr_nest_start_check) | |
void | mnl_attr_nest_end (struct nlmsghdr *nlh, struct nlattr *start) |
mnl_attr_nest_end - end an attribute nest More... | |
EXPORT_SYMBOL (mnl_attr_nest_end) | |
void | mnl_attr_nest_cancel (struct nlmsghdr *nlh, struct nlattr *start) |
mnl_attr_nest_cancel - cancel an attribute nest More... | |
EXPORT_SYMBOL (mnl_attr_nest_cancel) | |
Basic Attribute Data Types | |
enum | { NLA_UNSPEC, NLA_U8, NLA_U16, NLA_U32, NLA_U64, NLA_STRING, NLA_FLAG, NLA_MSECS, NLA_NESTED, __NLA_TYPE_MAX } |
Basic attribute data types. More... | |
Attribute Construction (Exception Based) | |
#define | NLA_PUT(msg, attrtype, attrlen, data) |
Add unspecific attribute to netlink message. More... | |
#define | NLA_PUT_TYPE(msg, type, attrtype, value) |
Add atomic type attribute to netlink message. More... | |
#define | NLA_PUT_U8(msg, attrtype, value) NLA_PUT_TYPE(msg, uint8_t, attrtype, value) |
Add 8 bit integer attribute to netlink message. More... | |
#define | NLA_PUT_U16(msg, attrtype, value) NLA_PUT_TYPE(msg, uint16_t, attrtype, value) |
Add 16 bit integer attribute to netlink message. More... | |
#define | NLA_PUT_U32(msg, attrtype, value) NLA_PUT_TYPE(msg, uint32_t, attrtype, value) |
Add 32 bit integer attribute to netlink message. More... | |
#define | NLA_PUT_U64(msg, attrtype, value) NLA_PUT_TYPE(msg, uint64_t, attrtype, value) |
Add 64 bit integer attribute to netlink message. More... | |
#define | NLA_PUT_STRING(msg, attrtype, value) NLA_PUT(msg, attrtype, strlen(value) + 1, value) |
Add string attribute to netlink message. More... | |
#define | NLA_PUT_FLAG(msg, attrtype) NLA_PUT(msg, attrtype, 0, NULL) |
Add flag attribute to netlink message. More... | |
#define | NLA_PUT_MSECS(msg, attrtype, msecs) NLA_PUT_U64(msg, attrtype, msecs) |
Add msecs attribute to netlink message. More... | |
#define | NLA_PUT_ADDR(msg, attrtype, addr) |
Add address attribute to netlink message. More... | |
#define | NLA_PUT_DATA(msg, attrtype, data) |
Add abstract data attribute to netlink message. More... | |
Iterators | |
#define | nla_for_each_attr(pos, head, len, rem) |
Iterate over a stream of attributes. More... | |
#define | nla_for_each_nested(pos, nla, rem) |
Iterate over a stream of nested attributes. More... | |
Attribute Size Calculation | |
int | nla_attr_size (int payload) |
Return size of attribute whithout padding. More... | |
int | nla_total_size (int payload) |
Return size of attribute including padding. More... | |
int | nla_padlen (int payload) |
Return length of padding at the tail of the attribute. More... | |
Parsing Attributes | |
int | nla_type (const struct nlattr *nla) |
Return type of the attribute. More... | |
void * | nla_data (const struct nlattr *nla) |
Return pointer to the payload section. More... | |
int | nla_len (const struct nlattr *nla) |
Return length of the payload . More... | |
int | nla_ok (const struct nlattr *nla, int remaining) |
Check if the attribute header and payload can be accessed safely. More... | |
struct nlattr * | nla_next (const struct nlattr *nla, int *remaining) |
Return next attribute in a stream of attributes. More... | |
int | nla_parse (struct nlattr *tb[], int maxtype, struct nlattr *head, int len, struct nla_policy *policy) |
Create attribute index based on a stream of attributes. More... | |
int | nla_validate (struct nlattr *head, int len, int maxtype, struct nla_policy *policy) |
Validate a stream of attributes. More... | |
struct nlattr * | nla_find (struct nlattr *head, int len, int attrtype) |
Find a single attribute in a stream of attributes. More... | |
Helper Functions | |
int | nla_memcpy (void *dest, struct nlattr *src, int count) |
Copy attribute payload to another memory area. More... | |
size_t | nla_strlcpy (char *dst, const struct nlattr *nla, size_t dstsize) |
Copy string attribute payload to a buffer. More... | |
int | nla_memcmp (const struct nlattr *nla, const void *data, size_t size) |
Compare attribute payload with memory area. More... | |
int | nla_strcmp (const struct nlattr *nla, const char *str) |
Compare string attribute payload with string. More... | |
Unspecific Attribute | |
struct nlattr * | nla_reserve (struct nl_msg *msg, int attrtype, int attrlen) |
Reserve space for a attribute. More... | |
int | nla_put (struct nl_msg *msg, int attrtype, int datalen, const void *data) |
Add a unspecific attribute to netlink message. More... | |
int | nla_put_data (struct nl_msg *msg, int attrtype, struct nl_data *data) |
Add abstract data as unspecific attribute to netlink message. More... | |
int | nla_put_addr (struct nl_msg *msg, int attrtype, struct nl_addr *addr) |
Add abstract address as unspecific attribute to netlink message. More... | |
Integer Attributes | |
int | nla_put_u8 (struct nl_msg *msg, int attrtype, uint8_t value) |
Add 8 bit integer attribute to netlink message. More... | |
uint8_t | nla_get_u8 (struct nlattr *nla) |
Return value of 8 bit integer attribute. More... | |
int | nla_put_u16 (struct nl_msg *msg, int attrtype, uint16_t value) |
Add 16 bit integer attribute to netlink message. More... | |
uint16_t | nla_get_u16 (struct nlattr *nla) |
Return payload of 16 bit integer attribute. More... | |
int | nla_put_u32 (struct nl_msg *msg, int attrtype, uint32_t value) |
Add 32 bit integer attribute to netlink message. More... | |
uint32_t | nla_get_u32 (struct nlattr *nla) |
Return payload of 32 bit integer attribute. More... | |
int | nla_put_u64 (struct nl_msg *msg, int attrtype, uint64_t value) |
Add 64 bit integer attribute to netlink message. More... | |
uint64_t | nla_get_u64 (struct nlattr *nla) |
Return payload of u64 attribute. More... | |
String Attribute | |
int | nla_put_string (struct nl_msg *msg, int attrtype, const char *str) |
Add string attribute to netlink message. More... | |
char * | nla_get_string (struct nlattr *nla) |
Return payload of string attribute. More... | |
char * | nla_strdup (struct nlattr *nla) |
Flag Attribute | |
int | nla_put_flag (struct nl_msg *msg, int attrtype) |
Add flag netlink attribute to netlink message. More... | |
int | nla_get_flag (struct nlattr *nla) |
Return true if flag attribute is set. More... | |
Microseconds Attribute | |
int | nla_put_msecs (struct nl_msg *n, int attrtype, unsigned long msecs) |
Add a msecs netlink attribute to a netlink message. More... | |
unsigned long | nla_get_msecs (struct nlattr *nla) |
Return payload of msecs attribute. More... | |
Nested Attribute | |
int | nla_put_nested (struct nl_msg *msg, int attrtype, struct nl_msg *nested) |
Add nested attributes to netlink message. More... | |
struct nlattr * | nla_nest_start (struct nl_msg *msg, int attrtype) |
Start a new level of nested attributes. More... | |
int | nla_nest_end (struct nl_msg *msg, struct nlattr *start) |
Finalize nesting of attributes. More... | |
int | nla_parse_nested (struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy) |
Create attribute index based on nested attribute. More... | |
Netlink Type-Length-Value (TLV) attribute:
Netlink Attributes Construction/Parsing Interface.
|<-- 2 bytes -->|<-- 2 bytes -->|<-- variable -->| ------------------------------------------------- | length | type | value | ------------------------------------------------- |<--------- header ------------>|<-- payload --->|
The payload of the Netlink message contains sequences of attributes that are expressed in TLV format.
Netlink attributes allow for data chunks of arbitary length to be attached to a netlink message. Each attribute is encoded with a type and length field, both 16 bits, stored in the attribute header preceding the attribute data. The main advantage of using attributes over packing everything into the family header is that the interface stays extendable as new attributes can supersede old attributes while remaining backwards compatible. Also attributes can be defined optional thus avoiding the transmission of unnecessary empty data blocks. Special nested attributes allow for more complex data structures to be transmitted, e.g. trees, lists, etc.
While not required, netlink attributes typically follow the family header of a netlink message and must be properly aligned to NLA_ALIGNTO:
The actual attributes are chained together each separately aligned to NLA_ALIGNTO. The position of an attribute is defined based on the length field of the preceding attributes:
The attribute itself consists of the attribute header followed by the actual payload also aligned to NLA_ALIGNTO. The function nla_data() returns a pointer to the start of the payload while nla_len() returns the length of the payload in bytes.
Note: Be aware, NLA_ALIGNTO equals to 4 bytes, therefore it is not safe to dereference any 64 bit data types directly.
A number of basic data types are supported to simplify access and validation of netlink attributes. This data type information is not encoded in the attribute, both the kernel and userspace part are required to share this information on their own.
One of the major advantages of these basic types is the automatic validation of each attribute based on an attribute policy. The validation covers most of the checks required to safely use attributes and thus keeps the individual sanity check to a minimum.
Never access attribute payload without ensuring basic validation first, attributes may:
Policies are defined as array of the struct nla_policy. The array is indexed with the attribute type, therefore the array must be sized accordingly.
Some basic validations are performed on every attribute, regardless of type.
Often a large number of attributes are added to a message in a single function. In order to simplify error handling, a second set of construction functions exist which jump to a error label when they fail instead of returning an error code. This second set consists of macros which are named after their error code based counterpart except that the name is written all uppercase.
All of the macros jump to the target nla_put_failure
if they fail.
Iterate over a stream of attributes.
Referenced by nla_find(), nla_parse(), and nla_validate().
#define nla_for_each_nested | ( | pos, | |
nla, | |||
rem | |||
) |
Iterate over a stream of nested attributes.
Referenced by nfnlmsg_nft_rule_parse(), and rtnl_ematch_parse().
#define NLA_PUT | ( | msg, | |
attrtype, | |||
attrlen, | |||
data | |||
) |
Add unspecific attribute to netlink message.
Referenced by netem_build_msg(), and nfnl_queue_build_create_request().
#define NLA_PUT_ADDR | ( | msg, | |
attrtype, | |||
addr | |||
) |
Add address attribute to netlink message.
Referenced by rtnl_link_build_change_request(), and rtnl_route_build_msg().
#define NLA_PUT_DATA | ( | msg, | |
attrtype, | |||
data | |||
) |
Add abstract data attribute to netlink message.
Add flag attribute to netlink message.
#define NLA_PUT_MSECS | ( | msg, | |
attrtype, | |||
msecs | |||
) | NLA_PUT_U64(msg, attrtype, msecs) |
Add msecs attribute to netlink message.
Add string attribute to netlink message.
Referenced by nfnl_nft_set_dump_request(), nfnl_nft_setelem_dump_request(), rtnl_link_build_change_request(), and rtnl_neightbl_build_change_request().
Add atomic type attribute to netlink message.
#define NLA_PUT_U16 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint16_t, attrtype, value) |
Add 16 bit integer attribute to netlink message.
#define NLA_PUT_U32 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint32_t, attrtype, value) |
Add 32 bit integer attribute to netlink message.
Referenced by rtnl_link_build_change_request(), rtnl_neightbl_build_change_request(), and rtnl_route_build_msg().
#define NLA_PUT_U64 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint64_t, attrtype, value) |
Add 64 bit integer attribute to netlink message.
Referenced by rtnl_neightbl_build_change_request().
#define NLA_PUT_U8 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint8_t, attrtype, value) |
Add 8 bit integer attribute to netlink message.
Referenced by rtnl_link_build_change_request().
anonymous enum |
Basic attribute data types.
See Attribute Data Types for more details.
EXPORT_SYMBOL | ( | mnl_attr_get_type | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_len | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_payload_len | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_payload | ) |
EXPORT_SYMBOL | ( | mnl_attr_ok | ) |
EXPORT_SYMBOL | ( | mnl_attr_next | ) |
EXPORT_SYMBOL | ( | mnl_attr_type_valid | ) |
EXPORT_SYMBOL | ( | mnl_attr_validate | ) |
EXPORT_SYMBOL | ( | mnl_attr_validate2 | ) |
EXPORT_SYMBOL | ( | mnl_attr_parse | ) |
EXPORT_SYMBOL | ( | mnl_attr_parse_nested | ) |
EXPORT_SYMBOL | ( | mnl_attr_parse_payload | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_u8 | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_u16 | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_u32 | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_u64 | ) |
EXPORT_SYMBOL | ( | mnl_attr_get_str | ) |
EXPORT_SYMBOL | ( | mnl_attr_put | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u8 | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u16 | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u32 | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u64 | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_str | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_strz | ) |
EXPORT_SYMBOL | ( | mnl_attr_nest_start | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u8_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u16_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u32_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_u64_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_str_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_put_strz_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_nest_start_check | ) |
EXPORT_SYMBOL | ( | mnl_attr_nest_end | ) |
EXPORT_SYMBOL | ( | mnl_attr_nest_cancel | ) |
mnl_attr_get_len - get length of netlink attribute
attr | pointer to netlink attribute |
This function returns the attribute length that is the attribute header plus the attribute payload.
References nlattr::nla_len.
mnl_attr_get_payload - get pointer to the attribute payload
attr | pointer to netlink attribute |
This function return a pointer to the attribute payload.
References MNL_ATTR_HDRLEN.
Referenced by mnl_attr_get_str(), mnl_attr_get_u16(), mnl_attr_get_u32(), mnl_attr_get_u64(), mnl_attr_get_u8(), mnl_attr_put(), and nft_rule_nlmsg_parse().
mnl_attr_get_payload_len - get the attribute payload-value length
attr | pointer to netlink attribute |
This function returns the attribute payload-value length.
References MNL_ATTR_HDRLEN, and nlattr::nla_len.
Referenced by nft_rule_nlmsg_parse().
mnl_attr_get_str - returns pointer to string attribute.
attr | pointer to netlink attribute |
This function returns the payload of string attribute value.
References mnl_attr_get_payload().
Referenced by nfacct_nlmsg_parse_payload(), nfct_helper_nlmsg_parse_payload(), nfct_timeout_nlmsg_parse_payload(), nfexp_nlmsg_parse(), nft_chain_nlmsg_parse(), nft_rule_nlmsg_parse(), nft_set_elems_nlmsg_parse(), nft_set_nlmsg_parse(), and nft_table_nlmsg_parse().
mnl_attr_get_type - get type of netlink attribute
attr | pointer to netlink attribute |
This function returns the attribute type.
References nlattr::nla_type, and NLA_TYPE_MASK.
Referenced by mnl_attr_type_valid().
mnl_attr_get_u16 - returns 16-bit unsigned integer attribute payload
attr | pointer to netlink attribute |
This function returns the 16-bit value of the attribute payload.
References mnl_attr_get_payload().
Referenced by nfct_payload_parse(), nfct_timeout_nlmsg_parse_payload(), and nfexp_nlmsg_parse().
mnl_attr_get_u32 - returns 32-bit unsigned integer attribute payload
attr | pointer to netlink attribute |
This function returns the 32-bit value of the attribute payload.
References mnl_attr_get_payload().
Referenced by nfacct_nlmsg_parse_payload(), nfct_helper_nlmsg_parse_payload(), nfct_payload_parse(), nfexp_nlmsg_parse(), nft_chain_nlmsg_parse(), nft_gen_nlmsg_parse(), nft_set_elems_nlmsg_parse(), nft_set_nlmsg_parse(), and nft_table_nlmsg_parse().
mnl_attr_get_u64 - returns 64-bit unsigned integer attribute.
attr | pointer to netlink attribute |
This function returns the 64-bit value of the attribute payload. This function is align-safe, since accessing 64-bit Netlink attributes is a common source of alignment issues.
References mnl_attr_get_payload().
Referenced by nfacct_nlmsg_parse_payload(), nft_chain_nlmsg_parse(), and nft_rule_nlmsg_parse().
mnl_attr_get_u8 - returns 8-bit unsigned integer attribute payload
attr | pointer to netlink attribute |
This function returns the 8-bit value of the attribute payload.
References mnl_attr_get_payload().
Referenced by nfct_timeout_nlmsg_parse_payload().
mnl_attr_nest_cancel - cancel an attribute nest
nlh | pointer to the netlink message |
start | pointer to the attribute nest returned by mnl_attr_nest_start() |
This function updates the attribute header that identifies the nest.
References mnl_nlmsg_get_payload_tail(), and nlmsghdr::nlmsg_len.
Referenced by nfct_build_tuple().
mnl_attr_nest_end - end an attribute nest
nlh | pointer to the netlink message |
start | pointer to the attribute nest returned by mnl_attr_nest_start() |
This function updates the attribute header that identifies the nest.
References mnl_nlmsg_get_payload_tail(), and nlattr::nla_len.
Referenced by nfct_build_tuple(), nfct_helper_nlmsg_build_payload(), nfct_timeout_nlmsg_build_payload(), nft_chain_nlmsg_build_payload(), nft_rule_expr_build_payload(), nft_rule_nlmsg_build_payload(), nft_set_elem_nlmsg_build_payload(), nft_set_elems_nlmsg_build_payload(), and nft_set_elems_nlmsg_build_payload_iter().
mnl_attr_nest_start - start an attribute nest
nlh | pointer to the netlink message |
type | netlink attribute type |
This function adds the attribute header that identifies the beginning of an attribute nest. This function always returns a valid pointer to the beginning of the nest.
References MNL_ALIGN, mnl_nlmsg_get_payload_tail(), NLA_F_NESTED, nlattr::nla_type, nlmsghdr::nlmsg_len, and type.
Referenced by mnl_attr_nest_start_check(), nfct_build_tuple(), nfct_helper_nlmsg_build_payload(), nfct_timeout_nlmsg_build_payload(), nft_chain_nlmsg_build_payload(), nft_rule_expr_build_payload(), nft_rule_nlmsg_build_payload(), nft_set_elem_nlmsg_build_payload(), nft_set_elems_nlmsg_build_payload(), and nft_set_elems_nlmsg_build_payload_iter().
mnl_attr_nest_start_check - start an attribute nest
buflen | size of buffer which stores the message |
nlh | pointer to the netlink message |
type | netlink attribute type |
This function adds the attribute header that identifies the beginning of an attribute nest. If the nested attribute cannot be added then NULL, otherwise valid pointer to the beginning of the nest is returned.
References MNL_ATTR_HDRLEN, mnl_attr_nest_start(), nlmsghdr::nlmsg_len, and NULL.
mnl_attr_next - get the next attribute in the payload of a netlink message
attr | pointer to the current attribute |
This function returns a pointer to the next attribute after the one passed as parameter. You have to use mnl_attr_ok() to ensure that the next attribute is valid.
References MNL_ALIGN, and nlattr::nla_len.
mnl_attr_ok - check if there is room for an attribute in a buffer
attr | attribute that we want to check if there is room for |
len | remaining bytes in a buffer that contains the attribute |
This function is used to check that a buffer, which is supposed to contain an attribute, has enough room for the attribute that it stores, i.e. this function can be used to verify that an attribute is neither malformed nor truncated.
This function does not set errno in case of error since it is intended for iterations. Thus, it returns true on success and false on error.
The len parameter may be negative in the case of malformed messages during attribute iteration, that is why we use a signed integer.
References nlattr::nla_len.
int mnl_attr_parse | ( | const struct nlmsghdr * | nlh, |
unsigned int | offset, | ||
mnl_attr_cb_t | cb, | ||
void * | data | ||
) |
mnl_attr_parse - parse attributes
nlh | pointer to netlink message |
offset | offset to start parsing from (if payload is after any header) |
cb | callback function that is called for each attribute |
data | pointer to data that is passed to the callback function |
This function allows to iterate over the sequence of attributes that compose the Netlink message. You can then put the attribute in an array as it usually happens at this stage or you can use any other data structure (such as lists or trees).
This function propagates the return value of the callback, which can be MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
References mnl_attr_for_each, MNL_CB_OK, and MNL_CB_STOP.
Referenced by ipset_debug_msg(), nfacct_nlmsg_parse_payload(), nfct_helper_nlmsg_parse_payload(), nfct_timeout_nlmsg_parse_payload(), nfexp_nlmsg_parse(), nfq_nlmsg_parse(), nft_chain_nlmsg_parse(), nft_gen_nlmsg_parse(), nft_rule_nlmsg_parse(), nft_set_elems_nlmsg_parse(), nft_set_nlmsg_parse(), and nft_table_nlmsg_parse().
int mnl_attr_parse_nested | ( | const struct nlattr * | nested, |
mnl_attr_cb_t | cb, | ||
void * | data | ||
) |
mnl_attr_parse_nested - parse attributes inside a nest
nested | pointer to netlink attribute that contains a nest |
cb | callback function that is called for each attribute in the nest |
data | pointer to data passed to the callback function |
This function allows to iterate over the sequence of attributes that compose the Netlink message. You can then put the attribute in an array as it usually happens at this stage or you can use any other data structure (such as lists or trees).
This function propagates the return value of the callback, which can be MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
References mnl_attr_for_each_nested, MNL_CB_OK, and MNL_CB_STOP.
Referenced by nfct_parse_tuple(), and nft_parse_data().
int mnl_attr_parse_payload | ( | const void * | payload, |
size_t | payload_len, | ||
mnl_attr_cb_t | cb, | ||
void * | data | ||
) |
mnl_attr_parse_payload - parse attributes in payload of Netlink message
payload | pointer to payload of the Netlink message |
payload_len | payload length that contains the attributes |
cb | callback function that is called for each attribute |
data | pointer to data that is passed to the callback function |
This function takes a pointer to the area that contains the attributes, commonly known as the payload of the Netlink message. Thus, you have to pass a pointer to the Netlink message payload, instead of the entire message.
This function allows you to iterate over the sequence of attributes that are located at some payload offset. You can then put the attributes in one array as usual, or you can use any other data structure (such as lists or trees).
This function propagates the return value of the callback, which can be MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
References mnl_attr_for_each_payload, MNL_CB_OK, and MNL_CB_STOP.
Referenced by nfct_payload_parse().
mnl_attr_put - add an attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type that you want to add |
len | netlink attribute payload length |
data | pointer to the data that will be stored by the new attribute |
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References len, MNL_ALIGN, mnl_attr_get_payload(), mnl_nlmsg_get_payload_tail(), nlattr::nla_len, nlattr::nla_type, nlmsghdr::nlmsg_len, and type.
Referenced by mnl_attr_put_check(), mnl_attr_put_str(), mnl_attr_put_strz(), mnl_attr_put_u16(), mnl_attr_put_u32(), mnl_attr_put_u64(), mnl_attr_put_u8(), nfq_nlmsg_cfg_put_cmd(), nfq_nlmsg_cfg_put_params(), nfq_nlmsg_verdict_put(), nfq_nlmsg_verdict_put_pkt(), nft_rule_nlmsg_build_payload(), and nft_set_elem_nlmsg_build_payload().
bool mnl_attr_put_check | ( | struct nlmsghdr * | nlh, |
size_t | buflen, | ||
uint16_t | type, | ||
size_t | len, | ||
const void * | data | ||
) |
mnl_attr_put_check - add an attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type that you want to add |
len | netlink attribute payload length |
data | pointer to the data that will be stored by the new attribute |
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned.
References MNL_ALIGN, MNL_ATTR_HDRLEN, mnl_attr_put(), and nlmsghdr::nlmsg_len.
Referenced by mnl_attr_put_str_check(), mnl_attr_put_strz_check(), mnl_attr_put_u16_check(), mnl_attr_put_u32_check(), mnl_attr_put_u64_check(), and mnl_attr_put_u8_check().
mnl_attr_put_str - add string attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type |
data | pointer to string data that is stored by the new attribute |
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put().
bool mnl_attr_put_str_check | ( | struct nlmsghdr * | nlh, |
size_t | buflen, | ||
uint16_t | type, | ||
const char * | data | ||
) |
mnl_attr_put_str_check - add string attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type |
data | pointer to string data that is stored by the new attribute |
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned. This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put_check().
mnl_attr_put_strz - add string attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type |
data | pointer to string data that is stored by the new attribute |
This function is similar to mnl_attr_put_str, but it includes the NUL/zero ('\0') terminator at the end of the string.
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put().
Referenced by nfacct_nlmsg_build_payload(), nfct_helper_nlmsg_build_payload(), nfct_timeout_nlmsg_build_payload(), nfexp_nlmsg_build(), nft_chain_nlmsg_build_payload(), nft_compatible_revision(), nft_rule_expr_build_payload(), nft_rule_nlmsg_build_payload(), nft_set_elem_nlmsg_build_payload(), nft_set_nlmsg_build_payload(), and nft_table_nlmsg_build_payload().
bool mnl_attr_put_strz_check | ( | struct nlmsghdr * | nlh, |
size_t | buflen, | ||
uint16_t | type, | ||
const char * | data | ||
) |
mnl_attr_put_strz_check - add string attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type |
data | pointer to string data that is stored by the new attribute |
This function is similar to mnl_attr_put_str, but it includes the NUL/zero ('\0') terminator at the end of the string.
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned.
References mnl_attr_put_check().
mnl_attr_put_u16 - add 16-bit unsigned integer attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type |
data | 16-bit unsigned integer data that is stored by the new attribute |
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put().
Referenced by nfct_helper_nlmsg_build_payload(), nfct_timeout_nlmsg_build_payload(), and nfexp_nlmsg_build().
mnl_attr_put_u16_check - add 16-bit unsigned int attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type |
data | 16-bit unsigned integer data that is stored by the new attribute |
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned. This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put_check().
mnl_attr_put_u32 - add 32-bit unsigned integer attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type |
data | 32-bit unsigned integer data that is stored by the new attribute |
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put().
Referenced by nfacct_nlmsg_build_payload(), nfct_helper_nlmsg_build_payload(), nfct_timeout_nlmsg_build_payload(), nfexp_nlmsg_build(), nfq_nlmsg_cfg_put_qmaxlen(), nfq_nlmsg_verdict_put_mark(), nft_chain_nlmsg_build_payload(), nft_compatible_revision(), nft_rule_nlmsg_build_payload(), nft_set_elem_nlmsg_build_payload(), nft_set_nlmsg_build_payload(), and nft_table_nlmsg_build_payload().
mnl_attr_put_u32_check - add 32-bit unsigned int attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type |
data | 32-bit unsigned integer data that is stored by the new attribute |
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned. This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put_check().
mnl_attr_put_u64 - add 64-bit unsigned integer attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type |
data | 64-bit unsigned integer data that is stored by the new attribute |
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put().
Referenced by nfacct_nlmsg_build_payload(), nft_chain_nlmsg_build_payload(), and nft_rule_nlmsg_build_payload().
mnl_attr_put_u64_check - add 64-bit unsigned int attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type |
data | 64-bit unsigned integer data that is stored by the new attribute |
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned. This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put_check().
mnl_attr_put_u8 - add 8-bit unsigned integer attribute to netlink message
nlh | pointer to the netlink message |
type | netlink attribute type |
data | 8-bit unsigned integer data that is stored by the new attribute |
This function updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute.
References mnl_attr_put().
Referenced by nfct_helper_nlmsg_build_payload(), and nfct_timeout_nlmsg_build_payload().
mnl_attr_put_u8_check - add 8-bit unsigned int attribute to netlink message
nlh | pointer to the netlink message |
buflen | size of buffer which stores the message |
type | netlink attribute type |
data | 8-bit unsigned integer data that is stored by the new attribute |
This function first checks that the data can be added to the message (fits into the buffer) and then updates the length field of the Netlink message (nlmsg_len) by adding the size (header + payload) of the new attribute. The function returns true if the attribute could be added to the message, otherwise false is returned.
References mnl_attr_put_check().
mnl_attr_type_valid - check if the attribute type is valid
attr | pointer to attribute to be checked |
max | maximum attribute type |
This function allows to check if the attribute type is higher than the maximum supported type. If the attribute type is invalid, this function returns -1 and errno is explicitly set. On success, this function returns 1.
Strict attribute checking in user-space is not a good idea since you may run an old application with a newer kernel that supports new attributes. This leads to backward compatibility breakages in user-space. Better check if you support an attribute, if not, skip it.
References mnl_attr_get_type().
int mnl_attr_validate | ( | const struct nlattr * | attr, |
enum mnl_attr_data_type | type | ||
) |
mnl_attr_validate - validate netlink attribute (simplified version)
attr | pointer to netlink attribute that we want to validate |
type | data type (see enum mnl_attr_data_type) |
The validation is based on the data type. Specifically, it checks that integers (u8, u16, u32 and u64) have enough room for them. This function returns -1 in case of error, and errno is explicitly set.
References MNL_TYPE_MAX, and type.
int mnl_attr_validate2 | ( | const struct nlattr * | attr, |
enum mnl_attr_data_type | type, | ||
size_t | exp_len | ||
) |
mnl_attr_validate2 - validate netlink attribute (extended version)
attr | pointer to netlink attribute that we want to validate |
type | attribute type (see enum mnl_attr_data_type) |
exp_len | expected attribute data size |
This function allows to perform a more accurate validation for attributes whose size is variable. If the size of the attribute is not what we expect, this functions returns -1 and errno is explicitly set.
References MNL_TYPE_MAX.
int nla_attr_size | ( | int | payload | ) |
Return size of attribute whithout padding.
References NLA_HDRLEN, and payload.
Referenced by nla_padlen(), nla_reserve(), and nla_total_size().
Return pointer to the payload section.
References NLA_HDRLEN.
Referenced by ip_set_get_ipaddr6(), nfnl_nft_data_parse(), nfnlmsg_log_msg_parse(), nfnlmsg_nft_chain_parse(), nfnlmsg_nft_rule_parse(), nfnlmsg_nft_set_parse(), nfnlmsg_nft_table_parse(), nfnlmsg_queue_msg_parse(), nft_expr_lookup_ops(), nl_addr_alloc_attr(), nl_data_alloc_attr(), nla_get_string(), nla_get_u16(), nla_get_u32(), nla_get_u8(), nla_memcmp(), nla_memcpy(), nla_parse_nested(), nla_put(), nla_strcmp(), nla_strlcpy(), and rtnl_ematch_parse().
Find a single attribute in a stream of attributes.
Iterates over the stream of attributes and compares each type with the type specified. Returns the first attribute which matches the type.
References nla_for_each_attr, nla_type(), and NULL.
Referenced by nlmsg_find_attr().
Return true if flag attribute is set.
Return payload of msecs attribute.
References nla_get_u64().
Return payload of string attribute.
References nla_data().
Referenced by nla_strdup().
Return payload of 16 bit integer attribute.
References nla_data().
Return payload of 32 bit integer attribute.
References nla_data().
Referenced by nfnl_nft_data_parse(), nfnlmsg_ct_parse(), nfnlmsg_log_msg_parse(), nfnlmsg_nft_chain_parse(), nfnlmsg_nft_set_parse(), nfnlmsg_queue_msg_parse(), and rtnl_route_parse().
Return payload of u64 attribute.
References nla_memcpy().
Referenced by nfnlmsg_nft_chain_parse(), nfnlmsg_nft_rule_parse(), and nla_get_msecs().
Return value of 8 bit integer attribute.
References nla_data().
Return length of the payload .
References NLA_HDRLEN, and nlattr::nla_len.
Referenced by nfnl_nft_data_parse(), nfnlmsg_log_msg_parse(), nfnlmsg_nft_chain_parse(), nfnlmsg_nft_rule_parse(), nfnlmsg_nft_set_parse(), nfnlmsg_nft_table_parse(), nfnlmsg_queue_msg_parse(), nl_addr_alloc_attr(), nl_data_alloc_attr(), nla_memcmp(), nla_memcpy(), nla_parse_nested(), nla_strcmp(), nla_strlcpy(), rtnl_ematch_parse(), and rtnl_route_parse().
Compare attribute payload with memory area.
References nla_data(), nla_len(), and size.
Copy attribute payload to another memory area.
Note: The number of bytes copied is limited by the length of the attribute payload.
References min_t, nla_data(), and nla_len().
Referenced by nla_get_u64(), and rtnl_route_parse().
Finalize nesting of attributes.
Corrects the container attribute header to include the appeneded attributes.
References nlattr::nla_len, nlmsg_tail(), and nl_msg::nm_nlh.
Referenced by nfnl_nft_data_put(), nfnl_nft_expr_build_message(), rtnl_link_build_change_request(), and rtnl_route_build_msg().
Start a new level of nested attributes.
References nla_put(), nlmsg_tail(), nl_msg::nm_nlh, and NULL.
Referenced by nfnl_nft_data_put(), nfnl_nft_expr_build_message(), rtnl_link_build_change_request(), and rtnl_route_build_msg().
Return next attribute in a stream of attributes.
Calculates the offset to the next attribute based on the attribute given. The attribute provided is assumed to be accessible, the caller is responsible to use nla_ok() beforehand. The offset (length of specified attribute including padding) is then subtracted from the remaining bytes variable and a pointer to the next attribute is returned.
nla_next() can be called as long as remainig is >0.
References NLA_ALIGN, and nlattr::nla_len.
Check if the attribute header and payload can be accessed safely.
Verifies that the header and payload do not exceed the number of bytes left in the attribute stream. This function must be called before access the attribute header or payload when iterating over the attribute stream using nla_next().
References nlattr::nla_len.
int nla_padlen | ( | int | payload | ) |
Return length of padding at the tail of the attribute.
References nla_attr_size(), and nla_total_size().
Referenced by nla_reserve().
int nla_parse | ( | struct nlattr * | tb[], |
int | maxtype, | ||
struct nlattr * | head, | ||
int | len, | ||
struct nla_policy * | policy | ||
) |
Create attribute index based on a stream of attributes.
Iterates over the stream of attributes and stores a pointer to each attribute in the index array using the attribute type as index to the array. Attribute with a type greater than the maximum type specified will be silently ignored in order to maintain backwards compatibility. If policy is not NULL, the attribute will be validated using the specified policy.
References nla_for_each_attr, nla_type(), and type.
Referenced by nla_parse_nested().
int nla_parse_nested | ( | struct nlattr * | tb[], |
int | maxtype, | ||
struct nlattr * | nla, | ||
struct nla_policy * | policy | ||
) |
Create attribute index based on nested attribute.
Feeds the stream of attributes nested into the specified attribute to nla_parse().
References nla_data(), nla_len(), and nla_parse().
Add a unspecific attribute to netlink message.
Reserves room for a unspecific attribute and copies the provided data into the message as payload of the attribute. Returns an error if there is insufficient space for the attribute.
References NL_DBG, nla_data(), nla_reserve(), NLE_NOMEM, nlmsg_data(), and nl_msg::nm_nlh.
Referenced by nfnl_log_build_create_request(), nfnl_nft_data_put(), nfnl_queue_msg_build_verdict(), nla_nest_start(), nla_put_addr(), nla_put_data(), nla_put_flag(), nla_put_nested(), nla_put_string(), nla_put_u16(), nla_put_u32(), nla_put_u64(), and nla_put_u8().
Add abstract address as unspecific attribute to netlink message.
References nl_addr_get_binary_addr(), nl_addr_get_len(), and nla_put().
Referenced by main().
Add abstract data as unspecific attribute to netlink message.
Equivalent to nla_put() except that the length of the payload is derived from the abstract data object.
References nl_data_get(), nl_data_get_size(), and nla_put().
Add a msecs netlink attribute to a netlink message.
References nla_put_u64().
Add nested attributes to netlink message.
Takes the attributes found in the nested message and appends them to the message msg nested in a container of the type attrtype. The nested message may not have a family specific header.
References nla_put(), nlmsg_data(), nlmsg_len(), and nl_msg::nm_nlh.
Referenced by rtnl_neightbl_build_change_request().
Add string attribute to netlink message.
References nla_put().
Referenced by nfnl_nft_data_put(), and nfnl_nft_expr_build_message().
Add 32 bit integer attribute to netlink message.
References nla_put().
Referenced by nfnl_nft_data_put(), and nfnl_queue_msg_build_verdict().
Add 64 bit integer attribute to netlink message.
References nla_put().
Referenced by nla_put_msecs().
Reserve space for a attribute.
Reserves room for a attribute in the specified netlink message and fills in the attribute header (type, length). Returns NULL if there is unsuficient space for the attribute.
Any padding between payload and the start of the next attribute is zeroed out.
References NL_DBG, nla_attr_size(), nlattr::nla_len, nla_padlen(), nla_total_size(), nlattr::nla_type, NLMSG_ALIGN, nlmsg_data(), nlmsghdr::nlmsg_len, nlmsg_tail(), nl_msg::nm_nlh, nl_msg::nm_size, and NULL.
Referenced by nla_put().
Compare string attribute payload with string.
References len, nla_data(), and nla_len().
References nla_get_string().
Referenced by nfnl_nft_data_parse().
Copy string attribute payload to a buffer.
Copies at most dstsize - 1 bytes to the destination buffer. The result is always a valid NUL terminated string. Unlike strlcpy the destination buffer is always padded out.
References len, nla_data(), and nla_len().
int nla_total_size | ( | int | payload | ) |
Return size of attribute including padding.
References NLA_ALIGN, and nla_attr_size().
Referenced by nla_padlen(), nla_reserve(), and rtnl_ematch_parse().
Return type of the attribute.
References nlattr::nla_type, and NLA_TYPE_MASK.
Referenced by nfnlmsg_nft_rule_parse(), nla_find(), and nla_parse().
int nla_validate | ( | struct nlattr * | head, |
int | len, | ||
int | maxtype, | ||
struct nla_policy * | policy | ||
) |
Validate a stream of attributes.
Iterates over the stream of attributes and validates each attribute one by one using the specified policy. Attributes with a type greater than the maximum type specified will be silently ignored in order to maintain backwards compatibility.
See Attribute Data Types for more details on what kind of validation checks are performed on each attribute data type.
References nla_for_each_attr.
Referenced by genlmsg_validate(), and nlmsg_validate().