/usr/share/doc/knot-resolver/lib.html is in knot-resolver-doc 2.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Knot DNS Resolver library — Knot DNS Resolver 2.1.1 documentation</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '2.1.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Modules API reference" href="modules_api.html" />
<link rel="prev" title="Building project" href="build.html" />
</head>
<body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="modules_api.html" title="Modules API reference"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="build.html" title="Building project"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Knot DNS Resolver 2.1.1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="knot-dns-resolver-library">
<span id="lib-index"></span><h1>Knot DNS Resolver library<a class="headerlink" href="#knot-dns-resolver-library" title="Permalink to this headline">¶</a></h1>
<div class="section" id="requirements">
<h2>Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://gitlab.labs.nic.cz/knot/knot-dns/tree/master/src/libknot">libknot</a> 2.0 (Knot DNS high-performance DNS library.)</li>
</ul>
</div>
<div class="section" id="for-users">
<h2>For users<a class="headerlink" href="#for-users" title="Permalink to this headline">¶</a></h2>
<p>The library as described provides basic services for name resolution, which should cover the usage,
examples are in the <a class="reference internal" href="#lib-api-rplan"><span class="std std-ref">resolve API</span></a> documentation.</p>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">If you’re migrating from <code class="docutils literal"><span class="pre">getaddrinfo()</span></code>, see <em>“synchronous”</em> API, but the library offers iterative API as well to plug it into your event loop for example.</p>
</div>
</div>
<div class="section" id="for-developers">
<span id="lib-layers"></span><h2>For developers<a class="headerlink" href="#for-developers" title="Permalink to this headline">¶</a></h2>
<p>The resolution process starts with the functions in <a class="reference internal" href="#lib-api-rplan"><span class="std std-ref">resolve.c</span></a>, they are responsible for:</p>
<ul class="simple">
<li>reacting to state machine state (i.e. calling consume layers if we have an answer ready)</li>
<li>interacting with the library user (i.e. asking caller for I/O, accepting queries)</li>
<li>fetching assets needed by layers (i.e. zone cut)</li>
</ul>
<p>This is the <em>driver</em>. The driver is not meant to know <em>“how”</em> the query resolves, but rather <em>“when”</em> to execute <em>“what”</em>.</p>
<img alt="_images/resolution.png" class="align-center" src="_images/resolution.png" />
<p>On the other side are <em>layers</em>. They are responsible for dissecting the packets and informing the driver about the results. For example, a <em>produce</em> layer generates query, a <em>consume</em> layer validates answer.</p>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">Layers are executed asynchronously by the driver. If you need some asset beforehand, you can signalize the driver using returning state or current query flags. For example, setting a flag <code class="docutils literal"><span class="pre">AWAIT_CUT</span></code> forces driver to fetch zone cut information before the packet is consumed; setting a <code class="docutils literal"><span class="pre">RESOLVED</span></code> flag makes it pop a query after the current set of layers is finished; returning <code class="docutils literal"><span class="pre">FAIL</span></code> state makes it fail current query.</p>
</div>
<p>Layers can also change course of resolution, for example by appending additional queries.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">consume</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span><span class="n">state</span><span class="p">,</span> <span class="n">req</span><span class="p">,</span> <span class="n">answer</span><span class="p">)</span>
<span class="n">answer</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">pkt_t</span><span class="p">(</span><span class="n">answer</span><span class="p">)</span>
<span class="kr">if</span> <span class="n">answer</span><span class="p">:</span><span class="n">qtype</span><span class="p">()</span> <span class="o">==</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">NS</span> <span class="kr">then</span>
<span class="n">req</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">request_t</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>
<span class="kd">local</span> <span class="n">qry</span> <span class="o">=</span> <span class="n">req</span><span class="p">:</span><span class="n">push</span><span class="p">(</span><span class="n">answer</span><span class="p">:</span><span class="n">qname</span><span class="p">(),</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">SOA</span><span class="p">,</span> <span class="n">kres</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">IN</span><span class="p">)</span>
<span class="n">qry</span><span class="p">.</span><span class="n">flags</span><span class="p">.</span><span class="n">AWAIT_CUT</span> <span class="o">=</span> <span class="kc">true</span>
<span class="kr">end</span>
<span class="kr">return</span> <span class="n">state</span>
<span class="kr">end</span>
</pre></div>
</div>
<p>This <strong>doesn’t</strong> block currently processed query, and the newly created sub-request will start as soon as driver finishes processing current. In some cases you might need to issue sub-request and process it <strong>before</strong> continuing with the current, i.e. validator may need a DNSKEY before it can validate signatures. In this case, layers can yield and resume afterwards.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">consume</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span><span class="n">state</span><span class="p">,</span> <span class="n">req</span><span class="p">,</span> <span class="n">answer</span><span class="p">)</span>
<span class="n">answer</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">pkt_t</span><span class="p">(</span><span class="n">answer</span><span class="p">)</span>
<span class="kr">if</span> <span class="n">state</span> <span class="o">==</span> <span class="n">kres</span><span class="p">.</span><span class="n">YIELD</span> <span class="kr">then</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'continuing yielded layer'</span><span class="p">)</span>
<span class="kr">return</span> <span class="n">kres</span><span class="p">.</span><span class="n">DONE</span>
<span class="kr">else</span>
<span class="kr">if</span> <span class="n">answer</span><span class="p">:</span><span class="n">qtype</span><span class="p">()</span> <span class="o">==</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">NS</span> <span class="kr">then</span>
<span class="n">req</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">request_t</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>
<span class="kd">local</span> <span class="n">qry</span> <span class="o">=</span> <span class="n">req</span><span class="p">:</span><span class="n">push</span><span class="p">(</span><span class="n">answer</span><span class="p">:</span><span class="n">qname</span><span class="p">(),</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">SOA</span><span class="p">,</span> <span class="n">kres</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">IN</span><span class="p">)</span>
<span class="n">qry</span><span class="p">.</span><span class="n">flags</span><span class="p">.</span><span class="n">AWAIT_CUT</span> <span class="o">=</span> <span class="kc">true</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'planned SOA query, yielding'</span><span class="p">)</span>
<span class="kr">return</span> <span class="n">kres</span><span class="p">.</span><span class="n">YIELD</span>
<span class="kr">end</span>
<span class="kr">return</span> <span class="n">state</span>
<span class="kr">end</span>
<span class="kr">end</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">YIELD</span></code> state is a bit special. When a layer returns it, it interrupts current walk through the layers. When the layer receives it,
it means that it yielded before and now it is resumed. This is useful in a situation where you need a sub-request to determine whether current answer is valid or not.</p>
</div>
<div class="section" id="writing-layers">
<h2>Writing layers<a class="headerlink" href="#writing-layers" title="Permalink to this headline">¶</a></h2>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">FIXME: this dev-docs section is outdated! Better see comments in files instead, for now.</p>
</div>
<p>The resolver <a class="reference internal" href="#lib-index"><span class="std std-ref">library</span></a> leverages the processing API from the libknot to separate packet processing code into layers.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This is only crash-course in the library internals, see the resolver <a class="reference internal" href="#lib-index"><span class="std std-ref">library</span></a> documentation for the complete overview of the services.</p>
</div>
<p>The library offers following services:</p>
<ul class="simple">
<li><a class="reference internal" href="#lib-api-cache"><span class="std std-ref">Cache</span></a> - MVCC cache interface for retrieving/storing resource records.</li>
<li><a class="reference internal" href="#lib-api-rplan"><span class="std std-ref">Resolution plan</span></a> - Query resolution plan, a list of partial queries (with hierarchy) sent in order to satisfy original query. This contains information about the queries, nameserver choice, timing information, answer and its class.</li>
<li><a class="reference internal" href="#lib-api-nameservers"><span class="std std-ref">Nameservers</span></a> - Reputation database of nameservers, this serves as an aid for nameserver choice.</li>
</ul>
<p>A processing layer is going to be called by the query resolution driver for each query,
so you’re going to work with <a class="reference internal" href="#lib-api-rplan"><span class="std std-ref">struct kr_request</span></a> as your per-query context.
This structure contains pointers to resolution context, resolution plan and also the final answer.</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">consume</span><span class="p">(</span><span class="n">kr_layer_t</span> <span class="o">*</span><span class="n">ctx</span><span class="p">,</span> <span class="n">knot_pkt_t</span> <span class="o">*</span><span class="n">pkt</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">kr_request</span> <span class="o">*</span><span class="n">req</span> <span class="o">=</span> <span class="n">ctx</span><span class="o">-></span><span class="n">req</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">kr_query</span> <span class="o">*</span><span class="n">qry</span> <span class="o">=</span> <span class="n">req</span><span class="o">-></span><span class="n">current_query</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This is only passive processing of the incoming answer. If you want to change the course of resolution, say satisfy a query from a local cache before the library issues a query to the nameserver, you can use states (see the <a class="reference internal" href="modules.html#mod-hints"><span class="std std-ref">Static hints</span></a> for example).</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">produce</span><span class="p">(</span><span class="n">kr_layer_t</span> <span class="o">*</span><span class="n">ctx</span><span class="p">,</span> <span class="n">knot_pkt_t</span> <span class="o">*</span><span class="n">pkt</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">kr_request</span> <span class="o">*</span><span class="n">req</span> <span class="o">=</span> <span class="n">ctx</span><span class="o">-></span><span class="n">req</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">kr_query</span> <span class="o">*</span><span class="n">qry</span> <span class="o">=</span> <span class="n">req</span><span class="o">-></span><span class="n">current_query</span><span class="p">;</span>
<span class="cm">/* Query can be satisfied locally. */</span>
<span class="k">if</span> <span class="p">(</span><span class="n">can_satisfy</span><span class="p">(</span><span class="n">qry</span><span class="p">))</span> <span class="p">{</span>
<span class="cm">/* This flag makes the resolver move the query</span>
<span class="cm"> * to the "resolved" list. */</span>
<span class="n">qry</span><span class="o">-></span><span class="n">flags</span><span class="p">.</span><span class="n">RESOLVED</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">return</span> <span class="n">KR_STATE_DONE</span><span class="p">;</span>
<span class="p">}</span>
<span class="cm">/* Pass-through. */</span>
<span class="k">return</span> <span class="n">ctx</span><span class="o">-></span><span class="n">state</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>It is possible to not only act during the query resolution, but also to view the complete resolution plan afterwards. This is useful for analysis-type tasks, or <em>“per answer”</em> hooks.</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">finish</span><span class="p">(</span><span class="n">kr_layer_t</span> <span class="o">*</span><span class="n">ctx</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">struct</span> <span class="n">kr_request</span> <span class="o">*</span><span class="n">req</span> <span class="o">=</span> <span class="n">ctx</span><span class="o">-></span><span class="n">req</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">kr_rplan</span> <span class="o">*</span><span class="n">rplan</span> <span class="o">=</span> <span class="n">req</span><span class="o">-></span><span class="n">rplan</span><span class="p">;</span>
<span class="cm">/* Print the query sequence with start time. */</span>
<span class="kt">char</span> <span class="n">qname_str</span><span class="p">[</span><span class="n">KNOT_DNAME_MAXLEN</span><span class="p">];</span>
<span class="k">struct</span> <span class="n">kr_query</span> <span class="o">*</span><span class="n">qry</span> <span class="o">=</span> <span class="nb">NULL</span>
<span class="n">WALK_LIST</span><span class="p">(</span><span class="n">qry</span><span class="p">,</span> <span class="n">rplan</span><span class="o">-></span><span class="n">resolved</span><span class="p">)</span> <span class="p">{</span>
<span class="n">knot_dname_to_str</span><span class="p">(</span><span class="n">qname_str</span><span class="p">,</span> <span class="n">qry</span><span class="o">-></span><span class="n">sname</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">qname_str</span><span class="p">));</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%s at %u</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">qname_str</span><span class="p">,</span> <span class="n">qry</span><span class="o">-></span><span class="n">timestamp</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ctx</span><span class="o">-></span><span class="n">state</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="apis-in-lua">
<h2>APIs in Lua<a class="headerlink" href="#apis-in-lua" title="Permalink to this headline">¶</a></h2>
<p>The APIs in Lua world try to mirror the C APIs using LuaJIT FFI, with several differences and enhancements.
There is not comprehensive guide on the API yet, but you can have a look at the <a class="reference external" href="https://gitlab.labs.nic.cz/knot/knot-resolver/blob/master/daemon/lua/kres.lua">bindings</a> file.</p>
<div class="section" id="elementary-types-and-constants">
<h3>Elementary types and constants<a class="headerlink" href="#elementary-types-and-constants" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>States are directly in <code class="docutils literal"><span class="pre">kres</span></code> table, e.g. <code class="docutils literal"><span class="pre">kres.YIELD,</span> <span class="pre">kres.CONSUME,</span> <span class="pre">kres.PRODUCE,</span> <span class="pre">kres.DONE,</span> <span class="pre">kres.FAIL</span></code>.</li>
<li>DNS classes are in <code class="docutils literal"><span class="pre">kres.class</span></code> table, e.g. <code class="docutils literal"><span class="pre">kres.class.IN</span></code> for Internet class.</li>
<li>DNS types are in <code class="docutils literal"><span class="pre">kres.type</span></code> table, e.g. <code class="docutils literal"><span class="pre">kres.type.AAAA</span></code> for AAAA type.</li>
<li>DNS rcodes types are in <code class="docutils literal"><span class="pre">kres.rcode</span></code> table, e.g. <code class="docutils literal"><span class="pre">kres.rcode.NOERROR</span></code>.</li>
<li>Packet sections (QUESTION, ANSWER, AUTHORITY, ADDITIONAL) are in the <code class="docutils literal"><span class="pre">kres.section</span></code> table.</li>
</ul>
</div>
<div class="section" id="working-with-domain-names">
<h3>Working with domain names<a class="headerlink" href="#working-with-domain-names" title="Permalink to this headline">¶</a></h3>
<p>The internal API usually works with domain names in label format, you can convert between text and wire freely.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="kd">local</span> <span class="n">dname</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">str2dname</span><span class="p">(</span><span class="s1">'business.se'</span><span class="p">)</span>
<span class="kd">local</span> <span class="n">strname</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">dname2str</span><span class="p">(</span><span class="n">dname</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="working-with-resource-records">
<h3>Working with resource records<a class="headerlink" href="#working-with-resource-records" title="Permalink to this headline">¶</a></h3>
<p>Resource records are stored as tables.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="kd">local</span> <span class="n">rr</span> <span class="o">=</span> <span class="p">{</span> <span class="n">owner</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">str2dname</span><span class="p">(</span><span class="s1">'owner'</span><span class="p">),</span>
<span class="n">ttl</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
<span class="n">class</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">IN</span><span class="p">,</span>
<span class="nb">type</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">CNAME</span><span class="p">,</span>
<span class="n">rdata</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">str2dname</span><span class="p">(</span><span class="s1">'someplace'</span><span class="p">)</span> <span class="p">}</span>
<span class="nb">print</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">rr2str</span><span class="p">(</span><span class="n">rr</span><span class="p">))</span>
</pre></div>
</div>
<p>RRSets in packet can be accessed using FFI, you can easily fetch single records.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="kd">local</span> <span class="n">rrset</span> <span class="o">=</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
<span class="kd">local</span> <span class="n">rr</span> <span class="o">=</span> <span class="n">rrset</span><span class="p">:</span><span class="n">get</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="c1">-- Return first RR</span>
<span class="nb">print</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">dname2str</span><span class="p">(</span><span class="n">rr</span><span class="p">:</span><span class="n">owner</span><span class="p">()))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">rr</span><span class="p">:</span><span class="n">ttl</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">rr2str</span><span class="p">(</span><span class="n">rr</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="section" id="working-with-packets">
<h3>Working with packets<a class="headerlink" href="#working-with-packets" title="Permalink to this headline">¶</a></h3>
<p>Packet is the data structure that you’re going to see in layers very often. They consists of a header, and four sections: QUESTION, ANSWER, AUTHORITY, ADDITIONAL. The first section is special, as it contains the query name, type, and class; the rest of the sections contain RRSets.</p>
<p>First you need to convert it to a type known to FFI and check basic properties. Let’s start with a snippet of a <em>consume</em> layer.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">consume</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span><span class="n">state</span><span class="p">,</span> <span class="n">req</span><span class="p">,</span> <span class="n">pkt</span><span class="p">)</span>
<span class="n">pkt</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">pkt_t</span><span class="p">(</span><span class="n">answer</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'rcode:'</span><span class="p">,</span> <span class="n">pkt</span><span class="p">:</span><span class="n">rcode</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'query:'</span><span class="p">,</span> <span class="n">kres</span><span class="p">.</span><span class="n">dname2str</span><span class="p">(</span><span class="n">pkt</span><span class="p">:</span><span class="n">qname</span><span class="p">()),</span> <span class="n">pkt</span><span class="p">:</span><span class="n">qclass</span><span class="p">(),</span> <span class="n">pkt</span><span class="p">:</span><span class="n">qtype</span><span class="p">())</span>
<span class="kr">if</span> <span class="n">pkt</span><span class="p">:</span><span class="n">rcode</span><span class="p">()</span> <span class="o">~=</span> <span class="n">kres</span><span class="p">.</span><span class="n">rcode</span><span class="p">.</span><span class="n">NOERROR</span> <span class="kr">then</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'error response'</span><span class="p">)</span>
<span class="kr">end</span>
<span class="kr">end</span>
</pre></div>
</div>
<p>You can enumerate records in the sections.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="kd">local</span> <span class="n">records</span> <span class="o">=</span> <span class="n">pkt</span><span class="p">:</span><span class="n">section</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">section</span><span class="p">.</span><span class="n">ANSWER</span><span class="p">)</span>
<span class="kr">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="o">#</span><span class="n">records</span> <span class="kr">do</span>
<span class="kd">local</span> <span class="n">rr</span> <span class="o">=</span> <span class="n">records</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="kr">if</span> <span class="n">rr</span><span class="p">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">AAAA</span> <span class="kr">then</span>
<span class="nb">print</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">rr2str</span><span class="p">(</span><span class="n">rr</span><span class="p">))</span>
<span class="kr">end</span>
<span class="kr">end</span>
</pre></div>
</div>
<p>During <em>produce</em> or <em>begin</em>, you might want to want to write to packet. Keep in mind that you have to write packet sections in sequence,
e.g. you can’t write to ANSWER after writing AUTHORITY, it’s like stages where you can’t go back.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">pkt</span><span class="p">:</span><span class="n">rcode</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">rcode</span><span class="p">.</span><span class="n">NXDOMAIN</span><span class="p">)</span>
<span class="c1">-- Clear answer and write QUESTION</span>
<span class="n">pkt</span><span class="p">:</span><span class="n">recycle</span><span class="p">()</span>
<span class="n">pkt</span><span class="p">:</span><span class="n">question</span><span class="p">(</span><span class="s1">'</span><span class="se">\7</span><span class="s1">blocked'</span><span class="p">,</span> <span class="n">kres</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">SOA</span><span class="p">)</span>
<span class="c1">-- Start writing data</span>
<span class="n">pkt</span><span class="p">:</span><span class="n">begin</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">section</span><span class="p">.</span><span class="n">ANSWER</span><span class="p">)</span>
<span class="c1">-- Nothing in answer</span>
<span class="n">pkt</span><span class="p">:</span><span class="n">begin</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">section</span><span class="p">.</span><span class="n">AUTHORITY</span><span class="p">)</span>
<span class="kd">local</span> <span class="n">soa</span> <span class="o">=</span> <span class="p">{</span> <span class="n">owner</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\7</span><span class="s1">blocked'</span><span class="p">,</span> <span class="n">ttl</span> <span class="o">=</span> <span class="mi">900</span><span class="p">,</span> <span class="n">class</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">IN</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">SOA</span><span class="p">,</span> <span class="n">rdata</span> <span class="o">=</span> <span class="s1">'...'</span> <span class="p">}</span>
<span class="n">pkt</span><span class="p">:</span><span class="n">put</span><span class="p">(</span><span class="n">soa</span><span class="p">.</span><span class="n">owner</span><span class="p">,</span> <span class="n">soa</span><span class="p">.</span><span class="n">ttl</span><span class="p">,</span> <span class="n">soa</span><span class="p">.</span><span class="n">class</span><span class="p">,</span> <span class="n">soa</span><span class="p">.</span><span class="n">type</span><span class="p">,</span> <span class="n">soa</span><span class="p">.</span><span class="n">rdata</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="working-with-requests">
<h3>Working with requests<a class="headerlink" href="#working-with-requests" title="Permalink to this headline">¶</a></h3>
<p>The request holds information about currently processed query, enabled options, cache, and other extra data.
You primarily need to retrieve currently processed query.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="n">consume</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span><span class="n">state</span><span class="p">,</span> <span class="n">req</span><span class="p">,</span> <span class="n">pkt</span><span class="p">)</span>
<span class="n">req</span> <span class="o">=</span> <span class="n">kres</span><span class="p">.</span><span class="n">request_t</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">req</span><span class="p">.</span><span class="n">options</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">req</span><span class="p">.</span><span class="n">state</span><span class="p">)</span>
<span class="c1">-- Print information about current query</span>
<span class="kd">local</span> <span class="n">current</span> <span class="o">=</span> <span class="n">req</span><span class="p">:</span><span class="n">current</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">kres</span><span class="p">.</span><span class="n">dname2str</span><span class="p">(</span><span class="n">current</span><span class="p">.</span><span class="n">owner</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">current</span><span class="p">.</span><span class="n">stype</span><span class="p">,</span> <span class="n">current</span><span class="p">.</span><span class="n">sclass</span><span class="p">,</span> <span class="n">current</span><span class="p">.</span><span class="n">id</span><span class="p">,</span> <span class="n">current</span><span class="p">.</span><span class="n">flags</span><span class="p">)</span>
<span class="kr">end</span>
</pre></div>
</div>
<p>In layers that either begin or finalize, you can walk the list of resolved queries.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="kd">local</span> <span class="n">last</span> <span class="o">=</span> <span class="n">req</span><span class="p">:</span><span class="n">resolved</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">last</span><span class="p">.</span><span class="n">stype</span><span class="p">)</span>
</pre></div>
</div>
<p>As described in the layers, you can not only retrieve information about current query, but also push new ones or pop old ones.</p>
<div class="highlight-lua"><div class="highlight"><pre><span></span><span class="c1">-- Push new query</span>
<span class="kd">local</span> <span class="n">qry</span> <span class="o">=</span> <span class="n">req</span><span class="p">:</span><span class="n">push</span><span class="p">(</span><span class="n">pkt</span><span class="p">:</span><span class="n">qname</span><span class="p">(),</span> <span class="n">kres</span><span class="p">.</span><span class="n">type</span><span class="p">.</span><span class="n">SOA</span><span class="p">,</span> <span class="n">kres</span><span class="p">.</span><span class="n">class</span><span class="p">.</span><span class="n">IN</span><span class="p">)</span>
<span class="n">qry</span><span class="p">.</span><span class="n">flags</span><span class="p">.</span><span class="n">AWAIT_CUT</span> <span class="o">=</span> <span class="kc">true</span>
<span class="c1">-- Pop the query, this will erase it from resolution plan</span>
<span class="n">req</span><span class="p">:</span><span class="n">pop</span><span class="p">(</span><span class="n">qry</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="api-reference">
<h2>API reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#name-resolution" id="id1">Name resolution</a></li>
<li><a class="reference internal" href="#cache" id="id2">Cache</a></li>
<li><a class="reference internal" href="#nameservers" id="id3">Nameservers</a></li>
<li><a class="reference internal" href="#modules" id="id4">Modules</a></li>
<li><a class="reference internal" href="#utilities" id="id5">Utilities</a></li>
<li><a class="reference internal" href="#generics-library" id="id6">Generics library</a></li>
</ul>
</div>
<div class="section" id="name-resolution">
<span id="lib-api-rplan"></span><h3><a class="toc-backref" href="#id1">Name resolution</a><a class="headerlink" href="#name-resolution" title="Permalink to this headline">¶</a></h3>
<p>The API provides an API providing a “consumer-producer”-like interface to enable user to plug it into existing event loop or I/O code. </p>
<p><em>Example usage of the iterative API:</em></p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="c1">// Create request and its memory pool</span>
<span class="k">struct</span> <span class="n">kr_request</span> <span class="n">req</span> <span class="o">=</span> <span class="p">{</span>
<span class="p">.</span><span class="n">pool</span> <span class="o">=</span> <span class="p">{</span>
<span class="p">.</span><span class="n">ctx</span> <span class="o">=</span> <span class="n">mp_new</span> <span class="p">(</span><span class="mi">4096</span><span class="p">),</span>
<span class="p">.</span><span class="n">alloc</span> <span class="o">=</span> <span class="p">(</span><span class="n">mm_alloc_t</span><span class="p">)</span> <span class="n">mp_alloc</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="c1">// Setup and provide input query</span>
<span class="kt">int</span> <span class="n">state</span> <span class="o">=</span> <span class="n">kr_resolve_begin</span><span class="p">(</span><span class="o">&</span><span class="n">req</span><span class="p">,</span> <span class="n">ctx</span><span class="p">,</span> <span class="n">final_answer</span><span class="p">);</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">kr_resolve_consume</span><span class="p">(</span><span class="o">&</span><span class="n">req</span><span class="p">,</span> <span class="n">query</span><span class="p">);</span>
<span class="c1">// Generate answer</span>
<span class="k">while</span> <span class="p">(</span><span class="n">state</span> <span class="o">==</span> <span class="n">KR_STATE_PRODUCE</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Additional query generate, do the I/O and pass back answer</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">kr_resolve_produce</span><span class="p">(</span><span class="o">&</span><span class="n">req</span><span class="p">,</span> <span class="o">&</span><span class="n">addr</span><span class="p">,</span> <span class="o">&</span><span class="n">type</span><span class="p">,</span> <span class="n">query</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">state</span> <span class="o">==</span> <span class="n">KR_STATE_CONSUME</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">ret</span> <span class="o">=</span> <span class="n">sendrecv</span><span class="p">(</span><span class="n">addr</span><span class="p">,</span> <span class="n">proto</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">resp</span><span class="p">);</span>
<span class="c1">// If I/O fails, make "resp" empty</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">kr_resolve_consume</span><span class="p">(</span><span class="o">&</span><span class="n">request</span><span class="p">,</span> <span class="n">addr</span><span class="p">,</span> <span class="n">resp</span><span class="p">);</span>
<span class="n">knot_pkt_clear</span><span class="p">(</span><span class="n">resp</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">knot_pkt_clear</span><span class="p">(</span><span class="n">query</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// "state" is either DONE or FAIL</span>
<span class="n">kr_resolve_finish</span><span class="p">(</span><span class="o">&</span><span class="n">request</span><span class="p">,</span> <span class="n">state</span><span class="p">);</span>
</pre></div>
</div>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.kr_request_selected">
<span class="target" id="resolve_8h_1a9ba8c6cef807cdf580e3249675a2589c"></span><code class="descname">kr_request_selected</code><span class="sig-paren">(</span>req<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_request_selected" title="Permalink to this definition">¶</a></dt>
<dd><p>Initializer for an array of *_selected. </p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Enums</p>
<dl class="enum">
<dt id="c.kr_rank">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910"></span><em class="property">enum </em><code class="descname">kr_rank</code><a class="headerlink" href="#c.kr_rank" title="Permalink to this definition">¶</a></dt>
<dd><p>RRset rank - for cache and ranked_rr_*. </p>
<p>The rank meaning consists of one independent flag - KR_RANK_AUTH, and the rest have meaning of values where only one can hold at any time. You can use one of the enums as a safe initial value, optionally | KR_RANK_AUTH; otherwise it’s best to manipulate ranks via the kr_rank_* functions.</p>
<p>
See also: <a class="reference external" href="https://tools.ietf.org/html/rfc2181#section-5.4.1">https://tools.ietf.org/html/rfc2181#section-5.4.1</a> <a class="reference external" href="https://tools.ietf.org/html/rfc4035#section-4.3">https://tools.ietf.org/html/rfc4035#section-4.3</a> <dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The representation is complicated by restrictions on integer comparison:<ul class="simple">
<li>AUTH must be > than !AUTH</li>
<li>AUTH INSECURE must be > than AUTH (because it attempted validation)</li>
<li>!AUTH SECURE must be > than AUTH (because it’s valid)</li>
</ul>
</dd>
</dl>
</p>
<p><em>Values:</em></p>
<dl class="enumvalue">
<dt id="c.KR_RANK_INITIAL">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a314a3c0622f106ac2d95166a955882eb"></span><code class="descname">KR_RANK_INITIAL</code> = 0<a class="headerlink" href="#c.KR_RANK_INITIAL" title="Permalink to this definition">¶</a></dt>
<dd><p>Did not attempt to validate. </p>
<p>It’s assumed compulsory to validate (or prove insecure). </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_OMIT">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a8ce363e2a0251b03d9e584dc816bc775"></span><code class="descname">KR_RANK_OMIT</code><a class="headerlink" href="#c.KR_RANK_OMIT" title="Permalink to this definition">¶</a></dt>
<dd><p>Do not attempt to validate. </p>
<p>(And don’t consider it a validation failure.) </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_TRY">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a76dfa0df9372e1b4a82a9da4aed01b1e"></span><code class="descname">KR_RANK_TRY</code><a class="headerlink" href="#c.KR_RANK_TRY" title="Permalink to this definition">¶</a></dt>
<dd><p>Attempt to validate, but failures are non-fatal. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_INDET">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a0b2bd0deec7f14daa770ed76a3cb2efd"></span><code class="descname">KR_RANK_INDET</code> = 4<a class="headerlink" href="#c.KR_RANK_INDET" title="Permalink to this definition">¶</a></dt>
<dd><p>Unable to determine whether it should be secure. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_BOGUS">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a96e35c2ef64df62bee72e1f8f272c5f8"></span><code class="descname">KR_RANK_BOGUS</code><a class="headerlink" href="#c.KR_RANK_BOGUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Ought to be secure but isn’t. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_MISMATCH">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a091bef5622c371a6af5a99b1512fd768"></span><code class="descname">KR_RANK_MISMATCH</code><a class="headerlink" href="#c.KR_RANK_MISMATCH" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_MISSING">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910af90e94cf80617a1ae87de5de6551a6da"></span><code class="descname">KR_RANK_MISSING</code><a class="headerlink" href="#c.KR_RANK_MISSING" title="Permalink to this definition">¶</a></dt>
<dd><p>Unable to obtain a good signature. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_INSECURE">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910a9d7776b87f70c084b0ee301be5ff7696"></span><code class="descname">KR_RANK_INSECURE</code> = 8<a class="headerlink" href="#c.KR_RANK_INSECURE" title="Permalink to this definition">¶</a></dt>
<dd><p>Proven to be insecure, i.e. </p>
<p>we have a chain of trust from TAs that cryptographically denies the possibility of existence of a positive chain of trust from the TAs to the record. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_AUTH">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910ab6bb0b23ed3c12c058f5a1a756fb9008"></span><code class="descname">KR_RANK_AUTH</code> = 16<a class="headerlink" href="#c.KR_RANK_AUTH" title="Permalink to this definition">¶</a></dt>
<dd><p>Authoritative data flag; the chain of authority was “verified”. </p>
<p>Even if not set, only in-bailiwick stuff is acceptable, i.e. almost authoritative (example: mandatory glue and its NS RR). </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_RANK_SECURE">
<span class="target" id="resolve_8h_1a0e289f25562f9b556ef10a98c6156910ac24395883ab262f224b8f98d7ee4fcf3"></span><code class="descname">KR_RANK_SECURE</code> = 32<a class="headerlink" href="#c.KR_RANK_SECURE" title="Permalink to this definition">¶</a></dt>
<dd><p>Verified whole chain of trust from the closest TA. </p>
</dd></dl>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.kr_rank_check">
<span class="target" id="resolve_8h_1a738bb98cdf863c916252379bbbba2f7c"></span>bool <code class="descname">kr_rank_check</code><span class="sig-paren">(</span>uint8_t<em> rank</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rank_check" title="Permalink to this definition">¶</a></dt>
<dd><p>Check that a rank value is valid. </p>
<p>Meant for assertions. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rank_test">
<span class="target" id="resolve_8h_1a852930fcbf2e70a7cf2d02799088485d"></span>static bool <code class="descname">kr_rank_test</code><span class="sig-paren">(</span>uint8_t<em> rank</em>, uint8_t<em> kr_flag</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rank_test" title="Permalink to this definition">¶</a></dt>
<dd><p>Test the presence of any flag/state in a rank, i.e. </p>
<p>including KR_RANK_AUTH. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rank_set">
<span class="target" id="resolve_8h_1a69240eec88e8feb588bd35be4d3c9a51"></span>static void <code class="descname">kr_rank_set</code><span class="sig-paren">(</span>uint8_t *<em> rank</em>, uint8_t<em> kr_flag</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rank_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the rank state. </p>
<p>The _AUTH flag is kept as it was. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_begin">
<span class="target" id="resolve_8h_1aaeed96e92822efabbc99f51559aec280"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_resolve_begin</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em>, struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a> *<em> ctx</em>, knot_pkt_t *<em> answer</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_begin" title="Permalink to this definition">¶</a></dt>
<dd><p>Begin name resolution. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>Expects a request to have an initialized mempool, the “answer” packet will be kept during the resolution and will contain the final answer at the end.</dd>
<dt><strong>Return</strong></dt>
<dd>CONSUME (expecting query) </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state with initialized mempool </li>
<li><code class="docutils literal"><span class="pre">ctx</span></code>: resolution context </li>
<li><code class="docutils literal"><span class="pre">answer</span></code>: allocated packet for final answer </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_consume">
<span class="target" id="resolve_8h_1ac76800068444e2da42c7562238115993"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_resolve_consume</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em>, const struct sockaddr *<em> src</em>, knot_pkt_t *<em> packet</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_consume" title="Permalink to this definition">¶</a></dt>
<dd><p>Consume input packet (may be either first query or answer to query originated from <a class="reference internal" href="#resolve_8h_1a762fbb13fdf6be59072a1da7784296d0"><span class="std std-ref">kr_resolve_produce()</span></a>) </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>If the I/O fails, provide an empty or NULL packet, this will make iterator recognize nameserver failure.</dd>
<dt><strong>Return</strong></dt>
<dd>any state </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state (awaiting input) </li>
<li><code class="docutils literal"><span class="pre">src</span></code>: [in] packet source address </li>
<li><code class="docutils literal"><span class="pre">packet</span></code>: [in] input packet </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_produce">
<span class="target" id="resolve_8h_1a762fbb13fdf6be59072a1da7784296d0"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_resolve_produce</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em>, struct sockaddr **<em> dst</em>, int *<em> type</em>, knot_pkt_t *<em> packet</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_produce" title="Permalink to this definition">¶</a></dt>
<dd><p>Produce either next additional query or finish. </p>
<p>If the CONSUME is returned then dst, type and packet will be filled with appropriate values and caller is responsible to send them and receive answer. If it returns any other state, then content of the variables is undefined.</p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>any state </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state (in PRODUCE state) </li>
<li><code class="docutils literal"><span class="pre">dst</span></code>: [out] possible address of the next nameserver </li>
<li><code class="docutils literal"><span class="pre">type</span></code>: [out] possible used socket type (SOCK_STREAM, SOCK_DGRAM) </li>
<li><code class="docutils literal"><span class="pre">packet</span></code>: [out] packet to be filled with additional query </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_checkout">
<span class="target" id="resolve_8h_1a0a09d1c699bd0e2dd659c712c90196c0"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_resolve_checkout</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em>, struct sockaddr *<em> src</em>, struct sockaddr *<em> dst</em>, int<em> type</em>, knot_pkt_t *<em> packet</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_checkout" title="Permalink to this definition">¶</a></dt>
<dd><p>Finalises the outbound query packet with the knowledge of the IP addresses. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The function must be called before actual sending of the request packet.</dd>
<dt><strong>Return</strong></dt>
<dd>kr_ok() or error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state (in PRODUCE state) </li>
<li><code class="docutils literal"><span class="pre">src</span></code>: address from which the query is going to be sent </li>
<li><code class="docutils literal"><span class="pre">dst</span></code>: address of the name server </li>
<li><code class="docutils literal"><span class="pre">type</span></code>: used socket type (SOCK_STREAM, SOCK_DGRAM) </li>
<li><code class="docutils literal"><span class="pre">packet</span></code>: [in,out] query packet to be finalised </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_finish">
<span class="target" id="resolve_8h_1a0f4380a2b5f8386821d81f5f38694993"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_resolve_finish</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em>, int<em> state</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_finish" title="Permalink to this definition">¶</a></dt>
<dd><p>Finish resolution and commit results if the state is DONE. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The structures will be deinitialized, but the assigned memory pool is not going to be destroyed, as it’s owned by caller.</dd>
<dt><strong>Return</strong></dt>
<dd>DONE </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state </li>
<li><code class="docutils literal"><span class="pre">state</span></code>: either DONE or FAIL state </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_plan">
<span class="target" id="resolve_8h_1a3341a4eed1b2f054a618580e228acb1c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a>* <code class="descname">kr_resolve_plan</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_plan" title="Permalink to this definition">¶</a></dt>
<dd><p>Return resolution plan. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>pointer to rplan </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_resolve_pool">
<span class="target" id="resolve_8h_1a3683a126517ae1867b371814835ec14b"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> knot_mm_t* <code class="descname">kr_resolve_pool</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_resolve_pool" title="Permalink to this definition">¶</a></dt>
<dd><p>Return memory pool associated with request. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>mempool </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">request</span></code>: request state </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.kr_context">
<span class="target" id="structkr__context"></span><em class="property">struct </em><code class="descname">kr_context</code><a class="headerlink" href="#c.kr_context" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <resolve.h></em><p>Name resolution context. </p>
<p>Resolution context provides basic services like cache, configuration and options.</p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This structure is persistent between name resolutions and may be shared between threads. </dd>
</dl>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_context::options">
<span class="target" id="structkr__context_1a9bbc99f3dbf046f26cad98f85eff0fa4"></span>struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a> <code class="descname">options</code><a class="headerlink" href="#c.kr_context::options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::opt_rr">
<span class="target" id="structkr__context_1a9dc0f316c385ab4560e7cd3a88e5f9c6"></span>knot_rrset_t* <code class="descname">opt_rr</code><a class="headerlink" href="#c.kr_context::opt_rr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::trust_anchors">
<span class="target" id="structkr__context_1a806763acebe5c488f25e511629f67919"></span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> <code class="descname">trust_anchors</code><a class="headerlink" href="#c.kr_context::trust_anchors" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::negative_anchors">
<span class="target" id="structkr__context_1afe6e44512f7424688bb0b50b0812cc3f"></span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> <code class="descname">negative_anchors</code><a class="headerlink" href="#c.kr_context::negative_anchors" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::root_hints">
<span class="target" id="structkr__context_1ad8412c6fe64ecb65cb9ec8ac4d203e89"></span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> <code class="descname">root_hints</code><a class="headerlink" href="#c.kr_context::root_hints" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::cache">
<span class="target" id="structkr__context_1a3b98e8436c67e58c92f37801ae3e4cf9"></span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> <code class="descname">cache</code><a class="headerlink" href="#c.kr_context::cache" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::cache_rtt">
<span class="target" id="structkr__context_1af8e17b874ae37e09a654492cd8d8f39e"></span>kr_nsrep_lru_t* <code class="descname">cache_rtt</code><a class="headerlink" href="#c.kr_context::cache_rtt" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::cache_rep">
<span class="target" id="structkr__context_1a6cfc05d8a69d44eb20bafe7c4e311376"></span>kr_nsrep_lru_t* <code class="descname">cache_rep</code><a class="headerlink" href="#c.kr_context::cache_rep" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::modules">
<span class="target" id="structkr__context_1a82e8ea897381daae632b9b13649bea99"></span>module_array_t* <code class="descname">modules</code><a class="headerlink" href="#c.kr_context::modules" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::cookie_ctx">
<span class="target" id="structkr__context_1a7127647976de645ee9c72b4600362087"></span>struct kr_cookie_ctx <code class="descname">cookie_ctx</code><a class="headerlink" href="#c.kr_context::cookie_ctx" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::cache_cookie">
<span class="target" id="structkr__context_1aa9d0a2aff71c9fced37fc4e246c927a7"></span>kr_cookie_lru_t* <code class="descname">cache_cookie</code><a class="headerlink" href="#c.kr_context::cache_cookie" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_context::tls_padding">
<span class="target" id="structkr__context_1a572149d2520138fa027cce35308c6c89"></span>int32_t <code class="descname">tls_padding</code><a class="headerlink" href="#c.kr_context::tls_padding" title="Permalink to this definition">¶</a></dt>
<dd><p>See net.tls_padding in ../daemon/README.rst -1 is “true” (default policy), 0 is “false” (no padding) </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_context::pool">
<span class="target" id="structkr__context_1ab2ead6f30ca33cf8f6000bfa7b717289"></span>knot_mm_t* <code class="descname">pool</code><a class="headerlink" href="#c.kr_context::pool" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
<dl class="struct">
<dt id="c.kr_request">
<span class="target" id="structkr__request"></span><em class="property">struct </em><code class="descname">kr_request</code><a class="headerlink" href="#c.kr_request" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <resolve.h></em><p>Name resolution request. </p>
<p>Keeps information about current query processing between calls to processing APIs, i.e. current resolved query, resolution plan, … Use this instead of the simple interface if you want to implement multiplexing or custom I/O.</p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>All data for this request must be allocated from the given pool. </dd>
</dl>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_request::ctx">
<span class="target" id="structkr__request_1ad210f8e6a48a75dc42c040a4d0b939f6"></span>struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a>* <code class="descname">ctx</code><a class="headerlink" href="#c.kr_request::ctx" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::answer">
<span class="target" id="structkr__request_1ab5a622407a013f6cacf74962a3689d47"></span>knot_pkt_t* <code class="descname">answer</code><a class="headerlink" href="#c.kr_request::answer" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::current_query">
<span class="target" id="structkr__request_1a5591b1d0fef156b2c25bf41152a7645d"></span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">current_query</code><a class="headerlink" href="#c.kr_request::current_query" title="Permalink to this definition">¶</a></dt>
<dd><p>Current evaluated query. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::key">
<span class="target" id="structkr__request_1afc1fa4562b408f83a1ef744248f510aa"></span>const knot_rrset_t* <code class="descname">key</code><a class="headerlink" href="#c.kr_request::key" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::addr">
<span class="target" id="structkr__request_1a18ece99c0fa98b9d2fcf11c28f85273b"></span>const struct sockaddr* <code class="descname">addr</code><a class="headerlink" href="#c.kr_request::addr" title="Permalink to this definition">¶</a></dt>
<dd><p>Address that originated the request. </p>
<p>Current upstream address.</p>
<p>NULL for internal origin. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::dst_addr">
<span class="target" id="structkr__request_1a7ebaea466facf85164955c92e521d439"></span>const struct sockaddr* <code class="descname">dst_addr</code><a class="headerlink" href="#c.kr_request::dst_addr" title="Permalink to this definition">¶</a></dt>
<dd><p>Address that accepted the request. </p>
<p>NULL for internal origin. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::packet">
<span class="target" id="structkr__request_1a1319b33ddfdad5e5144d580ca203e509"></span>const knot_pkt_t* <code class="descname">packet</code><a class="headerlink" href="#c.kr_request::packet" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::opt">
<span class="target" id="structkr__request_1a2df6bf35b6e809cb5a84158185acd833"></span>const knot_rrset_t* <code class="descname">opt</code><a class="headerlink" href="#c.kr_request::opt" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::tcp">
<span class="target" id="structkr__request_1aa76ec8bad5eaa5a3ba0f9d187f434622"></span>bool <code class="descname">tcp</code><a class="headerlink" href="#c.kr_request::tcp" title="Permalink to this definition">¶</a></dt>
<dd><p>true if the request is on tcp; only meaningful if (dst_addr) </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::size">
<span class="target" id="structkr__request_1a519093e642431ee2ff289f6e2f87247c"></span>size_t <code class="descname">size</code><a class="headerlink" href="#c.kr_request::size" title="Permalink to this definition">¶</a></dt>
<dd><p>query packet size </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::qsource">
<span class="target" id="structkr__request_1a61b1ff67daf6dbc92096ad0cbb26d6ae"></span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a>::@5 <code class="descname">qsource</code><a class="headerlink" href="#c.kr_request::qsource" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::rtt">
<span class="target" id="structkr__request_1ae7969d61fd63ca91c2220b8dfa710530"></span>unsigned <code class="descname">rtt</code><a class="headerlink" href="#c.kr_request::rtt" title="Permalink to this definition">¶</a></dt>
<dd><p>Current upstream RTT. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::upstream">
<span class="target" id="structkr__request_1af5a2288edc595d175145aa6fb040ba00"></span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a>::@6 <code class="descname">upstream</code><a class="headerlink" href="#c.kr_request::upstream" title="Permalink to this definition">¶</a></dt>
<dd><p>Upstream information, valid only in consume() phase. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::options">
<span class="target" id="structkr__request_1a14e4b846d8b4fc7edba2ff5482223919"></span>struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a> <code class="descname">options</code><a class="headerlink" href="#c.kr_request::options" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::state">
<span class="target" id="structkr__request_1a139750113076d5897d2edb33964d5b01"></span>int <code class="descname">state</code><a class="headerlink" href="#c.kr_request::state" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::answ_selected">
<span class="target" id="structkr__request_1a06620608a098ed3e336e9ad0d0dcc6ed"></span>ranked_rr_array_t <code class="descname">answ_selected</code><a class="headerlink" href="#c.kr_request::answ_selected" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::auth_selected">
<span class="target" id="structkr__request_1a13bbfd8d8a15cbb063f0a31037e3828a"></span>ranked_rr_array_t <code class="descname">auth_selected</code><a class="headerlink" href="#c.kr_request::auth_selected" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::add_selected">
<span class="target" id="structkr__request_1a0556d387d7c51de714c0fc7b389e91ce"></span>ranked_rr_array_t <code class="descname">add_selected</code><a class="headerlink" href="#c.kr_request::add_selected" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::additional">
<span class="target" id="structkr__request_1abac5fb0bc2817475e3c00d2896e91e76"></span>rr_array_t <code class="descname">additional</code><a class="headerlink" href="#c.kr_request::additional" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::answ_validated">
<span class="target" id="structkr__request_1ac186d5d3a4acc316939b95f68b994ee2"></span>bool <code class="descname">answ_validated</code><a class="headerlink" href="#c.kr_request::answ_validated" title="Permalink to this definition">¶</a></dt>
<dd><p>internal to validator; beware of caching, etc. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::auth_validated">
<span class="target" id="structkr__request_1aa1e3f01f813418117a60aa780fe3976b"></span>bool <code class="descname">auth_validated</code><a class="headerlink" href="#c.kr_request::auth_validated" title="Permalink to this definition">¶</a></dt>
<dd><p>see answ_validated ^^ ; TODO </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::rplan">
<span class="target" id="structkr__request_1a90acfe0a82b405d2239bfa808e8c89c3"></span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> <code class="descname">rplan</code><a class="headerlink" href="#c.kr_request::rplan" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::has_tls">
<span class="target" id="structkr__request_1a08ecc99a0d3b78b1c47068af535dedde"></span>int <code class="descname">has_tls</code><a class="headerlink" href="#c.kr_request::has_tls" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_request::trace_log">
<span class="target" id="structkr__request_1a91f1bf153d888db8fef691f2a035e569"></span><a class="reference internal" href="#c.trace_log_f" title="trace_log_f">trace_log_f</a> <code class="descname">trace_log</code><a class="headerlink" href="#c.kr_request::trace_log" title="Permalink to this definition">¶</a></dt>
<dd><p>Logging tracepoint. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::trace_finish">
<span class="target" id="structkr__request_1a3826043816b60dc5c7fad223662f2c69"></span><a class="reference internal" href="#c.trace_callback_f" title="trace_callback_f">trace_callback_f</a> <code class="descname">trace_finish</code><a class="headerlink" href="#c.kr_request::trace_finish" title="Permalink to this definition">¶</a></dt>
<dd><p>Request finish tracepoint. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_request::pool">
<span class="target" id="structkr__request_1a1d788044af471ca773ef9c81bbc5cfc9"></span>knot_mm_t <code class="descname">pool</code><a class="headerlink" href="#c.kr_request::pool" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt id="c.kr_stale_cb">
<span class="target" id="rplan_8h_1a33f78bd9b6d3eac20d4c96f746318897"></span><em class="property">typedef </em>int32_t<code class="descname">(* kr_stale_cb)</code><span class="sig-paren">(</span>int32_t<em> ttl</em>, const knot_dname_t<em> *owner</em>, uint16_t<em> type</em>, const struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a><em> *qry</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_stale_cb" title="Permalink to this definition">¶</a></dt>
<dd><p>Callback for serve-stale decisions. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>the adjusted TTL (typically 1) or < 0. </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ttl</span></code>: the expired TTL (i.e. it’s < 0) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.kr_qflags_set">
<span class="target" id="rplan_8h_1a360932da0d600f59c37702d0d46cdb58"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_qflags_set</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a> *<em> fl1</em>, struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a><em> fl2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_qflags_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Combine flags together. </p>
<p>This means set union for simple flags. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_qflags_clear">
<span class="target" id="rplan_8h_1a8b8d62fcc53dea4d353c06be5159d80f"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_qflags_clear</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a> *<em> fl1</em>, struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a><em> fl2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_qflags_clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove flags. </p>
<p>This means set-theoretic difference. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_init">
<span class="target" id="rplan_8h_1aa41e1509c65a27b90825601ef65bf9c8"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_rplan_init</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em>, struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a> *<em> request</em>, knot_mm_t *<em> pool</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_init" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize resolution plan (empty). </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
<li><code class="docutils literal"><span class="pre">request</span></code>: resolution request </li>
<li><code class="docutils literal"><span class="pre">pool</span></code>: ephemeral memory pool for whole resolution </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_deinit">
<span class="target" id="rplan_8h_1a3b447fe567cf37117859024cecbe61c6"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_rplan_deinit</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_deinit" title="Permalink to this definition">¶</a></dt>
<dd><p>Deinitialize resolution plan, aborting any uncommited transactions. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_empty">
<span class="target" id="rplan_8h_1a010dae4f10287d31d12176e36bddfe8c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> bool <code class="descname">kr_rplan_empty</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_empty" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if the resolution plan is empty (i.e. </p>
<p>finished or initialized) <dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>true or false </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_push_empty">
<span class="target" id="rplan_8h_1a2e69dec46731e032c7da6bc94ff14d3a"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">kr_rplan_push_empty</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em>, struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> parent</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_push_empty" title="Permalink to this definition">¶</a></dt>
<dd><p>Push empty query to the top of the resolution plan. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This query serves as a cookie query only. </dd>
<dt><strong>Return</strong></dt>
<dd>query instance or NULL </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
<li><code class="docutils literal"><span class="pre">parent</span></code>: query parent (or NULL) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_push">
<span class="target" id="rplan_8h_1a5169725f627ae3f27cebdae70e51c6d4"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">kr_rplan_push</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em>, struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> parent</em>, const knot_dname_t *<em> name</em>, uint16_t<em> cls</em>, uint16_t<em> type</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_push" title="Permalink to this definition">¶</a></dt>
<dd><p>Push a query to the top of the resolution plan. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This means that this query takes precedence before all pending queries. </dd>
<dt><strong>Return</strong></dt>
<dd>query instance or NULL </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
<li><code class="docutils literal"><span class="pre">parent</span></code>: query parent (or NULL) </li>
<li><code class="docutils literal"><span class="pre">name</span></code>: resolved name </li>
<li><code class="docutils literal"><span class="pre">cls</span></code>: resolved class </li>
<li><code class="docutils literal"><span class="pre">type</span></code>: resolved type </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_pop">
<span class="target" id="rplan_8h_1a46a73971828a46c959d702d6d14f61bf"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_rplan_pop</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em>, struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> qry</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_pop" title="Permalink to this definition">¶</a></dt>
<dd><p>Pop existing query from the resolution plan. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>Popped queries are not discarded, but moved to the resolved list. </dd>
<dt><strong>Return</strong></dt>
<dd>0 or an error </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
<li><code class="docutils literal"><span class="pre">qry</span></code>: resolved query </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_satisfies">
<span class="target" id="rplan_8h_1a4571eabfb07e1494f56cc30c5ede67b8"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> bool <code class="descname">kr_rplan_satisfies</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> closure</em>, const knot_dname_t *<em> name</em>, uint16_t<em> cls</em>, uint16_t<em> type</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_satisfies" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if resolution chain satisfies given query. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_resolved">
<span class="target" id="rplan_8h_1ae2610a3007adabc2f94153dd4c7c8019"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">kr_rplan_resolved</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_resolved" title="Permalink to this definition">¶</a></dt>
<dd><p>Return last resolved query. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_last">
<span class="target" id="rplan_8h_1a3c6141760e2862969f343f4f3934521f"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">kr_rplan_last</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_last" title="Permalink to this definition">¶</a></dt>
<dd><p>Return last query (either currently being solved or last resolved). </p>
<p>This is necessary to retrieve the last query in case of resolution failures (e.g. time limit reached). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rplan_find_resolved">
<span class="target" id="rplan_8h_1a53a77f726b118ca544c00ac92bb80f03"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">kr_rplan_find_resolved</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_rplan" title="kr_rplan">kr_rplan</a> *<em> rplan</em>, struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> parent</em>, const knot_dname_t *<em> name</em>, uint16_t<em> cls</em>, uint16_t<em> type</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rplan_find_resolved" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if a given query already resolved. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>query instance or NULL </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">rplan</span></code>: plan instance </li>
<li><code class="docutils literal"><span class="pre">parent</span></code>: query parent (or NULL) </li>
<li><code class="docutils literal"><span class="pre">name</span></code>: resolved name </li>
<li><code class="docutils literal"><span class="pre">cls</span></code>: resolved class </li>
<li><code class="docutils literal"><span class="pre">type</span></code>: resolved type </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.kr_qflags">
<span class="target" id="structkr__qflags"></span><em class="property">struct </em><code class="descname">kr_qflags</code><a class="headerlink" href="#c.kr_qflags" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <rplan.h></em><p>Query flags. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_qflags::NO_MINIMIZE">
<span class="target" id="structkr__qflags_1afcc05c86d1992f4d4b112b94c75e3eb6"></span>bool <code class="descname">NO_MINIMIZE</code><a class="headerlink" href="#c.kr_qflags::NO_MINIMIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Don’t minimize QNAME. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::NO_THROTTLE">
<span class="target" id="structkr__qflags_1afeee84c46635b195a121c74ffbd14c25"></span>bool <code class="descname">NO_THROTTLE</code><a class="headerlink" href="#c.kr_qflags::NO_THROTTLE" title="Permalink to this definition">¶</a></dt>
<dd><p>No query/slow NS throttling. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::NO_IPV6">
<span class="target" id="structkr__qflags_1a9bde0a39e9c83d3b372ea011cd3fba79"></span>bool <code class="descname">NO_IPV6</code><a class="headerlink" href="#c.kr_qflags::NO_IPV6" title="Permalink to this definition">¶</a></dt>
<dd><p>Disable IPv6. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::NO_IPV4">
<span class="target" id="structkr__qflags_1a810a76ae736462fc8af9793ae3eca6a5"></span>bool <code class="descname">NO_IPV4</code><a class="headerlink" href="#c.kr_qflags::NO_IPV4" title="Permalink to this definition">¶</a></dt>
<dd><p>Disable IPv4. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::TCP">
<span class="target" id="structkr__qflags_1a80d916918b5cb31897cf7617040a5450"></span>bool <code class="descname">TCP</code><a class="headerlink" href="#c.kr_qflags::TCP" title="Permalink to this definition">¶</a></dt>
<dd><p>Use TCP for this query. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::RESOLVED">
<span class="target" id="structkr__qflags_1a4a2f7ee7240fafcb4723280d55fdea10"></span>bool <code class="descname">RESOLVED</code><a class="headerlink" href="#c.kr_qflags::RESOLVED" title="Permalink to this definition">¶</a></dt>
<dd><p>Query is resolved. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::AWAIT_IPV4">
<span class="target" id="structkr__qflags_1af4b8fdff4c69132b000e4340e6c1a023"></span>bool <code class="descname">AWAIT_IPV4</code><a class="headerlink" href="#c.kr_qflags::AWAIT_IPV4" title="Permalink to this definition">¶</a></dt>
<dd><p>Query is waiting for A address. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::AWAIT_IPV6">
<span class="target" id="structkr__qflags_1af0b93babdc7d448f8c7407dd4f4fd0eb"></span>bool <code class="descname">AWAIT_IPV6</code><a class="headerlink" href="#c.kr_qflags::AWAIT_IPV6" title="Permalink to this definition">¶</a></dt>
<dd><p>Query is waiting for AAAA address. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::AWAIT_CUT">
<span class="target" id="structkr__qflags_1a16e2b318f47a36c691ad815f94b495e7"></span>bool <code class="descname">AWAIT_CUT</code><a class="headerlink" href="#c.kr_qflags::AWAIT_CUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Query is waiting for zone cut lookup. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::SAFEMODE">
<span class="target" id="structkr__qflags_1ac14bd17501df60f66e32e230200fed8d"></span>bool <code class="descname">SAFEMODE</code><a class="headerlink" href="#c.kr_qflags::SAFEMODE" title="Permalink to this definition">¶</a></dt>
<dd><p>Don’t use fancy stuff (EDNS, 0x20, …) </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::CACHED">
<span class="target" id="structkr__qflags_1ad24a1ae75c2f5e9686b68bfd36710c81"></span>bool <code class="descname">CACHED</code><a class="headerlink" href="#c.kr_qflags::CACHED" title="Permalink to this definition">¶</a></dt>
<dd><p>Query response is cached. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::NO_CACHE">
<span class="target" id="structkr__qflags_1a673972928e17b17d7c5096047085ff5f"></span>bool <code class="descname">NO_CACHE</code><a class="headerlink" href="#c.kr_qflags::NO_CACHE" title="Permalink to this definition">¶</a></dt>
<dd><p>No cache for lookup; exception: finding NSs and subqueries. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::EXPIRING">
<span class="target" id="structkr__qflags_1a536b53dd0ae3a6fa236e12f434272dbc"></span>bool <code class="descname">EXPIRING</code><a class="headerlink" href="#c.kr_qflags::EXPIRING" title="Permalink to this definition">¶</a></dt>
<dd><p>Query response is cached, but expiring. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::ALLOW_LOCAL">
<span class="target" id="structkr__qflags_1adf376fc4a24c08c32141990f2903bd1e"></span>bool <code class="descname">ALLOW_LOCAL</code><a class="headerlink" href="#c.kr_qflags::ALLOW_LOCAL" title="Permalink to this definition">¶</a></dt>
<dd><p>Allow queries to local or private address ranges. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_WANT">
<span class="target" id="structkr__qflags_1a8158c4987c3d39ac71c0d866ffe87ae2"></span>bool <code class="descname">DNSSEC_WANT</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_WANT" title="Permalink to this definition">¶</a></dt>
<dd><p>Want DNSSEC secured answer; exception: +cd, i.e. </p>
<p>knot_wire_set_cd(request->answer->wire). </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_BOGUS">
<span class="target" id="structkr__qflags_1a8dcde56de17835b5759890740133b63b"></span>bool <code class="descname">DNSSEC_BOGUS</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_BOGUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Query response is DNSSEC bogus. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_INSECURE">
<span class="target" id="structkr__qflags_1a27833abf4c074118e120819a6038b373"></span>bool <code class="descname">DNSSEC_INSECURE</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_INSECURE" title="Permalink to this definition">¶</a></dt>
<dd><p>Query response is DNSSEC insecure. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_CD">
<span class="target" id="structkr__qflags_1a5d2b81e08bac1004b070e4f9ccffc109"></span>bool <code class="descname">DNSSEC_CD</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_CD" title="Permalink to this definition">¶</a></dt>
<dd><p>CD bit in query. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::STUB">
<span class="target" id="structkr__qflags_1acf7611260bbec84d227f635ffd6f1509"></span>bool <code class="descname">STUB</code><a class="headerlink" href="#c.kr_qflags::STUB" title="Permalink to this definition">¶</a></dt>
<dd><p>Stub resolution, accept received answer as solved. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::ALWAYS_CUT">
<span class="target" id="structkr__qflags_1a4c78b8773b74f2ec9f7c142dff3483b9"></span>bool <code class="descname">ALWAYS_CUT</code><a class="headerlink" href="#c.kr_qflags::ALWAYS_CUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Always recover zone cut (even if cached). </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_WEXPAND">
<span class="target" id="structkr__qflags_1aed0db83afd285a7790bdd6e60fbdf9c2"></span>bool <code class="descname">DNSSEC_WEXPAND</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_WEXPAND" title="Permalink to this definition">¶</a></dt>
<dd><p>Query response has wildcard expansion. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::PERMISSIVE">
<span class="target" id="structkr__qflags_1a6692f57fbc63ee32b85483d215049861"></span>bool <code class="descname">PERMISSIVE</code><a class="headerlink" href="#c.kr_qflags::PERMISSIVE" title="Permalink to this definition">¶</a></dt>
<dd><p>Permissive resolver mode. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::STRICT">
<span class="target" id="structkr__qflags_1a886b549898524c89121d7de32e7c9bd1"></span>bool <code class="descname">STRICT</code><a class="headerlink" href="#c.kr_qflags::STRICT" title="Permalink to this definition">¶</a></dt>
<dd><p>Strict resolver mode. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::BADCOOKIE_AGAIN">
<span class="target" id="structkr__qflags_1ac8ddb2db032dbcdb48d78d3f62a59d78"></span>bool <code class="descname">BADCOOKIE_AGAIN</code><a class="headerlink" href="#c.kr_qflags::BADCOOKIE_AGAIN" title="Permalink to this definition">¶</a></dt>
<dd><p>Query again because bad cookie returned. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::CNAME">
<span class="target" id="structkr__qflags_1a5d8e8f4e34f5e4bba3b1da6009526e2c"></span>bool <code class="descname">CNAME</code><a class="headerlink" href="#c.kr_qflags::CNAME" title="Permalink to this definition">¶</a></dt>
<dd><p>Query response contains CNAME in answer section. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::REORDER_RR">
<span class="target" id="structkr__qflags_1afa00bdaaabef50150084ac0d61b3da0a"></span>bool <code class="descname">REORDER_RR</code><a class="headerlink" href="#c.kr_qflags::REORDER_RR" title="Permalink to this definition">¶</a></dt>
<dd><p>Reorder cached RRs. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::TRACE">
<span class="target" id="structkr__qflags_1a6fc788769fed04705f68f8f9483df5ce"></span>bool <code class="descname">TRACE</code><a class="headerlink" href="#c.kr_qflags::TRACE" title="Permalink to this definition">¶</a></dt>
<dd><p>Log answer with kr_verbose_log(), unless -DNDEBUG. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::NO_0X20">
<span class="target" id="structkr__qflags_1ac7ec5c61beb2ac7d2971dc9bbaef5e27"></span>bool <code class="descname">NO_0X20</code><a class="headerlink" href="#c.kr_qflags::NO_0X20" title="Permalink to this definition">¶</a></dt>
<dd><p>Disable query case randomization . </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_NODS">
<span class="target" id="structkr__qflags_1acd5c39bee00096af67b30bb355af0195"></span>bool <code class="descname">DNSSEC_NODS</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_NODS" title="Permalink to this definition">¶</a></dt>
<dd><p>DS non-existance is proven. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNSSEC_OPTOUT">
<span class="target" id="structkr__qflags_1a8d0e7e9a97361ec871ae8a5ebc3960b1"></span>bool <code class="descname">DNSSEC_OPTOUT</code><a class="headerlink" href="#c.kr_qflags::DNSSEC_OPTOUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Closest encloser proof has optout. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::NONAUTH">
<span class="target" id="structkr__qflags_1abc061ac2664f3959b9f4820b424b871e"></span>bool <code class="descname">NONAUTH</code><a class="headerlink" href="#c.kr_qflags::NONAUTH" title="Permalink to this definition">¶</a></dt>
<dd><p>Non-authoritative in-bailiwick records are enough. </p>
<p>TODO: utilize this also outside cache. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::FORWARD">
<span class="target" id="structkr__qflags_1a919ea424cc3bf9beee0af53c393bbda0"></span>bool <code class="descname">FORWARD</code><a class="headerlink" href="#c.kr_qflags::FORWARD" title="Permalink to this definition">¶</a></dt>
<dd><p>Forward all queries to upstream; validate answers. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::DNS64_MARK">
<span class="target" id="structkr__qflags_1a1fafb4dd98807f78a4a6f04614fecf27"></span>bool <code class="descname">DNS64_MARK</code><a class="headerlink" href="#c.kr_qflags::DNS64_MARK" title="Permalink to this definition">¶</a></dt>
<dd><p>Internal mark for dns64 module. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_qflags::CACHE_TRIED">
<span class="target" id="structkr__qflags_1a14b8ac862abd988e1f3816383b10a840"></span>bool <code class="descname">CACHE_TRIED</code><a class="headerlink" href="#c.kr_qflags::CACHE_TRIED" title="Permalink to this definition">¶</a></dt>
<dd><p>Internal to cache module. </p>
</dd></dl>
</div>
</dd></dl>
<dl class="struct">
<dt id="c.kr_query">
<span class="target" id="structkr__query"></span><em class="property">struct </em><code class="descname">kr_query</code><a class="headerlink" href="#c.kr_query" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <rplan.h></em><p>Single query representation. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_query::parent">
<span class="target" id="structkr__query_1ac776350105351e21c98d6e5fcf2cada6"></span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">parent</code><a class="headerlink" href="#c.kr_query::parent" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::sname">
<span class="target" id="structkr__query_1ad80b692bc0d4dfc9fb82c8fc0bbbc58d"></span>knot_dname_t* <code class="descname">sname</code><a class="headerlink" href="#c.kr_query::sname" title="Permalink to this definition">¶</a></dt>
<dd><p>The name to resolve - lower-cased, uncompressed. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::stype">
<span class="target" id="structkr__query_1a1ccbe35400f7860c97e81b5f975a3fb8"></span>uint16_t <code class="descname">stype</code><a class="headerlink" href="#c.kr_query::stype" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::sclass">
<span class="target" id="structkr__query_1a46c2b5b863b628bedc6d66803e9b33f0"></span>uint16_t <code class="descname">sclass</code><a class="headerlink" href="#c.kr_query::sclass" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::id">
<span class="target" id="structkr__query_1a3b5d6c672199d4f497a37e9924ae3bc8"></span>uint16_t <code class="descname">id</code><a class="headerlink" href="#c.kr_query::id" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::forward_flags">
<span class="target" id="structkr__query_1acf4160ec64e5280556b42d95c17e815b"></span>struct <a class="reference internal" href="#c.kr_qflags" title="kr_qflags">kr_qflags</a> flags <code class="descname">forward_flags</code><a class="headerlink" href="#c.kr_query::forward_flags" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::secret">
<span class="target" id="structkr__query_1a6d5925cdca7144406feb9bdb77e10116"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">secret</code><a class="headerlink" href="#c.kr_query::secret" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::fails">
<span class="target" id="structkr__query_1a074537dfd8770bb434238751f2fa7edc"></span>uint16_t <code class="descname">fails</code><a class="headerlink" href="#c.kr_query::fails" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::reorder">
<span class="target" id="structkr__query_1a1c39989089fc02cfd2b536ca6360b3c3"></span>uint16_t <code class="descname">reorder</code><a class="headerlink" href="#c.kr_query::reorder" title="Permalink to this definition">¶</a></dt>
<dd><p>Seed to reorder (cached) RRs in answer or zero. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::creation_time_mono">
<span class="target" id="structkr__query_1abbc6053b8404c0a049c3a6704069443d"></span>uint64_t <code class="descname">creation_time_mono</code><a class="headerlink" href="#c.kr_query::creation_time_mono" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::timestamp_mono">
<span class="target" id="structkr__query_1a83f1ae97d97200a257364ef99051c8a8"></span>uint64_t <code class="descname">timestamp_mono</code><a class="headerlink" href="#c.kr_query::timestamp_mono" title="Permalink to this definition">¶</a></dt>
<dd><p>Time of query created or time of query to upstream resolver (milliseconds). </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::timestamp">
<span class="target" id="structkr__query_1aa579e1cfad50d40c844ba6679af2477b"></span>struct timeval <code class="descname">timestamp</code><a class="headerlink" href="#c.kr_query::timestamp" title="Permalink to this definition">¶</a></dt>
<dd><p>Real time for TTL+DNSSEC checks (.tv_sec only). </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::zone_cut">
<span class="target" id="structkr__query_1a7f024d87a3ef56e2b1a54d56ced7bbd2"></span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> <code class="descname">zone_cut</code><a class="headerlink" href="#c.kr_query::zone_cut" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::deferred">
<span class="target" id="structkr__query_1aa264b88ddce5486c12c896143b6de2bb"></span>struct kr_layer_pickle* <code class="descname">deferred</code><a class="headerlink" href="#c.kr_query::deferred" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_query::uid">
<span class="target" id="structkr__query_1a57db5485786f0d5c00a7bd50bb59b7ae"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">uid</code><a class="headerlink" href="#c.kr_query::uid" title="Permalink to this definition">¶</a></dt>
<dd><p>Query iteration number, unique within the <a class="reference internal" href="#structkr__rplan"><span class="std std-ref">kr_rplan</span></a>. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::cname_parent">
<span class="target" id="structkr__query_1a3fbadeafc34da97c56f6e159143bc96b"></span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a>* <code class="descname">cname_parent</code><a class="headerlink" href="#c.kr_query::cname_parent" title="Permalink to this definition">¶</a></dt>
<dd><p>Pointer to the query that originated this one because of following a CNAME (or NULL). </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::request">
<span class="target" id="structkr__query_1a612c7e9b0efb1189b2bd29c8e806099a"></span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a>* <code class="descname">request</code><a class="headerlink" href="#c.kr_query::request" title="Permalink to this definition">¶</a></dt>
<dd><p>Parent resolution request. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::stale_cb">
<span class="target" id="structkr__query_1a5a65865a15b27e22ef7d89da16c62a8d"></span><a class="reference internal" href="#c.kr_stale_cb" title="kr_stale_cb">kr_stale_cb</a> <code class="descname">stale_cb</code><a class="headerlink" href="#c.kr_query::stale_cb" title="Permalink to this definition">¶</a></dt>
<dd><p>See the type. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_query::ns">
<span class="target" id="structkr__query_1a83c214f041ccb5255d6bea8e080d2820"></span>struct <a class="reference internal" href="#c.kr_nsrep" title="kr_nsrep">kr_nsrep</a> <code class="descname">ns</code><a class="headerlink" href="#c.kr_query::ns" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
<dl class="struct">
<dt id="c.kr_rplan">
<span class="target" id="structkr__rplan"></span><em class="property">struct </em><code class="descname">kr_rplan</code><a class="headerlink" href="#c.kr_rplan" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <rplan.h></em><p>Query resolution plan structure. </p>
<p>The structure most importantly holds the original query, answer and the list of pending queries required to resolve the original query. It also keeps a notion of current zone cut. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_rplan::pending">
<span class="target" id="structkr__rplan_1a9eba643aa0ea8254ade652526ad5374c"></span>kr_qarray_t <code class="descname">pending</code><a class="headerlink" href="#c.kr_rplan::pending" title="Permalink to this definition">¶</a></dt>
<dd><p>List of pending queries. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_rplan::resolved">
<span class="target" id="structkr__rplan_1a19c342d8a7e0e70bfacb7e48fa416ea8"></span>kr_qarray_t <code class="descname">resolved</code><a class="headerlink" href="#c.kr_rplan::resolved" title="Permalink to this definition">¶</a></dt>
<dd><p>List of resolved queries. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_rplan::request">
<span class="target" id="structkr__rplan_1a63a8a3163685787e83c5e1dcd9f7d151"></span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a>* <code class="descname">request</code><a class="headerlink" href="#c.kr_rplan::request" title="Permalink to this definition">¶</a></dt>
<dd><p>Parent resolution request. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_rplan::pool">
<span class="target" id="structkr__rplan_1aedbf82eb2ac7be1250e4529198c7a380"></span>knot_mm_t* <code class="descname">pool</code><a class="headerlink" href="#c.kr_rplan::pool" title="Permalink to this definition">¶</a></dt>
<dd><p>Temporary memory pool. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_rplan::next_uid">
<span class="target" id="structkr__rplan_1a4ad955147ad5226e7b508415d4468ad4"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">next_uid</code><a class="headerlink" href="#c.kr_rplan::next_uid" title="Permalink to this definition">¶</a></dt>
<dd><p>Next value for <a class="reference internal" href="#structkr__query_1a57db5485786f0d5c00a7bd50bb59b7ae"><span class="std std-ref">kr_query::uid</span></a> (incremental). </p>
</dd></dl>
</div>
</dd></dl>
</div>
<div class="section" id="cache">
<span id="lib-api-cache"></span><h3><a class="toc-backref" href="#id2">Cache</a><a class="headerlink" href="#cache" title="Permalink to this headline">¶</a></h3>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.cache_peek">
<span class="target" id="api_8h_1a58cdf0b5c085730126e9df898aeaf441"></span>int <code class="descname">cache_peek</code><span class="sig-paren">(</span>kr_layer_t *<em> ctx</em>, knot_pkt_t *<em> pkt</em><span class="sig-paren">)</span><a class="headerlink" href="#c.cache_peek" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.cache_stash">
<span class="target" id="api_8h_1a857370ca377c0a219ed6bcd4a691c50e"></span>int <code class="descname">cache_stash</code><span class="sig-paren">(</span>kr_layer_t *<em> ctx</em>, knot_pkt_t *<em> pkt</em><span class="sig-paren">)</span><a class="headerlink" href="#c.cache_stash" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_cache_open">
<span class="target" id="api_8h_1a600d986af87edd6b5479e30811009fe9"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_cache_open</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em>, const struct kr_cdb_api *<em> api</em>, struct kr_cdb_opts *<em> opts</em>, knot_mm_t *<em> mm</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_open" title="Permalink to this definition">¶</a></dt>
<dd><p>Open/create cache with provided storage options. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cache</span></code>: cache structure to be initialized </li>
<li><code class="docutils literal"><span class="pre">api</span></code>: storage engine API </li>
<li><code class="docutils literal"><span class="pre">opts</span></code>: storage-specific options (may be NULL for default) </li>
<li><code class="docutils literal"><span class="pre">mm</span></code>: memory context. </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_cache_close">
<span class="target" id="api_8h_1a0546fe921f3faa8e0936836357995148"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_cache_close</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close persistent cache. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This doesn’t clear the data, just closes the connection to the database. </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cache</span></code>: structure </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_cache_sync">
<span class="target" id="api_8h_1a8f02ce114dc10e592e077166c3881723"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_cache_sync</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_sync" title="Permalink to this definition">¶</a></dt>
<dd><p>Run after a row of operations to release transaction/lock if needed. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_cache_is_open">
<span class="target" id="api_8h_1a1953f24ab0d46665f4ff7cb4bba5407b"></span>static bool <code class="descname">kr_cache_is_open</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_is_open" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if cache is open and enabled. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_cache_make_checkpoint">
<span class="target" id="api_8h_1aefb1b80da603834391d3a06d2028222a"></span>static void <code class="descname">kr_cache_make_checkpoint</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_make_checkpoint" title="Permalink to this definition">¶</a></dt>
<dd><p>(Re)set the time pair to the current values. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_cache_clear">
<span class="target" id="api_8h_1acde14bf99a3b567a3d2547671efd557c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_cache_clear</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clear all items from the cache. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an errcode </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cache</span></code>: cache structure </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_cache_peek_exact">
<span class="target" id="api_8h_1ab1bcd5fe8172d4d10029b5076260c2e3"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_cache_peek_exact</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a> *<em> cache</em>, const knot_dname_t *<em> name</em>, uint16_t<em> type</em>, struct <a class="reference internal" href="#c.kr_cache_p" title="kr_cache_p">kr_cache_p</a> *<em> peek</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_peek_exact" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_cache_ttl">
<span class="target" id="api_8h_1a0d757cb94680a2c8a394e1eaea102652"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int32_t <code class="descname">kr_cache_ttl</code><span class="sig-paren">(</span>const struct <a class="reference internal" href="#c.kr_cache_p" title="kr_cache_p">kr_cache_p</a> *<em> peek</em>, const struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> qry</em>, const knot_dname_t *<em> name</em>, uint16_t<em> type</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_ttl" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_cache_materialize">
<span class="target" id="api_8h_1a1894c892218876170038118d684fa7e2"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_cache_materialize</code><span class="sig-paren">(</span>knot_rdataset_t *<em> dst</em>, const struct <a class="reference internal" href="#c.kr_cache_p" title="kr_cache_p">kr_cache_p</a> *<em> ref</em>, <a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a><em> new_ttl</em>, knot_mm_t *<em> pool</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_cache_materialize" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Variables</p>
<dl class="variable">
<dt id="c.PKT_SIZE_NOWIRE">
<span class="target" id="api_8h_1ad72ebde9baaaf82f3fa3134700fc51f6"></span>const size_t <code class="descname">PKT_SIZE_NOWIRE</code> = -1<a class="headerlink" href="#c.PKT_SIZE_NOWIRE" title="Permalink to this definition">¶</a></dt>
<dd><p>When knot_pkt is passed from cache without ->wire, this is the ->size. </p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.kr_cache">
<span class="target" id="structkr__cache"></span><em class="property">struct </em><code class="descname">kr_cache</code><a class="headerlink" href="#c.kr_cache" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <api.h></em><p>Cache structure, keeps API, instance and metadata. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_cache::db">
<span class="target" id="structkr__cache_1a9d863a8c0f33927425ce7000e29b8377"></span>knot_db_t* <code class="descname">db</code><a class="headerlink" href="#c.kr_cache::db" title="Permalink to this definition">¶</a></dt>
<dd><p>Storage instance. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::api">
<span class="target" id="structkr__cache_1ad255526a75926bf3ca14655ddd4efc39"></span>const struct kr_cdb_api* <code class="descname">api</code><a class="headerlink" href="#c.kr_cache::api" title="Permalink to this definition">¶</a></dt>
<dd><p>Storage engine. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::hit">
<span class="target" id="structkr__cache_1a1fa0ca52ca3d26f0168f65462cc4e5e4"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">hit</code><a class="headerlink" href="#c.kr_cache::hit" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of cache hits. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::miss">
<span class="target" id="structkr__cache_1a9fd17a88c568c96c366276318ddbc1f4"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">miss</code><a class="headerlink" href="#c.kr_cache::miss" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of cache misses. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::insert">
<span class="target" id="structkr__cache_1a1a7cb2cf99fd80353e448214a4cb68c6"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">insert</code><a class="headerlink" href="#c.kr_cache::insert" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of insertions. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::delete">
<span class="target" id="structkr__cache_1a5e8466e9d4375db268b165ad117e3831"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">delete</code><a class="headerlink" href="#c.kr_cache::delete" title="Permalink to this definition">¶</a></dt>
<dd><p>Number of deletions. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::stats">
<span class="target" id="structkr__cache_1a04a1d73a191d450b15db80e19c1dc8e1"></span>struct <a class="reference internal" href="#c.kr_cache" title="kr_cache">kr_cache</a>::@0 <code class="descname">stats</code><a class="headerlink" href="#c.kr_cache::stats" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_cache::ttl_min">
<span class="target" id="structkr__cache_1aded871294a1bdb2169b9ade4c98923a7"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">ttl_min</code><a class="headerlink" href="#c.kr_cache::ttl_min" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_cache::ttl_max">
<span class="target" id="structkr__cache_1afca01ffff824c142f0ef62a54c8d4632"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">ttl_max</code><a class="headerlink" href="#c.kr_cache::ttl_max" title="Permalink to this definition">¶</a></dt>
<dd><p>TTL limits. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::checkpoint_walltime">
<span class="target" id="structkr__cache_1ac034ee636e442e75cec7975a8ba7e75a"></span>struct timeval <code class="descname">checkpoint_walltime</code><a class="headerlink" href="#c.kr_cache::checkpoint_walltime" title="Permalink to this definition">¶</a></dt>
<dd><p>Wall time on the last check-point. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache::checkpoint_monotime">
<span class="target" id="structkr__cache_1acb60501dfd51291b29b8a0707d25171a"></span>uint64_t <code class="descname">checkpoint_monotime</code><a class="headerlink" href="#c.kr_cache::checkpoint_monotime" title="Permalink to this definition">¶</a></dt>
<dd><p>Monotonic milliseconds on the last check-point. </p>
</dd></dl>
</div>
</dd></dl>
<dl class="struct">
<dt id="c.kr_cache_p">
<span class="target" id="structkr__cache__p"></span><em class="property">struct </em><code class="descname">kr_cache_p</code><a class="headerlink" href="#c.kr_cache_p" title="Permalink to this definition">¶</a></dt>
<dd><div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_cache_p::time">
<span class="target" id="structkr__cache__p_1adfe1e6b3a9412b6b231af0dd3e202d04"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">time</code><a class="headerlink" href="#c.kr_cache_p::time" title="Permalink to this definition">¶</a></dt>
<dd><p>The time of inception. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache_p::ttl">
<span class="target" id="structkr__cache__p_1ab057033661c1f604eed203850316b1f4"></span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">ttl</code><a class="headerlink" href="#c.kr_cache_p::ttl" title="Permalink to this definition">¶</a></dt>
<dd><p>TTL at inception moment. </p>
<p>Assuming it fits into int32_t ATM. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache_p::rank">
<span class="target" id="structkr__cache__p_1ac5e35f83266006804e8138298811f476"></span>uint8_t <code class="descname">rank</code><a class="headerlink" href="#c.kr_cache_p::rank" title="Permalink to this definition">¶</a></dt>
<dd><p>See enum kr_rank. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_cache_p::raw_data">
<span class="target" id="structkr__cache__p_1a2cf4da0865c7706690d68238628b5261"></span>void* <code class="descname">raw_data</code><a class="headerlink" href="#c.kr_cache_p::raw_data" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_cache_p::raw_bound">
<span class="target" id="structkr__cache__p_1a6e3ff150cfd81032d8d9e2ed82239be1"></span>void * <code class="descname">raw_bound</code><a class="headerlink" href="#c.kr_cache_p::raw_bound" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.2">
<span class="target" id="structkr__cache__p_1af5a0af882523fa8a1243fe4204e0cf9d"></span>struct <a class="reference internal" href="#c.kr_cache_p" title="kr_cache_p">kr_cache_p</a>::@1 <a class="reference internal" href="#c.kr_cache_p" title="kr_cache_p">kr_cache_p</a>::@<code class="descname">2</code><a class="headerlink" href="#c.2" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
</div>
<div class="section" id="nameservers">
<span id="lib-api-nameservers"></span><h3><a class="toc-backref" href="#id3">Nameservers</a><a class="headerlink" href="#nameservers" title="Permalink to this headline">¶</a></h3>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.KR_NSREP_MAXADDR">
<span class="target" id="nsrep_8h_1a21b730c52769dcb4b41fdbec8c13f31e"></span><code class="descname">KR_NSREP_MAXADDR</code><a class="headerlink" href="#c.KR_NSREP_MAXADDR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Enums</p>
<dl class="enum">
<dt id="c.kr_ns_score">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3"></span><em class="property">enum </em><code class="descname">kr_ns_score</code><a class="headerlink" href="#c.kr_ns_score" title="Permalink to this definition">¶</a></dt>
<dd><p>NS RTT score (special values). </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>RTT is measured in milliseconds. </dd>
</dl>
</p>
<p><em>Values:</em></p>
<dl class="enumvalue">
<dt id="c.KR_NS_MAX_SCORE">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3a38e3321fcb1c2f049d451b204743d596"></span><code class="descname">KR_NS_MAX_SCORE</code> = KR_CONN_RTT_MAX<a class="headerlink" href="#c.KR_NS_MAX_SCORE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_TIMEOUT">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3a39db1585d1225ce0246d58ba0a2dae77"></span><code class="descname">KR_NS_TIMEOUT</code> = (95 * KR_NS_MAX_SCORE) / 100<a class="headerlink" href="#c.KR_NS_TIMEOUT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_LONG">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3a47c5db44f985aa54ce839a5f1bacb493"></span><code class="descname">KR_NS_LONG</code> = (3 * KR_NS_TIMEOUT) / 4<a class="headerlink" href="#c.KR_NS_LONG" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_UNKNOWN">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3a018abaa68bd13c5a4c2da22768311e3b"></span><code class="descname">KR_NS_UNKNOWN</code> = KR_NS_TIMEOUT / 2<a class="headerlink" href="#c.KR_NS_UNKNOWN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_PENALTY">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3a3dcfabbfa538cb48de1dd176b6007966"></span><code class="descname">KR_NS_PENALTY</code> = 100<a class="headerlink" href="#c.KR_NS_PENALTY" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_GLUED">
<span class="target" id="nsrep_8h_1a7c53a8d1eff2587db087e72244f5ffb3afef6e8effecf7b2b0d02757a656ffd2f"></span><code class="descname">KR_NS_GLUED</code> = 10<a class="headerlink" href="#c.KR_NS_GLUED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="enum">
<dt id="c.kr_ns_rep">
<span class="target" id="nsrep_8h_1aa757c6b4c986d7283b390815ae130c25"></span><em class="property">enum </em><code class="descname">kr_ns_rep</code><a class="headerlink" href="#c.kr_ns_rep" title="Permalink to this definition">¶</a></dt>
<dd><p>NS QoS flags. </p>
<p><em>Values:</em></p>
<dl class="enumvalue">
<dt id="c.KR_NS_NOIP4">
<span class="target" id="nsrep_8h_1aa757c6b4c986d7283b390815ae130c25a02a6ee61cc29e20d343d4d1cf9cb584e"></span><code class="descname">KR_NS_NOIP4</code> = 1 << 0<a class="headerlink" href="#c.KR_NS_NOIP4" title="Permalink to this definition">¶</a></dt>
<dd><p>NS has no IPv4. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_NOIP6">
<span class="target" id="nsrep_8h_1aa757c6b4c986d7283b390815ae130c25aaafdc24928057219958c0b8ada49aad8"></span><code class="descname">KR_NS_NOIP6</code> = 1 << 1<a class="headerlink" href="#c.KR_NS_NOIP6" title="Permalink to this definition">¶</a></dt>
<dd><p>NS has no IPv6. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_NOEDNS">
<span class="target" id="nsrep_8h_1aa757c6b4c986d7283b390815ae130c25a0dba5d53047b800910408aa917644e73"></span><code class="descname">KR_NS_NOEDNS</code> = 1 << 2<a class="headerlink" href="#c.KR_NS_NOEDNS" title="Permalink to this definition">¶</a></dt>
<dd><p>NS has no EDNS support. </p>
</dd></dl>
</dd></dl>
<dl class="enum">
<dt id="c.kr_ns_update_mode">
<span class="target" id="nsrep_8h_1aef3c779ee2542f416cb8479612b0eba0"></span><em class="property">enum </em><code class="descname">kr_ns_update_mode</code><a class="headerlink" href="#c.kr_ns_update_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>NS RTT update modes. </p>
<p><em>Values:</em></p>
<dl class="enumvalue">
<dt id="c.KR_NS_UPDATE">
<span class="target" id="nsrep_8h_1aef3c779ee2542f416cb8479612b0eba0a9c4ecea982417e2103e673e8d18adcdb"></span><code class="descname">KR_NS_UPDATE</code> = 0<a class="headerlink" href="#c.KR_NS_UPDATE" title="Permalink to this definition">¶</a></dt>
<dd><p>Update as smooth over last two measurements. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_RESET">
<span class="target" id="nsrep_8h_1aef3c779ee2542f416cb8479612b0eba0a796424beb4a0d9c402f38a421119fb67"></span><code class="descname">KR_NS_RESET</code><a class="headerlink" href="#c.KR_NS_RESET" title="Permalink to this definition">¶</a></dt>
<dd><p>Set to given value. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_ADD">
<span class="target" id="nsrep_8h_1aef3c779ee2542f416cb8479612b0eba0acae9c2d724140111217695e05c568e1f"></span><code class="descname">KR_NS_ADD</code><a class="headerlink" href="#c.KR_NS_ADD" title="Permalink to this definition">¶</a></dt>
<dd><p>Increment current value. </p>
</dd></dl>
<dl class="enumvalue">
<dt id="c.KR_NS_MAX">
<span class="target" id="nsrep_8h_1aef3c779ee2542f416cb8479612b0eba0a6ae880cdb4965d91034f4abff45b10d5"></span><code class="descname">KR_NS_MAX</code><a class="headerlink" href="#c.KR_NS_MAX" title="Permalink to this definition">¶</a></dt>
<dd><p>Set to maximum of current/proposed value. </p>
</dd></dl>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.lru_t">
<span class="target" id="nsrep_8h_1a35edad92fcb667f8287d9b4b7bda814e"></span>typedef <code class="descname">lru_t</code><span class="sig-paren">(</span>unsigned<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_t" title="Permalink to this definition">¶</a></dt>
<dd><p>NS reputation/QoS tracking. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_set">
<span class="target" id="nsrep_8h_1a751c73e71e7f58dc5b6f1cce655f377c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_nsrep_set</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> qry</em>, size_t<em> index</em>, const struct sockaddr *<em> sock</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Set given NS address. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">qry</span></code>: updated query </li>
<li><code class="docutils literal"><span class="pre">index</span></code>: index of the updated target </li>
<li><code class="docutils literal"><span class="pre">sock</span></code>: socket address to use (sockaddr_in or sockaddr_in6 or NULL) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_elect">
<span class="target" id="nsrep_8h_1a42c781290f750832569c0d0286cabbe0"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_nsrep_elect</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> qry</em>, struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a> *<em> ctx</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_elect" title="Permalink to this definition">¶</a></dt>
<dd><p>Elect best nameserver/address pair from the nsset. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">qry</span></code>: updated query </li>
<li><code class="docutils literal"><span class="pre">ctx</span></code>: resolution context </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_elect_addr">
<span class="target" id="nsrep_8h_1a1b225bbcf7c7de86dedf7c0fddb43cfe"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_nsrep_elect_addr</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> qry</em>, struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a> *<em> ctx</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_elect_addr" title="Permalink to this definition">¶</a></dt>
<dd><p>Elect best nameserver/address pair from the nsset. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">qry</span></code>: updated query </li>
<li><code class="docutils literal"><span class="pre">ctx</span></code>: resolution context </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_update_rtt">
<span class="target" id="nsrep_8h_1a198a47bcdba52de3e3e071520a19ce0c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_nsrep_update_rtt</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_nsrep" title="kr_nsrep">kr_nsrep</a> *<em> ns</em>, const struct sockaddr *<em> addr</em>, unsigned<em> score</em>, kr_nsrep_lru_t *<em> cache</em>, int<em> umode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_update_rtt" title="Permalink to this definition">¶</a></dt>
<dd><p>Update NS address RTT information. </p>
<p>In KR_NS_UPDATE mode reputation is smoothed over last N measurements.</p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 on success, error code on failure </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ns</span></code>: updated NS representation </li>
<li><code class="docutils literal"><span class="pre">addr</span></code>: chosen address (NULL for first) </li>
<li><code class="docutils literal"><span class="pre">score</span></code>: new score (i.e. RTT), see enum kr_ns_score </li>
<li><code class="docutils literal"><span class="pre">cache</span></code>: LRU cache </li>
<li><code class="docutils literal"><span class="pre">umode</span></code>: update mode (KR_NS_UPDATE or KR_NS_RESET or KR_NS_ADD) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_update_rep">
<span class="target" id="nsrep_8h_1a4b599496766dad83827b0babf7daa950"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_nsrep_update_rep</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_nsrep" title="kr_nsrep">kr_nsrep</a> *<em> ns</em>, unsigned<em> reputation</em>, kr_nsrep_lru_t *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_update_rep" title="Permalink to this definition">¶</a></dt>
<dd><p>Update NSSET reputation information. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 on success, error code on failure </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ns</span></code>: updated NS representation </li>
<li><code class="docutils literal"><span class="pre">reputation</span></code>: combined reputation flags, see enum kr_ns_rep </li>
<li><code class="docutils literal"><span class="pre">cache</span></code>: LRU cache </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_copy_set">
<span class="target" id="nsrep_8h_1aad18facad28535236a09d5d1d6e14cea"></span>int <code class="descname">kr_nsrep_copy_set</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_nsrep" title="kr_nsrep">kr_nsrep</a> *<em> dst</em>, const struct <a class="reference internal" href="#c.kr_nsrep" title="kr_nsrep">kr_nsrep</a> *<em> src</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_copy_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Copy NSSET reputation information and resets score. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 on success, error code on failure </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">dst</span></code>: updated NS representation </li>
<li><code class="docutils literal"><span class="pre">src</span></code>: source NS representation </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_nsrep_sort">
<span class="target" id="nsrep_8h_1a604784af3d1b10f1e769ae4f5fc970a3"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_nsrep_sort</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_nsrep" title="kr_nsrep">kr_nsrep</a> *<em> ns</em>, kr_nsrep_lru_t *<em> cache</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_nsrep_sort" title="Permalink to this definition">¶</a></dt>
<dd><p>Sort addresses in the query nsrep list. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Note</strong></dt>
<dd>ns reputation is zeroed, as KR_NS_NOIP{4,6} flags are useless in STUB/FORWARD mode. </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ns</span></code>: updated <a class="reference internal" href="#structkr__nsrep"><span class="std std-ref">kr_nsrep</span></a> </li>
<li><code class="docutils literal"><span class="pre">cache</span></code>: RTT cache </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.kr_nsrep">
<span class="target" id="structkr__nsrep"></span><em class="property">struct </em><code class="descname">kr_nsrep</code><a class="headerlink" href="#c.kr_nsrep" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <nsrep.h></em><p>Name server representation. </p>
<p>Contains extra information about the name server, e.g. score or other metadata. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_nsrep::score">
<span class="target" id="structkr__nsrep_1a2a01a3c1dbfad9d1644a0474596ca0cf"></span>unsigned <code class="descname">score</code><a class="headerlink" href="#c.kr_nsrep::score" title="Permalink to this definition">¶</a></dt>
<dd><p>NS score. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_nsrep::reputation">
<span class="target" id="structkr__nsrep_1a68db62a91f02d59475fbea8cb692c856"></span>unsigned <code class="descname">reputation</code><a class="headerlink" href="#c.kr_nsrep::reputation" title="Permalink to this definition">¶</a></dt>
<dd><p>NS reputation. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_nsrep::name">
<span class="target" id="structkr__nsrep_1ac492b4528578e3e1416afc5c927b7ca2"></span>const knot_dname_t* <code class="descname">name</code><a class="headerlink" href="#c.kr_nsrep::name" title="Permalink to this definition">¶</a></dt>
<dd><p>NS name. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_nsrep::ctx">
<span class="target" id="structkr__nsrep_1ad0c6dafecff3df9fd5da6aa2fadf7667"></span>struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a>* <code class="descname">ctx</code><a class="headerlink" href="#c.kr_nsrep::ctx" title="Permalink to this definition">¶</a></dt>
<dd><p>Resolution context. </p>
</dd></dl>
<dl class="variable">
<dt>
<span class="target" id="structkr__nsrep_1a33d4eec60bc38de851cc1a26b1b9c049"></span><code class="descname">union inaddr kr_nsrep::addr[KR_NSREP_MAXADDR]</code></dt>
<dd><p>NS address(es) </p>
</dd></dl>
</div>
</dd></dl>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.kr_zonecut_init">
<span class="target" id="zonecut_8h_1af9073ed26fea05ff30d5d9410c395492"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_init</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> name</em>, knot_mm_t *<em> pool</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_init" title="Permalink to this definition">¶</a></dt>
<dd><p>Populate root zone cut with SBELT. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: zone cut </li>
<li><code class="docutils literal"><span class="pre">name</span></code>: </li>
<li><code class="docutils literal"><span class="pre">pool</span></code>: </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_deinit">
<span class="target" id="zonecut_8h_1a946bae029b42d53fa551f0b96f5b83a4"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_zonecut_deinit</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_deinit" title="Permalink to this definition">¶</a></dt>
<dd><p>Clear the structure and free the address set. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: zone cut </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_set">
<span class="target" id="zonecut_8h_1abd55befb5ff91926335721b9442344ef"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_zonecut_set</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset zone cut to given name and clear address list. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This clears the address list even if the name doesn’t change. TA and DNSKEY don’t change. </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: zone cut to be set </li>
<li><code class="docutils literal"><span class="pre">name</span></code>: new zone cut name </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_copy">
<span class="target" id="zonecut_8h_1aa0daf244fcc4e2a38de03e0577655c0c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_copy</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> dst</em>, const struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> src</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Copy zone cut, including all data. </p>
<p>Does not copy keys and trust anchor. <dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">dst</span></code>: destination zone cut </li>
<li><code class="docutils literal"><span class="pre">src</span></code>: source zone cut </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_copy_trust">
<span class="target" id="zonecut_8h_1ad5dad8dfed1a42e0e4f3ad644f84c70a"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_copy_trust</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> dst</em>, const struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> src</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_copy_trust" title="Permalink to this definition">¶</a></dt>
<dd><p>Copy zone trust anchor and keys. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">dst</span></code>: destination zone cut </li>
<li><code class="docutils literal"><span class="pre">src</span></code>: source zone cut </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_add">
<span class="target" id="zonecut_8h_1aa9f9de3661b90762013f05afc5aa687d"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_add</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> ns</em>, const knot_rdata_t *<em> rdata</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_add" title="Permalink to this definition">¶</a></dt>
<dd><p>Add address record to the zone cut. </p>
<p>The record will be merged with existing data, it may be either A/AAAA type.</p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: zone cut to be populated </li>
<li><code class="docutils literal"><span class="pre">ns</span></code>: nameserver name </li>
<li><code class="docutils literal"><span class="pre">rdata</span></code>: nameserver address (as rdata) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_del">
<span class="target" id="zonecut_8h_1aedcbb9db772da22a1fd483070dd4731b"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_del</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> ns</em>, const knot_rdata_t *<em> rdata</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_del" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete nameserver/address pair from the zone cut. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: </li>
<li><code class="docutils literal"><span class="pre">ns</span></code>: name server name </li>
<li><code class="docutils literal"><span class="pre">rdata</span></code>: name server address </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_del_all">
<span class="target" id="zonecut_8h_1ace3ffa748e0083d004b458706392bdef"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_del_all</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> ns</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_del_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete all addresses associated with the given name. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: </li>
<li><code class="docutils literal"><span class="pre">ns</span></code>: name server name </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_find">
<span class="target" id="zonecut_8h_1a42bab9bcb58b4609bbf0d5aeb8e53f24"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> pack_t* <code class="descname">kr_zonecut_find</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> ns</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_find" title="Permalink to this definition">¶</a></dt>
<dd><p>Find nameserver address list in the zone cut. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>This can be used for membership test, a non-null pack is returned if the nameserver name exists.</dd>
<dt><strong>Return</strong></dt>
<dd>pack of addresses or NULL </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">cut</span></code>: </li>
<li><code class="docutils literal"><span class="pre">ns</span></code>: name server name </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_set_sbelt">
<span class="target" id="zonecut_8h_1a8659e251ff4984601f33d0082dc779f1"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_set_sbelt</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a> *<em> ctx</em>, struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_set_sbelt" title="Permalink to this definition">¶</a></dt>
<dd><p>Populate zone cut with a root zone using SBELT :rfc:<code class="docutils literal"><span class="pre">1034</span></code> </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or error code </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ctx</span></code>: resolution context (to fetch root hints) </li>
<li><code class="docutils literal"><span class="pre">cut</span></code>: zone cut to be populated </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_zonecut_find_cached">
<span class="target" id="zonecut_8h_1a5449f6528fab1321e1bf24fa41e92045"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_zonecut_find_cached</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a> *<em> ctx</em>, struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a> *<em> cut</em>, const knot_dname_t *<em> name</em>, const struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a> *<em> qry</em>, bool *restrict<em> secured</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_zonecut_find_cached" title="Permalink to this definition">¶</a></dt>
<dd><p>Populate zone cut address set from cache. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or error code (ENOENT if it doesn’t find anything) </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ctx</span></code>: resolution context (to fetch data from LRU caches) </li>
<li><code class="docutils literal"><span class="pre">cut</span></code>: zone cut to be populated </li>
<li><code class="docutils literal"><span class="pre">name</span></code>: QNAME to start finding zone cut for </li>
<li><code class="docutils literal"><span class="pre">qry</span></code>: query for timestamp and stale-serving decisions </li>
<li><code class="docutils literal"><span class="pre">secured</span></code>: set to true if want secured zone cut, will return false if it is provably insecure </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.kr_zonecut">
<span class="target" id="structkr__zonecut"></span><em class="property">struct </em><code class="descname">kr_zonecut</code><a class="headerlink" href="#c.kr_zonecut" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <zonecut.h></em><p>Current zone cut representation. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_zonecut::name">
<span class="target" id="structkr__zonecut_1ae9c772751af0a78be3d2a6828b1be213"></span>knot_dname_t* <code class="descname">name</code><a class="headerlink" href="#c.kr_zonecut::name" title="Permalink to this definition">¶</a></dt>
<dd><p>Zone cut name. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_zonecut::key">
<span class="target" id="structkr__zonecut_1a276255dd2d2e8cb19e906a21d6729bad"></span>knot_rrset_t* <code class="descname">key</code><a class="headerlink" href="#c.kr_zonecut::key" title="Permalink to this definition">¶</a></dt>
<dd><p>Zone cut DNSKEY. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_zonecut::trust_anchor">
<span class="target" id="structkr__zonecut_1ae84c1e737a2351aec800510fa29d1f1a"></span>knot_rrset_t* <code class="descname">trust_anchor</code><a class="headerlink" href="#c.kr_zonecut::trust_anchor" title="Permalink to this definition">¶</a></dt>
<dd><p>Current trust anchor. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_zonecut::parent">
<span class="target" id="structkr__zonecut_1ae3a6ad1cfd21e2f632cbf12356437839"></span>struct <a class="reference internal" href="#c.kr_zonecut" title="kr_zonecut">kr_zonecut</a>* <code class="descname">parent</code><a class="headerlink" href="#c.kr_zonecut::parent" title="Permalink to this definition">¶</a></dt>
<dd><p>Parent zone cut. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_zonecut::nsset">
<span class="target" id="structkr__zonecut_1a543a73d0b3ae2649a9001605df06d56c"></span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> <code class="descname">nsset</code><a class="headerlink" href="#c.kr_zonecut::nsset" title="Permalink to this definition">¶</a></dt>
<dd><p>Map of nameserver => address_set. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_zonecut::pool">
<span class="target" id="structkr__zonecut_1a0655819a68c9ed462e9930c0aba5f7af"></span>knot_mm_t* <code class="descname">pool</code><a class="headerlink" href="#c.kr_zonecut::pool" title="Permalink to this definition">¶</a></dt>
<dd><p>Memory pool. </p>
</dd></dl>
</div>
</dd></dl>
</div>
<div class="section" id="modules">
<span id="lib-api-modules"></span><h3><a class="toc-backref" href="#id4">Modules</a><a class="headerlink" href="#modules" title="Permalink to this headline">¶</a></h3>
<p>Module API definition and functions for (un)loading modules. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.KR_MODULE_EXPORT">
<span class="target" id="module_8h_1a83eb0125e1f3cf199aea559045c0e9d4"></span><code class="descname">KR_MODULE_EXPORT</code><span class="sig-paren">(</span>module<span class="sig-paren">)</span><a class="headerlink" href="#c.KR_MODULE_EXPORT" title="Permalink to this definition">¶</a></dt>
<dd><p>Export module API version (place this at the end of your module). </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">module</span></code>: module name (f.e. hints) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.KR_MODULE_API">
<span class="target" id="module_8h_1ac4927a992628fb963ea53080cb0a11e9"></span><code class="descname">KR_MODULE_API</code><a class="headerlink" href="#c.KR_MODULE_API" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt id="c.uint32_t">
<span class="target" id="module_8h_1a2ecde19af200fa2fd29c75318c670f50"></span><em class="property">typedef </em><code class="descname">uint32_t</code><span class="sig-paren">(</span>)<em> module_api_cb(void</em><span class="sig-paren">)</span><a class="headerlink" href="#c.uint32_t" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="typedef">
<dt>
<span class="target" id="module_8h_1a4ffc64ffa526196f2f841effaefe50fd"></span><em class="property">typedef </em><code class="descname">char*() kr_prop_cb(void *env, struct kr_module *self, const char *input)</code></dt>
<dd><p>Module property callback. </p>
<p>Input and output is passed via a JSON encoded in a string.</p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>a free-form JSON output (malloc-ated) </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">env</span></code>: pointer to the lua engine, i.e. struct engine *env (TODO: explicit type) </li>
<li><code class="docutils literal"><span class="pre">input</span></code>: parameter (NULL if missing/nil on lua level) </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.kr_module_load">
<span class="target" id="module_8h_1ad6a30e0b48fc7afa54838a2735b3190b"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_module_load</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a> *<em> module</em>, const char *<em> name</em>, const char *<em> path</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module_load" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a C module instance into memory. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 or an error </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">module</span></code>: module structure </li>
<li><code class="docutils literal"><span class="pre">name</span></code>: module name </li>
<li><code class="docutils literal"><span class="pre">path</span></code>: module search path </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_module_unload">
<span class="target" id="module_8h_1a9b67a9aebbd1cd8f5eacf3066e795e69"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_module_unload</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a> *<em> module</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module_unload" title="Permalink to this definition">¶</a></dt>
<dd><p>Unload module instance. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">module</span></code>: module structure </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_module_embedded">
<span class="target" id="module_8h_1a12102bc22458015a452cffbe4b5cbb65"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> const struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a>* <code class="descname">kr_module_embedded</code><span class="sig-paren">(</span>const char *<em> name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module_embedded" title="Permalink to this definition">¶</a></dt>
<dd><p>Get embedded module prototype by name (or NULL). </p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.kr_module">
<span class="target" id="structkr__module"></span><em class="property">struct </em><code class="descname">kr_module</code><a class="headerlink" href="#c.kr_module" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <module.h></em><p>Module representation. </p>
<p>The five symbols (init, …) may be defined by the module as name_init(), etc; all are optional and missing symbols are represented as NULLs; </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_module::name">
<span class="target" id="structkr__module_1ad785970a36963165092eaa61834cc03f"></span>char* <code class="descname">name</code><a class="headerlink" href="#c.kr_module::name" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_module::init">
<span class="target" id="structkr__module_1abe7be4d2b15f869cf59f3bacc47fa1bd"></span>int<code class="descname">init)</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a><em> *self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module::init" title="Permalink to this definition">¶</a></dt>
<dd><p>Constructor. </p>
<p>Called after loading the module. <dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>error code. </dd>
</dl>
</p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_module::deinit">
<span class="target" id="structkr__module_1af4e79464b525a7b95ec422edfded7076"></span>int<code class="descname">deinit)</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a><em> *self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module::deinit" title="Permalink to this definition">¶</a></dt>
<dd><p>Destructor. </p>
<p>Called before unloading the module. <dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>error code. </dd>
</dl>
</p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_module::config">
<span class="target" id="structkr__module_1ac937dc6c4d2858d4c79a02c12b28fd2a"></span>int<code class="descname">config)</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a><em> *self</em>, const char<em> *input</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module::config" title="Permalink to this definition">¶</a></dt>
<dd><p>Configure with encoded JSON (NULL if missing). </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>error code. </dd>
</dl>
</p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_module::layer">
<span class="target" id="structkr__module_1a9aede9fd1e51f4dadf04b450ab715511"></span>const kr_layer_api_t*<code class="descname">layer)</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_module" title="kr_module">kr_module</a><em> *self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module::layer" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a pointer to packet processing API specs. </p>
<p>See docs on that type. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_module::props">
<span class="target" id="structkr__module_1a6ceaeb95e84b4496b9c37edf55bb037e"></span>const struct <a class="reference internal" href="#c.kr_prop" title="kr_prop">kr_prop</a>*<code class="descname">props)</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module::props" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a pointer to list of properties, terminated by { NULL, NULL, NULL }. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_module::lib">
<span class="target" id="structkr__module_1a4ed9dc99cea78d49e73c4508bbecc867"></span>void* <code class="descname">lib</code><a class="headerlink" href="#c.kr_module::lib" title="Permalink to this definition">¶</a></dt>
<dd><p>Shared library handle or RTLD_DEFAULT. </p>
</dd></dl>
<dl class="variable">
<dt id="c.kr_module::data">
<span class="target" id="structkr__module_1a5cdd3202438bffc1115839b9f4f0999c"></span>void* <code class="descname">data</code><a class="headerlink" href="#c.kr_module::data" title="Permalink to this definition">¶</a></dt>
<dd><p>Custom data context. </p>
</dd></dl>
</div>
</dd></dl>
<dl class="struct">
<dt id="c.kr_prop">
<span class="target" id="structkr__prop"></span><em class="property">struct </em><code class="descname">kr_prop</code><a class="headerlink" href="#c.kr_prop" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <module.h></em><p>Module property (named callable). </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.kr_prop::cb">
<span class="target" id="structkr__prop_1a0665dd81a9b951f2cc24b6e7df7b6c60"></span>kr_prop_cb* <code class="descname">cb</code><a class="headerlink" href="#c.kr_prop::cb" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_prop::name">
<span class="target" id="structkr__prop_1a95427366911ee62accfda8410a49eb81"></span>const char* <code class="descname">name</code><a class="headerlink" href="#c.kr_prop::name" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.kr_prop::info">
<span class="target" id="structkr__prop_1a94c416bbbf9767674dd0087c15831246"></span>const char* <code class="descname">info</code><a class="headerlink" href="#c.kr_prop::info" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
</div>
<div class="section" id="utilities">
<h3><a class="toc-backref" href="#id5">Utilities</a><a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h3>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.kr_log_info">
<span class="target" id="utils_8h_1a498a4409494a3fae9baab0a78958b3ac"></span><code class="descname">kr_log_info</code><span class="sig-paren">(</span><a class="reference internal" href="#c.fmt" title="fmt">fmt</a>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_log_info" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.kr_log_error">
<span class="target" id="utils_8h_1a0e450893a68149ae3cfb00e0fd75b146"></span><code class="descname">kr_log_error</code><span class="sig-paren">(</span><a class="reference internal" href="#c.fmt" title="fmt">fmt</a>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_log_error" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.kr_log_trace_enabled">
<span class="target" id="utils_8h_1ab6ae89269bd79082096d86949867fbd5"></span><code class="descname">kr_log_trace_enabled</code><span class="sig-paren">(</span>query<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_log_trace_enabled" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if the query has request log handler installed. </p>
</dd></dl>
<dl class="define">
<dt id="c.VERBOSE_STATUS">
<span class="target" id="utils_8h_1a1126767933bd1fb832b3cee1d4811cfd"></span><code class="descname">VERBOSE_STATUS</code><a class="headerlink" href="#c.VERBOSE_STATUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Block run in verbose mode; optimized when not run. </p>
</dd></dl>
<dl class="define">
<dt id="c.WITH_VERBOSE">
<span class="target" id="utils_8h_1ad02f829b0352547cb63fe19e6aaf2bc1"></span><code class="descname">WITH_VERBOSE</code><span class="sig-paren">(</span>query<span class="sig-paren">)</span><a class="headerlink" href="#c.WITH_VERBOSE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.kr_log_verbose">
<span class="target" id="utils_8h_1a3f268f8e06c4cd1e666a420b1b88a92c"></span><code class="descname">kr_log_verbose</code><a class="headerlink" href="#c.kr_log_verbose" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.static_assert">
<span class="target" id="utils_8h_1a5de4bb4a71c09d00407b33fb528a0e3b"></span><code class="descname">static_assert</code><span class="sig-paren">(</span>cond, msg<span class="sig-paren">)</span><a class="headerlink" href="#c.static_assert" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.RDATA_ARR_MAX">
<span class="target" id="utils_8h_1a04734d6f5cc2717c2c7d3878d4eed0e6"></span><code class="descname">RDATA_ARR_MAX</code><a class="headerlink" href="#c.RDATA_ARR_MAX" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.kr_rdataset_next">
<span class="target" id="utils_8h_1acbab5bff541e4a46658c8bef7ea46a0e"></span><code class="descname">kr_rdataset_next</code><span class="sig-paren">(</span>rd<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rdataset_next" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.KR_RRKEY_LEN">
<span class="target" id="utils_8h_1a32f0878ed47280387a7189f7bbe9dda7"></span><code class="descname">KR_RRKEY_LEN</code><a class="headerlink" href="#c.KR_RRKEY_LEN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.SWAP">
<span class="target" id="utils_8h_1a5d9d454d4b9f2ff8106d5199ac0d0186"></span><code class="descname">SWAP</code><span class="sig-paren">(</span>x, y<span class="sig-paren">)</span><a class="headerlink" href="#c.SWAP" title="Permalink to this definition">¶</a></dt>
<dd><p>Swap two places. </p>
<p>Note: the parameters need to be without side effects. </p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt id="c.trace_callback_f">
<span class="target" id="utils_8h_1ade73428321037aea1773ca5cc022b832"></span><em class="property">typedef </em>void<code class="descname">(* trace_callback_f)</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_request" title="kr_request">kr_request</a><em> *request</em><span class="sig-paren">)</span><a class="headerlink" href="#c.trace_callback_f" title="Permalink to this definition">¶</a></dt>
<dd><p>Callback for request events. </p>
</dd></dl>
<dl class="typedef">
<dt id="c.trace_log_f">
<span class="target" id="utils_8h_1abcb9ef34af3bfdd1cc722055d8651058"></span><em class="property">typedef </em>void<code class="descname">(* trace_log_f)</code><span class="sig-paren">(</span>const struct <a class="reference internal" href="#c.kr_query" title="kr_query">kr_query</a><em> *query</em>, const char<em> *source</em>, const char<em> *msg</em><span class="sig-paren">)</span><a class="headerlink" href="#c.trace_log_f" title="Permalink to this definition">¶</a></dt>
<dd><p>Callback for request logging handler. </p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.kr_verbose_set">
<span class="target" id="utils_8h_1ae0d4ae88369999188368fdb789e588a0"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> bool <code class="descname">kr_verbose_set</code><span class="sig-paren">(</span>bool<em> status</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_verbose_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Set verbose mode. </p>
<p>Not available if compiled with -DNOVERBOSELOG. </p>
</dd></dl>
<dl class="function">
<dt id="c.KR_PRINTF">
<span class="target" id="utils_8h_1a87748f6900fce87e031c04a174c06bcd"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <code class="descname">KR_PRINTF</code><span class="sig-paren">(</span>1<span class="sig-paren">)</span><a class="headerlink" href="#c.KR_PRINTF" title="Permalink to this definition">¶</a></dt>
<dd><p>Log a message if in verbose mode. </p>
</dd></dl>
<dl class="function">
<dt>
<span class="target" id="utils_8h_1ae3e46a65d5b19f5292ad8e42a9a157ef"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <code class="descname">KR_PRINTF</code><span class="sig-paren">(</span>3<span class="sig-paren">)</span></dt>
<dd><p>Log a message through the request log handler. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>true if the message was logged </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">query</span></code>: current query </li>
<li><code class="docutils literal"><span class="pre">source</span></code>: message source </li>
<li><code class="docutils literal"><span class="pre">fmt</span></code>: message format </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.time_diff">
<span class="target" id="utils_8h_1a851b288423686421c2aebd50663ecebe"></span>static long <code class="descname">time_diff</code><span class="sig-paren">(</span>struct timeval *<em> begin</em>, struct timeval *<em> end</em><span class="sig-paren">)</span><a class="headerlink" href="#c.time_diff" title="Permalink to this definition">¶</a></dt>
<dd><p>Return time difference in miliseconds. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>based on the _BSD_SOURCE timersub() macro </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_strcatdup">
<span class="target" id="utils_8h_1a0ff4b48410b9e28bbb8c5bfb276884e3"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> char* <code class="descname">kr_strcatdup</code><span class="sig-paren">(</span>unsigned<em> n</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_strcatdup" title="Permalink to this definition">¶</a></dt>
<dd><p>Concatenate N strings. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rand_reseed">
<span class="target" id="utils_8h_1ab8e25e7fb9a25516920da803a56a106d"></span>int <code class="descname">kr_rand_reseed</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rand_reseed" title="Permalink to this definition">¶</a></dt>
<dd><p>Reseed CSPRNG context. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rand_uint">
<span class="target" id="utils_8h_1a31cced25e98699cd2810228719639728"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a> <code class="descname">kr_rand_uint</code><span class="sig-paren">(</span><a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a><em> max</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rand_uint" title="Permalink to this definition">¶</a></dt>
<dd><p>Get pseudo-random value between zero and max-1 (inclusive). </p>
<p>Passing zero means that any uint32_t should be returned (it’s also faster). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_memreserve">
<span class="target" id="utils_8h_1a66a6a25579bca570f3d1579108f90d9d"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_memreserve</code><span class="sig-paren">(</span>void *<em> baton</em>, char **<em> mem</em>, size_t<em> elm_size</em>, size_t<em> want</em>, size_t *<em> have</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_memreserve" title="Permalink to this definition">¶</a></dt>
<dd><p>Memory reservation routine for knot_mm_t. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_pkt_recycle">
<span class="target" id="utils_8h_1a260d7a794211255076d64dd710abdf7f"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_pkt_recycle</code><span class="sig-paren">(</span>knot_pkt_t *<em> pkt</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_pkt_recycle" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_pkt_clear_payload">
<span class="target" id="utils_8h_1aeb452972740eb982350a9f5cdf8facf2"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_pkt_clear_payload</code><span class="sig-paren">(</span>knot_pkt_t *<em> pkt</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_pkt_clear_payload" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_pkt_put">
<span class="target" id="utils_8h_1af0a0a8d59be56150e0b05a06a64ee7da"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_pkt_put</code><span class="sig-paren">(</span>knot_pkt_t *<em> pkt</em>, const knot_dname_t *<em> name</em>, <a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a><em> ttl</em>, uint16_t<em> rclass</em>, uint16_t<em> rtype</em>, const uint8_t *<em> rdata</em>, uint16_t<em> rdlen</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_pkt_put" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct and put record to packet. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_pkt_make_auth_header">
<span class="target" id="utils_8h_1ac9a7c5c2ac233137f81e23ac3322ba6e"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> void <code class="descname">kr_pkt_make_auth_header</code><span class="sig-paren">(</span>knot_pkt_t *<em> pkt</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_pkt_make_auth_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Set packet header suitable for authoritative answer. </p>
<p>(for policy module) </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_inaddr">
<span class="target" id="utils_8h_1a1928f8b657a2d04ae5945c9e4d024a44"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> const char* <code class="descname">kr_inaddr</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_inaddr" title="Permalink to this definition">¶</a></dt>
<dd><p>Address bytes for given family. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_inaddr_family">
<span class="target" id="utils_8h_1a04815e9d32965be1b78c90c746547133"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> int <code class="descname">kr_inaddr_family</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_inaddr_family" title="Permalink to this definition">¶</a></dt>
<dd><p>Address family. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_inaddr_len">
<span class="target" id="utils_8h_1a6f7d5ce58e8ddea4e5dde5b572b5cc06"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> int <code class="descname">kr_inaddr_len</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_inaddr_len" title="Permalink to this definition">¶</a></dt>
<dd><p>Address length for given family, i.e. </p>
<p>sizeof(struct in*_addr). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_sockaddr_len">
<span class="target" id="utils_8h_1a3f8b36fec39f549e6629e4078088b994"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> int <code class="descname">kr_sockaddr_len</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_sockaddr_len" title="Permalink to this definition">¶</a></dt>
<dd><p>Sockaddr length for given family, i.e. </p>
<p>sizeof(struct sockaddr_in*). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_inaddr_port">
<span class="target" id="utils_8h_1aa23e2b227cb7a9598372953ae91343a3"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> uint16_t <code class="descname">kr_inaddr_port</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_inaddr_port" title="Permalink to this definition">¶</a></dt>
<dd><p>Port. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_inaddr_str">
<span class="target" id="utils_8h_1a1854635b951ae38638e49b33e329259b"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_inaddr_str</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em>, char *<em> buf</em>, size_t *<em> buflen</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_inaddr_str" title="Permalink to this definition">¶</a></dt>
<dd><p>String representation for given address as “<addr>#<port>”. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_straddr_family">
<span class="target" id="utils_8h_1a48449bad54df167a2dfdeeef68a047c3"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> int <code class="descname">kr_straddr_family</code><span class="sig-paren">(</span>const char *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_straddr_family" title="Permalink to this definition">¶</a></dt>
<dd><p>Return address type for string. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_family_len">
<span class="target" id="utils_8h_1a5394a596e74b1360b62e814e9ab37157"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_CONST" title="KR_CONST">KR_CONST</a> int <code class="descname">kr_family_len</code><span class="sig-paren">(</span>int<em> family</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_family_len" title="Permalink to this definition">¶</a></dt>
<dd><p>Return address length in given family (struct in*_addr). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_straddr_socket">
<span class="target" id="utils_8h_1a0c6b02455a6a44596c34a7fb8c69770e"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> struct sockaddr* <code class="descname">kr_straddr_socket</code><span class="sig-paren">(</span>const char *<em> addr</em>, int<em> port</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_straddr_socket" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a sockaddr* from string+port representation (also accepts IPv6 link-local). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_straddr_subnet">
<span class="target" id="utils_8h_1ad2fa596da4212008bae0a8824f77a102"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_straddr_subnet</code><span class="sig-paren">(</span>void *<em> dst</em>, const char *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_straddr_subnet" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse address and return subnet length (bits). </p>
<p><dl class="docutils">
<dt><strong>Warning</strong></dt>
<dd>’dst’ must be at least <code class="docutils literal"><span class="pre">sizeof(struct</span> <span class="pre">in6_addr)</span></code> long. </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_straddr_split">
<span class="target" id="utils_8h_1a15a4bbfdf4f38f1be49ba2dc17aef66b"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_straddr_split</code><span class="sig-paren">(</span>const char *<em> addr</em>, char *<em> buf</em>, size_t<em> buflen</em>, uint16_t *<em> port</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_straddr_split" title="Permalink to this definition">¶</a></dt>
<dd><p>Splits ip address specified as “addr@port” or “addr#port” into addr and port and performs validation. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>if #port part isn’t present, then port will be set to 0. buf and port can be set to NULL. </dd>
<dt><strong>Return</strong></dt>
<dd>kr_error(EINVAL) - addr part doesn’t contains valid ip address or #port part is out-of-range (either < 0 either > UINT16_MAX) kr_error(ENOSP) - buflen is too small </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_straddr_join">
<span class="target" id="utils_8h_1a031590543cc52ed914670ca2a13d3c31"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_straddr_join</code><span class="sig-paren">(</span>const char *<em> addr</em>, uint16_t<em> port</em>, char *<em> buf</em>, size_t *<em> buflen</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_straddr_join" title="Permalink to this definition">¶</a></dt>
<dd><p>Formats ip address and port in “addr#port” format. </p>
<p>and performs validation. <dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>Port always formatted as five-character string with leading zeros. </dd>
<dt><strong>Return</strong></dt>
<dd>kr_error(EINVAL) - addr or buf is NULL or buflen is 0 or addr doesn’t contain a valid ip address kr_error(ENOSP) - buflen is too small </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_bitcmp">
<span class="target" id="utils_8h_1a11b4969e1a9987d530d15de5cca9f97b"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> int <code class="descname">kr_bitcmp</code><span class="sig-paren">(</span>const char *<em> a</em>, const char *<em> b</em>, int<em> bits</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_bitcmp" title="Permalink to this definition">¶</a></dt>
<dd><p>Compare memory bitwise. </p>
<p>The semantics is “the same” as for memcmp(). The partial byte is considered with more-significant bits first, so this is e.g. suitable for comparing IP prefixes. </p>
</dd></dl>
<dl class="function">
<dt id="c.KEY_FLAG_RANK">
<span class="target" id="utils_8h_1ac1ffbd1c3c8ced9eb1df4989200ea700"></span>static uint8_t <code class="descname">KEY_FLAG_RANK</code><span class="sig-paren">(</span>const char *<em> key</em><span class="sig-paren">)</span><a class="headerlink" href="#c.KEY_FLAG_RANK" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.KEY_COVERING_RRSIG">
<span class="target" id="utils_8h_1a2151606db82ec650e33f652cca1e5230"></span>static bool <code class="descname">KEY_COVERING_RRSIG</code><span class="sig-paren">(</span>const char *<em> key</em><span class="sig-paren">)</span><a class="headerlink" href="#c.KEY_COVERING_RRSIG" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_rrkey">
<span class="target" id="utils_8h_1afe76ea6d1730cd48d3b15009f33e56b0"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_rrkey</code><span class="sig-paren">(</span>char *<em> key</em>, const knot_dname_t *<em> owner</em>, uint16_t<em> type</em>, uint8_t<em> rank</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rrkey" title="Permalink to this definition">¶</a></dt>
<dd><p>Create unique null-terminated string key for RR. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>key length if successful or an error </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">key</span></code>: Destination buffer for key size, MUST be KR_RRKEY_LEN or larger. </li>
<li><code class="docutils literal"><span class="pre">owner</span></code>: RR owner domain name. </li>
<li><code class="docutils literal"><span class="pre">type</span></code>: RR type. </li>
<li><code class="docutils literal"><span class="pre">rank</span></code>: RR rank (8 bit tag usable for anything). </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rrmap_add">
<span class="target" id="utils_8h_1ad217620816e895f9b3517f36de55529b"></span>int <code class="descname">kr_rrmap_add</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> stash</em>, const knot_rrset_t *<em> rr</em>, uint8_t<em> rank</em>, knot_mm_t *<em> pool</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rrmap_add" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_ranked_rrarray_add">
<span class="target" id="utils_8h_1a501514bb06ea59423c3dbbf139843cd2"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> int <code class="descname">kr_ranked_rrarray_add</code><span class="sig-paren">(</span>ranked_rr_array_t *<em> array</em>, const knot_rrset_t *<em> rr</em>, uint8_t<em> rank</em>, bool<em> to_wire</em>, <a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a><em> qry_uid</em>, knot_mm_t *<em> pool</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_ranked_rrarray_add" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_ranked_rrarray_set_wire">
<span class="target" id="utils_8h_1af70ed3453007973a17f19e9c155a1962"></span>int <code class="descname">kr_ranked_rrarray_set_wire</code><span class="sig-paren">(</span>ranked_rr_array_t *<em> array</em>, bool<em> to_wire</em>, <a class="reference internal" href="#c.uint32_t" title="uint32_t">uint32_t</a><em> qry_uid</em>, bool<em> check_dups</em>, bool(<em>*extraCheck</em>)(const ranked_rr_array_entry_t *)<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_ranked_rrarray_set_wire" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_pkt_text">
<span class="target" id="utils_8h_1a81a0d9fa490a9f263e4cf2c80dd7569c"></span><a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> char* <code class="descname">kr_pkt_text</code><span class="sig-paren">(</span>const knot_pkt_t *<em> pkt</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_pkt_text" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_rrset_text">
<span class="target" id="utils_8h_1a6070ef72feda19950b121254246728f7"></span><a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> char* <code class="descname">kr_rrset_text</code><span class="sig-paren">(</span>const knot_rrset_t *<em> rr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rrset_text" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_dname_text">
<span class="target" id="utils_8h_1a5bd90caec51559e30b71877cb6e08320"></span>static <a class="reference internal" href="#c.KR_PURE" title="KR_PURE">KR_PURE</a> char* <code class="descname">kr_dname_text</code><span class="sig-paren">(</span>const knot_dname_t *<em> name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_dname_text" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_rrtype_text">
<span class="target" id="utils_8h_1a2b4f967badfa1ed4ea8ce755e5fe261c"></span>static <a class="reference internal" href="#c.KR_CONST" title="KR_CONST">KR_CONST</a> char* <code class="descname">kr_rrtype_text</code><span class="sig-paren">(</span>const uint16_t<em> rrtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rrtype_text" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_module_call">
<span class="target" id="utils_8h_1a5c9171c0a3599033622d9a0afb4f308c"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> char* <code class="descname">kr_module_call</code><span class="sig-paren">(</span>struct <a class="reference internal" href="#c.kr_context" title="kr_context">kr_context</a> *<em> ctx</em>, const char *<em> module</em>, const char *<em> prop</em>, const char *<em> input</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_module_call" title="Permalink to this definition">¶</a></dt>
<dd><p>Call module property. </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_rrset_type_maysig">
<span class="target" id="utils_8h_1a62bc73d0845065363cc0d8cfa3b7430b"></span>static uint16_t <code class="descname">kr_rrset_type_maysig</code><span class="sig-paren">(</span>const knot_rrset_t *<em> rr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_rrset_type_maysig" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the (covered) type of an nonempty RRset. </p>
</dd></dl>
<dl class="function">
<dt id="c.lua_push_printf">
<span class="target" id="utils_8h_1ae7ac34dee353ae20637c18677ff5dc17"></span>static const char* <code class="descname">lua_push_printf</code><span class="sig-paren">(</span>lua_State *<em> L</em>, const char *<em> fmt</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.lua_push_printf" title="Permalink to this definition">¶</a></dt>
<dd><p>Printf onto the lua stack, avoiding additional copy (thin wrapper). </p>
</dd></dl>
<dl class="function">
<dt id="c.kr_straddr">
<span class="target" id="utils_8h_1a8cc36053cdc42fb225066e92f3a85a68"></span>static char* <code class="descname">kr_straddr</code><span class="sig-paren">(</span>const struct sockaddr *<em> addr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_straddr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.kr_now">
<span class="target" id="utils_8h_1a974f8fc3a9801a49594c76a2c9f2243a"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> uint64_t <code class="descname">kr_now</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_now" title="Permalink to this definition">¶</a></dt>
<dd><p>The current time in monotonic milliseconds. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>it may be outdated in case of long callbacks; see uv_now(). </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.knot_dname_lf2wire">
<span class="target" id="utils_8h_1a620a0ab461fdf702523859bc03a470de"></span>int <code class="descname">knot_dname_lf2wire</code><span class="sig-paren">(</span>knot_dname_t *<em> dst</em>, uint8_t<em> len</em>, const uint8_t *<em> lf</em><span class="sig-paren">)</span><a class="headerlink" href="#c.knot_dname_lf2wire" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert name from lookup format to wire. </p>
<p>See knot_dname_lf</p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>len bytes are read and len+1 are written with <em>normal</em> LF, but it’s also allowed that the final zero byte is omitted in LF. </dd>
<dt><strong>Return</strong></dt>
<dd>the number of bytes written (>0) or error code (<0) </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.kr_dname_lf">
<span class="target" id="utils_8h_1a65477e76ef8764770055316b838d0b00"></span>static int <code class="descname">kr_dname_lf</code><span class="sig-paren">(</span>uint8_t *<em> dst</em>, const knot_dname_t *<em> src</em>, bool<em> add_wildcard</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_dname_lf" title="Permalink to this definition">¶</a></dt>
<dd><p>Patched knot_dname_lf. </p>
<p>LF for “.” has length zero instead of one, for consistency. (TODO: consistency?) <dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>packet is always NULL </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">add_wildcard</span></code>: append the wildcard label </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Variables</p>
<dl class="variable">
<dt id="c.kr_verbose_status">
<span class="target" id="utils_8h_1a80b870a8320682fa1243e962f47965cd"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> bool <code class="descname">kr_verbose_status</code><a class="headerlink" href="#c.kr_verbose_status" title="Permalink to this definition">¶</a></dt>
<dd><p>Whether in verbose mode. </p>
<p>Only use this for reading. </p>
</dd></dl>
<dl class="variable">
<dt id="c.source">
<span class="target" id="utils_8h_1a498ef00718080abf0643ff1a81f811ca"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> const char* <code class="descname">source</code><a class="headerlink" href="#c.source" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.fmt">
<span class="target" id="utils_8h_1a0ceac8f9bf59abddbc71713bf6894fbf"></span><a class="reference internal" href="#c.KR_EXPORT" title="KR_EXPORT">KR_EXPORT</a> const char const char* <code class="descname">fmt</code><a class="headerlink" href="#c.fmt" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.KEY_FLAG_RRSIG">
<span class="target" id="utils_8h_1a13b7ecf2a1cee49340ca673bebc17662"></span>const uint8_t <code class="descname">KEY_FLAG_RRSIG</code> = 0x02<a class="headerlink" href="#c.KEY_FLAG_RRSIG" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<dl class="union">
<dt id="c.inaddr">
<span class="target" id="unioninaddr"></span><em class="property">union </em><code class="descname">inaddr</code><a class="headerlink" href="#c.inaddr" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <utils.h></em><p>Simple storage for IPx address or AF_UNSPEC. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.inaddr::ip">
<span class="target" id="unioninaddr_1a3850b85ac7fb1385a07fa2f8882bf754"></span>struct sockaddr <code class="descname">ip</code><a class="headerlink" href="#c.inaddr::ip" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.inaddr::ip4">
<span class="target" id="unioninaddr_1aac4a5b77edd999f5cc03f6f53b5831ea"></span>struct sockaddr_in <code class="descname">ip4</code><a class="headerlink" href="#c.inaddr::ip4" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.inaddr::ip6">
<span class="target" id="unioninaddr_1ac774bdcdb29d92a470c198bc8ef638fc"></span>struct sockaddr_in6 <code class="descname">ip6</code><a class="headerlink" href="#c.inaddr::ip6" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.KR_EXPORT">
<span class="target" id="defines_8h_1ab13778da7764c59b437b9450631956ac"></span><code class="descname">KR_EXPORT</code><a class="headerlink" href="#c.KR_EXPORT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.KR_CONST">
<span class="target" id="defines_8h_1a1b230feca53b96588f4399bede2f0e7d"></span><code class="descname">KR_CONST</code><a class="headerlink" href="#c.KR_CONST" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.KR_PURE">
<span class="target" id="defines_8h_1ad0d33290cd4e91b25dec6cda9e0b71c5"></span><code class="descname">KR_PURE</code><a class="headerlink" href="#c.KR_PURE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.KR_NORETURN">
<span class="target" id="defines_8h_1aa20d0a7cc217c3c619d8599d12cbb8e5"></span><code class="descname">KR_NORETURN</code><a class="headerlink" href="#c.KR_NORETURN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.KR_COLD">
<span class="target" id="defines_8h_1a6dbc247433f7debaf036119ddbdeadf5"></span><code class="descname">KR_COLD</code><a class="headerlink" href="#c.KR_COLD" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt>
<span class="target" id="defines_8h_1a44b90d22482ec22e66c5d0792ca32b52"></span><code class="descname">KR_PRINTF</code><span class="sig-paren">(</span>n<span class="sig-paren">)</span></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.uint">
<span class="target" id="defines_8h_1ad46b2ebcd4c426b06cda147ddc1001e7"></span><code class="descname">uint</code><a class="headerlink" href="#c.uint" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.kr_ok">
<span class="target" id="defines_8h_1aedebd148cd0d9c42ea7fd18b1b0cd810"></span><code class="descname">kr_ok</code><a class="headerlink" href="#c.kr_ok" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.kr_strerror">
<span class="target" id="defines_8h_1a99dcbef6b4b9de0dbaf7b9f03d4f1e49"></span><code class="descname">kr_strerror</code><span class="sig-paren">(</span>x<span class="sig-paren">)</span><a class="headerlink" href="#c.kr_strerror" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt>
<span class="target" id="defines_8h_1a91ad9478d81a7aaf2593e8d9c3d06a14"></span><em class="property">typedef </em>unsigned int <code class="descname">uint</code></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.kr_error">
<span class="target" id="defines_8h_1a16f4e4a9ede6e43bc4f17bcc32add5e1"></span>static int <a class="reference internal" href="#c.KR_COLD" title="KR_COLD">KR_COLD</a> <code class="descname">kr_error</code><span class="sig-paren">(</span>int<em> x</em><span class="sig-paren">)</span><a class="headerlink" href="#c.kr_error" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</div>
<div class="section" id="generics-library">
<span id="lib-generics"></span><h3><a class="toc-backref" href="#id6">Generics library</a><a class="headerlink" href="#generics-library" title="Permalink to this headline">¶</a></h3>
<p>This small collection of “generics” was born out of frustration that I couldn’t find no
such thing for C. It’s either bloated, has poor interface, null-checking is absent or
doesn’t allow custom allocation scheme. BSD-licensed (or compatible) code is allowed here,
as long as it comes with a test case in <cite>tests/test_generics.c</cite>.</p>
<ul class="simple">
<li><a class="reference internal" href="#array">array</a> - a set of simple macros to make working with dynamic arrays easier.</li>
<li><a class="reference internal" href="#map">map</a> - a <a class="reference external" href="https://cr.yp.to/critbit.html">Crit-bit tree</a> key-value map implementation (public domain) that comes with tests.</li>
<li><a class="reference internal" href="#set">set</a> - set abstraction implemented on top of <code class="docutils literal"><span class="pre">map</span></code>.</li>
<li><a class="reference internal" href="#pack">pack</a> - length-prefixed list of objects (i.e. array-list).</li>
<li><a class="reference internal" href="#lru">lru</a> - LRU-like hash table</li>
</ul>
<div class="section" id="array">
<h4>array<a class="headerlink" href="#array" title="Permalink to this headline">¶</a></h4>
<p>A set of simple macros to make working with dynamic arrays easier. </p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">MIN</span><span class="p">(</span><span class="n">array_push</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="n">val</span><span class="p">),</span> <span class="n">other</span><span class="p">)</span>
</pre></div>
</div>
<dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The C has no generics, so it is implemented mostly using macros. Be aware of that, as direct usage of the macros in the evaluating macros may lead to different expectations:</dd>
</dl>
</p>
<p>May evaluate the code twice, leading to unexpected behaviour. This is a price to pay for the absence of proper generics.</p>
<p><em>Example usage:</em></p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">array_t</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span> <span class="n">arr</span><span class="p">;</span>
<span class="n">array_init</span><span class="p">(</span><span class="n">arr</span><span class="p">);</span>
<span class="c1">// Reserve memory in advance</span>
<span class="k">if</span> <span class="p">(</span><span class="n">array_reserve</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">ENOMEM</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// Already reserved, cannot fail</span>
<span class="n">array_push</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="s">"princess"</span><span class="p">);</span>
<span class="n">array_push</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="s">"leia"</span><span class="p">);</span>
<span class="c1">// Not reserved, may fail</span>
<span class="k">if</span> <span class="p">(</span><span class="n">array_push</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="s">"han"</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">ENOMEM</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// It does not hide what it really is</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">size_t</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">arr</span><span class="p">.</span><span class="n">len</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">arr</span><span class="p">.</span><span class="n">at</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="c1">// Random delete</span>
<span class="n">array_del</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
</pre></div>
</div>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.array_t">
<span class="target" id="group__generics_1ga5d9d054736c34ad8fbc685910100a045"></span><code class="descname">array_t</code><span class="sig-paren">(</span>type<span class="sig-paren">)</span><a class="headerlink" href="#c.array_t" title="Permalink to this definition">¶</a></dt>
<dd><p>Declare an array structure. </p>
</dd></dl>
<dl class="define">
<dt id="c.array_init">
<span class="target" id="group__generics_1ga58541e03ad681222ca2d00992d6452b9"></span><code class="descname">array_init</code><span class="sig-paren">(</span>array<span class="sig-paren">)</span><a class="headerlink" href="#c.array_init" title="Permalink to this definition">¶</a></dt>
<dd><p>Zero-initialize the array. </p>
</dd></dl>
<dl class="define">
<dt id="c.array_clear">
<span class="target" id="group__generics_1ga5e9c4df194072d20cabd2723a09a3060"></span><code class="descname">array_clear</code><span class="sig-paren">(</span>array<span class="sig-paren">)</span><a class="headerlink" href="#c.array_clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Free and zero-initialize the array. </p>
</dd></dl>
<dl class="define">
<dt id="c.array_clear_mm">
<span class="target" id="group__generics_1gaf6ed181f345a0ac10289732494c1bddc"></span><code class="descname">array_clear_mm</code><span class="sig-paren">(</span>array, free, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.array_clear_mm" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.array_reserve">
<span class="target" id="group__generics_1gac6db07f3f7f64de0bb08858f6c21adc9"></span><code class="descname">array_reserve</code><span class="sig-paren">(</span>array, n<span class="sig-paren">)</span><a class="headerlink" href="#c.array_reserve" title="Permalink to this definition">¶</a></dt>
<dd><p>Reserve capacity up to ‘n’ bytes. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 if success, <0 on failure </dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.array_reserve_mm">
<span class="target" id="group__generics_1gab281bd42b3051024a0d7553293e944d0"></span><code class="descname">array_reserve_mm</code><span class="sig-paren">(</span>array, n, reserve, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.array_reserve_mm" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.array_push">
<span class="target" id="group__generics_1ga51b099e70e641ed6cb9fc38f3649e111"></span><code class="descname">array_push</code><span class="sig-paren">(</span>array, val<span class="sig-paren">)</span><a class="headerlink" href="#c.array_push" title="Permalink to this definition">¶</a></dt>
<dd><p>Push value at the end of the array, resize it if necessary. </p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>May fail if the capacity is not reserved. </dd>
<dt><strong>Return</strong></dt>
<dd>element index on success, <0 on failure </dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.array_pop">
<span class="target" id="group__generics_1gab57c724be58bf9ceb87238ee34441c63"></span><code class="descname">array_pop</code><span class="sig-paren">(</span>array<span class="sig-paren">)</span><a class="headerlink" href="#c.array_pop" title="Permalink to this definition">¶</a></dt>
<dd><p>Pop value from the end of the array. </p>
</dd></dl>
<dl class="define">
<dt id="c.array_del">
<span class="target" id="group__generics_1ga2c95d6b667620c3ae28799cd61ef75eb"></span><code class="descname">array_del</code><span class="sig-paren">(</span>array, i<span class="sig-paren">)</span><a class="headerlink" href="#c.array_del" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove value at given index. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 on success, <0 on failure </dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.array_tail">
<span class="target" id="group__generics_1ga6654582e76021d887c334870111e446e"></span><code class="descname">array_tail</code><span class="sig-paren">(</span>array<span class="sig-paren">)</span><a class="headerlink" href="#c.array_tail" title="Permalink to this definition">¶</a></dt>
<dd><p>Return last element of the array. </p>
<p><dl class="docutils">
<dt><strong>Warning</strong></dt>
<dd>Undefined if the array is empty. </dd>
</dl>
</p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.array_next_count">
<span class="target" id="group__generics_1gab5ca5776e9167e80c1227f77aeb01ce1"></span>static size_t <code class="descname">array_next_count</code><span class="sig-paren">(</span>size_t<em> want</em><span class="sig-paren">)</span><a class="headerlink" href="#c.array_next_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Simplified Qt containers growth strategy. </p>
</dd></dl>
<dl class="function">
<dt id="c.array_std_reserve">
<span class="target" id="group__generics_1gae458f59fea6d67e32a07cd2ceb1c5d7c"></span>static int <code class="descname">array_std_reserve</code><span class="sig-paren">(</span>void *<em> baton</em>, char **<em> mem</em>, size_t<em> elm_size</em>, size_t<em> want</em>, size_t *<em> have</em><span class="sig-paren">)</span><a class="headerlink" href="#c.array_std_reserve" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="c.array_std_free">
<span class="target" id="group__generics_1ga8fbc8f0faa9c39771c717ae489a16c6b"></span>static void <code class="descname">array_std_free</code><span class="sig-paren">(</span>void *<em> baton</em>, void *<em> p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.array_std_free" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</div>
<div class="section" id="map">
<h4>map<a class="headerlink" href="#map" title="Permalink to this headline">¶</a></h4>
<p>A Crit-bit tree key-value map implementation. </p>
<p><em>Example usage:</em><dl class="docutils">
<dt><strong>Warning</strong></dt>
<dd>If the user provides a custom allocator, it must return addresses aligned to 2B boundary.</dd>
</dl>
</p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">map_t</span> <span class="n">map</span> <span class="o">=</span> <span class="n">map_make</span><span class="p">();</span>
<span class="c1">// Custom allocator (optional)</span>
<span class="n">map</span><span class="p">.</span><span class="n">malloc</span> <span class="o">=</span> <span class="o">&</span><span class="n">mymalloc</span><span class="p">;</span>
<span class="n">map</span><span class="p">.</span><span class="n">baton</span> <span class="o">=</span> <span class="o">&</span><span class="n">mymalloc_context</span><span class="p">;</span>
<span class="c1">// Insert k-v pairs</span>
<span class="kt">int</span> <span class="n">values</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">42</span><span class="p">,</span> <span class="mi">53</span><span class="p">,</span> <span class="mi">64</span> <span class="p">};</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map_set</span><span class="p">(</span><span class="o">&</span><span class="n">map</span><span class="p">,</span> <span class="s">"princess"</span><span class="p">,</span> <span class="o">&</span><span class="n">values</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">!=</span> <span class="mi">0</span> <span class="o">||</span>
<span class="n">map_set</span><span class="p">(</span><span class="o">&</span><span class="n">map</span><span class="p">,</span> <span class="s">"prince"</span><span class="p">,</span> <span class="o">&</span><span class="n">values</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">!=</span> <span class="mi">0</span> <span class="o">||</span>
<span class="n">map_set</span><span class="p">(</span><span class="o">&</span><span class="n">map</span><span class="p">,</span> <span class="s">"leia"</span><span class="p">,</span> <span class="o">&</span><span class="n">values</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">fail</span><span class="p">();</span>
<span class="p">}</span>
<span class="c1">// Test membership</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map_contains</span><span class="p">(</span><span class="o">&</span><span class="n">map</span><span class="p">,</span> <span class="s">"leia"</span><span class="p">))</span> <span class="p">{</span>
<span class="n">success</span><span class="p">();</span>
<span class="p">}</span>
<span class="c1">// Prefix search</span>
<span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">count</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">k</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">v</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">ext</span><span class="p">)</span> <span class="p">{</span> <span class="p">(</span><span class="o">*</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="p">)</span><span class="n">ext</span><span class="p">)</span><span class="o">++</span><span class="p">;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map_walk_prefixed</span><span class="p">(</span><span class="n">map</span><span class="p">,</span> <span class="s">"princ"</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="o">&</span><span class="n">i</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d matches</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// Delete</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map_del</span><span class="p">(</span><span class="o">&</span><span class="n">map</span><span class="p">,</span> <span class="s">"badkey"</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">fail</span><span class="p">();</span> <span class="c1">// No such key</span>
<span class="p">}</span>
<span class="c1">// Clear the map</span>
<span class="n">map_clear</span><span class="p">(</span><span class="o">&</span><span class="n">map</span><span class="p">);</span>
</pre></div>
</div>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.map_walk">
<span class="target" id="group__generics_1gaa36451468e80dbcc1981e53d3cac3083"></span><code class="descname">map_walk</code><span class="sig-paren">(</span><a class="reference internal" href="daemon.html#c.map" title="map">map</a>, callback, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.map_walk" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt id="c.map_alloc_f">
<span class="target" id="group__generics_1gaee9f637c866b329291c7e9aa5a9647b6"></span><em class="property">typedef </em>void*<code class="descname">(* map_alloc_f)</code><span class="sig-paren">(</span>void<em> *</em>, size_t<span class="sig-paren">)</span><a class="headerlink" href="#c.map_alloc_f" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="typedef">
<dt id="c.map_free_f">
<span class="target" id="group__generics_1ga3937b54b47dc8156cead02be7611dd91"></span><em class="property">typedef </em>void<code class="descname">(* map_free_f)</code><span class="sig-paren">(</span>void<em> *baton</em>, void<em> *ptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_free_f" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.map_make">
<span class="target" id="group__generics_1gaa322fefa6bccc84eba300311511baaf4"></span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> <code class="descname">map_make</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.map_make" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an new, empty critbit map. </p>
</dd></dl>
<dl class="function">
<dt id="c.map_contains">
<span class="target" id="group__generics_1ga1b26da0f65c55d3c869e048791cfe6c8"></span>int <code class="descname">map_contains</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> map</em>, const char *<em> str</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_contains" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns non-zero if map contains str. </p>
</dd></dl>
<dl class="function">
<dt id="c.map_get">
<span class="target" id="group__generics_1ga7c65d377b1b2a2270f91c4fa0c23bf1d"></span>void* <code class="descname">map_get</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> map</em>, const char *<em> str</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_get" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns value if map contains str. </p>
<p>Note: NULL may mean two different things. </p>
</dd></dl>
<dl class="function">
<dt id="c.map_set">
<span class="target" id="group__generics_1ga8d305f08994e935abee8db94b0805055"></span>int <code class="descname">map_set</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> map</em>, const char *<em> str</em>, void *<em> val</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Inserts str into map, returns 0 on suceess. </p>
</dd></dl>
<dl class="function">
<dt id="c.map_del">
<span class="target" id="group__generics_1gabb4a8061675af2b04ee6fc793524fe4e"></span>int <code class="descname">map_del</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> map</em>, const char *<em> str</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_del" title="Permalink to this definition">¶</a></dt>
<dd><p>Deletes str from the map, returns 0 on suceess. </p>
</dd></dl>
<dl class="function">
<dt id="c.map_clear">
<span class="target" id="group__generics_1ga24ab6610ba1d50a9833794c90f44ce6a"></span>void <code class="descname">map_clear</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> map</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clears the given map. </p>
</dd></dl>
<dl class="function">
<dt id="c.map_walk_prefixed">
<span class="target" id="group__generics_1gad15697e6966d0fe687c075e1e103978b"></span>int <code class="descname">map_walk_prefixed</code><span class="sig-paren">(</span><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> *<em> map</em>, const char *<em> prefix</em>, int(<em>*callback</em>)(const char *, void *, void *), void *<em> baton</em><span class="sig-paren">)</span><a class="headerlink" href="#c.map_walk_prefixed" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls callback for all strings in map with the given prefix. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">map</span></code>: </li>
<li><code class="docutils literal"><span class="pre">prefix</span></code>: required string prefix (empty => all strings) </li>
<li><code class="docutils literal"><span class="pre">callback</span></code>: callback parameters are (key, value, baton) </li>
<li><code class="docutils literal"><span class="pre">baton</span></code>: passed uservalue </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<dl class="struct">
<dt id="c.map_t">
<span class="target" id="structmap__t"></span><em class="property">struct </em><code class="descname">map_t</code><a class="headerlink" href="#c.map_t" title="Permalink to this definition">¶</a></dt>
<dd><em>#include <map.h></em><p>Main data structure. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="variable">
<dt id="c.map_t::root">
<span class="target" id="structmap__t_1a578b7c96a179273227161574d4840487"></span>void* <code class="descname">root</code><a class="headerlink" href="#c.map_t::root" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.map_t::malloc">
<span class="target" id="structmap__t_1a85cc17f55ad6a3002a974ccc434ac80d"></span><a class="reference internal" href="#c.map_alloc_f" title="map_alloc_f">map_alloc_f</a> <code class="descname">malloc</code><a class="headerlink" href="#c.map_t::malloc" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.map_t::free">
<span class="target" id="structmap__t_1a2164cd228506baef510361d9f61323ed"></span><a class="reference internal" href="#c.map_free_f" title="map_free_f">map_free_f</a> <code class="descname">free</code><a class="headerlink" href="#c.map_t::free" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="variable">
<dt id="c.map_t::baton">
<span class="target" id="structmap__t_1ac659611d2fae77a62c07ba88c7c3786d"></span>void* <code class="descname">baton</code><a class="headerlink" href="#c.map_t::baton" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</dd></dl>
</div>
<div class="section" id="set">
<h4>set<a class="headerlink" href="#set" title="Permalink to this headline">¶</a></h4>
<p>A set abstraction implemented on top of map. </p>
<p><em>Example usage:</em><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The API is based on map.h, see it for more examples.</dd>
</dl>
</p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">set_t</span> <span class="n">set</span> <span class="o">=</span> <span class="n">set_make</span><span class="p">();</span>
<span class="c1">// Insert keys</span>
<span class="k">if</span> <span class="p">(</span><span class="n">set_add</span><span class="p">(</span><span class="o">&</span><span class="n">set</span><span class="p">,</span> <span class="s">"princess"</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span> <span class="o">||</span>
<span class="n">set_add</span><span class="p">(</span><span class="o">&</span><span class="n">set</span><span class="p">,</span> <span class="s">"prince"</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span> <span class="o">||</span>
<span class="n">set_add</span><span class="p">(</span><span class="o">&</span><span class="n">set</span><span class="p">,</span> <span class="s">"leia"</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">fail</span><span class="p">();</span>
<span class="p">}</span>
<span class="c1">// Test membership</span>
<span class="k">if</span> <span class="p">(</span><span class="n">set_contains</span><span class="p">(</span><span class="o">&</span><span class="n">set</span><span class="p">,</span> <span class="s">"leia"</span><span class="p">))</span> <span class="p">{</span>
<span class="n">success</span><span class="p">();</span>
<span class="p">}</span>
<span class="c1">// Prefix search</span>
<span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">count</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">s</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">n</span><span class="p">)</span> <span class="p">{</span> <span class="p">(</span><span class="o">*</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="p">)</span><span class="n">n</span><span class="p">)</span><span class="o">++</span><span class="p">;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">set_walk_prefixed</span><span class="p">(</span><span class="n">set</span><span class="p">,</span> <span class="s">"princ"</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="o">&</span><span class="n">i</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d matches</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// Delete</span>
<span class="k">if</span> <span class="p">(</span><span class="n">set_del</span><span class="p">(</span><span class="o">&</span><span class="n">set</span><span class="p">,</span> <span class="s">"badkey"</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">fail</span><span class="p">();</span> <span class="c1">// No such key</span>
<span class="p">}</span>
<span class="c1">// Clear the set</span>
<span class="n">set_clear</span><span class="p">(</span><span class="o">&</span><span class="n">set</span><span class="p">);</span>
</pre></div>
</div>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.set_make">
<span class="target" id="group__generics_1gaf061df5241e07a14eb40c2af46041f5d"></span><code class="descname">set_make</code><a class="headerlink" href="#c.set_make" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an new, empty critbit set </p>
</dd></dl>
<dl class="define">
<dt id="c.set_contains">
<span class="target" id="group__generics_1ga6d0679c5f41032150e22af4acd59716f"></span><code class="descname">set_contains</code><span class="sig-paren">(</span>set, str<span class="sig-paren">)</span><a class="headerlink" href="#c.set_contains" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns non-zero if set contains str </p>
</dd></dl>
<dl class="define">
<dt id="c.set_add">
<span class="target" id="group__generics_1ga90f4a7d33c76163d8032054d93a21675"></span><code class="descname">set_add</code><span class="sig-paren">(</span>set, str<span class="sig-paren">)</span><a class="headerlink" href="#c.set_add" title="Permalink to this definition">¶</a></dt>
<dd><p>Inserts str into set, returns 0 on suceess </p>
</dd></dl>
<dl class="define">
<dt id="c.set_del">
<span class="target" id="group__generics_1ga962de254effcebd9d758c81b76428a08"></span><code class="descname">set_del</code><span class="sig-paren">(</span>set, str<span class="sig-paren">)</span><a class="headerlink" href="#c.set_del" title="Permalink to this definition">¶</a></dt>
<dd><p>Deletes str from the set, returns 0 on suceess </p>
</dd></dl>
<dl class="define">
<dt id="c.set_clear">
<span class="target" id="group__generics_1ga321d204dbcb8e6c033a5d24884578715"></span><code class="descname">set_clear</code><span class="sig-paren">(</span>set<span class="sig-paren">)</span><a class="headerlink" href="#c.set_clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clears the given set </p>
</dd></dl>
<dl class="define">
<dt id="c.set_walk">
<span class="target" id="group__generics_1gab1ca677d25e148e1960ee6a540f72a64"></span><code class="descname">set_walk</code><span class="sig-paren">(</span>set, callback, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.set_walk" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls callback for all strings in map </p>
</dd></dl>
<dl class="define">
<dt id="c.set_walk_prefixed">
<span class="target" id="group__generics_1ga4dbe6f23b32f6e70c6ba9f15ca8f6c7f"></span><code class="descname">set_walk_prefixed</code><span class="sig-paren">(</span>set, prefix, callback, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.set_walk_prefixed" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls callback for all strings in set with the given prefix </p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt id="c.set_t">
<span class="target" id="group__generics_1ga56f12270b7a240413244c9ad5288fe5e"></span><em class="property">typedef </em><a class="reference internal" href="#c.map_t" title="map_t">map_t</a> <code class="descname">set_t</code><a class="headerlink" href="#c.set_t" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="typedef">
<dt id="c.int">
<span class="target" id="group__generics_1gac4d344bf620fef306c03ae8d045174b0"></span><em class="property">typedef </em><code class="descname">int</code><span class="sig-paren">(</span>) set_walk_cb(const char<em> *</em>, void<em> *</em><span class="sig-paren">)</span><a class="headerlink" href="#c.int" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</div>
</div>
<div class="section" id="pack">
<h4>pack<a class="headerlink" href="#pack" title="Permalink to this headline">¶</a></h4>
<p>A length-prefixed list of objects, also an array list. </p>
<p>Each object is prefixed by item length, unlike array this structure permits variable-length data. It is also equivallent to forward-only list backed by an array.</p>
<p><em>Example usage:</em><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>Maximum object size is 2^16 bytes, see <a class="reference internal" href="#group__generics_1ga5e08d616c4f2a03c61f4756b5ade9807"><span class="std std-ref">pack_objlen_t</span></a> If some mistake happens somewhere, the access may end up in an infinite loop. (equality comparison on pointers)</dd>
</dl>
</p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">pack_t</span> <span class="n">pack</span><span class="p">;</span>
<span class="n">pack_init</span><span class="p">(</span><span class="n">pack</span><span class="p">);</span>
<span class="c1">// Reserve 2 objects, 6 bytes total</span>
<span class="n">pack_reserve</span><span class="p">(</span><span class="n">pack</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span> <span class="o">+</span> <span class="mi">2</span><span class="p">);</span>
<span class="c1">// Push 2 objects</span>
<span class="n">pack_obj_push</span><span class="p">(</span><span class="n">pack</span><span class="p">,</span> <span class="n">U8</span><span class="p">(</span><span class="s">"jedi"</span><span class="p">),</span> <span class="mi">4</span><span class="p">)</span>
<span class="n">pack_obj_push</span><span class="p">(</span><span class="n">pack</span><span class="p">,</span> <span class="n">U8</span><span class="p">(</span><span class="s">"</span><span class="se">\xbe\xef</span><span class="s">"</span><span class="p">),</span> <span class="mi">2</span><span class="p">);</span>
<span class="c1">// Iterate length-value pairs</span>
<span class="kt">uint8_t</span> <span class="o">*</span><span class="n">it</span> <span class="o">=</span> <span class="n">pack_head</span><span class="p">(</span><span class="n">pack</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">it</span> <span class="o">!=</span> <span class="n">pack_tail</span><span class="p">(</span><span class="n">pack</span><span class="p">))</span> <span class="p">{</span>
<span class="kt">uint8_t</span> <span class="o">*</span><span class="n">val</span> <span class="o">=</span> <span class="n">pack_obj_val</span><span class="p">(</span><span class="n">it</span><span class="p">);</span>
<span class="n">it</span> <span class="o">=</span> <span class="n">pack_obj_next</span><span class="p">(</span><span class="n">it</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// Remove object</span>
<span class="n">pack_obj_del</span><span class="p">(</span><span class="n">pack</span><span class="p">,</span> <span class="n">U8</span><span class="p">(</span><span class="s">"jedi"</span><span class="p">),</span> <span class="mi">4</span><span class="p">);</span>
<span class="n">pack_clear</span><span class="p">(</span><span class="n">pack</span><span class="p">);</span>
</pre></div>
</div>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt id="c.pack_init">
<span class="target" id="group__generics_1ga3e9598405467bd1bf570d02f22d37e20"></span><code class="descname">pack_init</code><span class="sig-paren">(</span>pack<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_init" title="Permalink to this definition">¶</a></dt>
<dd><p>Zero-initialize the pack. </p>
</dd></dl>
<dl class="define">
<dt id="c.pack_clear">
<span class="target" id="group__generics_1gacbe837543c95f942274a88111d4001eb"></span><code class="descname">pack_clear</code><span class="sig-paren">(</span>pack<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Free and the pack. </p>
</dd></dl>
<dl class="define">
<dt id="c.pack_clear_mm">
<span class="target" id="group__generics_1ga6c9f9cad568f90e5a0b7395eec728e03"></span><code class="descname">pack_clear_mm</code><span class="sig-paren">(</span>pack, free, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_clear_mm" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.pack_reserve">
<span class="target" id="group__generics_1ga1e7c52ec79dc4ed4f566da549a49f3e9"></span><code class="descname">pack_reserve</code><span class="sig-paren">(</span>pack, objs_count, objs_len<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_reserve" title="Permalink to this definition">¶</a></dt>
<dd><p>Incrementally reserve objects in the pack. </p>
</dd></dl>
<dl class="define">
<dt id="c.pack_reserve_mm">
<span class="target" id="group__generics_1ga6b9c63b0401caeeb15058e833255605c"></span><code class="descname">pack_reserve_mm</code><span class="sig-paren">(</span>pack, objs_count, objs_len, reserve, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_reserve_mm" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="define">
<dt id="c.pack_head">
<span class="target" id="group__generics_1ga21edb1fdaa2b1da8f1f7cbba071108e9"></span><code class="descname">pack_head</code><span class="sig-paren">(</span>pack<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_head" title="Permalink to this definition">¶</a></dt>
<dd><p>Return pointer to first packed object. </p>
</dd></dl>
<dl class="define">
<dt id="c.pack_tail">
<span class="target" id="group__generics_1gab3f0bc8a409ffcb1feb3fdd500f5e66d"></span><code class="descname">pack_tail</code><span class="sig-paren">(</span>pack<span class="sig-paren">)</span><a class="headerlink" href="#c.pack_tail" title="Permalink to this definition">¶</a></dt>
<dd><p>Return pack end pointer. </p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Typedefs</p>
<dl class="typedef">
<dt id="c.pack_objlen_t">
<span class="target" id="group__generics_1ga5e08d616c4f2a03c61f4756b5ade9807"></span><em class="property">typedef </em>uint16_t <code class="descname">pack_objlen_t</code><a class="headerlink" href="#c.pack_objlen_t" title="Permalink to this definition">¶</a></dt>
<dd><p>Packed object length type. </p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt>
<span class="target" id="group__generics_1ga2c52b32e620199d559969aa1dfd048cf"></span>typedef <code class="descname">array_t</code><span class="sig-paren">(</span>uint8_t<span class="sig-paren">)</span></dt>
<dd><p>Pack is defined as an array of bytes. </p>
</dd></dl>
<dl class="function">
<dt id="c.pack_obj_len">
<span class="target" id="group__generics_1ga41ab92b5874b45a7071c6a378794509f"></span>static <a class="reference internal" href="#c.pack_objlen_t" title="pack_objlen_t">pack_objlen_t</a> <code class="descname">pack_obj_len</code><span class="sig-paren">(</span>uint8_t *<em> it</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_obj_len" title="Permalink to this definition">¶</a></dt>
<dd><p>Return packed object length. </p>
</dd></dl>
<dl class="function">
<dt id="c.pack_obj_val">
<span class="target" id="group__generics_1ga9566a28cc68fce57cee6abd1003a0c67"></span>static uint8_t* <code class="descname">pack_obj_val</code><span class="sig-paren">(</span>uint8_t *<em> it</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_obj_val" title="Permalink to this definition">¶</a></dt>
<dd><p>Return packed object value. </p>
</dd></dl>
<dl class="function">
<dt id="c.pack_obj_next">
<span class="target" id="group__generics_1ga14ef3804fe6e4b70bcfbe03dbdf9a9b3"></span>static uint8_t* <code class="descname">pack_obj_next</code><span class="sig-paren">(</span>uint8_t *<em> it</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_obj_next" title="Permalink to this definition">¶</a></dt>
<dd><p>Return pointer to next packed object. </p>
</dd></dl>
<dl class="function">
<dt id="c.pack_last">
<span class="target" id="group__generics_1gadab2b643bb3118ad5ee6fb9373b269b8"></span>static uint8_t* <code class="descname">pack_last</code><span class="sig-paren">(</span>pack_t<em> pack</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_last" title="Permalink to this definition">¶</a></dt>
<dd><p>Return pointer to the last packed object. </p>
</dd></dl>
<dl class="function">
<dt id="c.pack_obj_push">
<span class="target" id="group__generics_1gad79e7024a293496264b0989655b47c7b"></span>static int <code class="descname">pack_obj_push</code><span class="sig-paren">(</span>pack_t *<em> pack</em>, const uint8_t *<em> obj</em>, <a class="reference internal" href="#c.pack_objlen_t" title="pack_objlen_t">pack_objlen_t</a><em> len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_obj_push" title="Permalink to this definition">¶</a></dt>
<dd><p>Push object to the end of the pack. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 on success, negative number on failure </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.pack_obj_find">
<span class="target" id="group__generics_1ga22da0718fc4a1765076ad48a9a8b84a9"></span>static uint8_t* <code class="descname">pack_obj_find</code><span class="sig-paren">(</span>pack_t *<em> pack</em>, const uint8_t *<em> obj</em>, <a class="reference internal" href="#c.pack_objlen_t" title="pack_objlen_t">pack_objlen_t</a><em> len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_obj_find" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a pointer to packed object. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>pointer to packed object or NULL </dd>
</dl>
</p>
</dd></dl>
<dl class="function">
<dt id="c.pack_obj_del">
<span class="target" id="group__generics_1ga3305d111b091644bb4fd6ffb3a1bbad8"></span>static int <code class="descname">pack_obj_del</code><span class="sig-paren">(</span>pack_t *<em> pack</em>, const uint8_t *<em> obj</em>, <a class="reference internal" href="#c.pack_objlen_t" title="pack_objlen_t">pack_objlen_t</a><em> len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.pack_obj_del" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete object from the pack. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 on success, negative number on failure </dd>
</dl>
</p>
</dd></dl>
</div>
</div>
<div class="section" id="lru">
<h4>lru<a class="headerlink" href="#lru" title="Permalink to this headline">¶</a></h4>
<p>A lossy cache. </p>
<p><em>Example usage:</em><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The implementation tries to keep frequent keys and avoid others, even if “used recently”, so it may refuse to store it on <a class="reference internal" href="#group__generics_1gabf3ce7347849c33ebfe9b99f94e054ae"><span class="std std-ref">lru_get_new()</span></a>. It uses hashing to split the problem pseudo-randomly into smaller groups, and within each it tries to approximate relative usage counts of several most frequent keys/hashes. This tracking is done for <em>more</em> keys than those that are actually stored.</dd>
</dl>
</p>
<p><div class="highlight-c"><div class="highlight"><pre><span></span><span class="c1">// Define new LRU type</span>
<span class="k">typedef</span> <span class="nf">lru_t</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span> <span class="n">lru_int_t</span><span class="p">;</span>
<span class="c1">// Create LRU</span>
<span class="n">lru_int_t</span> <span class="o">*</span><span class="n">lru</span><span class="p">;</span>
<span class="n">lru_create</span><span class="p">(</span><span class="o">&</span><span class="n">lru</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="c1">// Insert some values</span>
<span class="kt">int</span> <span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="n">lru_get_new</span><span class="p">(</span><span class="n">lru</span><span class="p">,</span> <span class="s">"luke"</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="s">"luke"</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pi</span><span class="p">)</span>
<span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
<span class="n">pi</span> <span class="o">=</span> <span class="n">lru_get_new</span><span class="p">(</span><span class="n">lru</span><span class="p">,</span> <span class="s">"leia"</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="s">"leia"</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pi</span><span class="p">)</span>
<span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="mi">24</span><span class="p">;</span>
<span class="c1">// Retrieve values</span>
<span class="kt">int</span> <span class="o">*</span><span class="n">ret</span> <span class="o">=</span> <span class="n">lru_get_try</span><span class="p">(</span><span class="n">lru</span><span class="p">,</span> <span class="s">"luke"</span><span class="p">,</span> <span class="n">strlen</span><span class="p">(</span><span class="s">"luke"</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">ret</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"luke dropped out!</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">else</span> <span class="nf">printf</span><span class="p">(</span><span class="s">"luke's number is %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">*</span><span class="n">ret</span><span class="p">);</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">enemies</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="s">"goro"</span><span class="p">,</span> <span class="s">"raiden"</span><span class="p">,</span> <span class="s">"subzero"</span><span class="p">,</span> <span class="s">"scorpion"</span><span class="p">};</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">4</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int</span> <span class="o">*</span><span class="n">val</span> <span class="o">=</span> <span class="n">lru_get_new</span><span class="p">(</span><span class="n">lru</span><span class="p">,</span> <span class="n">enemies</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">strlen</span><span class="p">(</span><span class="n">enemies</span><span class="p">[</span><span class="n">i</span><span class="p">]));</span>
<span class="k">if</span> <span class="p">(</span><span class="n">val</span><span class="p">)</span>
<span class="o">*</span><span class="n">val</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// We're done</span>
<span class="n">lru_free</span><span class="p">(</span><span class="n">lru</span><span class="p">);</span>
</pre></div>
</div>
</p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Defines</p>
<dl class="define">
<dt>
<span class="target" id="group__generics_1gad333892b01e15ffaf404739d3d421feb"></span><code class="descname">lru_t</code><span class="sig-paren">(</span>type<span class="sig-paren">)</span></dt>
<dd><p>The type for LRU, parametrized by value type. </p>
</dd></dl>
<dl class="define">
<dt id="c.lru_create">
<span class="target" id="group__generics_1ga604ed783a63f8c10fae12f746b9ac197"></span><code class="descname">lru_create</code><span class="sig-paren">(</span>ptable, max_slots, mm_ctx_array, mm_ctx<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_create" title="Permalink to this definition">¶</a></dt>
<dd><p>Allocate and initialize an LRU with default associativity. </p>
<p>The real limit on the number of slots can be a bit larger but less than double.</p>
<p><dl class="docutils">
<dt><strong>Note</strong></dt>
<dd>The pointers to memory contexts need to remain valid during the whole life of the structure (or be NULL). </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">ptable</span></code>: pointer to a pointer to the LRU </li>
<li><code class="docutils literal"><span class="pre">max_slots</span></code>: number of slots </li>
<li><code class="docutils literal"><span class="pre">mm_ctx_array</span></code>: memory context to use for the huge array, NULL for default </li>
<li><code class="docutils literal"><span class="pre">mm_ctx</span></code>: memory context to use for individual key-value pairs, NULL for default</li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.lru_free">
<span class="target" id="group__generics_1ga178f619486791e7c54e169591cc90695"></span><code class="descname">lru_free</code><span class="sig-paren">(</span>table<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_free" title="Permalink to this definition">¶</a></dt>
<dd><p>Free an LRU created by lru_create (it can be NULL). </p>
</dd></dl>
<dl class="define">
<dt id="c.lru_reset">
<span class="target" id="group__generics_1gaffdef67db599af94c504443ccdd96286"></span><code class="descname">lru_reset</code><span class="sig-paren">(</span>table<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_reset" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset an LRU to the empty state (but preserve any settings). </p>
</dd></dl>
<dl class="define">
<dt id="c.lru_get_try">
<span class="target" id="group__generics_1gaa53754b6f0df055ebab192cc2a68ecbd"></span><code class="descname">lru_get_try</code><span class="sig-paren">(</span>table, key_, len_<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_get_try" title="Permalink to this definition">¶</a></dt>
<dd><p>Find key in the LRU and return pointer to the corresponding value. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>pointer to data or NULL if not found </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">table</span></code>: pointer to LRU </li>
<li><code class="docutils literal"><span class="pre">key_</span></code>: lookup key </li>
<li><code class="docutils literal"><span class="pre">len_</span></code>: key length </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.lru_get_new">
<span class="target" id="group__generics_1gabf3ce7347849c33ebfe9b99f94e054ae"></span><code class="descname">lru_get_new</code><span class="sig-paren">(</span>table, key_, len_<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_get_new" title="Permalink to this definition">¶</a></dt>
<dd><p>Return pointer to value, inserting if needed (zeroed). </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>pointer to data or NULL (can be even if memory could be allocated!) </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">table</span></code>: pointer to LRU </li>
<li><code class="docutils literal"><span class="pre">key_</span></code>: lookup key </li>
<li><code class="docutils literal"><span class="pre">len_</span></code>: key lengthkeys </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.lru_apply">
<span class="target" id="group__generics_1ga76586a2848ef4ad20dd46193f038520b"></span><code class="descname">lru_apply</code><span class="sig-paren">(</span>table, function, baton<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_apply" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply a function to every item in LRU. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">table</span></code>: pointer to LRU </li>
<li><code class="docutils literal"><span class="pre">function</span></code>: enum lru_apply_do (*function)(const char *key, uint len, val_type *val, void *baton) See enum lru_apply_do for the return type meanings. </li>
<li><code class="docutils literal"><span class="pre">baton</span></code>: extra pointer passed to each function invocation </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="define">
<dt id="c.lru_capacity">
<span class="target" id="group__generics_1ga6383128ee3aae39ad02dc12dbcdc774f"></span><code class="descname">lru_capacity</code><span class="sig-paren">(</span>table<span class="sig-paren">)</span><a class="headerlink" href="#c.lru_capacity" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the real capacity - maximum number of keys holdable within. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal"><span class="pre">table</span></code>: pointer to LRU </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Enums</p>
<dl class="enum">
<dt id="c.lru_apply_do">
<span class="target" id="group__generics_1gad0db754d244197373c934dba49687cc3"></span><em class="property">enum </em><code class="descname">lru_apply_do</code><a class="headerlink" href="#c.lru_apply_do" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible actions to do with an element. </p>
<p><em>Values:</em></p>
<dl class="enumvalue">
<dt id="c.LRU_APPLY_DO_NOTHING">
<span class="target" id="group__generics_1ggad0db754d244197373c934dba49687cc3ab34ce43d9ca203f5d7b6a19da44c8999"></span><code class="descname">LRU_APPLY_DO_NOTHING</code><a class="headerlink" href="#c.LRU_APPLY_DO_NOTHING" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="enumvalue">
<dt id="c.LRU_APPLY_DO_EVICT">
<span class="target" id="group__generics_1ggad0db754d244197373c934dba49687cc3a41a33d1691fc8c95e25aa219649d951d"></span><code class="descname">LRU_APPLY_DO_EVICT</code><a class="headerlink" href="#c.LRU_APPLY_DO_EVICT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="c.round_power">
<span class="target" id="group__generics_1ga155d51f7388c3e042d39f9bb1ddc3fa7"></span>static <a class="reference internal" href="#c.uint" title="uint">uint</a> <code class="descname">round_power</code><span class="sig-paren">(</span><a class="reference internal" href="#c.uint" title="uint">uint</a><em> size</em>, <a class="reference internal" href="#c.uint" title="uint">uint</a><em> power</em><span class="sig-paren">)</span><a class="headerlink" href="#c.round_power" title="Permalink to this definition">¶</a></dt>
<dd><p>Round the value up to a multiple of (1 << power). </p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Knot DNS Resolver library</a><ul>
<li><a class="reference internal" href="#requirements">Requirements</a></li>
<li><a class="reference internal" href="#for-users">For users</a></li>
<li><a class="reference internal" href="#for-developers">For developers</a></li>
<li><a class="reference internal" href="#writing-layers">Writing layers</a></li>
<li><a class="reference internal" href="#apis-in-lua">APIs in Lua</a><ul>
<li><a class="reference internal" href="#elementary-types-and-constants">Elementary types and constants</a></li>
<li><a class="reference internal" href="#working-with-domain-names">Working with domain names</a></li>
<li><a class="reference internal" href="#working-with-resource-records">Working with resource records</a></li>
<li><a class="reference internal" href="#working-with-packets">Working with packets</a></li>
<li><a class="reference internal" href="#working-with-requests">Working with requests</a></li>
</ul>
</li>
<li><a class="reference internal" href="#api-reference">API reference</a><ul>
<li><a class="reference internal" href="#name-resolution">Name resolution</a></li>
<li><a class="reference internal" href="#cache">Cache</a></li>
<li><a class="reference internal" href="#nameservers">Nameservers</a></li>
<li><a class="reference internal" href="#modules">Modules</a></li>
<li><a class="reference internal" href="#utilities">Utilities</a></li>
<li><a class="reference internal" href="#generics-library">Generics library</a><ul>
<li><a class="reference internal" href="#array">array</a></li>
<li><a class="reference internal" href="#map">map</a></li>
<li><a class="reference internal" href="#set">set</a></li>
<li><a class="reference internal" href="#pack">pack</a></li>
<li><a class="reference internal" href="#lru">lru</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="build.html"
title="previous chapter">Building project</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="modules_api.html"
title="next chapter">Modules API reference</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/lib.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="modules_api.html" title="Modules API reference"
>next</a> |</li>
<li class="right" >
<a href="build.html" title="Building project"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Knot DNS Resolver 2.1.1 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2014-2018 CZ.NIC labs.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
</div>
</body>
</html>
|