/* * Can't be included in the header: it defines static variables which * will be unique to every object. Let's include it only once here.
*/ #include"../../../kselftest.h"
/* Prevent overriding of one thread's output by another */ static pthread_mutex_t ksft_print_lock = PTHREAD_MUTEX_INITIALIZER;
staticvoid link_init(constchar *veth, int family, uint8_t prefix, union tcp_addr addr, union tcp_addr dest)
{ if (link_set_up(veth))
test_error("Failed to set link up"); if (ip_addr_add(veth, family, addr, prefix))
test_error("Failed to add ip address"); if (ip_route_add(veth, family, addr, dest))
test_error("Failed to add route");
}
void __test_init(unsignedint ntests, int family, unsignedint prefix, union tcp_addr addr1, union tcp_addr addr2,
thread_fn peer1, thread_fn peer2)
{ struct sigaction sa = {
.sa_handler = sig_int,
.sa_flags = SA_RESTART,
};
time_t seed = time(NULL);
sigemptyset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL))
test_error("Can't set SIGINT handler");
test_family = family; if (!kernel_config_has(KCONFIG_NET_NS))
__test_skip_all(tests_skip_reason[KCONFIG_NET_NS]); if (!kernel_config_has(KCONFIG_VETH))
__test_skip_all(tests_skip_reason[KCONFIG_VETH]); if (!kernel_config_has(KCONFIG_TCP_AO))
__test_skip_all(tests_skip_reason[KCONFIG_TCP_AO]);
/* /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. * It is not virtualized in v6.7, so it has to written outside test * 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 * need to set/increase optmem value shouldn't run in parallel. * 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.
*/ staticconstchar *optmem_file = "/proc/sys/net/core/optmem_max"; static size_t saved_optmem; staticint optmem_ns = -1;
staticbool is_optmem_namespaced(void)
{ if (optmem_ns == -1) { int old_ns = switch_save_ns(nsfd_child);
if (!is_optmem_namespaced())
old_ns = switch_save_ns(nsfd_outside);
foptmem = fopen(optmem_file, "r"); if (!foptmem)
test_error("failed to open %s", optmem_file);
if (fscanf(foptmem, "%zu", &ret) != 1)
test_error("can't read from %s", optmem_file);
fclose(foptmem); if (!is_optmem_namespaced())
switch_close_ns(old_ns); return ret;
}
if (!is_optmem_namespaced())
old_ns = switch_save_ns(nsfd_outside);
foptmem = fopen(optmem_file, "w"); if (!foptmem)
test_error("failed to open %s", optmem_file);
if (fprintf(foptmem, "%zu", new) <= 0)
test_error("can't write %zu to %s", new, optmem_file);
fclose(foptmem); if (!is_optmem_namespaced())
switch_close_ns(old_ns);
}
staticvoid test_revert_optmem(void)
{ if (saved_optmem == 0) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.