kernel-netlink: Support extended table IDs for custom routes
[strongswan.git] / src / libcharon / tests / suites / test_ike_delete.c
1 /*
2 * Copyright (C) 2016 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "test_suite.h"
17
18 #include <tests/utils/exchange_test_helper.h>
19 #include <tests/utils/exchange_test_asserts.h>
20 #include <tests/utils/sa_asserts.h>
21
22 /**
23 * Regular IKE_SA delete either initiated by the original initiator or
24 * responder of the IKE_SA.
25 */
26 START_TEST(test_regular)
27 {
28 ike_sa_t *a, *b;
29 status_t s;
30
31 if (_i)
32 { /* responder deletes the IKE_SA */
33 exchange_test_helper->establish_sa(exchange_test_helper,
34 &b, &a, NULL);
35 }
36 else
37 { /* initiator deletes the IKE_SA */
38 exchange_test_helper->establish_sa(exchange_test_helper,
39 &a, &b, NULL);
40 }
41 assert_hook_not_called(ike_updown);
42 assert_hook_not_called(child_updown);
43 call_ikesa(a, delete, FALSE);
44 assert_ike_sa_state(a, IKE_DELETING);
45 assert_hook();
46 assert_hook();
47
48 /* INFORMATIONAL { D } --> */
49 assert_hook_updown(ike_updown, FALSE);
50 assert_hook_updown(child_updown, FALSE);
51 assert_single_payload(IN, PLV2_DELETE);
52 s = exchange_test_helper->process_message(exchange_test_helper, b, NULL);
53 ck_assert_int_eq(DESTROY_ME, s);
54 call_ikesa(b, destroy);
55 assert_hook();
56 assert_hook();
57
58 /* <-- INFORMATIONAL { } */
59 assert_hook_updown(ike_updown, FALSE);
60 assert_hook_updown(child_updown, FALSE);
61 assert_message_empty(IN);
62 s = exchange_test_helper->process_message(exchange_test_helper, a, NULL);
63 ck_assert_int_eq(DESTROY_ME, s);
64 call_ikesa(a, destroy);
65 assert_hook();
66 assert_hook();
67 }
68 END_TEST
69
70 /**
71 * Both peers initiate the IKE_SA deletion concurrently and should handle the
72 * collision properly.
73 */
74 START_TEST(test_collision)
75 {
76 ike_sa_t *a, *b;
77 status_t s;
78
79 exchange_test_helper->establish_sa(exchange_test_helper,
80 &a, &b, NULL);
81
82 assert_hook_not_called(ike_updown);
83 assert_hook_not_called(child_updown);
84 call_ikesa(a, delete, FALSE);
85 assert_ike_sa_state(a, IKE_DELETING);
86 call_ikesa(b, delete, FALSE);
87 assert_ike_sa_state(b, IKE_DELETING);
88 assert_hook();
89 assert_hook();
90
91 /* RFC 7296 says: If a peer receives a request to close an IKE SA that it
92 * is currently trying to close, it SHOULD reply as usual, and forget about
93 * its own close request.
94 * So we expect the SA to just get closed with an empty response still sent.
95 */
96
97 /* INFORMATIONAL { D } --> */
98 assert_hook_updown(ike_updown, FALSE);
99 assert_hook_updown(child_updown, FALSE);
100 assert_single_payload(IN, PLV2_DELETE);
101 assert_message_empty(OUT);
102 s = exchange_test_helper->process_message(exchange_test_helper, b, NULL);
103 ck_assert_int_eq(DESTROY_ME, s);
104 call_ikesa(b, destroy);
105 assert_hook();
106 assert_hook();
107
108 /* <-- INFORMATIONAL { D } */
109 assert_hook_updown(ike_updown, FALSE);
110 assert_hook_updown(child_updown, FALSE);
111 assert_single_payload(IN, PLV2_DELETE);
112 assert_message_empty(OUT);
113 s = exchange_test_helper->process_message(exchange_test_helper, a, NULL);
114 ck_assert_int_eq(DESTROY_ME, s);
115 call_ikesa(a, destroy);
116 assert_hook();
117 assert_hook();
118 }
119 END_TEST
120
121 Suite *ike_delete_suite_create()
122 {
123 Suite *s;
124 TCase *tc;
125
126 s = suite_create("ike delete");
127
128 tc = tcase_create("regular");
129 tcase_add_loop_test(tc, test_regular, 0, 2);
130 suite_add_tcase(s, tc);
131
132 tc = tcase_create("collisions");
133 tcase_add_test(tc, test_collision);
134 suite_add_tcase(s, tc);
135
136 return s;
137 }