1 // SPDX-License-Identifier: LGPL-2.1
4 * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
5 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
6 * Copyright (C) 2015 Huawei Inc.
7 * Copyright (C) 2017 Nicira, Inc.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License (not later!)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, see <http://www.gnu.org/licenses>
29 #define ERRNO_OFFSET(e) ((e) - __LIBBPF_ERRNO__START)
30 #define ERRCODE_OFFSET(c) ERRNO_OFFSET(LIBBPF_ERRNO__##c)
31 #define NR_ERRNO (__LIBBPF_ERRNO__END - __LIBBPF_ERRNO__START)
33 static const char *libbpf_strerror_table[NR_ERRNO] = {
34 [ERRCODE_OFFSET(LIBELF)] = "Something wrong in libelf",
35 [ERRCODE_OFFSET(FORMAT)] = "BPF object format invalid",
36 [ERRCODE_OFFSET(KVERSION)] = "'version' section incorrect or lost",
37 [ERRCODE_OFFSET(ENDIAN)] = "Endian mismatch",
38 [ERRCODE_OFFSET(INTERNAL)] = "Internal error in libbpf",
39 [ERRCODE_OFFSET(RELOC)] = "Relocation failed",
40 [ERRCODE_OFFSET(VERIFY)] = "Kernel verifier blocks program loading",
41 [ERRCODE_OFFSET(PROG2BIG)] = "Program too big",
42 [ERRCODE_OFFSET(KVER)] = "Incorrect kernel version",
43 [ERRCODE_OFFSET(PROGTYPE)] = "Kernel doesn't support this program type",
44 [ERRCODE_OFFSET(WRNGPID)] = "Wrong pid in netlink message",
45 [ERRCODE_OFFSET(INVSEQ)] = "Invalid netlink sequence",
48 int libbpf_strerror(int err, char *buf, size_t size)
53 err = err > 0 ? err : -err;
55 if (err < __LIBBPF_ERRNO__START) {
58 ret = strerror_r(err, buf, size);
63 if (err < __LIBBPF_ERRNO__END) {
66 msg = libbpf_strerror_table[ERRNO_OFFSET(err)];
67 snprintf(buf, size, "%s", msg);
72 snprintf(buf, size, "Unknown libbpf error %d", err);