Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'selftests-net-mixed-select-polling-mode-for-tcp-ao-tests'

Dmitry Safonov via says:

====================
selftests/net: Mixed select()+polling mode for TCP-AO tests

Should fix flaky tcp-ao/connect-deny-ipv6 test.

v1: https://lore.kernel.org/20250312-tcp-ao-selftests-polling-v1-0-72a642b855d5@gmail.com
====================

Link: https://patch.msgid.link/20250319-tcp-ao-selftests-polling-v2-0-da48040153d1@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+552 -345
+34 -24
tools/testing/selftests/net/tcp_ao/connect-deny.c
··· 4 4 #include "aolib.h" 5 5 6 6 #define fault(type) (inj == FAULT_ ## type) 7 + static volatile int sk_pair; 7 8 8 9 static inline int test_add_key_maclen(int sk, const char *key, uint8_t maclen, 9 10 union tcp_addr in_addr, uint8_t prefix, ··· 35 34 const char *cnt_name, test_cnt cnt_expected, 36 35 fault_t inj) 37 36 { 38 - struct tcp_ao_counters ao_cnt1, ao_cnt2; 37 + struct tcp_counters cnt1, cnt2; 39 38 uint64_t before_cnt = 0, after_cnt = 0; /* silence GCC */ 39 + test_cnt poll_cnt = (cnt_expected == TEST_CNT_GOOD) ? 0 : cnt_expected; 40 40 int lsk, err, sk = 0; 41 - time_t timeout; 42 41 43 42 lsk = test_listen_socket(this_ip_addr, port, 1); 44 43 ··· 47 46 48 47 if (cnt_name) 49 48 before_cnt = netstat_get_one(cnt_name, NULL); 50 - if (pwd && test_get_tcp_ao_counters(lsk, &ao_cnt1)) 51 - test_error("test_get_tcp_ao_counters()"); 49 + if (pwd && test_get_tcp_counters(lsk, &cnt1)) 50 + test_error("test_get_tcp_counters()"); 52 51 53 52 synchronize_threads(); /* preparations done */ 54 53 55 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 56 - err = test_wait_fd(lsk, timeout, 0); 54 + err = test_skpair_wait_poll(lsk, 0, poll_cnt, &sk_pair); 57 55 if (err == -ETIMEDOUT) { 56 + sk_pair = err; 58 57 if (!fault(TIMEOUT)) 59 - test_fail("timed out for accept()"); 58 + test_fail("%s: timed out for accept()", tst_name); 59 + } else if (err == -EKEYREJECTED) { 60 + if (!fault(KEYREJECT)) 61 + test_fail("%s: key was rejected", tst_name); 60 62 } else if (err < 0) { 61 - test_error("test_wait_fd()"); 63 + test_error("test_skpair_wait_poll()"); 62 64 } else { 63 65 if (fault(TIMEOUT)) 64 - test_fail("ready to accept"); 66 + test_fail("%s: ready to accept", tst_name); 65 67 66 68 sk = accept(lsk, NULL, NULL); 67 69 if (sk < 0) { ··· 76 72 } 77 73 78 74 synchronize_threads(); /* before counter checks */ 79 - if (pwd && test_get_tcp_ao_counters(lsk, &ao_cnt2)) 80 - test_error("test_get_tcp_ao_counters()"); 75 + if (pwd && test_get_tcp_counters(lsk, &cnt2)) 76 + test_error("test_get_tcp_counters()"); 81 77 82 78 close(lsk); 83 79 84 80 if (pwd) 85 - test_tcp_ao_counters_cmp(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected); 81 + test_assert_counters(tst_name, &cnt1, &cnt2, cnt_expected); 86 82 87 83 if (!cnt_name) 88 84 goto out; ··· 113 109 114 110 try_accept("Non-AO server + AO client", port++, NULL, 115 111 this_ip_dest, -1, 100, 100, 0, 116 - "TCPAOKeyNotFound", 0, FAULT_TIMEOUT); 112 + "TCPAOKeyNotFound", TEST_CNT_NS_KEY_NOT_FOUND, FAULT_TIMEOUT); 117 113 118 114 try_accept("AO server + Non-AO client", port++, DEFAULT_TEST_PASSWORD, 119 115 this_ip_dest, -1, 100, 100, 0, ··· 139 135 wrong_addr, -1, 100, 100, 0, 140 136 "TCPAOKeyNotFound", TEST_CNT_AO_KEY_NOT_FOUND, FAULT_TIMEOUT); 141 137 138 + /* Key rejected by the other side, failing short through skpair */ 142 139 try_accept("Client: Wrong addr", port++, NULL, 143 - this_ip_dest, -1, 100, 100, 0, NULL, 0, FAULT_TIMEOUT); 140 + this_ip_dest, -1, 100, 100, 0, NULL, 0, FAULT_KEYREJECT); 144 141 145 142 try_accept("rcv id != snd id", port++, DEFAULT_TEST_PASSWORD, 146 143 this_ip_dest, -1, 200, 100, 0, ··· 168 163 uint8_t sndid, uint8_t rcvid, 169 164 test_cnt cnt_expected, fault_t inj) 170 165 { 171 - struct tcp_ao_counters ao_cnt1, ao_cnt2; 172 - time_t timeout; 166 + struct tcp_counters cnt1, cnt2; 173 167 int sk, ret; 174 168 175 169 sk = socket(test_family, SOCK_STREAM, IPPROTO_TCP); ··· 178 174 if (pwd && test_add_key(sk, pwd, addr, prefix, sndid, rcvid)) 179 175 test_error("setsockopt(TCP_AO_ADD_KEY)"); 180 176 181 - if (pwd && test_get_tcp_ao_counters(sk, &ao_cnt1)) 182 - test_error("test_get_tcp_ao_counters()"); 177 + if (pwd && test_get_tcp_counters(sk, &cnt1)) 178 + test_error("test_get_tcp_counters()"); 183 179 184 180 synchronize_threads(); /* preparations done */ 185 181 186 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 187 - ret = _test_connect_socket(sk, this_ip_dest, port, timeout); 188 - 182 + ret = test_skpair_connect_poll(sk, this_ip_dest, port, cnt_expected, &sk_pair); 189 183 synchronize_threads(); /* before counter checks */ 190 184 if (ret < 0) { 185 + sk_pair = ret; 191 186 if (fault(KEYREJECT) && ret == -EKEYREJECTED) { 192 187 test_ok("%s: connect() was prevented", tst_name); 193 188 } else if (ret == -ETIMEDOUT && fault(TIMEOUT)) { ··· 205 202 else 206 203 test_ok("%s: connected", tst_name); 207 204 if (pwd && ret > 0) { 208 - if (test_get_tcp_ao_counters(sk, &ao_cnt2)) 209 - test_error("test_get_tcp_ao_counters()"); 210 - test_tcp_ao_counters_cmp(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected); 205 + if (test_get_tcp_counters(sk, &cnt2)) 206 + test_error("test_get_tcp_counters()"); 207 + test_assert_counters(tst_name, &cnt1, &cnt2, cnt_expected); 208 + } else if (pwd) { 209 + test_tcp_counters_free(&cnt1); 211 210 } 212 211 out: 213 212 synchronize_threads(); /* close() */ ··· 246 241 try_connect("Wrong rcv id", port++, DEFAULT_TEST_PASSWORD, 247 242 this_ip_dest, -1, 100, 100, 0, FAULT_TIMEOUT); 248 243 244 + /* 245 + * XXX: The test doesn't increase any counters, see tcp_make_synack(). 246 + * Potentially, it can be speed up by setting sk_pair = -ETIMEDOUT 247 + * but the price would be increased complexity of the tracer thread. 248 + */ 249 249 trace_ao_event_sk_expect(TCP_AO_SYNACK_NO_KEY, this_ip_dest, addr_any, 250 250 port, 0, 100, 100); 251 251 try_connect("Wrong snd id", port++, DEFAULT_TEST_PASSWORD,
+11 -11
tools/testing/selftests/net/tcp_ao/connect.c
··· 35 35 uint64_t before_aogood, after_aogood; 36 36 const size_t nr_packets = 20; 37 37 struct netstat *ns_before, *ns_after; 38 - struct tcp_ao_counters ao1, ao2; 38 + struct tcp_counters ao1, ao2; 39 39 40 40 if (sk < 0) 41 41 test_error("socket()"); ··· 50 50 51 51 ns_before = netstat_read(); 52 52 before_aogood = netstat_get(ns_before, "TCPAOGood", NULL); 53 - if (test_get_tcp_ao_counters(sk, &ao1)) 54 - test_error("test_get_tcp_ao_counters()"); 53 + if (test_get_tcp_counters(sk, &ao1)) 54 + test_error("test_get_tcp_counters()"); 55 55 56 - if (test_client_verify(sk, 100, nr_packets, TEST_TIMEOUT_SEC)) { 56 + if (test_client_verify(sk, 100, nr_packets)) { 57 57 test_fail("verify failed"); 58 58 return NULL; 59 59 } 60 60 61 61 ns_after = netstat_read(); 62 62 after_aogood = netstat_get(ns_after, "TCPAOGood", NULL); 63 - if (test_get_tcp_ao_counters(sk, &ao2)) 64 - test_error("test_get_tcp_ao_counters()"); 63 + if (test_get_tcp_counters(sk, &ao2)) 64 + test_error("test_get_tcp_counters()"); 65 65 netstat_print_diff(ns_before, ns_after); 66 66 netstat_free(ns_before); 67 67 netstat_free(ns_after); ··· 71 71 nr_packets, after_aogood, before_aogood); 72 72 return NULL; 73 73 } 74 - if (test_tcp_ao_counters_cmp("connect", &ao1, &ao2, TEST_CNT_GOOD)) 74 + if (test_assert_counters("connect", &ao1, &ao2, TEST_CNT_GOOD)) 75 75 return NULL; 76 76 77 77 test_ok("connect TCPAOGood %" PRIu64 "/%" PRIu64 "/%" PRIu64 " => %" PRIu64 "/%" PRIu64 "/%" PRIu64 ", sent %zu", 78 - before_aogood, ao1.ao_info_pkt_good, 79 - ao1.key_cnts[0].pkt_good, 80 - after_aogood, ao2.ao_info_pkt_good, 81 - ao2.key_cnts[0].pkt_good, 78 + before_aogood, ao1.ao.ao_info_pkt_good, 79 + ao1.ao.key_cnts[0].pkt_good, 80 + after_aogood, ao2.ao.ao_info_pkt_good, 81 + ao2.ao.key_cnts[0].pkt_good, 82 82 nr_packets); 83 83 return NULL; 84 84 }
+8 -9
tools/testing/selftests/net/tcp_ao/icmps-discard.c
··· 53 53 ssize_t test_quota = packet_size * packets_nr * 10; 54 54 uint64_t dest_unreach_a, dest_unreach_b; 55 55 uint64_t icmp_ignored_a, icmp_ignored_b; 56 - struct tcp_ao_counters ao_cnt1, ao_cnt2; 56 + struct tcp_counters cnt1, cnt2; 57 57 bool counter_not_found; 58 58 struct netstat *ns_after, *ns_before; 59 59 ssize_t bytes; ··· 61 61 ns_before = netstat_read(); 62 62 dest_unreach_a = netstat_get(ns_before, dst_unreach, NULL); 63 63 icmp_ignored_a = netstat_get(ns_before, tcpao_icmps, NULL); 64 - if (test_get_tcp_ao_counters(sk, &ao_cnt1)) 65 - test_error("test_get_tcp_ao_counters()"); 64 + if (test_get_tcp_counters(sk, &cnt1)) 65 + test_error("test_get_tcp_counters()"); 66 66 bytes = test_server_run(sk, test_quota, 0); 67 67 ns_after = netstat_read(); 68 68 netstat_print_diff(ns_before, ns_after); 69 69 dest_unreach_b = netstat_get(ns_after, dst_unreach, NULL); 70 70 icmp_ignored_b = netstat_get(ns_after, tcpao_icmps, 71 71 &counter_not_found); 72 - if (test_get_tcp_ao_counters(sk, &ao_cnt2)) 73 - test_error("test_get_tcp_ao_counters()"); 72 + if (test_get_tcp_counters(sk, &cnt2)) 73 + test_error("test_get_tcp_counters()"); 74 74 75 75 netstat_free(ns_before); 76 76 netstat_free(ns_after); ··· 91 91 return; 92 92 } 93 93 #ifdef TEST_ICMPS_ACCEPT 94 - test_tcp_ao_counters_cmp(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD); 94 + test_assert_counters(NULL, &cnt1, &cnt2, TEST_CNT_GOOD); 95 95 #else 96 - test_tcp_ao_counters_cmp(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD | TEST_CNT_AO_DROPPED_ICMP); 96 + test_assert_counters(NULL, &cnt1, &cnt2, TEST_CNT_GOOD | TEST_CNT_AO_DROPPED_ICMP); 97 97 #endif 98 98 if (icmp_ignored_a >= icmp_ignored_b) { 99 99 test_icmps_fail("%s counter didn't change: %" PRIu64 " >= %" PRIu64, ··· 395 395 396 396 static void send_interfered(int sk) 397 397 { 398 - const unsigned int timeout = TEST_TIMEOUT_SEC; 399 398 struct sockaddr_in6 src, dst; 400 399 socklen_t addr_sz; 401 400 ··· 408 409 while (1) { 409 410 uint32_t rcv_nxt; 410 411 411 - if (test_client_verify(sk, packet_size, packets_nr, timeout)) { 412 + if (test_client_verify(sk, packet_size, packets_nr)) { 412 413 test_fail("client: connection is broken"); 413 414 return; 414 415 }
+38 -38
tools/testing/selftests/net/tcp_ao/key-management.c
··· 629 629 } 630 630 631 631 static void verify_counters(const char *tst_name, bool is_listen_sk, bool server, 632 - struct tcp_ao_counters *a, struct tcp_ao_counters *b) 632 + struct tcp_counters *a, struct tcp_counters *b) 633 633 { 634 634 unsigned int i; 635 635 636 - __test_tcp_ao_counters_cmp(tst_name, a, b, TEST_CNT_GOOD); 636 + test_assert_counters_sk(tst_name, a, b, TEST_CNT_GOOD); 637 637 638 638 for (i = 0; i < collection.nr_keys; i++) { 639 639 struct test_key *key = &collection.keys[i]; ··· 652 652 rx_cnt_expected = key->used_on_server_tx; 653 653 } 654 654 655 - test_tcp_ao_key_counters_cmp(tst_name, a, b, 656 - rx_cnt_expected ? TEST_CNT_KEY_GOOD : 0, 657 - sndid, rcvid); 655 + test_assert_counters_key(tst_name, &a->ao, &b->ao, 656 + rx_cnt_expected ? TEST_CNT_KEY_GOOD : 0, 657 + sndid, rcvid); 658 658 } 659 - test_tcp_ao_counters_free(a); 660 - test_tcp_ao_counters_free(b); 659 + test_tcp_counters_free(a); 660 + test_tcp_counters_free(b); 661 661 test_ok("%s: passed counters checks", tst_name); 662 662 } 663 663 ··· 791 791 } 792 792 793 793 static int start_server(const char *tst_name, unsigned int port, size_t quota, 794 - struct tcp_ao_counters *begin, 794 + struct tcp_counters *begin, 795 795 unsigned int current_index, unsigned int rnext_index) 796 796 { 797 - struct tcp_ao_counters lsk_c1, lsk_c2; 797 + struct tcp_counters lsk_c1, lsk_c2; 798 798 ssize_t bytes; 799 799 int sk, lsk; 800 800 801 801 synchronize_threads(); /* 1: key collection initialized */ 802 802 lsk = key_collection_socket(true, port); 803 - if (test_get_tcp_ao_counters(lsk, &lsk_c1)) 804 - test_error("test_get_tcp_ao_counters()"); 803 + if (test_get_tcp_counters(lsk, &lsk_c1)) 804 + test_error("test_get_tcp_counters()"); 805 805 synchronize_threads(); /* 2: MKTs added => connect() */ 806 806 if (test_wait_fd(lsk, TEST_TIMEOUT_SEC, 0)) 807 807 test_error("test_wait_fd()"); ··· 809 809 sk = accept(lsk, NULL, NULL); 810 810 if (sk < 0) 811 811 test_error("accept()"); 812 - if (test_get_tcp_ao_counters(sk, begin)) 813 - test_error("test_get_tcp_ao_counters()"); 812 + if (test_get_tcp_counters(sk, begin)) 813 + test_error("test_get_tcp_counters()"); 814 814 815 815 synchronize_threads(); /* 3: accepted => send data */ 816 - if (test_get_tcp_ao_counters(lsk, &lsk_c2)) 817 - test_error("test_get_tcp_ao_counters()"); 816 + if (test_get_tcp_counters(lsk, &lsk_c2)) 817 + test_error("test_get_tcp_counters()"); 818 818 verify_keys(tst_name, lsk, true, true); 819 819 close(lsk); 820 820 ··· 830 830 } 831 831 832 832 static void end_server(const char *tst_name, int sk, 833 - struct tcp_ao_counters *begin) 833 + struct tcp_counters *begin) 834 834 { 835 - struct tcp_ao_counters end; 835 + struct tcp_counters end; 836 836 837 - if (test_get_tcp_ao_counters(sk, &end)) 838 - test_error("test_get_tcp_ao_counters()"); 837 + if (test_get_tcp_counters(sk, &end)) 838 + test_error("test_get_tcp_counters()"); 839 839 verify_keys(tst_name, sk, false, true); 840 840 841 841 synchronize_threads(); /* 4: verified => closed */ ··· 848 848 static void try_server_run(const char *tst_name, unsigned int port, size_t quota, 849 849 unsigned int current_index, unsigned int rnext_index) 850 850 { 851 - struct tcp_ao_counters tmp; 851 + struct tcp_counters tmp; 852 852 int sk; 853 853 854 854 sk = start_server(tst_name, port, quota, &tmp, ··· 860 860 size_t quota, unsigned int rotations, 861 861 unsigned int current_index, unsigned int rnext_index) 862 862 { 863 - struct tcp_ao_counters tmp; 863 + struct tcp_counters tmp; 864 864 unsigned int i; 865 865 int sk; 866 866 ··· 886 886 887 887 static int run_client(const char *tst_name, unsigned int port, 888 888 unsigned int nr_keys, int current_index, int rnext_index, 889 - struct tcp_ao_counters *before, 889 + struct tcp_counters *before, 890 890 const size_t msg_sz, const size_t msg_nr) 891 891 { 892 892 int sk; ··· 904 904 if (test_set_key(sk, sndid, rcvid)) 905 905 test_error("failed to set current/rnext keys"); 906 906 } 907 - if (before && test_get_tcp_ao_counters(sk, before)) 908 - test_error("test_get_tcp_ao_counters()"); 907 + if (before && test_get_tcp_counters(sk, before)) 908 + test_error("test_get_tcp_counters()"); 909 909 910 910 synchronize_threads(); /* 2: MKTs added => connect() */ 911 911 if (test_connect_socket(sk, this_ip_dest, port++) <= 0) ··· 918 918 collection.keys[rnext_index].used_on_server_tx = 1; 919 919 920 920 synchronize_threads(); /* 3: accepted => send data */ 921 - if (test_client_verify(sk, msg_sz, msg_nr, TEST_TIMEOUT_SEC)) { 921 + if (test_client_verify(sk, msg_sz, msg_nr)) { 922 922 test_fail("verify failed"); 923 923 close(sk); 924 924 if (before) 925 - test_tcp_ao_counters_free(before); 925 + test_tcp_counters_free(before); 926 926 return -1; 927 927 } 928 928 ··· 931 931 932 932 static int start_client(const char *tst_name, unsigned int port, 933 933 unsigned int nr_keys, int current_index, int rnext_index, 934 - struct tcp_ao_counters *before, 934 + struct tcp_counters *before, 935 935 const size_t msg_sz, const size_t msg_nr) 936 936 { 937 937 if (init_default_key_collection(nr_keys, true)) ··· 943 943 944 944 static void end_client(const char *tst_name, int sk, unsigned int nr_keys, 945 945 int current_index, int rnext_index, 946 - struct tcp_ao_counters *start) 946 + struct tcp_counters *start) 947 947 { 948 - struct tcp_ao_counters end; 948 + struct tcp_counters end; 949 949 950 950 /* Some application may become dependent on this kernel choice */ 951 951 if (current_index < 0) ··· 955 955 verify_current_rnext(tst_name, sk, 956 956 collection.keys[current_index].client_keyid, 957 957 collection.keys[rnext_index].server_keyid); 958 - if (start && test_get_tcp_ao_counters(sk, &end)) 959 - test_error("test_get_tcp_ao_counters()"); 958 + if (start && test_get_tcp_counters(sk, &end)) 959 + test_error("test_get_tcp_counters()"); 960 960 verify_keys(tst_name, sk, false, false); 961 961 synchronize_threads(); /* 4: verify => closed */ 962 962 close(sk); ··· 1016 1016 trace_ao_event_expect(TCP_AO_RNEXT_REQUEST, this_ip_addr, this_ip_dest, 1017 1017 -1, port, 0, -1, -1, -1, -1, -1, 1018 1018 -1, key->server_keyid, -1); 1019 - if (test_client_verify(sk, msg_len, nr_packets, TEST_TIMEOUT_SEC)) 1019 + if (test_client_verify(sk, msg_len, nr_packets)) 1020 1020 test_fail("verify failed"); 1021 1021 *rnext_index = i; 1022 1022 } ··· 1048 1048 unsigned int current_index, unsigned int rnext_index, 1049 1049 unsigned int rotate_to_index) 1050 1050 { 1051 - struct tcp_ao_counters tmp; 1051 + struct tcp_counters tmp; 1052 1052 int sk; 1053 1053 1054 1054 sk = start_client(tst_name, port, nr_keys, current_index, rnext_index, ··· 1061 1061 port, -1, 0, -1, -1, -1, -1, -1, 1062 1062 collection.keys[rotate_to_index].client_keyid, 1063 1063 collection.keys[current_index].client_keyid, -1); 1064 - if (test_client_verify(sk, msg_len, nr_packets, TEST_TIMEOUT_SEC)) 1064 + if (test_client_verify(sk, msg_len, nr_packets)) 1065 1065 test_fail("verify failed"); 1066 1066 /* There is a race here: between setting the current_key with 1067 1067 * setsockopt(TCP_AO_INFO) and starting to send some data - there ··· 1081 1081 unsigned int nr_keys, unsigned int rotations, 1082 1082 unsigned int current_index, unsigned int rnext_index) 1083 1083 { 1084 - struct tcp_ao_counters tmp; 1084 + struct tcp_counters tmp; 1085 1085 unsigned int i; 1086 1086 int sk; 1087 1087 ··· 1099 1099 collection.keys[i].server_keyid, -1); 1100 1100 if (test_set_key(sk, -1, collection.keys[i].server_keyid)) 1101 1101 test_error("Can't change the Rnext key"); 1102 - if (test_client_verify(sk, msg_len, nr_packets, TEST_TIMEOUT_SEC)) { 1102 + if (test_client_verify(sk, msg_len, nr_packets)) { 1103 1103 test_fail("verify failed"); 1104 1104 close(sk); 1105 - test_tcp_ao_counters_free(&tmp); 1105 + test_tcp_counters_free(&tmp); 1106 1106 return; 1107 1107 } 1108 1108 verify_current_rnext(tst_name, sk, -1, ··· 1116 1116 static void try_client_run(const char *tst_name, unsigned int port, 1117 1117 unsigned int nr_keys, int current_index, int rnext_index) 1118 1118 { 1119 - struct tcp_ao_counters tmp; 1119 + struct tcp_counters tmp; 1120 1120 int sk; 1121 1121 1122 1122 sk = start_client(tst_name, port, nr_keys, current_index, rnext_index,
+90 -24
tools/testing/selftests/net/tcp_ao/lib/aolib.h
··· 289 289 extern const unsigned int test_server_port; 290 290 extern int test_wait_fd(int sk, time_t sec, bool write); 291 291 extern int __test_connect_socket(int sk, const char *device, 292 - void *addr, size_t addr_sz, time_t timeout); 292 + void *addr, size_t addr_sz, bool async); 293 293 extern int __test_listen_socket(int backlog, void *addr, size_t addr_sz); 294 294 295 295 static inline int test_listen_socket(const union tcp_addr taddr, ··· 331 331 * If set to 0 - kernel will try to retransmit SYN number of times, set in 332 332 * /proc/sys/net/ipv4/tcp_syn_retries 333 333 * By default set to 1 to make tests pass faster on non-busy machine. 334 + * [in process of removal, don't use in new tests] 334 335 */ 335 336 #ifndef TEST_RETRANSMIT_SEC 336 337 #define TEST_RETRANSMIT_SEC 1 337 338 #endif 338 339 339 340 static inline int _test_connect_socket(int sk, const union tcp_addr taddr, 340 - unsigned int port, time_t timeout) 341 + unsigned int port, bool async) 341 342 { 342 343 sockaddr_af addr; 343 344 344 345 tcp_addr_to_sockaddr_in(&addr, &taddr, htons(port)); 345 346 return __test_connect_socket(sk, veth_name, 346 - (void *)&addr, sizeof(addr), timeout); 347 + (void *)&addr, sizeof(addr), async); 347 348 } 348 349 349 350 static inline int test_connect_socket(int sk, const union tcp_addr taddr, 350 351 unsigned int port) 351 352 { 352 - return _test_connect_socket(sk, taddr, port, TEST_TIMEOUT_SEC); 353 + return _test_connect_socket(sk, taddr, port, false); 353 354 } 354 355 355 356 extern int __test_set_md5(int sk, void *addr, size_t addr_sz, ··· 484 483 } 485 484 486 485 extern ssize_t test_server_run(int sk, ssize_t quota, time_t timeout_sec); 487 - extern ssize_t test_client_loop(int sk, char *buf, size_t buf_sz, 488 - const size_t msg_len, time_t timeout_sec); 489 - extern int test_client_verify(int sk, const size_t msg_len, const size_t nr, 490 - time_t timeout_sec); 486 + extern int test_client_verify(int sk, const size_t msg_len, const size_t nr); 491 487 492 488 struct tcp_ao_key_counters { 493 489 uint8_t sndid; ··· 510 512 size_t nr_keys; 511 513 struct tcp_ao_key_counters *key_cnts; 512 514 }; 513 - extern int test_get_tcp_ao_counters(int sk, struct tcp_ao_counters *out); 515 + 516 + struct tcp_counters { 517 + struct tcp_ao_counters ao; 518 + uint64_t netns_md5_notfound; 519 + uint64_t netns_md5_unexpected; 520 + uint64_t netns_md5_failure; 521 + }; 522 + 523 + extern int test_get_tcp_counters(int sk, struct tcp_counters *out); 514 524 515 525 #define TEST_CNT_KEY_GOOD BIT(0) 516 526 #define TEST_CNT_KEY_BAD BIT(1) ··· 532 526 #define TEST_CNT_NS_KEY_NOT_FOUND BIT(9) 533 527 #define TEST_CNT_NS_AO_REQUIRED BIT(10) 534 528 #define TEST_CNT_NS_DROPPED_ICMP BIT(11) 529 + #define TEST_CNT_NS_MD5_NOT_FOUND BIT(12) 530 + #define TEST_CNT_NS_MD5_UNEXPECTED BIT(13) 531 + #define TEST_CNT_NS_MD5_FAILURE BIT(14) 535 532 typedef uint16_t test_cnt; 533 + 534 + #define _for_each_counter(f) \ 535 + do { \ 536 + /* per-netns */ \ 537 + f(ao.netns_ao_good, TEST_CNT_NS_GOOD); \ 538 + f(ao.netns_ao_bad, TEST_CNT_NS_BAD); \ 539 + f(ao.netns_ao_key_not_found, TEST_CNT_NS_KEY_NOT_FOUND); \ 540 + f(ao.netns_ao_required, TEST_CNT_NS_AO_REQUIRED); \ 541 + f(ao.netns_ao_dropped_icmp, TEST_CNT_NS_DROPPED_ICMP); \ 542 + /* per-socket */ \ 543 + f(ao.ao_info_pkt_good, TEST_CNT_SOCK_GOOD); \ 544 + f(ao.ao_info_pkt_bad, TEST_CNT_SOCK_BAD); \ 545 + f(ao.ao_info_pkt_key_not_found, TEST_CNT_SOCK_KEY_NOT_FOUND); \ 546 + f(ao.ao_info_pkt_ao_required, TEST_CNT_SOCK_AO_REQUIRED); \ 547 + f(ao.ao_info_pkt_dropped_icmp, TEST_CNT_SOCK_DROPPED_ICMP); \ 548 + /* non-AO */ \ 549 + f(netns_md5_notfound, TEST_CNT_NS_MD5_NOT_FOUND); \ 550 + f(netns_md5_unexpected, TEST_CNT_NS_MD5_UNEXPECTED); \ 551 + f(netns_md5_failure, TEST_CNT_NS_MD5_FAILURE); \ 552 + } while (0) 536 553 537 554 #define TEST_CNT_AO_GOOD (TEST_CNT_SOCK_GOOD | TEST_CNT_NS_GOOD) 538 555 #define TEST_CNT_AO_BAD (TEST_CNT_SOCK_BAD | TEST_CNT_NS_BAD) ··· 568 539 #define TEST_CNT_GOOD (TEST_CNT_KEY_GOOD | TEST_CNT_AO_GOOD) 569 540 #define TEST_CNT_BAD (TEST_CNT_KEY_BAD | TEST_CNT_AO_BAD) 570 541 571 - extern int __test_tcp_ao_counters_cmp(const char *tst_name, 572 - struct tcp_ao_counters *before, struct tcp_ao_counters *after, 542 + extern test_cnt test_cmp_counters(struct tcp_counters *before, 543 + struct tcp_counters *after); 544 + extern int test_assert_counters_sk(const char *tst_name, 545 + struct tcp_counters *before, struct tcp_counters *after, 573 546 test_cnt expected); 574 - extern int test_tcp_ao_key_counters_cmp(const char *tst_name, 547 + extern int test_assert_counters_key(const char *tst_name, 575 548 struct tcp_ao_counters *before, struct tcp_ao_counters *after, 576 549 test_cnt expected, int sndid, int rcvid); 577 - extern void test_tcp_ao_counters_free(struct tcp_ao_counters *cnts); 550 + extern void test_tcp_counters_free(struct tcp_counters *cnts); 551 + 578 552 /* 579 - * Frees buffers allocated in test_get_tcp_ao_counters(). 553 + * Polling for netns and socket counters during select()/connect() and also 554 + * client/server messaging. Instead of constant timeout on underlying select(), 555 + * check the counters and return early. This allows to pass the tests where 556 + * timeout is expected without waiting for that fixing timeout (tests speed-up). 557 + * Previously shorter timeouts were used for tests expecting to time out, 558 + * but that leaded to sporadic false positives on counter checks failures, 559 + * as one second timeouts aren't enough for TCP retransmit. 560 + * 561 + * Two sides of the socketpair (client/server) should synchronize failures 562 + * using a shared variable *err, so that they can detect the other side's 563 + * failure. 564 + */ 565 + extern int test_skpair_wait_poll(int sk, bool write, test_cnt cond, 566 + volatile int *err); 567 + extern int _test_skpair_connect_poll(int sk, const char *device, 568 + void *addr, size_t addr_sz, 569 + test_cnt cond, volatile int *err); 570 + static inline int test_skpair_connect_poll(int sk, const union tcp_addr taddr, 571 + unsigned int port, 572 + test_cnt cond, volatile int *err) 573 + { 574 + sockaddr_af addr; 575 + 576 + tcp_addr_to_sockaddr_in(&addr, &taddr, htons(port)); 577 + return _test_skpair_connect_poll(sk, veth_name, 578 + (void *)&addr, sizeof(addr), cond, err); 579 + } 580 + 581 + extern int test_skpair_client(int sk, const size_t msg_len, const size_t nr, 582 + test_cnt cond, volatile int *err); 583 + extern int test_skpair_server(int sk, ssize_t quota, 584 + test_cnt cond, volatile int *err); 585 + 586 + /* 587 + * Frees buffers allocated in test_get_tcp_counters(). 580 588 * The function doesn't expect new keys or keys removed between calls 581 - * to test_get_tcp_ao_counters(). Check key counters manually if they 589 + * to test_get_tcp_counters(). Check key counters manually if they 582 590 * may change. 583 591 */ 584 - static inline int test_tcp_ao_counters_cmp(const char *tst_name, 585 - struct tcp_ao_counters *before, 586 - struct tcp_ao_counters *after, 587 - test_cnt expected) 592 + static inline int test_assert_counters(const char *tst_name, 593 + struct tcp_counters *before, 594 + struct tcp_counters *after, 595 + test_cnt expected) 588 596 { 589 597 int ret; 590 598 591 - ret = __test_tcp_ao_counters_cmp(tst_name, before, after, expected); 599 + ret = test_assert_counters_sk(tst_name, before, after, expected); 592 600 if (ret) 593 601 goto out; 594 - ret = test_tcp_ao_key_counters_cmp(tst_name, before, after, 595 - expected, -1, -1); 602 + ret = test_assert_counters_key(tst_name, &before->ao, &after->ao, 603 + expected, -1, -1); 596 604 out: 597 - test_tcp_ao_counters_free(before); 598 - test_tcp_ao_counters_free(after); 605 + test_tcp_counters_free(before); 606 + test_tcp_counters_free(after); 599 607 return ret; 600 608 } 601 609
+2 -5
tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
··· 427 427 test_print("trace event filter %s [%s:%d => %s:%d, L3index %d, flags: %s%s%s%s%s, keyid: %d, rnext: %d, maclen: %d, sne: %d] = %zu", 428 428 trace_event_names[e->type], 429 429 src, e->src_port, dst, e->dst_port, e->L3index, 430 - (e->fin > 0) ? "F" : (e->fin == 0) ? "!F" : "", 431 - (e->syn > 0) ? "S" : (e->syn == 0) ? "!S" : "", 432 - (e->rst > 0) ? "R" : (e->rst == 0) ? "!R" : "", 433 - (e->psh > 0) ? "P" : (e->psh == 0) ? "!P" : "", 434 - (e->ack > 0) ? "." : (e->ack == 0) ? "!." : "", 430 + e->fin ? "F" : "", e->syn ? "S" : "", e->rst ? "R" : "", 431 + e->psh ? "P" : "", e->ack ? "." : "", 435 432 e->keyid, e->rnext, e->maclen, e->sne, e->matched); 436 433 } 437 434
+225 -90
tools/testing/selftests/net/tcp_ao/lib/sock.c
··· 34 34 return sk; 35 35 } 36 36 37 - int test_wait_fd(int sk, time_t sec, bool write) 37 + static int __test_wait_fd(int sk, struct timeval *tv, bool write) 38 38 { 39 - struct timeval tv = { .tv_sec = sec }; 40 - struct timeval *ptv = NULL; 41 39 fd_set fds, efds; 42 40 int ret; 43 41 socklen_t slen = sizeof(ret); ··· 45 47 FD_ZERO(&efds); 46 48 FD_SET(sk, &efds); 47 49 48 - if (sec) 49 - ptv = &tv; 50 - 51 50 errno = 0; 52 51 if (write) 53 - ret = select(sk + 1, NULL, &fds, &efds, ptv); 52 + ret = select(sk + 1, NULL, &fds, &efds, tv); 54 53 else 55 - ret = select(sk + 1, &fds, NULL, &efds, ptv); 54 + ret = select(sk + 1, &fds, NULL, &efds, tv); 56 55 if (ret < 0) 57 56 return -errno; 58 57 if (ret == 0) { ··· 64 69 return 0; 65 70 } 66 71 72 + int test_wait_fd(int sk, time_t sec, bool write) 73 + { 74 + struct timeval tv = { .tv_sec = sec, }; 75 + 76 + return __test_wait_fd(sk, sec ? &tv : NULL, write); 77 + } 78 + 79 + static bool __skpair_poll_should_stop(int sk, struct tcp_counters *c, 80 + test_cnt condition) 81 + { 82 + struct tcp_counters c2; 83 + test_cnt diff; 84 + 85 + if (test_get_tcp_counters(sk, &c2)) 86 + test_error("test_get_tcp_counters()"); 87 + 88 + diff = test_cmp_counters(c, &c2); 89 + test_tcp_counters_free(&c2); 90 + return (diff & condition) == condition; 91 + } 92 + 93 + /* How often wake up and check netns counters & paired (*err) */ 94 + #define POLL_USEC 150 95 + static int __test_skpair_poll(int sk, bool write, uint64_t timeout, 96 + struct tcp_counters *c, test_cnt cond, 97 + volatile int *err) 98 + { 99 + uint64_t t; 100 + 101 + for (t = 0; t <= timeout * 1000000; t += POLL_USEC) { 102 + struct timeval tv = { .tv_usec = POLL_USEC, }; 103 + int ret; 104 + 105 + ret = __test_wait_fd(sk, &tv, write); 106 + if (ret != -ETIMEDOUT) 107 + return ret; 108 + if (c && cond && __skpair_poll_should_stop(sk, c, cond)) 109 + break; 110 + if (err && *err) 111 + return *err; 112 + } 113 + if (err) 114 + *err = -ETIMEDOUT; 115 + return -ETIMEDOUT; 116 + } 117 + 67 118 int __test_connect_socket(int sk, const char *device, 68 - void *addr, size_t addr_sz, time_t timeout) 119 + void *addr, size_t addr_sz, bool async) 69 120 { 70 121 long flags; 71 122 int err; ··· 123 82 test_error("setsockopt(SO_BINDTODEVICE, %s)", device); 124 83 } 125 84 126 - if (!timeout) { 127 - err = connect(sk, addr, addr_sz); 128 - if (err) { 129 - err = -errno; 130 - goto out; 131 - } 132 - return 0; 133 - } 134 - 135 85 flags = fcntl(sk, F_GETFL); 136 86 if ((flags < 0) || (fcntl(sk, F_SETFL, flags | O_NONBLOCK) < 0)) 137 87 test_error("fcntl()"); ··· 132 100 err = -errno; 133 101 goto out; 134 102 } 135 - if (timeout < 0) 103 + if (async) 136 104 return sk; 137 - err = test_wait_fd(sk, timeout, 1); 105 + err = test_wait_fd(sk, TEST_TIMEOUT_SEC, 1); 138 106 if (err) 139 107 goto out; 140 108 } ··· 143 111 out: 144 112 close(sk); 145 113 return err; 114 + } 115 + 116 + int test_skpair_wait_poll(int sk, bool write, 117 + test_cnt cond, volatile int *err) 118 + { 119 + struct tcp_counters c; 120 + int ret; 121 + 122 + *err = 0; 123 + if (test_get_tcp_counters(sk, &c)) 124 + test_error("test_get_tcp_counters()"); 125 + synchronize_threads(); /* 1: init skpair & read nscounters */ 126 + 127 + ret = __test_skpair_poll(sk, write, TEST_TIMEOUT_SEC, &c, cond, err); 128 + test_tcp_counters_free(&c); 129 + return ret; 130 + } 131 + 132 + int _test_skpair_connect_poll(int sk, const char *device, 133 + void *addr, size_t addr_sz, 134 + test_cnt condition, volatile int *err) 135 + { 136 + struct tcp_counters c; 137 + int ret; 138 + 139 + *err = 0; 140 + if (test_get_tcp_counters(sk, &c)) 141 + test_error("test_get_tcp_counters()"); 142 + synchronize_threads(); /* 1: init skpair & read nscounters */ 143 + ret = __test_connect_socket(sk, device, addr, addr_sz, true); 144 + if (ret < 0) { 145 + test_tcp_counters_free(&c); 146 + return (*err = ret); 147 + } 148 + ret = __test_skpair_poll(sk, 1, TEST_TIMEOUT_SEC, &c, condition, err); 149 + if (ret < 0) 150 + close(sk); 151 + test_tcp_counters_free(&c); 152 + return ret; 146 153 } 147 154 148 155 int __test_set_md5(int sk, void *addr, size_t addr_sz, uint8_t prefix, ··· 404 333 return 0; 405 334 } 406 335 407 - int test_get_tcp_ao_counters(int sk, struct tcp_ao_counters *out) 336 + int test_get_tcp_counters(int sk, struct tcp_counters *out) 408 337 { 409 338 struct tcp_ao_getsockopt *key_dump; 410 339 socklen_t key_dump_sz = sizeof(*key_dump); 411 340 struct tcp_ao_info_opt info = {}; 412 - bool c1, c2, c3, c4, c5; 341 + bool c1, c2, c3, c4, c5, c6, c7, c8; 413 342 struct netstat *ns; 414 343 int err, nr_keys; 415 344 ··· 417 346 418 347 /* per-netns */ 419 348 ns = netstat_read(); 420 - out->netns_ao_good = netstat_get(ns, "TCPAOGood", &c1); 421 - out->netns_ao_bad = netstat_get(ns, "TCPAOBad", &c2); 422 - out->netns_ao_key_not_found = netstat_get(ns, "TCPAOKeyNotFound", &c3); 423 - out->netns_ao_required = netstat_get(ns, "TCPAORequired", &c4); 424 - out->netns_ao_dropped_icmp = netstat_get(ns, "TCPAODroppedIcmps", &c5); 349 + out->ao.netns_ao_good = netstat_get(ns, "TCPAOGood", &c1); 350 + out->ao.netns_ao_bad = netstat_get(ns, "TCPAOBad", &c2); 351 + out->ao.netns_ao_key_not_found = netstat_get(ns, "TCPAOKeyNotFound", &c3); 352 + out->ao.netns_ao_required = netstat_get(ns, "TCPAORequired", &c4); 353 + out->ao.netns_ao_dropped_icmp = netstat_get(ns, "TCPAODroppedIcmps", &c5); 354 + out->netns_md5_notfound = netstat_get(ns, "TCPMD5NotFound", &c6); 355 + out->netns_md5_unexpected = netstat_get(ns, "TCPMD5Unexpected", &c7); 356 + out->netns_md5_failure = netstat_get(ns, "TCPMD5Failure", &c8); 425 357 netstat_free(ns); 426 - if (c1 || c2 || c3 || c4 || c5) 358 + if (c1 || c2 || c3 || c4 || c5 || c6 || c7 || c8) 427 359 return -EOPNOTSUPP; 428 360 429 361 err = test_get_ao_info(sk, &info); 362 + if (err == -ENOENT) 363 + return 0; 430 364 if (err) 431 365 return err; 432 366 433 367 /* per-socket */ 434 - out->ao_info_pkt_good = info.pkt_good; 435 - out->ao_info_pkt_bad = info.pkt_bad; 436 - out->ao_info_pkt_key_not_found = info.pkt_key_not_found; 437 - out->ao_info_pkt_ao_required = info.pkt_ao_required; 438 - out->ao_info_pkt_dropped_icmp = info.pkt_dropped_icmp; 368 + out->ao.ao_info_pkt_good = info.pkt_good; 369 + out->ao.ao_info_pkt_bad = info.pkt_bad; 370 + out->ao.ao_info_pkt_key_not_found = info.pkt_key_not_found; 371 + out->ao.ao_info_pkt_ao_required = info.pkt_ao_required; 372 + out->ao.ao_info_pkt_dropped_icmp = info.pkt_dropped_icmp; 439 373 440 374 /* per-key */ 441 375 nr_keys = test_get_ao_keys_nr(sk); ··· 448 372 return nr_keys; 449 373 if (nr_keys == 0) 450 374 test_error("test_get_ao_keys_nr() == 0"); 451 - out->nr_keys = (size_t)nr_keys; 375 + out->ao.nr_keys = (size_t)nr_keys; 452 376 key_dump = calloc(nr_keys, key_dump_sz); 453 377 if (!key_dump) 454 378 return -errno; ··· 462 386 return -errno; 463 387 } 464 388 465 - out->key_cnts = calloc(nr_keys, sizeof(out->key_cnts[0])); 466 - if (!out->key_cnts) { 389 + out->ao.key_cnts = calloc(nr_keys, sizeof(out->ao.key_cnts[0])); 390 + if (!out->ao.key_cnts) { 467 391 free(key_dump); 468 392 return -errno; 469 393 } 470 394 471 395 while (nr_keys--) { 472 - out->key_cnts[nr_keys].sndid = key_dump[nr_keys].sndid; 473 - out->key_cnts[nr_keys].rcvid = key_dump[nr_keys].rcvid; 474 - out->key_cnts[nr_keys].pkt_good = key_dump[nr_keys].pkt_good; 475 - out->key_cnts[nr_keys].pkt_bad = key_dump[nr_keys].pkt_bad; 396 + out->ao.key_cnts[nr_keys].sndid = key_dump[nr_keys].sndid; 397 + out->ao.key_cnts[nr_keys].rcvid = key_dump[nr_keys].rcvid; 398 + out->ao.key_cnts[nr_keys].pkt_good = key_dump[nr_keys].pkt_good; 399 + out->ao.key_cnts[nr_keys].pkt_bad = key_dump[nr_keys].pkt_bad; 476 400 } 477 401 free(key_dump); 478 402 479 403 return 0; 480 404 } 481 405 482 - int __test_tcp_ao_counters_cmp(const char *tst_name, 483 - struct tcp_ao_counters *before, 484 - struct tcp_ao_counters *after, 485 - test_cnt expected) 406 + test_cnt test_cmp_counters(struct tcp_counters *before, 407 + struct tcp_counters *after) 486 408 { 487 - #define __cmp_ao(cnt, expecting_inc) \ 409 + #define __cmp(cnt, e_cnt) \ 410 + do { \ 411 + if (before->cnt > after->cnt) \ 412 + test_error("counter " __stringify(cnt) " decreased"); \ 413 + if (before->cnt != after->cnt) \ 414 + ret |= e_cnt; \ 415 + } while (0) 416 + 417 + test_cnt ret = 0; 418 + size_t i; 419 + 420 + if (before->ao.nr_keys != after->ao.nr_keys) 421 + test_error("the number of keys has changed"); 422 + 423 + _for_each_counter(__cmp); 424 + 425 + i = before->ao.nr_keys; 426 + while (i--) { 427 + __cmp(ao.key_cnts[i].pkt_good, TEST_CNT_KEY_GOOD); 428 + __cmp(ao.key_cnts[i].pkt_bad, TEST_CNT_KEY_BAD); 429 + } 430 + #undef __cmp 431 + return ret; 432 + } 433 + 434 + int test_assert_counters_sk(const char *tst_name, 435 + struct tcp_counters *before, 436 + struct tcp_counters *after, 437 + test_cnt expected) 438 + { 439 + #define __cmp_ao(cnt, e_cnt) \ 488 440 do { \ 489 441 if (before->cnt > after->cnt) { \ 490 442 test_fail("%s: Decreased counter " __stringify(cnt) " %" PRIu64 " > %" PRIu64, \ 491 - tst_name ?: "", before->cnt, after->cnt); \ 443 + tst_name ?: "", before->cnt, after->cnt); \ 492 444 return -1; \ 493 445 } \ 494 - if ((before->cnt != after->cnt) != (expecting_inc)) { \ 446 + if ((before->cnt != after->cnt) != !!(expected & e_cnt)) { \ 495 447 test_fail("%s: Counter " __stringify(cnt) " was %sexpected to increase %" PRIu64 " => %" PRIu64, \ 496 - tst_name ?: "", (expecting_inc) ? "" : "not ", \ 448 + tst_name ?: "", (expected & e_cnt) ? "" : "not ", \ 497 449 before->cnt, after->cnt); \ 498 450 return -1; \ 499 451 } \ 500 - } while(0) 452 + } while (0) 501 453 502 454 errno = 0; 503 - /* per-netns */ 504 - __cmp_ao(netns_ao_good, !!(expected & TEST_CNT_NS_GOOD)); 505 - __cmp_ao(netns_ao_bad, !!(expected & TEST_CNT_NS_BAD)); 506 - __cmp_ao(netns_ao_key_not_found, 507 - !!(expected & TEST_CNT_NS_KEY_NOT_FOUND)); 508 - __cmp_ao(netns_ao_required, !!(expected & TEST_CNT_NS_AO_REQUIRED)); 509 - __cmp_ao(netns_ao_dropped_icmp, 510 - !!(expected & TEST_CNT_NS_DROPPED_ICMP)); 511 - /* per-socket */ 512 - __cmp_ao(ao_info_pkt_good, !!(expected & TEST_CNT_SOCK_GOOD)); 513 - __cmp_ao(ao_info_pkt_bad, !!(expected & TEST_CNT_SOCK_BAD)); 514 - __cmp_ao(ao_info_pkt_key_not_found, 515 - !!(expected & TEST_CNT_SOCK_KEY_NOT_FOUND)); 516 - __cmp_ao(ao_info_pkt_ao_required, !!(expected & TEST_CNT_SOCK_AO_REQUIRED)); 517 - __cmp_ao(ao_info_pkt_dropped_icmp, 518 - !!(expected & TEST_CNT_SOCK_DROPPED_ICMP)); 455 + _for_each_counter(__cmp_ao); 519 456 return 0; 520 457 #undef __cmp_ao 521 458 } 522 459 523 - int test_tcp_ao_key_counters_cmp(const char *tst_name, 524 - struct tcp_ao_counters *before, 525 - struct tcp_ao_counters *after, 526 - test_cnt expected, 527 - int sndid, int rcvid) 460 + int test_assert_counters_key(const char *tst_name, 461 + struct tcp_ao_counters *before, 462 + struct tcp_ao_counters *after, 463 + test_cnt expected, int sndid, int rcvid) 528 464 { 529 465 size_t i; 530 - #define __cmp_ao(i, cnt, expecting_inc) \ 466 + #define __cmp_ao(i, cnt, e_cnt) \ 531 467 do { \ 532 468 if (before->key_cnts[i].cnt > after->key_cnts[i].cnt) { \ 533 469 test_fail("%s: Decreased counter " __stringify(cnt) " %" PRIu64 " > %" PRIu64 " for key %u:%u", \ ··· 549 461 before->key_cnts[i].rcvid); \ 550 462 return -1; \ 551 463 } \ 552 - if ((before->key_cnts[i].cnt != after->key_cnts[i].cnt) != (expecting_inc)) { \ 464 + if ((before->key_cnts[i].cnt != after->key_cnts[i].cnt) != !!(expected & e_cnt)) { \ 553 465 test_fail("%s: Counter " __stringify(cnt) " was %sexpected to increase %" PRIu64 " => %" PRIu64 " for key %u:%u", \ 554 - tst_name ?: "", (expecting_inc) ? "" : "not ",\ 466 + tst_name ?: "", (expected & e_cnt) ? "" : "not ",\ 555 467 before->key_cnts[i].cnt, \ 556 468 after->key_cnts[i].cnt, \ 557 469 before->key_cnts[i].sndid, \ 558 470 before->key_cnts[i].rcvid); \ 559 471 return -1; \ 560 472 } \ 561 - } while(0) 473 + } while (0) 562 474 563 475 if (before->nr_keys != after->nr_keys) { 564 476 test_fail("%s: Keys changed on the socket %zu != %zu", ··· 573 485 continue; 574 486 if (rcvid >= 0 && before->key_cnts[i].rcvid != rcvid) 575 487 continue; 576 - __cmp_ao(i, pkt_good, !!(expected & TEST_CNT_KEY_GOOD)); 577 - __cmp_ao(i, pkt_bad, !!(expected & TEST_CNT_KEY_BAD)); 488 + __cmp_ao(i, pkt_good, TEST_CNT_KEY_GOOD); 489 + __cmp_ao(i, pkt_bad, TEST_CNT_KEY_BAD); 578 490 } 579 491 return 0; 580 492 #undef __cmp_ao 581 493 } 582 494 583 - void test_tcp_ao_counters_free(struct tcp_ao_counters *cnts) 495 + void test_tcp_counters_free(struct tcp_counters *cnts) 584 496 { 585 - free(cnts->key_cnts); 497 + free(cnts->ao.key_cnts); 586 498 } 587 499 588 500 #define TEST_BUF_SIZE 4096 589 - ssize_t test_server_run(int sk, ssize_t quota, time_t timeout_sec) 501 + static ssize_t _test_server_run(int sk, ssize_t quota, struct tcp_counters *c, 502 + test_cnt cond, volatile int *err, 503 + time_t timeout_sec) 590 504 { 591 505 ssize_t total = 0; 592 506 ··· 597 507 ssize_t bytes, sent; 598 508 int ret; 599 509 600 - ret = test_wait_fd(sk, timeout_sec, 0); 510 + ret = __test_skpair_poll(sk, 0, timeout_sec, c, cond, err); 601 511 if (ret) 602 512 return ret; 603 513 ··· 608 518 if (bytes == 0) 609 519 break; 610 520 611 - ret = test_wait_fd(sk, timeout_sec, 1); 521 + ret = __test_skpair_poll(sk, 1, timeout_sec, c, cond, err); 612 522 if (ret) 613 523 return ret; 614 524 ··· 623 533 return total; 624 534 } 625 535 626 - ssize_t test_client_loop(int sk, char *buf, size_t buf_sz, 627 - const size_t msg_len, time_t timeout_sec) 536 + ssize_t test_server_run(int sk, ssize_t quota, time_t timeout_sec) 537 + { 538 + return _test_server_run(sk, quota, NULL, 0, NULL, 539 + timeout_sec ?: TEST_TIMEOUT_SEC); 540 + } 541 + 542 + int test_skpair_server(int sk, ssize_t quota, test_cnt cond, volatile int *err) 543 + { 544 + struct tcp_counters c; 545 + ssize_t ret; 546 + 547 + *err = 0; 548 + if (test_get_tcp_counters(sk, &c)) 549 + test_error("test_get_tcp_counters()"); 550 + synchronize_threads(); /* 1: init skpair & read nscounters */ 551 + 552 + ret = _test_server_run(sk, quota, &c, cond, err, TEST_TIMEOUT_SEC); 553 + test_tcp_counters_free(&c); 554 + return ret; 555 + } 556 + 557 + static ssize_t test_client_loop(int sk, size_t buf_sz, const size_t msg_len, 558 + struct tcp_counters *c, test_cnt cond, 559 + volatile int *err) 628 560 { 629 561 char msg[msg_len]; 630 562 int nodelay = 1; 563 + char *buf; 631 564 size_t i; 565 + 566 + buf = alloca(buf_sz); 567 + if (!buf) 568 + return -ENOMEM; 569 + randomize_buffer(buf, buf_sz); 632 570 633 571 if (setsockopt(sk, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay))) 634 572 test_error("setsockopt(TCP_NODELAY)"); ··· 665 547 size_t sent, bytes = min(msg_len, buf_sz - i); 666 548 int ret; 667 549 668 - ret = test_wait_fd(sk, timeout_sec, 1); 550 + ret = __test_skpair_poll(sk, 1, TEST_TIMEOUT_SEC, c, cond, err); 669 551 if (ret) 670 552 return ret; 671 553 ··· 679 561 do { 680 562 ssize_t got; 681 563 682 - ret = test_wait_fd(sk, timeout_sec, 0); 564 + ret = __test_skpair_poll(sk, 0, TEST_TIMEOUT_SEC, 565 + c, cond, err); 683 566 if (ret) 684 567 return ret; 685 568 ··· 699 580 return i; 700 581 } 701 582 702 - int test_client_verify(int sk, const size_t msg_len, const size_t nr, 703 - time_t timeout_sec) 583 + int test_client_verify(int sk, const size_t msg_len, const size_t nr) 704 584 { 705 585 size_t buf_sz = msg_len * nr; 706 - char *buf = alloca(buf_sz); 707 586 ssize_t ret; 708 587 709 - randomize_buffer(buf, buf_sz); 710 - ret = test_client_loop(sk, buf, buf_sz, msg_len, timeout_sec); 588 + ret = test_client_loop(sk, buf_sz, msg_len, NULL, 0, NULL); 589 + if (ret < 0) 590 + return (int)ret; 591 + return ret != buf_sz ? -1 : 0; 592 + } 593 + 594 + int test_skpair_client(int sk, const size_t msg_len, const size_t nr, 595 + test_cnt cond, volatile int *err) 596 + { 597 + struct tcp_counters c; 598 + size_t buf_sz = msg_len * nr; 599 + ssize_t ret; 600 + 601 + *err = 0; 602 + if (test_get_tcp_counters(sk, &c)) 603 + test_error("test_get_tcp_counters()"); 604 + synchronize_threads(); /* 1: init skpair & read nscounters */ 605 + 606 + ret = test_client_loop(sk, buf_sz, msg_len, &c, cond, err); 607 + test_tcp_counters_free(&c); 711 608 if (ret < 0) 712 609 return (int)ret; 713 610 return ret != buf_sz ? -1 : 0;
+37 -38
tools/testing/selftests/net/tcp_ao/restore.c
··· 16 16 static void try_server_run(const char *tst_name, unsigned int port, 17 17 fault_t inj, test_cnt cnt_expected) 18 18 { 19 + test_cnt poll_cnt = (cnt_expected == TEST_CNT_GOOD) ? 0 : cnt_expected; 19 20 const char *cnt_name = "TCPAOGood"; 20 - struct tcp_ao_counters ao1, ao2; 21 + struct tcp_counters cnt1, cnt2; 21 22 uint64_t before_cnt, after_cnt; 22 - int sk, lsk; 23 - time_t timeout; 23 + int sk, lsk, dummy; 24 24 ssize_t bytes; 25 25 26 26 if (fault(TIMEOUT)) ··· 48 48 } 49 49 50 50 before_cnt = netstat_get_one(cnt_name, NULL); 51 - if (test_get_tcp_ao_counters(sk, &ao1)) 52 - test_error("test_get_tcp_ao_counters()"); 51 + if (test_get_tcp_counters(sk, &cnt1)) 52 + test_error("test_get_tcp_counters()"); 53 53 54 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 55 - bytes = test_server_run(sk, quota, timeout); 54 + bytes = test_skpair_server(sk, quota, poll_cnt, &dummy); 56 55 if (fault(TIMEOUT)) { 57 56 if (bytes > 0) 58 57 test_fail("%s: server served: %zd", tst_name, bytes); ··· 64 65 test_ok("%s: server alive", tst_name); 65 66 } 66 67 synchronize_threads(); /* 3: counters checks */ 67 - if (test_get_tcp_ao_counters(sk, &ao2)) 68 - test_error("test_get_tcp_ao_counters()"); 68 + if (test_get_tcp_counters(sk, &cnt2)) 69 + test_error("test_get_tcp_counters()"); 69 70 after_cnt = netstat_get_one(cnt_name, NULL); 70 71 71 - test_tcp_ao_counters_cmp(tst_name, &ao1, &ao2, cnt_expected); 72 + test_assert_counters(tst_name, &cnt1, &cnt2, cnt_expected); 72 73 73 74 if (after_cnt <= before_cnt) { 74 - test_fail("%s: %s counter did not increase: %" PRIu64 " <= %" PRIu64, 75 - tst_name, cnt_name, after_cnt, before_cnt); 75 + test_fail("%s(server): %s counter did not increase: %" PRIu64 " <= %" PRIu64, 76 + tst_name, cnt_name, after_cnt, before_cnt); 76 77 } else { 77 - test_ok("%s: counter %s increased %" PRIu64 " => %" PRIu64, 78 + test_ok("%s(server): counter %s increased %" PRIu64 " => %" PRIu64, 78 79 tst_name, cnt_name, before_cnt, after_cnt); 79 80 } 80 81 ··· 91 92 { 92 93 unsigned int port = test_server_port; 93 94 94 - try_server_run("TCP-AO migrate to another socket", port++, 95 + try_server_run("TCP-AO migrate to another socket (server)", port++, 95 96 0, TEST_CNT_GOOD); 96 - try_server_run("TCP-AO with wrong send ISN", port++, 97 + try_server_run("TCP-AO with wrong send ISN (server)", port++, 97 98 FAULT_TIMEOUT, TEST_CNT_BAD); 98 - try_server_run("TCP-AO with wrong receive ISN", port++, 99 + try_server_run("TCP-AO with wrong receive ISN (server)", port++, 99 100 FAULT_TIMEOUT, TEST_CNT_BAD); 100 - try_server_run("TCP-AO with wrong send SEQ ext number", port++, 101 + try_server_run("TCP-AO with wrong send SEQ ext number (server)", port++, 101 102 FAULT_TIMEOUT, TEST_CNT_BAD); 102 - try_server_run("TCP-AO with wrong receive SEQ ext number", port++, 103 - FAULT_TIMEOUT, TEST_CNT_NS_BAD | TEST_CNT_GOOD); 103 + try_server_run("TCP-AO with wrong receive SEQ ext number (server)", 104 + port++, FAULT_TIMEOUT, TEST_CNT_NS_BAD | TEST_CNT_GOOD); 104 105 105 106 synchronize_threads(); /* don't race to exit: client exits */ 106 107 return NULL; ··· 124 125 test_error("failed to connect()"); 125 126 126 127 synchronize_threads(); /* 2: accepted => send data */ 127 - if (test_client_verify(sk, msg_len, nr_packets, TEST_TIMEOUT_SEC)) 128 + if (test_client_verify(sk, msg_len, nr_packets)) 128 129 test_fail("pre-migrate verify failed"); 129 130 130 131 test_enable_repair(sk); ··· 138 139 struct tcp_ao_repair *ao_img, 139 140 fault_t inj, test_cnt cnt_expected) 140 141 { 142 + test_cnt poll_cnt = (cnt_expected == TEST_CNT_GOOD) ? 0 : cnt_expected; 141 143 const char *cnt_name = "TCPAOGood"; 142 - struct tcp_ao_counters ao1, ao2; 144 + struct tcp_counters cnt1, cnt2; 143 145 uint64_t before_cnt, after_cnt; 144 - time_t timeout; 145 - int sk; 146 + int sk, dummy; 146 147 147 148 if (fault(TIMEOUT)) 148 149 cnt_name = "TCPAOBad"; ··· 158 159 test_error("setsockopt(TCP_AO_ADD_KEY)"); 159 160 test_ao_restore(sk, ao_img); 160 161 161 - if (test_get_tcp_ao_counters(sk, &ao1)) 162 - test_error("test_get_tcp_ao_counters()"); 162 + if (test_get_tcp_counters(sk, &cnt1)) 163 + test_error("test_get_tcp_counters()"); 163 164 164 165 test_disable_repair(sk); 165 166 test_sock_state_free(img); 166 167 167 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 168 - if (test_client_verify(sk, msg_len, nr_packets, timeout)) { 168 + if (test_skpair_client(sk, msg_len, nr_packets, poll_cnt, &dummy)) { 169 169 if (fault(TIMEOUT)) 170 170 test_ok("%s: post-migrate connection is broken", tst_name); 171 171 else 172 172 test_fail("%s: post-migrate connection is working", tst_name); 173 173 } else { 174 174 if (fault(TIMEOUT)) 175 - test_fail("%s: post-migrate connection still working", tst_name); 175 + test_fail("%s: post-migrate connection is working", tst_name); 176 176 else 177 177 test_ok("%s: post-migrate connection is alive", tst_name); 178 178 } 179 + 179 180 synchronize_threads(); /* 3: counters checks */ 180 - if (test_get_tcp_ao_counters(sk, &ao2)) 181 - test_error("test_get_tcp_ao_counters()"); 181 + if (test_get_tcp_counters(sk, &cnt2)) 182 + test_error("test_get_tcp_counters()"); 182 183 after_cnt = netstat_get_one(cnt_name, NULL); 183 184 184 - test_tcp_ao_counters_cmp(tst_name, &ao1, &ao2, cnt_expected); 185 + test_assert_counters(tst_name, &cnt1, &cnt2, cnt_expected); 185 186 186 187 if (after_cnt <= before_cnt) { 187 188 test_fail("%s: %s counter did not increase: %" PRIu64 " <= %" PRIu64, ··· 202 203 sockaddr_af saddr; 203 204 204 205 test_get_sk_checkpoint(port, &saddr, &tcp_img, &ao_img); 205 - test_sk_restore("TCP-AO migrate to another socket", port++, 206 + test_sk_restore("TCP-AO migrate to another socket (client)", port++, 206 207 &saddr, &tcp_img, &ao_img, 0, TEST_CNT_GOOD); 207 208 208 209 test_get_sk_checkpoint(port, &saddr, &tcp_img, &ao_img); ··· 211 212 -1, port, 0, -1, -1, -1, -1, -1, 100, 100, -1); 212 213 trace_ao_event_expect(TCP_AO_MISMATCH, this_ip_dest, this_ip_addr, 213 214 port, -1, 0, -1, -1, -1, -1, -1, 100, 100, -1); 214 - test_sk_restore("TCP-AO with wrong send ISN", port++, 215 + test_sk_restore("TCP-AO with wrong send ISN (client)", port++, 215 216 &saddr, &tcp_img, &ao_img, FAULT_TIMEOUT, TEST_CNT_BAD); 216 217 217 218 test_get_sk_checkpoint(port, &saddr, &tcp_img, &ao_img); ··· 220 221 -1, port, 0, -1, -1, -1, -1, -1, 100, 100, -1); 221 222 trace_ao_event_expect(TCP_AO_MISMATCH, this_ip_dest, this_ip_addr, 222 223 port, -1, 0, -1, -1, -1, -1, -1, 100, 100, -1); 223 - test_sk_restore("TCP-AO with wrong receive ISN", port++, 224 + test_sk_restore("TCP-AO with wrong receive ISN (client)", port++, 224 225 &saddr, &tcp_img, &ao_img, FAULT_TIMEOUT, TEST_CNT_BAD); 225 226 226 227 test_get_sk_checkpoint(port, &saddr, &tcp_img, &ao_img); ··· 228 229 trace_ao_event_expect(TCP_AO_MISMATCH, this_ip_addr, this_ip_dest, 229 230 -1, port, 0, -1, -1, -1, -1, -1, 100, 100, -1); 230 231 /* not expecting server => client mismatches as only snd sne is broken */ 231 - test_sk_restore("TCP-AO with wrong send SEQ ext number", port++, 232 - &saddr, &tcp_img, &ao_img, FAULT_TIMEOUT, 232 + test_sk_restore("TCP-AO with wrong send SEQ ext number (client)", 233 + port++, &saddr, &tcp_img, &ao_img, FAULT_TIMEOUT, 233 234 TEST_CNT_NS_BAD | TEST_CNT_GOOD); 234 235 235 236 test_get_sk_checkpoint(port, &saddr, &tcp_img, &ao_img); ··· 237 238 /* not expecting client => server mismatches as only rcv sne is broken */ 238 239 trace_ao_event_expect(TCP_AO_MISMATCH, this_ip_dest, this_ip_addr, 239 240 port, -1, 0, -1, -1, -1, -1, -1, 100, 100, -1); 240 - test_sk_restore("TCP-AO with wrong receive SEQ ext number", port++, 241 - &saddr, &tcp_img, &ao_img, FAULT_TIMEOUT, 241 + test_sk_restore("TCP-AO with wrong receive SEQ ext number (client)", 242 + port++, &saddr, &tcp_img, &ao_img, FAULT_TIMEOUT, 242 243 TEST_CNT_NS_GOOD | TEST_CNT_BAD); 243 244 244 245 return NULL;
+23 -24
tools/testing/selftests/net/tcp_ao/rst.c
··· 84 84 85 85 static void test_server_active_rst(unsigned int port) 86 86 { 87 - struct tcp_ao_counters cnt1, cnt2; 87 + struct tcp_counters cnt1, cnt2; 88 88 ssize_t bytes; 89 89 int sk, lsk; 90 90 91 91 lsk = test_listen_socket(this_ip_addr, port, backlog); 92 92 if (test_add_key(lsk, DEFAULT_TEST_PASSWORD, this_ip_dest, -1, 100, 100)) 93 93 test_error("setsockopt(TCP_AO_ADD_KEY)"); 94 - if (test_get_tcp_ao_counters(lsk, &cnt1)) 95 - test_error("test_get_tcp_ao_counters()"); 94 + if (test_get_tcp_counters(lsk, &cnt1)) 95 + test_error("test_get_tcp_counters()"); 96 96 97 97 synchronize_threads(); /* 1: MKT added */ 98 98 if (test_wait_fd(lsk, TEST_TIMEOUT_SEC, 0)) ··· 103 103 test_error("accept()"); 104 104 105 105 synchronize_threads(); /* 2: connection accept()ed, another queued */ 106 - if (test_get_tcp_ao_counters(lsk, &cnt2)) 107 - test_error("test_get_tcp_ao_counters()"); 106 + if (test_get_tcp_counters(lsk, &cnt2)) 107 + test_error("test_get_tcp_counters()"); 108 108 109 109 synchronize_threads(); /* 3: close listen socket */ 110 110 close(lsk); ··· 120 120 synchronize_threads(); /* 5: closed active sk */ 121 121 122 122 synchronize_threads(); /* 6: counters checks */ 123 - if (test_tcp_ao_counters_cmp("active RST server", &cnt1, &cnt2, TEST_CNT_GOOD)) 123 + if (test_assert_counters("active RST server", &cnt1, &cnt2, TEST_CNT_GOOD)) 124 124 test_fail("MKT counters (server) have not only good packets"); 125 125 else 126 126 test_ok("MKT counters are good on server"); ··· 128 128 129 129 static void test_server_passive_rst(unsigned int port) 130 130 { 131 - struct tcp_ao_counters ao1, ao2; 131 + struct tcp_counters cnt1, cnt2; 132 132 int sk, lsk; 133 133 ssize_t bytes; 134 134 ··· 147 147 148 148 synchronize_threads(); /* 2: accepted => send data */ 149 149 close(lsk); 150 - if (test_get_tcp_ao_counters(sk, &ao1)) 151 - test_error("test_get_tcp_ao_counters()"); 150 + if (test_get_tcp_counters(sk, &cnt1)) 151 + test_error("test_get_tcp_counters()"); 152 152 153 153 bytes = test_server_run(sk, quota, TEST_TIMEOUT_SEC); 154 154 if (bytes != quota) { ··· 160 160 161 161 synchronize_threads(); /* 3: checkpoint the client */ 162 162 synchronize_threads(); /* 4: close the server, creating twsk */ 163 - if (test_get_tcp_ao_counters(sk, &ao2)) 164 - test_error("test_get_tcp_ao_counters()"); 163 + if (test_get_tcp_counters(sk, &cnt2)) 164 + test_error("test_get_tcp_counters()"); 165 165 close(sk); 166 166 167 167 synchronize_threads(); /* 5: restore the socket, send more data */ 168 - test_tcp_ao_counters_cmp("passive RST server", &ao1, &ao2, TEST_CNT_GOOD); 168 + test_assert_counters("passive RST server", &cnt1, &cnt2, TEST_CNT_GOOD); 169 169 170 170 synchronize_threads(); /* 6: server exits */ 171 171 } ··· 271 271 272 272 synchronize_threads(); /* 1: MKT added */ 273 273 for (i = 0; i < last; i++) { 274 - err = _test_connect_socket(sk[i], this_ip_dest, port, 275 - (i == 0) ? TEST_TIMEOUT_SEC : -1); 274 + err = _test_connect_socket(sk[i], this_ip_dest, port, i != 0); 276 275 if (err < 0) 277 276 test_error("failed to connect()"); 278 277 } ··· 282 283 test_error("test_wait_fds(): %d", err); 283 284 284 285 /* async connect() with third sk to get into request_sock_queue */ 285 - err = _test_connect_socket(sk[last], this_ip_dest, port, -1); 286 + err = _test_connect_socket(sk[last], this_ip_dest, port, 1); 286 287 if (err < 0) 287 288 test_error("failed to connect()"); 288 289 289 290 synchronize_threads(); /* 3: close listen socket */ 290 - if (test_client_verify(sk[0], packet_sz, quota / packet_sz, TEST_TIMEOUT_SEC)) 291 + if (test_client_verify(sk[0], packet_sz, quota / packet_sz)) 291 292 test_fail("Failed to send data on connected socket"); 292 293 else 293 294 test_ok("Verified established tcp connection"); ··· 322 323 323 324 static void test_client_passive_rst(unsigned int port) 324 325 { 325 - struct tcp_ao_counters ao1, ao2; 326 + struct tcp_counters cnt1, cnt2; 326 327 struct tcp_ao_repair ao_img; 327 328 struct tcp_sock_state img; 328 329 sockaddr_af saddr; ··· 340 341 test_error("failed to connect()"); 341 342 342 343 synchronize_threads(); /* 2: accepted => send data */ 343 - if (test_client_verify(sk, packet_sz, quota / packet_sz, TEST_TIMEOUT_SEC)) 344 + if (test_client_verify(sk, packet_sz, quota / packet_sz)) 344 345 test_fail("Failed to send data on connected socket"); 345 346 else 346 347 test_ok("Verified established tcp connection"); ··· 396 397 test_error("setsockopt(TCP_AO_ADD_KEY)"); 397 398 test_ao_restore(sk, &ao_img); 398 399 399 - if (test_get_tcp_ao_counters(sk, &ao1)) 400 - test_error("test_get_tcp_ao_counters()"); 400 + if (test_get_tcp_counters(sk, &cnt1)) 401 + test_error("test_get_tcp_counters()"); 401 402 402 403 test_disable_repair(sk); 403 404 test_sock_state_free(&img); ··· 416 417 * IP 10.0.254.1.7011 > 10.0.1.1.59772: Flags [R], seq 3215596252, win 0, 417 418 * options [tcp-ao keyid 100 rnextkeyid 100 mac 0x0bcfbbf497bce844312304b2], length 0 418 419 */ 419 - err = test_client_verify(sk, packet_sz, quota / packet_sz, 2 * TEST_TIMEOUT_SEC); 420 + err = test_client_verify(sk, packet_sz, quota / packet_sz); 420 421 /* Make sure that the connection was reset, not timeouted */ 421 422 if (err && err == -ECONNRESET) 422 423 test_ok("client sock was passively reset post-seq-adjust"); ··· 425 426 else 426 427 test_fail("client sock is yet connected post-seq-adjust"); 427 428 428 - if (test_get_tcp_ao_counters(sk, &ao2)) 429 - test_error("test_get_tcp_ao_counters()"); 429 + if (test_get_tcp_counters(sk, &cnt2)) 430 + test_error("test_get_tcp_counters()"); 430 431 431 432 synchronize_threads(); /* 6: server exits */ 432 433 close(sk); 433 - test_tcp_ao_counters_cmp("client passive RST", &ao1, &ao2, TEST_CNT_GOOD); 434 + test_assert_counters("client passive RST", &cnt1, &cnt2, TEST_CNT_GOOD); 434 435 } 435 436 436 437 static void *client_fn(void *arg)
+9 -9
tools/testing/selftests/net/tcp_ao/self-connect.c
··· 30 30 static void tcp_self_connect(const char *tst, unsigned int port, 31 31 bool different_keyids, bool check_restore) 32 32 { 33 - struct tcp_ao_counters before_ao, after_ao; 33 + struct tcp_counters before, after; 34 34 uint64_t before_aogood, after_aogood; 35 35 struct netstat *ns_before, *ns_after; 36 36 const size_t nr_packets = 20; ··· 60 60 61 61 ns_before = netstat_read(); 62 62 before_aogood = netstat_get(ns_before, "TCPAOGood", NULL); 63 - if (test_get_tcp_ao_counters(sk, &before_ao)) 64 - test_error("test_get_tcp_ao_counters()"); 63 + if (test_get_tcp_counters(sk, &before)) 64 + test_error("test_get_tcp_counters()"); 65 65 66 66 if (__test_connect_socket(sk, "lo", (struct sockaddr *)&addr, 67 - sizeof(addr), TEST_TIMEOUT_SEC) < 0) { 67 + sizeof(addr), 0) < 0) { 68 68 ns_after = netstat_read(); 69 69 netstat_print_diff(ns_before, ns_after); 70 70 test_error("failed to connect()"); 71 71 } 72 72 73 - if (test_client_verify(sk, 100, nr_packets, TEST_TIMEOUT_SEC)) { 73 + if (test_client_verify(sk, 100, nr_packets)) { 74 74 test_fail("%s: tcp connection verify failed", tst); 75 75 close(sk); 76 76 return; ··· 78 78 79 79 ns_after = netstat_read(); 80 80 after_aogood = netstat_get(ns_after, "TCPAOGood", NULL); 81 - if (test_get_tcp_ao_counters(sk, &after_ao)) 82 - test_error("test_get_tcp_ao_counters()"); 81 + if (test_get_tcp_counters(sk, &after)) 82 + test_error("test_get_tcp_counters()"); 83 83 if (!check_restore) { 84 84 /* to debug: netstat_print_diff(ns_before, ns_after); */ 85 85 netstat_free(ns_before); ··· 93 93 return; 94 94 } 95 95 96 - if (test_tcp_ao_counters_cmp(tst, &before_ao, &after_ao, TEST_CNT_GOOD)) { 96 + if (test_assert_counters(tst, &before, &after, TEST_CNT_GOOD)) { 97 97 close(sk); 98 98 return; 99 99 } ··· 136 136 test_ao_restore(sk, &ao_img); 137 137 test_disable_repair(sk); 138 138 test_sock_state_free(&img); 139 - if (test_client_verify(sk, 100, nr_packets, TEST_TIMEOUT_SEC)) { 139 + if (test_client_verify(sk, 100, nr_packets)) { 140 140 test_fail("%s: tcp connection verify failed", tst); 141 141 close(sk); 142 142 return;
+15 -15
tools/testing/selftests/net/tcp_ao/seq-ext.c
··· 40 40 static int test_sk_restore(struct tcp_sock_state *img, 41 41 struct tcp_ao_repair *ao_img, sockaddr_af *saddr, 42 42 const union tcp_addr daddr, unsigned int dport, 43 - struct tcp_ao_counters *cnt) 43 + struct tcp_counters *cnt) 44 44 { 45 45 int sk; 46 46 ··· 54 54 test_error("setsockopt(TCP_AO_ADD_KEY)"); 55 55 test_ao_restore(sk, ao_img); 56 56 57 - if (test_get_tcp_ao_counters(sk, cnt)) 58 - test_error("test_get_tcp_ao_counters()"); 57 + if (test_get_tcp_counters(sk, cnt)) 58 + test_error("test_get_tcp_counters()"); 59 59 60 60 test_disable_repair(sk); 61 61 test_sock_state_free(img); ··· 65 65 static void *server_fn(void *arg) 66 66 { 67 67 uint64_t before_good, after_good, after_bad; 68 - struct tcp_ao_counters ao1, ao2; 68 + struct tcp_counters cnt1, cnt2; 69 69 struct tcp_sock_state img; 70 70 struct tcp_ao_repair ao_img; 71 71 sockaddr_af saddr; ··· 114 114 test_adjust_seqs(&img, &ao_img, true); 115 115 synchronize_threads(); /* 4: dump finished */ 116 116 sk = test_sk_restore(&img, &ao_img, &saddr, this_ip_dest, 117 - client_new_port, &ao1); 117 + client_new_port, &cnt1); 118 118 119 119 trace_ao_event_sne_expect(TCP_AO_SND_SNE_UPDATE, this_ip_addr, 120 120 this_ip_dest, test_server_port + 1, client_new_port, 1); ··· 136 136 } 137 137 138 138 synchronize_threads(); /* 6: verify counters after SEQ-number rollover */ 139 - if (test_get_tcp_ao_counters(sk, &ao2)) 140 - test_error("test_get_tcp_ao_counters()"); 139 + if (test_get_tcp_counters(sk, &cnt2)) 140 + test_error("test_get_tcp_counters()"); 141 141 after_good = netstat_get_one("TCPAOGood", NULL); 142 142 143 - test_tcp_ao_counters_cmp(NULL, &ao1, &ao2, TEST_CNT_GOOD); 143 + test_assert_counters(NULL, &cnt1, &cnt2, TEST_CNT_GOOD); 144 144 145 145 if (after_good <= before_good) { 146 146 test_fail("TCPAOGood counter did not increase: %" PRIu64 " <= %" PRIu64, ··· 173 173 static void *client_fn(void *arg) 174 174 { 175 175 uint64_t before_good, after_good, after_bad; 176 - struct tcp_ao_counters ao1, ao2; 176 + struct tcp_counters cnt1, cnt2; 177 177 struct tcp_sock_state img; 178 178 struct tcp_ao_repair ao_img; 179 179 sockaddr_af saddr; ··· 191 191 test_error("failed to connect()"); 192 192 193 193 synchronize_threads(); /* 2: accepted => send data */ 194 - if (test_client_verify(sk, msg_len, nr_packets, TEST_TIMEOUT_SEC)) { 194 + if (test_client_verify(sk, msg_len, nr_packets)) { 195 195 test_fail("pre-migrate verify failed"); 196 196 return NULL; 197 197 } ··· 213 213 test_adjust_seqs(&img, &ao_img, false); 214 214 synchronize_threads(); /* 4: dump finished */ 215 215 sk = test_sk_restore(&img, &ao_img, &saddr, this_ip_dest, 216 - test_server_port + 1, &ao1); 216 + test_server_port + 1, &cnt1); 217 217 218 218 synchronize_threads(); /* 5: verify the connection during SEQ-number rollover */ 219 - if (test_client_verify(sk, msg_len, nr_packets, TEST_TIMEOUT_SEC)) 219 + if (test_client_verify(sk, msg_len, nr_packets)) 220 220 test_fail("post-migrate verify failed"); 221 221 else 222 222 test_ok("post-migrate connection alive"); 223 223 224 224 synchronize_threads(); /* 5: verify counters after SEQ-number rollover */ 225 - if (test_get_tcp_ao_counters(sk, &ao2)) 226 - test_error("test_get_tcp_ao_counters()"); 225 + if (test_get_tcp_counters(sk, &cnt2)) 226 + test_error("test_get_tcp_counters()"); 227 227 after_good = netstat_get_one("TCPAOGood", NULL); 228 228 229 - test_tcp_ao_counters_cmp(NULL, &ao1, &ao2, TEST_CNT_GOOD); 229 + test_assert_counters(NULL, &cnt1, &cnt2, TEST_CNT_GOOD); 230 230 231 231 if (after_good <= before_good) { 232 232 test_fail("TCPAOGood counter did not increase: %" PRIu64 " <= %" PRIu64,
+60 -58
tools/testing/selftests/net/tcp_ao/unsigned-md5.c
··· 6 6 #define fault(type) (inj == FAULT_ ## type) 7 7 static const char *md5_password = "Some evil genius, enemy to mankind, must have been the first contriver."; 8 8 static const char *ao_password = DEFAULT_TEST_PASSWORD; 9 + static volatile int sk_pair; 9 10 10 11 static union tcp_addr client2; 11 12 static union tcp_addr client3; ··· 42 41 const char *cnt_name, test_cnt cnt_expected, 43 42 int needs_tcp_md5, fault_t inj) 44 43 { 45 - struct tcp_ao_counters ao_cnt1, ao_cnt2; 44 + struct tcp_counters cnt1, cnt2; 46 45 uint64_t before_cnt = 0, after_cnt = 0; /* silence GCC */ 47 - int lsk, err, sk = 0; 48 - time_t timeout; 46 + test_cnt poll_cnt = (cnt_expected == TEST_CNT_GOOD) ? 0 : cnt_expected; 47 + int lsk, err, sk = -1; 49 48 50 49 if (needs_tcp_md5 && should_skip_test(tst_name, KCONFIG_TCP_MD5)) 51 50 return; ··· 64 63 65 64 if (cnt_name) 66 65 before_cnt = netstat_get_one(cnt_name, NULL); 67 - if (ao_addr && test_get_tcp_ao_counters(lsk, &ao_cnt1)) 68 - test_error("test_get_tcp_ao_counters()"); 66 + if (ao_addr && test_get_tcp_counters(lsk, &cnt1)) 67 + test_error("test_get_tcp_counters()"); 69 68 70 69 synchronize_threads(); /* preparations done */ 71 70 72 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 73 - err = test_wait_fd(lsk, timeout, 0); 71 + err = test_skpair_wait_poll(lsk, 0, poll_cnt, &sk_pair); 74 72 synchronize_threads(); /* connect()/accept() timeouts */ 75 73 if (err == -ETIMEDOUT) { 74 + sk_pair = err; 76 75 if (!fault(TIMEOUT)) 77 - test_fail("timed out for accept()"); 76 + test_fail("%s: timed out for accept()", tst_name); 77 + } else if (err == -EKEYREJECTED) { 78 + if (!fault(KEYREJECT)) 79 + test_fail("%s: key was rejected", tst_name); 78 80 } else if (err < 0) { 79 - test_error("test_wait_fd()"); 81 + test_error("test_skpair_wait_poll()"); 80 82 } else { 81 83 if (fault(TIMEOUT)) 82 - test_fail("ready to accept"); 84 + test_fail("%s: ready to accept", tst_name); 83 85 84 86 sk = accept(lsk, NULL, NULL); 85 87 if (sk < 0) { ··· 93 89 } 94 90 } 95 91 96 - if (ao_addr && test_get_tcp_ao_counters(lsk, &ao_cnt2)) 97 - test_error("test_get_tcp_ao_counters()"); 92 + if (ao_addr && test_get_tcp_counters(lsk, &cnt2)) 93 + test_error("test_get_tcp_counters()"); 98 94 close(lsk); 99 95 100 96 if (!cnt_name) { ··· 112 108 tst_name, cnt_name, before_cnt, after_cnt); 113 109 } 114 110 if (ao_addr) 115 - test_tcp_ao_counters_cmp(tst_name, &ao_cnt1, &ao_cnt2, cnt_expected); 111 + test_assert_counters(tst_name, &cnt1, &cnt2, cnt_expected); 116 112 117 113 out: 118 114 synchronize_threads(); /* test_kill_sk() */ 119 - if (sk > 0) 115 + if (sk >= 0) 120 116 test_kill_sk(sk); 121 117 } 122 118 ··· 157 153 158 154 server_add_routes(); 159 155 160 - try_accept("AO server (INADDR_ANY): AO client", port++, NULL, 0, 156 + try_accept("[server] AO server (INADDR_ANY): AO client", port++, NULL, 0, 161 157 &addr_any, 0, 0, 100, 100, 0, "TCPAOGood", 162 158 TEST_CNT_GOOD, 0, 0); 163 - try_accept("AO server (INADDR_ANY): MD5 client", port++, NULL, 0, 159 + try_accept("[server] AO server (INADDR_ANY): MD5 client", port++, NULL, 0, 164 160 &addr_any, 0, 0, 100, 100, 0, "TCPMD5Unexpected", 165 - 0, 1, FAULT_TIMEOUT); 166 - try_accept("AO server (INADDR_ANY): no sign client", port++, NULL, 0, 161 + TEST_CNT_NS_MD5_UNEXPECTED, 1, FAULT_TIMEOUT); 162 + try_accept("[server] AO server (INADDR_ANY): no sign client", port++, NULL, 0, 167 163 &addr_any, 0, 0, 100, 100, 0, "TCPAORequired", 168 164 TEST_CNT_AO_REQUIRED, 0, FAULT_TIMEOUT); 169 - try_accept("AO server (AO_REQUIRED): AO client", port++, NULL, 0, 165 + try_accept("[server] AO server (AO_REQUIRED): AO client", port++, NULL, 0, 170 166 &this_ip_dest, TEST_PREFIX, true, 171 167 100, 100, 0, "TCPAOGood", TEST_CNT_GOOD, 0, 0); 172 - try_accept("AO server (AO_REQUIRED): unsigned client", port++, NULL, 0, 168 + try_accept("[server] AO server (AO_REQUIRED): unsigned client", port++, NULL, 0, 173 169 &this_ip_dest, TEST_PREFIX, true, 174 170 100, 100, 0, "TCPAORequired", 175 171 TEST_CNT_AO_REQUIRED, 0, FAULT_TIMEOUT); 176 172 177 - try_accept("MD5 server (INADDR_ANY): AO client", port++, &addr_any, 0, 173 + try_accept("[server] MD5 server (INADDR_ANY): AO client", port++, &addr_any, 0, 178 174 NULL, 0, 0, 0, 0, 0, "TCPAOKeyNotFound", 179 - 0, 1, FAULT_TIMEOUT); 180 - try_accept("MD5 server (INADDR_ANY): MD5 client", port++, &addr_any, 0, 175 + TEST_CNT_NS_KEY_NOT_FOUND, 1, FAULT_TIMEOUT); 176 + try_accept("[server] MD5 server (INADDR_ANY): MD5 client", port++, &addr_any, 0, 181 177 NULL, 0, 0, 0, 0, 0, NULL, 0, 1, 0); 182 - try_accept("MD5 server (INADDR_ANY): no sign client", port++, &addr_any, 178 + try_accept("[server] MD5 server (INADDR_ANY): no sign client", port++, &addr_any, 183 179 0, NULL, 0, 0, 0, 0, 0, "TCPMD5NotFound", 184 - 0, 1, FAULT_TIMEOUT); 180 + TEST_CNT_NS_MD5_NOT_FOUND, 1, FAULT_TIMEOUT); 185 181 186 - try_accept("no sign server: AO client", port++, NULL, 0, 182 + try_accept("[server] no sign server: AO client", port++, NULL, 0, 187 183 NULL, 0, 0, 0, 0, 0, "TCPAOKeyNotFound", 188 - TEST_CNT_AO_KEY_NOT_FOUND, 0, FAULT_TIMEOUT); 189 - try_accept("no sign server: MD5 client", port++, NULL, 0, 184 + TEST_CNT_NS_KEY_NOT_FOUND, 0, FAULT_TIMEOUT); 185 + try_accept("[server] no sign server: MD5 client", port++, NULL, 0, 190 186 NULL, 0, 0, 0, 0, 0, "TCPMD5Unexpected", 191 - 0, 1, FAULT_TIMEOUT); 192 - try_accept("no sign server: no sign client", port++, NULL, 0, 187 + TEST_CNT_NS_MD5_UNEXPECTED, 1, FAULT_TIMEOUT); 188 + try_accept("[server] no sign server: no sign client", port++, NULL, 0, 193 189 NULL, 0, 0, 0, 0, 0, "CurrEstab", 0, 0, 0); 194 190 195 - try_accept("AO+MD5 server: AO client (matching)", port++, 191 + try_accept("[server] AO+MD5 server: AO client (matching)", port++, 196 192 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 197 193 100, 100, 0, "TCPAOGood", TEST_CNT_GOOD, 1, 0); 198 - try_accept("AO+MD5 server: AO client (misconfig, matching MD5)", port++, 194 + try_accept("[server] AO+MD5 server: AO client (misconfig, matching MD5)", port++, 199 195 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 200 196 100, 100, 0, "TCPAOKeyNotFound", TEST_CNT_AO_KEY_NOT_FOUND, 201 197 1, FAULT_TIMEOUT); 202 - try_accept("AO+MD5 server: AO client (misconfig, non-matching)", port++, 198 + try_accept("[server] AO+MD5 server: AO client (misconfig, non-matching)", port++, 203 199 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 204 200 100, 100, 0, "TCPAOKeyNotFound", TEST_CNT_AO_KEY_NOT_FOUND, 205 201 1, FAULT_TIMEOUT); 206 - try_accept("AO+MD5 server: MD5 client (matching)", port++, 202 + try_accept("[server] AO+MD5 server: MD5 client (matching)", port++, 207 203 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 208 204 100, 100, 0, NULL, 0, 1, 0); 209 - try_accept("AO+MD5 server: MD5 client (misconfig, matching AO)", port++, 205 + try_accept("[server] AO+MD5 server: MD5 client (misconfig, matching AO)", port++, 210 206 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 211 - 100, 100, 0, "TCPMD5Unexpected", 0, 1, FAULT_TIMEOUT); 212 - try_accept("AO+MD5 server: MD5 client (misconfig, non-matching)", port++, 207 + 100, 100, 0, "TCPMD5Unexpected", 208 + TEST_CNT_NS_MD5_UNEXPECTED, 1, FAULT_TIMEOUT); 209 + try_accept("[server] AO+MD5 server: MD5 client (misconfig, non-matching)", port++, 213 210 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 214 - 100, 100, 0, "TCPMD5Unexpected", 0, 1, FAULT_TIMEOUT); 215 - try_accept("AO+MD5 server: no sign client (unmatched)", port++, 211 + 100, 100, 0, "TCPMD5Unexpected", 212 + TEST_CNT_NS_MD5_UNEXPECTED, 1, FAULT_TIMEOUT); 213 + try_accept("[server] AO+MD5 server: no sign client (unmatched)", port++, 216 214 &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 217 215 100, 100, 0, "CurrEstab", 0, 1, 0); 218 - try_accept("AO+MD5 server: no sign client (misconfig, matching AO)", 216 + try_accept("[server] AO+MD5 server: no sign client (misconfig, matching AO)", 219 217 port++, &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 220 218 100, 100, 0, "TCPAORequired", 221 219 TEST_CNT_AO_REQUIRED, 1, FAULT_TIMEOUT); 222 - try_accept("AO+MD5 server: no sign client (misconfig, matching MD5)", 220 + try_accept("[server] AO+MD5 server: no sign client (misconfig, matching MD5)", 223 221 port++, &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 224 - 100, 100, 0, "TCPMD5NotFound", 0, 1, FAULT_TIMEOUT); 222 + 100, 100, 0, "TCPMD5NotFound", 223 + TEST_CNT_NS_MD5_NOT_FOUND, 1, FAULT_TIMEOUT); 225 224 226 - try_accept("AO+MD5 server: client with both [TCP-MD5] and TCP-AO keys", 225 + /* Key rejected by the other side, failing short through skpair */ 226 + try_accept("[server] AO+MD5 server: client with both [TCP-MD5] and TCP-AO keys", 227 227 port++, &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 228 - 100, 100, 0, NULL, 0, 1, FAULT_TIMEOUT); 229 - try_accept("AO+MD5 server: client with both TCP-MD5 and [TCP-AO] keys", 228 + 100, 100, 0, NULL, 0, 1, FAULT_KEYREJECT); 229 + try_accept("[server] AO+MD5 server: client with both TCP-MD5 and [TCP-AO] keys", 230 230 port++, &this_ip_dest, TEST_PREFIX, &client2, TEST_PREFIX, 0, 231 - 100, 100, 0, NULL, 0, 1, FAULT_TIMEOUT); 231 + 100, 100, 0, NULL, 0, 1, FAULT_KEYREJECT); 232 232 233 233 server_add_fail_tests(&port); 234 234 ··· 267 259 uint8_t sndid, uint8_t rcvid, uint8_t vrf, 268 260 fault_t inj, int needs_tcp_md5, union tcp_addr *bind_addr) 269 261 { 270 - time_t timeout; 271 262 int sk, ret; 272 263 273 264 if (needs_tcp_md5 && should_skip_test(tst_name, KCONFIG_TCP_MD5)) ··· 288 281 289 282 synchronize_threads(); /* preparations done */ 290 283 291 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 292 - ret = _test_connect_socket(sk, this_ip_dest, port, timeout); 293 - 284 + ret = test_skpair_connect_poll(sk, this_ip_dest, port, 0, &sk_pair); 294 285 synchronize_threads(); /* connect()/accept() timeouts */ 295 286 if (ret < 0) { 287 + sk_pair = ret; 296 288 if (fault(KEYREJECT) && ret == -EKEYREJECTED) 297 289 test_ok("%s: connect() was prevented", tst_name); 298 290 else if (ret == -ETIMEDOUT && fault(TIMEOUT)) ··· 311 305 312 306 out: 313 307 synchronize_threads(); /* test_kill_sk() */ 314 - /* _test_connect_socket() cleans up on failure */ 315 - if (ret > 0) 308 + if (ret > 0) /* test_skpair_connect_poll() cleans up on failure */ 316 309 test_kill_sk(sk); 317 310 } 318 311 ··· 442 437 int ao_vrf, uint8_t sndid, uint8_t rcvid, 443 438 int needs_tcp_md5, fault_t inj) 444 439 { 445 - time_t timeout; 446 440 int sk, ret; 447 441 448 442 if (needs_tcp_md5 && should_skip_test(tst_name, KCONFIG_TCP_MD5)) ··· 454 450 455 451 synchronize_threads(); /* preparations done */ 456 452 457 - timeout = fault(TIMEOUT) ? TEST_RETRANSMIT_SEC : TEST_TIMEOUT_SEC; 458 - ret = _test_connect_socket(sk, this_ip_dest, port, timeout); 453 + ret = test_skpair_connect_poll(sk, this_ip_dest, port, 0, &sk_pair); 459 454 460 455 synchronize_threads(); /* connect()/accept() timeouts */ 461 - if (ret <= 0) { 456 + if (ret < 0) { 462 457 test_error("%s: connect() returned %d", tst_name, ret); 463 458 goto out; 464 459 } ··· 493 490 494 491 out: 495 492 synchronize_threads(); /* test_kill_sk() */ 496 - /* _test_connect_socket() cleans up on failure */ 497 - if (ret > 0) 493 + if (ret > 0) /* test_skpair_connect_poll() cleans up on failure */ 498 494 test_kill_sk(sk); 499 495 } 500 496