From: Martin KaFai Lau <kafai@xxxxxx> Date: Fri, 14 May 2021 19:05:15 -0700 > On Mon, May 10, 2021 at 12:44:33PM +0900, Kuniyuki Iwashima wrote: > > diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c > > index 12ee40284da0..2060bc122c53 100644 > [ ... ] > > > +static int setup_fastopen(char *buf, int size, int *saved_len, bool restore) > > +{ > > + int err = 0, fd, len; > > + > > + fd = open("/proc/sys/net/ipv4/tcp_fastopen", O_RDWR); > > + if (!ASSERT_NEQ(fd, -1, "open")) > > + return -1; > > + > > + if (restore) { > > + len = write(fd, buf, *saved_len); > > + if (!ASSERT_EQ(len, *saved_len, "write - restore")) > > + err = -1; > > + } else { > > + *saved_len = read(fd, buf, size); > > + if (!ASSERT_GE(*saved_len, 1, "read")) { > > + err = -1; > > + goto close; > > + } > > + > > + err = lseek(fd, 0, SEEK_SET); > > + if (!ASSERT_OK(err, "lseek")) > > + goto close; > > + > > + /* (TFO_CLIENT_ENABLE | TFO_SERVER_ENABLE) */ > > + len = write(fd, "3", 1); > > + if (!ASSERT_EQ(len, 1, "write - setup")) > Is it to trigger the tcp_try_fastopen() case? > I am not sure it is enough. At least, I think not for the > very first connection before the cookie is saved. > The second run of the test may be able to trigger it. > > setsockopt(TCP_FASTOPEN_NO_COOKIE) or another value in the > "/proc/sys/net/ipv4/tcp_fastopen" (ip-sysctl.rst) may be > needed. Ah, right. I missed that point while testing in the same host. TFO should be always forced without cookies. > > > + err = -1; > > + } > > + > > +close: > > + close(fd); > > + > > + return err; > > +} > > + > [ ... ] > > > diff --git a/tools/testing/selftests/bpf/progs/test_migrate_reuseport.c b/tools/testing/selftests/bpf/progs/test_migrate_reuseport.c > > new file mode 100644 > > index 000000000000..72978b5d1fcb > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/progs/test_migrate_reuseport.c > > @@ -0,0 +1,67 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Check if we can migrate child sockets. > > + * > > + * 1. If reuse_md->migrating_sk is NULL (SYN packet), > > + * return SK_PASS without selecting a listener. > > + * 2. If reuse_md->migrating_sk is not NULL (socket migration), > > + * select a listener (reuseport_map[migrate_map[cookie]]) > > + * > > + * Author: Kuniyuki Iwashima <kuniyu@xxxxxxxxxxxx> > > + */ > > + > > +#include <stddef.h> > > +#include <linux/bpf.h> > > +#include <bpf/bpf_helpers.h> > > + > > +struct { > > + __uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY); > > + __uint(max_entries, 256); > > + __type(key, int); > > + __type(value, __u64); > > +} reuseport_map SEC(".maps"); > > + > > +struct { > > + __uint(type, BPF_MAP_TYPE_HASH); > > + __uint(max_entries, 256); > > + __type(key, __u64); > > + __type(value, int); > > +} migrate_map SEC(".maps"); > > + > > +int migrated_at_close SEC(".data"); > > +int migrated_at_send_synack SEC(".data"); > > +int migrated_at_recv_ack SEC(".data"); > int migrated_at_close = 0; > int migrated_at_send_synack = 0; > int migrated_at_recv_ack = 0; > > and then use skel->bss->migrated_at_* in migrate_reuseport.c. I'll fix them. Thank you.