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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* This is an implementation of rfc2370.
* Copyright (C) 2001 KDD R&D Laboratories, Inc.
* http://www.kddlabs.co.jp/
*/
#include <zebra.h>
#include "linklist.h"
#include "prefix.h"
#include "if.h"
#include "table.h"
#include "memory.h"
#include "command.h"
#include "vty.h"
#include "stream.h"
#include "log.h"
#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "printfrr.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_asbr.h"
#include "ospfd/ospf_lsa.h"
#include "ospfd/ospf_lsdb.h"
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_nsm.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_packet.h"
#include "ospfd/ospf_spf.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_route.h"
#include "ospfd/ospf_ase.h"
#include "ospfd/ospf_zebra.h"
#include "ospfd/ospf_te.h"
#include "ospfd/ospf_sr.h"
#include "ospfd/ospf_ri.h"
#include "ospfd/ospf_ext.h"
#include "ospfd/ospf_errors.h"
DEFINE_MTYPE_STATIC(OSPFD, OSPF_OPAQUE_FUNCTAB, "OSPF opaque function table");
DEFINE_MTYPE_STATIC(OSPFD, OPAQUE_INFO_PER_TYPE, "OSPF opaque per-type info");
DEFINE_MTYPE_STATIC(OSPFD, OPAQUE_INFO_PER_ID, "OSPF opaque per-ID info");
/*------------------------------------------------------------------------*
* Following are initialize/terminate functions for Opaque-LSAs handling.
*------------------------------------------------------------------------*/
#ifdef SUPPORT_OSPF_API
int ospf_apiserver_init(void);
void ospf_apiserver_term(void);
/* Init apiserver? It's disabled by default. */
int ospf_apiserver_enable;
#endif /* SUPPORT_OSPF_API */
static void ospf_opaque_register_vty(void);
static void ospf_opaque_funclist_init(void);
static void ospf_opaque_funclist_term(void);
static void free_opaque_info_per_type_del(void *val);
static void free_opaque_info_per_id(void *val);
static int ospf_opaque_lsa_install_hook(struct ospf_lsa *lsa);
static int ospf_opaque_lsa_delete_hook(struct ospf_lsa *lsa);
void ospf_opaque_init(void)
{
ospf_opaque_register_vty();
ospf_opaque_funclist_init();
if (ospf_mpls_te_init() != 0)
exit(1);
/* Segment Routing init */
if (ospf_sr_init() != 0)
exit(1);
if (ospf_router_info_init() != 0)
exit(1);
if (ospf_ext_init() != 0)
exit(1);
#ifdef SUPPORT_OSPF_API
if ((ospf_apiserver_enable) && (ospf_apiserver_init() != 0))
exit(1);
#endif /* SUPPORT_OSPF_API */
return;
}
void ospf_opaque_term(void)
{
ospf_mpls_te_term();
ospf_router_info_term();
ospf_ext_term();
ospf_sr_term();
#ifdef SUPPORT_OSPF_API
ospf_apiserver_term();
#endif /* SUPPORT_OSPF_API */
ospf_opaque_funclist_term();
return;
}
void ospf_opaque_finish(void)
{
ospf_mpls_te_finish();
ospf_router_info_finish();
ospf_ext_finish();
#ifdef SUPPORT_OSPF_API
ospf_apiserver_term();
#endif
ospf_sr_finish();
}
int ospf_opaque_type9_lsa_init(struct ospf_interface *oi)
{
if (oi->opaque_lsa_self != NULL)
list_delete(&oi->opaque_lsa_self);
oi->opaque_lsa_self = list_new();
oi->opaque_lsa_self->del = free_opaque_info_per_type_del;
oi->t_opaque_lsa_self = NULL;
return 0;
}
void ospf_opaque_type9_lsa_term(struct ospf_interface *oi)
{
EVENT_OFF(oi->t_opaque_lsa_self);
if (oi->opaque_lsa_self != NULL)
list_delete(&oi->opaque_lsa_self);
oi->opaque_lsa_self = NULL;
return;
}
int ospf_opaque_type10_lsa_init(struct ospf_area *area)
{
if (area->opaque_lsa_self != NULL)
list_delete(&area->opaque_lsa_self);
area->opaque_lsa_self = list_new();
area->opaque_lsa_self->del = free_opaque_info_per_type_del;
area->t_opaque_lsa_self = NULL;
#ifdef MONITOR_LSDB_CHANGE
area->lsdb->new_lsa_hook = ospf_opaque_lsa_install_hook;
area->lsdb->del_lsa_hook = ospf_opaque_lsa_delete_hook;
#endif /* MONITOR_LSDB_CHANGE */
return 0;
}
void ospf_opaque_type10_lsa_term(struct ospf_area *area)
{
#ifdef MONITOR_LSDB_CHANGE
area->lsdb->new_lsa_hook = area->lsdb->del_lsa_hook = NULL;
#endif /* MONITOR_LSDB_CHANGE */
EVENT_OFF(area->t_opaque_lsa_self);
if (area->opaque_lsa_self != NULL)
list_delete(&area->opaque_lsa_self);
return;
}
int ospf_opaque_type11_lsa_init(struct ospf *top)
{
if (top->opaque_lsa_self != NULL)
list_delete(&top->opaque_lsa_self);
top->opaque_lsa_self = list_new();
top->opaque_lsa_self->del = free_opaque_info_per_type_del;
top->t_opaque_lsa_self = NULL;
#ifdef MONITOR_LSDB_CHANGE
top->lsdb->new_lsa_hook = ospf_opaque_lsa_install_hook;
top->lsdb->del_lsa_hook = ospf_opaque_lsa_delete_hook;
#endif /* MONITOR_LSDB_CHANGE */
return 0;
}
void ospf_opaque_type11_lsa_term(struct ospf *top)
{
#ifdef MONITOR_LSDB_CHANGE
top->lsdb->new_lsa_hook = top->lsdb->del_lsa_hook = NULL;
#endif /* MONITOR_LSDB_CHANGE */
EVENT_OFF(top->t_opaque_lsa_self);
if (top->opaque_lsa_self != NULL)
list_delete(&top->opaque_lsa_self);
return;
}
static const char *ospf_opaque_type_name(uint8_t opaque_type)
{
const char *name = "Unknown";
switch (opaque_type) {
case OPAQUE_TYPE_WILDCARD: /* This is a special assignment! */
name = "Wildcard";
break;
case OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA:
name = "Traffic Engineering LSA";
break;
case OPAQUE_TYPE_SYCAMORE_OPTICAL_TOPOLOGY_DESC:
name = "Sycamore optical topology description";
break;
case OPAQUE_TYPE_GRACE_LSA:
name = "Grace-LSA";
break;
case OPAQUE_TYPE_INTER_AS_LSA:
name = "Inter-AS TE-v2 LSA";
break;
case OPAQUE_TYPE_ROUTER_INFORMATION_LSA:
name = "Router Information LSA";
break;
case OPAQUE_TYPE_EXTENDED_PREFIX_LSA:
name = "Extended Prefix Opaque LSA";
break;
case OPAQUE_TYPE_EXTENDED_LINK_LSA:
name = "Extended Link Opaque LSA";
break;
default:
if (OPAQUE_TYPE_RANGE_UNASSIGNED(opaque_type))
name = "Unassigned";
else {
uint32_t bigger_range = opaque_type;
/*
* Get around type-limits warning: comparison is always
* true due to limited range of data type
*/
if (OPAQUE_TYPE_RANGE_RESERVED(bigger_range))
name = "Private/Experimental";
}
break;
}
return name;
}
/*------------------------------------------------------------------------*
* Following are management functions to store user specified callbacks.
*------------------------------------------------------------------------*/
struct opaque_info_per_type; /* Forward declaration. */
static void free_opaque_info_per_type(struct opaque_info_per_type *oipt,
bool cleanup_owner);
struct ospf_opaque_functab {
uint8_t opaque_type;
uint32_t ref_count;
int (*new_if_hook)(struct interface *ifp);
int (*del_if_hook)(struct interface *ifp);
void (*ism_change_hook)(struct ospf_interface *oi, int old_status);
void (*nsm_change_hook)(struct ospf_neighbor *nbr, int old_status);
void (*config_write_router)(struct vty *vty);
void (*config_write_if)(struct vty *vty, struct interface *ifp);
void (*config_write_debug)(struct vty *vty);
void (*show_opaque_info)(struct vty *vty, struct json_object *json,
struct ospf_lsa *lsa);
int (*lsa_originator)(void *arg);
struct ospf_lsa *(*lsa_refresher)(struct ospf_lsa *lsa);
int (*new_lsa_hook)(struct ospf_lsa *lsa);
int (*del_lsa_hook)(struct ospf_lsa *lsa);
};
/* Handle LSA-9/10/11 altogether. */
static struct list *ospf_opaque_wildcard_funclist;
static struct list *ospf_opaque_type9_funclist;
static struct list *ospf_opaque_type10_funclist;
static struct list *ospf_opaque_type11_funclist;
static void ospf_opaque_functab_ref(struct ospf_opaque_functab *functab)
{
functab->ref_count++;
}
static void ospf_opaque_functab_deref(struct ospf_opaque_functab *functab)
{
assert(functab->ref_count);
functab->ref_count--;
if (functab->ref_count == 0)
XFREE(MTYPE_OSPF_OPAQUE_FUNCTAB, functab);
}
static void ospf_opaque_del_functab(void *val)
{
struct ospf_opaque_functab *functab = (struct ospf_opaque_functab *)val;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Opaque LSA functab list deletion callback type %u (%p)",
__func__, functab->opaque_type, functab);
ospf_opaque_functab_deref(functab);
return;
}
static void ospf_opaque_funclist_init(void)
{
struct list *funclist;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Function list initialize", __func__);
funclist = ospf_opaque_wildcard_funclist = list_new();
funclist->del = ospf_opaque_del_functab;
funclist = ospf_opaque_type9_funclist = list_new();
funclist->del = ospf_opaque_del_functab;
funclist = ospf_opaque_type10_funclist = list_new();
funclist->del = ospf_opaque_del_functab;
funclist = ospf_opaque_type11_funclist = list_new();
funclist->del = ospf_opaque_del_functab;
return;
}
static void ospf_opaque_funclist_term(void)
{
struct list *funclist;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Function list terminate", __func__);
funclist = ospf_opaque_wildcard_funclist;
list_delete(&funclist);
funclist = ospf_opaque_type9_funclist;
list_delete(&funclist);
funclist = ospf_opaque_type10_funclist;
list_delete(&funclist);
funclist = ospf_opaque_type11_funclist;
list_delete(&funclist);
return;
}
static struct list *ospf_get_opaque_funclist(uint8_t lsa_type)
{
struct list *funclist = NULL;
switch (lsa_type) {
case OPAQUE_TYPE_WILDCARD:
/* XXX
* This is an ugly trick to handle type-9/10/11 LSA altogether.
* Yes, "OPAQUE_TYPE_WILDCARD (value 0)" is not an LSA-type, nor
* an officially assigned opaque-type.
* Though it is possible that the value might be officially used
* in the future, we use it internally as a special label, for
* now.
*/
funclist = ospf_opaque_wildcard_funclist;
break;
case OSPF_OPAQUE_LINK_LSA:
funclist = ospf_opaque_type9_funclist;
break;
case OSPF_OPAQUE_AREA_LSA:
funclist = ospf_opaque_type10_funclist;
break;
case OSPF_OPAQUE_AS_LSA:
funclist = ospf_opaque_type11_funclist;
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa_type);
break;
}
return funclist;
}
/* XXX: such a huge argument list can /not/ be healthy... */
int ospf_register_opaque_functab(
uint8_t lsa_type, uint8_t opaque_type,
int (*new_if_hook)(struct interface *ifp),
int (*del_if_hook)(struct interface *ifp),
void (*ism_change_hook)(struct ospf_interface *oi, int old_status),
void (*nsm_change_hook)(struct ospf_neighbor *nbr, int old_status),
void (*config_write_router)(struct vty *vty),
void (*config_write_if)(struct vty *vty, struct interface *ifp),
void (*config_write_debug)(struct vty *vty),
void (*show_opaque_info)(struct vty *vty, struct json_object *json,
struct ospf_lsa *lsa),
int (*lsa_originator)(void *arg),
struct ospf_lsa *(*lsa_refresher)(struct ospf_lsa *lsa),
int (*new_lsa_hook)(struct ospf_lsa *lsa),
int (*del_lsa_hook)(struct ospf_lsa *lsa))
{
struct list *funclist;
struct ospf_opaque_functab *new;
if ((funclist = ospf_get_opaque_funclist(lsa_type)) == NULL)
return -1;
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->opaque_type == opaque_type) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Opaque LSA functab found type %u, (%p)",
__func__, functab->opaque_type,
functab);
break;
}
if (functab == NULL)
new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB,
sizeof(struct ospf_opaque_functab));
else {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Re-register Opaque LSA type %u, opaque type %u, (%p)",
__func__, lsa_type, opaque_type, functab);
return 0;
}
new->opaque_type = opaque_type;
new->new_if_hook = new_if_hook;
new->del_if_hook = del_if_hook;
new->ism_change_hook = ism_change_hook;
new->nsm_change_hook = nsm_change_hook;
new->config_write_router = config_write_router;
new->config_write_if = config_write_if;
new->config_write_debug = config_write_debug;
new->show_opaque_info = show_opaque_info;
new->lsa_originator = lsa_originator;
new->lsa_refresher = lsa_refresher;
new->new_lsa_hook = new_lsa_hook;
new->del_lsa_hook = del_lsa_hook;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Register Opaque LSA type %u, opaque type %u, (%p)",
__func__, lsa_type, opaque_type, new);
listnode_add(funclist, new);
ospf_opaque_functab_ref(new);
return 0;
}
void ospf_delete_opaque_functab(uint8_t lsa_type, uint8_t opaque_type)
{
struct list *funclist;
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
if ((funclist = ospf_get_opaque_funclist(lsa_type)) != NULL)
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab)) {
if (functab->opaque_type == opaque_type) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Delete Opaque functab LSA type %u, opaque type %u, (%p)",
__func__, lsa_type,
opaque_type, functab);
/* Dequeue listnode entry from the function table
* list coreesponding to the opaque LSA type.
* Note that the list deletion callback frees
* the functab entry memory.
*/
listnode_delete(funclist, functab);
ospf_opaque_functab_deref(functab);
break;
}
}
return;
}
static struct ospf_opaque_functab *
ospf_opaque_functab_lookup(struct ospf_lsa *lsa)
{
struct list *funclist;
struct listnode *node;
struct ospf_opaque_functab *functab;
uint8_t key = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr));
if ((funclist = ospf_get_opaque_funclist(lsa->data->type)) != NULL)
for (ALL_LIST_ELEMENTS_RO(funclist, node, functab))
if (functab->opaque_type == key)
return functab;
return NULL;
}
/*------------------------------------------------------------------------*
* Following are management functions for self-originated LSA entries.
*------------------------------------------------------------------------*/
/*
* Opaque-LSA control information per opaque-type.
* Single Opaque-Type may have multiple instances; each of them will be
* identified by their opaque-id.
*/
struct opaque_info_per_type {
uint8_t lsa_type;
uint8_t opaque_type;
enum { PROC_NORMAL, PROC_SUSPEND } status;
/*
* Thread for (re-)origination scheduling for this opaque-type.
*
* Initial origination of Opaque-LSAs is controlled by generic
* Opaque-LSA handling module so that same opaque-type entries are
* called all at once when certain conditions are met.
* However, there might be cases that some Opaque-LSA clients need
* to (re-)originate their own Opaque-LSAs out-of-sync with others.
* This thread is prepared for that specific purpose.
*/
struct event *t_opaque_lsa_self;
/*
* Backpointer to an "owner" which is LSA-type dependent.
* type-9: struct ospf_interface
* type-10: struct ospf_area
* type-11: struct ospf
*/
void *owner;
/* Collection of callback functions for this opaque-type. */
struct ospf_opaque_functab *functab;
/* List of Opaque-LSA control information per opaque-id. */
struct list *id_list;
};
/* Opaque-LSA control information per opaque-id. */
struct opaque_info_per_id {
uint32_t opaque_id;
/* Thread for refresh/flush scheduling for this opaque-type/id. */
struct event *t_opaque_lsa_self;
/* Backpointer to Opaque-LSA control information per opaque-type. */
struct opaque_info_per_type *opqctl_type;
/* Here comes an actual Opaque-LSA entry for this opaque-type/id. */
struct ospf_lsa *lsa;
};
static struct opaque_info_per_type *
register_opaque_info_per_type(struct ospf_opaque_functab *functab,
struct ospf_lsa *new);
static struct opaque_info_per_type *
lookup_opaque_info_by_type(struct ospf_lsa *lsa);
static struct opaque_info_per_id *
register_opaque_info_per_id(struct opaque_info_per_type *oipt,
struct ospf_lsa *new);
static struct opaque_info_per_id *
lookup_opaque_info_by_id(struct opaque_info_per_type *oipt,
struct ospf_lsa *lsa);
static struct opaque_info_per_id *register_opaque_lsa(struct ospf_lsa *new);
static struct opaque_info_per_type *
register_opaque_info_per_type(struct ospf_opaque_functab *functab,
struct ospf_lsa *new)
{
struct ospf *top;
struct opaque_info_per_type *oipt;
oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE,
sizeof(struct opaque_info_per_type));
switch (new->data->type) {
case OSPF_OPAQUE_LINK_LSA:
oipt->owner = new->oi;
listnode_add(new->oi->opaque_lsa_self, oipt);
break;
case OSPF_OPAQUE_AREA_LSA:
oipt->owner = new->area;
listnode_add(new->area->opaque_lsa_self, oipt);
break;
case OSPF_OPAQUE_AS_LSA:
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (new->area != NULL && (top = new->area->ospf) == NULL) {
free_opaque_info_per_type(oipt, true);
oipt = NULL;
goto out; /* This case may not exist. */
}
oipt->owner = top;
listnode_add(top->opaque_lsa_self, oipt);
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, new->data->type);
free_opaque_info_per_type(oipt, true);
oipt = NULL;
goto out; /* This case may not exist. */
}
oipt->lsa_type = new->data->type;
oipt->opaque_type = GET_OPAQUE_TYPE(ntohl(new->data->id.s_addr));
oipt->status = PROC_NORMAL;
oipt->functab = functab;
ospf_opaque_functab_ref(functab);
oipt->id_list = list_new();
oipt->id_list->del = free_opaque_info_per_id;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Register Opaque info-per-type LSA type %u, opaque type %u, (%p), Functab (%p)",
__func__, oipt->lsa_type, oipt->opaque_type, oipt,
oipt->functab);
out:
return oipt;
}
static void free_opaque_info_per_type(struct opaque_info_per_type *oipt,
bool cleanup_owner)
{
struct opaque_info_per_id *oipi;
struct ospf_lsa *lsa;
struct listnode *node, *nnode;
struct list *l;
/* Control information per opaque-id may still exist. */
for (ALL_LIST_ELEMENTS(oipt->id_list, node, nnode, oipi)) {
if ((lsa = oipi->lsa) == NULL)
continue;
if (IS_LSA_MAXAGE(lsa))
continue;
ospf_opaque_lsa_flush_schedule(lsa);
}
EVENT_OFF(oipt->t_opaque_lsa_self);
list_delete(&oipt->id_list);
if (cleanup_owner) {
/* Remove from its owner's self-originated LSA list. */
switch (oipt->lsa_type) {
case OSPF_OPAQUE_LINK_LSA:
l = ((struct ospf_interface *)oipt->owner)
->opaque_lsa_self;
break;
case OSPF_OPAQUE_AREA_LSA:
l = ((struct ospf_area *)oipt->owner)->opaque_lsa_self;
break;
case OSPF_OPAQUE_AS_LSA:
l = ((struct ospf *)oipt->owner)->opaque_lsa_self;
break;
default:
flog_warn(
EC_OSPF_LSA_UNEXPECTED,
"free_opaque_info_owner: Unexpected LSA-type(%u)",
oipt->lsa_type);
return;
}
listnode_delete(l, oipt);
}
if (oipt->functab)
ospf_opaque_functab_deref(oipt->functab);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Free Opaque info-per-type LSA type %u, opaque type %u, (%p), Functab (%p)",
__func__, oipt->lsa_type, oipt->opaque_type, oipt,
oipt->functab);
XFREE(MTYPE_OPAQUE_INFO_PER_TYPE, oipt);
return;
}
static void free_opaque_info_per_type_del(void *val)
{
free_opaque_info_per_type((struct opaque_info_per_type *)val, false);
}
static struct opaque_info_per_type *
lookup_opaque_info_by_type(struct ospf_lsa *lsa)
{
struct ospf *top;
struct ospf_area *area;
struct ospf_interface *oi;
struct list *listtop = NULL;
struct listnode *node, *nnode;
struct opaque_info_per_type *oipt = NULL;
uint8_t key = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr));
switch (lsa->data->type) {
case OSPF_OPAQUE_LINK_LSA:
if ((oi = lsa->oi) != NULL)
listtop = oi->opaque_lsa_self;
else
flog_warn(
EC_OSPF_LSA,
"Type-9 Opaque-LSA: Reference to OI is missing?");
break;
case OSPF_OPAQUE_AREA_LSA:
if ((area = lsa->area) != NULL)
listtop = area->opaque_lsa_self;
else
flog_warn(
EC_OSPF_LSA,
"Type-10 Opaque-LSA: Reference to AREA is missing?");
break;
case OSPF_OPAQUE_AS_LSA:
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if ((area = lsa->area) != NULL && (top = area->ospf) == NULL) {
flog_warn(
EC_OSPF_LSA,
"Type-11 Opaque-LSA: Reference to OSPF is missing?");
break; /* Unlikely to happen. */
}
listtop = top->opaque_lsa_self;
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa->data->type);
break;
}
if (listtop != NULL)
for (ALL_LIST_ELEMENTS(listtop, node, nnode, oipt))
if (oipt->opaque_type == key)
return oipt;
return NULL;
}
static struct opaque_info_per_id *
register_opaque_info_per_id(struct opaque_info_per_type *oipt,
struct ospf_lsa *new)
{
struct opaque_info_per_id *oipi;
oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID,
sizeof(struct opaque_info_per_id));
oipi->opaque_id = GET_OPAQUE_ID(ntohl(new->data->id.s_addr));
oipi->opqctl_type = oipt;
oipi->lsa = ospf_lsa_lock(new);
listnode_add(oipt->id_list, oipi);
return oipi;
}
static void free_opaque_info_per_id(void *val)
{
struct opaque_info_per_id *oipi = (struct opaque_info_per_id *)val;
EVENT_OFF(oipi->t_opaque_lsa_self);
if (oipi->lsa != NULL)
ospf_lsa_unlock(&oipi->lsa);
XFREE(MTYPE_OPAQUE_INFO_PER_ID, oipi);
return;
}
static struct opaque_info_per_id *
lookup_opaque_info_by_id(struct opaque_info_per_type *oipt,
struct ospf_lsa *lsa)
{
struct listnode *node, *nnode;
struct opaque_info_per_id *oipi;
uint32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
for (ALL_LIST_ELEMENTS(oipt->id_list, node, nnode, oipi))
if (oipi->opaque_id == key)
return oipi;
return NULL;
}
static struct opaque_info_per_id *register_opaque_lsa(struct ospf_lsa *new)
{
struct ospf_opaque_functab *functab;
struct opaque_info_per_type *oipt;
struct opaque_info_per_id *oipi = NULL;
if ((functab = ospf_opaque_functab_lookup(new)) == NULL)
goto out;
if ((oipt = lookup_opaque_info_by_type(new)) == NULL
&& (oipt = register_opaque_info_per_type(functab, new)) == NULL)
goto out;
if ((oipi = register_opaque_info_per_id(oipt, new)) == NULL)
goto out;
out:
return oipi;
}
int ospf_opaque_is_owned(struct ospf_lsa *lsa)
{
struct opaque_info_per_type *oipt = lookup_opaque_info_by_type(lsa);
return (oipt != NULL && lookup_opaque_info_by_id(oipt, lsa) != NULL);
}
/*
* Cleanup Link-Local LSAs assocaited with an interface that is being deleted.
* Since these LSAs are stored in the area link state database (LSDB) as opposed
* to a separate per-interface, they must be deleted from the area database.
* Since their flooding scope is solely the deleted OSPF interface, there is no
* need to attempt to flush them from the routing domain. For link local LSAs
* originated via the OSPF server API, LSA deletion before interface deletion
* is required so that the callback can access the OSPF interface address.
*/
void ospf_opaque_type9_lsa_if_cleanup(struct ospf_interface *oi)
{
struct route_node *rn;
struct ospf_lsdb *lsdb;
struct ospf_lsa *lsa;
lsdb = oi->area->lsdb;
LSDB_LOOP (OPAQUE_LINK_LSDB(oi->area), rn, lsa)
/*
* While the LSA shouldn't be referenced on any LSA
* lists since the flooding scoped is confined to the
* interface being deleted, clear the pointer to the
* deleted interface to avoid references and set the
* age to MAXAGE to avoid flush processing when the LSA
* is removed from the interface opaque info list.
*/
if (lsa->oi == oi) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Delete Type-9 Opaque-LSA on interface delete: [opaque-type=%u, opaque-id=%x]",
GET_OPAQUE_TYPE(
ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(
lsa->data->id.s_addr)));
ospf_lsdb_delete(lsdb, lsa);
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
lsa->oi = NULL;
ospf_lsa_discard(lsa);
}
}
/*------------------------------------------------------------------------*
* Following are (vty) configuration functions for Opaque-LSAs handling.
*------------------------------------------------------------------------*/
DEFUN (capability_opaque,
capability_opaque_cmd,
"capability opaque",
"Enable specific OSPF feature\n"
"Opaque LSA\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
/* Check that OSPF is using default VRF */
if (ospf->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"OSPF Opaque LSA is only supported in default VRF\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* Turn on the "master switch" of opaque-lsa capability. */
if (!CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Opaque capability: OFF -> ON");
SET_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE);
ospf_renegotiate_optional_capabilities(ospf);
}
return CMD_SUCCESS;
}
DEFUN (ospf_opaque,
ospf_opaque_cmd,
"ospf opaque-lsa",
"OSPF specific commands\n"
"Enable the Opaque-LSA capability (rfc2370)\n")
{
return capability_opaque(self, vty, argc, argv);
}
DEFUN (no_capability_opaque,
no_capability_opaque_cmd,
"no capability opaque",
NO_STR
"Enable specific OSPF feature\n"
"Opaque LSA\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
/* Turn off the "master switch" of opaque-lsa capability. */
if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Opaque capability: ON -> OFF");
UNSET_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE);
ospf_renegotiate_optional_capabilities(ospf);
}
return CMD_SUCCESS;
}
DEFUN (no_ospf_opaque,
no_ospf_opaque_cmd,
"no ospf opaque-lsa",
NO_STR
"OSPF specific commands\n"
"Enable the Opaque-LSA capability (rfc2370)\n")
{
return no_capability_opaque(self, vty, argc, argv);
}
static void ospf_opaque_register_vty(void)
{
install_element(OSPF_NODE, &capability_opaque_cmd);
install_element(OSPF_NODE, &no_capability_opaque_cmd);
install_element(OSPF_NODE, &ospf_opaque_cmd);
install_element(OSPF_NODE, &no_ospf_opaque_cmd);
return;
}
/*------------------------------------------------------------------------*
* Following are collection of user-registered function callers.
*------------------------------------------------------------------------*/
static int opaque_lsa_new_if_callback(struct list *funclist,
struct interface *ifp)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
int rc = -1;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->new_if_hook != NULL)
if ((*functab->new_if_hook)(ifp) != 0)
goto out;
rc = 0;
out:
return rc;
}
static int opaque_lsa_del_if_callback(struct list *funclist,
struct interface *ifp)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
int rc = -1;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->del_if_hook != NULL)
if ((*functab->del_if_hook)(ifp) != 0)
goto out;
rc = 0;
out:
return rc;
}
static void opaque_lsa_ism_change_callback(struct list *funclist,
struct ospf_interface *oi,
int old_status)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->ism_change_hook != NULL)
(*functab->ism_change_hook)(oi, old_status);
return;
}
static void opaque_lsa_nsm_change_callback(struct list *funclist,
struct ospf_neighbor *nbr,
int old_status)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->nsm_change_hook != NULL)
(*functab->nsm_change_hook)(nbr, old_status);
return;
}
static void opaque_lsa_config_write_router_callback(struct list *funclist,
struct vty *vty)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->config_write_router != NULL)
(*functab->config_write_router)(vty);
return;
}
static void opaque_lsa_config_write_if_callback(struct list *funclist,
struct vty *vty,
struct interface *ifp)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->config_write_if != NULL)
(*functab->config_write_if)(vty, ifp);
return;
}
static void opaque_lsa_config_write_debug_callback(struct list *funclist,
struct vty *vty)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->config_write_debug != NULL)
(*functab->config_write_debug)(vty);
return;
}
static int opaque_lsa_originate_callback(struct list *funclist,
void *lsa_type_dependent)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
int rc = -1;
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->lsa_originator != NULL)
if ((*functab->lsa_originator)(lsa_type_dependent) != 0)
goto out;
rc = 0;
out:
return rc;
}
static int new_lsa_callback(struct list *funclist, struct ospf_lsa *lsa)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
int rc = -1;
/* This function handles ALL types of LSAs, not only opaque ones. */
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->new_lsa_hook != NULL)
if ((*functab->new_lsa_hook)(lsa) != 0)
goto out;
rc = 0;
out:
return rc;
}
static int del_lsa_callback(struct list *funclist, struct ospf_lsa *lsa)
{
struct listnode *node, *nnode;
struct ospf_opaque_functab *functab;
int rc = -1;
/* This function handles ALL types of LSAs, not only opaque ones. */
for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab))
if (functab->del_lsa_hook != NULL)
if ((*functab->del_lsa_hook)(lsa) != 0)
goto out;
rc = 0;
out:
return rc;
}
/*------------------------------------------------------------------------*
* Following are glue functions to call Opaque-LSA specific processing.
*------------------------------------------------------------------------*/
int ospf_opaque_new_if(struct interface *ifp)
{
struct list *funclist;
int rc = -1;
funclist = ospf_opaque_wildcard_funclist;
if (opaque_lsa_new_if_callback(funclist, ifp) != 0)
goto out;
funclist = ospf_opaque_type9_funclist;
if (opaque_lsa_new_if_callback(funclist, ifp) != 0)
goto out;
funclist = ospf_opaque_type10_funclist;
if (opaque_lsa_new_if_callback(funclist, ifp) != 0)
goto out;
funclist = ospf_opaque_type11_funclist;
if (opaque_lsa_new_if_callback(funclist, ifp) != 0)
goto out;
rc = 0;
out:
return rc;
}
int ospf_opaque_del_if(struct interface *ifp)
{
struct list *funclist;
int rc = -1;
funclist = ospf_opaque_wildcard_funclist;
if (opaque_lsa_del_if_callback(funclist, ifp) != 0)
goto out;
funclist = ospf_opaque_type9_funclist;
if (opaque_lsa_del_if_callback(funclist, ifp) != 0)
goto out;
funclist = ospf_opaque_type10_funclist;
if (opaque_lsa_del_if_callback(funclist, ifp) != 0)
goto out;
funclist = ospf_opaque_type11_funclist;
if (opaque_lsa_del_if_callback(funclist, ifp) != 0)
goto out;
rc = 0;
out:
return rc;
}
void ospf_opaque_ism_change(struct ospf_interface *oi, int old_status)
{
struct list *funclist;
funclist = ospf_opaque_wildcard_funclist;
opaque_lsa_ism_change_callback(funclist, oi, old_status);
funclist = ospf_opaque_type9_funclist;
opaque_lsa_ism_change_callback(funclist, oi, old_status);
funclist = ospf_opaque_type10_funclist;
opaque_lsa_ism_change_callback(funclist, oi, old_status);
funclist = ospf_opaque_type11_funclist;
opaque_lsa_ism_change_callback(funclist, oi, old_status);
return;
}
void ospf_opaque_nsm_change(struct ospf_neighbor *nbr, int old_state)
{
struct ospf *top;
struct list *funclist;
if ((top = oi_to_top(nbr->oi)) == NULL)
goto out;
if (old_state != NSM_Full && nbr->state == NSM_Full) {
if (CHECK_FLAG(nbr->options, OSPF_OPTION_O)) {
if (!CHECK_FLAG(top->opaque,
OPAQUE_OPERATION_READY_BIT)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Opaque-LSA: Now get operational!");
SET_FLAG(top->opaque,
OPAQUE_OPERATION_READY_BIT);
}
ospf_opaque_lsa_originate_schedule(nbr->oi, NULL);
}
} else if (old_state == NSM_Full && nbr->state != NSM_Full) {
#ifdef NOTYET
/*
* If no more opaque-capable full-state neighbor remains in the
* flooding scope which corresponds to Opaque-LSA type, periodic
* LS flooding should be stopped.
*/
#endif /* NOTYET */
;
}
funclist = ospf_opaque_wildcard_funclist;
opaque_lsa_nsm_change_callback(funclist, nbr, old_state);
funclist = ospf_opaque_type9_funclist;
opaque_lsa_nsm_change_callback(funclist, nbr, old_state);
funclist = ospf_opaque_type10_funclist;
opaque_lsa_nsm_change_callback(funclist, nbr, old_state);
funclist = ospf_opaque_type11_funclist;
opaque_lsa_nsm_change_callback(funclist, nbr, old_state);
out:
return;
}
void ospf_opaque_config_write_router(struct vty *vty, struct ospf *ospf)
{
struct list *funclist;
if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE))
vty_out(vty, " capability opaque\n");
funclist = ospf_opaque_wildcard_funclist;
opaque_lsa_config_write_router_callback(funclist, vty);
funclist = ospf_opaque_type9_funclist;
opaque_lsa_config_write_router_callback(funclist, vty);
funclist = ospf_opaque_type10_funclist;
opaque_lsa_config_write_router_callback(funclist, vty);
funclist = ospf_opaque_type11_funclist;
opaque_lsa_config_write_router_callback(funclist, vty);
return;
}
void ospf_opaque_config_write_if(struct vty *vty, struct interface *ifp)
{
struct list *funclist;
funclist = ospf_opaque_wildcard_funclist;
opaque_lsa_config_write_if_callback(funclist, vty, ifp);
funclist = ospf_opaque_type9_funclist;
opaque_lsa_config_write_if_callback(funclist, vty, ifp);
funclist = ospf_opaque_type10_funclist;
opaque_lsa_config_write_if_callback(funclist, vty, ifp);
funclist = ospf_opaque_type11_funclist;
opaque_lsa_config_write_if_callback(funclist, vty, ifp);
return;
}
void ospf_opaque_config_write_debug(struct vty *vty)
{
struct list *funclist;
funclist = ospf_opaque_wildcard_funclist;
opaque_lsa_config_write_debug_callback(funclist, vty);
funclist = ospf_opaque_type9_funclist;
opaque_lsa_config_write_debug_callback(funclist, vty);
funclist = ospf_opaque_type10_funclist;
opaque_lsa_config_write_debug_callback(funclist, vty);
funclist = ospf_opaque_type11_funclist;
opaque_lsa_config_write_debug_callback(funclist, vty);
return;
}
void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
struct lsa_header *lsah = lsa->data;
uint32_t lsid = ntohl(lsah->id.s_addr);
uint8_t opaque_type = GET_OPAQUE_TYPE(lsid);
uint32_t opaque_id = GET_OPAQUE_ID(lsid);
struct ospf_opaque_functab *functab;
json_object *jopaque = NULL;
int len, lenValid;
/* Switch output functionality by vty address. */
if (vty != NULL) {
if (!json) {
vty_out(vty, " Opaque-Type %u (%s)\n", opaque_type,
ospf_opaque_type_name(opaque_type));
vty_out(vty, " Opaque-ID 0x%x\n", opaque_id);
vty_out(vty, " Opaque-Info: %u octets of data%s\n",
ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE,
VALID_OPAQUE_INFO_LEN(lsah)
? ""
: "(Invalid length?)");
} else {
json_object_string_add(
json, "opaqueType",
ospf_opaque_type_name(opaque_type));
json_object_int_add(json, "opaqueId", opaque_id);
len = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
json_object_int_add(json, "opaqueLength", len);
lenValid = VALID_OPAQUE_INFO_LEN(lsah);
json_object_boolean_add(json, "opaqueLengthValid",
lenValid);
if (lenValid) {
jopaque = json_object_new_object();
json_object_object_add(json, "opaqueValues",
jopaque);
}
}
} else {
zlog_debug(" Opaque-Type %u (%s)", opaque_type,
ospf_opaque_type_name(opaque_type));
zlog_debug(" Opaque-ID 0x%x", opaque_id);
zlog_debug(" Opaque-Info: %u octets of data%s",
ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE,
VALID_OPAQUE_INFO_LEN(lsah) ? ""
: "(Invalid length?)");
}
/* Call individual output functions. */
if ((functab = ospf_opaque_functab_lookup(lsa)) != NULL)
if (functab->show_opaque_info != NULL)
(*functab->show_opaque_info)(vty, jopaque, lsa);
return;
}
void ospf_opaque_lsa_dump(struct stream *s, uint16_t length)
{
struct ospf_lsa lsa = {};
lsa.data = (struct lsa_header *)stream_pnt(s);
lsa.size = length;
show_opaque_info_detail(NULL, &lsa, NULL);
return;
}
static int ospf_opaque_lsa_install_hook(struct ospf_lsa *lsa)
{
struct list *funclist;
int rc = -1;
/*
* Some Opaque-LSA user may want to monitor every LSA installation
* into the LSDB, regardless with target LSA type.
*/
funclist = ospf_opaque_wildcard_funclist;
if (new_lsa_callback(funclist, lsa) != 0)
goto out;
funclist = ospf_opaque_type9_funclist;
if (new_lsa_callback(funclist, lsa) != 0)
goto out;
funclist = ospf_opaque_type10_funclist;
if (new_lsa_callback(funclist, lsa) != 0)
goto out;
funclist = ospf_opaque_type11_funclist;
if (new_lsa_callback(funclist, lsa) != 0)
goto out;
rc = 0;
out:
return rc;
}
static int ospf_opaque_lsa_delete_hook(struct ospf_lsa *lsa)
{
struct list *funclist;
int rc = -1;
/*
* Some Opaque-LSA user may want to monitor every LSA deletion
* from the LSDB, regardless with target LSA type.
*/
funclist = ospf_opaque_wildcard_funclist;
if (del_lsa_callback(funclist, lsa) != 0)
goto out;
funclist = ospf_opaque_type9_funclist;
if (del_lsa_callback(funclist, lsa) != 0)
goto out;
funclist = ospf_opaque_type10_funclist;
if (del_lsa_callback(funclist, lsa) != 0)
goto out;
funclist = ospf_opaque_type11_funclist;
if (del_lsa_callback(funclist, lsa) != 0)
goto out;
rc = 0;
out:
return rc;
}
/*------------------------------------------------------------------------*
* Following are Opaque-LSA origination/refresh management functions.
*------------------------------------------------------------------------*/
static void ospf_opaque_type9_lsa_originate(struct event *t);
static void ospf_opaque_type10_lsa_originate(struct event *t);
static void ospf_opaque_type11_lsa_originate(struct event *t);
static void ospf_opaque_lsa_reoriginate_resume(struct list *listtop, void *arg);
void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0)
{
struct ospf *top;
struct ospf_area *area;
struct listnode *node, *nnode;
struct opaque_info_per_type *oipt;
int delay = 0;
if ((top = oi_to_top(oi)) == NULL || (area = oi->area) == NULL) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Invalid argument?", __func__);
return;
}
/* It may not a right time to schedule origination now. */
if (!CHECK_FLAG(top->opaque, OPAQUE_OPERATION_READY_BIT)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Not operational.", __func__);
return; /* This is not an error. */
}
if (delay0 != NULL)
delay = *delay0;
/*
* There might be some entries that have been waiting for triggering
* of per opaque-type re-origination get resumed.
*/
ospf_opaque_lsa_reoriginate_resume(oi->opaque_lsa_self, (void *)oi);
ospf_opaque_lsa_reoriginate_resume(area->opaque_lsa_self, (void *)area);
ospf_opaque_lsa_reoriginate_resume(top->opaque_lsa_self, (void *)top);
/*
* Now, schedule origination of all Opaque-LSAs per opaque-type.
*/
if (!list_isempty(ospf_opaque_type9_funclist)
&& list_isempty(oi->opaque_lsa_self)
&& oi->t_opaque_lsa_self == NULL) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Schedule Type-9 Opaque-LSA origination in %d ms later.",
delay);
oi->t_opaque_lsa_self = NULL;
event_add_timer_msec(master, ospf_opaque_type9_lsa_originate,
oi, delay, &oi->t_opaque_lsa_self);
delay += top->min_ls_interval;
}
if (!list_isempty(ospf_opaque_type10_funclist)
&& list_isempty(area->opaque_lsa_self)
&& area->t_opaque_lsa_self == NULL) {
/*
* One AREA may contain multiple OIs, but above 2nd and 3rd
* conditions prevent from scheduling the originate function
* again and again.
*/
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Schedule Type-10 Opaque-LSA origination in %d ms later.",
delay);
area->t_opaque_lsa_self = NULL;
event_add_timer_msec(master, ospf_opaque_type10_lsa_originate,
area, delay, &area->t_opaque_lsa_self);
delay += top->min_ls_interval;
}
if (!list_isempty(ospf_opaque_type11_funclist)
&& list_isempty(top->opaque_lsa_self)
&& top->t_opaque_lsa_self == NULL) {
/*
* One OSPF may contain multiple AREAs, but above 2nd and 3rd
* conditions prevent from scheduling the originate function
* again and again.
*/
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Schedule Type-11 Opaque-LSA origination in %d ms later.",
delay);
top->t_opaque_lsa_self = NULL;
event_add_timer_msec(master, ospf_opaque_type11_lsa_originate,
top, delay, &top->t_opaque_lsa_self);
delay += top->min_ls_interval;
}
/*
* Following section treats a special situation that this node's
* opaque capability has changed as "ON -> OFF -> ON".
*/
if (!list_isempty(ospf_opaque_type9_funclist)
&& !list_isempty(oi->opaque_lsa_self)) {
for (ALL_LIST_ELEMENTS(oi->opaque_lsa_self, node, nnode,
oipt)) {
/*
* removed the test for
* (! list_isempty (oipt->id_list)) * Handler is
* already active. *
* because opaque cababilities ON -> OFF -> ON result in
* list_isempty (oipt->id_list)
* not being empty.
*/
if (oipt->t_opaque_lsa_self
!= NULL /* Waiting for a thread call. */
|| oipt->status == PROC_SUSPEND) /* Cannot
originate
now. */
continue;
ospf_opaque_lsa_reoriginate_schedule(
(void *)oi, OSPF_OPAQUE_LINK_LSA,
oipt->opaque_type);
}
}
if (!list_isempty(ospf_opaque_type10_funclist)
&& !list_isempty(area->opaque_lsa_self)) {
for (ALL_LIST_ELEMENTS(area->opaque_lsa_self, node, nnode,
oipt)) {
/*
* removed the test for
* (! list_isempty (oipt->id_list)) * Handler is
* already active. *
* because opaque cababilities ON -> OFF -> ON result in
* list_isempty (oipt->id_list)
* not being empty.
*/
if (oipt->t_opaque_lsa_self
!= NULL /* Waiting for a thread call. */
|| oipt->status == PROC_SUSPEND) /* Cannot
originate
now. */
continue;
ospf_opaque_lsa_reoriginate_schedule(
(void *)area, OSPF_OPAQUE_AREA_LSA,
oipt->opaque_type);
}
}
if (!list_isempty(ospf_opaque_type11_funclist)
&& !list_isempty(top->opaque_lsa_self)) {
for (ALL_LIST_ELEMENTS(top->opaque_lsa_self, node, nnode,
oipt)) {
/*
* removed the test for
* (! list_isempty (oipt->id_list)) * Handler is
* already active. *
* because opaque cababilities ON -> OFF -> ON result in
* list_isempty (oipt->id_list)
* not being empty.
*/
if (oipt->t_opaque_lsa_self
!= NULL /* Waiting for a thread call. */
|| oipt->status == PROC_SUSPEND) /* Cannot
originate
now. */
continue;
ospf_opaque_lsa_reoriginate_schedule((void *)top,
OSPF_OPAQUE_AS_LSA,
oipt->opaque_type);
}
}
if (delay0 != NULL)
*delay0 = delay;
}
static void ospf_opaque_type9_lsa_originate(struct event *t)
{
struct ospf_interface *oi;
oi = EVENT_ARG(t);
oi->t_opaque_lsa_self = NULL;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Timer[Type9-LSA]: Originate Opaque-LSAs for OI %s",
IF_NAME(oi));
opaque_lsa_originate_callback(ospf_opaque_type9_funclist, oi);
}
static void ospf_opaque_type10_lsa_originate(struct event *t)
{
struct ospf_area *area;
area = EVENT_ARG(t);
area->t_opaque_lsa_self = NULL;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Timer[Type10-LSA]: Originate Opaque-LSAs for Area %pI4",
&area->area_id);
opaque_lsa_originate_callback(ospf_opaque_type10_funclist, area);
}
static void ospf_opaque_type11_lsa_originate(struct event *t)
{
struct ospf *top;
top = EVENT_ARG(t);
top->t_opaque_lsa_self = NULL;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Timer[Type11-LSA]: Originate AS-External Opaque-LSAs");
opaque_lsa_originate_callback(ospf_opaque_type11_funclist, top);
}
static void ospf_opaque_lsa_reoriginate_resume(struct list *listtop, void *arg)
{
struct listnode *node, *nnode;
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
if (listtop == NULL)
goto out;
/*
* Pickup oipt entries those which in SUSPEND status, and give
* them a chance to start re-origination now.
*/
for (ALL_LIST_ELEMENTS(listtop, node, nnode, oipt)) {
if (oipt->status != PROC_SUSPEND)
continue;
oipt->status = PROC_NORMAL;
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL)
continue;
if ((*functab->lsa_originator)(arg) != 0) {
flog_warn(EC_OSPF_LSA, "%s: Failed (opaque-type=%u)",
__func__, oipt->opaque_type);
continue;
}
}
out:
return;
}
struct ospf_lsa *ospf_opaque_lsa_install(struct ospf_lsa *lsa, int rt_recalc)
{
struct ospf_lsa *new = NULL;
struct opaque_info_per_type *oipt;
struct opaque_info_per_id *oipi;
struct ospf *top;
/* Don't take "rt_recalc" into consideration for now. */ /* XXX */
if (!IS_LSA_SELF(lsa)) {
new = lsa; /* Don't touch this LSA. */
goto out;
}
if (IS_DEBUG_OSPF(lsa, LSA_INSTALL))
zlog_debug(
"Install Type-%u Opaque-LSA: [opaque-type=%u, opaque-id=%x]",
lsa->data->type,
GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)));
/* Replace the existing lsa with the new one. */
if ((oipt = lookup_opaque_info_by_type(lsa)) != NULL
&& (oipi = lookup_opaque_info_by_id(oipt, lsa)) != NULL) {
ospf_lsa_unlock(&oipi->lsa);
oipi->lsa = ospf_lsa_lock(lsa);
}
/* Register the new lsa entry */
else if (register_opaque_lsa(lsa) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: register_opaque_lsa() ?", __func__);
goto out;
}
/*
* Make use of a common mechanism (ospf_lsa_refresh_walker)
* for periodic refresh of self-originated Opaque-LSAs.
*/
switch (lsa->data->type) {
case OSPF_OPAQUE_LINK_LSA:
if ((top = oi_to_top(lsa->oi)) == NULL) {
/* Above conditions must have passed. */
flog_warn(EC_OSPF_LSA, "%s: Something wrong?",
__func__);
goto out;
}
break;
case OSPF_OPAQUE_AREA_LSA:
if (lsa->area == NULL || (top = lsa->area->ospf) == NULL) {
/* Above conditions must have passed. */
flog_warn(EC_OSPF_LSA, "%s: Something wrong?",
__func__);
goto out;
}
break;
case OSPF_OPAQUE_AS_LSA:
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (lsa->area != NULL && (top = lsa->area->ospf) == NULL) {
/* Above conditions must have passed. */
flog_warn(EC_OSPF_LSA, "%s: Something wrong?",
__func__);
goto out;
}
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa->data->type);
goto out;
}
ospf_refresher_register_lsa(top, lsa);
new = lsa;
out:
return new;
}
struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa)
{
struct ospf *ospf;
struct ospf_opaque_functab *functab;
struct ospf_lsa *new = NULL;
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if ((functab = ospf_opaque_functab_lookup(lsa)) == NULL
|| functab->lsa_refresher == NULL) {
/*
* Though this LSA seems to have originated on this node, the
* handling module for this "lsa-type and opaque-type" was
* already deleted sometime ago.
* Anyway, this node still has a responsibility to flush this
* LSA from the routing domain.
*/
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("LSA[Type%d:%pI4]: Flush stray Opaque-LSA",
lsa->data->type, &lsa->data->id);
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
ospf_lsa_flush(ospf, lsa);
} else
new = (*functab->lsa_refresher)(lsa);
return new;
}
/*------------------------------------------------------------------------*
* Following are re-origination/refresh/flush operations of Opaque-LSAs,
* triggered by external interventions (vty session, signaling, etc).
*------------------------------------------------------------------------*/
#define OSPF_OPAQUE_TIMER_ON(T, F, L, V) \
event_add_timer_msec(master, (F), (L), (V), &(T))
static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi,
struct ospf_area *area, uint8_t lsa_type,
uint8_t opaque_type);
static void ospf_opaque_type9_lsa_reoriginate_timer(struct event *t);
static void ospf_opaque_type10_lsa_reoriginate_timer(struct event *t);
static void ospf_opaque_type11_lsa_reoriginate_timer(struct event *t);
static void ospf_opaque_lsa_refresh_timer(struct event *t);
void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent,
uint8_t lsa_type, uint8_t opaque_type)
{
struct ospf *top = NULL;
struct ospf_area dummy, *area = NULL;
struct ospf_interface *oi = NULL;
struct ospf_lsa *lsa;
struct opaque_info_per_type *oipt;
void (*func)(struct event * t) = NULL;
int delay;
switch (lsa_type) {
case OSPF_OPAQUE_LINK_LSA:
if ((oi = (struct ospf_interface *)lsa_type_dependent)
== NULL) {
flog_warn(EC_OSPF_LSA,
"%s: Type-9 Opaque-LSA: Invalid parameter?",
__func__);
goto out;
}
if ((top = oi_to_top(oi)) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: OI(%s) -> TOP?", __func__,
IF_NAME(oi));
goto out;
}
if (!list_isempty(ospf_opaque_type9_funclist)
&& list_isempty(oi->opaque_lsa_self)
&& oi->t_opaque_lsa_self != NULL) {
flog_warn(
EC_OSPF_LSA,
"Type-9 Opaque-LSA (opaque_type=%u): Common origination for OI(%s) has already started",
opaque_type, IF_NAME(oi));
goto out;
}
func = ospf_opaque_type9_lsa_reoriginate_timer;
break;
case OSPF_OPAQUE_AREA_LSA:
if ((area = (struct ospf_area *)lsa_type_dependent) == NULL) {
flog_warn(EC_OSPF_LSA,
"%s: Type-10 Opaque-LSA: Invalid parameter?",
__func__);
goto out;
}
if ((top = area->ospf) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: AREA(%pI4) -> TOP?",
__func__, &area->area_id);
goto out;
}
if (!list_isempty(ospf_opaque_type10_funclist)
&& list_isempty(area->opaque_lsa_self)
&& area->t_opaque_lsa_self != NULL) {
flog_warn(
EC_OSPF_LSA,
"Type-10 Opaque-LSA (opaque_type=%u): Common origination for AREA(%pI4) has already started",
opaque_type, &area->area_id);
goto out;
}
func = ospf_opaque_type10_lsa_reoriginate_timer;
break;
case OSPF_OPAQUE_AS_LSA:
if ((top = (struct ospf *)lsa_type_dependent) == NULL) {
flog_warn(EC_OSPF_LSA,
"%s: Type-11 Opaque-LSA: Invalid parameter?",
__func__);
goto out;
}
if (!list_isempty(ospf_opaque_type11_funclist)
&& list_isempty(top->opaque_lsa_self)
&& top->t_opaque_lsa_self != NULL) {
flog_warn(
EC_OSPF_LSA,
"Type-11 Opaque-LSA (opaque_type=%u): Common origination has already started",
opaque_type);
goto out;
}
/* Fake "area" to pass "ospf" to a lookup function later. */
dummy.ospf = top;
area = &dummy;
func = ospf_opaque_type11_lsa_reoriginate_timer;
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa_type);
goto out;
}
/* It may not a right time to schedule reorigination now. */
if (!CHECK_FLAG(top->opaque, OPAQUE_OPERATION_READY_BIT)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Not operational.", __func__);
goto out; /* This is not an error. */
}
/* Generate a dummy lsa to be passed for a lookup function. */
lsa = pseudo_lsa(oi, area, lsa_type, opaque_type);
lsa->vrf_id = VRF_DEFAULT;
if ((oipt = lookup_opaque_info_by_type(lsa)) == NULL) {
struct ospf_opaque_functab *functab;
if ((functab = ospf_opaque_functab_lookup(lsa)) == NULL) {
flog_warn(
EC_OSPF_LSA,
"%s: No associated function?: lsa_type(%u), opaque_type(%u)",
__func__, lsa_type, opaque_type);
goto out;
}
if ((oipt = register_opaque_info_per_type(functab, lsa))
== NULL) {
flog_warn(
EC_OSPF_LSA,
"%s: Cannot get a control info?: lsa_type(%u), opaque_type(%u)",
__func__, lsa_type, opaque_type);
goto out;
}
}
if (oipt->t_opaque_lsa_self != NULL) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Type-%u Opaque-LSA has already scheduled to RE-ORIGINATE: [opaque-type=%u]",
lsa_type,
GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)));
goto out;
}
/*
* Different from initial origination time, in which various conditions
* (opaque capability, neighbor status etc) are assured by caller of
* the originating function "ospf_opaque_lsa_originate_schedule ()",
* it is highly possible that these conditions might not be satisfied
* at the time of re-origination function is to be called.
*/
delay = top->min_ls_interval; /* XXX */
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Schedule Type-%u Opaque-LSA to RE-ORIGINATE in %d ms later: [opaque-type=%u]",
lsa_type, delay,
GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)));
OSPF_OPAQUE_TIMER_ON(oipt->t_opaque_lsa_self, func, oipt, delay);
out:
return;
}
static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi,
struct ospf_area *area, uint8_t lsa_type,
uint8_t opaque_type)
{
static struct ospf_lsa lsa = {0};
static struct lsa_header lsah = {0};
uint32_t tmp;
lsa.oi = oi;
lsa.area = area;
lsa.data = &lsah;
lsa.vrf_id = VRF_DEFAULT;
lsah.type = lsa_type;
tmp = SET_OPAQUE_LSID(opaque_type, 0); /* Opaque-ID is unused here. */
lsah.id.s_addr = htonl(tmp);
return &lsa;
}
static void ospf_opaque_type9_lsa_reoriginate_timer(struct event *t)
{
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
struct ospf *top;
struct ospf_interface *oi;
oipt = EVENT_ARG(t);
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL) {
flog_warn(EC_OSPF_LSA, "%s: No associated function?", __func__);
return;
}
oi = (struct ospf_interface *)oipt->owner;
if ((top = oi_to_top(oi)) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Something wrong?", __func__);
return;
}
if (!CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE) ||
!OSPF_IF_PARAM(oi, opaque_capable) || !ospf_if_is_enable(oi) ||
ospf_nbr_count_opaque_capable(oi) == 0) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Suspend re-origination of Type-9 Opaque-LSAs (opaque-type=%u) for a while...",
oipt->opaque_type);
oipt->status = PROC_SUSPEND;
return;
}
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Timer[Type9-LSA]: Re-originate Opaque-LSAs (opaque-type=%u) for OI (%s)",
oipt->opaque_type, IF_NAME(oi));
(*functab->lsa_originator)(oi);
}
static void ospf_opaque_type10_lsa_reoriginate_timer(struct event *t)
{
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
struct listnode *node, *nnode;
struct ospf *top;
struct ospf_area *area;
struct ospf_interface *oi;
int n;
oipt = EVENT_ARG(t);
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL) {
flog_warn(EC_OSPF_LSA, "%s: No associated function?", __func__);
return;
}
area = (struct ospf_area *)oipt->owner;
if (area == NULL || (top = area->ospf) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Something wrong?", __func__);
return;
}
/* There must be at least one "opaque-capable, full-state" neighbor. */
n = 0;
for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi)) {
if ((n = ospf_nbr_count_opaque_capable(oi)) > 0)
break;
}
if (n == 0 || !CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Suspend re-origination of Type-10 Opaque-LSAs (opaque-type=%u) for a while...",
oipt->opaque_type);
oipt->status = PROC_SUSPEND;
return;
}
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Timer[Type10-LSA]: Re-originate Opaque-LSAs (opaque-type=%u) for Area %pI4",
oipt->opaque_type, &area->area_id);
(*functab->lsa_originator)(area);
}
static void ospf_opaque_type11_lsa_reoriginate_timer(struct event *t)
{
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
struct ospf *top;
oipt = EVENT_ARG(t);
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL) {
flog_warn(EC_OSPF_LSA, "%s: No associated function?", __func__);
return;
}
if ((top = (struct ospf *)oipt->owner) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Something wrong?", __func__);
return;
}
if (!CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Suspend re-origination of Type-11 Opaque-LSAs (opaque-type=%u) for a while...",
oipt->opaque_type);
oipt->status = PROC_SUSPEND;
return;
}
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Timer[Type11-LSA]: Re-originate Opaque-LSAs (opaque-type=%u).",
oipt->opaque_type);
(*functab->lsa_originator)(top);
}
void ospf_opaque_lsa_refresh_schedule(struct ospf_lsa *lsa0)
{
struct opaque_info_per_type *oipt;
struct opaque_info_per_id *oipi;
struct ospf_lsa *lsa;
struct ospf *top;
int delay;
if ((oipt = lookup_opaque_info_by_type(lsa0)) == NULL
|| (oipi = lookup_opaque_info_by_id(oipt, lsa0)) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Invalid parameter?", __func__);
goto out;
}
/* Given "lsa0" and current "oipi->lsa" may different, but harmless. */
if ((lsa = oipi->lsa) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Something wrong?", __func__);
goto out;
}
if (oipi->t_opaque_lsa_self != NULL) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Type-%u Opaque-LSA has already scheduled to REFRESH: [opaque-type=%u, opaque-id=%x]",
lsa->data->type,
GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)));
goto out;
}
/* Delete this lsa from neighbor retransmit-list. */
switch (lsa->data->type) {
case OSPF_OPAQUE_LINK_LSA:
case OSPF_OPAQUE_AREA_LSA:
ospf_ls_retransmit_delete_nbr_area(lsa->area, lsa);
break;
case OSPF_OPAQUE_AS_LSA:
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if ((lsa0->area != NULL) && (lsa0->area->ospf != NULL))
top = lsa0->area->ospf;
ospf_ls_retransmit_delete_nbr_as(top, lsa);
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa->data->type);
goto out;
}
delay = ospf_lsa_refresh_delay(lsa);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Schedule Type-%u Opaque-LSA to REFRESH in %d sec later: [opaque-type=%u, opaque-id=%x]",
lsa->data->type, delay,
GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)));
OSPF_OPAQUE_TIMER_ON(oipi->t_opaque_lsa_self,
ospf_opaque_lsa_refresh_timer, oipi, delay * 1000);
out:
return;
}
static void ospf_opaque_lsa_refresh_timer(struct event *t)
{
struct opaque_info_per_id *oipi;
struct ospf_opaque_functab *functab;
struct ospf_lsa *lsa;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Timer[Opaque-LSA]: (Opaque-LSA Refresh expire)");
oipi = EVENT_ARG(t);
if ((lsa = oipi->lsa) != NULL)
if ((functab = oipi->opqctl_type->functab) != NULL)
if (functab->lsa_refresher != NULL)
(*functab->lsa_refresher)(lsa);
}
void ospf_opaque_lsa_flush_schedule(struct ospf_lsa *lsa0)
{
struct opaque_info_per_type *oipt;
struct opaque_info_per_id *oipi;
struct ospf_lsa *lsa;
struct ospf *top;
top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if ((oipt = lookup_opaque_info_by_type(lsa0)) == NULL
|| (oipi = lookup_opaque_info_by_id(oipt, lsa0)) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Invalid parameter?", __func__);
goto out;
}
/* Given "lsa0" and current "oipi->lsa" may different, but harmless. */
if ((lsa = oipi->lsa) == NULL) {
flog_warn(EC_OSPF_LSA, "%s: Something wrong?", __func__);
goto out;
}
if (lsa->opaque_zero_len_delete &&
lsa->data->length != htons(sizeof(struct lsa_header))) {
/* minimize the size of the withdrawal: */
/* increment the sequence number and make len just header */
/* and update checksum */
lsa->data->ls_seqnum = lsa_seqnum_increment(lsa);
lsa->data->length = htons(sizeof(struct lsa_header));
lsa->data->checksum = 0;
lsa->data->checksum = ospf_lsa_checksum(lsa->data);
}
/* Delete this lsa from neighbor retransmit-list. */
switch (lsa->data->type) {
case OSPF_OPAQUE_LINK_LSA:
case OSPF_OPAQUE_AREA_LSA:
ospf_ls_retransmit_delete_nbr_area(lsa->area, lsa);
break;
case OSPF_OPAQUE_AS_LSA:
if ((lsa0->area != NULL) && (lsa0->area->ospf != NULL))
top = lsa0->area->ospf;
ospf_ls_retransmit_delete_nbr_as(top, lsa);
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa->data->type);
goto out;
}
/* This lsa will be flushed and removed eventually. */
ospf_lsa_flush(top, lsa);
/* Dequeue listnode entry from the list. */
listnode_delete(oipt->id_list, oipi);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Schedule Type-%u Opaque-LSA to FLUSH: [opaque-type=%u, opaque-id=%x]",
lsa->data->type,
GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)));
/* Disassociate internal control information with the given lsa. */
free_opaque_info_per_id((void *)oipi);
out:
return;
}
void ospf_opaque_self_originated_lsa_received(struct ospf_neighbor *nbr,
struct ospf_lsa *lsa)
{
struct ospf *top;
if ((top = oi_to_top(nbr->oi)) == NULL)
return;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"LSA[Type%d:%pI4]: processing self-originated Opaque-LSA",
lsa->data->type, &lsa->data->id);
/*
* Install the stale LSA into the Link State Database, add it to the
* MaxAge list, and flush it from the OSPF routing domain. For other
* LSA types, the installation is done in the refresh function. It is
* done inline here since the opaque refresh function is dynamically
* registered when opaque LSAs are originated (which is not the case
* for stale LSAs).
*/
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
ospf_lsa_install(
top, (lsa->data->type == OSPF_OPAQUE_LINK_LSA) ? nbr->oi : NULL,
lsa);
ospf_lsa_maxage(top, lsa);
switch (lsa->data->type) {
case OSPF_OPAQUE_LINK_LSA:
case OSPF_OPAQUE_AREA_LSA:
ospf_flood_through_area(nbr->oi->area, NULL /*inbr*/, lsa);
break;
case OSPF_OPAQUE_AS_LSA:
ospf_flood_through_as(top, NULL /*inbr*/, lsa);
break;
default:
flog_warn(EC_OSPF_LSA_UNEXPECTED, "%s: Unexpected LSA-type(%u)",
__func__, lsa->data->type);
return;
}
}
/*------------------------------------------------------------------------*
* Following are util functions; probably be used by Opaque-LSAs only...
*------------------------------------------------------------------------*/
struct ospf *oi_to_top(struct ospf_interface *oi)
{
struct ospf *top = NULL;
struct ospf_area *area;
if (oi == NULL || (area = oi->area) == NULL
|| (top = area->ospf) == NULL)
flog_warn(EC_OSPF_LSA,
"Broken relationship for \"OI -> AREA -> OSPF\"?");
return top;
}
|