1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
|
/*
* Copyright (C) 2006-2012 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2009 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <time.h>
#include "ike_sa.h"
#include <library.h>
#include <hydra.h>
#include <daemon.h>
#include <utils/linked_list.h>
#include <utils/lexparser.h>
#include <processing/jobs/retransmit_job.h>
#include <processing/jobs/delete_ike_sa_job.h>
#include <processing/jobs/send_dpd_job.h>
#include <processing/jobs/send_keepalive_job.h>
#include <processing/jobs/rekey_ike_sa_job.h>
#include <sa/ikev2/tasks/ike_auth_lifetime.h>
#ifdef ME
#include <sa/ikev2/tasks/ike_me.h>
#include <processing/jobs/initiate_mediation_job.h>
#endif
ENUM(ike_sa_state_names, IKE_CREATED, IKE_DESTROYING,
"CREATED",
"CONNECTING",
"ESTABLISHED",
"PASSIVE",
"REKEYING",
"DELETING",
"DESTROYING",
);
typedef struct private_ike_sa_t private_ike_sa_t;
typedef struct attribute_entry_t attribute_entry_t;
/**
* Private data of an ike_sa_t object.
*/
struct private_ike_sa_t {
/**
* Public members
*/
ike_sa_t public;
/**
* Identifier for the current IKE_SA.
*/
ike_sa_id_t *ike_sa_id;
/**
* IKE version of this SA.
*/
ike_version_t version;
/**
* unique numerical ID for this IKE_SA.
*/
u_int32_t unique_id;
/**
* Current state of the IKE_SA
*/
ike_sa_state_t state;
/**
* IKE configuration used to set up this IKE_SA
*/
ike_cfg_t *ike_cfg;
/**
* Peer and authentication information to establish IKE_SA.
*/
peer_cfg_t *peer_cfg;
/**
* currently used authentication ruleset, local (as auth_cfg_t)
*/
auth_cfg_t *my_auth;
/**
* list of completed local authentication rounds
*/
linked_list_t *my_auths;
/**
* list of completed remote authentication rounds
*/
linked_list_t *other_auths;
/**
* currently used authentication constraints, remote (as auth_cfg_t)
*/
auth_cfg_t *other_auth;
/**
* Selected IKE proposal
*/
proposal_t *proposal;
/**
* Juggles tasks to process messages
*/
task_manager_t *task_manager;
/**
* Address of local host
*/
host_t *my_host;
/**
* Address of remote host
*/
host_t *other_host;
#ifdef ME
/**
* Are we mediation server
*/
bool is_mediation_server;
/**
* Server reflexive host
*/
host_t *server_reflexive_host;
/**
* Connect ID
*/
chunk_t connect_id;
#endif /* ME */
/**
* Identification used for us
*/
identification_t *my_id;
/**
* Identification used for other
*/
identification_t *other_id;
/**
* set of extensions the peer supports
*/
ike_extension_t extensions;
/**
* set of condition flags currently enabled for this IKE_SA
*/
ike_condition_t conditions;
/**
* Linked List containing the child sa's of the current IKE_SA.
*/
linked_list_t *child_sas;
/**
* keymat of this IKE_SA
*/
keymat_t *keymat;
/**
* Virtual IP on local host, if any
*/
host_t *my_virtual_ip;
/**
* Virtual IP on remote host, if any
*/
host_t *other_virtual_ip;
/**
* List of configuration attributes (attribute_entry_t)
*/
linked_list_t *attributes;
/**
* list of peer's addresses, additional ones transmitted via MOBIKE
*/
linked_list_t *peer_addresses;
/**
* previously value of received DESTINATION_IP hash
*/
chunk_t nat_detection_dest;
/**
* number pending UPDATE_SA_ADDRESS (MOBIKE)
*/
u_int32_t pending_updates;
/**
* NAT keep alive interval
*/
u_int32_t keepalive_interval;
/**
* Timestamps for this IKE_SA
*/
u_int32_t stats[STAT_MAX];
/**
* how many times we have retried so far (keyingtries)
*/
u_int32_t keyingtry;
/**
* local host address to be used for IKE, set via MIGRATE kernel message
*/
host_t *local_host;
/**
* remote host address to be used for IKE, set via MIGRATE kernel message
*/
host_t *remote_host;
/**
* Flush auth configs once established?
*/
bool flush_auth_cfg;
/**
* TRUE if we are currently reauthenticating this IKE_SA
*/
bool is_reauthenticating;
};
/**
* Entry to maintain install configuration attributes during IKE_SA lifetime
*/
struct attribute_entry_t {
/** handler used to install this attribute */
attribute_handler_t *handler;
/** attribute type */
configuration_attribute_type_t type;
/** attribute data */
chunk_t data;
};
/**
* get the time of the latest traffic processed by the kernel
*/
static time_t get_use_time(private_ike_sa_t* this, bool inbound)
{
enumerator_t *enumerator;
child_sa_t *child_sa;
time_t use_time, current;
if (inbound)
{
use_time = this->stats[STAT_INBOUND];
}
else
{
use_time = this->stats[STAT_OUTBOUND];
}
enumerator = this->child_sas->create_enumerator(this->child_sas);
while (enumerator->enumerate(enumerator, &child_sa))
{
child_sa->get_usestats(child_sa, inbound, ¤t, NULL);
use_time = max(use_time, current);
}
enumerator->destroy(enumerator);
return use_time;
}
METHOD(ike_sa_t, get_unique_id, u_int32_t,
private_ike_sa_t *this)
{
return this->unique_id;
}
METHOD(ike_sa_t, get_name, char*,
private_ike_sa_t *this)
{
if (this->peer_cfg)
{
return this->peer_cfg->get_name(this->peer_cfg);
}
return "(unnamed)";
}
METHOD(ike_sa_t, get_statistic, u_int32_t,
private_ike_sa_t *this, statistic_t kind)
{
if (kind < STAT_MAX)
{
return this->stats[kind];
}
return 0;
}
METHOD(ike_sa_t, set_statistic, void,
private_ike_sa_t *this, statistic_t kind, u_int32_t value)
{
if (kind < STAT_MAX)
{
this->stats[kind] = value;
}
}
METHOD(ike_sa_t, get_my_host, host_t*,
private_ike_sa_t *this)
{
return this->my_host;
}
METHOD(ike_sa_t, set_my_host, void,
private_ike_sa_t *this, host_t *me)
{
DESTROY_IF(this->my_host);
this->my_host = me;
}
METHOD(ike_sa_t, get_other_host, host_t*,
private_ike_sa_t *this)
{
return this->other_host;
}
METHOD(ike_sa_t, set_other_host, void,
private_ike_sa_t *this, host_t *other)
{
DESTROY_IF(this->other_host);
this->other_host = other;
}
METHOD(ike_sa_t, get_peer_cfg, peer_cfg_t*,
private_ike_sa_t *this)
{
return this->peer_cfg;
}
METHOD(ike_sa_t, set_peer_cfg, void,
private_ike_sa_t *this, peer_cfg_t *peer_cfg)
{
peer_cfg->get_ref(peer_cfg);
DESTROY_IF(this->peer_cfg);
this->peer_cfg = peer_cfg;
if (this->ike_cfg == NULL)
{
this->ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
this->ike_cfg->get_ref(this->ike_cfg);
}
}
METHOD(ike_sa_t, get_auth_cfg, auth_cfg_t*,
private_ike_sa_t *this, bool local)
{
if (local)
{
return this->my_auth;
}
return this->other_auth;
}
METHOD(ike_sa_t, add_auth_cfg, void,
private_ike_sa_t *this, bool local, auth_cfg_t *cfg)
{
if (local)
{
this->my_auths->insert_last(this->my_auths, cfg);
}
else
{
this->other_auths->insert_last(this->other_auths, cfg);
}
}
METHOD(ike_sa_t, create_auth_cfg_enumerator, enumerator_t*,
private_ike_sa_t *this, bool local)
{
if (local)
{
return this->my_auths->create_enumerator(this->my_auths);
}
return this->other_auths->create_enumerator(this->other_auths);
}
/**
* Flush the stored authentication round information
*/
static void flush_auth_cfgs(private_ike_sa_t *this)
{
auth_cfg_t *cfg;
this->my_auth->purge(this->my_auth, FALSE);
this->other_auth->purge(this->other_auth, FALSE);
while (this->my_auths->remove_last(this->my_auths,
(void**)&cfg) == SUCCESS)
{
cfg->destroy(cfg);
}
while (this->other_auths->remove_last(this->other_auths,
(void**)&cfg) == SUCCESS)
{
cfg->destroy(cfg);
}
}
METHOD(ike_sa_t, get_proposal, proposal_t*,
private_ike_sa_t *this)
{
return this->proposal;
}
METHOD(ike_sa_t, set_proposal, void,
private_ike_sa_t *this, proposal_t *proposal)
{
DESTROY_IF(this->proposal);
this->proposal = proposal->clone(proposal);
}
METHOD(ike_sa_t, set_message_id, void,
private_ike_sa_t *this, bool initiate, u_int32_t mid)
{
if (initiate)
{
this->task_manager->reset(this->task_manager, mid, UINT_MAX);
}
else
{
this->task_manager->reset(this->task_manager, UINT_MAX, mid);
}
}
METHOD(ike_sa_t, send_keepalive, void,
private_ike_sa_t *this)
{
send_keepalive_job_t *job;
time_t last_out, now, diff;
if (!(this->conditions & COND_NAT_HERE) || this->keepalive_interval == 0)
{ /* disable keep alives if we are not NATed anymore */
return;
}
last_out = get_use_time(this, FALSE);
now = time_monotonic(NULL);
diff = now - last_out;
if (diff >= this->keepalive_interval)
{
packet_t *packet;
chunk_t data;
packet = packet_create();
packet->set_source(packet, this->my_host->clone(this->my_host));
packet->set_destination(packet, this->other_host->clone(this->other_host));
data.ptr = malloc(1);
data.ptr[0] = 0xFF;
data.len = 1;
packet->set_data(packet, data);
DBG1(DBG_IKE, "sending keep alive");
charon->sender->send(charon->sender, packet);
diff = 0;
}
job = send_keepalive_job_create(this->ike_sa_id);
lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
this->keepalive_interval - diff);
}
METHOD(ike_sa_t, get_ike_cfg, ike_cfg_t*,
private_ike_sa_t *this)
{
return this->ike_cfg;
}
METHOD(ike_sa_t, set_ike_cfg, void,
private_ike_sa_t *this, ike_cfg_t *ike_cfg)
{
ike_cfg->get_ref(ike_cfg);
this->ike_cfg = ike_cfg;
}
METHOD(ike_sa_t, enable_extension, void,
private_ike_sa_t *this, ike_extension_t extension)
{
this->extensions |= extension;
}
METHOD(ike_sa_t, supports_extension, bool,
private_ike_sa_t *this, ike_extension_t extension)
{
return (this->extensions & extension) != FALSE;
}
METHOD(ike_sa_t, has_condition, bool,
private_ike_sa_t *this, ike_condition_t condition)
{
return (this->conditions & condition) != FALSE;
}
METHOD(ike_sa_t, set_condition, void,
private_ike_sa_t *this, ike_condition_t condition, bool enable)
{
if (has_condition(this, condition) != enable)
{
if (enable)
{
this->conditions |= condition;
switch (condition)
{
case COND_NAT_HERE:
DBG1(DBG_IKE, "local host is behind NAT, sending keep alives");
this->conditions |= COND_NAT_ANY;
send_keepalive(this);
break;
case COND_NAT_THERE:
DBG1(DBG_IKE, "remote host is behind NAT");
this->conditions |= COND_NAT_ANY;
break;
case COND_NAT_FAKE:
DBG1(DBG_IKE, "faking NAT situation to enforce UDP encapsulation");
this->conditions |= COND_NAT_ANY;
break;
default:
break;
}
}
else
{
this->conditions &= ~condition;
switch (condition)
{
case COND_NAT_HERE:
case COND_NAT_FAKE:
case COND_NAT_THERE:
set_condition(this, COND_NAT_ANY,
has_condition(this, COND_NAT_HERE) ||
has_condition(this, COND_NAT_THERE) ||
has_condition(this, COND_NAT_FAKE));
break;
default:
break;
}
}
}
}
METHOD(ike_sa_t, send_dpd, status_t,
private_ike_sa_t *this)
{
job_t *job;
time_t diff, delay;
if (this->state == IKE_PASSIVE)
{
return INVALID_STATE;
}
delay = this->peer_cfg->get_dpd(this->peer_cfg);
if (this->task_manager->busy(this->task_manager))
{
/* an exchange is in the air, no need to start a DPD check */
diff = 0;
}
else
{
/* check if there was any inbound traffic */
time_t last_in, now;
last_in = get_use_time(this, TRUE);
now = time_monotonic(NULL);
diff = now - last_in;
if (!delay || diff >= delay)
{
/* to long ago, initiate dead peer detection */
DBG1(DBG_IKE, "sending DPD request");
this->task_manager->queue_dpd(this->task_manager);
diff = 0;
}
}
/* recheck in "interval" seconds */
if (delay)
{
job = (job_t*)send_dpd_job_create(this->ike_sa_id);
lib->scheduler->schedule_job(lib->scheduler, job, delay - diff);
}
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, get_state, ike_sa_state_t,
private_ike_sa_t *this)
{
return this->state;
}
METHOD(ike_sa_t, set_state, void,
private_ike_sa_t *this, ike_sa_state_t state)
{
bool trigger_dpd = FALSE;
DBG2(DBG_IKE, "IKE_SA %s[%d] state change: %N => %N",
get_name(this), this->unique_id,
ike_sa_state_names, this->state,
ike_sa_state_names, state);
switch (state)
{
case IKE_ESTABLISHED:
{
if (this->state == IKE_CONNECTING ||
this->state == IKE_PASSIVE)
{
job_t *job;
u_int32_t t;
/* calculate rekey, reauth and lifetime */
this->stats[STAT_ESTABLISHED] = time_monotonic(NULL);
/* schedule rekeying if we have a time which is smaller than
* an already scheduled rekeying */
t = this->peer_cfg->get_rekey_time(this->peer_cfg, TRUE);
if (t && (this->stats[STAT_REKEY] == 0 ||
(this->stats[STAT_REKEY] > t + this->stats[STAT_ESTABLISHED])))
{
this->stats[STAT_REKEY] = t + this->stats[STAT_ESTABLISHED];
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, FALSE);
lib->scheduler->schedule_job(lib->scheduler, job, t);
DBG1(DBG_IKE, "scheduling rekeying in %ds", t);
}
t = this->peer_cfg->get_reauth_time(this->peer_cfg, TRUE);
if (t && (this->stats[STAT_REAUTH] == 0 ||
(this->stats[STAT_REAUTH] > t + this->stats[STAT_ESTABLISHED])))
{
this->stats[STAT_REAUTH] = t + this->stats[STAT_ESTABLISHED];
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE);
lib->scheduler->schedule_job(lib->scheduler, job, t);
DBG1(DBG_IKE, "scheduling reauthentication in %ds", t);
}
t = this->peer_cfg->get_over_time(this->peer_cfg);
if (this->stats[STAT_REKEY] || this->stats[STAT_REAUTH])
{
if (this->stats[STAT_REAUTH] == 0)
{
this->stats[STAT_DELETE] = this->stats[STAT_REKEY];
}
else if (this->stats[STAT_REKEY] == 0)
{
this->stats[STAT_DELETE] = this->stats[STAT_REAUTH];
}
else
{
this->stats[STAT_DELETE] = min(this->stats[STAT_REKEY],
this->stats[STAT_REAUTH]);
}
this->stats[STAT_DELETE] += t;
t = this->stats[STAT_DELETE] - this->stats[STAT_ESTABLISHED];
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
lib->scheduler->schedule_job(lib->scheduler, job, t);
DBG1(DBG_IKE, "maximum IKE_SA lifetime %ds", t);
}
trigger_dpd = this->peer_cfg->get_dpd(this->peer_cfg);
}
break;
}
case IKE_DELETING:
{
/* delete may fail if a packet gets lost, so set a timeout */
job_t *job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
lib->scheduler->schedule_job(lib->scheduler, job,
HALF_OPEN_IKE_SA_TIMEOUT);
break;
}
default:
break;
}
charon->bus->ike_state_change(charon->bus, &this->public, state);
this->state = state;
if (trigger_dpd)
{
if (supports_extension(this, EXT_DPD))
{
send_dpd(this);
}
else
{
DBG1(DBG_IKE, "DPD not supported by peer, disabled");
}
}
}
METHOD(ike_sa_t, reset, void,
private_ike_sa_t *this)
{
/* the responder ID is reset, as peer may choose another one */
if (this->ike_sa_id->is_initiator(this->ike_sa_id))
{
this->ike_sa_id->set_responder_spi(this->ike_sa_id, 0);
}
set_state(this, IKE_CREATED);
flush_auth_cfgs(this);
this->keymat->destroy(this->keymat);
this->keymat = keymat_create(this->version,
this->ike_sa_id->is_initiator(this->ike_sa_id));
this->task_manager->reset(this->task_manager, 0, 0);
}
METHOD(ike_sa_t, get_keymat, keymat_t*,
private_ike_sa_t *this)
{
return this->keymat;
}
METHOD(ike_sa_t, set_virtual_ip, void,
private_ike_sa_t *this, bool local, host_t *ip)
{
if (local)
{
DBG1(DBG_IKE, "installing new virtual IP %H", ip);
if (hydra->kernel_interface->add_ip(hydra->kernel_interface, ip,
this->my_host) == SUCCESS)
{
if (this->my_virtual_ip)
{
DBG1(DBG_IKE, "removing old virtual IP %H", this->my_virtual_ip);
hydra->kernel_interface->del_ip(hydra->kernel_interface,
this->my_virtual_ip);
}
DESTROY_IF(this->my_virtual_ip);
this->my_virtual_ip = ip->clone(ip);
}
else
{
DBG1(DBG_IKE, "installing virtual IP %H failed", ip);
this->my_virtual_ip = NULL;
}
}
else
{
DESTROY_IF(this->other_virtual_ip);
this->other_virtual_ip = ip->clone(ip);
}
}
METHOD(ike_sa_t, get_virtual_ip, host_t*,
private_ike_sa_t *this, bool local)
{
if (local)
{
return this->my_virtual_ip;
}
else
{
return this->other_virtual_ip;
}
}
METHOD(ike_sa_t, add_peer_address, void,
private_ike_sa_t *this, host_t *host)
{
this->peer_addresses->insert_last(this->peer_addresses, host);
}
METHOD(ike_sa_t, create_peer_address_enumerator, enumerator_t*,
private_ike_sa_t *this)
{
if (this->peer_addresses->get_count(this->peer_addresses))
{
return this->peer_addresses->create_enumerator(this->peer_addresses);
}
/* in case we don't have MOBIKE */
return enumerator_create_single(this->other_host, NULL);
}
METHOD(ike_sa_t, clear_peer_addresses, void,
private_ike_sa_t *this)
{
enumerator_t *enumerator;
host_t *host;
enumerator = this->peer_addresses->create_enumerator(this->peer_addresses);
while (enumerator->enumerate(enumerator, (void**)&host))
{
this->peer_addresses->remove_at(this->peer_addresses,
enumerator);
host->destroy(host);
}
enumerator->destroy(enumerator);
}
METHOD(ike_sa_t, has_mapping_changed, bool,
private_ike_sa_t *this, chunk_t hash)
{
if (this->nat_detection_dest.ptr == NULL)
{
this->nat_detection_dest = chunk_clone(hash);
return FALSE;
}
if (chunk_equals(hash, this->nat_detection_dest))
{
return FALSE;
}
free(this->nat_detection_dest.ptr);
this->nat_detection_dest = chunk_clone(hash);
return TRUE;
}
METHOD(ike_sa_t, set_pending_updates, void,
private_ike_sa_t *this, u_int32_t updates)
{
this->pending_updates = updates;
}
METHOD(ike_sa_t, get_pending_updates, u_int32_t,
private_ike_sa_t *this)
{
return this->pending_updates;
}
METHOD(ike_sa_t, float_ports, void,
private_ike_sa_t *this)
{
/* do not switch if we have a custom port from MOBIKE/NAT */
if (this->my_host->get_port(this->my_host) == IKEV2_UDP_PORT)
{
this->my_host->set_port(this->my_host, IKEV2_NATT_PORT);
}
if (this->other_host->get_port(this->other_host) == IKEV2_UDP_PORT)
{
this->other_host->set_port(this->other_host, IKEV2_NATT_PORT);
}
}
METHOD(ike_sa_t, update_hosts, void,
private_ike_sa_t *this, host_t *me, host_t *other, bool force)
{
bool update = FALSE;
if (me == NULL)
{
me = this->my_host;
}
if (other == NULL)
{
other = this->other_host;
}
/* apply hosts on first received message */
if (this->my_host->is_anyaddr(this->my_host) ||
this->other_host->is_anyaddr(this->other_host))
{
set_my_host(this, me->clone(me));
set_other_host(this, other->clone(other));
update = TRUE;
}
else
{
/* update our address in any case */
if (!me->equals(me, this->my_host))
{
set_my_host(this, me->clone(me));
update = TRUE;
}
if (!other->equals(other, this->other_host))
{
/* update others address if we are NOT NATed */
if (force || !has_condition(this, COND_NAT_HERE))
{
set_other_host(this, other->clone(other));
update = TRUE;
}
}
}
/* update all associated CHILD_SAs, if required */
if (update)
{
enumerator_t *enumerator;
child_sa_t *child_sa;
enumerator = this->child_sas->create_enumerator(this->child_sas);
while (enumerator->enumerate(enumerator, (void**)&child_sa))
{
if (child_sa->update(child_sa, this->my_host,
this->other_host, this->my_virtual_ip,
has_condition(this, COND_NAT_ANY)) == NOT_SUPPORTED)
{
this->public.rekey_child_sa(&this->public,
child_sa->get_protocol(child_sa),
child_sa->get_spi(child_sa, TRUE));
}
}
enumerator->destroy(enumerator);
}
}
METHOD(ike_sa_t, generate_message, status_t,
private_ike_sa_t *this, message_t *message, packet_t **packet)
{
status_t status;
if (message->is_encoded(message))
{ /* already done */
*packet = message->get_packet(message);
return SUCCESS;
}
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
message->set_ike_sa_id(message, this->ike_sa_id);
charon->bus->message(charon->bus, message, FALSE, TRUE);
status = message->generate(message, this->keymat, packet);
if (status == SUCCESS)
{
charon->bus->message(charon->bus, message, FALSE, FALSE);
}
return status;
}
METHOD(ike_sa_t, set_kmaddress, void,
private_ike_sa_t *this, host_t *local, host_t *remote)
{
DESTROY_IF(this->local_host);
DESTROY_IF(this->remote_host);
this->local_host = local->clone(local);
this->remote_host = remote->clone(remote);
}
#ifdef ME
METHOD(ike_sa_t, act_as_mediation_server, void,
private_ike_sa_t *this)
{
charon->mediation_manager->update_sa_id(charon->mediation_manager,
this->other_id, this->ike_sa_id);
this->is_mediation_server = TRUE;
}
METHOD(ike_sa_t, get_server_reflexive_host, host_t*,
private_ike_sa_t *this)
{
return this->server_reflexive_host;
}
METHOD(ike_sa_t, set_server_reflexive_host, void,
private_ike_sa_t *this, host_t *host)
{
DESTROY_IF(this->server_reflexive_host);
this->server_reflexive_host = host;
}
METHOD(ike_sa_t, get_connect_id, chunk_t,
private_ike_sa_t *this)
{
return this->connect_id;
}
METHOD(ike_sa_t, respond, status_t,
private_ike_sa_t *this, identification_t *peer_id, chunk_t connect_id)
{
ike_me_t *task = ike_me_create(&this->public, TRUE);
task->respond(task, peer_id, connect_id);
this->task_manager->queue_task(this->task_manager, (task_t*)task);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, callback, status_t,
private_ike_sa_t *this, identification_t *peer_id)
{
ike_me_t *task = ike_me_create(&this->public, TRUE);
task->callback(task, peer_id);
this->task_manager->queue_task(this->task_manager, (task_t*)task);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, relay, status_t,
private_ike_sa_t *this, identification_t *requester, chunk_t connect_id,
chunk_t connect_key, linked_list_t *endpoints, bool response)
{
ike_me_t *task = ike_me_create(&this->public, TRUE);
task->relay(task, requester, connect_id, connect_key, endpoints, response);
this->task_manager->queue_task(this->task_manager, (task_t*)task);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, initiate_mediation, status_t,
private_ike_sa_t *this, peer_cfg_t *mediated_cfg)
{
ike_me_t *task = ike_me_create(&this->public, TRUE);
task->connect(task, mediated_cfg->get_peer_id(mediated_cfg));
this->task_manager->queue_task(this->task_manager, (task_t*)task);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, initiate_mediated, status_t,
private_ike_sa_t *this, host_t *me, host_t *other, chunk_t connect_id)
{
set_my_host(this, me->clone(me));
set_other_host(this, other->clone(other));
chunk_free(&this->connect_id);
this->connect_id = chunk_clone(connect_id);
return this->task_manager->initiate(this->task_manager);
}
#endif /* ME */
/**
* Resolve DNS host in configuration
*/
static void resolve_hosts(private_ike_sa_t *this)
{
host_t *host;
if (this->remote_host)
{
host = this->remote_host->clone(this->remote_host);
host->set_port(host, IKEV2_UDP_PORT);
}
else
{
host = host_create_from_dns(this->ike_cfg->get_other_addr(this->ike_cfg),
0, this->ike_cfg->get_other_port(this->ike_cfg));
}
if (host)
{
set_other_host(this, host);
}
if (this->local_host)
{
host = this->local_host->clone(this->local_host);
host->set_port(host, IKEV2_UDP_PORT);
}
else
{
int family = 0;
/* use same address family as for other */
if (!this->other_host->is_anyaddr(this->other_host))
{
family = this->other_host->get_family(this->other_host);
}
host = host_create_from_dns(this->ike_cfg->get_my_addr(this->ike_cfg),
family, this->ike_cfg->get_my_port(this->ike_cfg));
if (host && host->is_anyaddr(host) &&
!this->other_host->is_anyaddr(this->other_host))
{
host->destroy(host);
host = hydra->kernel_interface->get_source_addr(
hydra->kernel_interface, this->other_host, NULL);
if (host)
{
host->set_port(host, this->ike_cfg->get_my_port(this->ike_cfg));
}
else
{ /* fallback to address family specific %any(6), if configured */
host = host_create_from_dns(
this->ike_cfg->get_my_addr(this->ike_cfg),
0, this->ike_cfg->get_my_port(this->ike_cfg));
}
}
}
if (host)
{
set_my_host(this, host);
}
}
METHOD(ike_sa_t, initiate, status_t,
private_ike_sa_t *this, child_cfg_t *child_cfg, u_int32_t reqid,
traffic_selector_t *tsi, traffic_selector_t *tsr)
{
if (this->state == IKE_CREATED)
{
if (this->my_host->is_anyaddr(this->my_host) ||
this->other_host->is_anyaddr(this->other_host))
{
resolve_hosts(this);
}
if (this->other_host->is_anyaddr(this->other_host)
#ifdef ME
&& !this->peer_cfg->get_mediated_by(this->peer_cfg)
#endif /* ME */
)
{
DESTROY_IF(child_cfg);
DBG1(DBG_IKE, "unable to initiate to %%any");
charon->bus->alert(charon->bus, ALERT_PEER_ADDR_FAILED);
return DESTROY_ME;
}
set_condition(this, COND_ORIGINAL_INITIATOR, TRUE);
this->task_manager->queue_ike(this->task_manager);
}
#ifdef ME
if (this->peer_cfg->is_mediation(this->peer_cfg))
{
if (this->state == IKE_ESTABLISHED)
{
/* mediation connection is already established, retrigger state
* change to notify bus listeners */
DBG1(DBG_IKE, "mediation connection is already up");
set_state(this, IKE_ESTABLISHED);
}
DESTROY_IF(child_cfg);
}
else
#endif /* ME */
if (child_cfg)
{
/* normal IKE_SA with CHILD_SA */
this->task_manager->queue_child(this->task_manager, child_cfg, reqid,
tsi, tsr);
#ifdef ME
if (this->peer_cfg->get_mediated_by(this->peer_cfg))
{
/* mediated connection, initiate mediation process */
job_t *job = (job_t*)initiate_mediation_job_create(this->ike_sa_id);
lib->processor->queue_job(lib->processor, job);
return SUCCESS;
}
#endif /* ME */
}
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, process_message, status_t,
private_ike_sa_t *this, message_t *message)
{
status_t status;
if (this->state == IKE_PASSIVE)
{ /* do not handle messages in passive state */
return FAILED;
}
if (message->get_major_version(message) != this->version)
{
DBG1(DBG_IKE, "ignoring %N IKEv%u exchange on %N SA",
exchange_type_names, message->get_exchange_type(message),
message->get_major_version(message),
ike_version_names, this->version);
/* TODO-IKEv1: fall back to IKEv1 if we receive an IKEv1
* INVALID_MAJOR_VERSION on an IKEv2 SA. */
return FAILED;
}
status = this->task_manager->process_message(this->task_manager, message);
if (this->flush_auth_cfg && this->state == IKE_ESTABLISHED)
{
/* authentication completed */
this->flush_auth_cfg = FALSE;
flush_auth_cfgs(this);
}
return status;
}
METHOD(ike_sa_t, get_id, ike_sa_id_t*,
private_ike_sa_t *this)
{
return this->ike_sa_id;
}
METHOD(ike_sa_t, get_version, ike_version_t,
private_ike_sa_t *this)
{
return this->version;
}
METHOD(ike_sa_t, get_my_id, identification_t*,
private_ike_sa_t *this)
{
return this->my_id;
}
METHOD(ike_sa_t, set_my_id, void,
private_ike_sa_t *this, identification_t *me)
{
DESTROY_IF(this->my_id);
this->my_id = me;
}
METHOD(ike_sa_t, get_other_id, identification_t*,
private_ike_sa_t *this)
{
return this->other_id;
}
METHOD(ike_sa_t, get_other_eap_id, identification_t*,
private_ike_sa_t *this)
{
identification_t *id = NULL, *current;
enumerator_t *enumerator;
auth_cfg_t *cfg;
enumerator = this->other_auths->create_enumerator(this->other_auths);
while (enumerator->enumerate(enumerator, &cfg))
{
/* prefer EAP-Identity of last round */
current = cfg->get(cfg, AUTH_RULE_EAP_IDENTITY);
if (!current || current->get_type(current) == ID_ANY)
{
current = cfg->get(cfg, AUTH_RULE_XAUTH_IDENTITY);
}
if (!current || current->get_type(current) == ID_ANY)
{
current = cfg->get(cfg, AUTH_RULE_IDENTITY);
}
if (current && current->get_type(current) != ID_ANY)
{
id = current;
continue;
}
}
enumerator->destroy(enumerator);
if (id)
{
return id;
}
return this->other_id;
}
METHOD(ike_sa_t, set_other_id, void,
private_ike_sa_t *this, identification_t *other)
{
DESTROY_IF(this->other_id);
this->other_id = other;
}
METHOD(ike_sa_t, add_child_sa, void,
private_ike_sa_t *this, child_sa_t *child_sa)
{
this->child_sas->insert_last(this->child_sas, child_sa);
}
METHOD(ike_sa_t, get_child_sa, child_sa_t*,
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi, bool inbound)
{
enumerator_t *enumerator;
child_sa_t *current, *found = NULL;
enumerator = this->child_sas->create_enumerator(this->child_sas);
while (enumerator->enumerate(enumerator, (void**)¤t))
{
if (current->get_spi(current, inbound) == spi &&
current->get_protocol(current) == protocol)
{
found = current;
}
}
enumerator->destroy(enumerator);
return found;
}
METHOD(ike_sa_t, get_child_count, int,
private_ike_sa_t *this)
{
return this->child_sas->get_count(this->child_sas);
}
METHOD(ike_sa_t, create_child_sa_enumerator, enumerator_t*,
private_ike_sa_t *this)
{
return this->child_sas->create_enumerator(this->child_sas);
}
METHOD(ike_sa_t, remove_child_sa, void,
private_ike_sa_t *this, enumerator_t *enumerator)
{
this->child_sas->remove_at(this->child_sas, enumerator);
}
METHOD(ike_sa_t, rekey_child_sa, status_t,
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
{
if (this->state == IKE_PASSIVE)
{
return INVALID_STATE;
}
this->task_manager->queue_child_rekey(this->task_manager, protocol, spi);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, delete_child_sa, status_t,
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi, bool expired)
{
if (this->state == IKE_PASSIVE)
{
return INVALID_STATE;
}
this->task_manager->queue_child_delete(this->task_manager,
protocol, spi, expired);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, destroy_child_sa, status_t,
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
{
enumerator_t *enumerator;
child_sa_t *child_sa;
status_t status = NOT_FOUND;
enumerator = this->child_sas->create_enumerator(this->child_sas);
while (enumerator->enumerate(enumerator, (void**)&child_sa))
{
if (child_sa->get_protocol(child_sa) == protocol &&
child_sa->get_spi(child_sa, TRUE) == spi)
{
this->child_sas->remove_at(this->child_sas, enumerator);
child_sa->destroy(child_sa);
status = SUCCESS;
break;
}
}
enumerator->destroy(enumerator);
return status;
}
METHOD(ike_sa_t, delete_, status_t,
private_ike_sa_t *this)
{
switch (this->state)
{
case IKE_REKEYING:
if (this->version == IKEV1)
{ /* SA has been reauthenticated, delete */
charon->bus->ike_updown(charon->bus, &this->public, FALSE);
break;
}
/* FALL */
case IKE_ESTABLISHED:
this->task_manager->queue_ike_delete(this->task_manager);
return this->task_manager->initiate(this->task_manager);
case IKE_CREATED:
DBG1(DBG_IKE, "deleting unestablished IKE_SA");
break;
case IKE_PASSIVE:
break;
default:
DBG1(DBG_IKE, "destroying IKE_SA in state %N "
"without notification", ike_sa_state_names, this->state);
charon->bus->ike_updown(charon->bus, &this->public, FALSE);
break;
}
return DESTROY_ME;
}
METHOD(ike_sa_t, rekey, status_t,
private_ike_sa_t *this)
{
if (this->state == IKE_PASSIVE)
{
return INVALID_STATE;
}
this->task_manager->queue_ike_rekey(this->task_manager);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, reauth, status_t,
private_ike_sa_t *this)
{
if (this->state == IKE_PASSIVE)
{
return INVALID_STATE;
}
/* we can't reauthenticate as responder when we use EAP or virtual IPs.
* If the peer does not support RFC4478, there is no way to keep the
* IKE_SA up. */
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
{
DBG1(DBG_IKE, "initiator did not reauthenticate as requested");
if (this->other_virtual_ip != NULL ||
has_condition(this, COND_XAUTH_AUTHENTICATED) ||
has_condition(this, COND_EAP_AUTHENTICATED)
#ifdef ME
/* as mediation server we too cannot reauth the IKE_SA */
|| this->is_mediation_server
#endif /* ME */
)
{
time_t del, now;
del = this->stats[STAT_DELETE];
now = time_monotonic(NULL);
DBG1(DBG_IKE, "IKE_SA %s[%d] will timeout in %V",
get_name(this), this->unique_id, &now, &del);
return FAILED;
}
else
{
DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d] actively",
get_name(this), this->unique_id);
}
}
else
{
DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d]",
get_name(this), this->unique_id);
}
this->is_reauthenticating = TRUE;
this->task_manager->queue_ike_reauth(this->task_manager);
return this->task_manager->initiate(this->task_manager);
}
METHOD(ike_sa_t, reestablish, status_t,
private_ike_sa_t *this)
{
ike_sa_t *new;
host_t *host;
action_t action;
enumerator_t *enumerator;
child_sa_t *child_sa;
child_cfg_t *child_cfg;
bool restart = FALSE;
status_t status = FAILED;
if (this->is_reauthenticating)
{ /* only reauthenticate if we have children */
if (this->child_sas->get_count(this->child_sas) == 0
#ifdef ME
/* allow reauth of mediation connections without CHILD_SAs */
&& !this->peer_cfg->is_mediation(this->peer_cfg)
#endif /* ME */
)
{
DBG1(DBG_IKE, "unable to reauthenticate IKE_SA, no CHILD_SA "
"to recreate");
}
else
{
restart = TRUE;
}
}
else
{ /* check if we have children to keep up at all */
enumerator = this->child_sas->create_enumerator(this->child_sas);
while (enumerator->enumerate(enumerator, (void**)&child_sa))
{
if (this->state == IKE_DELETING)
{
action = child_sa->get_close_action(child_sa);
}
else
{
action = child_sa->get_dpd_action(child_sa);
}
switch (action)
{
case ACTION_RESTART:
restart = TRUE;
break;
case ACTION_ROUTE:
charon->traps->install(charon->traps, this->peer_cfg,
child_sa->get_config(child_sa));
break;
default:
break;
}
}
enumerator->destroy(enumerator);
#ifdef ME
/* mediation connections have no children, keep them up anyway */
if (this->peer_cfg->is_mediation(this->peer_cfg))
{
restart = TRUE;
}
#endif /* ME */
}
if (!restart)
{
return FAILED;
}
/* check if we are able to reestablish this IKE_SA */
if (!has_condition(this, COND_ORIGINAL_INITIATOR) &&
(this->other_virtual_ip != NULL ||
has_condition(this, COND_EAP_AUTHENTICATED)
#ifdef ME
|| this->is_mediation_server
#endif /* ME */
))
{
DBG1(DBG_IKE, "unable to reestablish IKE_SA due to asymmetric setup");
return FAILED;
}
new = charon->ike_sa_manager->checkout_new(charon->ike_sa_manager,
this->version, TRUE);
if (!new)
{
return FAILED;
}
new->set_peer_cfg(new, this->peer_cfg);
host = this->other_host;
new->set_other_host(new, host->clone(host));
host = this->my_host;
new->set_my_host(new, host->clone(host));
/* if we already have a virtual IP, we reuse it */
host = this->my_virtual_ip;
if (host)
{
new->set_virtual_ip(new, TRUE, host);
}
#ifdef ME
if (this->peer_cfg->is_mediation(this->peer_cfg))
{
status = new->initiate(new, NULL, 0, NULL, NULL);
}
else
#endif /* ME */
{
enumerator = this->child_sas->create_enumerator(this->child_sas);
while (enumerator->enumerate(enumerator, (void**)&child_sa))
{
if (this->is_reauthenticating)
{
switch (child_sa->get_state(child_sa))
{
case CHILD_ROUTED:
{ /* move routed child directly */
this->child_sas->remove_at(this->child_sas, enumerator);
new->add_child_sa(new, child_sa);
action = ACTION_NONE;
break;
}
default:
{ /* initiate/queue all other CHILD_SAs */
action = ACTION_RESTART;
break;
}
}
}
else
{ /* only restart CHILD_SAs that are configured accordingly */
if (this->state == IKE_DELETING)
{
action = child_sa->get_close_action(child_sa);
}
else
{
action = child_sa->get_dpd_action(child_sa);
}
}
switch (action)
{
case ACTION_RESTART:
child_cfg = child_sa->get_config(child_sa);
DBG1(DBG_IKE, "restarting CHILD_SA %s",
child_cfg->get_name(child_cfg));
child_cfg->get_ref(child_cfg);
status = new->initiate(new, child_cfg, 0, NULL, NULL);
break;
default:
continue;
}
if (status == DESTROY_ME)
{
break;
}
}
enumerator->destroy(enumerator);
}
if (status == DESTROY_ME)
{
charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, new);
status = FAILED;
}
else
{
charon->ike_sa_manager->checkin(charon->ike_sa_manager, new);
status = SUCCESS;
}
charon->bus->set_sa(charon->bus, &this->public);
return status;
}
METHOD(ike_sa_t, retransmit, status_t,
private_ike_sa_t *this, u_int32_t message_id)
{
if (this->state == IKE_PASSIVE)
{
return INVALID_STATE;
}
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
if (this->task_manager->retransmit(this->task_manager, message_id) != SUCCESS)
{
/* send a proper signal to brief interested bus listeners */
switch (this->state)
{
case IKE_CONNECTING:
{
/* retry IKE_SA_INIT/Main Mode if we have multiple keyingtries */
u_int32_t tries = this->peer_cfg->get_keyingtries(this->peer_cfg);
this->keyingtry++;
if (tries == 0 || tries > this->keyingtry)
{
DBG1(DBG_IKE, "peer not responding, trying again (%d/%d)",
this->keyingtry + 1, tries);
reset(this);
resolve_hosts(this);
this->task_manager->queue_ike(this->task_manager);
return this->task_manager->initiate(this->task_manager);
}
DBG1(DBG_IKE, "establishing IKE_SA failed, peer not responding");
break;
}
case IKE_DELETING:
DBG1(DBG_IKE, "proper IKE_SA delete failed, peer not responding");
if (this->is_reauthenticating)
{
DBG1(DBG_IKE, "delete during reauthentication failed, "
"trying to reestablish IKE_SA anyway");
reestablish(this);
}
break;
case IKE_REKEYING:
DBG1(DBG_IKE, "rekeying IKE_SA failed, peer not responding");
/* FALL */
default:
reestablish(this);
break;
}
return DESTROY_ME;
}
return SUCCESS;
}
METHOD(ike_sa_t, set_auth_lifetime, status_t,
private_ike_sa_t *this, u_int32_t lifetime)
{
u_int32_t diff, hard, soft, now;
ike_auth_lifetime_t *task;
bool send_update;
diff = this->peer_cfg->get_over_time(this->peer_cfg);
now = time_monotonic(NULL);
hard = now + lifetime;
soft = hard - diff;
/* check if we have to send an AUTH_LIFETIME to enforce the new lifetime.
* We send the notify in IKE_AUTH if not yet ESTABLISHED. */
send_update = this->state == IKE_ESTABLISHED && this->version == IKEV2 &&
!has_condition(this, COND_ORIGINAL_INITIATOR) &&
(this->other_virtual_ip != NULL ||
has_condition(this, COND_EAP_AUTHENTICATED));
if (lifetime < diff)
{
this->stats[STAT_REAUTH] = now;
if (!send_update)
{
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
"starting reauthentication", lifetime);
lib->processor->queue_job(lib->processor,
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE));
}
}
else if (this->stats[STAT_REAUTH] == 0 ||
this->stats[STAT_REAUTH] > soft)
{
this->stats[STAT_REAUTH] = soft;
if (!send_update)
{
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, scheduling "
"reauthentication in %ds", lifetime, lifetime - diff);
lib->scheduler->schedule_job(lib->scheduler,
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE),
lifetime - diff);
}
}
else
{
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
"reauthentication already scheduled in %ds", lifetime,
this->stats[STAT_REAUTH] - time_monotonic(NULL));
send_update = FALSE;
}
/* give at least some seconds to reauthenticate */
this->stats[STAT_DELETE] = max(hard, now + 10);
if (send_update)
{
task = ike_auth_lifetime_create(&this->public, TRUE);
this->task_manager->queue_task(this->task_manager, &task->task);
return this->task_manager->initiate(this->task_manager);
}
return SUCCESS;
}
/**
* Check if the current combination of source and destination address is still
* valid.
*/
static bool is_current_path_valid(private_ike_sa_t *this)
{
bool valid = FALSE;
host_t *src;
src = hydra->kernel_interface->get_source_addr(hydra->kernel_interface,
this->other_host, this->my_host);
if (src)
{
if (src->ip_equals(src, this->my_host))
{
valid = TRUE;
}
src->destroy(src);
}
return valid;
}
/**
* Check if we have any path avialable for this IKE SA.
*/
static bool is_any_path_valid(private_ike_sa_t *this)
{
bool valid = FALSE;
enumerator_t *enumerator;
host_t *src = NULL, *addr;
DBG1(DBG_IKE, "old path is not available anymore, try to find another");
enumerator = create_peer_address_enumerator(this);
while (enumerator->enumerate(enumerator, &addr))
{
DBG1(DBG_IKE, "looking for a route to %H ...", addr);
src = hydra->kernel_interface->get_source_addr(
hydra->kernel_interface, addr, NULL);
if (src)
{
break;
}
}
enumerator->destroy(enumerator);
if (src)
{
valid = TRUE;
src->destroy(src);
}
return valid;
}
METHOD(ike_sa_t, roam, status_t,
private_ike_sa_t *this, bool address)
{
switch (this->state)
{
case IKE_CREATED:
case IKE_DELETING:
case IKE_DESTROYING:
case IKE_PASSIVE:
return SUCCESS;
default:
break;
}
/* keep existing path if possible */
if (is_current_path_valid(this))
{
DBG2(DBG_IKE, "keeping connection path %H - %H",
this->my_host, this->other_host);
set_condition(this, COND_STALE, FALSE);
if (supports_extension(this, EXT_MOBIKE) && address)
{ /* if any addresses changed, send an updated list */
DBG1(DBG_IKE, "sending address list update using MOBIKE");
this->task_manager->queue_mobike(this->task_manager, FALSE, TRUE);
return this->task_manager->initiate(this->task_manager);
}
return SUCCESS;
}
if (!is_any_path_valid(this))
{
DBG1(DBG_IKE, "no route found to reach %H, MOBIKE update deferred",
this->other_host);
set_condition(this, COND_STALE, TRUE);
return SUCCESS;
}
set_condition(this, COND_STALE, FALSE);
/* update addresses with mobike, if supported ... */
if (supports_extension(this, EXT_MOBIKE))
{
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
{ /* responder updates the peer about changed address config */
DBG1(DBG_IKE, "sending address list update using MOBIKE, "
"implicitly requesting an address change");
address = TRUE;
}
else
{
DBG1(DBG_IKE, "requesting address change using MOBIKE");
}
this->task_manager->queue_mobike(this->task_manager, TRUE, address);
return this->task_manager->initiate(this->task_manager);
}
/* ... reauth if not */
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
{ /* responder does not reauthenticate */
set_condition(this, COND_STALE, TRUE);
return SUCCESS;
}
DBG1(DBG_IKE, "reauthenticating IKE_SA due to address change");
return reauth(this);
}
METHOD(ike_sa_t, add_configuration_attribute, void,
private_ike_sa_t *this, attribute_handler_t *handler,
configuration_attribute_type_t type, chunk_t data)
{
attribute_entry_t *entry = malloc_thing(attribute_entry_t);
entry->handler = handler;
entry->type = type;
entry->data = chunk_clone(data);
this->attributes->insert_last(this->attributes, entry);
}
METHOD(ike_sa_t, create_task_enumerator, enumerator_t*,
private_ike_sa_t *this, task_queue_t queue)
{
return this->task_manager->create_task_enumerator(this->task_manager, queue);
}
METHOD(ike_sa_t, flush_queue, void,
private_ike_sa_t *this, task_queue_t queue)
{
this->task_manager->flush_queue(this->task_manager, queue);
}
METHOD(ike_sa_t, queue_task, void,
private_ike_sa_t *this, task_t *task)
{
this->task_manager->queue_task(this->task_manager, task);
}
METHOD(ike_sa_t, inherit, void,
private_ike_sa_t *this, ike_sa_t *other_public)
{
private_ike_sa_t *other = (private_ike_sa_t*)other_public;
child_sa_t *child_sa;
attribute_entry_t *entry;
enumerator_t *enumerator;
auth_cfg_t *cfg;
/* apply hosts and ids */
this->my_host->destroy(this->my_host);
this->other_host->destroy(this->other_host);
this->my_id->destroy(this->my_id);
this->other_id->destroy(this->other_id);
this->my_host = other->my_host->clone(other->my_host);
this->other_host = other->other_host->clone(other->other_host);
this->my_id = other->my_id->clone(other->my_id);
this->other_id = other->other_id->clone(other->other_id);
/* apply virtual assigned IPs... */
if (other->my_virtual_ip)
{
this->my_virtual_ip = other->my_virtual_ip;
other->my_virtual_ip = NULL;
}
if (other->other_virtual_ip)
{
this->other_virtual_ip = other->other_virtual_ip;
other->other_virtual_ip = NULL;
}
/* authentication information */
enumerator = other->my_auths->create_enumerator(other->my_auths);
while (enumerator->enumerate(enumerator, &cfg))
{
this->my_auths->insert_last(this->my_auths, cfg->clone(cfg));
}
enumerator->destroy(enumerator);
enumerator = other->other_auths->create_enumerator(other->other_auths);
while (enumerator->enumerate(enumerator, &cfg))
{
this->other_auths->insert_last(this->other_auths, cfg->clone(cfg));
}
enumerator->destroy(enumerator);
/* ... and configuration attributes */
while (other->attributes->remove_last(other->attributes,
(void**)&entry) == SUCCESS)
{
this->attributes->insert_first(this->attributes, entry);
}
/* inherit all conditions */
this->conditions = other->conditions;
if (this->conditions & COND_NAT_HERE)
{
send_keepalive(this);
}
#ifdef ME
if (other->is_mediation_server)
{
act_as_mediation_server(this);
}
else if (other->server_reflexive_host)
{
this->server_reflexive_host = other->server_reflexive_host->clone(
other->server_reflexive_host);
}
#endif /* ME */
/* adopt all children */
while (other->child_sas->remove_last(other->child_sas,
(void**)&child_sa) == SUCCESS)
{
this->child_sas->insert_first(this->child_sas, (void*)child_sa);
}
/* move pending tasks to the new IKE_SA */
this->task_manager->adopt_tasks(this->task_manager, other->task_manager);
/* reauthentication timeout survives a rekeying */
if (other->stats[STAT_REAUTH])
{
time_t reauth, delete, now = time_monotonic(NULL);
this->stats[STAT_REAUTH] = other->stats[STAT_REAUTH];
reauth = this->stats[STAT_REAUTH] - now;
delete = reauth + this->peer_cfg->get_over_time(this->peer_cfg);
this->stats[STAT_DELETE] = this->stats[STAT_REAUTH] + delete;
DBG1(DBG_IKE, "rescheduling reauthentication in %ds after rekeying, "
"lifetime reduced to %ds", reauth, delete);
lib->scheduler->schedule_job(lib->scheduler,
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE), reauth);
lib->scheduler->schedule_job(lib->scheduler,
(job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE), delete);
}
}
METHOD(ike_sa_t, destroy, void,
private_ike_sa_t *this)
{
attribute_entry_t *entry;
charon->bus->set_sa(charon->bus, &this->public);
set_state(this, IKE_DESTROYING);
DESTROY_IF(this->task_manager);
/* remove attributes first, as we pass the IKE_SA to the handler */
while (this->attributes->remove_last(this->attributes,
(void**)&entry) == SUCCESS)
{
hydra->attributes->release(hydra->attributes, entry->handler,
this->other_id, entry->type, entry->data);
free(entry->data.ptr);
free(entry);
}
this->attributes->destroy(this->attributes);
this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
/* unset SA after here to avoid usage by the listeners */
charon->bus->set_sa(charon->bus, NULL);
DESTROY_IF(this->keymat);
if (this->my_virtual_ip)
{
hydra->kernel_interface->del_ip(hydra->kernel_interface,
this->my_virtual_ip);
this->my_virtual_ip->destroy(this->my_virtual_ip);
}
if (this->other_virtual_ip)
{
if (this->peer_cfg && this->peer_cfg->get_pool(this->peer_cfg))
{
hydra->attributes->release_address(hydra->attributes,
this->peer_cfg->get_pool(this->peer_cfg),
this->other_virtual_ip, get_other_eap_id(this));
}
this->other_virtual_ip->destroy(this->other_virtual_ip);
}
this->peer_addresses->destroy_offset(this->peer_addresses,
offsetof(host_t, destroy));
#ifdef ME
if (this->is_mediation_server)
{
charon->mediation_manager->remove(charon->mediation_manager,
this->ike_sa_id);
}
DESTROY_IF(this->server_reflexive_host);
chunk_free(&this->connect_id);
#endif /* ME */
free(this->nat_detection_dest.ptr);
DESTROY_IF(this->my_host);
DESTROY_IF(this->other_host);
DESTROY_IF(this->my_id);
DESTROY_IF(this->other_id);
DESTROY_IF(this->local_host);
DESTROY_IF(this->remote_host);
DESTROY_IF(this->ike_cfg);
DESTROY_IF(this->peer_cfg);
DESTROY_IF(this->proposal);
this->my_auth->destroy(this->my_auth);
this->other_auth->destroy(this->other_auth);
this->my_auths->destroy_offset(this->my_auths,
offsetof(auth_cfg_t, destroy));
this->other_auths->destroy_offset(this->other_auths,
offsetof(auth_cfg_t, destroy));
this->ike_sa_id->destroy(this->ike_sa_id);
free(this);
}
/*
* Described in header.
*/
ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
ike_version_t version)
{
private_ike_sa_t *this;
static u_int32_t unique_id = 0;
if (version == IKE_ANY)
{ /* prefer IKEv2 if protocol not specified */
#ifdef USE_IKEV2
version = IKEV2;
#else
version = IKEV1;
#endif
}
INIT(this,
.public = {
.get_version = _get_version,
.get_state = _get_state,
.set_state = _set_state,
.get_name = _get_name,
.get_statistic = _get_statistic,
.set_statistic = _set_statistic,
.process_message = _process_message,
.initiate = _initiate,
.get_ike_cfg = _get_ike_cfg,
.set_ike_cfg = _set_ike_cfg,
.get_peer_cfg = _get_peer_cfg,
.set_peer_cfg = _set_peer_cfg,
.get_auth_cfg = _get_auth_cfg,
.create_auth_cfg_enumerator = _create_auth_cfg_enumerator,
.add_auth_cfg = _add_auth_cfg,
.get_proposal = _get_proposal,
.set_proposal = _set_proposal,
.get_id = _get_id,
.get_my_host = _get_my_host,
.set_my_host = _set_my_host,
.get_other_host = _get_other_host,
.set_other_host = _set_other_host,
.set_message_id = _set_message_id,
.float_ports = _float_ports,
.update_hosts = _update_hosts,
.get_my_id = _get_my_id,
.set_my_id = _set_my_id,
.get_other_id = _get_other_id,
.set_other_id = _set_other_id,
.get_other_eap_id = _get_other_eap_id,
.enable_extension = _enable_extension,
.supports_extension = _supports_extension,
.set_condition = _set_condition,
.has_condition = _has_condition,
.set_pending_updates = _set_pending_updates,
.get_pending_updates = _get_pending_updates,
.create_peer_address_enumerator = _create_peer_address_enumerator,
.add_peer_address = _add_peer_address,
.clear_peer_addresses = _clear_peer_addresses,
.has_mapping_changed = _has_mapping_changed,
.retransmit = _retransmit,
.delete = _delete_,
.destroy = _destroy,
.send_dpd = _send_dpd,
.send_keepalive = _send_keepalive,
.get_keymat = _get_keymat,
.add_child_sa = _add_child_sa,
.get_child_sa = _get_child_sa,
.get_child_count = _get_child_count,
.create_child_sa_enumerator = _create_child_sa_enumerator,
.remove_child_sa = _remove_child_sa,
.rekey_child_sa = _rekey_child_sa,
.delete_child_sa = _delete_child_sa,
.destroy_child_sa = _destroy_child_sa,
.rekey = _rekey,
.reauth = _reauth,
.reestablish = _reestablish,
.set_auth_lifetime = _set_auth_lifetime,
.roam = _roam,
.inherit = _inherit,
.generate_message = _generate_message,
.reset = _reset,
.get_unique_id = _get_unique_id,
.set_virtual_ip = _set_virtual_ip,
.get_virtual_ip = _get_virtual_ip,
.add_configuration_attribute = _add_configuration_attribute,
.set_kmaddress = _set_kmaddress,
.create_task_enumerator = _create_task_enumerator,
.flush_queue = _flush_queue,
.queue_task = _queue_task,
#ifdef ME
.act_as_mediation_server = _act_as_mediation_server,
.get_server_reflexive_host = _get_server_reflexive_host,
.set_server_reflexive_host = _set_server_reflexive_host,
.get_connect_id = _get_connect_id,
.initiate_mediation = _initiate_mediation,
.initiate_mediated = _initiate_mediated,
.relay = _relay,
.callback = _callback,
.respond = _respond,
#endif /* ME */
},
.ike_sa_id = ike_sa_id->clone(ike_sa_id),
.version = version,
.child_sas = linked_list_create(),
.my_host = host_create_any(AF_INET),
.other_host = host_create_any(AF_INET),
.my_id = identification_create_from_encoding(ID_ANY, chunk_empty),
.other_id = identification_create_from_encoding(ID_ANY, chunk_empty),
.keymat = keymat_create(version, initiator),
.state = IKE_CREATED,
.stats[STAT_INBOUND] = time_monotonic(NULL),
.stats[STAT_OUTBOUND] = time_monotonic(NULL),
.my_auth = auth_cfg_create(),
.other_auth = auth_cfg_create(),
.my_auths = linked_list_create(),
.other_auths = linked_list_create(),
.unique_id = ++unique_id,
.peer_addresses = linked_list_create(),
.attributes = linked_list_create(),
.keepalive_interval = lib->settings->get_time(lib->settings,
"%s.keep_alive", KEEPALIVE_INTERVAL, charon->name),
.flush_auth_cfg = lib->settings->get_bool(lib->settings,
"%s.flush_auth_cfg", FALSE, charon->name),
);
if (version == IKEV2)
{ /* always supported with IKEv2 */
enable_extension(this, EXT_DPD);
}
this->task_manager = task_manager_create(&this->public);
this->my_host->set_port(this->my_host, IKEV2_UDP_PORT);
if (!this->task_manager || !this->keymat)
{
DBG1(DBG_IKE, "IKE version %d not supported", this->version);
destroy(this);
return NULL;
}
return &this->public;
}
|