9#include <netlink/netlink.h>
10#include <netlink/object.h>
11#include <netlink/addr.h>
12#include <netlink/data.h>
56#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
83extern int nla_type(
const struct nlattr *);
84extern void *
nla_data(
const struct nlattr *);
85extern int nla_len(
const struct nlattr *);
86extern int nla_ok(
const struct nlattr *,
int);
87extern struct nlattr *
nla_next(
const struct nlattr *,
int *);
88extern int nla_parse(
struct nlattr **,
int,
struct nlattr *,
92extern struct nlattr *
nla_find(
const struct nlattr *,
int,
int);
95extern int nla_memcpy(
void *,
const struct nlattr *,
int);
96extern size_t nla_strlcpy(
char *,
const struct nlattr *,
size_t);
97extern int nla_memcmp(
const struct nlattr *,
const void *,
size_t);
98extern int nla_strcmp(
const struct nlattr *,
const char *);
101extern struct nlattr *
nla_reserve(
struct nl_msg *,
int,
int);
102extern int nla_put(
struct nl_msg *,
int,
int,
const void *);
104 const struct nl_data *);
105extern int nla_put_addr(
struct nl_msg *,
int,
struct nl_addr *);
108extern int8_t
nla_get_s8(
const struct nlattr *);
109extern int nla_put_s8(
struct nl_msg *,
int, int8_t);
110extern uint8_t
nla_get_u8(
const struct nlattr *);
111extern int nla_put_u8(
struct nl_msg *,
int, uint8_t);
113extern int nla_put_s16(
struct nl_msg *,
int, int16_t);
115extern int nla_put_u16(
struct nl_msg *,
int, uint16_t);
117extern int nla_put_s32(
struct nl_msg *,
int, int32_t);
119extern int nla_put_u32(
struct nl_msg *,
int, uint32_t);
121extern int nla_put_s64(
struct nl_msg *,
int, int64_t);
123extern int nla_put_u64(
struct nl_msg *,
int, uint64_t);
131extern char * nla_strdup(
const struct nlattr *);
140extern int nla_put_msecs(
struct nl_msg *,
int,
unsigned long);
144 const struct nl_msg *);
146extern int nla_nest_end(
struct nl_msg *,
struct nlattr *);
166#define NLA_PUT(msg, attrtype, attrlen, data) \
168 if (nla_put(msg, attrtype, attrlen, data) < 0) \
169 goto nla_put_failure; \
180#define NLA_PUT_TYPE(msg, type, attrtype, value) \
182 type __tmp = value; \
183 NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
192#define NLA_PUT_S8(msg, attrtype, value) \
193 NLA_PUT_TYPE(msg, int8_t, attrtype, value)
201#define NLA_PUT_U8(msg, attrtype, value) \
202 NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
210#define NLA_PUT_S16(msg, attrtype, value) \
211 NLA_PUT_TYPE(msg, int16_t, attrtype, value)
219#define NLA_PUT_U16(msg, attrtype, value) \
220 NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
228#define NLA_PUT_S32(msg, attrtype, value) \
229 NLA_PUT_TYPE(msg, int32_t, attrtype, value)
237#define NLA_PUT_U32(msg, attrtype, value) \
238 NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
246#define NLA_PUT_S64(msg, attrtype, value) \
247 NLA_PUT_TYPE(msg, int64_t, attrtype, value)
255#define NLA_PUT_U64(msg, attrtype, value) \
256 NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
264#define NLA_PUT_STRING(msg, attrtype, value) \
265 NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)
272#define NLA_PUT_FLAG(msg, attrtype) \
273 NLA_PUT(msg, attrtype, 0, NULL)
281#define NLA_PUT_MSECS(msg, attrtype, msecs) \
282 NLA_PUT_U64(msg, attrtype, msecs)
290#define NLA_PUT_ADDR(msg, attrtype, addr) \
291 NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \
292 nl_addr_get_binary_addr(addr))
300#define NLA_PUT_DATA(msg, attrtype, data) \
301 NLA_PUT(msg, attrtype, nl_data_get_size(data), \
319#define nla_for_each_attr(pos, head, len, rem) \
320 for (pos = head, rem = len; \
322 pos = nla_next(pos, &(rem)))
331#define nla_for_each_nested(pos, nla, rem) \
332 for (pos = (struct nlattr *) nla_data(nla), rem = nla_len(nla); \
334 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.
uint64_t nla_get_uint(const struct nlattr *)
Return payload of variable-length unsigned integer attribute.
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_uint(struct nl_msg *, int, uint64_t)
Add variable-length unsigned integer attribute to netlink message.
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.
int64_t nla_get_sint(const struct nlattr *)
Return payload of variable-length signed integer 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.
int nla_put_sint(struct nl_msg *, int, int64_t)
Add variable-length signed integer attribute to netlink message.
@ 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.