mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
b52db43a3d
Both glibc and the kernel have in6_* macros definitions. Build fails because it picks up wrong in6_* macro from the kernel header and not the header from glibc. Fixes build error below: clang -I. -I./include/uapi -I../../../include/uapi -Wno-compare-distinct-pointer-types \ -O2 -target bpf -emit-llvm -c test_tcpbpf_kern.c -o - | \ llc -march=bpf -mcpu=generic -filetype=obj -o .../tools/testing/selftests/bpf/test_tcpbpf_kern.o In file included from test_tcpbpf_kern.c:12: .../netinet/in.h:101:5: error: expected identifier IPPROTO_HOPOPTS = 0, /* IPv6 Hop-by-Hop options. */ ^ .../linux/in6.h:131:26: note: expanded from macro 'IPPROTO_HOPOPTS' ^ In file included from test_tcpbpf_kern.c:12: /usr/include/netinet/in.h:103:5: error: expected identifier IPPROTO_ROUTING = 43, /* IPv6 routing header. */ ^ .../linux/in6.h:132:26: note: expanded from macro 'IPPROTO_ROUTING' ^ In file included from test_tcpbpf_kern.c:12: .../netinet/in.h:105:5: error: expected identifier IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header. */ ^ Since both glibc and the kernel have in6_* macros definitions, use the one from glibc. Kernel headers will check for previous libc definitions by including include/linux/libc-compat.h. Reported-by: Daniel Díaz <daniel.diaz@linaro.org> Signed-off-by: Anders Roxell <anders.roxell@linaro.org> Tested-by: Daniel Díaz <daniel.diaz@linaro.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
115 lines
2.5 KiB
C
115 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <linux/bpf.h>
|
|
#include <linux/if_ether.h>
|
|
#include <linux/if_packet.h>
|
|
#include <linux/ip.h>
|
|
#include <linux/types.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/tcp.h>
|
|
#include <netinet/in.h>
|
|
#include "bpf_helpers.h"
|
|
#include "bpf_endian.h"
|
|
#include "test_tcpbpf.h"
|
|
|
|
struct bpf_map_def SEC("maps") global_map = {
|
|
.type = BPF_MAP_TYPE_ARRAY,
|
|
.key_size = sizeof(__u32),
|
|
.value_size = sizeof(struct tcpbpf_globals),
|
|
.max_entries = 2,
|
|
};
|
|
|
|
static inline void update_event_map(int event)
|
|
{
|
|
__u32 key = 0;
|
|
struct tcpbpf_globals g, *gp;
|
|
|
|
gp = bpf_map_lookup_elem(&global_map, &key);
|
|
if (gp == NULL) {
|
|
struct tcpbpf_globals g = {0};
|
|
|
|
g.event_map |= (1 << event);
|
|
bpf_map_update_elem(&global_map, &key, &g,
|
|
BPF_ANY);
|
|
} else {
|
|
g = *gp;
|
|
g.event_map |= (1 << event);
|
|
bpf_map_update_elem(&global_map, &key, &g,
|
|
BPF_ANY);
|
|
}
|
|
}
|
|
|
|
int _version SEC("version") = 1;
|
|
|
|
SEC("sockops")
|
|
int bpf_testcb(struct bpf_sock_ops *skops)
|
|
{
|
|
int rv = -1;
|
|
int bad_call_rv = 0;
|
|
int good_call_rv = 0;
|
|
int op;
|
|
int v = 0;
|
|
|
|
op = (int) skops->op;
|
|
|
|
update_event_map(op);
|
|
|
|
switch (op) {
|
|
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
|
|
/* Test failure to set largest cb flag (assumes not defined) */
|
|
bad_call_rv = bpf_sock_ops_cb_flags_set(skops, 0x80);
|
|
/* Set callback */
|
|
good_call_rv = bpf_sock_ops_cb_flags_set(skops,
|
|
BPF_SOCK_OPS_STATE_CB_FLAG);
|
|
/* Update results */
|
|
{
|
|
__u32 key = 0;
|
|
struct tcpbpf_globals g, *gp;
|
|
|
|
gp = bpf_map_lookup_elem(&global_map, &key);
|
|
if (!gp)
|
|
break;
|
|
g = *gp;
|
|
g.bad_cb_test_rv = bad_call_rv;
|
|
g.good_cb_test_rv = good_call_rv;
|
|
bpf_map_update_elem(&global_map, &key, &g,
|
|
BPF_ANY);
|
|
}
|
|
break;
|
|
case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
|
|
skops->sk_txhash = 0x12345f;
|
|
v = 0xff;
|
|
rv = bpf_setsockopt(skops, SOL_IPV6, IPV6_TCLASS, &v,
|
|
sizeof(v));
|
|
break;
|
|
case BPF_SOCK_OPS_RTO_CB:
|
|
break;
|
|
case BPF_SOCK_OPS_RETRANS_CB:
|
|
break;
|
|
case BPF_SOCK_OPS_STATE_CB:
|
|
if (skops->args[1] == BPF_TCP_CLOSE) {
|
|
__u32 key = 0;
|
|
struct tcpbpf_globals g, *gp;
|
|
|
|
gp = bpf_map_lookup_elem(&global_map, &key);
|
|
if (!gp)
|
|
break;
|
|
g = *gp;
|
|
g.total_retrans = skops->total_retrans;
|
|
g.data_segs_in = skops->data_segs_in;
|
|
g.data_segs_out = skops->data_segs_out;
|
|
g.bytes_received = skops->bytes_received;
|
|
g.bytes_acked = skops->bytes_acked;
|
|
bpf_map_update_elem(&global_map, &key, &g,
|
|
BPF_ANY);
|
|
}
|
|
break;
|
|
default:
|
|
rv = -1;
|
|
}
|
|
skops->reply = rv;
|
|
return 1;
|
|
}
|
|
char _license[] SEC("license") = "GPL";
|