libnl 1.1
Data Structures
Attributes
Messages

Netlink Attributes Construction/Parsing Interface. More...

Data Structures

struct  nla_policy
 attribute validation policy More...

Size Calculations

int nla_attr_size (int payload)
 length of attribute not including padding
int nla_total_size (int payload)
 total length of attribute including padding
int nla_padlen (int payload)
 length of padding at the tail of the attribute

Payload Access

int nla_type (const struct nlattr *nla)
 attribute type
void * nla_data (const struct nlattr *nla)
 head of payload
int nla_len (const struct nlattr *nla)
 length of payload

Attribute Parsing

int nla_ok (const struct nlattr *nla, int remaining)
 check if the netlink attribute fits into the remaining bytes
struct nlattr * nla_next (const struct nlattr *nla, int *remaining)
 next netlink attribte in attribute stream
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.
int nla_parse_nested (struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
 parse nested attributes
int nla_validate (struct nlattr *head, int len, int maxtype, struct nla_policy *policy)
 Validate a stream of attributes.
struct nlattr * nla_find (struct nlattr *head, int len, int attrtype)
 Find a specific attribute in a stream of attributes.

Utilities

int nla_memcpy (void *dest, struct nlattr *src, int count)
 Copy a netlink attribute into another memory area.
size_t nla_strlcpy (char *dst, const struct nlattr *nla, size_t dstsize)
 Copy string attribute payload into a sized buffer.
int nla_memcmp (const struct nlattr *nla, const void *data, size_t size)
 Compare an attribute with sized memory area.
int nla_strcmp (const struct nlattr *nla, const char *str)
 Compare a string attribute against a string.

Attribute Construction

struct nlattr * nla_reserve (struct nl_msg *n, int attrtype, int attrlen)
 reserve room for attribute on the skb
int nla_put (struct nl_msg *n, int attrtype, int attrlen, const void *data)
 Add a netlink attribute to a netlink message.
int nla_put_nested (struct nl_msg *n, int attrtype, struct nl_msg *nested)
 Add a nested netlink attribute to a netlink message.
int nla_put_u8 (struct nl_msg *n, int attrtype, uint8_t value)
 Add a u16 netlink attribute to a netlink message.
int nla_put_u16 (struct nl_msg *n, int attrtype, uint16_t value)
 Add a u16 netlink attribute to a netlink message.
int nla_put_u32 (struct nl_msg *n, int attrtype, uint32_t value)
 Add a u32 netlink attribute to a netlink message.
int nla_put_u64 (struct nl_msg *n, int attrtype, uint64_t value)
 Add a u64 netlink attribute to a netlink message.
int nla_put_string (struct nl_msg *n, int attrtype, const char *str)
 Add a string netlink attribute to a netlink message.
int nla_put_flag (struct nl_msg *n, int attrtype)
 Add a flag netlink attribute to a netlink message.
int nla_put_msecs (struct nl_msg *n, int attrtype, unsigned long msecs)
 Add a msecs netlink attribute to a netlink message.
int nla_put_data (struct nl_msg *n, int attrtype, struct nl_data *data)
 Add an abstract data netlink attribute to a netlink message.
int nla_put_addr (struct nl_msg *n, int attrtype, struct nl_addr *addr)
 Add an abstract address netlink attribute to a netlink message.

Attribute Nesting

struct nlattr * nla_nest_start (struct nl_msg *n, int attrtype)
 Start a new level of nested attributes.
int nla_nest_end (struct nl_msg *n, struct nlattr *start)
 Finalize nesting of attributes.

Attribute Reading

uint32_t nla_get_u32 (struct nlattr *nla)
 Return payload of u32 attribute.
uint16_t nla_get_u16 (struct nlattr *nla)
 Return payload of u16 attribute.
uint8_t nla_get_u8 (struct nlattr *nla)
 Return payload of u8 attribute.
uint64_t nla_get_u64 (struct nlattr *nla)
 Return payload of u64 attribute.
char * nla_get_string (struct nlattr *nla)
 return payload of string attribute
int nla_get_flag (struct nlattr *nla)
 Return payload of flag attribute.
unsigned long nla_get_msecs (struct nlattr *nla)
 Return payload of msecs attribute.
struct nl_addr * nla_get_addr (struct nlattr *nla, int family)
 Return payload of address attribute.
struct nl_data * nla_get_data (struct nlattr *nla)
 Return payload of abstract data attribute.

Validation Policy Types

enum  {
  NLA_UNSPEC, NLA_U8, NLA_U16, NLA_U32,
  NLA_U64, NLA_STRING, NLA_FLAG, NLA_MSECS,
  NLA_NESTED, __NLA_TYPE_MAX
}
 Standard attribute types to specify validation policy. More...
#define NLA_TYPE_MAX   (__NLA_TYPE_MAX - 1)
 Maximum netlink validation policy type.

Attribute Construction (Exception Based)

All these functions jump to nla_put_failure in case of a failure instead of returning an error code.

#define NLA_PUT(n, attrtype, attrlen, data)
 Add a netlink attribute to a netlink message.
#define NLA_PUT_TYPE(n, type, attrtype, value)
 Add a basic netlink attribute to a netlink message.
#define NLA_PUT_U8(n, attrtype, value)   NLA_PUT_TYPE(n, uint8_t, attrtype, value)
 Add a u8 netlink attribute to a netlink message.
#define NLA_PUT_U16(n, attrtype, value)   NLA_PUT_TYPE(n, uint16_t, attrtype, value)
 Add a u16 netlink attribute to a netlink message.
#define NLA_PUT_U32(n, attrtype, value)   NLA_PUT_TYPE(n, uint32_t, attrtype, value)
 Add a u32 netlink attribute to a netlink message.
#define NLA_PUT_U64(n, attrtype, value)   NLA_PUT_TYPE(n, uint64_t, attrtype, value)
 Add a u64 netlink attribute to a netlink message.
#define NLA_PUT_STRING(n, attrtype, value)   NLA_PUT(n, attrtype, strlen(value) + 1, value)
 Add a character string netlink attribute to a netlink message.
#define NLA_PUT_FLAG(n, attrtype)   NLA_PUT(n, attrtype, 0, NULL)
 Add a flag netlink attribute to a netlink message.
#define NLA_PUT_MSECS(n, attrtype, msecs)   NLA_PUT_U64(n, attrtype, msecs)
 Add a msecs netlink attribute to a netlink message.
#define NLA_PUT_ADDR(n, attrtype, addr)
 Add a address attribute to a netlink message.

Iterators

#define nla_for_each_attr(pos, head, len, rem)
 iterate over a stream of attributes
#define nla_for_each_nested(pos, nla, rem)
 iterate over a stream of nested attributes

Detailed Description

0) Introduction
Netlink attributes are chained together following each other:
    <------- nla_total_size(payload) ------->
    <---- nla_attr_size(payload) ----->
   +----------+- - -+- - - - - - - - - +- - -+-------- - -
   |  Header  | Pad |     Payload      | Pad |  Header
   +----------+- - -+- - - - - - - - - +- - -+-------- - -
                     <- nla_len(nla) ->      ^
   nla_data(nla)----^                        |
   nla_next(nla)-----------------------------'
The attribute header and payload must be aligned properly:
  <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
 +---------------------+- - -+- - - - - - - - - -+- - -+
 |        Header       | Pad |     Payload       | Pad |
 |   (struct nlattr)   | ing |                   | ing |
 +---------------------+- - -+- - - - - - - - - -+- - -+
  <-------------- nlattr->nla_len -------------->
Nested TLVs:
Nested TLVs are an array of TLVs nested into another TLV. This can be useful to allow subsystems to have their own formatting rules without the need to make the underlying layer be aware of it. It can also be useful to transfer arrays, lists and flattened trees.
  <-------------------- NLA_ALIGN(...) ------------------->
 +---------------+- - - - - - - - - - - - - - - - - -+- - -+
 |               |+---------+---------+- - -+-------+|     |
 |  TLV Header   ||  TLV 1  |  TLV 2  |     | TLV n || Pad |
 |               |+---------+---------+- - -+-------+|     |
 +---------------+- - - - - - - - - - - - - - - - - -+- - -+
                  <--------- nla_data(nla) --------->
1) Constructing a message with attributes
 int param1 = 10;
 char *param2 = "parameter text";

 struct nl_msg *msg = nlmsg_alloc();
 nla_put_u32(msg, 1, param1);
 nla_put_string(msg, 2, param2);
 
 nl_send_auto_complete(handle, nl_msg_get(msg));
 nlmsg_free(msg);
2) Constructing nested attributes
 struct nl_msg * nested_config(void)
 {
        int a = 5, int b = 10;
        struct nl_msg *n = nlmsg_alloc();
        nla_put_u32(n, 10, a);
        nla_put_u32(n, 20, b);
        return n;
 }

 ...
 struct nl_msg *m = nlmsg_alloc();
 struct nl_msg *nest = nested_config();
 nla_put_nested(m, 1, nest);

 nl_send_auto_complete(handle, nl_msg_get(m));
 nlmsg_free(nest);
 nlmsg_free(m);

Define Documentation

#define NLA_PUT (   n,
  attrtype,
  attrlen,
  data 
)
Value:
do { \
                if (nla_put(n, attrtype, attrlen, data) < 0) \
                        goto nla_put_failure; \
        } while(0)
Parameters:
nnetlink message
attrtypeattribute type
attrlenlength of attribute payload
datahead of attribute payload

Definition at line 157 of file attr.h.

#define NLA_PUT_TYPE (   n,
  type,
  attrtype,
  value 
)
Value:
do { \
                type __tmp = value; \
                NLA_PUT(n, attrtype, sizeof(type), &__tmp); \
        } while(0)
Parameters:
nnetlink message
typeatomic type
attrtypeattribute type
valuehead of attribute payload

Definition at line 171 of file attr.h.

#define nla_for_each_attr (   pos,
  head,
  len,
  rem 
)
Value:
for (pos = head, rem = len; \
             nla_ok(pos, rem); \
             pos = nla_next(pos, &(rem)))
Parameters:
posloop counter, set to current attribute
headhead of attribute stream
lenlength of attribute stream
reminitialized to len, holds bytes currently remaining in stream

Definition at line 264 of file attr.h.

Referenced by nla_find(), nla_parse(), and nla_validate().

#define nla_for_each_nested (   pos,
  nla,
  rem 
)
Value:
for (pos = nla_data(nla), rem = nla_len(nla); \
             nla_ok(pos, rem); \
             pos = nla_next(pos, &(rem)))
Parameters:
posloop counter, set to current attribute
nlaattribute containing the nested attributes
reminitialized to len, holds bytes currently remaining in stream

Definition at line 276 of file attr.h.

#define NLA_PUT_U8 (   n,
  attrtype,
  value 
)    NLA_PUT_TYPE(n, uint8_t, attrtype, value)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 183 of file attr.h.

Referenced by rtnl_link_build_change_request().

#define NLA_PUT_U16 (   n,
  attrtype,
  value 
)    NLA_PUT_TYPE(n, uint16_t, attrtype, value)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 192 of file attr.h.

#define NLA_PUT_U32 (   n,
  attrtype,
  value 
)    NLA_PUT_TYPE(n, uint32_t, attrtype, value)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 201 of file attr.h.

Referenced by rtnl_link_build_change_request().

#define NLA_PUT_U64 (   n,
  attrtype,
  value 
)    NLA_PUT_TYPE(n, uint64_t, attrtype, value)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 210 of file attr.h.

#define NLA_PUT_STRING (   n,
  attrtype,
  value 
)    NLA_PUT(n, attrtype, strlen(value) + 1, value)
Parameters:
nnetlink message
attrtypeattribute type
valuecharacter string

Definition at line 219 of file attr.h.

Referenced by rtnl_link_build_change_request().

#define NLA_PUT_FLAG (   n,
  attrtype 
)    NLA_PUT(n, attrtype, 0, NULL)
Parameters:
nnetlink message
attrtypeattribute type

Definition at line 227 of file attr.h.

#define NLA_PUT_MSECS (   n,
  attrtype,
  msecs 
)    NLA_PUT_U64(n, attrtype, msecs)
Parameters:
nnetlink message
attrtypeattribute type
msecsnumeric value in micro seconds

Definition at line 236 of file attr.h.

#define NLA_PUT_ADDR (   n,
  attrtype,
  addr 
)
Value:
NLA_PUT(n, attrtype, nl_addr_get_len(addr), \
                nl_addr_get_binary_addr(addr))
Parameters:
nnetlink message
attrtypeattribute type
addrabstract address object

Definition at line 245 of file attr.h.

Referenced by rtnl_link_build_change_request().


Enumeration Type Documentation

anonymous enum
Enumerator:
NLA_UNSPEC 

Unspecified type.

NLA_U8 

8bit integer

NLA_U16 

16bit integer

NLA_U32 

32bit integer

NLA_U64 

64bit integer

NLA_STRING 

character string

NLA_FLAG 

flag

NLA_MSECS 

micro seconds (64bit)

NLA_NESTED 

nested attributes

Definition at line 35 of file attr.h.

     {
        NLA_UNSPEC,     /**< Unspecified type */
        NLA_U8,         /**< 8bit integer */
        NLA_U16,        /**< 16bit integer */
        NLA_U32,        /**< 32bit integer */
        NLA_U64,        /**< 64bit integer */
        NLA_STRING,     /**< character string */
        NLA_FLAG,       /**< flag */
        NLA_MSECS,      /**< micro seconds (64bit) */
        NLA_NESTED,     /**< nested attributes */
        __NLA_TYPE_MAX,
};

Function Documentation

int nla_attr_size ( int  payload)
Parameters:
payloadlength of payload

Definition at line 108 of file attr.c.

Referenced by nla_padlen(), nla_reserve(), and nla_total_size().

{
        return NLA_HDRLEN + payload;
}
int nla_total_size ( int  payload)
Parameters:
payloadlength of payload

Definition at line 117 of file attr.c.

References nla_attr_size().

Referenced by nla_padlen(), and nla_reserve().

{
        return NLA_ALIGN(nla_attr_size(payload));
}
int nla_padlen ( int  payload)
Parameters:
payloadlength of payload

Definition at line 126 of file attr.c.

References nla_attr_size(), and nla_total_size().

Referenced by nla_reserve().

{
        return nla_total_size(payload) - nla_attr_size(payload);
}
int nla_type ( const struct nlattr *  nla)
Parameters:
nlanetlink attribute

Definition at line 142 of file attr.c.

Referenced by nla_find(), and nla_parse().

{
        return nla->nla_type & NLA_TYPE_MASK;
}
void* nla_data ( const struct nlattr *  nla)
Parameters:
nlanetlink attribute

Definition at line 151 of file attr.c.

Referenced by nla_get_addr(), nla_get_data(), nla_get_string(), nla_get_u16(), nla_get_u32(), nla_get_u8(), nla_memcmp(), nla_memcpy(), nla_parse_nested(), nla_put(), nla_strcmp(), and nla_strlcpy().

{
        return (char *) nla + NLA_HDRLEN;
}
int nla_len ( const struct nlattr *  nla)
Parameters:
nlanetlink attribute

Definition at line 160 of file attr.c.

Referenced by nla_get_addr(), nla_get_data(), nla_memcmp(), nla_memcpy(), nla_parse_nested(), nla_strcmp(), and nla_strlcpy().

{
        return nla->nla_len - NLA_HDRLEN;
}
int nla_ok ( const struct nlattr *  nla,
int  remaining 
)
Parameters:
nlanetlink attribute
remainingnumber of bytes remaining in attribute stream

Definition at line 177 of file attr.c.

{
        return remaining >= sizeof(*nla) &&
               nla->nla_len >= sizeof(*nla) &&
               nla->nla_len <= remaining;
}
struct nlattr* nla_next ( const struct nlattr *  nla,
int *  remaining 
) [read]
Parameters:
nlanetlink attribute
remainingnumber of bytes remaining in attribute stream
Returns:
the next netlink attribute in the attribute stream and decrements remaining by the size of the current attribute.

Definition at line 192 of file attr.c.

{
        int totlen = NLA_ALIGN(nla->nla_len);

        *remaining -= totlen;
        return (struct nlattr *) ((char *) nla + totlen);
}
int nla_parse ( struct nlattr *  tb[],
int  maxtype,
struct nlattr *  head,
int  len,
struct nla_policy policy 
)
Parameters:
tbdestination array with maxtype+1 elements
maxtypemaximum attribute type to be expected
headhead of attribute stream
lenlength of attribute stream
policyvalidation policy

Parses a stream of attributes and stores a pointer to each attribute in the tb array accessable via the attribute type. Attributes with a type exceeding maxtype will be silently ignored for backwards compatibility reasons. policy may be set to NULL if no validation is required.

Returns:
0 on success or a negative error code.

Definition at line 262 of file attr.c.

References nla_for_each_attr, and nla_type().

Referenced by nla_parse_nested(), and nlmsg_parse().

{
        struct nlattr *nla;
        int rem, err;

        memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));

        nla_for_each_attr(nla, head, len, rem) {
                int type = nla_type(nla);

                if (type == 0) {
                        fprintf(stderr, "Illegal nla->nla_type == 0\n");
                        continue;
                }

                if (type <= maxtype) {
                        if (policy) {
                                err = validate_nla(nla, maxtype, policy);
                                if (err < 0)
                                        goto errout;
                        }

                        tb[type] = nla;
                }
        }

        if (rem > 0)
                fprintf(stderr, "netlink: %d bytes leftover after parsing "
                       "attributes.\n", rem);

        err = 0;
errout:
        return err;
}
int nla_parse_nested ( struct nlattr *  tb[],
int  maxtype,
struct nlattr *  nla,
struct nla_policy policy 
)
Parameters:
tbdestination array with maxtype+1 elements
maxtypemaximum attribute type to be expected
nlaattribute containing the nested attributes
policyvalidation policy
See also:
nla_parse()

Definition at line 308 of file attr.c.

References nla_data(), nla_len(), and nla_parse().

{
        return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
}
int nla_validate ( struct nlattr *  head,
int  len,
int  maxtype,
struct nla_policy policy 
)
Parameters:
headhead of attribute stream
lenlength of attribute stream
maxtypemaximum attribute type to be expected
policyvalidation policy

Validates all attributes in the specified attribute stream against the specified policy. Attributes with a type exceeding maxtype will be ignored. See documenation of struct nla_policy for more details.

Returns:
0 on success or a negative error code.

Definition at line 328 of file attr.c.

References nla_for_each_attr.

Referenced by nlmsg_validate().

{
        struct nlattr *nla;
        int rem, err;

        nla_for_each_attr(nla, head, len, rem) {
                err = validate_nla(nla, maxtype, policy);
                if (err < 0)
                        goto errout;
        }

        err = 0;
errout:
        return err;
}
struct nlattr* nla_find ( struct nlattr *  head,
int  len,
int  attrtype 
) [read]
Parameters:
headhead of attribute stream
lenlength of attribute stream
attrtypetype of attribute to look for
Returns:
the first attribute in the stream matching the specified type.

Definition at line 353 of file attr.c.

References nla_for_each_attr, and nla_type().

Referenced by nlmsg_find_attr().

{
        struct nlattr *nla;
        int rem;

        nla_for_each_attr(nla, head, len, rem)
                if (nla_type(nla) == attrtype)
                        return nla;

        return NULL;
}
int nla_memcpy ( void *  dest,
struct nlattr *  src,
int  count 
)
Parameters:
destwhere to copy to memcpy
srcnetlink attribute to copy from
countsize of the destination area

Note: The number of bytes copied is limited by the length of attribute's payload. memcpy

Returns:
the number of bytes copied.

Definition at line 383 of file attr.c.

References nla_data(), and nla_len().

Referenced by nla_get_u64().

{
        int minlen;

        if (!src)
                return 0;
        
        minlen = min_t(int, count, nla_len(src));
        memcpy(dest, nla_data(src), minlen);

        return minlen;
}
size_t nla_strlcpy ( char *  dst,
const struct nlattr *  nla,
size_t  dstsize 
)
Parameters:
dstwhere to copy the string to
nlaattribute to copy the string from
dstsizesize of destination buffer

Copies at most dstsize - 1 bytes into the destination buffer. The result is always a valid NUL-terminated string. Unlike strlcpy the destination buffer is always padded out.

Returns:
the length of the source buffer.

Definition at line 408 of file attr.c.

References nla_data(), and nla_len().

{
        size_t srclen = nla_len(nla);
        char *src = nla_data(nla);

        if (srclen > 0 && src[srclen - 1] == '\0')
                srclen--;

        if (dstsize > 0) {
                size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen;

                memset(dst, 0, dstsize);
                memcpy(dst, src, len);
        }

        return srclen;
}
int nla_memcmp ( const struct nlattr *  nla,
const void *  data,
size_t  size 
)
Parameters:
nlanetlink attribute
datamemory area
sizesize of memory area

Definition at line 432 of file attr.c.

References nla_data(), and nla_len().

{
        int d = nla_len(nla) - size;

        if (d == 0)
                d = memcmp(nla_data(nla), data, size);

        return d;
}
int nla_strcmp ( const struct nlattr *  nla,
const char *  str 
)
Parameters:
nlanetlink string attribute
stranother string

Definition at line 448 of file attr.c.

References nla_data(), and nla_len().

{
        int len = strlen(str) + 1;
        int d = nla_len(nla) - len;

        if (d == 0)
                d = memcmp(nla_data(nla), str, len);

        return d;
}
struct nlattr* nla_reserve ( struct nl_msg *  n,
int  attrtype,
int  attrlen 
) [read]
Parameters:
nnetlink message
attrtypeattribute type
attrlenlength of attribute payload

Adds a netlink attribute header to a netlink message and reserves room for the payload but does not copy it.

Definition at line 475 of file attr.c.

References nla_attr_size(), nla_padlen(), nla_total_size(), and nlmsg_data().

Referenced by nla_put().

{
        struct nlattr *nla;
        int tlen;
        
        tlen = NLMSG_ALIGN(n->nm_nlh->nlmsg_len) + nla_total_size(attrlen);

        if ((tlen + n->nm_nlh->nlmsg_len) > n->nm_size) {
                nl_errno(ENOBUFS);
                return NULL;
        }

        nla = (struct nlattr *) nlmsg_tail(n->nm_nlh);
        nla->nla_type = attrtype;
        nla->nla_len = nla_attr_size(attrlen);

        memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen));
        n->nm_nlh->nlmsg_len = tlen;

        NL_DBG(2, "msg %p: Reserved %d bytes at offset +%td for attr %d "
                  "nlmsg_len=%d\n", n, attrlen,
                  (void *) nla - nlmsg_data(n->nm_nlh),
                  attrtype, n->nm_nlh->nlmsg_len);

        return nla;
}
int nla_put ( struct nl_msg *  n,
int  attrtype,
int  attrlen,
const void *  data 
)
Parameters:
nnetlink message
attrtypeattribute type
attrlenlength of attribute payload
datahead of attribute payload
Returns:
-1 if the tailroom of the skb is insufficient to store the attribute header and payload.

Definition at line 512 of file attr.c.

References nla_data(), nla_reserve(), and nlmsg_data().

Referenced by nla_nest_start(), nla_put_addr(), nla_put_data(), nla_put_flag(), nla_put_nested(), nla_put_string(), nla_put_u16(), nla_put_u32(), nla_put_u64(), and nla_put_u8().

{
        struct nlattr *nla;

        nla = nla_reserve(n, attrtype, attrlen);
        if (!nla)
                return nl_errno(ENOMEM);

        memcpy(nla_data(nla), data, attrlen);
        NL_DBG(2, "msg %p: Wrote %d bytes at offset +%td for attr %d\n",
               n, attrlen, (void *) nla - nlmsg_data(n->nm_nlh), attrtype);

        return 0;
}
int nla_put_nested ( struct nl_msg *  n,
int  attrtype,
struct nl_msg *  nested 
)
Parameters:
nnetlink message
attrtypeattribute type
nestednetlink attribute to nest
Returns:
-1 if the tailroom of the skb is insufficient to store the attribute header and payload.

Definition at line 536 of file attr.c.

References nla_put(), nlmsg_data(), and nlmsg_len().

Referenced by rtnl_neightbl_build_change_request().

{
        return nla_put(n, attrtype, nlmsg_len(nested->nm_nlh),
                       nlmsg_data(nested->nm_nlh));
}
int nla_put_u8 ( struct nl_msg *  n,
int  attrtype,
uint8_t  value 
)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 548 of file attr.c.

References nla_put().

{
        return nla_put(n, attrtype, sizeof(uint8_t), &value);
}
int nla_put_u16 ( struct nl_msg *  n,
int  attrtype,
uint16_t  value 
)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 559 of file attr.c.

References nla_put().

{
        return nla_put(n, attrtype, sizeof(uint16_t), &value);
}
int nla_put_u32 ( struct nl_msg *  n,
int  attrtype,
uint32_t  value 
)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 570 of file attr.c.

References nla_put().

Referenced by rtnl_neightbl_build_change_request().

{
        return nla_put(n, attrtype, sizeof(uint32_t), &value);
}
int nla_put_u64 ( struct nl_msg *  n,
int  attrtype,
uint64_t  value 
)
Parameters:
nnetlink message
attrtypeattribute type
valuenumeric value

Definition at line 581 of file attr.c.

References nla_put().

Referenced by nla_put_msecs(), and rtnl_neightbl_build_change_request().

{
        return nla_put(n, attrtype, sizeof(uint64_t), &value);
}
int nla_put_string ( struct nl_msg *  n,
int  attrtype,
const char *  str 
)
Parameters:
nnetlink message
attrtypeattribute type
strNUL terminated string

Definition at line 592 of file attr.c.

References nla_put().

Referenced by rtnl_neightbl_build_change_request().

{
        return nla_put(n, attrtype, strlen(str) + 1, str);
}
int nla_put_flag ( struct nl_msg *  n,
int  attrtype 
)
Parameters:
nnetlink message
attrtypeattribute type

Definition at line 602 of file attr.c.

References nla_put().

{
        return nla_put(n, attrtype, 0, NULL);
}
int nla_put_msecs ( struct nl_msg *  n,
int  attrtype,
unsigned long  msecs 
)
Parameters:
nnetlink message
attrtypeattribute type
msecsnumber of msecs

Definition at line 613 of file attr.c.

References nla_put_u64().

{
        return nla_put_u64(n, attrtype, msecs);
}
int nla_put_data ( struct nl_msg *  n,
int  attrtype,
struct nl_data *  data 
)
Parameters:
nnetlink message
attrtypeattribute type
dataabstract data

Definition at line 624 of file attr.c.

References nl_data_get(), nl_data_get_size(), and nla_put().

{
        return nla_put(n, attrtype, nl_data_get_size(data),
                       nl_data_get(data));
}
int nla_put_addr ( struct nl_msg *  n,
int  attrtype,
struct nl_addr *  addr 
)
Parameters:
nnetlink message
attrtypeattribute type
addrabstract address

Definition at line 636 of file attr.c.

References nl_addr_get_binary_addr(), nl_addr_get_len(), and nla_put().

{
        return nla_put(n, attrtype, nl_addr_get_len(addr),
                       nl_addr_get_binary_addr(addr));
}
struct nlattr* nla_nest_start ( struct nl_msg *  n,
int  attrtype 
) [read]
Parameters:
nnetlink message
attrtypeattribute type of container
Returns:
the container attribute

Definition at line 656 of file attr.c.

References nla_put().

Referenced by rtnl_link_build_change_request().

{
        struct nlattr *start = (struct nlattr *) nlmsg_tail(n->nm_nlh);

        if (nla_put(n, attrtype, 0, NULL) < 0)
                return NULL;

        return start;
}
int nla_nest_end ( struct nl_msg *  n,
struct nlattr *  start 
)
Parameters:
nnetlink message
startcontainer attribute

Corrects the container attribute header to include the all appeneded attributes.

Returns:
the total data length of the skb.

Definition at line 676 of file attr.c.

Referenced by rtnl_link_build_change_request().

{
        start->nla_len = (unsigned char *) nlmsg_tail(n->nm_nlh) -
                                (unsigned char *) start;
        return 0;
}
uint32_t nla_get_u32 ( struct nlattr *  nla)
Parameters:
nlau32 netlink attribute

Definition at line 694 of file attr.c.

References nla_data().

{
        return *(uint32_t *) nla_data(nla);
}
uint16_t nla_get_u16 ( struct nlattr *  nla)
Parameters:
nlau16 netlink attribute

Definition at line 703 of file attr.c.

References nla_data().

{
        return *(uint16_t *) nla_data(nla);
}
uint8_t nla_get_u8 ( struct nlattr *  nla)
Parameters:
nlau8 netlink attribute

Definition at line 712 of file attr.c.

References nla_data().

{
        return *(uint8_t *) nla_data(nla);
}
uint64_t nla_get_u64 ( struct nlattr *  nla)
Parameters:
nlau64 netlink attribute

Definition at line 721 of file attr.c.

References nla_memcpy().

Referenced by nla_get_msecs().

{
        uint64_t tmp;

        nla_memcpy(&tmp, nla, sizeof(tmp));

        return tmp;
}
char* nla_get_string ( struct nlattr *  nla)
Parameters:
nlastring netlink attribute

Definition at line 734 of file attr.c.

References nla_data().

{
        return (char *) nla_data(nla);
}
int nla_get_flag ( struct nlattr *  nla)
Parameters:
nlaflag netlink attribute

Definition at line 743 of file attr.c.

{
        return !!nla;
}
unsigned long nla_get_msecs ( struct nlattr *  nla)
Parameters:
nlamsecs netlink attribute
Returns:
the number of milliseconds.

Definition at line 754 of file attr.c.

References nla_get_u64().

{
        return nla_get_u64(nla);
}
struct nl_addr* nla_get_addr ( struct nlattr *  nla,
int  family 
) [read]
Parameters:
nlaaddress netlink attribute
familyaddress family
Returns:
Newly allocated address handle or NULL

Definition at line 766 of file attr.c.

References nl_addr_build(), nla_data(), and nla_len().

{
        return nl_addr_build(family, nla_data(nla), nla_len(nla));
}
struct nl_data* nla_get_data ( struct nlattr *  nla) [read]
Parameters:
nlaabstract data netlink attribute
Returns:
Newly allocated abstract data handle or NULL

Definition at line 777 of file attr.c.

References nl_data_alloc(), nla_data(), and nla_len().

{
        return nl_data_alloc(nla_data(nla), nla_len(nla));
}