strace/tests/kernel_version.c
Eugene Syromyatnikov e850f7f95c xlat: add flow dissector bpf program type constants
* xlat/bpf_attach_type.in (BPF_FLOW_DISSECTOR): New constant
introduced by Linux commit v4.20-rc1~14^2~259^2~9^2~4.
* xlat/bpf_prog_types.in (BPF_PROG_TYPE_FLOW_DISSECTOR): Likewise.
* NEWS: Mention this.
* tests/bpf.c (BPF_PROG_LOAD_checks, BPF_PROG_QUERY_checks): Update.
* tests/kernel_version.c (print_bpf_attr): Update.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-12-26 01:59:38 +00:00

99 lines
1.8 KiB
C

/*
* Check kernel version decoding.
*
* Copyright (c) 2015-2018 The strace developers.
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <asm/unistd.h>
#include "scno.h"
#ifdef HAVE_LINUX_BPF_H
# include <linux/bpf.h>
#endif
#include "bpf_attr.h"
#include "print_fields.h"
#include "xlat.h"
#include "xlat/bpf_commands.h"
#define CMD_STR(x) #x
static const char *errstr;
static void
print_bpf_attr(void)
{
#if XLAT_RAW
printf("{prog_type=0x16"
#else
printf("{prog_type=0x16 /* BPF_PROG_TYPE_??? */"
#endif
", insn_cnt=3134983661"
", insns=NULL"
", license=NULL"
", log_level=24"
", log_size=3141592653"
", log_buf=NULL"
#if XLAT_RAW
", kern_version=0xcafef00d"
#elif XLAT_VERBOSE
", kern_version=0xcafef00d"
" /* KERNEL_VERSION(51966, 240, 13) */"
#else
", kern_version=KERNEL_VERSION(51966, 240, 13)"
#endif
", prog_flags=0"
", prog_name=\"\""
", prog_ifindex=0"
", expected_attach_type="
#if XLAT_RAW
"0}"
#elif XLAT_VERBOSE
"0 /* BPF_CGROUP_INET_INGRESS */}"
#else /* XLAT_ABBREV */
"BPF_CGROUP_INET_INGRESS}"
#endif
);
}
int
main(void)
{
long ret;
struct BPF_PROG_LOAD_struct prog = {
.prog_type = 22,
.insn_cnt = 0xbadc0ded,
.insns = 0,
.license = 0,
.log_level = 24,
.log_size = 3141592653U,
.log_buf = 0,
.kern_version = 0xcafef00d,
.prog_flags = 0,
};
ret = syscall(__NR_bpf, BPF_PROG_LOAD, &prog, sizeof(prog));
errstr = sprintrc(ret);
#if XLAT_RAW
printf("bpf(%#x, ", BPF_PROG_LOAD);
#elif XLAT_VERBOSE
printf("bpf(%#x /* %s */, ", BPF_PROG_LOAD, CMD_STR(BPF_PROG_LOAD));
#else
printf("bpf(%s, ", CMD_STR(BPF_PROG_LOAD));
#endif
print_bpf_attr();
printf(", %u) = %s\n", (unsigned int) sizeof(prog), errstr);
puts("+++ exited with 0 +++");
return 0;
}