2018-10-06 07:40:00 +08:00
|
|
|
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
2018-07-11 05:43:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
|
|
|
|
* Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
|
|
|
|
* Copyright (C) 2015 Huawei Inc.
|
|
|
|
* Copyright (C) 2017 Nicira, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "libbpf.h"
|
|
|
|
|
|
|
|
#define ERRNO_OFFSET(e) ((e) - __LIBBPF_ERRNO__START)
|
|
|
|
#define ERRCODE_OFFSET(c) ERRNO_OFFSET(LIBBPF_ERRNO__##c)
|
|
|
|
#define NR_ERRNO (__LIBBPF_ERRNO__END - __LIBBPF_ERRNO__START)
|
|
|
|
|
|
|
|
static const char *libbpf_strerror_table[NR_ERRNO] = {
|
|
|
|
[ERRCODE_OFFSET(LIBELF)] = "Something wrong in libelf",
|
|
|
|
[ERRCODE_OFFSET(FORMAT)] = "BPF object format invalid",
|
|
|
|
[ERRCODE_OFFSET(KVERSION)] = "'version' section incorrect or lost",
|
|
|
|
[ERRCODE_OFFSET(ENDIAN)] = "Endian mismatch",
|
|
|
|
[ERRCODE_OFFSET(INTERNAL)] = "Internal error in libbpf",
|
|
|
|
[ERRCODE_OFFSET(RELOC)] = "Relocation failed",
|
|
|
|
[ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading",
|
|
|
|
[ERRCODE_OFFSET(PROG2BIG)] = "Program too big",
|
|
|
|
[ERRCODE_OFFSET(KVER)] = "Incorrect kernel version",
|
|
|
|
[ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type",
|
|
|
|
[ERRCODE_OFFSET(WRNGPID)] = "Wrong pid in netlink message",
|
|
|
|
[ERRCODE_OFFSET(INVSEQ)] = "Invalid netlink sequence",
|
tools/bpf: add more netlink functionalities in lib/bpf
This patch added a few netlink attribute parsing functions
and the netlink API functions to query networking links, tc classes,
tc qdiscs and tc filters. For example, the following API is
to get networking links:
int nl_get_link(int sock, unsigned int nl_pid,
dump_nlmsg_t dump_link_nlmsg,
void *cookie);
Note that when the API is called, the user also provided a
callback function with the following signature:
int (*dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
The "cookie" is the parameter the user passed to the API and will
be available for the callback function.
The "msg" is the information about the result, e.g., ifinfomsg or
tcmsg. The "tb" is the parsed netlink attributes.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2018-09-06 07:58:05 +08:00
|
|
|
[ERRCODE_OFFSET(NLPARSE)] = "Incorrect netlink message parsing",
|
2018-07-11 05:43:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int libbpf_strerror(int err, char *buf, size_t size)
|
|
|
|
{
|
|
|
|
if (!buf || !size)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
err = err > 0 ? err : -err;
|
|
|
|
|
|
|
|
if (err < __LIBBPF_ERRNO__START) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = strerror_r(err, buf, size);
|
|
|
|
buf[size - 1] = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err < __LIBBPF_ERRNO__END) {
|
|
|
|
const char *msg;
|
|
|
|
|
|
|
|
msg = libbpf_strerror_table[ERRNO_OFFSET(err)];
|
|
|
|
snprintf(buf, size, "%s", msg);
|
|
|
|
buf[size - 1] = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, size, "Unknown libbpf error %d", err);
|
|
|
|
buf[size - 1] = '\0';
|
|
|
|
return -1;
|
|
|
|
}
|