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> 52 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1) 90 extern int nla_type(
const struct nlattr *);
91 extern void *
nla_data(
const struct nlattr *);
92 extern int nla_len(
const struct nlattr *);
95 extern int nla_ok(
const struct nlattr *,
int);
96 extern struct nlattr *
nla_next(
const struct nlattr *,
int *);
97 extern int nla_parse(
struct nlattr **,
int,
struct nlattr *,
103 extern struct nlattr *
nla_find(
struct nlattr *,
int,
int);
106 extern int nla_memcpy(
void *,
struct nlattr *,
int);
107 extern size_t nla_strlcpy(
char *,
const struct nlattr *,
size_t);
108 extern int nla_memcmp(
const struct nlattr *,
const void *,
size_t);
109 extern int nla_strcmp(
const struct nlattr *,
const char *);
112 extern struct nlattr *
nla_reserve(
struct nl_msg *,
int,
int);
113 extern int nla_put(
struct nl_msg *,
int,
int,
const void *);
115 extern int nla_put_u8(
struct nl_msg *,
int, uint8_t);
116 extern int nla_put_u16(
struct nl_msg *,
int, uint16_t);
117 extern int nla_put_u32(
struct nl_msg *,
int, uint32_t);
118 extern int nla_put_u64(
struct nl_msg *,
int, uint64_t);
121 extern int nla_put_msecs(
struct nl_msg *,
int,
unsigned long);
122 extern int nla_put_data(
struct nl_msg *,
int,
struct nl_data *);
123 extern int nla_put_addr(
struct nl_msg *,
int,
struct nl_addr *);
127 extern int nla_nest_end(
struct nl_msg *,
struct nlattr *);
138 extern struct nl_addr *
nla_get_addr(
struct nlattr *,
int);
157 #define NLA_PUT(n, attrtype, attrlen, data) \ 159 if (nla_put(n, attrtype, attrlen, data) < 0) \ 160 goto nla_put_failure; \ 171 #define NLA_PUT_TYPE(n, type, attrtype, value) \ 173 type __tmp = value; \ 174 NLA_PUT(n, attrtype, sizeof(type), &__tmp); \ 183 #define NLA_PUT_U8(n, attrtype, value) \ 184 NLA_PUT_TYPE(n, uint8_t, attrtype, value) 192 #define NLA_PUT_U16(n, attrtype, value) \ 193 NLA_PUT_TYPE(n, uint16_t, attrtype, value) 201 #define NLA_PUT_U32(n, attrtype, value) \ 202 NLA_PUT_TYPE(n, uint32_t, attrtype, value) 210 #define NLA_PUT_U64(n, attrtype, value) \ 211 NLA_PUT_TYPE(n, uint64_t, attrtype, value) 219 #define NLA_PUT_STRING(n, attrtype, value) \ 220 NLA_PUT(n, attrtype, strlen(value) + 1, value) 227 #define NLA_PUT_FLAG(n, attrtype) \ 228 NLA_PUT(n, attrtype, 0, NULL) 236 #define NLA_PUT_MSECS(n, attrtype, msecs) \ 237 NLA_PUT_U64(n, attrtype, msecs) 245 #define NLA_PUT_ADDR(n, attrtype, addr) \ 246 NLA_PUT(n, attrtype, nl_addr_get_len(addr), \ 247 nl_addr_get_binary_addr(addr)) 264 #define nla_for_each_attr(pos, head, len, rem) \ 265 for (pos = head, rem = len; \ 267 pos = nla_next(pos, &(rem))) 276 #define nla_for_each_nested(pos, nla, rem) \ 277 for (pos = nla_data(nla), rem = nla_len(nla); \ 279 pos = nla_next(pos, &(rem))) int nla_validate(struct nlattr *, int, int, struct nla_policy *)
Validate a stream of attributes.
int nla_put_flag(struct nl_msg *, int)
Add a flag netlink attribute to a netlink message.
uint16_t nla_get_u16(struct nlattr *)
Return payload of u16 attribute.
int nla_ok(const struct nlattr *, int)
check if the netlink attribute fits into the remaining bytes
int nla_put_u64(struct nl_msg *, int, uint64_t)
Add a u64 netlink attribute to a netlink message.
int nla_padlen(int payload)
length of padding at the tail of the attribute
int nla_get_flag(struct nlattr *)
Return payload of flag attribute.
attribute validation policy
int nla_strcmp(const struct nlattr *, const char *)
Compare a string attribute against a string.
int nla_nest_end(struct nl_msg *, struct nlattr *)
Finalize nesting of attributes.
int nla_total_size(int payload)
total length of attribute including padding
int nla_memcpy(void *, struct nlattr *, int)
Copy a netlink attribute into another memory area.
int nla_put_u8(struct nl_msg *, int, uint8_t)
Add a u16 netlink attribute to a netlink message.
struct nlattr * nla_next(const struct nlattr *, int *)
next netlink attribte in attribute stream
int nla_put_data(struct nl_msg *, int, struct nl_data *)
Add an abstract data netlink attribute to a netlink message.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
parse nested attributes
uint8_t nla_get_u8(struct nlattr *)
Return payload of u8 attribute.
int nla_type(const struct nlattr *)
attribute type
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)
length of attribute not including padding
void * nla_data(const struct nlattr *)
head of payload
uint16_t maxlen
Maximal length of payload required to be available.
int nla_len(const struct nlattr *)
length of payload
struct nl_addr * nla_get_addr(struct nlattr *, int)
Return payload of address attribute.
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, struct nla_policy *policy)
Parse a stream of attributes into a tb buffer.
struct nlattr * nla_find(struct nlattr *, int, int)
Find a specific attribute in a stream of attributes.
uint16_t minlen
Minimal length of payload required to be available.
char * nla_get_string(struct nlattr *)
return payload of string attribute
int nla_put_string(struct nl_msg *, int, const char *)
Add a string netlink attribute to a netlink message.
int nla_put(struct nl_msg *, int, int, const void *)
Add a netlink attribute to a netlink message.
uint64_t nla_get_u64(struct nlattr *)
Return payload of u64 attribute.
int nla_put_u16(struct nl_msg *, int, uint16_t)
Add a u16 netlink attribute to a netlink message.
uint16_t type
Type of attribute or NLA_UNSPEC.
int nla_memcmp(const struct nlattr *, const void *, size_t)
Compare an attribute with sized memory area.
struct nlattr * nla_reserve(struct nl_msg *, int, int)
reserve room for attribute on the skb
int nla_put_nested(struct nl_msg *, int, struct nl_msg *)
Add a nested netlink attribute to a netlink message.
struct nl_data * nla_get_data(struct nlattr *)
Return payload of abstract data attribute.
struct nlattr * nla_nest_start(struct nl_msg *, int)
Start a new level of nested attributes.
uint32_t nla_get_u32(struct nlattr *)
Return payload of u32 attribute.
int nla_put_u32(struct nl_msg *, int, uint32_t)
Add a u32 netlink attribute to a netlink message.
int nla_put_addr(struct nl_msg *, int, struct nl_addr *)
Add an abstract address netlink attribute to a netlink message.
unsigned long nla_get_msecs(struct nlattr *)
Return payload of msecs attribute.
size_t nla_strlcpy(char *, const struct nlattr *, size_t)
Copy string attribute payload into a sized buffer.