mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-25 16:40:52 +07:00
7cf245a37e
Fix all files in samples/bpf to include libbpf header files with the bpf/
prefix, to be consistent with external users of the library. Also ensure
that all includes of exported libbpf header files (those that are exported
on 'make install' of the library) use bracketed includes instead of quoted.
To make sure no new files are introduced that doesn't include the bpf/
prefix in its include, remove tools/lib/bpf from the include path entirely,
and use tools/lib instead.
Fixes: 6910d7d386
("selftests/bpf: Ensure bpf_helper_defs.h are taken from selftests dir")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/157952560911.1683545.8795966751309534150.stgit@toke.dk
123 lines
2.5 KiB
C
123 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
|
|
|
|
/**
|
|
* ibumad BPF sample user side
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
* License as published by the Free Software Foundation.
|
|
*
|
|
* Copyright(c) 2018 Ira Weiny, Intel Corporation
|
|
*/
|
|
|
|
#include <linux/bpf.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <limits.h>
|
|
|
|
#include <sys/resource.h>
|
|
#include <getopt.h>
|
|
#include <net/if.h>
|
|
|
|
#include "bpf_load.h"
|
|
#include "bpf_util.h"
|
|
#include <bpf/libbpf.h>
|
|
|
|
static void dump_counts(int fd)
|
|
{
|
|
__u32 key;
|
|
__u64 value;
|
|
|
|
for (key = 0; key < 256; key++) {
|
|
if (bpf_map_lookup_elem(fd, &key, &value)) {
|
|
printf("failed to read key %u\n", key);
|
|
continue;
|
|
}
|
|
if (value)
|
|
printf("0x%02x : %llu\n", key, value);
|
|
}
|
|
}
|
|
|
|
static void dump_all_counts(void)
|
|
{
|
|
printf("Read 'Class : count'\n");
|
|
dump_counts(map_fd[0]);
|
|
printf("Write 'Class : count'\n");
|
|
dump_counts(map_fd[1]);
|
|
}
|
|
|
|
static void dump_exit(int sig)
|
|
{
|
|
dump_all_counts();
|
|
exit(0);
|
|
}
|
|
|
|
static const struct option long_options[] = {
|
|
{"help", no_argument, NULL, 'h'},
|
|
{"delay", required_argument, NULL, 'd'},
|
|
};
|
|
|
|
static void usage(char *cmd)
|
|
{
|
|
printf("eBPF test program to count packets from various IP addresses\n"
|
|
"Usage: %s <options>\n"
|
|
" --help, -h this menu\n"
|
|
" --delay, -d <delay> wait <delay> sec between prints [1 - 1000000]\n"
|
|
, cmd
|
|
);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
unsigned long delay = 5;
|
|
int longindex = 0;
|
|
int opt;
|
|
char bpf_file[256];
|
|
|
|
/* Create the eBPF kernel code path name.
|
|
* This follows the pattern of all of the other bpf samples
|
|
*/
|
|
snprintf(bpf_file, sizeof(bpf_file), "%s_kern.o", argv[0]);
|
|
|
|
/* Do one final dump when exiting */
|
|
signal(SIGINT, dump_exit);
|
|
signal(SIGTERM, dump_exit);
|
|
|
|
while ((opt = getopt_long(argc, argv, "hd:rSw",
|
|
long_options, &longindex)) != -1) {
|
|
switch (opt) {
|
|
case 'd':
|
|
delay = strtoul(optarg, NULL, 0);
|
|
if (delay == ULONG_MAX || delay < 0 ||
|
|
delay > 1000000) {
|
|
fprintf(stderr, "ERROR: invalid delay : %s\n",
|
|
optarg);
|
|
usage(argv[0]);
|
|
return 1;
|
|
}
|
|
break;
|
|
default:
|
|
case 'h':
|
|
usage(argv[0]);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if (load_bpf_file(bpf_file)) {
|
|
fprintf(stderr, "ERROR: failed to load eBPF from file : %s\n",
|
|
bpf_file);
|
|
return 1;
|
|
}
|
|
|
|
while (1) {
|
|
sleep(delay);
|
|
dump_all_counts();
|
|
}
|
|
|
|
return 0;
|
|
}
|