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
|
/*
* System-dependent procedures for pppd under Solaris 2.x (SunOS 5.x).
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies.
*
* SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*/
#include <limits.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <netdb.h>
#include <termios.h>
#include <signal.h>
#include <string.h>
#include <stropts.h>
#include <utmpx.h>
#include <sys/types.h>
#include <sys/ioccom.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sysmacros.h>
#include <sys/systeminfo.h>
#include <sys/stat.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/route.h>
#include <net/ppp_defs.h>
#include <net/pppio.h>
#include <net/if_types.h>
#include <net/if_dl.h>
#include <netinet/in.h>
#include <sys/tihdr.h>
#include <inet/mib2.h>
#include <inet/ip.h>
#include <sys/ethernet.h>
#include <sys/ser_sync.h>
#include <libdlpi.h>
#include <arpa/inet.h>
#include "pppd.h"
#include "fsm.h"
#include "lcp.h"
#include "ipcp.h"
#ifdef INET6
#include "ipv6cp.h"
#endif /* INET6 */
#include "ccp.h"
#define PPPSTRTIMOUT 1 /* Timeout in seconds for ioctl */
#define MAX_POLLFDS 32
#define NMODULES 32
#ifndef MAXIFS
#define MAXIFS 256
#endif /* MAXIFS */
#ifdef INET6
#define _IN6_LLX_FROM_EUI64(l, s, eui64, as, len) \
(s->sin6_addr.s6_addr32[0] = htonl(as), \
eui64_copy(eui64, s->sin6_addr.s6_addr32[2]), \
s->sin6_family = AF_INET6, \
l.lifr_addr.ss_family = AF_INET6, \
l.lifr_addrlen = len, \
l.lifr_addr = laddr)
/*
* Generate a link-local address with an interface-id based on the given
* EUI64 identifier. Note that the len field is unused by SIOCSLIFADDR.
*/
#define IN6_LLADDR_FROM_EUI64(l, s, eui64) \
_IN6_LLX_FROM_EUI64(l, s, eui64, 0xfe800000, 0)
/*
* Generate an EUI64 based interface-id for use by stateless address
* autoconfiguration. These are required to be 64 bits long as defined in
* the "Interface Identifiers" section of the IPv6 Addressing Architecture
* (RFC3513).
*/
#define IN6_LLTOKEN_FROM_EUI64(l, s, eui64) \
_IN6_LLX_FROM_EUI64(l, s, eui64, 0, 64)
#endif /* INET6 */
#define IPCP_ENABLED ipcp_protent.enabled_flag
#ifdef INET6
#define IPV6CP_ENABLED ipv6cp_protent.enabled_flag
#endif /* INET6 */
/* For plug-in usage. */
int (*sys_read_packet_hook) __P((int retv, struct strbuf *ctrl,
struct strbuf *data, int flags)) = NULL;
bool already_ppp = 0; /* Already in PPP mode */
static int pppfd = -1; /* ppp driver fd */
static int fdmuxid = -1; /* driver mux fd */
static int ipfd = -1; /* IPv4 fd */
static int ipmuxid = -1; /* IPv4 mux fd */
static int ip6fd = -1; /* IPv6 fd */
static int ip6muxid = -1; /* IPv6 mux fd */
static bool if6_is_up = 0; /* IPv6 if marked as up */
static bool if_is_up = 0; /* IPv4 if marked as up */
static bool restore_term = 0; /* Restore TTY after closing link */
static struct termios inittermios; /* TTY settings */
static struct winsize wsinfo; /* Initial window size info */
static pid_t tty_sid; /* original sess ID for term */
static struct pollfd pollfds[MAX_POLLFDS]; /* array of polled fd */
static int n_pollfds = 0; /* total count of polled fd */
static int link_mtu; /* link Maximum Transmit Unit */
static int tty_nmodules; /* total count of TTY modules used */
static char tty_modules[NMODULES][FMNAMESZ+1];
/* array of TTY modules used */
static int tty_npushed; /* total count of pushed PPP modules */
static u_int32_t remote_addr; /* IP address of peer */
static u_int32_t default_route_gateway; /* Gateway for default route */
static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry */
static u_int32_t lastlink_status; /* Last link status info */
static bool use_plink = 0; /* Use I_LINK by default */
static bool plumbed = 0; /* Use existing interface */
/* Default is to use /dev/sppp as driver. */
static const char *drvnam = PPP_DEV_NAME;
static bool integrated_driver = 0;
static int extra_dev_fd = -1; /* keep open until ready */
static option_t solaris_option_list[] = {
{ "plink", o_bool, &use_plink, "Use I_PLINK instead of I_LINK",
OPT_PRIV|1 },
{ "noplink", o_bool, &use_plink, "Use I_LINK instead of I_PLINK",
OPT_PRIV|0 },
{ "plumbed", o_bool, &plumbed, "Use pre-plumbed interface",
OPT_PRIV|1 },
{ NULL }
};
/*
* Prototypes for procedures local to this file.
*/
static int translate_speed __P((int));
static int baud_rate_of __P((int));
static int get_ether_addr __P((u_int32_t, struct sockaddr_dl *, int));
static int strioctl __P((int, int, void *, int, int));
static int plumb_ipif __P((int));
static int unplumb_ipif __P((int));
#ifdef INET6
static int plumb_ip6if __P((int));
static int unplumb_ip6if __P((int));
static int open_ip6fd(void);
#endif /* INET6 */
static int open_ipfd(void);
static int sifroute __P((int, u_int32_t, u_int32_t, int, const char *));
static int giflags __P((u_int32_t, bool *));
static void handle_unbind __P((u_int32_t));
static void handle_bind __P((u_int32_t));
/*
* Wrapper for regular ioctl; masks out EINTR.
*/
static int
myioctl(int fd, int cmd, void *arg)
{
int retv;
errno = 0;
while ((retv = ioctl(fd, cmd, arg)) == -1) {
if (errno != EINTR)
break;
}
return (retv);
}
/*
* sys_check_options()
*
* Check the options that the user specified.
*/
int
sys_check_options(void)
{
if (plumbed) {
if (req_unit == -1)
req_unit = -2;
ipmuxid = 0;
ip6muxid = 0;
}
return (1);
}
/*
* sys_options()
*
* Add or remove system-specific options.
*/
void
sys_options(void)
{
(void) remove_option("ktune");
(void) remove_option("noktune");
add_options(solaris_option_list);
}
/*
* sys_ifname()
*
* Set ifname[] to contain name of IP interface for this unit.
*/
void
sys_ifname(void)
{
const char *cp;
if ((cp = strrchr(drvnam, '/')) == NULL)
cp = drvnam;
else
cp++;
(void) slprintf(ifname, sizeof (ifname), "%s%d", cp, ifunit);
}
/*
* ppp_available()
*
* Check whether the system has any ppp interfaces.
*/
int
ppp_available(void)
{
struct stat buf;
int fd;
uint32_t typ;
if (stat(PPP_DEV_NAME, &buf) >= 0)
return (1);
/*
* Simple check for system using Apollo POS without SUNWpppd
* (/dev/sppp) installed. This is intentionally not kept open
* here, since the user may not have the same privileges (as
* determined later). If Apollo were just shipped with the
* full complement of packages, this wouldn't be an issue.
*/
if (devnam[0] == '\0' &&
(fd = open(devnam, O_RDWR | O_NONBLOCK | O_NOCTTY)) >= 0) {
if (strioctl(fd, PPPIO_GTYPE, &typ, 0, sizeof (typ)) >= 0 &&
typ == PPPTYP_MUX) {
(void) close(fd);
return (1);
}
(void) close(fd);
}
return (0);
}
static int
open_ipfd(void)
{
ipfd = open(IP_DEV_NAME, O_RDWR | O_NONBLOCK, 0);
if (ipfd < 0) {
error("Couldn't open IP device (%s): %m", IP_DEV_NAME);
}
return (ipfd);
}
static int
read_ip_interface(int unit)
{
struct ifreq ifr;
struct sockaddr_in sin;
if (ipfd == -1 && open_ipfd() == -1)
return (0);
BZERO(&ifr, sizeof (ifr));
(void) strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
/* Get the existing MTU */
if (myioctl(ipfd, SIOCGIFMTU, &ifr) < 0) {
warn("Couldn't get IP MTU on %s: %m", ifr.ifr_name);
return (0);
}
dbglog("got MTU %d from interface", ifr.ifr_metric);
if (ifr.ifr_metric != 0 &&
(lcp_allowoptions[unit].mru == 0 ||
lcp_allowoptions[unit].mru > ifr.ifr_metric))
lcp_allowoptions[unit].mru = ifr.ifr_metric;
/* Get the local IP address */
if (ipcp_wantoptions[unit].ouraddr == 0 ||
ipcp_from_hostname) {
if (myioctl(ipfd, SIOCGIFADDR, &ifr) < 0) {
warn("Couldn't get local IP address (%s): %m",
ifr.ifr_name);
return (0);
}
BCOPY(&ifr.ifr_addr, &sin, sizeof (struct sockaddr_in));
ipcp_wantoptions[unit].ouraddr = sin.sin_addr.s_addr;
dbglog("got local address %I from interface",
ipcp_wantoptions[unit].ouraddr);
}
/* Get the remote IP address */
if (ipcp_wantoptions[unit].hisaddr == 0) {
if (myioctl(ipfd, SIOCGIFDSTADDR, &ifr) < 0) {
warn("Couldn't get remote IP address (%s): %m",
ifr.ifr_name);
return (0);
}
BCOPY(&ifr.ifr_dstaddr, &sin, sizeof (struct sockaddr_in));
ipcp_wantoptions[unit].hisaddr = sin.sin_addr.s_addr;
dbglog("got remote address %I from interface",
ipcp_wantoptions[unit].hisaddr);
}
return (1);
}
#ifdef INET6
static int
open_ip6fd(void)
{
ip6fd = open(IP6_DEV_NAME, O_RDWR | O_NONBLOCK, 0);
if (ip6fd < 0) {
error("Couldn't open IPv6 device (%s): %m", IP6_DEV_NAME);
}
return (ip6fd);
}
static int
read_ipv6_interface(int unit)
{
struct lifreq lifr;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
if (ip6fd == -1 && open_ip6fd() == -1)
return (0);
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
/* Get the existing MTU */
if (myioctl(ip6fd, SIOCGLIFMTU, &lifr) < 0) {
warn("Couldn't get IPv6 MTU on %s: %m", lifr.lifr_name);
return (0);
}
if (lifr.lifr_mtu != 0 &&
(lcp_allowoptions[unit].mru == 0 ||
lcp_allowoptions[unit].mru > lifr.lifr_mtu))
lcp_allowoptions[unit].mru = lifr.lifr_mtu;
/* Get the local IPv6 address */
if (eui64_iszero(ipv6cp_wantoptions[unit].ourid) ||
(ipcp_from_hostname && ipv6cp_wantoptions[unit].use_ip)) {
if (myioctl(ip6fd, SIOCGLIFADDR, &lifr) < 0) {
warn("Couldn't get local IPv6 address (%s): %m",
lifr.lifr_name);
return (0);
}
eui64_copy(sin6->sin6_addr.s6_addr32[2],
ipv6cp_wantoptions[unit].ourid);
}
/* Get the remote IP address */
if (eui64_iszero(ipv6cp_wantoptions[unit].hisid)) {
if (myioctl(ip6fd, SIOCGLIFDSTADDR, &lifr) < 0) {
warn("Couldn't get remote IPv6 address (%s): %m",
lifr.lifr_name);
return (0);
}
eui64_copy(sin6->sin6_addr.s6_addr32[2],
ipv6cp_wantoptions[unit].hisid);
}
return (1);
}
#endif /* INET6 */
/*
* Read information on existing interface(s) and configure ourselves
* to negotiate appropriately.
*/
static void
read_interface(int unit)
{
dbglog("reading existing interface data; %sip %sipv6",
IPCP_ENABLED ? "" : "!",
#ifdef INET6
IPV6CP_ENABLED ? "" :
#endif
"!");
if (IPCP_ENABLED && !read_ip_interface(unit))
IPCP_ENABLED = 0;
#ifdef INET6
if (IPV6CP_ENABLED && !read_ipv6_interface(unit))
IPV6CP_ENABLED = 0;
#endif
}
/*
* sys_init()
*
* System-dependent initialization.
*/
void
sys_init(bool open_as_user)
{
uint32_t x;
uint32_t typ;
if (pppfd != -1) {
return;
}
if (!direct_tty && devnam[0] != '\0') {
/*
* Check for integrated driver-like devices (such as
* POS). These identify themselves as "PPP
* multiplexor" drivers.
*/
if (open_as_user)
(void) seteuid(getuid());
pppfd = open(devnam, O_RDWR | O_NONBLOCK);
if (open_as_user)
(void) seteuid(0);
if (pppfd >= 0 &&
strioctl(pppfd, PPPIO_GTYPE, &typ, 0, sizeof (typ)) >= 0 &&
typ == PPPTYP_MUX) {
integrated_driver = 1;
drvnam = devnam;
} else if (demand) {
(void) close(pppfd);
pppfd = -1;
} else {
extra_dev_fd = pppfd;
pppfd = -1;
}
}
/*
* Open Solaris PPP device driver.
*/
if (pppfd < 0)
pppfd = open(drvnam, O_RDWR | O_NONBLOCK);
if (pppfd < 0) {
fatal("Can't open %s: %m", drvnam);
}
if (kdebugflag & 1) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
if (strioctl(pppfd, PPPIO_DEBUG, &x, sizeof (x), 0) < 0) {
warn("PPPIO_DEBUG ioctl for mux failed: %m");
}
}
/*
* Assign a new PPA and get its unit number.
*/
x = req_unit;
if (strioctl(pppfd, PPPIO_NEWPPA, &x, sizeof (x), sizeof (x)) < 0) {
if (errno == ENXIO && plumbed)
fatal("No idle interfaces available for use");
fatal("PPPIO_NEWPPA ioctl failed: %m");
}
ifunit = x;
if (req_unit >= 0 && ifunit != req_unit) {
if (plumbed)
fatal("unable to get requested unit %d", req_unit);
else
warn("unable to get requested unit %d", req_unit);
}
/*
* Enable packet time-stamping when idle option is specified. Note
* that we need to only do this on the control stream. Subsequent
* streams attached to this control stream (ppa) will inherit
* the time-stamp bit.
*/
if (idle_time_limit > 0) {
if (strioctl(pppfd, PPPIO_USETIMESTAMP, NULL, 0, 0) < 0) {
warn("PPPIO_USETIMESTAMP ioctl failed: %m");
}
}
if (plumbed) {
sys_ifname();
read_interface(0);
}
}
int
sys_extra_fd(void)
{
int fd;
fd = extra_dev_fd;
extra_dev_fd = -1;
return (fd);
}
static int
open_udpfd(void)
{
int udpfd;
udpfd = open(UDP_DEV_NAME, O_RDWR | O_NONBLOCK, 0);
if (udpfd < 0) {
error("Couldn't open UDP device (%s): %m", UDP_DEV_NAME);
}
return (udpfd);
}
/*
* plumb_ipif()
*
* Perform IP interface plumbing.
*/
/*ARGSUSED*/
static int
plumb_ipif(int unit)
{
int udpfd = -1, tmpfd;
uint32_t x;
struct ifreq ifr;
if (!IPCP_ENABLED || (ifunit == -1) || (pppfd == -1)) {
return (0);
}
if (plumbed)
return (1);
if (ipfd == -1 && open_ipfd() == -1)
return (0);
if (use_plink && (udpfd = open_udpfd()) == -1)
return (0);
tmpfd = open(drvnam, O_RDWR | O_NONBLOCK, 0);
if (tmpfd < 0) {
error("Couldn't open PPP device (%s): %m", drvnam);
if (udpfd != -1)
(void) close(udpfd);
return (0);
}
if (kdebugflag & 1) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
if (strioctl(tmpfd, PPPIO_DEBUG, &x, sizeof (x), 0) < 0) {
warn("PPPIO_DEBUG ioctl for mux failed: %m");
}
}
if (myioctl(tmpfd, I_PUSH, IP_MOD_NAME) < 0) {
error("Couldn't push IP module (%s): %m", IP_MOD_NAME);
goto err_ret;
}
/*
* Assign ppa according to the unit number returned by ppp device
* after plumbing is completed above. Without setting the ppa, ip
* module will return EINVAL upon setting the interface UP
* (SIOCSxIFFLAGS). This is because ip module in 2.8 expects two
* DLPI_INFO_REQ to be sent down to the driver (below ip) before
* IFF_UP bit can be set. Plumbing the device causes one DLPI_INFO_REQ
* to be sent down, and the second DLPI_INFO_REQ is sent upon receiving
* IF_UNITSEL (old) or SIOCSLIFNAME (new) ioctls. Such setting of the
* ppa is required because the ppp DLPI provider advertises itself as
* a DLPI style 2 type, which requires a point of attachment to be
* specified. The only way the user can specify a point of attachment
* is via SIOCSLIFNAME or IF_UNITSEL. Such changes in the behavior of
* ip module was made to meet new or evolving standards requirements.
*/
if (myioctl(tmpfd, IF_UNITSEL, &ifunit) < 0) {
error("Couldn't set ppa for unit %d: %m", ifunit);
goto err_ret;
}
if (use_plink) {
ipmuxid = myioctl(udpfd, I_PLINK, (void *)tmpfd);
if (ipmuxid < 0) {
error("Can't I_PLINK PPP device to IP: %m");
goto err_ret;
}
} else {
ipmuxid = myioctl(ipfd, I_LINK, (void *)tmpfd);
if (ipmuxid < 0) {
error("Can't I_LINK PPP device to IP: %m");
goto err_ret;
}
}
BZERO(&ifr, sizeof (ifr));
(void) strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
ifr.ifr_ip_muxid = ipmuxid;
ifr.ifr_arp_muxid = -1;
if (myioctl(ipfd, SIOCSIFMUXID, (caddr_t)&ifr) < 0) {
error("Can't set mux ID SIOCSIFMUXID on %s: %m", ifname);
goto err_ret;
}
if (udpfd != -1)
(void) close(udpfd);
(void) close(tmpfd);
return (1);
err_ret:
if (udpfd != -1)
(void) close(udpfd);
(void) close(tmpfd);
return (0);
}
/*
* unplumb_ipif()
*
* Perform IP interface unplumbing. Possibly called from die(), so there
* shouldn't be any call to die() or fatal() here.
*/
static int
unplumb_ipif(int unit)
{
int udpfd = -1, fd = -1;
int id;
struct lifreq lifr;
if (!IPCP_ENABLED || (ifunit == -1)) {
return (0);
}
if (!plumbed && (ipmuxid == -1 || (ipfd == -1 && !use_plink)))
return (1);
id = ipmuxid;
if (!plumbed && use_plink) {
if ((udpfd = open_udpfd()) == -1)
return (0);
/*
* Note: must re-get mux ID, since any intervening
* ifconfigs will change this.
*/
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname,
sizeof (lifr.lifr_name));
if (myioctl(ipfd, SIOCGLIFMUXID, (caddr_t)&lifr) < 0) {
warn("Can't get mux fd: SIOCGLIFMUXID: %m");
} else {
id = lifr.lifr_ip_muxid;
fd = myioctl(udpfd, _I_MUXID2FD, (void *)id);
if (fd < 0) {
warn("Can't get mux fd: _I_MUXID2FD: %m");
}
}
}
/*
* Mark down and unlink the ip interface.
*/
(void) sifdown(unit);
if (default_route_gateway != 0) {
(void) cifdefaultroute(0, default_route_gateway,
default_route_gateway);
}
if (proxy_arp_addr != 0) {
(void) cifproxyarp(0, proxy_arp_addr);
}
ipmuxid = -1;
if (plumbed)
return (1);
if (use_plink) {
if (myioctl(udpfd, I_PUNLINK, (void *)id) < 0) {
error("Can't I_PUNLINK PPP from IP: %m");
if (fd != -1)
(void) close(fd);
(void) close(udpfd);
return (0);
}
if (fd != -1)
(void) close(fd);
(void) close(udpfd);
} else {
if (myioctl(ipfd, I_UNLINK, (void *)id) < 0) {
error("Can't I_UNLINK PPP from IP: %m");
return (0);
}
}
return (1);
}
/*
* sys_cleanup()
*
* Restore any system state we modified before exiting: mark the
* interface down, delete default route and/or proxy arp entry. This
* should not call die() because it's called from die().
*/
void
sys_cleanup()
{
(void) unplumb_ipif(0);
#ifdef INET6
(void) unplumb_ip6if(0);
#endif /* INET6 */
}
/*
* get_first_hwaddr()
*
* Stores the first hardware interface address found in the system
* into addr and return 1 upon success, or 0 if none is found. This
* is also called from the multilink code.
*/
int
get_first_hwaddr(addr, msize)
uchar_t *addr;
int msize;
{
struct ifconf ifc;
register struct ifreq *pifreq;
struct ifreq ifr;
int fd, num_ifs, i;
uint_t fl, req_size;
char *req;
boolean_t found;
if (addr == NULL) {
return (0);
}
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
error("get_first_hwaddr: error opening IP socket: %m");
return (0);
}
/*
* Find out how many interfaces are running
*/
if (myioctl(fd, SIOCGIFNUM, (caddr_t)&num_ifs) < 0) {
num_ifs = MAXIFS;
}
req_size = num_ifs * sizeof (struct ifreq);
req = malloc(req_size);
if (req == NULL) {
novm("interface request structure.");
}
/*
* Get interface configuration info for all interfaces
*/
ifc.ifc_len = req_size;
ifc.ifc_buf = req;
if (myioctl(fd, SIOCGIFCONF, &ifc) < 0) {
error("SIOCGIFCONF: %m");
(void) close(fd);
free(req);
return (0);
}
/*
* And traverse each interface to look specifically for the first
* occurence of an Ethernet interface which has been marked up
*/
pifreq = ifc.ifc_req;
found = 0;
for (i = ifc.ifc_len / sizeof (struct ifreq); i > 0; i--, pifreq++) {
if (strchr(pifreq->ifr_name, ':') != NULL) {
continue;
}
BZERO(&ifr, sizeof (ifr));
(void) strncpy(ifr.ifr_name, pifreq->ifr_name,
sizeof (ifr.ifr_name));
if (myioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
continue;
}
fl = ifr.ifr_flags;
if ((fl & (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK))
!= (IFF_UP | IFF_BROADCAST)) {
continue;
}
if (get_if_hwaddr(addr, msize, ifr.ifr_name) <= 0) {
continue;
}
found = 1;
break;
}
free(req);
(void) close(fd);
return (found);
}
/*
* get_if_hwaddr()
*
* Get the hardware address for the specified network interface device.
* Return the length of the MAC address (in bytes) or -1 if error.
*/
int
get_if_hwaddr(uchar_t *addrp, int msize, char *linkname)
{
dlpi_handle_t dh;
uchar_t physaddr[DLPI_PHYSADDR_MAX];
size_t physaddrlen = sizeof (physaddr);
int retv;
if ((addrp == NULL) || (linkname == NULL))
return (-1);
/*
* Open the link and ask for hardware address.
*/
if ((retv = dlpi_open(linkname, &dh, 0)) != DLPI_SUCCESS) {
error("Could not open %s: %s", linkname, dlpi_strerror(retv));
return (-1);
}
retv = dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR,
physaddr, &physaddrlen);
dlpi_close(dh);
if (retv != DLPI_SUCCESS) {
error("Could not get physical address on %s: %s", linkname,
dlpi_strerror(retv));
return (-1);
}
/*
* Check if we have enough space to copy the address to.
*/
if (physaddrlen > msize)
return (-1);
(void) memcpy(addrp, physaddr, physaddrlen);
return (physaddrlen);
}
/*
* giflags()
*/
static int
giflags(u_int32_t flag, bool *retval)
{
struct ifreq ifr;
int fd;
*retval = 0;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
error("giflags: error opening IP socket: %m");
return (errno);
}
BZERO(&ifr, sizeof (ifr));
(void) strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
(void) close(fd);
return (errno);
}
*retval = ((ifr.ifr_flags & flag) != 0);
(void) close(fd);
return (errno);
}
/*
* sys_close()
*
* Clean up in a child process before exec-ing.
*/
void
sys_close()
{
if (ipfd != -1) {
(void) close(ipfd);
ipfd = -1;
}
#ifdef INET6
if (ip6fd != -1) {
(void) close(ip6fd);
ip6fd = -1;
}
#endif /* INET6 */
if (pppfd != -1) {
(void) close(pppfd);
pppfd = -1;
}
}
/*
* any_compressions()
*
* Check if compression is enabled or not. In the STREAMS implementation of
* kernel-portion pppd, the comp STREAMS module performs the ACFC, PFC, as
* well CCP and VJ compressions. However, if the user has explicitly declare
* to not enable them from the command line, there is no point of having the
* comp module be pushed on the stream.
*/
static int
any_compressions(void)
{
if ((!lcp_wantoptions[0].neg_accompression) &&
(!lcp_wantoptions[0].neg_pcompression) &&
(!ccp_protent.enabled_flag) &&
(!ipcp_wantoptions[0].neg_vj)) {
return (0);
}
return (1);
}
/*
* modpush()
*
* Push a module on the stream.
*/
static int
modpush(int fd, const char *modname, const char *text)
{
if (myioctl(fd, I_PUSH, (void *)modname) < 0) {
error("Couldn't push %s module: %m", text);
return (-1);
}
if (++tty_npushed == 1 && !already_ppp) {
if (strioctl(fd, PPPIO_LASTMOD, NULL, 0, 0) < 0) {
warn("unable to set LASTMOD on %s: %m", text);
}
}
return (0);
}
/*
* establish_ppp()
*
* Turn the serial port into a ppp interface.
*/
int
establish_ppp(fd)
int fd;
{
int i;
uint32_t x;
if (default_device && !notty) {
tty_sid = getsid((pid_t)0);
}
if (integrated_driver)
return (pppfd);
/*
* Pop any existing modules off the tty stream
*/
for (i = 0; ; ++i) {
if ((myioctl(fd, I_LOOK, tty_modules[i]) < 0) ||
(strcmp(tty_modules[i], "ptem") == 0) ||
(myioctl(fd, I_POP, (void *)0) < 0)) {
break;
}
}
tty_nmodules = i;
/*
* Push the async hdlc module and the compressor module
*/
tty_npushed = 0;
if (!sync_serial && !already_ppp &&
modpush(fd, AHDLC_MOD_NAME, "PPP async HDLC") < 0) {
return (-1);
}
/*
* There's no need to push comp module if we don't intend
* to compress anything
*/
if (any_compressions()) {
(void) modpush(fd, COMP_MOD_NAME, "PPP compression");
}
/*
* Link the serial port under the PPP multiplexor
*/
if ((fdmuxid = myioctl(pppfd, I_LINK, (void *)fd)) < 0) {
error("Can't link tty to PPP mux: %m");
return (-1);
}
if (tty_npushed == 0 && !already_ppp) {
if (strioctl(pppfd, PPPIO_LASTMOD, NULL, 0, 0) < 0) {
warn("unable to set LASTMOD on PPP mux: %m");
}
}
/*
* Debug configuration must occur *after* I_LINK.
*/
if (kdebugflag & 4) {
x = PPPDBG_LOG + PPPDBG_AHDLC;
if (strioctl(pppfd, PPPIO_DEBUG, &x, sizeof (x), 0) < 0) {
warn("PPPIO_DEBUG ioctl for ahdlc module failed: %m");
}
}
if (any_compressions() && (kdebugflag & 2)) {
x = PPPDBG_LOG + PPPDBG_COMP;
if (strioctl(pppfd, PPPIO_DEBUG, &x, sizeof (x), 0) < 0) {
warn("PPPIO_DEBUG ioctl for comp module failed: %m");
}
}
return (pppfd);
}
/*
* restore_loop()
*
* Reattach the ppp unit to the loopback. This doesn't need to do anything
* because disestablish_ppp does it
*/
void
restore_loop()
{
}
/*
* disestablish_ppp()
*
* Restore the serial port to normal operation. It attempts to reconstruct
* the stream with the previously popped modules. This shouldn't call die()
* because it's called from die(). Stream reconstruction is needed in case
* pppd is used for dial-in on /dev/tty and there's an option error.
*/
void
disestablish_ppp(fd)
int fd;
{
int i;
if (fdmuxid == -1 || integrated_driver) {
return;
}
if (myioctl(pppfd, I_UNLINK, (void *)fdmuxid) < 0) {
if (!hungup) {
error("Can't unlink tty from PPP mux: %m");
}
}
fdmuxid = -1;
if (!hungup) {
while (tty_npushed > 0 && myioctl(fd, I_POP, (void *)0) >= 0) {
--tty_npushed;
}
for (i = tty_nmodules - 1; i >= 0; --i) {
if (myioctl(fd, I_PUSH, tty_modules[i]) < 0) {
error("Couldn't restore tty module %s: %m",
tty_modules[i]);
}
}
}
if (hungup && default_device && tty_sid > 0) {
/*
* If we have received a hangup, we need to send a
* SIGHUP to the terminal's controlling process.
* The reason is that the original stream head for
* the terminal hasn't seen the M_HANGUP message
* (it went up through the ppp driver to the stream
* head for our fd to /dev/ppp).
*/
(void) kill(tty_sid, SIGHUP);
}
}
/*
* clean_check()
*
* Check whether the link seems not to be 8-bit clean
*/
void
clean_check()
{
uint32_t x;
char *s = NULL;
/*
* Skip this is synchronous link is used, since spppasyn won't
* be anywhere in the stream below to handle the ioctl.
*/
if (sync_serial) {
return;
}
if (strioctl(pppfd, PPPIO_GCLEAN, &x, 0, sizeof (x)) < 0) {
warn("unable to obtain serial link status: %m");
return;
}
switch (~x) {
case RCV_B7_0:
s = "bit 7 set to 1";
break;
case RCV_B7_1:
s = "bit 7 set to 0";
break;
case RCV_EVNP:
s = "odd parity";
break;
case RCV_ODDP:
s = "even parity";
break;
}
if (s != NULL) {
warn("Serial link is not 8-bit clean:");
warn("All received characters had %s", s);
}
}
/*
* List of valid speeds.
*/
struct speed {
int speed_int;
int speed_val;
} speeds[] = {
{ 50, B50 },
{ 75, B75 },
{ 110, B110 },
{ 134, B134 },
{ 150, B150 },
{ 200, B200 },
{ 300, B300 },
{ 600, B600 },
{ 1200, B1200 },
{ 1800, B1800 },
{ 2400, B2400 },
{ 4800, B4800 },
{ 9600, B9600 },
{ 19200, B19200 },
{ 38400, B38400 },
{ 57600, B57600 },
{ 76800, B76800 },
{ 115200, B115200 },
{ 153600, B153600 },
{ 230400, B230400 },
{ 307200, B307200 },
{ 460800, B460800 },
{ 921600, B921600 },
{ 1000000, B1000000 },
{ 1152000, B1152000 },
{ 1500000, B1500000 },
{ 2000000, B2000000 },
{ 2500000, B2500000 },
{ 3000000, B3000000 },
{ 3500000, B3500000 },
{ 4000000, B4000000 },
{ 0, 0 }
};
/*
* translate_speed()
*
* Translate from bits/second to a speed_t
*/
static int
translate_speed(int bps)
{
struct speed *speedp;
if (bps == 0) {
return (0);
}
for (speedp = speeds; speedp->speed_int; speedp++) {
if (bps == speedp->speed_int) {
return (speedp->speed_val);
}
}
set_source(&speed_info);
option_error("speed %d not supported", bps);
return (0);
}
/*
* baud_rate_of()
*
* Translate from a speed_t to bits/second
*/
static int
baud_rate_of(int speed)
{
struct speed *speedp;
if (speed == 0) {
return (0);
}
for (speedp = speeds; speedp->speed_int; speedp++) {
if (speed == speedp->speed_val) {
return (speedp->speed_int);
}
}
return (0);
}
/*
* set_up_tty()
*
* Set up the serial port on `fd' for 8 bits, no parity, at the requested
* speed, etc. If `local' is true, set CLOCAL regardless of whether the
* modem option was specified.
*/
void
set_up_tty(fd, local)
int fd, local;
{
int speed;
struct termios tios;
struct scc_mode sm;
if (already_ppp)
return;
if (sync_serial) {
restore_term = 0;
speed = B0;
baud_rate = 0;
if (strioctl(fd, S_IOCGETMODE, &sm, sizeof (sm),
sizeof (sm)) < 0) {
return;
}
baud_rate = sm.sm_baudrate;
dbglog("synchronous speed appears to be %d bps", baud_rate);
} else {
if (tcgetattr(fd, &tios) < 0) {
fatal("tcgetattr: %m");
}
if (!restore_term) {
inittermios = tios;
if (myioctl(fd, TIOCGWINSZ, &wsinfo) < 0) {
if (errno == EINVAL) {
/*
* ptem returns EINVAL if all zeroes.
* Strange and unfixable code.
*/
bzero(&wsinfo, sizeof (wsinfo));
} else {
warn("unable to get TTY window "
"size: %m");
}
}
}
tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
if (crtscts > 0) {
tios.c_cflag |= CRTSCTS | CRTSXOFF;
} else if (crtscts < 0) {
tios.c_cflag &= ~CRTSCTS & ~CRTSXOFF;
}
tios.c_cflag |= CS8 | CREAD | HUPCL;
if (local || !modem) {
tios.c_cflag |= CLOCAL;
}
tios.c_iflag = IGNBRK | IGNPAR;
tios.c_oflag = 0;
tios.c_lflag = 0;
tios.c_cc[VMIN] = 1;
tios.c_cc[VTIME] = 0;
if (crtscts == -2) {
tios.c_iflag |= IXON | IXOFF;
tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
}
speed = translate_speed(inspeed);
if (speed) {
(void) cfsetospeed(&tios, speed);
(void) cfsetispeed(&tios, speed);
} else {
speed = cfgetospeed(&tios);
/*
* We can't proceed if the serial port speed is 0,
* since that implies that the serial port is disabled.
*/
if (speed == B0) {
fatal("Baud rate for %s is 0; need explicit "
"baud rate", devnam);
}
}
if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
fatal("tcsetattr: %m");
}
baud_rate = baud_rate_of(speed);
dbglog("%s speed set to %d bps",
fd == pty_slave ? "pty" : "serial", baud_rate);
restore_term = 1;
}
}
/*
* restore_tty()
*
* Restore the terminal to the saved settings.
*/
void
restore_tty(fd)
int fd;
{
if (restore_term == 0) {
return;
}
if (!default_device) {
/*
* Turn off echoing, because otherwise we can get into
* a loop with the tty and the modem echoing to each
* other. We presume we are the sole user of this tty
* device, so when we close it, it will revert to its
* defaults anyway.
*/
inittermios.c_lflag &= ~(ECHO | ECHONL);
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0) {
if (!hungup && errno != ENXIO) {
warn("tcsetattr: %m");
}
}
if (wsinfo.ws_row != 0 || wsinfo.ws_col != 0 ||
wsinfo.ws_xpixel != 0 || wsinfo.ws_ypixel != 0) {
if (myioctl(fd, TIOCSWINSZ, &wsinfo) < 0) {
warn("unable to set TTY window size: %m");
}
}
restore_term = 0;
}
/*
* setdtr()
*
* Control the DTR line on the serial port. This is called from die(), so it
* shouldn't call die()
*/
void
setdtr(fd, on)
int fd, on;
{
int modembits = TIOCM_DTR;
if (!already_ppp &&
myioctl(fd, (on ? TIOCMBIS : TIOCMBIC), &modembits) < 0) {
warn("unable to set DTR line %s: %m", (on ? "ON" : "OFF"));
}
}
/*
* open_loopback()
*
* Open the device we use for getting packets in demand mode. Under Solaris 2,
* we use our existing fd to the ppp driver.
*/
int
open_ppp_loopback()
{
/*
* Plumb the interface.
*/
if (IPCP_ENABLED && (plumb_ipif(0) == 0)) {
fatal("Unable to initialize IP interface for demand dial.");
}
#ifdef INET6
if (IPV6CP_ENABLED && (plumb_ip6if(0) == 0)) {
fatal("Unable to initialize IPv6 interface for demand dial.");
}
#endif /* INET6 */
return (pppfd);
}
/*
* output()
*
* Output PPP packet downstream
*/
/*ARGSUSED*/
void
output(unit, p, len)
int unit;
uchar_t *p;
int len;
{
struct strbuf data;
struct pollfd pfd;
int retries, n;
bool sent_ok = 1;
data.len = len;
data.buf = (caddr_t)p;
retries = 4;
while (putmsg(pppfd, NULL, &data, 0) < 0) {
if (errno == EINTR)
continue;
if (--retries < 0 ||
(errno != EWOULDBLOCK && errno != EAGAIN)) {
if (errno != ENXIO) {
error("Couldn't send packet: %m");
sent_ok = 0;
}
break;
}
pfd.fd = pppfd;
pfd.events = POLLOUT;
do {
/* wait for up to 0.25 seconds */
n = poll(&pfd, 1, 250);
} while ((n == -1) && (errno == EINTR));
}
if (debug && sent_ok) {
dbglog("sent %P", p, len);
}
}
/*
* wait_input()
*
* Wait until there is data available, for the length of time specified by
* timo (indefinite if timo is NULL).
*/
void
wait_input(timo)
struct timeval *timo;
{
int t;
t = (timo == NULL ? -1 : (timo->tv_sec * 1000 + timo->tv_usec / 1000));
if ((poll(pollfds, n_pollfds, t) < 0) && (errno != EINTR)) {
fatal("poll: %m");
}
}
/*
* add_fd()
*
* Add an fd to the set that wait_input waits for.
*/
void
add_fd(fd)
int fd;
{
int n;
if (fd < 0) {
return;
}
for (n = 0; n < n_pollfds; ++n) {
if (pollfds[n].fd == fd) {
return;
}
}
if (n_pollfds < MAX_POLLFDS) {
pollfds[n_pollfds].fd = fd;
pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
++n_pollfds;
} else {
fatal("add_fd: too many inputs!");
}
}
/*
* remove_fd()
*
* Remove an fd from the set that wait_input waits for.
*/
void
remove_fd(fd)
int fd;
{
int n;
for (n = 0; n < n_pollfds; ++n) {
if (pollfds[n].fd == fd) {
while (++n < n_pollfds) {
pollfds[n-1] = pollfds[n];
}
--n_pollfds;
break;
}
}
}
static void
dump_packet(uchar_t *buf, int len)
{
uchar_t *bp;
int proto, offs;
const char *cp;
char sbuf[32];
uint32_t src, dst;
struct protoent *pep;
struct in6_addr addr;
char fromstr[INET6_ADDRSTRLEN];
char tostr[INET6_ADDRSTRLEN];
if (len < 4) {
notice("strange link activity: %.*B", len, buf);
return;
}
bp = buf;
if (bp[0] == 0xFF && bp[1] == 0x03)
bp += 2;
proto = *bp++;
if (!(proto & 1))
proto = (proto << 8) + *bp++;
len -= bp-buf;
switch (proto) {
case PPP_IP:
if (len < IP_HDRLEN || get_ipv(bp) != 4 || get_iphl(bp) < 5) {
notice("strange IP packet activity: %16.*B", len, buf);
return;
}
src = get_ipsrc(bp);
dst = get_ipdst(bp);
proto = get_ipproto(bp);
if ((pep = getprotobynumber(proto)) != NULL) {
cp = pep->p_name;
} else {
(void) slprintf(sbuf, sizeof (sbuf), "IP proto %d",
proto);
cp = sbuf;
}
if ((get_ipoff(bp) & IP_OFFMASK) != 0) {
len -= get_iphl(bp) * 4;
bp += get_iphl(bp) * 4;
notice("%s fragment from %I->%I: %8.*B", cp, src, dst,
len, bp);
} else {
if (len > get_iplen(bp))
len = get_iplen(bp);
len -= get_iphl(bp) * 4;
bp += get_iphl(bp) * 4;
offs = proto == IPPROTO_TCP ? (get_tcpoff(bp)*4) : 8;
if (proto == IPPROTO_TCP || proto == IPPROTO_UDP)
notice("%s data:%d %s%I:%d->%I:%d: %8.*B", cp,
len-offs,
proto == IPPROTO_TCP ?
tcp_flag_decode(get_tcpflags(bp)) : "",
src, get_sport(bp), dst, get_dport(bp),
len-offs, bp+offs);
else
notice("%s %d bytes %I->%I: %8.*B", cp, len,
src, dst, len, bp);
}
return;
case PPP_IPV6:
if (len < IP6_HDRLEN) {
notice("strange IPv6 activity: %16.*B", len, buf);
return;
}
(void) BCOPY(get_ip6src(bp), &addr, sizeof (addr));
(void) inet_ntop(AF_INET6, &addr, fromstr, sizeof (fromstr));
(void) BCOPY(get_ip6dst(bp), &addr, sizeof (addr));
(void) inet_ntop(AF_INET6, &addr, tostr, sizeof (tostr));
proto = get_ip6nh(bp);
if (proto == IPPROTO_FRAGMENT) {
notice("IPv6 fragment from %s->%s", fromstr,
tostr);
return;
}
if ((pep = getprotobynumber(proto)) != NULL) {
cp = pep->p_name;
} else {
(void) slprintf(sbuf, sizeof (sbuf), "IPv6 proto %d",
proto);
cp = sbuf;
}
len -= IP6_HDRLEN;
bp += IP6_HDRLEN;
offs = proto == IPPROTO_TCP ? (get_tcpoff(bp)*4) : 8;
if (proto == IPPROTO_TCP || proto == IPPROTO_UDP)
notice("%s data:%d %s[%s]%d->[%s]%d: %8.*B", cp,
len-offs,
proto == IPPROTO_TCP ?
tcp_flag_decode(get_tcpflags(bp)) : "",
fromstr, get_sport(bp), tostr, get_dport(bp),
len-offs, bp+offs);
else
notice("%s %d bytes %s->%s: %8.*B", cp, len,
fromstr, tostr, len, bp);
return;
}
if ((cp = protocol_name(proto)) == NULL) {
(void) slprintf(sbuf, sizeof (sbuf), "0x#X", proto);
cp = (const char *)sbuf;
}
notice("link activity: %s %16.*B", cp, len, bp);
}
/*
* handle_bind()
*/
static void
handle_bind(u_int32_t reason)
{
/*
* Here we might, in the future, handle DL_BIND_REQ notifications
* in order to close and re-open a NCP when certain interface
* parameters (addresses, etc.) are changed via external mechanisms
* such as through the "ifconfig" program.
*/
switch (reason) {
case PPP_LINKSTAT_IPV4_BOUND:
break;
#ifdef INET6
case PPP_LINKSTAT_IPV6_BOUND:
break;
#endif
default:
error("handle_bind: unrecognized reason");
break;
}
}
/*
* handle_unbind()
*/
static void
handle_unbind(u_int32_t reason)
{
bool iff_up_isset;
int rc;
static const char *unplumb_str = "unplumbed";
static const char *down_str = "downed";
/*
* Since the kernel driver (sppp) notifies this daemon of the
* DLPI bind/unbind activities (for the purpose of bringing down
* a NCP), we need to explicitly test the "actual" status of
* the interface instance for which the notification is destined
* from. This is because /dev/ip performs multiple DLPI attach-
* bind-unbind-detach during the early life of the interface,
* and when certain interface parameters change. A DL_UNBIND_REQ
* coming down to the sppp driver from /dev/ip (which results in
* our receiving of the PPP_LINKSTAT_*_UNBOUND link status message)
* is not enough to conclude that the interface has been marked
* DOWN (its IFF_UP bit is cleared) or is going away. Therefore,
* we should query /dev/ip directly, upon receiving such *_UNBOUND
* notification, to determine whether the interface is DOWN
* for real, and only take the necessary actions when IFF_UP
* bit for the interface instance is actually cleared.
*/
switch (reason) {
case PPP_LINKSTAT_IPV4_UNBOUND:
(void) sleep(1);
rc = giflags(IFF_UP, &iff_up_isset);
if (!iff_up_isset) {
if_is_up = 0;
ipmuxid = -1;
info("IPv4 interface %s by administrator",
((rc < 0 && rc == ENXIO) ? unplumb_str : down_str));
fsm_close(&ipcp_fsm[0],
"administratively disconnected");
}
break;
#ifdef INET6
case PPP_LINKSTAT_IPV6_UNBOUND:
(void) sleep(1);
rc = giflags(IFF_UP, &iff_up_isset);
if (!iff_up_isset) {
if6_is_up = 0;
ip6muxid = -1;
info("IPv6 interface %s by administrator",
((rc < 0 && rc == ENXIO) ? unplumb_str : down_str));
fsm_close(&ipv6cp_fsm[0],
"administratively disconnected");
}
break;
#endif
default:
error("handle_unbind: unrecognized reason");
break;
}
}
/*
* read_packet()
*
* Get a PPP packet from the serial device.
*/
int
read_packet(buf)
uchar_t *buf;
{
struct strbuf ctrl;
struct strbuf data;
int flags;
int len;
int rc;
struct ppp_ls *plp;
uint32_t ctrlbuf[1536 / sizeof (uint32_t)];
bool flushmode;
flushmode = 0;
for (;;) {
data.maxlen = PPP_MRU + PPP_HDRLEN;
data.buf = (caddr_t)buf;
ctrl.maxlen = sizeof (ctrlbuf);
ctrl.buf = (caddr_t)ctrlbuf;
flags = 0;
rc = len = getmsg(pppfd, &ctrl, &data, &flags);
if (sys_read_packet_hook != NULL) {
rc = len = (*sys_read_packet_hook)(len, &ctrl, &data,
flags);
}
if (len < 0) {
if (errno == EAGAIN || errno == EINTR) {
return (-1);
}
fatal("Error reading packet: %m");
}
if ((data.len > 0) && (ctrl.len < 0)) {
/*
* If there's more data on stream head, keep reading
* but discard, since the stream is now corrupt.
*/
if (rc & MOREDATA) {
dbglog("More data; input packet garbled");
flushmode = 1;
continue;
}
if (flushmode)
return (-1);
return (data.len);
} else if (ctrl.len > 0) {
/*
* If there's more ctl on stream head, keep reading,
* but start discarding. We can't deal with fragmented
* messages at all.
*/
if (rc & MORECTL) {
dbglog("More control; stream garbled");
flushmode = 1;
continue;
}
if (flushmode)
return (-1);
if (ctrl.len < sizeof (struct ppp_ls)) {
warn("read_packet: ctl.len %d < "
"sizeof ppp_ls %d",
ctrl.len, sizeof (struct ppp_ls));
return (-1);
}
plp = (struct ppp_ls *)ctrlbuf;
if (plp->magic != PPPLSMAGIC) {
/* Skip, as we don't understand it */
dbglog("read_packet: unrecognized control %lX",
plp->magic);
return (-1);
}
lastlink_status = plp->ppp_message;
switch (plp->ppp_message) {
case PPP_LINKSTAT_HANGUP:
return (0); /* Hangup */
/* For use by integrated drivers. */
case PPP_LINKSTAT_UP:
lcp_lowerdown(0);
lcp_lowerup(0);
return (0);
case PPP_LINKSTAT_NEEDUP:
if (data.len > 0)
dump_packet(buf, data.len);
return (-1); /* Demand dial */
case PPP_LINKSTAT_IPV4_UNBOUND:
(void) handle_unbind(plp->ppp_message);
return (-1);
case PPP_LINKSTAT_IPV4_BOUND:
(void) handle_bind(plp->ppp_message);
return (-1);
#ifdef INET6
case PPP_LINKSTAT_IPV6_UNBOUND:
(void) handle_unbind(plp->ppp_message);
return (-1);
case PPP_LINKSTAT_IPV6_BOUND:
(void) handle_bind(plp->ppp_message);
return (-1);
#endif
default:
warn("read_packet: unknown link status type!");
return (-1);
}
} else {
/*
* We get here on zero length data or control.
*/
return (-1);
}
}
}
/*
* get_loop_output()
*
* Get outgoing packets from the ppp device, and detect when we want to bring
* the real link up. Return value is 1 if we need to bring up the link, or 0
* otherwise.
*/
int
get_loop_output()
{
int loops;
/*
* In the Solaris 2.x kernel-level portion implementation, packets
* which are received on a demand-dial interface are immediately
* discarded, and a notification message is sent up the control
* stream to the pppd process. Therefore, the call to read_packet()
* below is merely there to wait for such message.
*/
lastlink_status = 0;
loops = 0;
while (read_packet(inpacket_buf) > 0) {
if (++loops > 10)
break;
}
return (lastlink_status == PPP_LINKSTAT_NEEDUP);
}
#ifdef MUX_FRAME
/*ARGSUSED*/
void
ppp_send_muxoption(unit, muxflag)
int unit;
u_int32_t muxflag;
{
uint32_t cf[2];
/*
* Since muxed frame feature is implemented in the async module,
* don't send down the ioctl in the synchronous case.
*/
if (!sync_serial && fdmuxid >= 0 && pppfd != -1) {
cf[0] = muxflag;
cf[1] = X_MUXMASK;
if (strioctl(pppfd, PPPIO_MUX, cf, sizeof (cf), 0) < 0) {
error("Couldn't set mux option: %m");
}
}
}
/*ARGSUSED*/
void
ppp_recv_muxoption(unit, muxflag)
int unit;
u_int32_t muxflag;
{
uint32_t cf[2];
/*
* Since muxed frame feature is implemented in the async module,
* don't send down the ioctl in the synchronous case.
*/
if (!sync_serial && fdmuxid >= 0 && pppfd != -1) {
cf[0] = muxflag;
cf[1] = R_MUXMASK;
if (strioctl(pppfd, PPPIO_MUX, cf, sizeof (cf), 0) < 0) {
error("Couldn't set receive mux option: %m");
}
}
}
#endif
/*
* ppp_send_config()
*
* Configure the transmit characteristics of the ppp interface.
*/
/*ARGSUSED*/
void
ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
int unit;
int mtu;
u_int32_t asyncmap;
int pcomp;
int accomp;
{
uint32_t cf[2];
if (pppfd == -1) {
error("ppp_send_config called with invalid device handle");
return;
}
cf[0] = link_mtu = mtu;
if (strioctl(pppfd, PPPIO_MTU, cf, sizeof (cf[0]), 0) < 0) {
if (hungup && errno == ENXIO) {
return;
}
error("Couldn't set MTU: %m");
}
if (fdmuxid != -1) {
if (!sync_serial) {
if (strioctl(pppfd, PPPIO_XACCM, &asyncmap,
sizeof (asyncmap), 0) < 0) {
error("Couldn't set transmit ACCM: %m");
}
}
cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
cf[1] = COMP_PROT | COMP_AC;
if (any_compressions() && strioctl(pppfd, PPPIO_CFLAGS, cf,
sizeof (cf), sizeof (cf[0])) < 0) {
error("Couldn't set prot/AC compression: %m");
}
}
}
/*
* ppp_set_xaccm()
*
* Set the extended transmit ACCM for the interface.
*/
/*ARGSUSED*/
void
ppp_set_xaccm(unit, accm)
int unit;
ext_accm accm;
{
if (sync_serial) {
return;
}
if (fdmuxid != -1 && strioctl(pppfd, PPPIO_XACCM, accm,
sizeof (ext_accm), 0) < 0) {
if (!hungup || errno != ENXIO) {
warn("Couldn't set extended ACCM: %m");
}
}
}
/*
* ppp_recv_config()
*
* Configure the receive-side characteristics of the ppp interface.
*/
/*ARGSUSED*/
void
ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
int unit;
int mru;
u_int32_t asyncmap;
int pcomp;
int accomp;
{
uint32_t cf[2];
if (pppfd == -1) {
error("ppp_recv_config called with invalid device handle");
return;
}
cf[0] = mru;
if (strioctl(pppfd, PPPIO_MRU, cf, sizeof (cf[0]), 0) < 0) {
if (hungup && errno == ENXIO) {
return;
}
error("Couldn't set MRU: %m");
}
if (fdmuxid != -1) {
if (!sync_serial) {
if (strioctl(pppfd, PPPIO_RACCM, &asyncmap,
sizeof (asyncmap), 0) < 0) {
error("Couldn't set receive ACCM: %m");
}
}
cf[0] = (pcomp ? DECOMP_PROT : 0) + (accomp ? DECOMP_AC : 0);
cf[1] = DECOMP_PROT | DECOMP_AC;
if (any_compressions() && strioctl(pppfd, PPPIO_CFLAGS, cf,
sizeof (cf), sizeof (cf[0])) < 0) {
error("Couldn't set prot/AC decompression: %m");
}
}
}
#ifdef NEGOTIATE_FCS
/*
* ppp_send_fcs()
*
* Configure the sender-side FCS.
*/
/*ARGSUSED*/
void
ppp_send_fcs(unit, fcstype)
int unit, fcstype;
{
uint32_t fcs;
if (sync_serial) {
return;
}
if (fcstype & FCSALT_32) {
fcs = PPPFCS_32;
} else if (fcstype & FCSALT_NULL) {
fcs = PPPFCS_NONE;
} else {
fcs = PPPFCS_16;
}
if (strioctl(pppfd, PPPIO_XFCS, &fcs, sizeof (fcs), 0) < 0) {
warn("Couldn't set transmit FCS: %m");
}
}
/*
* ppp_recv_fcs()
*
* Configure the receiver-side FCS.
*/
/*ARGSUSED*/
void
ppp_recv_fcs(unit, fcstype)
int unit, fcstype;
{
uint32_t fcs;
if (sync_serial) {
return;
}
if (fcstype & FCSALT_32) {
fcs = PPPFCS_32;
} else if (fcstype & FCSALT_NULL) {
fcs = PPPFCS_NONE;
} else {
fcs = PPPFCS_16;
}
if (strioctl(pppfd, PPPIO_RFCS, &fcs, sizeof (fcs), 0) < 0) {
warn("Couldn't set receive FCS: %m");
}
}
#endif
/*
* ccp_test()
*
* Ask kernel whether a given compression method is acceptable for use.
*/
/*ARGSUSED*/
int
ccp_test(unit, opt_ptr, opt_len, for_transmit)
int unit;
uchar_t *opt_ptr;
int opt_len;
int for_transmit;
{
if (strioctl(pppfd, (for_transmit ? PPPIO_XCOMP : PPPIO_RCOMP),
opt_ptr, opt_len, 0) >= 0) {
return (1);
}
warn("Error in %s ioctl: %m",
(for_transmit ? "PPPIO_XCOMP" : "PPPIO_RCOMP"));
return ((errno == ENOSR) ? 0 : -1);
}
#ifdef COMP_TUNE
/*
* ccp_tune()
*
* Tune compression effort level.
*/
/*ARGSUSED*/
void
ccp_tune(unit, effort)
int unit, effort;
{
uint32_t x;
x = effort;
if (strioctl(pppfd, PPPIO_COMPLEV, &x, sizeof (x), 0) < 0) {
warn("unable to set compression effort level: %m");
}
}
#endif
/*
* ccp_flags_set()
*
* Inform kernel about the current state of CCP.
*/
/*ARGSUSED*/
void
ccp_flags_set(unit, isopen, isup)
int unit, isopen, isup;
{
uint32_t cf[2];
cf[0] = (isopen ? CCP_ISOPEN : 0) + (isup ? CCP_ISUP : 0);
cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof (cf), sizeof (cf[0]))
< 0) {
if (!hungup || errno != ENXIO) {
error("Couldn't set kernel CCP state: %m");
}
}
}
/*
* get_idle_time()
*
* Return how long the link has been idle.
*/
/*ARGSUSED*/
int
get_idle_time(u, pids)
int u;
struct ppp_idle *pids;
{
int rc;
rc = strioctl(pppfd, PPPIO_GIDLE, pids, 0, sizeof (struct ppp_idle));
if (rc < 0) {
warn("unable to obtain idle time: %m");
}
return ((rc == 0) ? 1 : 0);
}
/*
* get_ppp_stats()
*
* Return statistics for the link.
*/
/*ARGSUSED*/
int
get_ppp_stats(u, stats)
int u;
struct pppd_stats *stats;
{
struct ppp_stats64 s64;
struct ppp_stats s;
/* Try first to get these from the 64-bit interface */
if (strioctl(pppfd, PPPIO_GETSTAT64, &s64, 0, sizeof (s64)) >= 0) {
stats->bytes_in = s64.p.ppp_ibytes;
stats->bytes_out = s64.p.ppp_obytes;
stats->pkts_in = s64.p.ppp_ipackets;
stats->pkts_out = s64.p.ppp_opackets;
return (1);
}
if (strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof (s)) < 0) {
error("Couldn't get link statistics: %m");
return (0);
}
stats->bytes_in = s.p.ppp_ibytes;
stats->bytes_out = s.p.ppp_obytes;
stats->pkts_in = s.p.ppp_ipackets;
stats->pkts_out = s.p.ppp_opackets;
return (1);
}
#if defined(FILTER_PACKETS)
/*
* set_filters()
*
* Transfer the pass and active filters to the kernel.
*/
int
set_filters(pass, active)
struct bpf_program *pass;
struct bpf_program *active;
{
int ret = 1;
if (pass->bf_len > 0) {
if (strioctl(pppfd, PPPIO_PASSFILT, pass,
sizeof (struct bpf_program), 0) < 0) {
error("Couldn't set pass-filter in kernel: %m");
ret = 0;
}
}
if (active->bf_len > 0) {
if (strioctl(pppfd, PPPIO_ACTIVEFILT, active,
sizeof (struct bpf_program), 0) < 0) {
error("Couldn't set active-filter in kernel: %m");
ret = 0;
}
}
return (ret);
}
#endif /* FILTER_PACKETS */
/*
* ccp_fatal_error()
*
* Returns 1 if decompression was disabled as a result of an error detected
* after decompression of a packet, 0 otherwise. This is necessary because
* of patent nonsense.
*/
/*ARGSUSED*/
int
ccp_fatal_error(unit)
int unit;
{
uint32_t cf[2];
cf[0] = cf[1] = 0;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof (cf), sizeof (cf[0]))
< 0) {
if (errno != ENXIO && errno != EINVAL) {
error("Couldn't get compression flags: %m");
}
return (0);
}
return (cf[0] & CCP_FATALERROR);
}
/*
* sifvjcomp()
*
* Config TCP header compression.
*/
/*ARGSUSED*/
int
sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
int u, vjcomp, xcidcomp, xmaxcid;
{
uint32_t cf[2];
uchar_t maxcid[2];
/*
* Since VJ compression code is in the comp module, there's no
* point of sending down any ioctls pertaining to VJ compression
* when the module isn't pushed on the stream.
*/
if (!any_compressions()) {
return (1);
}
if (vjcomp) {
maxcid[0] = xcidcomp;
maxcid[1] = 15; /* XXX should be rmaxcid */
if (strioctl(pppfd, PPPIO_VJINIT, maxcid,
sizeof (maxcid), 0) < 0) {
error("Couldn't initialize VJ compression: %m");
return (0);
}
}
cf[0] = (vjcomp ? COMP_VJC + DECOMP_VJC : 0) /* XXX this is wrong */
+ (xcidcomp? COMP_VJCCID + DECOMP_VJCCID: 0);
cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof (cf), sizeof (cf[0]))
< 0) {
if (vjcomp) {
error("Couldn't enable VJ compression: %m");
} else {
error("Couldn't disable VJ compression: %m");
}
return (0);
}
return (1);
}
/*
* siflags()
*
* Set or clear the IP interface flags.
*/
int
siflags(f, set)
u_int32_t f;
int set;
{
struct ifreq ifr;
if (!IPCP_ENABLED || (ipmuxid == -1)) {
return (0);
}
if (ipfd == -1 && open_ipfd() == -1)
return (0);
BZERO(&ifr, sizeof (ifr));
(void) strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
if (myioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
error("Couldn't get IP interface flags: %m");
return (0);
}
if (set) {
ifr.ifr_flags |= f;
} else {
ifr.ifr_flags &= ~f;
}
if (myioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
error("Couldn't set IP interface flags: %m");
return (0);
}
return (1);
}
/*
* sifup()
*
* Config the interface up and enable IP packets to pass.
*/
/*ARGSUSED*/
int
sifup(u)
int u;
{
if (if_is_up) {
return (1);
} else if (!IPCP_ENABLED) {
warn("sifup called when IPCP is disabled");
return (0);
} else if (ipmuxid == -1) {
warn("sifup called in wrong state");
return (0);
} else if (!siflags(IFF_UP, 1)) {
error("Unable to mark the IP interface UP");
return (0);
}
if_is_up = 1;
return (1);
}
/*
* sifdown()
*
* Config the interface down and disable IP. Possibly called from die(),
* so there shouldn't be any call to die() here.
*/
/*ARGSUSED*/
int
sifdown(u)
int u;
{
if (!IPCP_ENABLED) {
warn("sifdown called when IPCP is disabled");
return (0);
} else if (!if_is_up || (ipmuxid == -1)) {
return (1);
} else if (!siflags(IFF_UP, 0)) {
error("Unable to mark the IP interface DOWN");
return (0);
}
if_is_up = 0;
return (1);
}
/*
* sifnpmode()
*
* Set the mode for handling packets for a given NP. Not worried
* about performance here since this is done only rarely.
*/
/*ARGSUSED*/
int
sifnpmode(u, proto, mode)
int u;
int proto;
enum NPmode mode;
{
uint32_t npi[2];
const char *cp;
static const struct npi_entry {
enum NPmode ne_value;
const char *ne_name;
} npi_list[] = {
{ NPMODE_PASS, "pass" },
{ NPMODE_DROP, "drop" },
{ NPMODE_ERROR, "error" },
{ NPMODE_QUEUE, "queue" },
};
int i;
char pname[32], mname[32];
npi[0] = proto;
npi[1] = (uint32_t)mode;
cp = protocol_name(proto);
if (cp == NULL)
(void) slprintf(pname, sizeof (pname), "NP %04X", proto);
else
(void) strlcpy(pname, cp, sizeof (pname));
for (i = 0; i < Dim(npi_list); i++)
if (npi_list[i].ne_value == mode)
break;
if (i >= Dim(npi_list))
(void) slprintf(mname, sizeof (mname), "mode %d", (int)mode);
else
(void) strlcpy(mname, npi_list[i].ne_name, sizeof (mname));
if ((proto == PPP_IP && !if_is_up) ||
(proto == PPP_IPV6 && !if6_is_up)) {
dbglog("ignoring request to set %s to %s", pname, mname);
return (1);
}
if (strioctl(pppfd, PPPIO_NPMODE, npi, sizeof (npi), 0) < 0) {
error("unable to set %s to %s: %m", pname, mname);
return (0);
}
return (1);
}
/*
* sifmtu()
*
* Config the interface IP MTU.
*/
int
sifmtu(mtu)
int mtu;
{
struct ifreq ifr;
if (!IPCP_ENABLED || (ipmuxid == -1)) {
return (0);
}
if (ipfd == -1 && open_ipfd() == -1)
return (0);
BZERO(&ifr, sizeof (ifr));
(void) strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
ifr.ifr_metric = mtu;
if (myioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
error("Couldn't set IP MTU on %s to %d: %m", ifr.ifr_name,
mtu);
return (0);
}
return (1);
}
/*
* sifaddr()
*
* Config the interface IP addresses and netmask.
*/
/*ARGSUSED*/
int
sifaddr(u, o, h, m)
int u;
u_int32_t o;
u_int32_t h;
u_int32_t m;
{
struct ifreq ifr;
struct sockaddr_in sin;
if (!IPCP_ENABLED || (ipmuxid == -1 && plumb_ipif(u) == 0)) {
return (0);
}
if (ipfd == -1 && open_ipfd() == -1)
return (0);
/*
* Set the IP interface MTU.
*/
if (!sifmtu(link_mtu)) {
return (0);
}
/*
* Set the IP interface local point-to-point address.
*/
BZERO(&sin, sizeof (sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = o;
BZERO(&ifr, sizeof (ifr));
(void) strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
ifr.ifr_addr = *(struct sockaddr *)&sin;
if (myioctl(ipfd, SIOCSIFADDR, &ifr) < 0) {
error("Couldn't set local IP address (%s): %m", ifr.ifr_name);
return (0);
}
/*
* Set the IP interface remote point-to-point address.
*/
sin.sin_addr.s_addr = h;
ifr.ifr_dstaddr = *(struct sockaddr *)&sin;
if (myioctl(ipfd, SIOCSIFDSTADDR, &ifr) < 0) {
error("Couldn't set remote IP address (%s): %m", ifr.ifr_name);
return (0);
}
remote_addr = h;
return (1);
}
/*
* cifaddr()
*
* Clear the interface IP addresses.
*/
/*ARGSUSED*/
int
cifaddr(u, o, h)
int u;
u_int32_t o;
u_int32_t h;
{
if (!IPCP_ENABLED) {
return (0);
}
/*
* Most of the work is done in sifdown().
*/
remote_addr = 0;
return (1);
}
/*
* sifroute()
*
* Add or delete a route.
*/
/*ARGSUSED*/
static int
sifroute(int u, u_int32_t l, u_int32_t g, int add, const char *str)
{
struct sockaddr_in sin_dst, sin_gtw;
struct rtentry rt;
if (!IPCP_ENABLED || (ipmuxid == -1)) {
error("Can't %s route: IP is not enabled", str);
return (0);
}
if (ipfd == -1 && open_ipfd() == -1)
return (0);
BZERO(&sin_dst, sizeof (sin_dst));
sin_dst.sin_family = AF_INET;
sin_dst.sin_addr.s_addr = l;
BZERO(&sin_gtw, sizeof (sin_gtw));
sin_gtw.sin_family = AF_INET;
sin_gtw.sin_addr.s_addr = g;
BZERO(&rt, sizeof (rt));
rt.rt_dst = *(struct sockaddr *)&sin_dst;
rt.rt_gateway = *(struct sockaddr *)&sin_gtw;
rt.rt_flags = (RTF_GATEWAY|RTF_STATIC);
if (myioctl(ipfd, (add ? SIOCADDRT : SIOCDELRT), &rt) < 0) {
error("Can't %s route: %m", str);
return (0);
}
return (1);
}
/*
* sifdefaultroute()
*
* Assign a default route through the address given.
*/
/*ARGSUSED*/
int
sifdefaultroute(u, l, g)
int u;
u_int32_t l;
u_int32_t g;
{
if (!sifroute(u, 0, g, 1, "add default")) {
return (0);
}
default_route_gateway = g;
return (1);
}
/*
* cifdefaultroute()
*
* Delete a default route through the address given.
*/
/*ARGSUSED*/
int
cifdefaultroute(u, l, g)
int u;
u_int32_t l;
u_int32_t g;
{
if (!sifroute(u, 0, g, 0, "delete default")) {
return (0);
}
default_route_gateway = 0;
return (1);
}
/*
* sifproxyarp()
*
* Make a proxy ARP entry for the peer.
*/
/*ARGSUSED*/
int
sifproxyarp(unit, hisaddr, quietflag)
int unit;
u_int32_t hisaddr;
int quietflag;
{
struct sockaddr_in sin;
struct xarpreq arpreq;
const uchar_t *cp;
char *str = NULL;
if (!IPCP_ENABLED || (ipmuxid == -1)) {
return (0);
}
if (ipfd == -1 && open_ipfd() == -1)
return (0);
BZERO(&sin, sizeof (sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = hisaddr;
BZERO(&arpreq, sizeof (arpreq));
if (!get_ether_addr(hisaddr, &arpreq.xarp_ha, quietflag)) {
return (0);
}
BCOPY(&sin, &arpreq.xarp_pa, sizeof (sin));
arpreq.xarp_flags = ATF_PERM | ATF_PUBL;
arpreq.xarp_ha.sdl_family = AF_LINK;
if (myioctl(ipfd, SIOCSXARP, (caddr_t)&arpreq) < 0) {
if (!quietflag)
error("Couldn't set proxy ARP entry: %m");
return (0);
}
cp = (const uchar_t *)LLADDR(&arpreq.xarp_ha);
str = _link_ntoa(cp, str, arpreq.xarp_ha.sdl_alen, IFT_OTHER);
if (str != NULL) {
dbglog("established proxy ARP for %I using %s", hisaddr,
str);
free(str);
}
proxy_arp_addr = hisaddr;
return (1);
}
/*
* cifproxyarp()
*
* Delete the proxy ARP entry for the peer.
*/
/*ARGSUSED*/
int
cifproxyarp(unit, hisaddr)
int unit;
u_int32_t hisaddr;
{
struct sockaddr_in sin;
struct xarpreq arpreq;
if (!IPCP_ENABLED || (ipmuxid == -1)) {
return (0);
}
if (ipfd == -1 && open_ipfd() == -1)
return (0);
BZERO(&sin, sizeof (sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = hisaddr;
BZERO(&arpreq, sizeof (arpreq));
BCOPY(&sin, &arpreq.xarp_pa, sizeof (sin));
arpreq.xarp_ha.sdl_family = AF_LINK;
if (myioctl(ipfd, SIOCDXARP, (caddr_t)&arpreq) < 0) {
error("Couldn't delete proxy ARP entry: %m");
return (0);
}
proxy_arp_addr = 0;
return (1);
}
/*
* get_ether_addr()
*
* Get the hardware address of an interface on the the same subnet as
* ipaddr. This routine uses old-style interfaces for intentional
* backward compatibility -- SIOCGLIF* isn't in older Solaris
* releases.
*/
static int
get_ether_addr(u_int32_t ipaddr, struct sockaddr_dl *hwaddr, int quietflag)
{
struct ifreq *ifr, *ifend, ifreq;
int nif, s, retv;
struct ifconf ifc;
u_int32_t ina, mask;
struct xarpreq req;
struct sockaddr_in sin;
if (ipfd == -1 && open_ipfd() == -1)
return (0);
/*
* Scan through the system's network interfaces.
*/
if (myioctl(ipfd, SIOCGIFNUM, &nif) < 0) {
nif = MAXIFS;
}
if (nif <= 0)
return (0);
ifc.ifc_len = nif * sizeof (struct ifreq);
ifc.ifc_buf = (caddr_t)malloc(ifc.ifc_len);
if (ifc.ifc_buf == NULL) {
return (0);
}
if (myioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
error("Couldn't get system interface list: %m");
free(ifc.ifc_buf);
return (0);
}
/* LINTED */
ifend = (struct ifreq *)(ifc.ifc_buf + ifc.ifc_len);
for (ifr = ifc.ifc_req; ifr < ifend; ++ifr) {
if (ifr->ifr_addr.sa_family != AF_INET) {
continue;
}
/*
* Check that the interface is up, and not
* point-to-point or loopback.
*/
(void) strlcpy(ifreq.ifr_name, ifr->ifr_name,
sizeof (ifreq.ifr_name));
if (myioctl(ipfd, SIOCGIFFLAGS, &ifreq) < 0) {
continue;
}
if ((ifreq.ifr_flags & (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|
IFF_LOOPBACK|IFF_NOARP)) != (IFF_UP|IFF_BROADCAST)) {
continue;
}
/*
* Get its netmask and check that it's on the right subnet.
*/
if (myioctl(ipfd, SIOCGIFNETMASK, &ifreq) < 0) {
continue;
}
(void) memcpy(&sin, &ifr->ifr_addr, sizeof (sin));
ina = sin.sin_addr.s_addr;
(void) memcpy(&sin, &ifreq.ifr_addr, sizeof (sin));
mask = sin.sin_addr.s_addr;
if ((ipaddr & mask) == (ina & mask)) {
break;
}
}
if (ifr >= ifend) {
if (!quietflag)
warn("No suitable interface found for proxy ARP of %I",
ipaddr);
free(ifc.ifc_buf);
return (0);
}
info("found interface %s for proxy ARP of %I", ifr->ifr_name, ipaddr);
/*
* New way - get the address by doing an arp request.
*/
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
error("get_ether_addr: error opening IP socket: %m");
free(ifc.ifc_buf);
return (0);
}
BZERO(&sin, sizeof (sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = ina;
BZERO(&req, sizeof (req));
BCOPY(&sin, &req.xarp_pa, sizeof (sin));
req.xarp_ha.sdl_family = AF_LINK;
if (myioctl(s, SIOCGXARP, &req) < 0) {
error("Couldn't get ARP entry for %I: %m", ina);
retv = 0;
} else {
(void) memcpy(hwaddr, &req.xarp_ha,
sizeof (struct sockaddr_dl));
retv = 1;
}
(void) close(s);
free(ifc.ifc_buf);
return (retv);
}
/*
* GetMask()
*
* Return mask (bogus, but needed for compatibility with other platforms).
*/
/*ARGSUSED*/
u_int32_t
GetMask(addr)
u_int32_t addr;
{
return (0xffffffffUL);
}
/*
* logwtmp()
*
* Write an accounting record to the /var/adm/wtmp file.
*/
/*ARGSUSED*/
void
logwtmp(line, name, host)
const char *line;
const char *name;
const char *host;
{
static struct utmpx utmpx;
if (name[0] != '\0') {
/*
* logging in
*/
(void) strncpy(utmpx.ut_user, name, sizeof (utmpx.ut_user));
(void) strncpy(utmpx.ut_id, ifname, sizeof (utmpx.ut_id));
(void) strncpy(utmpx.ut_line, line, sizeof (utmpx.ut_line));
utmpx.ut_pid = getpid();
utmpx.ut_type = USER_PROCESS;
} else {
utmpx.ut_type = DEAD_PROCESS;
}
(void) gettimeofday(&utmpx.ut_tv, NULL);
updwtmpx("/var/adm/wtmpx", &utmpx);
}
/*
* get_host_seed()
*
* Return the serial number of this machine.
*/
int
get_host_seed()
{
char buf[32];
if (sysinfo(SI_HW_SERIAL, buf, sizeof (buf)) < 0) {
error("sysinfo: %m");
return (0);
}
return ((int)strtoul(buf, NULL, 16));
}
/*
* strioctl()
*
* Wrapper for STREAMS I_STR ioctl. Masks out EINTR from caller.
*/
static int
strioctl(int fd, int cmd, void *ptr, int ilen, int olen)
{
struct strioctl str;
str.ic_cmd = cmd;
str.ic_timout = PPPSTRTIMOUT;
str.ic_len = ilen;
str.ic_dp = ptr;
if (myioctl(fd, I_STR, &str) == -1) {
return (-1);
}
if (str.ic_len != olen) {
dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
olen, str.ic_len, cmd);
}
return (0);
}
/*
* have_route_to()
*
* Determine if the system has a route to the specified IP address.
* Returns 0 if not, 1 if so, -1 if we can't tell. `addr' is in network
* byte order. For demand mode to work properly, we have to ignore routes
* through our own interface. XXX Would be nice to use routing socket.
*/
int
have_route_to(addr)
u_int32_t addr;
{
int r, flags, i;
struct {
struct T_optmgmt_req req;
struct opthdr hdr;
} req;
union {
struct T_optmgmt_ack ack;
unsigned char space[64];
} ack;
struct opthdr *rh;
struct strbuf cbuf, dbuf;
int nroutes;
mib2_ipRouteEntry_t routes[8];
mib2_ipRouteEntry_t *rp;
if (ipfd == -1 && open_ipfd() == -1)
return (0);
req.req.PRIM_type = T_OPTMGMT_REQ;
req.req.OPT_offset = (caddr_t)&req.hdr - (caddr_t)&req;
req.req.OPT_length = sizeof (req.hdr);
#ifdef T_CURRENT
req.req.MGMT_flags = T_CURRENT;
#else
/* Old-style */
req.req.MGMT_flags = T_CHECK;
#endif
req.hdr.level = MIB2_IP;
req.hdr.name = 0;
req.hdr.len = 0;
cbuf.buf = (caddr_t)&req;
cbuf.len = sizeof (req);
if (putmsg(ipfd, &cbuf, NULL, 0) == -1) {
warn("have_route_to: putmsg: %m");
return (-1);
}
for (;;) {
cbuf.buf = (caddr_t)&ack;
cbuf.maxlen = sizeof (ack);
dbuf.buf = (caddr_t)routes;
dbuf.maxlen = sizeof (routes);
flags = 0;
r = getmsg(ipfd, &cbuf, &dbuf, &flags);
if (r == -1) {
warn("have_route_to: getmsg: %m");
return (-1);
}
if (cbuf.len < sizeof (struct T_optmgmt_ack) ||
ack.ack.PRIM_type != T_OPTMGMT_ACK ||
ack.ack.MGMT_flags != T_SUCCESS ||
ack.ack.OPT_length < sizeof (struct opthdr)) {
dbglog("have_route_to: bad message len=%d prim=%d",
cbuf.len, ack.ack.PRIM_type);
return (-1);
}
/* LINTED */
rh = (struct opthdr *)((caddr_t)&ack + ack.ack.OPT_offset);
if (rh->level == 0 && rh->name == 0) {
break;
}
if (rh->level != MIB2_IP || rh->name != MIB2_IP_21) {
while (r == MOREDATA) {
r = getmsg(ipfd, NULL, &dbuf, &flags);
}
continue;
}
/*
* Note that we have to skip routes to our own
* interface in order for demand dial to work.
*
* XXX awful hack here. We don't know our own
* ifIndex, so we can't check ipRouteIfIndex here.
* Instead, we check the next hop address.
*/
for (;;) {
nroutes = dbuf.len / sizeof (mib2_ipRouteEntry_t);
for (rp = routes, i = 0; i < nroutes; ++i, ++rp) {
if (rp->ipRouteNextHop != remote_addr &&
((addr ^ rp->ipRouteDest) &
rp->ipRouteMask) == 0) {
dbglog("have route to %I/%I via %I",
rp->ipRouteDest,
rp->ipRouteMask,
rp->ipRouteNextHop);
return (1);
}
}
if (r == 0) {
break;
}
r = getmsg(ipfd, NULL, &dbuf, &flags);
}
}
return (0);
}
/*
* get_pty()
*
* Get a pty master/slave pair and chown the slave side to the uid given.
* Assumes slave_name points to MAXPATHLEN bytes of space.
*/
int
get_pty(master_fdp, slave_fdp, slave_name, uid)
int *master_fdp;
int *slave_fdp;
char *slave_name;
int uid;
{
int mfd;
int sfd;
char *pty_name;
mfd = open("/dev/ptmx", O_NOCTTY | O_RDWR);
if (mfd < 0) {
error("Couldn't open pty master: %m");
return (0);
}
pty_name = ptsname(mfd);
if (pty_name == NULL) {
dbglog("Didn't get pty slave name on first try; sleeping.");
/* In case "grow" operation is in progress; try again. */
(void) sleep(1);
pty_name = ptsname(mfd);
}
if (pty_name == NULL) {
error("Couldn't get name of pty slave");
(void) close(mfd);
return (0);
}
if (chown(pty_name, uid, -1) < 0) {
warn("Couldn't change owner of pty slave: %m");
}
if (chmod(pty_name, S_IRUSR | S_IWUSR) < 0) {
warn("Couldn't change permissions on pty slave: %m");
}
if (unlockpt(mfd) < 0) {
warn("Couldn't unlock pty slave: %m");
}
sfd = open(pty_name, O_RDWR);
if (sfd < 0) {
error("Couldn't open pty slave %s: %m", pty_name);
(void) close(mfd);
return (0);
}
if (myioctl(sfd, I_PUSH, "ptem") < 0) {
warn("Couldn't push ptem module on pty slave: %m");
}
dbglog("Using %s; master fd %d, slave fd %d", pty_name, mfd, sfd);
(void) strlcpy(slave_name, pty_name, MAXPATHLEN);
*master_fdp = mfd;
*slave_fdp = sfd;
return (1);
}
#ifdef INET6
static int
open_udp6fd(void)
{
int udp6fd;
udp6fd = open(UDP6_DEV_NAME, O_RDWR | O_NONBLOCK, 0);
if (udp6fd < 0) {
error("Couldn't open UDPv6 device (%s): %m", UDP6_DEV_NAME);
}
return (udp6fd);
}
/*
* plumb_ip6if()
*
* Perform IPv6 interface plumbing.
*/
/*ARGSUSED*/
static int
plumb_ip6if(int unit)
{
int udp6fd = -1, tmpfd;
uint32_t x;
struct lifreq lifr;
if (!IPV6CP_ENABLED || (ifunit == -1) || (pppfd == -1)) {
return (0);
}
if (plumbed)
return (1);
if (ip6fd == -1 && open_ip6fd() == -1)
return (0);
if (use_plink && (udp6fd = open_udp6fd()) == -1)
return (0);
tmpfd = open(drvnam, O_RDWR | O_NONBLOCK, 0);
if (tmpfd < 0) {
error("Couldn't open PPP device (%s): %m", drvnam);
if (udp6fd != -1)
(void) close(udp6fd);
return (0);
}
if (kdebugflag & 1) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
if (strioctl(tmpfd, PPPIO_DEBUG, &x, sizeof (x), 0) < 0) {
warn("PPPIO_DEBUG ioctl for mux failed: %m");
}
}
if (myioctl(tmpfd, I_PUSH, IP_MOD_NAME) < 0) {
error("Couldn't push IP module(%s): %m", IP_MOD_NAME);
goto err_ret;
}
/*
* Sets interface ppa and flags (refer to comments in plumb_ipif for
* the IF_UNITSEL ioctl). In addition, the IFF_IPV6 bit must be set in
* order to declare this as an IPv6 interface.
*/
BZERO(&lifr, sizeof (lifr));
if (myioctl(tmpfd, SIOCGLIFFLAGS, &lifr) < 0) {
error("Couldn't get IPv6 interface flags: %m");
goto err_ret;
}
lifr.lifr_flags |= IFF_IPV6;
lifr.lifr_flags &= ~(IFF_BROADCAST | IFF_IPV4);
lifr.lifr_ppa = ifunit;
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
if (myioctl(tmpfd, SIOCSLIFNAME, &lifr) < 0) {
error("Can't set ifname for unit %d: %m", ifunit);
goto err_ret;
}
if (use_plink) {
ip6muxid = myioctl(udp6fd, I_PLINK, (void *)tmpfd);
if (ip6muxid < 0) {
error("Can't I_PLINK PPP device to IPv6: %m");
goto err_ret;
}
} else {
ip6muxid = myioctl(ip6fd, I_LINK, (void *)tmpfd);
if (ip6muxid < 0) {
error("Can't I_LINK PPP device to IPv6: %m");
goto err_ret;
}
}
lifr.lifr_ip_muxid = ip6muxid;
lifr.lifr_arp_muxid = -1;
if (myioctl(ip6fd, SIOCSLIFMUXID, (caddr_t)&lifr) < 0) {
error("Can't set mux ID: SIOCSLIFMUXID: %m");
goto err_ret;
}
(void) close(tmpfd);
if (udp6fd != -1)
(void) close(udp6fd);
return (1);
err_ret:
(void) close(tmpfd);
if (udp6fd != -1)
(void) close(udp6fd);
return (0);
}
/*
* unplumb_ip6if()
*
* Perform IPv6 interface unplumbing. Possibly called from die(), so there
* shouldn't be any call to die() here.
*/
static int
unplumb_ip6if(int unit)
{
int udp6fd = -1, fd = -1;
int id;
struct lifreq lifr;
if (!IPV6CP_ENABLED || ifunit == -1) {
return (0);
}
if (!plumbed && (ip6muxid == -1 || (ip6fd == -1 && !use_plink))) {
return (1);
}
id = ip6muxid;
if (!plumbed && use_plink) {
if ((udp6fd = open_udp6fd()) == -1)
return (0);
/*
* Note: must re-get mux ID, since any intervening
* ifconfigs will change this.
*/
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname,
sizeof (lifr.lifr_name));
if (myioctl(ip6fd, SIOCGLIFMUXID, (caddr_t)&lifr) < 0) {
warn("Can't get mux fd: SIOCGLIFMUXID: %m");
} else {
id = lifr.lifr_ip_muxid;
fd = myioctl(udp6fd, _I_MUXID2FD, (void *)id);
if (fd < 0) {
warn("Can't get mux fd: _I_MUXID2FD: %m");
}
}
}
/*
* Mark down and unlink the IPv6 interface.
*/
(void) sif6down(unit);
if (plumbed)
return (1);
ip6muxid = -1;
if (use_plink) {
if ((fd = myioctl(udp6fd, _I_MUXID2FD, (void *)id)) < 0) {
error("Can't recapture mux fd: _I_MUXID2FD: %m");
(void) close(udp6fd);
return (0);
}
if (myioctl(udp6fd, I_PUNLINK, (void *)id) < 0) {
error("Can't I_PUNLINK PPP from IPv6: %m");
(void) close(fd);
(void) close(udp6fd);
return (0);
}
(void) close(fd);
(void) close(udp6fd);
} else {
if (myioctl(ip6fd, I_UNLINK, (void *)id) < 0) {
error("Can't I_UNLINK PPP from IPv6: %m");
return (0);
}
}
return (1);
}
/*
* sif6flags()
*
* Set or clear the IPv6 interface flags.
*/
int
sif6flags(f, set)
u_int32_t f;
int set;
{
struct lifreq lifr;
int fd;
if (!IPV6CP_ENABLED || (ip6muxid == -1)) {
return (0);
}
fd = socket(AF_INET6, SOCK_DGRAM, 0);
if (fd < 0) {
error("sif6flags: error opening IPv6 socket: %m");
return (0);
}
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
if (myioctl(fd, SIOCGLIFFLAGS, &lifr) < 0) {
error("Couldn't get IPv6 interface flags: %m");
(void) close(fd);
return (0);
}
if (set) {
lifr.lifr_flags |= f;
} else {
lifr.lifr_flags &= ~f;
}
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
if (myioctl(fd, SIOCSLIFFLAGS, &lifr) < 0) {
error("Couldn't set IPv6 interface flags: %m");
(void) close(fd);
return (0);
}
(void) close(fd);
return (1);
}
/*
* sif6up()
*
* Config the IPv6 interface up and enable IPv6 packets to pass.
*/
/*ARGSUSED*/
int
sif6up(unit)
int unit;
{
if (if6_is_up) {
return (1);
} else if (!IPV6CP_ENABLED) {
warn("sif6up called when IPV6CP is disabled");
return (0);
} else if (ip6muxid == -1) {
warn("sif6up called in wrong state");
return (0);
} else if (!sif6flags(IFF_UP, 1)) {
error("Unable to mark the IPv6 interface UP");
return (0);
}
if6_is_up = 1;
return (1);
}
/*
* sif6down()
*
* Config the IPv6 interface down and disable IPv6. Possibly called from
* die(), so there shouldn't be any call to die() here.
*/
/*ARGSUSED*/
int
sif6down(unit)
int unit;
{
if (!IPV6CP_ENABLED) {
warn("sif6down called when IPV6CP is disabled");
return (0);
} else if (!if6_is_up || (ip6muxid == -1)) {
return (1);
} else if (!sif6flags(IFF_UP, 0)) {
error("Unable to mark the IPv6 interface DOWN");
return (0);
}
if6_is_up = 0;
return (1);
}
/*
* sif6mtu()
*
* Config the IPv6 interface MTU.
*/
int
sif6mtu(mtu)
int mtu;
{
struct lifreq lifr;
int s;
if (!IPV6CP_ENABLED || (ip6muxid == -1)) {
return (0);
}
s = socket(AF_INET6, SOCK_DGRAM, 0);
if (s < 0) {
error("sif6mtu: error opening IPv6 socket: %m");
return (0);
}
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
lifr.lifr_mtu = mtu;
if (myioctl(s, SIOCSLIFMTU, &lifr) < 0) {
error("Couldn't set IPv6 MTU (%s): %m", lifr.lifr_name);
(void) close(s);
return (0);
}
(void) close(s);
return (1);
}
/*
* sif6addr()
*
* Config the interface with an IPv6 link-local address.
*/
/*ARGSUSED*/
int
sif6addr(unit, ourid, hisid)
int unit;
eui64_t ourid;
eui64_t hisid;
{
struct lifreq lifr;
struct sockaddr_storage laddr;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&laddr;
int fd;
if (!IPV6CP_ENABLED || (ip6muxid == -1 && plumb_ip6if(unit) == 0)) {
return (0);
}
fd = socket(AF_INET6, SOCK_DGRAM, 0);
if (fd < 0) {
error("sif6addr: error opening IPv6 socket: %m");
return (0);
}
/*
* Set the IPv6 interface MTU.
*/
if (!sif6mtu(link_mtu)) {
(void) close(fd);
return (0);
}
/*
* Set the interface address token. Do this because /dev/ppp responds
* to DL_PHYS_ADDR_REQ with zero values, hence the interface token
* came to be zero too, and without this, in.ndpd will complain.
*/
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
BZERO(sin6, sizeof (struct sockaddr_in6));
IN6_LLTOKEN_FROM_EUI64(lifr, sin6, ourid);
if (myioctl(fd, SIOCSLIFTOKEN, &lifr) < 0) {
error("Couldn't set IPv6 token (%s): %m", lifr.lifr_name);
(void) close(fd);
return (0);
}
/*
* Set the IPv6 interface local point-to-point address.
*/
IN6_LLADDR_FROM_EUI64(lifr, sin6, ourid);
if (myioctl(fd, SIOCSLIFADDR, &lifr) < 0) {
error("Couldn't set local IPv6 address (%s): %m",
lifr.lifr_name);
(void) close(fd);
return (0);
}
/*
* Set the IPv6 interface local point-to-point address.
*/
BZERO(&lifr, sizeof (lifr));
(void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
IN6_LLADDR_FROM_EUI64(lifr, sin6, hisid);
if (myioctl(fd, SIOCSLIFDSTADDR, &lifr) < 0) {
error("Couldn't set remote IPv6 address (%s): %m",
lifr.lifr_name);
(void) close(fd);
return (0);
}
(void) close(fd);
return (1);
}
/*
* cif6addr()
*/
/*ARGSUSED*/
int
cif6addr(u, o, h)
int u;
eui64_t o;
eui64_t h;
{
if (!IPV6CP_ENABLED) {
return (0);
}
/*
* Do nothing here, as everything has been done in sif6down().
*/
return (1);
}
/*
* ether_to_eui64()
*
* Convert 48-bit Ethernet address into 64-bit EUI. Walks the list of valid
* ethernet interfaces, and convert the first found 48-bit MAC address into
* EUI 64. caller also assumes that the system has a properly configured
* Ethernet interface for this function to return non-zero.
*/
int
ether_to_eui64(p_eui64)
eui64_t *p_eui64;
{
struct ether_addr eth_addr;
if (p_eui64 == NULL) {
return (0);
}
if (!get_first_hwaddr(eth_addr.ether_addr_octet,
sizeof (eth_addr.ether_addr_octet))) {
return (0);
}
/*
* And convert the EUI-48 into EUI-64, per RFC 2472 [sec 4.1]
*/
p_eui64->e8[0] = (eth_addr.ether_addr_octet[0] & 0xFF) | 0x02;
p_eui64->e8[1] = (eth_addr.ether_addr_octet[1] & 0xFF);
p_eui64->e8[2] = (eth_addr.ether_addr_octet[2] & 0xFF);
p_eui64->e8[3] = 0xFF;
p_eui64->e8[4] = 0xFE;
p_eui64->e8[5] = (eth_addr.ether_addr_octet[3] & 0xFF);
p_eui64->e8[6] = (eth_addr.ether_addr_octet[4] & 0xFF);
p_eui64->e8[7] = (eth_addr.ether_addr_octet[5] & 0xFF);
return (1);
}
#endif /* INET6 */
struct bit_ent {
int val;
char *off, *on;
};
/* see sbuf[] below if you change this list */
static struct bit_ent bit_list[] = {
{ TIOCM_DTR, "dtr", "DTR" },
{ TIOCM_RTS, "rts", "RTS" },
{ TIOCM_CTS, "cts", "CTS" },
{ TIOCM_CD, "dcd", "DCD" },
{ TIOCM_RI, "ri", "RI" },
{ TIOCM_DSR, "dsr", "DSR" },
#if 0
{ TIOCM_LE, "disabled", "ENABLED" },
{ TIOCM_ST, NULL, "2nd-XMIT" },
{ TIOCM_SR, NULL, "2nd-RECV" },
#endif
{ 0, NULL, NULL }
};
static void
getbits(int fd, char *name, FILE *strptr)
{
int nmods, i;
struct str_list strlist;
struct bit_ent *be;
int mstate;
char sbuf[50]; /* sum of string lengths in bit_list */
char *str;
nmods = ioctl(fd, I_LIST, NULL);
if (nmods < 0) {
error("unable to get module count: %m");
} else {
strlist.sl_nmods = nmods;
strlist.sl_modlist = malloc(sizeof (struct str_mlist) * nmods);
if (strlist.sl_modlist == NULL)
novm("module list");
if (ioctl(fd, I_LIST, (caddr_t)&strlist) < 0) {
error("unable to get module names: %m");
} else {
for (i = 0; i < strlist.sl_nmods; i++)
(void) flprintf(strptr, "%d: %s", i,
strlist.sl_modlist[i].l_name);
free(strlist.sl_modlist);
}
}
if (ioctl(fd, TIOCMGET, &mstate) < 0) {
error("unable to get modem state: %m");
} else {
sbuf[0] = '\0';
for (be = bit_list; be->val != 0; be++) {
str = (be->val & mstate) ? be->on : be->off;
if (str != NULL) {
if (sbuf[0] != '\0')
(void) strcat(sbuf, " ");
(void) strcat(sbuf, str);
}
}
(void) flprintf(strptr, "%s: %s\n", name, sbuf);
}
}
/*
* Print state of serial link. The stream might be linked under the
* /dev/sppp driver. If it is, then it's necessary to unlink it first
* and relink it when done. Otherwise, it's not possible to use
* ioctl() on the stream.
*/
void
sys_print_state(FILE *strptr)
{
bool was_linked;
if (pppfd == -1)
return;
if (ttyfd == -1) {
(void) flprintf(strptr, "serial link is not active");
return;
}
was_linked = fdmuxid != -1;
if (was_linked && ioctl(pppfd, I_UNLINK, fdmuxid) == -1) {
error("I_UNLINK: %m");
} else {
fdmuxid = -1;
getbits(ttyfd, devnam, strptr);
if (was_linked &&
(fdmuxid = ioctl(pppfd, I_LINK, (void *)ttyfd)) == -1)
fatal("I_LINK: %m");
}
}
/*
* send ioctl to driver asking it to block packets with network protocol
* proto in the control queue until the queue for proto is plumbed.
*/
void
sys_block_proto(uint16_t proto)
{
if (proto > 0x7fff) {
warn("cannot block: not a network proto 0x%lx\n", proto);
return;
}
if (strioctl(pppfd, PPPIO_BLOCKNP, &proto, sizeof (proto), 0) < 0) {
warn("PPPIO_BLOCKNP ioctl failed %m");
}
}
/*
* send ioctl to driver asking it to release packets with network protocol
* proto from control queue to the protocol specific queue.
*/
void
sys_unblock_proto(uint16_t proto)
{
if (proto > 0x7fff) {
warn("cannot unblock: not a network proto 0x%lx\n", proto);
return;
}
if (strioctl(pppfd, PPPIO_UNBLOCKNP, &proto, sizeof (proto), 0) < 0) {
warn("PPPIO_UNBLOCKNP ioctl failed %m");
}
}
|