aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/nlattr.h
diff options
context:
space:
mode:
authorEric Leblond <eric@regit.org>2018-01-30 15:55:02 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-02-02 20:53:48 -0500
commitbbf48c18ee0cd18b53712aa09aefa29b64b3976e (patch)
treeb8cb67b2922bdd88e43371158a0094fcf09129f3 /tools/lib/bpf/nlattr.h
parent949abbe88436c000cc63fce2bdfeb48b7d06a7df (diff)
libbpf: add error reporting in XDP
Parse netlink ext attribute to get the error message returned by the card. Code is partially take from libnl. We add netlink.h to the uapi include of tools. And we need to avoid include of userspace netlink header to have a successful build of sample so nlattr.h has a define to avoid the inclusion. Using a direct define could have been an issue as NLMSGERR_ATTR_MAX can change in the future. We also define SOL_NETLINK if not defined to avoid to have to copy socket.h for a fixed value. Signed-off-by: Eric Leblond <eric@regit.org> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/nlattr.h')
-rw-r--r--tools/lib/bpf/nlattr.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/tools/lib/bpf/nlattr.h b/tools/lib/bpf/nlattr.h
new file mode 100644
index 000000000000..931a71f68f93
--- /dev/null
+++ b/tools/lib/bpf/nlattr.h
@@ -0,0 +1,72 @@
1/* SPDX-License-Identifier: LGPL-2.1 */
2
3/*
4 * NETLINK Netlink attributes
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation version 2.1
9 * of the License.
10 *
11 * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
12 */
13
14#ifndef __NLATTR_H
15#define __NLATTR_H
16
17#include <stdint.h>
18#include <linux/netlink.h>
19/* avoid multiple definition of netlink features */
20#define __LINUX_NETLINK_H
21
22/**
23 * Standard attribute types to specify validation policy
24 */
25enum {
26 NLA_UNSPEC, /**< Unspecified type, binary data chunk */
27 NLA_U8, /**< 8 bit integer */
28 NLA_U16, /**< 16 bit integer */
29 NLA_U32, /**< 32 bit integer */
30 NLA_U64, /**< 64 bit integer */
31 NLA_STRING, /**< NUL terminated character string */
32 NLA_FLAG, /**< Flag */
33 NLA_MSECS, /**< Micro seconds (64bit) */
34 NLA_NESTED, /**< Nested attributes */
35 __NLA_TYPE_MAX,
36};
37
38#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
39
40/**
41 * @ingroup attr
42 * Attribute validation policy.
43 *
44 * See section @core_doc{core_attr_parse,Attribute Parsing} for more details.
45 */
46struct nla_policy {
47 /** Type of attribute or NLA_UNSPEC */
48 uint16_t type;
49
50 /** Minimal length of payload required */
51 uint16_t minlen;
52
53 /** Maximal length of payload allowed */
54 uint16_t maxlen;
55};
56
57/**
58 * @ingroup attr
59 * Iterate over a stream of attributes
60 * @arg pos loop counter, set to current attribute
61 * @arg head head of attribute stream
62 * @arg len length of attribute stream
63 * @arg rem initialized to len, holds bytes currently remaining in stream
64 */
65#define nla_for_each_attr(pos, head, len, rem) \
66 for (pos = head, rem = len; \
67 nla_ok(pos, rem); \
68 pos = nla_next(pos, &(rem)))
69
70int nla_dump_errormsg(struct nlmsghdr *nlh);
71
72#endif /* __NLATTR_H */