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> 
   50 #define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1) 
   77 extern int              nla_type(
const struct nlattr *);
 
   78 extern void *           
nla_data(
const struct nlattr *);
 
   79 extern int              nla_len(
const struct nlattr *);
 
   80 extern int              nla_ok(
const struct nlattr *, 
int);
 
   81 extern struct nlattr *  
nla_next(
const struct nlattr *, 
int *);
 
   82 extern int              nla_parse(
struct nlattr **, 
int, 
struct nlattr *,
 
   86 extern struct nlattr *  
nla_find(
struct nlattr *, 
int, 
int);
 
   89 extern int              nla_memcpy(
void *, 
struct nlattr *, 
int);
 
   90 extern size_t           nla_strlcpy(
char *, 
const struct nlattr *, 
size_t);
 
   91 extern int              nla_memcmp(
const struct nlattr *, 
const void *, 
size_t);
 
   92 extern int              nla_strcmp(
const struct nlattr *, 
const char *);
 
   95 extern struct nlattr *  
nla_reserve(
struct nl_msg *, 
int, 
int);
 
   96 extern int              nla_put(
struct nl_msg *, 
int, 
int, 
const void *);
 
   97 extern int              nla_put_data(
struct nl_msg *, 
int, 
struct nl_data *);
 
   98 extern int              nla_put_addr(
struct nl_msg *, 
int, 
struct nl_addr *);
 
  102 extern int              nla_put_u8(
struct nl_msg *, 
int, uint8_t);
 
  104 extern int              nla_put_u16(
struct nl_msg *, 
int, uint16_t);
 
  106 extern int              nla_put_u32(
struct nl_msg *, 
int, uint32_t);
 
  108 extern int              nla_put_u64(
struct nl_msg *, 
int, uint64_t);
 
  112 extern char *           nla_strdup(
struct nlattr *);
 
  121 extern int              nla_put_msecs(
struct nl_msg *, 
int, 
unsigned long);
 
  126 extern int              nla_nest_end(
struct nl_msg *, 
struct nlattr *);
 
  145 #define NLA_PUT(msg, attrtype, attrlen, data) \ 
  147                 if (nla_put(msg, attrtype, attrlen, data) < 0) \ 
  148                         goto nla_put_failure; \ 
  159 #define NLA_PUT_TYPE(msg, type, attrtype, value) \ 
  161                 type __tmp = value; \ 
  162                 NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \ 
  171 #define NLA_PUT_U8(msg, attrtype, value) \ 
  172         NLA_PUT_TYPE(msg, uint8_t, attrtype, value) 
  180 #define NLA_PUT_U16(msg, attrtype, value) \ 
  181         NLA_PUT_TYPE(msg, uint16_t, attrtype, value) 
  189 #define NLA_PUT_U32(msg, attrtype, value) \ 
  190         NLA_PUT_TYPE(msg, uint32_t, attrtype, value) 
  198 #define NLA_PUT_U64(msg, attrtype, value) \ 
  199         NLA_PUT_TYPE(msg, uint64_t, attrtype, value) 
  207 #define NLA_PUT_STRING(msg, attrtype, value) \ 
  208         NLA_PUT(msg, attrtype, strlen(value) + 1, value) 
  215 #define NLA_PUT_FLAG(msg, attrtype) \ 
  216         NLA_PUT(msg, attrtype, 0, NULL) 
  224 #define NLA_PUT_MSECS(msg, attrtype, msecs) \ 
  225         NLA_PUT_U64(msg, attrtype, msecs) 
  233 #define NLA_PUT_ADDR(msg, attrtype, addr) \ 
  234         NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \ 
  235                 nl_addr_get_binary_addr(addr)) 
  243 #define NLA_PUT_DATA(msg, attrtype, data) \ 
  244         NLA_PUT(msg, attrtype, nl_data_get_size(data), \ 
  262 #define nla_for_each_attr(pos, head, len, rem) \ 
  263         for (pos = head, rem = len; \ 
  265              pos = nla_next(pos, &(rem))) 
  274 #define nla_for_each_nested(pos, nla, rem) \ 
  275         for (pos = nla_data(nla), rem = nla_len(nla); \ 
  277              pos = nla_next(pos, &(rem)))