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 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
|
/* connection routing, for libreswan
*
* Copyright (C) 2023 Andrew Cagney
*
* 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 <https://www.gnu.org/licenses/gpl2.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 "enum_names.h"
#include "defs.h"
#include "routing.h"
#include "connections.h"
#include "pending.h"
#include "log.h"
#include "kernel.h"
#include "kernel_policy.h"
#include "revival.h"
#include "ikev2_ike_sa_init.h" /* for initiate_v2_IKE_SA_INIT_request() */
#include "pluto_stats.h"
#include "foodgroups.h" /* for connection_group_{route,unroute}() */
#include "orient.h"
#include "initiated_by.h"
#include "updown.h"
#include "instantiate.h"
#include "connection_event.h"
#include "ipsec_interface.h"
enum routing_event {
/* fiddle with the ROUTE bit */
CONNECTION_ROUTE,
CONNECTION_UNROUTE,
/* start/stop a connection */
CONNECTION_INITIATED, /* also revive */
CONNECTION_PENDING,
CONNECTION_RESCHEDULE,
/* establish a connection (speculative) */
CONNECTION_ESTABLISH_IKE,
CONNECTION_ESTABLISH_INBOUND,
CONNECTION_ESTABLISH_OUTBOUND,
/* tear down a connection */
CONNECTION_TEARDOWN_IKE,
CONNECTION_TEARDOWN_CHILD,
/* mobike */
CONNECTION_SUSPEND,
CONNECTION_RESUME,
#define ROUTING_EVENT_ROOF (CONNECTION_RESUME+1)
};
static const char *routing_event_name[] = {
#define S(E) [E] = #E
S(CONNECTION_ROUTE),
S(CONNECTION_UNROUTE),
S(CONNECTION_INITIATED),
S(CONNECTION_ESTABLISH_IKE),
S(CONNECTION_ESTABLISH_INBOUND),
S(CONNECTION_ESTABLISH_OUTBOUND),
S(CONNECTION_PENDING),
S(CONNECTION_RESCHEDULE),
S(CONNECTION_TEARDOWN_IKE),
S(CONNECTION_TEARDOWN_CHILD),
S(CONNECTION_SUSPEND),
S(CONNECTION_RESUME),
#undef S
};
static enum_names routing_event_names = {
0, ROUTING_EVENT_ROOF-1,
ARRAY_REF(routing_event_name),
"CONNECTION_",
NULL,
};
struct routing_annex {
struct ike_sa **ike;
struct child_sa **child;
enum initiated_by initiated_by;
const char *story;
bool (*dispatch_ok)(struct connection *c, struct logger *logger,
const struct routing_annex *e);
void (*post_op)(const struct routing_annex *e);
where_t where;
};
static bool dispatch(const enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e);
static bool dispatch_1(enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e);
static bool connection_cannot_die(enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
const char *subplot = (event == CONNECTION_TEARDOWN_IKE ? e->story :
event == CONNECTION_TEARDOWN_CHILD ? e->story :
event == CONNECTION_RESCHEDULE ? e->story :
"???");
if (e->child != NULL) {
struct child_sa *child = (*e->child);
if (child != NULL) {
PEXPECT(logger, child->sa.st_connection == c);
return scheduled_child_revival(child, subplot);
}
}
if (e->ike != NULL) {
struct ike_sa *ike = (*e->ike);
if (ike != NULL) {
PEXPECT(logger, ike->sa.st_connection == c);
return scheduled_ike_revival(ike, subplot);
}
}
return scheduled_connection_revival(c, subplot);
}
static void jam_sa(struct jambuf *buf, struct state *st, const char **sep)
{
if (st != NULL) {
jam_string(buf, (*sep)); (*sep) = " ";
jam_string(buf, state_sa_short_name(st));
jam_string(buf, " ");
jam_so(buf, st->st_serialno);
if (st == NULL) {
jam_string(buf, " (deleted)");
} else {
jam_string(buf, " (");
jam_string(buf, st->st_state->short_name);
jam_string(buf, ")");
}
}
}
static void jam_so_update(struct jambuf *buf,
enum connection_owner owner,
so_serial_t old, so_serial_t new,
const char **prefix)
{
if (old != SOS_NOBODY || new != SOS_NOBODY) {
jam_string(buf, (*prefix)); (*prefix) = " ";
jam_enum(buf, &connection_owner_names, owner);
jam_string(buf, " ");
jam_so(buf, old);
if (old != new) {
jam_string(buf, "->");
jam_so(buf, new);
}
}
}
static void jam_routing(struct jambuf *buf,
struct connection *c)
{
jam_string(buf, " ");
jam_connection_co(buf, c);
jam(buf, "@%p", c);
if (never_negotiate(c)) {
jam_string(buf, "; never-negotiate");
}
const char *sep = "; ";
for (enum connection_owner owner = 0; owner < elemsof(c->routing.owner); owner++) {
/* same value - no actual update */
jam_so_update(buf, owner, c->routing.owner[owner], c->routing.owner[owner], &sep);
}
}
static void jam_routing_annex(struct jambuf *buf, const struct routing_annex *e)
{
const char *sep = " ";
if (e->ike != NULL && (*e->ike) != NULL) {
jam_sa(buf, &(*e->ike)->sa, &sep);
}
if (e->child != NULL && (*e->child) != NULL) {
jam_sa(buf, &(*e->child)->sa, &sep);
}
jam_string(buf, sep); sep = " ";
jam_string(buf, "by=");
jam_enum_short(buf, &initiated_by_names, e->initiated_by);
jam_string(buf, ";");
}
static void jam_event(struct jambuf *buf,
struct connection *c,
const struct routing_annex *e)
{
jam_routing_annex(buf, e);
jam_routing(buf, c);
}
static void jam_routing_prefix(struct jambuf *buf,
const char *prefix,
enum routing_event event,
enum routing old_routing,
enum routing new_routing,
enum connection_kind kind)
{
jam_string(buf, "routing: ");
jam_string(buf, prefix);
jam_string(buf, " ");
jam_enum_short(buf, &routing_event_names, event);
jam_string(buf, ", ");
jam_enum_short(buf, &routing_names, old_routing);
if (old_routing != new_routing) {
jam_string(buf, "->");
jam_enum_short(buf, &routing_names, new_routing);
}
jam_string(buf, ", ");
jam_enum_short(buf, &connection_kind_names, kind);
jam_string(buf, ";");
}
struct old_routing {
/* capture what can change */
const char *ike_name;
so_serial_t ike_so;
const char *child_name;
so_serial_t child_so;
so_serial_t owner[CONNECTION_OWNER_ROOF];
enum routing routing;
unsigned revival_attempt;
};
static struct old_routing ldbg_routing_start(enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
struct old_routing old = {
/* capture what can change */
.ike_name = (e->ike == NULL || (*e->ike) == NULL ? SOS_NOBODY :
state_sa_short_name(&(*e->ike)->sa)),
.ike_so = (e->ike == NULL || (*e->ike) == NULL ? SOS_NOBODY :
(*e->ike)->sa.st_serialno),
.child_name = (e->child == NULL || (*e->child) == NULL ? SOS_NOBODY :
state_sa_short_name(&(*e->child)->sa)),
.child_so = (e->child == NULL || (*e->child) == NULL ? SOS_NOBODY :
(*e->child)->sa.st_serialno),
.routing = c->routing.state,
.revival_attempt = c->revival.attempt,
};
for (unsigned i = 0; i < elemsof(old.owner); i++) {
old.owner[i] = c->routing.owner[i];
}
if (DBGP(DBG_ROUTING)) {
/*
* XXX: force ADD_PREFIX so that the connection name
* is before the interesting stuff.
*/
LLOG_JAMBUF(DEBUG_STREAM|ADD_PREFIX, logger, buf) {
jam_routing_prefix(buf, "start", event,
c->routing.state, c->routing.state,
c->local->kind);
jam_event(buf, c, e);
jam_string(buf, " ");
jam_where(buf, e->where);
}
}
return old;
}
static void ldbg_routing_stop(enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e,
const struct old_routing *old,
bool ok)
{
if (DBGP(DBG_ROUTING)) {
/*
* XXX: force ADD_PREFIX so that the connection name
* is before the interesting stuff.
*/
LLOG_JAMBUF(DEBUG_STREAM|ADD_PREFIX, logger, buf) {
jam_routing_prefix(buf, "stop", event,
old->routing, c->routing.state,
c->local->kind);
jam(buf, " ok=%s", bool_str(ok));
/* various SAs */
const char *sep = "; ";
for (enum connection_owner owner = 0;
owner < elemsof(c->routing.owner); owner++) {
jam_so_update(buf, owner,
old->owner[owner],
c->routing.owner[owner], &sep);
}
if (old->revival_attempt != c->revival.attempt) {
jam_string(buf, sep); sep = " ";
jam(buf, "revival %u->%u",
old->revival_attempt,
c->revival.attempt);
}
jam_string(buf, " ");
jam_where(buf, e->where);
}
}
}
PRINTF_LIKE(2)
void ldbg_routing(struct logger *logger, const char *fmt, ...)
{
if (DBGP(DBG_ROUTING)) {
LLOG_JAMBUF(DEBUG_STREAM|ADD_PREFIX, logger, buf) {
jam_string(buf, "routing: ");
va_list ap;
va_start(ap, fmt);
jam_va_list(buf, fmt, ap);
va_end(ap);
}
}
}
/*
* The IKEv1 responder spreads establishing a Child SA over two
* transactions (messages): INBOUND is established while processing
* the first Quick Mode request; and OUTBOUND while processing the
* second Quick Mode request.
*
* IKEv2 and IKEv1 initiators all establish the Child SA in one
* transaction (message). However, to make error recovery slightly
* simpler, this single transaction is brown down just like for an
* IKEv1 responder.
*/
bool connection_establish_inbound(struct child_sa *child, where_t where)
{
struct connection *cc = child->sa.st_connection;
struct logger *logger = child->sa.logger;
struct routing_annex annex = {
.child = &child,
.where = where,
.initiated_by = INITIATED_BY_PEER,
};
return dispatch(CONNECTION_ESTABLISH_INBOUND, cc, logger, &annex);
}
bool connection_establish_outbound(struct ike_sa *ike, struct child_sa *child, where_t where)
{
struct connection *cc = child->sa.st_connection;
struct logger *logger = child->sa.logger;
struct routing_annex annex = {
.child = &child,
.ike = &ike,
.where = where,
.initiated_by = INITIATED_BY_PEER,
};
return dispatch(CONNECTION_ESTABLISH_OUTBOUND, cc, logger, &annex);
}
bool connection_establish_child(struct ike_sa *ike, struct child_sa *child, where_t where)
{
struct connection *cc = child->sa.st_connection;
struct logger *logger = child->sa.logger;
struct routing_annex annex = {
.child = &child,
.ike = &ike,
.where = where,
.initiated_by = INITIATED_BY_PEER,
};
/*
* The IKEv1 initiator, and IKEv2 initiators and responders
* always establish both inbound and outbound during the same
* exchange.
*
* However, since this can fail part way through, it is broken
* down into two transactions. That way, hopefully, the
* outbound code doesn't need to revert changes made by the
* inbound code.
*/
return (dispatch(CONNECTION_ESTABLISH_INBOUND, cc, logger, &annex) &&
dispatch(CONNECTION_ESTABLISH_OUTBOUND, cc, logger, &annex));
}
enum shunt_kind routing_shunt_kind(enum routing routing)
{
switch (routing) {
case RT_UNROUTED:
return SHUNT_KIND_NONE;
case RT_ROUTED_NEVER_NEGOTIATE:
return SHUNT_KIND_NEVER_NEGOTIATE;
case RT_ROUTED_ONDEMAND:
return SHUNT_KIND_ONDEMAND;
case RT_UNROUTED_BARE_NEGOTIATION:
case RT_UNROUTED_NEGOTIATION:
case RT_ROUTED_NEGOTIATION:
return SHUNT_KIND_NEGOTIATION;
case RT_UNROUTED_INBOUND:
case RT_UNROUTED_INBOUND_NEGOTIATION:
case RT_ROUTED_INBOUND_NEGOTIATION:
return SHUNT_KIND_NEGOTIATION; /*SHUNT_KIND_IPSEC?*/
case RT_UNROUTED_TUNNEL:
case RT_ROUTED_TUNNEL:
return SHUNT_KIND_IPSEC;
case RT_ROUTED_FAILURE:
return SHUNT_KIND_FAILURE;
}
bad_case(routing);
}
enum shunt_kind spd_shunt_kind(const struct spd *spd)
{
return routing_shunt_kind(spd->connection->routing.state);
}
/*
* True when updown(route) has been run; not <<ipsec route>>.
*/
bool kernel_route_installed(const struct connection *c)
{
enum routing r = c->routing.state;
switch (r) {
case RT_ROUTED_ONDEMAND:
case RT_ROUTED_NEVER_NEGOTIATE:
case RT_ROUTED_NEGOTIATION:
case RT_ROUTED_INBOUND_NEGOTIATION:
case RT_ROUTED_TUNNEL:
case RT_ROUTED_FAILURE:
return true;
case RT_UNROUTED:
case RT_UNROUTED_BARE_NEGOTIATION:
case RT_UNROUTED_NEGOTIATION:
case RT_UNROUTED_INBOUND:
case RT_UNROUTED_INBOUND_NEGOTIATION:
case RT_UNROUTED_TUNNEL:
return false;
}
bad_case(r);
}
bool kernel_policy_installed(const struct connection *c)
{
switch (c->routing.state) {
case RT_UNROUTED:
case RT_UNROUTED_NEGOTIATION:
case RT_UNROUTED_BARE_NEGOTIATION:
return false;
case RT_ROUTED_ONDEMAND:
case RT_ROUTED_NEGOTIATION:
case RT_UNROUTED_INBOUND:
case RT_UNROUTED_INBOUND_NEGOTIATION:
case RT_ROUTED_NEVER_NEGOTIATE:
case RT_ROUTED_INBOUND_NEGOTIATION:
case RT_ROUTED_TUNNEL:
case RT_ROUTED_FAILURE:
case RT_UNROUTED_TUNNEL:
return true;
}
bad_case(c->routing.state);
}
static void set_routing(struct connection *c,
enum routing new_routing)
{
c->routing_sa = SOS_NOBODY;
c->negotiating_child_sa = SOS_NOBODY;
c->established_child_sa = SOS_NOBODY;
c->routing.state = new_routing;
}
static void set_negotiating(struct connection *c,
enum routing new_routing,
const struct routing_annex *e)
{
/*
* The IKE and Child share the same initiate event but are
* dispatched separately.
*
* A negotiating Child SA using an existing IKE SA won't have
* .established_ike_sa set (ditto for .negotiating_ike_sa).
* Should it?
*/
if ((e->child) != NULL && (*e->child) != NULL) {
PEXPECT_WHERE((*e->child)->sa.logger, e->where,
c->negotiating_child_sa == SOS_NOBODY);
PEXPECT_WHERE((*e->child)->sa.logger, e->where,
c->established_child_sa == SOS_NOBODY);
c->routing_sa = (*e->child)->sa.st_serialno;
c->negotiating_child_sa = (*e->child)->sa.st_serialno;
c->established_child_sa = SOS_NOBODY;
c->routing.state = new_routing;
return;
}
if ((e->ike) != NULL && (*e->ike) != NULL) {
c->routing_sa = (*e->ike)->sa.st_serialno;
c->negotiating_ike_sa = (*e->ike)->sa.st_serialno;
c->established_ike_sa = SOS_NOBODY;
c->routing.state = new_routing;
return;
}
/*
* For instance when the initiated connection is on the
* pending queue. Should such a connection get its owner
* updated? It definitely needs its routing updated so that
* pending knows what to change when things progress.
*
* XXX: but isn't that a PENDING event? No, currently
* connection_pending() is dispatched as an INITIATE event.
*/
#if 1
ldbg_routing(c->logger, "no initiating IKE or Child SA; assumed to be pending");
c->routing.state = new_routing;
#else
llog_pexpect(c->logger, e->where,
"no initiating IKE or Child SA; assumed to be pending; leaving routing alone");
#endif
}
static void set_established_inbound(struct connection *c,
enum routing new_routing,
const struct routing_annex *e)
{
struct child_sa *child = (*e->child);
c->routing_sa = child->sa.st_serialno;
c->negotiating_child_sa = child->sa.st_serialno;
c->routing.state = new_routing;
}
static void set_established_outbound(struct connection *c,
enum routing routing,
const struct routing_annex *e)
{
struct child_sa *child = (*e->child);
struct ike_sa *ike = (e->ike != NULL ? (*e->ike) : NULL);
PEXPECT(child->sa.logger, child->sa.st_connection == c);
/*
* Do we have star-crossed-streams? When this happens
* try to mitigate the damage.
*/
if (ike != NULL) {
/* by definition */
PEXPECT(child->sa.logger, ike->sa.st_serialno == child->sa.st_clonedfrom);
for (enum connection_owner owner = IKE_SA_OWNER_FLOOR;
owner < IKE_SA_OWNER_ROOF; owner++) {
if (ike->sa.st_connection == c) {
if (ike->sa.st_serialno != c->routing.owner[owner]) {
/* child/ike have crossed streams */
enum_buf ob;
llog(RC_LOG, child->sa.logger,
"Child SA with IKE SA "PRI_SO" share their connection, .%s "PRI_SO" should be the IKE SA, updating "PRI_WHERE,
pri_so(ike->sa.st_serialno),
str_enum(&connection_owner_names, owner, &ob),
pri_so(c->routing.owner[owner]),
pri_where(e->where));
c->routing.owner[owner] = ike->sa.st_serialno;
}
} else {
if (c->routing.owner[owner] != SOS_NOBODY) {
/* child is a cuckoo */
enum_buf ob;
llog_pexpect(child->sa.logger, HERE,
"Child SA with IKE SA "PRI_SO" do not share their connection, .%s "PRI_SO" should be unset, clearing "PRI_WHERE,
pri_so(ike->sa.st_serialno),
str_enum(&connection_owner_names, owner, &ob),
pri_so(c->routing.owner[owner]),
pri_where(e->where));
c->routing.owner[owner] = SOS_NOBODY;
}
}
}
}
c->routing.state = routing;
c->routing_sa = child->sa.st_serialno;
c->negotiating_child_sa = child->sa.st_serialno;
c->established_child_sa = child->sa.st_serialno;
}
static bool unrouted_to_routed_ondemand(struct connection *c, where_t where)
{
if (!unrouted_to_routed(c, RT_ROUTED_ONDEMAND, where)) {
return false;
}
set_routing(c, RT_ROUTED_ONDEMAND);
return true;
}
/*
* Install inbound and outbound traps for the first SPD with sec_label
* attached.
*
* unrouted_to_routed_ondemand() installs multiple SPDs and only
* outbound.
*/
static bool unrouted_to_routed_ondemand_sec_label(struct connection *c,
struct logger *logger,
where_t where)
{
connection_buf cb;
enum_buf rsb;
ldbg(logger,
"kernel: %s() "PRI_CO" "PRI_CO" "PRI_CONNECTION" routed %s sec_label="PRI_SHUNK,
__func__,
pri_connection_co(c),
pri_connection_co(c->clonedfrom),
pri_connection(c, &cb),
str_enum(&routing_names, c->routing.state, &rsb),
pri_shunk(c->config->sec_label));
if (!PEXPECT(logger, is_labeled_template(c) || is_labeled_parent(c))) {
return false;
}
if (PBAD(logger, kernel_policy_installed(c))) {
dbg("kernel: %s() connection already routed", __func__);
return true;
}
/*
* SE installs both an outgoing and incoming policy. Normal
* connections do not.
*/
FOR_EACH_THING(direction, DIRECTION_OUTBOUND, DIRECTION_INBOUND) {
if (!add_sec_label_kernel_policy(c->spd, direction,
/*logger*/logger, where,
"ondemand security label")) {
if (direction == DIRECTION_INBOUND) {
/*
* Need to pull the just installed
* outbound policy.
*/
ldbg(logger, "pulling previously installed outbound policy");
pexpect(direction == DIRECTION_INBOUND);
/* go back to old routing */
struct spd_owner owner = spd_owner(c->spd, c->routing.state,
logger, where);
delete_spd_kernel_policy(c->spd, &owner, DIRECTION_OUTBOUND,
KERNEL_POLICY_PRESENT,
/*logger*/logger,
where, "security label policy");
}
return false;
}
}
/* a new route: no deletion required, but preparation is */
if (!do_updown(UPDOWN_PREPARE, c, c->spd, NULL/*ST*/, logger)) {
ldbg(logger, "kernel: %s() prepare command returned an error", __func__);
}
if (!do_updown(UPDOWN_ROUTE, c, c->spd, NULL/*ST*/, logger)) {
/* Failure! Unwind our work. */
ldbg(logger, "kernel: %s() route command returned an error", __func__);
if (!do_updown(UPDOWN_DOWN, c, c->spd, NULL/*st*/, logger)) {
ldbg(logger, "kernel: down command returned an error");
}
/* go back to old routing */
struct spd_owner owner = spd_owner(c->spd, c->routing.state,
logger, where);
delete_spd_kernel_policy(c->spd, &owner,
DIRECTION_OUTBOUND,
KERNEL_POLICY_PRESENT,
logger, where, "failed security label");
delete_spd_kernel_policy(c->spd, &owner,
DIRECTION_INBOUND,
KERNEL_POLICY_PRESENT,
logger, where, "failed security label");
return false;
}
/*
* XXX: this call clears the connection's
* .established_child_sa and .negotiating_child_sa. That is
* ok since, for sec_label, they should never be set on the
* LABELED_TEMPATE or LABELED_PARENT (see pexpect() above).
*/
set_routing(c, RT_ROUTED_ONDEMAND);
return true;
}
static bool unrouted_to_routed_never_negotiate(struct connection *c, where_t where)
{
if (!unrouted_to_routed(c, RT_ROUTED_NEVER_NEGOTIATE, where)) {
return false;
}
set_routing(c, RT_ROUTED_NEVER_NEGOTIATE);
return true;
}
static void routed_tunnel_to_routed_ondemand(struct child_sa *child,
where_t where)
{
/* currently up and routed */
struct logger *logger = child->sa.logger;
struct connection *c = child->sa.st_connection;
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
do_updown(UPDOWN_DOWN, c, spd, child, logger);
struct spd_owner owner = spd_owner(spd, RT_ROUTED_ONDEMAND,
logger, where);
delete_cat_kernel_policies(spd, &owner, logger, where);
replace_ipsec_with_bare_kernel_policy(child, c, spd, &owner,
SHUNT_KIND_ONDEMAND,
KERNEL_POLICY_PRESENT,
logger, where);
}
set_routing(child->sa.st_connection, RT_ROUTED_ONDEMAND);
}
static void routed_tunnel_to_routed_failure(struct child_sa *child,
where_t where)
{
/* currently up and routed */
struct logger *logger = child->sa.logger;
struct connection *c = child->sa.st_connection;
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
do_updown(UPDOWN_DOWN, c, spd, child, logger);
struct spd_owner owner = spd_owner(spd, RT_ROUTED_FAILURE,
logger, where);
delete_cat_kernel_policies(spd, &owner, logger, where);
replace_ipsec_with_bare_kernel_policy(child, c, spd, &owner,
SHUNT_KIND_FAILURE,
KERNEL_POLICY_PRESENT,
logger, where);
}
set_routing(child->sa.st_connection, RT_ROUTED_FAILURE);
}
static void routed_kernel_policy_to_unrouted(struct connection *c,
enum directions directions,
struct logger *logger,
where_t where,
const char *story)
{
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
struct spd_owner owner = spd_owner(spd, RT_UNROUTED,
logger, where);
delete_spd_kernel_policies(spd, &owner, directions,
logger, where, story);
do_updown_unroute_spd(spd, &owner, NULL, logger,
(struct updown_env) {0});
}
set_routing(c, RT_UNROUTED);
}
static void unrouted_kernel_policy_to_unrouted(struct connection *c,
enum directions directions,
struct logger *logger, where_t where,
const char *story)
{
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
struct spd_owner owner = spd_owner(spd, RT_UNROUTED,
logger, where);
delete_spd_kernel_policies(spd, &owner, directions,
logger, where, story);
}
set_routing(c, RT_UNROUTED);
}
static void routed_tunnel_to_unrouted(struct child_sa *child,
where_t where)
{
/* currently up and routed */
struct logger *logger = child->sa.logger;
struct connection *c = child->sa.st_connection;
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
do_updown(UPDOWN_DOWN, c, spd, child, logger);
struct spd_owner owner = spd_owner(spd, RT_UNROUTED,
logger, where);
delete_spd_kernel_policies(spd, &owner,
DIRECTIONS_INBOUND_AND_OUTBOUND,
logger, where, "delete");
do_updown_unroute_spd(spd, &owner, child, logger,
(struct updown_env) {0});
}
set_routing(c, RT_UNROUTED);
}
/*
* For instance:
*
* = an instance with a routed ondemand template
*
* = an instance with an unrouted template due to whack?
*
* If this is an instance, then presumably the instance instantiate
* code has figured out how wide the SPDs need to be.
*
* OTOH, if this is an unrouted permanent triggered by whack, just
* replace.
*/
static void unrouted_instance_to_unrouted_negotiation(enum routing_event event UNUSED,
struct connection *c, where_t where)
{
struct logger *logger = c->logger;
#if 0
/* fails when whack forces the initiate so that the template
* is instantiated before it is routed */
struct connection *t = c->clonedfrom; /* could be NULL */
PEXPECT(logger, t != NULL && t->routing.state == RT_ROUTED_ONDEMAND);
#endif
bool oe = is_opportunistic(c);
const char *reason = (oe ? "replace unrouted opportunistic %trap with broad %pass or %hold" :
"replace unrouted %trap with broad %pass or %hold");
add_spd_kernel_policies(c, KERNEL_POLICY_OP_REPLACE,
DIRECTION_OUTBOUND,
SHUNT_KIND_NEGOTIATION,
logger, where, reason);
}
/*
* Either C is permanent, or C is an instance that going to be revived
* - the full set of SPDs need to be changed to negotiation (just
* instantiated instances do not take this code path).
*/
static void routed_ondemand_to_routed_negotiation(enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
PEXPECT(logger, !is_opportunistic(c));
PASSERT(logger, event == CONNECTION_INITIATED);
enum routing rt_negotiation = RT_ROUTED_NEGOTIATION;
FOR_EACH_ITEM(spd, &c->child.spds) {
struct spd_owner owner = spd_owner(spd, rt_negotiation,
logger, HERE);
if (!replace_spd_kernel_policy(spd, &owner,
DIRECTION_OUTBOUND,
SHUNT_KIND_NEGOTIATION,
logger, e->where,
"ondemand->negotiation")) {
llog(RC_LOG, c->logger,
"converting ondemand kernel policy to negotiation");
}
}
/* the state isn't yet known */
set_negotiating(c, rt_negotiation, e);
}
/*
* Either C is permanent, or C is an instance that going to be revived
* - the full set of SPDs need to be changed to ondemand (just
* instantiated instances do not take this code path).
*/
static void routed_negotiation_to_routed_ondemand(struct connection *c,
struct logger *logger,
where_t where,
const char *reason)
{
FOR_EACH_ITEM(spd, &c->child.spds) {
struct spd_owner owner = spd_owner(spd, RT_ROUTED_ONDEMAND,
logger, HERE);
if (!replace_spd_kernel_policy(spd, &owner,
DIRECTION_OUTBOUND,
SHUNT_KIND_ONDEMAND,
logger, where, reason)) {
llog(RC_LOG, logger, "%s failed", reason);
}
}
set_routing(c, RT_ROUTED_ONDEMAND);
}
/*
* Delete the ROUTED_TUNNEL, and possibly delete the connection.
*/
static void teardown_routed_tunnel(struct connection *c,
struct child_sa **child,
where_t where)
{
if (scheduled_child_revival(*child, "received Delete/Notify")) {
routed_tunnel_to_routed_ondemand((*child), where);
return;
}
/*
* Should this go back to on-demand?
*/
if (is_permanent(c) && c->policy.route) {
/* it's being stripped of the state, hence SOS_NOBODY */
routed_tunnel_to_routed_ondemand((*child), where);
return;
}
/*
* Is there a failure shunt?
*/
if (is_permanent(c) && c->config->failure_shunt != SHUNT_NONE) {
routed_tunnel_to_routed_failure((*child), where);
return;
}
routed_tunnel_to_unrouted((*child), where);
}
static void unrouted_tunnel_to_routed_ondemand(struct child_sa *child,
where_t where)
{
/* currently down and unrouted */
struct logger *logger = child->sa.logger;
struct connection *c = child->sa.st_connection;
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
do_updown(UPDOWN_DOWN, c, spd, child, logger);
struct spd_owner owner = spd_owner(spd, RT_ROUTED_ONDEMAND,
logger, where);
delete_cat_kernel_policies(spd, &owner, logger, where);
replace_ipsec_with_bare_kernel_policy(child, c, spd, &owner,
SHUNT_KIND_ONDEMAND,
KERNEL_POLICY_PRESENT,
logger, where);
}
do_updown_child(UPDOWN_ROUTE, child);
set_routing(child->sa.st_connection, RT_ROUTED_ONDEMAND);
}
static void unrouted_tunnel_to_routed_failure(struct child_sa *child,
where_t where)
{
/* currently down and unrouted */
struct logger *logger = child->sa.logger;
struct connection *c = child->sa.st_connection;
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
do_updown(UPDOWN_DOWN, c, spd, child, logger);
struct spd_owner owner = spd_owner(spd, RT_ROUTED_FAILURE,
logger, where);
delete_cat_kernel_policies(spd, &owner, logger, where);
replace_ipsec_with_bare_kernel_policy(child, c, spd, &owner,
SHUNT_KIND_FAILURE,
KERNEL_POLICY_PRESENT,
logger, where);
}
do_updown_child(UPDOWN_ROUTE, child);
set_routing(child->sa.st_connection, RT_ROUTED_FAILURE);
}
static void unrouted_tunnel_to_unrouted(struct connection *c,
struct logger *logger,
where_t where,
const char *story)
{
/* currently down and unrouted */
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
struct spd_owner owner = spd_owner(spd, RT_UNROUTED,
logger, where);
delete_spd_kernel_policies(spd, &owner,
DIRECTIONS_INBOUND_AND_OUTBOUND,
logger, where, story);
}
/*
* update routing; route_owner() will see this and not
* think this route is the owner?
*/
set_routing(c, RT_UNROUTED);
}
static void teardown_unrouted_tunnel(struct connection *c,
struct child_sa *child,
struct logger *logger,
where_t where,
const char *story)
{
if (scheduled_child_revival(child, "received Delete/Notify")) {
unrouted_tunnel_to_routed_ondemand(child, where);
return;
}
/*
* Should this go back to on-demand?
*/
if (is_permanent(c) && c->policy.route) {
/* it's being stripped of the state, hence SOS_NOBODY */
unrouted_tunnel_to_routed_ondemand(child, where);
return;
}
/*
* Is there a failure shunt?
*/
if (is_permanent(c) && c->config->failure_shunt != SHUNT_NONE) {
unrouted_tunnel_to_routed_failure(child, where);
return;
}
unrouted_tunnel_to_unrouted(c, logger, where, story);
}
static void routed_inbound_negotiation_to_unrouted(struct connection *c,
struct child_sa *child,
struct logger *logger,
where_t where,
const char *story)
{
ldbg_routing(logger, "OOPS: ROUTED_INBOUND has no outbound policy");
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
struct spd_owner owner = spd_owner(spd, RT_UNROUTED/*ignored*/,
logger, where);
delete_spd_kernel_policies(spd, &owner,
DIRECTIONS_INBOUND_AND_OUTBOUND,
logger, where, story);
do_updown_unroute_spd(spd, &owner, child, logger,
(struct updown_env) {0});
}
set_routing(c, RT_UNROUTED);
}
static void unrouted_inbound_to_unrouted(struct connection *c,
struct logger *logger,
where_t where,
const char *story)
{
ldbg_routing(logger, "OOPS: UNROUTED_INBOUND doesn't have outbound!");
FOR_EACH_ITEM(spd, &c->child.spds) {
if (is_v1_cisco_split(spd, HERE)) {
continue;
}
struct spd_owner owner = spd_owner(spd, RT_UNROUTED,
logger, where);
delete_spd_kernel_policies(spd, &owner,
DIRECTIONS_INBOUND_AND_OUTBOUND,
logger, where, story);
}
set_routing(c, RT_UNROUTED);
}
static void teardown_unrouted_inbound(struct connection *c,
struct child_sa *child,
struct logger *logger,
where_t where,
const char *story)
{
if (scheduled_child_revival(child, story)) {
unrouted_inbound_to_unrouted(c, logger, where, story);
return;
}
unrouted_inbound_to_unrouted(c, logger, where, story);
}
static void teardown_unrouted_inbound_negotiation(struct connection *c,
struct child_sa *child,
struct logger *logger,
where_t where,
const char *story)
{
if (scheduled_child_revival(child, story)) {
unrouted_kernel_policy_to_unrouted(c, DIRECTIONS_INBOUND,
logger, where, story);
return;
}
unrouted_kernel_policy_to_unrouted(c, DIRECTIONS_INBOUND,
logger, where, story);
}
static void teardown_routed_negotiation(struct connection *c,
struct child_sa *child,
struct logger *logger,
where_t where,
const char *reason)
{
if (scheduled_child_revival(child, reason)) {
routed_negotiation_to_routed_ondemand(c, logger, where,
reason);
PEXPECT(logger, c->routing.state == RT_ROUTED_ONDEMAND);
return;
}
if (is_instance(c) && is_opportunistic(c)) {
/*
* A failed OE initiator, make shunt bare.
*/
orphan_holdpass(c, c->spd, logger);
/*
* Change routing so we don't get cleared out
* when state/connection dies.
*/
set_routing(c, RT_UNROUTED);
return;
}
if (c->policy.route) {
routed_negotiation_to_routed_ondemand(c, logger, where,
"restoring ondemand, connection is routed");
PEXPECT(logger, c->routing.state == RT_ROUTED_ONDEMAND);
return;
}
/*
* Should this instead install a failure shunt?
*
* A ROUTED_NEGOTIATION doesn't have inbound policy so don't
* expect it.
*/
routed_kernel_policy_to_unrouted(c, DIRECTIONS_INBOUND,
logger, where, "deleting");
PEXPECT(logger, c->routing.state == RT_UNROUTED);
}
/*
* Received a message telling us to delete the connection's Child.SA.
*/
static bool teardown_child_dispatch_ok(struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
if (c->routing_sa == (*e->child)->sa.st_serialno) {
ldbg_routing(logger, "Child SA matches .routing_sa");
return true;
}
ldbg_routing(logger, "Child SA does not match .routing_sa "PRI_SO,
pri_so(c->routing_sa));
return false;
}
static void teardown_child_post_op(const struct routing_annex *e)
{
delete_child_sa(e->child);
}
void connection_teardown_child(struct child_sa **child,
enum terminate_reason reason,
where_t where)
{
struct connection *cc = (*child)->sa.st_connection;
struct logger *logger = clone_logger((*child)->sa.logger, HERE); /* must free */
name_buf rb;
struct routing_annex annex = {
.child = child,
.where = where,
/*
* Does the child sa own the routing?
*/
.dispatch_ok = teardown_child_dispatch_ok,
.post_op = teardown_child_post_op,
.story = (reason == REASON_DELETED ? "delete Child SA" : /* logging compat hack */
reason == REASON_TOO_MANY_RETRANSMITS ? "timeout Child SA" : /* logging compat hack */
str_enum(&terminate_reason_names, reason, &rb)),
};
/*
* Let state machine figure out how to react.
*/
dispatch(CONNECTION_TEARDOWN_CHILD, cc, logger, &annex);
PEXPECT(logger, (*child) == NULL);
free_logger(&logger, HERE);
}
/*
* If there's an established IKE SA and it isn't this one (i.e., not
* owner) skip the route change.
*
* This isn't strong enough. There could be multiple larval IKE SAs
* and this check doesn't filter them out.
*/
static bool teardown_ike_dispatch_ok(struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
if (c->routing_sa == (*e->ike)->sa.st_serialno) {
ldbg_routing(logger, "IKE SA matches .routing_sa");
return true;
}
ldbg_routing(logger, "IKE SA does not match .routing_sa "PRI_SO,
pri_so(c->routing_sa));
return false;
}
static void teardown_ike_post_op(const struct routing_annex *e)
{
delete_ike_sa(e->ike);
}
void connection_teardown_ike(struct ike_sa **ike,
enum terminate_reason reason,
where_t where)
{
struct connection *c = (*ike)->sa.st_connection;
struct logger *logger = clone_logger((*ike)->sa.logger, HERE);
name_buf rb;
struct routing_annex annex = {
.story = (reason == REASON_DELETED ? "delete IKE SA" : /* logging compat hack */
reason == REASON_TOO_MANY_RETRANSMITS ? "timeout IKE SA" : /* logging compat hack */
str_enum(&terminate_reason_names, reason, &rb)),
.ike = ike,
.where = where,
.dispatch_ok = teardown_ike_dispatch_ok,
.post_op = teardown_ike_post_op,
};
dispatch(CONNECTION_TEARDOWN_IKE, c, logger, &annex);
PEXPECT(logger, (*ike) == NULL); /* no logger */
free_logger(&logger, HERE);
}
/*
* Stop reviving children trying to use this IKE SA.
*/
void connection_routing_init(struct connection *c)
{
c->routing.state = RT_UNROUTED;
for (unsigned i = 0; i < elemsof(c->routing.owner); i++) {
c->routing.owner[i] = SOS_NOBODY;
}
}
void state_disowns_connection(struct state *st)
{
struct connection *c = st->st_connection;
for (unsigned i = 0; i < elemsof(c->routing.owner); i++) {
if (c->routing.owner[i] == st->st_serialno) {
#if 0
/* should already be clear? */
llog_pexpect(st->logger, HERE,
connection_owner_names[i]);
#else
enum_buf ob;
pdbgf(DBG_ROUTING, st->logger,
"routing: disown .%s",
str_enum(&connection_owner_names, i, &ob));
#endif
c->routing.owner[i] = SOS_NOBODY;
}
}
}
bool pexpect_connection_is_unrouted(struct connection *c, struct logger *logger, where_t where)
{
bool ok_to_delete = true;
if (c->routing.state != RT_UNROUTED) {
enum_buf rn;
llog_pexpect(logger, where,
"connection "PRI_CO" [%p] still in %s",
pri_connection_co(c), c,
str_enum_short(&routing_names, c->routing.state, &rn));
ok_to_delete = false;
}
return ok_to_delete;
}
/*
* Must be unrouted (i.e., all policies have been pulled).
*/
bool pexpect_connection_is_disowned(struct connection *c, struct logger *logger, where_t where)
{
bool ok_to_delete = true;
for (unsigned i = 0; i < elemsof(c->routing.owner); i++) {
if (c->routing.owner[i] != SOS_NOBODY) {
enum_buf ob;
llog_pexpect(logger, where,
"connection "PRI_CO" [%p] is owned by .%s "PRI_SO,
pri_connection_co(c), c,
str_enum(&connection_owner_names, i, &ob),
pri_so(c->routing.owner[i]));
ok_to_delete = false;
}
}
return ok_to_delete;
}
static bool initiated_ike_dispatch_ok(struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
if (c->routing_sa == SOS_NOBODY) {
ldbg_routing(logger, "IKE SA matches unset .routing_sa");
return true;
}
if (c->routing_sa == (*e->ike)->sa.st_serialno) {
ldbg_routing(logger, "IKE SA matches .routing_sa");
}
return false;
}
void connection_initiated_ike(struct ike_sa *ike,
enum initiated_by initiated_by,
where_t where)
{
struct connection *c = ike->sa.st_connection;
struct logger *logger = ike->sa.logger;
struct routing_annex annex = {
.ike = &ike,
.initiated_by = initiated_by,
.where = where,
.dispatch_ok = initiated_ike_dispatch_ok,
};
dispatch(CONNECTION_INITIATED, c, logger, &annex);
}
static bool initiated_child_dispatch_ok(struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
if (c->routing_sa == SOS_NOBODY) {
ldbg_routing(logger, "Child SA matches unset .routing_sa");
return true;
}
if (c->routing_sa == (*e->child)->sa.st_serialno) {
ldbg_routing(logger, "Child SA matches .routing_sa");
return true;
}
if (c->routing_sa == (*e->child)->sa.st_clonedfrom) {
ldbg_routing(logger, "Child SA's IKE SA matches .routing_sa");
return true;
}
return false;
}
void connection_initiated_child(struct ike_sa *ike, struct child_sa *child,
enum initiated_by initiated_by,
where_t where)
{
struct connection *cc = child->sa.st_connection;
struct logger *logger = child->sa.logger;
struct routing_annex annex = {
.ike = &ike,
.child = &child,
.initiated_by = initiated_by,
.dispatch_ok = initiated_child_dispatch_ok,
.where = where,
};
dispatch(CONNECTION_INITIATED, cc, logger, &annex);
}
static bool pending_dispatch_ok(struct connection *c,
struct logger *logger,
const struct routing_annex *e UNUSED)
{
switch (c->routing.state) {
case RT_ROUTED_ONDEMAND:
ldbg_routing(logger, "connection matches ROUTED_ONDEMAND");
return true;
case RT_UNROUTED:
/*
* An UNROUTED connection (i.e., no Child SA) can
* still have an IKE SA, just as long as that IKE SA
* matches what is negotiating the connection?
*
* For instance:
*
* up cuckold -- #1, #2
* up cuckoo -- #3 (uses #1)
* down cuckold -- only deletes #2, #1 is in use
*
* followed by:
*
* up cuckold
*
* will initiate the connection cuckold with IKE SA
* still set to #1.
*
* Have to wonder what happens when there's a replace?
*/
ldbg_routing(logger, "connection matches UNROUTED");
return true;
default:
/*
* Ignore stray initiates (presumably due to two
* acquires triggering simultaneously) or due to an
* initiate being used to force a rekey.
*/
LLOG_JAMBUF(LOG_STREAM/*not-whack*/, logger, buf) {
jam_string(buf, "connection is already in state ");
jam_enum_human(buf, &routing_names, c->routing.state);
}
return false;
}
}
void connection_pending(struct connection *c, enum initiated_by initiated_by, where_t where)
{
struct routing_annex annex = {
.initiated_by = initiated_by,
.where = where,
.dispatch_ok = pending_dispatch_ok,
};
/*XXX: not pending */
dispatch(CONNECTION_INITIATED, c, c->logger, &annex);
}
static bool reschedule_dispatch_ok(struct connection *c,
struct logger *logger UNUSED,
const struct routing_annex *e UNUSED)
{
/* skip when any hint of an owner */
for (unsigned i = 0; i < elemsof(c->routing.owner); i++) {
if (c->routing.owner[i] != SOS_NOBODY) {
enum_buf ob;
ldbg_routing(logger, "connection owned by %s "PRI_SO,
str_enum(&connection_owner_names, i, &ob),
pri_so(c->routing.owner[i]));
return false;
}
}
ldbg_routing(logger, "connection has no owner");
return true;
}
void connection_reschedule(struct connection *c, struct logger *logger, where_t where)
{
struct routing_annex annex = {
.story = "re-schedule",
.where = where,
.dispatch_ok = reschedule_dispatch_ok,
};
dispatch(CONNECTION_RESCHEDULE, c, logger, &annex);
}
static void set_established_ike(enum routing_event event UNUSED,
struct connection *c,
enum routing routing,
const struct routing_annex *e)
{
/* steal both the established and negotiating IKE SAs */
struct ike_sa *ike = (*e->ike);
c->negotiating_ike_sa = c->established_ike_sa = ike->sa.st_serialno;
c->routing.state = routing; /* XXX: but this is IKE!?! */
ike->sa.st_viable_parent = true;
linux_audit_conn(&ike->sa, LAK_PARENT_START);
/* dump new keys */
if (DBGP(DBG_PRIVATE)) {
LDBG_tcpdump_ike_sa_keys(&global_logger, ike);
}
}
void connection_establish_ike(struct ike_sa *ike, where_t where)
{
struct connection *c = ike->sa.st_connection;
struct logger *logger = ike->sa.logger;
struct routing_annex annex = {
.ike = &ike,
.where = where,
.initiated_by = INITIATED_BY_PEER,
};
dispatch(CONNECTION_ESTABLISH_IKE, c, logger, &annex);
}
void connection_route(struct connection *c, where_t where)
{
if (!oriented(c)) {
llog(RC_ORIENT, c->logger,
"we cannot identify ourselves with either end of this connection");
return;
}
if (is_template(c)) {
if (is_opportunistic(c)) {
ldbg(c->logger, "template-route-possible: opportunistic");
} else if (is_group_instance(c)) {
ldbg(c->logger, "template-route-possible: groupinstance");
} else if (is_labeled(c)) {
ldbg(c->logger, "template-route-possible: has sec-label");
} else if (c->local->config->child.virt != NULL) {
ldbg(c->logger, "template-route-possible: local is virtual");
} else if (c->remote->child.has_client) {
/* see extract_child_end() */
ldbg(c->logger, "template-route-possible: remote %s.child.has_client==true",
c->remote->config->leftright);
} else {
policy_buf pb;
llog(RC_ROUTE, c->logger,
"cannot route template policy of %s",
str_connection_policies(c, &pb));
return;
}
}
struct routing_annex annex = {
.where = where,
};
dispatch(CONNECTION_ROUTE, c, c->logger, &annex);
}
void connection_unroute(struct connection *c, where_t where)
{
/*
* XXX: strip POLICY.ROUTE in whack code, not here (code
* expects to be able to route/unroute without losing the
* policy bits).
*/
struct routing_annex annex = {
.where = where,
};
dispatch(CONNECTION_UNROUTE, c, c->logger, &annex);
}
/*
* "down" / "unroute" the connection but _don't_ delete the kernel
* state / policy.
*
* Presumably the kernel policy (at least) is acting like a trap while
* mibike migrates things?
*/
void connection_suspend(struct child_sa *child, where_t where)
{
struct connection *cc = child->sa.st_connection;
struct logger *logger = child->sa.logger;
struct routing_annex annex = {
.child = &child,
.where = where,
};
dispatch(CONNECTION_SUSPEND, cc, logger, &annex);
}
void connection_resume(struct child_sa *child, where_t where)
{
struct connection *cc = child->sa.st_connection;
struct logger *logger = child->sa.logger;
struct routing_annex annex = {
.child = &child,
.where = where,
};
dispatch(CONNECTION_RESUME, cc, logger, &annex);
}
static bool dispatch_1(enum routing_event event,
struct connection *c,
struct logger *logger,
const struct routing_annex *e)
{
#define XX(CONNECTION_EVENT, CONNECTION_ROUTING, CONNECTION_KIND) \
(((CONNECTION_EVENT) * \
CONNECTION_ROUTING_ROOF + CONNECTION_ROUTING) * \
CONNECTION_KIND_ROOF + CONNECTION_KIND)
#define X(EVENT, ROUTING, KIND) \
XX(CONNECTION_##EVENT, RT_##ROUTING, CK_##KIND)
const enum routing routing = c->routing.state;
const enum connection_kind kind = c->local->kind;
switch (XX(event, routing, kind)) {
case X(ROUTE, UNROUTED, GROUP):
/* caller deals with recursion */
add_policy(c, policy.route); /* always */
return true;
case X(ROUTE, UNROUTED, TEMPLATE):
case X(ROUTE, UNROUTED, PERMANENT):
add_policy(c, policy.route); /* always */
if (never_negotiate(c)) {
if (!unrouted_to_routed_never_negotiate(c, e->where)) {
/* XXX: why whack only? */
llog(RC_ROUTE, logger, "could not route");
return true;
}
PEXPECT(logger, c->routing.state == RT_ROUTED_NEVER_NEGOTIATE);
} else {
if (!unrouted_to_routed_ondemand(c, e->where)) {
/* XXX: why whack only? */
llog(RC_ROUTE, logger, "could not route");
return true;
}
PEXPECT(logger, c->routing.state == RT_ROUTED_ONDEMAND);
}
return true;
case X(ESTABLISH_IKE, UNROUTED, INSTANCE):
case X(ESTABLISH_IKE, UNROUTED, PERMANENT):
case X(ESTABLISH_IKE, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(ESTABLISH_IKE, UNROUTED_BARE_NEGOTIATION, PERMANENT):
case X(ESTABLISH_IKE, ROUTED_NEGOTIATION, INSTANCE):
case X(ESTABLISH_IKE, ROUTED_NEGOTIATION, PERMANENT):
case X(ESTABLISH_IKE, ROUTED_ONDEMAND, INSTANCE):
case X(ESTABLISH_IKE, ROUTED_ONDEMAND, PERMANENT):
case X(ESTABLISH_IKE, ROUTED_TUNNEL, INSTANCE):
case X(ESTABLISH_IKE, ROUTED_TUNNEL, PERMANENT):
case X(ESTABLISH_IKE, UNROUTED_NEGOTIATION, INSTANCE):
case X(ESTABLISH_IKE, UNROUTED_NEGOTIATION, PERMANENT):
case X(ESTABLISH_IKE, UNROUTED_INBOUND, INSTANCE):
case X(ESTABLISH_IKE, UNROUTED_INBOUND, PERMANENT):
/* unchanged; except to attach IKE */
set_established_ike(event, c, c->routing.state, e);
return true;
case X(INITIATED, ROUTED_ONDEMAND, INSTANCE): /* from revival */
case X(INITIATED, ROUTED_ONDEMAND, PERMANENT):
flush_routed_ondemand_revival(c);
routed_ondemand_to_routed_negotiation(event, c, logger, e);
return true;
case X(INITIATED, UNROUTED, INSTANCE):
/*
* Triggered by whack against the template which is
* then instantiated creating this connection. The
* template may or may not be routed.
*/
if (c->clonedfrom->routing.state == RT_UNROUTED) {
/*
* Since the template has no policy nor
* routing, skip these in the instance.
*/
ldbg_routing(logger, "skipping hold as template is unrouted");
set_negotiating(c, RT_UNROUTED_BARE_NEGOTIATION, e);
return true;
}
if (c->clonedfrom->routing.state == RT_ROUTED_ONDEMAND) {
/*
* Need to override the template's policy with our own
* (else things will keep acquiring). I's assumed that
* the template's routing is sufficient for now.
*/
unrouted_instance_to_unrouted_negotiation(event, c, e->where);
set_negotiating(c, RT_UNROUTED_NEGOTIATION, e);
return true;
}
break;
case X(INITIATED, UNROUTED, PERMANENT):
flush_unrouted_revival(c);
set_negotiating(c, RT_UNROUTED_BARE_NEGOTIATION, e);
return true;
case X(INITIATED, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(INITIATED, UNROUTED_BARE_NEGOTIATION, PERMANENT):
set_negotiating(c, RT_UNROUTED_BARE_NEGOTIATION, e);
return true;
case X(INITIATED, ROUTED_NEGOTIATION, INSTANCE):
case X(INITIATED, ROUTED_NEGOTIATION, PERMANENT):
/*
* For instance, Child SA, during an on-demand
* triggered IKE AUTH, stealing the connection from
* the IKE SA.
*/
set_negotiating(c, RT_ROUTED_NEGOTIATION, e);
return true;
case X(INITIATED, UNROUTED_NEGOTIATION, INSTANCE):
case X(INITIATED, UNROUTED_NEGOTIATION, PERMANENT):
/*
* For instance, Child SA, during an on-demand
* triggered IKE AUTH, stealing the connection from
* the IKE SA.
*/
set_negotiating(c, RT_UNROUTED_NEGOTIATION, e);
return true;
case X(TEARDOWN_IKE, UNROUTED, INSTANCE):
case X(TEARDOWN_IKE, UNROUTED, PERMANENT):
/*
* already -routed -policy; presumably the Child SA
* deleted the policy earlier.
*/
return true;
case X(TEARDOWN_IKE, ROUTED_ONDEMAND, INSTANCE): /* ikev2-30-rw-no-rekey */
case X(TEARDOWN_IKE, ROUTED_ONDEMAND, PERMANENT): /* ROUTED_NEGOTIATION!?! */
/*
* Happens after all children are killed, and
* connection put into routed ondemand. Just need to
* delete IKE.
*
* ikev2-31-nat-rw-no-rekey:
*
* The established child unroutes the connection;
* followed by this IKE timeout.
*
* ikev2-child-ipsec-retransmit:
*
* The UP and established child schedules revival,
* putting the connection into ROUTED_ONDEMAND,
* followed by this IKE timeout.
*/
return true;
case X(RESCHEDULE, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(RESCHEDULE, UNROUTED_BARE_NEGOTIATION, PERMANENT):
case X(RESCHEDULE, UNROUTED, INSTANCE): /* does this ever happen? */
case X(RESCHEDULE, UNROUTED, PERMANENT):
case X(TEARDOWN_CHILD, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(TEARDOWN_CHILD, UNROUTED_BARE_NEGOTIATION, PERMANENT):
case X(TEARDOWN_CHILD, UNROUTED, PERMANENT): /* permanent+up */
case X(TEARDOWN_IKE, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(TEARDOWN_IKE, UNROUTED_BARE_NEGOTIATION, PERMANENT):
if (connection_cannot_die(event, c, logger, e)) {
ldbg(logger, "will not die!");
}
/*
* Even though the SPD isn't routed, invoke
* UPDOWN_UNROUTE. This way scripts are notified when
* a bare initiate fails.
*
* This is v4.x behaviour that was lost in v5.0 and
* restored !?! in v5.1.
*/
FOR_EACH_ITEM(spd, &c->child.spds) {
struct spd_owner owner = spd_owner(spd, RT_UNROUTED/*ignored*/,
logger, HERE);
do_updown_unroute_spd(spd, &owner,
(e->child != NULL ? (*e->child) : NULL),
logger, (struct updown_env) {0});
}
set_routing(c, RT_UNROUTED);
return true;
case X(TEARDOWN_CHILD, ROUTED_NEGOTIATION, PERMANENT):
/*
* For instance, things fail during IKE_AUTH.
*/
teardown_routed_negotiation(c, (*e->child), logger,
e->where, "delete Child SA");
return true;
case X(TEARDOWN_IKE, ROUTED_NEGOTIATION, INSTANCE):
case X(TEARDOWN_IKE, ROUTED_NEGOTIATION, PERMANENT):
case X(RESCHEDULE, ROUTED_NEGOTIATION, INSTANCE):
case X(RESCHEDULE, ROUTED_NEGOTIATION, PERMANENT):
/*
* For instance, this end initiated a Child SA for the
* connection while at the same time the peer
* initiated an IKE SA delete and/or the exchange
* timed out.
*
* Because the Child SA is larval and, presumably,
* there is no earlier child the code below, and not
* zap_connection(), will need to deal with revival
* et.al.
*/
/* ex, permanent+up */
if (connection_cannot_die(event, c, logger, e)) {
routed_negotiation_to_routed_ondemand(c, logger, e->where,
"restoring ondemand, reviving");
PEXPECT(logger, c->routing.state == RT_ROUTED_ONDEMAND);
return true;
}
if (is_instance(c) && is_opportunistic(c)) {
/*
* A failed OE initiator, make shunt bare.
*/
orphan_holdpass(c, c->spd, logger);
/*
* Change routing so we don't get cleared out
* when state/connection dies.
*/
set_routing(c, RT_UNROUTED);
return true;
}
if (c->policy.route) {
routed_negotiation_to_routed_ondemand(c, logger, e->where,
"restoring ondemand, connection is routed");
PEXPECT(logger, c->routing.state == RT_ROUTED_ONDEMAND);
return true;
}
/* is this reachable? */
routed_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, "deleting");
PEXPECT(logger, c->routing.state == RT_UNROUTED);
/* connection lives to fight another day */
return true;
case X(TEARDOWN_CHILD, UNROUTED_NEGOTIATION, INSTANCE):
case X(TEARDOWN_IKE, UNROUTED_NEGOTIATION, INSTANCE):
if (connection_cannot_die(event, c, logger, e)) {
unrouted_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, e->story);
return true;
}
if (is_opportunistic(c)) {
/*
* A failed OE initiator, make shunt bare.
*/
orphan_holdpass(c, c->spd, logger);
/*
* Change routing so we don't get cleared out
* when state/connection dies.
*/
set_routing(c, RT_UNROUTED);
return true;
}
unrouted_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, e->story);
return true;
case X(TEARDOWN_IKE, ROUTED_TUNNEL, INSTANCE):
case X(TEARDOWN_IKE, ROUTED_TUNNEL, PERMANENT):
PEXPECT(c->logger, (*e->ike)->sa.st_ike_version == IKEv1);
return true;
case X(TEARDOWN_CHILD, ROUTED_TUNNEL, INSTANCE):
case X(TEARDOWN_CHILD, ROUTED_TUNNEL, PERMANENT):
/* permanent connections are never deleted */
teardown_routed_tunnel(c, e->child, e->where);
return true;
case X(TEARDOWN_CHILD, ROUTED_INBOUND_NEGOTIATION, INSTANCE):
case X(TEARDOWN_CHILD, ROUTED_INBOUND_NEGOTIATION, PERMANENT):
/* total overkill */
teardown_routed_tunnel(c, e->child, e->where);
return true;
case X(TEARDOWN_CHILD, UNROUTED_TUNNEL, INSTANCE):
case X(TEARDOWN_CHILD, UNROUTED_TUNNEL, PERMANENT):
teardown_unrouted_tunnel(c, (*e->child), logger, e->where, e->story);
return true;
case X(TEARDOWN_CHILD, UNROUTED_INBOUND, INSTANCE):
case X(TEARDOWN_CHILD, UNROUTED_INBOUND, PERMANENT):
/* ikev1-xfrmi-02-aggr */
/*
* IKEv1 responder mid way through establishing child
* gets a timeout. Full down_routed_tunnel is
* overkill - just inbound needs to be pulled.
*/
teardown_unrouted_inbound(c, (*e->child), logger, e->where, e->story);
return true;
case X(TEARDOWN_CHILD, UNROUTED_INBOUND_NEGOTIATION, INSTANCE):
case X(TEARDOWN_CHILD, UNROUTED_INBOUND_NEGOTIATION, PERMANENT):
/*
* IKEv1 responder mid way through establishing child
* gets a timeout. Full down_routed_tunnel is
* overkill - just inbound needs to be pulled.
*/
ldbg_routing(logger, "OOPS: UNROUTED_INBOUND_NEGOTIATION isn't routed!");
teardown_unrouted_inbound_negotiation(c, (*e->child), logger, e->where, e->story);
return true;
case X(ESTABLISH_INBOUND, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(ESTABLISH_INBOUND, UNROUTED_BARE_NEGOTIATION, PERMANENT):
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_INBOUND, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return false;
}
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return true;
case X(ESTABLISH_INBOUND, ROUTED_INBOUND_NEGOTIATION, PERMANENT):
/* alias-01 */
if (!install_inbound_ipsec_sa((*e->child), RT_ROUTED_INBOUND_NEGOTIATION, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_ROUTED_INBOUND_NEGOTIATION, e);
return false;
}
set_established_inbound(c, RT_ROUTED_INBOUND_NEGOTIATION, e);
return true;
case X(ESTABLISH_INBOUND, ROUTED_NEGOTIATION, INSTANCE):
case X(ESTABLISH_INBOUND, ROUTED_NEGOTIATION, PERMANENT):
/* addconn-05-bogus-left-interface
* algo-ikev2-aes128-sha1-ecp256 et.al. */
if (!install_inbound_ipsec_sa((*e->child), RT_ROUTED_INBOUND_NEGOTIATION, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_ROUTED_INBOUND_NEGOTIATION, e);
return false;
}
set_established_inbound(c, RT_ROUTED_INBOUND_NEGOTIATION, e);
return true;
case X(ESTABLISH_INBOUND, ROUTED_ONDEMAND, INSTANCE):
case X(ESTABLISH_INBOUND, ROUTED_ONDEMAND, PERMANENT):
/*
* This transition (ignoring IKEv1 responder) is
* immediately followed by an event to replace the
* outbound on-demand policy. Hence, don't bother
* updating it to routed-negotiation.
*/
flush_routed_ondemand_revival(c);
if (!install_inbound_ipsec_sa((*e->child), RT_ROUTED_INBOUND_NEGOTIATION, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_ROUTED_INBOUND_NEGOTIATION, e);
return false;
}
set_established_inbound(c, RT_ROUTED_INBOUND_NEGOTIATION, e);
return true;
case X(ESTABLISH_INBOUND, ROUTED_TUNNEL, INSTANCE):
case X(ESTABLISH_INBOUND, ROUTED_TUNNEL, PERMANENT):
/*
* This happens when there's a re-key where the state
* is re-established but not the policy (that is left
* untouched).
*
* For instance ikev2-12-transport-psk and
* ikev2-28-rw-server-rekey
* ikev1-labeled-ipsec-01-permissive.
*
* XXX: suspect this is too early - for rekey should
* only update after new child establishes?
*/
if (!install_inbound_ipsec_sa((*e->child), RT_ROUTED_TUNNEL, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_ROUTED_TUNNEL, e);
return false;
}
set_established_inbound(c, RT_ROUTED_TUNNEL, e);
return true;
case X(ESTABLISH_INBOUND, UNROUTED, INSTANCE):
case X(ESTABLISH_INBOUND, UNROUTED, PERMANENT):
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_INBOUND, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return false;
}
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return true;
case X(ESTABLISH_INBOUND, UNROUTED_INBOUND, PERMANENT):
/* alias-01 */
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_INBOUND, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return false;
}
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return true;
case X(ESTABLISH_INBOUND, UNROUTED_INBOUND_NEGOTIATION, PERMANENT):
/* alias-01 */
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_INBOUND_NEGOTIATION, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_UNROUTED_INBOUND_NEGOTIATION, e);
return false;
}
set_established_inbound(c, RT_UNROUTED_INBOUND_NEGOTIATION, e);
return true;
case X(ESTABLISH_INBOUND, UNROUTED_NEGOTIATION, INSTANCE):
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_INBOUND_NEGOTIATION, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_inbound(c, RT_UNROUTED_INBOUND_NEGOTIATION, e);
return false;
}
set_established_inbound(c, RT_UNROUTED_INBOUND_NEGOTIATION, e);
return true;
case X(ESTABLISH_OUTBOUND, ROUTED_INBOUND_NEGOTIATION, INSTANCE):
case X(ESTABLISH_OUTBOUND, ROUTED_INBOUND_NEGOTIATION, PERMANENT):
if (!install_outbound_ipsec_sa((*e->child), RT_ROUTED_TUNNEL,
(struct do_updown) {
.up = true,
.route = false,
}, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return false;
}
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return true;
case X(ESTABLISH_OUTBOUND, ROUTED_TUNNEL, INSTANCE):
case X(ESTABLISH_OUTBOUND, ROUTED_TUNNEL, PERMANENT):
/*
* This happens when there's a re-key where the state
* is re-established but not the policy (that is left
* untouched).
*
* For instance ikev2-12-transport-psk and
* ikev2-28-rw-server-rekey
* ikev1-labeled-ipsec-01-permissive.
*/
if (!install_outbound_ipsec_sa((*e->child), RT_ROUTED_TUNNEL,
(struct do_updown) {
.up = false,
.route = false,
}, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return false;
}
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return true;
case X(ESTABLISH_OUTBOUND, UNROUTED_INBOUND, INSTANCE):
case X(ESTABLISH_OUTBOUND, UNROUTED_INBOUND, PERMANENT):
case X(ESTABLISH_OUTBOUND, UNROUTED_INBOUND_NEGOTIATION, INSTANCE):
case X(ESTABLISH_OUTBOUND, UNROUTED_INBOUND_NEGOTIATION, PERMANENT):
if (!install_outbound_ipsec_sa((*e->child), RT_ROUTED_TUNNEL,
(struct do_updown) {
.up = true,
.route = true,
}, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return false;
}
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return true;
case X(SUSPEND, ROUTED_TUNNEL, INSTANCE):
case X(SUSPEND, ROUTED_TUNNEL, PERMANENT):
/*
* Suspend leaves kernel state and policy in place
* while running UPDOWN_DOWN and UPDOWN_UNROUTE.
* Hopefully this stops traffic flow.
*
* For UPDOWN_UNROUTE, only really run it when this
* connection hold's the only SPD, i.e. .bare_route is
* NULL (which happens when there is no other matching
* SPD). Think of .bare_route as .other_route_owner).
*/
do_updown_child(UPDOWN_DOWN, (*e->child));
FOR_EACH_ITEM(spd, &c->child.spds) {
/* only unroute if no other connection shares it */
struct spd_owner owner = spd_owner(spd, RT_UNROUTED/*ignored*/,
logger, HERE);
/* Pass PLUTO_MOBIKE_EVENT=yes to UPDOWN */
do_updown_unroute_spd(spd, &owner, (*e->child), logger,
(struct updown_env) {
.pluto_mobike_event = true,
});
}
/* finally flag as unrouted */
c->routing.state = RT_UNROUTED_TUNNEL;
PEXPECT(logger, !kernel_route_installed(c)); /* per previous line */
return true;
case X(RESUME, UNROUTED_TUNNEL, INSTANCE):
case X(RESUME, UNROUTED_TUNNEL, PERMANENT):
c->routing.state = RT_ROUTED_TUNNEL;
do_updown_child(UPDOWN_ROUTE, (*e->child));
do_updown_child(UPDOWN_UP, (*e->child));
return true;
case X(ROUTE, UNROUTED_BARE_NEGOTIATION, PERMANENT):
if (BROKEN_TRANSITION) {
/*
* XXX: should install routing+policy!
*/
add_policy(c, policy.route);
llog(RC_LOG, logger,
"policy ROUTE added to negotiating connection");
return true;
}
break;
case X(ROUTE, ROUTED_NEGOTIATION, PERMANENT):
add_policy(c, policy.route);
llog(RC_LOG, logger, "connection already routed");
return true;
case X(ROUTE, ROUTED_TUNNEL, PERMANENT):
add_policy(c, policy.route); /* always */
llog(RC_LOG, logger, "policy ROUTE added to established connection");
return true;
case X(UNROUTE, UNROUTED_BARE_NEGOTIATION, INSTANCE):
case X(UNROUTE, UNROUTED_BARE_NEGOTIATION, PERMANENT):
set_routing(c, RT_UNROUTED);
return true;
case X(UNROUTE, ROUTED_FAILURE, INSTANCE):
case X(UNROUTE, ROUTED_FAILURE, PERMANENT):
routed_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(UNROUTE, ROUTED_INBOUND_NEGOTIATION, TEMPLATE): /* xauth-pluto-25-lsw299 xauth-pluto-25-mixed-addresspool */
case X(UNROUTE, ROUTED_INBOUND_NEGOTIATION, INSTANCE): /* xauth-pluto-25-lsw299 */
case X(UNROUTE, ROUTED_INBOUND_NEGOTIATION, PERMANENT): /* ikev1-xfrmi-02-aggr */
routed_inbound_negotiation_to_unrouted(c, (*e->child), logger, e->where, e->story);
return true;
case X(UNROUTE, ROUTED_NEGOTIATION, INSTANCE):
case X(UNROUTE, ROUTED_NEGOTIATION, PERMANENT):
routed_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(UNROUTE, ROUTED_NEVER_NEGOTIATE, TEMPLATE):
case X(UNROUTE, ROUTED_NEVER_NEGOTIATE, PERMANENT):
routed_kernel_policy_to_unrouted(c, DIRECTION_INBOUND|DIRECTION_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(UNROUTE, ROUTED_ONDEMAND, TEMPLATE):
case X(UNROUTE, ROUTED_ONDEMAND, INSTANCE):
case X(UNROUTE, ROUTED_ONDEMAND, PERMANENT):
if (c->local->kind == CK_INSTANCE ||
c->local->kind == CK_PERMANENT) {
flush_routed_ondemand_revival(c);
}
routed_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(UNROUTE, ROUTED_TUNNEL, INSTANCE):
case X(UNROUTE, ROUTED_TUNNEL, PERMANENT):
llog(RC_RTBUSY, logger, "cannot unroute: route busy");
return true;
case X(UNROUTE, UNROUTED, GROUP):
case X(UNROUTE, UNROUTED, TEMPLATE):
case X(UNROUTE, UNROUTED, INSTANCE):
case X(UNROUTE, UNROUTED, PERMANENT):
ldbg_routing(logger, "already unrouted");
return true;
case X(UNROUTE, UNROUTED_NEGOTIATION, INSTANCE):
unrouted_kernel_policy_to_unrouted(c, DIRECTIONS_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(UNROUTE, UNROUTED_TUNNEL, INSTANCE):
case X(UNROUTE, UNROUTED_TUNNEL, PERMANENT):
unrouted_tunnel_to_unrouted(c, logger, e->where, "unroute");
return true;
/*
* Labeled IPsec.
*/
case X(ESTABLISH_IKE, UNROUTED, LABELED_PARENT):
/*
* For SEC_LABELs install a trap for any outgoing
* connection so that it will trigger an acquire which
* will then negotiate the child.
*
* Because the is_labeled_parent() connection was
* instantiated from the is_labeled_template() the
* parent is unrouted.
*
* There's a chance that the is_labeled_template() and
* is_labeled_parent() have overlapping SPDs that
* seems to do no harm.
*/
if (!unrouted_to_routed_ondemand_sec_label(c, logger, e->where)) {
llog(RC_ROUTE, logger, "could not route");
return true;
}
set_established_ike(event, c, RT_ROUTED_ONDEMAND, e);
c->routing_sa = (*e->ike)->sa.st_serialno;
return true;
case X(ESTABLISH_IKE, ROUTED_ONDEMAND, LABELED_PARENT):
/*
* Presumably a rekey?
*/
set_established_ike(event, c, RT_ROUTED_ONDEMAND, e);
c->routing_sa = (*e->ike)->sa.st_serialno;
return true;
case X(ROUTE, UNROUTED, LABELED_TEMPLATE):
add_policy(c, policy.route); /* always */
if (never_negotiate(c)) {
if (!unrouted_to_routed_never_negotiate(c, e->where)) {
/* XXX: why whack only? */
llog(WHACK_STREAM|RC_ROUTE, logger, "could not route");
return true;
}
PEXPECT(logger, c->routing.state == RT_ROUTED_NEVER_NEGOTIATE);
return true;
}
if (!unrouted_to_routed_ondemand_sec_label(c, logger, e->where)) {
llog(RC_ROUTE, logger, "could not route");
return true;
}
return true;
case X(ROUTE, ROUTED_ONDEMAND, LABELED_PARENT):
/*
* ikev2-labeled-ipsec-06-rekey-ike-acquire where the
* rekey re-routes the existing routed connection from
* IKE AUTH.
*/
set_routing(c, RT_ROUTED_ONDEMAND);
return true;
case X(ROUTE, UNROUTED_BARE_NEGOTIATION, LABELED_PARENT): /* see above */
case X(ROUTE, UNROUTED, LABELED_PARENT):
/*
* The CK_LABELED_TEMPLATE connection may have been
* routed (i.e., route+ondemand), but not this
* CK_LABELED_PARENT - it is still negotiating.
*
* The negotiating LABELED_PARENT connection should be
* in UNROUTED_NEGOTIATION but ACQUIRE doesn't yet go
* through that path.
*
* But what if the two have the same SPDs? Then the
* routing happens twice which seems to be harmless.
*/
if (!unrouted_to_routed_ondemand_sec_label(c, logger, e->where)) {
llog(RC_ROUTE, logger, "could not route");
return true;
}
return true;
case X(UNROUTE, UNROUTED, LABELED_TEMPLATE):
case X(UNROUTE, UNROUTED, LABELED_PARENT):
ldbg_routing(logger, "already unrouted");
return true;
case X(UNROUTE, ROUTED_ONDEMAND, LABELED_TEMPLATE):
case X(UNROUTE, ROUTED_ONDEMAND, LABELED_PARENT):
/* labeled ipsec installs both inbound and outbound */
routed_kernel_policy_to_unrouted(c, DIRECTION_INBOUND|DIRECTION_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(INITIATED, ROUTED_ONDEMAND, LABELED_PARENT):
case X(INITIATED, UNROUTED, LABELED_CHILD):
case X(INITIATED, UNROUTED, LABELED_PARENT):
return true;
case X(TEARDOWN_IKE, ROUTED_ONDEMAND, LABELED_PARENT):
/* labeled ipsec installs both inbound and outbound */
routed_kernel_policy_to_unrouted(c, DIRECTION_INBOUND|DIRECTION_OUTBOUND,
logger, e->where, "unroute");
return true;
case X(TEARDOWN_IKE, UNROUTED, LABELED_PARENT):
return true;
/*
* Labeled IPsec child.
*/
case X(ESTABLISH_INBOUND, UNROUTED_TUNNEL, LABELED_CHILD):
/* rekey; already up */
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_TUNNEL, e->where)) {
return false;
}
set_established_inbound(c, RT_UNROUTED_TUNNEL, e);
return true;
case X(ESTABLISH_OUTBOUND, UNROUTED_TUNNEL, LABELED_CHILD):
/* rekey; already up */
if (!install_outbound_ipsec_sa((*e->child), RT_UNROUTED_TUNNEL,
(struct do_updown) {
.up = false,
.route = false,
}, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return false;
}
set_established_outbound(c, RT_UNROUTED_TUNNEL, e);
return true;
case X(ESTABLISH_INBOUND, UNROUTED, LABELED_CHILD):
if (!install_inbound_ipsec_sa((*e->child), RT_UNROUTED_INBOUND, e->where)) {
return false;
}
set_established_inbound(c, RT_UNROUTED_INBOUND, e);
return true;
case X(ESTABLISH_OUTBOUND, UNROUTED_INBOUND, LABELED_CHILD):
/* new; not up */
if (!install_outbound_ipsec_sa((*e->child), RT_UNROUTED_TUNNEL,
(struct do_updown) {
.up = true,
.route = false,
}, e->where)) {
/*
* Assume Child SA at least partially
* scribbled on the state/policy and hence,
* has become owner. Should this also
* transition the connection's routing?
*/
set_established_outbound(c, RT_ROUTED_TUNNEL, e);
return false;
}
set_established_outbound(c, RT_UNROUTED_TUNNEL, e);
return true;
case X(UNROUTE, UNROUTED_INBOUND, LABELED_CHILD):
case X(UNROUTE, UNROUTED_TUNNEL, LABELED_CHILD):
set_routing(c, RT_UNROUTED);
return true;
case X(UNROUTE, UNROUTED, LABELED_CHILD):
ldbg_routing(logger, "already unrouted");
return true;
case X(TEARDOWN_CHILD, UNROUTED_INBOUND, LABELED_CHILD):
case X(TEARDOWN_CHILD, UNROUTED_TUNNEL, LABELED_CHILD):
set_routing(c, RT_UNROUTED);
return true;
case X(RESCHEDULE, UNROUTED, LABELED_CHILD):
/* drop it on the floor; ike died */
return true;
}
BARF_JAMBUF((DBGP(DBG_ROUTING) ? PASSERT_FLAGS : PEXPECT_FLAGS),
c->logger, /*ignore-exit-code*/0, e->where, buf) {
jam_routing_prefix(buf, "unhandled", event,
c->routing.state, c->routing.state,
c->local->kind);
jam_event(buf, c, e);
}
return false;
}
static bool dispatch(enum routing_event event,
struct connection *c,
struct logger *logger, /* must out-live call */
const struct routing_annex *e)
{
PASSERT(logger, e->where != NULL);
bool ok = true;
connection_addref_where(c, logger, HERE);
{
struct old_routing old = ldbg_routing_start(event, c, logger, e);
{
/*
* When missing, add the ipsec-interface
* pseudo-device. Also add the connection's
* CIDR (when known).
*
* + early for route on demand
* RT_UNROUTED->RT_ROUTE_ONDEMAND
*
* + late when established from unrouted
* tunnel RT_UNROUTED_INBOUND->RT_TUNNEL.
*/
if ((c->routing.state == RT_UNROUTED && event == CONNECTION_ROUTE) ||
c->routing.state == RT_UNROUTED_INBOUND) {
if (c->config->ipsec_interface.enabled) {
ok = add_kernel_ipsec_interface_address(c, logger);
}
}
if (ok &
(e->dispatch_ok == NULL || e->dispatch_ok(c, logger, e))) {
ok = dispatch_1(event, c, logger, e);
}
/*
* When the connection transitions to
* RT_UNROUTED, remove the connection's local
* CIDR.
*
* Since routing only changes when the
* transition completes, can pexpect(ok).
*/
if (old.routing != RT_UNROUTED &&
c->routing.state == RT_UNROUTED) {
PEXPECT(logger, ok);
/* ignore any failure */
if (c->config->ipsec_interface.enabled) {
del_kernel_ipsec_interface_address(c, logger);
}
}
if (ok && e->post_op != NULL) {
e->post_op(e);
}
}
ldbg_routing_stop(event, c, logger, e, &old, ok);
}
connection_delref_where(&c, logger, HERE);
return ok;
}
void jam_routing_sa(struct jambuf *buf, const struct connection *c)
{
/*
* Only call when c->routing_sa is valid.
*/
if (c->routing_sa == SOS_NOBODY) {
jam_string(buf, "no routing SA!?!");
return;
}
/*
* Try to figure out which SA is the routing SA and include
* it's description in the log.
*
* Work backwards through established / negotiating Child SA,
* established /negotiating IKE SA. One should match. The
* routing SA acts as a backstop guarenteeing someting is
* logged.
*/
for (enum connection_owner owner = CONNECTION_OWNER_ROOF-1;
owner >= CONNECTION_OWNER_FLOOR; owner--) {
if (c->routing_sa == c->routing.owner[owner]) {
jam_enum(buf, &connection_owner_stories, owner);
jam_string(buf, " ");
break;
}
}
struct state *sa = state_by_serialno(c->routing_sa);
if (PBAD(c->logger, sa == NULL)) {
return;
}
jam_state(buf, sa);
}
|