Skip to content

Commit c075c9c

Browse files
Martin KaFai LauAlexei Starovoitov
authored andcommitted
selftests/bpf: Remove the bpf_tcp_helpers.h usages from other non tcp-cc tests
The patch removes the remaining bpf_tcp_helpers.h usages in the non tcp-cc networking tests. It either replaces it with bpf_tracing_net.h or just removed it because the test is not actually using any kernel sockets. For the later, the missing macro (mainly SOL_TCP) is defined locally. An exception is the test_sock_fields which is testing the "struct bpf_sock" type instead of the kernel sock type. Whenever "vmlinux.h" is used instead, it hits a verifier error on doing arithmetic on the sock_common pointer: ; return !a6[0] && !a6[1] && !a6[2] && a6[3] == bpf_htonl(1); @ test_sock_fields.c:54 21: (61) r2 = *(u32 *)(r1 +28) ; R1_w=sock_common() R2_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) 22: (56) if w2 != 0x0 goto pc-6 ; R2_w=0 23: (b7) r3 = 28 ; R3_w=28 24: (bf) r2 = r1 ; R1_w=sock_common() R2_w=sock_common() 25: (0f) r2 += r3 R2 pointer arithmetic on sock_common prohibited Hence, instead of including bpf_tracing_net.h, the test_sock_fields test defines a tcp_sock with one lsndtime field in it. Another highlight is, in sockopt_qos_to_cc.c, the tcp_cc_eq() is replaced by bpf_strncmp(). tcp_cc_eq() was a workaround in bpf_tcp_helpers.h before bpf_strncmp had been added. The SOL_IPV6 addition to bpf_tracing_net.h is needed by the test_tcpbpf_kern test. Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://lore.kernel.org/r/20240509175026.3423614-10-martin.lau@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 6eee55a commit c075c9c

7 files changed

Lines changed: 23 additions & 38 deletions

File tree

tools/testing/selftests/bpf/progs/bpf_tracing_net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#define IP_TOS 1
2727

28+
#define SOL_IPV6 41
2829
#define IPV6_TCLASS 67
2930
#define IPV6_AUTOFLOWLABEL 70
3031

tools/testing/selftests/bpf/progs/connect4_prog.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <bpf/bpf_helpers.h>
1515
#include <bpf/bpf_endian.h>
1616

17-
#include "bpf_tcp_helpers.h"
18-
1917
#define SRC_REWRITE_IP4 0x7f000004U
2018
#define DST_REWRITE_IP4 0x7f000001U
2119
#define DST_REWRITE_PORT4 4444
@@ -32,6 +30,10 @@
3230
#define IFNAMSIZ 16
3331
#endif
3432

33+
#ifndef SOL_TCP
34+
#define SOL_TCP 6
35+
#endif
36+
3537
__attribute__ ((noinline)) __weak
3638
int do_bind(struct bpf_sock_addr *ctx)
3739
{

tools/testing/selftests/bpf/progs/mptcp_sock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/* Copyright (c) 2020, Tessares SA. */
33
/* Copyright (c) 2022, SUSE. */
44

5-
#include <linux/bpf.h>
5+
#include "bpf_tracing_net.h"
66
#include <bpf/bpf_helpers.h>
7-
#include "bpf_tcp_helpers.h"
7+
#include <bpf/bpf_tracing.h>
88

99
char _license[] SEC("license") = "GPL";
1010
__u32 token = 0;

tools/testing/selftests/bpf/progs/sockopt_qos_to_cc.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2021 Facebook */
3-
#include <string.h>
4-
#include <linux/tcp.h>
5-
#include <netinet/in.h>
6-
#include <linux/bpf.h>
7-
#include <bpf/bpf_helpers.h>
8-
#include "bpf_tcp_helpers.h"
3+
#include "bpf_tracing_net.h"
94

105
char _license[] SEC("license") = "GPL";
116

127
__s32 page_size = 0;
138

9+
const char cc_reno[TCP_CA_NAME_MAX] = "reno";
10+
const char cc_cubic[TCP_CA_NAME_MAX] = "cubic";
11+
1412
SEC("cgroup/setsockopt")
1513
int sockopt_qos_to_cc(struct bpf_sockopt *ctx)
1614
{
1715
void *optval_end = ctx->optval_end;
1816
int *optval = ctx->optval;
1917
char buf[TCP_CA_NAME_MAX];
20-
char cc_reno[TCP_CA_NAME_MAX] = "reno";
21-
char cc_cubic[TCP_CA_NAME_MAX] = "cubic";
2218

2319
if (ctx->level != SOL_IPV6 || ctx->optname != IPV6_TCLASS)
2420
goto out;
@@ -29,11 +25,11 @@ int sockopt_qos_to_cc(struct bpf_sockopt *ctx)
2925
if (bpf_getsockopt(ctx->sk, SOL_TCP, TCP_CONGESTION, &buf, sizeof(buf)))
3026
return 0;
3127

32-
if (!tcp_cc_eq(buf, cc_cubic))
28+
if (bpf_strncmp(buf, sizeof(buf), cc_cubic))
3329
return 0;
3430

3531
if (*optval == 0x2d) {
36-
if (bpf_setsockopt(ctx->sk, SOL_TCP, TCP_CONGESTION, &cc_reno,
32+
if (bpf_setsockopt(ctx->sk, SOL_TCP, TCP_CONGESTION, (void *)&cc_reno,
3733
sizeof(cc_reno)))
3834
return 0;
3935
}

tools/testing/selftests/bpf/progs/test_btf_skc_cls_ingress.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2020 Facebook */
33

4-
#include <string.h>
5-
#include <errno.h>
6-
#include <netinet/in.h>
7-
#include <linux/stddef.h>
8-
#include <linux/bpf.h>
9-
#include <linux/ipv6.h>
10-
#include <linux/tcp.h>
11-
#include <linux/if_ether.h>
12-
#include <linux/pkt_cls.h>
13-
4+
#include "bpf_tracing_net.h"
145
#include <bpf/bpf_helpers.h>
156
#include <bpf/bpf_endian.h>
16-
#include "bpf_tcp_helpers.h"
7+
8+
#ifndef ENOENT
9+
#define ENOENT 2
10+
#endif
1711

1812
struct sockaddr_in6 srv_sa6 = {};
1913
__u16 listen_tp_sport = 0;

tools/testing/selftests/bpf/progs/test_sock_fields.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <bpf/bpf_helpers.h>
99
#include <bpf/bpf_endian.h>
10-
#include "bpf_tcp_helpers.h"
1110

1211
enum bpf_linum_array_idx {
1312
EGRESS_LINUM_IDX,
@@ -42,6 +41,10 @@ struct {
4241
__type(value, struct bpf_spinlock_cnt);
4342
} sk_pkt_out_cnt10 SEC(".maps");
4443

44+
struct tcp_sock {
45+
__u32 lsndtime;
46+
} __attribute__((preserve_access_index));
47+
4548
struct bpf_tcp_sock listen_tp = {};
4649
struct sockaddr_in6 srv_sa6 = {};
4750
struct bpf_tcp_sock cli_tp = {};

tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
#include <stddef.h>
3-
#include <string.h>
4-
#include <netinet/in.h>
5-
#include <linux/bpf.h>
6-
#include <linux/if_ether.h>
7-
#include <linux/if_packet.h>
8-
#include <linux/ip.h>
9-
#include <linux/ipv6.h>
10-
#include <linux/types.h>
11-
#include <linux/socket.h>
12-
#include <linux/tcp.h>
2+
#include "bpf_tracing_net.h"
133
#include <bpf/bpf_helpers.h>
144
#include <bpf/bpf_endian.h>
15-
#include "bpf_tcp_helpers.h"
165
#include "test_tcpbpf.h"
176

187
struct tcpbpf_globals global = {};

0 commit comments

Comments
 (0)