2018-04-02 16:12:57 +03:00
/*
* Copyright ( c ) 2015 - 2018 Dmitry V . Levin < ldv @ altlinux . org >
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : LGPL - 2.1 - or - later
2018-04-02 16:12:57 +03:00
*/
# ifndef STRACE_BPF_ATTR_H
2018-12-30 18:35:21 +03:00
# define STRACE_BPF_ATTR_H
2018-04-02 16:12:57 +03:00
2018-06-01 22:43:35 +03:00
/*
* The policy is that all fields of type uint64_t in this header file
* must have ATTRIBUTE_ALIGNED ( 8 ) .
*
* This should not cause any contradictions with < linux / bpf . h >
* unless the latter is buggy .
*
* By word " buggy " I mean containing such changes as Linux kernel commit
* v4 .16 - rc1 ~ 123 ^ 2 ~ 109 ^ 2 ~ 5 ^ 2 ~ 4.
*/
2018-12-30 18:35:21 +03:00
# ifndef BPF_OBJ_NAME_LEN
# define BPF_OBJ_NAME_LEN 16U
# else
# if BPF_OBJ_NAME_LEN != 16U
# error "Unexpected value of BPF_OBJ_NAME_LEN"
# endif
2018-02-22 05:22:48 +03:00
# endif
2018-12-30 18:35:21 +03:00
# ifndef BPF_TAG_SIZE
# define BPF_TAG_SIZE 8
# else
# if BPF_TAG_SIZE != 8
# error "Unexpected value of BPF_TAG_SIZE"
# endif
2018-03-05 17:56:35 +03:00
# endif
2018-04-02 16:12:57 +03:00
struct BPF_MAP_CREATE_struct {
uint32_t map_type ;
uint32_t key_size ;
uint32_t value_size ;
uint32_t max_entries ;
uint32_t map_flags ;
uint32_t inner_map_fd ;
uint32_t numa_node ;
2018-03-05 17:53:48 +03:00
char map_name [ BPF_OBJ_NAME_LEN ] ;
uint32_t map_ifindex ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_MAP_CREATE_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_MAP_CREATE_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_MAP_CREATE_struct_size 48
2018-04-02 16:12:57 +03:00
struct BPF_MAP_LOOKUP_ELEM_struct {
uint32_t map_fd ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) key ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) value ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_MAP_LOOKUP_ELEM_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_MAP_LOOKUP_ELEM_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
2018-04-02 16:12:57 +03:00
struct BPF_MAP_UPDATE_ELEM_struct {
uint32_t map_fd ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) key ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) value ;
2018-06-01 22:43:35 +03:00
uint64_t ATTRIBUTE_ALIGNED ( 8 ) flags ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_MAP_UPDATE_ELEM_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_MAP_UPDATE_ELEM_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
2018-04-02 16:12:57 +03:00
struct BPF_MAP_DELETE_ELEM_struct {
uint32_t map_fd ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) key ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_MAP_DELETE_ELEM_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_MAP_DELETE_ELEM_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_MAP_DELETE_ELEM_struct_size 16
2018-04-02 16:12:57 +03:00
struct BPF_MAP_GET_NEXT_KEY_struct {
uint32_t map_fd ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) key ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) next_key ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_MAP_GET_NEXT_KEY_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_MAP_GET_NEXT_KEY_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
2018-04-02 16:12:57 +03:00
struct BPF_PROG_LOAD_struct {
uint32_t prog_type ;
uint32_t insn_cnt ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) insns ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) license ;
uint32_t log_level ;
uint32_t log_size ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) log_buf ;
uint32_t kern_version ;
uint32_t prog_flags ;
2018-02-22 05:22:48 +03:00
char prog_name [ BPF_OBJ_NAME_LEN ] ;
uint32_t prog_ifindex ;
2018-05-15 15:19:01 +03:00
uint32_t expected_attach_type ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_LOAD_struct_size \
2018-05-15 15:19:01 +03:00
offsetofend ( struct BPF_PROG_LOAD_struct , expected_attach_type )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_LOAD_struct_size 72
2018-04-02 16:12:57 +03:00
struct BPF_OBJ_PIN_struct {
uint64_t ATTRIBUTE_ALIGNED ( 8 ) pathname ;
uint32_t bpf_fd ;
bpf: add support for file mode flags
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-26 21:40:08 +03:00
uint32_t file_flags ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_OBJ_PIN_struct_size \
bpf: add support for file mode flags
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-26 21:40:08 +03:00
sizeof ( struct BPF_OBJ_PIN_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_OBJ_PIN_struct_size 16
2018-04-02 16:12:57 +03:00
2018-12-30 18:35:21 +03:00
# define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
# define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
2018-04-02 16:12:57 +03:00
struct BPF_PROG_ATTACH_struct {
uint32_t target_fd ;
uint32_t attach_bpf_fd ;
uint32_t attach_type ;
uint32_t attach_flags ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_ATTACH_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_PROG_ATTACH_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_ATTACH_struct_size 16
2018-04-02 16:12:57 +03:00
struct BPF_PROG_DETACH_struct {
uint32_t target_fd ;
uint32_t dummy ;
uint32_t attach_type ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_DETACH_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_PROG_DETACH_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_DETACH_struct_size 12
2018-04-02 16:12:57 +03:00
struct BPF_PROG_TEST_RUN_struct /* test */ {
uint32_t prog_fd ;
uint32_t retval ;
uint32_t data_size_in ;
uint32_t data_size_out ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) data_in ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) data_out ;
uint32_t repeat ;
uint32_t duration ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_TEST_RUN_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_PROG_TEST_RUN_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_TEST_RUN_struct_size 40
2018-04-02 16:12:57 +03:00
struct BPF_PROG_GET_NEXT_ID_struct {
uint32_t start_id ;
uint32_t next_id ;
bpf: add support for file mode flags
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-26 21:40:08 +03:00
uint32_t open_flags ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_GET_NEXT_ID_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_PROG_GET_NEXT_ID_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
2018-04-02 16:12:57 +03:00
2018-12-30 18:35:21 +03:00
# define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
# define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
2018-04-02 16:12:57 +03:00
struct BPF_PROG_GET_FD_BY_ID_struct {
uint32_t prog_id ;
uint32_t next_id ;
bpf: add support for file mode flags
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-26 21:40:08 +03:00
uint32_t open_flags ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_GET_FD_BY_ID_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_PROG_GET_FD_BY_ID_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
2018-04-02 16:12:57 +03:00
struct BPF_MAP_GET_FD_BY_ID_struct {
uint32_t map_id ;
uint32_t next_id ;
bpf: add support for file mode flags
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-02-26 21:40:08 +03:00
uint32_t open_flags ;
2018-04-02 16:12:57 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define BPF_MAP_GET_FD_BY_ID_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_MAP_GET_FD_BY_ID_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
2018-04-02 16:12:57 +03:00
struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
uint32_t bpf_fd ;
uint32_t info_len ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) info ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_OBJ_GET_INFO_BY_FD_struct_size \
2018-04-02 16:12:57 +03:00
sizeof ( struct BPF_OBJ_GET_INFO_BY_FD_struct )
2018-12-30 18:35:21 +03:00
# define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
2018-04-02 16:12:57 +03:00
2018-03-02 01:54:00 +03:00
struct BPF_PROG_QUERY_struct /* query */ {
uint32_t target_fd ;
uint32_t attach_type ;
uint32_t query_flags ;
uint32_t attach_flags ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) prog_ids ;
uint32_t prog_cnt ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_PROG_QUERY_struct_size \
2018-03-02 01:54:00 +03:00
offsetofend ( struct BPF_PROG_QUERY_struct , prog_cnt )
2018-12-30 18:35:21 +03:00
# define expected_BPF_PROG_QUERY_struct_size 28
2018-03-02 01:54:00 +03:00
2018-05-15 16:38:54 +03:00
struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
uint64_t ATTRIBUTE_ALIGNED ( 8 ) name ;
uint32_t prog_fd ;
} ;
2018-12-30 18:35:21 +03:00
# define BPF_RAW_TRACEPOINT_OPEN_struct_size \
2018-05-15 16:38:54 +03:00
offsetofend ( struct BPF_RAW_TRACEPOINT_OPEN_struct , prog_fd )
2018-12-30 18:35:21 +03:00
# define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
2018-05-15 16:38:54 +03:00
2018-03-05 17:56:35 +03:00
struct bpf_map_info_struct {
uint32_t type ;
uint32_t id ;
uint32_t key_size ;
uint32_t value_size ;
uint32_t max_entries ;
uint32_t map_flags ;
char name [ BPF_OBJ_NAME_LEN ] ;
uint32_t ifindex ;
2018-06-01 22:43:35 +03:00
/*
* The kernel UAPI is broken by Linux commit
* v4 .16 - rc1 ~ 123 ^ 2 ~ 109 ^ 2 ~ 5 ^ 2 ~ 4 .
*/
uint64_t ATTRIBUTE_ALIGNED ( 8 ) netns_dev ; /* skip check */
uint64_t ATTRIBUTE_ALIGNED ( 8 ) netns_ino ; /* skip check */
2018-03-05 17:56:35 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define bpf_map_info_struct_size \
2018-03-05 17:56:35 +03:00
sizeof ( struct bpf_map_info_struct )
2018-12-30 18:35:21 +03:00
# define expected_bpf_map_info_struct_size 64
2018-03-05 17:56:35 +03:00
struct bpf_prog_info_struct {
uint32_t type ;
uint32_t id ;
uint8_t tag [ BPF_TAG_SIZE ] ;
uint32_t jited_prog_len ;
uint32_t xlated_prog_len ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) jited_prog_insns ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) xlated_prog_insns ;
2018-06-01 22:43:35 +03:00
uint64_t ATTRIBUTE_ALIGNED ( 8 ) load_time ;
2018-03-05 17:56:35 +03:00
uint32_t created_by_uid ;
uint32_t nr_map_ids ;
uint64_t ATTRIBUTE_ALIGNED ( 8 ) map_ids ;
char name [ BPF_OBJ_NAME_LEN ] ;
uint32_t ifindex ;
2018-06-01 22:43:35 +03:00
/*
* The kernel UAPI is broken by Linux commit
* v4 .16 - rc1 ~ 123 ^ 2 ~ 227 ^ 2 ~ 5 ^ 2 ~ 2 .
*/
uint64_t ATTRIBUTE_ALIGNED ( 8 ) netns_dev ; /* skip check */
uint64_t ATTRIBUTE_ALIGNED ( 8 ) netns_ino ; /* skip check */
2018-03-05 17:56:35 +03:00
} ;
2018-12-30 18:35:21 +03:00
# define bpf_prog_info_struct_size \
2018-03-05 17:56:35 +03:00
sizeof ( struct bpf_prog_info_struct )
2018-12-30 18:35:21 +03:00
# define expected_bpf_prog_info_struct_size 104
2018-03-05 17:56:35 +03:00
2018-04-02 16:12:57 +03:00
# endif /* !STRACE_BPF_ATTR_H */