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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2003 Yasuhiro Ohara
*/
#include <zebra.h>
#include "memory.h"
#include "log.h"
#include "vty.h"
#include "command.h"
#include "event.h"
#include "linklist.h"
#include "lib_errors.h"
#include "checksum.h"
#include "network.h"
#include "ospf6_proto.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"
#include "ospf6_top.h"
#include "ospf6_network.h"
#include "ospf6_message.h"
#include "ospf6_area.h"
#include "ospf6_neighbor.h"
#include "ospf6_interface.h"
/* for structures and macros ospf6_lsa_examin() needs */
#include "ospf6_abr.h"
#include "ospf6_asbr.h"
#include "ospf6_intra.h"
#include "ospf6_flood.h"
#include "ospf6d.h"
#include "ospf6_gr.h"
#include <netinet/ip6.h>
#include "lib/libospf.h"
#include "lib/keychain.h"
#include "ospf6_auth_trailer.h"
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_MESSAGE, "OSPF6 message");
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_PACKET, "OSPF6 packet");
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_FIFO, "OSPF6 FIFO queue");
unsigned char conf_debug_ospf6_message[6] = {0x03, 0, 0, 0, 0, 0};
const char *ospf6_message_type(int type)
{
switch (type) {
case OSPF6_MESSAGE_TYPE_HELLO:
return "Hello";
case OSPF6_MESSAGE_TYPE_DBDESC:
return "DbDesc";
case OSPF6_MESSAGE_TYPE_LSREQ:
return "LSReq";
case OSPF6_MESSAGE_TYPE_LSUPDATE:
return "LSUpdate";
case OSPF6_MESSAGE_TYPE_LSACK:
return "LSAck";
case OSPF6_MESSAGE_TYPE_UNKNOWN:
default:
return "unknown";
}
}
/* Minimum (besides the standard OSPF packet header) lengths for OSPF
packets of particular types, offset is the "type" field. */
const uint16_t ospf6_packet_minlen[OSPF6_MESSAGE_TYPE_ALL] = {
0,
OSPF6_HELLO_MIN_SIZE,
OSPF6_DB_DESC_MIN_SIZE,
OSPF6_LS_REQ_MIN_SIZE,
OSPF6_LS_UPD_MIN_SIZE,
OSPF6_LS_ACK_MIN_SIZE};
/* Minimum (besides the standard LSA header) lengths for LSAs of particular
types, offset is the "LSA function code" portion of "LSA type" field. */
const uint16_t ospf6_lsa_minlen[OSPF6_LSTYPE_SIZE] = {
0,
/* 0x2001 */ OSPF6_ROUTER_LSA_MIN_SIZE,
/* 0x2002 */ OSPF6_NETWORK_LSA_MIN_SIZE,
/* 0x2003 */ OSPF6_INTER_PREFIX_LSA_MIN_SIZE,
/* 0x2004 */ OSPF6_INTER_ROUTER_LSA_FIX_SIZE,
/* 0x4005 */ OSPF6_AS_EXTERNAL_LSA_MIN_SIZE,
/* 0x2006 */ 0,
/* 0x2007 */ OSPF6_AS_EXTERNAL_LSA_MIN_SIZE,
/* 0x0008 */ OSPF6_LINK_LSA_MIN_SIZE,
/* 0x2009 */ OSPF6_INTRA_PREFIX_LSA_MIN_SIZE,
/* 0x200a */ 0,
/* 0x000b */ OSPF6_GRACE_LSA_MIN_SIZE};
/* print functions */
static void ospf6_header_print(struct ospf6_header *oh)
{
zlog_debug(" OSPFv%d Type:%d Len:%hu Router-ID:%pI4", oh->version,
oh->type, ntohs(oh->length), &oh->router_id);
zlog_debug(" Area-ID:%pI4 Cksum:%hx Instance-ID:%d", &oh->area_id,
ntohs(oh->checksum), oh->instance_id);
}
void ospf6_hello_print(struct ospf6_header *oh, int action)
{
struct ospf6_hello *hello;
char options[32];
char *p;
ospf6_header_print(oh);
assert(oh->type == OSPF6_MESSAGE_TYPE_HELLO);
hello = (struct ospf6_hello *)((caddr_t)oh
+ sizeof(struct ospf6_header));
ospf6_options_printbuf(hello->options, options, sizeof(options));
zlog_debug(" I/F-Id:%ld Priority:%d Option:%s",
(unsigned long)ntohl(hello->interface_id), hello->priority,
options);
zlog_debug(" HelloInterval:%hu DeadInterval:%hu",
ntohs(hello->hello_interval), ntohs(hello->dead_interval));
zlog_debug(" DR:%pI4 BDR:%pI4", &hello->drouter, &hello->bdrouter);
if ((IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)
&& action == OSPF6_ACTION_RECV)
|| (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND)
&& action == OSPF6_ACTION_SEND)) {
for (p = (char *)((caddr_t)hello + sizeof(struct ospf6_hello));
p + sizeof(uint32_t) <= OSPF6_MESSAGE_END(oh);
p += sizeof(uint32_t))
zlog_debug(" Neighbor: %pI4", (in_addr_t *)p);
assert(p == OSPF6_MESSAGE_END(oh));
}
}
void ospf6_dbdesc_print(struct ospf6_header *oh, int action)
{
struct ospf6_dbdesc *dbdesc;
char options[32];
char *p;
ospf6_header_print(oh);
assert(oh->type == OSPF6_MESSAGE_TYPE_DBDESC);
dbdesc = (struct ospf6_dbdesc *)((caddr_t)oh
+ sizeof(struct ospf6_header));
ospf6_options_printbuf(dbdesc->options, options, sizeof(options));
zlog_debug(" MBZ: %#x Option: %s IfMTU: %hu", dbdesc->reserved1,
options, ntohs(dbdesc->ifmtu));
zlog_debug(" MBZ: %#x Bits: %s%s%s SeqNum: %#lx", dbdesc->reserved2,
(CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT) ? "I" : "-"),
(CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MBIT) ? "M" : "-"),
(CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MSBIT) ? "m" : "s"),
(unsigned long)ntohl(dbdesc->seqnum));
if ((IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)
&& action == OSPF6_ACTION_RECV)
|| (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND)
&& action == OSPF6_ACTION_SEND)) {
for (p = (char *)((caddr_t)dbdesc
+ sizeof(struct ospf6_dbdesc));
p + sizeof(struct ospf6_lsa_header)
<= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsa_header))
ospf6_lsa_header_print_raw(
(struct ospf6_lsa_header *)p);
assert(p == OSPF6_MESSAGE_END(oh));
}
}
void ospf6_lsreq_print(struct ospf6_header *oh, int action)
{
char *p;
ospf6_header_print(oh);
assert(oh->type == OSPF6_MESSAGE_TYPE_LSREQ);
if ((IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)
&& action == OSPF6_ACTION_RECV)
|| (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND)
&& action == OSPF6_ACTION_SEND)) {
for (p = (char *)((caddr_t)oh + sizeof(struct ospf6_header));
p + sizeof(struct ospf6_lsreq_entry)
<= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsreq_entry)) {
struct ospf6_lsreq_entry *e =
(struct ospf6_lsreq_entry *)p;
zlog_debug(" [%s Id:%pI4 Adv:%pI4]",
ospf6_lstype_name(e->type), &e->id,
&e->adv_router);
}
assert(p == OSPF6_MESSAGE_END(oh));
}
}
void ospf6_lsupdate_print(struct ospf6_header *oh, int action)
{
struct ospf6_lsupdate *lsupdate;
unsigned long num;
char *p;
ospf6_header_print(oh);
assert(oh->type == OSPF6_MESSAGE_TYPE_LSUPDATE);
lsupdate = (struct ospf6_lsupdate *)((caddr_t)oh
+ sizeof(struct ospf6_header));
num = ntohl(lsupdate->lsa_number);
zlog_debug(" Number of LSA: %ld", num);
if ((IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)
&& action == OSPF6_ACTION_RECV)
|| (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND)
&& action == OSPF6_ACTION_SEND)) {
for (p = (char *)((caddr_t)lsupdate
+ sizeof(struct ospf6_lsupdate));
p < OSPF6_MESSAGE_END(oh)
&& p + OSPF6_LSA_SIZE(p) <= OSPF6_MESSAGE_END(oh);
p += OSPF6_LSA_SIZE(p)) {
ospf6_lsa_header_print_raw(
(struct ospf6_lsa_header *)p);
}
assert(p == OSPF6_MESSAGE_END(oh));
}
}
void ospf6_lsack_print(struct ospf6_header *oh, int action)
{
char *p;
ospf6_header_print(oh);
assert(oh->type == OSPF6_MESSAGE_TYPE_LSACK);
if ((IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)
&& action == OSPF6_ACTION_RECV)
|| (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND)
&& action == OSPF6_ACTION_SEND)) {
for (p = (char *)((caddr_t)oh + sizeof(struct ospf6_header));
p + sizeof(struct ospf6_lsa_header)
<= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsa_header))
ospf6_lsa_header_print_raw(
(struct ospf6_lsa_header *)p);
assert(p == OSPF6_MESSAGE_END(oh));
}
}
static struct ospf6_packet *ospf6_packet_new(size_t size)
{
struct ospf6_packet *new;
new = XCALLOC(MTYPE_OSPF6_PACKET, sizeof(struct ospf6_packet));
new->s = stream_new(size);
return new;
}
static void ospf6_packet_free(struct ospf6_packet *op)
{
if (op->s)
stream_free(op->s);
XFREE(MTYPE_OSPF6_PACKET, op);
}
struct ospf6_fifo *ospf6_fifo_new(void)
{
struct ospf6_fifo *new;
new = XCALLOC(MTYPE_OSPF6_FIFO, sizeof(struct ospf6_fifo));
return new;
}
/* Add new packet to fifo. */
static void ospf6_fifo_push(struct ospf6_fifo *fifo, struct ospf6_packet *op)
{
if (fifo->tail)
fifo->tail->next = op;
else
fifo->head = op;
fifo->tail = op;
fifo->count++;
}
/* Add new packet to head of fifo. */
static void ospf6_fifo_push_head(struct ospf6_fifo *fifo,
struct ospf6_packet *op)
{
op->next = fifo->head;
if (fifo->tail == NULL)
fifo->tail = op;
fifo->head = op;
fifo->count++;
}
/* Delete first packet from fifo. */
static struct ospf6_packet *ospf6_fifo_pop(struct ospf6_fifo *fifo)
{
struct ospf6_packet *op;
op = fifo->head;
if (op) {
fifo->head = op->next;
if (fifo->head == NULL)
fifo->tail = NULL;
fifo->count--;
}
return op;
}
/* Return first fifo entry. */
static struct ospf6_packet *ospf6_fifo_head(struct ospf6_fifo *fifo)
{
return fifo->head;
}
/* Flush ospf packet fifo. */
void ospf6_fifo_flush(struct ospf6_fifo *fifo)
{
struct ospf6_packet *op;
struct ospf6_packet *next;
for (op = fifo->head; op; op = next) {
next = op->next;
ospf6_packet_free(op);
}
fifo->head = fifo->tail = NULL;
fifo->count = 0;
}
/* Free ospf packet fifo. */
void ospf6_fifo_free(struct ospf6_fifo *fifo)
{
ospf6_fifo_flush(fifo);
XFREE(MTYPE_OSPF6_FIFO, fifo);
}
static void ospf6_packet_add(struct ospf6_interface *oi,
struct ospf6_packet *op)
{
/* Add packet to end of queue. */
ospf6_fifo_push(oi->obuf, op);
/* Debug of packet fifo*/
/* ospf_fifo_debug (oi->obuf); */
}
static void ospf6_packet_add_top(struct ospf6_interface *oi,
struct ospf6_packet *op)
{
/* Add packet to head of queue. */
ospf6_fifo_push_head(oi->obuf, op);
/* Debug of packet fifo*/
/* ospf_fifo_debug (oi->obuf); */
}
static void ospf6_packet_delete(struct ospf6_interface *oi)
{
struct ospf6_packet *op;
op = ospf6_fifo_pop(oi->obuf);
if (op)
ospf6_packet_free(op);
}
static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst,
struct ospf6_interface *oi,
struct ospf6_header *oh)
{
struct ospf6_hello *hello;
struct ospf6_neighbor *on;
char *p;
int twoway = 0;
int neighborchange = 0;
int neighbor_ifindex_change = 0;
int backupseen = 0;
int64_t latency = 0;
struct timeval timestamp;
monotime(×tamp);
hello = (struct ospf6_hello *)((caddr_t)oh
+ sizeof(struct ospf6_header));
/* HelloInterval check */
if (ntohs(hello->hello_interval) != oi->hello_interval) {
zlog_warn(
"VRF %s: I/F %s HelloInterval mismatch from %pI6 (%pI4): (my %d, rcvd %d)",
oi->interface->vrf->name, oi->interface->name, src,
&oh->router_id, oi->hello_interval,
ntohs(hello->hello_interval));
return;
}
/* RouterDeadInterval check */
if (ntohs(hello->dead_interval) != oi->dead_interval) {
zlog_warn(
"VRF %s: I/F %s DeadInterval mismatch from %pI6 (%pI4): (my %d, rcvd %d)",
oi->interface->vrf->name, oi->interface->name, src,
&oh->router_id, oi->dead_interval,
ntohs(hello->dead_interval));
return;
}
/* E-bit check */
if (OSPF6_OPT_ISSET(hello->options, OSPF6_OPT_E) !=
OSPF6_OPT_ISSET(oi->area->options, OSPF6_OPT_E)) {
zlog_warn("VRF %s: IF %s E-bit mismatch from %pI6 (%pI4)",
oi->interface->vrf->name, oi->interface->name, src,
&oh->router_id);
return;
}
/* N-bit check */
if (OSPF6_OPT_ISSET(hello->options, OSPF6_OPT_N)
!= OSPF6_OPT_ISSET(oi->area->options, OSPF6_OPT_N)) {
zlog_warn("VRF %s: IF %s N-bit mismatch",
oi->interface->vrf->name, oi->interface->name);
return;
}
if (((OSPF6_OPT_ISSET_EXT(hello->options, OSPF6_OPT_AT) ==
OSPF6_OPT_AT) &&
(oi->at_data.flags == 0)) ||
((OSPF6_OPT_ISSET_EXT(hello->options, OSPF6_OPT_AT) !=
OSPF6_OPT_AT) &&
(oi->at_data.flags != 0))) {
if (IS_OSPF6_DEBUG_AUTH_RX)
zlog_warn(
"VRF %s: IF %s AT-bit mismatch in hello packet",
oi->interface->vrf->name, oi->interface->name);
oi->at_data.rx_drop++;
return;
}
/* Find neighbor, create if not exist */
on = ospf6_neighbor_lookup(oh->router_id, oi);
if (on == NULL) {
on = ospf6_neighbor_create(oh->router_id, oi);
on->prev_drouter = on->drouter = hello->drouter;
on->prev_bdrouter = on->bdrouter = hello->bdrouter;
on->priority = hello->priority;
}
/* check latency against hello period */
if (on->hello_in)
latency = monotime_since(&on->last_hello, NULL)
- ((int64_t)oi->hello_interval * 1000000);
/* log if latency exceeds the hello period */
if (latency > ((int64_t)oi->hello_interval * 1000000))
zlog_warn("%s RX %pI4 high latency %" PRId64 "us.", __func__,
&on->router_id, latency);
on->last_hello = timestamp;
on->hello_in++;
/* Always override neighbor's source address */
memcpy(&on->linklocal_addr, src, sizeof(struct in6_addr));
/* Neighbor ifindex check */
if (on->ifindex != (ifindex_t)ntohl(hello->interface_id)) {
on->ifindex = ntohl(hello->interface_id);
neighbor_ifindex_change++;
}
/* TwoWay check */
for (p = (char *)((caddr_t)hello + sizeof(struct ospf6_hello));
p + sizeof(uint32_t) <= OSPF6_MESSAGE_END(oh);
p += sizeof(uint32_t)) {
uint32_t *router_id = (uint32_t *)p;
if (*router_id == oi->area->ospf6->router_id)
twoway++;
}
assert(p == OSPF6_MESSAGE_END(oh));
/* RouterPriority check */
if (on->priority != hello->priority) {
on->priority = hello->priority;
neighborchange++;
}
/* DR check */
if (on->drouter != hello->drouter) {
on->prev_drouter = on->drouter;
on->drouter = hello->drouter;
if (on->prev_drouter == on->router_id
|| on->drouter == on->router_id)
neighborchange++;
}
/* BDR check */
if (on->bdrouter != hello->bdrouter) {
on->prev_bdrouter = on->bdrouter;
on->bdrouter = hello->bdrouter;
if (on->prev_bdrouter == on->router_id
|| on->bdrouter == on->router_id)
neighborchange++;
}
/* BackupSeen check */
if (oi->state == OSPF6_INTERFACE_WAITING) {
if (hello->bdrouter == on->router_id)
backupseen++;
else if (hello->drouter == on->router_id
&& hello->bdrouter == htonl(0))
backupseen++;
}
oi->hello_in++;
/* Execute neighbor events */
thread_execute(master, hello_received, on, 0);
if (twoway)
thread_execute(master, twoway_received, on, 0);
else {
if (OSPF6_GR_IS_ACTIVE_HELPER(on)) {
if (IS_DEBUG_OSPF6_GR)
zlog_debug(
"%s, Received oneway hello from RESTARTER so ignore here.",
__PRETTY_FUNCTION__);
} else {
/* If the router is DR_OTHER, RESTARTER will not wait
* until it receives the hello from it if it receives
* from DR and BDR.
* So, helper might receives ONE_WAY hello from
* RESTARTER. So not allowing to change the state if it
* receives one_way hellow when it acts as HELPER for
* that specific neighbor.
*/
thread_execute(master, oneway_received, on, 0);
}
}
if (OSPF6_GR_IS_ACTIVE_HELPER(on)) {
/* As per the GR Conformance Test Case 7.2. Section 3
* "Also, if X was the Designated Router on network segment S
* when the helping relationship began, Y maintains X as the
* Designated Router until the helping relationship is
* terminated."
* When it is a helper for this neighbor, It should not trigger
* the ISM Events. Also Intentionally not setting the priority
* and other fields so that when the neighbor exits the Grace
* period, it can handle if there is any change before GR and
* after GR.
*/
if (IS_DEBUG_OSPF6_GR)
zlog_debug(
"%s, Neighbor is under GR Restart, hence ignoring the ISM Events",
__PRETTY_FUNCTION__);
return;
}
/*
* RFC 3623 - Section 2:
* "If the restarting router determines that it was the Designated
* Router on a given segment prior to the restart, it elects
* itself as the Designated Router again. The restarting router
* knows that it was the Designated Router if, while the
* associated interface is in Waiting state, a Hello packet is
* received from a neighbor listing the router as the Designated
* Router".
*/
if (oi->area->ospf6->gr_info.restart_in_progress
&& oi->state == OSPF6_INTERFACE_WAITING
&& hello->drouter == oi->area->ospf6->router_id)
oi->drouter = hello->drouter;
/* Schedule interface events */
if (backupseen)
thread_add_event(master, backup_seen, oi, 0, NULL);
if (neighborchange)
thread_add_event(master, neighbor_change, oi, 0, NULL);
if (neighbor_ifindex_change && on->state == OSPF6_NEIGHBOR_FULL)
OSPF6_ROUTER_LSA_SCHEDULE(oi->area);
}
static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
struct ospf6_neighbor *on)
{
struct ospf6_dbdesc *dbdesc;
char *p;
dbdesc = (struct ospf6_dbdesc *)((caddr_t)oh
+ sizeof(struct ospf6_header));
if (on->state < OSPF6_NEIGHBOR_INIT) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state less than Init, ignore");
return;
}
switch (on->state) {
case OSPF6_NEIGHBOR_TWOWAY:
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state is 2-Way, ignore");
return;
case OSPF6_NEIGHBOR_INIT:
thread_execute(master, twoway_received, on, 0);
if (on->state != OSPF6_NEIGHBOR_EXSTART) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Neighbor state is not ExStart, ignore");
return;
}
/* else fall through to ExStart */
/* fallthru */
case OSPF6_NEIGHBOR_EXSTART:
/* if neighbor obeys us as our slave, schedule negotiation_done
and process LSA Headers. Otherwise, ignore this message */
if (!CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MSBIT)
&& !CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT)
&& ntohl(dbdesc->seqnum) == on->dbdesc_seqnum) {
/* execute NegotiationDone */
thread_execute(master, negotiation_done, on, 0);
/* Record neighbor options */
memcpy(on->options, dbdesc->options,
sizeof(on->options));
} else {
zlog_warn("VRF %s: Nbr %s: Negotiation failed",
on->ospf6_if->interface->vrf->name, on->name);
return;
}
/* fall through to exchange */
case OSPF6_NEIGHBOR_EXCHANGE:
if (!memcmp(dbdesc, &on->dbdesc_last,
sizeof(struct ospf6_dbdesc))) {
/* Duplicated DatabaseDescription is dropped by master
*/
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Duplicated dbdesc discarded by Master, ignore");
return;
}
if (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MSBIT)) {
zlog_warn(
"DbDesc recv: Master/Slave bit mismatch Nbr %s",
on->name);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
if (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT)) {
zlog_warn("DbDesc recv: Initialize bit mismatch Nbr %s",
on->name);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
if (memcmp(on->options, dbdesc->options, sizeof(on->options))) {
zlog_warn("DbDesc recv: Option field mismatch Nbr %s",
on->name);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
if (ntohl(dbdesc->seqnum) != on->dbdesc_seqnum) {
zlog_warn(
"DbDesc recv: Sequence number mismatch Nbr %s (received %#lx, %#lx expected)",
on->name, (unsigned long)ntohl(dbdesc->seqnum),
(unsigned long)on->dbdesc_seqnum);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
break;
case OSPF6_NEIGHBOR_LOADING:
case OSPF6_NEIGHBOR_FULL:
if (!memcmp(dbdesc, &on->dbdesc_last,
sizeof(struct ospf6_dbdesc))) {
/* Duplicated DatabaseDescription is dropped by master
*/
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Duplicated dbdesc discarded by Master, ignore");
return;
}
zlog_warn(
"DbDesc recv: Not duplicate dbdesc in state %s Nbr %s",
ospf6_neighbor_state_str[on->state], on->name);
thread_add_event(master, seqnumber_mismatch, on, 0, NULL);
return;
default:
assert(0);
break;
}
/* Process LSA headers */
for (p = (char *)((caddr_t)dbdesc + sizeof(struct ospf6_dbdesc));
p + sizeof(struct ospf6_lsa_header) <= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsa_header)) {
struct ospf6_lsa *his, *mine;
struct ospf6_lsdb *lsdb = NULL;
his = ospf6_lsa_create_headeronly((struct ospf6_lsa_header *)p);
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("%s", his->name);
switch (OSPF6_LSA_SCOPE(his->header->type)) {
case OSPF6_SCOPE_LINKLOCAL:
lsdb = on->ospf6_if->lsdb;
break;
case OSPF6_SCOPE_AREA:
lsdb = on->ospf6_if->area->lsdb;
break;
case OSPF6_SCOPE_AS:
lsdb = on->ospf6_if->area->ospf6->lsdb;
break;
case OSPF6_SCOPE_RESERVED:
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Ignoring LSA of reserved scope");
ospf6_lsa_delete(his);
continue;
}
if (ntohs(his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL
&& (IS_AREA_STUB(on->ospf6_if->area)
|| IS_AREA_NSSA(on->ospf6_if->area))) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug(
"SeqNumMismatch (E-bit mismatch), discard");
ospf6_lsa_delete(his);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
mine = ospf6_lsdb_lookup(his->header->type, his->header->id,
his->header->adv_router, lsdb);
if (mine == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Add request (No database copy)");
ospf6_lsdb_add(ospf6_lsa_copy(his), on->request_list);
} else if (ospf6_lsa_compare(his, mine) < 0) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Add request (Received MoreRecent)");
ospf6_lsdb_add(ospf6_lsa_copy(his), on->request_list);
} else {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Discard (Existing MoreRecent)");
}
ospf6_lsa_delete(his);
}
assert(p == OSPF6_MESSAGE_END(oh));
/* Increment sequence number */
on->dbdesc_seqnum++;
/* schedule send lsreq */
if (on->request_list->count)
thread_add_event(master, ospf6_lsreq_send, on, 0,
&on->thread_send_lsreq);
THREAD_OFF(on->thread_send_dbdesc);
/* More bit check */
if (!CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MBIT)
&& !CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT))
thread_add_event(master, exchange_done, on, 0,
&on->thread_exchange_done);
else {
thread_add_event(master, ospf6_dbdesc_send_newone, on, 0,
&on->thread_send_dbdesc);
}
/* save last received dbdesc */
memcpy(&on->dbdesc_last, dbdesc, sizeof(struct ospf6_dbdesc));
}
static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
struct ospf6_neighbor *on)
{
struct ospf6_dbdesc *dbdesc;
char *p;
dbdesc = (struct ospf6_dbdesc *)((caddr_t)oh
+ sizeof(struct ospf6_header));
if (on->state < OSPF6_NEIGHBOR_INIT) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state less than Init, ignore");
return;
}
switch (on->state) {
case OSPF6_NEIGHBOR_TWOWAY:
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state is 2-Way, ignore");
return;
case OSPF6_NEIGHBOR_INIT:
thread_execute(master, twoway_received, on, 0);
if (on->state != OSPF6_NEIGHBOR_EXSTART) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Neighbor state is not ExStart, ignore");
return;
}
/* else fall through to ExStart */
/* fallthru */
case OSPF6_NEIGHBOR_EXSTART:
/* If the neighbor is Master, act as Slave. Schedule
negotiation_done
and process LSA Headers. Otherwise, ignore this message */
if (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT)
&& CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MBIT)
&& CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MSBIT)
&& ntohs(oh->length)
== sizeof(struct ospf6_header)
+ sizeof(struct ospf6_dbdesc)) {
/* set the master/slave bit to slave */
UNSET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
/* set the DD sequence number to one specified by master
*/
on->dbdesc_seqnum = ntohl(dbdesc->seqnum);
/* schedule NegotiationDone */
thread_execute(master, negotiation_done, on, 0);
/* Record neighbor options */
memcpy(on->options, dbdesc->options,
sizeof(on->options));
} else {
zlog_warn("VRF %s: Nbr %s Negotiation failed",
on->ospf6_if->interface->vrf->name, on->name);
return;
}
break;
case OSPF6_NEIGHBOR_EXCHANGE:
if (!memcmp(dbdesc, &on->dbdesc_last,
sizeof(struct ospf6_dbdesc))) {
/* Duplicated DatabaseDescription causes slave to
* retransmit */
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Duplicated dbdesc causes retransmit");
THREAD_OFF(on->thread_send_dbdesc);
thread_add_event(master, ospf6_dbdesc_send, on, 0,
&on->thread_send_dbdesc);
return;
}
if (!CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MSBIT)) {
zlog_warn(
"DbDesc slave recv: Master/Slave bit mismatch Nbr %s",
on->name);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
if (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT)) {
zlog_warn(
"DbDesc slave recv: Initialize bit mismatch Nbr %s",
on->name);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
if (memcmp(on->options, dbdesc->options, sizeof(on->options))) {
zlog_warn(
"DbDesc slave recv: Option field mismatch Nbr %s",
on->name);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
if (ntohl(dbdesc->seqnum) != on->dbdesc_seqnum + 1) {
zlog_warn(
"DbDesc slave recv: Sequence number mismatch Nbr %s (received %#lx, %#lx expected)",
on->name, (unsigned long)ntohl(dbdesc->seqnum),
(unsigned long)on->dbdesc_seqnum + 1);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
break;
case OSPF6_NEIGHBOR_LOADING:
case OSPF6_NEIGHBOR_FULL:
if (!memcmp(dbdesc, &on->dbdesc_last,
sizeof(struct ospf6_dbdesc))) {
/* Duplicated DatabaseDescription causes slave to
* retransmit */
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Duplicated dbdesc causes retransmit");
THREAD_OFF(on->thread_send_dbdesc);
thread_add_event(master, ospf6_dbdesc_send, on, 0,
&on->thread_send_dbdesc);
return;
}
zlog_warn(
"DbDesc slave recv: Not duplicate dbdesc in state %s Nbr %s",
ospf6_neighbor_state_str[on->state], on->name);
thread_add_event(master, seqnumber_mismatch, on, 0, NULL);
return;
default:
assert(0);
break;
}
/* Process LSA headers */
for (p = (char *)((caddr_t)dbdesc + sizeof(struct ospf6_dbdesc));
p + sizeof(struct ospf6_lsa_header) <= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsa_header)) {
struct ospf6_lsa *his, *mine;
struct ospf6_lsdb *lsdb = NULL;
his = ospf6_lsa_create_headeronly((struct ospf6_lsa_header *)p);
switch (OSPF6_LSA_SCOPE(his->header->type)) {
case OSPF6_SCOPE_LINKLOCAL:
lsdb = on->ospf6_if->lsdb;
break;
case OSPF6_SCOPE_AREA:
lsdb = on->ospf6_if->area->lsdb;
break;
case OSPF6_SCOPE_AS:
lsdb = on->ospf6_if->area->ospf6->lsdb;
break;
case OSPF6_SCOPE_RESERVED:
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Ignoring LSA of reserved scope");
ospf6_lsa_delete(his);
continue;
}
if (OSPF6_LSA_SCOPE(his->header->type) == OSPF6_SCOPE_AS
&& (IS_AREA_STUB(on->ospf6_if->area)
|| IS_AREA_NSSA(on->ospf6_if->area))) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("E-bit mismatch with LSA Headers");
ospf6_lsa_delete(his);
thread_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
mine = ospf6_lsdb_lookup(his->header->type, his->header->id,
his->header->adv_router, lsdb);
if (mine == NULL || ospf6_lsa_compare(his, mine) < 0) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Add request-list: %s", his->name);
ospf6_lsdb_add(ospf6_lsa_copy(his), on->request_list);
}
ospf6_lsa_delete(his);
}
assert(p == OSPF6_MESSAGE_END(oh));
/* Set sequence number to Master's */
on->dbdesc_seqnum = ntohl(dbdesc->seqnum);
/* schedule send lsreq */
if (on->request_list->count)
thread_add_event(master, ospf6_lsreq_send, on, 0,
&on->thread_send_lsreq);
THREAD_OFF(on->thread_send_dbdesc);
thread_add_event(master, ospf6_dbdesc_send_newone, on, 0,
&on->thread_send_dbdesc);
/* save last received dbdesc */
memcpy(&on->dbdesc_last, dbdesc, sizeof(struct ospf6_dbdesc));
}
static void ospf6_dbdesc_recv(struct in6_addr *src, struct in6_addr *dst,
struct ospf6_interface *oi,
struct ospf6_header *oh)
{
struct ospf6_neighbor *on;
struct ospf6_dbdesc *dbdesc;
on = ospf6_neighbor_lookup(oh->router_id, oi);
if (on == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor not found, ignore");
return;
}
dbdesc = (struct ospf6_dbdesc *)((caddr_t)oh
+ sizeof(struct ospf6_header));
if (((OSPF6_OPT_ISSET_EXT(dbdesc->options, OSPF6_OPT_AT) ==
OSPF6_OPT_AT) &&
(oi->at_data.flags == 0)) ||
((OSPF6_OPT_ISSET_EXT(dbdesc->options, OSPF6_OPT_AT) !=
OSPF6_OPT_AT) &&
(oi->at_data.flags != 0))) {
if (IS_OSPF6_DEBUG_AUTH_RX)
zlog_warn(
"VRF %s: IF %s AT-bit mismatch in dbdesc packet",
oi->interface->vrf->name, oi->interface->name);
oi->at_data.rx_drop++;
return;
}
/* Interface MTU check */
if (!oi->mtu_ignore && ntohs(dbdesc->ifmtu) != oi->ifmtu) {
zlog_warn("VRF %s: I/F %s MTU mismatch (my %d rcvd %d)",
oi->interface->vrf->name, oi->interface->name,
oi->ifmtu, ntohs(dbdesc->ifmtu));
return;
}
if (dbdesc->reserved1 || dbdesc->reserved2) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Non-0 reserved field in %s's DbDesc, correct",
on->name);
dbdesc->reserved1 = 0;
dbdesc->reserved2 = 0;
}
oi->db_desc_in++;
if (ntohl(oh->router_id) < ntohl(oi->area->ospf6->router_id))
ospf6_dbdesc_recv_master(oh, on);
else if (ntohl(oi->area->ospf6->router_id) < ntohl(oh->router_id))
ospf6_dbdesc_recv_slave(oh, on);
else {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Can't decide which is master, ignore");
}
}
static void ospf6_lsreq_recv(struct in6_addr *src, struct in6_addr *dst,
struct ospf6_interface *oi,
struct ospf6_header *oh)
{
struct ospf6_neighbor *on;
char *p;
struct ospf6_lsreq_entry *e;
struct ospf6_lsdb *lsdb = NULL;
struct ospf6_lsa *lsa;
on = ospf6_neighbor_lookup(oh->router_id, oi);
if (on == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor not found, ignore");
return;
}
if (on->state != OSPF6_NEIGHBOR_EXCHANGE
&& on->state != OSPF6_NEIGHBOR_LOADING
&& on->state != OSPF6_NEIGHBOR_FULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state less than Exchange, ignore");
return;
}
oi->ls_req_in++;
/* Process each request */
for (p = (char *)((caddr_t)oh + sizeof(struct ospf6_header));
p + sizeof(struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsreq_entry)) {
e = (struct ospf6_lsreq_entry *)p;
switch (OSPF6_LSA_SCOPE(e->type)) {
case OSPF6_SCOPE_LINKLOCAL:
lsdb = on->ospf6_if->lsdb;
break;
case OSPF6_SCOPE_AREA:
lsdb = on->ospf6_if->area->lsdb;
break;
case OSPF6_SCOPE_AS:
lsdb = on->ospf6_if->area->ospf6->lsdb;
break;
default:
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Ignoring LSA of reserved scope");
continue;
}
/* Find database copy */
lsa = ospf6_lsdb_lookup(e->type, e->id, e->adv_router, lsdb);
if (lsa == NULL) {
zlog_warn(
"Can't find requested lsa [%s Id:%pI4 Adv:%pI4] send badLSReq",
ospf6_lstype_name(e->type), &e->id,
&e->adv_router);
thread_add_event(master, bad_lsreq, on, 0, NULL);
return;
}
ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->lsupdate_list);
}
assert(p == OSPF6_MESSAGE_END(oh));
/* schedule send lsupdate */
THREAD_OFF(on->thread_send_lsupdate);
thread_add_event(master, ospf6_lsupdate_send_neighbor, on, 0,
&on->thread_send_lsupdate);
}
/* Verify, that the specified memory area contains exactly N valid IPv6
prefixes as specified by RFC5340, A.4.1. */
static unsigned ospf6_prefixes_examin(
struct ospf6_prefix *current, /* start of buffer */
unsigned length,
const uint32_t req_num_pfxs /* always compared with the actual number
of prefixes */
)
{
uint8_t requested_pfx_bytes;
uint32_t real_num_pfxs = 0;
while (length) {
if (length < OSPF6_PREFIX_MIN_SIZE) {
zlog_warn("%s: undersized IPv6 prefix header",
__func__);
return MSG_NG;
}
/* safe to look deeper */
if (current->prefix_length > IPV6_MAX_BITLEN) {
zlog_warn("%s: invalid PrefixLength (%u bits)",
__func__, current->prefix_length);
return MSG_NG;
}
/* covers both fixed- and variable-sized fields */
requested_pfx_bytes =
OSPF6_PREFIX_MIN_SIZE
+ OSPF6_PREFIX_SPACE(current->prefix_length);
if (requested_pfx_bytes > length) {
zlog_warn("%s: undersized IPv6 prefix", __func__);
return MSG_NG;
}
/* next prefix */
length -= requested_pfx_bytes;
current = (struct ospf6_prefix *)((caddr_t)current
+ requested_pfx_bytes);
real_num_pfxs++;
}
if (real_num_pfxs != req_num_pfxs) {
zlog_warn(
"%s: IPv6 prefix number mismatch (%u required, %u real)",
__func__, req_num_pfxs, real_num_pfxs);
return MSG_NG;
}
return MSG_OK;
}
/* Verify an LSA to have a valid length and dispatch further (where
appropriate) to check if the contents, including nested IPv6 prefixes,
is properly sized/aligned within the LSA. Note that this function gets
LSA type in network byte order, uses in host byte order and passes to
ospf6_lstype_name() in network byte order again. */
static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah,
const uint16_t lsalen,
const uint8_t headeronly)
{
struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
struct ospf6_as_external_lsa *as_external_lsa;
struct ospf6_link_lsa *link_lsa;
unsigned exp_length;
uint8_t ltindex;
uint16_t lsatype;
/* In case an additional minimum length constraint is defined for
current
LSA type, make sure that this constraint is met. */
lsatype = ntohs(lsah->type);
ltindex = lsatype & OSPF6_LSTYPE_FCODE_MASK;
if (ltindex < OSPF6_LSTYPE_SIZE && ospf6_lsa_minlen[ltindex]
&& lsalen < ospf6_lsa_minlen[ltindex] + OSPF6_LSA_HEADER_SIZE) {
zlog_warn("%s: undersized (%u B) LSA", __func__, lsalen);
return MSG_NG;
}
switch (lsatype) {
case OSPF6_LSTYPE_ROUTER:
/* RFC5340 A.4.3, LSA header + OSPF6_ROUTER_LSA_MIN_SIZE bytes
followed
by N>=0 interface descriptions. */
if ((lsalen - OSPF6_LSA_HEADER_SIZE - OSPF6_ROUTER_LSA_MIN_SIZE)
% OSPF6_ROUTER_LSDESC_FIX_SIZE) {
zlog_warn(
"%s: Router LSA interface description alignment error",
__func__);
return MSG_NG;
}
break;
case OSPF6_LSTYPE_NETWORK:
/* RFC5340 A.4.4, LSA header + OSPF6_NETWORK_LSA_MIN_SIZE bytes
followed by N>=0 attached router descriptions. */
if ((lsalen - OSPF6_LSA_HEADER_SIZE
- OSPF6_NETWORK_LSA_MIN_SIZE)
% OSPF6_NETWORK_LSDESC_FIX_SIZE) {
zlog_warn(
"%s: Network LSA router description alignment error",
__func__);
return MSG_NG;
}
break;
case OSPF6_LSTYPE_INTER_PREFIX:
/* RFC5340 A.4.5, LSA header + OSPF6_INTER_PREFIX_LSA_MIN_SIZE
bytes
followed by 3-4 fields of a single IPv6 prefix. */
if (headeronly)
break;
return ospf6_prefixes_examin(
(struct ospf6_prefix
*)((caddr_t)lsah + OSPF6_LSA_HEADER_SIZE
+ OSPF6_INTER_PREFIX_LSA_MIN_SIZE),
lsalen - OSPF6_LSA_HEADER_SIZE
- OSPF6_INTER_PREFIX_LSA_MIN_SIZE,
1);
case OSPF6_LSTYPE_INTER_ROUTER:
/* RFC5340 A.4.6, fixed-size LSA. */
if (lsalen
> OSPF6_LSA_HEADER_SIZE + OSPF6_INTER_ROUTER_LSA_FIX_SIZE) {
zlog_warn("%s: Inter Router LSA oversized (%u B) LSA",
__func__, lsalen);
return MSG_NG;
}
break;
case OSPF6_LSTYPE_AS_EXTERNAL: /* RFC5340 A.4.7, same as A.4.8. */
case OSPF6_LSTYPE_TYPE_7:
/* RFC5340 A.4.8, LSA header + OSPF6_AS_EXTERNAL_LSA_MIN_SIZE
bytes
followed by 3-4 fields of IPv6 prefix and 3 conditional LSA
fields:
16 bytes of forwarding address, 4 bytes of external route
tag,
4 bytes of referenced link state ID. */
if (headeronly)
break;
as_external_lsa =
(struct ospf6_as_external_lsa
*)((caddr_t)lsah + OSPF6_LSA_HEADER_SIZE);
exp_length =
OSPF6_LSA_HEADER_SIZE + OSPF6_AS_EXTERNAL_LSA_MIN_SIZE;
/* To find out if the last optional field (Referenced Link State
ID) is
assumed in this LSA, we need to access fixed fields of the
IPv6
prefix before ospf6_prefix_examin() confirms its sizing. */
if (exp_length + OSPF6_PREFIX_MIN_SIZE > lsalen) {
zlog_warn(
"%s: AS External undersized (%u B) LSA header",
__func__, lsalen);
return MSG_NG;
}
/* forwarding address */
if (CHECK_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F))
exp_length += 16;
/* external route tag */
if (CHECK_FLAG(as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T))
exp_length += 4;
/* referenced link state ID */
if (as_external_lsa->prefix.u._prefix_referenced_lstype)
exp_length += 4;
/* All the fixed-size fields (mandatory and optional) must fit.
I.e.,
this check does not include any IPv6 prefix fields. */
if (exp_length > lsalen) {
zlog_warn(
"%s: AS External undersized (%u B) LSA header",
__func__, lsalen);
return MSG_NG;
}
/* The last call completely covers the remainder (IPv6 prefix).
*/
return ospf6_prefixes_examin(
(struct ospf6_prefix
*)((caddr_t)as_external_lsa
+ OSPF6_AS_EXTERNAL_LSA_MIN_SIZE),
lsalen - exp_length, 1);
case OSPF6_LSTYPE_LINK:
/* RFC5340 A.4.9, LSA header + OSPF6_LINK_LSA_MIN_SIZE bytes
followed
by N>=0 IPv6 prefix blocks (with N declared beforehand). */
if (headeronly)
break;
link_lsa = (struct ospf6_link_lsa *)((caddr_t)lsah
+ OSPF6_LSA_HEADER_SIZE);
return ospf6_prefixes_examin(
(struct ospf6_prefix *)((caddr_t)link_lsa
+ OSPF6_LINK_LSA_MIN_SIZE),
lsalen - OSPF6_LSA_HEADER_SIZE
- OSPF6_LINK_LSA_MIN_SIZE,
ntohl(link_lsa->prefix_num) /* 32 bits */
);
case OSPF6_LSTYPE_INTRA_PREFIX:
/* RFC5340 A.4.10, LSA header + OSPF6_INTRA_PREFIX_LSA_MIN_SIZE
bytes
followed by N>=0 IPv6 prefixes (with N declared beforehand).
*/
if (headeronly)
break;
intra_prefix_lsa =
(struct ospf6_intra_prefix_lsa
*)((caddr_t)lsah + OSPF6_LSA_HEADER_SIZE);
return ospf6_prefixes_examin(
(struct ospf6_prefix
*)((caddr_t)intra_prefix_lsa
+ OSPF6_INTRA_PREFIX_LSA_MIN_SIZE),
lsalen - OSPF6_LSA_HEADER_SIZE
- OSPF6_INTRA_PREFIX_LSA_MIN_SIZE,
ntohs(intra_prefix_lsa->prefix_num) /* 16 bits */
);
case OSPF6_LSTYPE_GRACE_LSA:
if (lsalen < OSPF6_LSA_HEADER_SIZE + GRACE_PERIOD_TLV_SIZE
+ GRACE_RESTART_REASON_TLV_SIZE) {
if (IS_DEBUG_OSPF6_GR)
zlog_debug("%s: Undersized GraceLSA.",
__func__);
return MSG_NG;
}
}
/* No additional validation is possible for unknown LSA types, which are
themselves valid in OPSFv3, hence the default decision is to accept.
*/
return MSG_OK;
}
/* Verify if the provided input buffer is a valid sequence of LSAs. This
includes verification of LSA blocks length/alignment and dispatching
of deeper-level checks. */
static unsigned
ospf6_lsaseq_examin(struct ospf6_lsa_header *lsah, /* start of buffered data */
size_t length, const uint8_t headeronly,
/* When declared_num_lsas is not 0, compare it to the real
number of LSAs
and treat the difference as an error. */
const uint32_t declared_num_lsas)
{
uint32_t counted_lsas = 0;
while (length) {
uint16_t lsalen;
if (length < OSPF6_LSA_HEADER_SIZE) {
zlog_warn(
"%s: undersized (%zu B) trailing (#%u) LSA header",
__func__, length, counted_lsas);
return MSG_NG;
}
/* save on ntohs() calls here and in the LSA validator */
lsalen = OSPF6_LSA_SIZE(lsah);
if (lsalen < OSPF6_LSA_HEADER_SIZE) {
zlog_warn(
"%s: malformed LSA header #%u, declared length is %u B",
__func__, counted_lsas, lsalen);
return MSG_NG;
}
if (headeronly) {
/* less checks here and in ospf6_lsa_examin() */
if (MSG_OK != ospf6_lsa_examin(lsah, lsalen, 1)) {
zlog_warn(
"%s: anomaly in header-only %s LSA #%u",
__func__, ospf6_lstype_name(lsah->type),
counted_lsas);
return MSG_NG;
}
lsah = (struct ospf6_lsa_header
*)((caddr_t)lsah
+ OSPF6_LSA_HEADER_SIZE);
length -= OSPF6_LSA_HEADER_SIZE;
} else {
/* make sure the input buffer is deep enough before
* further checks */
if (lsalen > length) {
zlog_warn(
"%s: anomaly in %s LSA #%u: declared length is %u B, buffered length is %zu B",
__func__, ospf6_lstype_name(lsah->type),
counted_lsas, lsalen, length);
return MSG_NG;
}
if (MSG_OK != ospf6_lsa_examin(lsah, lsalen, 0)) {
zlog_warn("%s: anomaly in %s LSA #%u", __func__,
ospf6_lstype_name(lsah->type),
counted_lsas);
return MSG_NG;
}
lsah = (struct ospf6_lsa_header *)((caddr_t)lsah
+ lsalen);
length -= lsalen;
}
counted_lsas++;
}
if (declared_num_lsas && counted_lsas != declared_num_lsas) {
zlog_warn("%s: #LSAs declared (%u) does not match actual (%u)",
__func__, declared_num_lsas, counted_lsas);
return MSG_NG;
}
return MSG_OK;
}
/* Verify a complete OSPF packet for proper sizing/alignment. */
static unsigned ospf6_packet_examin(struct ospf6_header *oh,
const unsigned bytesonwire)
{
struct ospf6_lsupdate *lsupd;
unsigned test;
/* length, 1st approximation */
if (bytesonwire < OSPF6_HEADER_SIZE) {
zlog_warn("%s: undersized (%u B) packet", __func__,
bytesonwire);
return MSG_NG;
}
/* Now it is safe to access header fields. */
if (bytesonwire != ntohs(oh->length)) {
zlog_warn("%s: %s packet length error (%u real, %u declared)",
__func__, ospf6_message_type(oh->type), bytesonwire,
ntohs(oh->length));
return MSG_NG;
}
/* version check */
if (oh->version != OSPFV3_VERSION) {
zlog_warn("%s: invalid (%u) protocol version", __func__,
oh->version);
return MSG_NG;
}
/* length, 2nd approximation */
if (oh->type < OSPF6_MESSAGE_TYPE_ALL && ospf6_packet_minlen[oh->type]
&& bytesonwire
< OSPF6_HEADER_SIZE + ospf6_packet_minlen[oh->type]) {
zlog_warn("%s: undersized (%u B) %s packet", __func__,
bytesonwire, ospf6_message_type(oh->type));
return MSG_NG;
}
/* type-specific deeper validation */
switch (oh->type) {
case OSPF6_MESSAGE_TYPE_HELLO:
/* RFC5340 A.3.2, packet header + OSPF6_HELLO_MIN_SIZE bytes
followed
by N>=0 router-IDs. */
if (0
== (bytesonwire - OSPF6_HEADER_SIZE - OSPF6_HELLO_MIN_SIZE)
% 4)
return MSG_OK;
zlog_warn("%s: alignment error in %s packet", __func__,
ospf6_message_type(oh->type));
return MSG_NG;
case OSPF6_MESSAGE_TYPE_DBDESC:
/* RFC5340 A.3.3, packet header + OSPF6_DB_DESC_MIN_SIZE bytes
followed
by N>=0 header-only LSAs. */
test = ospf6_lsaseq_examin(
(struct ospf6_lsa_header *)((caddr_t)oh
+ OSPF6_HEADER_SIZE
+ OSPF6_DB_DESC_MIN_SIZE),
bytesonwire - OSPF6_HEADER_SIZE
- OSPF6_DB_DESC_MIN_SIZE,
1, 0);
break;
case OSPF6_MESSAGE_TYPE_LSREQ:
/* RFC5340 A.3.4, packet header + N>=0 LS description blocks. */
if (0
== (bytesonwire - OSPF6_HEADER_SIZE - OSPF6_LS_REQ_MIN_SIZE)
% OSPF6_LSREQ_LSDESC_FIX_SIZE)
return MSG_OK;
zlog_warn("%s: alignment error in %s packet", __func__,
ospf6_message_type(oh->type));
return MSG_NG;
case OSPF6_MESSAGE_TYPE_LSUPDATE:
/* RFC5340 A.3.5, packet header + OSPF6_LS_UPD_MIN_SIZE bytes
followed
by N>=0 full LSAs (with N declared beforehand). */
lsupd = (struct ospf6_lsupdate *)((caddr_t)oh
+ OSPF6_HEADER_SIZE);
test = ospf6_lsaseq_examin(
(struct ospf6_lsa_header *)((caddr_t)lsupd
+ OSPF6_LS_UPD_MIN_SIZE),
bytesonwire - OSPF6_HEADER_SIZE - OSPF6_LS_UPD_MIN_SIZE,
0, ntohl(lsupd->lsa_number) /* 32 bits */
);
break;
case OSPF6_MESSAGE_TYPE_LSACK:
/* RFC5340 A.3.6, packet header + N>=0 header-only LSAs. */
test = ospf6_lsaseq_examin(
(struct ospf6_lsa_header *)((caddr_t)oh
+ OSPF6_HEADER_SIZE
+ OSPF6_LS_ACK_MIN_SIZE),
bytesonwire - OSPF6_HEADER_SIZE - OSPF6_LS_ACK_MIN_SIZE,
1, 0);
break;
default:
zlog_warn("%s: invalid (%u) message type", __func__, oh->type);
return MSG_NG;
}
if (test != MSG_OK)
zlog_warn("%s: anomaly in %s packet", __func__,
ospf6_message_type(oh->type));
return test;
}
/* Verify particular fields of otherwise correct received OSPF packet to
meet the requirements of RFC. */
static int ospf6_rxpacket_examin(struct ospf6_interface *oi,
struct ospf6_header *oh,
const unsigned bytesonwire)
{
struct ospf6_neighbor *on;
if (MSG_OK != ospf6_packet_examin(oh, bytesonwire))
return MSG_NG;
on = ospf6_neighbor_lookup(oh->router_id, oi);
/* Area-ID check */
if (oh->area_id != oi->area->area_id) {
if (oh->area_id == OSPF_AREA_BACKBONE)
zlog_warn(
"VRF %s: I/F %s (%s, Router-ID: %pI4) Message may be via Virtual Link: not supported",
oi->interface->vrf->name, oi->interface->name,
on ? on->name : "null", &oh->router_id);
else
zlog_warn(
"VRF %s: I/F %s (%s, Router-ID: %pI4) Area-ID mismatch (my %pI4, rcvd %pI4)",
oi->interface->vrf->name, oi->interface->name,
on ? on->name : "null", &oh->router_id,
&oi->area->area_id, &oh->area_id);
return MSG_NG;
}
/* Instance-ID check */
if (oh->instance_id != oi->instance_id) {
zlog_warn(
"VRF %s: I/F %s (%s, Router-ID: %pI4) Instance-ID mismatch (my %u, rcvd %u)",
oi->interface->vrf->name, oi->interface->name,
on ? on->name : "null", &oh->router_id, oi->instance_id,
oh->instance_id);
return MSG_NG;
}
/* Router-ID check */
if (oh->router_id == oi->area->ospf6->router_id) {
zlog_warn("VRF %s: I/F %s Duplicate Router-ID (%pI4)",
oi->interface->vrf->name, oi->interface->name,
&oh->router_id);
return MSG_NG;
}
return MSG_OK;
}
static void ospf6_lsupdate_recv(struct in6_addr *src, struct in6_addr *dst,
struct ospf6_interface *oi,
struct ospf6_header *oh)
{
struct ospf6_neighbor *on;
struct ospf6_lsupdate *lsupdate;
char *p;
on = ospf6_neighbor_lookup(oh->router_id, oi);
if (on == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor not found, ignore");
return;
}
if (on->state != OSPF6_NEIGHBOR_EXCHANGE
&& on->state != OSPF6_NEIGHBOR_LOADING
&& on->state != OSPF6_NEIGHBOR_FULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state less than Exchange, ignore");
return;
}
lsupdate = (struct ospf6_lsupdate *)((caddr_t)oh
+ sizeof(struct ospf6_header));
oi->ls_upd_in++;
/* Process LSAs */
for (p = (char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate));
p < OSPF6_MESSAGE_END(oh)
&& p + OSPF6_LSA_SIZE(p) <= OSPF6_MESSAGE_END(oh);
p += OSPF6_LSA_SIZE(p)) {
ospf6_receive_lsa(on, (struct ospf6_lsa_header *)p);
}
assert(p == OSPF6_MESSAGE_END(oh));
}
static void ospf6_lsack_recv(struct in6_addr *src, struct in6_addr *dst,
struct ospf6_interface *oi,
struct ospf6_header *oh)
{
struct ospf6_neighbor *on;
char *p;
struct ospf6_lsa *his, *mine;
struct ospf6_lsdb *lsdb = NULL;
assert(oh->type == OSPF6_MESSAGE_TYPE_LSACK);
on = ospf6_neighbor_lookup(oh->router_id, oi);
if (on == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor not found, ignore");
return;
}
if (on->state != OSPF6_NEIGHBOR_EXCHANGE
&& on->state != OSPF6_NEIGHBOR_LOADING
&& on->state != OSPF6_NEIGHBOR_FULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug("Neighbor state less than Exchange, ignore");
return;
}
oi->ls_ack_in++;
for (p = (char *)((caddr_t)oh + sizeof(struct ospf6_header));
p + sizeof(struct ospf6_lsa_header) <= OSPF6_MESSAGE_END(oh);
p += sizeof(struct ospf6_lsa_header)) {
his = ospf6_lsa_create_headeronly((struct ospf6_lsa_header *)p);
switch (OSPF6_LSA_SCOPE(his->header->type)) {
case OSPF6_SCOPE_LINKLOCAL:
lsdb = on->ospf6_if->lsdb;
break;
case OSPF6_SCOPE_AREA:
lsdb = on->ospf6_if->area->lsdb;
break;
case OSPF6_SCOPE_AS:
lsdb = on->ospf6_if->area->ospf6->lsdb;
break;
case OSPF6_SCOPE_RESERVED:
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Ignoring LSA of reserved scope");
ospf6_lsa_delete(his);
continue;
}
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("%s acknowledged by %s", his->name,
on->name);
/* Find database copy */
mine = ospf6_lsdb_lookup(his->header->type, his->header->id,
his->header->adv_router, lsdb);
if (mine == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("No database copy");
ospf6_lsa_delete(his);
continue;
}
/* Check if the LSA is on his retrans-list */
mine = ospf6_lsdb_lookup(his->header->type, his->header->id,
his->header->adv_router,
on->retrans_list);
if (mine == NULL) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Not on %s's retrans-list",
on->name);
ospf6_lsa_delete(his);
continue;
}
if (ospf6_lsa_compare(his, mine) != 0) {
/* Log this questionable acknowledgement,
and examine the next one. */
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("Questionable acknowledgement");
ospf6_lsa_delete(his);
continue;
}
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug(
"Acknowledged, remove from %s's retrans-list",
on->name);
ospf6_decrement_retrans_count(mine);
if (OSPF6_LSA_IS_MAXAGE(mine))
ospf6_maxage_remove(on->ospf6_if->area->ospf6);
ospf6_lsdb_remove(mine, on->retrans_list);
ospf6_lsa_delete(his);
}
assert(p == OSPF6_MESSAGE_END(oh));
}
static uint8_t *recvbuf = NULL;
static uint8_t *sendbuf = NULL;
static unsigned int iobuflen = 0;
int ospf6_iobuf_size(unsigned int size)
{
/* NB: there was previously code here that tried to dynamically size
* the buffer for whatever we see in MTU on interfaces. Which is
* _unconditionally wrong_ - we can always receive fragmented IPv6
* up to the regular 64k length limit. (No jumbograms, thankfully.)
*/
if (!iobuflen) {
/* the + 128 is to have some runway at the end */
size_t alloc_size = 65536 + 128;
assert(!recvbuf && !sendbuf);
recvbuf = XMALLOC(MTYPE_OSPF6_MESSAGE, alloc_size);
sendbuf = XMALLOC(MTYPE_OSPF6_MESSAGE, alloc_size);
iobuflen = alloc_size;
}
return iobuflen;
}
void ospf6_message_terminate(void)
{
XFREE(MTYPE_OSPF6_MESSAGE, recvbuf);
XFREE(MTYPE_OSPF6_MESSAGE, sendbuf);
iobuflen = 0;
}
enum ospf6_read_return_enum {
OSPF6_READ_ERROR,
OSPF6_READ_CONTINUE,
};
static int ospf6_read_helper(int sockfd, struct ospf6 *ospf6)
{
int len;
struct in6_addr src, dst;
ifindex_t ifindex;
struct iovec iovector[2];
struct ospf6_interface *oi;
struct ospf6_header *oh;
enum ospf6_auth_err ret = OSPF6_AUTH_PROCESS_NORMAL;
uint32_t at_len = 0;
uint32_t lls_len = 0;
/* initialize */
memset(&src, 0, sizeof(src));
memset(&dst, 0, sizeof(dst));
ifindex = 0;
iovector[0].iov_base = recvbuf;
iovector[0].iov_len = iobuflen;
iovector[1].iov_base = NULL;
iovector[1].iov_len = 0;
/* receive message */
len = ospf6_recvmsg(&src, &dst, &ifindex, iovector, sockfd);
if (len < 0)
return OSPF6_READ_ERROR;
if ((uint)len > iobuflen) {
flog_err(EC_LIB_DEVELOPMENT, "Excess message read");
return OSPF6_READ_ERROR;
}
/* ensure some zeroes past the end, just as a security precaution */
memset(recvbuf + len, 0, MIN(128, iobuflen - len));
oi = ospf6_interface_lookup_by_ifindex(ifindex, ospf6->vrf_id);
if (oi == NULL || oi->area == NULL
|| CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN,
RECV_HDR))
zlog_debug("Message received on disabled interface");
return OSPF6_READ_CONTINUE;
}
if (CHECK_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE)) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN,
RECV_HDR))
zlog_debug("%s: Ignore message on passive interface %s",
__func__, oi->interface->name);
return OSPF6_READ_CONTINUE;
}
/*
* Drop packet destined to another VRF.
* This happens when raw_l3mdev_accept is set to 1.
*/
if (ospf6->vrf_id != oi->interface->vrf->vrf_id)
return OSPF6_READ_CONTINUE;
oh = (struct ospf6_header *)recvbuf;
ret = ospf6_auth_validate_pkt(oi, (uint32_t *)&len, oh, &at_len,
&lls_len);
if (ret == OSPF6_AUTH_VALIDATE_SUCCESS) {
ret = ospf6_auth_check_digest(oh, oi, &src, lls_len);
if (ret == OSPF6_AUTH_VALIDATE_FAILURE) {
if (IS_OSPF6_DEBUG_AUTH_RX)
zlog_err(
"RECV[%s]: OSPF packet auth digest miss-match on %s",
oi->interface->name,
ospf6_message_type(oh->type));
oi->at_data.rx_drop++;
return OSPF6_READ_CONTINUE;
}
} else if (ret == OSPF6_AUTH_VALIDATE_FAILURE) {
oi->at_data.rx_drop++;
return OSPF6_READ_CONTINUE;
}
if (ospf6_rxpacket_examin(oi, oh, len) != MSG_OK)
return OSPF6_READ_CONTINUE;
/* Being here means, that no sizing/alignment issues were detected in
the input packet. This renders the additional checks performed below
and also in the type-specific dispatching functions a dead code,
which can be dismissed in a cleanup-focused review round later. */
/* Log */
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR)) {
zlog_debug("%s received on %s", ospf6_message_type(oh->type),
oi->interface->name);
zlog_debug(" src: %pI6", &src);
zlog_debug(" dst: %pI6", &dst);
switch (oh->type) {
case OSPF6_MESSAGE_TYPE_HELLO:
ospf6_hello_print(oh, OSPF6_ACTION_RECV);
break;
case OSPF6_MESSAGE_TYPE_DBDESC:
ospf6_dbdesc_print(oh, OSPF6_ACTION_RECV);
break;
case OSPF6_MESSAGE_TYPE_LSREQ:
ospf6_lsreq_print(oh, OSPF6_ACTION_RECV);
break;
case OSPF6_MESSAGE_TYPE_LSUPDATE:
ospf6_lsupdate_print(oh, OSPF6_ACTION_RECV);
break;
case OSPF6_MESSAGE_TYPE_LSACK:
ospf6_lsack_print(oh, OSPF6_ACTION_RECV);
break;
default:
assert(0);
}
if ((at_len != 0) && IS_OSPF6_DEBUG_AUTH_RX)
ospf6_auth_hdr_dump_recv(oh, (len + at_len + lls_len),
lls_len);
}
switch (oh->type) {
case OSPF6_MESSAGE_TYPE_HELLO:
ospf6_hello_recv(&src, &dst, oi, oh);
break;
case OSPF6_MESSAGE_TYPE_DBDESC:
ospf6_dbdesc_recv(&src, &dst, oi, oh);
break;
case OSPF6_MESSAGE_TYPE_LSREQ:
ospf6_lsreq_recv(&src, &dst, oi, oh);
break;
case OSPF6_MESSAGE_TYPE_LSUPDATE:
ospf6_lsupdate_recv(&src, &dst, oi, oh);
break;
case OSPF6_MESSAGE_TYPE_LSACK:
ospf6_lsack_recv(&src, &dst, oi, oh);
break;
default:
assert(0);
}
return OSPF6_READ_CONTINUE;
}
void ospf6_receive(struct event *thread)
{
int sockfd;
struct ospf6 *ospf6;
int count = 0;
/* add next read thread */
ospf6 = THREAD_ARG(thread);
sockfd = THREAD_FD(thread);
thread_add_read(master, ospf6_receive, ospf6, ospf6->fd,
&ospf6->t_ospf6_receive);
while (count < ospf6->write_oi_count) {
count++;
switch (ospf6_read_helper(sockfd, ospf6)) {
case OSPF6_READ_ERROR:
return;
case OSPF6_READ_CONTINUE:
break;
}
}
}
static void ospf6_fill_hdr_checksum(struct ospf6_interface *oi,
struct ospf6_packet *op)
{
struct ipv6_ph ph = {};
struct ospf6_header *oh;
void *offset = NULL;
if (oi->at_data.flags != 0)
return;
memcpy(&ph.src, oi->linklocal_addr, sizeof(struct in6_addr));
memcpy(&ph.dst, &op->dst, sizeof(struct in6_addr));
ph.ulpl = htonl(op->length);
ph.next_hdr = IPPROTO_OSPFIGP;
/* Suppress static analysis warnings about accessing icmp6 oob */
oh = (struct ospf6_header *)STREAM_DATA(op->s);
offset = oh;
oh->checksum = in_cksum_with_ph6(&ph, offset, op->length);
}
static void ospf6_make_header(uint8_t type, struct ospf6_interface *oi,
struct stream *s)
{
struct ospf6_header *oh;
oh = (struct ospf6_header *)STREAM_DATA(s);
oh->version = (uint8_t)OSPFV3_VERSION;
oh->type = type;
oh->length = 0;
oh->router_id = oi->area->ospf6->router_id;
oh->area_id = oi->area->area_id;
oh->checksum = 0;
oh->instance_id = oi->instance_id;
oh->reserved = 0;
stream_forward_endp(s, OSPF6_HEADER_SIZE);
}
static void ospf6_fill_header(struct ospf6_interface *oi, struct stream *s,
uint16_t length)
{
struct ospf6_header *oh;
oh = (struct ospf6_header *)STREAM_DATA(s);
oh->length = htons(length);
}
static void ospf6_fill_lsupdate_header(struct stream *s, uint32_t lsa_num)
{
struct ospf6_header *oh;
struct ospf6_lsupdate *lsu;
oh = (struct ospf6_header *)STREAM_DATA(s);
lsu = (struct ospf6_lsupdate *)((caddr_t)oh
+ sizeof(struct ospf6_header));
lsu->lsa_number = htonl(lsa_num);
}
static void ospf6_auth_trailer_copy_keychain_key(struct ospf6_interface *oi)
{
char *keychain_name = NULL;
struct keychain *keychain = NULL;
struct key *key = NULL;
keychain_name = oi->at_data.keychain;
keychain = keychain_lookup(keychain_name);
if (keychain) {
key = key_lookup_for_send(keychain);
if (key && key->string &&
key->hash_algo != KEYCHAIN_ALGO_NULL) {
/* storing the values so that further
* lookup can be avoided. after
* processing the digest need to reset
* these values
*/
oi->at_data.hash_algo = key->hash_algo;
if (oi->at_data.auth_key)
XFREE(MTYPE_OSPF6_AUTH_MANUAL_KEY,
oi->at_data.auth_key);
oi->at_data.auth_key = XSTRDUP(
MTYPE_OSPF6_AUTH_MANUAL_KEY, key->string);
oi->at_data.key_id = key->index;
SET_FLAG(oi->at_data.flags,
OSPF6_AUTH_TRAILER_KEYCHAIN_VALID);
}
}
}
static uint16_t ospf6_packet_max(struct ospf6_interface *oi)
{
uint16_t at_len = 0;
assert(oi->ifmtu > sizeof(struct ip6_hdr));
if (oi->at_data.flags != 0) {
if (CHECK_FLAG(oi->at_data.flags, OSPF6_AUTH_TRAILER_KEYCHAIN))
ospf6_auth_trailer_copy_keychain_key(oi);
at_len += OSPF6_AUTH_HDR_MIN_SIZE;
at_len += keychain_get_hash_len(oi->at_data.hash_algo);
return oi->ifmtu - (sizeof(struct ip6_hdr)) - at_len;
}
return oi->ifmtu - (sizeof(struct ip6_hdr));
}
static uint16_t ospf6_make_hello(struct ospf6_interface *oi, struct stream *s)
{
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
uint16_t length = OSPF6_HELLO_MIN_SIZE;
uint8_t options1 = oi->area->options[1];
if (oi->at_data.flags != 0)
options1 |= OSPF6_OPT_AT;
stream_putl(s, oi->interface->ifindex);
stream_putc(s, oi->priority);
stream_putc(s, oi->area->options[0]);
stream_putc(s, options1);
stream_putc(s, oi->area->options[2]);
stream_putw(s, oi->hello_interval);
stream_putw(s, oi->dead_interval);
stream_put_ipv4(s, oi->drouter);
stream_put_ipv4(s, oi->bdrouter);
for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
if (on->state < OSPF6_NEIGHBOR_INIT)
continue;
if ((length + sizeof(uint32_t) + OSPF6_HEADER_SIZE)
> ospf6_packet_max(oi)) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO,
SEND))
zlog_debug(
"sending Hello message: exceeds I/F MTU");
break;
}
stream_put_ipv4(s, on->router_id);
length += sizeof(uint32_t);
}
return length;
}
static void ospf6_write(struct event *thread)
{
struct ospf6 *ospf6 = THREAD_ARG(thread);
struct ospf6_interface *oi;
struct ospf6_header *oh;
struct ospf6_packet *op;
struct listnode *node;
struct iovec iovector[2];
int pkt_count = 0;
int len;
int64_t latency = 0;
struct timeval timestamp;
uint16_t at_len = 0;
if (ospf6->fd < 0) {
zlog_warn("ospf6_write failed to send, fd %d", ospf6->fd);
return;
}
node = listhead(ospf6->oi_write_q);
assert(node);
oi = listgetdata(node);
while ((pkt_count < ospf6->write_oi_count) && oi) {
op = ospf6_fifo_head(oi->obuf);
assert(op);
assert(op->length >= OSPF6_HEADER_SIZE);
iovector[0].iov_base = (caddr_t)stream_pnt(op->s);
iovector[0].iov_len = op->length;
iovector[1].iov_base = NULL;
iovector[1].iov_len = 0;
oh = (struct ospf6_header *)STREAM_DATA(op->s);
if (oi->at_data.flags != 0) {
at_len = ospf6_auth_len_get(oi);
if (at_len) {
iovector[0].iov_len =
ntohs(oh->length) + at_len;
ospf6_auth_digest_send(oi->linklocal_addr, oi,
oh, at_len,
iovector[0].iov_len);
} else {
iovector[0].iov_len = ntohs(oh->length);
}
} else {
iovector[0].iov_len = ntohs(oh->length);
}
len = ospf6_sendmsg(oi->linklocal_addr, &op->dst,
oi->interface->ifindex, iovector,
ospf6->fd);
if (len != (op->length + (int)at_len))
flog_err(EC_LIB_DEVELOPMENT,
"Could not send entire message");
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND_HDR)) {
zlog_debug("%s send on %s",
ospf6_message_type(oh->type),
oi->interface->name);
zlog_debug(" src: %pI6", oi->linklocal_addr);
zlog_debug(" dst: %pI6", &op->dst);
switch (oh->type) {
case OSPF6_MESSAGE_TYPE_HELLO:
ospf6_hello_print(oh, OSPF6_ACTION_SEND);
break;
case OSPF6_MESSAGE_TYPE_DBDESC:
ospf6_dbdesc_print(oh, OSPF6_ACTION_SEND);
break;
case OSPF6_MESSAGE_TYPE_LSREQ:
ospf6_lsreq_print(oh, OSPF6_ACTION_SEND);
break;
case OSPF6_MESSAGE_TYPE_LSUPDATE:
ospf6_lsupdate_print(oh, OSPF6_ACTION_SEND);
break;
case OSPF6_MESSAGE_TYPE_LSACK:
ospf6_lsack_print(oh, OSPF6_ACTION_SEND);
break;
default:
zlog_debug("Unknown message");
assert(0);
break;
}
}
switch (oh->type) {
case OSPF6_MESSAGE_TYPE_HELLO:
monotime(×tamp);
if (oi->hello_out)
latency = monotime_since(&oi->last_hello, NULL)
- ((int64_t)oi->hello_interval
* 1000000);
/* log if latency exceeds the hello period */
if (latency > ((int64_t)oi->hello_interval * 1000000))
zlog_warn("%s hello TX high latency %" PRId64
"us.",
__func__, latency);
oi->last_hello = timestamp;
oi->hello_out++;
break;
case OSPF6_MESSAGE_TYPE_DBDESC:
oi->db_desc_out++;
break;
case OSPF6_MESSAGE_TYPE_LSREQ:
oi->ls_req_out++;
break;
case OSPF6_MESSAGE_TYPE_LSUPDATE:
oi->ls_upd_out++;
break;
case OSPF6_MESSAGE_TYPE_LSACK:
oi->ls_ack_out++;
break;
default:
zlog_debug("Unknown message");
assert(0);
break;
}
if ((oi->at_data.flags != 0) &&
(IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND_HDR)) &&
(IS_OSPF6_DEBUG_AUTH_TX))
ospf6_auth_hdr_dump_send(oh, iovector[0].iov_len);
/* initialize at_len to 0 for next packet */
at_len = 0;
/* Now delete packet from queue. */
ospf6_packet_delete(oi);
/* Move this interface to the tail of write_q to
serve everyone in a round robin fashion */
list_delete_node(ospf6->oi_write_q, node);
if (ospf6_fifo_head(oi->obuf) == NULL) {
oi->on_write_q = 0;
oi = NULL;
} else {
listnode_add(ospf6->oi_write_q, oi);
}
/* Setup to service from the head of the queue again */
if (!list_isempty(ospf6->oi_write_q)) {
node = listhead(ospf6->oi_write_q);
oi = listgetdata(node);
}
}
/* If packets still remain in queue, call write thread. */
if (!list_isempty(ospf6->oi_write_q))
thread_add_write(master, ospf6_write, ospf6, ospf6->fd,
&ospf6->t_write);
}
void ospf6_hello_send(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
oi = (struct ospf6_interface *)THREAD_ARG(thread);
if (oi->state <= OSPF6_INTERFACE_DOWN) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND_HDR))
zlog_debug("Unable to send Hello on down interface %s",
oi->interface->name);
return;
}
op = ospf6_packet_new(oi->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_HELLO, oi, op->s);
/* Prepare OSPF Hello body */
length += ospf6_make_hello(oi, op->s);
if (length == OSPF6_HEADER_SIZE) {
/* Hello overshooting MTU */
ospf6_packet_free(op);
return;
}
/* Fill OSPF header. */
ospf6_fill_header(oi, op->s, length);
/* Set packet length. */
op->length = length;
op->dst = allspfrouters6;
ospf6_fill_hdr_checksum(oi, op);
/* Add packet to the top of the interface output queue, so that they
* can't get delayed by things like long queues of LS Update packets
*/
ospf6_packet_add_top(oi, op);
/* set next thread */
thread_add_timer(master, ospf6_hello_send, oi, oi->hello_interval,
&oi->thread_send_hello);
OSPF6_MESSAGE_WRITE_ON(oi);
}
static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s)
{
uint16_t length = OSPF6_DB_DESC_MIN_SIZE;
struct ospf6_lsa *lsa, *lsanext;
uint8_t options1 = on->ospf6_if->area->options[1];
if (on->ospf6_if->at_data.flags != 0)
options1 |= OSPF6_OPT_AT;
/* if this is initial one, initialize sequence number for DbDesc */
if (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)
&& (on->dbdesc_seqnum == 0)) {
on->dbdesc_seqnum = frr_sequence32_next();
}
/* reserved */
stream_putc(s, 0); /* reserved 1 */
stream_putc(s, on->ospf6_if->area->options[0]);
stream_putc(s, options1);
stream_putc(s, on->ospf6_if->area->options[2]);
stream_putw(s, on->ospf6_if->ifmtu);
stream_putc(s, 0); /* reserved 2 */
stream_putc(s, on->dbdesc_bits);
stream_putl(s, on->dbdesc_seqnum);
/* if this is not initial one, set LSA headers in dbdesc */
if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)) {
for (ALL_LSDB(on->dbdesc_list, lsa, lsanext)) {
ospf6_lsa_age_update_to_send(lsa,
on->ospf6_if->transdelay);
/* MTU check */
if ((length + sizeof(struct ospf6_lsa_header)
+ OSPF6_HEADER_SIZE)
> ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa);
if (lsanext)
ospf6_lsa_unlock(lsanext);
break;
}
stream_put(s, lsa->header,
sizeof(struct ospf6_lsa_header));
length += sizeof(struct ospf6_lsa_header);
}
}
return length;
}
void ospf6_dbdesc_send(struct event *thread)
{
struct ospf6_neighbor *on;
uint16_t length = OSPF6_HEADER_SIZE;
struct ospf6_packet *op;
on = (struct ospf6_neighbor *)THREAD_ARG(thread);
if (on->state < OSPF6_NEIGHBOR_EXSTART) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_DBDESC, SEND))
zlog_debug(
"Quit to send DbDesc to neighbor %s state %s",
on->name, ospf6_neighbor_state_str[on->state]);
return;
}
/* set next thread if master */
if (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
thread_add_timer(master, ospf6_dbdesc_send, on,
on->ospf6_if->rxmt_interval,
&on->thread_send_dbdesc);
op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_DBDESC, on->ospf6_if, op->s);
length += ospf6_make_dbdesc(on, op->s);
ospf6_fill_header(on->ospf6_if, op->s, length);
/* Set packet length. */
op->length = length;
if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
op->dst = allspfrouters6;
else
op->dst = on->linklocal_addr;
ospf6_fill_hdr_checksum(on->ospf6_if, op);
ospf6_packet_add(on->ospf6_if, op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
}
void ospf6_dbdesc_send_newone(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_lsa *lsa, *lsanext;
unsigned int size = 0;
on = (struct ospf6_neighbor *)THREAD_ARG(thread);
ospf6_lsdb_remove_all(on->dbdesc_list);
/* move LSAs from summary_list to dbdesc_list (within neighbor
structure)
so that ospf6_send_dbdesc () can send those LSAs */
size = sizeof(struct ospf6_lsa_header) + sizeof(struct ospf6_dbdesc);
for (ALL_LSDB(on->summary_list, lsa, lsanext)) {
/* if stub area then don't advertise AS-External LSAs */
if ((IS_AREA_STUB(on->ospf6_if->area)
|| IS_AREA_NSSA(on->ospf6_if->area))
&& ntohs(lsa->header->type) == OSPF6_LSTYPE_AS_EXTERNAL) {
ospf6_lsdb_remove(lsa, on->summary_list);
continue;
}
if (size + sizeof(struct ospf6_lsa_header)
> ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa);
if (lsanext)
ospf6_lsa_unlock(lsanext);
break;
}
ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->dbdesc_list);
ospf6_lsdb_remove(lsa, on->summary_list);
size += sizeof(struct ospf6_lsa_header);
}
if (on->summary_list->count == 0)
UNSET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
/* If slave, More bit check must be done here */
if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */
!CHECK_FLAG(on->dbdesc_last.bits, OSPF6_DBDESC_MBIT)
&& !CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT))
thread_add_event(master, exchange_done, on, 0,
&on->thread_exchange_done);
thread_execute(master, ospf6_dbdesc_send, on, 0);
}
static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s)
{
uint16_t length = 0;
struct ospf6_lsa *lsa, *lsanext, *last_req = NULL;
for (ALL_LSDB(on->request_list, lsa, lsanext)) {
if ((length + OSPF6_HEADER_SIZE)
> ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa);
if (lsanext)
ospf6_lsa_unlock(lsanext);
break;
}
stream_putw(s, 0); /* reserved */
stream_putw(s, ntohs(lsa->header->type));
stream_putl(s, ntohl(lsa->header->id));
stream_putl(s, ntohl(lsa->header->adv_router));
length += sizeof(struct ospf6_lsreq_entry);
last_req = lsa;
}
if (last_req != NULL) {
if (on->last_ls_req != NULL)
on->last_ls_req = ospf6_lsa_unlock(on->last_ls_req);
ospf6_lsa_lock(last_req);
on->last_ls_req = last_req;
}
return length;
}
static uint16_t ospf6_make_lsack_neighbor(struct ospf6_neighbor *on,
struct ospf6_packet **op)
{
uint16_t length = 0;
struct ospf6_lsa *lsa, *lsanext;
int lsa_cnt = 0;
for (ALL_LSDB(on->lsack_list, lsa, lsanext)) {
if ((length + sizeof(struct ospf6_lsa_header)
+ OSPF6_HEADER_SIZE)
> ospf6_packet_max(on->ospf6_if)) {
/* if we run out of packet size/space here,
better to try again soon. */
if (lsa_cnt) {
ospf6_fill_header(on->ospf6_if, (*op)->s,
length + OSPF6_HEADER_SIZE);
(*op)->length = length + OSPF6_HEADER_SIZE;
(*op)->dst = on->linklocal_addr;
ospf6_fill_hdr_checksum(on->ospf6_if, *op);
ospf6_packet_add(on->ospf6_if, *op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
/* new packet */
*op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSACK,
on->ospf6_if, (*op)->s);
length = 0;
lsa_cnt = 0;
}
}
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
stream_put((*op)->s, lsa->header,
sizeof(struct ospf6_lsa_header));
length += sizeof(struct ospf6_lsa_header);
assert(lsa->lock == 2);
ospf6_lsdb_remove(lsa, on->lsack_list);
lsa_cnt++;
}
return length;
}
void ospf6_lsreq_send(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
on = (struct ospf6_neighbor *)THREAD_ARG(thread);
/* LSReq will be sent only in ExStart or Loading */
if (on->state != OSPF6_NEIGHBOR_EXCHANGE
&& on->state != OSPF6_NEIGHBOR_LOADING) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSREQ, SEND_HDR))
zlog_debug("Quit to send LSReq to neighbor %s state %s",
on->name,
ospf6_neighbor_state_str[on->state]);
return;
}
/* schedule loading_done if request list is empty */
if (on->request_list->count == 0) {
thread_add_event(master, loading_done, on, 0, NULL);
return;
}
op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSREQ, on->ospf6_if, op->s);
length += ospf6_make_lsreq(on, op->s);
if (length == OSPF6_HEADER_SIZE) {
/* Hello overshooting MTU */
ospf6_packet_free(op);
return;
}
/* Fill OSPF header. */
ospf6_fill_header(on->ospf6_if, op->s, length);
/* Set packet length */
op->length = length;
if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
op->dst = allspfrouters6;
else
op->dst = on->linklocal_addr;
ospf6_fill_hdr_checksum(on->ospf6_if, op);
ospf6_packet_add(on->ospf6_if, op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
/* set next thread */
if (on->request_list->count != 0) {
thread_add_timer(master, ospf6_lsreq_send, on,
on->ospf6_if->rxmt_interval,
&on->thread_send_lsreq);
}
}
static void ospf6_send_lsupdate(struct ospf6_neighbor *on,
struct ospf6_interface *oi,
struct ospf6_packet *op)
{
if (on) {
if ((on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
|| (on->ospf6_if->state == OSPF6_INTERFACE_DR)
|| (on->ospf6_if->state == OSPF6_INTERFACE_BDR))
op->dst = allspfrouters6;
else
op->dst = on->linklocal_addr;
oi = on->ospf6_if;
} else if (oi) {
if ((oi->state == OSPF6_INTERFACE_POINTTOPOINT)
|| (oi->state == OSPF6_INTERFACE_DR)
|| (oi->state == OSPF6_INTERFACE_BDR))
op->dst = allspfrouters6;
else
op->dst = alldrouters6;
}
if (oi) {
ospf6_fill_hdr_checksum(oi, op);
ospf6_packet_add(oi, op);
/* If ospf instance is being deleted, send the packet
* immediately
*/
if ((oi->area == NULL) || (oi->area->ospf6 == NULL))
return;
if (oi->area->ospf6->inst_shutdown) {
if (oi->on_write_q == 0) {
listnode_add(oi->area->ospf6->oi_write_q, oi);
oi->on_write_q = 1;
}
thread_execute(master, ospf6_write, oi->area->ospf6, 0);
} else
OSPF6_MESSAGE_WRITE_ON(oi);
}
}
static uint16_t ospf6_make_lsupdate_list(struct ospf6_neighbor *on,
struct ospf6_packet **op, int *lsa_cnt)
{
uint16_t length = OSPF6_LS_UPD_MIN_SIZE;
struct ospf6_lsa *lsa, *lsanext;
/* skip over fixed header */
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
for (ALL_LSDB(on->lsupdate_list, lsa, lsanext)) {
if ((length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE) >
ospf6_packet_max(on->ospf6_if)) {
ospf6_fill_header(on->ospf6_if, (*op)->s,
length + OSPF6_HEADER_SIZE);
(*op)->length = length + OSPF6_HEADER_SIZE;
ospf6_fill_lsupdate_header((*op)->s, *lsa_cnt);
ospf6_send_lsupdate(on, NULL, *op);
/* refresh packet */
*op = ospf6_packet_new(on->ospf6_if->ifmtu);
length = OSPF6_LS_UPD_MIN_SIZE;
*lsa_cnt = 0;
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE,
on->ospf6_if, (*op)->s);
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
}
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
(*lsa_cnt)++;
length += OSPF6_LSA_SIZE(lsa->header);
assert(lsa->lock == 2);
ospf6_lsdb_remove(lsa, on->lsupdate_list);
}
return length;
}
static uint16_t ospf6_make_ls_retrans_list(struct ospf6_neighbor *on,
struct ospf6_packet **op,
int *lsa_cnt)
{
uint16_t length = OSPF6_LS_UPD_MIN_SIZE;
struct ospf6_lsa *lsa, *lsanext;
/* skip over fixed header */
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
if ((length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE) >
ospf6_packet_max(on->ospf6_if)) {
ospf6_fill_header(on->ospf6_if, (*op)->s,
length + OSPF6_HEADER_SIZE);
(*op)->length = length + OSPF6_HEADER_SIZE;
ospf6_fill_lsupdate_header((*op)->s, *lsa_cnt);
if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
(*op)->dst = allspfrouters6;
else
(*op)->dst = on->linklocal_addr;
ospf6_fill_hdr_checksum(on->ospf6_if, *op);
ospf6_packet_add(on->ospf6_if, *op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
/* refresh packet */
*op = ospf6_packet_new(on->ospf6_if->ifmtu);
length = OSPF6_LS_UPD_MIN_SIZE;
*lsa_cnt = 0;
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE,
on->ospf6_if, (*op)->s);
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
}
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
(*lsa_cnt)++;
length += OSPF6_LSA_SIZE(lsa->header);
}
return length;
}
void ospf6_lsupdate_send_neighbor(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
int lsa_cnt = 0;
on = (struct ospf6_neighbor *)THREAD_ARG(thread);
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, SEND_HDR))
zlog_debug("LSUpdate to neighbor %s", on->name);
if (on->state < OSPF6_NEIGHBOR_EXCHANGE) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE,
SEND_HDR))
zlog_debug("Quit to send (neighbor state %s)",
ospf6_neighbor_state_str[on->state]);
return;
}
/* first do lsupdate_list */
op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE, on->ospf6_if, op->s);
length += ospf6_make_lsupdate_list(on, &op, &lsa_cnt);
if (lsa_cnt) {
/* Fill OSPF header. */
ospf6_fill_header(on->ospf6_if, op->s, length);
ospf6_fill_lsupdate_header(op->s, lsa_cnt);
op->length = length;
ospf6_send_lsupdate(on, NULL, op);
/* prepare new packet */
op = ospf6_packet_new(on->ospf6_if->ifmtu);
length = OSPF6_HEADER_SIZE;
lsa_cnt = 0;
} else {
stream_reset(op->s);
length = OSPF6_HEADER_SIZE;
}
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE, on->ospf6_if, op->s);
/* now do retransmit list */
length += ospf6_make_ls_retrans_list(on, &op, &lsa_cnt);
if (lsa_cnt) {
ospf6_fill_header(on->ospf6_if, op->s, length);
ospf6_fill_lsupdate_header(op->s, lsa_cnt);
op->length = length;
if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
op->dst = allspfrouters6;
else
op->dst = on->linklocal_addr;
ospf6_fill_hdr_checksum(on->ospf6_if, op);
ospf6_packet_add(on->ospf6_if, op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
} else
ospf6_packet_free(op);
if (on->lsupdate_list->count != 0) {
thread_add_event(master, ospf6_lsupdate_send_neighbor, on, 0,
&on->thread_send_lsupdate);
} else if (on->retrans_list->count != 0) {
thread_add_timer(master, ospf6_lsupdate_send_neighbor, on,
on->ospf6_if->rxmt_interval,
&on->thread_send_lsupdate);
}
}
int ospf6_lsupdate_send_neighbor_now(struct ospf6_neighbor *on,
struct ospf6_lsa *lsa)
{
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE, on->ospf6_if, op->s);
/* skip over fixed header */
stream_forward_endp(op->s, OSPF6_LS_UPD_MIN_SIZE);
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
stream_put(op->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
length = OSPF6_HEADER_SIZE + OSPF6_LS_UPD_MIN_SIZE
+ OSPF6_LSA_SIZE(lsa->header);
ospf6_fill_header(on->ospf6_if, op->s, length);
ospf6_fill_lsupdate_header(op->s, 1);
op->length = length;
if (IS_OSPF6_DEBUG_FLOODING
|| IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, SEND_HDR))
zlog_debug("%s: Send lsupdate with lsa %s (age %u)", __func__,
lsa->name, ntohs(lsa->header->age));
ospf6_send_lsupdate(on, NULL, op);
return 0;
}
static uint16_t ospf6_make_lsupdate_interface(struct ospf6_interface *oi,
struct ospf6_packet **op,
int *lsa_cnt)
{
uint16_t length = OSPF6_LS_UPD_MIN_SIZE;
struct ospf6_lsa *lsa, *lsanext;
/* skip over fixed header */
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext)) {
if (length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE >
ospf6_packet_max(oi)) {
ospf6_fill_header(oi, (*op)->s,
length + OSPF6_HEADER_SIZE);
(*op)->length = length + OSPF6_HEADER_SIZE;
ospf6_fill_lsupdate_header((*op)->s, *lsa_cnt);
ospf6_send_lsupdate(NULL, oi, *op);
/* refresh packet */
*op = ospf6_packet_new(oi->ifmtu);
length = OSPF6_LS_UPD_MIN_SIZE;
*lsa_cnt = 0;
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE, oi,
(*op)->s);
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
}
ospf6_lsa_age_update_to_send(lsa, oi->transdelay);
stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
(*lsa_cnt)++;
length += OSPF6_LSA_SIZE(lsa->header);
assert(lsa->lock == 2);
ospf6_lsdb_remove(lsa, oi->lsupdate_list);
}
return length;
}
void ospf6_lsupdate_send_interface(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
int lsa_cnt = 0;
oi = (struct ospf6_interface *)THREAD_ARG(thread);
if (oi->state <= OSPF6_INTERFACE_WAITING) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE,
SEND_HDR))
zlog_debug(
"Quit to send LSUpdate to interface %s state %s",
oi->interface->name,
ospf6_interface_state_str[oi->state]);
return;
}
/* if we have nothing to send, return */
if (oi->lsupdate_list->count == 0)
return;
op = ospf6_packet_new(oi->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE, oi, op->s);
length += ospf6_make_lsupdate_interface(oi, &op, &lsa_cnt);
if (lsa_cnt) {
/* Fill OSPF header. */
ospf6_fill_header(oi, op->s, length);
ospf6_fill_lsupdate_header(op->s, lsa_cnt);
op->length = length;
ospf6_send_lsupdate(NULL, oi, op);
} else
ospf6_packet_free(op);
if (oi->lsupdate_list->count > 0) {
thread_add_event(master, ospf6_lsupdate_send_interface, oi, 0,
&oi->thread_send_lsupdate);
}
}
void ospf6_lsack_send_neighbor(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
on = (struct ospf6_neighbor *)THREAD_ARG(thread);
if (on->state < OSPF6_NEIGHBOR_EXCHANGE) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSACK, SEND_HDR))
zlog_debug("Quit to send LSAck to neighbor %s state %s",
on->name,
ospf6_neighbor_state_str[on->state]);
return;
}
/* if we have nothing to send, return */
if (on->lsack_list->count == 0)
return;
op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSACK, on->ospf6_if, op->s);
length += ospf6_make_lsack_neighbor(on, &op);
if (length == OSPF6_HEADER_SIZE) {
ospf6_packet_free(op);
return;
}
/* Fill OSPF header. */
ospf6_fill_header(on->ospf6_if, op->s, length);
/* Set packet length, dst and queue to FIFO. */
op->length = length;
op->dst = on->linklocal_addr;
ospf6_fill_hdr_checksum(on->ospf6_if, op);
ospf6_packet_add(on->ospf6_if, op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
if (on->lsack_list->count > 0)
thread_add_event(master, ospf6_lsack_send_neighbor, on, 0,
&on->thread_send_lsack);
}
static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi,
struct ospf6_packet *op)
{
uint16_t length = 0;
struct ospf6_lsa *lsa, *lsanext;
for (ALL_LSDB(oi->lsack_list, lsa, lsanext)) {
if ((length + sizeof(struct ospf6_lsa_header)
+ OSPF6_HEADER_SIZE)
> ospf6_packet_max(oi)) {
/* if we run out of packet size/space here,
better to try again soon. */
THREAD_OFF(oi->thread_send_lsack);
thread_add_event(master, ospf6_lsack_send_interface, oi,
0, &oi->thread_send_lsack);
ospf6_lsa_unlock(lsa);
if (lsanext)
ospf6_lsa_unlock(lsanext);
break;
}
ospf6_lsa_age_update_to_send(lsa, oi->transdelay);
stream_put(op->s, lsa->header, sizeof(struct ospf6_lsa_header));
length += sizeof(struct ospf6_lsa_header);
assert(lsa->lock == 2);
ospf6_lsdb_remove(lsa, oi->lsack_list);
}
return length;
}
void ospf6_lsack_send_interface(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
oi = (struct ospf6_interface *)THREAD_ARG(thread);
if (oi->state <= OSPF6_INTERFACE_WAITING) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSACK, SEND_HDR))
zlog_debug(
"Quit to send LSAck to interface %s state %s",
oi->interface->name,
ospf6_interface_state_str[oi->state]);
return;
}
/* if we have nothing to send, return */
if (oi->lsack_list->count == 0)
return;
op = ospf6_packet_new(oi->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_LSACK, oi, op->s);
length += ospf6_make_lsack_interface(oi, op);
if (length == OSPF6_HEADER_SIZE) {
ospf6_packet_free(op);
return;
}
/* Fill OSPF header. */
ospf6_fill_header(oi, op->s, length);
/* Set packet length, dst and queue to FIFO. */
op->length = length;
if ((oi->state == OSPF6_INTERFACE_POINTTOPOINT)
|| (oi->state == OSPF6_INTERFACE_DR)
|| (oi->state == OSPF6_INTERFACE_BDR))
op->dst = allspfrouters6;
else
op->dst = alldrouters6;
ospf6_fill_hdr_checksum(oi, op);
ospf6_packet_add(oi, op);
OSPF6_MESSAGE_WRITE_ON(oi);
if (oi->lsack_list->count > 0)
thread_add_event(master, ospf6_lsack_send_interface, oi, 0,
&oi->thread_send_lsack);
}
/* Commands */
DEFUN(debug_ospf6_message, debug_ospf6_message_cmd,
"debug ospf6 message <unknown|hello|dbdesc|lsreq|lsupdate|lsack|all> [<send|recv|send-hdr|recv-hdr>]",
DEBUG_STR OSPF6_STR
"Debug OSPFv3 message\n"
"Debug Unknown message\n"
"Debug Hello message\n"
"Debug Database Description message\n"
"Debug Link State Request message\n"
"Debug Link State Update message\n"
"Debug Link State Acknowledgement message\n"
"Debug All message\n"
"Debug only sending message, entire packet\n"
"Debug only receiving message, entire packet\n"
"Debug only sending message, header only\n"
"Debug only receiving message, header only\n")
{
int idx_packet = 3;
int idx_send_recv = 4;
unsigned char level = 0;
int type = 0;
int i;
/* check type */
if (!strncmp(argv[idx_packet]->arg, "u", 1))
type = OSPF6_MESSAGE_TYPE_UNKNOWN;
else if (!strncmp(argv[idx_packet]->arg, "h", 1))
type = OSPF6_MESSAGE_TYPE_HELLO;
else if (!strncmp(argv[idx_packet]->arg, "d", 1))
type = OSPF6_MESSAGE_TYPE_DBDESC;
else if (!strncmp(argv[idx_packet]->arg, "lsr", 3))
type = OSPF6_MESSAGE_TYPE_LSREQ;
else if (!strncmp(argv[idx_packet]->arg, "lsu", 3))
type = OSPF6_MESSAGE_TYPE_LSUPDATE;
else if (!strncmp(argv[idx_packet]->arg, "lsa", 3))
type = OSPF6_MESSAGE_TYPE_LSACK;
else if (!strncmp(argv[idx_packet]->arg, "a", 1))
type = OSPF6_MESSAGE_TYPE_ALL;
if (argc == 4)
level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
else if (!strncmp(argv[idx_send_recv]->arg, "send-h", 6))
level = OSPF6_DEBUG_MESSAGE_SEND_HDR;
else if (!strncmp(argv[idx_send_recv]->arg, "s", 1))
level = OSPF6_DEBUG_MESSAGE_SEND;
else if (!strncmp(argv[idx_send_recv]->arg, "recv-h", 6))
level = OSPF6_DEBUG_MESSAGE_RECV_HDR;
else if (!strncmp(argv[idx_send_recv]->arg, "r", 1))
level = OSPF6_DEBUG_MESSAGE_RECV;
if (type == OSPF6_MESSAGE_TYPE_ALL) {
for (i = 0; i < 6; i++)
OSPF6_DEBUG_MESSAGE_ON(i, level);
} else
OSPF6_DEBUG_MESSAGE_ON(type, level);
return CMD_SUCCESS;
}
DEFUN(no_debug_ospf6_message, no_debug_ospf6_message_cmd,
"no debug ospf6 message <unknown|hello|dbdesc|lsreq|lsupdate|lsack|all> [<send|recv|send-hdr|recv-hdr>]",
NO_STR DEBUG_STR OSPF6_STR
"Debug OSPFv3 message\n"
"Debug Unknown message\n"
"Debug Hello message\n"
"Debug Database Description message\n"
"Debug Link State Request message\n"
"Debug Link State Update message\n"
"Debug Link State Acknowledgement message\n"
"Debug All message\n"
"Debug only sending message, entire pkt\n"
"Debug only receiving message, entire pkt\n"
"Debug only sending message, header only\n"
"Debug only receiving message, header only\n")
{
int idx_packet = 4;
int idx_send_recv = 5;
unsigned char level = 0;
int type = 0;
int i;
/* check type */
if (!strncmp(argv[idx_packet]->arg, "u", 1))
type = OSPF6_MESSAGE_TYPE_UNKNOWN;
else if (!strncmp(argv[idx_packet]->arg, "h", 1))
type = OSPF6_MESSAGE_TYPE_HELLO;
else if (!strncmp(argv[idx_packet]->arg, "d", 1))
type = OSPF6_MESSAGE_TYPE_DBDESC;
else if (!strncmp(argv[idx_packet]->arg, "lsr", 3))
type = OSPF6_MESSAGE_TYPE_LSREQ;
else if (!strncmp(argv[idx_packet]->arg, "lsu", 3))
type = OSPF6_MESSAGE_TYPE_LSUPDATE;
else if (!strncmp(argv[idx_packet]->arg, "lsa", 3))
type = OSPF6_MESSAGE_TYPE_LSACK;
else if (!strncmp(argv[idx_packet]->arg, "a", 1))
type = OSPF6_MESSAGE_TYPE_ALL;
if (argc == 5)
level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV
| OSPF6_DEBUG_MESSAGE_SEND_HDR
| OSPF6_DEBUG_MESSAGE_RECV_HDR;
else if (!strncmp(argv[idx_send_recv]->arg, "send-h", 6))
level = OSPF6_DEBUG_MESSAGE_SEND_HDR;
else if (!strncmp(argv[idx_send_recv]->arg, "s", 1))
level = OSPF6_DEBUG_MESSAGE_SEND;
else if (!strncmp(argv[idx_send_recv]->arg, "recv-h", 6))
level = OSPF6_DEBUG_MESSAGE_RECV_HDR;
else if (!strncmp(argv[idx_send_recv]->arg, "r", 1))
level = OSPF6_DEBUG_MESSAGE_RECV;
if (type == OSPF6_MESSAGE_TYPE_ALL) {
for (i = 0; i < 6; i++)
OSPF6_DEBUG_MESSAGE_OFF(i, level);
} else
OSPF6_DEBUG_MESSAGE_OFF(type, level);
return CMD_SUCCESS;
}
int config_write_ospf6_debug_message(struct vty *vty)
{
const char *type_str[] = {"unknown", "hello", "dbdesc",
"lsreq", "lsupdate", "lsack"};
unsigned char s = 0, r = 0, sh = 0, rh = 0;
int i;
for (i = 0; i < 6; i++) {
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, SEND))
s |= 1 << i;
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, RECV))
r |= 1 << i;
}
for (i = 0; i < 6; i++) {
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, SEND_HDR))
sh |= 1 << i;
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, RECV_HDR))
rh |= 1 << i;
}
if (s == 0x3f && r == 0x3f) {
vty_out(vty, "debug ospf6 message all\n");
return 0;
}
if (s == 0x3f && r == 0) {
vty_out(vty, "debug ospf6 message all send\n");
return 0;
} else if (s == 0 && r == 0x3f) {
vty_out(vty, "debug ospf6 message all recv\n");
return 0;
}
if (sh == 0x3f && rh == 0) {
vty_out(vty, "debug ospf6 message all send-hdr\n");
return 0;
} else if (sh == 0 && rh == 0x3f) {
vty_out(vty, "debug ospf6 message all recv-hdr\n");
return 0;
}
/* Unknown message is logged by default */
if (!IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN, SEND)
&& !IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
vty_out(vty, "no debug ospf6 message unknown\n");
else if (!IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN, SEND))
vty_out(vty, "no debug ospf6 message unknown send\n");
else if (!IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
vty_out(vty, "no debug ospf6 message unknown recv\n");
for (i = 1; i < 6; i++) {
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, SEND)
&& IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, RECV)) {
vty_out(vty, "debug ospf6 message %s\n", type_str[i]);
continue;
}
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, SEND))
vty_out(vty, "debug ospf6 message %s send\n",
type_str[i]);
else if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, SEND_HDR))
vty_out(vty, "debug ospf6 message %s send-hdr\n",
type_str[i]);
if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, RECV))
vty_out(vty, "debug ospf6 message %s recv\n",
type_str[i]);
else if (IS_OSPF6_DEBUG_MESSAGE_ENABLED(i, RECV_HDR))
vty_out(vty, "debug ospf6 message %s recv-hdr\n",
type_str[i]);
}
return 0;
}
void install_element_ospf6_debug_message(void)
{
install_element(ENABLE_NODE, &debug_ospf6_message_cmd);
install_element(ENABLE_NODE, &no_debug_ospf6_message_cmd);
install_element(CONFIG_NODE, &debug_ospf6_message_cmd);
install_element(CONFIG_NODE, &no_debug_ospf6_message_cmd);
}
|