Skip to content

Commit d11301f

Browse files
0x7f454c46davem330
authored andcommitted
selftests/net: Add TCP-AO ICMPs accept test
Reverse to icmps-discard test: the server accepts ICMPs, using TCP_AO_CMDF_ACCEPT_ICMP and it is expected to fail under ICMP flood from client. Test that the default pre-TCP-AO behaviour functions when TCP_AO_CMDF_ACCEPT_ICMP is set. Expected output for ipv4 version (in case it receives ICMP_PROT_UNREACH): > # ./icmps-accept_ipv4 > 1..3 > # 3209[lib/setup.c:166] rand seed 1642623870 > TAP version 13 > # 3209[lib/proc.c:207] Snmp6 Ip6InReceives: 0 => 1 > # 3209[lib/proc.c:207] Snmp6 Ip6InNoRoutes: 0 => 1 > # 3209[lib/proc.c:207] Snmp6 Ip6InOctets: 0 => 76 > # 3209[lib/proc.c:207] Snmp6 Ip6InNoECTPkts: 0 => 1 > # 3209[lib/proc.c:207] Tcp InSegs: 3 => 23 > # 3209[lib/proc.c:207] Tcp OutSegs: 2 => 22 > # 3209[lib/proc.c:207] IcmpMsg InType3: 0 => 4 > # 3209[lib/proc.c:207] Icmp InMsgs: 0 => 4 > # 3209[lib/proc.c:207] Icmp InDestUnreachs: 0 => 4 > # 3209[lib/proc.c:207] Ip InReceives: 3 => 27 > # 3209[lib/proc.c:207] Ip InDelivers: 3 => 27 > # 3209[lib/proc.c:207] Ip OutRequests: 2 => 22 > # 3209[lib/proc.c:207] IpExt InOctets: 288 => 3420 > # 3209[lib/proc.c:207] IpExt OutOctets: 124 => 3244 > # 3209[lib/proc.c:207] IpExt InNoECTPkts: 3 => 25 > # 3209[lib/proc.c:207] TcpExt TCPPureAcks: 1 => 2 > # 3209[lib/proc.c:207] TcpExt TCPOrigDataSent: 0 => 20 > # 3209[lib/proc.c:207] TcpExt TCPDelivered: 0 => 19 > # 3209[lib/proc.c:207] TcpExt TCPAOGood: 3 => 23 > ok 1 InDestUnreachs delivered 4 > ok 2 server failed with -92: Protocol not available > ok 3 TCPAODroppedIcmps counter didn't change: 0 >= 0 > # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0 Expected output for ipv6 version (in case it receives ADM_PROHIBITED): > # ./icmps-accept_ipv6 > 1..3 > # 3277[lib/setup.c:166] rand seed 1642624035 > TAP version 13 > # 3277[lib/proc.c:207] Snmp6 Ip6InReceives: 6 => 31 > # 3277[lib/proc.c:207] Snmp6 Ip6InDelivers: 4 => 29 > # 3277[lib/proc.c:207] Snmp6 Ip6OutRequests: 4 => 24 > # 3277[lib/proc.c:207] Snmp6 Ip6InOctets: 592 => 4492 > # 3277[lib/proc.c:207] Snmp6 Ip6OutOctets: 332 => 3852 > # 3277[lib/proc.c:207] Snmp6 Ip6InNoECTPkts: 6 => 31 > # 3277[lib/proc.c:207] Snmp6 Icmp6InMsgs: 1 => 6 > # 3277[lib/proc.c:207] Snmp6 Icmp6InDestUnreachs: 0 => 5 > # 3277[lib/proc.c:207] Snmp6 Icmp6InType1: 0 => 5 > # 3277[lib/proc.c:207] Tcp InSegs: 3 => 23 > # 3277[lib/proc.c:207] Tcp OutSegs: 2 => 22 > # 3277[lib/proc.c:207] TcpExt TCPPureAcks: 1 => 2 > # 3277[lib/proc.c:207] TcpExt TCPOrigDataSent: 0 => 20 > # 3277[lib/proc.c:207] TcpExt TCPDelivered: 0 => 19 > # 3277[lib/proc.c:207] TcpExt TCPAOGood: 3 => 23 > ok 1 Icmp6InDestUnreachs delivered 5 > ok 2 server failed with -13: Permission denied > ok 3 TCPAODroppedIcmps counter didn't change: 0 >= 0 > # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0 With some luck the server may fail with ECONNREFUSED (depending on what icmp packet was delivered firstly). For the kernel error handlers see: tab_unreach[] and icmp_err_convert[]. Signed-off-by: Dmitry Safonov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a8fcf8c commit d11301f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

tools/testing/selftests/net/tcp_ao/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
TEST_BOTH_AF := connect
3-
TEST_BOTH_AF += icmps-discard
3+
TEST_BOTH_AF += icmps-accept icmps-discard
44

55
TEST_IPV4_PROGS := $(TEST_BOTH_AF:%=%_ipv4)
66
TEST_IPV6_PROGS := $(TEST_BOTH_AF:%=%_ipv6)
@@ -44,3 +44,5 @@ $(OUTPUT)/%_ipv4: %.c
4444
$(OUTPUT)/%_ipv6: %.c
4545
$(LINK.c) -DIPV6_TEST $^ $(LDLIBS) -o $@
4646

47+
$(OUTPUT)/icmps-accept_ipv4: CFLAGS+= -DTEST_ICMPS_ACCEPT
48+
$(OUTPUT)/icmps-accept_ipv6: CFLAGS+= -DTEST_ICMPS_ACCEPT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
icmps-discard.c

tools/testing/selftests/net/tcp_ao/icmps-discard.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ const int sk_ip_level = SOL_IP;
3939
const int sk_recverr = IP_RECVERR;
4040
#endif
4141

42-
#define test_icmps_fail test_fail
43-
#define test_icmps_ok test_ok
42+
/* Server is expected to fail with hard error if ::accept_icmp is set */
43+
#ifdef TEST_ICMPS_ACCEPT
44+
# define test_icmps_fail test_ok
45+
# define test_icmps_ok test_fail
46+
#else
47+
# define test_icmps_fail test_fail
48+
# define test_icmps_ok test_ok
49+
#endif
4450

4551
static void serve_interfered(int sk)
4652
{
@@ -84,7 +90,11 @@ static void serve_interfered(int sk)
8490
test_fail("Not found %s counter", tcpao_icmps);
8591
return;
8692
}
93+
#ifdef TEST_ICMPS_ACCEPT
94+
test_tcp_ao_counters_cmp(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD);
95+
#else
8796
test_tcp_ao_counters_cmp(NULL, &ao_cnt1, &ao_cnt2, TEST_CNT_GOOD | TEST_CNT_AO_DROPPED_ICMP);
97+
#endif
8898
if (icmp_ignored_a >= icmp_ignored_b) {
8999
test_icmps_fail("%s counter didn't change: %" PRIu64 " >= %" PRIu64,
90100
tcpao_icmps, icmp_ignored_a, icmp_ignored_b);
@@ -95,22 +105,23 @@ static void serve_interfered(int sk)
95105

96106
static void *server_fn(void *arg)
97107
{
98-
int val, err, sk, lsk;
108+
int val, sk, lsk;
99109
bool accept_icmps = false;
100110

101111
lsk = test_listen_socket(this_ip_addr, test_server_port, 1);
102112

113+
#ifdef TEST_ICMPS_ACCEPT
114+
accept_icmps = true;
115+
#endif
116+
103117
if (test_set_ao_flags(lsk, false, accept_icmps))
104118
test_error("setsockopt(TCP_AO_INFO)");
105119

106120
if (test_add_key(lsk, DEFAULT_TEST_PASSWORD, this_ip_dest, -1, 100, 100))
107121
test_error("setsockopt(TCP_AO_ADD_KEY)");
108122
synchronize_threads();
109123

110-
err = test_wait_fd(lsk, TEST_TIMEOUT_SEC, 0);
111-
if (!err)
112-
test_error("timeouted for accept()");
113-
else if (err < 0)
124+
if (test_wait_fd(lsk, TEST_TIMEOUT_SEC, 0))
114125
test_error("test_wait_fd()");
115126

116127
sk = accept(lsk, NULL, NULL);

0 commit comments

Comments
 (0)