12 #ifndef NETLINK_ATTR_H_ 13 #define NETLINK_ATTR_H_ 15 #include <netlink/netlink.h> 16 #include <netlink/object.h> 17 #include <netlink/addr.h> 18 #include <netlink/data.h> 57 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1) 84 extern int nla_type(
const struct nlattr *);
85 extern void *
nla_data(
const struct nlattr *);
86 extern int nla_len(
const struct nlattr *);
87 extern int nla_ok(
const struct nlattr *,
int);
88 extern struct nlattr *
nla_next(
const struct nlattr *,
int *);
89 extern int nla_parse(
struct nlattr **,
int,
struct nlattr *,
93 extern struct nlattr *
nla_find(
const struct nlattr *,
int,
int);
96 extern int nla_memcpy(
void *,
const struct nlattr *,
int);
97 extern size_t nla_strlcpy(
char *,
const struct nlattr *,
size_t);
98 extern int nla_memcmp(
const struct nlattr *,
const void *,
size_t);
99 extern int nla_strcmp(
const struct nlattr *,
const char *);
102 extern struct nlattr *
nla_reserve(
struct nl_msg *,
int,
int);
103 extern int nla_put(
struct nl_msg *,
int,
int,
const void *);
105 const struct nl_data *);
106 extern int nla_put_addr(
struct nl_msg *,
int,
struct nl_addr *);
109 extern int8_t
nla_get_s8(
const struct nlattr *);
110 extern int nla_put_s8(
struct nl_msg *,
int, int8_t);
111 extern uint8_t
nla_get_u8(
const struct nlattr *);
112 extern int nla_put_u8(
struct nl_msg *,
int, uint8_t);
114 extern int nla_put_s16(
struct nl_msg *,
int, int16_t);
115 extern uint16_t
nla_get_u16(
const struct nlattr *);
116 extern int nla_put_u16(
struct nl_msg *,
int, uint16_t);
118 extern int nla_put_s32(
struct nl_msg *,
int, int32_t);
119 extern uint32_t
nla_get_u32(
const struct nlattr *);
120 extern int nla_put_u32(
struct nl_msg *,
int, uint32_t);
122 extern int nla_put_s64(
struct nl_msg *,
int, int64_t);
123 extern uint64_t
nla_get_u64(
const struct nlattr *);
124 extern int nla_put_u64(
struct nl_msg *,
int, uint64_t);
128 extern char * nla_strdup(
const struct nlattr *);
137 extern int nla_put_msecs(
struct nl_msg *,
int,
unsigned long);
141 const struct nl_msg *);
143 extern int nla_nest_end(
struct nl_msg *,
struct nlattr *);
162 #define NLA_PUT(msg, attrtype, attrlen, data) \ 164 if (nla_put(msg, attrtype, attrlen, data) < 0) \ 165 goto nla_put_failure; \ 176 #define NLA_PUT_TYPE(msg, type, attrtype, value) \ 178 type __tmp = value; \ 179 NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \ 188 #define NLA_PUT_S8(msg, attrtype, value) \ 189 NLA_PUT_TYPE(msg, int8_t, attrtype, value) 197 #define NLA_PUT_U8(msg, attrtype, value) \ 198 NLA_PUT_TYPE(msg, uint8_t, attrtype, value) 206 #define NLA_PUT_S16(msg, attrtype, value) \ 207 NLA_PUT_TYPE(msg, int16_t, attrtype, value) 215 #define NLA_PUT_U16(msg, attrtype, value) \ 216 NLA_PUT_TYPE(msg, uint16_t, attrtype, value) 224 #define NLA_PUT_S32(msg, attrtype, value) \ 225 NLA_PUT_TYPE(msg, int32_t, attrtype, value) 233 #define NLA_PUT_U32(msg, attrtype, value) \ 234 NLA_PUT_TYPE(msg, uint32_t, attrtype, value) 242 #define NLA_PUT_S64(msg, attrtype, value) \ 243 NLA_PUT_TYPE(msg, int64_t, attrtype, value) 251 #define NLA_PUT_U64(msg, attrtype, value) \ 252 NLA_PUT_TYPE(msg, uint64_t, attrtype, value) 260 #define NLA_PUT_STRING(msg, attrtype, value) \ 261 NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value) 268 #define NLA_PUT_FLAG(msg, attrtype) \ 269 NLA_PUT(msg, attrtype, 0, NULL) 277 #define NLA_PUT_MSECS(msg, attrtype, msecs) \ 278 NLA_PUT_U64(msg, attrtype, msecs) 286 #define NLA_PUT_ADDR(msg, attrtype, addr) \ 287 NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \ 288 nl_addr_get_binary_addr(addr)) 296 #define NLA_PUT_DATA(msg, attrtype, data) \ 297 NLA_PUT(msg, attrtype, nl_data_get_size(data), \ 315 #define nla_for_each_attr(pos, head, len, rem) \ 316 for (pos = head, rem = len; \ 318 pos = nla_next(pos, &(rem))) 327 #define nla_for_each_nested(pos, nla, rem) \ 328 for (pos = (struct nlattr *) nla_data(nla), rem = nla_len(nla); \ 330 pos = nla_next(pos, &(rem)))
int nla_ok(const struct nlattr *, int)
Check if the attribute header and payload can be accessed safely.
int32_t nla_get_s32(const struct nlattr *)
Return payload of 32 bit signed integer attribute.
int nla_padlen(int payload)
Return length of padding at the tail of the attribute.
int nla_put_u16(struct nl_msg *, int, uint16_t)
Add 16 bit integer attribute to netlink message.
struct nlattr * nla_find(const struct nlattr *, int, int)
Find a single attribute in a stream of attributes.
int nla_get_flag(const struct nlattr *)
Return true if flag attribute is set.
int16_t nla_get_s16(const struct nlattr *)
Return payload of 16 bit signed integer attribute.
int nla_put_addr(struct nl_msg *, int, struct nl_addr *)
Add abstract address as unspecific attribute to netlink message.
int nla_put_s8(struct nl_msg *, int, int8_t)
Add 8 bit signed integer attribute to netlink message.
Attribute validation policy.
uint8_t nla_get_u8(const struct nlattr *)
Return value of 8 bit integer attribute.
Unspecified type, binary data chunk.
int nla_strcmp(const struct nlattr *, const char *)
Compare string attribute payload with string.
char * nla_get_string(const struct nlattr *)
Return payload of string attribute.
uint32_t nla_get_u32(const struct nlattr *)
Return payload of 32 bit integer attribute.
struct nlattr * nla_reserve(struct nl_msg *, int, int)
Reserve space for a attribute.
int8_t nla_get_s8(const struct nlattr *)
Return value of 8 bit signed integer attribute.
int nla_put_s32(struct nl_msg *, int, int32_t)
Add 32 bit signed integer attribute to netlink message.
NUL terminated character string.
int nla_is_nested(const struct nlattr *)
Return true if attribute has NLA_F_NESTED flag set.
int nla_total_size(int payload)
Return size of attribute including padding.
int nla_nest_end(struct nl_msg *, struct nlattr *)
Finalize nesting of attributes.
int nla_put_flag(struct nl_msg *, int)
Add flag netlink attribute to netlink message.
int64_t nla_get_s64(const struct nlattr *)
Return payload of s64 attribute.
struct nlattr * nla_next(const struct nlattr *, int *)
Return next attribute in a stream of attributes.
int nla_put_data(struct nl_msg *, int, const struct nl_data *)
Add abstract data as unspecific attribute to netlink message.
int nla_memcpy(void *, const struct nlattr *, int)
Copy attribute payload to another memory area.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
Create attribute index based on nested attribute.
int nla_type(const struct nlattr *)
Return type of the attribute.
int nla_put_msecs(struct nl_msg *, int, unsigned long)
Add a msecs netlink attribute to a netlink message.
int nla_attr_size(int payload)
Return size of attribute whithout padding.
int nla_put_u64(struct nl_msg *, int, uint64_t)
Add 64 bit integer attribute to netlink message.
int nla_put_nested(struct nl_msg *, int, const struct nl_msg *)
Add nested attributes to netlink message.
void * nla_data(const struct nlattr *)
Return pointer to the payload section.
uint16_t maxlen
Maximal length of payload allowed.
int nla_len(const struct nlattr *)
Return length of the payload .
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.
unsigned long nla_get_msecs(const struct nlattr *)
Return payload of msecs attribute.
uint16_t minlen
Minimal length of payload required.
int nla_put_s16(struct nl_msg *, int, int16_t)
Add 16 bit signed integer attribute to netlink message.
void nla_nest_cancel(struct nl_msg *, const struct nlattr *)
Cancel the addition of a nested attribute.
uint16_t type
Type of attribute or NLA_UNSPEC.
int nla_memcmp(const struct nlattr *, const void *, size_t)
Compare attribute payload with memory area.
uint16_t nla_get_u16(const struct nlattr *)
Return payload of 16 bit integer attribute.
int nla_put_u32(struct nl_msg *, int, uint32_t)
Add 32 bit integer attribute to netlink message.
int nla_put_u8(struct nl_msg *, int, uint8_t)
Add 8 bit integer attribute to netlink message.
uint64_t nla_get_u64(const struct nlattr *)
Return payload of u64 attribute.
int nla_put_string(struct nl_msg *, int, const char *)
Add string attribute to netlink message.
int nla_put(struct nl_msg *, int, int, const void *)
Add a unspecific attribute to netlink message.
int nla_put_s64(struct nl_msg *, int, int64_t)
Add 64 bit signed integer attribute to netlink message.
size_t nla_strlcpy(char *, const struct nlattr *, size_t)
Copy string attribute payload to a buffer.
struct nlattr * nla_nest_start(struct nl_msg *, int)
Start a new level of nested attributes.
int nla_validate(const struct nlattr *, int, int, const struct nla_policy *)
Validate a stream of attributes.