|
root / base / usr / src / uts / common / netinet
netinet Plain Text 5920 lines 178.9 KB
   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
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#ident	"%Z%%M%	%I%	%E% SMI"
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# uts/common/netinet/Makefile
#
# include global definitions
include ../../../Makefile.master

HDRS=	arp.h dhcp.h dhcp6.h icmp6.h icmp_var.h if_ether.h igmp.h igmp_var.h \
	in.h inetutil.h in_pcb.h in_systm.h in_var.h ip.h ip6.h ip_icmp.h \
	ip_mroute.h ip_var.h pim.h sctp.h tcp.h tcp_debug.h tcp_fsm.h \
	tcp_seq.h tcp_timer.h tcp_var.h tcpip.h udp.h udp_var.h

ROOTDIRS= $(ROOT)/usr/include/netinet

ROOTHDRS= $(HDRS:%=$(ROOT)/usr/include/netinet/%)

CHECKHDRS= $(HDRS:%.h=%.check)

$(ROOTDIRS)/%: %
	$(INS.file)

.KEEP_STATE:

.PARALLEL: $(CHECKHDRS)

install_h: $(ROOTDIRS) $(ROOTHDRS)

$(ROOTDIRS):
	$(INS.dir)

check:	$(CHECKHDRS)
/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved. The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef	_NETINET_ARP_H
#define	_NETINET_ARP_H

#include <sys/types.h>
#include <sys/ethernet.h>
#include <sys/socket.h>
#include <net/if_arp.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Ethernet Address Resolution Protocol.
 *
 * See RFC 826 for protocol description.  Structure below is adapted
 * to resolving internet addresses.  Field names used correspond to
 * RFC 826.
 */
struct	ether_arp {
	struct	arphdr ea_hdr;		/* fixed-size header */
	struct ether_addr arp_sha;	/* sender hardware address */
	uchar_t	arp_spa[4];		/* sender protocol address */
	struct ether_addr arp_tha;	/* target hardware address */
	uchar_t	arp_tpa[4];		/* target protocol address */
};
#define	arp_hrd	ea_hdr.ar_hrd
#define	arp_pro	ea_hdr.ar_pro
#define	arp_hln	ea_hdr.ar_hln
#define	arp_pln	ea_hdr.ar_pln
#define	arp_op	ea_hdr.ar_op

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_ARP_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 1996-2003 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
 */

/*
 * dhcp.h - Generic DHCP definitions, as per RFC's 2131 and 2132.
 */

#ifndef	_DHCP_H
#define	_DHCP_H

#ifdef	__cplusplus
extern "C" {
#endif

#ifdef  _REENTRANT
#include <thread.h>
#endif  /* _REENTRANT */

/*
 * DHCP option codes.
 */

#define	CD_PAD			0
#define	CD_END			255
#define	CD_SUBNETMASK		1
#define	CD_TIMEOFFSET		2
#define	CD_ROUTER		3
#define	CD_TIMESERV		4
#define	CD_IEN116_NAME_SERV	5
#define	CD_DNSSERV		6
#define	CD_LOG_SERV		7
#define	CD_COOKIE_SERV		8
#define	CD_LPR_SERV		9
#define	CD_IMPRESS_SERV		10
#define	CD_RESOURCE_SERV	11
#define	CD_HOSTNAME		12
#define	CD_BOOT_SIZE		13
#define	CD_DUMP_FILE		14
#define	CD_DNSDOMAIN		15
#define	CD_SWAP_SERV		16
#define	CD_ROOT_PATH		17
#define	CD_EXTEND_PATH		18

/* IP layer parameters */
#define	CD_IP_FORWARDING_ON	19
#define	CD_NON_LCL_ROUTE_ON	20
#define	CD_POLICY_FILTER	21
#define	CD_MAXIPSIZE		22
#define	CD_IPTTL		23
#define	CD_PATH_MTU_TIMEOUT	24
#define	CD_PATH_MTU_TABLE_SZ	25

/* IP layer parameters per interface */
#define	CD_MTU			26
#define	CD_ALL_SUBNETS_LCL_ON	27
#define	CD_BROADCASTADDR	28
#define	CD_MASK_DISCVRY_ON	29
#define	CD_MASK_SUPPLIER_ON	30
#define	CD_ROUTER_DISCVRY_ON	31
#define	CD_ROUTER_SOLICIT_SERV	32
#define	CD_STATIC_ROUTE		33

/* Link Layer Parameters per Interface */
#define	CD_TRAILER_ENCAPS_ON	34
#define	CD_ARP_TIMEOUT		35
#define	CD_ETHERNET_ENCAPS_ON	36

/* TCP Parameters */
#define	CD_TCP_TTL		37
#define	CD_TCP_KALIVE_INTVL	38
#define	CD_TCP_KALIVE_GRBG_ON	39

/* Application layer parameters */
#define	CD_NIS_DOMAIN		40
#define	CD_NIS_SERV		41
#define	CD_NTP_SERV		42
#define	CD_VENDOR_SPEC		43

/* NetBIOS parameters */
#define	CD_NETBIOS_NAME_SERV	44
#define	CD_NETBIOS_DIST_SERV	45
#define	CD_NETBIOS_NODE_TYPE	46
#define	CD_NETBIOS_SCOPE	47

/* X Window parameters */
#define	CD_XWIN_FONT_SERV	48
#define	CD_XWIN_DISP_SERV	49

/* DHCP protocol extension options */
#define	CD_REQUESTED_IP_ADDR	50
#define	CD_LEASE_TIME		51
#define	CD_OPTION_OVERLOAD	52
#define	CD_DHCP_TYPE		53
#define	CD_SERVER_ID		54
#define	CD_REQUEST_LIST		55
#define	CD_MESSAGE		56
#define	CD_MAX_DHCP_SIZE	57
#define	CD_T1_TIME		58
#define	CD_T2_TIME		59
#define	CD_CLASS_ID		60
#define	CD_CLIENT_ID		61

/* Netware options */
#define	CD_NW_IP_DOMAIN		62
#define	CD_NW_IP_OPTIONS	63

/* Nisplus options */
#define	CD_NISPLUS_DMAIN	64
#define	CD_NISPLUS_SERVS	65

/* Optional sname/bootfile options */
#define	CD_TFTP_SERV_NAME	66
#define	CD_OPT_BOOTFILE_NAME	67

/* Additional server options */
#define	CD_MOBILE_IP_AGENT	68
#define	CD_SMTP_SERVS		69
#define	CD_POP3_SERVS		70
#define	CD_NNTP_SERVS		71
#define	CD_WWW_SERVS		72
#define	CD_FINGER_SERVS		73
#define	CD_IRC_SERVS		74

/* Streettalk options */
#define	CD_STREETTALK_SERVS	75
#define	CD_STREETTALK_DA_SERVS	76

/* User class identifier */
#define	CD_USER_CLASS_ID	77

/* Newer options */

#define	CD_SLPDA		78
#define	CD_SLPSS		79
#define	CD_CLIENTFQDN		81
#define	CD_AGENTOPT		82

/*
 * Per RFC 3679, option 89 was "Never published as standard and [is] not in
 * general use". See active CD_CLIENTFQDN and RFC 4702.
 */
#define	CD_FQDN			89

#define	CD_PXEARCHi		93
#define	CD_PXENIIi		94
#define	CD_PXECID		95
#define	CD_MULTICST		107

#define	DHCP_FIRST_OPT		CD_SUBNETMASK
#define	DHCP_LAST_STD		CD_MULTICST
#define	DHCP_SITE_OPT		128		/* inclusive */
#define	DHCP_END_SITE		254
#define	DHCP_LAST_OPT		DHCP_END_SITE	/* last op code */

#define	DHCP_MAX_OPT_SIZE	255	/* maximum option size in octets */

/*
 * DHCP Packet. What will fit in a ethernet frame. We may use a smaller
 * size, based on what our transport can handle.
 */
#define	DHCP_DEF_MAX_SIZE	576	/* as spec'ed in RFC 2131 */
#define	PKT_BUFFER		1486	/* max possible size of pkt buffer */
#define	BASE_PKT_SIZE		240	/* everything but the options */
typedef struct dhcp {
	uint8_t		op;		/* message opcode */
	uint8_t		htype;		/* Hardware address type */
	uint8_t		hlen;		/* Hardware address length */
	uint8_t		hops;		/* Used by relay agents */
	uint32_t	xid;		/* transaction id */
	uint16_t	secs;		/* Secs elapsed since client boot */
	uint16_t	flags;		/* DHCP Flags field */
	struct in_addr	ciaddr;		/* client IP addr */
	struct in_addr	yiaddr;		/* 'Your' IP addr. (from server) */
	struct in_addr	siaddr;		/* Boot server IP addr */
	struct in_addr	giaddr;		/* Relay agent IP addr */
	uint8_t		chaddr[16];	/* Client hardware addr */
	uint8_t		sname[64];	/* Optl. boot server hostname */
	uint8_t		file[128];	/* boot file name (ascii path) */
	uint8_t		cookie[4];	/* Magic cookie */
	uint8_t		options[60];	/* Options */
} PKT;

typedef uint32_t	lease_t; /* DHCP lease time (32 bit quantity) */

/*
 * DHCP packet types. As per protocol.
 */
#define	DISCOVER	((uint8_t)1)
#define	OFFER		((uint8_t)2)
#define	REQUEST		((uint8_t)3)
#define	DECLINE		((uint8_t)4)
#define	ACK		((uint8_t)5)
#define	NAK		((uint8_t)6)
#define	RELEASE		((uint8_t)7)
#define	INFORM		((uint8_t)8)

/*
 * Generic DHCP protocol defines
 */
#define	DHCP_PERM	((lease_t)0xffffffff)	/* "permanent" lease time */
#define	BOOTREQUEST		(1)		/* BOOTP REQUEST opcode */
#define	BOOTREPLY		(2)		/* BOOTP REPLY opcode */
#define	BOOTMAGIC	{ 99, 130, 83, 99 }	/* rfc1048 magic cookie */
#define	BCAST_MASK	0x8000			/* BROADCAST flag */

#ifdef	__cplusplus
}
#endif

#endif	/* _DHCP_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _DHCP6_H
#define	_DHCP6_H

/*
 * This header file describes constants and on-the-wire data structures used
 * with DHCPv6.
 *
 * Note that the data structures contained here must be used with caution.  The
 * DHCPv6 protocol generally does not maintain alignment.
 *
 * (Users may also need to include other header files to get ntohs/htons
 * definitions, if the DHCPV6_{GET,SET} macros are used.)
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <netinet/in.h>

/*
 * Message Types
 */
#define	DHCPV6_MSG_SOLICIT	1	/* Client sends */
#define	DHCPV6_MSG_ADVERTISE	2	/* Server sends */
#define	DHCPV6_MSG_REQUEST	3	/* Client sends */
#define	DHCPV6_MSG_CONFIRM	4	/* Client sends */
#define	DHCPV6_MSG_RENEW	5	/* Client sends */
#define	DHCPV6_MSG_REBIND	6	/* Client sends */
#define	DHCPV6_MSG_REPLY	7	/* Server sends */
#define	DHCPV6_MSG_RELEASE	8	/* Client sends */
#define	DHCPV6_MSG_DECLINE	9	/* Client sends */
#define	DHCPV6_MSG_RECONFIGURE	10	/* Server sends */
#define	DHCPV6_MSG_INFO_REQ	11	/* Client sends */
#define	DHCPV6_MSG_RELAY_FORW	12	/* Relay agent sends to server */
#define	DHCPV6_MSG_RELAY_REPL	13	/* Server sends to relay agent */

/*
 * Status Codes
 */
#define	DHCPV6_STAT_SUCCESS	0
#define	DHCPV6_STAT_UNSPECFAIL	1	/* Unknown reason */
#define	DHCPV6_STAT_NOADDRS	2	/* Server has no addresses available */
#define	DHCPV6_STAT_NOBINDING	3	/* Client record unavailable */
#define	DHCPV6_STAT_NOTONLINK	4	/* Prefix inappropriate for link */
#define	DHCPV6_STAT_USEMCAST	5	/* Client must use multicast */
#define	DHCPV6_STAT_NOPREFIX	6	/* No prefix available; RFC3633 */

/*
 * DHCP Unique Identifier (DUID) Types
 */
#define	DHCPV6_DUID_LLT		1	/* Link layer address plus time */
#define	DHCPV6_DUID_EN		2	/* Vendor assigned */
#define	DHCPV6_DUID_LL		3	/* Link layer address */

/*
 * DHCPv6 Option Codes
 * Note: options 10 and 35 are not assigned.
 */
#define	DHCPV6_OPT_CLIENTID	1	/* Client's DUID */
#define	DHCPV6_OPT_SERVERID	2	/* Server's DUID */
#define	DHCPV6_OPT_IA_NA	3	/* Non-temporary addrs; dhcpv6_ia_na */
#define	DHCPV6_OPT_IA_TA	4	/* Temporary addrs; dhcpv6_ia_ta */
#define	DHCPV6_OPT_IAADDR	5	/* IA Address; dhcpv6_iaaddr */
#define	DHCPV6_OPT_ORO		6	/* Option Request; uint16_t array */
#define	DHCPV6_OPT_PREFERENCE	7	/* Server preference; uint8_t */
#define	DHCPV6_OPT_ELAPSED_TIME	8	/* Client time; uint16_t; centisec */
#define	DHCPV6_OPT_RELAY_MSG	9	/* Relayed client DHCP message */
#define	DHCPV6_OPT_AUTH		11	/* Authentication; dhcpv6_auth */
#define	DHCPV6_OPT_UNICAST	12	/* Client may unicast; in6_addr_t */
#define	DHCPV6_OPT_STATUS_CODE	13	/* Status; uint16_t plus string */
#define	DHCPV6_OPT_RAPID_COMMIT	14	/* Server may do RC; boolean (len 0) */
#define	DHCPV6_OPT_USER_CLASS	15	/* Classes; {uint16_t,uint8_t...}... */
#define	DHCPV6_OPT_VENDOR_CLASS	16	/* Client vendor; uint32_t + list */
#define	DHCPV6_OPT_VENDOR_OPT	17	/* Vendor specific; uint32_t+opts */
#define	DHCPV6_OPT_INTERFACE_ID	18	/* Relay agent interface */
#define	DHCPV6_OPT_RECONF_MSG	19	/* Reconfigure; uint8_t */
#define	DHCPV6_OPT_RECONF_ACC	20	/* Reconfigure accept; boolean */
#define	DHCPV6_OPT_SIP_NAMES	21	/* SIP srv domain names (RFC3319) */
#define	DHCPV6_OPT_SIP_ADDR	22	/* SIP srv IPv6 address (RFC3319) */
#define	DHCPV6_OPT_DNS_ADDR	23	/* DNS Recur. Name Server (RFC3646) */
#define	DHCPV6_OPT_DNS_SEARCH	24	/* Domain Search List (RFC3646) */
#define	DHCPV6_OPT_IA_PD	25	/* Delegate dhcpv6_ia_na (RFC3633) */
#define	DHCPV6_OPT_IAPREFIX	26	/* Prefix dhcpv6_iaprefix (RFC3633) */
#define	DHCPV6_OPT_NIS_SERVERS	27	/* NIS in6_addr_t array (RFC3898) */
#define	DHCPV6_OPT_NIS_DOMAIN	29	/* NIS Domain string (RFC3898) */
#define	DHCPV6_OPT_SNTP_SERVERS	31	/* SNTP in6_addr_t array (RFC4075) */
#define	DHCPV6_OPT_INFO_REFTIME	32	/* Info refresh uint32_t (RFC4242) */
#define	DHCPV6_OPT_BCMCS_SRV_D	33	/* NUL-term string list (RFC4280) */
#define	DHCPV6_OPT_BCMCS_SRV_A	34	/* in6_addr_t array (RFC4280) */
#define	DHCPV6_OPT_GEOCONF_CVC	36	/* dhcpv6_civic_t plus TLVs */
#define	DHCPV6_OPT_REMOTE_ID	37	/* uint32_t plus opaque */
#define	DHCPV6_OPT_SUBSCRIBER	38	/* opaque; may be NVT ASCII */
#define	DHCPV6_OPT_CLIENT_FQDN	39	/* uint8_t plus domain */

/*
 * Reconfiguration types; used with DHCPV6_OPT_RECONF_MSG option.
 */
#define	DHCPV6_RECONF_RENEW	5	/* Renew now */
#define	DHCPV6_RECONF_INFO	11	/* Request information */

/*
 * FQDN Flags; used with DHCPV6_OPT_CLIENT_FQDN option.
 */
#define	DHCPV6_FQDNF_S	0x01	/* Server should perform AAAA RR updates */
#define	DHCPV6_FQDNF_O	0x02	/* Server override of 'S' bit */
#define	DHCPV6_FQDNF_N	0x04	/* Server should not perform any updates */

/*
 * Miscellany
 */
#define	DHCPV6_INFTIME	0xfffffffful	/* Infinity; used for timers */
#define	DHCPV6_FOREVER	0xffff		/* Used for elapsed time option */
#define	DHCPV6_SUN_ENT	42		/* Sun Microsystems enterprise ID */

/*
 * Basic DHCPv6 message header used for server/client communications.  The
 * options follow this header.
 */
struct dhcpv6_message {
	uint8_t		d6m_msg_type;
	uint8_t		d6m_transid_ho;
	uint16_t	d6m_transid_lo;
};

#define	DHCPV6_GET_TRANSID(msg) \
	(((msg)->d6m_transid_ho << 16) + ntohs((msg)->d6m_transid_lo))
#define	DHCPV6_SET_TRANSID(msg, id) \
	((msg)->d6m_transid_ho = (id) >> 16, (msg)->d6m_transid_lo = htons(id))

/*
 * DHCPv6 relay agent header used only for server/relay communications.  The
 * options follow this header, and the client message is encapsulated as an
 * option.  Note that the IPv6 addresses are not on natural word boundaries.
 */
struct dhcpv6_relay {
	uint8_t		d6r_msg_type;
	uint8_t		d6r_hop_count;
	uint8_t		d6r_linkaddr[16];
	uint8_t		d6r_peeraddr[16];
};

/*
 * DHCPv6 generic option header.  Note that options are not aligned on any
 * convenient boundary.
 */
struct dhcpv6_option {
	uint16_t	d6o_code;
	uint16_t	d6o_len;
};

/*
 * Option header for IA_NA (Non-temporary addresses) and IA_PD (Prefix
 * delegation).  Contains IA Address options for IA_NA, IA_PD Prefixes for
 * IA_PD.
 */
struct dhcpv6_ia_na {
	uint16_t	d6in_code;
	uint16_t	d6in_len;
	uint32_t	d6in_iaid;	/* Unique ID [interface] */
	uint32_t	d6in_t1;	/* Extend from same server */
	uint32_t	d6in_t2;	/* Extend from any server */
};

/*
 * Option header for IA_TA (Temporary addresses).  Contains IA Address options.
 */
struct dhcpv6_ia_ta {
	uint16_t	d6it_code;
	uint16_t	d6it_len;
	uint32_t	d6it_iaid;	/* Unique ID [interface] */
};

/*
 * Option header for IA Address.  Must be used inside of an IA_NA or IA_TA
 * option.  May contain a Status Code option.
 */
struct dhcpv6_iaaddr {
	uint16_t	d6ia_code;
	uint16_t	d6ia_len;
	in6_addr_t	d6ia_addr;	/* IPv6 address */
	uint32_t	d6ia_preflife;	/* Preferred lifetime */
	uint32_t	d6ia_vallife;	/* Valid lifetime */
};

/*
 * Option header for Authentication.  Followed by variable-length
 * authentication information field.  Warning: padding may be present.  Use
 * defined size.
 */
struct dhcpv6_auth {
	uint16_t	d6a_code;
	uint16_t	d6a_len;
	uint8_t		d6a_proto;	/* Protocol */
	uint8_t		d6a_alg;	/* Algorithm */
	uint8_t		d6a_rdm;	/* Replay Detection Method (RDM) */
	uint8_t		d6a_replay[8];	/* Information for RDM */
};
#define	DHCPV6_AUTH_SIZE	15

/* dhpv6_auth.d6a_proto values */
#define	DHCPV6_PROTO_DELAYED	2	/* Delayed Authentication mechanism */
#define	DHCPV6_PROTO_RECONFIG	3	/* Reconfigure Key mechanism */

/* dhpv6_auth.d6a_alg values */
#define	DHCPV6_ALG_HMAC_MD5	1	/* HMAC-MD5 signature */

/* dhpv6_auth.d6a_rdm values */
#define	DHCPV6_RDM_MONOCNT	0	/* Monotonic counter */

/*
 * Option header for IA_PD Prefix.  Must be used inside of an IA_PD option.
 * May contain a Status Code option.  Warning: padding may be present; use
 * defined size.
 */
struct dhcpv6_iaprefix {
	uint16_t	d6ip_code;
	uint16_t	d6ip_len;
	uint32_t	d6ip_preflife;	/* Preferred lifetime */
	uint32_t	d6ip_vallife;	/* Valid lifetime */
	uint8_t		d6ip_preflen;	/* Prefix length */
	uint8_t		d6ip_addr[16];	/* IPv6 prefix */
};
#define	DHCPV6_IAPREFIX_SIZE	29

/*
 * Option header for Civic Address information.  Followed by single octet TLV
 * encoded address elements, using CIVICADDR_* values for type.  Warning:
 * padding may be present; use defined size.
 */
struct dhcpv6_civic {
	uint16_t	d6c_code;
	uint16_t	d6c_len;
	uint8_t		d6c_what;	/* DHCPV6_CWHAT_* value */
	char		d6c_cc[2];		/* Country code; ISO 3166 */
};
#define	DHCPV6_CIVIC_SIZE	7

#define	DHCPV6_CWHAT_SERVER	0	/* Location of server */
#define	DHCPV6_CWHAT_NETWORK	1	/* Location of network */
#define	DHCPV6_CWHAT_CLIENT	2	/* Location of client */

#define	CIVICADDR_LANG	0	/* Language; RFC 2277 */
#define	CIVICADDR_A1	1	/* National division (state) */
#define	CIVICADDR_A2	2	/* County */
#define	CIVICADDR_A3	3	/* City */
#define	CIVICADDR_A4	4	/* City division */
#define	CIVICADDR_A5	5	/* Neighborhood */
#define	CIVICADDR_A6	6	/* Street group */
#define	CIVICADDR_PRD	16	/* Leading street direction */
#define	CIVICADDR_POD	17	/* Trailing street suffix */
#define	CIVICADDR_STS	18	/* Street suffix or type */
#define	CIVICADDR_HNO	19	/* House number */
#define	CIVICADDR_HNS	20	/* House number suffix */
#define	CIVICADDR_LMK	21	/* Landmark */
#define	CIVICADDR_LOC	22	/* Additional location information */
#define	CIVICADDR_NAM	23	/* Name/occupant */
#define	CIVICADDR_PC	24	/* Postal Code/ZIP */
#define	CIVICADDR_BLD	25	/* Building */
#define	CIVICADDR_UNIT	26	/* Unit/apt/suite */
#define	CIVICADDR_FLR	27	/* Floor */
#define	CIVICADDR_ROOM	28	/* Room number */
#define	CIVICADDR_TYPE	29	/* Place type */
#define	CIVICADDR_PCN	30	/* Postal community name */
#define	CIVICADDR_POBOX	31	/* Post office box */
#define	CIVICADDR_ADDL	32	/* Additional code */
#define	CIVICADDR_SEAT	33	/* Seat/desk */
#define	CIVICADDR_ROAD	34	/* Primary road or street */
#define	CIVICADDR_RSEC	35	/* Road section */
#define	CIVICADDR_RBRA	36	/* Road branch */
#define	CIVICADDR_RSBR	37	/* Road sub-branch */
#define	CIVICADDR_SPRE	38	/* Street name pre-modifier */
#define	CIVICADDR_SPOST	39	/* Street name post-modifier */
#define	CIVICADDR_SCRIPT 128	/* Script */

/*
 * DHCP Unique Identifier structures.  These represent the fixed portion of the
 * unique identifier object, and are followed by the variable-length link layer
 * address or identifier.
 */
struct duid_llt {
	uint16_t	dllt_dutype;
	uint16_t	dllt_hwtype;
	uint32_t	dllt_time;
};

/* DUID time stamps start on January 1st, 2000 UTC */
#define	DUID_TIME_BASE	946684800ul

struct duid_en {
	uint16_t	den_dutype;
	uint16_t	den_entho;
	uint16_t	den_entlo;
};

#define	DHCPV6_GET_ENTNUM(den) \
	((ntohs((den)->den_entho) << 16) + ntohs((den)->den_entlo))
#define	DHCPV6_SET_ENTNUM(den, val) \
	((den)->den_entho = htons((val) >> 16), (den)->den_entlo = htons(val))

struct duid_ll {
	uint16_t	dll_dutype;
	uint16_t	dll_hwtype;
};

/*
 * Data types
 */
typedef	struct dhcpv6_message	dhcpv6_message_t;
typedef	struct dhcpv6_relay	dhcpv6_relay_t;
typedef	struct dhcpv6_option	dhcpv6_option_t;
typedef	struct dhcpv6_ia_na	dhcpv6_ia_na_t;
typedef	struct dhcpv6_ia_ta	dhcpv6_ia_ta_t;
typedef	struct dhcpv6_iaaddr	dhcpv6_iaaddr_t;
typedef	struct dhcpv6_auth	dhcpv6_auth_t;
typedef	struct dhcpv6_iaprefix	dhcpv6_iaprefix_t;
typedef struct dhcpv6_civic	dhcpv6_civic_t;
typedef	struct duid_llt		duid_llt_t;
typedef	struct duid_en		duid_en_t;
typedef	struct duid_ll		duid_ll_t;

#ifdef __cplusplus
}
#endif

#endif /* _DHCP6_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/*
 * Copyright 2024 Bill Sommerfeld <sommerfeld@hamachi.org>
 */

#ifndef	_NETINET_ICMP6_H
#define	_NETINET_ICMP6_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <sys/types.h>

/*
 * Type and code definitions for ICMPv6.
 * Based on RFC2292.
 */

#define	ICMP6_INFOMSG_MASK		0x80 /* all informational messages */

/* Minimum ICMPv6 header length. */
#define	ICMP6_MINLEN	8

typedef struct icmp6_hdr {
	uint8_t	 icmp6_type;	/* type field */
	uint8_t	 icmp6_code;	/* code field */
	uint16_t icmp6_cksum;	/* checksum field */
	union {
		uint32_t icmp6_un_data32[1];	/* type-specific field */
		uint16_t icmp6_un_data16[2];	/* type-specific field */
		uint8_t	 icmp6_un_data8[4];	/* type-specific field */
	} icmp6_dataun;
} icmp6_t;

#define	icmp6_data32	icmp6_dataun.icmp6_un_data32
#define	icmp6_data16	icmp6_dataun.icmp6_un_data16
#define	icmp6_data8	icmp6_dataun.icmp6_un_data8
#define	icmp6_pptr	icmp6_data32[0]	/* parameter prob */
#define	icmp6_mtu	icmp6_data32[0]	/* packet too big */
#define	icmp6_id	icmp6_data16[0]	/* echo request/reply */
#define	icmp6_seq	icmp6_data16[1]	/* echo request/reply */
#define	icmp6_maxdelay	icmp6_data16[0]	/* mcast group membership */

/* Multicast Listener Discovery messages (RFC 3542 (v1), RFC 3810 (v2)). */

#define	MLD_MINLEN		24
#define	MLD_V2_QUERY_MINLEN	28

/* Query Header, common to v1 and v2 */
typedef struct mld_hdr {
	struct icmp6_hdr	mld_icmp6_hdr;
	struct in6_addr		mld_addr; /* multicast address */
} mld_hdr_t;

#define	mld_type	mld_icmp6_hdr.icmp6_type
#define	mld_code	mld_icmp6_hdr.icmp6_code
#define	mld_cksum	mld_icmp6_hdr.icmp6_cksum
#define	mld_maxdelay	mld_icmp6_hdr.icmp6_data16[0]
#define	mld_reserved	mld_icmp6_hdr.icmp6_data16[1]

/* MLDv2 query */
typedef struct mld2q {
	mld_hdr_t	mld2q_hdr;
	uint8_t		mld2q_sqrv;	/* S Flag, Q's Robustness Variable  */
	uint8_t		mld2q_qqic;	/* Querier's Query Interval Code    */
	uint16_t	mld2q_numsrc;	/* number of sources		    */
} mld2q_t;

#define	mld2q_type	mld2q_hdr.mld_icmp6_hdr.icmp6_type
#define	mld2q_code	mld2q_hdr.mld_icmp6_hdr.icmp6_code
#define	mld2q_cksum	mld2q_hdr.mld_icmp6_hdr.icmp6_cksum
#define	mld2q_mxrc	mld2q_hdr.mld_icmp6_hdr.icmp6_data16[0]
#define	mld2q_addr	mld2q_hdr.mld_addr

#define	MLD_V2_SFLAG_MASK		0x8	/* mask off s part of sqrv */
#define	MLD_V2_RV_MASK			0x7	/* mask off qrv part of sqrv */

/* definitions used to extract max response delay from mrc field */
#define	MLD_V2_MAXRT_FPMIN	0x8000
#define	MLD_V2_MAXRT_MANT_MASK	0x0fff
#define	MLD_V2_MAXRT_EXP_MASK	0x7000

/* definitions used to extract querier's query interval from qqic field */
#define	MLD_V2_QQI_FPMIN	0x80
#define	MLD_V2_QQI_MANT_MASK	0x0f
#define	MLD_V2_QQI_EXP_MASK	0x70

/* MLDv2 response */
typedef icmp6_t		mld2r_t;

#define	mld2r_type	icmp6_type
#define	mld2r_res	icmp6_code
#define	mld2r_cksum	icmp6_cksum
#define	mld2r_res1	icmp6_data16[0]
#define	mld2r_nummar	icmp6_data16[1]

/* MLDv2 multicast address record */
typedef struct mld2mar {
	uint8_t		mld2mar_type;	/* type of record		    */
	uint8_t		mld2mar_auxlen;	/* auxiliary data length	    */
	uint16_t	mld2mar_numsrc;	/* number of sources		    */
	struct in6_addr	mld2mar_group;	/* group address being reported	    */
} mld2mar_t;


/* For router renumbering. */
struct icmp6_router_renum {	/* router renumbering header */
	struct icmp6_hdr	rr_hdr;
	uint8_t			rr_segnum;
	uint8_t			rr_flags;
	uint16_t		rr_maxdelay;
	uint32_t		rr_reserved;
};

#define	rr_type		rr_hdr.icmp6_type
#define	rr_code		rr_hdr.icmp6_code
#define	rr_cksum	rr_hdr.icmp6_cksum
#define	rr_seqnum	rr_hdr.icmp6_data32[0]

/* Router renumbering flags */
#define	ICMP6_RR_FLAGS_TEST		0x80
#define	ICMP6_RR_FLAGS_REQRESULT	0x40
#define	ICMP6_RR_FLAGS_FORCEAPPLY	0x20
#define	ICMP6_RR_FLAGS_SPECSITE		0x10
#define	ICMP6_RR_FLAGS_PREVDONE		0x08

struct rr_pco_match {	/* match prefix part */
	uint8_t			rpm_code;
	uint8_t			rpm_len;
	uint8_t			rpm_ordinal;
	uint8_t			rpm_matchlen;
	uint8_t			rpm_minlen;
	uint8_t			rpm_maxlen;
	uint16_t		rpm_reserved;
	struct in6_addr		rpm_prefix;
};

/* PCO code values */
#define	RPM_PCO_ADD			1
#define	RPM_PCO_CHANGE			2
#define	RPM_PCO_SETGLOBAL		3

struct rr_pco_use {	/* use prefix part */
	uint8_t			rpu_uselen;
	uint8_t			rpu_keeplen;
	uint8_t			rpu_ramask;
	uint8_t			rpu_raflags;
	uint32_t		rpu_vltime;
	uint32_t		rpu_pltime;
	uint32_t		rpu_flags;
	struct in6_addr		rpu_prefix;
};

#define	ICMP6_RR_PCOUSE_RAFLAGS_ONLINK	0x20
#define	ICMP6_RR_PCOUSE_RAFLAGS_AUTO	0x10

#ifdef _BIG_ENDIAN
#define	ICMP_RR_PCOUSE_FLAGS_DECRVLTIME	0x80000000
#define	ICMP_RR_PCOUSE_FLAGS_DECRPLTIME	0x40000000
#else /* _BIG_ENDIAN */
#define	ICMP_RR_PCOUSE_FLAGS_DECRVLTIME	0x80
#define	ICMP_RR_PCOUSE_FLAGS_DECRPLTIME	0x40
#endif /* _BIG_ENDIAN */

struct rr_result {	/* router renumbering result message */
	uint16_t		rrr_flags;
	uint8_t			rrr_ordinal;
	uint8_t			rrr_matchedlen;
	uint32_t		rrr_ifid;
	struct in6_addr		rrr_prefix;
};

#ifdef _BIG_ENDIAN
#define	ICMP6_RR_RESULT_FLAGS_OOB	0x0002
#define	ICMP6_RR_RESULT_FLAGS_FORBIDDEN	0x0001
#else /* _BIG_ENDIAN */
#define	ICMP6_RR_RESULT_FLAGS_OOB	0x0200
#define	ICMP6_RR_RESULT_FLAGS_FORBIDDEN	0x0100
#endif /* _BIG_ENDIAN */

/* ICMPv6 error types */
#define	ICMP6_DST_UNREACH		1
#define	ICMP6_PACKET_TOO_BIG		2
#define	ICMP6_TIME_EXCEEDED		3
#define	ICMP6_PARAM_PROB		4

#define	ICMP6_INFOMSG_MASK		0x80 /* all informational messages */

/* ICMPv6 query types */
#define	ICMP6_ECHO_REQUEST		128
#define	ICMP6_ECHO_REPLY		129

/*
 * ICMPv6 group membership types
 * ICMP6_MEMBERSHIP* types are the older names for these constants and should
 * not be used in new code.
 */
#define	MLD_LISTENER_QUERY		130
#define	ICMP6_MEMBERSHIP_QUERY		130
#define	MLD_LISTENER_REPORT		131
#define	ICMP6_MEMBERSHIP_REPORT		131
#define	MLD_LISTENER_REDUCTION		132
#define	ICMP6_MEMBERSHIP_REDUCTION	132
#define	MLD_V2_LISTENER_REPORT		143

/* types for neighbor discovery */
#define	ND_ROUTER_SOLICIT		133
#define	ND_ROUTER_ADVERT		134
#define	ND_NEIGHBOR_SOLICIT		135
#define	ND_NEIGHBOR_ADVERT		136
#define	ND_REDIRECT			137

/* router renumbering */
#define	ICMP6_ROUTER_RENUMBERING	138

#define	ICMP6_MAX_INFO_TYPE		138

#define	ICMP6_IS_ERROR(x) ((x) < 128)

/* codes for ICMP6_DST_UNREACH */
#define	ICMP6_DST_UNREACH_NOROUTE	0 /* no route to destination */
#define	ICMP6_DST_UNREACH_ADMIN		1 /* communication with destination */
					/* administratively prohibited */
#define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2 /* not a neighbor */
#define	ICMP6_DST_UNREACH_BEYONDSCOPE	2 /* beyond scope of source */
#define	ICMP6_DST_UNREACH_ADDR		3 /* address unreachable */
#define	ICMP6_DST_UNREACH_NOPORT	4 /* bad port */

/* codes for ICMP6_TIME_EXCEEDED */
#define	ICMP6_TIME_EXCEED_TRANSIT	0 /* Hop Limit == 0 in transit */
#define	ICMP6_TIME_EXCEED_REASSEMBLY	1 /* Reassembly time out */

/* codes for ICMP6_PARAM_PROB */
#define	ICMP6_PARAMPROB_HEADER		0 /* erroneous header field */
#define	ICMP6_PARAMPROB_NEXTHEADER	1 /* unrecognized Next Header */
#define	ICMP6_PARAMPROB_OPTION		2 /* unrecognized IPv6 option */

/* Default MLD max report delay value */
#define	ICMP6_MAX_HOST_REPORT_DELAY	10	/* max delay for response to */
						/* query (in seconds)   */

typedef struct nd_router_solicit {	/* router solicitation */
	icmp6_t		nd_rs_hdr;
	/* could be followed by options */
} nd_router_solicit_t;

#define	nd_rs_type	nd_rs_hdr.icmp6_type
#define	nd_rs_code	nd_rs_hdr.icmp6_code
#define	nd_rs_cksum	nd_rs_hdr.icmp6_cksum
#define	nd_rs_reserved	nd_rs_hdr.icmp6_data32[0]

typedef struct nd_router_advert {	/* router advertisement */
	icmp6_t		nd_ra_hdr;
	uint32_t	nd_ra_reachable;   /* reachable time */
	uint32_t	nd_ra_retransmit;  /* retransmit timer */
	/* could be followed by options */
} nd_router_advert_t;

#define	nd_ra_type		nd_ra_hdr.icmp6_type
#define	nd_ra_code		nd_ra_hdr.icmp6_code
#define	nd_ra_cksum		nd_ra_hdr.icmp6_cksum
#define	nd_ra_curhoplimit	nd_ra_hdr.icmp6_data8[0]
#define	nd_ra_flags_reserved	nd_ra_hdr.icmp6_data8[1]

#define	ND_RA_FLAG_OTHER	0x40
#define	ND_RA_FLAG_MANAGED	0x80

#define	nd_ra_router_lifetime    nd_ra_hdr.icmp6_data16[1]

typedef struct nd_neighbor_solicit {   /* neighbor solicitation */
	icmp6_t		nd_ns_hdr;
	struct in6_addr nd_ns_target; /* target address */
	/* could be followed by options */
} nd_neighbor_solicit_t;

#define	nd_ns_type		nd_ns_hdr.icmp6_type
#define	nd_ns_code		nd_ns_hdr.icmp6_code
#define	nd_ns_cksum		nd_ns_hdr.icmp6_cksum
#define	nd_ns_reserved		nd_ns_hdr.icmp6_data32[0]

typedef struct nd_neighbor_advert {	/* neighbor advertisement */
	icmp6_t		  nd_na_hdr;
	struct in6_addr   nd_na_target; /* target address */
	/* could be followed by options */
} nd_neighbor_advert_t;

#define	nd_na_type	nd_na_hdr.icmp6_type
#define	nd_na_code	nd_na_hdr.icmp6_code
#define	nd_na_cksum	nd_na_hdr.icmp6_cksum

#define	nd_na_flags_reserved	nd_na_hdr.icmp6_data32[0]

/*
 * The first three bits of the flgs_reserved field of the ND structure are
 * defined in this order:
 *	Router flag
 *	Solicited flag
 *	Override flag
 */

/* Save valuable htonl() cycles on little-endian boxen. */

#ifdef _BIG_ENDIAN

#define	ND_NA_FLAG_ROUTER	0x80000000
#define	ND_NA_FLAG_SOLICITED	0x40000000
#define	ND_NA_FLAG_OVERRIDE	0x20000000

#else /* _BIG_ENDIAN */

#define	ND_NA_FLAG_ROUTER	0x80
#define	ND_NA_FLAG_SOLICITED	0x40
#define	ND_NA_FLAG_OVERRIDE	0x20

#endif /* _BIG_ENDIAN */

typedef struct nd_redirect {	/* redirect */
	icmp6_t		nd_rd_hdr;
	struct in6_addr	nd_rd_target; /* target address */
	struct in6_addr	nd_rd_dst;    /* destination address */
	/* could be followed by options */
} nd_redirect_t;

#define	nd_rd_type	nd_rd_hdr.icmp6_type
#define	nd_rd_code	nd_rd_hdr.icmp6_code
#define	nd_rd_cksum	nd_rd_hdr.icmp6_cksum
#define	nd_rd_reserved	nd_rd_hdr.icmp6_data32[0]

typedef struct nd_opt_hdr {	/* Neighbor discovery option header */
	uint8_t	nd_opt_type;
	uint8_t	nd_opt_len;	/* in units of 8 octets */
	/* followed by option specific data */
} nd_opt_hdr_t;

/* Neighbor discovery option types */
#define	ND_OPT_SOURCE_LINKADDR		1
#define	ND_OPT_TARGET_LINKADDR		2
#define	ND_OPT_PREFIX_INFORMATION	3
#define	ND_OPT_REDIRECTED_HEADER	4
#define	ND_OPT_MTU			5
#define	ND_OPT_DNS_RESOLVER		25
#define	ND_OPT_DNS_SEARCHLIST		31

typedef struct nd_opt_prefix_info {	/* prefix information */
	uint8_t   nd_opt_pi_type;
	uint8_t   nd_opt_pi_len;
	uint8_t   nd_opt_pi_prefix_len;
	uint8_t   nd_opt_pi_flags_reserved;
	uint32_t  nd_opt_pi_valid_time;
	uint32_t  nd_opt_pi_preferred_time;
	uint32_t  nd_opt_pi_reserved2;
	struct in6_addr  nd_opt_pi_prefix;
} nd_opt_prefix_info_t;

#define	ND_OPT_PI_FLAG_AUTO	0x40
#define	ND_OPT_PI_FLAG_ONLINK	0x80

typedef struct nd_opt_rd_hdr {	/* redirected header */
	uint8_t   nd_opt_rh_type;
	uint8_t   nd_opt_rh_len;
	uint16_t  nd_opt_rh_reserved1;
	uint32_t  nd_opt_rh_reserved2;
	/* followed by IP header and data */
} nd_opt_rd_hdr_t;

typedef struct nd_opt_mtu {	/* MTU option */
	uint8_t   nd_opt_mtu_type;
	uint8_t   nd_opt_mtu_len;
	uint16_t  nd_opt_mtu_reserved;
	uint32_t  nd_opt_mtu_mtu;
} nd_opt_mtu_t;

/* Note: the option is variable length (at least 8 bytes long) */
#ifndef ND_MAX_HDW_LEN
#define	ND_MAX_HDW_LEN	64
#endif
struct nd_opt_lla {
	uint8_t	nd_opt_lla_type;
	uint8_t	nd_opt_lla_len;	/* in units of 8 octets */
	uint8_t	nd_opt_lla_hdw_addr[ND_MAX_HDW_LEN];
};

struct nd_opt_dns_resolver {
	uint8_t	  nd_opt_dnsr_type;
	uint8_t	  nd_opt_dnsr_len;	/* in units of 8 octets */
	uint16_t  nd_opt_dnsr_reserved;
	uint32_t  nd_opt_dnsr_lifetime;
	struct in6_addr nd_opt_dnsr_addr[];
};

struct nd_opt_dns_sl {
	uint8_t	  nd_opt_dnss_type;
	uint8_t	  nd_opt_dnss_len;	/* in units of 8 octets */
	uint16_t  nd_opt_dnss_reserved;
	uint32_t  nd_opt_dnss_lifetime;
	uint8_t   nd_opt_dnss_names[];
};

/* Neighbor discovery protocol constants */

/* Router constants */
#define	ND_MAX_INITIAL_RTR_ADVERT_INTERVAL	16000	/* milliseconds */
#define	ND_MAX_INITIAL_RTR_ADVERTISEMENTS	3	/* transmissions */
#define	ND_MAX_FINAL_RTR_ADVERTISEMENTS		3	/* transmissions */
#define	ND_MIN_DELAY_BETWEEN_RAS		3000	/* milliseconds */
#define	ND_MAX_RA_DELAY_TIME			500	/* milliseconds */

/* Host constants */
#define	ND_MAX_RTR_SOLICITATION_DELAY		1000	/* milliseconds */
#define	ND_RTR_SOLICITATION_INTERVAL		4000	/* milliseconds */
#define	ND_MAX_RTR_SOLICITATIONS		3	/* transmissions */

/* Node constants */
#define	ND_MAX_MULTICAST_SOLICIT		3	/* transmissions */
#define	ND_MAX_UNICAST_SOLICIT			3	/* transmissions */
#define	ND_MAX_ANYCAST_DELAY_TIME		1000	/* milliseconds */
#define	ND_MAX_NEIGHBOR_ADVERTISEMENT		3	/* transmissions */
#define	ND_REACHABLE_TIME			30000	/* milliseconds */
#define	ND_RETRANS_TIMER			1000	/* milliseconds */
#define	ND_DELAY_FIRST_PROBE_TIME		5000	/* milliseconds */
#define	ND_MIN_RANDOM_FACTOR			.5
#define	ND_MAX_RANDOM_FACTOR			1.5

#define	ND_MAX_REACHTIME			3600000	/* milliseconds */
#define	ND_MAX_REACHRETRANSTIME			100000	/* milliseconds */

/*
 * ICMPv6 type filtering for IPPROTO_ICMPV6 ICMP6_FILTER socket option
 */
#define	ICMP6_FILTER	0x01	/* Set filter */

typedef struct icmp6_filter {
	uint32_t	__icmp6_filt[8];
} icmp6_filter_t;

/* Pass all ICMPv6 messages to the application */
#define	ICMP6_FILTER_SETPASSALL(filterp) ( \
	((filterp)->__icmp6_filt[0] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[1] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[2] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[3] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[4] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[5] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[6] = 0xFFFFFFFFU), \
	((filterp)->__icmp6_filt[7] = 0xFFFFFFFFU))

/* ICMPv6 messages are blocked from being passed to the application */
#define	ICMP6_FILTER_SETBLOCKALL(filterp) ( \
	((filterp)->__icmp6_filt[0] = 0x0), \
	((filterp)->__icmp6_filt[1] = 0x0), \
	((filterp)->__icmp6_filt[2] = 0x0), \
	((filterp)->__icmp6_filt[3] = 0x0), \
	((filterp)->__icmp6_filt[4] = 0x0), \
	((filterp)->__icmp6_filt[5] = 0x0), \
	((filterp)->__icmp6_filt[6] = 0x0), \
	((filterp)->__icmp6_filt[7] = 0x0))

/* Pass messages of a given type to the application */
#define	ICMP6_FILTER_SETPASS(type, filterp) \
	((((filterp)->__icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))

/* Block messages of a given type from being passed to the application */
#define	ICMP6_FILTER_SETBLOCK(type, filterp) \
	((((filterp)->__icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))

/* Test if message of a given type will be passed to an application */
#define	ICMP6_FILTER_WILLPASS(type, filterp) \
	((((filterp)->__icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)

/*
 * Test if message of a given type will blocked from
 * being passed to an application
 */
#define	ICMP6_FILTER_WILLBLOCK(type, filterp) \
	((((filterp)->__icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)

#define	ICMP_IOC_DEFAULT_Q	(('I' << 8) + 51)

#ifdef	__cplusplus
}
#endif

#endif /* _NETINET_ICMP6_H */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Variables related to this implementation
 * of the internet control message protocol.
 */

#ifndef	_NETINET_ICMP_VAR_H
#define	_NETINET_ICMP_VAR_H

/* icmp_var.h 1.10 88/08/19 SMI; from UCB 7.2 1/13/87	*/

#ifdef	__cplusplus
extern "C" {
#endif

struct	icmpstat {
/* statistics related to icmp packets generated */
	int	icps_error;		/* # of calls to icmp_error */
	int	icps_oldshort;		/* no error 'cuz old ip too short */
	int	icps_oldicmp;		/* no error 'cuz old was icmp */
	int	icps_outhist[ICMP_MAXTYPE + 1];
/* statistics related to input messages processed */
	int	icps_badcode;		/* icmp_code out of range */
	int	icps_tooshort;		/* packet < ICMP_MINLEN */
	int	icps_checksum;		/* bad checksum */
	int	icps_badlen;		/* calculated bound mismatch */
	int	icps_reflect;		/* number of responses */
	int	icps_inhist[ICMP_MAXTYPE + 1];
};

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_ICMP_VAR_H */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of California at Berkeley. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */

#ifndef	_NETINET_IF_ETHER_H
#define	_NETINET_IF_ETHER_H

/* if_ether.h 1.28 89/08/04 SMI; from UCB 7.2 12/7/87 */

#include <sys/ethernet.h>

/*
 * The following include is for compatibility with SunOS 3.x and
 * 4.3bsd.  Newly written programs should include it separately.
 */
#include <net/if_arp.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Ethernet Address Resolution Protocol.
 *
 * See RFC 826 for protocol description.  Structure below is adapted
 * to resolving internet addresses.  Field names used correspond to
 * RFC 826.
 */
struct	ether_arp {
	struct	arphdr ea_hdr;		/* fixed-size header */
	ether_addr_t arp_sha;		/* sender hardware address */
	uchar_t	arp_spa[4];		/* sender protocol address */
	ether_addr_t arp_tha;		/* target hardware address */
	uchar_t	arp_tpa[4];		/* target protocol address */
};
#define	arp_hrd	ea_hdr.ar_hrd
#define	arp_pro	ea_hdr.ar_pro
#define	arp_hln	ea_hdr.ar_hln
#define	arp_pln	ea_hdr.ar_pln
#define	arp_op	ea_hdr.ar_op

/*
 *	multicast address structure
 *
 *	Keep a reference count for each multicast address so
 *	addresses loaded into chip are unique.
 */
struct	mcaddr {
	struct	ether_addr	mc_enaddr;	/* multicast address */
	ushort_t mc_count;			/* reference count */
};
#define	MCADDRMAX	64		/* multicast addr table length */
#define	MCCOUNTMAX	4096		/* multicast addr max reference count */

/*
 * Structure shared between the ethernet driver modules and
 * the address resolution code.  For example, each ec_softc or il_softc
 * begins with this structure.
 *
 * The structure contains a pointer to an array of multicast addresses.
 * This pointer is NULL until the first successful SIOCADDMULTI ioctl
 * is issued for the interface.
 */
struct	arpcom {
	struct	ifnet ac_if;		/* network-visible interface */
	struct	ether_addr ac_enaddr;	/* ethernet hardware address */
	struct	in_addr ac_ipaddr;	/* copy of ip address- XXX */
	struct	mcaddr *ac_mcaddr;	/* table of multicast addrs */
	ushort_t ac_nmcaddr;		/* count of M/C addrs in use */
	struct  in_addr ac_lastip;	/* cache of last ARP lookup */
	struct	ether_addr ac_lastarp;	/* result of the last ARP */
};

/*
 * Internet to ethernet address resolution table.
 */
struct	arptab {
	struct	in_addr at_iaddr;	/* internet address */
	union {
	    struct ether_addr atu_enaddr;	/* ethernet address */
	    long   atu_tvsec;			/* timestamp if incomplete */
	} 	at_union;
	uchar_t	at_timer;		/* minutes since last reference */
	uchar_t	at_flags;		/* flags */
	struct	mbuf *at_hold;		/* last packet until resolved/timeout */
};

#define	at_enaddr	at_union.atu_enaddr
#define	at_tvsec	at_union.atu_tvsec

/*
 * Copy IP addresses from a to b - assumes that the two given
 * pointers can be referenced as shorts.  On architectures
 * where this is not the case, use bcopy instead.
 */
#if defined(__sparc) || defined(__i386) || defined(__amd64)
#define	ip_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \
	((short *)b)[1] = ((short *)a)[1]; }
#else
#define	ip_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 4))
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IF_ETHER_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/* Copyright (c) 1990 Mentat Inc. */

#ifndef	_NETINET_IGMP_H
#define	_NETINET_IGMP_H

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Internet Group Management Protocol (IGMP) definitions.
 *
 * Written by Steve Deering, Stanford, May 1988.
 * Modified by Rosen Sharma, Stanford, Aug 1994
 * Modified by Bill Fenner, Xerox PARC, April 1995
 *
 * MULTICAST 3.5.1.1
 */

/*
 * IGMP packet format.
 */
struct igmp {
	uchar_t		igmp_type;	/* version & type of IGMP message  */
	uchar_t		igmp_code;	/* code for routing sub-msgs	   */
	ushort_t	igmp_cksum;	/* IP-style checksum		   */
	struct in_addr	igmp_group;	/* group address being reported	   */
};					/*  (zero for queries)		   */

/* IGMPv3 Membership Report common header */
struct igmp3r {
	uchar_t		igmp3r_type;	/* version & type of IGMP message  */
	uchar_t		igmp3r_code;	/* code for routing sub-msgs	   */
	ushort_t	igmp3r_cksum;	/* IP-style checksum		   */
	ushort_t	igmp3r_res;	/* Reserved			   */
	ushort_t	igmp3r_numrec;	/* Number of group records	   */
};

/* IGMPv3 Group Record header */
struct grphdr {
	uchar_t		grphdr_type;	/* type of record		   */
	uchar_t		grphdr_auxlen;	/* auxiliary data length	   */
	ushort_t	grphdr_numsrc;	/* number of sources		   */
	struct in_addr	grphdr_group;	/* group address being reported	   */
};

/* IGMPv3 Membership Query header */
struct igmp3q {
	uchar_t		igmp3q_type;	/* type of IGMP message		   */
	uchar_t		igmp3q_mxrt;	/* maximum response time	   */
	ushort_t	igmp3q_cksum;	/* IP-style checksum		   */
	struct in_addr	igmp3q_group;	/* group address being queried	   */
	ushort_t	igmp3q_res;	/* reserved			   */
	ushort_t	igmp3q_numsrc;	/* number of sources		   */
};

#ifdef _KERNEL
typedef struct igmp_s {
	uint8_t		igmp_type;	/* version & type of IGMP message  */
	uint8_t		igmp_code;	/* code for routing sub-msgs	   */
	uint8_t		igmp_cksum[2];	/* IP-style checksum		   */
	uint8_t		igmp_group[4];	/* group address being reported	   */
} igmp_t;				/*  (zero for queries)		   */

/* Aligned igmp header */
typedef struct igmpa_s {
	uint8_t		igmpa_type;	/* version & type of IGMP message  */
	uint8_t		igmpa_code;	/* code for routing sub-msgs	   */
	uint16_t	igmpa_cksum;	/* IP-style checksum		   */
	ipaddr_t	igmpa_group;	/* group address being reported	   */
} igmpa_t;				/*  (zero for queries)		   */

/* Aligned IGMPv3 Membership Report common header */
typedef struct igmp3ra_s {
	uint8_t		igmp3ra_type;	/* version & type of IGMP message  */
	uint8_t		igmp3ra_res;	/* Reserved			   */
	uint16_t	igmp3ra_cksum;	/* IP-style checksum		   */
	uint16_t	igmp3ra_res1;	/* Reserved			   */
	uint16_t	igmp3ra_numrec;	/* Number of group records	   */
} igmp3ra_t;

/* Aligned IGMPv3 Group Record header */
typedef struct grphdra_s {
	uint8_t		grphdra_type;	/* type of record		   */
	uint8_t		grphdra_auxlen;	/* auxiliary data length	   */
	uint16_t	grphdra_numsrc;	/* number of sources		   */
	ipaddr_t	grphdra_group;	/* group addrss being reported	   */
} grphdra_t;

/* Aligned IGMpv3 Membership Query header */
typedef struct igmp3qa_s {
	uint8_t		igmp3qa_type;	/* type of IGMP message		   */
	uint8_t		igmp3qa_mxrc;	/* maximum response code	   */
	uint16_t	igmp3qa_cksum;	/* IP-style checksum		   */
	ipaddr_t	igmp3qa_group;	/* group address being queried	   */
	uint8_t		igmp3qa_sqrv;	/* S Flag, Q's Robustness Variable */
	uint8_t		igmp3qa_qqic;	/* Querier's Query Interval Code   */
	uint16_t	igmp3qa_numsrc;	/* number of sources		   */
} igmp3qa_t;

#endif	/* _KERNEL */


#define	IGMP_MINLEN			8
#define	IGMP_V3_QUERY_MINLEN		12


/*
 * Message types, including version number.
 */

#define	IGMP_MEMBERSHIP_QUERY		0x11	/* membership query    */
#define	IGMP_V1_MEMBERSHIP_REPORT	0x12	/* Vers.1 membership report */
#define	IGMP_V2_MEMBERSHIP_REPORT	0x16	/* Vers.2 membership report */
#define	IGMP_V3_MEMBERSHIP_REPORT	0x22	/* Vers.3 membership report */
#define	IGMP_V2_LEAVE_GROUP		0x17	/* Leave-group message	    */
#define	IGMP_DVMRP			0x13	/* DVMRP routing message    */
#define	IGMP_PIM			0x14	/* PIM routing message	    */

#define	IGMP_MTRACE_RESP		0x1e  	/* traceroute resp to sender */
#define	IGMP_MTRACE			0x1f	/* mcast traceroute messages */

#define	IGMP_MAX_HOST_REPORT_DELAY	10	/* max delay for response to */
						/* query (in seconds)	*/
						/* according to RFC1112 */

#define	IGMP_V3_MAXRT_FPMIN		0x80	/* max resp code fp format */
#define	IGMP_V3_MAXRT_MANT_MASK		0x0f
#define	IGMP_V3_MAXRT_EXP_MASK		0x70

#define	IGMP_V3_SFLAG_MASK		0x8	/* mask off s part of sqrv */
#define	IGMP_V3_RV_MASK			0x7	/* mask off qrv part of sqrv */

#define	IGMP_V3_QQI_FPMIN		0x80	/* qqi code fp format */
#define	IGMP_V3_QQI_MANT_MASK		0x0f
#define	IGMP_V3_QQI_EXP_MASK		0x70

/*
 * IGMPv3/MLDv2-specific definitions
 */
/*
 * Group Record Types.  The values of these enums match the Record Type
 * field values defined in RFCs 3376 and 3810 for IGMPv3 and MLDv2 reports.
 */
typedef enum {
	MODE_IS_INCLUDE = 1,
	MODE_IS_EXCLUDE,
	CHANGE_TO_INCLUDE,
	CHANGE_TO_EXCLUDE,
	ALLOW_NEW_SOURCES,
	BLOCK_OLD_SOURCES
} mcast_record_t;

/* Router Alert Option */
#define	RTRALERT_LEN			4
#define	RTRALERT_LEN_IN_WORDS		1

/*
 * The following four defininitions are for backwards compatibility.
 * They should be removed as soon as all applications are updated to
 * use the new constant names.
 */
#define	IGMP_HOST_MEMBERSHIP_QUERY	IGMP_MEMBERSHIP_QUERY
#define	IGMP_HOST_MEMBERSHIP_REPORT	IGMP_V1_MEMBERSHIP_REPORT
#define	IGMP_HOST_NEW_MEMBERSHIP_REPORT	IGMP_V2_MEMBERSHIP_REPORT
#define	IGMP_HOST_LEAVE_MESSAGE		IGMP_V2_LEAVE_GROUP

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IGMP_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_NETINET_IGMP_VAR_H
#define	_NETINET_IGMP_VAR_H

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Internet Group Management Protocol (IGMP),
 * implementation-specific definitions.
 *
 * Written by Steve Deering, Stanford, May 1988.
 * Modified by Ajit Thyagarajan, PARC, August 1994.
 *
 * MULTICAST 3.5.1.1
 */

struct igmpstat {
	uint_t	igps_rcv_total;		/* total IGMP messages received    */
	uint_t	igps_rcv_tooshort;	/* received with too few bytes	   */
	uint_t	igps_rcv_badsum;	/* received with bad checksum	   */
	uint_t	igps_rcv_queries;	/* received membership queries	   */
	uint_t	igps_rcv_badqueries;	/* received invalid queries	   */
	uint_t	igps_rcv_reports;	/* received membership reports	   */
	uint_t	igps_rcv_badreports;	/* received invalid reports	   */
	uint_t	igps_rcv_ourreports;	/* received reports for our groups */
	uint_t	igps_snd_reports;	/* sent membership reports	   */
};

#ifdef _KERNEL
/*
 * slowtimo interval used for both IGMP and MLD
 */
#define	MCAST_SLOWTIMO_INTERVAL	10000	/* milliseconds */


/*
 * Macro to compute a random timer value between 1 and maxticks.
 * Include <sys/random.h> for random_get_pseudo_bytes() declaration.
 */
#include <sys/random.h>
#define	MCAST_RANDOM_DELAY(timer, maxticks)				      \
	/* uint_t timer; int maxticks */				      \
	(void) random_get_pseudo_bytes((uint8_t *)&(timer), sizeof (uint_t)); \
	(timer) = ((uint_t)(timer) % (maxticks)) + 1

/*
 * States for IGMPv2's leave processing
 */
#define	IGMP_OTHERMEMBER			0
#define	IGMP_IREPORTEDLAST			1

/*
 * We must remember what version the subnet's querier is.
 */
#define	IGMP_V1_ROUTER				0
#define	IGMP_V2_ROUTER				1
#define	IGMP_V3_ROUTER				2

/*
 * Map MLD versions to corresponding IGMP versions
 */
#define	MLD_V1_ROUTER				IGMP_V2_ROUTER
#define	MLD_V2_ROUTER				IGMP_V3_ROUTER

/*
 * Default values for various IGMPv3/MLDv2 values
 */
#define	MCAST_DEF_ROBUSTNESS			2
#define	MCAST_QUERY_RESP_INTERVAL		10	/* in seconds */
#define	MCAST_DEF_QUERY_INTERVAL		125	/* in seconds */
#define	MCAST_DEF_QUERY_RESP_INTERVAL		100	/* in tenths of secs */
#define	MCAST_DEF_UNSOL_RPT_INTERVAL		1	/* in seconds */

/*
 * IGMP and MLD mandate a TTL/Hop Limit of 1 for protocol messages
 */
#define	IGMP_TTL	1
#define	MLD_HOP_LIMIT	1

#endif	/* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IGMP_VAR_H */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 *
 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
 * Copyright 2015, Joyent, Inc.
 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
 * Copyright 2024 Oxide Computer Company
 */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of California at Berkeley. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */

/*
 * Constants and structures defined by the internet system,
 * according to following documents
 *
 * Internet ASSIGNED NUMBERS (RFC1700) and its successors:
 *	http://www.iana.org/assignments/protocol-numbers
 *	http://www.iana.org/assignments/port-numbers
 * Basic Socket Interface Extensions for IPv6 (RFC2133 and its successors)
 *
 */

#ifndef _NETINET_IN_H
#define	_NETINET_IN_H

#include <sys/feature_tests.h>

#ifdef	__cplusplus
extern "C" {
#endif

#include <sys/types.h>

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#include <sys/socket_impl.h>
#endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

#ifndef _SOCKLEN_T
#define	_SOCKLEN_T

/*
 * The socklen definitions are reproduced here from sys/socket.h so as to
 * not introduce that namespace into existing users of netinet/in.h.
 */
#if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64)
typedef	size_t		socklen_t;
#else
typedef	uint32_t	socklen_t;
#endif	/* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */

#if defined(_XPG4_2) || defined(_BOOT)
typedef	socklen_t	*Psocklen_t;
#else
typedef	void		*Psocklen_t;
#endif	/* defined(_XPG4_2) || defined(_BOOT) */

#endif /* _SOCKLEN_T */

/*
 * Symbols such as htonl() are required to be exposed through this file,
 * per XNS Issue 5. This is achieved by inclusion of <sys/byteorder.h>
 */
#if !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5)
#include <sys/byteorder.h>
#endif

#ifndef _IN_PORT_T
#define	_IN_PORT_T
typedef	uint16_t	in_port_t;
#endif

/*
 * Note: IPv4 address data structures usage conventions.
 * The "in_addr_t" type below (required by Unix standards)
 * is NOT a typedef of "struct in_addr" and violates the usual
 * conventions where "struct <name>" and <name>_t are corresponding
 * typedefs.
 * To minimize confusion, kernel data structures/usage prefers use
 * of "ipaddr_t" as atomic uint32_t type and avoid using "in_addr_t"
 * The user level APIs continue to follow the historic popular
 * practice of using "struct in_addr".
 */
#ifndef _IN_ADDR_T
#define	_IN_ADDR_T
typedef	uint32_t	in_addr_t;
#endif

#ifndef _IPADDR_T
#define	_IPADDR_T
typedef uint32_t ipaddr_t;
#endif

#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)

struct in6_addr {
	union {
		/*
		 * Note: Static initalizers of "union" type assume
		 * the constant on the RHS is the type of the first member
		 * of union.
		 * To make static initializers (and efficient usage) work,
		 * the order of members exposed to user and kernel view of
		 * this data structure is different.
		 * User environment sees specified uint8_t type as first
		 * member whereas kernel sees most efficient type as
		 * first member.
		 */
#ifdef _KERNEL
		uint32_t	_S6_u32[4];	/* IPv6 address */
		uint16_t	_S6_u16[8];	/* IPv6 address */
		uint8_t		_S6_u8[16];	/* IPv6 address */
#else
		uint8_t		_S6_u8[16];	/* IPv6 address */
		uint16_t	_S6_u16[8];	/* IPv6 address */
		uint32_t	_S6_u32[4];	/* IPv6 address */
#endif
		uint32_t	__S6_align;	/* Align on 32 bit boundary */
	} _S6_un;
};
#define	s6_addr		_S6_un._S6_u8

#ifdef _KERNEL
#define	s6_addr8	_S6_un._S6_u8
#define	s6_addr16	_S6_un._S6_u16
#define	s6_addr32	_S6_un._S6_u32
#endif

typedef struct in6_addr in6_addr_t;

#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */

#ifndef _SA_FAMILY_T
#define	_SA_FAMILY_T
typedef	uint16_t	sa_family_t;
#endif

/*
 * Protocols
 *
 * Some of these constant names are copied for the DTrace IP provider in
 * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
 * in sync.
 */
#define	IPPROTO_IP		0		/* dummy for IP */
#define	IPPROTO_HOPOPTS		0		/* Hop by hop header for IPv6 */
#define	IPPROTO_ICMP		1		/* control message protocol */
#define	IPPROTO_IGMP		2		/* group control protocol */
#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
#define	IPPROTO_ENCAP		4		/* IP in IP encapsulation */
#define	IPPROTO_TCP		6		/* tcp */
#define	IPPROTO_EGP		8		/* exterior gateway protocol */
#define	IPPROTO_PUP		12		/* pup */
#define	IPPROTO_UDP		17		/* user datagram protocol */
#define	IPPROTO_IDP		22		/* xns idp */
#define	IPPROTO_IPV6		41		/* IPv6 encapsulated in IP */
#define	IPPROTO_ROUTING		43		/* Routing header for IPv6 */
#define	IPPROTO_FRAGMENT	44		/* Fragment header for IPv6 */
#define	IPPROTO_RSVP		46		/* rsvp */
#define	IPPROTO_ESP		50		/* IPsec Encap. Sec. Payload */
#define	IPPROTO_AH		51		/* IPsec Authentication Hdr. */
#define	IPPROTO_ICMPV6		58		/* ICMP for IPv6 */
#define	IPPROTO_NONE		59		/* No next header for IPv6 */
#define	IPPROTO_DSTOPTS		60		/* Destination options */
#define	IPPROTO_HELLO		63		/* "hello" routing protocol */
#define	IPPROTO_ND		77		/* UNOFFICIAL net disk proto */
#define	IPPROTO_EON		80		/* ISO clnp */
#define	IPPROTO_OSPF		89		/* OSPF */
#define	IPPROTO_PIM		103		/* PIM routing protocol */
#define	IPPROTO_SCTP		132		/* Stream Control */
						/* Transmission Protocol */
#define	IPPROTO_MH		135		/* Mobility EH */
#define	IPPROTO_HIP		139		/* Host Identity Protocol */
#define	IPPROTO_SHIM6		140		/* Shim6 Protocol */

#define	IPPROTO_RAW		255		/* raw IP packet */
#define	IPPROTO_MAX		256

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#define	PROTO_SDP		257		/* Sockets Direct Protocol */
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

/*
 * Port/socket numbers: network standard functions
 *
 * Entries should exist here for each port number compiled into an ON
 * component, such as snoop.
 */
#define	IPPORT_ECHO		7
#define	IPPORT_DISCARD		9
#define	IPPORT_SYSTAT		11
#define	IPPORT_DAYTIME		13
#define	IPPORT_NETSTAT		15
#define	IPPORT_CHARGEN		19
#define	IPPORT_FTP		21
#define	IPPORT_TELNET		23
#define	IPPORT_SMTP		25
#define	IPPORT_TIMESERVER	37
#define	IPPORT_NAMESERVER	42
#define	IPPORT_WHOIS		43
#define	IPPORT_DOMAIN		53
#define	IPPORT_MDNS		5353
#define	IPPORT_MTP		57

/*
 * Port/socket numbers: host specific functions
 */
#define	IPPORT_BOOTPS		67
#define	IPPORT_BOOTPC		68
#define	IPPORT_TFTP		69
#define	IPPORT_RJE		77
#define	IPPORT_FINGER		79
#define	IPPORT_HTTP		80
#define	IPPORT_HTTP_ALT		8080
#define	IPPORT_TTYLINK		87
#define	IPPORT_SUPDUP		95
#define	IPPORT_NTP		123
#define	IPPORT_NETBIOS_NS	137
#define	IPPORT_NETBIOS_DGM	138
#define	IPPORT_NETBIOS_SSN	139
#define	IPPORT_LDAP		389
#define	IPPORT_SLP		427
#define	IPPORT_MIP		434
#define	IPPORT_SMB		445		/* a.k.a. microsoft-ds */
#define	IPPORT_VXLAN		4789

/*
 * Internet Key Exchange (IKE) ports
 */
#define	IPPORT_IKE		500
#define	IPPORT_IKE_NATT		4500

/*
 * UNIX TCP sockets
 */
#define	IPPORT_EXECSERVER	512
#define	IPPORT_LOGINSERVER	513
#define	IPPORT_CMDSERVER	514
#define	IPPORT_PRINTER		515
#define	IPPORT_EFSSERVER	520

/*
 * UNIX UDP sockets
 */
#define	IPPORT_BIFFUDP		512
#define	IPPORT_WHOSERVER	513
#define	IPPORT_SYSLOG		514
#define	IPPORT_TALK		517
#define	IPPORT_ROUTESERVER	520
#define	IPPORT_RIPNG		521

/*
 * DHCPv6 UDP ports
 */
#define	IPPORT_DHCPV6C		546
#define	IPPORT_DHCPV6S		547

#define	IPPORT_SOCKS		1080

/*
 * Ports < IPPORT_RESERVED are reserved for
 * privileged processes (e.g. root).
 * Ports > IPPORT_USERRESERVED are reserved
 * for servers, not necessarily privileged.
 */
#define	IPPORT_RESERVED		1024
#define	IPPORT_USERRESERVED	5000

#ifdef _KERNEL
#define	IPPORT_DYNAMIC_MIN	49152
#define	IPPORT_DYNAMIC_MAX	65535
#endif

/*
 * Link numbers
 */
#define	IMPLINK_IP		155
#define	IMPLINK_LOWEXPER	156
#define	IMPLINK_HIGHEXPER	158

/*
 * IPv4 Internet address
 *	This definition contains obsolete fields for compatibility
 *	with SunOS 3.x and 4.2bsd.  The presence of subnets renders
 *	divisions into fixed fields misleading at best.  New code
 *	should use only the s_addr field.
 */

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
#define	_S_un_b	S_un_b
#define	_S_un_w	S_un_w
#define	_S_addr	S_addr
#define	_S_un	S_un
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

struct in_addr {
	union {
		struct { uint8_t s_b1, s_b2, s_b3, s_b4; } _S_un_b;
		struct { uint16_t s_w1, s_w2; } _S_un_w;
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
		uint32_t _S_addr;
#else
		in_addr_t _S_addr;
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
	} _S_un;
#define	s_addr	_S_un._S_addr		/* should be used for all code */
#define	s_host	_S_un._S_un_b.s_b2	/* OBSOLETE: host on imp */
#define	s_net	_S_un._S_un_b.s_b1	/* OBSOLETE: network */
#define	s_imp	_S_un._S_un_w.s_w2	/* OBSOLETE: imp */
#define	s_impno	_S_un._S_un_b.s_b4	/* OBSOLETE: imp # */
#define	s_lh	_S_un._S_un_b.s_b3	/* OBSOLETE: logical host */
};

/*
 * Definitions of bits in internet address integers.
 * On subnets, the decomposition of addresses to host and net parts
 * is done according to subnet mask, not the masks here.
 *
 * Note that with the introduction of CIDR, IN_CLASSA, IN_CLASSB,
 * IN_CLASSC, IN_CLASSD and IN_CLASSE macros have become "de-facto
 * obsolete". IN_MULTICAST macro should be used to test if a address
 * is a multicast address.
 */
#define	IN_CLASSA(i)		(((i) & 0x80000000U) == 0)
#define	IN_CLASSA_NET		0xff000000U
#define	IN_CLASSA_NSHIFT	24
#define	IN_CLASSA_HOST		0x00ffffffU
#define	IN_CLASSA_MAX		128

#define	IN_CLASSB(i)		(((i) & 0xc0000000U) == 0x80000000U)
#define	IN_CLASSB_NET		0xffff0000U
#define	IN_CLASSB_NSHIFT	16
#define	IN_CLASSB_HOST		0x0000ffffU
#define	IN_CLASSB_MAX		65536

#define	IN_CLASSC(i)		(((i) & 0xe0000000U) == 0xc0000000U)
#define	IN_CLASSC_NET		0xffffff00U
#define	IN_CLASSC_NSHIFT	8
#define	IN_CLASSC_HOST		0x000000ffU

#define	IN_CLASSD(i)		(((i) & 0xf0000000U) == 0xe0000000U)
#define	IN_CLASSD_NET		0xf0000000U	/* These aren't really  */
#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
#define	IN_CLASSD_HOST		0x0fffffffU	/* routing needn't know */

#define	IN_CLASSE(i)		(((i) & 0xf0000000U) == 0xf0000000U)
#define	IN_CLASSE_NET		0xffffffffU

#define	IN_MULTICAST(i)		IN_CLASSD(i)

/*
 * We have removed CLASS E checks from the kernel
 * But we preserve these defines for userland in order
 * to avoid compile  breakage of some 3rd party piece of software
 */
#ifndef _KERNEL
#define	IN_EXPERIMENTAL(i)	(((i) & 0xe0000000U) == 0xe0000000U)
#define	IN_BADCLASS(i)		(((i) & 0xf0000000U) == 0xf0000000U)
#endif

#define	INADDR_ANY		0x00000000U
#define	INADDR_LOOPBACK		0x7F000001U
#define	INADDR_BROADCAST	0xffffffffU	/* must be masked */
#define	INADDR_NONE		0xffffffffU

#define	INADDR_UNSPEC_GROUP	0xe0000000U	/* 224.0.0.0   */
#define	INADDR_ALLHOSTS_GROUP	0xe0000001U	/* 224.0.0.1   */
#define	INADDR_ALLRTRS_GROUP	0xe0000002U	/* 224.0.0.2   */
#define	INADDR_ALLRPTS_GROUP	0xe0000016U	/* 224.0.0.22, IGMPv3 */
#define	INADDR_MAX_LOCAL_GROUP	0xe00000ffU	/* 224.0.0.255 */

/* Scoped IPv4 prefixes (in host byte-order) */
#define	IN_AUTOCONF_NET		0xa9fe0000U	/* 169.254/16 */
#define	IN_AUTOCONF_MASK	0xffff0000U
#define	IN_PRIVATE8_NET		0x0a000000U	/* 10/8 */
#define	IN_PRIVATE8_MASK	0xff000000U
#define	IN_PRIVATE12_NET	0xac100000U	/* 172.16/12 */
#define	IN_PRIVATE12_MASK	0xfff00000U
#define	IN_PRIVATE16_NET	0xc0a80000U	/* 192.168/16 */
#define	IN_PRIVATE16_MASK	0xffff0000U

/* RFC 3927 IPv4 link local address (i in host byte-order) */
#define	IN_LINKLOCAL(i)		(((i) & IN_AUTOCONF_MASK) == IN_AUTOCONF_NET)

/* Well known 6to4 Relay Router Anycast address defined in RFC 3068 */
#if !defined(_XPG4_2) || !defined(__EXTENSIONS__)
#define	INADDR_6TO4RRANYCAST	0xc0586301U	/* 192.88.99.1 */
#endif	/* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */

#define	IN_LOOPBACKNET		127			/* official! */

/*
 * Define a macro to stuff the loopback address into an Internet address
 */
#if !defined(_XPG4_2) || !defined(__EXTENSIONS__)
#define	IN_SET_LOOPBACK_ADDR(a) \
	{ (a)->sin_addr.s_addr  = htonl(INADDR_LOOPBACK); \
	(a)->sin_family = AF_INET; }
#endif /* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */

/*
 * IPv4 Socket address.
 */
struct sockaddr_in {
	sa_family_t	sin_family;
	in_port_t	sin_port;
	struct	in_addr sin_addr;
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
	char		sin_zero[8];
#else
	unsigned char	sin_zero[8];
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
};

#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
/*
 * IPv6 socket address.
 */
struct sockaddr_in6 {
	sa_family_t	sin6_family;
	in_port_t	sin6_port;
	uint32_t	sin6_flowinfo;
	struct in6_addr	sin6_addr;
	uint32_t	sin6_scope_id;  /* Depends on scope of sin6_addr */
	uint32_t	__sin6_src_id;	/* Impl. specific - UDP replies */
};

/*
 * Macros for accessing the traffic class and flow label fields from
 * sin6_flowinfo.
 * These are designed to be applied to a 32-bit value.
 */
#ifdef _BIG_ENDIAN

/* masks */
#define	IPV6_FLOWINFO_FLOWLABEL			0x000fffffU
#define	IPV6_FLOWINFO_TCLASS			0x0ff00000U

#else /* _BIG_ENDIAN */

/* masks */
#define	IPV6_FLOWINFO_FLOWLABEL			0xffff0f00U
#define	IPV6_FLOWINFO_TCLASS			0x0000f00fU

#endif	/* _BIG_ENDIAN */

/*
 * Note: Macros IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT are for
 * use as RHS of Static initializers of "struct in6_addr" (or in6_addr_t)
 * only. They need to be different for User/Kernel versions because union
 * component data structure is defined differently (it is identical at
 * binary representation level).
 *
 * const struct in6_addr IN6ADDR_ANY_INIT;
 * const struct in6_addr IN6ADDR_LOOPBACK_INIT;
 */


#ifdef _KERNEL
#define	IN6ADDR_ANY_INIT		{ 0, 0, 0, 0 }

#ifdef _BIG_ENDIAN
#define	IN6ADDR_LOOPBACK_INIT		{ 0, 0, 0, 0x00000001U }
#else /* _BIG_ENDIAN */
#define	IN6ADDR_LOOPBACK_INIT		{ 0, 0, 0, 0x01000000U }
#endif /* _BIG_ENDIAN */

#else

#define	IN6ADDR_ANY_INIT	    {	0, 0, 0, 0,	\
					0, 0, 0, 0,	\
					0, 0, 0, 0,	\
					0, 0, 0, 0 }

#define	IN6ADDR_LOOPBACK_INIT	    {	0, 0, 0, 0,	\
					0, 0, 0, 0,	\
					0, 0, 0, 0,	\
					0, 0, 0, 0x1U }
#endif /* _KERNEL */

/*
 * RFC 2553 specifies the following macros. Their type is defined
 * as "int" in the RFC but they only have boolean significance
 * (zero or non-zero). For the purposes of our comment notation,
 * we assume a hypothetical type "bool" defined as follows to
 * write the prototypes assumed for macros in our comments better.
 *
 * typedef int bool;
 */

/*
 * IN6 macros used to test for special IPv6 addresses
 * (Mostly from spec)
 *
 * bool  IN6_IS_ADDR_UNSPECIFIED (const struct in6_addr *);
 * bool  IN6_IS_ADDR_LOOPBACK    (const struct in6_addr *);
 * bool  IN6_IS_ADDR_MULTICAST   (const struct in6_addr *);
 * bool  IN6_IS_ADDR_LINKLOCAL   (const struct in6_addr *);
 * bool  IN6_IS_ADDR_SITELOCAL   (const struct in6_addr *);
 * bool  IN6_IS_ADDR_V4MAPPED    (const struct in6_addr *);
 * bool  IN6_IS_ADDR_V4MAPPED_ANY(const struct in6_addr *); -- Not from RFC2553
 * bool  IN6_IS_ADDR_V4COMPAT    (const struct in6_addr *);
 * bool  IN6_IS_ADDR_MC_RESERVED (const struct in6_addr *); -- Not from RFC2553
 * bool  IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *);
 * bool  IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *);
 * bool  IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *);
 * bool  IN6_IS_ADDR_MC_ORGLOCAL (const struct in6_addr *);
 * bool  IN6_IS_ADDR_MC_GLOBAL   (const struct in6_addr *);
 * bool  IN6_IS_ADDR_6TO4	 (const struct in6_addr *); -- Not from RFC2553
 * bool  IN6_ARE_6TO4_PREFIX_EQUAL(const struct in6_addr *,
 *	     const struct in6_addr *);			    -- Not from RFC2553
 * bool  IN6_IS_ADDR_LINKSCOPE	 (const struct in6addr  *); -- Not from RFC2553
 */

#define	IN6_IS_ADDR_UNSPECIFIED(addr) \
	(((addr)->_S6_un._S6_u32[3] == 0) && \
	((addr)->_S6_un._S6_u32[2] == 0) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_LOOPBACK(addr) \
	(((addr)->_S6_un._S6_u32[3] == 0x00000001) && \
	((addr)->_S6_un._S6_u32[2] == 0) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))
#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_LOOPBACK(addr) \
	(((addr)->_S6_un._S6_u32[3] == 0x01000000) && \
	((addr)->_S6_un._S6_u32[2] == 0) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MULTICAST(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff000000) == 0xff000000)
#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MULTICAST(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x000000ff) == 0x000000ff)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_LINKLOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfe800000)
#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_LINKLOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x000080fe)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_SITELOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfec00000)
#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_SITELOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x0000c0fe)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_V4MAPPED(addr) \
	(((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))
#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_V4MAPPED(addr) \
	(((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))
#endif /* _BIG_ENDIAN */

/*
 * IN6_IS_ADDR_V4MAPPED_ANY - A IPv4 mapped INADDR_ANY
 * Note: This macro is currently NOT defined in RFC2553 specification
 * and not a standard macro that portable applications should use.
 */
#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_V4MAPPED_ANY(addr) \
	(((addr)->_S6_un._S6_u32[3] == 0) && \
	((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))
#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_V4MAPPED_ANY(addr) \
	(((addr)->_S6_un._S6_u32[3] == 0) && \
	((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0))
#endif /* _BIG_ENDIAN */

/* Exclude loopback and unspecified address */
#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_V4COMPAT(addr) \
	(((addr)->_S6_un._S6_u32[2] == 0) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0) && \
	!((addr)->_S6_un._S6_u32[3] == 0) && \
	!((addr)->_S6_un._S6_u32[3] == 0x00000001))

#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_V4COMPAT(addr) \
	(((addr)->_S6_un._S6_u32[2] == 0) && \
	((addr)->_S6_un._S6_u32[1] == 0) && \
	((addr)->_S6_un._S6_u32[0] == 0) && \
	!((addr)->_S6_un._S6_u32[3] == 0) && \
	!((addr)->_S6_un._S6_u32[3] == 0x01000000))
#endif /* _BIG_ENDIAN */

/*
 * Note:
 * IN6_IS_ADDR_MC_RESERVED macro is currently NOT defined in RFC2553
 * specification and not a standard macro that portable applications
 * should use.
 */
#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_RESERVED(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff000000)

#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MC_RESERVED(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000000ff)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_NODELOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff010000)
#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MC_NODELOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000001ff)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_LINKLOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff020000)
#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MC_LINKLOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000002ff)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_SITELOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff050000)
#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MC_SITELOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000005ff)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_ORGLOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff080000)
#else  /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MC_ORGLOCAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000008ff)
#endif /* _BIG_ENDIAN */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_GLOBAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff0e0000)
#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_MC_GLOBAL(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x00000eff)
#endif /* _BIG_ENDIAN */

/*
 * The IN6_IS_ADDR_MC_SOLICITEDNODE macro is not defined in any standard or
 * RFC, and shouldn't be used by portable applications.  It is used to see
 * if an address is a solicited-node multicast address, which is prefixed
 * with ff02:0:0:0:0:1:ff00::/104.
 */
#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_MC_SOLICITEDNODE(addr)			\
	(((addr)->_S6_un._S6_u32[0] == 0xff020000) &&		\
	((addr)->_S6_un._S6_u32[1] == 0x00000000) &&		\
	((addr)->_S6_un._S6_u32[2] == 0x00000001) &&		\
	(((addr)->_S6_un._S6_u32[3] & 0xff000000) == 0xff000000))
#else
#define	IN6_IS_ADDR_MC_SOLICITEDNODE(addr)			\
	(((addr)->_S6_un._S6_u32[0] == 0x000002ff) &&		\
	((addr)->_S6_un._S6_u32[1] == 0x00000000) &&		\
	((addr)->_S6_un._S6_u32[2] == 0x01000000) &&		\
	(((addr)->_S6_un._S6_u32[3] & 0x000000ff) == 0x000000ff))
#endif

/*
 * Macros to a) test for 6to4 IPv6 address, and b) to test if two
 * 6to4 addresses have the same /48 prefix, and, hence, are from the
 * same 6to4 site.
 */

#ifdef _BIG_ENDIAN
#define	IN6_IS_ADDR_6TO4(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0xffff0000) == 0x20020000)
#else /* _BIG_ENDIAN */
#define	IN6_IS_ADDR_6TO4(addr) \
	(((addr)->_S6_un._S6_u32[0] & 0x0000ffff) == 0x00000220)
#endif /* _BIG_ENDIAN */

#define	IN6_ARE_6TO4_PREFIX_EQUAL(addr1, addr2) \
	(((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0]) && \
	((addr1)->_S6_un._S6_u8[4] == (addr2)->_S6_un._S6_u8[4]) && \
	((addr1)->_S6_un._S6_u8[5] == (addr2)->_S6_un._S6_u8[5]))

/*
 * IN6_IS_ADDR_LINKSCOPE
 * Identifies an address as being either link-local, link-local multicast or
 * node-local multicast.  All types of addresses are considered to be unique
 * within the scope of a given link.
 */
#define	IN6_IS_ADDR_LINKSCOPE(addr) \
	(IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr) || \
	IN6_IS_ADDR_MC_NODELOCAL(addr))

/*
 * Useful utility macros for operations with IPv6 addresses
 * Note: These macros are NOT defined in the RFC2553 or any other
 * standard specification and are not standard macros that portable
 * applications should use.
 */

/*
 * IN6_V4MAPPED_TO_INADDR
 * IN6_V4MAPPED_TO_IPADDR
 *	Assign a IPv4-Mapped IPv6 address to an IPv4 address.
 *	Note: These macros are NOT defined in RFC2553 or any other standard
 *	specification and are not macros that portable applications should
 *	use.
 *
 * void IN6_V4MAPPED_TO_INADDR(const in6_addr_t *v6, struct in_addr *v4);
 * void IN6_V4MAPPED_TO_IPADDR(const in6_addr_t *v6, ipaddr_t v4);
 *
 */
#define	IN6_V4MAPPED_TO_INADDR(v6, v4) \
	((v4)->s_addr = (v6)->_S6_un._S6_u32[3])
#define	IN6_V4MAPPED_TO_IPADDR(v6, v4) \
	((v4) = (v6)->_S6_un._S6_u32[3])

/*
 * IN6_INADDR_TO_V4MAPPED
 * IN6_IPADDR_TO_V4MAPPED
 *	Assign a IPv4 address address to an IPv6 address as a IPv4-mapped
 *	address.
 *	Note: These macros are NOT defined in RFC2553 or any other standard
 *	specification and are not macros that portable applications should
 *	use.
 *
 * void IN6_INADDR_TO_V4MAPPED(const struct in_addr *v4, in6_addr_t *v6);
 * void IN6_IPADDR_TO_V4MAPPED(const ipaddr_t v4, in6_addr_t *v6);
 *
 */
#ifdef _BIG_ENDIAN
#define	IN6_INADDR_TO_V4MAPPED(v4, v6) \
	((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \
	(v6)->_S6_un._S6_u32[2] = 0x0000ffff, \
	(v6)->_S6_un._S6_u32[1] = 0, \
	(v6)->_S6_un._S6_u32[0] = 0)
#define	IN6_IPADDR_TO_V4MAPPED(v4, v6) \
	((v6)->_S6_un._S6_u32[3] = (v4), \
	(v6)->_S6_un._S6_u32[2] = 0x0000ffff, \
	(v6)->_S6_un._S6_u32[1] = 0, \
	(v6)->_S6_un._S6_u32[0] = 0)
#else /* _BIG_ENDIAN */
#define	IN6_INADDR_TO_V4MAPPED(v4, v6) \
	((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \
	(v6)->_S6_un._S6_u32[2] = 0xffff0000U, \
	(v6)->_S6_un._S6_u32[1] = 0, \
	(v6)->_S6_un._S6_u32[0] = 0)
#define	IN6_IPADDR_TO_V4MAPPED(v4, v6) \
	((v6)->_S6_un._S6_u32[3] = (v4), \
	(v6)->_S6_un._S6_u32[2] = 0xffff0000U, \
	(v6)->_S6_un._S6_u32[1] = 0, \
	(v6)->_S6_un._S6_u32[0] = 0)
#endif /* _BIG_ENDIAN */

/*
 * IN6_6TO4_TO_V4ADDR
 *	Extract the embedded IPv4 address from the prefix to a 6to4 IPv6
 *      address.
 *	Note: This macro is NOT defined in RFC2553 or any other standard
 *	specification and is not a macro that portable applications should
 *	use.
 *	Note: we don't use the IPADDR form of the macro because we need
 *	to do a bytewise copy; the V4ADDR in the 6to4 address is not
 *	32-bit aligned.
 *
 * void IN6_6TO4_TO_V4ADDR(const in6_addr_t *v6, struct in_addr *v4);
 *
 */
#define	IN6_6TO4_TO_V4ADDR(v6, v4) \
	((v4)->_S_un._S_un_b.s_b1 = (v6)->_S6_un._S6_u8[2], \
	(v4)->_S_un._S_un_b.s_b2 = (v6)->_S6_un._S6_u8[3],  \
	(v4)->_S_un._S_un_b.s_b3 = (v6)->_S6_un._S6_u8[4],  \
	(v4)->_S_un._S_un_b.s_b4 = (v6)->_S6_un._S6_u8[5])

/*
 * IN6_V4ADDR_TO_6TO4
 *	Given an IPv4 address and an IPv6 address for output, a 6to4 address
 *	will be created from the IPv4 Address.
 *	Note:  This method for creating 6to4 addresses is not standardized
 *	outside of Solaris.  The newly created 6to4 address will be of the form
 *	2002:<V4ADDR>:<SUBNETID>::<HOSTID>, where SUBNETID will equal 0 and
 *	HOSTID will equal 1.
 *
 * void IN6_V4ADDR_TO_6TO4(const struct in_addr *v4, in6_addr_t *v6)
 *
 */
#ifdef _BIG_ENDIAN
#define	IN6_V4ADDR_TO_6TO4(v4, v6) \
	((v6)->_S6_un._S6_u8[0] = 0x20, \
	(v6)->_S6_un._S6_u8[1] = 0x02, \
	(v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \
	(v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \
	(v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \
	(v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \
	(v6)->_S6_un._S6_u8[6] = 0, \
	(v6)->_S6_un._S6_u8[7] = 0, \
	(v6)->_S6_un._S6_u32[2] = 0, \
	(v6)->_S6_un._S6_u32[3] = 0x00000001U)
#else
#define	IN6_V4ADDR_TO_6TO4(v4, v6) \
	((v6)->_S6_un._S6_u8[0] = 0x20, \
	(v6)->_S6_un._S6_u8[1] = 0x02, \
	(v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \
	(v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \
	(v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \
	(v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \
	(v6)->_S6_un._S6_u8[6] = 0, \
	(v6)->_S6_un._S6_u8[7] = 0, \
	(v6)->_S6_un._S6_u32[2] = 0, \
	(v6)->_S6_un._S6_u32[3] = 0x01000000U)
#endif /* _BIG_ENDIAN */

/*
 * IN6_ARE_ADDR_EQUAL (defined in RFC2292)
 *	 Compares if IPv6 addresses are equal.
 * Note: Compares in order of high likelyhood of a miss so we minimize
 * compares. (Current heuristic order, compare in reverse order of
 * uint32_t units)
 *
 * bool  IN6_ARE_ADDR_EQUAL(const struct in6_addr *,
 *			    const struct in6_addr *);
 */
#define	IN6_ARE_ADDR_EQUAL(addr1, addr2) \
	(((addr1)->_S6_un._S6_u32[3] == (addr2)->_S6_un._S6_u32[3]) && \
	((addr1)->_S6_un._S6_u32[2] == (addr2)->_S6_un._S6_u32[2]) && \
	((addr1)->_S6_un._S6_u32[1] == (addr2)->_S6_un._S6_u32[1]) && \
	((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0]))

/*
 * IN6_ARE_PREFIXEDADDR_EQUAL (not defined in RFCs)
 *	Compares if prefixed parts of IPv6 addresses are equal.
 *
 * uint32_t IN6_MASK_FROM_PREFIX(int, int);
 * bool     IN6_ARE_PREFIXEDADDR_EQUAL(const struct in6_addr *,
 *				       const struct in6_addr *,
 *				       int);
 */
#define	IN6_MASK_FROM_PREFIX(qoctet, prefix) \
	((((qoctet) + 1) * 32 < (prefix)) ? 0xFFFFFFFFu : \
	((((qoctet) * 32) >= (prefix)) ? 0x00000000u : \
	0xFFFFFFFFu << (((qoctet) + 1) * 32 - (prefix))))

#define	IN6_ARE_PREFIXEDADDR_EQUAL(addr1, addr2, prefix) \
	(((ntohl((addr1)->_S6_un._S6_u32[0]) & \
	IN6_MASK_FROM_PREFIX(0, prefix)) == \
	(ntohl((addr2)->_S6_un._S6_u32[0]) & \
	IN6_MASK_FROM_PREFIX(0, prefix))) && \
	((ntohl((addr1)->_S6_un._S6_u32[1]) & \
	IN6_MASK_FROM_PREFIX(1, prefix)) == \
	(ntohl((addr2)->_S6_un._S6_u32[1]) & \
	IN6_MASK_FROM_PREFIX(1, prefix))) && \
	((ntohl((addr1)->_S6_un._S6_u32[2]) & \
	IN6_MASK_FROM_PREFIX(2, prefix)) == \
	(ntohl((addr2)->_S6_un._S6_u32[2]) & \
	IN6_MASK_FROM_PREFIX(2, prefix))) && \
	((ntohl((addr1)->_S6_un._S6_u32[3]) & \
	IN6_MASK_FROM_PREFIX(3, prefix)) == \
	(ntohl((addr2)->_S6_un._S6_u32[3]) & \
	IN6_MASK_FROM_PREFIX(3, prefix))))

#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */


/*
 * Options for use with [gs]etsockopt at the IP level.
 *
 * Note: Some of the IP_ namespace has conflict with and
 * and is exposed through <xti.h>. (It also requires exposing
 * options not implemented). The options with potential
 * for conflicts use #ifndef guards.
 */
#ifndef IP_OPTIONS
#define	IP_OPTIONS	1	/* set/get IP per-packet options   */
#endif

#define	IP_HDRINCL	2	/* int; header is included with data (raw) */

#ifndef IP_TOS
#define	IP_TOS		3	/* int; IP type of service and precedence */
#endif

#ifndef IP_TTL
#define	IP_TTL		4	/* int; IP time to live */
#endif

#define	IP_RECVOPTS	0x5	/* int; receive all IP options w/datagram */
#define	IP_RECVRETOPTS	0x6	/* int; receive IP options for response */
#define	IP_RECVDSTADDR	0x7	/* int; receive IP dst addr w/datagram */
#define	IP_RETOPTS	0x8	/* ip_opts; set/get IP per-packet options */
#define	IP_RECVIF	0x9	/* int; receive the inbound interface index */
#define	IP_RECVSLLA	0xa	/* sockaddr_dl; get source link layer address */
#define	IP_RECVTTL	0xb	/* uint8_t; get TTL for inbound packet */
#define	IP_RECVTOS	0xc	/* uint8_t; get TOS for inbound packet */

#define	IP_MULTICAST_IF		0x10	/* set/get IP multicast interface  */
#define	IP_MULTICAST_TTL	0x11	/* set/get IP multicast timetolive */
#define	IP_MULTICAST_LOOP	0x12	/* set/get IP multicast loopback   */
#define	IP_ADD_MEMBERSHIP	0x13	/* add	an IP group membership	   */
#define	IP_DROP_MEMBERSHIP	0x14	/* drop an IP group membership	   */
#define	IP_BLOCK_SOURCE		0x15	/* block   mcast pkts from source  */
#define	IP_UNBLOCK_SOURCE	0x16	/* unblock mcast pkts from source  */
#define	IP_ADD_SOURCE_MEMBERSHIP  0x17	/* add  mcast group/source pair	   */
#define	IP_DROP_SOURCE_MEMBERSHIP 0x18	/* drop mcast group/source pair	   */
#define	IP_NEXTHOP		0x19	/* send directly to next hop	   */
/*
 * IP_PKTINFO and IP_RECVPKTINFO have same value. Size of argument passed in
 * is used to differentiate b/w the two.
 */
#define	IP_PKTINFO		0x1a	/* specify src address and/or index */
#define	IP_RECVPKTINFO		0x1a	/* recv dest/matched addr and index */
#define	IP_DONTFRAG		0x1b	/* don't fragment packets */
#define	IP_MINTTL		0x1c	/* minimum acceptable TTL */

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
/*
 * Different preferences that can be requested from IPSEC protocols.
 */
#define	IP_SEC_OPT		0x22	/* Used to set IPSEC options */
#define	IPSEC_PREF_NEVER	0x01
#define	IPSEC_PREF_REQUIRED	0x02
#define	IPSEC_PREF_UNIQUE	0x04
/*
 * This can be used with the setsockopt() call to set per socket security
 * options. When the application uses per-socket API, we will reflect
 * the request on both outbound and inbound packets.
 */

typedef struct ipsec_req {
	uint_t		ipsr_ah_req;		/* AH request */
	uint_t		ipsr_esp_req;		/* ESP request */
	uint_t		ipsr_self_encap_req;	/* Self-Encap request */
	uint8_t		ipsr_auth_alg;		/* Auth algs for AH */
	uint8_t		ipsr_esp_alg;		/* Encr algs for ESP */
	uint8_t		ipsr_esp_auth_alg;	/* Auth algs for ESP */
} ipsec_req_t;

/*
 * MCAST_* options are protocol-independent.  The actual definitions
 * are with the v6 options below; this comment is here to note the
 * namespace usage.
 *
 * #define	MCAST_JOIN_GROUP	0x29
 * #define	MCAST_LEAVE_GROUP	0x2a
 * #define	MCAST_BLOCK_SOURCE	0x2b
 * #define	MCAST_UNBLOCK_SOURCE	0x2c
 * #define	MCAST_JOIN_SOURCE_GROUP	0x2d
 * #define	MCAST_LEAVE_SOURCE_GROUP 0x2e
 */
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

/*
 * SunOS private (potentially not portable) IP_ option names
 */
#define	IP_BOUND_IF		0x41	/* bind socket to an ifindex	   */
#define	IP_UNSPEC_SRC		0x42	/* use unspecified source address  */
#define	IP_BROADCAST_TTL	0x43	/* use specific TTL for broadcast  */
/* can be reused		0x44 */
#define	IP_DHCPINIT_IF		0x45	/* accept all unicast DHCP traffic */

/*
 * Option values and names (when !_XPG5) shared with <xti_inet.h>
 */
#ifndef IP_REUSEADDR
#define	IP_REUSEADDR		0x104
#endif

#ifndef IP_DONTROUTE
#define	IP_DONTROUTE		0x105
#endif

#ifndef IP_BROADCAST
#define	IP_BROADCAST		0x106
#endif

/*
 * The following option values are reserved by <xti_inet.h>
 *
 * T_IP_OPTIONS	0x107	 -  IP per-packet options
 * T_IP_TOS	0x108	 -  IP per packet type of service
 */

/*
 * Default value constants for multicast attributes controlled by
 * IP*_MULTICAST_LOOP and IP*_MULTICAST_{TTL,HOPS} options.
 */
#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop */
#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member */

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
/*
 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
 */
struct ip_mreq {
	struct in_addr	imr_multiaddr;	/* IP multicast address of group */
	struct in_addr	imr_interface;	/* local IP address of interface */
};

/*
 * Argument structure for IP_BLOCK_SOURCE, IP_UNBLOCK_SOURCE,
 * IP_ADD_SOURCE_MEMBERSHIP, and IP_DROP_SOURCE_MEMBERSHIP.
 */
struct ip_mreq_source {
	struct in_addr	imr_multiaddr;	/* IP address of group */
	struct in_addr	imr_sourceaddr;	/* IP address of source */
	struct in_addr	imr_interface;	/* IP address of interface */
};

/*
 * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP on
 * IPv6 addresses.
 */
struct ipv6_mreq {
	struct in6_addr	ipv6mr_multiaddr;	/* IPv6 multicast addr */
	unsigned int	ipv6mr_interface;	/* interface index */
};

/*
 * Use #pragma pack() construct to force 32-bit alignment on amd64.
 * This is needed to keep the structure size and offsets consistent
 * between a 32-bit app and the 64-bit amd64 kernel in structures
 * where 64-bit alignment would create gaps (in this case, structures
 * which have a uint32_t followed by a struct sockaddr_storage).
 */
#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack(4)
#endif

/*
 * Argument structure for MCAST_JOIN_GROUP and MCAST_LEAVE_GROUP.
 */
struct group_req {
	uint32_t		gr_interface;	/* interface index */
	struct sockaddr_storage	gr_group;	/* group address */
};

/*
 * Argument structure for MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE,
 * MCAST_JOIN_SOURCE_GROUP, MCAST_LEAVE_SOURCE_GROUP.
 */
struct group_source_req {
	uint32_t		gsr_interface;	/* interface index */
	struct sockaddr_storage	gsr_group;	/* group address */
	struct sockaddr_storage	gsr_source;	/* source address */
};

/*
 * Argument for SIOC[GS]MSFILTER ioctls
 */
struct group_filter {
	uint32_t		gf_interface;	/* interface index */
	struct sockaddr_storage	gf_group;	/* multicast address */
	uint32_t		gf_fmode;	/* filter mode */
	uint32_t		gf_numsrc;	/* number of sources */
	struct sockaddr_storage	gf_slist[1];	/* source address */
};

#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack()
#endif

#define	GROUP_FILTER_SIZE(numsrc) \
	(sizeof (struct group_filter) - sizeof (struct sockaddr_storage) \
	+ (numsrc) * sizeof (struct sockaddr_storage))

/*
 * Argument for SIOC[GS]IPMSFILTER ioctls (IPv4-specific)
 */
struct ip_msfilter {
	struct in_addr	imsf_multiaddr;	/* IP multicast address of group */
	struct in_addr	imsf_interface;	/* local IP address of interface */
	uint32_t	imsf_fmode;	/* filter mode */
	uint32_t	imsf_numsrc;	/* number of sources in src_list */
	struct in_addr	imsf_slist[1];	/* start of source list */
};

#define	IP_MSFILTER_SIZE(numsrc) \
	(sizeof (struct ip_msfilter) - sizeof (struct in_addr) \
	+ (numsrc) * sizeof (struct in_addr))

/*
 * Multicast source filter manipulation functions in libsocket;
 * defined in RFC 3678.
 */
int setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t,
			uint_t, struct sockaddr_storage *);

int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t *,
			uint_t *, struct sockaddr_storage *);

int setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t,
			uint32_t, struct in_addr *);

int getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *,
			uint32_t *, struct in_addr *);

/*
 * Definitions needed for [gs]etsourcefilter(), [gs]etipv4sourcefilter()
 */
#define	MCAST_INCLUDE	1
#define	MCAST_EXCLUDE	2

/*
 * Argument struct for IP_PKTINFO option
 */
typedef struct in_pktinfo {
	unsigned int		ipi_ifindex;	/* send/recv interface index */
	struct in_addr		ipi_spec_dst;	/* matched source address */
	struct in_addr		ipi_addr;	/* src/dst address in IP hdr */
} in_pktinfo_t;

/*
 * Argument struct for IPV6_PKTINFO option
 */
struct in6_pktinfo {
	struct in6_addr		ipi6_addr;	/* src/dst IPv6 address */
	unsigned int		ipi6_ifindex;	/* send/recv interface index */
};

/*
 * Argument struct for IPV6_MTUINFO option
 */
struct ip6_mtuinfo {
	struct sockaddr_in6	ip6m_addr; /* dst address including zone ID */
	uint32_t		ip6m_mtu;  /* path MTU in host byte order */
};

/*
 * IPv6 routing header types
 */
#define	IPV6_RTHDR_TYPE_0	0

extern socklen_t inet6_rth_space(int type, int segments);
extern void *inet6_rth_init(void *bp, socklen_t bp_len, int type, int segments);
extern int inet6_rth_add(void *bp, const struct in6_addr *addr);
extern int inet6_rth_reverse(const void *in, void *out);
extern int inet6_rth_segments(const void *bp);
extern struct in6_addr *inet6_rth_getaddr(const void *bp, int index);

extern int inet6_opt_init(void *extbuf, socklen_t extlen);
extern int inet6_opt_append(void *extbuf, socklen_t extlen, int offset,
	uint8_t type, socklen_t len, uint_t align, void **databufp);
extern int inet6_opt_finish(void *extbuf, socklen_t extlen, int offset);
extern int inet6_opt_set_val(void *databuf, int offset, void *val,
	socklen_t vallen);
extern int inet6_opt_next(void *extbuf, socklen_t extlen, int offset,
	uint8_t *typep, socklen_t *lenp, void **databufp);
extern int inet6_opt_find(void *extbufp, socklen_t extlen, int offset,
	uint8_t type, socklen_t *lenp, void **databufp);
extern int inet6_opt_get_val(void *databuf, int offset, void *val,
	socklen_t vallen);
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

/*
 * Argument structure for IP_ADD_PROXY_ADDR.
 * Note that this is an unstable, experimental interface. It may change
 * later. Don't use it unless you know what it is.
 */
typedef struct {
	struct in_addr	in_prefix_addr;
	unsigned int	in_prefix_len;
} in_prefix_t;


#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
/*
 * IPv6 options
 */
#define	IPV6_UNICAST_HOPS	0x5	/* hop limit value for unicast */
					/* packets. */
					/* argument type: uint_t */
#define	IPV6_MULTICAST_IF	0x6	/* outgoing interface for */
					/* multicast packets. */
					/* argument type: struct in6_addr */
#define	IPV6_MULTICAST_HOPS	0x7	/* hop limit value to use for */
					/* multicast packets. */
					/* argument type: uint_t */
#define	IPV6_MULTICAST_LOOP	0x8	/* enable/disable delivery of */
					/* multicast packets on same socket. */
					/* argument type: uint_t */
#define	IPV6_JOIN_GROUP		0x9	/* join an IPv6 multicast group. */
					/* argument type: struct ipv6_mreq */
#define	IPV6_LEAVE_GROUP	0xa	/* leave an IPv6 multicast group */
					/* argument type: struct ipv6_mreq */

/*
 * Other XPG6 constants.
 */
#define	INET_ADDRSTRLEN		16	/* max len IPv4 addr in ascii dotted */
					/* decimal notation. */
#define	INET6_ADDRSTRLEN	46	/* max len of IPv6 addr in ascii */
					/* standard colon-hex notation. */

#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)

/*
 * IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP are being kept
 * for backward compatibility. They have the same meaning as IPV6_JOIN_GROUP
 * and IPV6_LEAVE_GROUP respectively.
 */
#define	IPV6_ADD_MEMBERSHIP	0x9	/* join an IPv6 multicast group. */
					/* argument type: struct ipv6_mreq */
#define	IPV6_DROP_MEMBERSHIP	0xa	/* leave an IPv6 multicast group */
					/* argument type: struct ipv6_mreq */

#define	IPV6_PKTINFO		0xb	/* addr plus interface index */
					/* arg type: "struct in6_pktingo" - */
#define	IPV6_HOPLIMIT		0xc	/* hoplimit for datagram */
#define	IPV6_NEXTHOP		0xd	/* next hop address  */
#define	IPV6_HOPOPTS		0xe	/* hop by hop options */
#define	IPV6_DSTOPTS		0xf	/* destination options - after */
					/* the routing header */
#define	IPV6_RTHDR		0x10	/* routing header  */
#define	IPV6_RTHDRDSTOPTS	0x11	/* destination options - before */
					/* the routing header */
#define	IPV6_RECVPKTINFO	0x12	/* enable/disable IPV6_PKTINFO */
#define	IPV6_RECVHOPLIMIT	0x13	/* enable/disable IPV6_HOPLIMIT */
#define	IPV6_RECVHOPOPTS	0x14	/* enable/disable IPV6_HOPOPTS */

/*
 * This options exists for backwards compatability and should no longer be
 * used.  Use IPV6_RECVDSTOPTS instead.
 */
#define	_OLD_IPV6_RECVDSTOPTS	0x15

#define	IPV6_RECVRTHDR		0x16	/* enable/disable IPV6_RTHDR */

/*
 * enable/disable IPV6_RTHDRDSTOPTS.  Now obsolete.  IPV6_RECVDSTOPTS enables
 * the receipt of both headers.
 */
#define	IPV6_RECVRTHDRDSTOPTS	0x17

#define	IPV6_CHECKSUM		0x18	/* Control checksum on raw sockets */
#define	IPV6_RECVTCLASS		0x19	/* enable/disable IPV6_TCLASS */
#define	IPV6_USE_MIN_MTU	0x20	/* send packets with minimum MTU */
#define	IPV6_DONTFRAG		0x21	/* don't fragment packets */
#define	IPV6_SEC_OPT		0x22	/* Used to set IPSEC options */
#define	IPV6_SRC_PREFERENCES	0x23	/* Control socket's src addr select */
#define	IPV6_RECVPATHMTU	0x24	/* receive PMTU info */
#define	IPV6_PATHMTU		0x25	/* get the PMTU */
#define	IPV6_TCLASS		0x26	/* traffic class */
#define	IPV6_V6ONLY		0x27	/* v6 only socket option */

/*
 * enable/disable receipt of both both IPV6_DSTOPTS headers.
 */
#define	IPV6_RECVDSTOPTS	0x28

/*
 * protocol-independent multicast membership options.
 */
#define	MCAST_JOIN_GROUP	0x29	/* join group for all sources */
#define	MCAST_LEAVE_GROUP	0x2a	/* leave group */
#define	MCAST_BLOCK_SOURCE	0x2b	/* block specified source */
#define	MCAST_UNBLOCK_SOURCE	0x2c	/* unblock specified source */
#define	MCAST_JOIN_SOURCE_GROUP	0x2d	/* join group for specified source */
#define	MCAST_LEAVE_SOURCE_GROUP 0x2e	/* leave source/group pair */

/* 32Bit field for IPV6_SRC_PREFERENCES */
#define	IPV6_PREFER_SRC_HOME		0x00000001
#define	IPV6_PREFER_SRC_COA		0x00000002
#define	IPV6_PREFER_SRC_PUBLIC		0x00000004
#define	IPV6_PREFER_SRC_TMP		0x00000008
#define	IPV6_PREFER_SRC_NONCGA		0x00000010
#define	IPV6_PREFER_SRC_CGA		0x00000020

#define	IPV6_PREFER_SRC_MIPMASK	(IPV6_PREFER_SRC_HOME | IPV6_PREFER_SRC_COA)
#define	IPV6_PREFER_SRC_MIPDEFAULT	IPV6_PREFER_SRC_HOME
#define	IPV6_PREFER_SRC_TMPMASK	(IPV6_PREFER_SRC_PUBLIC | IPV6_PREFER_SRC_TMP)
#define	IPV6_PREFER_SRC_TMPDEFAULT	IPV6_PREFER_SRC_PUBLIC
#define	IPV6_PREFER_SRC_CGAMASK	(IPV6_PREFER_SRC_NONCGA | IPV6_PREFER_SRC_CGA)
#define	IPV6_PREFER_SRC_CGADEFAULT	IPV6_PREFER_SRC_NONCGA

#define	IPV6_PREFER_SRC_MASK (IPV6_PREFER_SRC_MIPMASK |\
	IPV6_PREFER_SRC_TMPMASK | IPV6_PREFER_SRC_CGAMASK)

#define	IPV6_PREFER_SRC_DEFAULT	(IPV6_PREFER_SRC_MIPDEFAULT |\
	IPV6_PREFER_SRC_TMPDEFAULT | IPV6_PREFER_SRC_CGADEFAULT)

#define	IPV6_MINHOPCOUNT	0x2f	/* minimum acceptable hop limit */

/*
 * SunOS private (potentially not portable) IPV6_ option names
 */
#define	IPV6_BOUND_IF		0x41	/* bind to an ifindex */
#define	IPV6_UNSPEC_SRC		0x42	/* source of packets set to */
					/* unspecified (all zeros) */

/*
 * Miscellaneous IPv6 constants.
 */
#define	IPV6_PAD1_OPT		0	/* pad byte in IPv6 extension hdrs */

#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */

/*
 * Extern declarations for pre-defined global const variables
 */
#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
#ifndef _KERNEL
#ifdef __STDC__
extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;
#else
extern struct in6_addr in6addr_any;
extern struct in6_addr in6addr_loopback;
#endif
#endif
#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IN_H */
/*
 * Copyright (c) 1997-1998 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Common structure pcb for internet protocol implementation.
 * Here are stored pointers to local and foreign host table
 * entries, local and foreign socket numbers, and pointers
 * up (to a socket structure) and down (to a protocol-specific)
 * control block.
 */

#ifndef	_NETINET_IN_PCB_H
#define	_NETINET_IN_PCB_H

/* in_pcb.h 1.7 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#ifdef	__cplusplus
extern "C" {
#endif

struct inpcb {
	struct	inpcb *inp_next, *inp_prev;	/* pointers to other pcb's */
	struct	inpcb *inp_head;	/* pointer back to chain of inpcb's */
					/* for this protocol */
	struct	in_addr inp_faddr;	/* foreign host table entry */
	ushort_t inp_fport;		/* foreign port */
	struct	in_addr inp_laddr;	/* local host table entry */
	ushort_t inp_lport;		/* local port */
	struct	socket *inp_socket;	/* back pointer to socket */
	caddr_t	inp_ppcb;		/* pointer to per-protocol pcb */
	struct	route inp_route;	/* placeholder for routing entry */
	struct	mbuf *inp_options;	/* IP options */
};

#define	INPLOOKUP_WILDCARD	1
#define	INPLOOKUP_SETLOCAL	2

#define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IN_PCB_H */
/*
 * Copyright (c) 1997-1998, 2001 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef	_NETINET_IN_SYSTM_H
#define	_NETINET_IN_SYSTM_H

/* in_systm.h 1.8 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Legacy "network types" -- these are provided for backwards compatibility
 * only; new code should use uint16_t and uint32_t instead.
 */
typedef uint16_t n_short;	/* short as received from the net */
typedef uint32_t n_long;	/* long as received from the net */
typedef uint32_t n_time;	/* ms since 00:00 GMT, byte rev */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IN_SYSTM_H */
/*
 * Copyright (c) 1997-1998 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 * Copyright (c) 1985, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Interface address, Internet version.  One of these structures
 * is allocated for each interface with an Internet address.
 * The ifaddr structure contains the protocol-independent part
 * of the structure and is assumed to be first.
 */

#ifndef	_NETINET_IN_VAR_H
#define	_NETINET_IN_VAR_H

/* in_var.h 1.3 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#ifdef	__cplusplus
extern "C" {
#endif

struct in_ifaddr {
	struct	ifaddr ia_ifa;		/* protocol-independent info */
#define	ia_addr	ia_ifa.ifa_addr
#define	ia_broadaddr	ia_ifa.ifa_broadaddr
#define	ia_dstaddr	ia_ifa.ifa_dstaddr
#define	ia_ifp		ia_ifa.ifa_ifp
	ulong_t	ia_net;			/* network number of interface */
	ulong_t	ia_netmask;		/* mask of net part */
	ulong_t	ia_subnet;		/* subnet number, including net */
	ulong_t	ia_subnetmask;		/* mask of net + subnet */
	struct	in_addr ia_netbroadcast; /* broadcast addr for (logical) net */
	int	ia_flags;
	struct	in_ifaddr *ia_next;	/* next in list of internet addresses */
};
/*
 * Given a pointer to an in_ifaddr (ifaddr),
 * return a pointer to the addr as a sockadd_in.
 */
#define	IA_SIN(ia) ((struct sockaddr_in *)(&((struct in_ifaddr *)ia)->ia_addr))
/*
 * ia_flags
 */
#define	IFA_ROUTE	0x01		/* routing entry installed */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IN_VAR_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2001 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#ifndef	_NETINET_INETUTIL_H
#define	_NETINET_INETUTIL_H

#include <sys/types.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Routines to convert binary data into hexidecimal ascii notation and
 * vice versa.
 */
extern int octet_to_hexascii(const void *, uint_t, char *, uint_t *);
extern int hexascii_to_octet(const char *, uint_t, void *, uint_t *);

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_INETUTIL_H */
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of California at Berkeley. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */

/*
 * Definitions for internet protocol version 4.
 * Per RFC 791, September 1981.
 */

#ifndef	_NETINET_IP_H
#define	_NETINET_IP_H

/* ip.h 1.13 88/08/19 SMI; from UCB 7.6.1.1 3/15/88	*/

#include <sys/isa_defs.h>

#ifdef	__cplusplus
extern "C" {
#endif

#define	IPVERSION	4

/*
 * Structure of an internet header, naked of options.
 */
struct ip {
#ifdef _BIT_FIELDS_LTOH
	uchar_t	ip_hl:4,		/* header length */
		ip_v:4;			/* version */
#else
	uchar_t	ip_v:4,			/* version */
		ip_hl:4;		/* header length */
#endif
	uchar_t	ip_tos;			/* type of service */
	ushort_t ip_len;		/* total length */
	ushort_t ip_id;			/* identification */
	ushort_t ip_off;		/* fragment offset field */
#define	IP_DF 0x4000			/* dont fragment flag */
#define	IP_MF 0x2000			/* more fragments flag */
	uchar_t	ip_ttl;			/* time to live */
	uchar_t	ip_p;			/* protocol */
	ushort_t ip_sum;		/* checksum */
	struct	in_addr ip_src, ip_dst;	/* source and dest address */
};

#define	IP_MAXPACKET	65535		/* maximum packet size */

/*
 * Definitions for IP type of service (ip_tos)
 */
#define	IPTOS_LOWDELAY		0x10
#define	IPTOS_THROUGHPUT	0x08
#define	IPTOS_RELIABILITY	0x04
#define	IPTOS_ECT		0x02	/* ECN-Capable Transport flag */
#define	IPTOS_CE		0x01	/* ECN-Congestion Experienced flag */

/*
 * Definitions for IP precedence (also in ip_tos) (hopefully unused)
 */
#define	IPTOS_PREC_NETCONTROL		0xe0
#define	IPTOS_PREC_INTERNETCONTROL	0xc0
#define	IPTOS_PREC_CRITIC_ECP		0xa0
#define	IPTOS_PREC_FLASHOVERRIDE	0x80
#define	IPTOS_PREC_FLASH		0x60
#define	IPTOS_PREC_IMMEDIATE		0x40
#define	IPTOS_PREC_PRIORITY		0x20
#define	IPTOS_PREC_ROUTINE		0x00

/*
 * Definitions for options.
 */

/* Bits in the option value */
#define	IPOPT_COPY		0x80

#define	IPOPT_COPIED(o)		((o)&0x80)
#define	IPOPT_CLASS(o)		((o)&0x60)
#define	IPOPT_NUMBER(o)		((o)&0x1f)

#define	IPOPT_CONTROL		0x00
#define	IPOPT_RESERVED1		0x20
#define	IPOPT_DEBMEAS		0x40
#define	IPOPT_RESERVED2		0x60

#define	IPOPT_EOL		0x00		/* end of option list */
#define	IPOPT_NOP		0x01		/* no operation */

#define	IPOPT_RR		0x07		/* record packet route */
#define	IPOPT_RTRALERT		0x14		/* router alert */
#define	IPOPT_TS		0x44		/* timestamp */
#define	IPOPT_SECURITY		0x82		/* provide s,c,h,tcc */
#define	IPOPT_LSRR		0x83		/* loose source route */
#define	IPOPT_EXTSEC		0x85
#define	IPOPT_COMSEC		0x86
#define	IPOPT_SATID		0x88		/* satnet id */
#define	IPOPT_SSRR		0x89		/* strict source route */
#define	IPOPT_RA		0x94
#define	IPOPT_SDMDD		0x95

/*
 * Offsets to fields in options other than EOL and NOP.
 */
#define	IPOPT_OPTVAL		0		/* option ID */
#define	IPOPT_OLEN		1		/* option length */
#define	IPOPT_OFFSET		2		/* offset within option */
#define	IPOPT_POS_OV_FLG	3
#define	IPOPT_MINOFF		4		/* min value of IPOPT_OFFSET */


/* Minimum for src and record route options */
#define	IPOPT_MINOFF_SR		IPOPT_MINOFF

/*
 * Time stamp option structure.
 */
struct	ip_timestamp {
	uchar_t	ipt_code;		/* IPOPT_TS */
	uchar_t	ipt_len;		/* size of structure (variable) */
	uchar_t	ipt_ptr;		/* index of current entry */
#ifdef _BIT_FIELDS_LTOH
	uchar_t	ipt_flg:4,		/* flags, see below */
		ipt_oflw:4;		/* overflow counter */
#else
	uchar_t	ipt_oflw:4,		/* overflow counter */
		ipt_flg:4;		/* flags, see below */
#endif
	union ipt_timestamp {
		uint32_t	ipt_time[1];
		struct	ipt_ta {
			struct in_addr	ipt_addr;
			uint32_t	ipt_time;
		} ipt_ta[1];
	} ipt_timestamp;
};

/* flag bits for ipt_flg */
#define	IPOPT_TS_TSONLY		0		/* timestamps only */
#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
#define	IPOPT_TS_PRESPEC	2		/* specified modules only */
#define	IPOPT_TS_PRESPEC_RFC791	3

/* Minimum for timestamp option */
#define	IPOPT_MINOFF_IT		5
#define	IPOPT_MINLEN_IT		5

#define	IPOPT_TS_TIMELEN	4	/* Timestamp size */

/* bits for security (not byte swapped) */
#define	IPOPT_SECUR_UNCLASS	0x0000
#define	IPOPT_SECUR_CONFID	0xf135
#define	IPOPT_SECUR_EFTO	0x789a
#define	IPOPT_SECUR_MMMM	0xbc4d
#define	IPOPT_SECUR_RESTR	0xaf13
#define	IPOPT_SECUR_SECRET	0xd788
#define	IPOPT_SECUR_TOPSECRET	0x6bc5

/*
 * Internet implementation parameters.
 */
#define	MAXTTL		255		/* maximum time to live (seconds) */
#define	IPFRAGTTL	60		/* time to live for frags, slowhz */
#define	IPTTLDEC	1		/* subtracted when forwarding */

#define	IP_MSS		576		/* default maximum segment size */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IP_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * ip6.h - Common structures and definitions as defined by
 * advanced BSD API.
 */

#ifndef	_NETINET_IP6_H
#define	_NETINET_IP6_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <netinet/in.h>

struct	ip6_hdr {
	union {
		struct ip6_hdrctl {
			uint32_t	ip6_un1_flow;   /* 4 bits version, */
							/* 8 bits tclass, and */
							/* 20 bits flow-ID */
			uint16_t	ip6_un1_plen;   /* payload length */
			uint8_t		ip6_un1_nxt;    /* next header */
			uint8_t		ip6_un1_hlim;   /* hop limit */
		} ip6_un1;
		uint8_t	ip6_un2_vfc;	/* 4 bits version and */
					/* top 4 bits of tclass */
	} ip6_ctlun;
	struct in6_addr ip6_src;	/* source address */
	struct in6_addr ip6_dst;	/* destination address */
};
typedef struct ip6_hdr	ip6_t;

#define	ip6_vfc		ip6_ctlun.ip6_un2_vfc	/* 4 bits version and */
						/* top 4 bits of tclass */
#define	ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
#define	ip6_vcf		ip6_flow		/* Version, tclass, flow-ID */
#define	ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
#define	ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt
#define	ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
#define	ip6_hops	ip6_ctlun.ip6_un1.ip6_un1_hlim

/* Hop-by-Hop options header */
struct ip6_hbh {
	uint8_t	ip6h_nxt;	/* next header */
	uint8_t	ip6h_len;	/* length in units of 8 octets */
		/* followed by options */
};
typedef struct ip6_hbh	ip6_hbh_t;

/* Destination options header */
struct ip6_dest {
	uint8_t	ip6d_nxt;	/* next header */
	uint8_t	ip6d_len;	/* length in units of 8 octets */
		/* followed by options */
};
typedef struct ip6_dest	ip6_dest_t;

/* Routing header */
struct ip6_rthdr {
	uint8_t	ip6r_nxt;	/* next header */
	uint8_t	ip6r_len;	/* length in units of 8 octets */
	uint8_t	ip6r_type;	/* routing type */
	uint8_t	ip6r_segleft;	/* segments left */
		/* followed by routing type specific data */
};
typedef struct ip6_rthdr	ip6_rthdr_t;

/* Type 0 Routing header */
struct ip6_rthdr0 {
	uint8_t	ip6r0_nxt;		/* next header */
	uint8_t	ip6r0_len;		/* length in units of 8 octets */
	uint8_t	ip6r0_type;		/* always zero */
	uint8_t	ip6r0_segleft;		/* segments left */
	uint32_t ip6r0_reserved;	/* reserved field */
};
typedef struct ip6_rthdr0	ip6_rthdr0_t;

/* Fragment header */
struct ip6_frag {
	uint8_t		ip6f_nxt;	/* next header */
	uint8_t		ip6f_reserved;	/* reserved field */
	uint16_t	ip6f_offlg;	/* offset, reserved, and flag */
	uint32_t	ip6f_ident;	/* identification */
};
typedef struct ip6_frag	ip6_frag_t;

/* ip6f_offlg field related constants (in network byte order) */
#ifdef _BIG_ENDIAN
#define	IP6F_OFF_MASK		0xfff8	/* mask out offset from _offlg */
#define	IP6F_RESERVED_MASK	0x0006	/* reserved bits in ip6f_offlg */
#define	IP6F_MORE_FRAG		0x0001	/* more-fragments flag */
#else
#define	IP6F_OFF_MASK		0xf8ff	/* mask out offset from _offlg */
#define	IP6F_RESERVED_MASK	0x0600	/* reserved bits in ip6f_offlg */
#define	IP6F_MORE_FRAG		0x0100	/* more-fragments flag */
#endif

/* IPv6 options */
struct	ip6_opt {
	uint8_t	ip6o_type;
	uint8_t	ip6o_len;
};

/*
 * The high-order 3 bits of the option type define the behavior
 * when processing an unknown option and whether or not the option
 * content changes in flight.
 */
#define	IP6OPT_TYPE(o)		((o) & 0xc0)
#define	IP6OPT_TYPE_SKIP	0x00
#define	IP6OPT_TYPE_DISCARD	0x40
#define	IP6OPT_TYPE_FORCEICMP	0x80
#define	IP6OPT_TYPE_ICMP	0xc0
#define	IP6OPT_MUTABLE		0x20

#define	IP6OPT_PAD1			0x00	/* 00 0 00000 */
#define	IP6OPT_PADN			0x01	/* 00 0 00001 */
#define	IP6OPT_JUMBO			0xc2	/* 11 0 00010 = 194 */
#define	IP6OPT_NSAP_ADDR		0xc3	/* 11 0 00011 */
#define	IP6OPT_TUNNEL_LIMIT		0x04	/* 00 0 00100 */
#define	IP6OPT_ROUTER_ALERT		0x05	/* 00 0 00101 */
#define	IP6OPT_BINDING_UPDATE		0xc6	/* 11 0 00110 */
#define	IP6OPT_BINDING_ACK		0x07	/* 00 0 00111 */
#define	IP6OPT_BINDING_REQ		0x08	/* 00 0 01000 */
#define	IP6OPT_HOME_ADDRESS		0xc9	/* 11 0 01001 */
#define	IP6OPT_EID			0x8a	/* 10 0 01010 */

#define	IP6OPT_LS			0x0a	/* 00 0 01010 */

#define	IP6_MAX_OPT_LENGTH	255

/* Jumbo Payload Option */
struct	ip6_opt_jumbo {
	uint8_t	ip6oj_type;
	uint8_t	ip6oj_len;
	uint8_t ip6oj_jumbo_len[4];
};
#define	IP6OPT_JUMBO_LEN	6

/* NSAP Address Option */
struct	ip6_opt_nsap {
	uint8_t	ip6on_type;
	uint8_t	ip6on_len;
	uint8_t ip6on_src_nsap_len;
	uint8_t ip6on_dst_nsap_len;
	/* Followed by source NSAP */
	/* Followed by destination NSAP */
};

/* Tunnel Limit Option */
struct	ip6_opt_tunnel {
	uint8_t	ip6ot_type;
	uint8_t	ip6ot_len;
	uint8_t ip6ot_encap_limit;
};

/* Router Alert Option */
struct	ip6_opt_router {
	uint8_t	ip6or_type;
	uint8_t	ip6or_len;
	uint8_t ip6or_value[2];
};

/* Router alert values (in network byte order) */
#ifdef _BIG_ENDIAN
#define	IP6_ALERT_MLD			0x0000
#define	IP6_ALERT_RSVP			0x0001
#define	IP6_ALERT_AN			0x0002
#else
#define	IP6_ALERT_MLD			0x0000
#define	IP6_ALERT_RSVP			0x0100
#define	IP6_ALERT_AN			0x0200
#endif

/* Binding Update Option */
struct	ip6_opt_binding_update {
	uint8_t	ip6ou_type;
	uint8_t	ip6ou_len;
	uint8_t ip6ou_flags;
	uint8_t ip6ou_prefixlen;
	uint8_t ip6ou_seqno[2];
	uint8_t ip6ou_lifetime[4];
	uint8_t ip6ou_coa[16];		/* Optional based on flags */
	/* Followed by sub-options */
};

/* Binding Update Flags */
#define	IP6_BUF_ACK	0x80	/* Request a binding ack */
#define	IP6_BUF_HOME	0x40	/* Home Registration */
#define	IP6_BUF_COA	0x20	/* Care-of-address present in option */
#define	IP6_BUF_ROUTER	0x10	/* Sending mobile node is a router */

/* Binding Ack Option */
struct	ip6_opt_binding_ack {
	uint8_t	ip6oa_type;
	uint8_t	ip6oa_len;
	uint8_t ip6oa_status;
	uint8_t ip6oa_seqno[2];
	uint8_t ip6oa_lifetime[4];
	uint8_t ip6oa_refresh[4];
	/* Followed by sub-options */
};

/* Binding Request Option */
struct	ip6_opt_binding_request {
	uint8_t	ip6or_type;
	uint8_t	ip6or_len;
	/* Followed by sub-options */
};

/* Home Address Option */
struct	ip6_opt_home_address {
	uint8_t	ip6oh_type;
	uint8_t	ip6oh_len;
	uint8_t ip6oh_addr[16];		/* Home Address */
	/* Followed by sub-options */
};

/* Labeled Security Option */
struct	ip6_opt_labeled_security {
	uint8_t ip6ol_type;
	uint8_t ip6ol_len;	/* always even for defined values */
	uint8_t ip6ol_doi[4];
	/* Followed by sub-options */
};

#define	IP6LS_DOI_V4	0	/* IPv4 transition */

#define	IP6LS_TT_LEVEL	1	/* level or classification; 2-octet value */
#define	IP6LS_TT_VECTOR	2	/* compartments; bit vector (even # octets) */
#define	IP6LS_TT_ENUM	3	/* set membership; list of 2-octet values */
#define	IP6LS_TT_RANGES	4	/* set membership; pairs of 2-octet values */
#define	IP6LS_TT_V4	5	/* IPv4 compatible option */
#define	IP6LS_TT_DEST	6	/* destination-only data; per DOI */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IP6_H */
/*
 * Copyright 1997-2002 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1982, 1986, 1993
 *      The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * Interface Control Message Protocol Definitions.
 * Per RFC 792, September 1981.
 */

#ifndef	_NETINET_IP_ICMP_H
#define	_NETINET_IP_ICMP_H

#include <netinet/in_systm.h>

/* ip_icmp.h 1.9 88/08/19 SMI; from UCB 7.3 12/7/87	*/

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Structure of an icmp header.
 */
struct icmp {
	uchar_t	icmp_type;		/* type of message, see below */
	uchar_t	icmp_code;		/* type sub code */
	uint16_t icmp_cksum;		/* ones complement cksum of struct */
	union {
		uchar_t ih_pptr;		/* ICMP_PARAMPROB */
		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT */
		struct ih_idseq {
			uint16_t icd_id;
			uint16_t icd_seq;
		} ih_idseq;
		int ih_void;

		/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
		struct ih_pmtu {
			uint16_t ipm_void;
			uint16_t ipm_nextmtu;
		} ih_pmtu;

		struct ih_rtradv {
			uchar_t irt_num_addrs;
			uchar_t irt_wpa;
			uint16_t irt_lifetime;
		} ih_rtradv;
	} icmp_hun;
#define	icmp_pptr	icmp_hun.ih_pptr
#define	icmp_gwaddr	icmp_hun.ih_gwaddr
#define	icmp_id		icmp_hun.ih_idseq.icd_id
#define	icmp_seq	icmp_hun.ih_idseq.icd_seq
#define	icmp_void	icmp_hun.ih_void
#define	icmp_pmvoid	icmp_hun.ih_pmtu.ipm_void
#define	icmp_nextmtu	icmp_hun.ih_pmtu.ipm_nextmtu
	union {
		struct id_ts {
			n_time its_otime;
			n_time its_rtime;
			n_time its_ttime;
		} id_ts;
		struct id_ip  {
			struct ip idi_ip;
			/* options and then 64 bits of data */
		} id_ip;
		uint32_t id_mask;
		char	id_data[1];
	} icmp_dun;
#define	icmp_otime	icmp_dun.id_ts.its_otime
#define	icmp_rtime	icmp_dun.id_ts.its_rtime
#define	icmp_ttime	icmp_dun.id_ts.its_ttime
#define	icmp_ip		icmp_dun.id_ip.idi_ip
#define	icmp_mask	icmp_dun.id_mask
#define	icmp_data	icmp_dun.id_data
};

/*
 * Lower bounds on packet lengths for various types.
 * For the error advice packets must first insure that the
 * packet is large enough to contain the returned ip header.
 * Only then can we do the check to see if 64 bits of packet
 * data have been returned, since we need to check the returned
 * ip header length.
 */
#define	ICMP_MINLEN	8				/* abs minimum */
#define	ICMP_TSLEN	(8 + 3 * sizeof (n_time))	/* timestamp */
#define	ICMP_MASKLEN	12				/* address mask */
#define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8)	/* min */
#define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8)
	/* N.B.: must separately check that ip_hl >= 5 */

/*
 * Definition of type and code field values.
 */
#define	ICMP_ECHOREPLY		0		/* echo reply */
#define	ICMP_UNREACH		3		/* dest unreachable, codes: */
#define		ICMP_UNREACH_NET		0	/* bad net */
#define		ICMP_UNREACH_HOST		1	/* bad host */
#define		ICMP_UNREACH_PROTOCOL		2	/* bad protocol */
#define		ICMP_UNREACH_PORT		3	/* bad port */
#define		ICMP_UNREACH_NEEDFRAG		4	/* IP_DF caused drop */
#define		ICMP_UNREACH_SRCFAIL		5	/* src route failed */
#define		ICMP_UNREACH_NET_UNKNOWN	6	/* unknown net */
#define		ICMP_UNREACH_HOST_UNKNOWN	7	/* unknown host */
#define		ICMP_UNREACH_ISOLATED		8	/* src host isolated */
#define		ICMP_UNREACH_NET_PROHIB		9	/* prohibited access */
#define		ICMP_UNREACH_HOST_PROHIB	10	/* ditto */
#define		ICMP_UNREACH_TOSNET		11	/* bad tos for net */
#define		ICMP_UNREACH_TOSHOST		12	/* bad tos for host */
#define		ICMP_UNREACH_FILTER_PROHIB	13	/* prohibited access */
#define		ICMP_UNREACH_HOST_PRECEDENCE	14	/* pred violationn */
#define		ICMP_UNREACH_PRECEDENCE_CUTOFF	15	/* precedence cutoff */
#define	ICMP_SOURCEQUENCH	4		/* packet lost, slow down */
#define	ICMP_REDIRECT		5		/* shorter route, codes: */
#define		ICMP_REDIRECT_NET	0		/* for network */
#define		ICMP_REDIRECT_HOST	1		/* for host */
#define		ICMP_REDIRECT_TOSNET	2		/* for tos and net */
#define		ICMP_REDIRECT_TOSHOST	3		/* for tos and host */
#define	ICMP_ECHO		8		/* echo service */
#define	ICMP_ROUTERADVERT	9		/* router advertisement */
#define		ICMP_ROUTERADVERT_COMMON	0	/* common traffic */
#define		ICMP_ROUTERADVERT_NOCOMMON	16	/* no common traffic */
#define	ICMP_ROUTERSOLICIT	10		/* router solicitation */
#define	ICMP_TIMXCEED		11		/* time exceeded, code: */
#define		ICMP_TIMXCEED_INTRANS	0		/* ttl==0 in transit */
#define		ICMP_TIMXCEED_REASS	1		/* ttl==0 in reass */
#define	ICMP_PARAMPROB		12		/* ip header bad */
#define		ICMP_PARAMPROB_OPTABSENT	1	/* req. opt. absent */
#define		ICMP_PARAMPROB_BADLENGTH	2	/* Bad Length */
#define	ICMP_TSTAMP		13		/* timestamp request */
#define	ICMP_TSTAMPREPLY	14		/* timestamp reply */
#define	ICMP_IREQ		15		/* information request */
#define	ICMP_IREQREPLY		16		/* information reply */
#define	ICMP_MASKREQ		17		/* address mask request */
#define	ICMP_MASKREPLY		18		/* address mask reply */

#define	ICMP_MAXTYPE		18

#define	ICMP_INFOTYPE(type) \
	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
	(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IP_ICMP_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/* Copyright (c) 1990 Mentat Inc. */

#ifndef	_NETINET_IP_MROUTE_H
#define	_NETINET_IP_MROUTE_H

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Definitions for the kernel part of DVMRP,
 * a Distance-Vector Multicast Routing Protocol.
 * (See RFC-1075.)
 *
 * Written by David Waitzman, BBN Labs, August 1988.
 * Modified by Steve Deering, Stanford, February 1989.
 * Modified by Ajit Thyagarajan, PARC, August 1993.
 * Modified by Ajit Thyagarajan, PARC, August 1994.
 *
 * MROUTING 3.5
 */

/*
 * DVMRP-specific setsockopt commands.
 */

#define	MRT_INIT		100	/* initialize forwarder */
#define	MRT_DONE		101	/* shut down forwarder */
#define	MRT_ADD_VIF		102	/* create virtual interface */
#define	MRT_DEL_VIF		103	/* delete virtual interface */
#define	MRT_ADD_MFC		104	/* insert forwarding cache entry */
#define	MRT_DEL_MFC		105	/* delete forwarding cache entry */
#define	MRT_VERSION		106	/* get kernel version number */
#define	MRT_ASSERT		107	/* enable PIM assert processing */

/*
 * Types and macros for handling bitmaps with one bit per virtual interface.
 */
#define	MAXVIFS			32
typedef uint_t			vifbitmap_t;
typedef ushort_t		vifi_t;	/* type of a vif index */
#define	ALL_VIFS		(vifi_t)-1

#define	VIFM_SET(n, m)		((m) |=  (1 << (n)))
#define	VIFM_CLR(n, m)		((m) &= ~(1 << (n)))
#define	VIFM_ISSET(n, m)	((m) &   (1 << (n)))
#define	VIFM_CLRALL(m)		((m) = 0x00000000)
#define	VIFM_COPY(mfrom, mto)	((mto) = (mfrom))
#define	VIFM_SAME(m1, m2)	((m1) == (m2))


/*
 * Argument structure for MRT_ADD_VIF. Also used for netstat.
 * (MRT_DEL_VIF takes a single vifi_t argument.)
 */
struct vifctl {
    vifi_t	vifc_vifi;	/* the index of the vif to be added   */
	uchar_t	vifc_flags;	/* VIFF_ flags defined below	*/
	uchar_t	vifc_threshold;		/* min ttl required to forward on vif */
	uint_t	vifc_rate_limit;	/* max rate	*/
	struct	in_addr	vifc_lcl_addr;	/* local interface address	*/
	struct	in_addr	vifc_rmt_addr;	/* remote address(tunnels only)	*/
	/*
	 * vifc_pkt_in/out in Solaris, to report out of the kernel.
	 * Not nec. in BSD.
	 */
	uint_t	vifc_pkt_in;		/* # Pkts in on interface	*/
	uint_t	vifc_pkt_out;		/* # Pkts out on interface	*/
};

#define	VIFF_TUNNEL	0x1		/* vif represents a tunnel end-point */
#define	VIFF_SRCRT	0x2		/* tunnel uses IP src routing	*/
#define	VIFF_REGISTER	0x4		/* for RPF check of PIM Register msg */

/*
 * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
 * (mfcc_tos to be added at a future point)
 */
struct mfcctl {
    struct	in_addr	mfcc_origin;	/* ip origin of mcasts	*/
    struct	in_addr	mfcc_mcastgrp; 	/* multicast group associated */
    vifi_t		mfcc_parent;	/* incoming vif	*/
    uint_t		mfcc_pkt_cnt;	/* pkt count for src-grp	*/
    uchar_t		mfcc_ttls[MAXVIFS]; 	/* forwarding ttls on vifs    */
};

/*
 * The kernel's multicast routing statistics.
 */
struct mrtstat {
    uint_t	mrts_mfcfind_lookups;	/* #forwarding cache table lookups */
    uint_t	mrts_mfcfind_misses;    /* # forwarding cache table misses */
    uint_t	mrts_mfc_hits;		/* forwarding pkt mfctable hits	   */
    uint_t	mrts_mfc_misses;	/* forwarding pkt mfctable misses  */
    uint_t	mrts_upcalls;		/* # calls to mrouted		   */
    uint_t	mrts_fwd_in;		/* # packets potentially forwarded */
    uint_t	mrts_fwd_out;		/* # resulting outgoing packets    */
    uint_t	mrts_fwd_drop;		/* # dropped for lack of resources */
    uint_t	mrts_bad_tunnel;	/* malformed tunnel options	   */
    uint_t	mrts_cant_tunnel;	/* no room for tunnel options	   */
    uint_t	mrts_wrong_if;		/* arrived on wrong interface	   */
    uint_t	mrts_upq_ovflw;		/* upcall Q overflow		   */
    uint_t	mrts_cache_cleanups;	/* # entries with no upcalls	   */
    uint_t	mrts_drop_sel;		/* pkts dropped selectively	   */
    uint_t	mrts_q_overflow;	/* pkts dropped - Q overflow	   */
    uint_t	mrts_pkt2large;		/* pkts dropped - size > BKT SIZE  */
    uint_t	mrts_vifctlSize;	/* Size of vifctl		   */
    uint_t	mrts_mfcctlSize;	/* Size of mfcctl		   */
    uint_t 	mrts_pim_badversion;    /* dtgrms dropped - bad version */
    uint_t 	mrts_pim_rcv_badcsum;   /* dtgrms dropped - bad checksum */
    uint_t 	mrts_pim_badregisters;  /* dtgrms dropped - bad register pkts */
    uint_t 	mrts_pim_regforwards;   /* dtgrms to be forwd - register pkts */
    uint_t 	mrts_pim_regsend_drops; /* dtgrms dropped - register send */
    uint_t	mrts_pim_malformed;	/* dtgrms dropped - packet malformed */
    uint_t	mrts_pim_nomemory;	/* dtgrms dropped - no memory to fwd. */
};

/*
 * Argument structure used by mrouted to get src-grp pkt counts
 */
struct sioc_sg_req {
    struct in_addr src;
    struct in_addr grp;
    uint_t pktcnt;
    uint_t bytecnt;
    uint_t wrong_if;
};

/*
 * Argument structure used by mrouted to get vif pkt counts
 */
struct sioc_vif_req {
    vifi_t	vifi;		/* vif number				*/
    uint_t	icount;		/* Input packet count on vif		*/
    uint_t	ocount;		/* Output packet count on vif		*/
    uint_t	ibytes;		/* Input byte count on vif		*/
    uint_t	obytes;		/* Output byte count on vif		*/
};

#ifdef _KERNEL
/*
 * The kernel's virtual-interface structure.
 */
struct vif {
	uchar_t		v_flags;	/* VIFF_ flags defined above	*/
	uchar_t		v_threshold;	/* Min ttl required to forward on vif */
	uint_t		v_rate_limit;	/* Max rate, in kbits/sec	*/
	struct tbf	*v_tbf;		/* Token bkt structure at intf.	*/
	struct in_addr	v_lcl_addr;	/* Local interface address	*/
	struct in_addr	v_rmt_addr;	/* Remote address(tunnels only)	*/
	struct ipif_s 	*v_ipif;	/* Pointer to logical interface	*/
	uint_t		v_pkt_in;	/* # Pkts in on interface	*/
	uint_t		v_pkt_out;	/* # Pkts out on interface	*/
	uint_t		v_bytes_in;	/* # Bytes in on interface	*/
	uint_t		v_bytes_out;	/* # Bytes out on interface	*/
	timeout_id_t	v_timeout_id;	/* Qtimeout return id	*/
	/*
	 * struct route	v_route;	Cached route if this is a tunnel
	 *				Used in bsd for performance
	 */
	uint_t			v_refcnt;
	uchar_t 		v_marks;
	kmutex_t		v_lock;
	ilm_t			*v_ilm;	/* allmulti join */
};

/*
 * vif is not being used. However if refcnt != 0 than its being initalized.
 */
#define	VIF_MARK_NOTINUSE	0x0	/* see comment above */

#define	VIF_MARK_CONDEMNED	0x1	/* delete when refcnt goes to zero. */

#define	VIF_MARK_GOOD		0x2	/* vif is good */

#define	VIF_MARK_INUSE		VIF_MARK_CONDEMNED | VIF_MARK_GOOD

/*
 * The kernel's multicast forwarding cache entry structure
 * (A field for the type of service (mfc_tos) is to be added
 * at a future point)
 */
struct mfc {
    struct in_addr	mfc_origin;	/* ip origin of mcasts	*/
    struct in_addr  	mfc_mcastgrp;	/* multicast group associated */
    vifi_t		mfc_parent;	/* incoming vif	*/
    uchar_t		mfc_ttls[MAXVIFS];	/* forwarding ttls on vifs    */
    uint_t		mfc_pkt_cnt;	/* pkt count for src-grp	*/
    uint_t		mfc_byte_cnt;	/* byte count for src-grp	*/
    uint_t		mfc_wrong_if;	/* wrong if for src-grp	*/
    struct timespec  	mfc_last_assert;	/* last time I sent an assert */
    struct rtdetq	*mfc_rte;	/* pending upcall	*/
    timeout_id_t	mfc_timeout_id;	/* qtimeout return id	*/
    struct mfc		*mfc_next;
    uchar_t 		mfc_marks;
    kmutex_t		mfc_mutex;	/* protects fields and rte list */
};

/*
 * mfc bucket structure.
 */
struct mfcb {
    struct mfc  *mfcb_mfc;	/* first mfc in this bucket */
    kmutex_t	mfcb_lock;
    uint_t	mfcb_refcnt;	/* protected by mfcb_lock */
    uchar_t	mfcb_marks;	/* protected by mfcb_lock */
};

#define	MFCB_MARK_CONDEMNED	0x1

/*
 * Argument structure used for pkt info. while upcall is made
 */
struct rtdetq {
    mblk_t		*mp;		/*  A copy of the packet	*/
    ill_t		*ill;		/*  Interface pkt came in on	*/
    struct rtdetq	*rte_next;
};
#endif

/*
 * Struct used to communicate from kernel to multicast router
 * note the convenient similarity to an IP packet
 */
struct igmpmsg {
    uint_t	    unused1;
    uint_t	    unused2;
    uchar_t	    im_msgtype;			/* what type of message	    */
#define	IGMPMSG_NOCACHE		1
#define	IGMPMSG_WRONGVIF	2
#define	IGMPMSG_WHOLEPKT	3
    uchar_t	    im_mbz;			/* must be zero		    */
    uchar_t	    im_vif;			/* vif rec'd on		    */
    uchar_t	    unused3;
    struct in_addr  im_src, im_dst;
};

#ifdef _KERNEL
#define	MFCTBLSIZ	256
#if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0	  /* from sys:route.h */
#define	MFCHASHMOD(h)	((h) & (MFCTBLSIZ - 1))
#else
#define	MFCHASHMOD(h)	((h) % MFCTBLSIZ)
#endif

#define	MAX_UPQ	4		/* max. no of pkts in upcall Q */

/*
 * Token Bucket filter code
 */
#define	MAX_BKT_SIZE	10000		/* 10K bytes size 		*/
#define	MAXQSIZE	10		/* max # of pkts in queue 	*/
#define	TOKEN_SIZE	8		/* number of bits in token	*/

/*
 * The token bucket filter at each vif
 */
struct tbf {
    timespec_t 		tbf_last_pkt_t; /* arr. time of last pkt 	*/
    uint_t 		tbf_n_tok;	/* no of tokens in bucket 	*/
    uint_t 		tbf_q_len;    	/* length of queue at this vif	*/
    uint_t 		tbf_max_q_len;  /* max queue length		*/
    mblk_t		*tbf_q;		/* Packet queue	*/
    mblk_t		*tbf_t;		/* Tail-insertion pointer	*/
    kmutex_t 		tbf_lock;	/* lock on the tbf		*/
};

#endif /* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IP_MROUTE_H */
/*
 * Copyright (c) 1997-2001 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Overlay for ip header used by other protocols (tcp, udp).
 */

#ifndef	_NETINET_IP_VAR_H
#define	_NETINET_IP_VAR_H

/* ip_var.h 1.11 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#include <sys/isa_defs.h>

#ifdef	__cplusplus
extern "C" {
#endif

struct ipovly {
#ifdef _LP64
	uint32_t	ih_next, ih_prev;
#else
	caddr_t	ih_next, ih_prev;	/* for protocol sequence q's */
#endif
	uchar_t	ih_x1;			/* (unused) */
	uchar_t	ih_pr;			/* protocol */
	short	ih_len;			/* protocol length */
	struct	in_addr ih_src;		/* source internet address */
	struct	in_addr ih_dst;		/* destination internet address */
};

/*
 * Ip reassembly queue structure.  Each fragment
 * being reassembled is attached to one of these structures.
 * They are timed out after ipq_ttl drops to 0, and may also
 * be reclaimed if memory becomes tight.
 */
struct ipq {
	struct	ipq *next, *prev;	/* to other reass headers */
	uchar_t	ipq_ttl;		/* time for reass q to live */
	uchar_t	ipq_p;			/* protocol of this fragment */
	ushort_t ipq_id;		/* sequence id for reassembly */
	struct	ipasfrag *ipq_next, *ipq_prev;
					/* to ip headers of fragments */
	struct	in_addr ipq_src, ipq_dst;
};

/*
 * Ip header, when holding a fragment.
 *
 * Note: ipf_next must be at same offset as ipq_next above
 */
struct	ipasfrag {
#ifdef _BIT_FIELDS_LTOH
	uchar_t	ip_hl:4,
		ip_v:4;
#else
	uchar_t	ip_v:4,
		ip_hl:4;
#endif
	uchar_t	ipf_mff;		/* copied from (ip_off&IP_MF) */
	short	ip_len;
	ushort_t ip_id;
	short	ip_off;
	uchar_t	ip_ttl;
	uchar_t	ip_p;
	ushort_t ip_sum;
	struct	ipasfrag *ipf_next;	/* next fragment */
	struct	ipasfrag *ipf_prev;	/* previous fragment */
};

/*
 * Structure stored in mbuf in inpcb.ip_options
 * and passed to ip_output when ip options are in use.
 * The actual length of the options (including ipopt_dst)
 * is in m_len.
 */
#define	MAX_IPOPTLEN	40

struct ipoption {
	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
};

struct	ipstat {
	long	ips_total;		/* total packets received */
	long	ips_badsum;		/* checksum bad */
	long	ips_tooshort;		/* packet too short */
	long	ips_toosmall;		/* not enough data */
	long	ips_badhlen;		/* ip header length < data size */
	long	ips_badlen;		/* ip length < ip header length */
	long	ips_fragments;		/* fragments received */
	long	ips_fragdropped;	/* frags dropped (dups, out of space) */
	long	ips_fragtimeout;	/* fragments timed out */
	long	ips_forward;		/* packets forwarded */
	long	ips_cantforward;	/* packets rcvd for unreachable dest */
	long	ips_redirectsent;	/* packets forwarded on same net */
};

#ifdef _KERNEL
/* flags passed to ip_output as last parameter */
#define	IP_FORWARDING		0x1		/* most of ip header exists */
#define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
#define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_IP_VAR_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 1999 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 *  Copyright (c) 1996-1999 by the University of Southern California.
 *  All rights reserved.
 *
 *  Permission to use, copy, modify, and distribute this software and
 *  its documentation in source and binary forms for lawful
 *  purposes and without fee is hereby granted, provided
 *  that the above copyright notice appear in all copies and that both
 *  the copyright notice and this permission notice appear in supporting
 *  documentation, and that any documentation, advertising materials,
 *  and other materials related to such distribution and use acknowledge
 *  that the software was developed by the University of Southern
 *  California and/or Information Sciences Institute.
 *  The name of the University of Southern California may not
 *  be used to endorse or promote products derived from this software
 *  without specific prior written permission.
 *
 *  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY REPRESENTATIONS
 *  ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.  THIS SOFTWARE IS
 *  PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
 *  INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
 *  NON-INFRINGEMENT.
 *
 *  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
 *  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT,
 *  TORT, OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH,
 *  THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *  Other copyrights might apply to parts of this software and are so
 *  noted when applicable.
 */

#ifndef _NETINET_PIM_H
#define	_NETINET_PIM_H

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Protocol Independent Multicast (PIM) definitions
 *
 * Written by Ahmed Helmy, USC/SGI, July 1996
 * Modified by George Edmond Eddy (Rusty), ISI, February 1998
 * Modified by Pavlin Ivanov Radoslavov, USC/ISI, May 1998
 *
 * $Id: pim.h,v 1.3 1999/08/31 03:03:08 pavlin Exp $
 */

/*
 * PIM packet format.
 */
typedef struct pim {
#ifdef _BIT_FIELDS_LTOH
	uint8_t		pim_type:4,	/* type of PIM message */
			pim_vers:4;	/* PIM version */
#else
	uint8_t		pim_vers:4,	/* PIM version */
			pim_type:4;	/* type of PIM message */
#endif
	uint8_t		pim_reserved;	/* Reserved */
	uint16_t	pim_cksum;	/* IP-style checksum */
} pim_t;

#define	PIM_VERSION	2
#define	PIM_MINLEN	8		/* The header min. length is 8 */

/* Register message + inner IPheader */
#define	PIM_REG_MINLEN 	(PIM_MINLEN + IP_SIMPLE_HDR_LENGTH)

/*
 * From the PIM protocol spec (RFC 2362), the following PIM message types
 * are defined.  All of these, except PIM_REGISTER, are currently not defined
 * in the USC/ISI distributed <netinet/pim.h> include file.  So they are listed
 * here commented out.
 *
 * #define	PIM_HELLO		0x0
 * #define	PIM_REGISTER		0x1
 * #define	PIM_REGISTER_STOP	0x2
 * #define	PIM_JOIN_PRUNE		0x3
 * #define	PIM_BOOTSTRAP		0x4
 * #define	PIM_ASSERT		0x5
 * #define	PIM_GRAFT		0x6
 * #define	PIM_GRAFT_ACK		0x7
 * #define	PIM_CAND_RP_ADV		0x8
 *
 */
#define	PIM_REGISTER	0x1		/* PIM Register type is 1 */

/*
 * First bit in reg_head (right after PIM header) is the Border bit.
 */
#define	PIM_BORDER_REGISTER	0x80000000

/*
 * Second bit in reg_head (right after PIM header) is the Null-Register bit
 */
#define	PIM_NULL_REGISTER	0x40000000

#ifdef __cplusplus
}
#endif

#endif /* _NETINET_PIM_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_NETINET_SCTP_H
#define	_NETINET_SCTP_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>

/*
 * This file contains the structure defintions and function prototypes
 * described in the IETF SCTP socket API document.
 */

/* SCTP association ID type. */
typedef int	sctp_assoc_t;
typedef int32_t	sctp_assoc32_t;

/*
 * SCTP socket options
 */
#define	SCTP_RTOINFO			1
#define	SCTP_ASSOCINFO			2
#define	SCTP_INITMSG			3
#define	SCTP_NODELAY			4
#define	SCTP_AUTOCLOSE			5
#define	SCTP_SET_PEER_PRIMARY_ADDR	6
#define	SCTP_PRIMARY_ADDR		7
#define	SCTP_ADAPTATION_LAYER		8
#define	SCTP_DISABLE_FRAGMENTS		9
#define	SCTP_PEER_ADDR_PARAMS		10
#define	SCTP_DEFAULT_SEND_PARAM		11
#define	SCTP_EVENTS			12
#define	SCTP_I_WANT_MAPPED_V4_ADDR	13
#define	SCTP_MAXSEG			14
#define	SCTP_STATUS			15
#define	SCTP_GET_PEER_ADDR_INFO		16

/*
 * Private socket options
 */
#define	SCTP_GET_NLADDRS		17
#define	SCTP_GET_LADDRS			18
#define	SCTP_GET_NPADDRS		19
#define	SCTP_GET_PADDRS			20
#define	SCTP_ADD_ADDR			21
#define	SCTP_REM_ADDR			22

/*
 * Additional SCTP socket options. This socket option is used to enable or
 * disable PR-SCTP support prior to establishing an association. By default,
 * PR-SCTP support is disabled.
 */
#define	SCTP_PRSCTP			23

/*
 * SCTP socket option used to read per endpoint association statistics.
 */
#define	SCTP_GET_ASSOC_STATS		24

/*
 * Ancillary data identifiers
 */
#define	SCTP_SNDRCV		0x100
#define	SCTP_INIT		0x101

/*
 * Notification types
 */
#define	SCTP_ASSOC_CHANGE		1
#define	SCTP_PEER_ADDR_CHANGE		2
#define	SCTP_REMOTE_ERROR		3
#define	SCTP_SEND_FAILED		4
#define	SCTP_SHUTDOWN_EVENT		5
#define	SCTP_ADAPTATION_INDICATION	6
#define	SCTP_PARTIAL_DELIVERY_EVENT	7

/*
 * SCTP Ancillary Data Definitions
 */

/*
 * sctp_initmsg structure provides information for initializing new SCTP
 * associations with sendmsg().  The SCTP_INITMSG socket option uses
 * this same data structure.
 */
struct sctp_initmsg {
	uint16_t	sinit_num_ostreams;
	uint16_t	sinit_max_instreams;
	uint16_t	sinit_max_attempts;
	uint16_t	sinit_max_init_timeo;
};

/*
 * sctp_sndrcvinfo structure specifies SCTP options for sendmsg() and
 * describes SCTP header information about a received message through
 * recvmsg().
 */
struct sctp_sndrcvinfo {
	uint16_t	sinfo_stream;
	uint16_t	sinfo_ssn;
	uint16_t	sinfo_flags;
	uint32_t	sinfo_ppid;
	uint32_t	sinfo_context;
	uint32_t	sinfo_timetolive;
	uint32_t	sinfo_tsn;
	uint32_t	sinfo_cumtsn;
	sctp_assoc_t	sinfo_assoc_id;
};

/* sinfo_flags */
#define	MSG_UNORDERED	0x01		/* Unordered data */
#define	MSG_ABORT	0x02		/* Abort the connection */
#define	MSG_EOF		0x04		/* Shutdown the connection */

/*
 * Use destination addr passed as parameter, not the association primary one.
 */
#define	MSG_ADDR_OVER	0x08
/*
 * This flag when set in sinfo_flags is used alongwith sinfo_timetolive to
 * implement the "timed reliability" service discussed in RFC 3758.
 */
#define	MSG_PR_SCTP	0x10
/*
 * SCTP notification definitions
 */

/*
 * To receive any ancillary data or notifications, the application can
 * register it's interest by calling the SCTP_EVENTS setsockopt() with
 * the sctp_event_subscribe structure.
 */
struct sctp_event_subscribe {
	uint8_t	sctp_data_io_event;
	uint8_t sctp_association_event;
	uint8_t sctp_address_event;
	uint8_t sctp_send_failure_event;
	uint8_t sctp_peer_error_event;
	uint8_t sctp_shutdown_event;
	uint8_t sctp_partial_delivery_event;
	uint8_t sctp_adaptation_layer_event;
};

/* Association events used in sctp_assoc_change structure */
#define	SCTP_COMM_UP		0
#define	SCTP_COMM_LOST		1
#define	SCTP_RESTART		2
#define	SCTP_SHUTDOWN_COMP	3
#define	SCTP_CANT_STR_ASSOC	4

/*
 * Association flags. This flags is filled in the sac_flags for a SCTP_COMM_UP
 * event if the association supports PR-SCTP.
 */
#define	SCTP_PRSCTP_CAPABLE	0x01

/*
 * sctp_assoc_change notification informs the socket that an SCTP association
 * has either begun or ended.  The identifier for a new association is
 * provided by this notification.
 */
struct sctp_assoc_change {
	uint16_t	sac_type;
	uint16_t	sac_flags;
	uint32_t	sac_length;
	uint16_t	sac_state;
	uint16_t	sac_error;
	uint16_t	sac_outbound_streams;
	uint16_t	sac_inbound_streams;
	sctp_assoc_t	sac_assoc_id;
	/*
	 * The assoc ID can be followed by the ABORT chunk if available.
	 */
};

/*
 * A remote peer may send an Operational Error message to its peer. This
 * message indicates a variety of error conditions on an association.
 * The entire ERROR chunk as it appears on the wire is included in a
 * SCTP_REMOTE_ERROR event.  Refer to the SCTP specification RFC2960
 * and any extensions for a list of possible error formats.
 */
struct sctp_remote_error {
	uint16_t	sre_type;
	uint16_t	sre_flags;
	uint32_t	sre_length;
	uint16_t	sre_error;
	sctp_assoc_t	sre_assoc_id;
	/*
	 * The assoc ID is followed by the actual error chunk.
	 */
};

/*
 * Note:
 *
 * In order to keep the offsets and size of the structure having a
 * struct sockaddr_storage field the same between a 32-bit application
 * and a 64-bit amd64 kernel, we use a #pragma pack(4) for those
 * structures.
 */
#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack(4)
#endif

/* Address change event state */
#define	SCTP_ADDR_AVAILABLE	0
#define	SCTP_ADDR_UNREACHABLE	1
#define	SCTP_ADDR_REMOVED	2
#define	SCTP_ADDR_ADDED		3
#define	SCTP_ADDR_MADE_PRIM	4

/*
 * When a destination address on a multi-homed peer encounters a change,
 * an interface details event, sctp_paddr_change, is sent to the socket.
 */
struct sctp_paddr_change {
	uint16_t	spc_type;
	uint16_t	spc_flags;
	uint32_t	spc_length;
	struct sockaddr_storage spc_aaddr;
	int		spc_state;
	int		spc_error;
	sctp_assoc_t	spc_assoc_id;
};

#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack()
#endif

/* flags used in sctp_send_failed notification. */
#define	SCTP_DATA_UNSENT	1
#define	SCTP_DATA_SENT		2

/*
 * If SCTP cannot deliver a message it may return the message as a
 * notification using the following structure.
 */
struct sctp_send_failed {
	uint16_t	ssf_type;
	uint16_t	ssf_flags;
	uint32_t	ssf_length;
	uint32_t	ssf_error;
	struct sctp_sndrcvinfo ssf_info;
	sctp_assoc_t	ssf_assoc_id;
	/*
	 * The assoc ID is followed by the failed message.
	 */
};

/*
 * When a peer sends a SHUTDOWN, SCTP delivers the sctp_shutdown_event
 * notification to inform the socket user that it should cease sending data.
 */
struct sctp_shutdown_event {
	uint16_t	sse_type;
	uint16_t	sse_flags;
	uint16_t	sse_length;
	sctp_assoc_t	sse_assoc_id;
};

/*
 * When a peer sends an Adaptation Layer Indication parameter, SCTP
 * delivers the sctp_adaptation_event notification to inform the socket
 * user the peer's requested adaptation layer.
 */
struct sctp_adaptation_event {
	uint16_t	sai_type;
	uint16_t	sai_flags;
	uint32_t	sai_length;
	uint32_t	sai_adaptation_ind;
	sctp_assoc_t	sai_assoc_id;
};

/* Possible values in pdapi_indication for sctp_pdapi_event notification. */
#define	SCTP_PARTIAL_DELIVERY_ABORTED	1

/*
 * When a receiver is engaged in a partial delivery of a message the
 * sctp_pdapi_event notification is used to indicate various events.
 */
struct sctp_pdapi_event {
	uint16_t	pdapi_type;
	uint16_t	pdapi_flags;
	uint32_t	pdapi_length;
	uint32_t	pdapi_indication;
	sctp_assoc_t	pdapi_assoc_id;
};

/*
 * The sctp_notification structure is defined as the union of all
 * notification types defined above.
 */
union sctp_notification {
	struct {
		uint16_t		sn_type; /* Notification type. */
		uint16_t		sn_flags;
		uint32_t		sn_length;
	} sn_header;
	struct sctp_assoc_change	sn_assoc_change;
	struct sctp_paddr_change	sn_paddr_change;
	struct sctp_remote_error	sn_remote_error;
	struct sctp_send_failed		sn_send_failed;
	struct sctp_shutdown_event	sn_shutdown_event;
	struct sctp_adaptation_event	sn_adaptation_event;
	struct sctp_pdapi_event		sn_pdapi_event;
};

/*
 * sctp_opt_info() option definitions
 */

/*
 * The protocol parameters used to initialize and bound retransmission
 * timeout (RTO) are tunable.  See RFC2960 for more information on
 * how these parameters are used in RTO calculation.
 *
 * The sctp_rtoinfo structure is used to access and modify these
 * parameters.
 */
struct sctp_rtoinfo {
	sctp_assoc_t	srto_assoc_id;
	uint32_t	srto_initial;
	uint32_t	srto_max;
	uint32_t	srto_min;
};

/*
 * The sctp_assocparams option is used to both examine and set various
 * association and endpoint parameters.  See RFC2960 for more information
 * on how this parameter is used.  The peer address parameter is ignored
 * for one-to-one style socket.
 */
struct sctp_assocparams {
	sctp_assoc_t	sasoc_assoc_id;
	uint16_t	sasoc_asocmaxrxt;
	uint16_t	sasoc_number_peer_destinations;
	uint32_t	sasoc_peer_rwnd;
	uint32_t	sasoc_local_rwnd;
	uint32_t	sasoc_cookie_life;
};

#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack(4)
#endif

/* sctp_paddrinfo reachability state. */
#define	SCTP_INACTIVE	1
#define	SCTP_ACTIVE	2

/*
 * Applications can retrieve information about a specific peer address
 * of an association, including its reachability state, congestion
 * window, and retransmission timer values.  This information is
 * read-only. The sctp_paddrinfo structure is used to access this
 * information:
 */
struct sctp_paddrinfo {
	sctp_assoc_t	spinfo_assoc_id;
	struct sockaddr_storage spinfo_address;
	int32_t		spinfo_state;
	uint32_t	spinfo_cwnd;
	uint32_t	spinfo_srtt;
	uint32_t	spinfo_rto;
	uint32_t	spinfo_mtu;
};

/*
 * Applications can enable or disable heartbeats for any peer address of
 * an association, modify an address's heartbeat interval, force a
 * heartbeat to be sent immediately, and adjust the address's maximum
 * number of retransmissions sent before an address is considered
 * unreachable.  The sctp_paddrparams structure is used to access and modify
 * an address' parameters.
 */
struct sctp_paddrparams {
	sctp_assoc_t		spp_assoc_id;
	struct sockaddr_storage	spp_address;
	uint32_t		spp_hbinterval;
	uint16_t		spp_pathmaxrxt;
};

/*
 * A socket user can request that the peer mark the enclosed address as the
 * association's primary.  The enclosed address must be one of the
 * association's locally bound addresses. The sctp_setpeerprim structure is
 * used to make such request.
 */
struct sctp_setpeerprim {
	sctp_assoc_t		sspp_assoc_id;
	struct sockaddr_storage	sspp_addr;
};

/*
 * A socket user can request that the local SCTP stack use the enclosed peer
 * address as the association primary.  The enclosed address must be one of
 * the association peer's addresses.  The sctp_setprim structure is used to
 * make such request.
 */
struct sctp_setprim {
	sctp_assoc_t		ssp_assoc_id;
	struct sockaddr_storage	ssp_addr;
};

#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack()
#endif

/* SCTP association states */
#define	SCTPS_IDLE		-5	/* idle (opened, but not bound) */
#define	SCTPS_BOUND		-4	/* bound, ready to connect or accept */
#define	SCTPS_LISTEN		-3	/* listening for connection */
#define	SCTPS_COOKIE_WAIT	-2
#define	SCTPS_COOKIE_ECHOED	-1
/* states < SCTPS_ESTABLISHED are those where connections not established */
#define	SCTPS_ESTABLISHED	0	/* established */
#define	SCTPS_SHUTDOWN_PENDING	1
#define	SCTPS_SHUTDOWN_SENT	2
#define	SCTPS_SHUTDOWN_RECEIVED	3
#define	SCTPS_SHUTDOWN_ACK_SENT	4

/*
 * Applications can retrieve current status information about an
 * association, including association state, peer receiver window size,
 * number of unacked data chunks, and number of data chunks pending
 * receipt.  This information is read-only.  The sctp_status structure is
 * used to access this information:
 */
struct sctp_status {
	sctp_assoc_t		sstat_assoc_id;
	int32_t			sstat_state;
	uint32_t		sstat_rwnd;
	uint16_t		sstat_unackdata;
	uint16_t		sstat_penddata;
	uint16_t		sstat_instrms;
	uint16_t		sstat_outstrms;
	uint32_t		sstat_fragmentation_point;
	struct sctp_paddrinfo	sstat_primary;
};

/* Possible values for sstat_state */
#define	SCTP_CLOSED		SCTPS_IDLE
#define	SCTP_BOUND		SCTPS_BOUND
#define	SCTP_LISTEN		SCTPS_LISTEN
#define	SCTP_COOKIE_WAIT	SCTPS_COOKIE_WAIT
#define	SCTP_COOKIE_ECHOED	SCTPS_COOKIE_ECHOED
#define	SCTP_ESTABLISHED	SCTPS_ESTABLISHED
#define	SCTP_SHUTDOWN_PENDING	SCTPS_SHUTDOWN_PENDING
#define	SCTP_SHUTDOWN_SENT	SCTPS_SHUTDOWN_SENT
#define	SCTP_SHUTDOWN_RECEIVED	SCTPS_SHUTDOWN_RECEIVED
#define	SCTP_SHUTDOWN_ACK_SENT	SCTPS_SHUTDOWN_ACK_SENT

/*
 * A socket user can request that the local endpoint set the specified
 * Adaptation Layer Indication parameter for all future INIT and INIT-ACK
 * exchanges.  The sctp_setadaptation structure is used to make such request.
 */
struct sctp_setadaptation {
	uint32_t   ssb_adaptation_ind;
};

/*
 * A socket user request reads local per endpoint association stats.
 * All stats are counts except sas_maxrto, which is the max value
 * since the last user request for stats on this endpoint.
 */
typedef struct sctp_assoc_stats {
	uint64_t	sas_rtxchunks; /* Retransmitted Chunks */
	uint64_t	sas_gapcnt; /* Gap Acknowledgements Received */
	uint64_t	sas_maxrto; /* Maximum Observed RTO this period */
	uint64_t	sas_outseqtsns; /* TSN received > next expected */
	uint64_t	sas_osacks; /* SACKs sent */
	uint64_t	sas_isacks; /* SACKs received */
	uint64_t	sas_octrlchunks; /* Control chunks sent - no dups */
	uint64_t	sas_ictrlchunks; /* Control chunks received - no dups */
	uint64_t	sas_oodchunks; /* Ordered data chunks sent */
	uint64_t	sas_iodchunks; /* Ordered data chunks received */
	uint64_t	sas_ouodchunks; /* Unordered data chunks sent */
	uint64_t	sas_iuodchunks; /* Unordered data chunks received */
	uint64_t	sas_idupchunks; /* Dups received (ordered+unordered) */
} sctp_assoc_stats_t;

/*
 * Private ioctl option structure
 */
struct sctpopt {
	sctp_assoc_t	sopt_aid;
	int		sopt_name;
	uint_t		sopt_len;
	caddr_t		sopt_val;
};

#if defined(_SYSCALL32)
struct sctpopt32 {
	sctp_assoc32_t	sopt_aid;
	int32_t		sopt_name;
	uint32_t	sopt_len;
	caddr32_t	sopt_val;
};
#endif	/* _SYSCALL32 */

/* Forward Cumulative TSN chunk entry. */
typedef struct ftsn_entry_s {
	uint16_t	ftsn_sid;
	uint16_t	ftsn_ssn;
} ftsn_entry_t;

/*
 * New socket functions for SCTP
 */

/* sctp_bindx() operations. */
#define	SCTP_BINDX_ADD_ADDR	1
#define	SCTP_BINDX_REM_ADDR	2

#if !defined(_KERNEL) || defined(_BOOT)
#ifdef	__STDC__
extern int sctp_bindx(int, void *, int, int);
extern void sctp_freeladdrs(void *);
extern void sctp_freepaddrs(void *);
extern int sctp_getladdrs(int, sctp_assoc_t, void **);
extern int sctp_getpaddrs(int, sctp_assoc_t, void **);
extern int sctp_opt_info(int, sctp_assoc_t, int, void *, socklen_t *);
extern int sctp_peeloff(int, sctp_assoc_t);
extern ssize_t sctp_recvmsg(int, void *, size_t, struct sockaddr *,
    socklen_t *, struct sctp_sndrcvinfo *, int *msg_flags);
extern ssize_t sctp_send(int, const void *, size_t,
    const struct sctp_sndrcvinfo *, int);
extern ssize_t sctp_sendmsg(int, const void *, size_t, const struct sockaddr *,
    socklen_t, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t);
#else	/* __STDC__ */
extern int sctp_bindx();
extern void sctp_freeladdrs();
extern void sctp_freepaddrs();
extern int sctp_getladdrs();
extern int sctp_getpaddrs();
extern int sctp_opt_info();
extern int sctp_peeloff();
extern ssize_t sctp_recvmsg();
extern ssize_t sctp_send();
extern ssize_t sctp_sendmsg();
#endif	/* __STDC__ */
#endif	/* !defined(_KERNEL) || defined(_BOOT) */


/*
 * SCTP protocol related elements.
 */

/* All SCTP chunks and parameters are 32-bit aligned */
#define	SCTP_ALIGN	4

/*
 * SCTP association optional parameter handling. The top two bits
 * of the parameter type define how this and further parameters in
 * the received chunk should be handled.
 */
#define	SCTP_UNREC_PARAM_MASK	0xc000
/* Continue processing parameters after an unrecognized optional param? */
#define	SCTP_CONT_PROC_PARAMS	0x8000
/* Report this unreconized optional parameter or silently ignore it? */
#define	SCTP_REPORT_THIS_PARAM	0x4000

/*
 * Data chunk bit manipulations
 */
#define	SCTP_DATA_EBIT	0x01
#define	SCTP_TBIT	0x01
#define	SCTP_DATA_BBIT	0x02
#define	SCTP_DATA_UBIT	0x04

#define	SCTP_DATA_GET_BBIT(sdc)	((sdc)->sdh_flags & SCTP_DATA_BBIT)
#define	SCTP_GET_TBIT(cp)	((cp)->sch_flags & SCTP_TBIT)
#define	SCTP_DATA_GET_EBIT(sdc)	((sdc)->sdh_flags & SCTP_DATA_EBIT)
#define	SCTP_DATA_GET_UBIT(sdc)	((sdc)->sdh_flags & SCTP_DATA_UBIT)

#define	SCTP_DATA_SET_BBIT(sdc)	((sdc)->sdh_flags |= SCTP_DATA_BBIT)
#define	SCTP_SET_TBIT(cp)	((cp)->sch_flags |= SCTP_TBIT)
#define	SCTP_DATA_SET_EBIT(sdc)	((sdc)->sdh_flags |= SCTP_DATA_EBIT)
#define	SCTP_DATA_SET_UBIT(sdc)	((sdc)->sdh_flags |=  SCTP_DATA_UBIT)

/* SCTP common header */
typedef struct sctp_hdr {
	uint16_t	sh_sport;
	uint16_t	sh_dport;
	uint32_t	sh_verf;
	uint32_t	sh_chksum;
} sctp_hdr_t;

/* Chunk IDs */
typedef enum {
	CHUNK_DATA,
	CHUNK_INIT,
	CHUNK_INIT_ACK,
	CHUNK_SACK,
	CHUNK_HEARTBEAT,
	CHUNK_HEARTBEAT_ACK,
	CHUNK_ABORT,
	CHUNK_SHUTDOWN,
	CHUNK_SHUTDOWN_ACK,
	CHUNK_ERROR,
	CHUNK_COOKIE,
	CHUNK_COOKIE_ACK,
	CHUNK_ECNE,
	CHUNK_CWR,
	CHUNK_SHUTDOWN_COMPLETE,
	CHUNK_ASCONF_ACK = 128,
	CHUNK_FORWARD_TSN = 192,
	CHUNK_ASCONF = 193
} sctp_chunk_id_t;

/* Common chunk header */
typedef struct sctp_chunk_hdr {
	uint8_t		sch_id;
	uint8_t		sch_flags;
	uint16_t	sch_len;
} sctp_chunk_hdr_t;

/* INIT chunk data definition */
typedef struct sctp_init_chunk {
	uint32_t	sic_inittag;
	uint32_t	sic_a_rwnd;
	uint16_t	sic_outstr;
	uint16_t	sic_instr;
	uint32_t	sic_inittsn;
} sctp_init_chunk_t;

/* SCTP DATA chunk */
typedef struct sctp_data_chunk {
	uint32_t	sdc_tsn;
	uint16_t	sdc_sid;
	uint16_t	sdc_ssn;
	uint32_t	sdc_payload_id;
} sctp_data_chunk_t;

/* sctp_data_hdr includes the SCTP chunk hdr and the DATA chunk */
typedef struct sctp_data_hdr {
	sctp_chunk_hdr_t	sdh_chdr;
	sctp_data_chunk_t	sdh_data;
#define	sdh_id		sdh_chdr.sch_id
#define	sdh_flags	sdh_chdr.sch_flags
#define	sdh_len		sdh_chdr.sch_len
#define	sdh_tsn		sdh_data.sdc_tsn
#define	sdh_sid		sdh_data.sdc_sid
#define	sdh_ssn		sdh_data.sdc_ssn
#define	sdh_payload_id	sdh_data.sdc_payload_id
} sctp_data_hdr_t;

typedef struct sctp_sack_chunk {
	uint32_t	ssc_cumtsn;
	uint32_t	ssc_a_rwnd;
	uint16_t	ssc_numfrags;
	uint16_t	ssc_numdups;
} sctp_sack_chunk_t;

typedef struct sctp_sack_frag {
	uint16_t	ssf_start;
	uint16_t	ssf_end;
} sctp_sack_frag_t;

/* Parameter types */
#define	PARM_UNKNOWN		0
#define	PARM_HBINFO		1
#define	PARM_ADDR4		5
#define	PARM_ADDR6		6
#define	PARM_COOKIE		7
#define	PARM_UNRECOGNIZED	8
#define	PARM_COOKIE_PRESERVE	9
#define	PARM_ADDR_HOST_NAME	11
#define	PARM_SUPP_ADDRS		12
#define	PARM_ECN		0x8000
#define	PARM_ECN_CAPABLE	PARM_ECN
#define	PARM_FORWARD_TSN	0xc000
#define	PARM_ADD_IP		0xc001
#define	PARM_DEL_IP		0xc002
#define	PARM_ERROR_IND		0xc003
#define	PARM_ASCONF_ERROR	PARM_ERROR_IND
#define	PARM_SET_PRIMARY	0xc004
#define	PARM_PRIMARY_ADDR	PARM_SET_PRIMARY
#define	PARM_SUCCESS		0xc005
#define	PARM_ASCONF_SUCCESS	PARM_SUCCESS
#define	PARM_ADAPT_LAYER_IND	0xc006


/* Lengths from SCTP spec */
#define	PARM_ADDR4_LEN		8
#define	PARM_ADDR6_LEN		20

/* Parameter header */
typedef struct sctp_parm_hdr {
	uint16_t	sph_type;
	uint16_t	sph_len;
} sctp_parm_hdr_t;

/*
 * The following extend sctp_parm_hdr_t
 * with cause-specfic content used to fill
 * CAUSE blocks in ABORT or ERROR chunks.
 * The overall size of the CAUSE block will
 * be sizeof (sctp_parm_hdr_t) plus the size
 * of the extended cause structure,
 */

/*
 * Invalid stream-identifier extended cause.
 * SCTP_ERR_BAD_SID
 */
typedef struct sctp_bsc {
	uint16_t	bsc_sid;
	uint16_t	bsc_pad; /* RESV = 0 */
} sctp_bsc_t;

/*
 * Missing parameter extended cause, currently
 * only one missing parameter is supported.
 * SCTP_ERR_MISSING_PARM
 */
typedef struct sctp_mpc {
	uint32_t	mpc_num;
	uint16_t	mpc_param;
	uint16_t	mpc_pad;
} sctp_mpc_t;

/* Error causes */
#define	SCTP_ERR_UNKNOWN		0
#define	SCTP_ERR_BAD_SID		1
#define	SCTP_ERR_MISSING_PARM		2
#define	SCTP_ERR_STALE_COOKIE		3
#define	SCTP_ERR_NO_RESOURCES		4
#define	SCTP_ERR_BAD_ADDR		5
#define	SCTP_ERR_UNREC_CHUNK		6
#define	SCTP_ERR_BAD_MANDPARM		7
#define	SCTP_ERR_UNREC_PARM		8
#define	SCTP_ERR_NO_USR_DATA		9
#define	SCTP_ERR_COOKIE_SHUT		10
#define	SCTP_ERR_RESTART_NEW_ADDRS	11
#define	SCTP_ERR_USER_ABORT		12
#define	SCTP_ERR_DELETE_LASTADDR	256
#define	SCTP_ERR_RESOURCE_SHORTAGE	257
#define	SCTP_ERR_DELETE_SRCADDR		258
#define	SCTP_ERR_AUTH_ERR		260

/*
 * Extensions
 */

/* Extended Chunk Types */
#define	CHUNK_ASCONF		0xc1
#define	CHUNK_ASCONF_ACK	0x80

/* Extension Error Causes */
#define	SCTP_ERR_DEL_LAST_ADDR	0x0100
#define	SCTP_ERR_RES_SHORTAGE	0x0101
#define	SCTP_ERR_DEL_SRC_ADDR	0x0102
#define	SCTP_ERR_ILLEGAL_ACK	0x0103
#define	SCTP_ERR_UNAUTHORIZED	0x0104

typedef struct sctp_addip4 {
	sctp_parm_hdr_t		sad4_addip_ph;
	uint32_t		asconf_req_cid;
	sctp_parm_hdr_t		sad4_addr4_ph;
	ipaddr_t		sad4_addr;
} sctp_addip4_t;

typedef struct sctp_addip6 {
	sctp_parm_hdr_t		sad6_addip_ph;
	uint32_t		asconf_req_cid;
	sctp_parm_hdr_t		sad6_addr6_ph;
	in6_addr_t		sad6_addr;
} sctp_addip6_t;

#ifdef __cplusplus
}
#endif

#endif	/* _NETINET_SCTP_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
 * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
 * Copyright 2024 Oxide Computer Company
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef	_NETINET_TCP_H
#define	_NETINET_TCP_H

/* tcp.h 1.11 88/08/19 SMI; from UCB 7.2 10/28/86	*/


#include <sys/isa_defs.h>
#include <sys/inttypes.h>

#ifdef	__cplusplus
extern "C" {
#endif

typedef	uint32_t	tcp_seq;
/*
 * TCP header.
 * Per RFC 793, September, 1981.
 */
struct tcphdr {
	uint16_t	th_sport;	/* source port */
	uint16_t	th_dport;	/* destination port */
	tcp_seq		th_seq;		/* sequence number */
	tcp_seq		th_ack;		/* acknowledgement number */
#ifdef _BIT_FIELDS_LTOH
	uint_t	th_x2:4,		/* (unused) */
		th_off:4;		/* data offset */
#else
	uint_t	th_off:4,		/* data offset */
		th_x2:4;		/* (unused) */
#endif
	uchar_t	th_flags;
#define	TH_FIN	0x01
#define	TH_SYN	0x02
#define	TH_RST	0x04
#define	TH_PUSH	0x08
#define	TH_ACK	0x10
#define	TH_URG	0x20
#define	TH_ECE	0x40
#define	TH_CWR	0x80
	uint16_t	th_win;		/* window */
	uint16_t	th_sum;		/* checksum */
	uint16_t	th_urp;		/* urgent pointer */
};

#define	TCPOPT_EOL	0
#define	TCPOPT_NOP	1
#define	TCPOPT_MAXSEG	2
#define	TCPOPT_WSCALE	3
#define	TCPOPT_SACK_PERMITTED	4
#define	TCPOPT_SACK	5
#define	TCPOPT_TSTAMP	8
#define	TCPOPT_MD5	19	/* RFC 2385 */

/*
 * Default maximum segment size for TCP.
 * With an IP MTU of 576, this is 536.
 */
#define	TCP_MSS	536

/*
 * Options for use with [gs]etsockopt at the TCP level.
 *
 * Note: Some of the TCP_ namespace has conflict with and
 * and is exposed through <xti.h>. (It also requires exposing
 * options not implemented). The options with potential
 * for conflicts use #ifndef guards.
 */
#ifndef TCP_NODELAY
#define	TCP_NODELAY	0x01	/* don't delay send to coalesce packets */
#endif

#ifndef TCP_MAXSEG
#define	TCP_MAXSEG	0x02	/* set maximum segment size */
#endif

#ifndef TCP_KEEPALIVE
#define	TCP_KEEPALIVE	0x8	/* set keepalive timer */
#endif


#define	TCP_NOTIFY_THRESHOLD		0x10
#define	TCP_ABORT_THRESHOLD		0x11
#define	TCP_CONN_NOTIFY_THRESHOLD	0x12
#define	TCP_CONN_ABORT_THRESHOLD	0x13
#define	TCP_RECVDSTADDR			0x14
#define	TCP_INIT_CWND			0x15
#define	TCP_KEEPALIVE_THRESHOLD		0x16
#define	TCP_KEEPALIVE_ABORT_THRESHOLD	0x17
#define	TCP_CORK			0x18
#define	TCP_RTO_INITIAL			0x19
#define	TCP_RTO_MIN			0x1A
#define	TCP_RTO_MAX			0x1B
#define	TCP_LINGER2			0x1C

/* gap for expansion of ``standard'' options */
#define	TCP_ANONPRIVBIND		0x20	/* for internal use only  */
#define	TCP_EXCLBIND			0x21	/* for internal use only  */
#define	TCP_KEEPIDLE			0x22
#define	TCP_KEEPCNT			0x23
#define	TCP_KEEPINTVL			0x24
#define	TCP_CONGESTION			0x25
#define	TCP_QUICKACK			0x26	/* enable/disable quick acks */
#define	TCP_MD5SIG			0x27

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCP_H */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef	_NETINET_TCP_DEBUG_H
#define	_NETINET_TCP_DEBUG_H

/* tcp_debug.h 1.8 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#ifdef	__cplusplus
extern "C" {
#endif

struct	tcp_debug {
	n_time	td_time;
	short	td_act;
	short	td_ostate;
	caddr_t	td_tcb;
	struct	tcpiphdr td_ti;
	short	td_req;
	struct	tcpcb td_cb;
};

#define	TA_INPUT 	0
#define	TA_OUTPUT	1
#define	TA_USER		2
#define	TA_RESPOND	3
#define	TA_DROP		4

#ifdef TANAMES
char	*tanames[] =
	{ "input", "output", "user", "respond", "drop" };
#endif

#define	TCP_NDEBUG 100

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCP_DEBUG_H */
/*
 * Copyright (c) 1997-1998 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * TCP FSM state definitions.
 * Per RFC793, September, 1981.
 */

#ifndef	_NETINET_TCP_FSM_H
#define	_NETINET_TCP_FSM_H

/* tcp_fsm.h 1.7 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#ifdef	__cplusplus
extern "C" {
#endif

#define	TCP_NSTATES	11

#define	TCPS_CLOSED		0	/* closed */
#define	TCPS_LISTEN		1	/* listening for connection */
#define	TCPS_SYN_SENT		2	/* active, have sent syn */
#define	TCPS_SYN_RECEIVED	3	/* have send and received syn */
/* states < TCPS_ESTABLISHED are those where connections not established */
#define	TCPS_ESTABLISHED	4	/* established */
#define	TCPS_CLOSE_WAIT		5	/* rcvd fin, waiting for close */
/* states > TCPS_CLOSE_WAIT are those where user has closed */
#define	TCPS_FIN_WAIT_1		6	/* have closed, sent fin */
#define	TCPS_CLOSING		7	/* closed xchd FIN; await FIN ACK */
#define	TCPS_LAST_ACK		8	/* had fin and close; await FIN ACK */
/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
#define	TCPS_FIN_WAIT_2		9	/* have closed, fin is acked */
#define	TCPS_TIME_WAIT		10	/* in 2*msl quiet wait after close */

#define	TCPS_HAVERCVDSYN(s)	((s) >= TCPS_SYN_RECEIVED)
#define	TCPS_HAVERCVDFIN(s)	((s) >= TCPS_TIME_WAIT)

#ifdef	TCPOUTFLAGS
/*
 * Flags used when sending segments in tcp_output.
 * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally
 * determined by state, with the proviso that TH_FIN is sent only
 * if all data queued for output is included in the segment.
 */
uchar_t	tcp_outflags[TCP_NSTATES] = {
    TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
    TH_ACK, TH_ACK,
    TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK,
};
#endif

#ifdef KPROF
int	tcp_acounts[TCP_NSTATES][PRU_NREQ];
#endif

#ifdef	TCPSTATES
char *tcpstates[] = {
	"CLOSED",	"LISTEN",	"SYN_SENT",	"SYN_RCVD",
	"ESTABLISHED",	"CLOSE_WAIT",	"FIN_WAIT_1",	"CLOSING",
	"LAST_ACK",	"FIN_WAIT_2",	"TIME_WAIT",
};
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCP_FSM_H */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef	_NETINET_TCP_SEQ_H
#define	_NETINET_TCP_SEQ_H

/* tcp_seq.h 1.7 88/08/19 SMI; from UCB 7.1 6/5/85	*/

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * TCP sequence numbers are 32 bit integers operated
 * on with modular arithmetic.  These macros can be
 * used to compare such integers.
 */
#define	SEQ_LT(a, b)	((int32_t)((a)-(b)) < 0)
#define	SEQ_LEQ(a, b)	((int32_t)((a)-(b)) <= 0)
#define	SEQ_GT(a, b)	((int32_t)((a)-(b)) > 0)
#define	SEQ_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)

/*
 * Macros to initialize tcp sequence numbers for
 * send and receive from initial send and receive
 * sequence numbers.
 */
#define	tcp_rcvseqinit(tp) \
	(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1

#define	tcp_sendseqinit(tp) \
	(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
	    (tp)->iss

#define	TCP_ISSINCR	(125*1024)	/* increment for tcp_iss each second */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCP_SEQ_H */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.
 * Copyright (c) 2016 by Delphix. All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the University of California, Berkeley.  The name of the
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 */

/*
 * Definitions of the TCP timers.  These timers are counted
 * down PR_SLOWHZ times a second.
 */

#ifndef	_NETINET_TCP_TIMER_H
#define	_NETINET_TCP_TIMER_H

/* tcp_timer.h 1.13 89/06/16 SMI; from UCB 7.6 6/29/88 */

#ifdef	__cplusplus
extern "C" {
#endif

#define	TCPT_NTIMERS	4

#define	TCPT_REXMT	0		/* retransmit */
#define	TCPT_PERSIST	1		/* retransmit persistance */
#define	TCPT_KEEP	2		/* keep alive */
#define	TCPT_2MSL	3		/* 2*msl quiet time timer */

/*
 * The TCPT_REXMT timer is used to force retransmissions.
 * The TCP has the TCPT_REXMT timer set whenever segments
 * have been sent for which ACKs are expected but not yet
 * received.  If an ACK is received which advances tp->snd_una,
 * then the retransmit timer is cleared (if there are no more
 * outstanding segments) or reset to the base value (if there
 * are more ACKs expected).  Whenever the retransmit timer goes off,
 * we retransmit one unacknowledged segment, and do a backoff
 * on the retransmit timer.
 *
 * The TCPT_PERSIST timer is used to keep window size information
 * flowing even if the window goes shut.  If all previous transmissions
 * have been acknowledged (so that there are no retransmissions in progress),
 * and the window is too small to bother sending anything, then we start
 * the TCPT_PERSIST timer.  When it expires, if the window is nonzero,
 * we go to transmit state.  Otherwise, at intervals send a single byte
 * into the peer's window to force it to update our window information.
 * We do this at most as often as TCPT_PERSMIN time intervals,
 * but no more frequently than the current estimate of round-trip
 * packet time.  The TCPT_PERSIST timer is cleared whenever we receive
 * a window update from the peer.
 *
 * The TCPT_KEEP timer is used to keep connections alive.  If a
 * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
 * but not yet established, then we drop the connection.  Once the connection
 * is established, if the connection is idle for TCPTV_KEEP_IDLE time
 * (and keepalives have been enabled on the socket), we begin to probe
 * the connection.  We force the peer to send us a segment by sending:
 *	<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
 * This segment is (deliberately) outside the window, and should elicit
 * an ack segment in response from the peer.  If, despite the TCPT_KEEP
 * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
 * amount of time probing, then we drop the connection.
 */

#define	TCP_TTL		60		/* default time to live for TCP segs */
/*
 * Time constants.
 */
#define	TCPTV_MSL	(30*PR_SLOWHZ)		/* max seg lifetime (hah!) */
#define	TCPTV_SRTTBASE	0			/* base roundtrip time; */
						/* if 0, no idea yet */
#define	TCPTV_SRTTDFLT	(3*PR_SLOWHZ)		/* assumed RTT if no info */

#define	TCPTV_PERSMIN	(5*PR_SLOWHZ)		/* retransmit persistance */
#define	TCPTV_PERSMAX	(60*PR_SLOWHZ)		/* maximum persist interval */

#define	TCPTV_KEEP_INIT	(75*PR_SLOWHZ)		/* initial connect keep alive */
#define	TCPTV_KEEP_IDLE	(120*60*PR_SLOWHZ)	/* dflt time before probing */
#define	TCPTV_KEEPINTVL	(75*PR_SLOWHZ)		/* default probe interval */
#define	TCPTV_KEEPCNT	8			/* max probes before drop */

#define	TCPTV_MIN	(1*PR_SLOWHZ)		/* minimum allowable value */
#define	TCPTV_REXMTMAX	(64*PR_SLOWHZ)		/* max allowable REXMT value */

#define	TCP_LINGERTIME	120			/* linger at most 2 minutes */

#define	TCP_MAXRXTSHIFT	12			/* maximum retransmits */

#ifdef	TCPTIMERS
char *tcptimers[] =
	{ "REXMT", "PERSIST", "KEEP", "2MSL" };
#endif

/*
 * Force a time value to be in a certain range.
 */
#define	TCPT_RANGESET(tv, value, tvmin, tvmax) { \
	(tv) = (value); \
	if ((tv) < (tvmin)) \
		(tv) = (tvmin); \
	else if ((tv) > (tvmax)) \
		(tv) = (tvmax); \
}

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCP_TIMER_H */
/*
 * Copyright (c) 1997-1998 by Sun Microsystems, Inc.
 * All rights reserved.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Kernel variables for tcp.
 */

#ifndef	_NETINET_TCP_VAR_H
#define	_NETINET_TCP_VAR_H

/* tcp_var.h 1.11 88/08/19 SMI; from UCB 7.3 6/30/87	*/

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Tcp control block, one per tcp; fields:
 */
struct tcpcb {
	struct	tcpiphdr *seg_next;	/* sequencing queue */
	struct	tcpiphdr *seg_prev;
	short	t_state;		/* state of this connection */
	short	t_timer[TCPT_NTIMERS];	/* tcp timers */
	short	t_rxtshift;		/* log(2) of rexmt exp. backoff */
	short	t_rxtcur;		/* current retransmit value */
	short	t_dupacks;		/* consecutive dup acks recd */
	ushort_t t_maxseg;		/* maximum segment size */
	char	t_force;		/* 1 if forcing out a byte */
	uchar_t	t_flags;
#define	TF_ACKNOW	0x01		/* ack peer immediately */
#define	TF_DELACK	0x02		/* ack, but try to delay it */
#define	TF_NODELAY	0x04		/* don't delay packets to coalesce */
#define	TF_NOOPT	0x08		/* don't use tcp options */
#define	TF_SENTFIN	0x10		/* have sent FIN */
	struct	tcpiphdr *t_template;	/* skeletal packet for transmit */
	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
/*
 * The following fields are used as in the protocol specification.
 * See RFC783, Dec. 1981, page 21.
 */
/* send sequence variables */
	tcp_seq	snd_una;		/* send unacknowledged */
	tcp_seq	snd_nxt;		/* send next */
	tcp_seq	snd_up;			/* send urgent pointer */
	tcp_seq	snd_wl1;		/* window update seg seq number */
	tcp_seq	snd_wl2;		/* window update seg ack number */
	tcp_seq	iss;			/* initial send sequence number */
	ushort_t snd_wnd;		/* send window */
/* receive sequence variables */
	ushort_t rcv_wnd;		/* receive window */
	tcp_seq	rcv_nxt;		/* receive next */
	tcp_seq	rcv_up;			/* receive urgent pointer */
	tcp_seq	irs;			/* initial receive sequence number */
/*
 * Additional variables for this implementation.
 */
/* receive variables */
	tcp_seq	rcv_adv;		/* advertised window */
/* retransmit variables */
	tcp_seq	snd_max;		/* highest sequence number sent */
					/* used to recognize retransmits */

/* congestion control (for slow start, source quench, retransmit after loss) */
	ushort_t snd_cwnd;		/* congestion-controlled window */
	ushort_t snd_ssthresh;		/* snd_cwnd size threshhold for */
					/* for slow start exponential to */
/*
 * transmit timing stuff.
 * srtt and rttvar are stored as fixed point; for convenience in smoothing,
 * srtt has 3 bits to the right of the binary point, rttvar has 2.
 * "Variance" is actually smoothed difference.
 */
	short	t_idle;			/* inactivity time */
	short	t_rtt;			/* round trip time */
	tcp_seq	t_rtseq;		/* sequence number being timed */
	short	t_srtt;			/* smoothed round-trip time */
	short	t_rttvar;		/* variance in round-trip time */
	ushort_t max_rcvd;		/* most peer has sent into window */
	ushort_t max_sndwnd;		/* largest window peer has offered */
/* out-of-band data */
	char	t_oobflags;		/* have some */
	char	t_iobc;			/* input character */
#define	TCPOOB_HAVEDATA	0x01
#define	TCPOOB_HADDATA	0x02
};

#define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
#define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))

/*
 * TCP statistics.
 * Many of these should be kept per connection,
 * but that's inconvenient at the moment.
 */
struct	tcpstat {
	uint_t	tcps_connattempt;	/* connections initiated */
	uint_t	tcps_accepts;		/* connections accepted */
	uint_t	tcps_connects;		/* connections established */
	uint_t	tcps_drops;		/* connections dropped */
	uint_t	tcps_conndrops;		/* embryonic connections dropped */
	uint_t	tcps_closed;		/* conn. closed (includes drops) */
	uint_t	tcps_segstimed;		/* segs where we tried to get rtt */
	uint_t	tcps_rttupdated;	/* times we succeeded */
	uint_t	tcps_delack;		/* delayed acks sent */
	uint_t	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
	uint_t	tcps_rexmttimeo;	/* retransmit timeouts */
	uint_t	tcps_persisttimeo;	/* persist timeouts */
	uint_t	tcps_keeptimeo;		/* keepalive timeouts */
	uint_t	tcps_keepprobe;		/* keepalive probes sent */
	uint_t	tcps_keepdrops;		/* connections dropped in keepalive */

	uint_t	tcps_sndtotal;		/* total packets sent */
	uint_t	tcps_sndpack;		/* data packets sent */
	uint_t	tcps_sndbyte;		/* data bytes sent */
	uint_t	tcps_sndrexmitpack;	/* data packets retransmitted */
	uint_t	tcps_sndrexmitbyte;	/* data bytes retransmitted */
	uint_t	tcps_sndacks;		/* ack-only packets sent */
	uint_t	tcps_sndprobe;		/* window probes sent */
	uint_t	tcps_sndurg;		/* packets sent with URG only */
	uint_t	tcps_sndwinup;		/* window update-only packets sent */
	uint_t	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */

	uint_t	tcps_rcvtotal;		/* total packets received */
	uint_t	tcps_rcvpack;		/* packets received in sequence */
	uint_t	tcps_rcvbyte;		/* bytes received in sequence */
	uint_t	tcps_rcvbadsum;		/* packets received with ccksum errs */
	uint_t	tcps_rcvbadoff;		/* packets received with bad offset */
	uint_t	tcps_rcvshort;		/* packets received too short */
	uint_t	tcps_rcvduppack;	/* duplicate-only packets received */
	uint_t	tcps_rcvdupbyte;	/* duplicate-only bytes received */
	uint_t	tcps_rcvpartduppack;	/* packets with some duplicate data */
	uint_t	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
	uint_t	tcps_rcvoopack;		/* out-of-order packets received */
	uint_t	tcps_rcvoobyte;		/* out-of-order bytes received */
	uint_t	tcps_rcvpackafterwin;	/* packets with data after window */
	uint_t	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
	uint_t	tcps_rcvafterclose;	/* packets rcvd after "close" */
	uint_t	tcps_rcvwinprobe;	/* rcvd window probe packets */
	uint_t	tcps_rcvdupack;		/* rcvd duplicate acks */
	uint_t	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
	uint_t	tcps_rcvackpack;	/* rcvd ack packets */
	uint_t	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
	uint_t	tcps_rcvwinupd;		/* rcvd window update packets */
};

#define	TCP_COMPAT_42

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCP_VAR_H */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Tcp+ip header, after ip options removed.
 */

#ifndef	_NETINET_TCPIP_H
#define	_NETINET_TCPIP_H

/* tcpip.h 1.7 88/08/19 SMI; from UCB 7.1 6/5/85	*/

#ifdef	__cplusplus
extern "C" {
#endif

struct tcpiphdr {
	struct 	ipovly ti_i;		/* overlaid ip structure */
	struct	tcphdr ti_t;		/* tcp header */
};
#define	ti_next		ti_i.ih_next
#define	ti_prev		ti_i.ih_prev
#define	ti_x1		ti_i.ih_x1
#define	ti_pr		ti_i.ih_pr
#define	ti_len		ti_i.ih_len
#define	ti_src		ti_i.ih_src
#define	ti_dst		ti_i.ih_dst
#define	ti_sport	ti_t.th_sport
#define	ti_dport	ti_t.th_dport
#define	ti_seq		ti_t.th_seq
#define	ti_ack		ti_t.th_ack
#define	ti_x2		ti_t.th_x2
#define	ti_off		ti_t.th_off
#define	ti_flags	ti_t.th_flags
#define	ti_win		ti_t.th_win
#define	ti_sum		ti_t.th_sum
#define	ti_urp		ti_t.th_urp

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_TCPIP_H */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * Udp protocol header.
 * Per RFC 768, September, 1981.
 */

#ifndef	_NETINET_UDP_H
#define	_NETINET_UDP_H

#ifdef	__cplusplus
extern "C" {
#endif

struct udphdr {
	in_port_t	uh_sport;		/* source port */
	in_port_t	uh_dport;		/* destination port */
	int16_t		uh_ulen;		/* udp length */
	uint16_t	uh_sum;			/* udp checksum */
};

/* Option definitions. */
#define	UDP_ANONPRIVBIND	0x0100		/* for internal use only */
#define	UDP_EXCLBIND		0x0101		/* for internal use only */
#define	UDP_RCVHDR		0x0102		/* for internal use only */
#define	UDP_NAT_T_ENDPOINT	0x0103		/* for internal use only */
#define	UDP_SRCPORT_HASH	0x0104		/* for internal use only */

/*
 * Hash definitions for UDP_SRCPORT_HASH that effectively tell UDP how to go
 * handle UDP_SRCPORT_HASH.
 */
#define	UDP_HASH_DISABLE	0x0000		/* for internal use only */
#define	UDP_HASH_VXLAN		0x0001		/* for internal use only */

/*
 * Following option in UDP_ namespace required to be exposed through
 * <xti.h> (It also requires exposing options not implemented). The options
 * with potential for conflicts use #ifndef guards.
 *
 */
#ifndef UDP_CHECKSUM
#define	UDP_CHECKSUM	0x0600
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_UDP_H */
/*
 * Copyright (c) 1982, 1986 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

/*
 * UDP kernel structures and variables.
 */

#ifndef	_NETINET_UDP_VAR_H
#define	_NETINET_UDP_VAR_H

/* udp_var.h 1.8 88/08/19 SMI; from UCB 7.1 6/5/86	*/

#ifdef	__cplusplus
extern "C" {
#endif

struct	udpiphdr {
	struct 	ipovly ui_i;		/* overlaid ip structure */
	struct	udphdr ui_u;		/* udp header */
};
#define	ui_next		ui_i.ih_next
#define	ui_prev		ui_i.ih_prev
#define	ui_x1		ui_i.ih_x1
#define	ui_pr		ui_i.ih_pr
#define	ui_len		ui_i.ih_len
#define	ui_src		ui_i.ih_src
#define	ui_dst		ui_i.ih_dst
#define	ui_sport	ui_u.uh_sport
#define	ui_dport	ui_u.uh_dport
#define	ui_ulen		ui_u.uh_ulen
#define	ui_sum		ui_u.uh_sum

struct	udpstat {
	int	udps_hdrops;
	int	udps_badsum;
	int	udps_badlen;
	int	udps_fullsock;
};

#define	UDP_TTL		30		/* time to live for UDP packets */

#ifdef	__cplusplus
}
#endif

#endif	/* _NETINET_UDP_VAR_H */