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 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(C) 2023 Marvell.
*/
#include <stdio.h>
#include <inttypes.h>
#include <rte_ethdev.h>
#include <rte_malloc.h>
#include <rte_security.h>
#include "test.h"
#include "test_security_inline_macsec_vectors.h"
#ifdef RTE_EXEC_ENV_WINDOWS
static int
test_inline_macsec(void)
{
printf("Inline MACsec not supported on Windows, skipping test\n");
return TEST_SKIPPED;
}
#else
#define NB_ETHPORTS_USED 1
#define MEMPOOL_CACHE_SIZE 32
#define RTE_TEST_RX_DESC_DEFAULT 1024
#define RTE_TEST_TX_DESC_DEFAULT 1024
#define RTE_PORT_ALL (~(uint16_t)0x0)
#define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
#define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
#define RX_WTHRESH 0 /**< Default values of RX write-back threshold reg. */
#define TX_PTHRESH 32 /**< Default values of TX prefetch threshold reg. */
#define TX_HTHRESH 0 /**< Default values of TX host threshold reg. */
#define TX_WTHRESH 0 /**< Default values of TX write-back threshold reg. */
#define MAX_TRAFFIC_BURST 2048
#define NB_MBUF 10240
#define MCS_INVALID_SA 0xFFFF
#define MCS_DEFAULT_PN_THRESHOLD 0xFFFFF
static struct rte_mempool *mbufpool;
static struct rte_mempool *sess_pool;
/* ethernet addresses of ports */
static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
struct mcs_test_opts {
int val_frames;
int nb_td;
uint16_t mtu;
uint8_t sa_in_use;
bool encrypt;
bool protect_frames;
uint8_t sectag_insert_mode;
uint8_t nb_vlan;
uint32_t replay_win_sz;
uint8_t replay_protect;
uint8_t rekey_en;
const struct mcs_test_vector *rekey_td;
const struct mcs_test_vector *ar_td[3];
bool dump_all_stats;
uint8_t check_untagged_rx;
uint8_t check_bad_tag_cnt;
uint8_t check_sa_not_in_use;
uint8_t check_decap_stats;
uint8_t check_verify_only_stats;
uint8_t check_pkts_invalid_stats;
uint8_t check_pkts_unchecked_stats;
uint8_t check_out_pkts_untagged;
uint8_t check_out_pkts_toolong;
uint8_t check_encap_stats;
uint8_t check_auth_only_stats;
uint8_t check_sectag_interrupts;
};
static struct rte_eth_conf port_conf = {
.rxmode = {
.mq_mode = RTE_ETH_MQ_RX_NONE,
.offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM |
RTE_ETH_RX_OFFLOAD_MACSEC_STRIP,
},
.txmode = {
.mq_mode = RTE_ETH_MQ_TX_NONE,
.offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE |
RTE_ETH_TX_OFFLOAD_MACSEC_INSERT,
},
.lpbk_mode = 1, /* enable loopback */
};
static struct rte_eth_rxconf rx_conf = {
.rx_thresh = {
.pthresh = RX_PTHRESH,
.hthresh = RX_HTHRESH,
.wthresh = RX_WTHRESH,
},
.rx_free_thresh = 32,
};
static struct rte_eth_txconf tx_conf = {
.tx_thresh = {
.pthresh = TX_PTHRESH,
.hthresh = TX_HTHRESH,
.wthresh = TX_WTHRESH,
},
.tx_free_thresh = 32, /* Use PMD default values */
.tx_rs_thresh = 32, /* Use PMD default values */
};
static uint16_t port_id;
static uint64_t link_mbps;
static struct rte_flow *default_tx_flow[RTE_MAX_ETHPORTS];
static struct rte_flow *default_rx_flow[RTE_MAX_ETHPORTS];
static struct rte_mbuf **tx_pkts_burst;
static struct rte_mbuf **rx_pkts_burst;
static inline struct rte_mbuf *
init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len)
{
struct rte_mbuf *pkt;
pkt = rte_pktmbuf_alloc(mp);
if (pkt == NULL)
return NULL;
rte_memcpy(rte_pktmbuf_append(pkt, len), data, len);
return pkt;
}
static int
init_mempools(unsigned int nb_mbuf)
{
void *sec_ctx;
uint16_t nb_sess = 512;
uint32_t sess_sz;
char s[64];
if (mbufpool == NULL) {
snprintf(s, sizeof(s), "mbuf_pool");
mbufpool = rte_pktmbuf_pool_create(s, nb_mbuf,
MEMPOOL_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, SOCKET_ID_ANY);
if (mbufpool == NULL) {
printf("Cannot init mbuf pool\n");
return TEST_FAILED;
}
printf("Allocated mbuf pool\n");
}
sec_ctx = rte_eth_dev_get_sec_ctx(port_id);
if (sec_ctx == NULL) {
printf("Device does not support Security ctx\n");
return TEST_SKIPPED;
}
sess_sz = rte_security_session_get_size(sec_ctx);
if (sess_pool == NULL) {
snprintf(s, sizeof(s), "sess_pool");
sess_pool = rte_mempool_create(s, nb_sess, sess_sz,
MEMPOOL_CACHE_SIZE, 0,
NULL, NULL, NULL, NULL,
SOCKET_ID_ANY, 0);
if (sess_pool == NULL) {
printf("Cannot init sess pool\n");
return TEST_FAILED;
}
printf("Allocated sess pool\n");
}
return 0;
}
static void
fill_macsec_sa_conf(const struct mcs_test_vector *td, struct rte_security_macsec_sa *sa,
enum rte_security_macsec_direction dir, uint8_t an, uint8_t tci_off)
{
sa->dir = dir;
sa->key.data = td->sa_key.data;
sa->key.length = td->sa_key.len;
memcpy((uint8_t *)sa->salt, (const uint8_t *)td->salt, RTE_SECURITY_MACSEC_SALT_LEN);
/* AN is set as per the value in secure packet in test vector */
sa->an = an & RTE_MACSEC_AN_MASK;
sa->ssci = td->ssci;
sa->xpn = td->xpn;
/* Starting packet number which is expected to come next.
* It is take from the test vector so that we can match the out packet.
*/
sa->next_pn = *(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]);
}
static void
fill_macsec_sc_conf(const struct mcs_test_vector *td,
struct rte_security_macsec_sc *sc_conf,
const struct mcs_test_opts *opts,
enum rte_security_macsec_direction dir,
uint16_t sa_id[], uint8_t tci_off)
{
uint8_t i;
sc_conf->dir = dir;
sc_conf->pn_threshold = ((uint64_t)td->xpn << 32) |
rte_be_to_cpu_32(*(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]));
if (dir == RTE_SECURITY_MACSEC_DIR_TX) {
sc_conf->sc_tx.sa_id = sa_id[0];
if (sa_id[1] != MCS_INVALID_SA) {
sc_conf->sc_tx.sa_id_rekey = sa_id[1];
sc_conf->sc_tx.re_key_en = 1;
}
sc_conf->sc_tx.active = 1;
/* is SCI valid */
if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) {
memcpy(&sc_conf->sc_tx.sci, &td->secure_pkt.data[tci_off + 6],
sizeof(sc_conf->sc_tx.sci));
sc_conf->sc_tx.sci = rte_be_to_cpu_64(sc_conf->sc_tx.sci);
} else if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) {
/* sci = source_mac + port_id when ES.bit = 1 & SC.bit = 0 */
const uint8_t *smac = td->plain_pkt.data + RTE_ETHER_ADDR_LEN;
uint8_t *ptr = (uint8_t *)&sc_conf->sc_tx.sci;
ptr[0] = 0x01;
ptr[1] = 0;
for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
ptr[2 + i] = smac[RTE_ETHER_ADDR_LEN - 1 - i];
} else {
/* use some default SCI */
sc_conf->sc_tx.sci = 0xf1341e023a2b1c5d;
}
if (td->xpn > 0)
sc_conf->sc_tx.is_xpn = 1;
} else {
for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
sc_conf->sc_rx.sa_id[i] = sa_id[i];
sc_conf->sc_rx.sa_in_use[i] = opts->sa_in_use;
}
sc_conf->sc_rx.active = 1;
if (td->xpn > 0)
sc_conf->sc_rx.is_xpn = 1;
}
}
/* Create Inline MACsec session */
static int
fill_session_conf(const struct mcs_test_vector *td, uint16_t portid __rte_unused,
const struct mcs_test_opts *opts,
struct rte_security_session_conf *sess_conf,
enum rte_security_macsec_direction dir,
uint16_t sc_id,
uint8_t tci_off)
{
sess_conf->action_type = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL;
sess_conf->protocol = RTE_SECURITY_PROTOCOL_MACSEC;
sess_conf->macsec.dir = dir;
sess_conf->macsec.alg = td->alg;
sess_conf->macsec.cipher_off = 0;
if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) {
sess_conf->macsec.sci = rte_be_to_cpu_64(*(const uint64_t *)
(&td->secure_pkt.data[tci_off + 6]));
} else if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) {
/* sci = source_mac + port_id when ES.bit = 1 & SC.bit = 0 */
const uint8_t *smac = td->plain_pkt.data + RTE_ETHER_ADDR_LEN;
uint8_t *ptr = (uint8_t *)&sess_conf->macsec.sci;
uint8_t j;
ptr[0] = 0x01;
ptr[1] = 0;
for (j = 0; j < RTE_ETHER_ADDR_LEN; j++)
ptr[2 + j] = smac[RTE_ETHER_ADDR_LEN - 1 - j];
}
sess_conf->macsec.sc_id = sc_id;
if (dir == RTE_SECURITY_MACSEC_DIR_TX) {
sess_conf->macsec.tx_secy.mtu = opts->mtu;
sess_conf->macsec.tx_secy.sectag_off = (opts->sectag_insert_mode == 1) ?
2 * RTE_ETHER_ADDR_LEN :
RTE_VLAN_HLEN;
sess_conf->macsec.tx_secy.sectag_insert_mode = opts->sectag_insert_mode;
sess_conf->macsec.tx_secy.ctrl_port_enable = 1;
sess_conf->macsec.tx_secy.sectag_version = 0;
sess_conf->macsec.tx_secy.end_station =
(td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) >> 6;
sess_conf->macsec.tx_secy.send_sci =
(td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) >> 5;
sess_conf->macsec.tx_secy.scb =
(td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SCB) >> 4;
sess_conf->macsec.tx_secy.encrypt = opts->encrypt;
sess_conf->macsec.tx_secy.protect_frames = opts->protect_frames;
sess_conf->macsec.tx_secy.icv_include_da_sa = 1;
} else {
sess_conf->macsec.rx_secy.replay_win_sz = opts->replay_win_sz;
sess_conf->macsec.rx_secy.replay_protect = opts->replay_protect;
sess_conf->macsec.rx_secy.icv_include_da_sa = 1;
sess_conf->macsec.rx_secy.ctrl_port_enable = 1;
sess_conf->macsec.rx_secy.preserve_sectag = 0;
sess_conf->macsec.rx_secy.preserve_icv = 0;
sess_conf->macsec.rx_secy.validate_frames = opts->val_frames;
}
return 0;
}
static int
create_default_flow(const struct mcs_test_vector *td, uint16_t portid,
enum rte_security_macsec_direction dir, void *sess)
{
struct rte_flow_action action[2];
struct rte_flow_item pattern[2];
struct rte_flow_attr attr = {0};
struct rte_flow_error err;
struct rte_flow *flow;
struct rte_flow_item_eth eth = { .hdr.ether_type = 0, };
static const struct rte_flow_item_eth eth_mask = {
.hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
.hdr.ether_type = RTE_BE16(0x0000),
};
int ret;
eth.has_vlan = 0;
if (dir == RTE_SECURITY_MACSEC_DIR_TX)
memcpy(ð.hdr, td->plain_pkt.data, RTE_ETHER_HDR_LEN);
else
memcpy(ð.hdr, td->secure_pkt.data, RTE_ETHER_HDR_LEN);
pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
pattern[0].spec = ð
pattern[0].mask = ð_mask;
pattern[0].last = NULL;
pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
action[0].type = RTE_FLOW_ACTION_TYPE_SECURITY;
action[0].conf = sess;
action[1].type = RTE_FLOW_ACTION_TYPE_END;
action[1].conf = NULL;
attr.ingress = (dir == RTE_SECURITY_MACSEC_DIR_RX) ? 1 : 0;
attr.egress = (dir == RTE_SECURITY_MACSEC_DIR_TX) ? 1 : 0;
ret = rte_flow_validate(portid, &attr, pattern, action, &err);
if (ret) {
printf("\nValidate flow failed, ret = %d\n", ret);
return -1;
}
flow = rte_flow_create(portid, &attr, pattern, action, &err);
if (flow == NULL) {
printf("\nDefault flow rule create failed\n");
return -1;
}
if (dir == RTE_SECURITY_MACSEC_DIR_TX)
default_tx_flow[portid] = flow;
else
default_rx_flow[portid] = flow;
return 0;
}
static void
destroy_default_flow(uint16_t portid)
{
struct rte_flow_error err;
int ret;
if (default_tx_flow[portid]) {
ret = rte_flow_destroy(portid, default_tx_flow[portid], &err);
if (ret) {
printf("\nDefault Tx flow rule destroy failed\n");
return;
}
default_tx_flow[portid] = NULL;
}
if (default_rx_flow[portid]) {
ret = rte_flow_destroy(portid, default_rx_flow[portid], &err);
if (ret) {
printf("\nDefault Rx flow rule destroy failed\n");
return;
}
default_rx_flow[portid] = NULL;
}
}
static void
print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
{
char buf[RTE_ETHER_ADDR_FMT_SIZE];
rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
printf("%s%s", name, buf);
}
/* Check the link status of all ports in up to 3s, and print them finally */
static void
check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
{
#define CHECK_INTERVAL 100 /* 100ms */
#define MAX_CHECK_TIME 30 /* 3s (30 * 100ms) in total */
uint16_t portid;
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
char link_status[RTE_ETH_LINK_MAX_STR_LEN];
printf("Checking link statuses...\n");
fflush(stdout);
for (count = 0; count <= MAX_CHECK_TIME; count++) {
all_ports_up = 1;
for (portid = 0; portid < port_num; portid++) {
if ((port_mask & (1 << portid)) == 0)
continue;
memset(&link, 0, sizeof(link));
ret = rte_eth_link_get_nowait(portid, &link);
if (ret < 0) {
all_ports_up = 0;
if (print_flag == 1)
printf("Port %u link get failed: %s\n",
portid, rte_strerror(-ret));
continue;
}
/* print link status if flag set */
if (print_flag == 1) {
if (link.link_status && link_mbps == 0)
link_mbps = link.link_speed;
rte_eth_link_to_str(link_status,
sizeof(link_status), &link);
printf("Port %d %s\n", portid, link_status);
continue;
}
/* clear all_ports_up flag if any link down */
if (link.link_status == RTE_ETH_LINK_DOWN) {
all_ports_up = 0;
break;
}
}
/* after finally printing all link status, get out */
if (print_flag == 1)
break;
if (all_ports_up == 0)
fflush(stdout);
/* set the print_flag if all ports up or timeout */
if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1))
print_flag = 1;
}
}
static int
test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td,
enum mcs_op op, uint8_t check_out_pkts_untagged)
{
const uint8_t *dptr;
uint16_t pkt_len;
if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY ||
check_out_pkts_untagged == 1) {
dptr = td->plain_pkt.data;
pkt_len = td->plain_pkt.len;
} else {
dptr = td->secure_pkt.data;
pkt_len = td->secure_pkt.len;
}
if (memcmp(rte_pktmbuf_mtod(m, uint8_t *), dptr, pkt_len)) {
printf("\nData comparison failed for td.");
rte_pktmbuf_dump(stdout, m, m->pkt_len);
rte_hexdump(stdout, "expected_data", dptr, pkt_len);
return TEST_FAILED;
}
return TEST_SUCCESS;
}
static void
mcs_stats_dump(void *ctx, enum mcs_op op,
void *rx_sess, void *tx_sess,
uint8_t rx_sc_id, uint8_t tx_sc_id,
uint16_t rx_sa_id[], uint16_t tx_sa_id[])
{
struct rte_security_stats sess_stats = {0};
struct rte_security_macsec_secy_stats *secy_stat;
struct rte_security_macsec_sc_stats sc_stat = {0};
struct rte_security_macsec_sa_stats sa_stat = {0};
int i;
if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
printf("\n********* RX SECY STATS ************\n");
rte_security_session_stats_get(ctx, rx_sess, &sess_stats);
secy_stat = &sess_stats.macsec;
if (secy_stat->ctl_pkt_bcast_cnt)
printf("RX: ctl_pkt_bcast_cnt: 0x%" PRIx64 "\n",
secy_stat->ctl_pkt_bcast_cnt);
if (secy_stat->ctl_pkt_mcast_cnt)
printf("RX: ctl_pkt_mcast_cnt: 0x%" PRIx64 "\n",
secy_stat->ctl_pkt_mcast_cnt);
if (secy_stat->ctl_pkt_ucast_cnt)
printf("RX: ctl_pkt_ucast_cnt: 0x%" PRIx64 "\n",
secy_stat->ctl_pkt_ucast_cnt);
if (secy_stat->ctl_octet_cnt)
printf("RX: ctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->ctl_octet_cnt);
if (secy_stat->unctl_pkt_bcast_cnt)
printf("RX: unctl_pkt_bcast_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_pkt_bcast_cnt);
if (secy_stat->unctl_pkt_mcast_cnt)
printf("RX: unctl_pkt_mcast_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_pkt_mcast_cnt);
if (secy_stat->unctl_pkt_ucast_cnt)
printf("RX: unctl_pkt_ucast_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_pkt_ucast_cnt);
if (secy_stat->unctl_octet_cnt)
printf("RX: unctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->unctl_octet_cnt);
/* Valid only for RX */
if (secy_stat->octet_decrypted_cnt)
printf("RX: octet_decrypted_cnt: 0x%" PRIx64 "\n",
secy_stat->octet_decrypted_cnt);
if (secy_stat->octet_validated_cnt)
printf("RX: octet_validated_cnt: 0x%" PRIx64 "\n",
secy_stat->octet_validated_cnt);
if (secy_stat->pkt_port_disabled_cnt)
printf("RX: pkt_port_disabled_cnt: 0x%" PRIx64 "\n",
secy_stat->pkt_port_disabled_cnt);
if (secy_stat->pkt_badtag_cnt)
printf("RX: pkt_badtag_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_badtag_cnt);
if (secy_stat->pkt_nosa_cnt)
printf("RX: pkt_nosa_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_nosa_cnt);
if (secy_stat->pkt_nosaerror_cnt)
printf("RX: pkt_nosaerror_cnt: 0x%" PRIx64 "\n",
secy_stat->pkt_nosaerror_cnt);
if (secy_stat->pkt_tagged_ctl_cnt)
printf("RX: pkt_tagged_ctl_cnt: 0x%" PRIx64 "\n",
secy_stat->pkt_tagged_ctl_cnt);
if (secy_stat->pkt_untaged_cnt)
printf("RX: pkt_untaged_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_untaged_cnt);
if (secy_stat->pkt_ctl_cnt)
printf("RX: pkt_ctl_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_ctl_cnt);
if (secy_stat->pkt_notag_cnt)
printf("RX: pkt_notag_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_notag_cnt);
printf("\n");
printf("\n********** RX SC[%u] STATS **************\n", rx_sc_id);
rte_security_macsec_sc_stats_get(ctx, rx_sc_id, RTE_SECURITY_MACSEC_DIR_RX,
&sc_stat);
/* RX */
if (sc_stat.hit_cnt)
printf("RX hit_cnt: 0x%" PRIx64 "\n", sc_stat.hit_cnt);
if (sc_stat.pkt_invalid_cnt)
printf("RX pkt_invalid_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_invalid_cnt);
if (sc_stat.pkt_late_cnt)
printf("RX pkt_late_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_late_cnt);
if (sc_stat.pkt_notvalid_cnt)
printf("RX pkt_notvalid_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_notvalid_cnt);
if (sc_stat.pkt_unchecked_cnt)
printf("RX pkt_unchecked_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_unchecked_cnt);
if (sc_stat.pkt_delay_cnt)
printf("RX pkt_delay_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_delay_cnt);
if (sc_stat.pkt_ok_cnt)
printf("RX pkt_ok_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_ok_cnt);
if (sc_stat.octet_decrypt_cnt)
printf("RX octet_decrypt_cnt: 0x%" PRIx64 "\n", sc_stat.octet_decrypt_cnt);
if (sc_stat.octet_validate_cnt)
printf("RX octet_validate_cnt: 0x%" PRIx64 "\n",
sc_stat.octet_validate_cnt);
printf("\n");
for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
printf("\n********** RX SA[%u] STATS ****************\n", rx_sa_id[i]);
memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
RTE_SECURITY_MACSEC_DIR_RX, &sa_stat);
/* RX */
if (sa_stat.pkt_invalid_cnt)
printf("RX pkt_invalid_cnt: 0x%" PRIx64 "\n",
sa_stat.pkt_invalid_cnt);
if (sa_stat.pkt_nosaerror_cnt)
printf("RX pkt_nosaerror_cnt: 0x%" PRIx64 "\n",
sa_stat.pkt_nosaerror_cnt);
if (sa_stat.pkt_notvalid_cnt)
printf("RX pkt_notvalid_cnt: 0x%" PRIx64 "\n",
sa_stat.pkt_notvalid_cnt);
if (sa_stat.pkt_ok_cnt)
printf("RX pkt_ok_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_ok_cnt);
if (sa_stat.pkt_nosa_cnt)
printf("RX pkt_nosa_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_nosa_cnt);
printf("\n");
}
}
if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
memset(&sess_stats, 0, sizeof(struct rte_security_stats));
rte_security_session_stats_get(ctx, tx_sess, &sess_stats);
secy_stat = &sess_stats.macsec;
printf("\n********* TX SECY STATS ************\n");
if (secy_stat->ctl_pkt_bcast_cnt)
printf("TX: ctl_pkt_bcast_cnt: 0x%" PRIx64 "\n",
secy_stat->ctl_pkt_bcast_cnt);
if (secy_stat->ctl_pkt_mcast_cnt)
printf("TX: ctl_pkt_mcast_cnt: 0x%" PRIx64 "\n",
secy_stat->ctl_pkt_mcast_cnt);
if (secy_stat->ctl_pkt_ucast_cnt)
printf("TX: ctl_pkt_ucast_cnt: 0x%" PRIx64 "\n",
secy_stat->ctl_pkt_ucast_cnt);
if (secy_stat->ctl_octet_cnt)
printf("TX: ctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->ctl_octet_cnt);
if (secy_stat->unctl_pkt_bcast_cnt)
printf("TX: unctl_pkt_bcast_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_pkt_bcast_cnt);
if (secy_stat->unctl_pkt_mcast_cnt)
printf("TX: unctl_pkt_mcast_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_pkt_mcast_cnt);
if (secy_stat->unctl_pkt_ucast_cnt)
printf("TX: unctl_pkt_ucast_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_pkt_ucast_cnt);
if (secy_stat->unctl_octet_cnt)
printf("TX: unctl_octet_cnt: 0x%" PRIx64 "\n",
secy_stat->unctl_octet_cnt);
/* Valid only for TX */
if (secy_stat->octet_encrypted_cnt)
printf("TX: octet_encrypted_cnt: 0x%" PRIx64 "\n",
secy_stat->octet_encrypted_cnt);
if (secy_stat->octet_protected_cnt)
printf("TX: octet_protected_cnt: 0x%" PRIx64 "\n",
secy_stat->octet_protected_cnt);
if (secy_stat->pkt_noactivesa_cnt)
printf("TX: pkt_noactivesa_cnt: 0x%" PRIx64 "\n",
secy_stat->pkt_noactivesa_cnt);
if (secy_stat->pkt_toolong_cnt)
printf("TX: pkt_toolong_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_toolong_cnt);
if (secy_stat->pkt_untagged_cnt)
printf("TX: pkt_untagged_cnt: 0x%" PRIx64 "\n",
secy_stat->pkt_untagged_cnt);
memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats));
rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX,
&sc_stat);
printf("\n********** TX SC[%u] STATS **************\n", tx_sc_id);
if (sc_stat.pkt_encrypt_cnt)
printf("TX pkt_encrypt_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_encrypt_cnt);
if (sc_stat.pkt_protected_cnt)
printf("TX pkt_protected_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_protected_cnt);
if (sc_stat.octet_encrypt_cnt)
printf("TX octet_encrypt_cnt: 0x%" PRIx64 "\n", sc_stat.octet_encrypt_cnt);
memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0],
RTE_SECURITY_MACSEC_DIR_TX, &sa_stat);
printf("\n********** TX SA[%u] STATS ****************\n", tx_sa_id[0]);
if (sa_stat.pkt_encrypt_cnt)
printf("TX pkt_encrypt_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_encrypt_cnt);
if (sa_stat.pkt_protected_cnt)
printf("TX pkt_protected_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_protected_cnt);
}
}
static int
mcs_stats_check(void *ctx, enum mcs_op op,
const struct mcs_test_opts *opts,
const struct mcs_test_vector *td,
void *rx_sess, void *tx_sess,
uint8_t rx_sc_id, uint8_t tx_sc_id,
uint16_t rx_sa_id[], uint16_t tx_sa_id[])
{
struct rte_security_stats sess_stats = {0};
struct rte_security_macsec_secy_stats *secy_stat;
struct rte_security_macsec_sc_stats sc_stat = {0};
struct rte_security_macsec_sa_stats sa_stat = {0};
int i;
if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
rte_security_session_stats_get(ctx, rx_sess, &sess_stats);
secy_stat = &sess_stats.macsec;
if ((opts->check_untagged_rx && secy_stat->pkt_notag_cnt != 1) ||
(opts->check_untagged_rx && secy_stat->pkt_untaged_cnt != 1))
return TEST_FAILED;
if (opts->check_bad_tag_cnt && secy_stat->pkt_badtag_cnt != 1)
return TEST_FAILED;
if (opts->check_sa_not_in_use && secy_stat->pkt_nosaerror_cnt != 1)
return TEST_FAILED;
if (opts->check_decap_stats && secy_stat->octet_decrypted_cnt !=
(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
return TEST_FAILED;
if (opts->check_verify_only_stats && secy_stat->octet_validated_cnt !=
(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
return TEST_FAILED;
rte_security_macsec_sc_stats_get(ctx, rx_sc_id,
RTE_SECURITY_MACSEC_DIR_RX, &sc_stat);
if ((opts->check_decap_stats || opts->check_verify_only_stats) &&
sc_stat.pkt_ok_cnt != 1)
return TEST_FAILED;
if (opts->check_pkts_invalid_stats && sc_stat.pkt_notvalid_cnt != 1)
return TEST_FAILED;
if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
return TEST_FAILED;
if (opts->replay_protect) {
if (opts->replay_win_sz == 0 &&
sc_stat.pkt_late_cnt != 2)
return TEST_FAILED;
else if (opts->replay_win_sz == 32 &&
sc_stat.pkt_late_cnt != 1)
return TEST_FAILED;
}
for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
RTE_SECURITY_MACSEC_DIR_RX, &sa_stat);
}
}
if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
memset(&sess_stats, 0, sizeof(struct rte_security_stats));
rte_security_session_stats_get(ctx, tx_sess, &sess_stats);
secy_stat = &sess_stats.macsec;
if (opts->check_out_pkts_untagged && secy_stat->pkt_untagged_cnt != 1)
return TEST_FAILED;
if (opts->check_out_pkts_toolong && secy_stat->pkt_toolong_cnt != 1)
return TEST_FAILED;
if (opts->check_encap_stats && secy_stat->octet_encrypted_cnt !=
(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
return TEST_FAILED;
if (opts->check_auth_only_stats && secy_stat->octet_protected_cnt !=
(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
return TEST_FAILED;
memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats));
rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX,
&sc_stat);
if (opts->check_encap_stats && sc_stat.pkt_encrypt_cnt != 1)
return TEST_FAILED;
if (opts->check_auth_only_stats && sc_stat.pkt_protected_cnt != 1)
return TEST_FAILED;
memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0],
RTE_SECURITY_MACSEC_DIR_TX, &sa_stat);
}
return 0;
}
static int
test_macsec_event_callback(uint16_t port_id, enum rte_eth_event_type type,
void *param, void *ret_param)
{
struct mcs_err_vector *vector = (struct mcs_err_vector *)param;
struct rte_eth_event_macsec_desc *event_desc = NULL;
RTE_SET_USED(port_id);
if (type != RTE_ETH_EVENT_MACSEC)
return -1;
event_desc = ret_param;
if (event_desc == NULL) {
printf("Event descriptor not set\n");
return -1;
}
vector->notify_event = true;
switch (event_desc->type) {
case RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR:
vector->event = RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR;
switch (event_desc->subtype) {
case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1:
vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1;
break;
case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1:
vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1;
break;
case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48:
vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48;
break;
case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1:
vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1;
break;
case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1:
vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1;
break;
default:
printf("\nUnknown Macsec event subtype: %d", event_desc->subtype);
}
break;
case RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP:
vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP;
break;
case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP;
break;
case RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP:
vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP;
break;
case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP;
break;
case RTE_ETH_EVENT_MACSEC_SA_NOT_VALID:
vector->event = RTE_ETH_EVENT_MACSEC_SA_NOT_VALID;
break;
default:
printf("Invalid MACsec event reported\n");
return -1;
}
return 0;
}
static int
test_macsec_sec_caps_verify(const struct mcs_test_opts *opts,
const struct rte_security_capability *sec_cap, bool silent)
{
if (opts->mtu > sec_cap->macsec.mtu) {
if (!silent)
RTE_LOG(INFO, USER1, "MTU size is not supported\n");
return -ENOTSUP;
}
if (opts->replay_protect == 1 && sec_cap->macsec.anti_replay == 0) {
if (!silent)
RTE_LOG(INFO, USER1, "Anti replay is not supported\n");
return -ENOTSUP;
}
if (opts->replay_win_sz > sec_cap->macsec.replay_win_sz) {
if (!silent)
RTE_LOG(INFO, USER1, "Replay window size is not "
"supported\n");
return -ENOTSUP;
}
if (opts->rekey_en == 1 && sec_cap->macsec.re_key == 0) {
if (!silent)
RTE_LOG(INFO, USER1, "Rekey is not supported\n");
return -ENOTSUP;
}
if (opts->sectag_insert_mode == 0 &&
sec_cap->macsec.relative_sectag_insert == 0) {
if (!silent)
RTE_LOG(INFO, USER1, "Relative offset sectag insert "
"not supported\n");
return -ENOTSUP;
}
if (opts->sectag_insert_mode == 1 &&
sec_cap->macsec.fixed_sectag_insert == 0) {
if (!silent)
RTE_LOG(INFO, USER1, "Fixed offset sectag insert "
"not supported\n");
return -ENOTSUP;
}
return 0;
}
static int
test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
{
uint16_t rx_sa_id[MCS_MAX_FLOWS][RTE_SECURITY_MACSEC_NUM_AN] = {{0}};
struct rte_security_capability_idx sec_cap_idx;
const struct rte_security_capability *sec_cap;
uint16_t tx_sa_id[MCS_MAX_FLOWS][2] = {{0}};
uint16_t rx_sc_id[MCS_MAX_FLOWS] = {0};
uint16_t tx_sc_id[MCS_MAX_FLOWS] = {0};
void *rx_sess[MCS_MAX_FLOWS] = {0};
void *tx_sess[MCS_MAX_FLOWS] = {0};
struct rte_security_session_conf sess_conf = {0};
struct rte_security_macsec_sa sa_conf = {0};
struct rte_security_macsec_sc sc_conf = {0};
struct mcs_err_vector err_vector = {0};
void *ctx;
int nb_rx = 0, nb_sent;
int i, j = 0, ret, id, an = 0;
uint8_t tci_off;
int k;
memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * opts->nb_td);
ctx = rte_eth_dev_get_sec_ctx(port_id);
if (ctx == NULL) {
printf("Ethernet device doesn't support security features.\n");
return TEST_SKIPPED;
}
sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL;
sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_MACSEC;
sec_cap_idx.macsec.alg = td[0]->alg;
sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
if (sec_cap == NULL) {
printf("No capabilities registered\n");
return TEST_SKIPPED;
}
if (test_macsec_sec_caps_verify(opts, sec_cap, false) != 0)
return TEST_SKIPPED;
if (opts->rekey_en) {
/* Verify the rekey td */
sec_cap_idx.macsec.alg = opts->rekey_td->alg;
sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
if (sec_cap == NULL) {
printf("No capabilities registered\n");
return TEST_SKIPPED;
}
if (test_macsec_sec_caps_verify(opts, sec_cap, false) != 0)
return TEST_SKIPPED;
}
tci_off = (opts->sectag_insert_mode == 1) ? RTE_ETHER_HDR_LEN :
RTE_ETHER_HDR_LEN + (opts->nb_vlan * RTE_VLAN_HLEN);
for (i = 0, j = 0; i < opts->nb_td; i++) {
if (op == MCS_DECAP || op == MCS_VERIFY_ONLY)
tx_pkts_burst[j] = init_packet(mbufpool, td[i]->secure_pkt.data,
td[i]->secure_pkt.len);
else {
tx_pkts_burst[j] = init_packet(mbufpool, td[i]->plain_pkt.data,
td[i]->plain_pkt.len);
tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC;
}
if (tx_pkts_burst[j] == NULL) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
j++;
if (opts->replay_protect) {
for (k = 0; k < 3; k++, j++) {
tx_pkts_burst[j] = init_packet(mbufpool,
opts->ar_td[k]->secure_pkt.data,
opts->ar_td[k]->secure_pkt.len);
if (tx_pkts_burst[j] == NULL) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
}
}
if (opts->rekey_en) {
err_vector.td = td[i];
err_vector.rekey_td = opts->rekey_td;
err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
test_macsec_event_callback, &err_vector);
if (op == MCS_DECAP || op == MCS_VERIFY_ONLY)
tx_pkts_burst[j] = init_packet(mbufpool,
opts->rekey_td->secure_pkt.data,
opts->rekey_td->secure_pkt.len);
else {
tx_pkts_burst[j] = init_packet(mbufpool,
opts->rekey_td->plain_pkt.data,
opts->rekey_td->plain_pkt.len);
tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC;
}
if (tx_pkts_burst[j] == NULL) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
j++;
}
if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
if (opts->rekey_en && an ==
(opts->rekey_td->secure_pkt.data[tci_off] &
RTE_MACSEC_AN_MASK))
fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
else
/* For simplicity, using same SA conf for all AN */
fill_macsec_sa_conf(td[i], &sa_conf,
RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
id = rte_security_macsec_sa_create(ctx, &sa_conf);
if (id < 0) {
printf("MACsec SA create failed : %d.\n", id);
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
rx_sa_id[i][an] = (uint16_t)id;
}
fill_macsec_sc_conf(td[i], &sc_conf, opts,
RTE_SECURITY_MACSEC_DIR_RX, rx_sa_id[i], tci_off);
id = rte_security_macsec_sc_create(ctx, &sc_conf);
if (id < 0) {
printf("MACsec SC create failed : %d.\n", id);
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
rx_sc_id[i] = (uint16_t)id;
/* Create Inline IPsec session. */
ret = fill_session_conf(td[i], port_id, opts, &sess_conf,
RTE_SECURITY_MACSEC_DIR_RX, rx_sc_id[i], tci_off);
if (ret) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
rx_sess[i] = rte_security_session_create(ctx, &sess_conf,
sess_pool);
if (rx_sess[i] == NULL) {
printf("SEC Session init failed.\n");
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
ret = create_default_flow(td[i], port_id,
RTE_SECURITY_MACSEC_DIR_RX, rx_sess[i]);
if (ret) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
}
if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
int id;
fill_macsec_sa_conf(td[i], &sa_conf,
RTE_SECURITY_MACSEC_DIR_TX,
td[i]->secure_pkt.data[tci_off] & RTE_MACSEC_AN_MASK,
tci_off);
id = rte_security_macsec_sa_create(ctx, &sa_conf);
if (id < 0) {
printf("MACsec SA create failed : %d.\n", id);
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
tx_sa_id[i][0] = (uint16_t)id;
tx_sa_id[i][1] = MCS_INVALID_SA;
if (opts->rekey_en) {
memset(&sa_conf, 0, sizeof(struct rte_security_macsec_sa));
fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
RTE_SECURITY_MACSEC_DIR_TX,
opts->rekey_td->secure_pkt.data[tci_off] &
RTE_MACSEC_AN_MASK,
tci_off);
id = rte_security_macsec_sa_create(ctx, &sa_conf);
if (id < 0) {
printf("MACsec rekey SA create failed : %d.\n", id);
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
tx_sa_id[i][1] = (uint16_t)id;
}
fill_macsec_sc_conf(td[i], &sc_conf, opts,
RTE_SECURITY_MACSEC_DIR_TX, tx_sa_id[i], tci_off);
id = rte_security_macsec_sc_create(ctx, &sc_conf);
if (id < 0) {
printf("MACsec SC create failed : %d.\n", id);
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
tx_sc_id[i] = (uint16_t)id;
/* Create Inline IPsec session. */
ret = fill_session_conf(td[i], port_id, opts, &sess_conf,
RTE_SECURITY_MACSEC_DIR_TX, tx_sc_id[i], tci_off);
if (ret) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
tx_sess[i] = rte_security_session_create(ctx, &sess_conf,
sess_pool);
if (tx_sess[i] == NULL) {
printf("SEC Session init failed.\n");
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
ret = create_default_flow(td[i], port_id,
RTE_SECURITY_MACSEC_DIR_TX, tx_sess[i]);
if (ret) {
rte_pktmbuf_free_bulk(tx_pkts_burst, j);
ret = TEST_FAILED;
goto out;
}
}
}
/* Send packet to ethdev for inline MACsec processing. */
nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, j);
if (nb_sent != j) {
printf("\nUnable to TX %d packets, sent: %i", j, nb_sent);
for ( ; nb_sent < j; nb_sent++)
rte_pktmbuf_free(tx_pkts_burst[nb_sent]);
ret = TEST_FAILED;
goto out;
}
rte_pause();
j = 0;
/* Receive back packet on loopback interface. */
do {
nb_rx += rte_eth_rx_burst(port_id, 0,
&rx_pkts_burst[nb_rx],
nb_sent - nb_rx);
if (nb_rx >= nb_sent)
break;
rte_delay_ms(1);
} while (j++ < 5 && nb_rx == 0);
if (nb_rx != nb_sent) {
printf("\nUnable to RX all %d packets, received(%i)",
nb_sent, nb_rx);
rte_pktmbuf_free_bulk(rx_pkts_burst, nb_rx);
ret = TEST_FAILED;
if (opts->check_sectag_interrupts == 1)
ret = TEST_SUCCESS;
goto out;
}
if (opts->rekey_en) {
switch (err_vector.event) {
case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
printf("Received RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP event\n");
/* The first sa is active now, so the 0th sa can be
* reconfigured. Using the same key as zeroeth sa, but
* other key can also be configured.
*/
rte_security_macsec_sa_destroy(ctx, tx_sa_id[0][0],
RTE_SECURITY_MACSEC_DIR_TX);
fill_macsec_sa_conf(td[0], &sa_conf,
RTE_SECURITY_MACSEC_DIR_TX,
td[0]->secure_pkt.data[tci_off] &
RTE_MACSEC_AN_MASK, tci_off);
id = rte_security_macsec_sa_create(ctx, &sa_conf);
if (id < 0) {
printf("MACsec SA create failed : %d.\n", id);
rte_pktmbuf_free_bulk(rx_pkts_burst, nb_rx);
ret = TEST_FAILED;
goto out;
}
tx_sa_id[0][0] = (uint16_t)id;
break;
case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
printf("Received RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP event\n");
break;
default:
printf("Received unsupported event\n");
}
}
if (opts->replay_protect) {
for (i = 0; i < nb_rx; i++) {
rte_pktmbuf_free(rx_pkts_burst[i]);
rx_pkts_burst[i] = NULL;
}
ret = TEST_SUCCESS;
goto out;
}
for (i = 0; i < nb_rx; i++) {
if (opts->rekey_en && i == 1) {
/* The second received packet is matched with
* rekey td
*/
ret = test_macsec_post_process(rx_pkts_burst[i],
opts->rekey_td, op,
opts->check_out_pkts_untagged);
} else {
ret = test_macsec_post_process(rx_pkts_burst[i], td[i],
op, opts->check_out_pkts_untagged);
}
if (ret != TEST_SUCCESS) {
for ( ; i < nb_rx; i++)
rte_pktmbuf_free(rx_pkts_burst[i]);
goto out;
}
rte_pktmbuf_free(rx_pkts_burst[i]);
rx_pkts_burst[i] = NULL;
}
out:
if (opts->check_out_pkts_toolong == 1 ||
opts->check_sa_not_in_use == 1 ||
opts->check_bad_tag_cnt == 1)
ret = TEST_SUCCESS;
for (i = 0; i < opts->nb_td; i++) {
if (opts->dump_all_stats) {
mcs_stats_dump(ctx, op,
rx_sess[i], tx_sess[i],
rx_sc_id[i], tx_sc_id[i],
rx_sa_id[i], tx_sa_id[i]);
} else {
if (ret == TEST_SUCCESS)
ret = mcs_stats_check(ctx, op, opts, td[i],
rx_sess[i], tx_sess[i],
rx_sc_id[i], tx_sc_id[i],
rx_sa_id[i], tx_sa_id[i]);
}
}
destroy_default_flow(port_id);
if (opts->rekey_en)
rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
test_macsec_event_callback, &err_vector);
/* Destroy session so that other cases can create the session again */
for (i = 0; i < opts->nb_td; i++) {
if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
rte_security_session_destroy(ctx, tx_sess[i]);
tx_sess[i] = NULL;
rte_security_macsec_sc_destroy(ctx, tx_sc_id[i],
RTE_SECURITY_MACSEC_DIR_TX);
rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][0],
RTE_SECURITY_MACSEC_DIR_TX);
if (opts->rekey_en) {
rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][1],
RTE_SECURITY_MACSEC_DIR_TX);
}
}
if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
rte_security_session_destroy(ctx, rx_sess[i]);
rx_sess[i] = NULL;
rte_security_macsec_sc_destroy(ctx, rx_sc_id[i],
RTE_SECURITY_MACSEC_DIR_RX);
for (j = 0; j < RTE_SECURITY_MACSEC_NUM_AN; j++) {
rte_security_macsec_sa_destroy(ctx, rx_sa_id[i][j],
RTE_SECURITY_MACSEC_DIR_RX);
}
}
}
return ret;
}
static int
test_inline_macsec_encap_all(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.encrypt = true;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
if (err == TEST_SKIPPED) {
printf("Cipher Auth Encryption case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nCipher Auth Encryption case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nCipher Auth Encryption case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_decap_all(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Cipher Auth Decryption case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nCipher Auth Decryption case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nCipher Auth Decryption case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_auth_only_all(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
if (err == TEST_SKIPPED) {
printf("Auth Generate case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nAuth Generate case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nAuth Generate case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_verify_only_all(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
if (err == TEST_SKIPPED) {
printf("Auth Verify case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nAuth Verify case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nAuth Verify case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_encap_decap_all(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.encrypt = true;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Cipher Auth Encap-decap case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_auth_verify_all(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts);
if (err == TEST_SKIPPED) {
printf("Auth Generate + Verify case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_multi_flow(void)
{
const struct mcs_test_vector *tv[MCS_MAX_FLOWS];
struct mcs_test_vector iter[MCS_MAX_FLOWS];
struct mcs_test_opts opts = {0};
int i, err;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.encrypt = true;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = MCS_MAX_FLOWS;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
for (i = 0; i < MCS_MAX_FLOWS; i++) {
memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ);
memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data,
MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ);
memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data,
MCS_MULTI_FLOW_TD_SECURE_DATA_SZ);
iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ;
iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ +
(2 * RTE_ETHER_ADDR_LEN);
iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ +
(2 * RTE_ETHER_ADDR_LEN);
iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128;
iter[i].ssci = 0x0;
iter[i].xpn = 0x0;
tv[i] = (const struct mcs_test_vector *)&iter[i];
}
err = test_macsec(tv, MCS_ENCAP_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Cipher Auth Encryption multi flow skipped\n");
} else if (err) {
printf("\nCipher Auth Encryption multi flow failed");
err = -1;
} else {
printf("\nCipher Auth Encryption multi flow Passed");
err = 0;
}
return err;
}
static int
test_inline_macsec_with_vlan(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_vlan_vectors[i];
if (i == 0) {
opts.sectag_insert_mode = 1;
} else if (i == 1) {
opts.sectag_insert_mode = 0; /* offset from special E-type */
opts.nb_vlan = 1;
} else if (i == 2) {
opts.sectag_insert_mode = 0; /* offset from special E-type */
opts.nb_vlan = 2;
}
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
if (err == TEST_SKIPPED) {
printf("VLAN Encap case %d skipped", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\n VLAN Encap case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\n VLAN Encap case %d passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
for (i = 0; i < size; i++) {
cur_td = &list_mcs_vlan_vectors[i];
if (i == 0) {
opts.sectag_insert_mode = 1;
} else if (i == 1) {
opts.sectag_insert_mode = 0; /* offset from special E-type */
opts.nb_vlan = 1;
} else if (i == 2) {
opts.sectag_insert_mode = 0; /* offset from special E-type */
opts.nb_vlan = 2;
}
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("VLAN Decap case %d skipped", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\n VLAN Decap case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\n VLAN Decap case %d passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
2 * size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_pkt_drop(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.encrypt = true;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_err_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Packet drop case %d skipped", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nPacket drop case %d passed", cur_td->test_idx);
err = 0;
} else {
printf("\nPacket drop case %d failed", cur_td->test_idx);
err = -1;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_untagged_rx(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_untagged_rx = 1;
size = (sizeof(list_mcs_untagged_cipher_vectors) /
sizeof((list_mcs_untagged_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_untagged_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = 0;
else
err = -1;
all_err += err;
}
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
for (i = 0; i < size; i++) {
cur_td = &list_mcs_untagged_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = 0;
else
err = -1;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
2 * size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_bad_tag_rx(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_bad_tag_cnt = 1;
size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_bad_tag_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_sa_not_in_use(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 0;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_sa_not_in_use = 1;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_decap_stats(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_decap_stats = 1;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Decap stats case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nDecap stats case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nDecap stats case %d passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_verify_only_stats(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_verify_only_stats = 1;
size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
if (err == TEST_SKIPPED) {
printf("Verify only stats case %d skipped\n", cur_td->test_idx);
skipped += 1;
err = 0;
} else if (err) {
printf("\nVerify only stats case %d failed", cur_td->test_idx);
err = -1;
} else {
printf("\nVerify only stats case %d Passed", cur_td->test_idx);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_pkts_invalid_stats(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_err_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = 0;
else
err = -1;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_pkts_unchecked_stats(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_DISABLE;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_pkts_unchecked_stats = 1;
size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_out_pkts_untagged(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.encrypt = false;
opts.protect_frames = false;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_out_pkts_untagged = 1;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_out_pkts_toolong(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
opts.encrypt = true;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = 50;
opts.check_out_pkts_toolong = 1;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_encap_stats(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.encrypt = true;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_encap_stats = 1;
size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_cipher_vectors[i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_auth_only_stats(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_auth_only_stats = 1;
size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_integrity_vectors[i];
err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
if (err == TEST_SKIPPED) {
skipped += 1;
err = 0;
} else if (err)
err = -1;
else
err = 0;
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_interrupts_all(void)
{
struct mcs_err_vector err_vector = {0};
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int skipped = 0;
int i, size;
int err, all_err = 0;
enum rte_eth_event_macsec_subtype subtype[] = {
RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1,
RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1,
RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48,
RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1,
RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1,
};
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.check_sectag_interrupts = 1;
err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
test_macsec_event_callback, &err_vector);
size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_intr_test_vectors[i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Sectag val err interrupt test case %d skipped",
cur_td->test_idx);
skipped += 1;
err = 0;
} else if ((err_vector.event == RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR) &&
(err_vector.event_subtype == subtype[i])) {
printf("\nSectag val err interrupt test case %d passed",
cur_td->test_idx);
err = 0;
} else {
printf("\nSectag val err interrupt test case %d failed",
cur_td->test_idx);
err = -1;
}
all_err += err;
}
rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
test_macsec_event_callback, &err_vector);
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_rekey_tx(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.encrypt = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.rekey_en = 1;
size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_rekey_vectors[i];
opts.rekey_td = &list_mcs_rekey_vectors[++i];
err = test_macsec(&cur_td, MCS_ENCAP, &opts);
if (err == TEST_SKIPPED) {
printf("Tx hw rekey test case %d skipped\n", i);
skipped += 1;
err = 0;
} else if (err) {
printf("Tx hw rekey test case %d failed\n", i);
err = -1;
} else {
printf("Tx hw rekey test case %d passed\n", i);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size / 2 + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_rekey_rx(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
int err, all_err = 0;
int skipped = 0;
int i, size;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.protect_frames = true;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.mtu = RTE_ETHER_MTU;
opts.rekey_en = 1;
size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
for (i = 0; i < size; i++) {
cur_td = &list_mcs_rekey_vectors[i];
opts.rekey_td = &list_mcs_rekey_vectors[++i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Rx rekey test case %d skipped\n", i);
skipped += 1;
err = 0;
} else if (err) {
printf("Rx rekey test case %d failed\n", i);
err = -1;
} else {
printf("Rx rekey test case %d passed\n", i);
err = 0;
}
all_err += err;
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size / 2 + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
test_inline_macsec_anti_replay(void)
{
const struct mcs_test_vector *cur_td;
struct mcs_test_opts opts = {0};
uint16_t replay_win_sz[2] = {32, 0};
int err, all_err = 0;
int skipped = 0;
int i, size;
int j;
opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
opts.sa_in_use = 1;
opts.nb_td = 1;
opts.sectag_insert_mode = 1;
opts.replay_protect = 1;
size = (sizeof(list_mcs_anti_replay_vectors) / sizeof((list_mcs_anti_replay_vectors)[0]));
for (j = 0; j < 2; j++) {
opts.replay_win_sz = replay_win_sz[j];
for (i = 0; i < size; i++) {
cur_td = &list_mcs_anti_replay_vectors[i];
opts.ar_td[0] = &list_mcs_anti_replay_vectors[++i];
opts.ar_td[1] = &list_mcs_anti_replay_vectors[++i];
opts.ar_td[2] = &list_mcs_anti_replay_vectors[++i];
err = test_macsec(&cur_td, MCS_DECAP, &opts);
if (err == TEST_SKIPPED) {
printf("Replay window: %u, Anti replay test "
"case %d skipped\n", opts.replay_win_sz,
i);
skipped += 1;
err = 0;
} else if (err) {
printf("Replay window: %u, Anti replay test "
"case %d failed\n", opts.replay_win_sz,
i);
err = -1;
} else {
printf("Replay window: %u, Anti replay test "
"case %d passed\n", opts.replay_win_sz,
i);
err = 0;
}
all_err += err;
}
}
printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__,
size / 2 + all_err - skipped, -all_err, skipped);
return skipped > 0 ? TEST_SKIPPED : all_err;
}
static int
ut_setup_inline_macsec(void)
{
int ret;
/* Start device */
ret = rte_eth_dev_start(port_id);
if (ret < 0) {
printf("rte_eth_dev_start: err=%d, port=%d\n",
ret, port_id);
return ret;
}
/* always enable promiscuous */
ret = rte_eth_promiscuous_enable(port_id);
if (ret != 0) {
printf("rte_eth_promiscuous_enable: err=%s, port=%d\n",
rte_strerror(-ret), port_id);
return ret;
}
check_all_ports_link_status(1, RTE_PORT_ALL);
return 0;
}
static void
ut_teardown_inline_macsec(void)
{
uint16_t portid;
int ret;
/* port tear down */
RTE_ETH_FOREACH_DEV(portid) {
ret = rte_eth_dev_stop(portid);
if (ret != 0)
printf("rte_eth_dev_stop: err=%s, port=%u\n",
rte_strerror(-ret), portid);
}
}
static int
inline_macsec_testsuite_setup(void)
{
struct rte_eth_dev_info dev_info;
uint16_t nb_rxd;
uint16_t nb_txd;
uint16_t nb_ports;
int ret;
uint16_t nb_rx_queue = 1, nb_tx_queue = 1;
printf("Start inline MACsec test.\n");
nb_ports = rte_eth_dev_count_avail();
if (nb_ports < NB_ETHPORTS_USED) {
printf("At least %u port(s) used for test\n",
NB_ETHPORTS_USED);
return TEST_SKIPPED;
}
ret = init_mempools(NB_MBUF);
if (ret)
return ret;
if (tx_pkts_burst == NULL) {
tx_pkts_burst = (struct rte_mbuf **)rte_calloc("tx_buff",
MAX_TRAFFIC_BURST,
sizeof(void *),
RTE_CACHE_LINE_SIZE);
if (!tx_pkts_burst)
return TEST_FAILED;
rx_pkts_burst = (struct rte_mbuf **)rte_calloc("rx_buff",
MAX_TRAFFIC_BURST,
sizeof(void *),
RTE_CACHE_LINE_SIZE);
if (!rx_pkts_burst)
return TEST_FAILED;
}
printf("Generate %d packets\n", MAX_TRAFFIC_BURST);
nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
nb_txd = RTE_TEST_TX_DESC_DEFAULT;
/* configuring port 0 for the test is enough */
port_id = 0;
if (rte_eth_dev_info_get(port_id, &dev_info)) {
printf("Failed to get devinfo");
return -1;
}
if ((dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_MACSEC_STRIP) !=
RTE_ETH_RX_OFFLOAD_MACSEC_STRIP ||
(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) !=
RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
printf("Device does not support MACsec\n");
return TEST_SKIPPED;
}
/* port configure */
ret = rte_eth_dev_configure(port_id, nb_rx_queue,
nb_tx_queue, &port_conf);
if (ret < 0) {
printf("Cannot configure device: err=%d, port=%d\n",
ret, port_id);
return ret;
}
ret = rte_eth_macaddr_get(port_id, &ports_eth_addr[port_id]);
if (ret < 0) {
printf("Cannot get mac address: err=%d, port=%d\n",
ret, port_id);
return ret;
}
printf("Port %u ", port_id);
print_ethaddr("Address:", &ports_eth_addr[port_id]);
printf("\n");
/* tx queue setup */
ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd,
SOCKET_ID_ANY, &tx_conf);
if (ret < 0) {
printf("rte_eth_tx_queue_setup: err=%d, port=%d\n",
ret, port_id);
return ret;
}
/* rx queue steup */
ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd, SOCKET_ID_ANY,
&rx_conf, mbufpool);
if (ret < 0) {
printf("rte_eth_rx_queue_setup: err=%d, port=%d\n",
ret, port_id);
return ret;
}
return 0;
}
static void
inline_macsec_testsuite_teardown(void)
{
uint16_t portid;
int ret;
/* port tear down */
RTE_ETH_FOREACH_DEV(portid) {
ret = rte_eth_dev_reset(portid);
if (ret != 0)
printf("rte_eth_dev_reset: err=%s, port=%u\n",
rte_strerror(-ret), port_id);
}
rte_free(tx_pkts_burst);
rte_free(rx_pkts_burst);
}
static struct unit_test_suite inline_macsec_testsuite = {
.suite_name = "Inline MACsec Ethernet Device Unit Test Suite",
.unit_test_cases = {
TEST_CASE_NAMED_ST(
"MACsec Encap + decap Multi flow",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_multi_flow),
TEST_CASE_NAMED_ST(
"MACsec encap(Cipher+Auth) known vector",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_encap_all),
TEST_CASE_NAMED_ST(
"MACsec decap(De-cipher+verify) known vector",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_decap_all),
TEST_CASE_NAMED_ST(
"MACsec auth only known vector",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_auth_only_all),
TEST_CASE_NAMED_ST(
"MACsec verify only known vector",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_verify_only_all),
TEST_CASE_NAMED_ST(
"MACsec encap + decap known vector",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_encap_decap_all),
TEST_CASE_NAMED_ST(
"MACsec auth + verify known vector",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_auth_verify_all),
TEST_CASE_NAMED_ST(
"MACsec Encap and decap with VLAN",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_with_vlan),
TEST_CASE_NAMED_ST(
"MACsec packet drop",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_pkt_drop),
TEST_CASE_NAMED_ST(
"MACsec untagged Rx",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_untagged_rx),
TEST_CASE_NAMED_ST(
"MACsec bad tag Rx",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_bad_tag_rx),
TEST_CASE_NAMED_ST(
"MACsec SA not in use",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_sa_not_in_use),
TEST_CASE_NAMED_ST(
"MACsec decap stats",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_decap_stats),
TEST_CASE_NAMED_ST(
"MACsec verify only stats",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_verify_only_stats),
TEST_CASE_NAMED_ST(
"MACsec pkts invalid stats",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_pkts_invalid_stats),
TEST_CASE_NAMED_ST(
"MACsec pkts unchecked stats",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_pkts_unchecked_stats),
TEST_CASE_NAMED_ST(
"MACsec out pkts untagged",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_out_pkts_untagged),
TEST_CASE_NAMED_ST(
"MACsec out pkts too long",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_out_pkts_toolong),
TEST_CASE_NAMED_ST(
"MACsec Encap stats",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_encap_stats),
TEST_CASE_NAMED_ST(
"MACsec auth only stats",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_auth_only_stats),
TEST_CASE_NAMED_ST(
"MACsec interrupts all",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_interrupts_all),
TEST_CASE_NAMED_ST(
"MACsec re-key Tx",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_rekey_tx),
TEST_CASE_NAMED_ST(
"MACsec re-key Rx",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_rekey_rx),
TEST_CASE_NAMED_ST(
"MACsec anti-replay",
ut_setup_inline_macsec, ut_teardown_inline_macsec,
test_inline_macsec_anti_replay),
TEST_CASES_END() /**< NULL terminate unit test array */
},
};
static int
test_inline_macsec(void)
{
inline_macsec_testsuite.setup = inline_macsec_testsuite_setup;
inline_macsec_testsuite.teardown = inline_macsec_testsuite_teardown;
return unit_test_suite_runner(&inline_macsec_testsuite);
}
#endif /* !RTE_EXEC_ENV_WINDOWS */
REGISTER_TEST_COMMAND(inline_macsec_autotest, test_inline_macsec);
|