9#include <netlink/netlink.h>
10#include <netlink/object.h>
11#include <netlink/addr.h>
12#include <netlink/data.h>
53#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
80extern int nla_type(
const struct nlattr *);
81extern void *
nla_data(
const struct nlattr *);
82extern int nla_len(
const struct nlattr *);
83extern int nla_ok(
const struct nlattr *,
int);
84extern struct nlattr *
nla_next(
const struct nlattr *,
int *);
85extern int nla_parse(
struct nlattr **,
int,
struct nlattr *,
89extern struct nlattr *
nla_find(
const struct nlattr *,
int,
int);
92extern int nla_memcpy(
void *,
const struct nlattr *,
int);
93extern size_t nla_strlcpy(
char *,
const struct nlattr *,
size_t);
94extern int nla_memcmp(
const struct nlattr *,
const void *,
size_t);
95extern int nla_strcmp(
const struct nlattr *,
const char *);
98extern struct nlattr *
nla_reserve(
struct nl_msg *,
int,
int);
99extern int nla_put(
struct nl_msg *,
int,
int,
const void *);
101 const struct nl_data *);
102extern int nla_put_addr(
struct nl_msg *,
int,
struct nl_addr *);
105extern int8_t
nla_get_s8(
const struct nlattr *);
106extern int nla_put_s8(
struct nl_msg *,
int, int8_t);
107extern uint8_t
nla_get_u8(
const struct nlattr *);
108extern int nla_put_u8(
struct nl_msg *,
int, uint8_t);
110extern int nla_put_s16(
struct nl_msg *,
int, int16_t);
112extern int nla_put_u16(
struct nl_msg *,
int, uint16_t);
114extern int nla_put_s32(
struct nl_msg *,
int, int32_t);
116extern int nla_put_u32(
struct nl_msg *,
int, uint32_t);
118extern int nla_put_s64(
struct nl_msg *,
int, int64_t);
120extern int nla_put_u64(
struct nl_msg *,
int, uint64_t);
124extern char * nla_strdup(
const struct nlattr *);
133extern int nla_put_msecs(
struct nl_msg *,
int,
unsigned long);
137 const struct nl_msg *);
139extern int nla_nest_end(
struct nl_msg *,
struct nlattr *);
159#define NLA_PUT(msg, attrtype, attrlen, data) \
161 if (nla_put(msg, attrtype, attrlen, data) < 0) \
162 goto nla_put_failure; \
173#define NLA_PUT_TYPE(msg, type, attrtype, value) \
175 type __tmp = value; \
176 NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
185#define NLA_PUT_S8(msg, attrtype, value) \
186 NLA_PUT_TYPE(msg, int8_t, attrtype, value)
194#define NLA_PUT_U8(msg, attrtype, value) \
195 NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
203#define NLA_PUT_S16(msg, attrtype, value) \
204 NLA_PUT_TYPE(msg, int16_t, attrtype, value)
212#define NLA_PUT_U16(msg, attrtype, value) \
213 NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
221#define NLA_PUT_S32(msg, attrtype, value) \
222 NLA_PUT_TYPE(msg, int32_t, attrtype, value)
230#define NLA_PUT_U32(msg, attrtype, value) \
231 NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
239#define NLA_PUT_S64(msg, attrtype, value) \
240 NLA_PUT_TYPE(msg, int64_t, attrtype, value)
248#define NLA_PUT_U64(msg, attrtype, value) \
249 NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
257#define NLA_PUT_STRING(msg, attrtype, value) \
258 NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)
265#define NLA_PUT_FLAG(msg, attrtype) \
266 NLA_PUT(msg, attrtype, 0, NULL)
274#define NLA_PUT_MSECS(msg, attrtype, msecs) \
275 NLA_PUT_U64(msg, attrtype, msecs)
283#define NLA_PUT_ADDR(msg, attrtype, addr) \
284 NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \
285 nl_addr_get_binary_addr(addr))
293#define NLA_PUT_DATA(msg, attrtype, data) \
294 NLA_PUT(msg, attrtype, nl_data_get_size(data), \
312#define nla_for_each_attr(pos, head, len, rem) \
313 for (pos = head, rem = len; \
315 pos = nla_next(pos, &(rem)))
324#define nla_for_each_nested(pos, nla, rem) \
325 for (pos = (struct nlattr *) nla_data(nla), rem = nla_len(nla); \
327 pos = nla_next(pos, &(rem)))
int nla_validate(const struct nlattr *, int, int, const struct nla_policy *)
Validate a stream of attributes.
int nla_put_s16(struct nl_msg *, int, int16_t)
Add 16 bit signed integer attribute to netlink message.
uint32_t nla_get_u32(const struct nlattr *)
Return payload of 32 bit integer attribute.
int nla_put_u16(struct nl_msg *, int, uint16_t)
Add 16 bit integer attribute to netlink message.
uint16_t nla_get_u16(const struct nlattr *)
Return payload of 16 bit integer attribute.
int nla_strcmp(const struct nlattr *, const char *)
Compare string attribute payload with string.
int nla_put_data(struct nl_msg *, int, const struct nl_data *)
Add abstract data as unspecific attribute to netlink message.
int nla_put_nested(struct nl_msg *, int, const struct nl_msg *)
Add nested attributes to netlink message.
struct nlattr * nla_next(const struct nlattr *, int *)
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_put_string(struct nl_msg *, int, const char *)
Add string attribute to netlink message.
uint64_t nla_get_u64(const struct nlattr *)
Return payload of u64 attribute.
int nla_get_flag(const struct nlattr *)
Return true if flag attribute is set.
int nla_type(const struct nlattr *)
Return type of the attribute.
int nla_put_u64(struct nl_msg *, int, uint64_t)
Add 64 bit integer attribute to netlink message.
int nla_ok(const struct nlattr *, int)
Check if the attribute header and payload can be accessed safely.
void * nla_data(const struct nlattr *)
Return pointer to the payload section.
int nla_is_nested(const struct nlattr *)
Return true if attribute has NLA_F_NESTED flag set.
int nla_put_u32(struct nl_msg *, int, uint32_t)
Add 32 bit integer attribute to netlink message.
int nla_put_addr(struct nl_msg *, int, struct nl_addr *)
Add abstract address as unspecific attribute to netlink message.
int nla_memcmp(const struct nlattr *, const void *, size_t)
Compare attribute payload with memory area.
int nla_put_s64(struct nl_msg *, int, int64_t)
Add 64 bit signed integer attribute to netlink message.
int nla_put_msecs(struct nl_msg *, int, unsigned long)
Add a msecs netlink attribute to a netlink message.
uint8_t nla_get_u8(const struct nlattr *)
Return value of 8 bit integer attribute.
int nla_attr_size(int payload)
Return size of attribute whithout padding.
int16_t nla_get_s16(const struct nlattr *)
Return payload of 16 bit signed integer attribute.
int64_t nla_get_s64(const struct nlattr *)
Return payload of s64 attribute.
int nla_put_flag(struct nl_msg *, int)
Add flag netlink attribute to netlink message.
int nla_put_s32(struct nl_msg *, int, int32_t)
Add 32 bit signed integer attribute to netlink message.
int nla_memcpy(void *, const struct nlattr *, int)
Copy attribute payload to another memory area.
struct nlattr * nla_nest_start(struct nl_msg *, int)
Start a new level of nested attributes.
unsigned long nla_get_msecs(const struct nlattr *)
Return payload of msecs attribute.
size_t nla_strlcpy(char *, const struct nlattr *, size_t)
Copy string attribute payload to a buffer.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
char * nla_get_string(const struct nlattr *)
Return payload of string attribute.
int32_t nla_get_s32(const struct nlattr *)
Return payload of 32 bit signed integer attribute.
void nla_nest_cancel(struct nl_msg *, const struct nlattr *)
Cancel the addition of a nested attribute.
int nla_len(const struct nlattr *)
Return length of the payload .
int nla_put_u8(struct nl_msg *, int, uint8_t)
Add 8 bit integer attribute to netlink message.
int nla_nest_end(struct nl_msg *, struct nlattr *)
Finalize nesting of attributes.
int nla_nest_end_keep_empty(struct nl_msg *, struct nlattr *)
Finalize nesting of attributes without stripping off empty attributes.
int8_t nla_get_s8(const struct nlattr *)
Return value of 8 bit signed integer attribute.
struct nlattr * nla_find(const struct nlattr *, int, int)
Find a single attribute in a stream of attributes.
int nla_padlen(int payload)
Return length of padding at the tail of the attribute.
int nla_put(struct nl_msg *, int, int, const void *)
Add a unspecific attribute to netlink message.
int nla_put_s8(struct nl_msg *, int, int8_t)
Add 8 bit signed integer attribute to netlink message.
struct nlattr * nla_reserve(struct nl_msg *, int, int)
Reserve space for a attribute.
int nla_total_size(int payload)
Return size of attribute including padding.
@ NLA_STRING
NUL terminated character string.
@ NLA_UNSPEC
Unspecified type, binary data chunk.
@ NLA_MSECS
Micro seconds (64bit)
@ NLA_NESTED
Nested attributes.
Attribute validation policy.
uint16_t maxlen
Maximal length of payload allowed.
uint16_t minlen
Minimal length of payload required.
uint16_t type
Type of attribute or NLA_UNSPEC.