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
|
/*
* IS-IS Rout(e)ing protocol - isis_pdu.c
* PDU processing
*
* Copyright (C) 2001,2002 Sampo Saaristo
* Tampere University of Technology
* Institute of Communications Engineering
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public Licenseas published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <zebra.h>
#include "memory.h"
#include "thread.h"
#include "linklist.h"
#include "log.h"
#include "stream.h"
#include "vty.h"
#include "hash.h"
#include "prefix.h"
#include "if.h"
#include "checksum.h"
#include "md5.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_flags.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_network.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_dr.h"
#include "isisd/isis_tlv.h"
#include "isisd/isisd.h"
#include "isisd/isis_dynhn.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/iso_checksum.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
#define ISIS_MINIMUM_FIXED_HDR_LEN 15
#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
#ifndef PNBBY
#define PNBBY 8
#endif /* PNBBY */
/* Utility mask array. */
static const u_char maskbit[] = {
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
};
/*
* HELPER FUNCS
*/
/*
* Compares two sets of area addresses
*/
static int
area_match (struct list *left, struct list *right)
{
struct area_addr *addr1, *addr2;
struct listnode *node1, *node2;
for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
{
for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
{
if (addr1->addr_len == addr2->addr_len &&
!memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
return 1; /* match */
}
}
return 0; /* mismatch */
}
/*
* Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
* param ip1 the IS interface ip address structure
* param ip2 the IIH's ip address
* return 0 the IIH's IP is not in the IS's subnetwork
* 1 the IIH's IP is in the IS's subnetwork
*/
static int
ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
{
u_char *addr1, *addr2;
int shift, offset, offsetloop;
int len;
addr1 = (u_char *) & ip1->prefix.s_addr;
addr2 = (u_char *) & ip2->s_addr;
len = ip1->prefixlen;
shift = len % PNBBY;
offsetloop = offset = len / PNBBY;
while (offsetloop--)
if (addr1[offsetloop] != addr2[offsetloop])
return 0;
if (shift)
if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
return 0;
return 1; /* match */
}
/*
* Compares two set of ip addresses
* param left the local interface's ip addresses
* param right the iih interface's ip address
* return 0 no match;
* 1 match;
*/
static int
ip_match (struct list *left, struct list *right)
{
struct prefix_ipv4 *ip1;
struct in_addr *ip2;
struct listnode *node1, *node2;
if ((left == NULL) || (right == NULL))
return 0;
for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
{
for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
{
if (ip_same_subnet (ip1, ip2))
{
return 1; /* match */
}
}
}
return 0;
}
/*
* Checks whether we should accept a PDU of given level
*/
static int
accept_level (int level, int circuit_t)
{
int retval = ((circuit_t & level) == level); /* simple approach */
return retval;
}
/*
* Verify authentication information
* Support cleartext and HMAC MD5 authentication
*/
static int
authentication_check (struct isis_passwd *remote, struct isis_passwd *local,
struct stream *stream, uint32_t auth_tlv_offset)
{
unsigned char digest[ISIS_AUTH_MD5_SIZE];
/* Auth fail () - passwd type mismatch */
if (local->type != remote->type)
return ISIS_ERROR;
switch (local->type)
{
/* No authentication required */
case ISIS_PASSWD_TYPE_UNUSED:
break;
/* Cleartext (ISO 10589) */
case ISIS_PASSWD_TYPE_CLEARTXT:
/* Auth fail () - passwd len mismatch */
if (remote->len != local->len)
return ISIS_ERROR;
return memcmp (local->passwd, remote->passwd, local->len);
/* HMAC MD5 (RFC 3567) */
case ISIS_PASSWD_TYPE_HMAC_MD5:
/* Auth fail () - passwd len mismatch */
if (remote->len != ISIS_AUTH_MD5_SIZE)
return ISIS_ERROR;
/* Set the authentication value to 0 before the check */
memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0,
ISIS_AUTH_MD5_SIZE);
/* Compute the digest */
hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream),
(unsigned char *) &(local->passwd), local->len,
(unsigned char *) &digest);
/* Copy back the authentication value after the check */
memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3,
remote->passwd, ISIS_AUTH_MD5_SIZE);
return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
default:
zlog_err ("Unsupported authentication type");
return ISIS_ERROR;
}
/* Authentication pass when no authentication is configured */
return ISIS_OK;
}
static int
lsp_authentication_check (struct stream *stream, struct isis_area *area,
int level, struct isis_passwd *passwd)
{
struct isis_link_state_hdr *hdr;
uint32_t expected = 0, found = 0, auth_tlv_offset = 0;
uint16_t checksum, rem_lifetime, pdu_len;
struct tlvs tlvs;
int retval = ISIS_OK;
hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream));
pdu_len = ntohs (hdr->pdu_len);
expected |= TLVFLAG_AUTH_INFO;
auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN;
retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN,
pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN,
&expected, &found, &tlvs, &auth_tlv_offset);
if (retval != ISIS_OK)
{
zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, "
"cksum 0x%04x, lifetime %us, len %u",
area->area_tag, level, rawlspid_print (hdr->lsp_id),
ntohl (hdr->seq_num), ntohs (hdr->checksum),
ntohs (hdr->rem_lifetime), pdu_len);
if ((isis->debugs & DEBUG_UPDATE_PACKETS) &&
(isis->debugs & DEBUG_PACKET_DUMP))
zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream));
return retval;
}
if (!(found & TLVFLAG_AUTH_INFO))
{
zlog_err ("No authentication tlv in LSP");
return ISIS_ERROR;
}
if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT &&
tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5)
{
zlog_err ("Unknown authentication type in LSP");
return ISIS_ERROR;
}
/*
* RFC 5304 set checksum and remaining lifetime to zero before
* verification and reset to old values after verification.
*/
checksum = hdr->checksum;
rem_lifetime = hdr->rem_lifetime;
hdr->checksum = 0;
hdr->rem_lifetime = 0;
retval = authentication_check (&tlvs.auth_info, passwd, stream,
auth_tlv_offset);
hdr->checksum = checksum;
hdr->rem_lifetime = rem_lifetime;
return retval;
}
/*
* Processing helper functions
*/
static void
del_addr (void *val)
{
XFREE (MTYPE_ISIS_TMP, val);
}
static void
tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
{
struct listnode *node;
struct area_addr *area_addr, *malloced;
if (adj->area_addrs)
{
adj->area_addrs->del = del_addr;
list_delete (adj->area_addrs);
}
adj->area_addrs = list_new ();
if (tlvs->area_addrs)
{
for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr))
{
malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr));
memcpy (malloced, area_addr, sizeof (struct area_addr));
listnode_add (adj->area_addrs, malloced);
}
}
}
static int
tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
{
int i;
struct nlpids *tlv_nlpids;
if (tlvs->nlpids)
{
tlv_nlpids = tlvs->nlpids;
if (tlv_nlpids->count > array_size (adj->nlpids.nlpids))
return 1;
adj->nlpids.count = tlv_nlpids->count;
for (i = 0; i < tlv_nlpids->count; i++)
{
adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
}
}
return 0;
}
static void
tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
{
struct listnode *node;
struct in_addr *ipv4_addr, *malloced;
if (adj->ipv4_addrs)
{
adj->ipv4_addrs->del = del_addr;
list_delete (adj->ipv4_addrs);
}
adj->ipv4_addrs = list_new ();
if (tlvs->ipv4_addrs)
{
for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
{
malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
listnode_add (adj->ipv4_addrs, malloced);
}
}
}
static void
tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
{
struct listnode *node;
struct in6_addr *ipv6_addr, *malloced;
if (adj->ipv6_addrs)
{
adj->ipv6_addrs->del = del_addr;
list_delete (adj->ipv6_addrs);
}
adj->ipv6_addrs = list_new ();
if (tlvs->ipv6_addrs)
{
for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
{
malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
listnode_add (adj->ipv6_addrs, malloced);
}
}
}
/*
* RECEIVE SIDE
*/
/*
* Process P2P IIH
* ISO - 10589
* Section 8.2.5 - Receiving point-to-point IIH PDUs
*
*/
static int
process_p2p_hello (struct isis_circuit *circuit)
{
int retval = ISIS_OK;
struct isis_p2p_hello_hdr *hdr;
struct isis_adjacency *adj;
u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
uint16_t pdu_len;
struct tlvs tlvs;
int v4_usable = 0, v6_usable = 0;
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u",
circuit->area->area_tag, circuit->interface->name,
circuit_t2string (circuit->is_type), circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
stream_get_endp (circuit->rcv_stream));
}
if (circuit->circ_type != CIRCUIT_T_P2P)
{
zlog_warn ("p2p hello on non p2p circuit");
return ISIS_WARNING;
}
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
{
zlog_warn ("Packet too short");
return ISIS_WARNING;
}
/* 8.2.5.1 PDU acceptance tests */
/* 8.2.5.1 a) external domain untrue */
/* FIXME: not useful at all? */
/* 8.2.5.1 b) ID Length mismatch */
/* checked at the handle_pdu */
/* 8.2.5.2 IIH PDU Processing */
/* 8.2.5.2 a) 1) Maximum Area Addresses */
/* Already checked, and can also be ommited */
/*
* Get the header
*/
hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
pdu_len = ntohs (hdr->pdu_len);
if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) ||
pdu_len > ISO_MTU(circuit) ||
pdu_len > stream_get_endp (circuit->rcv_stream))
{
zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with "
"invalid pdu length %d",
circuit->area->area_tag, circuit->interface->name, pdu_len);
return ISIS_WARNING;
}
/*
* Set the stream endp to PDU length, ignoring additional padding
* introduced by transport chips.
*/
if (pdu_len < stream_get_endp (circuit->rcv_stream))
stream_set_endp (circuit->rcv_stream, pdu_len);
stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN);
/*
* Lets get the TLVS now
*/
expected |= TLVFLAG_AREA_ADDRS;
expected |= TLVFLAG_AUTH_INFO;
expected |= TLVFLAG_NLPID;
expected |= TLVFLAG_IPV4_ADDR;
expected |= TLVFLAG_IPV6_ADDR;
expected |= TLVFLAG_MT_ROUTER_INFORMATION;
auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
retval = parse_tlvs (circuit->area->area_tag,
STREAM_PNT (circuit->rcv_stream),
pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
&expected, &found, &tlvs, &auth_tlv_offset);
if (retval > ISIS_WARNING)
{
zlog_warn ("parse_tlvs() failed");
free_tlvs (&tlvs);
return retval;
};
if (!(found & TLVFLAG_AREA_ADDRS))
{
zlog_warn ("No Area addresses TLV in P2P IS to IS hello");
free_tlvs (&tlvs);
return ISIS_WARNING;
}
if (!(found & TLVFLAG_NLPID))
{
zlog_warn ("No supported protocols TLV in P2P IS to IS hello");
free_tlvs (&tlvs);
return ISIS_WARNING;
}
/* 8.2.5.1 c) Authentication */
if (circuit->passwd.type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
authentication_check (&tlvs.auth_info, &circuit->passwd,
circuit->rcv_stream, auth_tlv_offset))
{
isis_event_auth_failure (circuit->area->area_tag,
"P2P hello authentication failure",
hdr->source_id);
free_tlvs (&tlvs);
return ISIS_OK;
}
}
/*
* check if it's own interface ip match iih ip addrs
*/
if (found & TLVFLAG_IPV4_ADDR)
{
if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
v4_usable = 1;
else
zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
"in P2P IIH from %s\n", circuit->interface->name);
}
if (found & TLVFLAG_IPV6_ADDR)
{
/* TBA: check that we have a linklocal ourselves? */
struct listnode *node;
struct in6_addr *ip;
for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
if (IN6_IS_ADDR_LINKLOCAL (ip))
{
v6_usable = 1;
break;
}
if (!v6_usable)
zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
"in P2P IIH from %s\n", circuit->interface->name);
}
if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n",
circuit->interface->name);
if (!v6_usable && !v4_usable)
{
free_tlvs (&tlvs);
return ISIS_WARNING;
}
/*
* it's own p2p IIH PDU - discard
*/
if (!memcmp (hdr->source_id, isis->sysid, ISIS_SYS_ID_LEN))
{
zlog_warn ("ISIS-Adj (%s): it's own IIH PDU - discarded",
circuit->area->area_tag);
free_tlvs (&tlvs);
return ISIS_WARNING;
}
/*
* My interpertation of the ISO, if no adj exists we will create one for
* the circuit
*/
adj = circuit->u.p2p.neighbor;
/* If an adjacency exists, check it is with the source of the hello
* packets */
if (adj)
{
if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
{
zlog_debug("hello source and adjacency do not match, set adj down\n");
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
return 0;
}
}
if (!adj || adj->level != hdr->circuit_t)
{
if (!adj)
{
adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit);
if (adj == NULL)
return ISIS_ERROR;
}
else
{
adj->level = hdr->circuit_t;
}
circuit->u.p2p.neighbor = adj;
/* Build lsp with the new neighbor entry when a new
* adjacency is formed. Set adjacency circuit type to
* IIH PDU header circuit type before lsp is regenerated
* when an adjacency is up. This will result in the new
* adjacency entry getting added to the lsp tlv neighbor list.
*/
adj->circuit_t = hdr->circuit_t;
isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
}
/* 8.2.6 Monitoring point-to-point adjacencies */
adj->hold_time = ntohs (hdr->hold_time);
adj->last_upd = time (NULL);
/* we do this now because the adj may not survive till the end... */
tlvs_to_adj_area_addrs (&tlvs, adj);
/* which protocol are spoken ??? */
if (tlvs_to_adj_nlpids (&tlvs, adj))
{
free_tlvs (&tlvs);
return ISIS_WARNING;
}
/* we need to copy addresses to the adj */
if (found & TLVFLAG_IPV4_ADDR)
tlvs_to_adj_ipv4_addrs (&tlvs, adj);
/* Update MPLS TE Remote IP address parameter if possible */
if (IS_MPLS_TE(isisMplsTE) && circuit->mtc && IS_CIRCUIT_TE(circuit->mtc))
if (adj->ipv4_addrs != NULL && listcount(adj->ipv4_addrs) != 0)
{
struct in_addr *ip_addr;
ip_addr = (struct in_addr *)listgetdata ((struct listnode *)listhead (adj->ipv4_addrs));
set_circuitparams_rmt_ipaddr (circuit->mtc, *ip_addr);
}
if (found & TLVFLAG_IPV6_ADDR)
tlvs_to_adj_ipv6_addrs (&tlvs, adj);
bool mt_set_changed = tlvs_to_adj_mt_set(&tlvs, v4_usable, v6_usable, adj);
/* lets take care of the expiry */
THREAD_TIMER_OFF (adj->t_expire);
THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
(long) adj->hold_time);
/* 8.2.5.2 a) a match was detected */
if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
{
/* 8.2.5.2 a) 2) If the system is L1 - table 5 */
if (circuit->area->is_type == IS_LEVEL_1)
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
case IS_LEVEL_1_AND_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (4) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (5) adj usage level 1 */
adj->adj_usage = ISIS_ADJ_LEVEL1;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
; /* accept */
}
break;
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (7) reject - wrong system type event */
zlog_warn ("wrongSystemType");
free_tlvs (&tlvs);
return ISIS_WARNING; /* Reject */
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
/* (6) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
}
}
/* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
if (circuit->area->is_type == IS_LEVEL_1_AND_2)
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (7) adj usage level 1 */
adj->adj_usage = ISIS_ADJ_LEVEL1;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
; /* accept */
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (8) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (9) adj usage level 2 */
adj->adj_usage = ISIS_ADJ_LEVEL2;
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
(adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
{
/* (8) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
{
; /* Accept */
}
break;
case IS_LEVEL_1_AND_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (10) adj usage level 1 */
adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (8) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
{
; /* Accept */
}
break;
}
}
/* 8.2.5.2 a) 4) If the system is L2 - table 7 */
if (circuit->area->is_type == IS_LEVEL_2)
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (5) reject - wrong system type event */
zlog_warn ("wrongSystemType");
free_tlvs (&tlvs);
return ISIS_WARNING; /* Reject */
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (6) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (7) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (8) adj usage level 2 */
adj->adj_usage = ISIS_ADJ_LEVEL2;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
{
/* (6) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
{
; /* Accept */
}
break;
}
}
}
/* 8.2.5.2 b) if no match was detected */
else if (listcount (circuit->area->area_addrs) > 0)
{
if (circuit->area->is_type == IS_LEVEL_1)
{
/* 8.2.5.2 b) 1) is_type L1 and adj is not up */
if (adj->adj_state != ISIS_ADJ_UP)
{
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
/* 8.2.5.2 b) 2)is_type L1 and adj is up */
}
else
{
isis_adj_state_change (adj, ISIS_ADJ_DOWN,
"Down - Area Mismatch");
}
}
/* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
else
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) reject - Area Mismatch event */
zlog_warn ("AreaMismatch");
free_tlvs (&tlvs);
return ISIS_WARNING; /* Reject */
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
/* (7) down - area mismatch */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (7) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (8) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (9) adj usage level 2 */
adj->adj_usage = ISIS_ADJ_LEVEL2;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
/* (7) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
{
if (hdr->circuit_t == IS_LEVEL_2)
{
/* (7) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN,
"Wrong System");
}
else
{
/* (7) down - area mismatch */
isis_adj_state_change (adj, ISIS_ADJ_DOWN,
"Area Mismatch");
}
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
{
; /* Accept */
}
break;
}
}
}
else
{
/* down - area mismatch */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
}
if (adj->adj_state == ISIS_ADJ_UP && mt_set_changed)
{
lsp_regenerate_schedule(adj->circuit->area,
isis_adj_usage2levels(adj->adj_usage), 0);
}
/* 8.2.5.2 c) if the action was up - comparing circuit IDs */
/* FIXME - Missing parts */
/* some of my own understanding of the ISO, why the heck does
* it not say what should I change the system_type to...
*/
switch (adj->adj_usage)
{
case ISIS_ADJ_LEVEL1:
adj->sys_type = ISIS_SYSTYPE_L1_IS;
break;
case ISIS_ADJ_LEVEL2:
adj->sys_type = ISIS_SYSTYPE_L2_IS;
break;
case ISIS_ADJ_LEVEL1AND2:
adj->sys_type = ISIS_SYSTYPE_L2_IS;
break;
case ISIS_ADJ_NONE:
adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
break;
}
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
" cir id %02d, length %d",
circuit->area->area_tag, circuit->interface->name,
circuit_t2string (circuit->is_type),
circuit->circuit_id, pdu_len);
}
free_tlvs (&tlvs);
return retval;
}
/*
* Process IS-IS LAN Level 1/2 Hello PDU
*/
static int
process_lan_hello (int level, struct isis_circuit *circuit, const u_char *ssnpa)
{
int retval = ISIS_OK;
struct isis_lan_hello_hdr hdr;
struct isis_adjacency *adj;
u_int32_t expected = 0, found = 0, auth_tlv_offset = 0;
struct tlvs tlvs;
u_char *snpa;
struct listnode *node;
int v4_usable = 0, v6_usable = 0;
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, "
"cirID %u",
circuit->area->area_tag, level, circuit->interface->name,
circuit_t2string (circuit->is_type), circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
stream_get_endp (circuit->rcv_stream));
}
if (circuit->circ_type != CIRCUIT_T_BROADCAST)
{
zlog_warn ("lan hello on non broadcast circuit");
return ISIS_WARNING;
}
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
{
zlog_warn ("Packet too short");
return ISIS_WARNING;
}
if (circuit->ext_domain)
{
zlog_debug ("level %d LAN Hello received over circuit with "
"externalDomain = true", level);
return ISIS_WARNING;
}
if (!accept_level (level, circuit->is_type))
{
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
circuit->area->area_tag, circuit->interface->name);
}
return ISIS_WARNING;
}
#if 0
/* Cisco's debug message compatability */
if (!accept_level (level, circuit->area->is_type))
{
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): is type mismatch",
circuit->area->area_tag);
}
return ISIS_WARNING;
}
#endif
/*
* Fill the header
*/
hdr.circuit_t = stream_getc (circuit->rcv_stream);
stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
hdr.hold_time = stream_getw (circuit->rcv_stream);
hdr.pdu_len = stream_getw (circuit->rcv_stream);
hdr.prio = stream_getc (circuit->rcv_stream);
stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) ||
hdr.pdu_len > ISO_MTU(circuit) ||
hdr.pdu_len > stream_get_endp (circuit->rcv_stream))
{
zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with "
"invalid pdu length %d",
circuit->area->area_tag, circuit->interface->name,
hdr.pdu_len);
return ISIS_WARNING;
}
/*
* Set the stream endp to PDU length, ignoring additional padding
* introduced by transport chips.
*/
if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream))
stream_set_endp (circuit->rcv_stream, hdr.pdu_len);
if (hdr.circuit_t != IS_LEVEL_1 &&
hdr.circuit_t != IS_LEVEL_2 &&
hdr.circuit_t != IS_LEVEL_1_AND_2 &&
(level & hdr.circuit_t) == 0)
{
zlog_err ("Level %d LAN Hello with Circuit Type %d", level,
hdr.circuit_t);
return ISIS_ERROR;
}
/*
* Then get the tlvs
*/
expected |= TLVFLAG_AUTH_INFO;
expected |= TLVFLAG_AREA_ADDRS;
expected |= TLVFLAG_LAN_NEIGHS;
expected |= TLVFLAG_NLPID;
expected |= TLVFLAG_IPV4_ADDR;
expected |= TLVFLAG_IPV6_ADDR;
expected |= TLVFLAG_MT_ROUTER_INFORMATION;
auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
retval = parse_tlvs (circuit->area->area_tag,
STREAM_PNT (circuit->rcv_stream),
hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN,
&expected, &found, &tlvs,
&auth_tlv_offset);
if (retval > ISIS_WARNING)
{
zlog_warn ("parse_tlvs() failed");
goto out;
}
if (!(found & TLVFLAG_AREA_ADDRS))
{
zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
level);
retval = ISIS_WARNING;
goto out;
}
if (!(found & TLVFLAG_NLPID))
{
zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello",
level);
retval = ISIS_WARNING;
goto out;
}
/* Verify authentication, either cleartext of HMAC MD5 */
if (circuit->passwd.type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
authentication_check (&tlvs.auth_info, &circuit->passwd,
circuit->rcv_stream, auth_tlv_offset))
{
isis_event_auth_failure (circuit->area->area_tag,
"LAN hello authentication failure",
hdr.source_id);
retval = ISIS_WARNING;
goto out;
}
}
if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN))
{
zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s",
circuit->area->area_tag, circuit->interface->name);
return ISIS_WARNING;
}
/*
* Accept the level 1 adjacency only if a match between local and
* remote area addresses is found
*/
if (listcount (circuit->area->area_addrs) == 0 ||
(level == IS_LEVEL_1 &&
area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0))
{
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
circuit->area->area_tag, level,
circuit->interface->name);
}
retval = ISIS_OK;
goto out;
}
/*
* it's own IIH PDU - discard silently
*/
if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
{
zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
circuit->area->area_tag);
retval = ISIS_OK;
goto out;
}
/*
* check if it's own interface ip match iih ip addrs
*/
if (found & TLVFLAG_IPV4_ADDR)
{
if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
v4_usable = 1;
else
zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap "
"in LAN IIH from %s\n", circuit->interface->name);
}
if (found & TLVFLAG_IPV6_ADDR)
{
/* TBA: check that we have a linklocal ourselves? */
struct listnode *node;
struct in6_addr *ip;
for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip))
if (IN6_IS_ADDR_LINKLOCAL (ip))
{
v6_usable = 1;
break;
}
if (!v6_usable)
zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local "
"in LAN IIH from %s\n", circuit->interface->name);
}
if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR)))
zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n",
circuit->interface->name);
if (!v6_usable && !v4_usable)
{
free_tlvs (&tlvs);
return ISIS_WARNING;
}
adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) ||
(adj->level != level))
{
if (!adj)
{
/*
* Do as in 8.4.2.5
*/
adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
if (adj == NULL)
{
retval = ISIS_ERROR;
goto out;
}
}
else
{
if (ssnpa) {
memcpy (adj->snpa, ssnpa, 6);
} else {
memset (adj->snpa, ' ', 6);
}
adj->level = level;
}
isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
if (level == IS_LEVEL_1)
adj->sys_type = ISIS_SYSTYPE_L1_IS;
else
adj->sys_type = ISIS_SYSTYPE_L2_IS;
list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
circuit->u.bc.lan_neighs[level - 1]);
}
if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
switch (level)
{
case 1:
if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
{
thread_add_event (master, isis_event_dis_status_change, circuit, 0);
memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
ISIS_SYS_ID_LEN + 1);
}
break;
case 2:
if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
{
thread_add_event (master, isis_event_dis_status_change, circuit, 0);
memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
ISIS_SYS_ID_LEN + 1);
}
break;
}
adj->hold_time = hdr.hold_time;
adj->last_upd = time (NULL);
adj->prio[level - 1] = hdr.prio;
memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
tlvs_to_adj_area_addrs (&tlvs, adj);
/* which protocol are spoken ??? */
if (tlvs_to_adj_nlpids (&tlvs, adj))
{
retval = ISIS_WARNING;
goto out;
}
/* we need to copy addresses to the adj */
if (found & TLVFLAG_IPV4_ADDR)
tlvs_to_adj_ipv4_addrs (&tlvs, adj);
if (found & TLVFLAG_IPV6_ADDR)
tlvs_to_adj_ipv6_addrs (&tlvs, adj);
adj->circuit_t = hdr.circuit_t;
bool mt_set_changed = tlvs_to_adj_mt_set(&tlvs, v4_usable, v6_usable, adj);
/* lets take care of the expiry */
THREAD_TIMER_OFF (adj->t_expire);
THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
(long) adj->hold_time);
/*
* If the snpa for this circuit is found from LAN Neighbours TLV
* we have two-way communication -> adjacency can be put to state "up"
*/
if (found & TLVFLAG_LAN_NEIGHS)
{
if (adj->adj_state != ISIS_ADJ_UP)
{
for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
{
if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
{
isis_adj_state_change (adj, ISIS_ADJ_UP,
"own SNPA found in LAN Neighbours TLV");
}
}
}
else
{
int found = 0;
for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
{
found = 1;
break;
}
if (found == 0)
isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
"own SNPA not found in LAN Neighbours TLV");
}
}
else if (adj->adj_state == ISIS_ADJ_UP)
{
isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING,
"no LAN Neighbours TLV found");
}
if (adj->adj_state == ISIS_ADJ_UP && mt_set_changed)
lsp_regenerate_schedule(adj->circuit->area, level, 0);
out:
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
"cirID %u, length %zd",
circuit->area->area_tag,
level, snpa_print (ssnpa), circuit->interface->name,
circuit_t2string (circuit->is_type),
circuit->circuit_id,
stream_get_endp (circuit->rcv_stream));
}
free_tlvs (&tlvs);
return retval;
}
/*
* Process Level 1/2 Link State
* ISO - 10589
* Section 7.3.15.1 - Action on receipt of a link state PDU
*/
static int
process_lsp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
{
struct isis_link_state_hdr *hdr;
struct isis_adjacency *adj = NULL;
struct isis_lsp *lsp, *lsp0 = NULL;
int retval = ISIS_OK, comp = 0;
u_char lspid[ISIS_SYS_ID_LEN + 2];
struct isis_passwd *passwd;
uint16_t pdu_len;
int lsp_confusion;
if (isis->debugs & DEBUG_UPDATE_PACKETS)
{
zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u",
circuit->area->area_tag, level, circuit->interface->name,
circuit_t2string (circuit->is_type), circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
stream_get_endp (circuit->rcv_stream));
}
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
{
zlog_warn ("Packet too short");
return ISIS_WARNING;
}
/* Reference the header */
hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
pdu_len = ntohs (hdr->pdu_len);
/* lsp length check */
if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) ||
pdu_len > ISO_MTU(circuit) ||
pdu_len > stream_get_endp (circuit->rcv_stream))
{
zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id), pdu_len);
return ISIS_WARNING;
}
/*
* Set the stream endp to PDU length, ignoring additional padding
* introduced by transport chips.
*/
if (pdu_len < stream_get_endp (circuit->rcv_stream))
stream_set_endp (circuit->rcv_stream, pdu_len);
if (isis->debugs & DEBUG_UPDATE_PACKETS)
{
zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
"lifetime %us, len %u, on %s",
circuit->area->area_tag,
level,
rawlspid_print (hdr->lsp_id),
ntohl (hdr->seq_num),
ntohs (hdr->checksum),
ntohs (hdr->rem_lifetime),
pdu_len,
circuit->interface->name);
}
/* lsp is_type check */
if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 &&
(hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2)
{
zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id), hdr->lsp_bits);
/* continue as per RFC1122 Be liberal in what you accept, and
* conservative in what you send */
}
/* Checksum sanity check - FIXME: move to correct place */
/* 12 = sysid+pdu+remtime */
if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
pdu_len - 12, &hdr->checksum))
{
zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
return ISIS_WARNING;
}
/* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
if (circuit->ext_domain)
{
zlog_debug
("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
"externalDomain = true", circuit->area->area_tag,
rawlspid_print (hdr->lsp_id), level);
return ISIS_WARNING;
}
/* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
if (!accept_level (level, circuit->is_type))
{
zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
" type %s",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id),
level, circuit_t2string (circuit->is_type));
return ISIS_WARNING;
}
/* 7.3.15.1 a) 4 - need to make sure IDLength matches */
/* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
/* 7.3.15.1 a) 7 - password check */
(level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) :
(passwd = &circuit->area->domain_passwd);
if (passwd->type)
{
if (lsp_authentication_check (circuit->rcv_stream, circuit->area,
level, passwd))
{
isis_event_auth_failure (circuit->area->area_tag,
"LSP authentication failure", hdr->lsp_id);
return ISIS_WARNING;
}
}
/* Find the LSP in our database and compare it to this Link State header */
lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]);
if (lsp)
comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num,
hdr->checksum, hdr->rem_lifetime);
if (lsp && (lsp->own_lsp))
goto dontcheckadj;
/* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */
/* for broadcast circuits, snpa should be compared */
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
{
adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]);
if (!adj)
{
zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, "
"lifetime %us on %s",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id),
ntohl (hdr->seq_num),
ntohs (hdr->checksum),
ntohs (hdr->rem_lifetime), circuit->interface->name);
return ISIS_WARNING; /* Silently discard */
}
}
/* for non broadcast, we just need to find same level adj */
else
{
/* If no adj, or no sharing of level */
if (!circuit->u.p2p.neighbor)
{
return ISIS_OK; /* Silently discard */
}
else
{
if (((level == IS_LEVEL_1) &&
(circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) ||
((level == IS_LEVEL_2) &&
(circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1)))
return ISIS_WARNING; /* Silently discard */
adj = circuit->u.p2p.neighbor;
}
}
dontcheckadj:
/* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */
/* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */
/* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */
/* 7.3.16.2 - If this is an LSP from another IS with identical seq_num but
* wrong checksum, initiate a purge. */
if (lsp
&& (lsp->lsp_header->seq_num == hdr->seq_num)
&& (lsp->lsp_header->checksum != hdr->checksum))
{
zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
circuit->area->area_tag, rawlspid_print(hdr->lsp_id),
ntohl(hdr->seq_num));
hdr->rem_lifetime = 0;
lsp_confusion = 1;
}
else
lsp_confusion = 0;
/* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */
if (hdr->rem_lifetime == 0)
{
if (!lsp)
{
/* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */
/* only needed on explicit update, eg - p2p */
if (circuit->circ_type == CIRCUIT_T_P2P)
ack_lsp (hdr, circuit, level);
return retval; /* FIXME: do we need a purge? */
}
else
{
if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
{
/* LSP by some other system -> do 7.3.16.4 b) */
/* 7.3.16.4 b) 1) */
if (comp == LSP_NEWER)
{
lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
/* ii */
lsp_set_all_srmflags (lsp);
/* v */
ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */
/* For the case of lsp confusion, flood the purge back to its
* originator so that it can react. Otherwise, don't reflood
* through incoming circuit as usual */
if (!lsp_confusion)
{
/* iii */
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
/* iv */
if (circuit->circ_type != CIRCUIT_T_BROADCAST)
ISIS_SET_FLAG (lsp->SSNflags, circuit);
}
} /* 7.3.16.4 b) 2) */
else if (comp == LSP_EQUAL)
{
/* i */
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
/* ii */
if (circuit->circ_type != CIRCUIT_T_BROADCAST)
ISIS_SET_FLAG (lsp->SSNflags, circuit);
} /* 7.3.16.4 b) 3) */
else
{
ISIS_SET_FLAG (lsp->SRMflags, circuit);
ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
}
}
else if (lsp->lsp_header->rem_lifetime != 0)
{
/* our own LSP -> 7.3.16.4 c) */
if (comp == LSP_NEWER)
{
lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
lsp_set_all_srmflags (lsp);
}
else
{
ISIS_SET_FLAG (lsp->SRMflags, circuit);
ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
}
if (isis->debugs & DEBUG_UPDATE_PACKETS)
zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new "
"seq 0x%08x", circuit->area->area_tag,
rawlspid_print (hdr->lsp_id),
ntohl (lsp->lsp_header->seq_num));
}
}
return retval;
}
/* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a
* purge */
if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0)
{
if (!lsp)
{
/* 7.3.16.4: initiate a purge */
lsp_purge_non_exist(level, hdr, circuit->area);
return ISIS_OK;
}
/* 7.3.15.1 d) - If this is our own lsp and we have it */
/* In 7.3.16.1, If an Intermediate system R somewhere in the domain
* has information that the current sequence number for source S is
* "greater" than that held by S, ... */
if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num))
{
/* 7.3.16.1 */
lsp_inc_seqnum (lsp, ntohl (hdr->seq_num));
if (isis->debugs & DEBUG_UPDATE_PACKETS)
zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq "
"0x%08x", circuit->area->area_tag,
rawlspid_print (hdr->lsp_id),
ntohl (lsp->lsp_header->seq_num));
}
/* If the received LSP is older or equal,
* resend the LSP which will act as ACK */
lsp_set_all_srmflags (lsp);
}
else
{
/* 7.3.15.1 e) - This lsp originated on another system */
/* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
if ((!lsp || comp == LSP_NEWER))
{
/*
* If this lsp is a frag, need to see if we have zero lsp present
*/
if (LSP_FRAGMENT (hdr->lsp_id) != 0)
{
memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1);
LSP_FRAGMENT (lspid) = 0;
lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]);
if (!lsp0)
{
zlog_debug ("Got lsp frag, while zero lsp not in database");
return ISIS_OK;
}
}
/* i */
if (!lsp)
{
lsp = lsp_new_from_stream_ptr (circuit->rcv_stream,
pdu_len, lsp0,
circuit->area, level);
lsp_insert (lsp, circuit->area->lspdb[level - 1]);
}
else /* exists, so we overwrite */
{
lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
}
/* ii */
lsp_set_all_srmflags (lsp);
/* iii */
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
/* iv */
if (circuit->circ_type != CIRCUIT_T_BROADCAST)
ISIS_SET_FLAG (lsp->SSNflags, circuit);
/* FIXME: v) */
}
/* 7.3.15.1 e) 2) LSP equal to the one in db */
else if (comp == LSP_EQUAL)
{
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
lsp_update (lsp, circuit->rcv_stream, circuit->area, level);
if (circuit->circ_type != CIRCUIT_T_BROADCAST)
ISIS_SET_FLAG (lsp->SSNflags, circuit);
}
/* 7.3.15.1 e) 3) LSP older than the one in db */
else
{
ISIS_SET_FLAG (lsp->SRMflags, circuit);
ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
}
}
return retval;
}
/*
* Process Sequence Numbers
* ISO - 10589
* Section 7.3.15.2 - Action on receipt of a sequence numbers PDU
*/
static int
process_snp (int snp_type, int level, struct isis_circuit *circuit,
const u_char *ssnpa)
{
int retval = ISIS_OK;
int cmp, own_lsp;
char typechar = ' ';
uint16_t pdu_len;
struct isis_adjacency *adj;
struct isis_complete_seqnum_hdr *chdr = NULL;
struct isis_partial_seqnum_hdr *phdr = NULL;
uint32_t found = 0, expected = 0, auth_tlv_offset = 0;
struct isis_lsp *lsp;
struct lsp_entry *entry;
struct listnode *node, *nnode;
struct listnode *node2, *nnode2;
struct tlvs tlvs;
struct list *lsp_list = NULL;
struct isis_passwd *passwd;
if (snp_type == ISIS_SNP_CSNP_FLAG)
{
/* getting the header info */
typechar = 'C';
chdr =
(struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN);
pdu_len = ntohs (chdr->pdu_len);
if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) ||
pdu_len > ISO_MTU(circuit) ||
pdu_len > stream_get_endp (circuit->rcv_stream))
{
zlog_warn ("Received a CSNP with bogus length %d", pdu_len);
return ISIS_WARNING;
}
}
else
{
typechar = 'P';
phdr =
(struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream);
stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN);
pdu_len = ntohs (phdr->pdu_len);
if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) ||
pdu_len > ISO_MTU(circuit) ||
pdu_len > stream_get_endp (circuit->rcv_stream))
{
zlog_warn ("Received a PSNP with bogus length %d", pdu_len);
return ISIS_WARNING;
}
}
/*
* Set the stream endp to PDU length, ignoring additional padding
* introduced by transport chips.
*/
if (pdu_len < stream_get_endp (circuit->rcv_stream))
stream_set_endp (circuit->rcv_stream, pdu_len);
/* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */
if (circuit->ext_domain)
{
zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
"skipping: circuit externalDomain = true",
circuit->area->area_tag,
level, typechar, circuit->interface->name);
return ISIS_OK;
}
/* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */
if (!accept_level (level, circuit->is_type))
{
zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, "
"skipping: circuit type %s does not match level %d",
circuit->area->area_tag,
level,
typechar,
circuit->interface->name,
circuit_t2string (circuit->is_type), level);
return ISIS_OK;
}
/* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */
if ((snp_type == ISIS_SNP_PSNP_FLAG) &&
(circuit->circ_type == CIRCUIT_T_BROADCAST) &&
(!circuit->u.bc.is_dr[level - 1]))
{
zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, "
"skipping: we are not the DIS",
circuit->area->area_tag,
level,
typechar, snpa_print (ssnpa), circuit->interface->name);
return ISIS_OK;
}
/* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */
/* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3
* - already checked */
/* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */
/* for broadcast circuits, snpa should be compared */
/* FIXME : Do we need to check SNPA? */
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
{
if (snp_type == ISIS_SNP_CSNP_FLAG)
{
adj =
isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]);
}
else
{
/* a psnp on a broadcast, how lovely of Juniper :) */
adj =
isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]);
}
if (!adj)
return ISIS_OK; /* Silently discard */
}
else
{
if (!circuit->u.p2p.neighbor)
{
zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name);
return ISIS_OK; /* Silently discard */
}
}
/* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */
/* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */
memset (&tlvs, 0, sizeof (struct tlvs));
/* parse the SNP */
expected |= TLVFLAG_LSP_ENTRIES;
expected |= TLVFLAG_AUTH_INFO;
auth_tlv_offset = stream_get_getp (circuit->rcv_stream);
retval = parse_tlvs (circuit->area->area_tag,
STREAM_PNT (circuit->rcv_stream),
pdu_len - stream_get_getp (circuit->rcv_stream),
&expected, &found, &tlvs, &auth_tlv_offset);
if (retval > ISIS_WARNING)
{
zlog_warn ("something went very wrong processing SNP");
free_tlvs (&tlvs);
return retval;
}
if (level == IS_LEVEL_1)
passwd = &circuit->area->area_passwd;
else
passwd = &circuit->area->domain_passwd;
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV))
{
if (passwd->type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
authentication_check (&tlvs.auth_info, passwd,
circuit->rcv_stream, auth_tlv_offset))
{
isis_event_auth_failure (circuit->area->area_tag,
"SNP authentication" " failure",
phdr ? phdr->source_id :
chdr->source_id);
free_tlvs (&tlvs);
return ISIS_OK;
}
}
}
/* debug isis snp-packets */
if (isis->debugs & DEBUG_SNP_PACKETS)
{
zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
circuit->area->area_tag,
level,
typechar, snpa_print (ssnpa), circuit->interface->name);
if (tlvs.lsp_entries)
{
for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
{
zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x,"
" cksum 0x%04x, lifetime %us",
circuit->area->area_tag,
typechar,
rawlspid_print (entry->lsp_id),
ntohl (entry->seq_num),
ntohs (entry->checksum), ntohs (entry->rem_lifetime));
}
}
}
/* 7.3.15.2 b) Actions on LSP_ENTRIES reported */
if (tlvs.lsp_entries)
{
for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry))
{
lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]);
own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
if (lsp)
{
/* 7.3.15.2 b) 1) is this LSP newer */
cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num,
entry->checksum, entry->rem_lifetime);
/* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */
if (cmp == LSP_EQUAL)
{
/* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
}
/* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */
else if (cmp == LSP_OLDER)
{
ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
ISIS_SET_FLAG (lsp->SRMflags, circuit);
}
/* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */
else
{
if (own_lsp)
{
lsp_inc_seqnum (lsp, ntohl (entry->seq_num));
ISIS_SET_FLAG (lsp->SRMflags, circuit);
}
else
{
ISIS_SET_FLAG (lsp->SSNflags, circuit);
/* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
}
}
}
else
{
/* 7.3.15.2 b) 5) if it was not found, and all of those are not 0,
* insert it and set SSN on it */
if (entry->rem_lifetime && entry->checksum && entry->seq_num &&
memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN))
{
lsp = lsp_new(circuit->area, entry->lsp_id,
ntohs(entry->rem_lifetime),
0, 0, entry->checksum, level);
lsp_insert (lsp, circuit->area->lspdb[level - 1]);
ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags);
ISIS_SET_FLAG (lsp->SSNflags, circuit);
}
}
}
}
/* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */
if (snp_type == ISIS_SNP_CSNP_FLAG)
{
/*
* Build a list from our own LSP db bounded with
* start_lsp_id and stop_lsp_id
*/
lsp_list = list_new ();
lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id,
lsp_list, circuit->area->lspdb[level - 1]);
/* Fixme: Find a better solution */
if (tlvs.lsp_entries)
{
for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry))
{
for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp))
{
if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0)
{
list_delete_node (lsp_list, node2);
break;
}
}
}
}
/* on remaining LSPs we set SRM (neighbor knew not of) */
for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp))
ISIS_SET_FLAG (lsp->SRMflags, circuit);
/* lets free it */
list_delete (lsp_list);
}
free_tlvs (&tlvs);
return retval;
}
static int
process_csnp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
{
if (isis->debugs & DEBUG_SNP_PACKETS)
{
zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u",
circuit->area->area_tag, level, circuit->interface->name,
circuit_t2string (circuit->is_type), circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
stream_get_endp (circuit->rcv_stream));
}
/* Sanity check - FIXME: move to correct place */
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN)
{
zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN);
return ISIS_WARNING;
}
return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa);
}
static int
process_psnp (int level, struct isis_circuit *circuit, const u_char *ssnpa)
{
if (isis->debugs & DEBUG_SNP_PACKETS)
{
zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u",
circuit->area->area_tag, level, circuit->interface->name,
circuit_t2string (circuit->is_type), circuit->circuit_id);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->rcv_stream),
stream_get_endp (circuit->rcv_stream));
}
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN)
{
zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN);
return ISIS_WARNING;
}
return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa);
}
/*
* PDU Dispatcher
*/
static int
isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
{
struct isis_fixed_hdr *hdr;
int retval = ISIS_OK;
/*
* Let's first read data from stream to the header
*/
hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream);
if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS))
{
zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp);
return ISIS_ERROR;
}
/* now we need to know if this is an ISO 9542 packet and
* take real good care of it, waaa!
*/
if (hdr->idrp == ISO9542_ESIS)
{
zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp);
return ISIS_ERROR;
}
stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN);
/*
* and then process it
*/
if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN)
{
zlog_err ("Fixed header length = %d", hdr->length);
return ISIS_ERROR;
}
if (hdr->version1 != 1)
{
zlog_warn ("Unsupported ISIS version %u", hdr->version1);
return ISIS_WARNING;
}
/* either 6 or 0 */
if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN))
{
zlog_err
("IDFieldLengthMismatch: ID Length field in a received PDU %u, "
"while the parameter for this IS is %u", hdr->id_len,
ISIS_SYS_ID_LEN);
return ISIS_ERROR;
}
if (hdr->version2 != 1)
{
zlog_warn ("Unsupported ISIS version %u", hdr->version2);
return ISIS_WARNING;
}
if (circuit->is_passive)
{
zlog_warn ("Received ISIS PDU on passive circuit %s",
circuit->interface->name);
return ISIS_WARNING;
}
/* either 3 or 0 */
if ((hdr->max_area_addrs != 0)
&& (hdr->max_area_addrs != isis->max_area_addrs))
{
zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a "
"received PDU %u while the parameter for this IS is %u",
hdr->max_area_addrs, isis->max_area_addrs);
return ISIS_ERROR;
}
switch (hdr->pdu_type)
{
case L1_LAN_HELLO:
retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa);
break;
case L2_LAN_HELLO:
retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa);
break;
case P2P_HELLO:
retval = process_p2p_hello (circuit);
break;
case L1_LINK_STATE:
retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa);
break;
case L2_LINK_STATE:
retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa);
break;
case L1_COMPLETE_SEQ_NUM:
retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa);
break;
case L2_COMPLETE_SEQ_NUM:
retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa);
break;
case L1_PARTIAL_SEQ_NUM:
retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa);
break;
case L2_PARTIAL_SEQ_NUM:
retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa);
break;
default:
return ISIS_ERROR;
}
return retval;
}
int
isis_receive (struct thread *thread)
{
struct isis_circuit *circuit;
u_char ssnpa[ETH_ALEN];
int retval;
/*
* Get the circuit
*/
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->t_read = NULL;
isis_circuit_stream(circuit, &circuit->rcv_stream);
retval = circuit->rx (circuit, ssnpa);
if (retval == ISIS_OK)
retval = isis_handle_pdu (circuit, ssnpa);
/*
* prepare for next packet.
*/
if (!circuit->is_passive)
isis_circuit_prepare (circuit);
return retval;
}
/* filling of the fixed isis header */
void
fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
{
memset (hdr, 0, sizeof (struct isis_fixed_hdr));
hdr->idrp = ISO10589_ISIS;
switch (pdu_type)
{
case L1_LAN_HELLO:
case L2_LAN_HELLO:
hdr->length = ISIS_LANHELLO_HDRLEN;
break;
case P2P_HELLO:
hdr->length = ISIS_P2PHELLO_HDRLEN;
break;
case L1_LINK_STATE:
case L2_LINK_STATE:
hdr->length = ISIS_LSP_HDR_LEN;
break;
case L1_COMPLETE_SEQ_NUM:
case L2_COMPLETE_SEQ_NUM:
hdr->length = ISIS_CSNP_HDRLEN;
break;
case L1_PARTIAL_SEQ_NUM:
case L2_PARTIAL_SEQ_NUM:
hdr->length = ISIS_PSNP_HDRLEN;
break;
default:
zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type);
return;
}
hdr->length += ISIS_FIXED_HDR_LEN;
hdr->pdu_type = pdu_type;
hdr->version1 = 1;
hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */
hdr->version2 = 1;
hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */
}
/*
* SEND SIDE
*/
static void
fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type,
struct stream *stream)
{
fill_fixed_hdr (hdr, pdu_type);
stream_putc (stream, hdr->idrp);
stream_putc (stream, hdr->length);
stream_putc (stream, hdr->version1);
stream_putc (stream, hdr->id_len);
stream_putc (stream, hdr->pdu_type);
stream_putc (stream, hdr->version2);
stream_putc (stream, hdr->reserved);
stream_putc (stream, hdr->max_area_addrs);
return;
}
int
send_hello (struct isis_circuit *circuit, int level)
{
struct isis_fixed_hdr fixed_hdr;
struct isis_lan_hello_hdr hello_hdr;
struct isis_p2p_hello_hdr p2p_hello_hdr;
unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
size_t len_pointer, length, auth_tlv_offset = 0;
u_int32_t interval;
int retval;
if (circuit->is_passive)
return ISIS_OK;
if (circuit->interface->mtu == 0)
{
zlog_warn ("circuit has zero MTU");
return ISIS_WARNING;
}
isis_circuit_stream(circuit, &circuit->snd_stream);
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
if (level == IS_LEVEL_1)
fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO,
circuit->snd_stream);
else
fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO,
circuit->snd_stream);
else
fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream);
/*
* Fill LAN Level 1 or 2 Hello PDU header
*/
memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
interval = circuit->hello_multiplier[level - 1] *
circuit->hello_interval[level - 1];
if (interval > USHRT_MAX)
interval = USHRT_MAX;
hello_hdr.circuit_t = circuit->is_type;
memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN);
hello_hdr.hold_time = htons ((u_int16_t) interval);
hello_hdr.pdu_len = 0; /* Update the PDU Length later */
len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN;
/* copy the shared part of the hello to the p2p hello if needed */
if (circuit->circ_type == CIRCUIT_T_P2P)
{
memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN);
p2p_hello_hdr.local_id = circuit->circuit_id;
/* FIXME: need better understanding */
stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN);
}
else
{
hello_hdr.prio = circuit->priority[level - 1];
if (level == IS_LEVEL_1)
{
memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is,
ISIS_SYS_ID_LEN + 1);
}
else if (level == IS_LEVEL_2)
{
memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is,
ISIS_SYS_ID_LEN + 1);
}
stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN);
}
/*
* Then the variable length part.
*/
/* add circuit password */
switch (circuit->passwd.type)
{
/* Cleartext */
case ISIS_PASSWD_TYPE_CLEARTXT:
if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
circuit->passwd.passwd, circuit->snd_stream))
return ISIS_WARNING;
break;
/* HMAC MD5 */
case ISIS_PASSWD_TYPE_HMAC_MD5:
/* Remember where TLV is written so we can later overwrite the MD5 hash */
auth_tlv_offset = stream_get_endp (circuit->snd_stream);
memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE,
hmac_md5_hash, circuit->snd_stream))
return ISIS_WARNING;
break;
default:
break;
}
/* Area Addresses TLV */
if (listcount (circuit->area->area_addrs) == 0)
return ISIS_WARNING;
if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
return ISIS_WARNING;
/* LAN Neighbors TLV */
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
{
if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] &&
listcount (circuit->u.bc.lan_neighs[0]) > 0)
if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
circuit->snd_stream))
return ISIS_WARNING;
if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] &&
listcount (circuit->u.bc.lan_neighs[1]) > 0)
if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
circuit->snd_stream))
return ISIS_WARNING;
}
/* Protocols Supported TLV */
if (circuit->nlpids.count > 0)
if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
return ISIS_WARNING;
/* IP interface Address TLV */
if (circuit->ip_router && circuit->ip_addrs &&
listcount (circuit->ip_addrs) > 0)
if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
return ISIS_WARNING;
/*
* MT Supported TLV
*
* TLV gets included if no topology is enabled on the interface,
* if one topology other than #0 is enabled, or if multiple topologies
* are enabled.
*/
struct isis_circuit_mt_setting **mt_settings;
unsigned int mt_count;
mt_settings = circuit_mt_settings(circuit, &mt_count);
if ((mt_count == 0 && area_is_mt(circuit->area))
|| (mt_count == 1 && mt_settings[0]->mtid != ISIS_MT_IPV4_UNICAST)
|| (mt_count > 1))
{
struct list *mt_info = list_new();
mt_info->del = free_tlv;
for (unsigned int i = 0; i < mt_count; i++)
{
struct mt_router_info *info;
info = XCALLOC(MTYPE_ISIS_TLV, sizeof(*info));
info->mtid = mt_settings[i]->mtid;
/* overload info is not valid in IIH, so it's not included here */
listnode_add(mt_info, info);
}
tlv_add_mt_router_info (mt_info, circuit->snd_stream);
list_free(mt_info);
}
/* IPv6 Interface Address TLV */
if (circuit->ipv6_router && circuit->ipv6_link &&
listcount (circuit->ipv6_link) > 0)
if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream))
return ISIS_WARNING;
if (circuit->pad_hellos)
if (tlv_add_padding (circuit->snd_stream))
return ISIS_WARNING;
length = stream_get_endp (circuit->snd_stream);
/* Update PDU length */
stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
/* For HMAC MD5 we need to compute the md5 hash and store it */
if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
{
hmac_md5 (STREAM_DATA (circuit->snd_stream),
stream_get_endp (circuit->snd_stream),
(unsigned char *) &circuit->passwd.passwd, circuit->passwd.len,
(unsigned char *) &hmac_md5_hash);
/* Copy the hash into the stream */
memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
}
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
{
zlog_debug ("ISIS-Adj (%s): Sending L%d LAN IIH on %s, length %zd",
circuit->area->area_tag, level, circuit->interface->name,
length);
}
else
{
zlog_debug ("ISIS-Adj (%s): Sending P2P IIH on %s, length %zd",
circuit->area->area_tag, circuit->interface->name,
length);
}
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->snd_stream),
stream_get_endp (circuit->snd_stream));
}
retval = circuit->tx (circuit, level);
if (retval != ISIS_OK)
zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed",
circuit->area->area_tag, level, circuit->interface->name);
return retval;
}
int
send_lan_l1_hello (struct thread *thread)
{
struct isis_circuit *circuit;
int retval;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->u.bc.t_send_lan_hello[0] = NULL;
if (!(circuit->area->is_type & IS_LEVEL_1))
{
zlog_warn ("ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
circuit->area->area_tag);
return 1;
}
if (circuit->u.bc.run_dr_elect[0])
isis_dr_elect (circuit, 1);
retval = send_hello (circuit, 1);
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
send_lan_l1_hello, circuit,
isis_jitter (circuit->hello_interval[0], IIH_JITTER));
return retval;
}
int
send_lan_l2_hello (struct thread *thread)
{
struct isis_circuit *circuit;
int retval;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->u.bc.t_send_lan_hello[1] = NULL;
if (!(circuit->area->is_type & IS_LEVEL_2))
{
zlog_warn ("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
circuit->area->area_tag);
return 1;
}
if (circuit->u.bc.run_dr_elect[1])
isis_dr_elect (circuit, 2);
retval = send_hello (circuit, 2);
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
send_lan_l2_hello, circuit,
isis_jitter (circuit->hello_interval[1], IIH_JITTER));
return retval;
}
int
send_p2p_hello (struct thread *thread)
{
struct isis_circuit *circuit;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->u.p2p.t_send_p2p_hello = NULL;
send_hello (circuit, 1);
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello,
circuit, isis_jitter (circuit->hello_interval[1],
IIH_JITTER));
return ISIS_OK;
}
static int
build_csnp (int level, u_char * start, u_char * stop, struct list *lsps,
struct isis_circuit *circuit)
{
struct isis_fixed_hdr fixed_hdr;
struct isis_passwd *passwd;
unsigned long lenp;
u_int16_t length;
unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
unsigned long auth_tlv_offset = 0;
int retval = ISIS_OK;
isis_circuit_stream(circuit, &circuit->snd_stream);
if (level == IS_LEVEL_1)
fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM,
circuit->snd_stream);
else
fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM,
circuit->snd_stream);
/*
* Fill Level 1 or 2 Complete Sequence Numbers header
*/
lenp = stream_get_endp (circuit->snd_stream);
stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
/* no need to send the source here, it is always us if we csnp */
stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
/* with zero circuit id - ref 9.10, 9.11 */
stream_putc (circuit->snd_stream, 0x00);
stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2);
stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2);
/*
* And TLVs
*/
if (level == IS_LEVEL_1)
passwd = &circuit->area->area_passwd;
else
passwd = &circuit->area->domain_passwd;
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
{
switch (passwd->type)
{
/* Cleartext */
case ISIS_PASSWD_TYPE_CLEARTXT:
if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
passwd->passwd, circuit->snd_stream))
return ISIS_WARNING;
break;
/* HMAC MD5 */
case ISIS_PASSWD_TYPE_HMAC_MD5:
/* Remember where TLV is written so we can later overwrite the MD5 hash */
auth_tlv_offset = stream_get_endp (circuit->snd_stream);
memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
hmac_md5_hash, circuit->snd_stream))
return ISIS_WARNING;
break;
default:
break;
}
}
retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
if (retval != ISIS_OK)
return retval;
length = (u_int16_t) stream_get_endp (circuit->snd_stream);
/* Update PU length */
stream_putw_at (circuit->snd_stream, lenp, length);
/* For HMAC MD5 we need to compute the md5 hash and store it */
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
{
hmac_md5 (STREAM_DATA (circuit->snd_stream),
stream_get_endp(circuit->snd_stream),
(unsigned char *) &passwd->passwd, passwd->len,
(unsigned char *) &hmac_md5_hash);
/* Copy the hash into the stream */
memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
}
return retval;
}
/*
* Count the maximum number of lsps that can be accomodated by a given size.
*/
static uint16_t
get_max_lsp_count (uint16_t size)
{
uint16_t tlv_count;
uint16_t lsp_count;
uint16_t remaining_size;
/* First count the full size TLVs */
tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE;
lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN);
/* The last TLV, if any */
remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE;
if (remaining_size - 2 >= LSP_ENTRIES_LEN)
lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN;
return lsp_count;
}
/*
* Calculate the length of Authentication Info. TLV.
*/
static uint16_t
auth_tlv_length (int level, struct isis_circuit *circuit)
{
struct isis_passwd *passwd;
uint16_t length;
if (level == IS_LEVEL_1)
passwd = &circuit->area->area_passwd;
else
passwd = &circuit->area->domain_passwd;
/* Also include the length of TLV header */
length = AUTH_INFO_HDRLEN;
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
{
switch (passwd->type)
{
/* Cleartext */
case ISIS_PASSWD_TYPE_CLEARTXT:
length += passwd->len;
break;
/* HMAC MD5 */
case ISIS_PASSWD_TYPE_HMAC_MD5:
length += ISIS_AUTH_MD5_SIZE;
break;
default:
break;
}
}
return length;
}
/*
* Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP.
*/
static uint16_t
max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit)
{
int snp_hdr_len;
int auth_tlv_len;
uint16_t lsp_count;
snp_hdr_len = ISIS_FIXED_HDR_LEN;
if (snp_type == ISIS_SNP_CSNP_FLAG)
snp_hdr_len += ISIS_CSNP_HDRLEN;
else
snp_hdr_len += ISIS_PSNP_HDRLEN;
auth_tlv_len = auth_tlv_length (level, circuit);
lsp_count = get_max_lsp_count (
stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len);
return lsp_count;
}
/*
* FIXME: support multiple CSNPs
*/
int
send_csnp (struct isis_circuit *circuit, int level)
{
u_char start[ISIS_SYS_ID_LEN + 2];
u_char stop[ISIS_SYS_ID_LEN + 2];
struct list *list = NULL;
struct listnode *node;
struct isis_lsp *lsp;
u_char num_lsps, loop = 1;
int i, retval = ISIS_OK;
if (circuit->area->lspdb[level - 1] == NULL ||
dict_count (circuit->area->lspdb[level - 1]) == 0)
return retval;
memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit);
while (loop)
{
list = list_new ();
lsp_build_list (start, stop, num_lsps, list,
circuit->area->lspdb[level - 1]);
/*
* Update the stop lsp_id before encoding this CSNP.
*/
if (listcount (list) < num_lsps)
{
memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
}
else
{
node = listtail (list);
lsp = listgetdata (node);
memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2);
}
retval = build_csnp (level, start, stop, list, circuit);
if (retval != ISIS_OK)
{
zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed",
circuit->area->area_tag, level, circuit->interface->name);
list_delete (list);
return retval;
}
if (isis->debugs & DEBUG_SNP_PACKETS)
{
zlog_debug ("ISIS-Snp (%s): Sending L%d CSNP on %s, length %zd",
circuit->area->area_tag, level, circuit->interface->name,
stream_get_endp (circuit->snd_stream));
for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
{
zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x,"
" cksum 0x%04x, lifetime %us",
circuit->area->area_tag,
rawlspid_print (lsp->lsp_header->lsp_id),
ntohl (lsp->lsp_header->seq_num),
ntohs (lsp->lsp_header->checksum),
ntohs (lsp->lsp_header->rem_lifetime));
}
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->snd_stream),
stream_get_endp (circuit->snd_stream));
}
retval = circuit->tx (circuit, level);
if (retval != ISIS_OK)
{
zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
list_delete (list);
return retval;
}
/*
* Start lsp_id of the next CSNP should be one plus the
* stop lsp_id in this current CSNP.
*/
memcpy (start, stop, ISIS_SYS_ID_LEN + 2);
loop = 0;
for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i)
{
if (start[i] < (u_char)0xff)
{
start[i] += 1;
loop = 1;
break;
}
}
memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
list_delete (list);
}
return retval;
}
int
send_l1_csnp (struct thread *thread)
{
struct isis_circuit *circuit;
int retval = ISIS_OK;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->t_send_csnp[0] = NULL;
if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
{
send_csnp (circuit, 1);
}
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
return retval;
}
int
send_l2_csnp (struct thread *thread)
{
struct isis_circuit *circuit;
int retval = ISIS_OK;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->t_send_csnp[1] = NULL;
if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
{
send_csnp (circuit, 2);
}
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
return retval;
}
static int
build_psnp (int level, struct isis_circuit *circuit, struct list *lsps)
{
struct isis_fixed_hdr fixed_hdr;
unsigned long lenp;
u_int16_t length;
struct isis_lsp *lsp;
struct isis_passwd *passwd;
struct listnode *node;
unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
unsigned long auth_tlv_offset = 0;
int retval = ISIS_OK;
isis_circuit_stream(circuit, &circuit->snd_stream);
if (level == IS_LEVEL_1)
fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
circuit->snd_stream);
else
fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
circuit->snd_stream);
/*
* Fill Level 1 or 2 Partial Sequence Numbers header
*/
lenp = stream_get_endp (circuit->snd_stream);
stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */
stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
stream_putc (circuit->snd_stream, circuit->idx);
/*
* And TLVs
*/
if (level == IS_LEVEL_1)
passwd = &circuit->area->area_passwd;
else
passwd = &circuit->area->domain_passwd;
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
{
switch (passwd->type)
{
/* Cleartext */
case ISIS_PASSWD_TYPE_CLEARTXT:
if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len,
passwd->passwd, circuit->snd_stream))
return ISIS_WARNING;
break;
/* HMAC MD5 */
case ISIS_PASSWD_TYPE_HMAC_MD5:
/* Remember where TLV is written so we can later overwrite the MD5 hash */
auth_tlv_offset = stream_get_endp (circuit->snd_stream);
memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
hmac_md5_hash, circuit->snd_stream))
return ISIS_WARNING;
break;
default:
break;
}
}
retval = tlv_add_lsp_entries (lsps, circuit->snd_stream);
if (retval != ISIS_OK)
return retval;
if (isis->debugs & DEBUG_SNP_PACKETS)
{
for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp))
{
zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x,"
" cksum 0x%04x, lifetime %us",
circuit->area->area_tag,
rawlspid_print (lsp->lsp_header->lsp_id),
ntohl (lsp->lsp_header->seq_num),
ntohs (lsp->lsp_header->checksum),
ntohs (lsp->lsp_header->rem_lifetime));
}
}
length = (u_int16_t) stream_get_endp (circuit->snd_stream);
/* Update PDU length */
stream_putw_at (circuit->snd_stream, lenp, length);
/* For HMAC MD5 we need to compute the md5 hash and store it */
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) &&
passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5)
{
hmac_md5 (STREAM_DATA (circuit->snd_stream),
stream_get_endp(circuit->snd_stream),
(unsigned char *) &passwd->passwd, passwd->len,
(unsigned char *) &hmac_md5_hash);
/* Copy the hash into the stream */
memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3,
hmac_md5_hash, ISIS_AUTH_MD5_SIZE);
}
return ISIS_OK;
}
/*
* 7.3.15.4 action on expiration of partial SNP interval
* level 1
*/
static int
send_psnp (int level, struct isis_circuit *circuit)
{
struct isis_lsp *lsp;
struct list *list = NULL;
struct listnode *node;
u_char num_lsps;
int retval = ISIS_OK;
if (circuit->circ_type == CIRCUIT_T_BROADCAST &&
circuit->u.bc.is_dr[level - 1])
return ISIS_OK;
if (circuit->area->lspdb[level - 1] == NULL ||
dict_count (circuit->area->lspdb[level - 1]) == 0)
return ISIS_OK;
if (! circuit->snd_stream)
return ISIS_ERROR;
num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit);
while (1)
{
list = list_new ();
lsp_build_list_ssn (circuit, num_lsps, list,
circuit->area->lspdb[level - 1]);
if (listcount (list) == 0)
{
list_delete (list);
return ISIS_OK;
}
retval = build_psnp (level, circuit, list);
if (retval != ISIS_OK)
{
zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed",
circuit->area->area_tag, level, circuit->interface->name);
list_delete (list);
return retval;
}
if (isis->debugs & DEBUG_SNP_PACKETS)
{
zlog_debug ("ISIS-Snp (%s): Sending L%d PSNP on %s, length %zd",
circuit->area->area_tag, level,
circuit->interface->name,
stream_get_endp (circuit->snd_stream));
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->snd_stream),
stream_get_endp (circuit->snd_stream));
}
retval = circuit->tx (circuit, level);
if (retval != ISIS_OK)
{
zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
list_delete (list);
return retval;
}
/*
* sending succeeded, we can clear SSN flags of this circuit
* for the LSPs in list
*/
for (ALL_LIST_ELEMENTS_RO (list, node, lsp))
ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
list_delete (list);
}
return retval;
}
int
send_l1_psnp (struct thread *thread)
{
struct isis_circuit *circuit;
int retval = ISIS_OK;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->t_send_psnp[0] = NULL;
send_psnp (1, circuit);
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
return retval;
}
/*
* 7.3.15.4 action on expiration of partial SNP interval
* level 2
*/
int
send_l2_psnp (struct thread *thread)
{
struct isis_circuit *circuit;
int retval = ISIS_OK;
circuit = THREAD_ARG (thread);
assert (circuit);
circuit->t_send_psnp[1] = NULL;
send_psnp (2, circuit);
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
return retval;
}
/*
* ISO 10589 - 7.3.14.3
*/
int
send_lsp (struct thread *thread)
{
struct isis_circuit *circuit;
struct isis_lsp *lsp;
struct listnode *node;
int clear_srm = 1;
int retval = ISIS_OK;
circuit = THREAD_ARG (thread);
assert (circuit);
if (!circuit->lsp_queue)
return ISIS_OK;
node = listhead (circuit->lsp_queue);
/*
* Handle case where there are no LSPs on the queue. This can
* happen, for instance, if an adjacency goes down before this
* thread gets a chance to run.
*/
if (!node)
return ISIS_OK;
/*
* Delete LSP from lsp_queue. If it's still in queue, it is assumed
* as 'transmit pending', but send_lsp may never be called again.
* Retry will happen because SRM flag will not be cleared.
*/
lsp = listgetdata(node);
list_delete_node (circuit->lsp_queue, node);
/* Set the last-cleared time if the queue is empty. */
/* TODO: Is is possible that new lsps keep being added to the queue
* that the queue is never empty? */
if (list_isempty (circuit->lsp_queue))
circuit->lsp_queue_last_cleared = time (NULL);
if (circuit->state != C_STATE_UP || circuit->is_passive == 1)
goto out;
/*
* Do not send if levels do not match
*/
if (!(lsp->level & circuit->is_type))
goto out;
/*
* Do not send if we do not have adjacencies in state up on the circuit
*/
if (circuit->upadjcount[lsp->level - 1] == 0)
goto out;
/* stream_copy will assert and stop program execution if LSP is larger than
* the circuit's MTU. So handle and log this case here. */
if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream))
{
zlog_err("ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x,"
" cksum 0x%04x, lifetime %us on %s. LSP Size is %zu"
" while interface stream size is %zu.",
circuit->area->area_tag, lsp->level,
rawlspid_print(lsp->lsp_header->lsp_id),
ntohl(lsp->lsp_header->seq_num),
ntohs(lsp->lsp_header->checksum),
ntohs(lsp->lsp_header->rem_lifetime),
circuit->interface->name,
stream_get_endp(lsp->pdu),
stream_get_size(circuit->snd_stream));
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data(STREAM_DATA(lsp->pdu), stream_get_endp(lsp->pdu));
retval = ISIS_ERROR;
goto out;
}
/* copy our lsp to the send buffer */
stream_copy (circuit->snd_stream, lsp->pdu);
if (isis->debugs & DEBUG_UPDATE_PACKETS)
{
zlog_debug
("ISIS-Upd (%s): Sending L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
" lifetime %us on %s", circuit->area->area_tag, lsp->level,
rawlspid_print (lsp->lsp_header->lsp_id),
ntohl (lsp->lsp_header->seq_num),
ntohs (lsp->lsp_header->checksum),
ntohs (lsp->lsp_header->rem_lifetime),
circuit->interface->name);
if (isis->debugs & DEBUG_PACKET_DUMP)
zlog_dump_data (STREAM_DATA (circuit->snd_stream),
stream_get_endp (circuit->snd_stream));
}
clear_srm = 0;
retval = circuit->tx (circuit, lsp->level);
if (retval != ISIS_OK)
{
zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
circuit->area->area_tag, lsp->level,
circuit->interface->name,
(retval == ISIS_WARNING) ? "temporarily" : "permanently");
}
out:
if (clear_srm
|| (retval == ISIS_OK && circuit->circ_type == CIRCUIT_T_BROADCAST)
|| (retval != ISIS_OK && retval != ISIS_WARNING))
{
/* SRM flag will trigger retransmission. We will not retransmit if we
* encountered a fatal error.
* On success, they should only be cleared if it's a broadcast circuit.
* On a P2P circuit, we will wait for the ack from the neighbor to clear
* the fag.
*/
ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
}
return retval;
}
int
ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit,
int level)
{
unsigned long lenp;
int retval;
u_int16_t length;
struct isis_fixed_hdr fixed_hdr;
isis_circuit_stream(circuit, &circuit->snd_stream);
// fill_llc_hdr (stream);
if (level == IS_LEVEL_1)
fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM,
circuit->snd_stream);
else
fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM,
circuit->snd_stream);
lenp = stream_get_endp (circuit->snd_stream);
stream_putw (circuit->snd_stream, 0); /* PDU length */
stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN);
stream_putc (circuit->snd_stream, circuit->idx);
stream_putc (circuit->snd_stream, 9); /* code */
stream_putc (circuit->snd_stream, 16); /* len */
stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime));
stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2);
stream_putl (circuit->snd_stream, ntohl (hdr->seq_num));
stream_putw (circuit->snd_stream, ntohs (hdr->checksum));
length = (u_int16_t) stream_get_endp (circuit->snd_stream);
/* Update PDU length */
stream_putw_at (circuit->snd_stream, lenp, length);
retval = circuit->tx (circuit, level);
if (retval != ISIS_OK)
zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
return retval;
}
|