Skip to content

Commit 8529e2c

Browse files
geliangtangKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests: bpf: verify ca_name of struct mptcp_sock
This patch verifies another member of struct mptcp_sock, ca_name. Add a new function get_msk_ca_name() to read the sysctl tcp_congestion_control and verify it in verify_msk(). Acked-by: Matthieu Baerts <[email protected]> Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Mat Martineau <[email protected]>
1 parent a81904d commit 8529e2c

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

tools/testing/selftests/bpf/bpf_mptcp_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct mptcp_sock {
1010
struct inet_connection_sock sk;
1111

1212
__u32 token;
13+
char ca_name[TCP_CA_NAME_MAX];
1314
} __attribute__((preserve_access_index));
1415

1516
#endif

tools/testing/selftests/bpf/bpf_tcp_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ BPF_PROG(name, args)
1616
#define SOL_TCP 6
1717
#endif
1818

19+
#ifndef TCP_CA_NAME_MAX
20+
#define TCP_CA_NAME_MAX 16
21+
#endif
22+
1923
#define tcp_jiffies32 ((__u32)bpf_jiffies64())
2024

2125
struct sock_common {

tools/testing/selftests/bpf/prog_tests/mptcp.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
#include "cgroup_helpers.h"
66
#include "network_helpers.h"
77

8+
#ifndef TCP_CA_NAME_MAX
9+
#define TCP_CA_NAME_MAX 16
10+
#endif
11+
812
struct mptcp_storage {
913
__u32 invoked;
1014
__u32 is_mptcp;
1115
__u32 token;
16+
char ca_name[TCP_CA_NAME_MAX];
1217
};
1318

1419
static char monitor_log_path[64];
@@ -79,11 +84,22 @@ static __u32 get_msk_token(void)
7984
return token;
8085
}
8186

87+
void get_msk_ca_name(char ca_name[])
88+
{
89+
FILE *stream = popen("sysctl -b net.ipv4.tcp_congestion_control", "r");
90+
91+
if (!fgets(ca_name, TCP_CA_NAME_MAX, stream))
92+
log_err("Failed to read ca_name");
93+
94+
pclose(stream);
95+
}
96+
8297
static int verify_msk(int map_fd, int client_fd)
8398
{
8499
char *msg = "MPTCP subflow socket";
85100
int err = 0, cfd = client_fd;
86101
struct mptcp_storage val;
102+
char ca_name[TCP_CA_NAME_MAX];
87103
__u32 token;
88104

89105
token = get_msk_token();
@@ -92,6 +108,8 @@ static int verify_msk(int map_fd, int client_fd)
92108
return -1;
93109
}
94110

111+
get_msk_ca_name(ca_name);
112+
95113
if (CHECK_FAIL(bpf_map_lookup_elem(map_fd, &cfd, &val) < 0)) {
96114
perror("Failed to read socket storage");
97115
return -1;
@@ -115,6 +133,12 @@ static int verify_msk(int map_fd, int client_fd)
115133
err++;
116134
}
117135

136+
if (strncmp(val.ca_name, ca_name, TCP_CA_NAME_MAX)) {
137+
log_err("Unexpected mptcp_sock.ca_name %s != %s",
138+
val.ca_name, ca_name);
139+
err++;
140+
}
141+
118142
return err;
119143
}
120144

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2020, Tessares SA. */
33

4+
#include <string.h>
45
#include <linux/bpf.h>
56
#include <bpf/bpf_helpers.h>
67
#include "bpf_mptcp_helpers.h"
@@ -12,6 +13,7 @@ struct mptcp_storage {
1213
__u32 invoked;
1314
__u32 is_mptcp;
1415
__u32 token;
16+
char ca_name[TCP_CA_NAME_MAX];
1517
};
1618

1719
struct {
@@ -48,6 +50,7 @@ int _sockops(struct bpf_sock_ops *ctx)
4850
return 1;
4951

5052
storage->token = 0;
53+
bzero(storage->ca_name, TCP_CA_NAME_MAX);
5154
} else {
5255
msk = bpf_skc_to_mptcp_sock(sk);
5356
if (!msk)
@@ -59,6 +62,7 @@ int _sockops(struct bpf_sock_ops *ctx)
5962
return 1;
6063

6164
storage->token = msk->token;
65+
memcpy(storage->ca_name, msk->ca_name, TCP_CA_NAME_MAX);
6266
}
6367
storage->invoked++;
6468
storage->is_mptcp = tcp_sk->is_mptcp;

0 commit comments

Comments
 (0)