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
|
/*
* Common routines for IPsec SA maintenance routines.
*
* Copyright (C) 1996, 1997 John Ioannidis.
* Copyright (C) 1998, 1999, 2000, 2001, 2002 Richard Guy Briggs.
*
* 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.
*
* RCSID $Id: ipsec_sa.c,v 1.30.2.1 2006/04/20 16:33:07 mcr Exp $
*
* This is the file formerly known as "ipsec_xform.h"
*
*/
#include <linux/config.h>
#include <linux/version.h>
#include <linux/kernel.h> /* printk() */
#include "openswan/ipsec_param.h"
#ifdef MALLOC_SLAB
# include <linux/slab.h> /* kmalloc() */
#else /* MALLOC_SLAB */
# include <linux/malloc.h> /* kmalloc() */
#endif /* MALLOC_SLAB */
#include <linux/vmalloc.h> /* vmalloc() */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/interrupt.h> /* mark_bh */
#include <linux/netdevice.h> /* struct device, and other headers */
#include <linux/etherdevice.h> /* eth_type_trans */
#include <linux/ip.h> /* struct iphdr */
#include <linux/skbuff.h>
#include <openswan.h>
#ifdef SPINLOCK
#ifdef SPINLOCK_23
#include <linux/spinlock.h> /* *lock* */
#else /* SPINLOCK_23 */
#include <asm/spinlock.h> /* *lock* */
#endif /* SPINLOCK_23 */
#endif /* SPINLOCK */
#include <net/ip.h>
#include "openswan/radij.h"
#include "openswan/ipsec_stats.h"
#include "openswan/ipsec_life.h"
#include "openswan/ipsec_sa.h"
#include "openswan/ipsec_xform.h"
#include "openswan/ipsec_encap.h"
#include "openswan/ipsec_radij.h"
#include "openswan/ipsec_xform.h"
#include "openswan/ipsec_ipe4.h"
#include "openswan/ipsec_ah.h"
#include "openswan/ipsec_esp.h"
#include <pfkeyv2.h>
#include <pfkey.h>
#include "openswan/ipsec_proto.h"
#include "openswan/ipsec_alg.h"
#ifdef CONFIG_KLIPS_DEBUG
int debug_xform = 0;
#endif /* CONFIG_KLIPS_DEBUG */
#define SENDERR(_x) do { error = -(_x); goto errlab; } while (0)
struct ipsec_sa *ipsec_sadb_hash[SADB_HASHMOD];
#ifdef SPINLOCK
spinlock_t tdb_lock = SPIN_LOCK_UNLOCKED;
#else /* SPINLOCK */
spinlock_t tdb_lock;
#endif /* SPINLOCK */
struct ipsec_sadb ipsec_sadb;
#if IPSEC_SA_REF_CODE
/* the sub table must be narrower (or equal) in bits than the variable type
in the main table to count the number of unused entries in it. */
typedef struct {
int testSizeOf_refSubTable :
((sizeof(IPsecRefTableUnusedCount) * 8) < IPSEC_SA_REF_SUBTABLE_IDX_WIDTH ? -1 : 1);
} dummy;
/* The field where the saref will be hosted in the skb must be wide enough to
accomodate the information it needs to store. */
typedef struct {
int testSizeOf_refField :
(IPSEC_SA_REF_HOST_FIELD_WIDTH < IPSEC_SA_REF_TABLE_IDX_WIDTH ? -1 : 1 );
} dummy2;
#define IPS_HASH(said) (((said)->spi + (said)->dst.u.v4.sin_addr.s_addr + (said)->proto) % SADB_HASHMOD)
void
ipsec_SAtest(void)
{
IPsecSAref_t SAref = 258;
struct ipsec_sa ips;
ips.ips_ref = 772;
printk("klips_debug:ipsec_SAtest: "
"IPSEC_SA_REF_SUBTABLE_IDX_WIDTH=%u\n"
"IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES=%u\n"
"IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES=%u\n"
"IPSEC_SA_REF_HOST_FIELD_WIDTH=%lu\n"
"IPSEC_SA_REF_TABLE_MASK=%x\n"
"IPSEC_SA_REF_ENTRY_MASK=%x\n"
"IPsecSAref2table(%d)=%u\n"
"IPsecSAref2entry(%d)=%u\n"
"IPsecSAref2NFmark(%d)=%u\n"
"IPsecSAref2SA(%d)=%p\n"
"IPsecSA2SAref(%p)=%d\n"
,
IPSEC_SA_REF_SUBTABLE_IDX_WIDTH,
IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES,
IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES,
(unsigned long) IPSEC_SA_REF_HOST_FIELD_WIDTH,
IPSEC_SA_REF_TABLE_MASK,
IPSEC_SA_REF_ENTRY_MASK,
SAref, IPsecSAref2table(SAref),
SAref, IPsecSAref2entry(SAref),
SAref, IPsecSAref2NFmark(SAref),
SAref, IPsecSAref2SA(SAref),
(&ips), IPsecSA2SAref((&ips))
);
return;
}
int
ipsec_SAref_recycle(void)
{
int table;
int entry;
int error = 0;
ipsec_sadb.refFreeListHead = -1;
ipsec_sadb.refFreeListTail = -1;
if(ipsec_sadb.refFreeListCont == IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES * IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_recycle: "
"end of table reached, continuing at start..\n");
ipsec_sadb.refFreeListCont = 0;
}
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_recycle: "
"recycling, continuing from SAref=%d (0p%p), table=%d, entry=%d.\n",
ipsec_sadb.refFreeListCont,
(ipsec_sadb.refTable[IPsecSAref2table(ipsec_sadb.refFreeListCont)] != NULL) ? IPsecSAref2SA(ipsec_sadb.refFreeListCont) : NULL,
IPsecSAref2table(ipsec_sadb.refFreeListCont),
IPsecSAref2entry(ipsec_sadb.refFreeListCont));
for(table = IPsecSAref2table(ipsec_sadb.refFreeListCont);
table < IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES;
table++) {
if(ipsec_sadb.refTable[table] == NULL) {
error = ipsec_SArefSubTable_alloc(table);
if(error) {
return error;
}
}
for(entry = IPsecSAref2entry(ipsec_sadb.refFreeListCont);
entry < IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES;
entry++) {
if(ipsec_sadb.refTable[table]->entry[entry] == NULL) {
ipsec_sadb.refFreeList[++ipsec_sadb.refFreeListTail] = IPsecSArefBuild(table, entry);
if(ipsec_sadb.refFreeListTail == (IPSEC_SA_REF_FREELIST_NUM_ENTRIES - 1)) {
ipsec_sadb.refFreeListHead = 0;
ipsec_sadb.refFreeListCont = ipsec_sadb.refFreeList[ipsec_sadb.refFreeListTail] + 1;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_recycle: "
"SArefFreeList refilled.\n");
return 0;
}
}
}
}
if(ipsec_sadb.refFreeListTail == -1) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_recycle: "
"out of room in the SArefTable.\n");
return(-ENOSPC);
}
ipsec_sadb.refFreeListHead = 0;
ipsec_sadb.refFreeListCont = ipsec_sadb.refFreeList[ipsec_sadb.refFreeListTail] + 1;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_recycle: "
"SArefFreeList partly refilled to %d of %d.\n",
ipsec_sadb.refFreeListTail,
IPSEC_SA_REF_FREELIST_NUM_ENTRIES);
return 0;
}
int
ipsec_SArefSubTable_alloc(unsigned table)
{
unsigned entry;
struct IPsecSArefSubTable* SArefsub;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SArefSubTable_alloc: "
"allocating %lu bytes for table %u of %u.\n",
(unsigned long) (IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES * sizeof(struct ipsec_sa *)),
table,
IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES);
/* allocate another sub-table */
SArefsub = vmalloc(IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES * sizeof(struct ipsec_sa *));
if(SArefsub == NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SArefSubTable_alloc: "
"error allocating memory for table %u of %u!\n",
table,
IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES);
return -ENOMEM;
}
/* add this sub-table to the main table */
ipsec_sadb.refTable[table] = SArefsub;
/* initialise each element to NULL */
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SArefSubTable_alloc: "
"initialising %u elements (2 ^ %u) of table %u.\n",
IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES,
IPSEC_SA_REF_SUBTABLE_IDX_WIDTH,
table);
for(entry = 0; entry < IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES; entry++) {
SArefsub->entry[entry] = NULL;
}
return 0;
}
#endif /* IPSEC_SA_REF_CODE */
int
ipsec_saref_freelist_init(void)
{
int i;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_saref_freelist_init: "
"initialising %u elements of FreeList.\n",
IPSEC_SA_REF_FREELIST_NUM_ENTRIES);
for(i = 0; i < IPSEC_SA_REF_FREELIST_NUM_ENTRIES; i++) {
ipsec_sadb.refFreeList[i] = IPSEC_SAREF_NULL;
}
ipsec_sadb.refFreeListHead = -1;
ipsec_sadb.refFreeListCont = 0;
ipsec_sadb.refFreeListTail = -1;
return 0;
}
int
ipsec_sadb_init(void)
{
int error = 0;
unsigned i;
for(i = 0; i < SADB_HASHMOD; i++) {
ipsec_sadb_hash[i] = NULL;
}
/* parts above are for the old style SADB hash table */
#if IPSEC_SA_REF_CODE
/* initialise SA reference table */
/* initialise the main table */
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_init: "
"initialising main table of size %u (2 ^ %u).\n",
IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES,
IPSEC_SA_REF_MAINTABLE_IDX_WIDTH);
{
unsigned table;
for(table = 0; table < IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES; table++) {
ipsec_sadb.refTable[table] = NULL;
}
}
/* allocate the first sub-table */
error = ipsec_SArefSubTable_alloc(0);
if(error) {
return error;
}
error = ipsec_saref_freelist_init();
#endif /* IPSEC_SA_REF_CODE */
return error;
}
#if IPSEC_SA_REF_CODE
IPsecSAref_t
ipsec_SAref_alloc(int*error) /* pass in error var by pointer */
{
IPsecSAref_t SAref;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_alloc: "
"SAref requested... head=%d, cont=%d, tail=%d, listsize=%d.\n",
ipsec_sadb.refFreeListHead,
ipsec_sadb.refFreeListCont,
ipsec_sadb.refFreeListTail,
IPSEC_SA_REF_FREELIST_NUM_ENTRIES);
if(ipsec_sadb.refFreeListHead == -1) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_alloc: "
"FreeList empty, recycling...\n");
*error = ipsec_SAref_recycle();
if(*error) {
return IPSEC_SAREF_NULL;
}
}
SAref = ipsec_sadb.refFreeList[ipsec_sadb.refFreeListHead];
if(SAref == IPSEC_SAREF_NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_alloc: "
"unexpected error, refFreeListHead = %d points to invalid entry.\n",
ipsec_sadb.refFreeListHead);
*error = -ESPIPE;
return IPSEC_SAREF_NULL;
}
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_alloc: "
"allocating SAref=%d, table=%u, entry=%u of %u.\n",
SAref,
IPsecSAref2table(SAref),
IPsecSAref2entry(SAref),
IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES * IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES);
ipsec_sadb.refFreeList[ipsec_sadb.refFreeListHead] = IPSEC_SAREF_NULL;
ipsec_sadb.refFreeListHead++;
if(ipsec_sadb.refFreeListHead > ipsec_sadb.refFreeListTail) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_SAref_alloc: "
"last FreeList entry allocated, resetting list head to empty.\n");
ipsec_sadb.refFreeListHead = -1;
}
return SAref;
}
#endif /* IPSEC_SA_REF_CODE */
int
ipsec_sa_print(struct ipsec_sa *ips)
{
char sa[SATOT_BUF];
size_t sa_len;
printk(KERN_INFO "klips_debug: SA:");
if(ips == NULL) {
printk("NULL\n");
return -ENOENT;
}
printk(" ref=%d", ips->ips_ref);
printk(" refcount=%d", atomic_read(&ips->ips_refcount));
if(ips->ips_hnext != NULL) {
printk(" hnext=0p%p", ips->ips_hnext);
}
if(ips->ips_inext != NULL) {
printk(" inext=0p%p", ips->ips_inext);
}
if(ips->ips_onext != NULL) {
printk(" onext=0p%p", ips->ips_onext);
}
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
printk(" said=%s", sa_len ? sa : " (error)");
if(ips->ips_seq) {
printk(" seq=%u", ips->ips_seq);
}
if(ips->ips_pid) {
printk(" pid=%u", ips->ips_pid);
}
if(ips->ips_authalg) {
printk(" authalg=%u", ips->ips_authalg);
}
if(ips->ips_encalg) {
printk(" encalg=%u", ips->ips_encalg);
}
printk(" XFORM=%s%s%s", IPS_XFORM_NAME(ips));
if(ips->ips_replaywin) {
printk(" ooowin=%u", ips->ips_replaywin);
}
if(ips->ips_flags) {
printk(" flags=%u", ips->ips_flags);
}
if(ips->ips_addr_s) {
char buf[SUBNETTOA_BUF];
addrtoa(((struct sockaddr_in*)(ips->ips_addr_s))->sin_addr,
0, buf, sizeof(buf));
printk(" src=%s", buf);
}
if(ips->ips_addr_d) {
char buf[SUBNETTOA_BUF];
addrtoa(((struct sockaddr_in*)(ips->ips_addr_s))->sin_addr,
0, buf, sizeof(buf));
printk(" dst=%s", buf);
}
if(ips->ips_addr_p) {
char buf[SUBNETTOA_BUF];
addrtoa(((struct sockaddr_in*)(ips->ips_addr_p))->sin_addr,
0, buf, sizeof(buf));
printk(" proxy=%s", buf);
}
if(ips->ips_key_bits_a) {
printk(" key_bits_a=%u", ips->ips_key_bits_a);
}
if(ips->ips_key_bits_e) {
printk(" key_bits_e=%u", ips->ips_key_bits_e);
}
printk("\n");
return 0;
}
struct ipsec_sa*
ipsec_sa_alloc(int*error) /* pass in error var by pointer */
{
struct ipsec_sa* ips;
if((ips = kmalloc(sizeof(*ips), GFP_ATOMIC) ) == NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_alloc: "
"memory allocation error\n");
*error = -ENOMEM;
return NULL;
}
memset((caddr_t)ips, 0, sizeof(*ips));
#if IPSEC_SA_REF_CODE
ips->ips_ref = ipsec_SAref_alloc(error); /* pass in error return by pointer */
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_alloc: "
"allocated %lu bytes for ipsec_sa struct=0p%p ref=%d.\n",
(unsigned long) sizeof(*ips),
ips,
ips->ips_ref);
if(ips->ips_ref == IPSEC_SAREF_NULL) {
kfree(ips);
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_alloc: "
"SAref allocation error\n");
return NULL;
}
atomic_inc(&ips->ips_refcount);
IPsecSAref2SA(ips->ips_ref) = ips;
#endif /* IPSEC_SA_REF_CODE */
*error = 0;
return(ips);
}
int
ipsec_sa_free(struct ipsec_sa* ips)
{
return ipsec_sa_wipe(ips);
}
struct ipsec_sa *
ipsec_sa_getbyid(ip_said *said)
{
int hashval;
struct ipsec_sa *ips;
char sa[SATOT_BUF];
size_t sa_len;
if(said == NULL) {
KLIPS_PRINT(debug_xform,
"klips_error:ipsec_sa_getbyid: "
"null pointer passed in!\n");
return NULL;
}
sa_len = satot(said, 0, sa, sizeof(sa));
hashval = IPS_HASH(said);
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_getbyid: "
"linked entry in ipsec_sa table for hash=%d of SA:%s requested.\n",
hashval,
sa_len ? sa : " (error)");
if((ips = ipsec_sadb_hash[hashval]) == NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_getbyid: "
"no entries in ipsec_sa table for hash=%d of SA:%s.\n",
hashval,
sa_len ? sa : " (error)");
return NULL;
}
for (; ips; ips = ips->ips_hnext) {
if ((ips->ips_said.spi == said->spi) &&
(ips->ips_said.dst.u.v4.sin_addr.s_addr == said->dst.u.v4.sin_addr.s_addr) &&
(ips->ips_said.proto == said->proto)) {
atomic_inc(&ips->ips_refcount);
return ips;
}
}
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_getbyid: "
"no entry in linked list for hash=%d of SA:%s.\n",
hashval,
sa_len ? sa : " (error)");
return NULL;
}
int
ipsec_sa_put(struct ipsec_sa *ips)
{
char sa[SATOT_BUF];
size_t sa_len;
if(ips == NULL) {
KLIPS_PRINT(debug_xform,
"klips_error:ipsec_sa_put: "
"null pointer passed in!\n");
return -1;
}
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_put: "
"ipsec_sa SA:%s, ref:%d reference count decremented.\n",
sa_len ? sa : " (error)",
ips->ips_ref);
atomic_dec(&ips->ips_refcount);
return 0;
}
/*
The ipsec_sa table better *NOT* be locked before it is handed in, or SMP locks will happen
*/
int
ipsec_sa_add(struct ipsec_sa *ips)
{
int error = 0;
unsigned int hashval;
if(ips == NULL) {
KLIPS_PRINT(debug_xform,
"klips_error:ipsec_sa_add: "
"null pointer passed in!\n");
return -ENODATA;
}
hashval = IPS_HASH(&ips->ips_said);
atomic_inc(&ips->ips_refcount);
spin_lock_bh(&tdb_lock);
ips->ips_hnext = ipsec_sadb_hash[hashval];
ipsec_sadb_hash[hashval] = ips;
spin_unlock_bh(&tdb_lock);
return error;
}
/*
The ipsec_sa table better be locked before it is handed in, or races might happen
*/
int
ipsec_sa_del(struct ipsec_sa *ips)
{
unsigned int hashval;
struct ipsec_sa *ipstp;
char sa[SATOT_BUF];
size_t sa_len;
if(ips == NULL) {
KLIPS_PRINT(debug_xform,
"klips_error:ipsec_sa_del: "
"null pointer passed in!\n");
return -ENODATA;
}
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
if(ips->ips_inext || ips->ips_onext) {
KLIPS_PRINT(debug_xform,
"klips_error:ipsec_sa_del: "
"SA:%s still linked!\n",
sa_len ? sa : " (error)");
return -EMLINK;
}
hashval = IPS_HASH(&ips->ips_said);
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_del: "
"deleting SA:%s, hashval=%d.\n",
sa_len ? sa : " (error)",
hashval);
if(ipsec_sadb_hash[hashval] == NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_del: "
"no entries in ipsec_sa table for hash=%d of SA:%s.\n",
hashval,
sa_len ? sa : " (error)");
return -ENOENT;
}
if (ips == ipsec_sadb_hash[hashval]) {
ipsec_sadb_hash[hashval] = ipsec_sadb_hash[hashval]->ips_hnext;
ips->ips_hnext = NULL;
atomic_dec(&ips->ips_refcount);
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_del: "
"successfully deleted first ipsec_sa in chain.\n");
return 0;
} else {
for (ipstp = ipsec_sadb_hash[hashval];
ipstp;
ipstp = ipstp->ips_hnext) {
if (ipstp->ips_hnext == ips) {
ipstp->ips_hnext = ips->ips_hnext;
ips->ips_hnext = NULL;
atomic_dec(&ips->ips_refcount);
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_del: "
"successfully deleted link in ipsec_sa chain.\n");
return 0;
}
}
}
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_del: "
"no entries in linked list for hash=%d of SA:%s.\n",
hashval,
sa_len ? sa : " (error)");
return -ENOENT;
}
/*
The ipsec_sa table better be locked before it is handed in, or races
might happen
*/
int
ipsec_sa_delchain(struct ipsec_sa *ips)
{
struct ipsec_sa *ipsdel;
int error = 0;
char sa[SATOT_BUF];
size_t sa_len;
if(ips == NULL) {
KLIPS_PRINT(debug_xform,
"klips_error:ipsec_sa_delchain: "
"null pointer passed in!\n");
return -ENODATA;
}
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_delchain: "
"passed SA:%s\n",
sa_len ? sa : " (error)");
while(ips->ips_onext != NULL) {
ips = ips->ips_onext;
}
while(ips) {
/* XXX send a pfkey message up to advise of deleted ipsec_sa */
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_delchain: "
"unlinking and delting SA:%s",
sa_len ? sa : " (error)");
ipsdel = ips;
ips = ips->ips_inext;
if(ips != NULL) {
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", inext=%s",
sa_len ? sa : " (error)");
atomic_dec(&ipsdel->ips_refcount);
ipsdel->ips_inext = NULL;
atomic_dec(&ips->ips_refcount);
ips->ips_onext = NULL;
}
KLIPS_PRINT(debug_xform,
".\n");
if((error = ipsec_sa_del(ipsdel))) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_delchain: "
"ipsec_sa_del returned error %d.\n", -error);
return error;
}
if((error = ipsec_sa_wipe(ipsdel))) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_delchain: "
"ipsec_sa_wipe returned error %d.\n", -error);
return error;
}
}
return error;
}
int
ipsec_sadb_cleanup(__u8 proto)
{
unsigned i;
int error = 0;
struct ipsec_sa *ips, **ipsprev, *ipsdel;
char sa[SATOT_BUF];
size_t sa_len;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"cleaning up proto=%d.\n",
proto);
spin_lock_bh(&tdb_lock);
for (i = 0; i < SADB_HASHMOD; i++) {
ipsprev = &(ipsec_sadb_hash[i]);
ips = ipsec_sadb_hash[i];
if(ips != NULL) {
atomic_inc(&ips->ips_refcount);
}
for(; ips != NULL;) {
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"checking SA:%s, hash=%d, ref=%d",
sa_len ? sa : " (error)",
i,
ips->ips_ref);
ipsdel = ips;
ips = ipsdel->ips_hnext;
if(ips != NULL) {
atomic_inc(&ips->ips_refcount);
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", hnext=%s",
sa_len ? sa : " (error)");
}
if(*ipsprev != NULL) {
sa_len = satot(&(*ipsprev)->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", *ipsprev=%s",
sa_len ? sa : " (error)");
if((*ipsprev)->ips_hnext) {
sa_len = satot(&(*ipsprev)->ips_hnext->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", *ipsprev->ips_hnext=%s",
sa_len ? sa : " (error)");
}
}
KLIPS_PRINT(debug_xform,
".\n");
if(proto == 0 || (proto == ipsdel->ips_said.proto)) {
sa_len = satot(&ipsdel->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"deleting SA chain:%s.\n",
sa_len ? sa : " (error)");
if((error = ipsec_sa_delchain(ipsdel))) {
SENDERR(-error);
}
ipsprev = &(ipsec_sadb_hash[i]);
ips = ipsec_sadb_hash[i];
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"deleted SA chain:%s",
sa_len ? sa : " (error)");
if(ips != NULL) {
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", ipsec_sadb_hash[%d]=%s",
i,
sa_len ? sa : " (error)");
}
if(*ipsprev != NULL) {
sa_len = satot(&(*ipsprev)->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", *ipsprev=%s",
sa_len ? sa : " (error)");
if((*ipsprev)->ips_hnext != NULL) {
sa_len = satot(&(*ipsprev)->ips_hnext->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
", *ipsprev->ips_hnext=%s",
sa_len ? sa : " (error)");
}
}
KLIPS_PRINT(debug_xform,
".\n");
} else {
ipsprev = &ipsdel;
}
if(ipsdel != NULL) {
ipsec_sa_put(ipsdel);
}
}
}
errlab:
spin_unlock_bh(&tdb_lock);
#if IPSEC_SA_REF_CODE
/* clean up SA reference table */
/* go through the ref table and clean out all the SAs */
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"removing SAref entries and tables.");
{
unsigned table, entry;
for(table = 0; table < IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES; table++) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"cleaning SAref table=%u.\n",
table);
if(ipsec_sadb.refTable[table] == NULL) {
printk("\n");
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_cleanup: "
"cleaned %u used refTables.\n",
table);
break;
}
for(entry = 0; entry < IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES; entry++) {
if(ipsec_sadb.refTable[table]->entry[entry] != NULL) {
ipsec_sa_delchain(ipsec_sadb.refTable[table]->entry[entry]);
ipsec_sadb.refTable[table]->entry[entry] = NULL;
}
}
}
}
#endif /* IPSEC_SA_REF_CODE */
return(error);
}
int
ipsec_sadb_free(void)
{
int error = 0;
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_free: "
"freeing SArefTable memory.\n");
/* clean up SA reference table */
/* go through the ref table and clean out all the SAs if any are
left and free table memory */
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_free: "
"removing SAref entries and tables.\n");
{
unsigned table, entry;
for(table = 0; table < IPSEC_SA_REF_MAINTABLE_NUM_ENTRIES; table++) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_free: "
"removing SAref table=%u.\n",
table);
if(ipsec_sadb.refTable[table] == NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sadb_free: "
"removed %u used refTables.\n",
table);
break;
}
for(entry = 0; entry < IPSEC_SA_REF_SUBTABLE_NUM_ENTRIES; entry++) {
if(ipsec_sadb.refTable[table]->entry[entry] != NULL) {
ipsec_sa_delchain(ipsec_sadb.refTable[table]->entry[entry]);
ipsec_sadb.refTable[table]->entry[entry] = NULL;
}
}
vfree(ipsec_sadb.refTable[table]);
ipsec_sadb.refTable[table] = NULL;
}
}
return(error);
}
int
ipsec_sa_wipe(struct ipsec_sa *ips)
{
if(ips == NULL) {
return -ENODATA;
}
/* if(atomic_dec_and_test(ips)) {
}; */
#if IPSEC_SA_REF_CODE
/* remove me from the SArefTable */
{
char sa[SATOT_BUF];
size_t sa_len;
sa_len = satot(&ips->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_wipe: "
"removing SA=%s(0p%p), SAref=%d, table=%d(0p%p), entry=%d from the refTable.\n",
sa_len ? sa : " (error)",
ips,
ips->ips_ref,
IPsecSAref2table(IPsecSA2SAref(ips)),
ipsec_sadb.refTable[IPsecSAref2table(IPsecSA2SAref(ips))],
IPsecSAref2entry(IPsecSA2SAref(ips)));
}
if(ips->ips_ref == IPSEC_SAREF_NULL) {
KLIPS_PRINT(debug_xform,
"klips_debug:ipsec_sa_wipe: "
"why does this SA not have a valid SAref?.\n");
}
ipsec_sadb.refTable[IPsecSAref2table(IPsecSA2SAref(ips))]->entry[IPsecSAref2entry(IPsecSA2SAref(ips))] = NULL;
ips->ips_ref = IPSEC_SAREF_NULL;
ipsec_sa_put(ips);
#endif /* IPSEC_SA_REF_CODE */
/* paranoid clean up */
if(ips->ips_addr_s != NULL) {
memset((caddr_t)(ips->ips_addr_s), 0, ips->ips_addr_s_size);
kfree(ips->ips_addr_s);
}
ips->ips_addr_s = NULL;
if(ips->ips_addr_d != NULL) {
memset((caddr_t)(ips->ips_addr_d), 0, ips->ips_addr_d_size);
kfree(ips->ips_addr_d);
}
ips->ips_addr_d = NULL;
if(ips->ips_addr_p != NULL) {
memset((caddr_t)(ips->ips_addr_p), 0, ips->ips_addr_p_size);
kfree(ips->ips_addr_p);
}
ips->ips_addr_p = NULL;
#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
if(ips->ips_natt_oa) {
memset((caddr_t)(ips->ips_natt_oa), 0, ips->ips_natt_oa_size);
kfree(ips->ips_natt_oa);
}
ips->ips_natt_oa = NULL;
#endif
if(ips->ips_key_a != NULL) {
memset((caddr_t)(ips->ips_key_a), 0, ips->ips_key_a_size);
kfree(ips->ips_key_a);
}
ips->ips_key_a = NULL;
if(ips->ips_key_e != NULL) {
if (ips->ips_alg_enc &&
ips->ips_alg_enc->ixt_e_destroy_key)
{
ips->ips_alg_enc->ixt_e_destroy_key(ips->ips_alg_enc,
ips->ips_key_e);
} else
{
memset((caddr_t)(ips->ips_key_e), 0, ips->ips_key_e_size);
kfree(ips->ips_key_e);
}
}
ips->ips_key_e = NULL;
if(ips->ips_iv != NULL) {
memset((caddr_t)(ips->ips_iv), 0, ips->ips_iv_size);
kfree(ips->ips_iv);
}
ips->ips_iv = NULL;
if(ips->ips_ident_s.data != NULL) {
memset((caddr_t)(ips->ips_ident_s.data),
0,
ips->ips_ident_s.len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident));
kfree(ips->ips_ident_s.data);
}
ips->ips_ident_s.data = NULL;
if(ips->ips_ident_d.data != NULL) {
memset((caddr_t)(ips->ips_ident_d.data),
0,
ips->ips_ident_d.len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident));
kfree(ips->ips_ident_d.data);
}
ips->ips_ident_d.data = NULL;
if (ips->ips_alg_enc||ips->ips_alg_auth) {
ipsec_alg_sa_wipe(ips);
}
memset((caddr_t)ips, 0, sizeof(*ips));
kfree(ips);
ips = NULL;
return 0;
}
extern int sysctl_ipsec_debug_verbose;
int ipsec_sa_init(struct ipsec_sa *ipsp)
{
int i;
int error = 0;
char sa[SATOT_BUF];
size_t sa_len;
char ipaddr_txt[ADDRTOA_BUF];
char ipaddr2_txt[ADDRTOA_BUF];
#if defined (CONFIG_KLIPS_AUTH_HMAC_MD5) || defined (CONFIG_KLIPS_AUTH_HMAC_SHA1)
unsigned char kb[AHMD596_BLKLEN];
#endif
struct ipsec_alg_enc *ixt_e = NULL;
struct ipsec_alg_auth *ixt_a = NULL;
if(ipsp == NULL) {
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"ipsp is NULL, fatal\n");
SENDERR(EINVAL);
}
sa_len = satot(&ipsp->ips_said, 0, sa, sizeof(sa));
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"(pfkey defined) called for SA:%s\n",
sa_len ? sa : " (error)");
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"calling init routine of %s%s%s\n",
IPS_XFORM_NAME(ipsp));
switch(ipsp->ips_said.proto) {
#ifdef CONFIG_KLIPS_IPIP
case IPPROTO_IPIP: {
addrtoa(((struct sockaddr_in*)(ipsp->ips_addr_s))->sin_addr,
0,
ipaddr_txt, sizeof(ipaddr_txt));
addrtoa(((struct sockaddr_in*)(ipsp->ips_addr_d))->sin_addr,
0,
ipaddr2_txt, sizeof(ipaddr_txt));
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"(pfkey defined) IPIP ipsec_sa set for %s->%s.\n",
ipaddr_txt,
ipaddr2_txt);
}
break;
#endif /* !CONFIG_KLIPS_IPIP */
#ifdef CONFIG_KLIPS_AH
case IPPROTO_AH:
switch(ipsp->ips_authalg) {
# ifdef CONFIG_KLIPS_AUTH_HMAC_MD5
case AH_MD5: {
unsigned char *akp;
unsigned int aks;
MD5_CTX *ictx;
MD5_CTX *octx;
if(ipsp->ips_key_bits_a != (AHMD596_KLEN * 8)) {
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"incorrect key size: %d bits -- must be %d bits\n"/*octets (bytes)\n"*/,
ipsp->ips_key_bits_a, AHMD596_KLEN * 8);
SENDERR(EINVAL);
}
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"hmac md5-96 key is 0x%08x %08x %08x %08x\n",
ntohl(*(((__u32 *)ipsp->ips_key_a)+0)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+1)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+2)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+3)));
# endif /* KLIPS_DIVULGE_HMAC_KEY */
ipsp->ips_auth_bits = AHMD596_ALEN * 8;
/* save the pointer to the key material */
akp = ipsp->ips_key_a;
aks = ipsp->ips_key_a_size;
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"allocating %lu bytes for md5_ctx.\n",
(unsigned long) sizeof(struct md5_ctx));
if((ipsp->ips_key_a = (caddr_t)
kmalloc(sizeof(struct md5_ctx), GFP_ATOMIC)) == NULL) {
ipsp->ips_key_a = akp;
SENDERR(ENOMEM);
}
ipsp->ips_key_a_size = sizeof(struct md5_ctx);
for (i = 0; i < DIVUP(ipsp->ips_key_bits_a, 8); i++) {
kb[i] = akp[i] ^ HMAC_IPAD;
}
for (; i < AHMD596_BLKLEN; i++) {
kb[i] = HMAC_IPAD;
}
ictx = &(((struct md5_ctx*)(ipsp->ips_key_a))->ictx);
osMD5Init(ictx);
osMD5Update(ictx, kb, AHMD596_BLKLEN);
for (i = 0; i < AHMD596_BLKLEN; i++) {
kb[i] ^= (HMAC_IPAD ^ HMAC_OPAD);
}
octx = &(((struct md5_ctx*)(ipsp->ips_key_a))->octx);
osMD5Init(octx);
osMD5Update(octx, kb, AHMD596_BLKLEN);
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"MD5 ictx=0x%08x %08x %08x %08x octx=0x%08x %08x %08x %08x\n",
((__u32*)ictx)[0],
((__u32*)ictx)[1],
((__u32*)ictx)[2],
((__u32*)ictx)[3],
((__u32*)octx)[0],
((__u32*)octx)[1],
((__u32*)octx)[2],
((__u32*)octx)[3] );
# endif /* KLIPS_DIVULGE_HMAC_KEY */
/* zero key buffer -- paranoid */
memset(akp, 0, aks);
kfree(akp);
}
break;
# endif /* CONFIG_KLIPS_AUTH_HMAC_MD5 */
# ifdef CONFIG_KLIPS_AUTH_HMAC_SHA1
case AH_SHA: {
unsigned char *akp;
unsigned int aks;
SHA1_CTX *ictx;
SHA1_CTX *octx;
if(ipsp->ips_key_bits_a != (AHSHA196_KLEN * 8)) {
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"incorrect key size: %d bits -- must be %d bits\n"/*octets (bytes)\n"*/,
ipsp->ips_key_bits_a, AHSHA196_KLEN * 8);
SENDERR(EINVAL);
}
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"hmac sha1-96 key is 0x%08x %08x %08x %08x\n",
ntohl(*(((__u32 *)ipsp->ips_key_a)+0)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+1)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+2)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+3)));
# endif /* KLIPS_DIVULGE_HMAC_KEY */
ipsp->ips_auth_bits = AHSHA196_ALEN * 8;
/* save the pointer to the key material */
akp = ipsp->ips_key_a;
aks = ipsp->ips_key_a_size;
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"allocating %lu bytes for sha1_ctx.\n",
(unsigned long) sizeof(struct sha1_ctx));
if((ipsp->ips_key_a = (caddr_t)
kmalloc(sizeof(struct sha1_ctx), GFP_ATOMIC)) == NULL) {
ipsp->ips_key_a = akp;
SENDERR(ENOMEM);
}
ipsp->ips_key_a_size = sizeof(struct sha1_ctx);
for (i = 0; i < DIVUP(ipsp->ips_key_bits_a, 8); i++) {
kb[i] = akp[i] ^ HMAC_IPAD;
}
for (; i < AHMD596_BLKLEN; i++) {
kb[i] = HMAC_IPAD;
}
ictx = &(((struct sha1_ctx*)(ipsp->ips_key_a))->ictx);
SHA1Init(ictx);
SHA1Update(ictx, kb, AHSHA196_BLKLEN);
for (i = 0; i < AHSHA196_BLKLEN; i++) {
kb[i] ^= (HMAC_IPAD ^ HMAC_OPAD);
}
octx = &(((struct sha1_ctx*)(ipsp->ips_key_a))->octx);
SHA1Init(octx);
SHA1Update(octx, kb, AHSHA196_BLKLEN);
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"SHA1 ictx=0x%08x %08x %08x %08x octx=0x%08x %08x %08x %08x\n",
((__u32*)ictx)[0],
((__u32*)ictx)[1],
((__u32*)ictx)[2],
((__u32*)ictx)[3],
((__u32*)octx)[0],
((__u32*)octx)[1],
((__u32*)octx)[2],
((__u32*)octx)[3] );
# endif /* KLIPS_DIVULGE_HMAC_KEY */
/* zero key buffer -- paranoid */
memset(akp, 0, aks);
kfree(akp);
}
break;
# endif /* CONFIG_KLIPS_AUTH_HMAC_SHA1 */
default:
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"authalg=%d support not available in the kernel",
ipsp->ips_authalg);
SENDERR(EINVAL);
}
break;
#endif /* CONFIG_KLIPS_AH */
#ifdef CONFIG_KLIPS_ESP
case IPPROTO_ESP:
{
#if defined (CONFIG_KLIPS_AUTH_HMAC_MD5) || defined (CONFIG_KLIPS_AUTH_HMAC_SHA1)
unsigned char *akp;
unsigned int aks;
#endif
ipsec_alg_sa_init(ipsp);
ixt_e=ipsp->ips_alg_enc;
if (ixt_e == NULL) {
if(printk_ratelimit()) {
printk(KERN_INFO
"ipsec_sa_init: "
"encalg=%d support not available in the kernel",
ipsp->ips_encalg);
}
SENDERR(ENOENT);
}
ipsp->ips_iv_size = ixt_e->ixt_common.ixt_support.ias_ivlen/8;
/* Create IV */
if (ipsp->ips_iv_size) {
if((ipsp->ips_iv = (caddr_t)
kmalloc(ipsp->ips_iv_size, GFP_ATOMIC)) == NULL) {
SENDERR(ENOMEM);
}
prng_bytes(&ipsec_prng,
(char *)ipsp->ips_iv,
ipsp->ips_iv_size);
ipsp->ips_iv_bits = ipsp->ips_iv_size * 8;
}
if ((error=ipsec_alg_enc_key_create(ipsp)) < 0)
SENDERR(-error);
if ((ixt_a=ipsp->ips_alg_auth)) {
if ((error=ipsec_alg_auth_key_create(ipsp)) < 0)
SENDERR(-error);
} else
switch(ipsp->ips_authalg) {
# ifdef CONFIG_KLIPS_AUTH_HMAC_MD5
case AH_MD5: {
MD5_CTX *ictx;
MD5_CTX *octx;
if(ipsp->ips_key_bits_a != (AHMD596_KLEN * 8)) {
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"incorrect authorisation key size: %d bits -- must be %d bits\n"/*octets (bytes)\n"*/,
ipsp->ips_key_bits_a,
AHMD596_KLEN * 8);
SENDERR(EINVAL);
}
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"hmac md5-96 key is 0x%08x %08x %08x %08x\n",
ntohl(*(((__u32 *)(ipsp->ips_key_a))+0)),
ntohl(*(((__u32 *)(ipsp->ips_key_a))+1)),
ntohl(*(((__u32 *)(ipsp->ips_key_a))+2)),
ntohl(*(((__u32 *)(ipsp->ips_key_a))+3)));
# endif /* KLIPS_DIVULGE_HMAC_KEY */
ipsp->ips_auth_bits = AHMD596_ALEN * 8;
/* save the pointer to the key material */
akp = ipsp->ips_key_a;
aks = ipsp->ips_key_a_size;
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"allocating %lu bytes for md5_ctx.\n",
(unsigned long) sizeof(struct md5_ctx));
if((ipsp->ips_key_a = (caddr_t)
kmalloc(sizeof(struct md5_ctx), GFP_ATOMIC)) == NULL) {
ipsp->ips_key_a = akp;
SENDERR(ENOMEM);
}
ipsp->ips_key_a_size = sizeof(struct md5_ctx);
for (i = 0; i < DIVUP(ipsp->ips_key_bits_a, 8); i++) {
kb[i] = akp[i] ^ HMAC_IPAD;
}
for (; i < AHMD596_BLKLEN; i++) {
kb[i] = HMAC_IPAD;
}
ictx = &(((struct md5_ctx*)(ipsp->ips_key_a))->ictx);
osMD5Init(ictx);
osMD5Update(ictx, kb, AHMD596_BLKLEN);
for (i = 0; i < AHMD596_BLKLEN; i++) {
kb[i] ^= (HMAC_IPAD ^ HMAC_OPAD);
}
octx = &(((struct md5_ctx*)(ipsp->ips_key_a))->octx);
osMD5Init(octx);
osMD5Update(octx, kb, AHMD596_BLKLEN);
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"MD5 ictx=0x%08x %08x %08x %08x octx=0x%08x %08x %08x %08x\n",
((__u32*)ictx)[0],
((__u32*)ictx)[1],
((__u32*)ictx)[2],
((__u32*)ictx)[3],
((__u32*)octx)[0],
((__u32*)octx)[1],
((__u32*)octx)[2],
((__u32*)octx)[3] );
# endif /* KLIPS_DIVULGE_HMAC_KEY */
/* paranoid */
memset(akp, 0, aks);
kfree(akp);
break;
}
# endif /* CONFIG_KLIPS_AUTH_HMAC_MD5 */
# ifdef CONFIG_KLIPS_AUTH_HMAC_SHA1
case AH_SHA: {
SHA1_CTX *ictx;
SHA1_CTX *octx;
if(ipsp->ips_key_bits_a != (AHSHA196_KLEN * 8)) {
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"incorrect authorisation key size: %d bits -- must be %d bits\n"/*octets (bytes)\n"*/,
ipsp->ips_key_bits_a,
AHSHA196_KLEN * 8);
SENDERR(EINVAL);
}
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"hmac sha1-96 key is 0x%08x %08x %08x %08x\n",
ntohl(*(((__u32 *)ipsp->ips_key_a)+0)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+1)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+2)),
ntohl(*(((__u32 *)ipsp->ips_key_a)+3)));
# endif /* KLIPS_DIVULGE_HMAC_KEY */
ipsp->ips_auth_bits = AHSHA196_ALEN * 8;
/* save the pointer to the key material */
akp = ipsp->ips_key_a;
aks = ipsp->ips_key_a_size;
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"allocating %lu bytes for sha1_ctx.\n",
(unsigned long) sizeof(struct sha1_ctx));
if((ipsp->ips_key_a = (caddr_t)
kmalloc(sizeof(struct sha1_ctx), GFP_ATOMIC)) == NULL) {
ipsp->ips_key_a = akp;
SENDERR(ENOMEM);
}
ipsp->ips_key_a_size = sizeof(struct sha1_ctx);
for (i = 0; i < DIVUP(ipsp->ips_key_bits_a, 8); i++) {
kb[i] = akp[i] ^ HMAC_IPAD;
}
for (; i < AHMD596_BLKLEN; i++) {
kb[i] = HMAC_IPAD;
}
ictx = &(((struct sha1_ctx*)(ipsp->ips_key_a))->ictx);
SHA1Init(ictx);
SHA1Update(ictx, kb, AHSHA196_BLKLEN);
for (i = 0; i < AHSHA196_BLKLEN; i++) {
kb[i] ^= (HMAC_IPAD ^ HMAC_OPAD);
}
octx = &((struct sha1_ctx*)(ipsp->ips_key_a))->octx;
SHA1Init(octx);
SHA1Update(octx, kb, AHSHA196_BLKLEN);
# if KLIPS_DIVULGE_HMAC_KEY
KLIPS_PRINT(debug_pfkey && sysctl_ipsec_debug_verbose,
"ipsec_sa_init: "
"SHA1 ictx=0x%08x %08x %08x %08x octx=0x%08x %08x %08x %08x\n",
((__u32*)ictx)[0],
((__u32*)ictx)[1],
((__u32*)ictx)[2],
((__u32*)ictx)[3],
((__u32*)octx)[0],
((__u32*)octx)[1],
((__u32*)octx)[2],
((__u32*)octx)[3] );
# endif /* KLIPS_DIVULGE_HMAC_KEY */
memset(akp, 0, aks);
kfree(akp);
break;
}
# endif /* CONFIG_KLIPS_AUTH_HMAC_SHA1 */
case AH_NONE:
break;
default:
KLIPS_PRINT(debug_pfkey,
"ipsec_sa_init: "
"authalg=%d support not available in the kernel.\n",
ipsp->ips_authalg);
SENDERR(EINVAL);
}
}
break;
#endif /* !CONFIG_KLIPS_ESP */
#ifdef CONFIG_KLIPS_IPCOMP
case IPPROTO_COMP:
ipsp->ips_comp_adapt_tries = 0;
ipsp->ips_comp_adapt_skip = 0;
ipsp->ips_comp_ratio_cbytes = 0;
ipsp->ips_comp_ratio_dbytes = 0;
break;
#endif /* CONFIG_KLIPS_IPCOMP */
default:
printk(KERN_ERR "KLIPS sa initialization: "
"proto=%d unknown.\n",
ipsp->ips_said.proto);
SENDERR(EINVAL);
}
errlab:
return(error);
}
/*
* $Log: ipsec_sa.c,v $
* Revision 1.30.2.1 2006/04/20 16:33:07 mcr
* remove all of CONFIG_KLIPS_ALG --- one can no longer build without it.
* Fix in-kernel module compilation. Sub-makefiles do not work.
*
* Revision 1.30 2005/05/24 01:02:35 mcr
* some refactoring/simplification of situation where alg
* is not found.
*
* Revision 1.29 2005/05/18 19:13:28 mcr
* rename debug messages. make sure that algo not found is not
* a debug message.
*
* Revision 1.28 2005/05/11 01:30:20 mcr
* removed "poor-man"s OOP in favour of proper C structures.
*
* Revision 1.27 2005/04/29 05:10:22 mcr
* removed from extraenous includes to make unit testing easier.
*
* Revision 1.26 2005/04/14 20:56:24 mcr
* moved (pfkey_)ipsec_sa_init to ipsec_sa.c.
*
* Revision 1.25 2004/08/22 20:12:16 mcr
* one more KLIPS_NAT->IPSEC_NAT.
*
* Revision 1.24 2004/07/10 19:11:18 mcr
* CONFIG_IPSEC -> CONFIG_KLIPS.
*
* Revision 1.23 2004/04/06 02:49:26 mcr
* pullup of algo code from alg-branch.
*
* Revision 1.22.2.1 2003/12/22 15:25:52 jjo
* . Merged algo-0.8.1-rc11-test1 into alg-branch
*
* Revision 1.22 2003/12/10 01:14:27 mcr
* NAT-traversal patches to KLIPS.
*
* Revision 1.21 2003/10/31 02:27:55 mcr
* pulled up port-selector patches and sa_id elimination.
*
* Revision 1.20.4.1 2003/10/29 01:30:41 mcr
* elimited "struct sa_id".
*
* Revision 1.20 2003/02/06 01:50:34 rgb
* Fixed initialisation bug for first sadb hash bucket that would only manifest itself on platforms where NULL != 0.
*
* Revision 1.19 2003/01/30 02:32:22 rgb
*
* Rename SAref table macro names for clarity.
* Transmit error code through to caller from callee for better diagnosis of problems.
* Convert IPsecSAref_t from signed to unsigned to fix apparent SAref exhaustion bug.
*
* Revision 1.18 2002/10/12 23:11:53 dhr
*
* [KenB + DHR] more 64-bit cleanup
*
* Revision 1.17 2002/10/07 18:31:43 rgb
* Move field width sanity checks to ipsec_sa.c
*
* Revision 1.16 2002/09/20 15:41:02 rgb
* Re-wrote most of the SAref code to eliminate Entry pointers.
* Added SAref code compiler directive switch.
* Added a saref test function for testing macros.
* Switch from pfkey_alloc_ipsec_sa() to ipsec_sa_alloc().
* Split ipsec_sadb_cleanup from new funciton ipsec_sadb_free to avoid problem
* of freeing newly created structures when clearing the reftable upon startup
* to start from a known state.
* Place all ipsec sadb globals into one struct.
* Rework saref freelist.
* Added memory allocation debugging.
*
* Revision 1.15 2002/09/20 05:01:44 rgb
* Update copyright date.
*
* Revision 1.14 2002/08/13 19:01:25 mcr
* patches from kenb to permit compilation of FreeSWAN on ia64.
* des library patched to use proper DES_LONG type for ia64.
*
* Revision 1.13 2002/07/29 03:06:20 mcr
* get rid of variable not used warnings.
*
* Revision 1.12 2002/07/26 08:48:31 rgb
* Added SA ref table code.
*
* Revision 1.11 2002/06/04 16:48:49 rgb
* Tidied up pointer code for processor independance.
*
* Revision 1.10 2002/05/23 07:16:17 rgb
* Added ipsec_sa_put() for releasing an ipsec_sa refcount.
* Pointer clean-up.
* Added refcount code.
* Convert "usecount" to "refcount" to remove ambiguity.
*
* Revision 1.9 2002/05/14 02:34:49 rgb
* Converted reference from ipsec_sa_put to ipsec_sa_add to avoid confusion
* with "put" usage in the kernel.
* Change all references to tdb, TDB or Tunnel Descriptor Block to ips,
* ipsec_sa or ipsec_sa.
* Added some preliminary refcount code.
*
* Revision 1.8 2002/04/24 07:55:32 mcr
* #include patches and Makefiles for post-reorg compilation.
*
* Revision 1.7 2002/04/24 07:36:30 mcr
* Moved from ./klips/net/ipsec/ipsec_sa.c,v
*
* Revision 1.6 2002/04/20 00:12:25 rgb
* Added esp IV CBC attack fix, disabled.
*
* Revision 1.5 2002/01/29 17:17:56 mcr
* moved include of ipsec_param.h to after include of linux/kernel.h
* otherwise, it seems that some option that is set in ipsec_param.h
* screws up something subtle in the include path to kernel.h, and
* it complains on the snprintf() prototype.
*
* Revision 1.4 2002/01/29 04:00:52 mcr
* more excise of kversions.h header.
*
* Revision 1.3 2002/01/29 02:13:18 mcr
* introduction of ipsec_kversion.h means that include of
* ipsec_param.h must preceed any decisions about what files to
* include to deal with differences in kernel source.
*
* Revision 1.2 2001/11/26 09:16:15 rgb
* Merge MCR's ipsec_sa, eroute, proc and struct lifetime changes.
*
* Revision 1.1.2.2 2001/10/22 21:05:41 mcr
* removed phony prototype for des_set_key.
*
* Revision 1.1.2.1 2001/09/25 02:24:57 mcr
* struct tdb -> struct ipsec_sa.
* sa(tdb) manipulation functions renamed and moved to ipsec_sa.c
* ipsec_xform.c removed. header file still contains useful things.
*
*
*
* CLONED from ipsec_xform.c:
* Revision 1.53 2001/09/08 21:13:34 rgb
* Added pfkey ident extension support for ISAKMPd. (NetCelo)
*
* Revision 1.52 2001/06/14 19:35:11 rgb
* Update copyright date.
*
* Revision 1.51 2001/05/30 08:14:03 rgb
* Removed vestiges of esp-null transforms.
*
* Revision 1.50 2001/05/03 19:43:18 rgb
* Initialise error return variable.
* Update SENDERR macro.
* Fix sign of error return code for ipsec_tdbcleanup().
* Use more appropriate return code for ipsec_tdbwipe().
*
* Revision 1.49 2001/04/19 18:56:17 rgb
* Fixed tdb table locking comments.
*
* Revision 1.48 2001/02/27 22:24:55 rgb
* Re-formatting debug output (line-splitting, joining, 1arg/line).
* Check for satoa() return codes.
*
* Revision 1.47 2000/11/06 04:32:08 rgb
* Ditched spin_lock_irqsave in favour of spin_lock_bh.
*
* Revision 1.46 2000/09/20 16:21:57 rgb
* Cleaned up ident string alloc/free.
*
* Revision 1.45 2000/09/08 19:16:51 rgb
* Change references from DEBUG_IPSEC to CONFIG_IPSEC_DEBUG.
* Removed all references to CONFIG_IPSEC_PFKEYv2.
*
* Revision 1.44 2000/08/30 05:29:04 rgb
* Compiler-define out no longer used tdb_init() in ipsec_xform.c.
*
* Revision 1.43 2000/08/18 21:30:41 rgb
* Purged all tdb_spi, tdb_proto and tdb_dst macros. They are unclear.
*
* Revision 1.42 2000/08/01 14:51:51 rgb
* Removed _all_ remaining traces of DES.
*
* Revision 1.41 2000/07/28 14:58:31 rgb
* Changed kfree_s to kfree, eliminating extra arg to fix 2.4.0-test5.
*
* Revision 1.40 2000/06/28 05:50:11 rgb
* Actually set iv_bits.
*
* Revision 1.39 2000/05/10 23:11:09 rgb
* Added netlink debugging output.
* Added a cast to quiet down the ntohl bug.
*
* Revision 1.38 2000/05/10 19:18:42 rgb
* Cast output of ntohl so that the broken prototype doesn't make our
* compile noisy.
*
* Revision 1.37 2000/03/16 14:04:59 rgb
* Hardwired CONFIG_IPSEC_PFKEYv2 on.
*
* Revision 1.36 2000/01/26 10:11:28 rgb
* Fixed spacing in error text causing run-in words.
*
* Revision 1.35 2000/01/21 06:17:16 rgb
* Tidied up compiler directive indentation for readability.
* Added ictx,octx vars for simplification.(kravietz)
* Added macros for HMAC padding magic numbers.(kravietz)
* Fixed missing key length reporting bug.
* Fixed bug in tdbwipe to return immediately on NULL tdbp passed in.
*
* Revision 1.34 1999/12/08 00:04:19 rgb
* Fixed SA direction overwriting bug for netlink users.
*
* Revision 1.33 1999/12/01 22:16:44 rgb
* Minor formatting changes in ESP MD5 initialisation.
*
* Revision 1.32 1999/11/25 09:06:36 rgb
* Fixed error return messages, should be returning negative numbers.
* Implemented SENDERR macro for propagating error codes.
* Added debug message and separate error code for algorithms not compiled
* in.
*
* Revision 1.31 1999/11/23 23:06:26 rgb
* Sort out pfkey and freeswan headers, putting them in a library path.
*
* Revision 1.30 1999/11/18 04:09:20 rgb
* Replaced all kernel version macros to shorter, readable form.
*
* Revision 1.29 1999/11/17 15:53:40 rgb
* Changed all occurrences of #include "../../../lib/freeswan.h"
* to #include <freeswan.h> which works due to -Ilibfreeswan in the
* klips/net/ipsec/Makefile.
*
* Revision 1.28 1999/10/18 20:04:01 rgb
* Clean-out unused cruft.
*
* Revision 1.27 1999/10/03 19:01:03 rgb
* Spinlock support for 2.3.xx and 2.0.xx kernels.
*
* Revision 1.26 1999/10/01 16:22:24 rgb
* Switch from assignment init. to functional init. of spinlocks.
*
* Revision 1.25 1999/10/01 15:44:54 rgb
* Move spinlock header include to 2.1> scope.
*
* Revision 1.24 1999/10/01 00:03:46 rgb
* Added tdb structure locking.
* Minor formatting changes.
* Add function to initialize tdb hash table.
*
* Revision 1.23 1999/05/25 22:42:12 rgb
* Add deltdbchain() debugging.
*
* Revision 1.22 1999/05/25 21:24:31 rgb
* Add debugging statements to deltdbchain().
*
* Revision 1.21 1999/05/25 03:51:48 rgb
* Refix error return code.
*
* Revision 1.20 1999/05/25 03:34:07 rgb
* Fix error return for flush.
*
* Revision 1.19 1999/05/09 03:25:37 rgb
* Fix bug introduced by 2.2 quick-and-dirty patch.
*
* Revision 1.18 1999/05/05 22:02:32 rgb
* Add a quick and dirty port to 2.2 kernels by Marc Boucher <marc@mbsi.ca>.
*
* Revision 1.17 1999/04/29 15:20:16 rgb
* Change gettdb parameter to a pointer to reduce stack loading and
* facilitate parameter sanity checking.
* Add sanity checking for null pointer arguments.
* Add debugging instrumentation.
* Add function deltdbchain() which will take care of unlinking,
* zeroing and deleting a chain of tdbs.
* Add a parameter to tdbcleanup to be able to delete a class of SAs.
* tdbwipe now actually zeroes the tdb as well as any of its pointed
* structures.
*
* Revision 1.16 1999/04/16 15:36:29 rgb
* Fix cut-and-paste error causing a memory leak in IPIP TDB freeing.
*
* Revision 1.15 1999/04/11 00:29:01 henry
* GPL boilerplate
*
* Revision 1.14 1999/04/06 04:54:28 rgb
* Fix/Add RCSID Id: and Log: bits to make PHMDs happy. This includes
* patch shell fixes.
*
* Revision 1.13 1999/02/19 18:23:01 rgb
* Nix debug off compile warning.
*
* Revision 1.12 1999/02/17 16:52:16 rgb
* Consolidate satoa()s for space and speed efficiency.
* Convert DEBUG_IPSEC to KLIPS_PRINT
* Clean out unused cruft.
* Ditch NET_IPIP dependancy.
* Loop for 3des key setting.
*
* Revision 1.11 1999/01/26 02:09:05 rgb
* Remove ah/esp/IPIP switching on include files.
* Removed CONFIG_IPSEC_ALGO_SWITCH macro.
* Removed dead code.
* Clean up debug code when switched off.
* Remove references to INET_GET_PROTOCOL.
* Added code exclusion macros to reduce code from unused algorithms.
*
* Revision 1.10 1999/01/22 06:28:55 rgb
* Cruft clean-out.
* Put random IV generation in kernel.
* Added algorithm switch code.
* Enhanced debugging.
* 64-bit clean-up.
*
* Revision 1.9 1998/11/30 13:22:55 rgb
* Rationalised all the klips kernel file headers. They are much shorter
* now and won't conflict under RH5.2.
*
* Revision 1.8 1998/11/25 04:59:06 rgb
* Add conditionals for no IPIP tunnel code.
* Delete commented out code.
*
* Revision 1.7 1998/10/31 06:50:41 rgb
* Convert xform ASCII names to no spaces.
* Fixed up comments in #endif directives.
*
* Revision 1.6 1998/10/19 14:44:28 rgb
* Added inclusion of freeswan.h.
* sa_id structure implemented and used: now includes protocol.
*
* Revision 1.5 1998/10/09 04:32:19 rgb
* Added 'klips_debug' prefix to all klips printk debug statements.
*
* Revision 1.4 1998/08/12 00:11:31 rgb
* Added new xform functions to the xform table.
* Fixed minor debug output spelling error.
*
* Revision 1.3 1998/07/09 17:45:31 rgb
* Clarify algorithm not available message.
*
* Revision 1.2 1998/06/23 03:00:51 rgb
* Check for presence of IPIP protocol if it is setup one way (we don't
* know what has been set up the other way and can only assume it will be
* symmetrical with the exception of keys).
*
* Revision 1.1 1998/06/18 21:27:51 henry
* move sources from klips/src to klips/net/ipsec, to keep stupid
* kernel-build scripts happier in the presence of symlinks
*
* Revision 1.3 1998/06/11 05:54:59 rgb
* Added transform version string pointer to xformsw initialisations.
*
* Revision 1.2 1998/04/21 21:28:57 rgb
* Rearrange debug switches to change on the fly debug output from user
* space. Only kernel changes checked in at this time. radij.c was also
* changed to temporarily remove buggy debugging code in rj_delete causing
* an OOPS and hence, netlink device open errors.
*
* Revision 1.1 1998/04/09 03:06:13 henry
* sources moved up from linux/net/ipsec
*
* Revision 1.1.1.1 1998/04/08 05:35:02 henry
* RGB's ipsec-0.8pre2.tar.gz ipsec-0.8
*
* Revision 0.5 1997/06/03 04:24:48 ji
* Added ESP-3DES-MD5-96
*
* Revision 0.4 1997/01/15 01:28:15 ji
* Added new transforms.
*
* Revision 0.3 1996/11/20 14:39:04 ji
* Minor cleanups.
* Rationalized debugging code.
*
* Revision 0.2 1996/11/02 00:18:33 ji
* First limited release.
*
*
*/
|