Skip to content

Commit

Permalink
set_block_flag
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Apr 1, 2024
1 parent 09423a3 commit 0af3ea7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
9 changes: 1 addition & 8 deletions tools/testing/selftests/bpf/network_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ struct arg {
int fd;
unsigned total_bytes;
int stop;
bool again;
};

static void *server(void *arg)
Expand Down Expand Up @@ -539,8 +538,6 @@ static void *server(void *arg)
MIN(a->total_bytes - bytes, sizeof(batch)), 0);
if (nr_sent == -1 && errno == EINTR)
continue;
if (nr_sent == -1 && a->again && errno == EAGAIN)
continue;
if (nr_sent == -1) {
err = -errno;
break;
Expand All @@ -561,15 +558,13 @@ static void *server(void *arg)
}

void send_recv_data(int lfd, int fd,
unsigned total_bytes,
bool again)
unsigned total_bytes)
{
ssize_t nr_recv = 0, bytes = 0;
pthread_t srv_thread;
struct arg arg = {
.fd = lfd,
.total_bytes = total_bytes,
.again = again,
};
void *thread_ret;
char batch[1500];
Expand All @@ -587,8 +582,6 @@ void send_recv_data(int lfd, int fd,
MIN(total_bytes - bytes, sizeof(batch)), 0);
if (nr_recv == -1 && errno == EINTR)
continue;
if (nr_recv == -1 && again && errno == EAGAIN)
continue;
if (nr_recv == -1)
break;
bytes += nr_recv;
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/selftests/bpf/network_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ struct nstoken *open_netns(const char *name);
void close_netns(struct nstoken *token);
int send_byte(int fd);
void send_recv_data(int lfd, int fd,
unsigned total_bytes,
bool again);
unsigned total_bytes);

static __u16 csum_fold(__u32 csum)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
goto done;
}

send_recv_data(lfd, fd, total_bytes, false);
send_recv_data(lfd, fd, total_bytes);

done:
close(lfd);
Expand Down
28 changes: 25 additions & 3 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ static int ss_search(char *src, char *keyword)
return _ss_search(src, ADDR_1, "dport", keyword);
}

static int set_block_flag(int fd)
{
int flags;

flags = fcntl(fd, F_GETFL, 0);
if (flags < 0)
return -1;

flags &=~O_NONBLOCK;
if (fcntl(fd, F_SETFL, flags) < 0)
return -1;

return 0;
}

static void run_mptcp_subflow(int cgroup_fd, struct mptcp_subflow *skel)
{
int server_fd, client_fd, prog_fd, err;
Expand All @@ -329,7 +344,10 @@ static void run_mptcp_subflow(int cgroup_fd, struct mptcp_subflow *skel)
if (!ASSERT_GE(client_fd, 0, "connect to fd"))
goto close_server;

send_recv_data(server_fd, client_fd, total_bytes, true);
if (set_block_flag(server_fd))
goto close_server;

send_recv_data(server_fd, client_fd, total_bytes * 20);

ASSERT_OK(ss_search(ADDR_1, "fwmark:0x1"), "ss_search fwmark:0x1");
ASSERT_OK(ss_search(ADDR_2, "fwmark:0x2"), "ss_search fwmark:0x2");
Expand Down Expand Up @@ -418,9 +436,12 @@ static void send_data_and_verify(char *msg, int addr1, int addr2)
}

if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
return;
goto close_server;

if (set_block_flag(server_fd))
goto close_server;

send_recv_data(server_fd, client_fd, total_bytes, true);
send_recv_data(server_fd, client_fd, total_bytes * 20);

if (clock_gettime(CLOCK_MONOTONIC, &end) < 0)
return;
Expand All @@ -438,6 +459,7 @@ static void send_data_and_verify(char *msg, int addr1, int addr2)
ASSERT_GT(has_bytes_sent(ADDR_2), 0, "Shouldn't have bytes_sent on addr2");

close(client_fd);
close_server:
close(server_fd);
}

Expand Down

0 comments on commit 0af3ea7

Please sign in to comment.