netlink: Add functions for working with big-endian attribute values.
[sliver-openvswitch.git] / lib / netlink.c
1 /*
2  * Copyright (c) 2008, 2009, 2010 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18 #include "netlink.h"
19 #include <assert.h>
20 #include <errno.h>
21 #include <inttypes.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include "coverage.h"
25 #include "netlink-protocol.h"
26 #include "ofpbuf.h"
27 #include "timeval.h"
28 #include "vlog.h"
29
30 VLOG_DEFINE_THIS_MODULE(netlink);
31
32 /* A single (bad) Netlink message can in theory dump out many, many log
33  * messages, so the burst size is set quite high here to avoid missing useful
34  * information.  Also, at high logging levels we log *all* Netlink messages. */
35 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 600);
36
37 /* Returns the nlmsghdr at the head of 'msg'.
38  *
39  * 'msg' must be at least as large as a nlmsghdr. */
40 struct nlmsghdr *
41 nl_msg_nlmsghdr(const struct ofpbuf *msg)
42 {
43     return ofpbuf_at_assert(msg, 0, NLMSG_HDRLEN);
44 }
45
46 /* Returns the genlmsghdr just past 'msg''s nlmsghdr.
47  *
48  * Returns a null pointer if 'msg' is not large enough to contain an nlmsghdr
49  * and a genlmsghdr. */
50 struct genlmsghdr *
51 nl_msg_genlmsghdr(const struct ofpbuf *msg)
52 {
53     return ofpbuf_at(msg, NLMSG_HDRLEN, GENL_HDRLEN);
54 }
55
56 /* If 'buffer' is a NLMSG_ERROR message, stores 0 in '*errorp' if it is an ACK
57  * message, otherwise a positive errno value, and returns true.  If 'buffer' is
58  * not an NLMSG_ERROR message, returns false.
59  *
60  * 'msg' must be at least as large as a nlmsghdr. */
61 bool
62 nl_msg_nlmsgerr(const struct ofpbuf *msg, int *errorp)
63 {
64     if (nl_msg_nlmsghdr(msg)->nlmsg_type == NLMSG_ERROR) {
65         struct nlmsgerr *err = ofpbuf_at(msg, NLMSG_HDRLEN, sizeof *err);
66         int code = EPROTO;
67         if (!err) {
68             VLOG_ERR_RL(&rl, "received invalid nlmsgerr (%zd bytes < %zd)",
69                         msg->size, NLMSG_HDRLEN + sizeof *err);
70         } else if (err->error <= 0 && err->error > INT_MIN) {
71             code = -err->error;
72         }
73         if (errorp) {
74             *errorp = code;
75         }
76         return true;
77     } else {
78         return false;
79     }
80 }
81
82 /* Ensures that 'b' has room for at least 'size' bytes plus netlink padding at
83  * its tail end, reallocating and copying its data if necessary. */
84 void
85 nl_msg_reserve(struct ofpbuf *msg, size_t size)
86 {
87     ofpbuf_prealloc_tailroom(msg, NLMSG_ALIGN(size));
88 }
89
90 static uint32_t
91 get_nlmsg_seq(void)
92 {
93     /* Next nlmsghdr sequence number.
94      *
95      * This implementation uses sequence numbers that are unique process-wide,
96      * to avoid a hypothetical race: send request, close socket, open new
97      * socket that reuses the old socket's PID value, send request on new
98      * socket, receive reply from kernel to old socket but with same PID and
99      * sequence number.  (This race could be avoided other ways, e.g. by
100      * preventing PIDs from being quickly reused). */
101     static uint32_t next_seq;
102
103     if (next_seq == 0) {
104         /* Pick initial sequence number. */
105         next_seq = getpid() ^ time_wall();
106     }
107     return next_seq++;
108 }
109
110 /* Puts a nlmsghdr at the beginning of 'msg', which must be initially empty.
111  * Uses the given 'type' and 'flags'.  'expected_payload' should be
112  * an estimate of the number of payload bytes to be supplied; if the size of
113  * the payload is unknown a value of 0 is acceptable.
114  *
115  * 'type' is ordinarily an enumerated value specific to the Netlink protocol
116  * (e.g. RTM_NEWLINK, for NETLINK_ROUTE protocol).  For Generic Netlink, 'type'
117  * is the family number obtained via nl_lookup_genl_family().
118  *
119  * 'flags' is a bit-mask that indicates what kind of request is being made.  It
120  * is often NLM_F_REQUEST indicating that a request is being made, commonly
121  * or'd with NLM_F_ACK to request an acknowledgement.
122  *
123  * Sets the new nlmsghdr's nlmsg_pid field to 0 for now.  nl_sock_send() will
124  * fill it in just before sending the message.
125  *
126  * nl_msg_put_genlmsghdr() is more convenient for composing a Generic Netlink
127  * message. */
128 void
129 nl_msg_put_nlmsghdr(struct ofpbuf *msg,
130                     size_t expected_payload, uint32_t type, uint32_t flags)
131 {
132     struct nlmsghdr *nlmsghdr;
133
134     assert(msg->size == 0);
135
136     nl_msg_reserve(msg, NLMSG_HDRLEN + expected_payload);
137     nlmsghdr = nl_msg_put_uninit(msg, NLMSG_HDRLEN);
138     nlmsghdr->nlmsg_len = 0;
139     nlmsghdr->nlmsg_type = type;
140     nlmsghdr->nlmsg_flags = flags;
141     nlmsghdr->nlmsg_seq = get_nlmsg_seq();
142     nlmsghdr->nlmsg_pid = 0;
143 }
144
145 /* Puts a nlmsghdr and genlmsghdr at the beginning of 'msg', which must be
146  * initially empty.  'expected_payload' should be an estimate of the number of
147  * payload bytes to be supplied; if the size of the payload is unknown a value
148  * of 0 is acceptable.
149  *
150  * 'family' is the family number obtained via nl_lookup_genl_family().
151  *
152  * 'flags' is a bit-mask that indicates what kind of request is being made.  It
153  * is often NLM_F_REQUEST indicating that a request is being made, commonly
154  * or'd with NLM_F_ACK to request an acknowledgement.
155  *
156  * 'cmd' is an enumerated value specific to the Generic Netlink family
157  * (e.g. CTRL_CMD_NEWFAMILY for the GENL_ID_CTRL family).
158  *
159  * 'version' is a version number specific to the family and command (often 1).
160  *
161  * Sets the new nlmsghdr's nlmsg_pid field to 0 for now.  nl_sock_send() will
162  * fill it in just before sending the message.
163  *
164  * nl_msg_put_nlmsghdr() should be used to compose Netlink messages that are
165  * not Generic Netlink messages. */
166 void
167 nl_msg_put_genlmsghdr(struct ofpbuf *msg, size_t expected_payload,
168                       int family, uint32_t flags, uint8_t cmd, uint8_t version)
169 {
170     struct genlmsghdr *genlmsghdr;
171
172     nl_msg_put_nlmsghdr(msg, GENL_HDRLEN + expected_payload, family, flags);
173     assert(msg->size == NLMSG_HDRLEN);
174     genlmsghdr = nl_msg_put_uninit(msg, GENL_HDRLEN);
175     genlmsghdr->cmd = cmd;
176     genlmsghdr->version = version;
177     genlmsghdr->reserved = 0;
178 }
179
180 /* Appends the 'size' bytes of data in 'p', plus Netlink padding if needed, to
181  * the tail end of 'msg'.  Data in 'msg' is reallocated and copied if
182  * necessary. */
183 void
184 nl_msg_put(struct ofpbuf *msg, const void *data, size_t size)
185 {
186     memcpy(nl_msg_put_uninit(msg, size), data, size);
187 }
188
189 /* Appends 'size' bytes of data, plus Netlink padding if needed, to the tail
190  * end of 'msg', reallocating and copying its data if necessary.  Returns a
191  * pointer to the first byte of the new data, which is left uninitialized. */
192 void *
193 nl_msg_put_uninit(struct ofpbuf *msg, size_t size)
194 {
195     size_t pad = NLMSG_ALIGN(size) - size;
196     char *p = ofpbuf_put_uninit(msg, size + pad);
197     if (pad) {
198         memset(p + size, 0, pad);
199     }
200     return p;
201 }
202
203 /* Appends a Netlink attribute of the given 'type' and room for 'size' bytes of
204  * data as its payload, plus Netlink padding if needed, to the tail end of
205  * 'msg', reallocating and copying its data if necessary.  Returns a pointer to
206  * the first byte of data in the attribute, which is left uninitialized. */
207 void *
208 nl_msg_put_unspec_uninit(struct ofpbuf *msg, uint16_t type, size_t size)
209 {
210     size_t total_size = NLA_HDRLEN + size;
211     struct nlattr* nla = nl_msg_put_uninit(msg, total_size);
212     assert(NLA_ALIGN(total_size) <= UINT16_MAX);
213     nla->nla_len = total_size;
214     nla->nla_type = type;
215     return nla + 1;
216 }
217
218 /* Appends a Netlink attribute of the given 'type' and the 'size' bytes of
219  * 'data' as its payload, to the tail end of 'msg', reallocating and copying
220  * its data if necessary.  Returns a pointer to the first byte of data in the
221  * attribute, which is left uninitialized. */
222 void
223 nl_msg_put_unspec(struct ofpbuf *msg, uint16_t type,
224                   const void *data, size_t size)
225 {
226     memcpy(nl_msg_put_unspec_uninit(msg, type, size), data, size);
227 }
228
229 /* Appends a Netlink attribute of the given 'type' and no payload to 'msg'.
230  * (Some Netlink protocols use the presence or absence of an attribute as a
231  * Boolean flag.) */
232 void
233 nl_msg_put_flag(struct ofpbuf *msg, uint16_t type)
234 {
235     nl_msg_put_unspec(msg, type, NULL, 0);
236 }
237
238 /* Appends a Netlink attribute of the given 'type' and the given 8-bit 'value'
239  * to 'msg'. */
240 void
241 nl_msg_put_u8(struct ofpbuf *msg, uint16_t type, uint8_t value)
242 {
243     nl_msg_put_unspec(msg, type, &value, sizeof value);
244 }
245
246 /* Appends a Netlink attribute of the given 'type' and the given 16-bit host
247  * byte order 'value' to 'msg'. */
248 void
249 nl_msg_put_u16(struct ofpbuf *msg, uint16_t type, uint16_t value)
250 {
251     nl_msg_put_unspec(msg, type, &value, sizeof value);
252 }
253
254 /* Appends a Netlink attribute of the given 'type' and the given 32-bit host
255  * byte order 'value' to 'msg'. */
256 void
257 nl_msg_put_u32(struct ofpbuf *msg, uint16_t type, uint32_t value)
258 {
259     nl_msg_put_unspec(msg, type, &value, sizeof value);
260 }
261
262 /* Appends a Netlink attribute of the given 'type' and the given 64-bit host
263  * byte order 'value' to 'msg'. */
264 void
265 nl_msg_put_u64(struct ofpbuf *msg, uint16_t type, uint64_t value)
266 {
267     nl_msg_put_unspec(msg, type, &value, sizeof value);
268 }
269
270 /* Appends a Netlink attribute of the given 'type' and the given 16-bit network
271  * byte order 'value' to 'msg'. */
272 void
273 nl_msg_put_be16(struct ofpbuf *msg, uint16_t type, ovs_be16 value)
274 {
275     nl_msg_put_unspec(msg, type, &value, sizeof value);
276 }
277
278 /* Appends a Netlink attribute of the given 'type' and the given 32-bit network
279  * byte order 'value' to 'msg'. */
280 void
281 nl_msg_put_be32(struct ofpbuf *msg, uint16_t type, ovs_be32 value)
282 {
283     nl_msg_put_unspec(msg, type, &value, sizeof value);
284 }
285
286 /* Appends a Netlink attribute of the given 'type' and the given 64-bit network
287  * byte order 'value' to 'msg'. */
288 void
289 nl_msg_put_be64(struct ofpbuf *msg, uint16_t type, ovs_be64 value)
290 {
291     nl_msg_put_unspec(msg, type, &value, sizeof value);
292 }
293
294 /* Appends a Netlink attribute of the given 'type' and the given
295  * null-terminated string 'value' to 'msg'. */
296 void
297 nl_msg_put_string(struct ofpbuf *msg, uint16_t type, const char *value)
298 {
299     nl_msg_put_unspec(msg, type, value, strlen(value) + 1);
300 }
301
302 /* Adds the header for nested Netlink attributes to 'msg', with the specified
303  * 'type', and returns the header's offset within 'msg'.  The caller should add
304  * the content for the nested Netlink attribute to 'msg' (e.g. using the other
305  * nl_msg_*() functions), and then pass the returned offset to
306  * nl_msg_end_nested() to finish up the nested attributes. */
307 size_t
308 nl_msg_start_nested(struct ofpbuf *msg, uint16_t type)
309 {
310     size_t offset = msg->size;
311     nl_msg_put_unspec(msg, type, NULL, 0);
312     return offset;
313 }
314
315 /* Finalizes a nested Netlink attribute in 'msg'.  'offset' should be the value
316  * returned by nl_msg_start_nested(). */
317 void
318 nl_msg_end_nested(struct ofpbuf *msg, size_t offset)
319 {
320     struct nlattr *attr = ofpbuf_at_assert(msg, offset, sizeof *attr);
321     attr->nla_len = msg->size - offset;
322 }
323
324 /* Appends a nested Netlink attribute of the given 'type', with the 'size'
325  * bytes of content starting at 'data', to 'msg'. */
326 void
327 nl_msg_put_nested(struct ofpbuf *msg,
328                   uint16_t type, const void *data, size_t size)
329 {
330     size_t offset = nl_msg_start_nested(msg, type);
331     nl_msg_put(msg, data, size);
332     nl_msg_end_nested(msg, offset);
333 }
334
335 /* If 'buffer' begins with a valid "struct nlmsghdr", pulls the header and its
336  * payload off 'buffer', stores header and payload in 'msg->data' and
337  * 'msg->size', and returns a pointer to the header.
338  *
339  * If 'buffer' does not begin with a "struct nlmsghdr" or begins with one that
340  * is invalid, returns NULL without modifying 'buffer'. */
341 struct nlmsghdr *
342 nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg)
343 {
344     if (buffer->size >= sizeof(struct nlmsghdr)) {
345         struct nlmsghdr *nlmsghdr = nl_msg_nlmsghdr(buffer);
346         size_t len = nlmsghdr->nlmsg_len;
347         if (len >= sizeof *nlmsghdr && len <= buffer->size) {
348             ofpbuf_use_const(msg, nlmsghdr, len);
349             ofpbuf_pull(buffer, len);
350             return nlmsghdr;
351         }
352     }
353
354     msg->data = NULL;
355     msg->size = 0;
356     return NULL;
357 }
358 \f
359 /* Attributes. */
360
361 /* Returns the first byte in the payload of attribute 'nla'. */
362 const void *
363 nl_attr_get(const struct nlattr *nla)
364 {
365     assert(nla->nla_len >= NLA_HDRLEN);
366     return nla + 1;
367 }
368
369 /* Returns the number of bytes in the payload of attribute 'nla'. */
370 size_t
371 nl_attr_get_size(const struct nlattr *nla)
372 {
373     assert(nla->nla_len >= NLA_HDRLEN);
374     return nla->nla_len - NLA_HDRLEN;
375 }
376
377 /* Asserts that 'nla''s payload is at least 'size' bytes long, and returns the
378  * first byte of the payload. */
379 const void *
380 nl_attr_get_unspec(const struct nlattr *nla, size_t size)
381 {
382     assert(nla->nla_len >= NLA_HDRLEN + size);
383     return nla + 1;
384 }
385
386 /* Returns true if 'nla' is nonnull.  (Some Netlink protocols use the presence
387  * or absence of an attribute as a Boolean flag.) */
388 bool
389 nl_attr_get_flag(const struct nlattr *nla)
390 {
391     return nla != NULL;
392 }
393
394 #define NL_ATTR_GET_AS(NLA, TYPE) \
395         (*(TYPE*) nl_attr_get_unspec(nla, sizeof(TYPE)))
396
397 /* Returns the 8-bit value in 'nla''s payload.
398  *
399  * Asserts that 'nla''s payload is at least 1 byte long. */
400 uint8_t
401 nl_attr_get_u8(const struct nlattr *nla)
402 {
403     return NL_ATTR_GET_AS(nla, uint8_t);
404 }
405
406 /* Returns the 16-bit host byte order value in 'nla''s payload.
407  *
408  * Asserts that 'nla''s payload is at least 2 bytes long. */
409 uint16_t
410 nl_attr_get_u16(const struct nlattr *nla)
411 {
412     return NL_ATTR_GET_AS(nla, uint16_t);
413 }
414
415 /* Returns the 32-bit host byte order value in 'nla''s payload.
416  *
417  * Asserts that 'nla''s payload is at least 4 bytes long. */
418 uint32_t
419 nl_attr_get_u32(const struct nlattr *nla)
420 {
421     return NL_ATTR_GET_AS(nla, uint32_t);
422 }
423
424 /* Returns the 64-bit host byte order value in 'nla''s payload.
425  *
426  * Asserts that 'nla''s payload is at least 8 bytes long. */
427 uint64_t
428 nl_attr_get_u64(const struct nlattr *nla)
429 {
430     return NL_ATTR_GET_AS(nla, uint64_t);
431 }
432
433 /* Returns the 16-bit network byte order value in 'nla''s payload.
434  *
435  * Asserts that 'nla''s payload is at least 2 bytes long. */
436 ovs_be16
437 nl_attr_get_be16(const struct nlattr *nla)
438 {
439     return NL_ATTR_GET_AS(nla, ovs_be16);
440 }
441
442 /* Returns the 32-bit network byte order value in 'nla''s payload.
443  *
444  * Asserts that 'nla''s payload is at least 4 bytes long. */
445 ovs_be32
446 nl_attr_get_be32(const struct nlattr *nla)
447 {
448     return NL_ATTR_GET_AS(nla, ovs_be32);
449 }
450
451 /* Returns the 64-bit network byte order value in 'nla''s payload.
452  *
453  * Asserts that 'nla''s payload is at least 8 bytes long. */
454 ovs_be64
455 nl_attr_get_be64(const struct nlattr *nla)
456 {
457     return NL_ATTR_GET_AS(nla, ovs_be64);
458 }
459
460 /* Returns the null-terminated string value in 'nla''s payload.
461  *
462  * Asserts that 'nla''s payload contains a null-terminated string. */
463 const char *
464 nl_attr_get_string(const struct nlattr *nla)
465 {
466     assert(nla->nla_len > NLA_HDRLEN);
467     assert(memchr(nl_attr_get(nla), '\0', nla->nla_len - NLA_HDRLEN) != NULL);
468     return nl_attr_get(nla);
469 }
470
471 /* Initializes 'nested' to the payload of 'nla'. */
472 void
473 nl_attr_get_nested(const struct nlattr *nla, struct ofpbuf *nested)
474 {
475     ofpbuf_use_const(nested, nl_attr_get(nla), nl_attr_get_size(nla));
476 }
477
478 /* Default minimum and maximum payload sizes for each type of attribute. */
479 static const size_t attr_len_range[][2] = {
480     [0 ... N_NL_ATTR_TYPES - 1] = { 0, SIZE_MAX },
481     [NL_A_U8] = { 1, 1 },
482     [NL_A_U16] = { 2, 2 },
483     [NL_A_U32] = { 4, 4 },
484     [NL_A_U64] = { 8, 8 },
485     [NL_A_STRING] = { 1, SIZE_MAX },
486     [NL_A_FLAG] = { 0, SIZE_MAX },
487     [NL_A_NESTED] = { 0, SIZE_MAX },
488 };
489
490 /* Parses the 'msg' starting at the given 'nla_offset' as a sequence of Netlink
491  * attributes.  'policy[i]', for 0 <= i < n_attrs, specifies how the attribute
492  * with nla_type == i is parsed; a pointer to attribute i is stored in
493  * attrs[i].  Returns true if successful, false on failure.
494  *
495  * If the Netlink attributes in 'msg' follow a Netlink header and a Generic
496  * Netlink header, then 'nla_offset' should be NLMSG_HDRLEN + GENL_HDRLEN. */
497 bool
498 nl_policy_parse(const struct ofpbuf *msg, size_t nla_offset,
499                 const struct nl_policy policy[],
500                 struct nlattr *attrs[], size_t n_attrs)
501 {
502     void *p, *tail;
503     size_t n_required;
504     size_t i;
505
506     n_required = 0;
507     for (i = 0; i < n_attrs; i++) {
508         attrs[i] = NULL;
509
510         assert(policy[i].type < N_NL_ATTR_TYPES);
511         if (policy[i].type != NL_A_NO_ATTR
512             && policy[i].type != NL_A_FLAG
513             && !policy[i].optional) {
514             n_required++;
515         }
516     }
517
518     p = ofpbuf_at(msg, nla_offset, 0);
519     if (p == NULL) {
520         VLOG_DBG_RL(&rl, "missing headers in nl_policy_parse");
521         return false;
522     }
523     tail = ofpbuf_tail(msg);
524
525     while (p < tail) {
526         size_t offset = (char*)p - (char*)msg->data;
527         struct nlattr *nla = p;
528         size_t len, aligned_len;
529         uint16_t type;
530
531         /* Make sure its claimed length is plausible. */
532         if (nla->nla_len < NLA_HDRLEN) {
533             VLOG_DBG_RL(&rl, "%zu: attr shorter than NLA_HDRLEN (%"PRIu16")",
534                         offset, nla->nla_len);
535             return false;
536         }
537         len = nla->nla_len - NLA_HDRLEN;
538         aligned_len = NLA_ALIGN(len);
539         if (aligned_len > (char*)tail - (char*)p) {
540             VLOG_DBG_RL(&rl, "%zu: attr %"PRIu16" aligned data len (%zu) "
541                         "> bytes left (%tu)",
542                         offset, nla->nla_type, aligned_len,
543                         (char*)tail - (char*)p);
544             return false;
545         }
546
547         type = nla->nla_type;
548         if (type < n_attrs && policy[type].type != NL_A_NO_ATTR) {
549             const struct nl_policy *e = &policy[type];
550             size_t min_len, max_len;
551
552             /* Validate length and content. */
553             min_len = e->min_len ? e->min_len : attr_len_range[e->type][0];
554             max_len = e->max_len ? e->max_len : attr_len_range[e->type][1];
555             if (len < min_len || len > max_len) {
556                 VLOG_DBG_RL(&rl, "%zu: attr %"PRIu16" length %zu not in "
557                             "allowed range %zu...%zu",
558                             offset, type, len, min_len, max_len);
559                 return false;
560             }
561             if (e->type == NL_A_STRING) {
562                 if (((char *) nla)[nla->nla_len - 1]) {
563                     VLOG_DBG_RL(&rl, "%zu: attr %"PRIu16" lacks null at end",
564                                 offset, type);
565                     return false;
566                 }
567                 if (memchr(nla + 1, '\0', len - 1) != NULL) {
568                     VLOG_DBG_RL(&rl, "%zu: attr %"PRIu16" has bad length",
569                                 offset, type);
570                     return false;
571                 }
572             }
573             if (!e->optional && attrs[type] == NULL) {
574                 assert(n_required > 0);
575                 --n_required;
576             }
577             attrs[type] = nla;
578         } else {
579             /* Skip attribute type that we don't care about. */
580         }
581         p = (char*)p + NLA_ALIGN(nla->nla_len);
582     }
583     if (n_required) {
584         VLOG_DBG_RL(&rl, "%zu required attrs missing", n_required);
585         return false;
586     }
587     return true;
588 }
589
590 /* Parses the Netlink attributes within 'nla'.  'policy[i]', for 0 <= i <
591  * n_attrs, specifies how the attribute with nla_type == i is parsed; a pointer
592  * to attribute i is stored in attrs[i].  Returns true if successful, false on
593  * failure. */
594 bool
595 nl_parse_nested(const struct nlattr *nla, const struct nl_policy policy[],
596                 struct nlattr *attrs[], size_t n_attrs)
597 {
598     struct ofpbuf buf;
599
600     nl_attr_get_nested(nla, &buf);
601     return nl_policy_parse(&buf, 0, policy, attrs, n_attrs);
602 }