On 4/16/24 3:13 AM, Geliang Tang wrote:
From: Geliang Tang <tanggeli...@kylinos.cn>

This patch uses public helper connect_to_addr() exported in
network_helpers.h instead of the local defined function connect_to_server()
in prog_tests/sk_assign.c. This can avoid duplicate code.

The code that sets SO_SNDTIMEO timeout as timeo_sec (3s) can be dropped,
since connect_to_addr() sets default timeout as 3s.

Signed-off-by: Geliang Tang <tanggeli...@kylinos.cn>
---
  .../selftests/bpf/prog_tests/sk_assign.c      | 26 +------------------
  1 file changed, 1 insertion(+), 25 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c 
b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
index fa8f757c0edd..766fc56f5fc7 100644
--- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c
+++ b/tools/testing/selftests/bpf/prog_tests/sk_assign.c
@@ -23,8 +23,6 @@
  #define NS_SELF "/proc/self/ns/net"
  #define SERVER_MAP_PATH "/sys/fs/bpf/tc/globals/server_map"
-static const struct timeval timeo_sec = { .tv_sec = 3 };
-static const size_t timeo_optlen = sizeof(timeo_sec);
  static int stop, duration;
static bool
@@ -74,28 +72,6 @@ configure_stack(void)
        return true;
  }
-static int
-connect_to_server(const struct sockaddr *addr, socklen_t len, int type)
-{
-       int fd = -1;
-
-       fd = socket(addr->sa_family, type, 0);
-       if (CHECK_FAIL(fd == -1))
-               goto out;
-       if (CHECK_FAIL(setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo_sec,
-                                 timeo_optlen)))

I think Eduard has also pointed out in v2 that the existing connect_to_addr() does not set the timeout and suggested to add the opts arg also.

One option is to just modify the connect_to_addr() to set the default timeout (3s) without needing to add the opts arg. Since we are changing the signature of connect_to_addr() anyway, lets just add the opts argument also. When opts is NULL or opts->timeout_ms is 0, then use the default 3s timeout like other helpers do.

something like,

int connect_to_addr(int type, const struct sockaddr_storage *addr,
                    socklen_t addrlen, const struct network_helper_opts *opts);



Reply via email to