summaryrefslogtreecommitdiffstats
path: root/zebra/interface.c
blob: 96b244635df98c7f3c7117285adce4914604d939 (plain)
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
/*
 * Interface function.
 * Copyright (C) 1997, 1999 Kunihiro Ishiguro
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; see the file COPYING; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <zebra.h>

#include "if.h"
#include "lib_errors.h"
#include "vty.h"
#include "sockunion.h"
#include "prefix.h"
#include "command.h"
#include "memory.h"
#include "zebra_memory.h"
#include "ioctl.h"
#include "connected.h"
#include "log.h"
#include "zclient.h"
#include "vrf.h"

#include "zebra/rtadv.h"
#include "zebra_ns.h"
#include "zebra_vrf.h"
#include "zebra/interface.h"
#include "zebra/rib.h"
#include "zebra/rt.h"
#include "zebra/zserv.h"
#include "zebra/redistribute.h"
#include "zebra/debug.h"
#include "zebra/irdp.h"
#include "zebra/zebra_ptm.h"
#include "zebra/rt_netlink.h"
#include "zebra/interface.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_errors.h"

DEFINE_MTYPE_STATIC(ZEBRA, ZINFO, "Zebra Interface Information")

#define ZEBRA_PTM_SUPPORT

DEFINE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
	    (vty, ifp))
DEFINE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
	    (vty, ifp))


static void if_down_del_nbr_connected(struct interface *ifp);

static int if_zebra_speed_update(struct thread *thread)
{
	struct interface *ifp = THREAD_ARG(thread);
	struct zebra_if *zif = ifp->info;
	uint32_t new_speed;

	zif->speed_update = NULL;

	new_speed = kernel_get_speed(ifp);
	if (new_speed != ifp->speed) {
		zlog_info("%s: %s old speed: %u new speed: %u",
			  __PRETTY_FUNCTION__, ifp->name, ifp->speed,
			  new_speed);
		ifp->speed = new_speed;
		if_add_update(ifp);
	}

	return 1;
}

static void zebra_if_node_destroy(route_table_delegate_t *delegate,
				  struct route_table *table,
				  struct route_node *node)
{
	if (node->info)
		list_delete_and_null((struct list **)&node->info);
	route_node_destroy(delegate, table, node);
}

route_table_delegate_t zebra_if_table_delegate = {
	.create_node = route_node_create,
	.destroy_node = zebra_if_node_destroy};

/* Called when new interface is added. */
static int if_zebra_new_hook(struct interface *ifp)
{
	struct zebra_if *zebra_if;

	zebra_if = XCALLOC(MTYPE_ZINFO, sizeof(struct zebra_if));

	zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
	zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
	zebra_ptm_if_init(zebra_if);

	ifp->ptm_enable = zebra_ptm_get_enable_state();
#if defined(HAVE_RTADV)
	{
		/* Set default router advertise values. */
		struct rtadvconf *rtadv;

		rtadv = &zebra_if->rtadv;

		rtadv->AdvSendAdvertisements = 0;
		rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL;
		rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL;
		rtadv->AdvIntervalTimer = 0;
		rtadv->AdvManagedFlag = 0;
		rtadv->AdvOtherConfigFlag = 0;
		rtadv->AdvHomeAgentFlag = 0;
		rtadv->AdvLinkMTU = 0;
		rtadv->AdvReachableTime = 0;
		rtadv->AdvRetransTimer = 0;
		rtadv->AdvCurHopLimit = 0;
		rtadv->AdvDefaultLifetime =
			-1; /* derive from MaxRtrAdvInterval */
		rtadv->HomeAgentPreference = 0;
		rtadv->HomeAgentLifetime =
			-1; /* derive from AdvDefaultLifetime */
		rtadv->AdvIntervalOption = 0;
		rtadv->DefaultPreference = RTADV_PREF_MEDIUM;

		rtadv->AdvPrefixList = list_new();
	}
#endif /* HAVE_RTADV */

	memset(&zebra_if->neigh_mac[0], 0, 6);

	/* Initialize installed address chains tree. */
	zebra_if->ipv4_subnets =
		route_table_init_with_delegate(&zebra_if_table_delegate);

	ifp->info = zebra_if;

	/*
	 * Some platforms are telling us that the interface is
	 * up and ready to go.  When we check the speed we
	 * sometimes get the wrong value.  Wait a couple
	 * of seconds and ask again.  Hopefully it's all settled
	 * down upon startup.
	 */
	thread_add_timer(zebrad.master, if_zebra_speed_update, ifp, 15,
			 &zebra_if->speed_update);
	return 0;
}

/* Called when interface is deleted. */
static int if_zebra_delete_hook(struct interface *ifp)
{
	struct zebra_if *zebra_if;

	if (ifp->info) {
		zebra_if = ifp->info;

		/* Free installed address chains tree. */
		if (zebra_if->ipv4_subnets)
			route_table_finish(zebra_if->ipv4_subnets);
#if defined(HAVE_RTADV)

		struct rtadvconf *rtadv;

		rtadv = &zebra_if->rtadv;
		list_delete_and_null(&rtadv->AdvPrefixList);
#endif /* HAVE_RTADV */

		THREAD_OFF(zebra_if->speed_update);

		XFREE(MTYPE_ZINFO, zebra_if);
	}

	return 0;
}

/* Build the table key */
static void if_build_key(uint32_t ifindex, struct prefix *p)
{
	p->family = AF_INET;
	p->prefixlen = IPV4_MAX_BITLEN;
	p->u.prefix4.s_addr = ifindex;
}

/* Link an interface in a per NS interface tree */
struct interface *if_link_per_ns(struct zebra_ns *ns, struct interface *ifp)
{
	struct prefix p;
	struct route_node *rn;

	if (ifp->ifindex == IFINDEX_INTERNAL)
		return NULL;

	if_build_key(ifp->ifindex, &p);
	rn = route_node_get(ns->if_table, &p);
	if (rn->info) {
		ifp = (struct interface *)rn->info;
		route_unlock_node(rn); /* get */
		return ifp;
	}

	rn->info = ifp;
	ifp->node = rn;

	return ifp;
}

/* Delete a VRF. This is called in vrf_terminate(). */
void if_unlink_per_ns(struct interface *ifp)
{
	ifp->node->info = NULL;
	route_unlock_node(ifp->node);
	ifp->node = NULL;
}

/* Look up an interface by identifier within a NS */
struct interface *if_lookup_by_index_per_ns(struct zebra_ns *ns,
					    uint32_t ifindex)
{
	struct prefix p;
	struct route_node *rn;
	struct interface *ifp = NULL;

	if_build_key(ifindex, &p);
	rn = route_node_lookup(ns->if_table, &p);
	if (rn) {
		ifp = (struct interface *)rn->info;
		route_unlock_node(rn); /* lookup */
	}
	return ifp;
}

/* Look up an interface by name within a NS */
struct interface *if_lookup_by_name_per_ns(struct zebra_ns *ns,
					   const char *ifname)
{
	struct route_node *rn;
	struct interface *ifp;

	for (rn = route_top(ns->if_table); rn; rn = route_next(rn)) {
		ifp = (struct interface *)rn->info;
		if (ifp && strcmp(ifp->name, ifname) == 0)
			return (ifp);
	}

	return NULL;
}

const char *ifindex2ifname_per_ns(struct zebra_ns *zns, unsigned int ifindex)
{
	struct interface *ifp;

	return ((ifp = if_lookup_by_index_per_ns(zns, ifindex)) != NULL)
		       ? ifp->name
		       : "unknown";
}

/* Tie an interface address to its derived subnet list of addresses. */
int if_subnet_add(struct interface *ifp, struct connected *ifc)
{
	struct route_node *rn;
	struct zebra_if *zebra_if;
	struct prefix cp;
	struct list *addr_list;

	assert(ifp && ifp->info && ifc);
	zebra_if = ifp->info;

	/* Get address derived subnet node and associated address list, while
	   marking
	   address secondary attribute appropriately. */
	cp = *CONNECTED_PREFIX(ifc);
	apply_mask(&cp);
	rn = route_node_get(zebra_if->ipv4_subnets, &cp);

	if ((addr_list = rn->info))
		SET_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY);
	else {
		UNSET_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY);
		rn->info = addr_list = list_new();
		route_lock_node(rn);
	}

	/* Tie address at the tail of address list. */
	listnode_add(addr_list, ifc);

	/* Return list element count. */
	return (addr_list->count);
}

/* Untie an interface address from its derived subnet list of addresses. */
int if_subnet_delete(struct interface *ifp, struct connected *ifc)
{
	struct route_node *rn;
	struct zebra_if *zebra_if;
	struct list *addr_list;
	struct prefix cp;

	assert(ifp && ifp->info && ifc);
	zebra_if = ifp->info;

	cp = *CONNECTED_PREFIX(ifc);
	apply_mask(&cp);

	/* Get address derived subnet node. */
	rn = route_node_lookup(zebra_if->ipv4_subnets, &cp);
	if (!(rn && rn->info)) {
		flog_warn(EC_ZEBRA_REMOVE_ADDR_UNKNOWN_SUBNET,
			  "Trying to remove an address from an unknown subnet."
			  " (please report this bug)");
		return -1;
	}
	route_unlock_node(rn);

	/* Untie address from subnet's address list. */
	addr_list = rn->info;

	/* Deleting an address that is not registered is a bug.
	 * In any case, we shouldn't decrement the lock counter if the address
	 * is unknown. */
	if (!listnode_lookup(addr_list, ifc)) {
		flog_warn(
			EC_ZEBRA_REMOVE_UNREGISTERED_ADDR,
			"Trying to remove an address from a subnet where it is not"
			" currently registered. (please report this bug)");
		return -1;
	}

	listnode_delete(addr_list, ifc);
	route_unlock_node(rn);

	/* Return list element count, if not empty. */
	if (addr_list->count) {
		/* If deleted address is primary, mark subsequent one as such
		 * and distribute. */
		if (!CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) {
			ifc = listgetdata(
				(struct listnode *)listhead(addr_list));
			zebra_interface_address_delete_update(ifp, ifc);
			UNSET_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY);
			/* XXX: Linux kernel removes all the secondary addresses
			 * when the primary
			 * address is removed. We could try to work around that,
			 * though this is
			 * non-trivial. */
			zebra_interface_address_add_update(ifp, ifc);
		}

		return addr_list->count;
	}

	/* Otherwise, free list and route node. */
	list_delete_and_null(&addr_list);
	rn->info = NULL;
	route_unlock_node(rn);

	return 0;
}

/* if_flags_mangle: A place for hacks that require mangling
 * or tweaking the interface flags.
 *
 * ******************** Solaris flags hacks **************************
 *
 * Solaris IFF_UP flag reflects only the primary interface as the
 * routing socket only sends IFINFO for the primary interface.  Hence
 * ~IFF_UP does not per se imply all the logical interfaces are also
 * down - which we only know of as addresses. Instead we must determine
 * whether the interface really is up or not according to how many
 * addresses are still attached. (Solaris always sends RTM_DELADDR if
 * an interface, logical or not, goes ~IFF_UP).
 *
 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
 * are addresses left in struct connected, not just the actual underlying
 * IFF_UP flag.
 *
 * We must hence remember the real state of IFF_UP, which we do in
 * struct zebra_if.primary_state.
 *
 * Setting IFF_UP within zebra to administratively shutdown the
 * interface will affect only the primary interface/address on Solaris.
 ************************End Solaris flags hacks ***********************
 */
static void if_flags_mangle(struct interface *ifp, uint64_t *newflags)
{
#ifdef SUNOS_5
	struct zebra_if *zif = ifp->info;

	zif->primary_state = *newflags & (IFF_UP & 0xff);

	if (CHECK_FLAG(zif->primary_state, IFF_UP)
	    || listcount(ifp->connected) > 0)
		SET_FLAG(*newflags, IFF_UP);
	else
		UNSET_FLAG(*newflags, IFF_UP);
#endif /* SUNOS_5 */
}

/* Update the flags field of the ifp with the new flag set provided.
 * Take whatever actions are required for any changes in flags we care
 * about.
 *
 * newflags should be the raw value, as obtained from the OS.
 */
void if_flags_update(struct interface *ifp, uint64_t newflags)
{
	if_flags_mangle(ifp, &newflags);

	if (if_is_no_ptm_operative(ifp)) {
		/* operative -> inoperative? */
		ifp->flags = newflags;
		if (!if_is_operative(ifp))
			if_down(ifp);
	} else {
		/* inoperative -> operative? */
		ifp->flags = newflags;
		if (if_is_operative(ifp))
			if_up(ifp);
	}
}

/* Wake up configured address if it is not in current kernel
   address. */
static void if_addr_wakeup(struct interface *ifp)
{
	struct listnode *node, *nnode;
	struct connected *ifc;
	struct prefix *p;
	int ret;

	for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
		p = ifc->address;

		if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)
		    && !CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)) {
			/* Address check. */
			if (p->family == AF_INET) {
				if (!if_is_up(ifp)) {
					/* Assume zebra is configured like
					 * following:
					 *
					 *   interface gre0
					 *    ip addr 192.0.2.1/24
					 *   !
					 *
					 * As soon as zebra becomes first aware
					 * that gre0 exists in the
					 * kernel, it will set gre0 up and
					 * configure its addresses.
					 *
					 * (This may happen at startup when the
					 * interface already exists
					 * or during runtime when the interface
					 * is added to the kernel)
					 *
					 * XXX: IRDP code is calling here via
					 * if_add_update - this seems
					 * somewhat weird.
					 * XXX: RUNNING is not a settable flag
					 * on any system
					 * I (paulj) am aware of.
					*/
					if_set_flags(ifp, IFF_UP | IFF_RUNNING);
					if_refresh(ifp);
				}

				ret = if_set_prefix(ifp, ifc);
				if (ret < 0) {
					flog_err_sys(
						EC_ZEBRA_IFACE_ADDR_ADD_FAILED,
						"Can't set interface's address: %s",
						safe_strerror(errno));
					continue;
				}

				SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
				/* The address will be advertised to zebra
				 * clients when the notification
				 * from the kernel has been received.
				 * It will also be added to the interface's
				 * subnet list then. */
			}
			if (p->family == AF_INET6) {
				if (!if_is_up(ifp)) {
					/* See long comment above */
					if_set_flags(ifp, IFF_UP | IFF_RUNNING);
					if_refresh(ifp);
				}

				ret = if_prefix_add_ipv6(ifp, ifc);
				if (ret < 0) {
					flog_err_sys(
						EC_ZEBRA_IFACE_ADDR_ADD_FAILED,
						"Can't set interface's address: %s",
						safe_strerror(errno));
					continue;
				}

				SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
				/* The address will be advertised to zebra
				 * clients when the notification
				 * from the kernel has been received. */
			}
		}
	}
}

/* Handle interface addition */
void if_add_update(struct interface *ifp)
{
	struct zebra_if *if_data;
	struct zebra_ns *zns;
	struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);

	/* case interface populate before vrf enabled */
	if (zvrf->zns)
		zns = zvrf->zns;
	else
		zns = zebra_ns_lookup(NS_DEFAULT);
	if_link_per_ns(zns, ifp);
	if_data = ifp->info;
	assert(if_data);

	if (if_data->multicast == IF_ZEBRA_MULTICAST_ON)
		if_set_flags(ifp, IFF_MULTICAST);
	else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF)
		if_unset_flags(ifp, IFF_MULTICAST);

	zebra_ptm_if_set_ptm_state(ifp, if_data);

	zebra_interface_add_update(ifp);

	if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
		SET_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE);

		if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) {
			if (IS_ZEBRA_DEBUG_KERNEL)
				zlog_debug(
					"interface %s vrf %u index %d is shutdown. "
					"Won't wake it up.",
					ifp->name, ifp->vrf_id, ifp->ifindex);
			return;
		}

		if_addr_wakeup(ifp);

		if (IS_ZEBRA_DEBUG_KERNEL)
			zlog_debug(
				"interface %s vrf %u index %d becomes active.",
				ifp->name, ifp->vrf_id, ifp->ifindex);

	} else {
		if (IS_ZEBRA_DEBUG_KERNEL)
			zlog_debug("interface %s vrf %u index %d is added.",
				   ifp->name, ifp->vrf_id, ifp->ifindex);
	}
}

/* Install connected routes corresponding to an interface. */
static void if_install_connected(struct interface *ifp)
{
	struct listnode *node;
	struct listnode *next;
	struct connected *ifc;

	if (ifp->connected) {
		for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) {
			if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
				zebra_interface_address_add_update(ifp, ifc);

			connected_up(ifp, ifc);
		}
	}
}

/* Uninstall connected routes corresponding to an interface. */
static void if_uninstall_connected(struct interface *ifp)
{
	struct listnode *node;
	struct listnode *next;
	struct connected *ifc;

	if (ifp->connected) {
		for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) {
			zebra_interface_address_delete_update(ifp, ifc);
			connected_down(ifp, ifc);
		}
	}
}

/* Uninstall and delete connected routes corresponding to an interface. */
/* TODO - Check why IPv4 handling here is different from install or if_down */
static void if_delete_connected(struct interface *ifp)
{
	struct connected *ifc;
	struct prefix cp;
	struct route_node *rn;
	struct zebra_if *zebra_if;
	struct listnode *node;
	struct listnode *last = NULL;

	zebra_if = ifp->info;

	if (!ifp->connected)
		return;

	while ((node = (last ? last->next : listhead(ifp->connected)))) {
		ifc = listgetdata(node);

		cp = *CONNECTED_PREFIX(ifc);
		apply_mask(&cp);

		if (cp.family == AF_INET
		    && (rn = route_node_lookup(zebra_if->ipv4_subnets, &cp))) {
			struct listnode *anode;
			struct listnode *next;
			struct listnode *first;
			struct list *addr_list;

			route_unlock_node(rn);
			addr_list = (struct list *)rn->info;

			/* Remove addresses, secondaries first. */
			first = listhead(addr_list);
			if (first)
				for (anode = first->next; anode || first;
				     anode = next) {
					if (!anode) {
						anode = first;
						first = NULL;
					}
					next = anode->next;

					ifc = listgetdata(anode);
					connected_down(ifp, ifc);

					/* XXX: We have to send notifications
					 * here explicitly, because we destroy
					 * the ifc before receiving the
					 * notification about the address being
					 * deleted.
					 */
					zebra_interface_address_delete_update(
						ifp, ifc);

					UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
					UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);

					/* Remove from subnet chain. */
					list_delete_node(addr_list, anode);
					route_unlock_node(rn);

					/* Remove from interface address list
					 * (unconditionally). */
					if (!CHECK_FLAG(ifc->conf,
							ZEBRA_IFC_CONFIGURED)) {
						listnode_delete(ifp->connected,
								ifc);
						connected_free(ifc);
					} else
						last = node;
				}

			/* Free chain list and respective route node. */
			list_delete_and_null(&addr_list);
			rn->info = NULL;
			route_unlock_node(rn);
		} else if (cp.family == AF_INET6) {
			connected_down(ifp, ifc);

			zebra_interface_address_delete_update(ifp, ifc);

			UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
			UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);

			if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
				last = node;
			else {
				listnode_delete(ifp->connected, ifc);
				connected_free(ifc);
			}
		} else {
			last = node;
		}
	}
}

/* Handle an interface delete event */
void if_delete_update(struct interface *ifp)
{
	struct zebra_if *zif;

	if (if_is_up(ifp)) {
		flog_err(
			EC_LIB_INTERFACE,
			"interface %s vrf %u index %d is still up while being deleted.",
			ifp->name, ifp->vrf_id, ifp->ifindex);
		return;
	}

	if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE))
		return;

	/* Mark interface as inactive */
	UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE);

	if (IS_ZEBRA_DEBUG_KERNEL)
		zlog_debug("interface %s vrf %u index %d is now inactive.",
			   ifp->name, ifp->vrf_id, ifp->ifindex);

	/* Delete connected routes from the kernel. */
	if_delete_connected(ifp);

	/* Send out notification on interface delete. */
	zebra_interface_delete_update(ifp);

	if_unlink_per_ns(ifp);

	/* Update ifindex after distributing the delete message.  This is in
	   case any client needs to have the old value of ifindex available
	   while processing the deletion.  Each client daemon is responsible
	   for setting ifindex to IFINDEX_INTERNAL after processing the
	   interface deletion message. */
	if_set_index(ifp, IFINDEX_INTERNAL);
	ifp->node = NULL;

	/* if the ifp is in a vrf, move it to default so vrf can be deleted if
	 * desired. This operation is not done for netns implementation to avoid
	 * collision with interface with the same name in the default vrf (can
	 * occur with this implementation whereas it is not possible with
	 * vrf-lite).
	 */
	if (ifp->vrf_id && !vrf_is_backend_netns())
		if_handle_vrf_change(ifp, VRF_DEFAULT);

	/* Reset some zebra interface params to default values. */
	zif = ifp->info;
	if (zif) {
		zif->zif_type = ZEBRA_IF_OTHER;
		zif->zif_slave_type = ZEBRA_IF_SLAVE_NONE;
		memset(&zif->l2info, 0, sizeof(union zebra_l2if_info));
		memset(&zif->brslave_info, 0,
		       sizeof(struct zebra_l2info_brslave));
	}
}

/* VRF change for an interface */
void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id)
{
	vrf_id_t old_vrf_id;

	old_vrf_id = ifp->vrf_id;

	/* Uninstall connected routes. */
	if_uninstall_connected(ifp);

	/* Delete any IPv4 neighbors created to implement RFC 5549 */
	if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);

	/* Delete all neighbor addresses learnt through IPv6 RA */
	if_down_del_nbr_connected(ifp);

	/* Send out notification on interface VRF change. */
	/* This is to issue an UPDATE or a DELETE, as appropriate. */
	zebra_interface_vrf_update_del(ifp, vrf_id);

	/* update VRF */
	if_update_to_new_vrf(ifp, vrf_id);

	/* Send out notification on interface VRF change. */
	/* This is to issue an ADD, if needed. */
	zebra_interface_vrf_update_add(ifp, old_vrf_id);

	/* Install connected routes (in new VRF). */
	if (if_is_operative(ifp))
		if_install_connected(ifp);

	/* Due to connected route change, schedule RIB processing for both old
	 * and new VRF.
	 */
	if (IS_ZEBRA_DEBUG_RIB_DETAILED)
		zlog_debug("%u: IF %s VRF change, scheduling RIB processing",
			   ifp->vrf_id, ifp->name);
	rib_update(old_vrf_id, RIB_UPDATE_IF_CHANGE);
	rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
}

static void ipv6_ll_address_to_mac(struct in6_addr *address, uint8_t *mac)
{
	mac[0] = address->s6_addr[8] ^ 0x02;
	mac[1] = address->s6_addr[9];
	mac[2] = address->s6_addr[10];
	mac[3] = address->s6_addr[13];
	mac[4] = address->s6_addr[14];
	mac[5] = address->s6_addr[15];
}

static bool mac_is_same(char *mac1, char *mac2)
{
	if (mac1[0] == mac2[0] &&
	    mac1[1] == mac2[1] &&
	    mac1[2] == mac2[2] &&
	    mac1[3] == mac2[3] &&
	    mac1[4] == mac2[4] &&
	    mac1[5] == mac2[5])
		return true;
	else
		return false;
}

void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *ifp,
				       char mac[6],
				       struct in6_addr *address,
				       int add)
{
	struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
	struct zebra_if *zif = ifp->info;
	char buf[16] = "169.254.0.1";
	struct in_addr ipv4_ll;
	ns_id_t ns_id;

	inet_pton(AF_INET, buf, &ipv4_ll);

	ns_id = zvrf->zns->ns_id;

	/*
	 * Remove existed arp record for the interface as netlink
	 * protocol does not have update message types
	 *
	 * supported message types are RTM_NEWNEIGH and RTM_DELNEIGH
	 */
	if (!mac_is_same(zif->neigh_mac, mac)) {
		kernel_neigh_update(0, ifp->ifindex, ipv4_ll.s_addr,
				    mac, 6, ns_id);

		/* Add arp record */
		kernel_neigh_update(add, ifp->ifindex, ipv4_ll.s_addr,
				    mac, 6, ns_id);
	}

	memcpy(&zif->neigh_mac[0], &mac[0], 6);

	/*
	 * We need to note whether or not we originated a v6
	 * neighbor entry for this interface.  So that when
	 * someone unwisely accidently deletes this entry
	 * we can shove it back in.
	 */
	zif->v6_2_v4_ll_neigh_entry = !!add;
	memcpy(&zif->v6_2_v4_ll_addr6, address, sizeof(*address));

	zvrf->neigh_updates++;
}

void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp,
					  struct in6_addr *address, int add)
{

	char mac[6];

	ipv6_ll_address_to_mac(address, (uint8_t *)mac);
	if_nbr_mac_to_ipv4ll_neigh_update(ifp, mac, address, add);
}

static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface *ifp)
{
	if (listhead(ifp->nbr_connected)) {
		struct nbr_connected *nbr_connected;
		struct listnode *node;

		for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node,
					  nbr_connected))
			if_nbr_ipv6ll_to_ipv4ll_neigh_update(
				ifp, &nbr_connected->address->u.prefix6, 1);
	}
}

void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp)
{
	if (listhead(ifp->nbr_connected)) {
		struct nbr_connected *nbr_connected;
		struct listnode *node;

		for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node,
					  nbr_connected))
			if_nbr_ipv6ll_to_ipv4ll_neigh_update(
				ifp, &nbr_connected->address->u.prefix6, 0);
	}
}

static void if_down_del_nbr_connected(struct interface *ifp)
{
	struct nbr_connected *nbr_connected;
	struct listnode *node, *nnode;

	for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode,
			       nbr_connected)) {
		listnode_delete(ifp->nbr_connected, nbr_connected);
		nbr_connected_free(nbr_connected);
	}
}

/* Interface is up. */
void if_up(struct interface *ifp)
{
	struct zebra_if *zif;
	struct interface *link_if;
	struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);

	zif = ifp->info;
	zif->up_count++;
	quagga_timestamp(2, zif->up_last, sizeof(zif->up_last));

	/* Notify the protocol daemons. */
	if (ifp->ptm_enable && (ifp->ptm_status == ZEBRA_PTM_STATUS_DOWN)) {
		flog_warn(EC_ZEBRA_PTM_NOT_READY,
			  "%s: interface %s hasn't passed ptm check\n",
			  __func__, ifp->name);
		return;
	}
	zebra_interface_up_update(ifp);

	if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp);

#if defined(HAVE_RTADV)
	/* Enable fast tx of RA if enabled && RA interval is not in msecs */
	if (zif->rtadv.AdvSendAdvertisements
	    && (zif->rtadv.MaxRtrAdvInterval >= 1000)) {
		zif->rtadv.inFastRexmit = 1;
		zif->rtadv.NumFastReXmitsRemain = RTADV_NUM_FAST_REXMITS;
	}
#endif

	/* Install connected routes to the kernel. */
	if_install_connected(ifp);

	if (IS_ZEBRA_DEBUG_RIB_DETAILED)
		zlog_debug("%u: IF %s up, scheduling RIB processing",
			   ifp->vrf_id, ifp->name);
	rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);

	/* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
	 * are checked to see if (remote) neighbor entries need to be installed
	 * on them for ARP suppression.
	 */
	if (IS_ZEBRA_IF_VXLAN(ifp))
		zebra_vxlan_if_up(ifp);
	else if (IS_ZEBRA_IF_BRIDGE(ifp)) {
		link_if = ifp;
		zebra_vxlan_svi_up(ifp, link_if);
	} else if (IS_ZEBRA_IF_VLAN(ifp)) {
		link_if = if_lookup_by_index_per_ns(zvrf->zns,
						    zif->link_ifindex);
		if (link_if)
			zebra_vxlan_svi_up(ifp, link_if);
	}
}

/* Interface goes down.  We have to manage different behavior of based
   OS. */
void if_down(struct interface *ifp)
{
	struct zebra_if *zif;
	struct interface *link_if;
	struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);

	zif = ifp->info;
	zif->down_count++;
	quagga_timestamp(2, zif->down_last, sizeof(zif->down_last));

	/* Handle interface down for specific types for EVPN. Non-VxLAN
	 * interfaces
	 * are checked to see if (remote) neighbor entries need to be purged
	 * for ARP suppression.
	 */
	if (IS_ZEBRA_IF_VXLAN(ifp))
		zebra_vxlan_if_down(ifp);
	else if (IS_ZEBRA_IF_BRIDGE(ifp)) {
		link_if = ifp;
		zebra_vxlan_svi_down(ifp, link_if);
	} else if (IS_ZEBRA_IF_VLAN(ifp)) {
		link_if = if_lookup_by_index_per_ns(zvrf->zns,
						    zif->link_ifindex);
		if (link_if)
			zebra_vxlan_svi_down(ifp, link_if);
	}


	/* Notify to the protocol daemons. */
	zebra_interface_down_update(ifp);

	/* Uninstall connected routes from the kernel. */
	if_uninstall_connected(ifp);

	if (IS_ZEBRA_DEBUG_RIB_DETAILED)
		zlog_debug("%u: IF %s down, scheduling RIB processing",
			   ifp->vrf_id, ifp->name);
	rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);

	if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);

	/* Delete all neighbor addresses learnt through IPv6 RA */
	if_down_del_nbr_connected(ifp);
}

void if_refresh(struct interface *ifp)
{
	if_get_flags(ifp);
}

void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
			  ns_id_t ns_id)
{
	struct zebra_if *zif;

	if (IS_ZEBRA_IF_VETH(ifp))
		return;
	zif = (struct zebra_if *)ifp->info;
	zif->link_ifindex = link_ifindex;
	zif->link = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
					      link_ifindex);
}

/*
 * during initial link dump kernel does not order lower devices before
 * upper devices so we need to fixup link dependencies at the end of dump
 */
void zebra_if_update_all_links(void)
{
	struct route_node *rn;
	struct interface *ifp;
	struct zebra_if *zif;
	struct zebra_ns *ns;

	if (IS_ZEBRA_DEBUG_KERNEL)
		zlog_info("fixup link dependencies");

	ns = zebra_ns_lookup(NS_DEFAULT);
	for (rn = route_top(ns->if_table); rn; rn = route_next(rn)) {
		ifp = (struct interface *)rn->info;
		if (!ifp)
			continue;
		zif = ifp->info;
		if ((zif->link_ifindex != IFINDEX_INTERNAL) && !zif->link) {
			zif->link = if_lookup_by_index_per_ns(ns,
							 zif->link_ifindex);
			if (IS_ZEBRA_DEBUG_KERNEL)
				zlog_debug("interface %s/%d's lower fixup to %s/%d",
						ifp->name, ifp->ifindex,
						zif->link?zif->link->name:"unk",
						zif->link_ifindex);
		}
	}
}



/* Output prefix string to vty. */
static int prefix_vty_out(struct vty *vty, struct prefix *p)
{
	char str[INET6_ADDRSTRLEN];

	inet_ntop(p->family, &p->u.prefix, str, sizeof(str));
	vty_out(vty, "%s", str);
	return strlen(str);
}

/* Dump if address information to vty. */
static void connected_dump_vty(struct vty *vty, struct connected *connected)
{
	struct prefix *p;

	/* Print interface address. */
	p = connected->address;
	vty_out(vty, "  %s ", prefix_family_str(p));
	prefix_vty_out(vty, p);
	vty_out(vty, "/%d", p->prefixlen);

	/* If there is destination address, print it. */
	if (connected->destination) {
		vty_out(vty,
			(CONNECTED_PEER(connected) ? " peer " : " broadcast "));
		prefix_vty_out(vty, connected->destination);
		if (CONNECTED_PEER(connected))
			vty_out(vty, "/%d", connected->destination->prefixlen);
	}

	if (CHECK_FLAG(connected->flags, ZEBRA_IFA_SECONDARY))
		vty_out(vty, " secondary");

	if (CHECK_FLAG(connected->flags, ZEBRA_IFA_UNNUMBERED))
		vty_out(vty, " unnumbered");

	if (connected->label)
		vty_out(vty, " %s", connected->label);

	vty_out(vty, "\n");
}

/* Dump interface neighbor address information to vty. */
static void nbr_connected_dump_vty(struct vty *vty,
				   struct nbr_connected *connected)
{
	struct prefix *p;

	/* Print interface address. */
	p = connected->address;
	vty_out(vty, "  %s ", prefix_family_str(p));
	prefix_vty_out(vty, p);
	vty_out(vty, "/%d", p->prefixlen);

	vty_out(vty, "\n");
}

static const char *zebra_ziftype_2str(zebra_iftype_t zif_type)
{
	switch (zif_type) {
	case ZEBRA_IF_OTHER:
		return "Other";
		break;

	case ZEBRA_IF_BRIDGE:
		return "Bridge";
		break;

	case ZEBRA_IF_VLAN:
		return "Vlan";
		break;

	case ZEBRA_IF_VXLAN:
		return "Vxlan";
		break;

	case ZEBRA_IF_VRF:
		return "VRF";
		break;

	case ZEBRA_IF_VETH:
		return "VETH";
		break;

	default:
		return "Unknown";
		break;
	}
}

/* Interface's information print out to vty interface. */
static void if_dump_vty(struct vty *vty, struct interface *ifp)
{
	struct connected *connected;
	struct nbr_connected *nbr_connected;
	struct listnode *node;
	struct route_node *rn;
	struct zebra_if *zebra_if;
	struct vrf *vrf;

	zebra_if = ifp->info;

	vty_out(vty, "Interface %s is ", ifp->name);
	if (if_is_up(ifp)) {
		vty_out(vty, "up, line protocol ");

		if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
			if (if_is_running(ifp))
				vty_out(vty, "is up\n");
			else
				vty_out(vty, "is down\n");
		} else {
			vty_out(vty, "detection is disabled\n");
		}
	} else {
		vty_out(vty, "down\n");
	}

	vty_out(vty, "  Link ups:   %5u    last: %s\n", zebra_if->up_count,
		zebra_if->up_last[0] ? zebra_if->up_last : "(never)");
	vty_out(vty, "  Link downs: %5u    last: %s\n", zebra_if->down_count,
		zebra_if->down_last[0] ? zebra_if->down_last : "(never)");

	zebra_ptm_show_status(vty, ifp);

	vrf = vrf_lookup_by_id(ifp->vrf_id);
	vty_out(vty, "  vrf: %s\n", vrf->name);

	if (ifp->desc)
		vty_out(vty, "  Description: %s\n", ifp->desc);
	if (ifp->ifindex == IFINDEX_INTERNAL) {
		vty_out(vty, "  pseudo interface\n");
		return;
	} else if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
		vty_out(vty, "  index %d inactive interface\n", ifp->ifindex);
		return;
	}

	vty_out(vty, "  index %d metric %d mtu %d speed %u ", ifp->ifindex,
		ifp->metric, ifp->mtu, ifp->speed);
	if (ifp->mtu6 != ifp->mtu)
		vty_out(vty, "mtu6 %d ", ifp->mtu6);
	vty_out(vty, "\n  flags: %s\n", if_flag_dump(ifp->flags));

	/* Hardware address. */
	vty_out(vty, "  Type: %s\n", if_link_type_str(ifp->ll_type));
	if (ifp->hw_addr_len != 0) {
		int i;

		vty_out(vty, "  HWaddr: ");
		for (i = 0; i < ifp->hw_addr_len; i++)
			vty_out(vty, "%s%02x", i == 0 ? "" : ":",
				ifp->hw_addr[i]);
		vty_out(vty, "\n");
	}

	/* Bandwidth in Mbps */
	if (ifp->bandwidth != 0) {
		vty_out(vty, "  bandwidth %u Mbps", ifp->bandwidth);
		vty_out(vty, "\n");
	}

	for (rn = route_top(zebra_if->ipv4_subnets); rn; rn = route_next(rn)) {
		if (!rn->info)
			continue;

		for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node,
					  connected))
			connected_dump_vty(vty, connected);
	}

	for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
		if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
		    && (connected->address->family == AF_INET6))
			connected_dump_vty(vty, connected);
	}

	vty_out(vty, "  Interface Type %s\n",
		zebra_ziftype_2str(zebra_if->zif_type));
	if (IS_ZEBRA_IF_BRIDGE(ifp)) {
		struct zebra_l2info_bridge *bridge_info;

		bridge_info = &zebra_if->l2info.br;
		vty_out(vty, "  Bridge VLAN-aware: %s\n",
			bridge_info->vlan_aware ? "yes" : "no");
	} else if (IS_ZEBRA_IF_VLAN(ifp)) {
		struct zebra_l2info_vlan *vlan_info;

		vlan_info = &zebra_if->l2info.vl;
		vty_out(vty, "  VLAN Id %u\n", vlan_info->vid);
	} else if (IS_ZEBRA_IF_VXLAN(ifp)) {
		struct zebra_l2info_vxlan *vxlan_info;

		vxlan_info = &zebra_if->l2info.vxl;
		vty_out(vty, "  VxLAN Id %u", vxlan_info->vni);
		if (vxlan_info->vtep_ip.s_addr != INADDR_ANY)
			vty_out(vty, " VTEP IP: %s",
				inet_ntoa(vxlan_info->vtep_ip));
		if (vxlan_info->access_vlan)
			vty_out(vty, " Access VLAN Id %u",
				vxlan_info->access_vlan);
		vty_out(vty, "\n");
	}

	if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) {
		struct zebra_l2info_brslave *br_slave;

		br_slave = &zebra_if->brslave_info;
		if (br_slave->bridge_ifindex != IFINDEX_INTERNAL)
			vty_out(vty, "  Master (bridge) ifindex %u\n",
				br_slave->bridge_ifindex);
	}

	if (zebra_if->link_ifindex != IFINDEX_INTERNAL) {
		vty_out(vty, "  Link ifindex %u", zebra_if->link_ifindex);
		if (zebra_if->link)
			vty_out(vty, "(%s)\n", zebra_if->link->name);
		else
			vty_out(vty, "(Unknown)\n");
	}

	if (HAS_LINK_PARAMS(ifp)) {
		int i;
		struct if_link_params *iflp = ifp->link_params;
		vty_out(vty, "  Traffic Engineering Link Parameters:\n");
		if (IS_PARAM_SET(iflp, LP_TE_METRIC))
			vty_out(vty, "    TE metric %u\n", iflp->te_metric);
		if (IS_PARAM_SET(iflp, LP_MAX_BW))
			vty_out(vty, "    Maximum Bandwidth %g (Byte/s)\n",
				iflp->max_bw);
		if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW))
			vty_out(vty,
				"    Maximum Reservable Bandwidth %g (Byte/s)\n",
				iflp->max_rsv_bw);
		if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) {
			vty_out(vty,
				"    Unreserved Bandwidth per Class Type in Byte/s:\n");
			for (i = 0; i < MAX_CLASS_TYPE; i += 2)
				vty_out(vty,
					"      [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
					i, iflp->unrsv_bw[i], i + 1,
					iflp->unrsv_bw[i + 1]);
		}

		if (IS_PARAM_SET(iflp, LP_ADM_GRP))
			vty_out(vty, "    Administrative Group:%u\n",
				iflp->admin_grp);
		if (IS_PARAM_SET(iflp, LP_DELAY)) {
			vty_out(vty, "    Link Delay Average: %u (micro-sec.)",
				iflp->av_delay);
			if (IS_PARAM_SET(iflp, LP_MM_DELAY)) {
				vty_out(vty, " Min:  %u (micro-sec.)",
					iflp->min_delay);
				vty_out(vty, " Max:  %u (micro-sec.)",
					iflp->max_delay);
			}
			vty_out(vty, "\n");
		}
		if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
			vty_out(vty,
				"    Link Delay Variation %u (micro-sec.)\n",
				iflp->delay_var);
		if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
			vty_out(vty, "    Link Packet Loss %g (in %%)\n",
				iflp->pkt_loss);
		if (IS_PARAM_SET(iflp, LP_AVA_BW))
			vty_out(vty, "    Available Bandwidth %g (Byte/s)\n",
				iflp->ava_bw);
		if (IS_PARAM_SET(iflp, LP_RES_BW))
			vty_out(vty, "    Residual Bandwidth %g (Byte/s)\n",
				iflp->res_bw);
		if (IS_PARAM_SET(iflp, LP_USE_BW))
			vty_out(vty, "    Utilized Bandwidth %g (Byte/s)\n",
				iflp->use_bw);
		if (IS_PARAM_SET(iflp, LP_RMT_AS))
			vty_out(vty, "    Neighbor ASBR IP: %s AS: %u \n",
				inet_ntoa(iflp->rmt_ip), iflp->rmt_as);
	}

	hook_call(zebra_if_extra_info, vty, ifp);

	if (listhead(ifp->nbr_connected))
		vty_out(vty, "  Neighbor address(s):\n");
	for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node, nbr_connected))
		nbr_connected_dump_vty(vty, nbr_connected);

#ifdef HAVE_PROC_NET_DEV
	/* Statistics print out using proc file system. */
	vty_out(vty,
		"    %lu input packets (%lu multicast), %lu bytes, "
		"%lu dropped\n",
		ifp->stats.rx_packets, ifp->stats.rx_multicast,
		ifp->stats.rx_bytes, ifp->stats.rx_dropped);

	vty_out(vty,
		"    %lu input errors, %lu length, %lu overrun,"
		" %lu CRC, %lu frame\n",
		ifp->stats.rx_errors, ifp->stats.rx_length_errors,
		ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
		ifp->stats.rx_frame_errors);

	vty_out(vty, "    %lu fifo, %lu missed\n", ifp->stats.rx_fifo_errors,
		ifp->stats.rx_missed_errors);

	vty_out(vty, "    %lu output packets, %lu bytes, %lu dropped\n",
		ifp->stats.tx_packets, ifp->stats.tx_bytes,
		ifp->stats.tx_dropped);

	vty_out(vty,
		"    %lu output errors, %lu aborted, %lu carrier,"
		" %lu fifo, %lu heartbeat\n",
		ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
		ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
		ifp->stats.tx_heartbeat_errors);

	vty_out(vty, "    %lu window, %lu collisions\n",
		ifp->stats.tx_window_errors, ifp->stats.collisions);
#endif /* HAVE_PROC_NET_DEV */

#ifdef HAVE_NET_RT_IFLIST
#if defined(__bsdi__) || defined(__NetBSD__)
	/* Statistics print out using sysctl (). */
	vty_out(vty,
		"    input packets %llu, bytes %llu, dropped %llu,"
		" multicast packets %llu\n",
		(unsigned long long)ifp->stats.ifi_ipackets,
		(unsigned long long)ifp->stats.ifi_ibytes,
		(unsigned long long)ifp->stats.ifi_iqdrops,
		(unsigned long long)ifp->stats.ifi_imcasts);

	vty_out(vty, "    input errors %llu\n",
		(unsigned long long)ifp->stats.ifi_ierrors);

	vty_out(vty,
		"    output packets %llu, bytes %llu,"
		" multicast packets %llu\n",
		(unsigned long long)ifp->stats.ifi_opackets,
		(unsigned long long)ifp->stats.ifi_obytes,
		(unsigned long long)ifp->stats.ifi_omcasts);

	vty_out(vty, "    output errors %llu\n",
		(unsigned long long)ifp->stats.ifi_oerrors);

	vty_out(vty, "    collisions %llu\n",
		(unsigned long long)ifp->stats.ifi_collisions);
#else
	/* Statistics print out using sysctl (). */
	vty_out(vty,
		"    input packets %lu, bytes %lu, dropped %lu,"
		" multicast packets %lu\n",
		ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
		ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts);

	vty_out(vty, "    input errors %lu\n", ifp->stats.ifi_ierrors);

	vty_out(vty,
		"    output packets %lu, bytes %lu, multicast packets %lu\n",
		ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
		ifp->stats.ifi_omcasts);

	vty_out(vty, "    output errors %lu\n", ifp->stats.ifi_oerrors);

	vty_out(vty, "    collisions %lu\n", ifp->stats.ifi_collisions);
#endif /* __bsdi__ || __NetBSD__ */
#endif /* HAVE_NET_RT_IFLIST */
}

static void interface_update_stats(void)
{
#ifdef HAVE_PROC_NET_DEV
	/* If system has interface statistics via proc file system, update
	   statistics. */
	ifstat_update_proc();
#endif /* HAVE_PROC_NET_DEV */
#ifdef HAVE_NET_RT_IFLIST
	ifstat_update_sysctl();
#endif /* HAVE_NET_RT_IFLIST */
}

struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};

/* Show all interfaces to vty. */
DEFUN (show_interface,
       show_interface_cmd,
       "show interface [vrf NAME]",
       SHOW_STR
       "Interface status and configuration\n"
       VRF_CMD_HELP_STR)
{
	struct vrf *vrf;
	struct interface *ifp;
	vrf_id_t vrf_id = VRF_DEFAULT;

	interface_update_stats();

	if (argc > 2)
		VRF_GET_ID(vrf_id, argv[3]->arg, false);

	/* All interface print. */
	vrf = vrf_lookup_by_id(vrf_id);
	FOR_ALL_INTERFACES (vrf, ifp)
		if_dump_vty(vty, ifp);

	return CMD_SUCCESS;
}


/* Show all interfaces to vty. */
DEFUN (show_interface_vrf_all,
       show_interface_vrf_all_cmd,
       "show interface vrf all",
       SHOW_STR
       "Interface status and configuration\n"
       VRF_ALL_CMD_HELP_STR)
{
	struct vrf *vrf;
	struct interface *ifp;

	interface_update_stats();

	/* All interface print. */
	RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
		FOR_ALL_INTERFACES (vrf, ifp)
			if_dump_vty(vty, ifp);

	return CMD_SUCCESS;
}

/* Show specified interface to vty. */

DEFUN (show_interface_name_vrf,
       show_interface_name_vrf_cmd,
       "show interface IFNAME vrf NAME",
       SHOW_STR
       "Interface status and configuration\n"
       "Interface name\n"
       VRF_CMD_HELP_STR)
{
	int idx_ifname = 2;
	int idx_name = 4;
	struct interface *ifp;
	vrf_id_t vrf_id;

	interface_update_stats();

	VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);

	/* Specified interface print. */
	ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
	if (ifp == NULL) {
		vty_out(vty, "%% Can't find interface %s\n",
			argv[idx_ifname]->arg);
		return CMD_WARNING;
	}
	if_dump_vty(vty, ifp);

	return CMD_SUCCESS;
}

/* Show specified interface to vty. */
DEFUN (show_interface_name_vrf_all,
       show_interface_name_vrf_all_cmd,
       "show interface IFNAME [vrf all]",
       SHOW_STR
       "Interface status and configuration\n"
       "Interface name\n"
       VRF_ALL_CMD_HELP_STR)
{
	int idx_ifname = 2;
	struct vrf *vrf;
	struct interface *ifp;
	int found = 0;

	interface_update_stats();

	/* All interface print. */
	RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
		/* Specified interface print. */
		ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf->vrf_id);
		if (ifp) {
			if_dump_vty(vty, ifp);
			found++;
		}
	}

	if (!found) {
		vty_out(vty, "%% Can't find interface %s\n",
			argv[idx_ifname]->arg);
		return CMD_WARNING;
	}

	return CMD_SUCCESS;
}


static void if_show_description(struct vty *vty, vrf_id_t vrf_id)
{
	struct vrf *vrf = vrf_lookup_by_id(vrf_id);
	struct interface *ifp;

	vty_out(vty, "Interface       Status  Protocol  Description\n");
	FOR_ALL_INTERFACES (vrf, ifp) {
		int len;

		len = vty_out(vty, "%s", ifp->name);
		vty_out(vty, "%*s", (16 - len), " ");

		if (if_is_up(ifp)) {
			vty_out(vty, "up      ");
			if (CHECK_FLAG(ifp->status,
				       ZEBRA_INTERFACE_LINKDETECTION)) {
				if (if_is_running(ifp))
					vty_out(vty, "up        ");
				else
					vty_out(vty, "down      ");
			} else {
				vty_out(vty, "unknown   ");
			}
		} else {
			vty_out(vty, "down    down      ");
		}

		if (ifp->desc)
			vty_out(vty, "%s", ifp->desc);
		vty_out(vty, "\n");
	}
}

DEFUN (show_interface_desc,
       show_interface_desc_cmd,
       "show interface description [vrf NAME]",
       SHOW_STR
       "Interface status and configuration\n"
       "Interface description\n"
       VRF_CMD_HELP_STR)
{
	vrf_id_t vrf_id = VRF_DEFAULT;

	if (argc > 3)
		VRF_GET_ID(vrf_id, argv[4]->arg, false);

	if_show_description(vty, vrf_id);

	return CMD_SUCCESS;
}


DEFUN (show_interface_desc_vrf_all,
       show_interface_desc_vrf_all_cmd,
       "show interface description vrf all",
       SHOW_STR
       "Interface status and configuration\n"
       "Interface description\n"
       VRF_ALL_CMD_HELP_STR)
{
	struct vrf *vrf;

	RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
		if (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
			vty_out(vty, "\n\tVRF %u\n\n", vrf->vrf_id);
			if_show_description(vty, vrf->vrf_id);
		}

	return CMD_SUCCESS;
}

DEFUN (multicast,
       multicast_cmd,
       "multicast",
       "Set multicast flag to interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	int ret;
	struct zebra_if *if_data;

	if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
		ret = if_set_flags(ifp, IFF_MULTICAST);
		if (ret < 0) {
			vty_out(vty, "Can't set multicast flag\n");
			return CMD_WARNING_CONFIG_FAILED;
		}
		if_refresh(ifp);
	}
	if_data = ifp->info;
	if_data->multicast = IF_ZEBRA_MULTICAST_ON;

	return CMD_SUCCESS;
}

DEFUN (no_multicast,
       no_multicast_cmd,
       "no multicast",
       NO_STR
       "Unset multicast flag to interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	int ret;
	struct zebra_if *if_data;

	if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
		ret = if_unset_flags(ifp, IFF_MULTICAST);
		if (ret < 0) {
			vty_out(vty, "Can't unset multicast flag\n");
			return CMD_WARNING_CONFIG_FAILED;
		}
		if_refresh(ifp);
	}
	if_data = ifp->info;
	if_data->multicast = IF_ZEBRA_MULTICAST_OFF;

	return CMD_SUCCESS;
}

DEFUN (linkdetect,
       linkdetect_cmd,
       "link-detect",
       "Enable link detection on interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	int if_was_operative;

	if_was_operative = if_is_no_ptm_operative(ifp);
	SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);

	/* When linkdetection is enabled, if might come down */
	if (!if_is_no_ptm_operative(ifp) && if_was_operative)
		if_down(ifp);

	/* FIXME: Will defer status change forwarding if interface
	   does not come down! */

	return CMD_SUCCESS;
}


DEFUN (no_linkdetect,
       no_linkdetect_cmd,
       "no link-detect",
       NO_STR
       "Disable link detection on interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	int if_was_operative;

	if_was_operative = if_is_no_ptm_operative(ifp);
	UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);

	/* Interface may come up after disabling link detection */
	if (if_is_operative(ifp) && !if_was_operative)
		if_up(ifp);

	/* FIXME: see linkdetect_cmd */

	return CMD_SUCCESS;
}

DEFUN (shutdown_if,
       shutdown_if_cmd,
       "shutdown",
       "Shutdown the selected interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	int ret;
	struct zebra_if *if_data;

	if (ifp->ifindex != IFINDEX_INTERNAL) {
		ret = if_unset_flags(ifp, IFF_UP);
		if (ret < 0) {
			vty_out(vty, "Can't shutdown interface\n");
			return CMD_WARNING_CONFIG_FAILED;
		}
		if_refresh(ifp);
	}
	if_data = ifp->info;
	if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;

	return CMD_SUCCESS;
}

DEFUN (no_shutdown_if,
       no_shutdown_if_cmd,
       "no shutdown",
       NO_STR
       "Shutdown the selected interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	int ret;
	struct zebra_if *if_data;

	if (ifp->ifindex != IFINDEX_INTERNAL) {
		ret = if_set_flags(ifp, IFF_UP | IFF_RUNNING);
		if (ret < 0) {
			vty_out(vty, "Can't up interface\n");
			return CMD_WARNING_CONFIG_FAILED;
		}
		if_refresh(ifp);

		/* Some addresses (in particular, IPv6 addresses on Linux) get
		 * removed when the interface goes down. They need to be
		 * readded.
		 */
		if_addr_wakeup(ifp);
	}

	if_data = ifp->info;
	if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;

	return CMD_SUCCESS;
}

DEFUN (bandwidth_if,
       bandwidth_if_cmd,
       "bandwidth (1-100000)",
       "Set bandwidth informational parameter\n"
       "Bandwidth in megabits\n")
{
	int idx_number = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	unsigned int bandwidth;

	bandwidth = strtol(argv[idx_number]->arg, NULL, 10);

	/* bandwidth range is <1-100000> */
	if (bandwidth < 1 || bandwidth > 100000) {
		vty_out(vty, "Bandwidth is invalid\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	ifp->bandwidth = bandwidth;

	/* force protocols to recalculate routes due to cost change */
	if (if_is_operative(ifp))
		zebra_interface_up_update(ifp);

	return CMD_SUCCESS;
}

DEFUN (no_bandwidth_if,
       no_bandwidth_if_cmd,
       "no bandwidth [(1-100000)]",
       NO_STR
       "Set bandwidth informational parameter\n"
       "Bandwidth in megabits\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	ifp->bandwidth = 0;

	/* force protocols to recalculate routes due to cost change */
	if (if_is_operative(ifp))
		zebra_interface_up_update(ifp);

	return CMD_SUCCESS;
}


struct cmd_node link_params_node = {
	LINK_PARAMS_NODE, "%s(config-link-params)# ", 1,
};

static void link_param_cmd_set_uint32(struct interface *ifp, uint32_t *field,
				      uint32_t type, uint32_t value)
{
	/* Update field as needed */
	if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) {
		*field = value;
		SET_PARAM(ifp->link_params, type);

		/* force protocols to update LINK STATE due to parameters change
		 */
		if (if_is_operative(ifp))
			zebra_interface_parameters_update(ifp);
	}
}
static void link_param_cmd_set_float(struct interface *ifp, float *field,
				     uint32_t type, float value)
{

	/* Update field as needed */
	if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) {
		*field = value;
		SET_PARAM(ifp->link_params, type);

		/* force protocols to update LINK STATE due to parameters change
		 */
		if (if_is_operative(ifp))
			zebra_interface_parameters_update(ifp);
	}
}

static void link_param_cmd_unset(struct interface *ifp, uint32_t type)
{
	if (ifp->link_params == NULL)
		return;

	/* Unset field */
	UNSET_PARAM(ifp->link_params, type);

	/* force protocols to update LINK STATE due to parameters change */
	if (if_is_operative(ifp))
		zebra_interface_parameters_update(ifp);
}

DEFUN_NOSH (link_params,
       link_params_cmd,
       "link-params",
       LINK_PARAMS_STR)
{
	/* vty->qobj_index stays the same @ interface pointer */
	vty->node = LINK_PARAMS_NODE;

	return CMD_SUCCESS;
}

DEFUN_NOSH (exit_link_params,
       exit_link_params_cmd,
       "exit-link-params",
       "Exit from Link Params configuration mode\n")
{
	if (vty->node == LINK_PARAMS_NODE)
		vty->node = INTERFACE_NODE;
	return CMD_SUCCESS;
}

/* Specific Traffic Engineering parameters commands */
DEFUN (link_params_enable,
       link_params_enable_cmd,
       "enable",
       "Activate link parameters on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* This command could be issue at startup, when activate MPLS TE */
	/* on a new interface or after a ON / OFF / ON toggle */
	/* In all case, TE parameters are reset to their default factory */
	if (IS_ZEBRA_DEBUG_EVENT)
		zlog_debug(
			"Link-params: enable TE link parameters on interface %s",
			ifp->name);

	if (!if_link_params_get(ifp)) {
		if (IS_ZEBRA_DEBUG_EVENT)
			zlog_debug(
				"Link-params: failed to init TE link parameters  %s",
				ifp->name);

		return CMD_WARNING_CONFIG_FAILED;
	}

	/* force protocols to update LINK STATE due to parameters change */
	if (if_is_operative(ifp))
		zebra_interface_parameters_update(ifp);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_enable,
       no_link_params_enable_cmd,
       "no enable",
       NO_STR
       "Disable link parameters on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
		   ifp->name);

	if_link_params_free(ifp);

	/* force protocols to update LINK STATE due to parameters change */
	if (if_is_operative(ifp))
		zebra_interface_parameters_update(ifp);

	return CMD_SUCCESS;
}

/* STANDARD TE metrics */
DEFUN (link_params_metric,
       link_params_metric_cmd,
       "metric (0-4294967295)",
       "Link metric for MPLS-TE purpose\n"
       "Metric value in decimal\n")
{
	int idx_number = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	uint32_t metric;

	metric = strtoul(argv[idx_number]->arg, NULL, 10);

	/* Update TE metric if needed */
	link_param_cmd_set_uint32(ifp, &iflp->te_metric, LP_TE_METRIC, metric);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_metric,
       no_link_params_metric_cmd,
       "no metric",
       NO_STR
       "Disable Link Metric on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset TE Metric */
	link_param_cmd_unset(ifp, LP_TE_METRIC);

	return CMD_SUCCESS;
}

DEFUN (link_params_maxbw,
       link_params_maxbw_cmd,
       "max-bw BANDWIDTH",
       "Maximum bandwidth that can be used\n"
       "Bytes/second (IEEE floating point format)\n")
{
	int idx_bandwidth = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);

	float bw;

	if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
		vty_out(vty, "link_params_maxbw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check that Maximum bandwidth is not lower than other bandwidth
	 * parameters */
	if ((bw <= iflp->max_rsv_bw) || (bw <= iflp->unrsv_bw[0])
	    || (bw <= iflp->unrsv_bw[1]) || (bw <= iflp->unrsv_bw[2])
	    || (bw <= iflp->unrsv_bw[3]) || (bw <= iflp->unrsv_bw[4])
	    || (bw <= iflp->unrsv_bw[5]) || (bw <= iflp->unrsv_bw[6])
	    || (bw <= iflp->unrsv_bw[7]) || (bw <= iflp->ava_bw)
	    || (bw <= iflp->res_bw) || (bw <= iflp->use_bw)) {
		vty_out(vty,
			"Maximum Bandwidth could not be lower than others bandwidth\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Maximum Bandwidth if needed */
	link_param_cmd_set_float(ifp, &iflp->max_bw, LP_MAX_BW, bw);

	return CMD_SUCCESS;
}

DEFUN (link_params_max_rsv_bw,
       link_params_max_rsv_bw_cmd,
       "max-rsv-bw BANDWIDTH",
       "Maximum bandwidth that may be reserved\n"
       "Bytes/second (IEEE floating point format)\n")
{
	int idx_bandwidth = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	float bw;

	if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
		vty_out(vty, "link_params_max_rsv_bw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check that bandwidth is not greater than maximum bandwidth parameter
	 */
	if (bw > iflp->max_bw) {
		vty_out(vty,
			"Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
			iflp->max_bw);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Maximum Reservable Bandwidth if needed */
	link_param_cmd_set_float(ifp, &iflp->max_rsv_bw, LP_MAX_RSV_BW, bw);

	return CMD_SUCCESS;
}

DEFUN (link_params_unrsv_bw,
       link_params_unrsv_bw_cmd,
       "unrsv-bw (0-7) BANDWIDTH",
       "Unreserved bandwidth at each priority level\n"
       "Priority\n"
       "Bytes/second (IEEE floating point format)\n")
{
	int idx_number = 1;
	int idx_bandwidth = 2;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	int priority;
	float bw;

	/* We don't have to consider about range check here. */
	if (sscanf(argv[idx_number]->arg, "%d", &priority) != 1) {
		vty_out(vty, "link_params_unrsv_bw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
		vty_out(vty, "link_params_unrsv_bw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check that bandwidth is not greater than maximum bandwidth parameter
	 */
	if (bw > iflp->max_bw) {
		vty_out(vty,
			"UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
			iflp->max_bw);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Unreserved Bandwidth if needed */
	link_param_cmd_set_float(ifp, &iflp->unrsv_bw[priority], LP_UNRSV_BW,
				 bw);

	return CMD_SUCCESS;
}

DEFUN (link_params_admin_grp,
       link_params_admin_grp_cmd,
       "admin-grp BITPATTERN",
       "Administrative group membership\n"
       "32-bit Hexadecimal value (e.g. 0xa1)\n")
{
	int idx_bitpattern = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	unsigned long value;

	if (sscanf(argv[idx_bitpattern]->arg, "0x%lx", &value) != 1) {
		vty_out(vty, "link_params_admin_grp: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Administrative Group if needed */
	link_param_cmd_set_uint32(ifp, &iflp->admin_grp, LP_ADM_GRP, value);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_admin_grp,
       no_link_params_admin_grp_cmd,
       "no admin-grp",
       NO_STR
       "Disable Administrative group membership on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset Admin Group */
	link_param_cmd_unset(ifp, LP_ADM_GRP);

	return CMD_SUCCESS;
}

/* RFC5392 & RFC5316: INTER-AS */
DEFUN (link_params_inter_as,
       link_params_inter_as_cmd,
       "neighbor A.B.C.D as (1-4294967295)",
       "Configure remote ASBR information (Neighbor IP address and AS number)\n"
       "Remote IP address in dot decimal A.B.C.D\n"
       "Remote AS number\n"
       "AS number in the range <1-4294967295>\n")
{
	int idx_ipv4 = 1;
	int idx_number = 3;

	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	struct in_addr addr;
	uint32_t as;

	if (!inet_aton(argv[idx_ipv4]->arg, &addr)) {
		vty_out(vty, "Please specify Router-Addr by A.B.C.D\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	as = strtoul(argv[idx_number]->arg, NULL, 10);

	/* Update Remote IP and Remote AS fields if needed */
	if (IS_PARAM_UNSET(iflp, LP_RMT_AS) || iflp->rmt_as != as
	    || iflp->rmt_ip.s_addr != addr.s_addr) {

		iflp->rmt_as = as;
		iflp->rmt_ip.s_addr = addr.s_addr;
		SET_PARAM(iflp, LP_RMT_AS);

		/* force protocols to update LINK STATE due to parameters change
		 */
		if (if_is_operative(ifp))
			zebra_interface_parameters_update(ifp);
	}
	return CMD_SUCCESS;
}

DEFUN (no_link_params_inter_as,
       no_link_params_inter_as_cmd,
       "no neighbor",
       NO_STR
       "Remove Neighbor IP address and AS number for Inter-AS TE\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);

	/* Reset Remote IP and AS neighbor */
	iflp->rmt_as = 0;
	iflp->rmt_ip.s_addr = 0;
	UNSET_PARAM(iflp, LP_RMT_AS);

	/* force protocols to update LINK STATE due to parameters change */
	if (if_is_operative(ifp))
		zebra_interface_parameters_update(ifp);

	return CMD_SUCCESS;
}

/* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
 * draft-ietf-isis-metric-extensions-07.txt */
DEFUN (link_params_delay,
       link_params_delay_cmd,
       "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
       "Unidirectional Average Link Delay\n"
       "Average delay in micro-second as decimal (0...16777215)\n"
       "Minimum delay\n"
       "Minimum delay in micro-second as decimal (0...16777215)\n"
       "Maximum delay\n"
       "Maximum delay in micro-second as decimal (0...16777215)\n")
{
	/* Get and Check new delay values */
	uint32_t delay = 0, low = 0, high = 0;
	delay = strtoul(argv[1]->arg, NULL, 10);
	if (argc == 6) {
		low = strtoul(argv[3]->arg, NULL, 10);
		high = strtoul(argv[5]->arg, NULL, 10);
	}

	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	uint8_t update = 0;

	if (argc == 2) {
		/* Check new delay value against old Min and Max delays if set
		 */
		if (IS_PARAM_SET(iflp, LP_MM_DELAY)
		    && (delay <= iflp->min_delay || delay >= iflp->max_delay)) {
			vty_out(vty,
				"Average delay should be comprise between Min (%d) and Max (%d) delay\n",
				iflp->min_delay, iflp->max_delay);
			return CMD_WARNING_CONFIG_FAILED;
		}
		/* Update delay if value is not set or change */
		if (IS_PARAM_UNSET(iflp, LP_DELAY) || iflp->av_delay != delay) {
			iflp->av_delay = delay;
			SET_PARAM(iflp, LP_DELAY);
			update = 1;
		}
		/* Unset Min and Max delays if already set */
		if (IS_PARAM_SET(iflp, LP_MM_DELAY)) {
			iflp->min_delay = 0;
			iflp->max_delay = 0;
			UNSET_PARAM(iflp, LP_MM_DELAY);
			update = 1;
		}
	} else {
		/* Check new delays value coherency */
		if (delay <= low || delay >= high) {
			vty_out(vty,
				"Average delay should be comprise between Min (%d) and Max (%d) delay\n",
				low, high);
			return CMD_WARNING_CONFIG_FAILED;
		}
		/* Update Delays if needed */
		if (IS_PARAM_UNSET(iflp, LP_DELAY)
		    || IS_PARAM_UNSET(iflp, LP_MM_DELAY)
		    || iflp->av_delay != delay || iflp->min_delay != low
		    || iflp->max_delay != high) {
			iflp->av_delay = delay;
			SET_PARAM(iflp, LP_DELAY);
			iflp->min_delay = low;
			iflp->max_delay = high;
			SET_PARAM(iflp, LP_MM_DELAY);
			update = 1;
		}
	}

	/* force protocols to update LINK STATE due to parameters change */
	if (update == 1 && if_is_operative(ifp))
		zebra_interface_parameters_update(ifp);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_delay,
       no_link_params_delay_cmd,
       "no delay",
       NO_STR
       "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);

	/* Unset Delays */
	iflp->av_delay = 0;
	UNSET_PARAM(iflp, LP_DELAY);
	iflp->min_delay = 0;
	iflp->max_delay = 0;
	UNSET_PARAM(iflp, LP_MM_DELAY);

	/* force protocols to update LINK STATE due to parameters change */
	if (if_is_operative(ifp))
		zebra_interface_parameters_update(ifp);

	return CMD_SUCCESS;
}

DEFUN (link_params_delay_var,
       link_params_delay_var_cmd,
       "delay-variation (0-16777215)",
       "Unidirectional Link Delay Variation\n"
       "delay variation in micro-second as decimal (0...16777215)\n")
{
	int idx_number = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	uint32_t value;

	value = strtoul(argv[idx_number]->arg, NULL, 10);

	/* Update Delay Variation if needed */
	link_param_cmd_set_uint32(ifp, &iflp->delay_var, LP_DELAY_VAR, value);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_delay_var,
       no_link_params_delay_var_cmd,
       "no delay-variation",
       NO_STR
       "Disable Unidirectional Delay Variation on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset Delay Variation */
	link_param_cmd_unset(ifp, LP_DELAY_VAR);

	return CMD_SUCCESS;
}

DEFUN (link_params_pkt_loss,
       link_params_pkt_loss_cmd,
       "packet-loss PERCENTAGE",
       "Unidirectional Link Packet Loss\n"
       "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
{
	int idx_percentage = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	float fval;

	if (sscanf(argv[idx_percentage]->arg, "%g", &fval) != 1) {
		vty_out(vty, "link_params_pkt_loss: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	if (fval > MAX_PKT_LOSS)
		fval = MAX_PKT_LOSS;

	/* Update Packet Loss if needed */
	link_param_cmd_set_float(ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_pkt_loss,
       no_link_params_pkt_loss_cmd,
       "no packet-loss",
       NO_STR
       "Disable Unidirectional Link Packet Loss on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset Packet Loss */
	link_param_cmd_unset(ifp, LP_PKT_LOSS);

	return CMD_SUCCESS;
}

DEFUN (link_params_res_bw,
       link_params_res_bw_cmd,
       "res-bw BANDWIDTH",
       "Unidirectional Residual Bandwidth\n"
       "Bytes/second (IEEE floating point format)\n")
{
	int idx_bandwidth = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	float bw;

	if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
		vty_out(vty, "link_params_res_bw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check that bandwidth is not greater than maximum bandwidth parameter
	 */
	if (bw > iflp->max_bw) {
		vty_out(vty,
			"Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
			iflp->max_bw);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Residual Bandwidth if needed */
	link_param_cmd_set_float(ifp, &iflp->res_bw, LP_RES_BW, bw);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_res_bw,
       no_link_params_res_bw_cmd,
       "no res-bw",
       NO_STR
       "Disable Unidirectional Residual Bandwidth on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset Residual Bandwidth */
	link_param_cmd_unset(ifp, LP_RES_BW);

	return CMD_SUCCESS;
}

DEFUN (link_params_ava_bw,
       link_params_ava_bw_cmd,
       "ava-bw BANDWIDTH",
       "Unidirectional Available Bandwidth\n"
       "Bytes/second (IEEE floating point format)\n")
{
	int idx_bandwidth = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	float bw;

	if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
		vty_out(vty, "link_params_ava_bw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check that bandwidth is not greater than maximum bandwidth parameter
	 */
	if (bw > iflp->max_bw) {
		vty_out(vty,
			"Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
			iflp->max_bw);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Residual Bandwidth if needed */
	link_param_cmd_set_float(ifp, &iflp->ava_bw, LP_AVA_BW, bw);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_ava_bw,
       no_link_params_ava_bw_cmd,
       "no ava-bw",
       NO_STR
       "Disable Unidirectional Available Bandwidth on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset Available Bandwidth */
	link_param_cmd_unset(ifp, LP_AVA_BW);

	return CMD_SUCCESS;
}

DEFUN (link_params_use_bw,
       link_params_use_bw_cmd,
       "use-bw BANDWIDTH",
       "Unidirectional Utilised Bandwidth\n"
       "Bytes/second (IEEE floating point format)\n")
{
	int idx_bandwidth = 1;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct if_link_params *iflp = if_link_params_get(ifp);
	float bw;

	if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
		vty_out(vty, "link_params_use_bw: fscanf: %s\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check that bandwidth is not greater than maximum bandwidth parameter
	 */
	if (bw > iflp->max_bw) {
		vty_out(vty,
			"Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
			iflp->max_bw);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Update Utilized Bandwidth if needed */
	link_param_cmd_set_float(ifp, &iflp->use_bw, LP_USE_BW, bw);

	return CMD_SUCCESS;
}

DEFUN (no_link_params_use_bw,
       no_link_params_use_bw_cmd,
       "no use-bw",
       NO_STR
       "Disable Unidirectional Utilised Bandwidth on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	/* Unset Utilised Bandwidth */
	link_param_cmd_unset(ifp, LP_USE_BW);

	return CMD_SUCCESS;
}

static int ip_address_install(struct vty *vty, struct interface *ifp,
			      const char *addr_str, const char *peer_str,
			      const char *label)
{
	struct zebra_if *if_data;
	struct prefix_ipv4 lp, pp;
	struct connected *ifc;
	struct prefix_ipv4 *p;
	int ret;

	if_data = ifp->info;

	ret = str2prefix_ipv4(addr_str, &lp);
	if (ret <= 0) {
		vty_out(vty, "%% Malformed address \n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	if (ipv4_martian(&lp.prefix)) {
		vty_out(vty, "%% Invalid address\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	if (peer_str) {
		if (lp.prefixlen != 32) {
			vty_out(vty,
				"%% Local prefix length for P-t-P address must be /32\n");
			return CMD_WARNING_CONFIG_FAILED;
		}

		ret = str2prefix_ipv4(peer_str, &pp);
		if (ret <= 0) {
			vty_out(vty, "%% Malformed peer address\n");
			return CMD_WARNING_CONFIG_FAILED;
		}
	}

	ifc = connected_check_ptp(ifp, &lp, peer_str ? &pp : NULL);
	if (!ifc) {
		ifc = connected_new();
		ifc->ifp = ifp;

		/* Address. */
		p = prefix_ipv4_new();
		*p = lp;
		ifc->address = (struct prefix *)p;

		if (peer_str) {
			SET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
			p = prefix_ipv4_new();
			*p = pp;
			ifc->destination = (struct prefix *)p;
		} else if (p->prefixlen <= IPV4_MAX_PREFIXLEN - 2) {
			p = prefix_ipv4_new();
			*p = lp;
			p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,
							       p->prefixlen);
			ifc->destination = (struct prefix *)p;
		}

		/* Label. */
		if (label)
			ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);

		/* Add to linked list. */
		listnode_add(ifp->connected, ifc);
	}

	/* This address is configured from zebra. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
		SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);

	/* In case of this route need to install kernel. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
	    && CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)
	    && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) {
		/* Some system need to up the interface to set IP address. */
		if (!if_is_up(ifp)) {
			if_set_flags(ifp, IFF_UP | IFF_RUNNING);
			if_refresh(ifp);
		}

		ret = if_set_prefix(ifp, ifc);
		if (ret < 0) {
			vty_out(vty, "%% Can't set interface IP address: %s.\n",
				safe_strerror(errno));
			return CMD_WARNING_CONFIG_FAILED;
		}

		SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
		/* The address will be advertised to zebra clients when the
		 * notification
		 * from the kernel has been received.
		 * It will also be added to the subnet chain list, then. */
	}

	return CMD_SUCCESS;
}

static int ip_address_uninstall(struct vty *vty, struct interface *ifp,
				const char *addr_str, const char *peer_str,
				const char *label)
{
	struct prefix_ipv4 lp, pp;
	struct connected *ifc;
	int ret;

	/* Convert to prefix structure. */
	ret = str2prefix_ipv4(addr_str, &lp);
	if (ret <= 0) {
		vty_out(vty, "%% Malformed address \n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	if (peer_str) {
		if (lp.prefixlen != 32) {
			vty_out(vty,
				"%% Local prefix length for P-t-P address must be /32\n");
			return CMD_WARNING_CONFIG_FAILED;
		}

		ret = str2prefix_ipv4(peer_str, &pp);
		if (ret <= 0) {
			vty_out(vty, "%% Malformed peer address\n");
			return CMD_WARNING_CONFIG_FAILED;
		}
	}

	/* Check current interface address. */
	ifc = connected_check_ptp(ifp, &lp, peer_str ? &pp : NULL);
	if (!ifc) {
		vty_out(vty, "%% Can't find address\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* This is not configured address. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
		return CMD_WARNING_CONFIG_FAILED;

	UNSET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);

	/* This is not real address or interface is not active. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
	    || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
		listnode_delete(ifp->connected, ifc);
		connected_free(ifc);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* This is real route. */
	ret = if_unset_prefix(ifp, ifc);
	if (ret < 0) {
		vty_out(vty, "%% Can't unset interface IP address: %s.\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}
	UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
	/* we will receive a kernel notification about this route being removed.
	 * this will trigger its removal from the connected list. */
	return CMD_SUCCESS;
}

DEFUN (ip_address,
       ip_address_cmd,
       "ip address A.B.C.D/M",
       "Interface Internet Protocol config commands\n"
       "Set the IP address of an interface\n"
       "IP address (e.g. 10.0.0.1/8)\n")
{
	int idx_ipv4_prefixlen = 2;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ip_address_install(vty, ifp, argv[idx_ipv4_prefixlen]->arg, NULL,
				  NULL);
}

DEFUN (no_ip_address,
       no_ip_address_cmd,
       "no ip address A.B.C.D/M",
       NO_STR
       "Interface Internet Protocol config commands\n"
       "Set the IP address of an interface\n"
       "IP Address (e.g. 10.0.0.1/8)\n")
{
	int idx_ipv4_prefixlen = 3;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ip_address_uninstall(vty, ifp, argv[idx_ipv4_prefixlen]->arg,
				    NULL, NULL);
}

DEFUN(ip_address_peer,
      ip_address_peer_cmd,
      "ip address A.B.C.D peer A.B.C.D/M",
      "Interface Internet Protocol config commands\n"
      "Set the IP address of an interface\n"
      "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
      "Specify P-t-P address\n"
      "Peer IP address (e.g. 10.0.0.1/8)\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ip_address_install(vty, ifp, argv[2]->arg, argv[4]->arg, NULL);
}

DEFUN(no_ip_address_peer,
      no_ip_address_peer_cmd,
      "no ip address A.B.C.D peer A.B.C.D/M",
      NO_STR
      "Interface Internet Protocol config commands\n"
      "Set the IP address of an interface\n"
      "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
      "Specify P-t-P address\n"
      "Peer IP address (e.g. 10.0.0.1/8)\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ip_address_uninstall(vty, ifp, argv[3]->arg, argv[5]->arg, NULL);
}

#ifdef HAVE_NETLINK
DEFUN (ip_address_label,
       ip_address_label_cmd,
       "ip address A.B.C.D/M label LINE",
       "Interface Internet Protocol config commands\n"
       "Set the IP address of an interface\n"
       "IP address (e.g. 10.0.0.1/8)\n"
       "Label of this address\n"
       "Label\n")
{
	int idx_ipv4_prefixlen = 2;
	int idx_line = 4;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ip_address_install(vty, ifp, argv[idx_ipv4_prefixlen]->arg, NULL,
				  argv[idx_line]->arg);
}

DEFUN (no_ip_address_label,
       no_ip_address_label_cmd,
       "no ip address A.B.C.D/M label LINE",
       NO_STR
       "Interface Internet Protocol config commands\n"
       "Set the IP address of an interface\n"
       "IP address (e.g. 10.0.0.1/8)\n"
       "Label of this address\n"
       "Label\n")
{
	int idx_ipv4_prefixlen = 3;
	int idx_line = 5;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ip_address_uninstall(vty, ifp, argv[idx_ipv4_prefixlen]->arg,
				    NULL, argv[idx_line]->arg);
}
#endif /* HAVE_NETLINK */

static int ipv6_address_install(struct vty *vty, struct interface *ifp,
				const char *addr_str, const char *peer_str,
				const char *label, int secondary)
{
	struct zebra_if *if_data;
	struct prefix_ipv6 cp;
	struct connected *ifc;
	struct prefix_ipv6 *p;
	int ret;

	if_data = ifp->info;

	ret = str2prefix_ipv6(addr_str, &cp);
	if (ret <= 0) {
		vty_out(vty, "%% Malformed address \n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	if (ipv6_martian(&cp.prefix)) {
		vty_out(vty, "%% Invalid address\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	ifc = connected_check(ifp, (struct prefix *)&cp);
	if (!ifc) {
		ifc = connected_new();
		ifc->ifp = ifp;

		/* Address. */
		p = prefix_ipv6_new();
		*p = cp;
		ifc->address = (struct prefix *)p;

		/* Secondary. */
		if (secondary)
			SET_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY);

		/* Label. */
		if (label)
			ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);

		/* Add to linked list. */
		listnode_add(ifp->connected, ifc);
	}

	/* This address is configured from zebra. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
		SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);

	/* In case of this route need to install kernel. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
	    && CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)
	    && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) {
		/* Some system need to up the interface to set IP address. */
		if (!if_is_up(ifp)) {
			if_set_flags(ifp, IFF_UP | IFF_RUNNING);
			if_refresh(ifp);
		}

		ret = if_prefix_add_ipv6(ifp, ifc);

		if (ret < 0) {
			vty_out(vty, "%% Can't set interface IP address: %s.\n",
				safe_strerror(errno));
			return CMD_WARNING_CONFIG_FAILED;
		}

		SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
		/* The address will be advertised to zebra clients when the
		 * notification
		 * from the kernel has been received. */
	}

	return CMD_SUCCESS;
}

/* Return true if an ipv6 address is configured on ifp */
int ipv6_address_configured(struct interface *ifp)
{
	struct connected *connected;
	struct listnode *node;

	for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected))
		if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
		    && (connected->address->family == AF_INET6))
			return 1;

	return 0;
}

static int ipv6_address_uninstall(struct vty *vty, struct interface *ifp,
				  const char *addr_str, const char *peer_str,
				  const char *label, int secondry)
{
	struct prefix_ipv6 cp;
	struct connected *ifc;
	int ret;

	/* Convert to prefix structure. */
	ret = str2prefix_ipv6(addr_str, &cp);
	if (ret <= 0) {
		vty_out(vty, "%% Malformed address \n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* Check current interface address. */
	ifc = connected_check(ifp, (struct prefix *)&cp);
	if (!ifc) {
		vty_out(vty, "%% Can't find address\n");
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* This is not configured address. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
		return CMD_WARNING_CONFIG_FAILED;

	UNSET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);

	/* This is not real address or interface is not active. */
	if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
	    || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
		listnode_delete(ifp->connected, ifc);
		connected_free(ifc);
		return CMD_WARNING_CONFIG_FAILED;
	}

	/* This is real route. */
	ret = if_prefix_delete_ipv6(ifp, ifc);
	if (ret < 0) {
		vty_out(vty, "%% Can't unset interface IP address: %s.\n",
			safe_strerror(errno));
		return CMD_WARNING_CONFIG_FAILED;
	}

	UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
	/* This information will be propagated to the zclients when the
	 * kernel notification is received. */
	return CMD_SUCCESS;
}

DEFUN (ipv6_address,
       ipv6_address_cmd,
       "ipv6 address X:X::X:X/M",
       "Interface IPv6 config commands\n"
       "Set the IP address of an interface\n"
       "IPv6 address (e.g. 3ffe:506::1/48)\n")
{
	int idx_ipv6_prefixlen = 2;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ipv6_address_install(vty, ifp, argv[idx_ipv6_prefixlen]->arg,
				    NULL, NULL, 0);
}

DEFUN (no_ipv6_address,
       no_ipv6_address_cmd,
       "no ipv6 address X:X::X:X/M",
       NO_STR
       "Interface IPv6 config commands\n"
       "Set the IP address of an interface\n"
       "IPv6 address (e.g. 3ffe:506::1/48)\n")
{
	int idx_ipv6_prefixlen = 3;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	return ipv6_address_uninstall(vty, ifp, argv[idx_ipv6_prefixlen]->arg,
				      NULL, NULL, 0);
}

static int link_params_config_write(struct vty *vty, struct interface *ifp)
{
	int i;

	if ((ifp == NULL) || !HAS_LINK_PARAMS(ifp))
		return -1;

	struct if_link_params *iflp = ifp->link_params;

	vty_out(vty, " link-params\n");
	vty_out(vty, "  enable\n");
	if (IS_PARAM_SET(iflp, LP_TE_METRIC) && iflp->te_metric != ifp->metric)
		vty_out(vty, "  metric %u\n", iflp->te_metric);
	if (IS_PARAM_SET(iflp, LP_MAX_BW) && iflp->max_bw != iflp->default_bw)
		vty_out(vty, "  max-bw %g\n", iflp->max_bw);
	if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW)
	    && iflp->max_rsv_bw != iflp->default_bw)
		vty_out(vty, "  max-rsv-bw %g\n", iflp->max_rsv_bw);
	if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) {
		for (i = 0; i < 8; i++)
			if (iflp->unrsv_bw[i] != iflp->default_bw)
				vty_out(vty, "  unrsv-bw %d %g\n", i,
					iflp->unrsv_bw[i]);
	}
	if (IS_PARAM_SET(iflp, LP_ADM_GRP))
		vty_out(vty, "  admin-grp 0x%x\n", iflp->admin_grp);
	if (IS_PARAM_SET(iflp, LP_DELAY)) {
		vty_out(vty, "  delay %u", iflp->av_delay);
		if (IS_PARAM_SET(iflp, LP_MM_DELAY)) {
			vty_out(vty, " min %u", iflp->min_delay);
			vty_out(vty, " max %u", iflp->max_delay);
		}
		vty_out(vty, "\n");
	}
	if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
		vty_out(vty, "  delay-variation %u\n", iflp->delay_var);
	if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
		vty_out(vty, "  packet-loss %g\n", iflp->pkt_loss);
	if (IS_PARAM_SET(iflp, LP_AVA_BW))
		vty_out(vty, "  ava-bw %g\n", iflp->ava_bw);
	if (IS_PARAM_SET(iflp, LP_RES_BW))
		vty_out(vty, "  res-bw %g\n", iflp->res_bw);
	if (IS_PARAM_SET(iflp, LP_USE_BW))
		vty_out(vty, "  use-bw %g\n", iflp->use_bw);
	if (IS_PARAM_SET(iflp, LP_RMT_AS))
		vty_out(vty, "  neighbor %s as %u\n", inet_ntoa(iflp->rmt_ip),
			iflp->rmt_as);
	vty_out(vty, "  exit-link-params\n");
	return 0;
}

static int if_config_write(struct vty *vty)
{
	struct vrf *vrf0;
	struct interface *ifp;

	zebra_ptm_write(vty);

	RB_FOREACH (vrf0, vrf_name_head, &vrfs_by_name)
		FOR_ALL_INTERFACES (vrf0, ifp) {
			struct zebra_if *if_data;
			struct listnode *addrnode;
			struct connected *ifc;
			struct prefix *p;
			struct vrf *vrf;

			if_data = ifp->info;
			vrf = vrf_lookup_by_id(ifp->vrf_id);

			if (ifp->vrf_id == VRF_DEFAULT)
				vty_frame(vty, "interface %s\n", ifp->name);
			else
				vty_frame(vty, "interface %s vrf %s\n",
					  ifp->name, vrf->name);

			if (if_data) {
				if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
					vty_out(vty, " shutdown\n");

				zebra_ptm_if_write(vty, if_data);
			}

			if (ifp->desc)
				vty_out(vty, " description %s\n", ifp->desc);

			/* Assign bandwidth here to avoid unnecessary interface
			   flap
			   while processing config script */
			if (ifp->bandwidth != 0)
				vty_out(vty, " bandwidth %u\n", ifp->bandwidth);

			if (!CHECK_FLAG(ifp->status,
					ZEBRA_INTERFACE_LINKDETECTION))
				vty_out(vty, " no link-detect\n");

			for (ALL_LIST_ELEMENTS_RO(ifp->connected, addrnode,
						  ifc)) {
				if (CHECK_FLAG(ifc->conf,
					       ZEBRA_IFC_CONFIGURED)) {
					char buf[INET6_ADDRSTRLEN];
					p = ifc->address;
					vty_out(vty, " ip%s address %s",
						p->family == AF_INET ? ""
								     : "v6",
						inet_ntop(p->family,
							  &p->u.prefix, buf,
							  sizeof(buf)));
					if (CONNECTED_PEER(ifc)) {
						p = ifc->destination;
						vty_out(vty, " peer %s",
							inet_ntop(p->family,
								  &p->u.prefix,
								  buf,
								  sizeof(buf)));
					}
					vty_out(vty, "/%d", p->prefixlen);

					if (ifc->label)
						vty_out(vty, " label %s",
							ifc->label);

					vty_out(vty, "\n");
				}
			}

			if (if_data) {
				if (if_data->multicast
				    != IF_ZEBRA_MULTICAST_UNSPEC)
					vty_out(vty, " %smulticast\n",
						if_data->multicast
								== IF_ZEBRA_MULTICAST_ON
							? ""
							: "no ");
			}

			hook_call(zebra_if_config_wr, vty, ifp);

			link_params_config_write(vty, ifp);

			vty_endframe(vty, "!\n");
		}
	return 0;
}

/* Allocate and initialize interface vector. */
void zebra_if_init(void)
{
	/* Initialize interface and new hook. */
	hook_register_prio(if_add, 0, if_zebra_new_hook);
	hook_register_prio(if_del, 0, if_zebra_delete_hook);

	/* Install configuration write function. */
	install_node(&interface_node, if_config_write);
	install_node(&link_params_node, NULL);
	if_cmd_init();

	install_element(VIEW_NODE, &show_interface_cmd);
	install_element(VIEW_NODE, &show_interface_vrf_all_cmd);
	install_element(VIEW_NODE, &show_interface_name_vrf_cmd);
	install_element(VIEW_NODE, &show_interface_name_vrf_all_cmd);

	install_element(ENABLE_NODE, &show_interface_desc_cmd);
	install_element(ENABLE_NODE, &show_interface_desc_vrf_all_cmd);
	install_element(INTERFACE_NODE, &multicast_cmd);
	install_element(INTERFACE_NODE, &no_multicast_cmd);
	install_element(INTERFACE_NODE, &linkdetect_cmd);
	install_element(INTERFACE_NODE, &no_linkdetect_cmd);
	install_element(INTERFACE_NODE, &shutdown_if_cmd);
	install_element(INTERFACE_NODE, &no_shutdown_if_cmd);
	install_element(INTERFACE_NODE, &bandwidth_if_cmd);
	install_element(INTERFACE_NODE, &no_bandwidth_if_cmd);
	install_element(INTERFACE_NODE, &ip_address_cmd);
	install_element(INTERFACE_NODE, &no_ip_address_cmd);
	install_element(INTERFACE_NODE, &ip_address_peer_cmd);
	install_element(INTERFACE_NODE, &no_ip_address_peer_cmd);
	install_element(INTERFACE_NODE, &ipv6_address_cmd);
	install_element(INTERFACE_NODE, &no_ipv6_address_cmd);
#ifdef HAVE_NETLINK
	install_element(INTERFACE_NODE, &ip_address_label_cmd);
	install_element(INTERFACE_NODE, &no_ip_address_label_cmd);
#endif /* HAVE_NETLINK */
	install_element(INTERFACE_NODE, &link_params_cmd);
	install_default(LINK_PARAMS_NODE);
	install_element(LINK_PARAMS_NODE, &link_params_enable_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_enable_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_metric_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_metric_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_maxbw_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_max_rsv_bw_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_unrsv_bw_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_admin_grp_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_admin_grp_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_inter_as_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_inter_as_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_delay_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_delay_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_delay_var_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_pkt_loss_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_pkt_loss_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_ava_bw_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_ava_bw_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_res_bw_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_res_bw_cmd);
	install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
	install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd);
	install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
}