Commit bc2468f9 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Jakub Kicinski

selftests/net: Be consistent in kconfig checks

Most of the functions in tcp-ao lib/ return negative errno or -1 in case
of a failure. That creates inconsistencies in lib/kconfig, which saves
what was the error code. As well as the uninitialized kconfig value is
-1, which also may be the result of a check.

Define KCONFIG_UNKNOWN and save negative return code, rather than
libc-style errno.
Signed-off-by: default avatarDmitry Safonov <0x7f454c46@gmail.com>
Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-3-05623636fe8c@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 7053e788
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "aolib.h" #include "aolib.h"
struct kconfig_t { struct kconfig_t {
int _errno; /* the returned error if not supported */ int _error; /* negative errno if not supported */
int (*check_kconfig)(int *error); int (*check_kconfig)(int *error);
}; };
...@@ -62,7 +62,7 @@ static int has_tcp_ao(int *err) ...@@ -62,7 +62,7 @@ static int has_tcp_ao(int *err)
memcpy(&tmp.addr, &addr, sizeof(addr)); memcpy(&tmp.addr, &addr, sizeof(addr));
*err = 0; *err = 0;
if (setsockopt(sk, IPPROTO_TCP, TCP_AO_ADD_KEY, &tmp, sizeof(tmp)) < 0) { if (setsockopt(sk, IPPROTO_TCP, TCP_AO_ADD_KEY, &tmp, sizeof(tmp)) < 0) {
*err = errno; *err = -errno;
if (errno != ENOPROTOOPT) if (errno != ENOPROTOOPT)
ret = -errno; ret = -errno;
} }
...@@ -87,7 +87,7 @@ static int has_tcp_md5(int *err) ...@@ -87,7 +87,7 @@ static int has_tcp_md5(int *err)
*/ */
*err = 0; *err = 0;
if (test_set_md5(sk, addr_any, 0, -1, DEFAULT_TEST_PASSWORD)) { if (test_set_md5(sk, addr_any, 0, -1, DEFAULT_TEST_PASSWORD)) {
*err = errno; *err = -errno;
if (errno != ENOPROTOOPT && errno == ENOMEM) { if (errno != ENOPROTOOPT && errno == ENOMEM) {
test_print("setsockopt(TCP_MD5SIG_EXT): %m"); test_print("setsockopt(TCP_MD5SIG_EXT): %m");
ret = -errno; ret = -errno;
...@@ -116,13 +116,14 @@ static int has_vrfs(int *err) ...@@ -116,13 +116,14 @@ static int has_vrfs(int *err)
return ret; return ret;
} }
#define KCONFIG_UNKNOWN 1
static pthread_mutex_t kconfig_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t kconfig_lock = PTHREAD_MUTEX_INITIALIZER;
static struct kconfig_t kconfig[__KCONFIG_LAST__] = { static struct kconfig_t kconfig[__KCONFIG_LAST__] = {
{ -1, has_net_ns }, { KCONFIG_UNKNOWN, has_net_ns },
{ -1, has_veth }, { KCONFIG_UNKNOWN, has_veth },
{ -1, has_tcp_ao }, { KCONFIG_UNKNOWN, has_tcp_ao },
{ -1, has_tcp_md5 }, { KCONFIG_UNKNOWN, has_tcp_md5 },
{ -1, has_vrfs }, { KCONFIG_UNKNOWN, has_vrfs },
}; };
const char *tests_skip_reason[__KCONFIG_LAST__] = { const char *tests_skip_reason[__KCONFIG_LAST__] = {
...@@ -138,11 +139,11 @@ bool kernel_config_has(enum test_needs_kconfig k) ...@@ -138,11 +139,11 @@ bool kernel_config_has(enum test_needs_kconfig k)
bool ret; bool ret;
pthread_mutex_lock(&kconfig_lock); pthread_mutex_lock(&kconfig_lock);
if (kconfig[k]._errno == -1) { if (kconfig[k]._error == KCONFIG_UNKNOWN) {
if (kconfig[k].check_kconfig(&kconfig[k]._errno)) if (kconfig[k].check_kconfig(&kconfig[k]._error))
test_error("Failed to initialize kconfig %u", k); test_error("Failed to initialize kconfig %u", k);
} }
ret = kconfig[k]._errno == 0; ret = kconfig[k]._error == 0;
pthread_mutex_unlock(&kconfig_lock); pthread_mutex_unlock(&kconfig_lock);
return ret; return ret;
} }
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