Commit 42a7889a authored by David S. Miller's avatar David S. Miller

Merge branch 'selftests-tcp-ao'

Dmitry Safonov says:

====================
selftest/net: Some more TCP-AO selftest post-merge fixups

Note that there's another post-merge fix for TCP-AO selftests, but that
doesn't conflict with these, so I don't resend that:

https://lore.kernel.org/all/20231219-b4-tcp-ao-selftests-out-of-tree-v1-1-0fff92d26eac@arista.com/T/#u
====================
Tested-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Reviewed-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Signed-off-by: default avatarDmitry Safonov <dima@arista.com>
parents a27359ab 80057b20
...@@ -46,8 +46,10 @@ static void test_add_routes(union tcp_addr *ips, size_t ips_nr) ...@@ -46,8 +46,10 @@ static void test_add_routes(union tcp_addr *ips, size_t ips_nr)
for (i = 0; i < ips_nr; i++) { for (i = 0; i < ips_nr; i++) {
union tcp_addr *p = (union tcp_addr *)&ips[i]; union tcp_addr *p = (union tcp_addr *)&ips[i];
int err;
if (ip_route_add(veth_name, TEST_FAMILY, this_ip_addr, *p)) err = ip_route_add(veth_name, TEST_FAMILY, this_ip_addr, *p);
if (err && err != -EEXIST)
test_error("Failed to add route"); test_error("Failed to add route");
} }
} }
......
...@@ -261,7 +261,7 @@ static int __ip_route_add(int sock, uint32_t seq, const char *intf, int family, ...@@ -261,7 +261,7 @@ static int __ip_route_add(int sock, uint32_t seq, const char *intf, int family,
req.nh.nlmsg_seq = seq; req.nh.nlmsg_seq = seq;
req.rt.rtm_family = family; req.rt.rtm_family = family;
req.rt.rtm_dst_len = (family == AF_INET) ? 32 : 128; req.rt.rtm_dst_len = (family == AF_INET) ? 32 : 128;
req.rt.rtm_table = RT_TABLE_MAIN; req.rt.rtm_table = vrf;
req.rt.rtm_protocol = RTPROT_BOOT; req.rt.rtm_protocol = RTPROT_BOOT;
req.rt.rtm_scope = RT_SCOPE_UNIVERSE; req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
req.rt.rtm_type = RTN_UNICAST; req.rt.rtm_type = RTN_UNICAST;
...@@ -294,8 +294,6 @@ int ip_route_add_vrf(const char *intf, int family, ...@@ -294,8 +294,6 @@ int ip_route_add_vrf(const char *intf, int family,
ret = __ip_route_add(route_sock, route_seq++, intf, ret = __ip_route_add(route_sock, route_seq++, intf,
family, src, dst, vrf); family, src, dst, vrf);
if (ret == -EEXIST) /* ignoring */
ret = 0;
close(route_sock); close(route_sock);
return ret; return ret;
......
...@@ -277,22 +277,38 @@ void __test_init(unsigned int ntests, int family, unsigned int prefix, ...@@ -277,22 +277,38 @@ void __test_init(unsigned int ntests, int family, unsigned int prefix,
/* /proc/sys/net/core/optmem_max artifically limits the amount of memory /* /proc/sys/net/core/optmem_max artifically limits the amount of memory
* that can be allocated with sock_kmalloc() on each socket in the system. * that can be allocated with sock_kmalloc() on each socket in the system.
* It is not virtualized, so it has to written outside test namespaces. * It is not virtualized in v6.7, so it has to written outside test
* To be nice a test will revert optmem back to the old value. * namespaces. To be nice a test will revert optmem back to the old value.
* Keeping it simple without any file lock, which means the tests that * Keeping it simple without any file lock, which means the tests that
* need to set/increase optmem value shouldn't run in parallel. * need to set/increase optmem value shouldn't run in parallel.
* Also, not re-entrant. * Also, not re-entrant.
* Since commit f5769faeec36 ("net: Namespace-ify sysctl_optmem_max")
* it is per-namespace, keeping logic for non-virtualized optmem_max
* for v6.7, which supports TCP-AO.
*/ */
static const char *optmem_file = "/proc/sys/net/core/optmem_max"; static const char *optmem_file = "/proc/sys/net/core/optmem_max";
static size_t saved_optmem; static size_t saved_optmem;
static int optmem_ns = -1;
static bool is_optmem_namespaced(void)
{
if (optmem_ns == -1) {
int old_ns = switch_save_ns(nsfd_child);
optmem_ns = !access(optmem_file, F_OK);
switch_ns(old_ns);
}
return !!optmem_ns;
}
size_t test_get_optmem(void) size_t test_get_optmem(void)
{ {
int old_ns = 0;
FILE *foptmem; FILE *foptmem;
int old_ns;
size_t ret; size_t ret;
old_ns = switch_save_ns(nsfd_outside); if (!is_optmem_namespaced())
old_ns = switch_save_ns(nsfd_outside);
foptmem = fopen(optmem_file, "r"); foptmem = fopen(optmem_file, "r");
if (!foptmem) if (!foptmem)
test_error("failed to open %s", optmem_file); test_error("failed to open %s", optmem_file);
...@@ -300,19 +316,21 @@ size_t test_get_optmem(void) ...@@ -300,19 +316,21 @@ size_t test_get_optmem(void)
if (fscanf(foptmem, "%zu", &ret) != 1) if (fscanf(foptmem, "%zu", &ret) != 1)
test_error("can't read from %s", optmem_file); test_error("can't read from %s", optmem_file);
fclose(foptmem); fclose(foptmem);
switch_ns(old_ns); if (!is_optmem_namespaced())
switch_ns(old_ns);
return ret; return ret;
} }
static void __test_set_optmem(size_t new, size_t *old) static void __test_set_optmem(size_t new, size_t *old)
{ {
int old_ns = 0;
FILE *foptmem; FILE *foptmem;
int old_ns;
if (old != NULL) if (old != NULL)
*old = test_get_optmem(); *old = test_get_optmem();
old_ns = switch_save_ns(nsfd_outside); if (!is_optmem_namespaced())
old_ns = switch_save_ns(nsfd_outside);
foptmem = fopen(optmem_file, "w"); foptmem = fopen(optmem_file, "w");
if (!foptmem) if (!foptmem)
test_error("failed to open %s", optmem_file); test_error("failed to open %s", optmem_file);
...@@ -320,7 +338,8 @@ static void __test_set_optmem(size_t new, size_t *old) ...@@ -320,7 +338,8 @@ static void __test_set_optmem(size_t new, size_t *old)
if (fprintf(foptmem, "%zu", new) <= 0) if (fprintf(foptmem, "%zu", new) <= 0)
test_error("can't write %zu to %s", new, optmem_file); test_error("can't write %zu to %s", new, optmem_file);
fclose(foptmem); fclose(foptmem);
switch_ns(old_ns); if (!is_optmem_namespaced())
switch_ns(old_ns);
} }
static void test_revert_optmem(void) static void test_revert_optmem(void)
......
...@@ -30,7 +30,7 @@ static void setup_vrfs(void) ...@@ -30,7 +30,7 @@ static void setup_vrfs(void)
err = ip_route_add_vrf(veth_name, TEST_FAMILY, err = ip_route_add_vrf(veth_name, TEST_FAMILY,
this_ip_addr, this_ip_dest, test_vrf_tabid); this_ip_addr, this_ip_dest, test_vrf_tabid);
if (err) if (err)
test_error("Failed to add a route to VRF"); test_error("Failed to add a route to VRF: %d", err);
} }
static void try_accept(const char *tst_name, unsigned int port, static void try_accept(const char *tst_name, unsigned int port,
...@@ -494,15 +494,14 @@ static void try_to_add(const char *tst_name, unsigned int port, ...@@ -494,15 +494,14 @@ static void try_to_add(const char *tst_name, unsigned int port,
static void client_add_ip(union tcp_addr *client, const char *ip) static void client_add_ip(union tcp_addr *client, const char *ip)
{ {
int family = TEST_FAMILY; int err, family = TEST_FAMILY;
if (inet_pton(family, ip, client) != 1) if (inet_pton(family, ip, client) != 1)
test_error("Can't convert ip address %s", ip); test_error("Can't convert ip address %s", ip);
if (ip_addr_add(veth_name, family, *client, TEST_PREFIX)) err = ip_addr_add(veth_name, family, *client, TEST_PREFIX);
test_error("Failed to add ip address"); if (err)
if (ip_route_add(veth_name, family, *client, this_ip_dest)) test_error("Failed to add ip address: %d", err);
test_error("Failed to add route");
} }
static void client_add_ips(void) static void client_add_ips(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment