1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
|
/** @file
Implementation of Neighbor Discovery support routines.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Ip6Impl.h"
EFI_MAC_ADDRESS mZeroMacAddress;
/**
Update the ReachableTime in IP6 service binding instance data, in milliseconds.
@param[in, out] IpSb Points to the IP6_SERVICE.
**/
VOID
Ip6UpdateReachableTime (
IN OUT IP6_SERVICE *IpSb
)
{
UINT32 Random;
Random = (NetRandomInitSeed () / 4294967295UL) * IP6_RANDOM_FACTOR_SCALE;
Random = Random + IP6_MIN_RANDOM_FACTOR_SCALED;
IpSb->ReachableTime = (IpSb->BaseReachableTime * Random) / IP6_RANDOM_FACTOR_SCALE;
}
/**
Build a array of EFI_IP6_NEIGHBOR_CACHE to be returned to the caller. The number
of EFI_IP6_NEIGHBOR_CACHE is also returned.
@param[in] IpInstance The pointer to IP6_PROTOCOL instance.
@param[out] NeighborCount The number of returned neighbor cache entries.
@param[out] NeighborCache The pointer to the array of EFI_IP6_NEIGHBOR_CACHE.
@retval EFI_SUCCESS The EFI_IP6_NEIGHBOR_CACHE successfully built.
@retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the route table.
**/
EFI_STATUS
Ip6BuildEfiNeighborCache (
IN IP6_PROTOCOL *IpInstance,
OUT UINT32 *NeighborCount,
OUT EFI_IP6_NEIGHBOR_CACHE **NeighborCache
)
{
IP6_NEIGHBOR_ENTRY *Neighbor;
LIST_ENTRY *Entry;
IP6_SERVICE *IpSb;
UINT32 Count;
EFI_IP6_NEIGHBOR_CACHE *EfiNeighborCache;
EFI_IP6_NEIGHBOR_CACHE *NeighborCacheTmp;
NET_CHECK_SIGNATURE (IpInstance, IP6_PROTOCOL_SIGNATURE);
ASSERT (NeighborCount != NULL && NeighborCache != NULL);
IpSb = IpInstance->Service;
Count = 0;
NET_LIST_FOR_EACH (Entry, &IpSb->NeighborTable) {
Count++;
}
if (Count == 0) {
return EFI_SUCCESS;
}
NeighborCacheTmp = AllocatePool (Count * sizeof (EFI_IP6_NEIGHBOR_CACHE));
if (NeighborCacheTmp == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*NeighborCount = Count;
Count = 0;
NET_LIST_FOR_EACH (Entry, &IpSb->NeighborTable) {
Neighbor = NET_LIST_USER_STRUCT (Entry, IP6_NEIGHBOR_ENTRY, Link);
EfiNeighborCache = NeighborCacheTmp + Count;
EfiNeighborCache->State = Neighbor->State;
IP6_COPY_ADDRESS (&EfiNeighborCache->Neighbor, &Neighbor->Neighbor);
IP6_COPY_LINK_ADDRESS (&EfiNeighborCache->LinkAddress, &Neighbor->LinkAddress);
Count++;
}
ASSERT (*NeighborCount == Count);
*NeighborCache = NeighborCacheTmp;
return EFI_SUCCESS;
}
/**
Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number
of prefix entries is also returned.
@param[in] IpInstance The pointer to IP6_PROTOCOL instance.
@param[out] PrefixCount The number of returned prefix entries.
@param[out] PrefixTable The pointer to the array of PrefixTable.
@retval EFI_SUCCESS The prefix table successfully built.
@retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the prefix table.
**/
EFI_STATUS
Ip6BuildPrefixTable (
IN IP6_PROTOCOL *IpInstance,
OUT UINT32 *PrefixCount,
OUT EFI_IP6_ADDRESS_INFO **PrefixTable
)
{
LIST_ENTRY *Entry;
IP6_SERVICE *IpSb;
UINT32 Count;
IP6_PREFIX_LIST_ENTRY *PrefixList;
EFI_IP6_ADDRESS_INFO *EfiPrefix;
EFI_IP6_ADDRESS_INFO *PrefixTableTmp;
NET_CHECK_SIGNATURE (IpInstance, IP6_PROTOCOL_SIGNATURE);
ASSERT (PrefixCount != NULL && PrefixTable != NULL);
IpSb = IpInstance->Service;
Count = 0;
NET_LIST_FOR_EACH (Entry, &IpSb->OnlinkPrefix) {
Count++;
}
if (Count == 0) {
return EFI_SUCCESS;
}
PrefixTableTmp = AllocatePool (Count * sizeof (EFI_IP6_ADDRESS_INFO));
if (PrefixTableTmp == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*PrefixCount = Count;
Count = 0;
NET_LIST_FOR_EACH (Entry, &IpSb->OnlinkPrefix) {
PrefixList = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link);
EfiPrefix = PrefixTableTmp + Count;
IP6_COPY_ADDRESS (&EfiPrefix->Address, &PrefixList->Prefix);
EfiPrefix->PrefixLength = PrefixList->PrefixLength;
Count++;
}
ASSERT (*PrefixCount == Count);
*PrefixTable = PrefixTableTmp;
return EFI_SUCCESS;
}
/**
Allocate and initialize a IP6 prefix list entry.
@param[in] IpSb The pointer to IP6_SERVICE instance.
@param[in] OnLinkOrAuto If TRUE, the entry is created for the on link prefix list.
Otherwise, it is created for the autoconfiguration prefix list.
@param[in] ValidLifetime The length of time in seconds that the prefix
is valid for the purpose of on-link determination.
@param[in] PreferredLifetime The length of time in seconds that addresses
generated from the prefix via stateless address
autoconfiguration remain preferred.
@param[in] PrefixLength The prefix length of the Prefix.
@param[in] Prefix The prefix address.
@return NULL if it failed to allocate memory for the prefix node. Otherwise, point
to the created or existing prefix list entry.
**/
IP6_PREFIX_LIST_ENTRY *
Ip6CreatePrefixListEntry (
IN IP6_SERVICE *IpSb,
IN BOOLEAN OnLinkOrAuto,
IN UINT32 ValidLifetime,
IN UINT32 PreferredLifetime,
IN UINT8 PrefixLength,
IN EFI_IPv6_ADDRESS *Prefix
)
{
IP6_PREFIX_LIST_ENTRY *PrefixEntry;
IP6_ROUTE_ENTRY *RtEntry;
LIST_ENTRY *ListHead;
LIST_ENTRY *Entry;
IP6_PREFIX_LIST_ENTRY *TmpPrefixEntry;
if (Prefix == NULL || PreferredLifetime > ValidLifetime || PrefixLength >= IP6_PREFIX_NUM) {
return NULL;
}
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
PrefixEntry = Ip6FindPrefixListEntry (
IpSb,
OnLinkOrAuto,
PrefixLength,
Prefix
);
if (PrefixEntry != NULL) {
PrefixEntry->RefCnt ++;
return PrefixEntry;
}
PrefixEntry = AllocatePool (sizeof (IP6_PREFIX_LIST_ENTRY));
if (PrefixEntry == NULL) {
return NULL;
}
PrefixEntry->RefCnt = 1;
PrefixEntry->ValidLifetime = ValidLifetime;
PrefixEntry->PreferredLifetime = PreferredLifetime;
PrefixEntry->PrefixLength = PrefixLength;
IP6_COPY_ADDRESS (&PrefixEntry->Prefix, Prefix);
ListHead = OnLinkOrAuto ? &IpSb->OnlinkPrefix : &IpSb->AutonomousPrefix;
//
// Create a direct route entry for on-link prefix and insert to route area.
//
if (OnLinkOrAuto) {
RtEntry = Ip6CreateRouteEntry (Prefix, PrefixLength, NULL);
if (RtEntry == NULL) {
FreePool (PrefixEntry);
return NULL;
}
RtEntry->Flag = IP6_DIRECT_ROUTE;
InsertHeadList (&IpSb->RouteTable->RouteArea[PrefixLength], &RtEntry->Link);
IpSb->RouteTable->TotalNum++;
}
//
// Insert the prefix entry in the order that a prefix with longer prefix length
// is put ahead in the list.
//
NET_LIST_FOR_EACH (Entry, ListHead) {
TmpPrefixEntry = NET_LIST_USER_STRUCT(Entry, IP6_PREFIX_LIST_ENTRY, Link);
if (TmpPrefixEntry->PrefixLength < PrefixEntry->PrefixLength) {
break;
}
}
NetListInsertBefore (Entry, &PrefixEntry->Link);
return PrefixEntry;
}
/**
Destory a IP6 prefix list entry.
@param[in] IpSb The pointer to IP6_SERVICE instance.
@param[in] PrefixEntry The to be destroyed prefix list entry.
@param[in] OnLinkOrAuto If TRUE, the entry is removed from on link prefix list.
Otherwise remove from autoconfiguration prefix list.
@param[in] ImmediateDelete If TRUE, remove the entry directly.
Otherwise, check the reference count to see whether
it should be removed.
**/
VOID
Ip6DestroyPrefixListEntry (
IN IP6_SERVICE *IpSb,
IN IP6_PREFIX_LIST_ENTRY *PrefixEntry,
IN BOOLEAN OnLinkOrAuto,
IN BOOLEAN ImmediateDelete
)
{
LIST_ENTRY *Entry;
IP6_INTERFACE *IpIf;
EFI_STATUS Status;
if ((!ImmediateDelete) && (PrefixEntry->RefCnt > 0) && ((--PrefixEntry->RefCnt) > 0)) {
return ;
}
if (OnLinkOrAuto) {
//
// Remove the direct route for onlink prefix from route table.
//
do {
Status = Ip6DelRoute (
IpSb->RouteTable,
&PrefixEntry->Prefix,
PrefixEntry->PrefixLength,
NULL
);
} while (Status != EFI_NOT_FOUND);
} else {
//
// Remove the corresponding addresses generated from this autonomous prefix.
//
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);
Ip6RemoveAddr (IpSb, &IpIf->AddressList, &IpIf->AddressCount, &PrefixEntry->Prefix, PrefixEntry->PrefixLength);
}
}
RemoveEntryList (&PrefixEntry->Link);
FreePool (PrefixEntry);
}
/**
Search the list array to find an IP6 prefix list entry.
@param[in] IpSb The pointer to IP6_SERVICE instance.
@param[in] OnLinkOrAuto If TRUE, the search the link prefix list,
Otherwise search the autoconfiguration prefix list.
@param[in] PrefixLength The prefix length of the Prefix
@param[in] Prefix The prefix address.
@return NULL if cannot find the IP6 prefix list entry. Otherwise, return the
pointer to the IP6 prefix list entry.
**/
IP6_PREFIX_LIST_ENTRY *
Ip6FindPrefixListEntry (
IN IP6_SERVICE *IpSb,
IN BOOLEAN OnLinkOrAuto,
IN UINT8 PrefixLength,
IN EFI_IPv6_ADDRESS *Prefix
)
{
IP6_PREFIX_LIST_ENTRY *PrefixList;
LIST_ENTRY *Entry;
LIST_ENTRY *ListHead;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ASSERT (Prefix != NULL);
if (OnLinkOrAuto) {
ListHead = &IpSb->OnlinkPrefix;
} else {
ListHead = &IpSb->AutonomousPrefix;
}
NET_LIST_FOR_EACH (Entry, ListHead) {
PrefixList = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link);
if (PrefixLength != 255) {
//
// Perform exactly prefix match.
//
if (PrefixList->PrefixLength == PrefixLength &&
NetIp6IsNetEqual (&PrefixList->Prefix, Prefix, PrefixLength)) {
return PrefixList;
}
} else {
//
// Perform the longest prefix match. The list is already sorted with
// the longest length prefix put at the head of the list.
//
if (NetIp6IsNetEqual (&PrefixList->Prefix, Prefix, PrefixList->PrefixLength)) {
return PrefixList;
}
}
}
return NULL;
}
/**
Release the resource in the prefix list table, and destroy the list entry and
corresponding addresses or route entries.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] ListHead The list entry head of the prefix list table.
**/
VOID
Ip6CleanPrefixListTable (
IN IP6_SERVICE *IpSb,
IN LIST_ENTRY *ListHead
)
{
IP6_PREFIX_LIST_ENTRY *PrefixList;
BOOLEAN OnLink;
OnLink = (BOOLEAN) (ListHead == &IpSb->OnlinkPrefix);
while (!IsListEmpty (ListHead)) {
PrefixList = NET_LIST_HEAD (ListHead, IP6_PREFIX_LIST_ENTRY, Link);
Ip6DestroyPrefixListEntry (IpSb, PrefixList, OnLink, TRUE);
}
}
/**
Callback function when address resolution is finished. It will cancel
all the queued frames if the address resolution failed, or transmit them
if the request succeeded.
@param[in] Context The context of the callback, a pointer to IP6_NEIGHBOR_ENTRY.
**/
VOID
Ip6OnArpResolved (
IN VOID *Context
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP6_NEIGHBOR_ENTRY *ArpQue;
IP6_SERVICE *IpSb;
IP6_LINK_TX_TOKEN *Token;
EFI_STATUS Status;
BOOLEAN Sent;
ArpQue = (IP6_NEIGHBOR_ENTRY *) Context;
if ((ArpQue == NULL) || (ArpQue->Interface == NULL)) {
return ;
}
IpSb = ArpQue->Interface->Service;
if ((IpSb == NULL) || (IpSb->Signature != IP6_SERVICE_SIGNATURE)) {
return ;
}
//
// ARP resolve failed for some reason. Release all the frame
// and ARP queue itself. Ip6FreeArpQue will call the frame's
// owner back.
//
if (NET_MAC_EQUAL (&ArpQue->LinkAddress, &mZeroMacAddress, IpSb->SnpMode.HwAddressSize)) {
Ip6FreeNeighborEntry (IpSb, ArpQue, FALSE, TRUE, EFI_NO_MAPPING, NULL, NULL);
return ;
}
//
// ARP resolve succeeded, Transmit all the frame.
//
Sent = FALSE;
NET_LIST_FOR_EACH_SAFE (Entry, Next, &ArpQue->Frames) {
RemoveEntryList (Entry);
Token = NET_LIST_USER_STRUCT (Entry, IP6_LINK_TX_TOKEN, Link);
IP6_COPY_LINK_ADDRESS (&Token->DstMac, &ArpQue->LinkAddress);
//
// Insert the tx token before transmitting it via MNP as the FrameSentDpc
// may be called before Mnp->Transmit returns which will remove this tx
// token from the SentFrames list. Remove it from the list if the returned
// Status of Mnp->Transmit is not EFI_SUCCESS as in this case the
// FrameSentDpc won't be queued.
//
InsertTailList (&ArpQue->Interface->SentFrames, &Token->Link);
Status = IpSb->Mnp->Transmit (IpSb->Mnp, &Token->MnpToken);
if (EFI_ERROR (Status)) {
RemoveEntryList (&Token->Link);
Token->CallBack (Token->Packet, Status, 0, Token->Context);
Ip6FreeLinkTxToken (Token);
continue;
} else {
Sent = TRUE;
}
}
//
// Free the ArpQue only but not the whole neighbor entry.
//
Ip6FreeNeighborEntry (IpSb, ArpQue, FALSE, FALSE, EFI_SUCCESS, NULL, NULL);
if (Sent && (ArpQue->State == EfiNeighborStale)) {
ArpQue->State = EfiNeighborDelay;
ArpQue->Ticks = (UINT32) IP6_GET_TICKS (IP6_DELAY_FIRST_PROBE_TIME);
}
}
/**
Allocate and initialize an IP6 neighbor cache entry.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] CallBack The callback function to be called when
address resolution is finished.
@param[in] Ip6Address Points to the IPv6 address of the neighbor.
@param[in] LinkAddress Points to the MAC address of the neighbor.
Ignored if NULL.
@return NULL if failed to allocate memory for the neighbor cache entry.
Otherwise, point to the created neighbor cache entry.
**/
IP6_NEIGHBOR_ENTRY *
Ip6CreateNeighborEntry (
IN IP6_SERVICE *IpSb,
IN IP6_ARP_CALLBACK CallBack,
IN EFI_IPv6_ADDRESS *Ip6Address,
IN EFI_MAC_ADDRESS *LinkAddress OPTIONAL
)
{
IP6_NEIGHBOR_ENTRY *Entry;
IP6_DEFAULT_ROUTER *DefaultRouter;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ASSERT (Ip6Address!= NULL);
Entry = AllocateZeroPool (sizeof (IP6_NEIGHBOR_ENTRY));
if (Entry == NULL) {
return NULL;
}
Entry->RefCnt = 1;
Entry->IsRouter = FALSE;
Entry->ArpFree = FALSE;
Entry->Dynamic = FALSE;
Entry->State = EfiNeighborInComplete;
Entry->Transmit = IP6_MAX_MULTICAST_SOLICIT + 1;
Entry->CallBack = CallBack;
Entry->Interface = NULL;
InitializeListHead (&Entry->Frames);
IP6_COPY_ADDRESS (&Entry->Neighbor, Ip6Address);
if (LinkAddress != NULL) {
IP6_COPY_LINK_ADDRESS (&Entry->LinkAddress, LinkAddress);
} else {
IP6_COPY_LINK_ADDRESS (&Entry->LinkAddress, &mZeroMacAddress);
}
InsertHeadList (&IpSb->NeighborTable, &Entry->Link);
//
// If corresponding default router entry exists, establish the relationship.
//
DefaultRouter = Ip6FindDefaultRouter (IpSb, Ip6Address);
if (DefaultRouter != NULL) {
DefaultRouter->NeighborCache = Entry;
}
return Entry;
}
/**
Search a IP6 neighbor cache entry.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] Ip6Address Points to the IPv6 address of the neighbor.
@return NULL if it failed to find the matching neighbor cache entry.
Otherwise, point to the found neighbor cache entry.
**/
IP6_NEIGHBOR_ENTRY *
Ip6FindNeighborEntry (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *Ip6Address
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP6_NEIGHBOR_ENTRY *Neighbor;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ASSERT (Ip6Address != NULL);
NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->NeighborTable) {
Neighbor = NET_LIST_USER_STRUCT (Entry, IP6_NEIGHBOR_ENTRY, Link);
if (EFI_IP6_EQUAL (Ip6Address, &Neighbor->Neighbor)) {
RemoveEntryList (Entry);
InsertHeadList (&IpSb->NeighborTable, Entry);
return Neighbor;
}
}
return NULL;
}
/**
Free a IP6 neighbor cache entry and remove all the frames on the address
resolution queue that pass the FrameToCancel. That is, either FrameToCancel
is NULL, or it returns true for the frame.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] NeighborCache The to be free neighbor cache entry.
@param[in] SendIcmpError If TRUE, send out ICMP error.
@param[in] FullFree If TRUE, remove the neighbor cache entry.
Otherwise remove the pending frames.
@param[in] IoStatus The status returned to the cancelled frames'
callback function.
@param[in] FrameToCancel Function to select which frame to cancel.
This is an optional parameter that may be NULL.
@param[in] Context Opaque parameter to the FrameToCancel.
Ignored if FrameToCancel is NULL.
@retval EFI_INVALID_PARAMETER The input parameter is invalid.
@retval EFI_SUCCESS The operation finished successfully.
**/
EFI_STATUS
Ip6FreeNeighborEntry (
IN IP6_SERVICE *IpSb,
IN IP6_NEIGHBOR_ENTRY *NeighborCache,
IN BOOLEAN SendIcmpError,
IN BOOLEAN FullFree,
IN EFI_STATUS IoStatus,
IN IP6_FRAME_TO_CANCEL FrameToCancel OPTIONAL,
IN VOID *Context OPTIONAL
)
{
IP6_LINK_TX_TOKEN *TxToken;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP6_DEFAULT_ROUTER *DefaultRouter;
//
// If FrameToCancel fails, the token will not be released.
// To avoid the memory leak, stop this usage model.
//
if (FullFree && FrameToCancel != NULL) {
return EFI_INVALID_PARAMETER;
}
NET_LIST_FOR_EACH_SAFE (Entry, Next, &NeighborCache->Frames) {
TxToken = NET_LIST_USER_STRUCT (Entry, IP6_LINK_TX_TOKEN, Link);
if (SendIcmpError && !IP6_IS_MULTICAST (&TxToken->Packet->Ip.Ip6->DestinationAddress)) {
Ip6SendIcmpError (
IpSb,
TxToken->Packet,
NULL,
&TxToken->Packet->Ip.Ip6->SourceAddress,
ICMP_V6_DEST_UNREACHABLE,
ICMP_V6_ADDR_UNREACHABLE,
NULL
);
}
if ((FrameToCancel == NULL) || FrameToCancel (TxToken, Context)) {
RemoveEntryList (Entry);
TxToken->CallBack (TxToken->Packet, IoStatus, 0, TxToken->Context);
Ip6FreeLinkTxToken (TxToken);
}
}
if (NeighborCache->ArpFree && IsListEmpty (&NeighborCache->Frames)) {
RemoveEntryList (&NeighborCache->ArpList);
NeighborCache->ArpFree = FALSE;
}
if (FullFree) {
if (NeighborCache->IsRouter) {
DefaultRouter = Ip6FindDefaultRouter (IpSb, &NeighborCache->Neighbor);
if (DefaultRouter != NULL) {
Ip6DestroyDefaultRouter (IpSb, DefaultRouter);
}
}
RemoveEntryList (&NeighborCache->Link);
FreePool (NeighborCache);
}
return EFI_SUCCESS;
}
/**
Allocate and initialize an IP6 default router entry.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] Ip6Address The IPv6 address of the default router.
@param[in] RouterLifetime The lifetime associated with the default
router, in units of seconds.
@return NULL if it failed to allocate memory for the default router node.
Otherwise, point to the created default router node.
**/
IP6_DEFAULT_ROUTER *
Ip6CreateDefaultRouter (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *Ip6Address,
IN UINT16 RouterLifetime
)
{
IP6_DEFAULT_ROUTER *Entry;
IP6_ROUTE_ENTRY *RtEntry;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ASSERT (Ip6Address != NULL);
Entry = AllocatePool (sizeof (IP6_DEFAULT_ROUTER));
if (Entry == NULL) {
return NULL;
}
Entry->RefCnt = 1;
Entry->Lifetime = RouterLifetime;
Entry->NeighborCache = Ip6FindNeighborEntry (IpSb, Ip6Address);
IP6_COPY_ADDRESS (&Entry->Router, Ip6Address);
//
// Add a default route into route table with both Destination and PrefixLength set to zero.
//
RtEntry = Ip6CreateRouteEntry (NULL, 0, Ip6Address);
if (RtEntry == NULL) {
FreePool (Entry);
return NULL;
}
InsertHeadList (&IpSb->RouteTable->RouteArea[0], &RtEntry->Link);
IpSb->RouteTable->TotalNum++;
InsertTailList (&IpSb->DefaultRouterList, &Entry->Link);
return Entry;
}
/**
Destroy an IP6 default router entry.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] DefaultRouter The to be destroyed IP6_DEFAULT_ROUTER.
**/
VOID
Ip6DestroyDefaultRouter (
IN IP6_SERVICE *IpSb,
IN IP6_DEFAULT_ROUTER *DefaultRouter
)
{
EFI_STATUS Status;
RemoveEntryList (&DefaultRouter->Link);
//
// Update the Destination Cache - all entries using the time-out router as next-hop
// should perform next-hop determination again.
//
do {
Status = Ip6DelRoute (IpSb->RouteTable, NULL, 0, &DefaultRouter->Router);
} while (Status != EFI_NOT_FOUND);
FreePool (DefaultRouter);
}
/**
Clean an IP6 default router list.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
**/
VOID
Ip6CleanDefaultRouterList (
IN IP6_SERVICE *IpSb
)
{
IP6_DEFAULT_ROUTER *DefaultRouter;
while (!IsListEmpty (&IpSb->DefaultRouterList)) {
DefaultRouter = NET_LIST_HEAD (&IpSb->DefaultRouterList, IP6_DEFAULT_ROUTER, Link);
Ip6DestroyDefaultRouter (IpSb, DefaultRouter);
}
}
/**
Search a default router node from an IP6 default router list.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] Ip6Address The IPv6 address of the to be searched default router node.
@return NULL if it failed to find the matching default router node.
Otherwise, point to the found default router node.
**/
IP6_DEFAULT_ROUTER *
Ip6FindDefaultRouter (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *Ip6Address
)
{
LIST_ENTRY *Entry;
IP6_DEFAULT_ROUTER *DefaultRouter;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ASSERT (Ip6Address != NULL);
NET_LIST_FOR_EACH (Entry, &IpSb->DefaultRouterList) {
DefaultRouter = NET_LIST_USER_STRUCT (Entry, IP6_DEFAULT_ROUTER, Link);
if (EFI_IP6_EQUAL (Ip6Address, &DefaultRouter->Router)) {
return DefaultRouter;
}
}
return NULL;
}
/**
The function to be called after DAD (Duplicate Address Detection) is performed.
@param[in] IsDadPassed If TRUE, the DAD operation succeed. Otherwise, the DAD operation failed.
@param[in] IpIf Points to the IP6_INTERFACE.
@param[in] DadEntry The DAD entry which already performed DAD.
**/
VOID
Ip6OnDADFinished (
IN BOOLEAN IsDadPassed,
IN IP6_INTERFACE *IpIf,
IN IP6_DAD_ENTRY *DadEntry
)
{
IP6_SERVICE *IpSb;
IP6_ADDRESS_INFO *AddrInfo;
EFI_DHCP6_PROTOCOL *Dhcp6;
UINT16 OptBuf[4];
EFI_DHCP6_PACKET_OPTION *Oro;
EFI_DHCP6_RETRANSMISSION InfoReqReXmit;
IpSb = IpIf->Service;
AddrInfo = DadEntry->AddressInfo;
if (IsDadPassed) {
//
// DAD succeed.
//
if (NetIp6IsLinkLocalAddr (&AddrInfo->Address)) {
ASSERT (!IpSb->LinkLocalOk);
IP6_COPY_ADDRESS (&IpSb->LinkLocalAddr, &AddrInfo->Address);
IpSb->LinkLocalOk = TRUE;
IpIf->Configured = TRUE;
//
// Check whether DHCP6 need to be started.
//
Dhcp6 = IpSb->Ip6ConfigInstance.Dhcp6;
if (IpSb->Dhcp6NeedStart) {
Dhcp6->Start (Dhcp6);
IpSb->Dhcp6NeedStart = FALSE;
}
if (IpSb->Dhcp6NeedInfoRequest) {
//
// Set the exta options to send. Here we only want the option request option
// with DNS SERVERS.
//
Oro = (EFI_DHCP6_PACKET_OPTION *) OptBuf;
Oro->OpCode = HTONS (IP6_CONFIG_DHCP6_OPTION_ORO);
Oro->OpLen = HTONS (2);
*((UINT16 *) &Oro->Data[0]) = HTONS (IP6_CONFIG_DHCP6_OPTION_DNS_SERVERS);
InfoReqReXmit.Irt = 4;
InfoReqReXmit.Mrc = 64;
InfoReqReXmit.Mrt = 60;
InfoReqReXmit.Mrd = 0;
Dhcp6->InfoRequest (
Dhcp6,
TRUE,
Oro,
0,
NULL,
&InfoReqReXmit,
IpSb->Ip6ConfigInstance.Dhcp6Event,
Ip6ConfigOnDhcp6Reply,
&IpSb->Ip6ConfigInstance
);
}
//
// Add an on-link prefix for link-local address.
//
Ip6CreatePrefixListEntry (
IpSb,
TRUE,
(UINT32) IP6_INFINIT_LIFETIME,
(UINT32) IP6_INFINIT_LIFETIME,
IP6_LINK_LOCAL_PREFIX_LENGTH,
&IpSb->LinkLocalAddr
);
} else {
//
// Global scope unicast address.
//
Ip6AddAddr (IpIf, AddrInfo);
//
// Add an on-link prefix for this address.
//
Ip6CreatePrefixListEntry (
IpSb,
TRUE,
AddrInfo->ValidLifetime,
AddrInfo->PreferredLifetime,
AddrInfo->PrefixLength,
&AddrInfo->Address
);
IpIf->Configured = TRUE;
}
} else {
//
// Leave the group we joined before.
//
Ip6LeaveGroup (IpSb, &DadEntry->Destination);
}
if (DadEntry->Callback != NULL) {
DadEntry->Callback (IsDadPassed, &AddrInfo->Address, DadEntry->Context);
}
if (!IsDadPassed && NetIp6IsLinkLocalAddr (&AddrInfo->Address)) {
FreePool (AddrInfo);
RemoveEntryList (&DadEntry->Link);
FreePool (DadEntry);
//
// Disable IP operation since link-local address is a duplicate address.
//
IpSb->LinkLocalDadFail = TRUE;
IpSb->Mnp->Configure (IpSb->Mnp, NULL);
gBS->SetTimer (IpSb->Timer, TimerCancel, 0);
gBS->SetTimer (IpSb->FasterTimer, TimerCancel, 0);
return ;
}
if (!IsDadPassed || NetIp6IsLinkLocalAddr (&AddrInfo->Address)) {
//
// Free the AddressInfo we hold if DAD fails or it is a link-local address.
//
FreePool (AddrInfo);
}
RemoveEntryList (&DadEntry->Link);
FreePool (DadEntry);
}
/**
Create a DAD (Duplicate Address Detection) entry and queue it to be performed.
@param[in] IpIf Points to the IP6_INTERFACE.
@param[in] AddressInfo The address information which needs DAD performed.
@param[in] Callback The callback routine that will be called after DAD
is performed. This is an optional parameter that
may be NULL.
@param[in] Context The opaque parameter for a DAD callback routine.
This is an optional parameter that may be NULL.
@retval EFI_SUCCESS The DAD entry was created and queued.
@retval EFI_OUT_OF_RESOURCES Failed to allocate the memory to complete the
operation.
**/
EFI_STATUS
Ip6InitDADProcess (
IN IP6_INTERFACE *IpIf,
IN IP6_ADDRESS_INFO *AddressInfo,
IN IP6_DAD_CALLBACK Callback OPTIONAL,
IN VOID *Context OPTIONAL
)
{
IP6_DAD_ENTRY *Entry;
EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS *DadXmits;
IP6_SERVICE *IpSb;
EFI_STATUS Status;
UINT32 MaxDelayTick;
NET_CHECK_SIGNATURE (IpIf, IP6_INTERFACE_SIGNATURE);
ASSERT (AddressInfo != NULL);
Status = EFI_SUCCESS;
IpSb = IpIf->Service;
DadXmits = &IpSb->Ip6ConfigInstance.DadXmits;
//
// Allocate the resources and insert info
//
Entry = AllocatePool (sizeof (IP6_DAD_ENTRY));
if (Entry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Map the incoming unicast address to solicited-node multicast address
//
Ip6CreateSNMulticastAddr (&AddressInfo->Address, &Entry->Destination);
//
// Join in the solicited-node multicast address.
//
Status = Ip6JoinGroup (IpSb, IpIf, &Entry->Destination);
if (EFI_ERROR (Status)) {
FreePool (Entry);
return Status;
}
Entry->Signature = IP6_DAD_ENTRY_SIGNATURE;
Entry->MaxTransmit = DadXmits->DupAddrDetectTransmits;
Entry->Transmit = 0;
Entry->Receive = 0;
MaxDelayTick = IP6_MAX_RTR_SOLICITATION_DELAY / IP6_TIMER_INTERVAL_IN_MS;
Entry->RetransTick = (MaxDelayTick * ((NET_RANDOM (NetRandomInitSeed ()) % 5) + 1)) / 5;
Entry->AddressInfo = AddressInfo;
Entry->Callback = Callback;
Entry->Context = Context;
InsertTailList (&IpIf->DupAddrDetectList, &Entry->Link);
if (Entry->MaxTransmit == 0) {
//
// DAD is disabled on this interface, immediately mark this DAD successful.
//
Ip6OnDADFinished (TRUE, IpIf, Entry);
}
return EFI_SUCCESS;
}
/**
Search IP6_DAD_ENTRY from the Duplicate Address Detection List.
@param[in] IpSb The pointer to the IP6_SERVICE instance.
@param[in] Target The address information which needs DAD performed .
@param[out] Interface If not NULL, output the IP6 interface that configures
the tentative address.
@return NULL if failed to find the matching DAD entry.
Otherwise, point to the found DAD entry.
**/
IP6_DAD_ENTRY *
Ip6FindDADEntry (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *Target,
OUT IP6_INTERFACE **Interface OPTIONAL
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Entry2;
IP6_INTERFACE *IpIf;
IP6_DAD_ENTRY *DupAddrDetect;
IP6_ADDRESS_INFO *AddrInfo;
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP6_INTERFACE, Link);
NET_LIST_FOR_EACH (Entry2, &IpIf->DupAddrDetectList) {
DupAddrDetect = NET_LIST_USER_STRUCT_S (Entry2, IP6_DAD_ENTRY, Link, IP6_DAD_ENTRY_SIGNATURE);
AddrInfo = DupAddrDetect->AddressInfo;
if (EFI_IP6_EQUAL (&AddrInfo->Address, Target)) {
if (Interface != NULL) {
*Interface = IpIf;
}
return DupAddrDetect;
}
}
}
return NULL;
}
/**
Generate router solicit message and send it out to Destination Address or
All Router Link Local scope multicast address.
@param[in] IpSb The IP service to send the packet.
@param[in] Interface If not NULL, points to the IP6 interface to send
the packet.
@param[in] SourceAddress If not NULL, the source address of the message.
@param[in] DestinationAddress If not NULL, the destination address of the message.
@param[in] SourceLinkAddress If not NULL, the MAC address of the source.
A source link-layer address option will be appended
to the message.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
operation.
@retval EFI_SUCCESS The router solicit message was successfully sent.
**/
EFI_STATUS
Ip6SendRouterSolicit (
IN IP6_SERVICE *IpSb,
IN IP6_INTERFACE *Interface OPTIONAL,
IN EFI_IPv6_ADDRESS *SourceAddress OPTIONAL,
IN EFI_IPv6_ADDRESS *DestinationAddress OPTIONAL,
IN EFI_MAC_ADDRESS *SourceLinkAddress OPTIONAL
)
{
NET_BUF *Packet;
EFI_IP6_HEADER Head;
IP6_ICMP_INFORMATION_HEAD *IcmpHead;
IP6_ETHER_ADDR_OPTION *LinkLayerOption;
UINT16 PayloadLen;
IP6_INTERFACE *IpIf;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
IpIf = Interface;
if (IpIf == NULL && IpSb->DefaultInterface != NULL) {
IpIf = IpSb->DefaultInterface;
}
//
// Generate the packet to be sent
//
PayloadLen = (UINT16) sizeof (IP6_ICMP_INFORMATION_HEAD);
if (SourceLinkAddress != NULL) {
PayloadLen += sizeof (IP6_ETHER_ADDR_OPTION);
}
Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen);
if (Packet == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create the basic IPv6 header.
//
Head.FlowLabelL = 0;
Head.FlowLabelH = 0;
Head.PayloadLength = HTONS (PayloadLen);
Head.NextHeader = IP6_ICMP;
Head.HopLimit = IP6_HOP_LIMIT;
if (SourceAddress != NULL) {
IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress);
} else {
ZeroMem (&Head.SourceAddress, sizeof (EFI_IPv6_ADDRESS));
}
if (DestinationAddress != NULL) {
IP6_COPY_ADDRESS (&Head.DestinationAddress, DestinationAddress);
} else {
Ip6SetToAllNodeMulticast (TRUE, IP6_LINK_LOCAL_SCOPE, &Head.DestinationAddress);
}
NetbufReserve (Packet, sizeof (EFI_IP6_HEADER));
//
// Fill in the ICMP header, and Source link-layer address if contained.
//
IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE);
ASSERT (IcmpHead != NULL);
ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD));
IcmpHead->Head.Type = ICMP_V6_ROUTER_SOLICIT;
IcmpHead->Head.Code = 0;
LinkLayerOption = NULL;
if (SourceLinkAddress != NULL) {
LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) NetbufAllocSpace (
Packet,
sizeof (IP6_ETHER_ADDR_OPTION),
FALSE
);
ASSERT (LinkLayerOption != NULL);
LinkLayerOption->Type = Ip6OptionEtherSource;
LinkLayerOption->Length = (UINT8) sizeof (IP6_ETHER_ADDR_OPTION);
CopyMem (LinkLayerOption->EtherAddr, SourceLinkAddress, 6);
}
//
// Transmit the packet
//
return Ip6Output (IpSb, IpIf, NULL, Packet, &Head, NULL, 0, Ip6SysPacketSent, NULL);
}
/**
Generate a Neighbor Advertisement message and send it out to Destination Address.
@param[in] IpSb The IP service to send the packet.
@param[in] SourceAddress The source address of the message.
@param[in] DestinationAddress The destination address of the message.
@param[in] TargetIp6Address The target address field in the Neighbor Solicitation
message that prompted this advertisement.
@param[in] TargetLinkAddress The MAC address for the target, i.e. the sender
of the advertisement.
@param[in] IsRouter If TRUE, indicates the sender is a router.
@param[in] Override If TRUE, indicates the advertisement should override
an existing cache entry and update the MAC address.
@param[in] Solicited If TRUE, indicates the advertisement was sent
in response to a Neighbor Solicitation from
the Destination address.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
operation.
@retval EFI_SUCCESS The Neighbor Advertise message was successfully sent.
**/
EFI_STATUS
Ip6SendNeighborAdvertise (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *SourceAddress,
IN EFI_IPv6_ADDRESS *DestinationAddress,
IN EFI_IPv6_ADDRESS *TargetIp6Address,
IN EFI_MAC_ADDRESS *TargetLinkAddress,
IN BOOLEAN IsRouter,
IN BOOLEAN Override,
IN BOOLEAN Solicited
)
{
NET_BUF *Packet;
EFI_IP6_HEADER Head;
IP6_ICMP_INFORMATION_HEAD *IcmpHead;
IP6_ETHER_ADDR_OPTION *LinkLayerOption;
EFI_IPv6_ADDRESS *Target;
UINT16 PayloadLen;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
//
// The Neighbor Advertisement message must include a Target link-layer address option
// when responding to multicast solicitation and should include such option when
// responding to unicast solicitation. It also must include such option as unsolicited
// advertisement.
//
ASSERT (DestinationAddress != NULL && TargetIp6Address != NULL && TargetLinkAddress != NULL);
PayloadLen = (UINT16) (sizeof (IP6_ICMP_INFORMATION_HEAD) + sizeof (EFI_IPv6_ADDRESS) + sizeof (IP6_ETHER_ADDR_OPTION));
//
// Generate the packet to be sent
//
Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen);
if (Packet == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create the basic IPv6 header.
//
Head.FlowLabelL = 0;
Head.FlowLabelH = 0;
Head.PayloadLength = HTONS (PayloadLen);
Head.NextHeader = IP6_ICMP;
Head.HopLimit = IP6_HOP_LIMIT;
IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress);
IP6_COPY_ADDRESS (&Head.DestinationAddress, DestinationAddress);
NetbufReserve (Packet, sizeof (EFI_IP6_HEADER));
//
// Fill in the ICMP header, Target address, and Target link-layer address.
// Set the Router flag, Solicited flag and Override flag.
//
IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE);
ASSERT (IcmpHead != NULL);
ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD));
IcmpHead->Head.Type = ICMP_V6_NEIGHBOR_ADVERTISE;
IcmpHead->Head.Code = 0;
if (IsRouter) {
IcmpHead->Fourth |= IP6_IS_ROUTER_FLAG;
}
if (Solicited) {
IcmpHead->Fourth |= IP6_SOLICITED_FLAG;
}
if (Override) {
IcmpHead->Fourth |= IP6_OVERRIDE_FLAG;
}
Target = (EFI_IPv6_ADDRESS *) NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE);
ASSERT (Target != NULL);
IP6_COPY_ADDRESS (Target, TargetIp6Address);
LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) NetbufAllocSpace (
Packet,
sizeof (IP6_ETHER_ADDR_OPTION),
FALSE
);
ASSERT (LinkLayerOption != NULL);
LinkLayerOption->Type = Ip6OptionEtherTarget;
LinkLayerOption->Length = 1;
CopyMem (LinkLayerOption->EtherAddr, TargetLinkAddress, 6);
//
// Transmit the packet
//
return Ip6Output (IpSb, NULL, NULL, Packet, &Head, NULL, 0, Ip6SysPacketSent, NULL);
}
/**
Generate the Neighbor Solicitation message and send it to the Destination Address.
@param[in] IpSb The IP service to send the packet
@param[in] SourceAddress The source address of the message.
@param[in] DestinationAddress The destination address of the message.
@param[in] TargetIp6Address The IP address of the target of the solicitation.
It must not be a multicast address.
@param[in] SourceLinkAddress The MAC address for the sender. If not NULL,
a source link-layer address option will be appended
to the message.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
operation.
@retval EFI_SUCCESS The Neighbor Advertise message was successfully sent.
**/
EFI_STATUS
Ip6SendNeighborSolicit (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *SourceAddress,
IN EFI_IPv6_ADDRESS *DestinationAddress,
IN EFI_IPv6_ADDRESS *TargetIp6Address,
IN EFI_MAC_ADDRESS *SourceLinkAddress OPTIONAL
)
{
NET_BUF *Packet;
EFI_IP6_HEADER Head;
IP6_ICMP_INFORMATION_HEAD *IcmpHead;
IP6_ETHER_ADDR_OPTION *LinkLayerOption;
EFI_IPv6_ADDRESS *Target;
BOOLEAN IsDAD;
UINT16 PayloadLen;
IP6_NEIGHBOR_ENTRY *Neighbor;
//
// Check input parameters
//
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
if (DestinationAddress == NULL || TargetIp6Address == NULL) {
return EFI_INVALID_PARAMETER;
}
IsDAD = FALSE;
if (SourceAddress == NULL || (SourceAddress != NULL && NetIp6IsUnspecifiedAddr (SourceAddress))) {
IsDAD = TRUE;
}
//
// The Neighbor Solicitation message should include a source link-layer address option
// if the solicitation is not sent by performing DAD - Duplicate Address Detection.
// Otherwise must not include it.
//
PayloadLen = (UINT16) (sizeof (IP6_ICMP_INFORMATION_HEAD) + sizeof (EFI_IPv6_ADDRESS));
if (!IsDAD) {
if (SourceLinkAddress == NULL) {
return EFI_INVALID_PARAMETER;
}
PayloadLen = (UINT16) (PayloadLen + sizeof (IP6_ETHER_ADDR_OPTION));
}
//
// Generate the packet to be sent
//
Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen);
if (Packet == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create the basic IPv6 header
//
Head.FlowLabelL = 0;
Head.FlowLabelH = 0;
Head.PayloadLength = HTONS (PayloadLen);
Head.NextHeader = IP6_ICMP;
Head.HopLimit = IP6_HOP_LIMIT;
if (SourceAddress != NULL) {
IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress);
} else {
ZeroMem (&Head.SourceAddress, sizeof (EFI_IPv6_ADDRESS));
}
IP6_COPY_ADDRESS (&Head.DestinationAddress, DestinationAddress);
NetbufReserve (Packet, sizeof (EFI_IP6_HEADER));
//
// Fill in the ICMP header, Target address, and Source link-layer address.
//
IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE);
ASSERT (IcmpHead != NULL);
ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD));
IcmpHead->Head.Type = ICMP_V6_NEIGHBOR_SOLICIT;
IcmpHead->Head.Code = 0;
Target = (EFI_IPv6_ADDRESS *) NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE);
ASSERT (Target != NULL);
IP6_COPY_ADDRESS (Target, TargetIp6Address);
LinkLayerOption = NULL;
if (!IsDAD) {
//
// Fill in the source link-layer address option
//
LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) NetbufAllocSpace (
Packet,
sizeof (IP6_ETHER_ADDR_OPTION),
FALSE
);
ASSERT (LinkLayerOption != NULL);
LinkLayerOption->Type = Ip6OptionEtherSource;
LinkLayerOption->Length = 1;
CopyMem (LinkLayerOption->EtherAddr, SourceLinkAddress, 6);
}
//
// Create a Neighbor Cache entry in the INCOMPLETE state when performing
// address resolution.
//
if (!IsDAD && Ip6IsSNMulticastAddr (DestinationAddress)) {
Neighbor = Ip6FindNeighborEntry (IpSb, TargetIp6Address);
if (Neighbor == NULL) {
Neighbor = Ip6CreateNeighborEntry (IpSb, Ip6OnArpResolved, TargetIp6Address, NULL);
ASSERT (Neighbor != NULL);
}
}
//
// Transmit the packet
//
return Ip6Output (IpSb, IpSb->DefaultInterface, NULL, Packet, &Head, NULL, 0, Ip6SysPacketSent, NULL);
}
/**
Process the Neighbor Solicitation message. The message may be sent for Duplicate
Address Detection or Address Resolution.
@param[in] IpSb The IP service that received the packet.
@param[in] Head The IP head of the message.
@param[in] Packet The content of the message with IP head removed.
@retval EFI_SUCCESS The packet processed successfully.
@retval EFI_INVALID_PARAMETER The packet is invalid.
@retval EFI_ICMP_ERROR The packet indicates that DAD is failed.
@retval Others Failed to process the packet.
**/
EFI_STATUS
Ip6ProcessNeighborSolicit (
IN IP6_SERVICE *IpSb,
IN EFI_IP6_HEADER *Head,
IN NET_BUF *Packet
)
{
IP6_ICMP_INFORMATION_HEAD Icmp;
EFI_IPv6_ADDRESS Target;
IP6_ETHER_ADDR_OPTION LinkLayerOption;
BOOLEAN IsDAD;
BOOLEAN IsUnicast;
BOOLEAN IsMaintained;
IP6_DAD_ENTRY *DupAddrDetect;
IP6_INTERFACE *IpIf;
IP6_NEIGHBOR_ENTRY *Neighbor;
BOOLEAN Solicited;
BOOLEAN UpdateCache;
EFI_IPv6_ADDRESS Dest;
UINT16 OptionLen;
UINT8 *Option;
BOOLEAN Provided;
EFI_STATUS Status;
VOID *MacAddress;
NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);
NetbufCopy (Packet, sizeof (Icmp), sizeof (Target), Target.Addr);
//
// Perform Message Validation:
// The IP Hop Limit field has a value of 255, i.e., the packet
// could not possibly have been forwarded by a router.
// ICMP Code is 0.
// Target Address is not a multicast address.
//
Status = EFI_INVALID_PARAMETER;
if (Head->HopLimit != IP6_HOP_LIMIT || Icmp.Head.Code != 0 || !NetIp6IsValidUnicast (&Target)) {
goto Exit;
}
//
// ICMP length is 24 or more octets.
//
OptionLen = 0;
if (Head->PayloadLength < IP6_ND_LENGTH) {
goto Exit;
} else {
OptionLen = (UINT16) (Head->PayloadLength - IP6_ND_LENGTH);
if (OptionLen != 0) {
Option = NetbufGetByte (Packet, IP6_ND_LENGTH, NULL);
ASSERT (Option != NULL);
//
// All included options should have a length that is greater than zero.
//
if (!Ip6IsNDOptionValid (Option, OptionLen)) {
goto Exit;
}
}
}
IsDAD = NetIp6IsUnspecifiedAddr (&Head->SourceAddress);
IsUnicast = (BOOLEAN) !Ip6IsSNMulticastAddr (&Head->DestinationAddress);
IsMaintained = Ip6IsOneOfSetAddress (IpSb, &Target, &IpIf, NULL);
Provided = FALSE;
if (OptionLen >= sizeof (IP6_ETHER_ADDR_OPTION)) {
NetbufCopy (
Packet,
IP6_ND_LENGTH,
sizeof (IP6_ETHER_ADDR_OPTION),
(UINT8 *) &LinkLayerOption
);
//
// The solicitation for neighbor discovery should include a source link-layer
// address option. If the option is not recognized, silently ignore it.
//
if (LinkLayerOption.Type == Ip6OptionEtherSource) {
if (IsDAD) {
//
// If the IP source address is the unspecified address, the source
// link-layer address option must not be included in the message.
//
goto Exit;
}
Provided = TRUE;
}
}
//
// If the IP source address is the unspecified address, the IP
// destination address is a solicited-node multicast address.
//
if (IsDAD && IsUnicast) {
goto Exit;
}
//
// If the target address is tentative, and the source address is a unicast address,
// the solicitation's sender is performing address resolution on the target;
// the solicitation should be silently ignored.
//
if (!IsDAD && !IsMaintained) {
goto Exit;
}
//
// If received unicast neighbor solicitation but destination is not this node,
// drop the packet.
//
if (IsUnicast && !IsMaintained) {
goto Exit;
}
//
// In DAD, when target address is a tentative address,
// process the received neighbor solicitation message but not send out response.
//
if (IsDAD && !IsMaintained) {
DupAddrDetect = Ip6FindDADEntry (IpSb, &Target, &IpIf);
if (DupAddrDetect != NULL) {
if (DupAddrDetect->Transmit == 0) {
//
// The NS is from another node to performing DAD on the same address since
// we haven't send out any NS yet. Fail DAD for the tentative address.
//
Ip6OnDADFinished (FALSE, IpIf, DupAddrDetect);
Status = EFI_ICMP_ERROR;
goto Exit;
}
//
// Check the MAC address of the incoming packet.
//
if (IpSb->RecvRequest.MnpToken.Packet.RxData == NULL) {
goto Exit;
}
MacAddress = IpSb->RecvRequest.MnpToken.Packet.RxData->SourceAddress;
if (MacAddress != NULL) {
if (CompareMem (
MacAddress,
&IpSb->SnpMode.CurrentAddress,
IpSb->SnpMode.HwAddressSize
) != 0) {
//
// The NS is from another node to performing DAD on the same address.
// Fail DAD for the tentative address.
//
Ip6OnDADFinished (FALSE, IpIf, DupAddrDetect);
Status = EFI_ICMP_ERROR;
} else {
//
// The below layer loopback the NS we sent. Record it and wait for more.
//
DupAddrDetect->Receive++;
Status = EFI_SUCCESS;
}
}
}
goto Exit;
}
//
// If the solicitation does not contain a link-layer address, DO NOT create or
// update the neighbor cache entries.
//
if (Provided) {
Neighbor = Ip6FindNeighborEntry (IpSb, &Head->SourceAddress);
UpdateCache = FALSE;
if (Neighbor == NULL) {
Neighbor = Ip6CreateNeighborEntry (IpSb, Ip6OnArpResolved, &Head->SourceAddress, NULL);
if (Neighbor == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
UpdateCache = TRUE;
} else {
if (CompareMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6) != 0) {
UpdateCache = TRUE;
}
}
if (UpdateCache) {
Neighbor->State = EfiNeighborStale;
Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
CopyMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6);
//
// Send queued packets if exist.
//
Neighbor->CallBack ((VOID *) Neighbor);
}
}
//
// Sends a Neighbor Advertisement as response.
// Set the Router flag to zero since the node is a host.
// If the source address of the solicitation is unspeicifed, and target address
// is one of the maintained address, reply a unsolicited multicast advertisement.
//
if (IsDAD && IsMaintained) {
Solicited = FALSE;
Ip6SetToAllNodeMulticast (FALSE, IP6_LINK_LOCAL_SCOPE, &Dest);
} else {
Solicited = TRUE;
IP6_COPY_ADDRESS (&Dest, &Head->SourceAddress);
}
Status = Ip6SendNeighborAdvertise (
IpSb,
&Target,
&Dest,
&Target,
&IpSb->SnpMode.CurrentAddress,
FALSE,
TRUE,
Solicited
);
Exit:
NetbufFree (Packet);
return Status;
}
/**
Process the Neighbor Advertisement message.
@param[in] IpSb The IP service that received the packet.
@param[in] Head The IP head of the message.
@param[in] Packet The content of the message with IP head removed.
@retval EFI_SUCCESS The packet processed successfully.
@retval EFI_INVALID_PARAMETER The packet is invalid.
@retval EFI_ICMP_ERROR The packet indicates that DAD is failed.
@retval Others Failed to process the packet.
**/
EFI_STATUS
Ip6ProcessNeighborAdvertise (
IN IP6_SERVICE *IpSb,
IN EFI_IP6_HEADER *Head,
IN NET_BUF *Packet
)
{
IP6_ICMP_INFORMATION_HEAD Icmp;
EFI_IPv6_ADDRESS Target;
IP6_ETHER_ADDR_OPTION LinkLayerOption;
BOOLEAN Provided;
INTN Compare;
IP6_NEIGHBOR_ENTRY *Neighbor;
IP6_DEFAULT_ROUTER *DefaultRouter;
BOOLEAN Solicited;
BOOLEAN IsRouter;
BOOLEAN Override;
IP6_DAD_ENTRY *DupAddrDetect;
IP6_INTERFACE *IpIf;
UINT16 OptionLen;
UINT8 *Option;
EFI_STATUS Status;
NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);
NetbufCopy (Packet, sizeof (Icmp), sizeof (Target), Target.Addr);
//
// Validate the incoming Neighbor Advertisement
//
Status = EFI_INVALID_PARAMETER;
//
// The IP Hop Limit field has a value of 255, i.e., the packet
// could not possibly have been forwarded by a router.
// ICMP Code is 0.
// Target Address is not a multicast address.
//
if (Head->HopLimit != IP6_HOP_LIMIT || Icmp.Head.Code != 0 || !NetIp6IsValidUnicast (&Target)) {
goto Exit;
}
//
// ICMP length is 24 or more octets.
//
Provided = FALSE;
OptionLen = 0;
if (Head->PayloadLength < IP6_ND_LENGTH) {
goto Exit;
} else {
OptionLen = (UINT16) (Head->PayloadLength - IP6_ND_LENGTH);
if (OptionLen != 0) {
Option = NetbufGetByte (Packet, IP6_ND_LENGTH, NULL);
ASSERT (Option != NULL);
//
// All included options should have a length that is greater than zero.
//
if (!Ip6IsNDOptionValid (Option, OptionLen)) {
goto Exit;
}
}
}
//
// If the IP destination address is a multicast address, Solicited Flag is ZERO.
//
Solicited = FALSE;
if ((Icmp.Fourth & IP6_SOLICITED_FLAG) == IP6_SOLICITED_FLAG) {
Solicited = TRUE;
}
if (IP6_IS_MULTICAST (&Head->DestinationAddress) && Solicited) {
goto Exit;
}
//
// DAD - Check whether the Target is one of our tentative address.
//
DupAddrDetect = Ip6FindDADEntry (IpSb, &Target, &IpIf);
if (DupAddrDetect != NULL) {
//
// DAD fails, some other node is using this address.
//
NetbufFree (Packet);
Ip6OnDADFinished (FALSE, IpIf, DupAddrDetect);
return EFI_ICMP_ERROR;
}
//
// Search the Neighbor Cache for the target's entry. If no entry exists,
// the advertisement should be silently discarded.
//
Neighbor = Ip6FindNeighborEntry (IpSb, &Target);
if (Neighbor == NULL) {
goto Exit;
}
//
// Get IsRouter Flag and Override Flag
//
IsRouter = FALSE;
Override = FALSE;
if ((Icmp.Fourth & IP6_IS_ROUTER_FLAG) == IP6_IS_ROUTER_FLAG) {
IsRouter = TRUE;
}
if ((Icmp.Fourth & IP6_OVERRIDE_FLAG) == IP6_OVERRIDE_FLAG) {
Override = TRUE;
}
//
// Check whether link layer option is included.
//
if (OptionLen >= sizeof (IP6_ETHER_ADDR_OPTION)) {
NetbufCopy (
Packet,
IP6_ND_LENGTH,
sizeof (IP6_ETHER_ADDR_OPTION),
(UINT8 *) &LinkLayerOption
);
if (LinkLayerOption.Type == Ip6OptionEtherTarget) {
Provided = TRUE;
}
}
Compare = 0;
if (Provided) {
Compare = CompareMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6);
}
if (!Neighbor->IsRouter && IsRouter) {
DefaultRouter = Ip6FindDefaultRouter (IpSb, &Target);
if (DefaultRouter != NULL) {
DefaultRouter->NeighborCache = Neighbor;
}
}
if (Neighbor->State == EfiNeighborInComplete) {
//
// If the target's Neighbor Cache entry is in INCOMPLETE state and no
// Target Link-Layer address option is included while link layer has
// address, the message should be silently discarded.
//
if (!Provided) {
goto Exit;
}
//
// Update the Neighbor Cache
//
CopyMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6);
if (Solicited) {
Neighbor->State = EfiNeighborReachable;
Neighbor->Ticks = IP6_GET_TICKS (IpSb->ReachableTime);
} else {
Neighbor->State = EfiNeighborStale;
Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
//
// Send any packets queued for the neighbor awaiting address resolution.
//
Neighbor->CallBack ((VOID *) Neighbor);
}
Neighbor->IsRouter = IsRouter;
} else {
if (!Override && Compare != 0) {
//
// When the Override Flag is clear and supplied link-layer address differs from
// that in the cache, if the state of the entry is not REACHABLE, ignore the
// message. Otherwise set it to STALE but do not update the entry in any
// other way.
//
if (Neighbor->State == EfiNeighborReachable) {
Neighbor->State = EfiNeighborStale;
Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
}
} else {
if (Compare != 0) {
CopyMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6);
}
//
// Update the entry's state
//
if (Solicited) {
Neighbor->State = EfiNeighborReachable;
Neighbor->Ticks = IP6_GET_TICKS (IpSb->ReachableTime);
} else {
if (Compare != 0) {
Neighbor->State = EfiNeighborStale;
Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
}
}
//
// When IsRouter is changed from TRUE to FALSE, remove the router from the
// Default Router List and remove the Destination Cache entries for all destinations
// using the neighbor as a router.
//
if (Neighbor->IsRouter && !IsRouter) {
DefaultRouter = Ip6FindDefaultRouter (IpSb, &Target);
if (DefaultRouter != NULL) {
Ip6DestroyDefaultRouter (IpSb, DefaultRouter);
}
}
Neighbor->IsRouter = IsRouter;
}
}
if (Neighbor->State == EfiNeighborReachable) {
Neighbor->CallBack ((VOID *) Neighbor);
}
Status = EFI_SUCCESS;
Exit:
NetbufFree (Packet);
return Status;
}
/**
Process the Router Advertisement message according to RFC4861.
@param[in] IpSb The IP service that received the packet.
@param[in] Head The IP head of the message.
@param[in] Packet The content of the message with the IP head removed.
@retval EFI_SUCCESS The packet processed successfully.
@retval EFI_INVALID_PARAMETER The packet is invalid.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
operation.
@retval Others Failed to process the packet.
**/
EFI_STATUS
Ip6ProcessRouterAdvertise (
IN IP6_SERVICE *IpSb,
IN EFI_IP6_HEADER *Head,
IN NET_BUF *Packet
)
{
IP6_ICMP_INFORMATION_HEAD Icmp;
UINT32 ReachableTime;
UINT32 RetransTimer;
UINT16 RouterLifetime;
UINT16 Offset;
UINT8 Type;
UINT8 Length;
IP6_ETHER_ADDR_OPTION LinkLayerOption;
UINT32 Fourth;
UINT8 CurHopLimit;
BOOLEAN Mflag;
BOOLEAN Oflag;
IP6_DEFAULT_ROUTER *DefaultRouter;
IP6_NEIGHBOR_ENTRY *NeighborCache;
EFI_MAC_ADDRESS LinkLayerAddress;
IP6_MTU_OPTION MTUOption;
IP6_PREFIX_INFO_OPTION PrefixOption;
IP6_PREFIX_LIST_ENTRY *PrefixList;
BOOLEAN OnLink;
BOOLEAN Autonomous;
EFI_IPv6_ADDRESS StatelessAddress;
EFI_STATUS Status;
UINT16 OptionLen;
UINT8 *Option;
INTN Result;
Status = EFI_INVALID_PARAMETER;
if (IpSb->Ip6ConfigInstance.Policy != Ip6ConfigPolicyAutomatic) {
//
// Skip the process below as it's not required under the current policy.
//
goto Exit;
}
NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);
//
// Validate the incoming Router Advertisement
//
//
// The IP source address must be a link-local address
//
if (!NetIp6IsLinkLocalAddr (&Head->SourceAddress)) {
goto Exit;
}
//
// The IP Hop Limit field has a value of 255, i.e. the packet
// could not possibly have been forwarded by a router.
// ICMP Code is 0.
// ICMP length (derived from the IP length) is 16 or more octets.
//
if (Head->HopLimit != IP6_HOP_LIMIT || Icmp.Head.Code != 0 ||
Head->PayloadLength < IP6_RA_LENGTH) {
goto Exit;
}
//
// All included options have a length that is greater than zero.
//
OptionLen = (UINT16) (Head->PayloadLength - IP6_RA_LENGTH);
if (OptionLen != 0) {
Option = NetbufGetByte (Packet, IP6_RA_LENGTH, NULL);
ASSERT (Option != NULL);
if (!Ip6IsNDOptionValid (Option, OptionLen)) {
goto Exit;
}
}
//
// Process Fourth field.
// In Router Advertisement, Fourth is composed of CurHopLimit (8bit), M flag, O flag,
// and Router Lifetime (16 bit).
//
Fourth = NTOHL (Icmp.Fourth);
CopyMem (&RouterLifetime, &Fourth, sizeof (UINT16));
//
// If the source address already in the default router list, update it.
// Otherwise create a new entry.
// A Lifetime of zero indicates that the router is not a default router.
//
DefaultRouter = Ip6FindDefaultRouter (IpSb, &Head->SourceAddress);
if (DefaultRouter == NULL) {
if (RouterLifetime != 0) {
DefaultRouter = Ip6CreateDefaultRouter (IpSb, &Head->SourceAddress, RouterLifetime);
if (DefaultRouter == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
}
} else {
if (RouterLifetime != 0) {
DefaultRouter->Lifetime = RouterLifetime;
//
// Check the corresponding neighbor cache entry here.
//
if (DefaultRouter->NeighborCache == NULL) {
DefaultRouter->NeighborCache = Ip6FindNeighborEntry (IpSb, &Head->SourceAddress);
}
} else {
//
// If the address is in the host's default router list and the router lifetime is zero,
// immediately time-out the entry.
//
Ip6DestroyDefaultRouter (IpSb, DefaultRouter);
}
}
CurHopLimit = *((UINT8 *) &Fourth + 3);
if (CurHopLimit != 0) {
IpSb->CurHopLimit = CurHopLimit;
}
Mflag = FALSE;
Oflag = FALSE;
if ((*((UINT8 *) &Fourth + 2) & IP6_M_ADDR_CONFIG_FLAG) == IP6_M_ADDR_CONFIG_FLAG) {
Mflag = TRUE;
} else {
if ((*((UINT8 *) &Fourth + 2) & IP6_O_CONFIG_FLAG) == IP6_O_CONFIG_FLAG) {
Oflag = TRUE;
}
}
if (Mflag || Oflag) {
//
// Use Ip6Config to get available addresses or other configuration from DHCP.
//
Ip6ConfigStartStatefulAutoConfig (&IpSb->Ip6ConfigInstance, Oflag);
}
//
// Process Reachable Time and Retrans Timer fields.
//
NetbufCopy (Packet, sizeof (Icmp), sizeof (UINT32), (UINT8 *) &ReachableTime);
NetbufCopy (Packet, sizeof (Icmp) + sizeof (UINT32), sizeof (UINT32), (UINT8 *) &RetransTimer);
ReachableTime = NTOHL (ReachableTime);
RetransTimer = NTOHL (RetransTimer);
if (ReachableTime != 0 && ReachableTime != IpSb->BaseReachableTime) {
//
// If new value is not unspecified and differs from the previous one, record it
// in BaseReachableTime and recompute a ReachableTime.
//
IpSb->BaseReachableTime = ReachableTime;
Ip6UpdateReachableTime (IpSb);
}
if (RetransTimer != 0) {
IpSb->RetransTimer = RetransTimer;
}
//
// IsRouter flag must be set to TRUE if corresponding neighbor cache entry exists.
//
NeighborCache = Ip6FindNeighborEntry (IpSb, &Head->SourceAddress);
if (NeighborCache != NULL) {
NeighborCache->IsRouter = TRUE;
}
//
// If an valid router advertisment is received, stops router solicitation.
//
IpSb->RouterAdvertiseReceived = TRUE;
//
// The only defined options that may appear are the Source
// Link-Layer Address, Prefix information and MTU options.
// All included options have a length that is greater than zero.
//
Offset = 16;
while (Offset < Head->PayloadLength) {
NetbufCopy (Packet, Offset, sizeof (UINT8), &Type);
switch (Type) {
case Ip6OptionEtherSource:
//
// Update the neighbor cache
//
NetbufCopy (Packet, Offset, sizeof (IP6_ETHER_ADDR_OPTION), (UINT8 *) &LinkLayerOption);
if (LinkLayerOption.Length <= 0) {
goto Exit;
}
ZeroMem (&LinkLayerAddress, sizeof (EFI_MAC_ADDRESS));
CopyMem (&LinkLayerAddress, LinkLayerOption.EtherAddr, 6);
if (NeighborCache == NULL) {
NeighborCache = Ip6CreateNeighborEntry (
IpSb,
Ip6OnArpResolved,
&Head->SourceAddress,
&LinkLayerAddress
);
if (NeighborCache == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
NeighborCache->IsRouter = TRUE;
NeighborCache->State = EfiNeighborStale;
NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
} else {
Result = CompareMem (&LinkLayerAddress, &NeighborCache->LinkAddress, 6);
//
// If the link-local address is the same as that already in the cache,
// the cache entry's state remains unchanged. Otherwise update the
// reachability state to STALE.
//
if ((NeighborCache->State == EfiNeighborInComplete) || (Result != 0)) {
CopyMem (&NeighborCache->LinkAddress, &LinkLayerAddress, 6);
NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
if (NeighborCache->State == EfiNeighborInComplete) {
//
// Send queued packets if exist.
//
NeighborCache->State = EfiNeighborStale;
NeighborCache->CallBack ((VOID *) NeighborCache);
} else {
NeighborCache->State = EfiNeighborStale;
}
}
}
Offset = (UINT16) (Offset + (UINT16) LinkLayerOption.Length * 8);
break;
case Ip6OptionPrefixInfo:
NetbufCopy (Packet, Offset, sizeof (IP6_PREFIX_INFO_OPTION), (UINT8 *) &PrefixOption);
if (PrefixOption.Length != 4) {
goto Exit;
}
PrefixOption.ValidLifetime = NTOHL (PrefixOption.ValidLifetime);
PrefixOption.PreferredLifetime = NTOHL (PrefixOption.PreferredLifetime);
//
// Get L and A flag, recorded in the lower 2 bits of Reserved1
//
OnLink = FALSE;
if ((PrefixOption.Reserved1 & IP6_ON_LINK_FLAG) == IP6_ON_LINK_FLAG) {
OnLink = TRUE;
}
Autonomous = FALSE;
if ((PrefixOption.Reserved1 & IP6_AUTO_CONFIG_FLAG) == IP6_AUTO_CONFIG_FLAG) {
Autonomous = TRUE;
}
//
// If the prefix is the link-local prefix, silently ignore the prefix option.
//
if (PrefixOption.PrefixLength == IP6_LINK_LOCAL_PREFIX_LENGTH &&
NetIp6IsLinkLocalAddr (&PrefixOption.Prefix)
) {
Offset += sizeof (IP6_PREFIX_INFO_OPTION);
break;
}
//
// Do following if on-link flag is set according to RFC4861.
//
if (OnLink) {
PrefixList = Ip6FindPrefixListEntry (
IpSb,
TRUE,
PrefixOption.PrefixLength,
&PrefixOption.Prefix
);
//
// Create a new entry for the prefix, if the ValidLifetime is zero,
// silently ignore the prefix option.
//
if (PrefixList == NULL && PrefixOption.ValidLifetime != 0) {
PrefixList = Ip6CreatePrefixListEntry (
IpSb,
TRUE,
PrefixOption.ValidLifetime,
PrefixOption.PreferredLifetime,
PrefixOption.PrefixLength,
&PrefixOption.Prefix
);
if (PrefixList == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
} else if (PrefixList != NULL) {
if (PrefixOption.ValidLifetime != 0) {
PrefixList->ValidLifetime = PrefixOption.ValidLifetime;
} else {
//
// If the prefix exists and incoming ValidLifetime is zero, immediately
// remove the prefix.
Ip6DestroyPrefixListEntry (IpSb, PrefixList, OnLink, TRUE);
}
}
}
//
// Do following if Autonomous flag is set according to RFC4862.
//
if (Autonomous && PrefixOption.PreferredLifetime <= PrefixOption.ValidLifetime) {
PrefixList = Ip6FindPrefixListEntry (
IpSb,
FALSE,
PrefixOption.PrefixLength,
&PrefixOption.Prefix
);
//
// Create a new entry for the prefix, and form an address by prefix + interface id
// If the sum of the prefix length and interface identifier length
// does not equal 128 bits, the Prefix Information option MUST be ignored.
//
if (PrefixList == NULL &&
PrefixOption.ValidLifetime != 0 &&
PrefixOption.PrefixLength + IpSb->InterfaceIdLen * 8 == 128
) {
//
// Form the address in network order.
//
CopyMem (&StatelessAddress, &PrefixOption.Prefix, sizeof (UINT64));
CopyMem (&StatelessAddress.Addr[8], IpSb->InterfaceId, sizeof (UINT64));
//
// If the address is not yet in the assigned address list, adds it into.
//
if (!Ip6IsOneOfSetAddress (IpSb, &StatelessAddress, NULL, NULL)) {
//
// And also not in the DAD process, check its uniqeness firstly.
//
if (Ip6FindDADEntry (IpSb, &StatelessAddress, NULL) == NULL) {
Status = Ip6SetAddress (
IpSb->DefaultInterface,
&StatelessAddress,
FALSE,
PrefixOption.PrefixLength,
PrefixOption.ValidLifetime,
PrefixOption.PreferredLifetime,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
goto Exit;
}
}
}
//
// Adds the prefix option to stateless prefix option list.
//
PrefixList = Ip6CreatePrefixListEntry (
IpSb,
FALSE,
PrefixOption.ValidLifetime,
PrefixOption.PreferredLifetime,
PrefixOption.PrefixLength,
&PrefixOption.Prefix
);
if (PrefixList == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
} else if (PrefixList != NULL) {
//
// Reset the preferred lifetime of the address if the advertised prefix exists.
// Perform specific action to valid lifetime together.
//
PrefixList->PreferredLifetime = PrefixOption.PreferredLifetime;
if ((PrefixOption.ValidLifetime > 7200) ||
(PrefixOption.ValidLifetime > PrefixList->ValidLifetime)) {
//
// If the received Valid Lifetime is greater than 2 hours or
// greater than RemainingLifetime, set the valid lifetime of the
// corresponding address to the advertised Valid Lifetime.
//
PrefixList->ValidLifetime = PrefixOption.ValidLifetime;
} else if (PrefixList->ValidLifetime <= 7200) {
//
// If RemainingLifetime is less than or equls to 2 hours, ignore the
// Prefix Information option with regards to the valid lifetime.
// TODO: If this option has been authenticated, set the valid lifetime.
//
} else {
//
// Otherwise, reset the valid lifetime of the corresponding
// address to 2 hours.
//
PrefixList->ValidLifetime = 7200;
}
}
}
Offset += sizeof (IP6_PREFIX_INFO_OPTION);
break;
case Ip6OptionMtu:
NetbufCopy (Packet, Offset, sizeof (IP6_MTU_OPTION), (UINT8 *) &MTUOption);
if (MTUOption.Length != 1) {
goto Exit;
}
//
// Use IPv6 minimum link MTU 1280 bytes as the maximum packet size in order
// to omit implementation of Path MTU Discovery. Thus ignore the MTU option
// in Router Advertisement.
//
Offset += sizeof (IP6_MTU_OPTION);
break;
default:
//
// Silently ignore unrecognized options
//
NetbufCopy (Packet, Offset + sizeof (UINT8), sizeof (UINT8), &Length);
if (Length <= 0) {
goto Exit;
}
Offset = (UINT16) (Offset + (UINT16) Length * 8);
break;
}
}
Status = EFI_SUCCESS;
Exit:
NetbufFree (Packet);
return Status;
}
/**
Process the ICMPv6 redirect message. Find the instance, then update
its route cache.
@param[in] IpSb The IP6 service binding instance that received
the packet.
@param[in] Head The IP head of the received ICMPv6 packet.
@param[in] Packet The content of the ICMPv6 redirect packet with
the IP head removed.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Insuffcient resources to complete the
operation.
@retval EFI_SUCCESS Successfully updated the route caches.
**/
EFI_STATUS
Ip6ProcessRedirect (
IN IP6_SERVICE *IpSb,
IN EFI_IP6_HEADER *Head,
IN NET_BUF *Packet
)
{
IP6_ICMP_INFORMATION_HEAD *Icmp;
EFI_IPv6_ADDRESS *Target;
EFI_IPv6_ADDRESS *IcmpDest;
UINT8 *Option;
UINT16 OptionLen;
IP6_ROUTE_ENTRY *RouteEntry;
IP6_ROUTE_CACHE_ENTRY *RouteCache;
IP6_NEIGHBOR_ENTRY *NeighborCache;
INT32 Length;
UINT8 OptLen;
IP6_ETHER_ADDR_OPTION *LinkLayerOption;
EFI_MAC_ADDRESS Mac;
UINT32 Index;
BOOLEAN IsRouter;
EFI_STATUS Status;
INTN Result;
Status = EFI_INVALID_PARAMETER;
Icmp = (IP6_ICMP_INFORMATION_HEAD *) NetbufGetByte (Packet, 0, NULL);
if (Icmp == NULL) {
goto Exit;
}
//
// Validate the incoming Redirect message
//
//
// The IP Hop Limit field has a value of 255, i.e. the packet
// could not possibly have been forwarded by a router.
// ICMP Code is 0.
// ICMP length (derived from the IP length) is 40 or more octets.
//
if (Head->HopLimit != IP6_HOP_LIMIT || Icmp->Head.Code != 0 ||
Head->PayloadLength < IP6_REDITECT_LENGTH) {
goto Exit;
}
//
// The IP source address must be a link-local address
//
if (!NetIp6IsLinkLocalAddr (&Head->SourceAddress)) {
goto Exit;
}
//
// The dest of this ICMP redirect message is not us.
//
if (!Ip6IsOneOfSetAddress (IpSb, &Head->DestinationAddress, NULL, NULL)) {
goto Exit;
}
//
// All included options have a length that is greater than zero.
//
OptionLen = (UINT16) (Head->PayloadLength - IP6_REDITECT_LENGTH);
if (OptionLen != 0) {
Option = NetbufGetByte (Packet, IP6_REDITECT_LENGTH, NULL);
ASSERT (Option != NULL);
if (!Ip6IsNDOptionValid (Option, OptionLen)) {
goto Exit;
}
}
Target = (EFI_IPv6_ADDRESS *) (Icmp + 1);
IcmpDest = Target + 1;
//
// The ICMP Destination Address field in the redirect message does not contain
// a multicast address.
//
if (IP6_IS_MULTICAST (IcmpDest)) {
goto Exit;
}
//
// The ICMP Target Address is either a link-local address (when redirected to
// a router) or the same as the ICMP Destination Address (when redirected to
// the on-link destination).
//
IsRouter = (BOOLEAN) !EFI_IP6_EQUAL (Target, IcmpDest);
if (!NetIp6IsLinkLocalAddr (Target) && IsRouter) {
goto Exit;
}
//
// Check the options. The only interested option here is the target-link layer
// address option.
//
Length = Packet->TotalSize - 40;
Option = (UINT8 *) (IcmpDest + 1);
LinkLayerOption = NULL;
while (Length > 0) {
switch (*Option) {
case Ip6OptionEtherTarget:
LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) Option;
OptLen = LinkLayerOption->Length;
if (OptLen != 1) {
//
// For ethernet, the length must be 1.
//
goto Exit;
}
break;
default:
OptLen = *(Option + 1);
if (OptLen == 0) {
//
// A length of 0 is invalid.
//
goto Exit;
}
break;
}
Length -= 8 * OptLen;
Option += 8 * OptLen;
}
if (Length != 0) {
goto Exit;
}
//
// The IP source address of the Redirect is the same as the current
// first-hop router for the specified ICMP Destination Address.
//
RouteCache = Ip6FindRouteCache (IpSb->RouteTable, IcmpDest, &Head->DestinationAddress);
if (RouteCache != NULL) {
if (!EFI_IP6_EQUAL (&RouteCache->NextHop, &Head->SourceAddress)) {
//
// The source of this Redirect message must match the NextHop of the
// corresponding route cache entry.
//
goto Exit;
}
//
// Update the NextHop.
//
IP6_COPY_ADDRESS (&RouteCache->NextHop, Target);
if (!IsRouter) {
RouteEntry = (IP6_ROUTE_ENTRY *) RouteCache->Tag;
RouteEntry->Flag = RouteEntry->Flag | IP6_DIRECT_ROUTE;
}
} else {
//
// Get the Route Entry.
//
RouteEntry = Ip6FindRouteEntry (IpSb->RouteTable, IcmpDest, NULL);
if (RouteEntry == NULL) {
RouteEntry = Ip6CreateRouteEntry (IcmpDest, 0, NULL);
if (RouteEntry == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
}
if (!IsRouter) {
RouteEntry->Flag = IP6_DIRECT_ROUTE;
}
//
// Create a route cache for this.
//
RouteCache = Ip6CreateRouteCacheEntry (
IcmpDest,
&Head->DestinationAddress,
Target,
(UINTN) RouteEntry
);
if (RouteCache == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Insert the newly created route cache entry.
//
Index = IP6_ROUTE_CACHE_HASH (IcmpDest, &Head->DestinationAddress);
InsertHeadList (&IpSb->RouteTable->Cache.CacheBucket[Index], &RouteCache->Link);
}
//
// Try to locate the neighbor cache for the Target.
//
NeighborCache = Ip6FindNeighborEntry (IpSb, Target);
if (LinkLayerOption != NULL) {
if (NeighborCache == NULL) {
//
// Create a neighbor cache for the Target.
//
ZeroMem (&Mac, sizeof (EFI_MAC_ADDRESS));
CopyMem (&Mac, LinkLayerOption->EtherAddr, 6);
NeighborCache = Ip6CreateNeighborEntry (IpSb, Ip6OnArpResolved, Target, &Mac);
if (NeighborCache == NULL) {
//
// Just report a success here. The neighbor cache can be created in
// some other place.
//
Status = EFI_SUCCESS;
goto Exit;
}
NeighborCache->State = EfiNeighborStale;
NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
} else {
Result = CompareMem (LinkLayerOption->EtherAddr, &NeighborCache->LinkAddress, 6);
//
// If the link-local address is the same as that already in the cache,
// the cache entry's state remains unchanged. Otherwise update the
// reachability state to STALE.
//
if ((NeighborCache->State == EfiNeighborInComplete) || (Result != 0)) {
CopyMem (&NeighborCache->LinkAddress, LinkLayerOption->EtherAddr, 6);
NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
if (NeighborCache->State == EfiNeighborInComplete) {
//
// Send queued packets if exist.
//
NeighborCache->State = EfiNeighborStale;
NeighborCache->CallBack ((VOID *) NeighborCache);
} else {
NeighborCache->State = EfiNeighborStale;
}
}
}
}
if (NeighborCache != NULL && IsRouter) {
//
// The Target is a router, set IsRouter to TRUE.
//
NeighborCache->IsRouter = TRUE;
}
Status = EFI_SUCCESS;
Exit:
NetbufFree (Packet);
return Status;
}
/**
Add Neighbor cache entries. It is a work function for EfiIp6Neighbors().
@param[in] IpSb The IP6 service binding instance.
@param[in] TargetIp6Address Pointer to Target IPv6 address.
@param[in] TargetLinkAddress Pointer to link-layer address of the target. Ignored if NULL.
@param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
cache. It will be deleted after Timeout. A value of zero means that
the entry is permanent. A non-zero value means that the entry is
dynamic.
@param[in] Override If TRUE, the cached link-layer address of the matching entry will
be overridden and updated; if FALSE, and if a
corresponding cache entry already existed, EFI_ACCESS_DENIED
will be returned.
@retval EFI_SUCCESS The neighbor cache entry has been added.
@retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache
due to insufficient resources.
@retval EFI_NOT_FOUND TargetLinkAddress is NULL.
@retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
and that entry is tagged as un-overridden (when DeleteFlag
is FALSE).
**/
EFI_STATUS
Ip6AddNeighbor (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *TargetIp6Address,
IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL,
IN UINT32 Timeout,
IN BOOLEAN Override
)
{
IP6_NEIGHBOR_ENTRY *Neighbor;
Neighbor = Ip6FindNeighborEntry (IpSb, TargetIp6Address);
if (Neighbor != NULL) {
if (!Override) {
return EFI_ACCESS_DENIED;
} else {
if (TargetLinkAddress != NULL) {
IP6_COPY_LINK_ADDRESS (&Neighbor->LinkAddress, TargetLinkAddress);
}
}
} else {
if (TargetLinkAddress == NULL) {
return EFI_NOT_FOUND;
}
Neighbor = Ip6CreateNeighborEntry (IpSb, Ip6OnArpResolved, TargetIp6Address, TargetLinkAddress);
if (Neighbor == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
Neighbor->State = EfiNeighborReachable;
if (Timeout != 0) {
Neighbor->Ticks = IP6_GET_TICKS (Timeout / TICKS_PER_MS);
Neighbor->Dynamic = TRUE;
} else {
Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
}
return EFI_SUCCESS;
}
/**
Delete or update Neighbor cache entries. It is a work function for EfiIp6Neighbors().
@param[in] IpSb The IP6 service binding instance.
@param[in] TargetIp6Address Pointer to Target IPv6 address.
@param[in] TargetLinkAddress Pointer to link-layer address of the target. Ignored if NULL.
@param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
cache. It will be deleted after Timeout. A value of zero means that
the entry is permanent. A non-zero value means that the entry is
dynamic.
@param[in] Override If TRUE, the cached link-layer address of the matching entry will
be overridden and updated; if FALSE, and if a
corresponding cache entry already existed, EFI_ACCESS_DENIED
will be returned.
@retval EFI_SUCCESS The neighbor cache entry has been updated or deleted.
@retval EFI_NOT_FOUND This entry is not in the neighbor cache.
**/
EFI_STATUS
Ip6DelNeighbor (
IN IP6_SERVICE *IpSb,
IN EFI_IPv6_ADDRESS *TargetIp6Address,
IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL,
IN UINT32 Timeout,
IN BOOLEAN Override
)
{
IP6_NEIGHBOR_ENTRY *Neighbor;
Neighbor = Ip6FindNeighborEntry (IpSb, TargetIp6Address);
if (Neighbor == NULL) {
return EFI_NOT_FOUND;
}
RemoveEntryList (&Neighbor->Link);
FreePool (Neighbor);
return EFI_SUCCESS;
}
/**
The heartbeat timer of ND module in IP6_TIMER_INTERVAL_IN_MS milliseconds.
This time routine handles DAD module and neighbor state transition.
It is also responsible for sending out router solicitations.
@param[in] Event The IP6 service instance's heartbeat timer.
@param[in] Context The IP6 service instance.
**/
VOID
EFIAPI
Ip6NdFasterTimerTicking (
IN EFI_EVENT Event,
IN VOID *Context
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
LIST_ENTRY *Entry2;
IP6_INTERFACE *IpIf;
IP6_DELAY_JOIN_LIST *DelayNode;
EFI_IPv6_ADDRESS Source;
IP6_DAD_ENTRY *DupAddrDetect;
EFI_STATUS Status;
IP6_NEIGHBOR_ENTRY *NeighborCache;
EFI_IPv6_ADDRESS Destination;
IP6_SERVICE *IpSb;
BOOLEAN Flag;
IpSb = (IP6_SERVICE *) Context;
NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
ZeroMem (&Source, sizeof (EFI_IPv6_ADDRESS));
//
// A host SHOULD transmit up to MAX_RTR_SOLICITATIONS (3) Router
// Solicitation messages, each separated by at least
// RTR_SOLICITATION_INTERVAL (4) seconds.
//
if ((IpSb->Ip6ConfigInstance.Policy == Ip6ConfigPolicyAutomatic) &&
!IpSb->RouterAdvertiseReceived &&
IpSb->SolicitTimer > 0
) {
if ((IpSb->Ticks == 0) || (--IpSb->Ticks == 0)) {
Status = Ip6SendRouterSolicit (IpSb, NULL, NULL, NULL, NULL);
if (!EFI_ERROR (Status)) {
IpSb->SolicitTimer--;
IpSb->Ticks = (UINT32) IP6_GET_TICKS (IP6_RTR_SOLICITATION_INTERVAL);
}
}
}
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP6_INTERFACE, Link);
//
// Process the delay list to join the solicited-node multicast address.
//
NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DelayJoinList) {
DelayNode = NET_LIST_USER_STRUCT (Entry2, IP6_DELAY_JOIN_LIST, Link);
if ((DelayNode->DelayTime == 0) || (--DelayNode->DelayTime == 0)) {
//
// The timer expires, init the duplicate address detection.
//
Ip6InitDADProcess (
DelayNode->Interface,
DelayNode->AddressInfo,
DelayNode->DadCallback,
DelayNode->Context
);
//
// Remove the delay node
//
RemoveEntryList (&DelayNode->Link);
FreePool (DelayNode);
}
}
//
// Process the duplicate address detection list.
//
NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DupAddrDetectList) {
DupAddrDetect = NET_LIST_USER_STRUCT (Entry2, IP6_DAD_ENTRY, Link);
if ((DupAddrDetect->RetransTick == 0) || (--DupAddrDetect->RetransTick == 0)) {
//
// The timer expires, check the remaining transmit counts.
//
if (DupAddrDetect->Transmit < DupAddrDetect->MaxTransmit) {
//
// Send the Neighbor Solicitation message with
// Source - unspecified address, destination - solicited-node multicast address
// Target - the address to be validated
//
Status = Ip6SendNeighborSolicit (
IpSb,
NULL,
&DupAddrDetect->Destination,
&DupAddrDetect->AddressInfo->Address,
NULL
);
if (EFI_ERROR (Status)) {
return;
}
DupAddrDetect->Transmit++;
DupAddrDetect->RetransTick = IP6_GET_TICKS (IpSb->RetransTimer);
} else {
//
// All required solicitation has been sent out, and the RetransTime after the last
// Neighbor Solicit is elapsed, finish the DAD process.
//
Flag = FALSE;
if ((DupAddrDetect->Receive == 0) ||
(DupAddrDetect->Transmit == DupAddrDetect->Receive)) {
Flag = TRUE;
}
Ip6OnDADFinished (Flag, IpIf, DupAddrDetect);
}
}
}
}
//
// Polling the state of Neighbor cache
//
NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->NeighborTable) {
NeighborCache = NET_LIST_USER_STRUCT (Entry, IP6_NEIGHBOR_ENTRY, Link);
switch (NeighborCache->State) {
case EfiNeighborInComplete:
if (NeighborCache->Ticks > 0) {
--NeighborCache->Ticks;
}
//
// Retransmit Neighbor Solicitation messages approximately every
// RetransTimer milliseconds while awaiting a response.
//
if (NeighborCache->Ticks == 0) {
if (NeighborCache->Transmit > 1) {
//
// Send out multicast neighbor solicitation for address resolution.
// After last neighbor solicitation message has been sent out, wait
// for RetransTimer and then remove entry if no response is received.
//
Ip6CreateSNMulticastAddr (&NeighborCache->Neighbor, &Destination);
Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source);
if (EFI_ERROR (Status)) {
return;
}
Status = Ip6SendNeighborSolicit (
IpSb,
&Source,
&Destination,
&NeighborCache->Neighbor,
&IpSb->SnpMode.CurrentAddress
);
if (EFI_ERROR (Status)) {
return;
}
}
//
// Update the retransmit times.
//
if (NeighborCache->Transmit > 0) {
--NeighborCache->Transmit;
NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer);
}
}
if (NeighborCache->Transmit == 0) {
//
// Timeout, send ICMP destination unreachable packet and then remove entry
//
Status = Ip6FreeNeighborEntry (
IpSb,
NeighborCache,
TRUE,
TRUE,
EFI_ICMP_ERROR,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
return;
}
}
break;
case EfiNeighborReachable:
//
// This entry is inserted by EfiIp6Neighbors() as static entry
// and will not timeout.
//
if (!NeighborCache->Dynamic && (NeighborCache->Ticks == IP6_INFINIT_LIFETIME)) {
break;
}
if ((NeighborCache->Ticks == 0) || (--NeighborCache->Ticks == 0)) {
if (NeighborCache->Dynamic) {
//
// This entry is inserted by EfiIp6Neighbors() as dynamic entry
// and will be deleted after timeout.
//
Status = Ip6FreeNeighborEntry (
IpSb,
NeighborCache,
FALSE,
TRUE,
EFI_TIMEOUT,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
return;
}
} else {
NeighborCache->State = EfiNeighborStale;
NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME;
}
}
break;
case EfiNeighborDelay:
if ((NeighborCache->Ticks == 0) || (--NeighborCache->Ticks == 0)) {
NeighborCache->State = EfiNeighborProbe;
NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer);
NeighborCache->Transmit = IP6_MAX_UNICAST_SOLICIT + 1;
//
// Send out unicast neighbor solicitation for Neighbor Unreachability Detection
//
Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source);
if (EFI_ERROR (Status)) {
return;
}
Status = Ip6SendNeighborSolicit (
IpSb,
&Source,
&NeighborCache->Neighbor,
&NeighborCache->Neighbor,
&IpSb->SnpMode.CurrentAddress
);
if (EFI_ERROR (Status)) {
return;
}
NeighborCache->Transmit--;
}
break;
case EfiNeighborProbe:
if (NeighborCache->Ticks > 0) {
--NeighborCache->Ticks;
}
//
// Retransmit Neighbor Solicitation messages approximately every
// RetransTimer milliseconds while awaiting a response.
//
if (NeighborCache->Ticks == 0) {
if (NeighborCache->Transmit > 1) {
//
// Send out unicast neighbor solicitation for Neighbor Unreachability
// Detection. After last neighbor solicitation message has been sent out,
// wait for RetransTimer and then remove entry if no response is received.
//
Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source);
if (EFI_ERROR (Status)) {
return;
}
Status = Ip6SendNeighborSolicit (
IpSb,
&Source,
&NeighborCache->Neighbor,
&NeighborCache->Neighbor,
&IpSb->SnpMode.CurrentAddress
);
if (EFI_ERROR (Status)) {
return;
}
}
//
// Update the retransmit times.
//
if (NeighborCache->Transmit > 0) {
--NeighborCache->Transmit;
NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer);
}
}
if (NeighborCache->Transmit == 0) {
//
// Delete the neighbor entry.
//
Status = Ip6FreeNeighborEntry (
IpSb,
NeighborCache,
FALSE,
TRUE,
EFI_TIMEOUT,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
return;
}
}
break;
default:
break;
}
}
}
/**
The heartbeat timer of ND module in 1 second. This time routine handles following
things: 1) maitain default router list; 2) maintain prefix options;
3) maintain route caches.
@param[in] IpSb The IP6 service binding instance.
**/
VOID
Ip6NdTimerTicking (
IN IP6_SERVICE *IpSb
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP6_DEFAULT_ROUTER *DefaultRouter;
IP6_PREFIX_LIST_ENTRY *PrefixOption;
UINT8 Index;
IP6_ROUTE_CACHE_ENTRY *RouteCache;
//
// Decrease the lifetime of default router, if expires remove it from default router list.
//
NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->DefaultRouterList) {
DefaultRouter = NET_LIST_USER_STRUCT (Entry, IP6_DEFAULT_ROUTER, Link);
if (DefaultRouter->Lifetime != IP6_INF_ROUTER_LIFETIME) {
if ((DefaultRouter->Lifetime == 0) || (--DefaultRouter->Lifetime == 0)) {
Ip6DestroyDefaultRouter (IpSb, DefaultRouter);
}
}
}
//
// Decrease Valid lifetime and Preferred lifetime of Prefix options and corresponding addresses.
//
NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->AutonomousPrefix) {
PrefixOption = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link);
if (PrefixOption->ValidLifetime != (UINT32) IP6_INFINIT_LIFETIME) {
if ((PrefixOption->ValidLifetime > 0) && (--PrefixOption->ValidLifetime > 0)) {
if ((PrefixOption->PreferredLifetime != (UINT32) IP6_INFINIT_LIFETIME) &&
(PrefixOption->PreferredLifetime > 0)
) {
--PrefixOption->PreferredLifetime;
}
} else {
Ip6DestroyPrefixListEntry (IpSb, PrefixOption, FALSE, TRUE);
}
}
}
NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->OnlinkPrefix) {
PrefixOption = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link);
if (PrefixOption->ValidLifetime != (UINT32) IP6_INFINIT_LIFETIME) {
if ((PrefixOption->ValidLifetime == 0) || (--PrefixOption->ValidLifetime == 0)) {
Ip6DestroyPrefixListEntry (IpSb, PrefixOption, TRUE, TRUE);
}
}
}
//
// Each bucket of route cache can contain at most IP6_ROUTE_CACHE_MAX entries.
// Remove the entries at the tail of the bucket. These entries
// are likely to be used least.
// Reclaim frequency is set to 1 second.
//
for (Index = 0; Index < IP6_ROUTE_CACHE_HASH_SIZE; Index++) {
while (IpSb->RouteTable->Cache.CacheNum[Index] > IP6_ROUTE_CACHE_MAX) {
Entry = NetListRemoveTail (&IpSb->RouteTable->Cache.CacheBucket[Index]);
if (Entry == NULL) {
break;
}
RouteCache = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_CACHE_ENTRY, Link);
Ip6FreeRouteCacheEntry (RouteCache);
ASSERT (IpSb->RouteTable->Cache.CacheNum[Index] > 0);
IpSb->RouteTable->Cache.CacheNum[Index]--;
}
}
}
|