mirror of
https://github.com/torvalds/linux.git
synced 2026-11-24 07:22:34 +00:00
libbpf is maturing as a library and gaining features that no other bpf libraries support (BPF Type Format, bpf to bpf calls, etc) Many Apache2 licensed projects (like bcc, bpftrace, gobpf, cilium, etc) would like to use libbpf, but cannot do this yet, since Apache Foundation explicitly states that LGPL is incompatible with Apache2. Hence let's relicense libbpf as dual license LGPL-2.1 or BSD-2-Clause, since BSD-2 is compatible with Apache2. Dual LGPL or Apache2 is invalid combination. Fix license mistake in Makefile as well. Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrey Ignatov <[email protected]> Acked-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Björn Töpel <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: David Beckett <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Acked-by: Joe Stringer <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Acked-by: Quentin Monnet <[email protected]> Acked-by: Thomas Graf <[email protected]> Acked-by: Roman Gushchin <[email protected]> Acked-by: Wang Nan <[email protected]> Acked-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
|
|
|
/*
|
|
* Copyright (C) 2013-2015 Alexei Starovoitov <[email protected]>
|
|
* Copyright (C) 2015 Wang Nan <[email protected]>
|
|
* 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",
|
|
[ERRCODE_OFFSET(NLPARSE)] = "Incorrect netlink message parsing",
|
|
};
|
|
|
|
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;
|
|
}
|