libnl
3.2.24-rc1
|
Netlink Attributes Construction/Parsing Interface. More...
Data Structures | |
struct | nla_policy |
Attribute validation policy. 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... | |
void | nla_nest_cancel (struct nl_msg *msg, struct nlattr *attr) |
Cancel the addition of a nested attribute. 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... | |
int | nla_is_nested (struct nlattr *attr) |
Return true if attribute has NLA_F_NESTED flag set. More... | |
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... | |
Netlink Attributes Construction/Parsing Interface.
Related sections in the development guide:
#define NLA_PUT | ( | msg, | |
attrtype, | |||
attrlen, | |||
data | |||
) |
Add unspecific attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
attrlen | Length of attribute payload. |
data | Head of attribute payload. |
#define NLA_PUT_TYPE | ( | msg, | |
type, | |||
attrtype, | |||
value | |||
) |
#define nla_for_each_attr | ( | pos, | |
head, | |||
len, | |||
rem | |||
) |
Iterate over a stream of attributes.
pos | loop counter, set to current attribute |
head | head of attribute stream |
len | length of attribute stream |
rem | initialized to len, holds bytes currently remaining in stream |
Definition at line 262 of file attr.h.
Referenced by nla_find(), nla_parse(), and nla_validate().
#define nla_for_each_nested | ( | pos, | |
nla, | |||
rem | |||
) |
Iterate over a stream of nested attributes.
pos | loop counter, set to current attribute |
nla | attribute containing the nested attributes |
rem | initialized to len, holds bytes currently remaining in stream |
Definition at line 274 of file attr.h.
Referenced by rtnl_ematch_parse_attr().
#define NLA_PUT_U8 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint8_t, attrtype, value) |
#define NLA_PUT_U16 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint16_t, attrtype, value) |
#define NLA_PUT_U32 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint32_t, attrtype, value) |
Add 32 bit integer attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | Numeric value. |
Definition at line 189 of file attr.h.
Referenced by rtnl_neightbl_build_change_request().
#define NLA_PUT_U64 | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT_TYPE(msg, uint64_t, attrtype, value) |
Add 64 bit integer attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | Numeric value. |
Definition at line 198 of file attr.h.
Referenced by rtnl_neightbl_build_change_request().
#define NLA_PUT_STRING | ( | msg, | |
attrtype, | |||
value | |||
) | NLA_PUT(msg, attrtype, strlen(value) + 1, value) |
Add string attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | NUL terminated character string. |
Definition at line 207 of file attr.h.
Referenced by rtnl_link_build_delete_request(), rtnl_link_build_get_request(), rtnl_neightbl_build_change_request(), and rtnl_qdisc_build_delete_request().
#define NLA_PUT_FLAG | ( | msg, | |
attrtype | |||
) | NLA_PUT(msg, attrtype, 0, NULL) |
#define NLA_PUT_MSECS | ( | msg, | |
attrtype, | |||
msecs | |||
) | NLA_PUT_U64(msg, attrtype, msecs) |
#define NLA_PUT_ADDR | ( | msg, | |
attrtype, | |||
addr | |||
) |
Add address attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
addr | Abstract address object. |
#define NLA_PUT_DATA | ( | msg, | |
attrtype, | |||
data | |||
) |
Add abstract data attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
data | Abstract data object. |
anonymous enum |
Basic attribute data types.
See section Attribute Parsing (Netlink Core Library Development Guide) for more details.
int nla_attr_size | ( | int | payload | ) |
Return size of attribute whithout padding.
payload | Payload length of attribute. |
Definition at line 55 of file attr.c.
Referenced by nla_padlen(), nla_reserve(), and nla_total_size().
int nla_total_size | ( | int | payload | ) |
Return size of attribute including padding.
payload | Payload length of attribute. |
Definition at line 73 of file attr.c.
References nla_attr_size().
Referenced by nla_padlen(), nla_reserve(), and rtnl_ematch_parse_attr().
int nla_padlen | ( | int | payload | ) |
Return length of padding at the tail of the attribute.
payload | Payload length of attribute. |
Definition at line 91 of file attr.c.
References nla_attr_size(), and nla_total_size().
Referenced by nla_reserve().
int nla_type | ( | const struct nlattr * | nla | ) |
Return type of the attribute.
nla | Attribute. |
Definition at line 109 of file attr.c.
Referenced by nla_find(), and nla_parse().
void* nla_data | ( | const struct nlattr * | nla | ) |
Return pointer to the payload section.
nla | Attribute. |
Definition at line 120 of file attr.c.
Referenced by 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_attr().
int nla_len | ( | const struct nlattr * | nla | ) |
Return length of the payload .
nla | Attribute |
Definition at line 131 of file attr.c.
Referenced by nl_addr_alloc_attr(), nl_data_alloc_attr(), nla_memcmp(), nla_memcpy(), nla_parse_nested(), nla_strcmp(), nla_strlcpy(), and rtnl_ematch_parse_attr().
int nla_ok | ( | const struct nlattr * | nla, |
int | remaining | ||
) |
Check if the attribute header and payload can be accessed safely.
nla | Attribute of any kind. |
remaining | Number of bytes remaining in attribute stream. |
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().
|
read |
Return next attribute in a stream of attributes.
nla | Attribute of any kind. |
remaining | Variable to count remaining bytes in stream. |
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.
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.
tb | Index array to be filled (maxtype+1 elements). |
maxtype | Maximum attribute type expected and accepted. |
head | Head of attribute stream. |
len | Length of attribute stream. |
policy | Attribute validation policy. |
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.
Definition at line 242 of file attr.c.
References nla_for_each_attr, and nla_type().
Referenced by genlmsg_parse(), nla_parse_nested(), and nlmsg_parse().
int nla_validate | ( | struct nlattr * | head, |
int | len, | ||
int | maxtype, | ||
struct nla_policy * | policy | ||
) |
Validate a stream of attributes.
head | Head of attributes stream. |
len | Length of attributes stream. |
maxtype | Maximum attribute type expected and accepted. |
policy | Validation policy. |
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 section Attribute Parsing (Netlink Core Library Development Guide) for more details.
Definition at line 294 of file attr.c.
References nla_for_each_attr.
Referenced by genlmsg_validate(), and nlmsg_validate().
|
read |
Find a single attribute in a stream of attributes.
head | Head of attributes stream. |
len | Length of attributes stream. |
attrtype | Attribute type to look for. |
Iterates over the stream of attributes and compares each type with the type specified. Returns the first attribute which matches the type.
Definition at line 323 of file attr.c.
References nla_for_each_attr, and nla_type().
Referenced by nlmsg_find_attr().
int nla_memcpy | ( | void * | dest, |
struct nlattr * | src, | ||
int | count | ||
) |
Copy attribute payload to another memory area.
dest | Pointer to destination memory area. |
src | Attribute |
count | Number of bytes to copy at most. |
Note: The number of bytes copied is limited by the length of the attribute payload.
Definition at line 353 of file attr.c.
References nla_data(), and nla_len().
Referenced by nla_get_u64().
size_t nla_strlcpy | ( | char * | dst, |
const struct nlattr * | nla, | ||
size_t | dstsize | ||
) |
Copy string attribute payload to a buffer.
dst | Pointer to destination buffer. |
nla | Attribute of type NLA_STRING. |
dstsize | Size of destination buffer in bytes. |
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.
Definition at line 378 of file attr.c.
References nla_data(), and nla_len().
int nla_memcmp | ( | const struct nlattr * | nla, |
const void * | data, | ||
size_t | size | ||
) |
Compare attribute payload with memory area.
nla | Attribute. |
data | Memory area to compare to. |
size | Number of bytes to compare. |
Definition at line 405 of file attr.c.
References nla_data(), and nla_len().
int nla_strcmp | ( | const struct nlattr * | nla, |
const char * | str | ||
) |
Compare string attribute payload with string.
nla | Attribute of type NLA_STRING. |
str | NUL terminated string. |
Definition at line 423 of file attr.c.
References nla_data(), and nla_len().
|
read |
Reserve space for a attribute.
msg | Netlink Message. |
attrtype | Attribute Type. |
attrlen | Length of payload. |
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.
Definition at line 456 of file attr.c.
References nla_attr_size(), nla_padlen(), nla_total_size(), and nlmsg_data().
Referenced by nla_put().
int nla_put | ( | struct nl_msg * | msg, |
int | attrtype, | ||
int | datalen, | ||
const void * | data | ||
) |
Add a unspecific attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
datalen | Length of data to be used as payload. |
data | Pointer to data to be used as attribute payload. |
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.
Definition at line 497 of file attr.c.
References nla_data(), nla_reserve(), and nlmsg_data().
Referenced by 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().
int nla_put_data | ( | struct nl_msg * | msg, |
int | attrtype, | ||
struct nl_data * | data | ||
) |
Add abstract data as unspecific attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
data | Abstract data object. |
Equivalent to nla_put() except that the length of the payload is derived from the abstract data object.
Definition at line 527 of file attr.c.
References nl_data_get(), nl_data_get_size(), and nla_put().
int nla_put_addr | ( | struct nl_msg * | msg, |
int | attrtype, | ||
struct nl_addr * | addr | ||
) |
Add abstract address as unspecific attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
addr | Abstract address object. |
Definition at line 542 of file attr.c.
References nl_addr_get_binary_addr(), nl_addr_get_len(), and nla_put().
int nla_put_u8 | ( | struct nl_msg * | msg, |
int | attrtype, | ||
uint8_t | value | ||
) |
Add 8 bit integer attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | Numeric value to store as payload. |
Definition at line 563 of file attr.c.
References nla_put().
uint8_t nla_get_u8 | ( | struct nlattr * | nla | ) |
Return value of 8 bit integer attribute.
nla | 8 bit integer attribute |
Definition at line 574 of file attr.c.
References nla_data().
int nla_put_u16 | ( | struct nl_msg * | msg, |
int | attrtype, | ||
uint16_t | value | ||
) |
Add 16 bit integer attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | Numeric value to store as payload. |
Definition at line 588 of file attr.c.
References nla_put().
uint16_t nla_get_u16 | ( | struct nlattr * | nla | ) |
Return payload of 16 bit integer attribute.
nla | 16 bit integer attribute |
Definition at line 599 of file attr.c.
References nla_data().
int nla_put_u32 | ( | struct nl_msg * | msg, |
int | attrtype, | ||
uint32_t | value | ||
) |
Add 32 bit integer attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | Numeric value to store as payload. |
Definition at line 613 of file attr.c.
References nla_put().
uint32_t nla_get_u32 | ( | struct nlattr * | nla | ) |
Return payload of 32 bit integer attribute.
nla | 32 bit integer attribute. |
Definition at line 624 of file attr.c.
References nla_data().
int nla_put_u64 | ( | struct nl_msg * | msg, |
int | attrtype, | ||
uint64_t | value | ||
) |
Add 64 bit integer attribute to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
value | Numeric value to store as payload. |
Definition at line 638 of file attr.c.
References nla_put().
Referenced by nla_put_msecs().
uint64_t nla_get_u64 | ( | struct nlattr * | nla | ) |
Return payload of u64 attribute.
nla | u64 netlink attribute |
Definition at line 649 of file attr.c.
References nla_memcpy().
Referenced by nla_get_msecs().
int nla_put_string | ( | struct nl_msg * | msg, |
int | attrtype, | ||
const char * | str | ||
) |
char* nla_get_string | ( | struct nlattr * | nla | ) |
Return payload of string attribute.
nla | String attribute. |
Definition at line 684 of file attr.c.
References nla_data().
int nla_put_flag | ( | struct nl_msg * | msg, |
int | attrtype | ||
) |
int nla_get_flag | ( | struct nlattr * | nla | ) |
int nla_put_msecs | ( | struct nl_msg * | n, |
int | attrtype, | ||
unsigned long | msecs | ||
) |
Add a msecs netlink attribute to a netlink message.
n | netlink message |
attrtype | attribute type |
msecs | number of msecs |
Definition at line 736 of file attr.c.
References nla_put_u64().
unsigned long nla_get_msecs | ( | struct nlattr * | nla | ) |
Return payload of msecs attribute.
nla | msecs netlink attribute |
Definition at line 747 of file attr.c.
References nla_get_u64().
int nla_put_nested | ( | struct nl_msg * | msg, |
int | attrtype, | ||
struct nl_msg * | nested | ||
) |
Add nested attributes to netlink message.
msg | Netlink message. |
attrtype | Attribute type. |
nested | Message containing attributes to be nested. |
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.
Definition at line 771 of file attr.c.
References nla_put(), nlmsg_data(), and nlmsg_datalen().
Referenced by rtnl_neightbl_build_change_request().
|
read |
int nla_nest_end | ( | struct nl_msg * | msg, |
struct nlattr * | start | ||
) |
Finalize nesting of attributes.
msg | Netlink message. |
start | Container attribute as returned from nla_nest_start(). |
Corrects the container attribute header to include the appeneded attributes.
Definition at line 810 of file attr.c.
References nla_nest_cancel(), and nlmsg_reserve().
void nla_nest_cancel | ( | struct nl_msg * | msg, |
struct nlattr * | attr | ||
) |
Cancel the addition of a nested attribute.
msg | Netlink message |
attr | Nested netlink attribute |
Removes any partially added nested Netlink attribute from the message by resetting the message to the size before the call to nla_nest_start() and by overwriting any potentially touched message segments with 0.
Definition at line 858 of file attr.c.
Referenced by nla_nest_end().
int nla_parse_nested | ( | struct nlattr * | tb[], |
int | maxtype, | ||
struct nlattr * | nla, | ||
struct nla_policy * | policy | ||
) |
Create attribute index based on nested attribute.
tb | Index array to be filled (maxtype+1 elements). |
maxtype | Maximum attribute type expected and accepted. |
nla | Nested Attribute. |
policy | Attribute validation policy. |
Feeds the stream of attributes nested into the specified attribute to nla_parse().
Definition at line 884 of file attr.c.
References nla_data(), nla_len(), and nla_parse().
Referenced by rtnl_ematch_parse_attr().