Skip to content

Commit 42a7889

Browse files
committed
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: Hangbin Liu <[email protected]> Reviewed-by: Hangbin Liu <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]>
2 parents a27359a + 80057b2 commit 42a7889

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

tools/testing/selftests/net/tcp_ao/bench-lookups.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ static void test_add_routes(union tcp_addr *ips, size_t ips_nr)
4646

4747
for (i = 0; i < ips_nr; i++) {
4848
union tcp_addr *p = (union tcp_addr *)&ips[i];
49+
int err;
4950

50-
if (ip_route_add(veth_name, TEST_FAMILY, this_ip_addr, *p))
51+
err = ip_route_add(veth_name, TEST_FAMILY, this_ip_addr, *p);
52+
if (err && err != -EEXIST)
5153
test_error("Failed to add route");
5254
}
5355
}

tools/testing/selftests/net/tcp_ao/lib/netlink.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static int __ip_route_add(int sock, uint32_t seq, const char *intf, int family,
261261
req.nh.nlmsg_seq = seq;
262262
req.rt.rtm_family = family;
263263
req.rt.rtm_dst_len = (family == AF_INET) ? 32 : 128;
264-
req.rt.rtm_table = RT_TABLE_MAIN;
264+
req.rt.rtm_table = vrf;
265265
req.rt.rtm_protocol = RTPROT_BOOT;
266266
req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
267267
req.rt.rtm_type = RTN_UNICAST;
@@ -294,8 +294,6 @@ int ip_route_add_vrf(const char *intf, int family,
294294

295295
ret = __ip_route_add(route_sock, route_seq++, intf,
296296
family, src, dst, vrf);
297-
if (ret == -EEXIST) /* ignoring */
298-
ret = 0;
299297

300298
close(route_sock);
301299
return ret;

tools/testing/selftests/net/tcp_ao/lib/setup.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,50 +277,69 @@ void __test_init(unsigned int ntests, int family, unsigned int prefix,
277277

278278
/* /proc/sys/net/core/optmem_max artifically limits the amount of memory
279279
* that can be allocated with sock_kmalloc() on each socket in the system.
280-
* It is not virtualized, so it has to written outside test namespaces.
281-
* To be nice a test will revert optmem back to the old value.
280+
* It is not virtualized in v6.7, so it has to written outside test
281+
* namespaces. To be nice a test will revert optmem back to the old value.
282282
* Keeping it simple without any file lock, which means the tests that
283283
* need to set/increase optmem value shouldn't run in parallel.
284284
* Also, not re-entrant.
285+
* Since commit f5769faeec36 ("net: Namespace-ify sysctl_optmem_max")
286+
* it is per-namespace, keeping logic for non-virtualized optmem_max
287+
* for v6.7, which supports TCP-AO.
285288
*/
286289
static const char *optmem_file = "/proc/sys/net/core/optmem_max";
287290
static size_t saved_optmem;
291+
static int optmem_ns = -1;
292+
293+
static bool is_optmem_namespaced(void)
294+
{
295+
if (optmem_ns == -1) {
296+
int old_ns = switch_save_ns(nsfd_child);
297+
298+
optmem_ns = !access(optmem_file, F_OK);
299+
switch_ns(old_ns);
300+
}
301+
return !!optmem_ns;
302+
}
288303

289304
size_t test_get_optmem(void)
290305
{
306+
int old_ns = 0;
291307
FILE *foptmem;
292-
int old_ns;
293308
size_t ret;
294309

295-
old_ns = switch_save_ns(nsfd_outside);
310+
if (!is_optmem_namespaced())
311+
old_ns = switch_save_ns(nsfd_outside);
296312
foptmem = fopen(optmem_file, "r");
297313
if (!foptmem)
298314
test_error("failed to open %s", optmem_file);
299315

300316
if (fscanf(foptmem, "%zu", &ret) != 1)
301317
test_error("can't read from %s", optmem_file);
302318
fclose(foptmem);
303-
switch_ns(old_ns);
319+
if (!is_optmem_namespaced())
320+
switch_ns(old_ns);
304321
return ret;
305322
}
306323

307324
static void __test_set_optmem(size_t new, size_t *old)
308325
{
326+
int old_ns = 0;
309327
FILE *foptmem;
310-
int old_ns;
311328

312329
if (old != NULL)
313330
*old = test_get_optmem();
314331

315-
old_ns = switch_save_ns(nsfd_outside);
332+
if (!is_optmem_namespaced())
333+
old_ns = switch_save_ns(nsfd_outside);
316334
foptmem = fopen(optmem_file, "w");
317335
if (!foptmem)
318336
test_error("failed to open %s", optmem_file);
319337

320338
if (fprintf(foptmem, "%zu", new) <= 0)
321339
test_error("can't write %zu to %s", new, optmem_file);
322340
fclose(foptmem);
323-
switch_ns(old_ns);
341+
if (!is_optmem_namespaced())
342+
switch_ns(old_ns);
324343
}
325344

326345
static void test_revert_optmem(void)

tools/testing/selftests/net/tcp_ao/unsigned-md5.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void setup_vrfs(void)
3030
err = ip_route_add_vrf(veth_name, TEST_FAMILY,
3131
this_ip_addr, this_ip_dest, test_vrf_tabid);
3232
if (err)
33-
test_error("Failed to add a route to VRF");
33+
test_error("Failed to add a route to VRF: %d", err);
3434
}
3535

3636
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,
494494

495495
static void client_add_ip(union tcp_addr *client, const char *ip)
496496
{
497-
int family = TEST_FAMILY;
497+
int err, family = TEST_FAMILY;
498498

499499
if (inet_pton(family, ip, client) != 1)
500500
test_error("Can't convert ip address %s", ip);
501501

502-
if (ip_addr_add(veth_name, family, *client, TEST_PREFIX))
503-
test_error("Failed to add ip address");
504-
if (ip_route_add(veth_name, family, *client, this_ip_dest))
505-
test_error("Failed to add route");
502+
err = ip_addr_add(veth_name, family, *client, TEST_PREFIX);
503+
if (err)
504+
test_error("Failed to add ip address: %d", err);
506505
}
507506

508507
static void client_add_ips(void)

0 commit comments

Comments
 (0)