Skip to content

Commit e27afb8

Browse files
4astdavem330
authored andcommitted
selftests/bpf: fix broken build of test_maps
fix multiple build errors and warnings 1. test_maps.c: In function ‘test_map_rdonly’: test_maps.c:1051:30: error: ‘BPF_F_RDONLY’ undeclared (first use in this function) MAP_SIZE, map_flags | BPF_F_RDONLY); 2. test_maps.c:1048:6: warning: unused variable ‘i’ [-Wunused-variable] int i, fd, key = 0, value = 0; 3. test_maps.c:1087:2: error: called object is not a function or function pointer assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == EPERM); 4. ./bpf_helpers.h:72:11: error: use of undeclared identifier 'BPF_FUNC_getsockopt' (void *) BPF_FUNC_getsockopt; Fixes: e043325 ("bpf: Add tests for eBPF file mode") Fixes: 6e71b04 ("bpf: Add file mode configuration into bpf maps") Fixes: cd86d1f ("bpf: Adding helper function bpf_getsockops") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f8ddadc commit e27afb8

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

tools/include/uapi/linux/bpf.h

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ enum bpf_attach_type {
218218

219219
#define BPF_OBJ_NAME_LEN 16U
220220

221+
/* Flags for accessing BPF object */
222+
#define BPF_F_RDONLY (1U << 3)
223+
#define BPF_F_WRONLY (1U << 4)
224+
221225
union bpf_attr {
222226
struct { /* anonymous struct used by BPF_MAP_CREATE command */
223227
__u32 map_type; /* one of enum bpf_map_type */
@@ -260,6 +264,7 @@ union bpf_attr {
260264
struct { /* anonymous struct used by BPF_OBJ_* commands */
261265
__aligned_u64 pathname;
262266
__u32 bpf_fd;
267+
__u32 file_flags;
263268
};
264269

265270
struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
@@ -287,6 +292,7 @@ union bpf_attr {
287292
__u32 map_id;
288293
};
289294
__u32 next_id;
295+
__u32 open_flags;
290296
};
291297

292298
struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
@@ -607,12 +613,22 @@ union bpf_attr {
607613
* int bpf_setsockopt(bpf_socket, level, optname, optval, optlen)
608614
* Calls setsockopt. Not all opts are available, only those with
609615
* integer optvals plus TCP_CONGESTION.
610-
* Supported levels: SOL_SOCKET and IPROTO_TCP
616+
* Supported levels: SOL_SOCKET and IPPROTO_TCP
611617
* @bpf_socket: pointer to bpf_socket
612-
* @level: SOL_SOCKET or IPROTO_TCP
618+
* @level: SOL_SOCKET or IPPROTO_TCP
613619
* @optname: option name
614620
* @optval: pointer to option value
615-
* @optlen: length of optval in byes
621+
* @optlen: length of optval in bytes
622+
* Return: 0 or negative error
623+
*
624+
* int bpf_getsockopt(bpf_socket, level, optname, optval, optlen)
625+
* Calls getsockopt. Not all opts are available.
626+
* Supported levels: IPPROTO_TCP
627+
* @bpf_socket: pointer to bpf_socket
628+
* @level: IPPROTO_TCP
629+
* @optname: option name
630+
* @optval: pointer to option value
631+
* @optlen: length of optval in bytes
616632
* Return: 0 or negative error
617633
*
618634
* int bpf_skb_adjust_room(skb, len_diff, mode, flags)
@@ -623,10 +639,9 @@ union bpf_attr {
623639
* @flags: reserved for future use
624640
* Return: 0 on success or negative error code
625641
*
626-
* int bpf_sk_redirect_map(skb, map, key, flags)
642+
* int bpf_sk_redirect_map(map, key, flags)
627643
* Redirect skb to a sock in map using key as a lookup key for the
628644
* sock in map.
629-
* @skb: pointer to skb
630645
* @map: pointer to sockmap
631646
* @key: key to lookup sock in map
632647
* @flags: reserved for future use
@@ -643,6 +658,21 @@ union bpf_attr {
643658
* @xdp_md: pointer to xdp_md
644659
* @delta: An positive/negative integer to be added to xdp_md.data_meta
645660
* Return: 0 on success or negative on error
661+
*
662+
* int bpf_perf_event_read_value(map, flags, buf, buf_size)
663+
* read perf event counter value and perf event enabled/running time
664+
* @map: pointer to perf_event_array map
665+
* @flags: index of event in the map or bitmask flags
666+
* @buf: buf to fill
667+
* @buf_size: size of the buf
668+
* Return: 0 on success or negative error code
669+
*
670+
* int bpf_perf_prog_read_value(ctx, buf, buf_size)
671+
* read perf prog attached perf event counter and enabled/running time
672+
* @ctx: pointer to ctx
673+
* @buf: buf to fill
674+
* @buf_size: size of the buf
675+
* Return : 0 on success or negative error code
646676
*/
647677
#define __BPF_FUNC_MAPPER(FN) \
648678
FN(unspec), \
@@ -701,7 +731,8 @@ union bpf_attr {
701731
FN(sock_map_update), \
702732
FN(xdp_adjust_meta), \
703733
FN(perf_event_read_value), \
704-
FN(perf_prog_read_value),
734+
FN(perf_prog_read_value), \
735+
FN(getsockopt),
705736

706737
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
707738
* function eBPF program intends to call
@@ -745,7 +776,9 @@ enum bpf_func_id {
745776
#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
746777
#define BPF_F_DONT_FRAGMENT (1ULL << 2)
747778

748-
/* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */
779+
/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
780+
* BPF_FUNC_perf_event_read_value flags.
781+
*/
749782
#define BPF_F_INDEX_MASK 0xffffffffULL
750783
#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
751784
/* BPF_FUNC_perf_event_output for sk_buff input context. */
@@ -873,7 +906,7 @@ struct bpf_prog_info {
873906
__u32 created_by_uid;
874907
__u32 nr_map_ids;
875908
__aligned_u64 map_ids;
876-
char name[BPF_OBJ_NAME_LEN];
909+
char name[BPF_OBJ_NAME_LEN];
877910
} __attribute__((aligned(8)));
878911

879912
struct bpf_map_info {
@@ -933,9 +966,22 @@ enum {
933966
BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control
934967
* needs ECN
935968
*/
969+
BPF_SOCK_OPS_BASE_RTT, /* Get base RTT. The correct value is
970+
* based on the path and may be
971+
* dependent on the congestion control
972+
* algorithm. In general it indicates
973+
* a congestion threshold. RTTs above
974+
* this indicate congestion
975+
*/
936976
};
937977

938978
#define TCP_BPF_IW 1001 /* Set TCP initial congestion window */
939979
#define TCP_BPF_SNDCWND_CLAMP 1002 /* Set sndcwnd_clamp */
940980

981+
struct bpf_perf_event_value {
982+
__u64 counter;
983+
__u64 enabled;
984+
__u64 running;
985+
};
986+
941987
#endif /* _UAPI__LINUX_BPF_H__ */

tools/testing/selftests/bpf/test_maps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ static void test_map_parallel(void)
10451045

10461046
static void test_map_rdonly(void)
10471047
{
1048-
int i, fd, key = 0, value = 0;
1048+
int fd, key = 0, value = 0;
10491049

10501050
fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value),
10511051
MAP_SIZE, map_flags | BPF_F_RDONLY);
@@ -1068,7 +1068,7 @@ static void test_map_rdonly(void)
10681068

10691069
static void test_map_wronly(void)
10701070
{
1071-
int i, fd, key = 0, value = 0;
1071+
int fd, key = 0, value = 0;
10721072

10731073
fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value),
10741074
MAP_SIZE, map_flags | BPF_F_WRONLY);
@@ -1081,7 +1081,7 @@ static void test_map_wronly(void)
10811081
key = 1;
10821082
value = 1234;
10831083
/* Insert key=1 element. */
1084-
assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0)
1084+
assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
10851085

10861086
/* Check that key=2 is not found. */
10871087
assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == EPERM);

0 commit comments

Comments
 (0)