Attributes
[Messages]

Netlink Attributes Construction/Parsing Interface. More...

Data Structures

struct  nla_policy
 attribute validation policy More...

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 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.

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

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.

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:
n netlink message
attrtype attribute type
attrlen length of attribute payload
data head 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:
n netlink message
type atomic type
attrtype attribute type
value head 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:
pos loop counter, set to current attribute
head head of attribute stream
len length of attribute stream
rem initialized 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:
pos loop counter, set to current attribute
nla attribute containing the nested attributes
rem initialized 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:
n netlink message
attrtype attribute type
value numeric 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:
n netlink message
attrtype attribute type
value numeric 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:
n netlink message
attrtype attribute type
value numeric 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:
n netlink message
attrtype attribute type
value numeric 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:
n netlink message
attrtype attribute type
value character 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:
n netlink message
attrtype attribute type

Definition at line 227 of file attr.h.

#define NLA_PUT_MSECS ( n,
attrtype,
msecs   )     NLA_PUT_U64(n, attrtype, msecs)
Parameters:
n netlink message
attrtype attribute type
msecs numeric 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:
n netlink message
attrtype attribute type
addr abstract 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.

00035      {
00036         NLA_UNSPEC,     /**< Unspecified type */
00037         NLA_U8,         /**< 8bit integer */
00038         NLA_U16,        /**< 16bit integer */
00039         NLA_U32,        /**< 32bit integer */
00040         NLA_U64,        /**< 64bit integer */
00041         NLA_STRING,     /**< character string */
00042         NLA_FLAG,       /**< flag */
00043         NLA_MSECS,      /**< micro seconds (64bit) */
00044         NLA_NESTED,     /**< nested attributes */
00045         __NLA_TYPE_MAX,
00046 };


Function Documentation

int nla_attr_size ( int  payload  ) 
Parameters:
payload length of payload

Definition at line 108 of file attr.c.

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

00109 {
00110         return NLA_HDRLEN + payload;
00111 }

int nla_total_size ( int  payload  ) 
Parameters:
payload length of payload

Definition at line 117 of file attr.c.

References nla_attr_size().

Referenced by nla_padlen(), and nla_reserve().

00118 {
00119         return NLA_ALIGN(nla_attr_size(payload));
00120 }

int nla_padlen ( int  payload  ) 
Parameters:
payload length of payload

Definition at line 126 of file attr.c.

References nla_attr_size(), and nla_total_size().

Referenced by nla_reserve().

00127 {
00128         return nla_total_size(payload) - nla_attr_size(payload);
00129 }

int nla_type ( const struct nlattr *  nla  ) 
Parameters:
nla netlink attribute

Definition at line 142 of file attr.c.

Referenced by nla_find(), and nla_parse().

00143 {
00144         return nla->nla_type & NLA_TYPE_MASK;
00145 }

void* nla_data ( const struct nlattr *  nla  ) 
Parameters:
nla netlink 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().

00152 {
00153         return (char *) nla + NLA_HDRLEN;
00154 }

int nla_len ( const struct nlattr *  nla  ) 
Parameters:
nla netlink 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().

00161 {
00162         return nla->nla_len - NLA_HDRLEN;
00163 }

int nla_ok ( const struct nlattr *  nla,
int  remaining 
)
Parameters:
nla netlink attribute
remaining number of bytes remaining in attribute stream

Definition at line 177 of file attr.c.

00178 {
00179         return remaining >= sizeof(*nla) &&
00180                nla->nla_len >= sizeof(*nla) &&
00181                nla->nla_len <= remaining;
00182 }

struct nlattr* nla_next ( const struct nlattr *  nla,
int *  remaining 
) [read]
Parameters:
nla netlink attribute
remaining number 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.

00193 {
00194         int totlen = NLA_ALIGN(nla->nla_len);
00195 
00196         *remaining -= totlen;
00197         return (struct nlattr *) ((char *) nla + totlen);
00198 }

int nla_parse ( struct nlattr *  tb[],
int  maxtype,
struct nlattr *  head,
int  len,
struct nla_policy policy 
)
Parameters:
tb destination array with maxtype+1 elements
maxtype maximum attribute type to be expected
head head of attribute stream
len length of attribute stream
policy validation 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().

00264 {
00265         struct nlattr *nla;
00266         int rem, err;
00267 
00268         memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
00269 
00270         nla_for_each_attr(nla, head, len, rem) {
00271                 int type = nla_type(nla);
00272 
00273                 /* Padding attributes */
00274                 if (type == 0)
00275                         continue;
00276 
00277                 if (type <= maxtype) {
00278                         if (policy) {
00279                                 err = validate_nla(nla, maxtype, policy);
00280                                 if (err < 0)
00281                                         goto errout;
00282                         }
00283 
00284                         tb[type] = nla;
00285                 }
00286         }
00287 
00288         if (rem > 0)
00289                 fprintf(stderr, "netlink: %d bytes leftover after parsing "
00290                        "attributes.\n", rem);
00291 
00292         err = 0;
00293 errout:
00294         return err;
00295 }

int nla_parse_nested ( struct nlattr *  tb[],
int  maxtype,
struct nlattr *  nla,
struct nla_policy policy 
)
Parameters:
tb destination array with maxtype+1 elements
maxtype maximum attribute type to be expected
nla attribute containing the nested attributes
policy validation policy
See also:
nla_parse()

Definition at line 307 of file attr.c.

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

00309 {
00310         return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
00311 }

int nla_validate ( struct nlattr *  head,
int  len,
int  maxtype,
struct nla_policy policy 
)
Parameters:
head head of attribute stream
len length of attribute stream
maxtype maximum attribute type to be expected
policy validation 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 327 of file attr.c.

References nla_for_each_attr.

Referenced by nlmsg_validate().

00329 {
00330         struct nlattr *nla;
00331         int rem, err;
00332 
00333         nla_for_each_attr(nla, head, len, rem) {
00334                 err = validate_nla(nla, maxtype, policy);
00335                 if (err < 0)
00336                         goto errout;
00337         }
00338 
00339         err = 0;
00340 errout:
00341         return err;
00342 }

struct nlattr* nla_find ( struct nlattr *  head,
int  len,
int  attrtype 
) [read]
Parameters:
head head of attribute stream
len length of attribute stream
attrtype type of attribute to look for
Returns:
the first attribute in the stream matching the specified type.

Definition at line 352 of file attr.c.

References nla_for_each_attr, and nla_type().

Referenced by nlmsg_find_attr().

00353 {
00354         struct nlattr *nla;
00355         int rem;
00356 
00357         nla_for_each_attr(nla, head, len, rem)
00358                 if (nla_type(nla) == attrtype)
00359                         return nla;
00360 
00361         return NULL;
00362 }

int nla_memcpy ( void *  dest,
struct nlattr *  src,
int  count 
)
Parameters:
dest where to copy to memcpy
src netlink attribute to copy from
count size 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 382 of file attr.c.

References nla_data(), and nla_len().

Referenced by nla_get_u64().

00383 {
00384         int minlen;
00385 
00386         if (!src)
00387                 return 0;
00388         
00389         minlen = min_t(int, count, nla_len(src));
00390         memcpy(dest, nla_data(src), minlen);
00391 
00392         return minlen;
00393 }

size_t nla_strlcpy ( char *  dst,
const struct nlattr *  nla,
size_t  dstsize 
)
Parameters:
dst where to copy the string to
nla attribute to copy the string from
dstsize size 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 407 of file attr.c.

References nla_data(), and nla_len().

00408 {
00409         size_t srclen = nla_len(nla);
00410         char *src = nla_data(nla);
00411 
00412         if (srclen > 0 && src[srclen - 1] == '\0')
00413                 srclen--;
00414 
00415         if (dstsize > 0) {
00416                 size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen;
00417 
00418                 memset(dst, 0, dstsize);
00419                 memcpy(dst, src, len);
00420         }
00421 
00422         return srclen;
00423 }

int nla_memcmp ( const struct nlattr *  nla,
const void *  data,
size_t  size 
)
Parameters:
nla netlink attribute
data memory area
size size of memory area

Definition at line 431 of file attr.c.

References nla_data(), and nla_len().

00433 {
00434         int d = nla_len(nla) - size;
00435 
00436         if (d == 0)
00437                 d = memcmp(nla_data(nla), data, size);
00438 
00439         return d;
00440 }

int nla_strcmp ( const struct nlattr *  nla,
const char *  str 
)
Parameters:
nla netlink string attribute
str another string

Definition at line 447 of file attr.c.

References nla_data(), and nla_len().

00448 {
00449         int len = strlen(str) + 1;
00450         int d = nla_len(nla) - len;
00451 
00452         if (d == 0)
00453                 d = memcmp(nla_data(nla), str, len);
00454 
00455         return d;
00456 }

struct nlattr* nla_reserve ( struct nl_msg *  n,
int  attrtype,
int  attrlen 
) [read]
Parameters:
n netlink message
attrtype attribute type
attrlen length 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 474 of file attr.c.

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

Referenced by nla_put().

00475 {
00476         struct nlattr *nla;
00477         int tlen;
00478         
00479         tlen = NLMSG_ALIGN(n->nm_nlh->nlmsg_len) + nla_total_size(attrlen);
00480 
00481         if (tlen > n->nm_size) {
00482                 nl_errno(ENOBUFS);
00483                 return NULL;
00484         }
00485 
00486         nla = (struct nlattr *) nlmsg_tail(n->nm_nlh);
00487         nla->nla_type = attrtype;
00488         nla->nla_len = nla_attr_size(attrlen);
00489 
00490         memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen));
00491         n->nm_nlh->nlmsg_len = tlen;
00492 
00493         NL_DBG(2, "msg %p: Reserved %d bytes at offset +%td for attr %d "
00494                   "nlmsg_len=%d\n", n, attrlen,
00495                   (void *) nla - nlmsg_data(n->nm_nlh),
00496                   attrtype, n->nm_nlh->nlmsg_len);
00497 
00498         return nla;
00499 }

int nla_put ( struct nl_msg *  n,
int  attrtype,
int  attrlen,
const void *  data 
)
Parameters:
n netlink message
attrtype attribute type
attrlen length of attribute payload
data head of attribute payload
Returns:
-1 if the tailroom of the skb is insufficient to store the attribute header and payload.

Definition at line 511 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().

00512 {
00513         struct nlattr *nla;
00514 
00515         nla = nla_reserve(n, attrtype, attrlen);
00516         if (!nla)
00517                 return nl_errno(ENOMEM);
00518 
00519         memcpy(nla_data(nla), data, attrlen);
00520         NL_DBG(2, "msg %p: Wrote %d bytes at offset +%td for attr %d\n",
00521                n, attrlen, (void *) nla - nlmsg_data(n->nm_nlh), attrtype);
00522 
00523         return 0;
00524 }

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

Definition at line 535 of file attr.c.

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

Referenced by rtnl_neightbl_build_change_request().

00536 {
00537         return nla_put(n, attrtype, nlmsg_len(nested->nm_nlh),
00538                        nlmsg_data(nested->nm_nlh));
00539 }

int nla_put_u8 ( struct nl_msg *  n,
int  attrtype,
uint8_t  value 
)
Parameters:
n netlink message
attrtype attribute type
value numeric value

Definition at line 547 of file attr.c.

References nla_put().

00548 {
00549         return nla_put(n, attrtype, sizeof(uint8_t), &value);
00550 }

int nla_put_u16 ( struct nl_msg *  n,
int  attrtype,
uint16_t  value 
)
Parameters:
n netlink message
attrtype attribute type
value numeric value

Definition at line 558 of file attr.c.

References nla_put().

00559 {
00560         return nla_put(n, attrtype, sizeof(uint16_t), &value);
00561 }

int nla_put_u32 ( struct nl_msg *  n,
int  attrtype,
uint32_t  value 
)
Parameters:
n netlink message
attrtype attribute type
value numeric value

Definition at line 569 of file attr.c.

References nla_put().

Referenced by rtnl_neightbl_build_change_request().

00570 {
00571         return nla_put(n, attrtype, sizeof(uint32_t), &value);
00572 }

int nla_put_u64 ( struct nl_msg *  n,
int  attrtype,
uint64_t  value 
)
Parameters:
n netlink message
attrtype attribute type
value numeric value

Definition at line 580 of file attr.c.

References nla_put().

Referenced by nla_put_msecs(), and rtnl_neightbl_build_change_request().

00581 {
00582         return nla_put(n, attrtype, sizeof(uint64_t), &value);
00583 }

int nla_put_string ( struct nl_msg *  n,
int  attrtype,
const char *  str 
)
Parameters:
n netlink message
attrtype attribute type
str NUL terminated string

Definition at line 591 of file attr.c.

References nla_put().

Referenced by rtnl_neightbl_build_change_request().

00592 {
00593         return nla_put(n, attrtype, strlen(str) + 1, str);
00594 }

int nla_put_flag ( struct nl_msg *  n,
int  attrtype 
)
Parameters:
n netlink message
attrtype attribute type

Definition at line 601 of file attr.c.

References nla_put().

00602 {
00603         return nla_put(n, attrtype, 0, NULL);
00604 }

int nla_put_msecs ( struct nl_msg *  n,
int  attrtype,
unsigned long  msecs 
)
Parameters:
n netlink message
attrtype attribute type
msecs number of msecs

Definition at line 612 of file attr.c.

References nla_put_u64().

00613 {
00614         return nla_put_u64(n, attrtype, msecs);
00615 }

int nla_put_data ( struct nl_msg *  n,
int  attrtype,
struct nl_data *  data 
)
Parameters:
n netlink message
attrtype attribute type
data abstract data

Definition at line 623 of file attr.c.

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

00624 {
00625         return nla_put(n, attrtype, nl_data_get_size(data),
00626                        nl_data_get(data));
00627 }

int nla_put_addr ( struct nl_msg *  n,
int  attrtype,
struct nl_addr *  addr 
)
Parameters:
n netlink message
attrtype attribute type
addr abstract address

Definition at line 635 of file attr.c.

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

00636 {
00637         return nla_put(n, attrtype, nl_addr_get_len(addr),
00638                        nl_addr_get_binary_addr(addr));
00639 }

struct nlattr* nla_nest_start ( struct nl_msg *  n,
int  attrtype 
) [read]
Parameters:
n netlink message
attrtype attribute type of container
Returns:
the container attribute

Definition at line 655 of file attr.c.

References nla_put().

Referenced by rtnl_link_build_change_request().

00656 {
00657         struct nlattr *start = (struct nlattr *) nlmsg_tail(n->nm_nlh);
00658 
00659         if (nla_put(n, attrtype, 0, NULL) < 0)
00660                 return NULL;
00661 
00662         return start;
00663 }

int nla_nest_end ( struct nl_msg *  n,
struct nlattr *  start 
)
Parameters:
n netlink message
start container attribute

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

Returns:
the total data length of the skb.

Definition at line 675 of file attr.c.

Referenced by rtnl_link_build_change_request().

00676 {
00677         start->nla_len = (unsigned char *) nlmsg_tail(n->nm_nlh) -
00678                                 (unsigned char *) start;
00679         return 0;
00680 }

uint32_t nla_get_u32 ( struct nlattr *  nla  ) 
Parameters:
nla u32 netlink attribute

Definition at line 693 of file attr.c.

References nla_data().

00694 {
00695         return *(uint32_t *) nla_data(nla);
00696 }

uint16_t nla_get_u16 ( struct nlattr *  nla  ) 
Parameters:
nla u16 netlink attribute

Definition at line 702 of file attr.c.

References nla_data().

00703 {
00704         return *(uint16_t *) nla_data(nla);
00705 }

uint8_t nla_get_u8 ( struct nlattr *  nla  ) 
Parameters:
nla u8 netlink attribute

Definition at line 711 of file attr.c.

References nla_data().

00712 {
00713         return *(uint8_t *) nla_data(nla);
00714 }

uint64_t nla_get_u64 ( struct nlattr *  nla  ) 
Parameters:
nla u64 netlink attribute

Definition at line 720 of file attr.c.

References nla_memcpy().

Referenced by nla_get_msecs().

00721 {
00722         uint64_t tmp;
00723 
00724         nla_memcpy(&tmp, nla, sizeof(tmp));
00725 
00726         return tmp;
00727 }

char* nla_get_string ( struct nlattr *  nla  ) 
Parameters:
nla string netlink attribute

Definition at line 733 of file attr.c.

References nla_data().

00734 {
00735         return (char *) nla_data(nla);
00736 }

int nla_get_flag ( struct nlattr *  nla  ) 
Parameters:
nla flag netlink attribute

Definition at line 742 of file attr.c.

00743 {
00744         return !!nla;
00745 }

unsigned long nla_get_msecs ( struct nlattr *  nla  ) 
Parameters:
nla msecs netlink attribute
Returns:
the number of milliseconds.

Definition at line 753 of file attr.c.

References nla_get_u64().

00754 {
00755         return nla_get_u64(nla);
00756 }

struct nl_addr* nla_get_addr ( struct nlattr *  nla,
int  family 
) [read]
Parameters:
nla address netlink attribute
family address family
Returns:
Newly allocated address handle or NULL

Definition at line 765 of file attr.c.

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

00766 {
00767         return nl_addr_build(family, nla_data(nla), nla_len(nla));
00768 }

struct nl_data* nla_get_data ( struct nlattr *  nla  )  [read]
Parameters:
nla abstract data netlink attribute
Returns:
Newly allocated abstract data handle or NULL

Definition at line 776 of file attr.c.

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

00777 {
00778         return nl_data_alloc(nla_data(nla), nla_len(nla));
00779 }


Generated on 24 Nov 2013 for libnl by  doxygen 1.6.1