for bpf-next
Subsystems (10)
v2 cover for bpf-next
v2:
- The series is for bpf-next v5.
- patch 1, keep bpf_mptcp_sock_from_subflow() in bpf.c
- patch 3, Drop the 'msg' parameter of verify_sk
- base-commit: df896c77f02a ("DO-NOT-MERGE: git markup: features
net-next-next"), export/20220517T155019
- The last squash-to patch is for "BPF packet scheduler" series.
v1:
- The first 10 patches is for bpf-next v5.
- Rebased the "BPF packet scheduler" series on export branch.
Geliang Tang (6):
bpf: add bpf_skc_to_mptcp_sock_proto selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config selftests/bpf: test bpf_skc_to_mptcp_sock selftests/bpf: verify token of struct mptcp_sock selftests/bpf: verify ca_name of struct mptcp_sock selftests/bpf: verify first of struct mptcp_sock
Nicolas Rybowski (1):
selftests/bpf: add MPTCP test base
MAINTAINERS | 1 + include/linux/bpf.h | 1 + include/linux/btf_ids.h | 3 +- include/net/mptcp.h | 6 + include/uapi/linux/bpf.h | 7 + kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 + net/core/filter.c | 18 ++ net/mptcp/Makefile | 2 + net/mptcp/bpf.c | 21 +++ scripts/bpf_doc.py | 2 + tools/include/uapi/linux/bpf.h | 7 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 13 ++ tools/testing/selftests/bpf/config | 3 + tools/testing/selftests/bpf/network_helpers.c | 40 +++- tools/testing/selftests/bpf/network_helpers.h | 2 + .../testing/selftests/bpf/prog_tests/mptcp.c | 174 ++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 89 +++++++++ 18 files changed, 382 insertions(+), 10 deletions(-) create mode 100644 net/mptcp/bpf.c create mode 100644 tools/testing/selftests/bpf/prog_tests/mptcp.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_sock.c
Signature · 1 line
2.34.1
PATCH v2 1/7 bpf: add bpf_skc_to_mptcp_sock_proto
This patch implements a new struct bpf_func_proto, named bpf_skc_to_mptcp_sock_proto. Define a new bpf_id BTF_SOCK_TYPE_MPTCP, and a new helper bpf_skc_to_mptcp_sock(), which invokes another new helper bpf_mptcp_sock_from_subflow() in net/mptcp/bpf.c to get struct mptcp_sock from a given subflow socket.
v2: Emit BTF type, add func_id checks in verifier.c and bpf_trace.c, remove build check for CONFIG_BPF_JIT
v3: Drop EXPORT_SYMBOL (Martin)
--- include/linux/bpf.h | 1 + include/linux/btf_ids.h | 3 ++- include/net/mptcp.h | 6 ++++++ include/uapi/linux/bpf.h | 7 +++++++ kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 ++ net/core/filter.c | 18 ++++++++++++++++++ net/mptcp/Makefile | 2 ++ net/mptcp/bpf.c | 21 +++++++++++++++++++++ scripts/bpf_doc.py | 2 ++ tools/include/uapi/linux/bpf.h | 7 +++++++ 11 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/bpf.c
include/linux/bpf.h +1 -0
@@ -2204,6 +2204,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto;extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto;extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto;extern const struct bpf_func_proto bpf_skc_to_unix_sock_proto; +extern const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto;extern const struct bpf_func_proto bpf_copy_from_user_proto;extern const struct bpf_func_proto bpf_snprintf_btf_proto;extern const struct bpf_func_proto bpf_snprintf_proto;
include/linux/btf_ids.h +2 -1
@@ -178,7 +178,8 @@ extern struct btf_id_set name; BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ - BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) + BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ + BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) enum {#define BTF_SOCK_TYPE (name, str) name,
include/net/mptcp.h +6 -0
@@ -284,4 +284,10 @@ static inline int mptcpv6_init(void) { return 0; }static inline void mptcpv6_handle_mapped (struct sock *sk,bool mapped) { }#endif +#if defined(CONFIG_MPTCP ) && defined(CONFIG_BPF_SYSCALL ) +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk); +#else +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) {return NULL ; } +#endif +#endif /* __NET_MPTCP_H */
include/uapi/linux/bpf.h +7 -0
@@ -5154,6 +5154,12 @@ union bpf_attr {* if not NULL, is a reference which must be released using its * corresponding release function, or moved into a BPF map before * program exit. +* +* struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) +* Description +* Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. +* Return +* *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER (FN ) \ FN(unspec), \
@@ -5351,6 +5357,7 @@ union bpf_attr {FN (skb_set_tstamp), \FN (ima_file_hash), \FN (kptr_xchg), \ +FN (skc_to_mptcp_sock), \/* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper
kernel/bpf/verifier.c +1 -0
@@ -509,6 +509,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id) func_id == BPF_FUNC_skc_to_tcp_sock || func_id == BPF_FUNC_skc_to_tcp6_sock || func_id == BPF_FUNC_skc_to_udp6_sock || + func_id == BPF_FUNC_skc_to_mptcp_sock || func_id == BPF_FUNC_skc_to_tcp_timewait_sock || func_id == BPF_FUNC_skc_to_tcp_request_sock; }
kernel/trace/bpf_trace.c +2 -0
@@ -1688,6 +1688,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_skc_to_udp6_sock_proto;case BPF_FUNC_skc_to_unix_sock:return &bpf_skc_to_unix_sock_proto; +case BPF_FUNC_skc_to_mptcp_sock: +return &bpf_skc_to_mptcp_sock_proto;case BPF_FUNC_sk_storage_get:return &bpf_sk_storage_get_tracing_proto;case BPF_FUNC_sk_storage_delete:
net/core/filter.c +18 -0
@@ -78,6 +78,7 @@#include <linux/btf_ids.h> #include <net/tls.h> #include <net/xdp.h> +#include <net/mptcp.h> static const struct bpf_func_proto *bpf_sk_base_func_proto (enum bpf_func_id func_id);
@@ -11272,6 +11273,20 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = { .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_UNIX], }; +BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk) +{ +BTF_TYPE_EMIT (struct mptcp_sock ); +return (unsigned long )bpf_mptcp_sock_from_subflow (sk); +} + +const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = { + .func = bpf_skc_to_mptcp_sock, + .gpl_only = false, + .ret_type =RET_PTR_TO_BTF_ID_OR_NULL , + .arg1_type =ARG_PTR_TO_SOCK_COMMON , + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_MPTCP ], +}; + BPF_CALL_1(bpf_sock_from_file, struct file *, file) {return (unsigned long )sock_from_file (file);
@@ -11314,6 +11329,9 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id)case BPF_FUNC_skc_to_unix_sock: func = &bpf_skc_to_unix_sock_proto;break ; +case BPF_FUNC_skc_to_mptcp_sock: + func = &bpf_skc_to_mptcp_sock_proto; +break ;case BPF_FUNC_ktime_get_coarse_ns:return &bpf_ktime_get_coarse_ns_proto;default :
net/mptcp/Makefile +2 -0
@@ -10,3 +10,5 @@ obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o mptcp_crypto_test-objs := crypto_test.o mptcp_token_test-objs := token_test.o obj-$(CONFIG_MPTCP_KUNIT_TEST) += mptcp_crypto_test.o mptcp_token_test.o + +obj-$(CONFIG_BPF_SYSCALL) += bpf.o
net/mptcp/bpf.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Multipath TCP +* +* Copyright (c) 2020, Tessares SA. +* Copyright (c) 2022, SUSE. +* +* Author: Nicolas Rybowski <[email protected]> +*/ + +#define pr_fmt (fmt) "MPTCP: " fmt + +#include <linux/bpf.h> +#include "protocol.h" + +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) +{ +if (sk &&sk_fullsock (sk) && sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk)) +return mptcp_sk (mptcp_subflow_ctx (sk)->conn); + +return NULL ; +}
scripts/bpf_doc.py +2 -0
@@ -633,6 +633,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', ] known_types = { '...',
@@ -682,6 +683,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', } mapped_types = { 'u8': '__u8',
tools/include/uapi/linux/bpf.h +7 -0
@@ -5154,6 +5154,12 @@ union bpf_attr {* if not NULL, is a reference which must be released using its * corresponding release function, or moved into a BPF map before * program exit. +* +* struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) +* Description +* Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. +* Return +* *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER (FN ) \ FN(unspec), \
@@ -5351,6 +5357,7 @@ union bpf_attr {FN (skb_set_tstamp), \FN (ima_file_hash), \FN (kptr_xchg), \ +FN (skc_to_mptcp_sock), \/* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper
Signature · 1 line
2.34.1
PATCH v2 2/7 selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config
In reply to Geliang TangCONFIG_IKCONFIG_PROC is required by BPF selftests, otherwise we get errors like this:
libbpf: failed to open system Kconfig
libbpf: failed to load object 'kprobe_multi'
libbpf: failed to load BPF skeleton 'kprobe_multi': -22
It's because /proc/config.gz is opened in bpf_object__read_kconfig_file() in tools/lib/bpf/libbpf.c:
file = gzopen("/proc/config.gz", "r");So this patch enables CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC in tools/testing/selftests/bpf/config.
--- tools/testing/selftests/bpf/config | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/config +2 -0
@@ -53,3 +53,5 @@ CONFIG_NF_DEFRAG_IPV4=y CONFIG_NF_DEFRAG_IPV6=y CONFIG_NF_CONNTRACK=y CONFIG_USERFAULTFD=y +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y
Signature · 1 line
2.34.1
PATCH v2 3/7 selftests/bpf: add MPTCP test base
In reply to Geliang TangFrom: Nicolas Rybowski <[email protected]>
This patch adds a base for MPTCP specific tests.
It is currently limited to the is_mptcp field in case of plain TCP connection because there is no easy way to get the subflow sk from a msk in userspace. This implies that we cannot lookup the sk_storage attached to the subflow sk in the sockops program.
v4:
- add copyright 2022 (Andrii)
- use ASSERT_* instead of CHECK_FAIL (Andrii)
- drop SEC("version") (Andrii)
- use is_mptcp in tcp_sock, instead of bpf_tcp_sock (Martin & Andrii)
v5:
- Drop connect_to_mptcp_fd (Martin)
- Use BPF test skeleton (Andrii)
- Use ASSERT_EQ (Andrii)
- Drop the 'msg' parameter of verify_sk
--- MAINTAINERS | 1 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/config | 1 + tools/testing/selftests/bpf/network_helpers.c | 40 +++++-- tools/testing/selftests/bpf/network_helpers.h | 2 + .../testing/selftests/bpf/prog_tests/mptcp.c | 112 ++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 53 +++++++++ 7 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/mptcp.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_sock.c
MAINTAINERS +1 -0
@@ -13799,6 +13799,7 @@ F: include/net/mptcp.h F: include/trace/events/mptcp.h F: include/uapi/linux/mptcp.h F: net/mptcp/ +F: tools/testing/selftests/bpf/*/*mptcp*.c F: tools/testing/selftests/net/mptcp/ NETWORKING [TCP]
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -81,6 +81,7 @@ struct tcp_sock {__u32 lsndtime;__u32 prior_cwnd;__u64 tcp_mstamp;/* most recent packet received/sent */ +bool is_mptcp; } __attribute__((preserve_access_index)); static __always_inline struct inet_connection_sock *inet_csk(const struct sock *sk)
tools/testing/selftests/bpf/config +1 -0
@@ -55,3 +55,4 @@ CONFIG_NF_CONNTRACK=y CONFIG_USERFAULTFD=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y +CONFIG_MPTCP=y
tools/testing/selftests/bpf/network_helpers.c +31 -9
@@ -21,6 +21,10 @@#include "network_helpers.h" #include "test_progs.h" +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif +#define clean_errno () (errno == 0 ? "None" : strerror(errno))#define log_err (MSG , ...) ({ \ int __save = errno; \
@@ -73,13 +77,13 @@ int settimeo(int fd, int timeout_ms)#define save_errno_close (fd) ({ int __save = errno; close(fd); errno = __save; }) -static int __start_server (int type,const struct sockaddr *addr, +static int __start_server (int type,int protocol,const struct sockaddr *addr,socklen_t addrlen,int timeout_ms,bool reuseport) {int on =1 ;int fd; - fd =socket (addr->sa_family, type,0 ); + fd =socket (addr->sa_family, type, protocol);if (fd <0 ) {log_err ("Failed to create server socket" );return -1 ;
@@ -113,8 +117,8 @@ static int __start_server(int type, const struct sockaddr *addr,return -1 ; } -int start_server (int family,int type,const char *addr_str,__u16 port, -int timeout_ms) +static int start_server_proto (int family,int type,int protocol, +const char *addr_str,__u16 port,int timeout_ms) {struct sockaddr_storage addr;socklen_t addrlen;
@@ -122,10 +126,23 @@ int start_server(int family, int type, const char *addr_str, __u16 port,if (make_sockaddr (family, addr_str, port, &addr, &addrlen))return -1 ; -return __start_server (type, (struct sockaddr *)&addr, +return __start_server (type, protocol, (struct sockaddr *)&addr, addrlen, timeout_ms, false); } +int start_server (int family,int type,const char *addr_str,__u16 port, +int timeout_ms) +{ +return start_server_proto (family, type,0 , addr_str, port, timeout_ms); +} + +int start_mptcp_server (int family,const char *addr_str,__u16 port, +int timeout_ms) +{ +return start_server_proto (family,SOCK_STREAM ,IPPROTO_MPTCP , addr_str, + port, timeout_ms); +} +int *start_reuseport_server (int family,int type,const char *addr_str,__u16 port,int timeout_ms,unsigned int nr_listens) {
@@ -144,7 +161,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str,if (!fds)return NULL ; - fds[0 ] =__start_server (type, (struct sockaddr *)&addr, addrlen, + fds[0 ] =__start_server (type,0 , (struct sockaddr *)&addr, addrlen, timeout_ms, true);if (fds[0 ] ==-1 ) goto close_fds;
@@ -154,7 +171,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, goto close_fds;for (; nr_fds < nr_listens; nr_fds++) { - fds[nr_fds] =__start_server (type, (struct sockaddr *)&addr, + fds[nr_fds] =__start_server (type,0 , (struct sockaddr *)&addr, addrlen, timeout_ms, true);if (fds[nr_fds] ==-1 ) goto close_fds;
@@ -247,7 +264,7 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)struct sockaddr_storage addr;struct sockaddr_in *addr_in;socklen_t addrlen, optlen; -int fd, type; +int fd, type, protocol;if (!opts) opts = &default_opts;
@@ -258,6 +275,11 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)return -1 ; } +if (getsockopt (server_fd,SOL_SOCKET ,SO_PROTOCOL , &protocol, &optlen)) { +log_err ("getsockopt(SOL_PROTOCOL)" ); +return -1 ; + } + addrlen =sizeof (addr);if (getsockname (server_fd, (struct sockaddr *)&addr, &addrlen)) {log_err ("Failed to get server addr" );
@@ -265,7 +287,7 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) } addr_in = (struct sockaddr_in *)&addr; - fd =socket (addr_in->sin_family, type,0 ); + fd =socket (addr_in->sin_family, type, protocol);if (fd <0 ) {log_err ("Failed to create client socket" );return -1 ;
tools/testing/selftests/bpf/network_helpers.h +2 -0
@@ -42,6 +42,8 @@ extern struct ipv6_packet pkt_v6;int settimeo (int fd,int timeout_ms);int start_server (int family,int type,const char *addr,__u16 port,int timeout_ms); +int start_mptcp_server (int family,const char *addr,__u16 port, +int timeout_ms);int *start_reuseport_server (int family,int type,const char *addr_str,__u16 port,int timeout_ms,unsigned int nr_listens);
tools/testing/selftests/bpf/prog_tests/mptcp.c new file +112 -0
112 lines not on this page · raw message
tools/testing/selftests/bpf/progs/mptcp_sock.c new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 4/7 selftests/bpf: test bpf_skc_to_mptcp_sock
In reply to Geliang TangThis patch extends the MPTCP test base, to test the new helper bpf_skc_to_mptcp_sock().
Define struct mptcp_sock in bpf_tcp_helpers.h, use bpf_skc_to_mptcp_sock to get the msk socket in progs/mptcp_sock.c and store the infos in socket_storage_map.
Get the infos from socket_storage_map in prog_tests/mptcp.c. Add a new function verify_msk() to verify the infos of MPTCP socket, and rename verify_sk() to verify_tsk() to verify TCP socket only.
v2: Add CONFIG_MPTCP check for clearer error messages
v4:
- use ASSERT_* instead of CHECK_FAIL (Andrii)
- drop bpf_mptcp_helpers.h (Andrii)
v5:
- some 'ASSERT_*' were replaced in the next commit by mistake.
- Drop CONFIG_MPTCP (Martin)
- Use ASSERT_EQ (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 ++++ .../testing/selftests/bpf/prog_tests/mptcp.c | 27 ++++++++++++++----- .../testing/selftests/bpf/progs/mptcp_sock.c | 19 ++++++++++--- 3 files changed, 41 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +5 -0
@@ -226,4 +226,9 @@ static __always_inline bool tcp_cc_eq(const char *a, const char *b) extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym; extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym; +struct mptcp_sock { +struct inet_connection_sock sk; + +} __attribute__((preserve_access_index)); +#endif
tools/testing/selftests/bpf/prog_tests/mptcp.c +21 -6
@@ -12,14 +12,11 @@ struct mptcp_storage {__u32 is_mptcp; }; -static int verify_sk (int map_fd,int client_fd,__u32 is_mptcp) +static int verify_tsk (int map_fd,int client_fd) {int err, cfd = client_fd;struct mptcp_storage val; -if (is_mptcp ==1 ) -return 0 ; - err =bpf_map_lookup_elem (map_fd, &cfd, &val);if (!ASSERT_OK (err,"bpf_map_lookup_elem" ))return err;
@@ -33,6 +30,24 @@ static int verify_sk(int map_fd, int client_fd, __u32 is_mptcp)return err; } +static int verify_msk (int map_fd,int client_fd) +{ +int err, cfd = client_fd; +struct mptcp_storage val; + + err =bpf_map_lookup_elem (map_fd, &cfd, &val); +if (!ASSERT_OK (err,"bpf_map_lookup_elem" )) +return err; + +if (!ASSERT_EQ (val.invoked,1 ,"unexpected invoked count" )) + err++; + +if (!ASSERT_EQ (val.is_mptcp,1 ,"unexpected is_mptcp" )) + err++; + +return err; +} +static int run_test (int cgroup_fd,int server_fd,bool is_mptcp) {int client_fd, prog_fd, map_fd, err;
@@ -64,8 +79,8 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; } - err += is_mptcp ?verify_sk (map_fd, client_fd,1 ) : -verify_sk (map_fd, client_fd,0 ); + err += is_mptcp ?verify_msk (map_fd, client_fd) : +verify_tsk (map_fd, client_fd);close (client_fd);
tools/testing/selftests/bpf/progs/mptcp_sock.c +15 -4
@@ -24,6 +24,7 @@ SEC("sockops")int _sockops (struct bpf_sock_ops *ctx) {struct mptcp_storage *storage; +struct mptcp_sock *msk;int op = (int )ctx->op;struct tcp_sock *tsk;struct bpf_sock *sk;
@@ -41,11 +42,21 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; is_mptcp =bpf_core_field_exists (tsk->is_mptcp) ? tsk->is_mptcp :0 ; - storage =bpf_sk_storage_get (&socket_storage_map, sk,0 , -BPF_SK_STORAGE_GET_F_CREATE ); -if (!storage) -return 1 ; +if (!is_mptcp) { + storage =bpf_sk_storage_get (&socket_storage_map, sk,0 , +BPF_SK_STORAGE_GET_F_CREATE ); +if (!storage) +return 1 ; + }else { + msk =bpf_skc_to_mptcp_sock (sk); +if (!msk) +return 1 ; + storage =bpf_sk_storage_get (&socket_storage_map, msk,0 , +BPF_SK_STORAGE_GET_F_CREATE ); +if (!storage) +return 1 ; + } storage->invoked++; storage->is_mptcp = is_mptcp;
Signature · 1 line
2.34.1
PATCH v2 5/7 selftests/bpf: verify token of struct mptcp_sock
In reply to Geliang TangThis patch verifies the struct member token of struct mptcp_sock. Add a new member token in struct mptcp_storage to store the token value of the msk socket got by bpf_skc_to_mptcp_sock(). Trace the kernel function mptcp_pm_new_connection() by using bpf fentry prog to obtain the msk token and save it in a global bpf variable. Pass the variable to verify_msk() to verify it with the token saved in socket_storage_map.
v4:
- use ASSERT_* instead of CHECK_FAIL (Andrii)
- skip the test if 'ip mptcp monitor' is not supported (Mat)
v5:
- Drop 'ip mptcp monitor', trace mptcp_pm_new_connection instead(Martin)
- Use ASSERT_EQ (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/mptcp.c | 15 +++++++++++++-- tools/testing/selftests/bpf/progs/mptcp_sock.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -229,6 +229,7 @@ extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;struct mptcp_sock {struct inet_connection_sock sk; +__u32 token; } __attribute__((preserve_access_index));#endif
tools/testing/selftests/bpf/prog_tests/mptcp.c +13 -2
@@ -10,6 +10,7 @@struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +__u32 token; };static int verify_tsk (int map_fd,int client_fd)
@@ -30,11 +31,14 @@ static int verify_tsk(int map_fd, int client_fd)return err; } -static int verify_msk (int map_fd,int client_fd) +static int verify_msk (int map_fd,int client_fd,__u32 token) {int err, cfd = client_fd;struct mptcp_storage val; +if (!ASSERT_GT (token,0 ,"invalid token" )) +return -1 ; + err =bpf_map_lookup_elem (map_fd, &cfd, &val);if (!ASSERT_OK (err,"bpf_map_lookup_elem" ))return err;
@@ -45,6 +49,9 @@ static int verify_msk(int map_fd, int client_fd)if (!ASSERT_EQ (val.is_mptcp,1 ,"unexpected is_mptcp" )) err++; +if (!ASSERT_EQ (val.token, token,"unexpected token" )) + err++; +return err; }
@@ -57,6 +64,10 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)if (!ASSERT_OK_PTR (sock_skel,"skel_open_load" ))return -EIO ; + err =mptcp_sock__attach (sock_skel); +if (!ASSERT_OK (err,"skel_attach" )) + goto out; + prog_fd =bpf_program__fd (sock_skel->progs._sockops);if (!ASSERT_GE (prog_fd,0 ,"bpf_program__fd" )) { err = -EIO ;
@@ -79,7 +90,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; } - err += is_mptcp ?verify_msk (map_fd, client_fd) : + err += is_mptcp ?verify_msk (map_fd, client_fd, sock_skel->bss->token) :verify_tsk (map_fd, client_fd);close (client_fd);
tools/testing/selftests/bpf/progs/mptcp_sock.c +16 -0
@@ -7,10 +7,12 @@#include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL"; +__u32 token =0 ;struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +__u32 token; };struct {
@@ -47,6 +49,8 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE);if (!storage)return 1 ; + + storage->token =0 ; }else { msk =bpf_skc_to_mptcp_sock (sk);if (!msk)
@@ -56,9 +60,21 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE);if (!storage)return 1 ; + + storage->token = msk->token; } storage->invoked++; storage->is_mptcp = is_mptcp;return 1 ; } + +SEC("fentry/mptcp_pm_new_connection") +int BPF_PROG (trace_mptcp_pm_new_connection ,struct mptcp_sock *msk, +const struct sock *ssk,int server_side) +{ +if (!server_side) + token = msk->token; + +return 0 ; +}
Signature · 1 line
2.34.1
PATCH v2 6/7 selftests/bpf: verify ca_name of struct mptcp_sock
In reply to Geliang TangThis 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().
v3: Access the sysctl through the filesystem to avoid compatibility
issues with the busybox sysctl command.
v4: use ASSERT_* instead of CHECK_FAIL (Andrii)
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 +++ .../testing/selftests/bpf/prog_tests/mptcp.c | 31 +++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 4 +++ 3 files changed, 40 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +5 -0
@@ -16,6 +16,10 @@ BPF_PROG(name, args)#define SOL_TCP 6#endif +#ifndef TCP_CA_NAME_MAX +#define TCP_CA_NAME_MAX 16 +#endif +#define tcp_jiffies32 ((__u32)bpf_jiffies64())struct sock_common {
@@ -230,6 +234,7 @@ struct mptcp_sock {struct inet_connection_sock sk;__u32 token; +char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index));#endif
tools/testing/selftests/bpf/prog_tests/mptcp.c +31 -0
@@ -7,10 +7,15 @@#include "network_helpers.h" #include "mptcp_sock.skel.h" +#ifndef TCP_CA_NAME_MAX +#define TCP_CA_NAME_MAX 16 +#endif +struct mptcp_storage {__u32 invoked;__u32 is_mptcp;__u32 token; +char ca_name[TCP_CA_NAME_MAX ]; };static int verify_tsk (int map_fd,int client_fd)
@@ -31,14 +36,37 @@ static int verify_tsk(int map_fd, int client_fd)return err; } +void get_msk_ca_name (char ca_name[]) +{ +size_t len; +int fd; + + fd =open ("/proc/sys/net/ipv4/tcp_congestion_control" ,O_RDONLY ); +if (!ASSERT_GE (fd,0 ,"failed to open tcp_congestion_control" )) +return ; + + len =read (fd, ca_name,TCP_CA_NAME_MAX ); +if (!ASSERT_GT (len,0 ,"failed to read ca_name" )) + goto err; + +if (len >0 && ca_name[len -1 ] =='\n' ) + ca_name[len -1 ] ='\0' ; + +err: +close (fd); +} +static int verify_msk (int map_fd,int client_fd,__u32 token) { +char ca_name[TCP_CA_NAME_MAX ];int err, cfd = client_fd;struct mptcp_storage val;if (!ASSERT_GT (token,0 ,"invalid token" ))return -1 ; +get_msk_ca_name (ca_name); + err =bpf_map_lookup_elem (map_fd, &cfd, &val);if (!ASSERT_OK (err,"bpf_map_lookup_elem" ))return err;
@@ -52,6 +80,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token)if (!ASSERT_EQ (val.token, token,"unexpected token" )) err++; +if (!ASSERT_STRNEQ (val.ca_name, ca_name,TCP_CA_NAME_MAX ,"unexpected ca_name" )) + err++; +return err; }
tools/testing/selftests/bpf/progs/mptcp_sock.c +4 -0
@@ -2,6 +2,7 @@/* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2022, SUSE. */ +#include <string.h> #include <linux/bpf.h> #include <bpf/bpf_helpers.h> #include "bpf_tcp_helpers.h"
@@ -13,6 +14,7 @@ struct mptcp_storage {__u32 invoked;__u32 is_mptcp;__u32 token; +char ca_name[TCP_CA_NAME_MAX ]; };struct {
@@ -51,6 +53,7 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; storage->token =0 ; +bzero (storage->ca_name,TCP_CA_NAME_MAX ); }else { msk =bpf_skc_to_mptcp_sock (sk);if (!msk)
@@ -62,6 +65,7 @@ int _sockops(struct bpf_sock_ops *ctx)return 1 ; storage->token = msk->token; +memcpy (storage->ca_name, msk->ca_name,TCP_CA_NAME_MAX ); } storage->invoked++; storage->is_mptcp = is_mptcp;
Signature · 1 line
2.34.1
PATCH v2 7/7 selftests/bpf: verify first of struct mptcp_sock
In reply to Geliang TangThis patch verifies the 'first' struct member of struct mptcp_sock, which points to the first subflow of msk. Save 'sk' in mptcp_storage, and verify it with 'first' in verify_msk().
v5:
- Use ASSERT_EQ.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/mptcp.c | 5 +++++ tools/testing/selftests/bpf/progs/mptcp_sock.c | 5 +++++ 3 files changed, 11 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -234,6 +234,7 @@ struct mptcp_sock {struct inet_connection_sock sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index));
tools/testing/selftests/bpf/prog_tests/mptcp.c +5 -0
@@ -14,7 +14,9 @@struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +struct sock *sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; };
@@ -80,6 +82,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token)if (!ASSERT_EQ (val.token, token,"unexpected token" )) err++; +if (!ASSERT_EQ (val.first, val.sk,"unexpected first" )) + err++; +if (!ASSERT_STRNEQ (val.ca_name, ca_name,TCP_CA_NAME_MAX ,"unexpected ca_name" )) err++;
tools/testing/selftests/bpf/progs/mptcp_sock.c +5 -0
@@ -13,7 +13,9 @@ __u32 token = 0;struct mptcp_storage {__u32 invoked;__u32 is_mptcp; +struct sock *sk;__u32 token; +struct sock *first;char ca_name[TCP_CA_NAME_MAX ]; };
@@ -54,6 +56,7 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token =0 ;bzero (storage->ca_name,TCP_CA_NAME_MAX ); + storage->first =NULL ; }else { msk =bpf_skc_to_mptcp_sock (sk);if (!msk)
@@ -66,9 +69,11 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token = msk->token;memcpy (storage->ca_name, msk->ca_name,TCP_CA_NAME_MAX ); + storage->first = msk->first; } storage->invoked++; storage->is_mptcp = is_mptcp; + storage->sk = (struct sock *)sk;return 1 ; }
Signature · 1 line
2.34.1
PATCH v2 1/1 Squash to "selftests/bpf: add bpf_first test"
In reply to Geliang TangDrop connect_to_mptcp_fd, use connect_to_fd instead.
--- tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
@@ -268,7 +268,7 @@ static void test_first(void)system ("sysctl -qw net.mptcp.scheduler=bpf_first" ); server_fd =start_mptcp_server (AF_INET ,NULL ,0 ,0 ); - client_fd =connect_to_mptcp_fd (server_fd,0 ); + client_fd =connect_to_fd (server_fd,0 );send_data (server_fd, client_fd);
Signature · 1 line
2.34.1
Re: Squash to "selftests/bpf: add bpf_first test": Tests Results
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/6468726106095616
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6468726106095616/summary/summary.txt
- KVM Validation: debug:
- Unstable: 2 failed test(s): selftest_diag selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/5373927668056064
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5373927668056064/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/7137300cca2a
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)
Hi Geliang,
Quoted 7 lines · Geliang Tang
v2:
- The series is for bpf-next v5.
- patch 1, keepbpf_mptcp_sock_from_subflow()inbpf.c
- patch 3, Drop the 'msg' parameter ofverify_sk
- base-commit:df896c77f02a("DO-NOT-MERGE: git markup: features
net-next-next"), export/20220517T155019
- The last squash-to patch is for "BPF packet scheduler" series.
I just imported this new series in our tree.
- 7046a98c4501: "squashed" patch 1/7 in "bpf: add bpf_skc_to_mptcp_sock_proto"
- dc043d25d647: "squashed" patch 2/7 in "selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config"
- bd3e6e2ffc15: "squashed" patch 3/7 in "selftests/bpf: add MPTCP test base"
- efa55efc427c: "squashed" patch 4/7 in "selftests/bpf: test bpf_skc_to_mptcp_sock"
- f087e13912ad: "squashed" patch 5/7 in "selftests/bpf: verify token of struct mptcp_sock"
- 21c0f634b797: "squashed" patch 6/7 in "selftests/bpf: verify ca_name of struct mptcp_sock"
- d38ab51eb84e: "squashed" patch 7/7 in "selftests/bpf: verify first of struct mptcp_sock"
- c79872213ec4: conflict in t/selftests-bpf-add-bpf_first-test
- Results: 9ceda99ef71f..5fbf0e7a331f (export)
- 4353cb87928e: "squashed" in "selftests/bpf: add bpf_first test"
- Results: 5fbf0e7a331f..086d4a4a0f34 (export)
Builds and tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20220519T141104
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net