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
|
#
# 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.
#
# Copyright (c) 2018, Joyent, Inc.
SVCMETHOD= svc-ripng
MANIFEST= ripng.xml
PROG= in.ripngd
OBJS= if.o input.o main.o output.o startup.o tables.o timer.o trace.o
SRCS= $(OBJS:%.o=%.c)
include ../../../Makefile.cmd
ROOTMANIFESTDIR= $(ROOTSVCNETWORKROUTING)
# these #defines are required to use UNIX 98 interfaces
_D_UNIX98_EXTN= -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
$(OBJS) : CFLAGS += $(CCVERBOSE)
$(OBJS) : CPPFLAGS += $(_D_UNIX98_EXTN)
LINTFLAGS += $(_D_UNIX98_EXTN)
# not linted
SMATCH=off
# in.ripngd uses the ancillary data feature which is available only through
# UNIX 98 standards version of Socket interface. This interface is supposed to
# be accessed by -lxnet. In addition, -lsocket is used to
# capture new not-yet-standard interfaces. Someday -lxnet alone should be enough
# when IPv6 inspired new interfaces are part of standards.
LDLIBS += -lxnet -lsocket
.KEEP_STATE:
.PARALLEL: $(OBJS)
all: $(PROG)
$(PROG): $(OBJS)
$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
$(POST_PROCESS)
include ../Makefile.lib
install: all $(ROOTLIBINETPROG) $(ROOTMANIFEST) $(ROOTSVCMETHOD)
check: $(CHKMANIFEST)
clean:
$(RM) $(OBJS)
lint: lint_SRCS
include ../../../Makefile.targ
/*
* 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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#ifndef _IN_RIPNGD_DEFS_H
#define _IN_RIPNGD_DEFS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/stream.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
#include <netinet/udp.h>
#include <net/if.h>
#include <net/route.h>
#include <protocols/ripngd.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <netdb.h>
#include <signal.h>
#include <stropts.h>
#include <arpa/inet.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <limits.h>
#include "table.h"
#include "trace.h"
#include "interface.h"
#define PATH_PID "/var/run/in.ripngd.pid"
/*
* Timer values (in seconds) used in managing the routing table.
* Every update forces an entry's timer to be reset. After
* EXPIRE_TIME without updates, the entry is marked invalid,
* but held onto until GARBAGE_TIME so that others may
* see it "be deleted".
*/
#define EXPIRE_TIME 180 /* time to mark entry invalid */
#define GARBAGE_TIME 300 /* time to garbage collect */
#define MIN_SUPPLY_TIME 15 /* min. time to supply tables */
#define MAX_SUPPLY_TIME 45 /* max. time to supply tables */
#define MIN_WAIT_TIME 1 /* min. interval to multicast changes */
#define MAX_WAIT_TIME 5 /* max. time to delay changes */
/*
* Return a random number from a an range inclusive of the endpoints
*/
#define GET_RANDOM(LOW, HIGH) (random() % ((HIGH) - (LOW) + 1) + (LOW))
/*
* When we find any interfaces marked down we rescan the
* kernel every CHECK_INTERVAL seconds to see if they've
* come up.
*/
#define CHECK_INTERVAL 60
#define START_POLL_SIZE 5
#define min(a, b) ((a) > (b) ? (b) : (a))
/*
* The maximum receive buffer size is controlled via Solaris' NDD udp_max_buf
* tunable.
*/
#define RCVBUFSIZ 65536
#define TIME_TO_MSECS(tval) ((tval).tv_sec * 1000 + (tval).tv_usec / 1000)
#define HOPCNT_INFINITY 16 /* RFC 2080, section 2.1 */
#define HOPCNT_NEXTHOP 255 /* RFC 2080, section 2.1.1 */
/*
* XXX Some of these are defined in <inet/ip6.h> under _KERNEL (but should be
* defined in <netinet/ip6.h> for completeness).
*/
#define IPV6_MAX_HOPS 255 /* Max IPv6 hops */
#define IPV6_MAX_PACKET 65535 /* maximum IPv6 packet size */
#define IPV6_MIN_MTU 1280 /* Minimum IPv6 MTU */
extern struct sockaddr_in6 allrouters;
extern struct in6_addr allrouters_in6;
extern char *control;
extern boolean_t dopoison;
extern struct interface *ifnet;
extern boolean_t install;
extern int iocsoc;
extern struct timeval lastfullupdate;
extern struct timeval lastmcast;
extern int max_poll_ifs;
extern struct rip6 *msg;
extern boolean_t needupdate;
extern struct timeval nextmcast;
extern struct timeval now;
extern char *packet;
extern struct pollfd *poll_ifs;
extern int poll_ifs_num;
extern int rip6_port;
extern int supplyinterval;
extern boolean_t supplier;
extern void dynamic_update(struct interface *);
extern void in_data(struct interface *);
extern void initifs(void);
extern void sendpacket(struct sockaddr_in6 *, struct interface *,
int, int);
extern void setup_rtsock(void);
extern void solicitall(struct sockaddr_in6 *);
extern void supply(struct sockaddr_in6 *, struct interface *,
int, boolean_t);
extern void supplyall(struct sockaddr_in6 *, int,
struct interface *, boolean_t);
extern void term(void);
extern void timer(void);
extern void timevaladd(struct timeval *, struct timeval *);
#ifdef __cplusplus
}
#endif
#endif /* _IN_RIPNGD_DEFS_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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing Table Management Daemon
*/
#include "defs.h"
/*
* Find the interface with given name.
*/
struct interface *
if_ifwithname(char *name)
{
struct interface *ifp;
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
if (ifp->int_name != NULL &&
strcmp(ifp->int_name, name) == 0)
break;
}
return (ifp);
}
/*
* An interface has declared itself down - remove it completely
* from our routing tables but keep the interface structure around.
*/
void
if_purge(struct interface *pifp)
{
rtpurgeif(pifp);
pifp->int_flags &= ~RIP6_IFF_UP;
}
static void
if_dump2(FILE *fp)
{
struct interface *ifp;
char buf1[INET6_ADDRSTRLEN];
static struct bits {
uint_t t_bits;
char *t_name;
} flagbits[] = {
/* BEGIN CSTYLED */
{ RIP6_IFF_UP, "UP" },
{ RIP6_IFF_POINTOPOINT, "POINTOPOINT" },
{ RIP6_IFF_MARKED, "MARKED" },
{ RIP6_IFF_NORTEXCH, "NORTEXCH" },
{ RIP6_IFF_PRIVATE, "PRIVATE" },
{ 0, NULL }
/* END CSTYLED */
};
struct bits *p;
char c;
boolean_t first;
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
(void) fprintf(fp, "interface %s:\n",
(ifp->int_name != NULL) ? ifp->int_name : "(noname)");
(void) fprintf(fp, "\tflags ");
c = ' ';
for (first = _B_TRUE, p = flagbits; p->t_bits > 0; p++) {
if ((ifp->int_flags & p->t_bits) == 0)
continue;
(void) fprintf(fp, "%c%s", c, p->t_name);
if (first) {
c = '|';
first = _B_FALSE;
}
}
if (first)
(void) fprintf(fp, " 0");
(void) fprintf(fp, "\n\tpackets received %d\n",
ifp->int_ipackets);
(void) fprintf(fp, "\tpackets sent %d\n", ifp->int_opackets);
(void) fprintf(fp, "\ttransitions %d\n", ifp->int_transitions);
if ((ifp->int_flags & RIP6_IFF_UP) == 0)
continue;
if (ifp->int_flags & RIP6_IFF_POINTOPOINT) {
(void) fprintf(fp, "\tlocal %s\n",
inet_ntop(AF_INET6, (void *)&ifp->int_addr, buf1,
sizeof (buf1)));
(void) fprintf(fp, "\tremote %s\n",
inet_ntop(AF_INET6, (void *)&ifp->int_dstaddr, buf1,
sizeof (buf1)));
} else {
(void) fprintf(fp, "\tprefix %s/%d\n",
inet_ntop(AF_INET6, (void *)&ifp->int_addr, buf1,
sizeof (buf1)),
ifp->int_prefix_length);
}
(void) fprintf(fp, "\tmetric %d\n", ifp->int_metric);
(void) fprintf(fp, "\tmtu %d\n", ifp->int_mtu);
}
(void) fflush(fp);
}
void
if_dump(void)
{
if (ftrace != NULL)
if_dump2(ftrace);
else
if_dump2(stderr);
}
/*
* 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 1999 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing Table Management Daemon
*/
#include "defs.h"
static char buf1[INET6_ADDRSTRLEN];
static char buf2[INET6_ADDRSTRLEN];
static void rip_input(struct sockaddr_in6 *from, int size, uint_t hopcount,
struct interface *ifp);
/*
* Return a pointer to the specified option buffer.
* If not found return NULL.
*/
static void *
find_ancillary(struct msghdr *rmsg, int cmsg_type)
{
struct cmsghdr *cmsg;
for (cmsg = CMSG_FIRSTHDR(rmsg); cmsg != NULL;
cmsg = CMSG_NXTHDR(rmsg, cmsg)) {
if (cmsg->cmsg_level == IPPROTO_IPV6 &&
cmsg->cmsg_type == cmsg_type) {
return (CMSG_DATA(cmsg));
}
}
return (NULL);
}
/*
* Read a packet and passes it to rip_input() for processing.
*/
void
in_data(struct interface *ifp)
{
struct sockaddr_in6 from;
int len;
struct msghdr rmsg;
struct iovec iov;
uchar_t *hopcntopt;
iov.iov_base = packet;
iov.iov_len = IPV6_MAX_PACKET;
rmsg.msg_name = &from;
rmsg.msg_namelen = (socklen_t)sizeof (from);
rmsg.msg_iov = &iov;
rmsg.msg_iovlen = 1;
rmsg.msg_control = control;
rmsg.msg_controllen = IPV6_MAX_PACKET;
if ((len = recvmsg(ifp->int_sock, &rmsg, 0)) < 0) {
/*
* Only syslog if a true error occurred.
*/
if (errno != EINTR)
syslog(LOG_ERR, "in_data: recvmsg: %m");
return;
}
if (len == 0)
return;
if (tracing & INPUT_BIT) {
(void) inet_ntop(from.sin6_family, &from.sin6_addr, buf1,
sizeof (buf1));
}
/* Ignore packets > 64k or control buffers that don't fit */
if (rmsg.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
if (tracing & INPUT_BIT) {
(void) fprintf(stderr,
"Truncated message: msg_flags 0x%x from %s\n",
rmsg.msg_flags, buf1);
}
return;
}
if ((hopcntopt = find_ancillary(&rmsg, IPV6_HOPLIMIT)) == NULL) {
if (tracing & INPUT_BIT) {
(void) fprintf(stderr, "Unknown hop limit from %s\n",
buf1);
}
return;
}
rip_input(&from, len, *(uint_t *)hopcntopt, ifp);
}
/*
* Process a newly received packet.
*/
static void
rip_input(struct sockaddr_in6 *from, int size, uint_t hopcount,
struct interface *ifp)
{
struct rt_entry *rt;
struct netinfo6 *n;
int newsize;
boolean_t changes = _B_FALSE;
int answer = supplier;
struct in6_addr prefix;
struct in6_addr nexthop;
struct in6_addr *gate;
boolean_t foundnexthop = _B_FALSE;
struct sioc_addrreq sa;
struct sockaddr_in6 *sin6;
TRACE_INPUT(ifp, from, size);
if (tracing & INPUT_BIT) {
(void) inet_ntop(from->sin6_family, (void *)&from->sin6_addr,
buf1, sizeof (buf1));
}
/*
* If the packet is recevied on an interface with IFF_NORTEXCH flag set,
* we ignore the packet.
*/
if (ifp->int_flags & RIP6_IFF_NORTEXCH) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Ignore received RIPng packet on %s "
"(no route exchange on interface)\n",
ifp->int_name);
(void) fflush(ftrace);
}
return;
}
if (msg->rip6_vers != RIPVERSION6) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad version number %d in packet from %s\n",
msg->rip6_vers, buf1);
(void) fflush(ftrace);
}
return;
}
if (ntohs(msg->rip6_res1) != 0) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Non-zero reserved octets found in packet from "
"%s\n",
buf1);
(void) fflush(ftrace);
}
}
switch (msg->rip6_cmd) {
case RIPCMD6_REQUEST: /* multicasted request */
ifp->int_ipackets++;
newsize = 0;
/*
* Adjust size by the length of the command, version and
* reserved fields (which are in total 32-bit aligned).
*/
size -= sizeof (msg->rip6_cmd) + sizeof (msg->rip6_vers) +
sizeof (msg->rip6_res1);
/*
* From section 2.4.1 of RFC 2080:
*
* If there is exactly one entry in the request with a
* destination prefix of zero, a prefix length of zero and
* an infinite metric, then supply the entire routing
* table.
*/
n = msg->rip6_nets;
if (size == sizeof (struct netinfo6) &&
n->rip6_prefix_length == 0 &&
n->rip6_metric == HOPCNT_INFINITY) {
rtcreate_prefix(&n->rip6_prefix, &prefix,
n->rip6_prefix_length);
if (IN6_IS_ADDR_UNSPECIFIED(&prefix)) {
supply(from, ifp, 0,
from->sin6_port == rip6_port);
return;
}
}
for (; size >= sizeof (struct netinfo6);
size -= sizeof (struct netinfo6), n++) {
if (n->rip6_prefix_length > IPV6_ABITS) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad prefix length %d in request "
"from %s\n",
n->rip6_prefix_length, buf1);
(void) fflush(ftrace);
}
continue;
}
if (IN6_IS_ADDR_LINKLOCAL(&n->rip6_prefix) ||
IN6_IS_ADDR_MULTICAST(&n->rip6_prefix)) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad prefix %s in request from "
"%s\n",
inet_ntop(AF_INET6,
(void *)&n->rip6_prefix, buf2,
sizeof (buf2)),
buf1);
(void) fflush(ftrace);
}
continue;
}
rtcreate_prefix(&n->rip6_prefix, &prefix,
n->rip6_prefix_length);
rt = rtlookup(&prefix, n->rip6_prefix_length);
n->rip6_metric = (rt == NULL ?
HOPCNT_INFINITY :
min(rt->rt_metric, HOPCNT_INFINITY));
newsize += sizeof (struct netinfo6);
}
if (size > 0) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Ignoring %d octets of trailing data in "
"request from %s\n",
size, buf1);
(void) fflush(ftrace);
}
}
if (answer && newsize > 0) {
/*
* Adjust newsize by the length of the command, version
* and reserved fields (which are in total 32-bit
* aligned).
*/
msg->rip6_cmd = RIPCMD6_RESPONSE;
newsize += sizeof (msg->rip6_cmd) +
sizeof (msg->rip6_vers) + sizeof (msg->rip6_res1);
sendpacket(from, ifp, newsize, 0);
}
return;
case RIPCMD6_RESPONSE:
if (hopcount != IPV6_MAX_HOPS) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad hop count %d in response from %s\n",
hopcount, buf1);
(void) fflush(ftrace);
}
return;
}
if (from->sin6_port != rip6_port) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad source port %d in response from %s\n",
from->sin6_port, buf1);
(void) fflush(ftrace);
}
return;
}
if (!IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad source address (not link-local) in "
"response from %s\n", buf1);
(void) fflush(ftrace);
}
return;
}
ifp->int_ipackets++;
/*
* Adjust size by the length of the command, version and
* reserved fields (which are in total 32-bit aligned).
*/
size -= sizeof (msg->rip6_cmd) + sizeof (msg->rip6_vers) +
sizeof (msg->rip6_res1);
for (n = msg->rip6_nets;
supplier && size >= sizeof (struct netinfo6);
size -= sizeof (struct netinfo6), n++) {
/*
* From section 2.1.1 of RFC 2080:
*
* This is a next hop RTE if n->rip6_metric is set to
* HOPCNT_NEXTHOP. If the next hop address (which is
* placed in the prefix field of this special RTE) is
* unspecified or is not a link-local address, then use
* the originator's address instead (effectively turning
* off next hop RTE processing.)
*/
if (n->rip6_metric == HOPCNT_NEXTHOP) {
/*
* First check to see if the unspecified address
* was given as the next hop address. This is
* the correct way of specifying the end of use
* of a next hop address.
*/
if (IN6_IS_ADDR_UNSPECIFIED(&n->rip6_prefix)) {
foundnexthop = _B_FALSE;
continue;
}
/*
* A next hop address that is not a link-local
* address is treated as the unspecified one.
* Trace this event if input tracing is enabled.
*/
if (!IN6_IS_ADDR_LINKLOCAL(&n->rip6_prefix)) {
foundnexthop = _B_FALSE;
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad next hop %s in "
"response from %s\n",
inet_ntop(AF_INET6,
(void *)&n->rip6_prefix,
buf2, sizeof (buf2)),
buf1);
}
continue;
}
/*
* Verify that the next hop address is not one
* of our own.
*/
sin6 = (struct sockaddr_in6 *)&sa.sa_addr;
sin6->sin6_family = AF_INET6;
sin6->sin6_addr = n->rip6_prefix;
if (ioctl(iocsoc, SIOCTMYADDR,
(char *)&sa) < 0) {
syslog(LOG_ERR,
"rip_input: "
"ioctl (verify my address): %m");
return;
}
if (sa.sa_res != 0) {
foundnexthop = _B_FALSE;
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad next hop %s is self "
"in response from %s\n",
inet_ntop(AF_INET6,
(void *)&n->rip6_prefix,
buf2, sizeof (buf2)),
buf1);
}
continue;
}
foundnexthop = _B_TRUE;
nexthop = n->rip6_prefix;
continue;
}
if (foundnexthop)
gate = &nexthop;
else
gate = &from->sin6_addr;
if (n->rip6_metric > HOPCNT_INFINITY ||
n->rip6_metric < 1) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad metric %d in response from "
"%s\n",
n->rip6_metric, buf1);
(void) fflush(ftrace);
}
continue;
}
if (n->rip6_prefix_length > IPV6_ABITS) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad prefix length %d in response "
"from %s\n",
n->rip6_prefix_length, buf1);
(void) fflush(ftrace);
}
continue;
}
if (IN6_IS_ADDR_LINKLOCAL(&n->rip6_prefix) ||
IN6_IS_ADDR_MULTICAST(&n->rip6_prefix)) {
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad prefix %s in response from "
"%s\n",
inet_ntop(AF_INET6,
(void *)&n->rip6_prefix, buf2,
sizeof (buf2)),
buf1);
(void) fflush(ftrace);
}
continue;
}
/* Include metric for incoming interface */
n->rip6_metric += IFMETRIC(ifp);
rtcreate_prefix(&n->rip6_prefix, &prefix,
n->rip6_prefix_length);
rt = rtlookup(&prefix, n->rip6_prefix_length);
if (rt == NULL) {
if (n->rip6_metric < HOPCNT_INFINITY) {
rtadd(&prefix,
gate, n->rip6_prefix_length,
n->rip6_metric, n->rip6_route_tag,
_B_FALSE, ifp);
changes = _B_TRUE;
}
continue;
}
/*
* If the supplied metric is at least HOPCNT_INFINITY
* and the current metric of the route is
* HOPCNT_INFINITY, then this particular RTE is ignored.
*/
if (n->rip6_metric >= HOPCNT_INFINITY &&
rt->rt_metric == HOPCNT_INFINITY)
continue;
/*
* From section 2.4.2 of RFC 2080:
*
* Update if any one of the following is true
*
* 1) From current gateway and a different metric.
* 2) From current gateway and a different index.
* 3) A shorter (smaller) metric.
* 4) Equivalent metric and an age at least
* one-half of EXPIRE_TIME.
*
* Otherwise, update timer for the interface on which
* the packet arrived.
*/
if (IN6_ARE_ADDR_EQUAL(gate, &rt->rt_router)) {
if (n->rip6_metric != rt->rt_metric ||
rt->rt_ifp != ifp) {
rtchange(rt, gate, n->rip6_metric, ifp);
changes = _B_TRUE;
} else if (n->rip6_metric < HOPCNT_INFINITY) {
rt->rt_timer = 0;
}
} else if (n->rip6_metric < rt->rt_metric ||
(rt->rt_timer > (EXPIRE_TIME / 2) &&
rt->rt_metric == n->rip6_metric)) {
rtchange(rt, gate, n->rip6_metric, ifp);
changes = _B_TRUE;
}
}
if (changes && supplier)
dynamic_update(ifp);
return;
default:
if (tracing & INPUT_BIT) {
(void) fprintf(ftrace,
"Bad command %d in packet from %s\n",
msg->rip6_cmd, buf1);
(void) fflush(ftrace);
}
return;
}
}
/*
* If changes have occurred, and if we have not sent a multicast
* recently, send a dynamic update. This update is sent only
* on interfaces other than the one on which we received notice
* of the change. If we are within MIN_WAIT_TIME of a full update,
* don't bother sending; if we just sent a dynamic update
* and set a timer (nextmcast), delay until that time.
* If we just sent a full update, delay the dynamic update.
* Set a timer for a randomized value to suppress additional
* dynamic updates until it expires; if we delayed sending
* the current changes, set needupdate.
*/
void
dynamic_update(struct interface *ifp)
{
int delay;
if (now.tv_sec - lastfullupdate.tv_sec >=
supplyinterval - MIN_WAIT_TIME)
return;
if (now.tv_sec - lastmcast.tv_sec >= MIN_WAIT_TIME &&
/* BEGIN CSTYLED */
timercmp(&nextmcast, &now, <)) {
/* END CSTYLED */
TRACE_ACTION("send dynamic update",
(struct rt_entry *)NULL);
supplyall(&allrouters, RTS_CHANGED, ifp, _B_TRUE);
lastmcast = now;
needupdate = _B_FALSE;
nextmcast.tv_sec = 0;
} else {
needupdate = _B_TRUE;
TRACE_ACTION("delay dynamic update",
(struct rt_entry *)NULL);
}
if (nextmcast.tv_sec == 0) {
delay = GET_RANDOM(MIN_WAIT_TIME * 1000000,
MAX_WAIT_TIME * 1000000);
if (tracing & ACTION_BIT) {
(void) fprintf(ftrace,
"inhibit dynamic update for %d msec\n",
delay / 1000);
(void) fflush(ftrace);
}
nextmcast.tv_sec = delay / 1000000;
nextmcast.tv_usec = delay % 1000000;
timevaladd(&nextmcast, &now);
/*
* If the next possibly dynamic update
* is within MIN_WAIT_TIME of the next full
* update, force the delay past the full
* update, or we might send a dynamic update
* just before the full update.
*/
if (nextmcast.tv_sec >
lastfullupdate.tv_sec + supplyinterval - MIN_WAIT_TIME) {
nextmcast.tv_sec =
lastfullupdate.tv_sec + supplyinterval + 1;
}
}
}
/*
* 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 1999 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#ident "%Z%%M% %I% %E% SMI"
struct interface {
struct interface *int_next;
struct in6_addr int_addr; /* address on this if */
struct in6_addr int_dstaddr; /* other end of p-to-p link */
int int_metric; /* init's routing entry */
uint_t int_flags; /* see below */
int int_prefix_length; /* prefix length on this if */
char *int_name; /* from kernel if structure */
char *int_ifbase; /* name of physical interface */
int int_sock; /* socket on if to send/recv */
int int_ifindex; /* interface index */
uint_t int_mtu; /* maximum transmission unit */
struct ifdebug int_input, int_output; /* packet tracing stuff */
int int_ipackets; /* input packets received */
int int_opackets; /* output packets sent */
ushort_t int_transitions; /* times gone up-down */
};
#define RIP6_IFF_UP 0x1 /* interface is up */
#define RIP6_IFF_POINTOPOINT 0x2 /* interface is p-to-p link */
#define RIP6_IFF_MARKED 0x4 /* to determine removed ifs */
#define RIP6_IFF_NORTEXCH 0x8 /* don't exchange route info */
#define RIP6_IFF_PRIVATE 0x10 /* interface is private */
#define IFMETRIC(ifp) ((ifp != NULL) ? (ifp)->int_metric : 1)
extern void if_dump(void);
extern struct interface *if_ifwithname(char *);
extern void if_purge(struct interface *);
/*
* 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) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#include "defs.h"
struct sockaddr_in6 allrouters;
char *control;
boolean_t dopoison = _B_TRUE; /* Do poison reverse */
int iocsoc;
struct timeval lastfullupdate; /* last time full table multicast */
struct timeval lastmcast; /* last time all/changes multicast */
int max_poll_ifs = START_POLL_SIZE;
struct rip6 *msg;
boolean_t needupdate; /* true if need update at nextmcast */
struct timeval nextmcast; /* time to wait before changes mcast */
struct timeval now; /* current idea of time */
char *packet;
struct pollfd *poll_ifs = NULL;
int poll_ifs_num = 0;
int rip6_port;
boolean_t supplier = _B_TRUE; /* process should supply updates */
struct in6_addr allrouters_in6 = {
/* BEGIN CSTYLED */
{ 0xff, 0x2, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x9 }
/* END CSTYLED */
};
static void timevalsub(struct timeval *t1, struct timeval *t2);
static void
usage(char *fname)
{
(void) fprintf(stderr,
"usage: "
"%s [ -P ] [ -p port ] [ -q ] [ -s ] [ -t ] [ -v ] [<logfile>]\n",
fname);
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
int i, n;
struct interface *ifp;
int c;
struct timeval waittime;
int timeout;
boolean_t daemon = _B_TRUE; /* Fork off a detached daemon */
FILE *pidfp;
mode_t pidmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* 0644 */
rip6_port = htons(IPPORT_ROUTESERVER6);
allrouters.sin6_family = AF_INET6;
allrouters.sin6_port = rip6_port;
allrouters.sin6_addr = allrouters_in6;
while ((c = getopt(argc, argv, "nsqvTtdgPp:")) != EOF) {
switch (c) {
case 'n':
install = _B_FALSE;
break;
case 's':
supplier = _B_TRUE;
break;
case 'q':
supplier = _B_FALSE;
break;
case 'v':
tracing |= ACTION_BIT;
break;
case 'T':
daemon = _B_FALSE;
break;
case 't':
tracepackets = _B_TRUE;
daemon = _B_FALSE;
tracing |= (INPUT_BIT | OUTPUT_BIT);
break;
case 'd':
break;
case 'P':
dopoison = _B_FALSE;
break;
case 'p':
rip6_port = htons(atoi(optarg));
allrouters.sin6_port = rip6_port;
break;
default:
usage(argv[0]);
/* NOTREACHED */
}
}
/*
* Any extra argument is considered
* a tracing log file.
*/
if (optind < argc) {
traceon(argv[optind]);
} else if (tracing && !daemon) {
traceonfp(stdout);
} else if (tracing) {
(void) fprintf(stderr, "Need logfile with -v\n");
usage(argv[0]);
/* NOTREACHED */
}
if (daemon) {
int t;
if (fork())
exit(EXIT_SUCCESS);
for (t = 0; t < 20; t++) {
if (!tracing || (t != fileno(ftrace)))
(void) close(t);
}
(void) open("/", 0);
(void) dup2(0, 1);
(void) dup2(0, 2);
(void) setsid();
}
/* Store our process id, blow away any existing file if it exists. */
if ((pidfp = fopen(PATH_PID, "w")) == NULL) {
(void) fprintf(stderr, "%s: unable to open " PATH_PID ": %s\n",
argv[0], strerror(errno));
} else {
(void) fprintf(pidfp, "%ld\n", getpid());
(void) fclose(pidfp);
(void) chmod(PATH_PID, pidmode);
}
iocsoc = socket(AF_INET6, SOCK_DGRAM, 0);
if (iocsoc < 0) {
syslog(LOG_ERR, "main: socket: %m");
exit(EXIT_FAILURE);
}
setup_rtsock();
/*
* Allocate the buffer to hold the RIPng packet. In reality, it will be
* smaller than IPV6_MAX_PACKET octets due to (at least) the IPv6 and
* UDP headers but IPV6_MAX_PACKET is a convenient size.
*/
packet = (char *)malloc(IPV6_MAX_PACKET);
if (packet == NULL) {
syslog(LOG_ERR, "main: malloc: %m");
exit(EXIT_FAILURE);
}
msg = (struct rip6 *)packet;
/*
* Allocate the buffer to hold the ancillary data. This data is used to
* insure that the incoming hop count of a RIPCMD6_RESPONSE message is
* IPV6_MAX_HOPS which indicates that it came from a direct neighbor
* (namely, no intervening router decremented it).
*/
control = (char *)malloc(IPV6_MAX_PACKET);
if (control == NULL) {
syslog(LOG_ERR, "main: malloc: %m");
exit(EXIT_FAILURE);
}
openlog("in.ripngd", LOG_PID | LOG_CONS, LOG_DAEMON);
(void) gettimeofday(&now, (struct timezone *)NULL);
initifs();
solicitall(&allrouters);
if (supplier)
supplyall(&allrouters, 0, (struct interface *)NULL, _B_TRUE);
(void) sigset(SIGALRM, (void (*)(int))timer);
(void) sigset(SIGHUP, (void (*)(int))initifs);
(void) sigset(SIGTERM, (void (*)(int))term);
(void) sigset(SIGUSR1, (void (*)(int))if_dump);
(void) sigset(SIGUSR2, (void (*)(int))rtdump);
/*
* Seed the pseudo-random number generator for GET_RANDOM().
*/
srandom((uint_t)gethostid());
timer();
for (;;) {
if (needupdate) {
waittime = nextmcast;
timevalsub(&waittime, &now);
if (waittime.tv_sec < 0) {
timeout = 0;
} else {
timeout = TIME_TO_MSECS(waittime);
}
if (tracing & ACTION_BIT) {
(void) fprintf(ftrace,
"poll until dynamic update in %d msec\n",
timeout);
(void) fflush(ftrace);
}
} else {
timeout = INFTIM;
}
if ((n = poll(poll_ifs, poll_ifs_num, timeout)) < 0) {
if (errno == EINTR)
continue;
syslog(LOG_ERR, "main: poll: %m");
exit(EXIT_FAILURE);
}
(void) sighold(SIGALRM);
(void) sighold(SIGHUP);
/*
* Poll timed out.
*/
if (n == 0) {
if (needupdate) {
TRACE_ACTION("send delayed dynamic update",
(struct rt_entry *)NULL);
(void) gettimeofday(&now,
(struct timezone *)NULL);
supplyall(&allrouters, RTS_CHANGED,
(struct interface *)NULL, _B_TRUE);
lastmcast = now;
needupdate = _B_FALSE;
nextmcast.tv_sec = 0;
}
(void) sigrelse(SIGHUP);
(void) sigrelse(SIGALRM);
continue;
}
(void) gettimeofday(&now, (struct timezone *)NULL);
for (i = 0; i < poll_ifs_num; i++) {
/*
* This case should never happen.
*/
if (poll_ifs[i].revents & POLLERR) {
syslog(LOG_ERR,
"main: poll returned a POLLERR event");
continue;
}
if (poll_ifs[i].revents & POLLIN) {
for (ifp = ifnet; ifp != NULL;
ifp = ifp->int_next) {
if (poll_ifs[i].fd == ifp->int_sock)
in_data(ifp);
}
}
}
(void) sigrelse(SIGHUP);
(void) sigrelse(SIGALRM);
}
return (0);
}
void
timevaladd(struct timeval *t1, struct timeval *t2)
{
t1->tv_sec += t2->tv_sec;
if ((t1->tv_usec += t2->tv_usec) > 1000000) {
t1->tv_sec++;
t1->tv_usec -= 1000000;
}
}
void
timevalsub(struct timeval *t1, struct timeval *t2)
{
t1->tv_sec -= t2->tv_sec;
if ((t1->tv_usec -= t2->tv_usec) < 0) {
t1->tv_sec--;
t1->tv_usec += 1000000;
}
}
/*
* 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 1999 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
/*
* Routing Table Management Daemon
*/
#include "defs.h"
/*
* Apply the function "supply" to all active
* interfaces with a link-local address.
*/
void
supplyall(struct sockaddr_in6 *sin6, int rtstate, struct interface *skipif,
boolean_t splith)
{
struct interface *ifp;
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
if ((ifp->int_flags & RIP6_IFF_UP) == 0)
continue;
if (ifp->int_flags & RIP6_IFF_NORTEXCH) {
if (tracing & OUTPUT_BIT) {
(void) fprintf(ftrace,
"Suppress sending RIPng response packet "
"on %s (no route exchange on interface)\n",
ifp->int_name);
(void) fflush(ftrace);
}
continue;
}
if (ifp->int_sock == -1)
continue;
if (ifp == skipif)
continue;
if (!IN6_IS_ADDR_LINKLOCAL(&ifp->int_addr))
continue;
supply(sin6, ifp, rtstate, splith);
}
}
static void
solicit(struct sockaddr_in6 *sin6, struct interface *ifp)
{
msg->rip6_cmd = RIPCMD6_REQUEST;
msg->rip6_vers = RIPVERSION6;
msg->rip6_nets[0].rip6_prefix = in6addr_any;
msg->rip6_nets[0].rip6_prefix_length = 0;
msg->rip6_nets[0].rip6_metric = HOPCNT_INFINITY;
sendpacket(sin6, ifp, sizeof (struct rip6), 0);
}
void
solicitall(struct sockaddr_in6 *sin6)
{
struct interface *ifp;
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
if ((ifp->int_flags & RIP6_IFF_UP) == 0)
continue;
if (ifp->int_flags & RIP6_IFF_NORTEXCH) {
if (tracing & OUTPUT_BIT) {
(void) fprintf(ftrace,
"Suppress sending RIPng request packet "
"on %s (no route exchange on interface)\n",
ifp->int_name);
(void) fflush(ftrace);
}
continue;
}
if (ifp->int_sock == -1)
continue;
solicit(sin6, ifp);
}
}
/*
* Output a preformed packet.
*/
/*ARGSUSED*/
void
sendpacket(struct sockaddr_in6 *sin6, struct interface *ifp, int size,
int flags)
{
if (sendto(ifp->int_sock, packet, size, flags,
(struct sockaddr *)sin6, sizeof (*sin6)) < 0) {
syslog(LOG_ERR, "sendpacket: sendto: %m");
return;
}
TRACE_OUTPUT(ifp, sin6, sizeof (struct rip6));
ifp->int_opackets++;
}
/*
* Supply dst with the contents of the routing tables.
* If this won't fit in one packet, chop it up into several.
*/
void
supply(struct sockaddr_in6 *sin6, struct interface *ifp, int rtstate,
boolean_t splith)
{
struct rt_entry *rt;
struct netinfo6 *n = msg->rip6_nets;
struct rthash *rh;
int size, i, maxsize;
uint8_t rtmetric;
msg->rip6_cmd = RIPCMD6_RESPONSE;
msg->rip6_vers = RIPVERSION6;
/*
* Initialize maxsize to the size of the largest RIPng packet supported
* on the outgoing interface.
*/
maxsize = ifp->int_mtu - sizeof (ip6_t) - sizeof (struct udphdr);
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i]; rh < &net_hashes[i][ROUTEHASHSIZ];
rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
if (IN6_IS_ADDR_LINKLOCAL(&rt->rt_dst))
continue;
if (IN6_IS_ADDR_UNSPECIFIED(&rt->rt_dst))
continue;
/* do not send if private */
if (rt->rt_state & RTS_PRIVATE)
continue;
/*
* Don't resend the information
* on the network from which it was received.
*/
if (splith && rt->rt_ifp != NULL &&
strcmp(ifp->int_ifbase,
rt->rt_ifp->int_ifbase) == 0) {
if (dopoison)
rtmetric = HOPCNT_INFINITY;
else
continue;
} else {
rtmetric = rt->rt_metric;
}
/*
* For dynamic updates, limit update to routes
* with the specified state.
*/
if (rtstate != 0 &&
(rt->rt_state & rtstate) == 0)
continue;
/*
* Check if there is space for another RTE. If
* not, send the packet built up and reset n for
* the remaining RTEs.
*/
size = (char *)n - packet;
if (size > maxsize - sizeof (struct netinfo6)) {
sendpacket(sin6, ifp, size, 0);
TRACE_OUTPUT(ifp, sin6, size);
n = msg->rip6_nets;
}
n->rip6_prefix = rt->rt_dst;
n->rip6_route_tag = rt->rt_tag;
n->rip6_prefix_length = rt->rt_prefix_length;
n->rip6_metric = min(rtmetric, HOPCNT_INFINITY);
n++;
} /* end of hash chain */
} /* end of particular prefix length */
} /* end of all prefix lengths */
if (n != msg->rip6_nets) {
size = (char *)n - packet;
sendpacket(sin6, ifp, size, 0);
TRACE_OUTPUT(ifp, sin6, size);
}
}
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Copyright 2007 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
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
NOTE: This service manifest is not editable; its contents will
be overwritten by package or patch operations, including
operating system upgrade. Make customizations in a different
file.
-->
<service_bundle type='manifest' name='SUNWroutr:ripng'>
<service
name='network/routing/ripng'
type='service'
version='1'>
<single_instance />
<instance name='default' enabled='false' >
<!--
in.ripngd will not run unless routing-setup has run.
-->
<dependency
name='network_routing_setup'
grouping='require_all'
restart_on='refresh'
type='service'>
<service_fmri value='svc:/network/routing-setup' />
</dependency>
<!--
We only start in.ripngd if IPv6 forwarding is enabled. This
is due to a giant gap in in.ripngd's design which causes
in.ripngd to propagate routes on all interfaces regardless of
their forwarding status. If that's fixed, then we can start
in.ripngd regardless of the global IPv6 forwarding status.
-->
<dependency
name='ipv6_forwarding'
grouping='require_all'
restart_on='refresh'
type='service'>
<service_fmri value='svc:/network/ipv6-forwarding' />
</dependency>
<exec_method
type='method'
name='start'
exec='/lib/svc/method/svc-ripng'
timeout_seconds='60'>
<method_context working_directory='/'>
<method_credential user='root' group='root'
privileges='basic,proc_owner,proc_fork,proc_exec,proc_info,proc_session,file_chown,sys_ip_config,net_privaddr,net_icmpaccess,net_rawaccess'/>
</method_context>
</exec_method>
<exec_method
type='method'
name='stop'
exec=':kill'
timeout_seconds='60'>
<method_context working_directory='/'>
<method_credential user='root' group='root'/>
</method_context>
</exec_method>
<!-- to start stop routing services -->
<property_group name='general' type='framework'>
<propval name='action_authorization' type='astring'
value='solaris.smf.manage.routing' />
<propval name='value_authorization' type='astring'
value='solaris.smf.manage.routing' />
</property_group>
<!-- Properties in this group are used by routeadm(8) -->
<property_group name='routeadm' type='application'>
<stability value='Unstable' />
<!-- Identifies service as a routing service -->
<propval name='protocol' type='astring' value='ipv6' />
<propval name='daemon' type='astring'
value='/usr/lib/inet/in.ripngd' />
<propval name='value_authorization' type='astring'
value='solaris.smf.value.routing' />
</property_group>
<!-- Properties in this group are modifiable via routeadm(8) -->
<property_group name='routing' type='application'>
<stability value='Evolving' />
<!-- Equivalent to -s option if true -->
<propval name='supply_routes' type='boolean' value='true' />
<!-- Equivalent to -q option if true -->
<propval name='quiet_mode' type='boolean' value='false' />
<!-- Equivalent to -p port option -->
<propval name='udp_port' type='integer' value='521' />
<!-- Equivalent to -P option if false -->
<propval name='poison_reverse' type='boolean' value='true' />
<!-- Equivalent to -v option if true -->
<propval name='verbose' type='boolean' value='false' />
<!-- Equivalent to optional logging file -->
<propval name='log_file' type='astring' value='' />
<propval name='value_authorization' type='astring'
value='solaris.smf.value.routing' />
</property_group>
<template>
<common_name>
<loctext xml:lang='C'>
in.ripngd network routing daemon
</loctext>
</common_name>
<documentation>
<manpage title='in.ripngd' section='8'
manpath='/usr/share/man' />
</documentation>
</template>
</instance>
<stability value='Unstable' />
</service>
</service_bundle>
/*
* 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 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#include "defs.h"
#define IF_SEPARATOR ':'
struct interface *ifnet;
static int setup_listen_sock(int ifindex);
static void addrouteforif(struct interface *ifp);
static void resetup_listen_sock(struct interface *, int);
/*
* This is called at startup and after that, every CHECK_INTERVAL seconds or
* when a SIGHUP is received.
*/
void
initifs(void)
{
static char *buf = NULL;
static uint_t maxbufsize = 0;
int bufsize;
int numifs;
struct lifnum lifn;
struct lifconf lifc;
struct lifreq lifr;
struct lifreq *lifrp;
int n;
struct interface ifs;
struct interface *ifp;
int netmaskchange = 0;
boolean_t changes = _B_FALSE;
lifn.lifn_family = AF_INET6;
lifn.lifn_flags = 0;
if (ioctl(iocsoc, SIOCGLIFNUM, (char *)&lifn) < 0) {
syslog(LOG_ERR, "initifs: ioctl (get interface numbers): %m");
return;
}
numifs = lifn.lifn_count;
bufsize = numifs * sizeof (struct lifreq);
if (buf == NULL || bufsize > maxbufsize) {
if (buf != NULL)
free(buf);
maxbufsize = bufsize;
buf = (char *)malloc(maxbufsize);
if (buf == NULL) {
syslog(LOG_ERR, "initifs: out of memory");
return;
}
}
lifc.lifc_family = AF_INET6;
lifc.lifc_flags = 0;
lifc.lifc_len = bufsize;
lifc.lifc_buf = buf;
if (ioctl(iocsoc, SIOCGLIFCONF, (char *)&lifc) < 0) {
syslog(LOG_ERR,
"initifs: ioctl (get interface configuration): %m");
return;
}
/*
* Mark all of the currently known interfaces in order to determine
* which of the these interfaces no longer exist.
*/
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next)
ifp->int_flags |= RIP6_IFF_MARKED;
lifrp = lifc.lifc_req;
for (n = lifc.lifc_len / sizeof (struct lifreq); n > 0; n--, lifrp++) {
bzero((char *)&ifs, sizeof (ifs));
(void) strncpy(lifr.lifr_name, lifrp->lifr_name,
sizeof (lifr.lifr_name));
if (ioctl(iocsoc, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
syslog(LOG_ERR,
"initifs: ioctl (get interface flags): %m");
continue;
}
if (!(lifr.lifr_flags & IFF_IPV6) ||
!(lifr.lifr_flags & IFF_MULTICAST) ||
(lifr.lifr_flags & IFF_LOOPBACK))
continue;
ifp = if_ifwithname(lifr.lifr_name);
if (ifp != NULL)
ifp->int_flags &= ~RIP6_IFF_MARKED;
if (lifr.lifr_flags & IFF_POINTOPOINT)
ifs.int_flags |= RIP6_IFF_POINTOPOINT;
if (lifr.lifr_flags & IFF_NORTEXCH)
ifs.int_flags |= RIP6_IFF_NORTEXCH;
if (lifr.lifr_flags & IFF_PRIVATE)
ifs.int_flags |= RIP6_IFF_PRIVATE;
if (lifr.lifr_flags & IFF_UP) {
ifs.int_flags |= RIP6_IFF_UP;
} else {
if (ifp != NULL) {
if (ifp->int_flags & RIP6_IFF_UP) {
/*
* If there is an transition from up to
* down for an exisiting interface,
* increment the counter.
*/
ifp->int_transitions++;
changes = _B_TRUE;
}
if_purge(ifp);
}
continue;
}
if (ifs.int_flags & RIP6_IFF_POINTOPOINT) {
/*
* For point-to-point interfaces, retrieve both the
* local and the remote addresses.
*/
if (ioctl(iocsoc, SIOCGLIFADDR, (char *)&lifr) < 0) {
syslog(LOG_ERR,
"initifs: ioctl (get interface address): "
"%m");
continue;
}
ifs.int_addr =
((struct sockaddr_in6 *)&lifr.lifr_addr)->sin6_addr;
if (ioctl(iocsoc, SIOCGLIFDSTADDR, (char *)&lifr) < 0) {
syslog(LOG_ERR,
"initifs: ioctl (get destination address): "
"%m");
continue;
}
ifs.int_dstaddr = ((struct sockaddr_in6 *)
&lifr.lifr_dstaddr)->sin6_addr;
ifs.int_prefix_length = IPV6_ABITS;
} else {
/*
* For other interfaces, retreieve the prefix (including
* the prefix length.
*/
if (ioctl(iocsoc, SIOCGLIFSUBNET, (char *)&lifr) < 0) {
syslog(LOG_ERR,
"initifs: ioctl (get subnet prefix): %m");
continue;
}
/*
* This should never happen but check for it in any case
* since the kernel stores it as an signed integer.
*/
if (lifr.lifr_addrlen < 0 ||
lifr.lifr_addrlen > IPV6_ABITS) {
syslog(LOG_ERR,
"initifs: ioctl (get subnet prefix) "
"returned invalid prefix length of %d",
lifr.lifr_addrlen);
continue;
}
ifs.int_prefix_length = lifr.lifr_addrlen;
ifs.int_addr = ((struct sockaddr_in6 *)
&lifr.lifr_subnet)->sin6_addr;
}
if (ioctl(iocsoc, SIOCGLIFMETRIC, (char *)&lifr) < 0 ||
lifr.lifr_metric < 0)
ifs.int_metric = 1;
else
ifs.int_metric = lifr.lifr_metric + 1;
if (ioctl(iocsoc, SIOCGLIFINDEX, (char *)&lifr) < 0) {
syslog(LOG_ERR, "initifs: ioctl (get index): %m");
continue;
}
ifs.int_ifindex = lifr.lifr_index;
if (ioctl(iocsoc, SIOCGLIFMTU, (char *)&lifr) < 0) {
syslog(LOG_ERR, "initifs: ioctl (get mtu): %m");
continue;
}
/*
* If the interface's recorded MTU doesn't make sense, use
* IPV6_MIN_MTU instead.
*/
if (lifr.lifr_mtu < IPV6_MIN_MTU)
ifs.int_mtu = IPV6_MIN_MTU;
else
ifs.int_mtu = lifr.lifr_mtu;
if (ifp != NULL) {
/*
* RIP6_IFF_NORTEXCH flag change by itself shouldn't
* cause an if_purge() call, which also purges all the
* routes heard off this interface. So, let's suppress
* changes of RIP6_IFF_NORTEXCH in the following
* comparisons.
*/
if (ifp->int_prefix_length == ifs.int_prefix_length &&
((ifp->int_flags | RIP6_IFF_NORTEXCH) ==
(ifs.int_flags | RIP6_IFF_NORTEXCH)) &&
ifp->int_metric == ifs.int_metric &&
ifp->int_ifindex == ifs.int_ifindex) {
/*
* Now let's make sure we capture the latest
* value of RIP6_IFF_NORTEXCH flag.
*/
if (ifs.int_flags & RIP6_IFF_NORTEXCH)
ifp->int_flags |= RIP6_IFF_NORTEXCH;
else
ifp->int_flags &= ~RIP6_IFF_NORTEXCH;
if (!(ifp->int_flags & RIP6_IFF_POINTOPOINT) &&
IN6_ARE_ADDR_EQUAL(&ifp->int_addr,
&ifs.int_addr))
continue;
if ((ifp->int_flags & RIP6_IFF_POINTOPOINT) &&
IN6_ARE_ADDR_EQUAL(&ifp->int_dstaddr,
&ifs.int_dstaddr))
continue;
}
if_purge(ifp);
if (ifp->int_prefix_length != ifs.int_prefix_length)
netmaskchange = 1;
ifp->int_addr = ifs.int_addr;
ifp->int_dstaddr = ifs.int_dstaddr;
ifp->int_metric = ifs.int_metric;
/*
* If there is an transition from down to up for an
* exisiting interface, increment the counter.
*/
if (!(ifp->int_flags & RIP6_IFF_UP) &&
(ifs.int_flags & RIP6_IFF_UP))
ifp->int_transitions++;
ifp->int_flags |= ifs.int_flags;
ifp->int_prefix_length = ifs.int_prefix_length;
/*
* If the interface index has changed, we may need to
* set up the listen socket again.
*/
if (ifp->int_ifindex != ifs.int_ifindex) {
if (ifp->int_sock != -1) {
resetup_listen_sock(ifp,
ifs.int_ifindex);
}
ifp->int_ifindex = ifs.int_ifindex;
}
ifp->int_mtu = ifs.int_mtu;
} else {
char *cp;
int log_num;
ifp = (struct interface *)
malloc(sizeof (struct interface));
if (ifp == NULL) {
syslog(LOG_ERR, "initifs: out of memory");
return;
}
*ifp = ifs;
ifp->int_name = ifp->int_ifbase = NULL;
ifp->int_name =
(char *)malloc((size_t)strlen(lifr.lifr_name) + 1);
if (ifp->int_name == NULL) {
free(ifp);
syslog(LOG_ERR, "initifs: out of memory");
return;
}
(void) strcpy(ifp->int_name, lifr.lifr_name);
ifp->int_ifbase =
(char *)malloc((size_t)strlen(lifr.lifr_name) + 1);
if (ifp->int_ifbase == NULL) {
free(ifp->int_name);
free(ifp);
syslog(LOG_ERR, "initifs: out of memory");
return;
}
(void) strcpy(ifp->int_ifbase, lifr.lifr_name);
cp = (char *)index(ifp->int_ifbase, IF_SEPARATOR);
if (cp != NULL) {
/*
* Verify that the value following the separator
* is an integer greater than zero (the only
* possible value for a logical interface).
*/
log_num = atoi((char *)(cp + 1));
if (log_num <= 0) {
free(ifp->int_ifbase);
free(ifp->int_name);
free(ifp);
syslog(LOG_ERR,
"initifs: interface name %s could "
"not be parsed", ifp->int_name);
return;
}
*cp = '\0';
} else {
log_num = 0;
}
if (log_num == 0) {
ifp->int_sock =
setup_listen_sock(ifp->int_ifindex);
} else {
ifp->int_sock = -1;
}
ifp->int_next = ifnet;
ifnet = ifp;
traceinit(ifp);
}
addrouteforif(ifp);
changes = _B_TRUE;
}
/*
* Any remaining interfaces that are still marked and which were in an
* up state (RIP6_IFF_UP) need to removed from the routing table.
*/
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
if ((ifp->int_flags & (RIP6_IFF_MARKED | RIP6_IFF_UP)) ==
(RIP6_IFF_MARKED | RIP6_IFF_UP)) {
if_purge(ifp);
ifp->int_flags &= ~RIP6_IFF_MARKED;
changes = _B_TRUE;
}
}
if (netmaskchange)
rtchangeall();
if (supplier & changes)
dynamic_update((struct interface *)NULL);
}
static void
addrouteforif(struct interface *ifp)
{
struct rt_entry *rt;
struct in6_addr *dst;
if (ifp->int_flags & RIP6_IFF_POINTOPOINT)
dst = &ifp->int_dstaddr;
else
dst = &ifp->int_addr;
rt = rtlookup(dst, ifp->int_prefix_length);
if (rt != NULL) {
if (rt->rt_state & RTS_INTERFACE)
return;
rtdelete(rt);
}
rtadd(dst, &ifp->int_addr, ifp->int_prefix_length, ifp->int_metric, 0,
_B_TRUE, ifp);
}
static int
setup_listen_sock(int ifindex)
{
int sock;
struct sockaddr_in6 sin6;
uint_t hops;
struct ipv6_mreq allrouters_mreq;
int on = 1;
int off = 0;
int recvsize;
sock = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock == -1)
goto sock_fail;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_BOUND_IF, (char *)&ifindex,
sizeof (ifindex)) < 0) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: IPV6_BOUND_IF: %m");
goto sock_fail;
}
hops = IPV6_MAX_HOPS;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (char *)&hops,
sizeof (hops)) < 0) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: IPV6_UNICAST_HOPS: %m");
goto sock_fail;
}
if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hops,
sizeof (hops)) < 0) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: IPV6_MULTICAST_HOPS: %m");
goto sock_fail;
}
if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (char *)&off,
sizeof (off)) < 0) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: IPV6_MULTICAST_LOOP: %m");
goto sock_fail;
}
allrouters_mreq.ipv6mr_multiaddr = allrouters_in6;
allrouters_mreq.ipv6mr_interface = ifindex;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
(char *)&allrouters_mreq, sizeof (allrouters_mreq)) < 0) {
if (errno != EADDRINUSE) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: "
"IPV6_JOIN_GROUP: %m");
goto sock_fail;
}
}
if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, (char *)&on,
sizeof (off)) < 0) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: IPV6_RECVHOPLIMIT: %m");
goto sock_fail;
}
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on,
sizeof (on)) < 0) {
syslog(LOG_ERR,
"setup_listen_sock: setsockopt: SO_REUSEADDR: %m");
goto sock_fail;
}
recvsize = RCVBUFSIZ;
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&recvsize,
sizeof (int)) < 0) {
syslog(LOG_ERR, "setup_listen_sock: setsockopt: SO_RCVBUF: %m");
goto sock_fail;
}
bzero((char *)&sin6, sizeof (sin6));
sin6.sin6_family = AF_INET6;
sin6.sin6_port = rip6_port;
if (bind(sock, (struct sockaddr *)&sin6, sizeof (sin6)) < 0) {
syslog(LOG_ERR, "setup_listen_sock: bind: %m");
goto sock_fail;
}
poll_ifs_num++;
if (poll_ifs == NULL) {
poll_ifs = (struct pollfd *)
malloc(max_poll_ifs * sizeof (struct pollfd));
} else if (poll_ifs_num > max_poll_ifs) {
max_poll_ifs *= 2;
poll_ifs = (struct pollfd *)realloc((char *)poll_ifs,
max_poll_ifs * sizeof (struct pollfd));
}
if (poll_ifs == NULL) {
syslog(LOG_ERR, "setup_listen_sock: out of memory");
goto sock_fail;
}
poll_ifs[poll_ifs_num - 1].fd = sock;
poll_ifs[poll_ifs_num - 1].events = POLLIN;
return (sock);
sock_fail:
if (sock > 0)
(void) close(sock);
return (-1);
}
/*
* resetup_listen_sock is primarily used in the case where a tunnel was
* plumbed, unplumbed, then plumbed again. This would cause the binding set by
* IPV6_BOUND_IF to be useless, and sends to the associated socket will be
* transmitted on the wrong interface. resetup_listen_sock
* closes the socket,
* removes the socket from poll_ifs[]
* plugs the hole in poll_ifs[]
* calls setup_listen_sock to set up the socket again
*/
void
resetup_listen_sock(struct interface *ifp, int newindex)
{
int i;
(void) close(ifp->int_sock);
/* Remove socket from poll_ifs[]. */
for (i = poll_ifs_num - 1; i >= 0; i--) {
if (poll_ifs[i].fd == ifp->int_sock) {
poll_ifs[i].fd = 0;
poll_ifs[i].events = 0;
/*
* Remove hole in poll_ifs. Possibly exchange
* poll_ifs[i] with poll_ifs[poll_ifs_num-1].
*/
if (i != poll_ifs_num - 1) {
poll_ifs[i] = poll_ifs[poll_ifs_num - 1];
poll_ifs[poll_ifs_num - 1].fd = 0;
poll_ifs[poll_ifs_num - 1].events = 0;
}
poll_ifs_num--;
/* Now set everything up again. */
ifp->int_sock = setup_listen_sock(newindex);
break;
}
}
}
#!/sbin/sh
#
# 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.
#
# ident "%Z%%M% %I% %E% SMI"
. /lib/svc/share/smf_include.sh
. /lib/svc/share/routing_include.sh
smf_configure_ip || exit $SMF_EXIT_OK
daemon_args=`get_daemon_args $SMF_FMRI`
options="sqp:Ptv"
#
# Handle upgrade - routing/daemon-args property must be mapped to properties
# in routeadm property group. Note the SMF-incompatible -t option is not
# supported, since it requires that in.ripngd run in the foreground.
#
if [ -n "$daemon_args" ]; then
set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
"$options" "q" quiet_mode true false
set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
"$options" "s" supply_routes true false
set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
"$options" "p" udp_port 521
set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
"$options" "P" poison_reverse false true
set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
"$options" "v" verbose true false
set_daemon_nonoption_properties "$SMF_FMRI" "$daemon_args" \
"$options" "log_file"
clear_daemon_args $SMF_FMRI
fi
#
# Assemble arguments to daemon from properties
#
args="`get_daemon_option_from_boolean_property $SMF_FMRI \
quiet_mode -q true`"
args="$args `get_daemon_option_from_boolean_property $SMF_FMRI \
supply_routes -s true`"
args="$args `get_daemon_option_from_property $SMF_FMRI udp_port p 521`"
args="$args `get_daemon_option_from_boolean_property $SMF_FMRI \
poison_reverse -P false`"
args="$args `get_daemon_option_from_boolean_property $SMF_FMRI \
verbose -v true`"
args="$args `get_daemon_nonoption_property $SMF_FMRI log_file`"
/usr/lib/inet/in.ripngd $args
[ "$?" = 0 ] || exit $SMF_EXIT_ERR_FATAL
exit "$SMF_EXIT_OK"
/*
* 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 1999 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing table management daemon.
*/
/*
* Routing table structure; differs a bit from kernel tables.
*/
struct rthash {
struct rt_entry *rt_forw;
struct rt_entry *rt_back;
};
struct rt_entry {
struct rt_entry *rt_forw;
struct rt_entry *rt_back;
uint_t rt_hash; /* for net or host */
struct in6_addr rt_dst; /* match value */
struct in6_addr rt_router; /* who to forward to */
int rt_prefix_length; /* bits in prefix */
struct interface *rt_ifp; /* interface to take */
uint_t rt_flags; /* kernel flags */
uint_t rt_state; /* see below */
int rt_timer; /* for invalidation */
int rt_metric; /* cost of route including the if */
int rt_tag; /* route tag attribute */
};
#define ROUTEHASHSIZ 32 /* must be a power of 2 */
#define ROUTEHASHMASK (ROUTEHASHSIZ - 1)
/*
* "State" of routing table entry.
*/
#define RTS_CHANGED 0x1 /* route has been altered recently */
#define RTS_INTERFACE 0x2 /* route is for network interface */
#define RTS_PRIVATE 0x4 /* route is private, do not advertise */
/*
* XXX This is defined in <inet/ip.h> (but should be defined in <netinet/ip6.h>
* for completeness).
*/
#define IPV6_ABITS 128 /* Number of bits in an IPv6 address */
extern struct rthash *net_hashes[IPV6_ABITS + 1];
extern void rtadd(struct in6_addr *, struct in6_addr *, int, int, int,
boolean_t, struct interface *);
extern void rtchange(struct rt_entry *, struct in6_addr *, short,
struct interface *);
extern void rtchangeall(void);
extern void rtcreate_prefix(struct in6_addr *, struct in6_addr *, int);
extern void rtdelete(struct rt_entry *);
extern void rtdown(struct rt_entry *);
extern void rtdump(void);
extern struct rt_entry *rtlookup(struct in6_addr *, int);
extern void rtpurgeif(struct interface *);
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing Table Management Daemon
*/
#include "defs.h"
boolean_t install = _B_TRUE; /* update kernel routing table */
struct rthash *net_hashes[IPV6_ABITS + 1];
/*
* Size of routing socket message used by in.ripngd which includes the header,
* space for the RTA_DST, RTA_GATEWAY and RTA_NETMASK (each a sockaddr_in6)
* plus space for the RTA_IFP (a sockaddr_dl).
*/
#define RIPNG_RTM_MSGLEN sizeof (struct rt_msghdr) + \
sizeof (struct sockaddr_in6) + \
sizeof (struct sockaddr_in6) + \
sizeof (struct sockaddr_in6) + \
sizeof (struct sockaddr_dl)
static int rtmseq; /* rtm_seq sequence number */
static int rtsock; /* Routing socket */
static struct rt_msghdr *rt_msg; /* Routing socket message */
static struct sockaddr_in6 *rta_dst; /* RTA_DST sockaddr */
static struct sockaddr_in6 *rta_gateway; /* RTA_GATEWAY sockaddr */
static struct sockaddr_in6 *rta_netmask; /* RTA_NETMASK sockaddr */
static struct sockaddr_dl *rta_ifp; /* RTA_IFP sockaddr */
/* simulate vax insque and remque instructions. */
typedef struct vq {
caddr_t fwd, back;
} vq_t;
#define insque(e, p) ((vq_t *)(e))->back = (caddr_t)(p); \
((vq_t *)(e))->fwd = \
(caddr_t)((vq_t *)((vq_t *)(p))->fwd); \
((vq_t *)((vq_t *)(p))->fwd)->back = (caddr_t)(e); \
((vq_t *)(p))->fwd = (caddr_t)(e);
#define remque(e) ((vq_t *)((vq_t *)(e))->back)->fwd = \
(caddr_t)((vq_t *)(e))->fwd; \
((vq_t *)((vq_t *)(e))->fwd)->back = \
(caddr_t)((vq_t *)(e))->back; \
((vq_t *)(e))->fwd = NULL; \
((vq_t *)(e))->back = NULL;
static void
log_change(int level, struct rt_entry *orig, struct rt_entry *new)
{
char buf1[INET6_ADDRSTRLEN];
char buf2[INET6_ADDRSTRLEN];
char buf3[INET6_ADDRSTRLEN];
(void) inet_ntop(AF_INET6, (void *) &new->rt_dst, buf1, sizeof (buf1));
(void) inet_ntop(AF_INET6, (void *) &orig->rt_router, buf2,
sizeof (buf2));
(void) inet_ntop(AF_INET6, (void *) &new->rt_router, buf3,
sizeof (buf3));
syslog(level, "\tdst %s from gw %s if %s to gw %s if %s metric %d",
buf1, buf2,
(orig->rt_ifp != NULL && orig->rt_ifp->int_name != NULL) ?
orig->rt_ifp->int_name : "(noname)",
buf3,
(new->rt_ifp != NULL && new->rt_ifp->int_name != NULL) ?
new->rt_ifp->int_name : "(noname)", new->rt_metric);
}
static void
log_single(int level, struct rt_entry *rt)
{
char buf1[INET6_ADDRSTRLEN];
char buf2[INET6_ADDRSTRLEN];
(void) inet_ntop(AF_INET6, (void *)&rt->rt_dst, buf1, sizeof (buf1));
(void) inet_ntop(AF_INET6, (void *)&rt->rt_router, buf2, sizeof (buf2));
syslog(level, "\tdst %s gw %s if %s metric %d",
buf1, buf2,
(rt->rt_ifp != NULL && rt->rt_ifp->int_name != NULL) ?
rt->rt_ifp->int_name : "(noname)",
rt->rt_metric);
}
/*
* Computes a hash by XOR-ing the (up to sixteen) octets that make up an IPv6
* address. This function assumes that that there are no one-bits in the
* address beyond the prefix length.
*/
static uint8_t
rthash(struct in6_addr *dst, int prefix_length)
{
uint8_t val = 0;
int i;
for (i = 0; prefix_length > 0; prefix_length -= 8, i++)
val ^= dst->s6_addr[i];
return (val);
}
/*
* Given a prefix length, fill in the struct in6_addr representing an IPv6
* netmask.
*/
static void
rtmask_to_bits(uint_t prefix_length, struct in6_addr *prefix)
{
uint_t mask = 0xff;
int i;
bzero((caddr_t)prefix, sizeof (struct in6_addr));
for (i = 0; prefix_length >= 8; prefix_length -= 8, i++)
prefix->s6_addr[i] = 0xff;
mask = (mask << (8 - prefix_length));
if (mask != 0)
prefix->s6_addr[i] = mask;
}
void
rtcreate_prefix(struct in6_addr *p1, struct in6_addr *dst, int bits)
{
uchar_t mask;
int j;
for (j = 0; bits >= 8; bits -= 8, j++)
dst->s6_addr[j] = p1->s6_addr[j];
if (bits != 0) {
mask = 0xff << (8 - bits);
dst->s6_addr[j] = p1->s6_addr[j] & mask;
j++;
}
for (; j < 16; j++)
dst->s6_addr[j] = 0;
}
/*
* Lookup dst in the tables for an exact match.
*/
struct rt_entry *
rtlookup(struct in6_addr *dst, int prefix_length)
{
struct rt_entry *rt;
struct rthash *rh;
uint_t hash;
if (net_hashes[prefix_length] == NULL)
return (NULL);
hash = rthash(dst, prefix_length);
rh = &net_hashes[prefix_length][hash & ROUTEHASHMASK];
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
if (rt->rt_hash != hash)
continue;
if (IN6_ARE_ADDR_EQUAL(&rt->rt_dst, dst) &&
rt->rt_prefix_length == prefix_length)
return (rt);
}
return (NULL);
}
/*
* Given an IPv6 prefix (destination and prefix length), a gateway, an
* interface name and route flags, send down the requested command returning
* the return value and errno (in the case of error) from the write() on the
* routing socket.
*/
static int
rtcmd(uchar_t type, struct in6_addr *dst, struct in6_addr *gateway,
uint_t prefix_length, char *name, int flags)
{
int rlen;
rta_ifp->sdl_index = if_nametoindex(name);
if (rta_ifp->sdl_index == 0)
return (-1);
rta_dst->sin6_addr = *dst;
rta_gateway->sin6_addr = *gateway;
rtmask_to_bits(prefix_length, &rta_netmask->sin6_addr);
rt_msg->rtm_type = type;
rt_msg->rtm_flags = flags;
rt_msg->rtm_seq = ++rtmseq;
rlen = write(rtsock, rt_msg, RIPNG_RTM_MSGLEN);
if (rlen >= 0 && rlen < RIPNG_RTM_MSGLEN) {
syslog(LOG_ERR,
"rtcmd: write to routing socket got only %d for rlen\n",
rlen);
}
return (rlen);
}
void
rtadd(struct in6_addr *dst, struct in6_addr *gate, int prefix_length,
int metric, int tag, boolean_t ifroute, struct interface *ifp)
{
struct rt_entry *rt;
struct rthash *rh;
uint_t hash;
struct in6_addr pdst;
int rlen;
if (metric >= HOPCNT_INFINITY)
return;
if (net_hashes[prefix_length] == NULL) {
struct rthash *trh;
rh = (struct rthash *)
calloc(ROUTEHASHSIZ, sizeof (struct rt_entry));
if (rh == NULL)
return;
for (trh = rh; trh < &rh[ROUTEHASHSIZ]; trh++)
trh->rt_forw = trh->rt_back = (struct rt_entry *)trh;
net_hashes[prefix_length] = rh;
}
rtcreate_prefix(dst, &pdst, prefix_length);
hash = rthash(&pdst, prefix_length);
rh = &net_hashes[prefix_length][hash & ROUTEHASHMASK];
rt = (struct rt_entry *)malloc(sizeof (*rt));
if (rt == NULL) {
/*
* In the event of an allocation failure, log the error and
* continue since on the next update another attempt will be
* made.
*/
syslog(LOG_ERR, "rtadd: malloc: %m");
return;
}
rt->rt_hash = hash;
rt->rt_dst = pdst;
rt->rt_prefix_length = prefix_length;
rt->rt_router = *gate;
rt->rt_metric = metric;
rt->rt_tag = tag;
rt->rt_timer = 0;
rt->rt_flags = RTF_UP;
if (prefix_length == IPV6_ABITS)
rt->rt_flags |= RTF_HOST;
rt->rt_state = RTS_CHANGED;
if (ifroute) {
rt->rt_state |= RTS_INTERFACE;
if (ifp->int_flags & RIP6_IFF_PRIVATE)
rt->rt_state |= RTS_PRIVATE;
} else {
rt->rt_flags |= RTF_GATEWAY;
}
rt->rt_ifp = ifp;
insque(rt, rh);
TRACE_ACTION("ADD", rt);
/*
* If the RTM_ADD fails because the gateway is unreachable
* from this host, discard the entry. This should never
* happen.
*/
if (install && (rt->rt_state & RTS_INTERFACE) == 0) {
rlen = rtcmd(RTM_ADD, &rt->rt_dst, &rt->rt_router,
prefix_length, ifp->int_name, rt->rt_flags);
if (rlen < 0) {
if (errno != EEXIST) {
syslog(LOG_ERR, "rtadd: RTM_ADD: %m");
log_single(LOG_ERR, rt);
}
if (errno == ENETUNREACH) {
TRACE_ACTION("DELETE", rt);
remque(rt);
free((char *)rt);
}
} else if (rlen < RIPNG_RTM_MSGLEN) {
log_single(LOG_ERR, rt);
}
}
}
/*
* Handle the case when the metric changes but the gateway is the same (or the
* interface index associated with the gateway changes), or when both gateway
* and metric changes, or when only the gateway changes but the existing route
* is more than one-half of EXPIRE_TIME in age. Note that routes with metric >=
* HOPCNT_INFINITY are not in the kernel.
*/
void
rtchange(struct rt_entry *rt, struct in6_addr *gate, short metric,
struct interface *ifp)
{
boolean_t dokern = _B_FALSE;
boolean_t dokerndelete;
boolean_t metricchanged = _B_FALSE;
int oldmetric;
struct rt_entry oldroute;
int rlen;
if (metric >= HOPCNT_INFINITY) {
rtdown(rt);
return;
}
if (!IN6_ARE_ADDR_EQUAL(&rt->rt_router, gate) || rt->rt_ifp != ifp)
dokern = _B_TRUE;
oldmetric = rt->rt_metric;
if (oldmetric >= HOPCNT_INFINITY)
dokerndelete = _B_FALSE;
else
dokerndelete = dokern;
if (metric != rt->rt_metric)
metricchanged = _B_TRUE;
rt->rt_timer = 0;
if (dokern || metricchanged) {
TRACE_ACTION("CHANGE FROM", rt);
if ((rt->rt_state & RTS_INTERFACE) && metric != 0) {
rt->rt_state &= ~RTS_INTERFACE;
if (rt->rt_ifp != NULL) {
syslog(LOG_ERR,
"rtchange: changing route from "
"interface %s (timed out)",
(rt->rt_ifp->int_name != NULL) ?
rt->rt_ifp->int_name : "(noname)");
} else {
syslog(LOG_ERR,
"rtchange: "
"changing route no interface for route");
}
}
if (dokern) {
oldroute = *rt;
rt->rt_router = *gate;
rt->rt_ifp = ifp;
}
rt->rt_metric = metric;
if (!(rt->rt_state & RTS_INTERFACE))
rt->rt_flags |= RTF_GATEWAY;
else
rt->rt_flags &= ~RTF_GATEWAY;
rt->rt_state |= RTS_CHANGED;
TRACE_ACTION("CHANGE TO", rt);
}
if (install && (rt->rt_state & RTS_INTERFACE) == 0) {
if (dokerndelete) {
rlen = rtcmd(RTM_ADD, &rt->rt_dst, &rt->rt_router,
rt->rt_prefix_length, rt->rt_ifp->int_name,
rt->rt_flags);
if (rlen < 0) {
if (errno != EEXIST) {
syslog(LOG_ERR,
"rtchange: RTM_ADD: %m");
log_change(LOG_ERR, rt,
(struct rt_entry *)&oldroute);
}
} else if (rlen < RIPNG_RTM_MSGLEN) {
log_change(LOG_ERR, rt,
(struct rt_entry *)&oldroute);
}
rlen = rtcmd(RTM_DELETE, &oldroute.rt_dst,
&oldroute.rt_router, oldroute.rt_prefix_length,
oldroute.rt_ifp->int_name, oldroute.rt_flags);
if (rlen < 0) {
syslog(LOG_ERR, "rtchange: RTM_DELETE: %m");
log_change(LOG_ERR, rt,
(struct rt_entry *)&oldroute);
} else if (rlen < RIPNG_RTM_MSGLEN) {
log_change(LOG_ERR, rt,
(struct rt_entry *)&oldroute);
}
} else if (dokern || oldmetric >= HOPCNT_INFINITY) {
rlen = rtcmd(RTM_ADD, &rt->rt_dst, &rt->rt_router,
rt->rt_prefix_length, ifp->int_name, rt->rt_flags);
if (rlen < 0 && errno != EEXIST) {
syslog(LOG_ERR, "rtchange: RTM_ADD: %m");
log_change(LOG_ERR, rt,
(struct rt_entry *)&oldroute);
} else if (rlen < RIPNG_RTM_MSGLEN) {
log_change(LOG_ERR, rt,
(struct rt_entry *)&oldroute);
}
}
}
}
void
rtdown(struct rt_entry *rt)
{
int rlen;
if (rt->rt_metric != HOPCNT_INFINITY) {
TRACE_ACTION("DELETE", rt);
if (install && (rt->rt_state & RTS_INTERFACE) == 0) {
rlen = rtcmd(RTM_DELETE, &rt->rt_dst,
&rt->rt_router, rt->rt_prefix_length,
rt->rt_ifp->int_name, rt->rt_flags);
if (rlen < 0) {
syslog(LOG_ERR, "rtdown: RTM_DELETE: %m");
log_single(LOG_ERR, rt);
} else if (rlen < RIPNG_RTM_MSGLEN) {
log_single(LOG_ERR, rt);
}
}
rt->rt_metric = HOPCNT_INFINITY;
rt->rt_state |= RTS_CHANGED;
}
if (rt->rt_timer < EXPIRE_TIME)
rt->rt_timer = EXPIRE_TIME;
}
void
rtdelete(struct rt_entry *rt)
{
if (rt->rt_state & RTS_INTERFACE) {
if (rt->rt_ifp != NULL) {
syslog(LOG_ERR,
"rtdelete: "
"deleting route to interface %s (timed out)",
(rt->rt_ifp->int_name != NULL) ?
rt->rt_ifp->int_name : "(noname)");
log_single(LOG_ERR, rt);
}
}
rtdown(rt);
remque(rt);
free((char *)rt);
}
/*
* Mark all the routes heard off a particular interface "down". Unlike the
* routes managed by in.routed, all of these routes have an interface associated
* with them.
*/
void
rtpurgeif(struct interface *ifp)
{
struct rthash *rh;
struct rt_entry *rt;
int i;
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i];
rh < &net_hashes[i][ROUTEHASHSIZ]; rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
if (rt->rt_ifp == ifp) {
rtdown(rt);
rt->rt_ifp = NULL;
rt->rt_state &= ~RTS_INTERFACE;
}
}
}
}
}
/*
* Called when the subnetmask has changed on one or more interfaces.
* Re-evaluates all non-interface routes by doing a rtchange so that
* routes that were believed to be host routes before the netmask change
* can be converted to network routes and vice versa.
*/
void
rtchangeall(void)
{
struct rthash *rh;
struct rt_entry *rt;
int i;
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i];
rh < &net_hashes[i][ROUTEHASHSIZ]; rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
if ((rt->rt_state & RTS_INTERFACE) == 0) {
rtchange(rt, &rt->rt_router,
rt->rt_metric, rt->rt_ifp);
}
}
}
}
}
static void
rtdumpentry(FILE *fp, struct rt_entry *rt)
{
char buf1[INET6_ADDRSTRLEN];
static struct bits {
ulong_t t_bits;
char *t_name;
} flagbits[] = {
/* BEGIN CSTYLED */
{ RTF_UP, "UP" },
{ RTF_GATEWAY, "GATEWAY" },
{ RTF_HOST, "HOST" },
{ 0, NULL }
/* END CSTYLED */
}, statebits[] = {
/* BEGIN CSTYLED */
{ RTS_INTERFACE, "INTERFACE" },
{ RTS_CHANGED, "CHANGED" },
{ RTS_PRIVATE, "PRIVATE" },
{ 0, NULL }
/* END CSTYLED */
};
struct bits *p;
boolean_t first;
char c;
(void) fprintf(fp, "prefix %s/%d ",
inet_ntop(AF_INET6, (void *)&rt->rt_dst, buf1, sizeof (buf1)),
rt->rt_prefix_length);
(void) fprintf(fp, "via %s metric %d timer %d",
inet_ntop(AF_INET6, (void *)&rt->rt_router, buf1, sizeof (buf1)),
rt->rt_metric, rt->rt_timer);
if (rt->rt_ifp != NULL) {
(void) fprintf(fp, " if %s",
(rt->rt_ifp->int_name != NULL) ?
rt->rt_ifp->int_name : "(noname)");
}
(void) fprintf(fp, " state");
c = ' ';
for (first = _B_TRUE, p = statebits; p->t_bits > 0; p++) {
if ((rt->rt_state & p->t_bits) == 0)
continue;
(void) fprintf(fp, "%c%s", c, p->t_name);
if (first) {
c = '|';
first = _B_FALSE;
}
}
if (first)
(void) fprintf(fp, " 0");
if (rt->rt_flags & (RTF_UP | RTF_GATEWAY)) {
c = ' ';
for (first = _B_TRUE, p = flagbits; p->t_bits > 0; p++) {
if ((rt->rt_flags & p->t_bits) == 0)
continue;
(void) fprintf(fp, "%c%s", c, p->t_name);
if (first) {
c = '|';
first = _B_FALSE;
}
}
}
(void) putc('\n', fp);
(void) fflush(fp);
}
static void
rtdump2(FILE *fp)
{
struct rthash *rh;
struct rt_entry *rt;
int i;
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i];
rh < &net_hashes[i][ROUTEHASHSIZ]; rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
rtdumpentry(fp, rt);
}
}
}
}
void
rtdump(void)
{
if (ftrace != NULL)
rtdump2(ftrace);
else
rtdump2(stderr);
}
/*
* Create a routing socket for sending RTM_ADD and RTM_DELETE messages and
* initialize the routing socket message header and as much of the sockaddrs
* as possible.
*/
void
setup_rtsock(void)
{
char *cp;
int off = 0;
rtsock = socket(PF_ROUTE, SOCK_RAW, AF_INET6);
if (rtsock < 0) {
syslog(LOG_ERR, "setup_rtsock: socket: %m");
exit(EXIT_FAILURE);
}
/* We don't want to listen to our own messages */
if (setsockopt(rtsock, SOL_SOCKET, SO_USELOOPBACK, (char *)&off,
sizeof (off)) < 0) {
syslog(LOG_ERR, "setup_rtsock: setsockopt: SO_USELOOPBACK: %m");
exit(EXIT_FAILURE);
}
/*
* Allocate storage for the routing socket message.
*/
rt_msg = (struct rt_msghdr *)malloc(RIPNG_RTM_MSGLEN);
if (rt_msg == NULL) {
syslog(LOG_ERR, "setup_rtsock: malloc: %m");
exit(EXIT_FAILURE);
}
/*
* Initialize the routing socket message by zero-filling it and then
* setting the fields where are constant through the lifetime of the
* process.
*/
bzero(rt_msg, RIPNG_RTM_MSGLEN);
rt_msg->rtm_msglen = RIPNG_RTM_MSGLEN;
rt_msg->rtm_version = RTM_VERSION;
rt_msg->rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_IFP;
rt_msg->rtm_pid = getpid();
if (rt_msg->rtm_pid < 0) {
syslog(LOG_ERR, "setup_rtsock: getpid: %m");
exit(EXIT_FAILURE);
}
/*
* Initialize the constant portion of the RTA_DST sockaddr.
*/
cp = (char *)rt_msg + sizeof (struct rt_msghdr);
rta_dst = (struct sockaddr_in6 *)cp;
rta_dst->sin6_family = AF_INET6;
/*
* Initialize the constant portion of the RTA_GATEWAY sockaddr.
*/
cp += sizeof (struct sockaddr_in6);
rta_gateway = (struct sockaddr_in6 *)cp;
rta_gateway->sin6_family = AF_INET6;
/*
* Initialize the constant portion of the RTA_NETMASK sockaddr.
*/
cp += sizeof (struct sockaddr_in6);
rta_netmask = (struct sockaddr_in6 *)cp;
rta_netmask->sin6_family = AF_INET6;
/*
* Initialize the constant portion of the RTA_IFP sockaddr.
*/
cp += sizeof (struct sockaddr_in6);
rta_ifp = (struct sockaddr_dl *)cp;
rta_ifp->sdl_family = AF_LINK;
}
/*
* 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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing Table Management Daemon
*/
#include "defs.h"
int supplyinterval; /* current supply interval */
/*
* Timer routine. Performs routing information supply
* duties and manages timers on routing table entries.
* Management of the RTS_CHANGED bit assumes that we multicast
* each time called.
*/
void
timer(void)
{
struct rthash *rh;
struct rt_entry *rt;
boolean_t timetomulticast = _B_FALSE;
int i;
static int iftime; /* interface timer */
static int mtime; /* periodic mcast supply timer */
static int alarmtime = 0; /* time elapsed since last call */
int mintime; /* tracks when next timer will expire */
/*
* On the initial call to timer(), the various times that are kept track
* of need to be initialized. After initializing everything, "remember"
* (via a static) how long until the next timer expires.
*/
if (alarmtime == 0) {
supplyinterval = GET_RANDOM(MIN_SUPPLY_TIME, MAX_SUPPLY_TIME);
iftime = 0;
mtime = supplyinterval;
alarmtime = supplyinterval;
(void) alarm(alarmtime);
return;
}
/*
* Initialize mintime to a suitable "large" value and then compare it to
* other times in the future to determine which event will occur next.
*/
mintime = INT_MAX;
(void) sighold(SIGHUP);
(void) sighold(SIGUSR1);
(void) sighold(SIGUSR2);
iftime += alarmtime;
if (iftime >= CHECK_INTERVAL) {
initifs();
iftime = 0;
}
mintime = min(mintime, CHECK_INTERVAL - iftime);
mtime += alarmtime;
if (mtime >= supplyinterval) {
if (supplier)
timetomulticast = _B_TRUE;
mtime = 0;
supplyinterval = GET_RANDOM(MIN_SUPPLY_TIME, MAX_SUPPLY_TIME);
}
mintime = min(mintime, supplyinterval - mtime);
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i];
rh < &net_hashes[i][ROUTEHASHSIZ]; rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
/*
* We don't advance time on a routing entry for
* an interface because we catch
* interfaces going up and down in initifs.
*/
rt->rt_state &= ~RTS_CHANGED;
if ((rt->rt_state & RTS_INTERFACE) != 0)
continue;
rt->rt_timer += alarmtime;
if (rt->rt_timer >= GARBAGE_TIME) {
rt = rt->rt_back;
rtdelete(rt->rt_forw);
continue;
}
if (rt->rt_timer >= EXPIRE_TIME) {
rtdown(rt);
mintime = min(mintime,
GARBAGE_TIME - rt->rt_timer);
} else {
mintime = min(mintime,
EXPIRE_TIME - rt->rt_timer);
}
}
}
}
if (timetomulticast) {
supplyall(&allrouters, 0, (struct interface *)NULL, _B_TRUE);
(void) gettimeofday(&now, (struct timezone *)NULL);
lastmcast = now;
lastfullupdate = now;
needupdate = _B_FALSE; /* cancel any pending dynamic update */
nextmcast.tv_sec = 0;
}
(void) sigrelse(SIGUSR2);
(void) sigrelse(SIGUSR1);
(void) sigrelse(SIGHUP);
/*
* "Remember" (via a static) how long until the next timer expires.
*/
alarmtime = mintime;
(void) alarm(alarmtime);
}
/*
* On SIGTERM, let everyone know we're going away.
*/
void
term(void)
{
struct rthash *rh;
struct rt_entry *rt;
int i;
if (!supplier)
exit(EXIT_SUCCESS);
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i]; rh < &net_hashes[i][ROUTEHASHSIZ];
rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
rt->rt_metric = HOPCNT_INFINITY;
}
}
}
supplyall(&allrouters, 0, (struct interface *)NULL, _B_TRUE);
(void) unlink(PATH_PID);
exit(EXIT_SUCCESS);
}
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing Table Management Daemon
*/
#include "defs.h"
#define NRECORDS 50 /* size of circular trace buffer */
boolean_t tracepackets; /* watch packets as they go by */
int tracing; /* bitmask: */
FILE *ftrace; /* output trace file */
static int iftraceinit(struct interface *ifp, struct ifdebug *ifd);
static void dumpif(FILE *fp, struct interface *ifp);
static void dumptrace(FILE *fp, char *dir, struct ifdebug *ifd);
void
traceinit(struct interface *ifp)
{
if (iftraceinit(ifp, &ifp->int_input) &&
iftraceinit(ifp, &ifp->int_output))
return;
tracing = 0;
(void) fprintf(stderr, "traceinit: can't init %s\n",
(ifp->int_name != NULL) ? ifp->int_name : "(noname)");
}
static int
iftraceinit(struct interface *ifp, struct ifdebug *ifd)
{
struct iftrace *t;
ifd->ifd_records = (struct iftrace *)
malloc((size_t)NRECORDS * sizeof (struct iftrace));
if (ifd->ifd_records == NULL)
return (0);
ifd->ifd_front = ifd->ifd_records;
ifd->ifd_count = 0;
for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) {
t->ift_size = 0;
t->ift_packet = NULL;
}
ifd->ifd_if = ifp;
return (1);
}
void
traceon(char *file)
{
struct stat stbuf;
if (ftrace != NULL)
return;
if (stat(file, &stbuf) >= 0 && (stbuf.st_mode & S_IFMT) != S_IFREG)
return;
ftrace = fopen(file, "a");
if (ftrace == NULL)
return;
(void) dup2(fileno(ftrace), 1);
(void) dup2(fileno(ftrace), 2);
}
void
traceonfp(FILE *fp)
{
if (ftrace != NULL)
return;
ftrace = fp;
if (ftrace == NULL)
return;
(void) dup2(fileno(ftrace), 1);
(void) dup2(fileno(ftrace), 2);
}
void
trace(struct ifdebug *ifd, struct sockaddr_in6 *who, char *p, int len, int m)
{
struct iftrace *t;
if (ifd->ifd_records == 0)
return;
t = ifd->ifd_front++;
if (ifd->ifd_front >= ifd->ifd_records + NRECORDS)
ifd->ifd_front = ifd->ifd_records;
if (ifd->ifd_count < NRECORDS)
ifd->ifd_count++;
if (t->ift_size > 0 && t->ift_size < len && t->ift_packet != NULL) {
free(t->ift_packet);
t->ift_packet = NULL;
}
(void) time(&t->ift_stamp);
t->ift_who = *who;
if (len > 0 && t->ift_packet == NULL) {
t->ift_packet = (char *)malloc((size_t)len);
if (t->ift_packet == NULL)
len = 0;
}
if (len > 0)
bcopy(p, t->ift_packet, len);
t->ift_size = len;
t->ift_metric = m;
}
void
traceaction(FILE *fp, char *action, struct rt_entry *rt)
{
static struct bits {
ulong_t t_bits;
char *t_name;
} flagbits[] = {
/* BEGIN CSTYLED */
{ RTF_UP, "UP" },
{ RTF_GATEWAY, "GATEWAY" },
{ RTF_HOST, "HOST" },
{ 0, NULL }
/* END CSTYLED */
}, statebits[] = {
/* BEGIN CSTYLED */
{ RTS_INTERFACE, "INTERFACE" },
{ RTS_CHANGED, "CHANGED" },
{ RTS_PRIVATE, "PRIVATE" },
{ 0, NULL }
/* END CSTYLED */
};
struct bits *p;
boolean_t first;
char c;
time_t t;
if (fp == NULL)
return;
(void) time(&t);
(void) fprintf(fp, "%.15s %s ", ctime(&t) + 4, action);
if (rt != NULL) {
char buf1[INET6_ADDRSTRLEN];
(void) fprintf(fp, "prefix %s/%d ",
inet_ntop(AF_INET6, (void *)&rt->rt_dst, buf1,
sizeof (buf1)),
rt->rt_prefix_length);
(void) fprintf(fp, "via %s metric %d",
inet_ntop(AF_INET6, (void *)&rt->rt_router, buf1,
sizeof (buf1)),
rt->rt_metric);
if (rt->rt_ifp != NULL) {
(void) fprintf(fp, " if %s",
(rt->rt_ifp->int_name != NULL) ?
rt->rt_ifp->int_name : "(noname)");
}
(void) fprintf(fp, " state");
c = ' ';
for (first = _B_TRUE, p = statebits; p->t_bits > 0; p++) {
if ((rt->rt_state & p->t_bits) == 0)
continue;
(void) fprintf(fp, "%c%s", c, p->t_name);
if (first) {
c = '|';
first = _B_FALSE;
}
}
if (first)
(void) fprintf(fp, " 0");
if (rt->rt_flags & (RTF_UP | RTF_GATEWAY)) {
c = ' ';
for (first = _B_TRUE, p = flagbits; p->t_bits > 0;
p++) {
if ((rt->rt_flags & p->t_bits) == 0)
continue;
(void) fprintf(fp, "%c%s", c, p->t_name);
if (first) {
c = '|';
first = _B_FALSE;
}
}
}
}
(void) putc('\n', fp);
if (!tracepackets && rt != NULL && rt->rt_ifp != NULL)
dumpif(fp, rt->rt_ifp);
(void) fflush(fp);
}
static void
dumpif(FILE *fp, struct interface *ifp)
{
if (ifp->int_input.ifd_count != 0 || ifp->int_output.ifd_count != 0) {
(void) fprintf(fp, "*** Packet history for interface %s ***\n",
(ifp->int_name != NULL) ? ifp->int_name : "(noname)");
dumptrace(fp, "to", &ifp->int_output);
dumptrace(fp, "from", &ifp->int_input);
(void) fprintf(fp, "*** end packet history ***\n");
}
(void) fflush(fp);
}
static void
dumptrace(FILE *fp, char *dir, struct ifdebug *ifd)
{
struct iftrace *t;
char *cp = (strcmp(dir, "to") != 0) ? "Output" : "Input";
if (ifd->ifd_front == ifd->ifd_records &&
ifd->ifd_front->ift_size == 0) {
(void) fprintf(fp, "%s: no packets.\n", cp);
(void) fflush(fp);
return;
}
(void) fprintf(fp, "%s trace:\n", cp);
t = ifd->ifd_front - ifd->ifd_count;
if (t < ifd->ifd_records)
t += NRECORDS;
for (; ifd->ifd_count; ifd->ifd_count--, t++) {
if (t >= ifd->ifd_records + NRECORDS)
t = ifd->ifd_records;
if (t->ift_size == 0)
continue;
(void) fprintf(fp, "%.24s: metric=%d\n", ctime(&t->ift_stamp),
t->ift_metric);
dumppacket(fp, dir, (struct sockaddr_in6 *)&t->ift_who,
t->ift_packet, t->ift_size);
}
}
/*ARGSUSED*/
void
dumppacket(FILE *fp, char *dir, struct sockaddr_in6 *who, char *cp, int size)
{
/* XXX Output contents of the RIP packet */
}
/*
* 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 1999 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Routing table management daemon.
*/
/*
* Trace record format.
*/
struct iftrace {
time_t ift_stamp; /* time stamp */
struct sockaddr_in6 ift_who; /* from/to */
char *ift_packet; /* pointer to packet */
int ift_size; /* size of packet */
int ift_metric; /* metric on associated metric */
};
/*
* Per interface packet tracing buffers. An incoming and
* outgoing circular buffer of packets is maintained, per
* interface, for debugging. Buffers are dumped whenever
* an interface is marked down.
*/
struct ifdebug {
struct iftrace *ifd_records; /* array of trace records */
struct iftrace *ifd_front; /* next empty trace record */
int ifd_count; /* number of unprinted records */
struct interface *ifd_if; /* for locating stuff */
};
/*
* Packet tracing stuff.
*/
extern FILE *ftrace;
extern boolean_t tracepackets;
extern int tracing;
#define ACTION_BIT 0x0001
#define INPUT_BIT 0x0002
#define OUTPUT_BIT 0x0004
#define TRACE_ACTION(action, route) { \
if (tracing & ACTION_BIT) \
traceaction(ftrace, (action), (route)); \
}
#define TRACE_INPUT(ifp, src, size) { \
if ((tracing & INPUT_BIT) && ((ifp) != NULL)) { \
trace(&(ifp)->int_input, (src), packet, (size), \
(ifp)->int_metric); \
} \
if (tracepackets) { \
dumppacket(stdout, "from", (struct sockaddr_in6 *)(src), \
packet, (size)); \
} \
}
#define TRACE_OUTPUT(ifp, dst, size) { \
if ((tracing & OUTPUT_BIT) && ((ifp) != NULL)) { \
trace(&(ifp)->int_output, (dst), packet, (size), \
(ifp)->int_metric); \
} \
if (tracepackets) { \
dumppacket(stdout, "to", (struct sockaddr_in6 *)(dst), \
packet, (size)); \
} \
}
extern void dumppacket(FILE *, char *, struct sockaddr_in6 *, char *, int);
extern void trace(struct ifdebug *, struct sockaddr_in6 *, char *, int,
int);
extern void traceaction(FILE *, char *, struct rt_entry *);
extern void traceinit(struct interface *);
extern void traceon(char *);
extern void traceonfp(FILE *);
|