libnl: Attributes

libnl 3.10.0

Data Structures
Attributes
Core Library (libnl) » Message Construction & Parsing

Netlink Attributes Construction/Parsing Interface More...

## Data Structures
struct | nla_policy
| Attribute validation policy. 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_NESTED_COMPAT , NLA_NUL_STRING , NLA_BINARY , NLA_S8 , NLA_S16 , NLA_S32 , NLA_S64 , __NLA_TYPE_MAX }
| Basic attribute data types. More...

## Parsing Attributes
int | nla_type (const struct nlattr *nla)
| Return type of the attribute.
void * | nla_data (const struct nlattr *nla)
| Return pointer to the payload section.
int | nla_len (const struct nlattr *nla)
| Return length of the payload .
int | nla_ok (const struct nlattr *nla, int remaining)
| Check if the attribute header and payload can be accessed safely.
struct nlattr * | nla_next (const struct nlattr *nla, int *remaining)
| Return next attribute in a stream of attributes.
int | nla_parse (struct nlattr *tb[], int maxtype, struct nlattr *head, int len, const struct nla_policy *policy)
| Create attribute index based on a stream of attributes.
int | nla_validate (const struct nlattr *head, int len, int maxtype, const struct nla_policy *policy)
| Validate a stream of attributes.
struct nlattr * | nla_find (const struct nlattr *head, int len, int attrtype)
| Find a single attribute in a stream of attributes.

## Attribute Size Calculation
int | nla_attr_size (int payload)
| Return size of attribute whithout padding.
int | nla_total_size (int payload)
| Return size of attribute including padding.
int | nla_padlen (int payload)
| Return length of padding at the tail of the attribute.

## Helper Functions
int | nla_memcpy (void *dest, const struct nlattr *src, int count)
| Copy attribute payload to another memory area.
size_t | nla_strlcpy (char *dst, const struct nlattr *nla, size_t dstsize)
| Copy string attribute payload to a buffer.
int | nla_memcmp (const struct nlattr *nla, const void *data, size_t size)
| Compare attribute payload with memory area.
int | nla_strcmp (const struct nlattr *nla, const char *str)
| Compare string attribute payload with string.

## Unspecific Attribute
struct nlattr * | nla_reserve (struct nl_msg *msg, int attrtype, int attrlen)
| Reserve space for a attribute.
int | nla_put (struct nl_msg *msg, int attrtype, int datalen, const void *data)
| Add a unspecific attribute to netlink message.
int | nla_put_data (struct nl_msg *msg, int attrtype, const struct nl_data *data)
| Add abstract data as unspecific attribute to netlink message.
int | nla_put_addr (struct nl_msg *msg, int attrtype, struct nl_addr *addr)
| Add abstract address as unspecific attribute to netlink message.

## Integer Attributes
int | nla_put_s8 (struct nl_msg *msg, int attrtype, int8_t value)
| Add 8 bit signed integer attribute to netlink message.
int8_t | nla_get_s8 (const struct nlattr *nla)
| Return value of 8 bit signed integer attribute.
int | nla_put_u8 (struct nl_msg *msg, int attrtype, uint8_t value)
| Add 8 bit integer attribute to netlink message.
uint8_t | nla_get_u8 (const struct nlattr *nla)
| Return value of 8 bit integer attribute.
int | nla_put_s16 (struct nl_msg *msg, int attrtype, int16_t value)
| Add 16 bit signed integer attribute to netlink message.
int16_t | nla_get_s16 (const struct nlattr *nla)
| Return payload of 16 bit signed integer attribute.
int | nla_put_u16 (struct nl_msg *msg, int attrtype, uint16_t value)
| Add 16 bit integer attribute to netlink message.
uint16_t | nla_get_u16 (const struct nlattr *nla)
| Return payload of 16 bit integer attribute.
int | nla_put_s32 (struct nl_msg *msg, int attrtype, int32_t value)
| Add 32 bit signed integer attribute to netlink message.
int32_t | nla_get_s32 (const struct nlattr *nla)
| Return payload of 32 bit signed integer attribute.
int | nla_put_u32 (struct nl_msg *msg, int attrtype, uint32_t value)
| Add 32 bit integer attribute to netlink message.
uint32_t | nla_get_u32 (const struct nlattr *nla)
| Return payload of 32 bit integer attribute.
int | nla_put_s64 (struct nl_msg *msg, int attrtype, int64_t value)
| Add 64 bit signed integer attribute to netlink message.
int64_t | nla_get_s64 (const struct nlattr *nla)
| Return payload of s64 attribute.
int | nla_put_u64 (struct nl_msg *msg, int attrtype, uint64_t value)
| Add 64 bit integer attribute to netlink message.
uint64_t | nla_get_u64 (const struct nlattr *nla)
| Return payload of u64 attribute.

## String Attribute
int | nla_put_string (struct nl_msg *msg, int attrtype, const char *str)
| Add string attribute to netlink message.
char * | nla_get_string (const struct nlattr *nla)
| Return payload of string attribute.
char * | nla_strdup (const struct nlattr *nla)

## Flag Attribute
int | nla_put_flag (struct nl_msg *msg, int attrtype)
| Add flag netlink attribute to netlink message.
int | nla_get_flag (const struct nlattr *nla)
| Return true if flag attribute is set.

## Microseconds Attribute
int | nla_put_msecs (struct nl_msg *n, int attrtype, unsigned long msecs)
| Add a msecs netlink attribute to a netlink message.
unsigned long | nla_get_msecs (const struct nlattr *nla)
| Return payload of msecs attribute.

## Nested Attribute
int | nla_put_nested (struct nl_msg *msg, int attrtype, const struct nl_msg *nested)
| Add nested attributes to netlink message.
struct nlattr * | nla_nest_start (struct nl_msg *msg, int attrtype)
| Start a new level of nested attributes.
int | nla_nest_end (struct nl_msg *msg, struct nlattr *start)
| Finalize nesting of attributes.
int | nla_nest_end_keep_empty (struct nl_msg *msg, struct nlattr *start)
| Finalize nesting of attributes without stripping off empty attributes.
void | nla_nest_cancel (struct nl_msg *msg, const struct nlattr *attr)
| Cancel the addition of a nested attribute.
int | nla_parse_nested (struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
| Create attribute index based on nested attribute.
int | nla_is_nested (const struct nlattr *attr)
| Return true if attribute has NLA_F_NESTED flag set.

## Attribute Construction (Exception Based)
#define | NLA_PUT(msg, attrtype, attrlen, data)
| Add unspecific attribute to netlink message.
#define | NLA_PUT_TYPE(msg, type, attrtype, value)
| Add atomic type attribute to netlink message.
#define | NLA_PUT_S8(msg, attrtype, value) NLA_PUT_TYPE(msg, int8_t, attrtype, value)
| Add 8 bit signed integer attribute to netlink message.
#define | NLA_PUT_U8(msg, attrtype, value) NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
| Add 8 bit integer attribute to netlink message.
#define | NLA_PUT_S16(msg, attrtype, value) NLA_PUT_TYPE(msg, int16_t, attrtype, value)
| Add 16 bit signed integer 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_S32(msg, attrtype, value) NLA_PUT_TYPE(msg, int32_t, attrtype, value)
| Add 32 bit signed 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.
#define | NLA_PUT_S64(msg, attrtype, value) NLA_PUT_TYPE(msg, int64_t, attrtype, value)
| Add 64 bit signed integer attribute to netlink message.
#define | NLA_PUT_U64(msg, attrtype, value) NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
| Add 64 bit integer attribute to netlink message.
#define | NLA_PUT_STRING(msg, attrtype, value) NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)
| Add string attribute to netlink message.
#define | NLA_PUT_FLAG(msg, attrtype) NLA_PUT(msg, attrtype, 0, NULL)
| 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.
#define | NLA_PUT_ADDR(msg, attrtype, addr)
| Add address attribute to netlink message.
#define | NLA_PUT_DATA(msg, attrtype, data)
| Add abstract data attribute to netlink message.

## Iterators
#define | nla_for_each_attr(pos, head, len, rem)
| Iterate over a stream of attributes.
#define | nla_for_each_nested(pos, nla, rem)
| Iterate over a stream of nested attributes.

## Detailed Description

Netlink Attributes Construction/Parsing Interface

Related sections in the development guide:

- Netlink Attributes (Netlink Core Library Development Guide)

## Header

#include <netlink/attr.h>

## Macro Definition Documentation

## ◆ NLA_PUT

#define NLA_PUT | ( |  | msg,
|  |  | attrtype,
|  |  | attrlen,
|  |  | data )

Value:
do { \
if (nla_put(msg, attrtype, attrlen, data) < 0) \
goto nla_put_failure; \
} while(0)
nla_put
int nla_put(struct nl_msg *, int, int, const void *)
Add a unspecific attribute to netlink message.
Definition attr.c:503

Add unspecific attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  attrlen | Length of attribute payload.
  data | Head of attribute payload.

Definition at line 159 of file attr.h.

## ◆ NLA_PUT_TYPE

#define NLA_PUT_TYPE | ( |  | msg,
|  |  | type,
|  |  | attrtype,
|  |  | value )

Value:
do { \
type __tmp = value; \
NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
} while(0)

Add atomic type attribute to netlink message.

Parameters

  msg | Netlink message.
  type | Atomic type.
  attrtype | Attribute type.
  value | Head of attribute payload.

Definition at line 173 of file attr.h.

## ◆ nla_for_each_attr

#define nla_for_each_attr | ( |  | pos,
|  |  | head,
|  |  | len,
|  |  | rem )

Value:
for (pos = head, rem = len; \
nla_ok(pos, rem); \
pos = nla_next(pos, &(rem)))
nla_next
struct nlattr * nla_next(const struct nlattr *, int *)
Return next attribute in a stream of attributes.
Definition attr.c:172

Iterate over a stream of attributes.

Parameters

  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 312 of file attr.h.

Referenced by nla_find(), nla_parse(), and nla_validate().

## ◆ nla_for_each_nested

#define nla_for_each_nested | ( |  | pos,
|  |  | nla,
|  |  | rem )

Value:
for (pos = (struct nlattr *) nla_data(nla), rem = nla_len(nla); \
nla_ok(pos, rem); \
pos = nla_next(pos, &(rem)))
nla_data
void * nla_data(const struct nlattr *)
Return pointer to the payload section.
Definition attr.c:119
nla_len
int nla_len(const struct nlattr *)
Return length of the payload .
Definition attr.c:130

Iterate over a stream of nested attributes.

Parameters

  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 324 of file attr.h.

Referenced by rtnl_ematch_parse_attr().

## ◆ NLA_PUT_S8

#define NLA_PUT_S8 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, int8_t, attrtype, value)

Add 8 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 185 of file attr.h.

## ◆ NLA_PUT_U8

#define NLA_PUT_U8 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, uint8_t, attrtype, value)

Add 8 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 194 of file attr.h.

## ◆ NLA_PUT_S16

#define NLA_PUT_S16 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, int16_t, attrtype, value)

Add 16 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 203 of file attr.h.

## ◆ NLA_PUT_U16

#define NLA_PUT_U16 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, uint16_t, attrtype, value)

Add 16 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 212 of file attr.h.

## ◆ NLA_PUT_S32

#define NLA_PUT_S32 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, int32_t, attrtype, value)

Add 32 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 221 of file attr.h.

## ◆ NLA_PUT_U32

#define NLA_PUT_U32 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, uint32_t, attrtype, value)

Add 32 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 230 of file attr.h.

Referenced by rtnl_neightbl_build_change_request().

## ◆ NLA_PUT_S64

#define NLA_PUT_S64 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, int64_t, attrtype, value)

Add 64 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 239 of file attr.h.

## ◆ NLA_PUT_U64

#define NLA_PUT_U64 | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT_TYPE(msg, uint64_t, attrtype, value)

Add 64 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value.

Definition at line 248 of file attr.h.

Referenced by rtnl_neightbl_build_change_request().

## ◆ NLA_PUT_STRING

#define NLA_PUT_STRING | ( |  | msg,
|  |  | attrtype,
|  |  | value ) NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)

Add string attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | NUL terminated character string.

Definition at line 257 of file attr.h.

Referenced by rtnl_neightbl_build_change_request(), and rtnl_qdisc_build_delete_request().

## ◆ NLA_PUT_FLAG

#define NLA_PUT_FLAG | ( |  | msg,
|  |  | attrtype ) NLA_PUT(msg, attrtype, 0, NULL)

Add flag attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.

Definition at line 265 of file attr.h.

## ◆ NLA_PUT_MSECS

#define NLA_PUT_MSECS | ( |  | msg,
|  |  | attrtype,
|  |  | msecs ) NLA_PUT_U64(msg, attrtype, msecs)

Add msecs attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  msecs | Numeric value in micro seconds.

Definition at line 274 of file attr.h.

## ◆ NLA_PUT_ADDR

#define NLA_PUT_ADDR | ( |  | msg,
|  |  | attrtype,
|  |  | addr )

Value:
NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \
nl_addr_get_binary_addr(addr))
nl_addr_get_binary_addr
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
Definition addr.c:943
nl_addr_get_len
unsigned int nl_addr_get_len(const struct nl_addr *addr)
Get length of binary address of abstract address object.
Definition addr.c:955
NLA_PUT
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
Definition attr.h:159

Add address attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  addr | Abstract address object.

Definition at line 283 of file attr.h.

## ◆ NLA_PUT_DATA

#define NLA_PUT_DATA | ( |  | msg,
|  |  | attrtype,
|  |  | data )

Value:
NLA_PUT(msg, attrtype, nl_data_get_size(data), \
nl_data_get(data))
nl_data_get_size
size_t nl_data_get_size(const struct nl_data *data)
Get size of data buffer of abstract data object.
Definition data.c:166
nl_data_get
void * nl_data_get(const struct nl_data *data)
Get data buffer of abstract data object.
Definition data.c:154

Add abstract data attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  data | Abstract data object.

Definition at line 293 of file attr.h.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Basic attribute data types.

See section Attribute Parsing (Netlink Core Library Development Guide) for more details.

Enumerator
NLA_UNSPEC | Unspecified type, binary data chunk.
NLA_U8 | 8 bit integer
NLA_U16 | 16 bit integer
NLA_U32 | 32 bit integer
NLA_U64 | 64 bit integer
NLA_STRING | NUL terminated character string.
NLA_FLAG | Flag.
NLA_MSECS | Micro seconds (64bit)
NLA_NESTED | Nested attributes.

Definition at line 33 of file attr.h.

## Function Documentation

## ◆ nla_attr_size()

int nla_attr_size | ( | int | payload | ) |

Return size of attribute whithout padding.

Parameters

  payload | Payload length of attribute.

<-------- nla_attr_size(payload) --------->
+------------------+- - -+- - - - - - - - - +- - -+
| Attribute Header | Pad | Payload | Pad |
+------------------+- - -+- - - - - - - - - +- - -+
nla_attr_size
int nla_attr_size(int payload)
Return size of attribute whithout padding.
Definition attr.c:54

Returns
  Size of attribute in bytes without padding.

Definition at line 54 of file attr.c.

Referenced by nla_padlen(), nla_reserve(), and nla_total_size().

Here is the caller graph for this function:

## ◆ nla_total_size()

int nla_total_size | ( | int | payload | ) |

Return size of attribute including padding.

Parameters

  payload | Payload length of attribute.

<----------- nla_total_size(payload) ----------->
+------------------+- - -+- - - - - - - - - +- - -+
| Attribute Header | Pad | Payload | Pad |
+------------------+- - -+- - - - - - - - - +- - -+
nla_total_size
int nla_total_size(int payload)
Return size of attribute including padding.
Definition attr.c:72

Returns
  Size of attribute in bytes.

Definition at line 72 of file attr.c.

References nla_attr_size().

Referenced by nla_padlen(), nla_reserve(), and rtnl_ematch_parse_attr().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_padlen()

int nla_padlen | ( | int | payload | ) |

Return length of padding at the tail of the attribute.

Parameters

  payload | Payload length of attribute.

+------------------+- - -+- - - - - - - - - +- - -+
| Attribute Header | Pad | Payload | Pad |
+------------------+- - -+- - - - - - - - - +- - -+
<--->

Returns
  Length of padding in bytes.

Definition at line 90 of file attr.c.

References nla_attr_size(), and nla_total_size().

Referenced by nla_reserve().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_type()

int nla_type | ( | const struct nlattr * | nla | ) |

Return type of the attribute.

Parameters

  nla | Attribute.

Returns
  Type of attribute.

Definition at line 108 of file attr.c.

Referenced by nla_find(), and nla_parse().

Here is the caller graph for this function:

## ◆ nla_data()

void * nla_data | ( | const struct nlattr * | nla | ) |

Return pointer to the payload section.

Parameters

  nla | Attribute.

Returns
  Pointer to start of payload section.

Definition at line 119 of file attr.c.

Referenced by nl_addr_alloc_attr(), nl_data_alloc_attr(), nla_get_s16(), nla_get_s32(), nla_get_s64(), nla_get_s8(), nla_get_string(), nla_get_u16(), nla_get_u32(), nla_get_u64(), nla_get_u8(), nla_memcmp(), nla_memcpy(), nla_parse_nested(), nla_put(), nla_strcmp(), nla_strlcpy(), and rtnl_ematch_parse_attr().

Here is the caller graph for this function:

## ◆ nla_len()

int nla_len | ( | const struct nlattr * | nla | ) |

Return length of the payload .

Parameters

  nla | Attribute

Returns
  Length of payload in bytes.

Definition at line 130 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().

Here is the caller graph for this function:

## ◆ nla_ok()

int nla_ok | ( | const struct nlattr * | nla,
|  | int | remaining )

Check if the attribute header and payload can be accessed safely.

Parameters

  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().

Returns
  True if the attribute can be accessed safely, false otherwise.

Definition at line 147 of file attr.c.

## ◆ nla_next()

struct nlattr * nla_next | ( | const struct nlattr * | nla,
|  | int * | remaining )

Return next attribute in a stream of attributes.

Parameters

  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.

Returns
  Pointer to next attribute.

Definition at line 172 of file attr.c.

## ◆ nla_parse()

int nla_parse | ( | struct nlattr * | tb[],
|  | int | maxtype,
|  | struct nlattr * | head,
|  | int | len,
|  | const struct nla_policy * | policy )

Create attribute index based on a stream of attributes.

Parameters

  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.

See also
  nla_validate

Returns
  0 on success or a negative error code.

Definition at line 243 of file attr.c.

References nla_for_each_attr, and nla_type().

Referenced by genlmsg_parse(), nla_parse_nested(), and nlmsg_parse().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_validate()

int nla_validate | ( | const struct nlattr * | head,
|  | int | len,
|  | int | maxtype,
|  | const struct nla_policy * | policy )

Validate a stream of attributes.

Parameters

  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.

Returns
  0 on success or a negative error code.

Definition at line 294 of file attr.c.

References nla_for_each_attr.

Referenced by genlmsg_validate(), and nlmsg_validate().

Here is the caller graph for this function:

## ◆ nla_find()

struct nlattr * nla_find | ( | const struct nlattr * | head,
|  | int | len,
|  | int | attrtype )

Find a single attribute in a stream of attributes.

Parameters

  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.

Returns
  Pointer to attribute found or NULL.

Definition at line 323 of file attr.c.

References nla_for_each_attr, and nla_type().

Referenced by nlmsg_find_attr().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_memcpy()

int nla_memcpy | ( | void * | dest,
|  | const struct nlattr * | src,
|  | int | count )

Copy attribute payload to another memory area.

Parameters

  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.

Returns
  The number of bytes copied to dest.

Definition at line 353 of file attr.c.

References nla_data(), and nla_len().

Here is the call graph for this function:

## ◆ nla_strlcpy()

size_t nla_strlcpy | ( | char * | dst,
|  | const struct nlattr * | nla,
|  | size_t | dstsize )

Copy string attribute payload to a buffer.

Parameters

  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.

Returns
  The length of string attribute without the terminating NUL.

Definition at line 381 of file attr.c.

References nla_data(), and nla_len().

Here is the call graph for this function:

## ◆ nla_memcmp()

int nla_memcmp | ( | const struct nlattr * | nla,
|  | const void * | data,
|  | size_t | size )

Compare attribute payload with memory area.

Parameters

  nla | Attribute.
  data | Memory area to compare to.
  size | Number of bytes to compare.

See also
  memcmp(3)

Returns
  An integer less than, equal to, or greater than zero.

Definition at line 408 of file attr.c.

References nla_data(), and nla_len().

Here is the call graph for this function:

## ◆ nla_strcmp()

int nla_strcmp | ( | const struct nlattr * | nla,
|  | const char * | str )

Compare string attribute payload with string.

Parameters

  nla | Attribute of type NLA_STRING.
  str | NUL terminated string.

See also
  strcmp(3)

Returns
  An integer less than, equal to, or greater than zero.

Definition at line 426 of file attr.c.

References nla_data(), and nla_len().

Here is the call graph for this function:

## ◆ nla_reserve()

struct nlattr * nla_reserve | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | int | attrlen )

Reserve space for a attribute.

Parameters

  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.

Returns
  Pointer to start of attribute or NULL on failure.

Definition at line 459 of file attr.c.

References nla_attr_size(), nla_padlen(), nla_total_size(), and nlmsg_data().

Referenced by nla_put().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_put()

int nla_put | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | int | datalen,
|  | const void * | data )

Add a unspecific attribute to netlink message.

Parameters

  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.

See also
  nla_reserve

Returns
  0 on success or a negative error code.

Definition at line 503 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_s16(), nla_put_s32(), nla_put_s64(), nla_put_s8(), nla_put_string(), nla_put_u16(), nla_put_u32(), nla_put_u64(), nla_put_u8(), and rtnl_link_build_get_request().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_put_data()

int nla_put_data | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | const struct nl_data * | data )

Add abstract data as unspecific attribute to netlink message.

Parameters

  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.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 537 of file attr.c.

References nl_data_get(), nl_data_get_size(), and nla_put().

Here is the call graph for this function:

## ◆ nla_put_addr()

int nla_put_addr | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | struct nl_addr * | addr )

Add abstract address as unspecific attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  addr | Abstract address object.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 552 of file attr.c.

References nl_addr_get_binary_addr(), nl_addr_get_len(), and nla_put().

Here is the call graph for this function:

## ◆ nla_put_s8()

int nla_put_s8 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | int8_t | value )

Add 8 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 576 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_s8()

int8_t nla_get_s8 | ( | const struct nlattr * | nla | ) |

Return value of 8 bit signed integer attribute.

Parameters

  nla | 8 bit integer attribute

Returns
  Payload as 8 bit integer.

Definition at line 587 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_u8()

int nla_put_u8 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | uint8_t | value )

Add 8 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 601 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_u8()

uint8_t nla_get_u8 | ( | const struct nlattr * | nla | ) |

Return value of 8 bit integer attribute.

Parameters

  nla | 8 bit integer attribute

Returns
  Payload as 8 bit integer.

Definition at line 612 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_s16()

int nla_put_s16 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | int16_t | value )

Add 16 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 626 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_s16()

int16_t nla_get_s16 | ( | const struct nlattr * | nla | ) |

Return payload of 16 bit signed integer attribute.

Parameters

  nla | 16 bit integer attribute

Returns
  Payload as 16 bit integer.

Definition at line 637 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_u16()

int nla_put_u16 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | uint16_t | value )

Add 16 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 651 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_u16()

uint16_t nla_get_u16 | ( | const struct nlattr * | nla | ) |

Return payload of 16 bit integer attribute.

Parameters

  nla | 16 bit integer attribute

Returns
  Payload as 16 bit integer.

Definition at line 662 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_s32()

int nla_put_s32 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | int32_t | value )

Add 32 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 676 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_s32()

int32_t nla_get_s32 | ( | const struct nlattr * | nla | ) |

Return payload of 32 bit signed integer attribute.

Parameters

  nla | 32 bit integer attribute.

Returns
  Payload as 32 bit integer.

Definition at line 687 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_u32()

int nla_put_u32 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | uint32_t | value )

Add 32 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 701 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_u32()

uint32_t nla_get_u32 | ( | const struct nlattr * | nla | ) |

Return payload of 32 bit integer attribute.

Parameters

  nla | 32 bit integer attribute.

Returns
  Payload as 32 bit integer.

Definition at line 712 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_s64()

int nla_put_s64 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | int64_t | value )

Add 64 bit signed integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 726 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_s64()

int64_t nla_get_s64 | ( | const struct nlattr * | nla | ) |

Return payload of s64 attribute.

Parameters

  nla | s64 netlink attribute

Returns
  Payload as 64 bit integer.

Definition at line 737 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_put_u64()

int nla_put_u64 | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | uint64_t | value )

Add 64 bit integer attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  value | Numeric value to store as payload.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 756 of file attr.c.

References nla_put().

Referenced by nla_put_msecs().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_get_u64()

uint64_t nla_get_u64 | ( | const struct nlattr * | nla | ) |

Return payload of u64 attribute.

Parameters

  nla | u64 netlink attribute

Returns
  Payload as 64 bit integer.

Definition at line 767 of file attr.c.

References nla_data().

Referenced by nla_get_msecs().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_put_string()

int nla_put_string | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | const char * | str )

Add string attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.
  str | NUL terminated string.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 792 of file attr.c.

References nla_put().

Referenced by rtnl_link_build_delete_request(), and rtnl_link_build_get_request().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_get_string()

char * nla_get_string | ( | const struct nlattr * | nla | ) |

Return payload of string attribute.

Parameters

  nla | String attribute.

Returns
  Pointer to attribute payload.

Definition at line 803 of file attr.c.

References nla_data().

Here is the call graph for this function:

## ◆ nla_strdup()

char * nla_strdup | ( | const struct nlattr * | nla | ) |

Definition at line 808 of file attr.c.

## ◆ nla_put_flag()

int nla_put_flag | ( | struct nl_msg * | msg,
|  | int | attrtype )

Add flag netlink attribute to netlink message.

Parameters

  msg | Netlink message.
  attrtype | Attribute type.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 827 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_get_flag()

int nla_get_flag | ( | const struct nlattr * | nla | ) |

Return true if flag attribute is set.

Parameters

  nla | Flag netlink attribute.

Returns
  True if flag is set, otherwise false.

Definition at line 838 of file attr.c.

## ◆ nla_put_msecs()

int nla_put_msecs | ( | struct nl_msg * | n,
|  | int | attrtype,
|  | unsigned long | msecs )

Add a msecs netlink attribute to a netlink message.

Parameters

  n | netlink message
  attrtype | attribute type
  msecs | number of msecs

Definition at line 855 of file attr.c.

References nla_put_u64().

Here is the call graph for this function:

## ◆ nla_get_msecs()

unsigned long nla_get_msecs | ( | const struct nlattr * | nla | ) |

Return payload of msecs attribute.

Parameters

  nla | msecs netlink attribute

Returns
  the number of milliseconds.

Definition at line 866 of file attr.c.

References nla_get_u64().

Here is the call graph for this function:

## ◆ nla_put_nested()

int nla_put_nested | ( | struct nl_msg * | msg,
|  | int | attrtype,
|  | const struct nl_msg * | nested )

Add nested attributes to netlink message.

Parameters

  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.

See also
  nla_put

Returns
  0 on success or a negative error code.

Definition at line 890 of file attr.c.

References nla_put(), nlmsg_data(), and nlmsg_datalen().

Referenced by rtnl_neightbl_build_change_request().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_nest_start()

struct nlattr * nla_nest_start | ( | struct nl_msg * | msg,
|  | int | attrtype )

Start a new level of nested attributes.

Parameters

  msg | Netlink message.
  attrtype | Attribute type of container.

Returns
  Pointer to container attribute.

Definition at line 908 of file attr.c.

References nla_put().

Here is the call graph for this function:

## ◆ nla_nest_end()

int nla_nest_end | ( | struct nl_msg * | msg,
|  | struct nlattr * | start )

Finalize nesting of attributes.

Parameters

  msg | Netlink message.
  start | Container attribute as returned from nla_nest_start().

Corrects the container attribute header to include the appeneded attributes.

Returns
  0 on success or a negative error code.

Definition at line 971 of file attr.c.

## ◆ nla_nest_end_keep_empty()

int nla_nest_end_keep_empty | ( | struct nl_msg * | msg,
|  | struct nlattr * | start )

Finalize nesting of attributes without stripping off empty attributes.

Parameters

  msg | Netlink message.
  start | Container attribute as returned from nla_nest_start().

Corrects the container attribute header to include the appeneded attributes. Keep empty attribute if NO actual attribute payload exists.

Returns
  0 on success or a negative error code.

Definition at line 986 of file attr.c.

## ◆ nla_nest_cancel()

void nla_nest_cancel | ( | struct nl_msg * | msg,
|  | const struct nlattr * | attr )

Cancel the addition of a nested attribute.

Parameters

  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 1000 of file attr.c.

## ◆ nla_parse_nested()

int nla_parse_nested | ( | struct nlattr * | tb[],
|  | int | maxtype,
|  | struct nlattr * | nla,
|  | const struct nla_policy * | policy )

Create attribute index based on nested attribute.

Parameters

  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().

See also
  nla_parse

Returns
  0 on success or a negative error code.

Definition at line 1035 of file attr.c.

References nla_data(), nla_len(), and nla_parse().

Referenced by rtnl_ematch_parse_attr().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nla_is_nested()

int nla_is_nested | ( | const struct nlattr * | attr | ) |

Return true if attribute has NLA_F_NESTED flag set.

Parameters

  attr | Netlink attribute

Returns
  True if attribute has NLA_F_NESTED flag set, oterhwise False.

Definition at line 1047 of file attr.c.