On Fri, May 13, 2022 at 3:48 PM Mat Martineau <mathew.j.martineau@xxxxxxxxxxxxxxx> wrote: > > From: Geliang Tang <geliang.tang@xxxxxxxx> > > This patch verifies the struct member token of struct mptcp_sock. Add a > new function get_msk_token() to parse the msk token from the output of > the command 'ip mptcp monitor', and verify it in verify_msk(). > > v4: > - use ASSERT_* instead of CHECK_FAIL (Andrii) > - skip the test if 'ip mptcp monitor' is not supported (Mat) > > Acked-by: Matthieu Baerts <matthieu.baerts@xxxxxxxxxxxx> > Signed-off-by: Geliang Tang <geliang.tang@xxxxxxxx> > Signed-off-by: Mat Martineau <mathew.j.martineau@xxxxxxxxxxxxxxx> > --- > tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + > .../testing/selftests/bpf/prog_tests/mptcp.c | 64 +++++++++++++++++++ > .../testing/selftests/bpf/progs/mptcp_sock.c | 5 ++ > 3 files changed, 70 insertions(+) > [...] > + fd = open(monitor_log_path, O_RDONLY); > + if (!ASSERT_GE(fd, 0, "Failed to open monitor_log_path")) > + return token; > + > + len = read(fd, buf, sizeof(buf)); > + if (!ASSERT_GT(len, 0, "Failed to read monitor_log_path")) > + goto err; > + > + if (strncmp(buf, prefix, strlen(prefix))) { ASSERT_STRNEQ ? > + log_err("Invalid prefix %s", buf); > + goto err; > + } > + > + token = strtol(buf + strlen(prefix), NULL, 16); > + > +err: > + close(fd); > + return token; > +} > + > static int verify_msk(int map_fd, int client_fd) > { > char *msg = "MPTCP subflow socket"; > int err, cfd = client_fd; > struct mptcp_storage val; > + __u32 token; > + > + token = get_msk_token(); > + if (!ASSERT_GT(token, 0, "Unexpected token")) > + return -1; > > err = bpf_map_lookup_elem(map_fd, &cfd, &val); > if (!ASSERT_OK(err, "bpf_map_lookup_elem")) > @@ -58,6 +102,12 @@ static int verify_msk(int map_fd, int client_fd) > err++; > } > > + if (val.token != token) { ASSERT_NEQ > + log_err("Unexpected mptcp_sock.token %x != %x", > + val.token, token); > + err++; > + } > + > return err; > } > [...]