selftests/net: Drop timeout argument from test_client_verify()It's always TEST_TIMEOUT_SEC, with an unjustified exception in rst test,that is more paranoia-long timeout rather than based on requir
selftests/net: Drop timeout argument from test_client_verify()It's always TEST_TIMEOUT_SEC, with an unjustified exception in rst test,that is more paranoia-long timeout rather than based on requirements.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-7-da48040153d1@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
selftests/net: Delete timeout from test_connect_socket()Unused: it's always either the default timeout or asynchronousconnect().Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https:/
selftests/net: Delete timeout from test_connect_socket()Unused: it's always either the default timeout or asynchronousconnect().Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-6-da48040153d1@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Add mixed select()+polling mode to TCP-AO testsCurrently, tcp_ao tests have two timeouts: TEST_RETRANSMIT_SEC andTEST_TIMEOUT_SEC [by default 1 and 5 seconds]. The first one,TEST_R
selftests/net: Add mixed select()+polling mode to TCP-AO testsCurrently, tcp_ao tests have two timeouts: TEST_RETRANSMIT_SEC andTEST_TIMEOUT_SEC [by default 1 and 5 seconds]. The first one,TEST_RETRANSMIT_SEC is used for operations that are expected to succeedin order for a test to pass. It is usually not consumed and exists onlyto avoid indefinite test run if the operation didn't complete.The second one, TEST_RETRANSMIT_SEC exists for the tests that checkingoperations, that are expected to fail/timeout. It is shorter as it isfully consumed, with an expectation that if operation didn't succeedduring that period, it will timeout. And the related test that expectsthe timeout is passing. The actual operation failure is thencross-verified by other means like counters checks.The issue with TEST_RETRANSMIT_SEC timeout is that 1 second is the exactinitial TCP timeout. So, in case the initial segment gets lost (quiteunlikely on local veth interface between two net namespaces, yet happensin slow VMs), the retransmission never happens and as a result, the testis not actually testing the functionality. Which in the end failscounters checks.As I want tcp_ao selftests to be fast and finishing in a reasonableamount of time on manual run, I didn't consider increasingTEST_RETRANSMIT_SEC.Rather, initially, BPF_SOCK_OPS_TIMEOUT_INIT looked promising as a leverto make the initial TCP timeout shorter. But as it's not a socket bpfattached thing, but sock_ops (attaches to cgroups), the selftests wouldhave to use libbpf, which I wanted to avoid if not absolutely required.Instead, use a mixed select() and counters polling mode with the longerTEST_TIMEOUT_SEC timeout to detect running-away failed tests. Itactually not only allows losing segments and succeeding afterthe previous TEST_RETRANSMIT_SEC timeout was consumed, but makesthe tests expecting timeout/failure pass faster.The only test case taking longer (TEST_TIMEOUT_SEC) now is connect-deny"wrong snd id", which checks for no key on SYN-ACK for which there is nocounter in the kernel (see tcp_make_synack()). Yet it can be speed upby poking skpair from the trace event (see trace_tcp_ao_synack_no_key).Fixes: ed9d09b309b1 ("selftests/net: Add a test for TCP-AO keys matching")Reported-by: Jakub Kicinski <kuba@kernel.org>Closes: https://lore.kernel.org/netdev/20241205070656.6ef344d7@kernel.org/Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-4-da48040153d1@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Fetch and check TCP-MD5 countersThere are related TCP-MD5 <=> TCP and TCP-MD5 <=> TCP-AO teststhat can benefit from checking the related counters, not only fromvalidating operation
selftests/net: Fetch and check TCP-MD5 countersThere are related TCP-MD5 <=> TCP and TCP-MD5 <=> TCP-AO teststhat can benefit from checking the related counters, not only fromvalidating operations timeouts.It also prepares the code for introduction of mixed select()+poll mode,see the follow-up patches.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-3-da48040153d1@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Provide tcp-ao counters comparison helperRename __test_tcp_ao_counters_cmp() into test_assert_counters_ao() andtest_tcp_ao_key_counters_cmp() into test_assert_counters_key() as they
selftests/net: Provide tcp-ao counters comparison helperRename __test_tcp_ao_counters_cmp() into test_assert_counters_ao() andtest_tcp_ao_key_counters_cmp() into test_assert_counters_key() as theyare asserts, rather than just compare functions.Provide test_cmp_counters() helper, that's going to be used to compareao_info and netns counters as a stop condition for polling the sockets.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-2-da48040153d1@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Print TCP flags in more common formatBefore:># 13145[lib/ftrace-tcp.c:427] trace event filter tcp_ao_key_not_found [2001:db8:1::1:-1 => 2001:db8:254::1:7010, L3index 0, flags: !FS!R
selftests/net: Print TCP flags in more common formatBefore:># 13145[lib/ftrace-tcp.c:427] trace event filter tcp_ao_key_not_found [2001:db8:1::1:-1 => 2001:db8:254::1:7010, L3index 0, flags: !FS!R!P!., keyid: 100, rnext: 100, maclen: -1, sne: -1] = 1After:># 13487[lib/ftrace-tcp.c:427] trace event filter tcp_ao_key_not_found [2001:db8:1::1:-1 => 2001:db8:254::1:7010, L3index 0, flags: S, keyid: 100, rnext: 100, maclen: -1, sne: -1] = 1For the history, I think the initial format was to emphasize the absenceof flags as well as their presence (!R meant no RST flag). But lookingagain, it's just unreadable and hard to understand.Make it the standard/expected one.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-1-da48040153d1@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Add missing va_end.There is no va_end after va_copy, just add it.Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>Reviewed-by: Simon Horman <horms@kernel.org>Link: http
selftests/net: Add missing va_end.There is no va_end after va_copy, just add it.Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>Reviewed-by: Simon Horman <horms@kernel.org>Link: https://patch.msgid.link/20240927040050.7851-1-zhangjiao2@cmss.chinamobile.comSigned-off-by: Paolo Abeni <pabeni@redhat.com>
selftests/net: Add trace events matching to tcp_aoSetup trace points, add a new ftrace instance in order to not interferewith the rest of the system, filtering by net namespace cookies.Raise a ne
selftests/net: Add trace events matching to tcp_aoSetup trace points, add a new ftrace instance in order to not interferewith the rest of the system, filtering by net namespace cookies.Raise a new background thread that parses trace_pipe, matches them withthe list of expected events.Wiring up trace events to selftests provides another insight if there isanything unexpected happining in the tcp-ao code (i.e. key rotation whenit's not expected).Note: in real programs libtraceevent should be used instead of thismanual labor of setting ftrace up and parsing. I'm not using it hereas I don't want to have an .so library dependency that one would have tobring into VM or DUT (Device Under Test). Please, don't copy it overinto any real world programs, that aren't tests.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-8-05623636fe8c@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Don't forget to close nsfd after switch_save_ns()The switch_save_ns() helper suppose to help switching to anothernamespace for some action and to return back to original namespace.
selftests/net: Don't forget to close nsfd after switch_save_ns()The switch_save_ns() helper suppose to help switching to anothernamespace for some action and to return back to original namespace.The fd should be closed.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-5-05623636fe8c@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Open /proc/thread-self in open_netns()It turns to be that open_netns() is called rarely from the child-threadand more often from parent-thread. Yet, on initialization of kconfigche
selftests/net: Open /proc/thread-self in open_netns()It turns to be that open_netns() is called rarely from the child-threadand more often from parent-thread. Yet, on initialization of kconfigchecks, either of threads may reach kconfig_lock mutex first.VRF-related checks do create a temporary ksft-check VRF inan unshare()'d namespace and than setns() back to the original.As original was opened from "/proc/self/ns/net", it's valid forthread-leader (parent), but it's invalid for the child, resultingin the following failure on tests that check has_vrfs() support:> # ok 54 TCP-AO required on socket + TCP-MD5 key: prefailed as expected: Key was rejected by service> # not ok 55 # error 381[unsigned-md5.c:24] Failed to add a VRF: -17> # not ok 56 # error 383[unsigned-md5.c:33] Failed to add a route to VRF: -22: Key was rejected by service> not ok 1 selftests: net/tcp_ao: unsigned-md5_ipv6 # exit=1Use "/proc/thread-self/ns/net" which is valid for any thread.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-4-05623636fe8c@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Be consistent in kconfig checksMost of the functions in tcp-ao lib/ return negative errno or -1 in caseof a failure. That creates inconsistencies in lib/kconfig, which saveswhat wa
selftests/net: Be consistent in kconfig checksMost of the functions in tcp-ao lib/ return negative errno or -1 in caseof a failure. That creates inconsistencies in lib/kconfig, which saveswhat 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 thanlibc-style errno.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-3-05623636fe8c@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Provide test_snprintf() helperInstead of pre-allocating a fixed-sized buffer of TEST_MSG_BUFFER_SIZEand printing into it, call vsnprintf() with str = NULL, which willreturn the nee
selftests/net: Provide test_snprintf() helperInstead of pre-allocating a fixed-sized buffer of TEST_MSG_BUFFER_SIZEand printing into it, call vsnprintf() with str = NULL, which willreturn the needed size of the buffer. This hack is documented inman 3 vsnprintf.Essentially, in C++ terms, it re-invents std::stringstream, which isgoing to be used to print different tracing paths and formatted strings.Use it straight away in __test_print() - which is thread-safe version ofprinting in selftests.Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-2-05623636fe8c@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/net: Clean-up double assignmentCorrect copy'n'paste typo: the previous line already initialises get_allto 1.Reported-by: Nassiri, Mohammad <mnassiri@ciena.com>Closes: https://lore.ker
selftests/net: Clean-up double assignmentCorrect copy'n'paste typo: the previous line already initialises get_allto 1.Reported-by: Nassiri, Mohammad <mnassiri@ciena.com>Closes: https://lore.kernel.org/all/DM6PR04MB4202BC58A9FD5BDD24A16E8EC56F2@DM6PR04MB4202.namprd04.prod.outlook.com/Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Link: https://patch.msgid.link/20240823-tcp-ao-selftests-upd-6-12-v4-1-05623636fe8c@gmail.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftests/tcp_ao: Printing fixes to confirm with format-securityOn my new laptop with packages from nixos-unstable, gcc 12.3.0 produces> lib/setup.c: In function ‘__test_msg’:> lib/setup.c:20:9:
selftests/tcp_ao: Printing fixes to confirm with format-securityOn my new laptop with packages from nixos-unstable, gcc 12.3.0 produces> lib/setup.c: In function ‘__test_msg’:> lib/setup.c:20:9: error: format not a string literal and no format arguments [-Werror=format-security]> 20 | ksft_print_msg(buf);> | ^~~~~~~~~~~~~~> lib/setup.c: In function ‘__test_ok’:> lib/setup.c:26:9: error: format not a string literal and no format arguments [-Werror=format-security]> 26 | ksft_test_result_pass(buf);> | ^~~~~~~~~~~~~~~~~~~~~> lib/setup.c: In function ‘__test_fail’:> lib/setup.c:32:9: error: format not a string literal and no format arguments [-Werror=format-security]> 32 | ksft_test_result_fail(buf);> | ^~~~~~~~~~~~~~~~~~~~~> lib/setup.c: In function ‘__test_xfail’:> lib/setup.c:38:9: error: format not a string literal and no format arguments [-Werror=format-security]> 38 | ksft_test_result_xfail(buf);> | ^~~~~~~~~~~~~~~~~~~~~~> lib/setup.c: In function ‘__test_error’:> lib/setup.c:44:9: error: format not a string literal and no format arguments [-Werror=format-security]> 44 | ksft_test_result_error(buf);> | ^~~~~~~~~~~~~~~~~~~~~~> lib/setup.c: In function ‘__test_skip’:> lib/setup.c:50:9: error: format not a string literal and no format arguments [-Werror=format-security]> 50 | ksft_test_result_skip(buf);> | ^~~~~~~~~~~~~~~~~~~~~> cc1: some warnings being treated as errorsAs the buffer was already pre-printed into, print it as a stringrather than a format-string.Fixes: cfbab37b3da0 ("selftests/net: Add TCP-AO library")Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Reported-by: Muhammad Usama Anjum <usama.anjum@collabora.com>Signed-off-by: Paolo Abeni <pabeni@redhat.com>
selftests/tcp_ao: Fix fscanf() call for format-securityOn my new laptop with packages from nixos-unstable, gcc 12.3.0 produces:> lib/proc.c: In function ‘netstat_read_type’:> lib/proc.c:89:9: err
selftests/tcp_ao: Fix fscanf() call for format-securityOn my new laptop with packages from nixos-unstable, gcc 12.3.0 produces:> lib/proc.c: In function ‘netstat_read_type’:> lib/proc.c:89:9: error: format not a string literal and no format arguments [-Werror=format-security]> 89 | if (fscanf(fnetstat, type->header_name) == EOF)> | ^~> cc1: some warnings being treated as errorsHere the selftests lib parses header name, while expectes non-space wordending with a column.Fixes: cfbab37b3da0 ("selftests/net: Add TCP-AO library")Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>Reported-by: Muhammad Usama Anjum <usama.anjum@collabora.com>Signed-off-by: Paolo Abeni <pabeni@redhat.com>
selftests/net: Repair RST passive reset selftestCurrently, the test is racy and seems to not pass anymore.In order to rectify it, aim on TCP_TW_RST.Doesn't seem way too good with this sleep() pa
selftests/net: Repair RST passive reset selftestCurrently, the test is racy and seems to not pass anymore.In order to rectify it, aim on TCP_TW_RST.Doesn't seem way too good with this sleep() part, but it seems asa reasonable compromise for the test. There is a plan in-line comment onhow-to improve it, going to do it on the top, at this moment I want itto run on netdev/patchwork selftests dashboard.It also slightly changes tcp_ao-lib in order to get SO_ERROR propagatedto test_client_verify() return value.Fixes: c6df7b2361d7 ("selftests/net: Add TCP-AO RST test")Signed-off-by: Dmitry Safonov <dima@arista.com>Link: https://lore.kernel.org/r/20240130-tcp-ao-test-key-mgmt-v2-3-d190430a6c60@arista.comSigned-off-by: Jakub Kicinski <kuba@kernel.org>
selftest/tcp-ao: Work on namespace-ified sysctl_optmem_maxSince commit f5769faeec36 ("net: Namespace-ify sysctl_optmem_max")optmem_max is per-netns, so need of switching to root namespace.It seem
selftest/tcp-ao: Work on namespace-ified sysctl_optmem_maxSince commit f5769faeec36 ("net: Namespace-ify sysctl_optmem_max")optmem_max is per-netns, so need of switching to root namespace.It seems trivial to keep the old logic working, so going to keep it fora while (at least, until kernel with netns-optmem_max will be release).Currently, there is a test that checks that optmem_max limit applies toTCP-AO keys and a little benchmark that measures linked-list TCP-AO keysscaling, those are fixed by this.Cc: Eric Dumazet <edumazet@google.com>Signed-off-by: Dmitry Safonov <dima@arista.com>Signed-off-by: David S. Miller <davem@davemloft.net>
selftest/tcp-ao: Set routes in a proper VRF table idIn unsigned-md5 selftests ip_route_add() is not needed inclient_add_ip(): the route was pre-setup in __test_init() => link_init()for subnet, ra
selftest/tcp-ao: Set routes in a proper VRF table idIn unsigned-md5 selftests ip_route_add() is not needed inclient_add_ip(): the route was pre-setup in __test_init() => link_init()for subnet, rather than a specific ip-address.Currently, __ip_route_add() mistakenly always sets VRF tableto RT_TABLE_MAIN - this seems to have sneaked in during unsigned-md5tests debugging. That also explains, why ip_route_add_vrf() ignoredEEXIST, returned by fib6.Yet, keep EEXIST ignoring in bench-lookups selftests as it's expectedthat those selftests may add the same (duplicate) routes.Reported-by: Hangbin Liu <liuhangbin@gmail.com>Signed-off-by: Dmitry Safonov <dima@arista.com>Signed-off-by: David S. Miller <davem@davemloft.net>
selftests/net: Fix various spelling mistakes in TCP-AO testsThere are a handful of spelling mistakes in test messages in theTCP-AIO selftests. Fix these.Signed-off-by: Colin Ian King <colin.i.ki
selftests/net: Fix various spelling mistakes in TCP-AO testsThere are a handful of spelling mistakes in test messages in theTCP-AIO selftests. Fix these.Signed-off-by: Colin Ian King <colin.i.king@gmail.com>Reviewed-by: Dmitry Safonov <dima@arista.com>Reviewed-by: Randy Dunlap <rdunlap@infradead.org>Signed-off-by: David S. Miller <davem@davemloft.net>
selftests/net: Add TCP-AO RST testCheck that both active and passive reset works and correctly signsegments with TCP-AO or don't send RSTs if not possible to sign.A listening socket with backlog
selftests/net: Add TCP-AO RST testCheck that both active and passive reset works and correctly signsegments with TCP-AO or don't send RSTs if not possible to sign.A listening socket with backlog = 0 gets one connection in acceptqueue, another in syn queue. Once the server/listener socket isforcibly closed, client sockets aren't connected to anything.In regular situation they would receive RST on any segment, butwith TCP-AO as there's no listener, no AO-key and unknown ISNs,no RST should be sent.And "passive" reset, where RST is sent on reply for some segment(tcp_v{4,6}_send_reset()) - there use TCP_REPAIR to corrupt SEQ numbers,which later results in TCP-AO signed RST, which will be verified andclient socket will get EPIPE.No TCPAORequired/TCPAOBad segments are expected during these tests.Sample of the output:> # ./rst_ipv4> 1..15> # 1462[lib/setup.c:254] rand seed 1686611171> TAP version 13> ok 1 servered 1000 bytes> ok 2 Verified established tcp connection> ok 3 sk[0] = 7, connection was reset> ok 4 sk[1] = 8, connection was reset> ok 5 sk[2] = 9> ok 6 MKT counters are good on server> ok 7 Verified established tcp connection> ok 8 client connection broken post-seq-adjust> ok 9 client connection was reset> ok 10 No segments without AO sign (server)> ok 11 Signed AO segments (server): 0 => 30> ok 12 No segments with bad AO sign (server)> ok 13 No segments without AO sign (client)> ok 14 Signed AO segments (client): 0 => 30> ok 15 No segments with bad AO sign (client)> # Totals: pass:15 fail:0 xfail:0 xpass:0 skip:0 error:0Signed-off-by: Dmitry Safonov <dima@arista.com>Signed-off-by: David S. Miller <davem@davemloft.net>
selftests/net: Add TCP-AO libraryProvide functions to create selftests dedicated to TCP-AO.They can run in parallel, as they use temporary net namespaces.They can be very specific to the feature
selftests/net: Add TCP-AO libraryProvide functions to create selftests dedicated to TCP-AO.They can run in parallel, as they use temporary net namespaces.They can be very specific to the feature being tested.This will allow to create a lot of TCP-AO tests, without complicatingone binary with many --options and to create scenarios, that arehard to put in bash script that uses one binary.Signed-off-by: Dmitry Safonov <dima@arista.com>Signed-off-by: David S. Miller <davem@davemloft.net>