summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ipv6.c
blob: 2e62cf296ffcfc9d37acd3e649fa7d28e31cfa3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
/* packet-ipv6.c
 * Routines for IPv6 packet disassembly
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SHIM6 support added by Matthijs Mekking <matthijs@NLnetLabs.nl>
 *
 * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
 *
 * Added support for new IPv6 Hop by Hop PMTU Option  <bob.hinden@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <math.h>
#include <epan/packet.h>
#include <epan/capture_dissectors.h>
#include <epan/expert.h>
#include <epan/ip_opts.h>
#include <epan/addr_resolv.h>
#include <epan/maxmind_db.h>
#include <epan/prefs.h>
#include <epan/uat.h>
#include <epan/conversation_table.h>
#include <epan/conversation_filter.h>
#include <epan/reassemble.h>
#include <epan/ipproto.h>
#include <epan/etypes.h>
#include <epan/ppptypes.h>
#include <epan/aftypes.h>
#include <epan/nlpid.h>
#include <epan/arcnet_pids.h>
#include <epan/decode_as.h>
#include <epan/proto_data.h>
#include <epan/to_str.h>
#include <epan/exported_pdu.h>

#include <wiretap/erf_record.h>
#include <wsutil/str_util.h>
#include "packet-ip.h"
#include "packet-juniper.h"
#include "packet-sflow.h"
#include "packet-vxlan.h"
#include "packet-mpls.h"
#include "packet-nsh.h"

void proto_register_ipv6(void);
void proto_reg_handoff_ipv6(void);

/* Offsets of fields within an IPv6 header. */
#define IP6H_CTL_VFC    0
#define IP6H_CTL_FLOW   0
#define IP6H_CTL_PLEN   4
#define IP6H_CTL_NXT    6
#define IP6H_CTL_HLIM   7
#define IP6H_SRC        8
#define IP6H_DST        24

/* Option types and related macros */
#define IP6OPT_PAD1                     0x00    /* 00 0 00000 =   0 */
#define IP6OPT_PADN                     0x01    /* 00 0 00001 =   1 */
#define IP6OPT_TEL                      0x04    /* 00 0 00100 =   4 */
#define IP6OPT_RTALERT                  0x05    /* 00 0 00101 =   5 */
#define IP6OPT_CALIPSO                  0x07    /* 00 0 00111 =   7 */
#define IP6OPT_SMF_DPD                  0x08    /* 00 0 01000 =   8 */
#define IP6OPT_PDM                      0x0F    /* 00 0 01111 =  15 */
#define IP6OPT_APN6                     0x13    /* 00 0 10003 =  19 */
#define IP6OPT_EXP_1E                   0x1E    /* 00 0 11110 =  30 */
#define IP6OPT_RPL                      0x23    /* 00 1 00011 =  35 */
#define IP6OPT_QUICKSTART               0x26    /* 00 1 00110 =  38 */
#define IP6OPT_PMTU                     0x30    /* 00 1 10000 =  48 */
#define IP6OPT_IOAM                     0x31    /* 00 1 10001 =  49 */
#define IP6OPT_EXP_3E                   0x3E    /* 00 1 11110 =  62 */
#define IP6OPT_TPF                      0x41    /* 01 0 00001 =  65 */
#define IP6OPT_EXP_5E                   0x5E    /* 01 0 11110 =  94 */
#define IP6OPT_RPL_OLD                  0x63    /* 01 1 00011 =  99 */ /* DEPRECATED */
#define IP6OPT_MPL                      0x6D    /* 01 1 01101 = 109 */
#define IP6OPT_EXP_7E                   0x7E    /* 01 1 11110 = 126 */
#define IP6OPT_ENDI                     0x8A    /* 10 0 01010 = 138 */ /* DEPRECATED */
#define IP6OPT_ILNP_NONCE               0x8B    /* 10 0 01011 = 139 */
#define IP6OPT_LIO                      0x8C    /* 10 0 01100 = 140 */
#define IP6OPT_EXP_9E                   0x9E    /* 10 0 11110 = 158 */
#define IP6OPT_EXP_BE                   0xBE    /* 10 1 11110 = 190 */
#define IP6OPT_JUMBO                    0xC2    /* 11 0 00010 = 194 */
#define IP6OPT_HOME_ADDRESS             0xC9    /* 11 0 01001 = 201 */
#define IP6OPT_EXP_DE                   0xDE    /* 11 0 11110 = 222 */
#define IP6OPT_IP_DFF                   0xEE    /* 11 1 01110 = 238 */
#define IP6OPT_EXP_FE                   0xFE    /* 11 1 11110 = 254 */

#define IP6OPT_RTALERT_MLD              0       /* Datagram contains MLD msg */
#define IP6OPT_RTALERT_RSVP             1       /* Datagram contains RSVP msg */
#define IP6OPT_RTALERT_ACTNET           2       /* Datagram contains ACTNET msg */

/* RPL Routing header */
#define IP6RRPL_BITMASK_CMPRI     0xF0000000
#define IP6RRPL_BITMASK_CMPRE     0x0F000000
#define IP6RRPL_BITMASK_PAD       0x00F00000
#define IP6RRPL_BITMASK_RESERVED  0x000FFFFF

/* IOAM Option-Types */
#define IP6IOAM_PRE_TRACE               0       /* Pre-allocated Trace */
#define IP6IOAM_INC_TRACE               1       /* Incremental Trace */
#define IP6IOAM_POT                     2       /* Proof of Transit */
#define IP6IOAM_E2E                     3       /* Edge to Edge */

/* IOAM Trace Types */
#define IP6IOAM_TRACE_MASK_BIT0         (1 << 23) /* Hop_lim + Node ID */
#define IP6IOAM_TRACE_MASK_BIT1         (1 << 22) /* Ingress and Egress IDs */
#define IP6IOAM_TRACE_MASK_BIT2         (1 << 21) /* Timestamp seconds */
#define IP6IOAM_TRACE_MASK_BIT3         (1 << 20) /* Timestamp fraction */
#define IP6IOAM_TRACE_MASK_BIT4         (1 << 19) /* Transit delay */
#define IP6IOAM_TRACE_MASK_BIT5         (1 << 18) /* IOAM-Namespace data */
#define IP6IOAM_TRACE_MASK_BIT6         (1 << 17) /* Queue depth */
#define IP6IOAM_TRACE_MASK_BIT7         (1 << 16) /* Checksum complement */
#define IP6IOAM_TRACE_MASK_BIT8         (1 << 15) /* (wide) Hop_lim + Node ID */
#define IP6IOAM_TRACE_MASK_BIT9         (1 << 14) /* (wide) Ingress and Egress IDs */
#define IP6IOAM_TRACE_MASK_BIT10        (1 << 13) /* (wide) IOAM-Namespace data */
#define IP6IOAM_TRACE_MASK_BIT11        (1 << 12) /* Buffer occupancy */
#define IP6IOAM_TRACE_MASK_BIT12        (1 << 11) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT13        (1 << 10) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT14        (1 <<  9) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT15        (1 <<  8) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT16        (1 <<  7) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT17        (1 <<  6) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT18        (1 <<  5) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT19        (1 <<  4) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT20        (1 <<  3) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT21        (1 <<  2) /* Undefined */
#define IP6IOAM_TRACE_MASK_BIT22        (1 <<  1) /* Opaque state snapshot */

/* Protocol specific data indices */
#define IPV6_PROTO_VALUE            1
#define IPV6_PROTO_PINFO            2

static int ipv6_tap  = -1;

static int exported_pdu_tap = -1;

static int proto_ipv6                           = -1;
static int proto_ipv6_hopopts                   = -1;
static int proto_ipv6_routing                   = -1;
static int proto_ipv6_fraghdr                   = -1;
static int proto_ipv6_dstopts                   = -1;

static int proto_ipv6_routing_rt0               = -1;
static int proto_ipv6_routing_mipv6             = -1;
static int proto_ipv6_routing_rpl               = -1;
static int proto_ipv6_routing_srh               = -1;
static int proto_ipv6_routing_crh               = -1;

static int hf_ipv6_version                      = -1;
static int hf_ip_version                        = -1;
static int hf_ipv6_tclass                       = -1;
static int hf_ipv6_tclass_dscp                  = -1;
static int hf_ipv6_tclass_ecn                   = -1;
static int hf_ipv6_flow                         = -1;
static int hf_ipv6_plen                         = -1;
static int hf_ipv6_nxt                          = -1;
static int hf_ipv6_hlim                         = -1;
static int hf_ipv6_src                          = -1;
static int hf_ipv6_src_addr_space               = -1;
static int hf_ipv6_src_multicast_flags          = -1;
static int hf_ipv6_src_multicast_flags_reserved = -1;
static int hf_ipv6_src_multicast_flags_transient = -1;
static int hf_ipv6_src_multicast_flags_network_prefix = -1;
static int hf_ipv6_src_multicast_flags_embed_rp = -1;
static int hf_ipv6_src_special_purpose          = -1;
static int hf_ipv6_src_multicast_scope          = -1;
static int hf_ipv6_src_host                     = -1;
static int hf_ipv6_src_slaac_mac                = -1;
static int hf_ipv6_src_isatap_ipv4              = -1;
static int hf_ipv6_src_6to4_gateway_ipv4        = -1;
static int hf_ipv6_src_6to4_sla_id              = -1;
static int hf_ipv6_src_teredo_server_ipv4       = -1;
static int hf_ipv6_src_teredo_port              = -1;
static int hf_ipv6_src_teredo_client_ipv4       = -1;
static int hf_ipv6_src_embed_ipv4               = -1;
static int hf_ipv6_dst                          = -1;
static int hf_ipv6_dst_addr_space               = -1;
static int hf_ipv6_dst_multicast_flags          = -1;
static int hf_ipv6_dst_multicast_flags_reserved = -1;
static int hf_ipv6_dst_multicast_flags_transient = -1;
static int hf_ipv6_dst_multicast_flags_network_prefix = -1;
static int hf_ipv6_dst_multicast_flags_embed_rp = -1;
static int hf_ipv6_dst_multicast_scope          = -1;
static int hf_ipv6_dst_special_purpose          = -1;
static int hf_ipv6_dst_host                     = -1;
static int hf_ipv6_dst_slaac_mac                = -1;
static int hf_ipv6_dst_isatap_ipv4              = -1;
static int hf_ipv6_dst_6to4_gateway_ipv4        = -1;
static int hf_ipv6_dst_6to4_sla_id              = -1;
static int hf_ipv6_dst_teredo_server_ipv4       = -1;
static int hf_ipv6_dst_teredo_port              = -1;
static int hf_ipv6_dst_teredo_client_ipv4       = -1;
static int hf_ipv6_dst_embed_ipv4               = -1;
static int hf_ipv6_addr                         = -1;
static int hf_ipv6_addr_space                   = -1;
static int hf_ipv6_multicast_flags              = -1;
static int hf_ipv6_multicast_flags_reserved     = -1;
static int hf_ipv6_multicast_flags_transient    = -1;
static int hf_ipv6_multicast_flags_network_prefix = -1;
static int hf_ipv6_multicast_flags_embed_rp     = -1;
static int hf_ipv6_multicast_scope              = -1;
static int hf_ipv6_addr_special_purpose         = -1;
static int hf_ipv6_host                         = -1;
static int hf_ipv6_slaac_mac                    = -1;
static int hf_ipv6_isatap_ipv4                  = -1;
static int hf_ipv6_6to4_gateway_ipv4            = -1;
static int hf_ipv6_6to4_sla_id                  = -1;
static int hf_ipv6_teredo_server_ipv4           = -1;
static int hf_ipv6_teredo_port                  = -1;
static int hf_ipv6_teredo_client_ipv4           = -1;
static int hf_ipv6_embed_ipv4_prefix            = -1;
static int hf_ipv6_embed_ipv4                   = -1;
static int hf_ipv6_embed_ipv4_u                 = -1;
static int hf_ipv6_embed_ipv4_suffix            = -1;
static int hf_ipv6_opt                          = -1;
static int hf_ipv6_opt_type                     = -1;
static int hf_ipv6_opt_type_action              = -1;
static int hf_ipv6_opt_type_change              = -1;
static int hf_ipv6_opt_type_rest                = -1;
static int hf_ipv6_opt_length                   = -1;
static int hf_ipv6_opt_pad1                     = -1;
static int hf_ipv6_opt_padn                     = -1;
static int hf_ipv6_opt_tel                      = -1;
static int hf_ipv6_opt_rtalert                  = -1;
static int hf_ipv6_opt_pmtu_min                 = -1;
static int hf_ipv6_opt_pmtu_rtn                 = -1;
static int hf_ipv6_opt_pmtu_rtn_flag            = -1;
static int hf_ipv6_opt_apn_id_type              = -1;
static int hf_ipv6_opt_apn_flags                = -1;
static int hf_ipv6_opt_apn_param_type           = -1;
static int hf_ipv6_opt_apn_id_part1             = -1;
static int hf_ipv6_opt_apn_id_part2             = -1;
static int hf_ipv6_opt_apn_id_part3             = -1;
static int hf_ipv6_opt_apn_id_part4             = -1;
static int hf_ipv6_opt_jumbo                    = -1;
static int hf_ipv6_opt_calipso_doi              = -1;
static int hf_ipv6_opt_calipso_cmpt_length      = -1;
static int hf_ipv6_opt_calipso_sens_level       = -1;
static int hf_ipv6_opt_calipso_checksum         = -1;
static int hf_ipv6_opt_calipso_cmpt_bitmap      = -1;
static int hf_ipv6_opt_smf_dpd_hash_bit         = -1;
static int hf_ipv6_opt_smf_dpd_tid_type         = -1;
static int hf_ipv6_opt_smf_dpd_tid_len          = -1;
static int hf_ipv6_opt_smf_dpd_tagger_id        = -1;
static int hf_ipv6_opt_smf_dpd_ident            = -1;
static int hf_ipv6_opt_smf_dpd_hav              = -1;
static int hf_ipv6_opt_pdm_scale_dtlr           = -1;
static int hf_ipv6_opt_pdm_scale_dtls           = -1;
static int hf_ipv6_opt_pdm_psn_this_pkt         = -1;
static int hf_ipv6_opt_pdm_psn_last_recv        = -1;
static int hf_ipv6_opt_pdm_delta_last_recv      = -1;
static int hf_ipv6_opt_pdm_delta_last_sent      = -1;
static int hf_ipv6_opt_qs_func                  = -1;
static int hf_ipv6_opt_qs_rate                  = -1;
static int hf_ipv6_opt_qs_ttl                   = -1;
static int hf_ipv6_opt_qs_ttl_diff              = -1;
static int hf_ipv6_opt_qs_unused                = -1;
static int hf_ipv6_opt_qs_nonce                 = -1;
static int hf_ipv6_opt_qs_reserved              = -1;
static int hf_ipv6_opt_ioam_rsv                 = -1;
static int hf_ipv6_opt_ioam_opt_type            = -1;
static int hf_ipv6_opt_ioam_trace_ns            = -1;
static int hf_ipv6_opt_ioam_trace_nodelen       = -1;
static int hf_ipv6_opt_ioam_trace_flags         = -1;
static int hf_ipv6_opt_ioam_trace_flag_o        = -1;
static int hf_ipv6_opt_ioam_trace_flag_l        = -1;
static int hf_ipv6_opt_ioam_trace_flag_a        = -1;
static int hf_ipv6_opt_ioam_trace_flag_rsv      = -1;
static int hf_ipv6_opt_ioam_trace_remlen        = -1;
static int hf_ipv6_opt_ioam_trace_type          = -1;
static int hf_ipv6_opt_ioam_trace_type_bit0     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit1     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit2     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit3     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit4     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit5     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit6     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit7     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit8     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit9     = -1;
static int hf_ipv6_opt_ioam_trace_type_bit10    = -1;
static int hf_ipv6_opt_ioam_trace_type_bit11    = -1;
static int hf_ipv6_opt_ioam_trace_type_undef    = -1;
static int hf_ipv6_opt_ioam_trace_type_bit22    = -1;
static int hf_ipv6_opt_ioam_trace_type_rsv      = -1;
static int hf_ipv6_opt_ioam_trace_rsv           = -1;
static int hf_ipv6_opt_ioam_trace_free_space    = -1;
static int hf_ipv6_opt_ioam_trace_node_hlim     = -1;
static int hf_ipv6_opt_ioam_trace_node_id       = -1;
static int hf_ipv6_opt_ioam_trace_node_iif      = -1;
static int hf_ipv6_opt_ioam_trace_node_eif      = -1;
static int hf_ipv6_opt_ioam_trace_node_tss      = -1;
static int hf_ipv6_opt_ioam_trace_node_tsf      = -1;
static int hf_ipv6_opt_ioam_trace_node_trdelay  = -1;
static int hf_ipv6_opt_ioam_trace_node_nsdata   = -1;
static int hf_ipv6_opt_ioam_trace_node_qdepth   = -1;
static int hf_ipv6_opt_ioam_trace_node_csum     = -1;
static int hf_ipv6_opt_ioam_trace_node_id_wide  = -1;
static int hf_ipv6_opt_ioam_trace_node_iif_wide = -1;
static int hf_ipv6_opt_ioam_trace_node_eif_wide = -1;
static int hf_ipv6_opt_ioam_trace_node_nsdata_wide = -1;
static int hf_ipv6_opt_ioam_trace_node_bufoccup = -1;
static int hf_ipv6_opt_ioam_trace_node_undefined = -1;
static int hf_ipv6_opt_ioam_trace_node_oss_len  = -1;
static int hf_ipv6_opt_ioam_trace_node_oss_scid = -1;
static int hf_ipv6_opt_ioam_trace_node_oss_data = -1;
static int hf_ipv6_opt_tpf_information          = -1;
static int hf_ipv6_opt_mipv6_home_address       = -1;
static int hf_ipv6_opt_rpl_flag                 = -1;
static int hf_ipv6_opt_rpl_flag_o               = -1;
static int hf_ipv6_opt_rpl_flag_r               = -1;
static int hf_ipv6_opt_rpl_flag_f               = -1;
static int hf_ipv6_opt_rpl_flag_rsv             = -1;
static int hf_ipv6_opt_rpl_instance_id          = -1;
static int hf_ipv6_opt_rpl_senderrank           = -1;
static int hf_ipv6_opt_ilnp_nonce               = -1;
static int hf_ipv6_opt_lio_len                  = -1;
static int hf_ipv6_opt_lio_id                   = -1;
static int hf_ipv6_opt_mpl_flag                 = -1;
static int hf_ipv6_opt_mpl_flag_s               = -1;
static int hf_ipv6_opt_mpl_flag_m               = -1;
static int hf_ipv6_opt_mpl_flag_v               = -1;
static int hf_ipv6_opt_mpl_flag_rsv             = -1;
static int hf_ipv6_opt_mpl_sequence             = -1;
static int hf_ipv6_opt_mpl_seed_id              = -1;
static int hf_ipv6_opt_dff_flags                = -1;
static int hf_ipv6_opt_dff_flag_ver             = -1;
static int hf_ipv6_opt_dff_flag_dup             = -1;
static int hf_ipv6_opt_dff_flag_ret             = -1;
static int hf_ipv6_opt_dff_flag_rsv             = -1;
static int hf_ipv6_opt_dff_seqnum               = -1;
static int hf_ipv6_opt_experimental             = -1;
static int hf_ipv6_opt_unknown_data             = -1;
static int hf_ipv6_opt_unknown                  = -1;
static int hf_ipv6_dstopts_nxt                  = -1;
static int hf_ipv6_dstopts_len                  = -1;
static int hf_ipv6_dstopts_len_oct              = -1;
static int hf_ipv6_hopopts_nxt                  = -1;
static int hf_ipv6_hopopts_len                  = -1;
static int hf_ipv6_hopopts_len_oct              = -1;
static int hf_ipv6_routing_nxt                  = -1;
static int hf_ipv6_routing_len                  = -1;
static int hf_ipv6_routing_len_oct              = -1;
static int hf_ipv6_routing_type                 = -1;
static int hf_ipv6_routing_segleft              = -1;
static int hf_ipv6_routing_unknown_data         = -1;
static int hf_ipv6_fraghdr_nxt                  = -1;
static int hf_ipv6_fraghdr_reserved_octet       = -1;
static int hf_ipv6_fraghdr_offset               = -1;
static int hf_ipv6_fraghdr_reserved_bits        = -1;
static int hf_ipv6_fraghdr_more                 = -1;
static int hf_ipv6_fraghdr_ident                = -1;
static int hf_ipv6_fragment                     = -1;
static int hf_ipv6_fragment_overlap             = -1;
static int hf_ipv6_fragment_overlap_conflict    = -1;
static int hf_ipv6_fragment_multiple_tails      = -1;
static int hf_ipv6_fragment_too_long_fragment   = -1;
static int hf_ipv6_fragment_error               = -1;
static int hf_ipv6_fragment_count               = -1;
static int hf_ipv6_fragments                    = -1;
static int hf_ipv6_reassembled_in               = -1;
static int hf_ipv6_reassembled_length           = -1;
static int hf_ipv6_reassembled_data             = -1;

static int hf_ipv6_routing_src_reserved         = -1;
static int hf_ipv6_routing_src_addr             = -1;

static int hf_ipv6_routing_mipv6_reserved       = -1;
static int hf_ipv6_routing_mipv6_home_address   = -1;

static int hf_ipv6_routing_rpl_cmprI            = -1;
static int hf_ipv6_routing_rpl_cmprE            = -1;
static int hf_ipv6_routing_rpl_pad              = -1;
static int hf_ipv6_routing_rpl_reserved         = -1;
static int hf_ipv6_routing_rpl_addr_count       = -1;
static int hf_ipv6_routing_rpl_addr             = -1;
static int hf_ipv6_routing_rpl_fulladdr         = -1;

static int hf_ipv6_routing_srh_last_entry       = -1;
static int hf_ipv6_routing_srh_flags            = -1;
static int hf_ipv6_routing_srh_tag              = -1;
static int hf_ipv6_routing_srh_addr             = -1;

static int hf_ipv6_routing_crh16_current_sid      = -1;
static int hf_ipv6_routing_crh32_current_sid      = -1;
static int hf_ipv6_routing_crh16_segment_id     = -1;
static int hf_ipv6_routing_crh32_segment_id     = -1;

struct ipv6_addr_info_s {
    int *hf_addr;
    int *hf_addr_space;
    int *hf_multicast_flags;
    int *const *hf_multicast_flags_bits;
    int *hf_multicast_scope;
    int *hf_special_purpose;
    int *hf_host;
};

static int *const ipv6_src_multicast_flags_bits[5] = {
    &hf_ipv6_src_multicast_flags_reserved,
    &hf_ipv6_src_multicast_flags_embed_rp,
    &hf_ipv6_src_multicast_flags_network_prefix,
    &hf_ipv6_src_multicast_flags_transient,
    NULL
};

static struct ipv6_addr_info_s ipv6_src_info = {
    &hf_ipv6_src,
    &hf_ipv6_src_addr_space,
    &hf_ipv6_src_multicast_flags,
    ipv6_src_multicast_flags_bits,
    &hf_ipv6_src_multicast_scope,
    &hf_ipv6_src_special_purpose,
    &hf_ipv6_src_host,
};

static int *const ipv6_dst_multicast_flags_bits[5] = {
    &hf_ipv6_dst_multicast_flags_reserved,
    &hf_ipv6_dst_multicast_flags_embed_rp,
    &hf_ipv6_dst_multicast_flags_network_prefix,
    &hf_ipv6_dst_multicast_flags_transient,
    NULL
};

static struct ipv6_addr_info_s ipv6_dst_info = {
    &hf_ipv6_dst,
    &hf_ipv6_dst_addr_space,
    &hf_ipv6_dst_multicast_flags,
    ipv6_dst_multicast_flags_bits,
    &hf_ipv6_dst_multicast_scope,
    &hf_ipv6_dst_special_purpose,
    &hf_ipv6_dst_host,
};

static int hf_geoip_country             = -1;
static int hf_geoip_country_iso         = -1;
static int hf_geoip_city                = -1;
static int hf_geoip_as_number           = -1;
static int hf_geoip_as_org              = -1;
static int hf_geoip_latitude            = -1;
static int hf_geoip_longitude           = -1;
static int hf_geoip_src_summary         = -1;
static int hf_geoip_src_country         = -1;
static int hf_geoip_src_country_iso     = -1;
static int hf_geoip_src_city            = -1;
static int hf_geoip_src_as_number       = -1;
static int hf_geoip_src_as_org          = -1;
static int hf_geoip_src_latitude        = -1;
static int hf_geoip_src_longitude       = -1;
static int hf_geoip_dst_summary         = -1;
static int hf_geoip_dst_country         = -1;
static int hf_geoip_dst_country_iso     = -1;
static int hf_geoip_dst_city            = -1;
static int hf_geoip_dst_as_number       = -1;
static int hf_geoip_dst_as_org          = -1;
static int hf_geoip_dst_latitude        = -1;
static int hf_geoip_dst_longitude       = -1;

static gint ett_ipv6_proto              = -1;
static gint ett_ipv6_detail             = -1;
static gint ett_ipv6_multicast_flags    = -1;
static gint ett_ipv6_traffic_class      = -1;
static gint ett_ipv6_opt                = -1;
static gint ett_ipv6_opt_type           = -1;
static gint ett_ipv6_opt_rpl            = -1;
static gint ett_ipv6_opt_mpl            = -1;
static gint ett_ipv6_opt_dff_flags      = -1;
static gint ett_ipv6_opt_ioam_trace_flags = -1;
static gint ett_ipv6_opt_ioam_trace_types = -1;
static gint ett_ipv6_hopopts_proto      = -1;
static gint ett_ipv6_fraghdr_proto      = -1;
static gint ett_ipv6_routing_proto      = -1;
static gint ett_ipv6_routing_srh_vect   = -1;
static gint ett_ipv6_fragments          = -1;
static gint ett_ipv6_fragment           = -1;
static gint ett_ipv6_dstopts_proto      = -1;

static gint ett_geoip_info              = -1;

static expert_field ei_ipv6_routing_invalid_length = EI_INIT;
static expert_field ei_ipv6_routing_invalid_segleft = EI_INIT;
static expert_field ei_ipv6_routing_undecoded = EI_INIT;
static expert_field ei_ipv6_dst_addr_not_unspecified = EI_INIT;
static expert_field ei_ipv6_src_addr_not_multicast = EI_INIT;
static expert_field ei_ipv6_dst_addr_not_multicast = EI_INIT;
static expert_field ei_ipv6_src_route_list_mult_inst_same_addr = EI_INIT;
static expert_field ei_ipv6_src_route_list_src_addr = EI_INIT;
static expert_field ei_ipv6_src_route_list_dst_addr = EI_INIT;
static expert_field ei_ipv6_src_route_list_multicast_addr = EI_INIT;
static expert_field ei_ipv6_routing_rpl_cmpri_cmpre_pad = EI_INIT;
static expert_field ei_ipv6_routing_rpl_addr_count_ge0 = EI_INIT;
static expert_field ei_ipv6_routing_rpl_reserved = EI_INIT;
static expert_field ei_ipv6_routing_deprecated = EI_INIT;
static expert_field ei_ipv6_opt_jumbo_missing = EI_INIT;
static expert_field ei_ipv6_opt_jumbo_prohibited = EI_INIT;
static expert_field ei_ipv6_opt_jumbo_truncated = EI_INIT;
static expert_field ei_ipv6_opt_jumbo_fragment = EI_INIT;
static expert_field ei_ipv6_opt_invalid_len = EI_INIT;
static expert_field ei_ipv6_opt_apn_invalid_id_type = EI_INIT;
static expert_field ei_ipv6_opt_unknown_data = EI_INIT;
static expert_field ei_ipv6_opt_deprecated = EI_INIT;
static expert_field ei_ipv6_opt_mpl_ipv6_src_seed_id = EI_INIT;
static expert_field ei_ipv6_hopopts_not_first = EI_INIT;
static expert_field ei_ipv6_plen_exceeds_framing = EI_INIT;
static expert_field ei_ipv6_plen_zero = EI_INIT;
static expert_field ei_ipv6_bogus_ipv6_version = EI_INIT;
static expert_field ei_ipv6_invalid_header = EI_INIT;
static expert_field ei_ipv6_opt_header_mismatch = EI_INIT;
static expert_field ei_ipv6_opt_ioam_invalid_nodelen = EI_INIT;
static expert_field ei_ipv6_opt_ioam_invalid_remlen = EI_INIT;
static expert_field ei_ipv6_opt_ioam_invalid_trace_type = EI_INIT;
static expert_field ei_ipv6_embed_ipv4_u_value = EI_INIT;

static dissector_handle_t ipv6_handle;

#define set_address_ipv6(dst, src_ip6) \
    set_address((dst), AT_IPv6, IPv6_ADDR_SIZE, (src_ip6))

#define set_address_ipv6_tvb(dst, tvb, offset) \
    set_address_tvb((dst), AT_IPv6, IPv6_ADDR_SIZE, (tvb), (offset))

#define alloc_address_wmem_ipv6(scope, dst, src_ip6) \
    alloc_address_wmem((scope), (dst), AT_IPv6, IPv6_ADDR_SIZE, (src_ip6))

#define alloc_address_tvb_ipv6(scope, dst, tvb, offset) \
    alloc_address_tvb((scope), (dst), AT_IPv6, IPv6_ADDR_SIZE, (tvb), (offset))

extern const ws_in6_addr *tvb_get_ptr_ipv6(tvbuff_t tvb, int offset);
#define tvb_get_ptr_ipv6(tvb, offset) \
    ((const ws_in6_addr *)tvb_get_ptr(tvb, offset, IPv6_ADDR_SIZE))

ipv6_pinfo_t *p_get_ipv6_pinfo(packet_info *pinfo)
{
    return (ipv6_pinfo_t *)p_get_proto_data(pinfo->pool, pinfo, proto_ipv6, IPV6_PROTO_PINFO);
}

/* Return tree pointer (for tree root preference) */
proto_tree *p_ipv6_pinfo_select_root(packet_info *pinfo, proto_tree *tree)
{
    ipv6_pinfo_t *p;

    if ((p = p_get_ipv6_pinfo(pinfo)) != NULL && p->ipv6_tree != NULL)
        return p->ipv6_tree;
    return tree;
}

ipv6_pinfo_t *p_ipv6_pinfo_add_len(packet_info *pinfo, int exthdr_len)
{
    ipv6_pinfo_t *p;

    if ((p = p_get_ipv6_pinfo(pinfo)) == NULL)
        return NULL;

    p->frag_plen -= exthdr_len;
    p->ipv6_item_len += exthdr_len;
    return p;
}

static void p_add_ipv6_nxt(packet_info *pinfo, guint8 nxt)
{
    guint8 *ptr;

    ptr = (guint8 *)wmem_memdup(pinfo->pool, &nxt, sizeof(guint8));
    p_add_proto_data(pinfo->pool, pinfo, proto_ipv6,
                        (pinfo->curr_layer_num<<8) | IPV6_PROTO_VALUE, ptr);
}

static guint8 *p_get_ipv6_nxt(packet_info *pinfo)
{
    return (guint8 *)p_get_proto_data(pinfo->pool, pinfo, proto_ipv6,
                        (pinfo->curr_layer_num<<8) | IPV6_PROTO_VALUE);
}

static gpointer ipv6_value(packet_info *pinfo)
{
    guint8 *nxt = p_get_ipv6_nxt(pinfo);

    if (nxt == NULL) {
        return GUINT_TO_POINTER(255); /* Reserved IP Protocol */
    }
    return GUINT_TO_POINTER((guint)*nxt);
}

static void ipv6_prompt(packet_info *pinfo, gchar *result)
{
    gpointer value = ipv6_value(pinfo);

    snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "IP protocol %u as", GPOINTER_TO_UINT(value));
}

static const char* ipv6_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter)
{
    if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == AT_IPv6))
        return "ipv6.src";

    if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == AT_IPv6))
        return "ipv6.dst";

    if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == AT_IPv6))
        return "ipv6.addr";

    return CONV_FILTER_INVALID;
}

static ct_dissector_info_t ipv6_ct_dissector_info = {&ipv6_conv_get_filter_type};

static tap_packet_status
ipv6_conversation_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip, tap_flags_t flags)
{
    conv_hash_t *hash = (conv_hash_t*) pct;
    hash->flags = flags;

    const ipv6_tap_info_t *ip6 = (const ipv6_tap_info_t *)vip;

    add_conversation_table_data(hash, &ip6->ip6_src, &ip6->ip6_dst, 0, 0, 1,
            pinfo->fd->pkt_len, &pinfo->rel_ts, &pinfo->abs_ts,
            &ipv6_ct_dissector_info, CONVERSATION_NONE);

    return TAP_PACKET_REDRAW;
}

static const char* ipv6_endpoint_get_filter_type(endpoint_item_t* endpoint, conv_filter_type_e filter)
{
    if ((filter == CONV_FT_ANY_ADDRESS) && (endpoint->myaddress.type == AT_IPv6))
        return "ipv6.addr";

    return CONV_FILTER_INVALID;
}

static et_dissector_info_t ipv6_endpoint_dissector_info = {&ipv6_endpoint_get_filter_type};

static tap_packet_status
ipv6_endpoint_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip, tap_flags_t flags)
{
    conv_hash_t *hash = (conv_hash_t*) pit;
    hash->flags = flags;

    const ipv6_tap_info_t *ip6 = (const ipv6_tap_info_t *)vip;

    add_endpoint_table_data(hash, &ip6->ip6_src, 0, TRUE, 1,
                pinfo->fd->pkt_len, &ipv6_endpoint_dissector_info, ENDPOINT_NONE);
    add_endpoint_table_data(hash, &ip6->ip6_dst, 0, FALSE, 1,
                pinfo->fd->pkt_len, &ipv6_endpoint_dissector_info, ENDPOINT_NONE);

    return TAP_PACKET_REDRAW;
}

static gboolean
ipv6_filter_valid(packet_info *pinfo, void *user_data _U_)
{
    return proto_is_frame_protocol(pinfo->layers, "ipv6");
}

static gchar*
ipv6_build_filter(packet_info *pinfo, void *user_data _U_)
{
    return ws_strdup_printf("ipv6.addr eq %s and ipv6.addr eq %s",
                address_to_str(pinfo->pool, &pinfo->net_src),
                address_to_str(pinfo->pool, &pinfo->net_dst));
}


/* UAT for providing a list of NAT64 prefixes */

struct nat64_prefix_data {
    char *ipaddr;
    uint8_t prefix_len;
    uint32_t prefix_wildcard_len;
};


static uat_t *nat64_prefix_uat = NULL;
static struct nat64_prefix_data *nat64_prefix_uats = NULL;
static guint number_of_nat64_prefix = 0;


UAT_CSTRING_CB_DEF(nat64_prefix_uats, ipaddr, struct nat64_prefix_data)

static bool
nat64_prefix_uat_fld_ip_chk_cb(void *r _U_, const char *ipaddr, guint len _U_, const void *u1 _U_, const void *u2 _U_, char **err)
{
    /* Check for a valid IPv6 address */
    ws_in6_addr addr;

    if (ws_inet_pton6(ipaddr, &addr)) {
        *err = NULL;
        return TRUE;
    }

    *err = ws_strdup_printf("No valid IPv6 address given.");
    return FALSE;
}

static const value_string nat64_prefix_length_vals[] =
{
    { 32, "32" },
    { 40, "40" },
    { 48, "48" },
    { 56, "56" },
    { 64, "64" },
    { 96, "96" },
    {  0, NULL }
};

UAT_VS_DEF(nat64_prefix_uats, prefix_len, struct nat64_prefix_data, uint8_t, 96, "96")

static const value_string nat64_prefix_wildcard_length_vals[] =
{
    {  0, "0" },
    {  8, "8" },
    { 16, "16" },
    { 32, "32" },
    { 64, "64" },
    {  0, NULL }
};

UAT_VS_DEF(nat64_prefix_uats, prefix_wildcard_len, struct nat64_prefix_data, uint8_t, 0, "0")


static void
nat64_prefix_free_cb(void *data)
{
    struct nat64_prefix_data *h = (struct nat64_prefix_data *)data;

    g_free(h->ipaddr);
}

static void *
nat64_prefix_copy_cb(void *dst_, const void *src_, size_t len _U_)
{
    const struct nat64_prefix_data *src = (const struct nat64_prefix_data *)src_;
    struct nat64_prefix_data *dst = (struct nat64_prefix_data *)dst_;

    dst->ipaddr = g_strdup(src->ipaddr);
    dst->prefix_len = src->prefix_len;
    dst->prefix_wildcard_len = src->prefix_wildcard_len;

    return dst;
}


static gint
ipv6_previous_layer_id(packet_info *pinfo)
{
    wmem_list_frame_t *layer;

    layer = wmem_list_tail(pinfo->layers);
    DISSECTOR_ASSERT(layer);
    layer = wmem_list_frame_prev(layer);
    if (layer != NULL) {
        return GPOINTER_TO_INT(wmem_list_frame_data(layer));
    }
    return -1;
}

static const fragment_items ipv6_frag_items = {
    &ett_ipv6_fragment,
    &ett_ipv6_fragments,
    &hf_ipv6_fragments,
    &hf_ipv6_fragment,
    &hf_ipv6_fragment_overlap,
    &hf_ipv6_fragment_overlap_conflict,
    &hf_ipv6_fragment_multiple_tails,
    &hf_ipv6_fragment_too_long_fragment,
    &hf_ipv6_fragment_error,
    &hf_ipv6_fragment_count,
    &hf_ipv6_reassembled_in,
    &hf_ipv6_reassembled_length,
    &hf_ipv6_reassembled_data,
    "IPv6 fragments"
};

static dissector_table_t ip_dissector_table;
static dissector_table_t ipv6_routing_dissector_table;

/* Reassemble fragmented datagrams */
static gboolean ipv6_reassemble = TRUE;

/* Place IPv6 summary in proto tree */
static gboolean ipv6_summary_in_tree = TRUE;

/* Show expanded information about IPv6 address */
static gboolean ipv6_address_detail = FALSE;

/* Perform strict RFC adherence checking */
static gboolean g_ipv6_rpl_srh_strict_rfc_checking = FALSE;

/* Use heuristics to determine subdissector */
static gboolean try_heuristic_first = FALSE;

/* Display IPv6 extension headers under the root tree */
static gboolean ipv6_exthdr_under_root = FALSE;

/* Hide extension header generated field for length */
static gboolean ipv6_exthdr_hide_len_oct_field = FALSE;

/* Assume TSO and correct zero-length IP packets */
static gboolean ipv6_tso_supported = FALSE;

/*
 * defragmentation of IPv6
 */
static reassembly_table ipv6_reassembly_table;

/* http://www.iana.org/assignments/ipv6-parameters (last updated 2015-07-07) */
static const value_string ipv6_opt_type_vals[] = {
    { IP6OPT_PAD1,          "Pad1"                          },
    { IP6OPT_PADN,          "PadN"                          },
    { IP6OPT_TEL,           "Tunnel Encapsulation Limit"    },
    { IP6OPT_RTALERT,       "Router Alert"                  },
    { IP6OPT_CALIPSO,       "CALIPSO"                       },
    { IP6OPT_SMF_DPD,       "SMF_DPD"                       },
    { IP6OPT_PDM,           "Performance and Diagnostic Metrics" },
    { IP6OPT_APN6,          "Application-Aware IPv6 Networking (APN6)" },
    { IP6OPT_EXP_1E,        "Experimental (0x1E)"           },
    { IP6OPT_RPL,           "RPL Option"                    },
    { IP6OPT_QUICKSTART,    "Quick-Start"                   },
    { IP6OPT_PMTU,          "Path MTU Option"               },
    { IP6OPT_IOAM,          "IOAM Option"                   },
    { IP6OPT_EXP_3E,        "Experimental (0x3E)"           },
    { IP6OPT_TPF,           "Tunnel Payload Forwarding (TPF) Information" },
    { IP6OPT_EXP_5E,        "Experimental (0x5E)"           },
    { IP6OPT_RPL_OLD,       "RPL Option (deprecated)"       },
    { IP6OPT_MPL,           "MPL Option"                    },
    { IP6OPT_EXP_7E,        "Experimental (0x7E)"           },
    { IP6OPT_ENDI,          "Endpoint Identification"       },
    { IP6OPT_ILNP_NONCE,    "ILNP Nonce"                    },
    { IP6OPT_LIO,           "Line-Identification Option"    },
    { IP6OPT_EXP_9E,        "Experimental (0x9E)"           },
    { IP6OPT_EXP_BE,        "Experimental (0xBE)"           },
    { IP6OPT_JUMBO,         "Jumbo Payload"                 },
    { IP6OPT_HOME_ADDRESS,  "Home Address"                  },
    { IP6OPT_EXP_DE,        "Experimental (0xDE)"           },
    { IP6OPT_IP_DFF,        "IP_DFF"                        },
    { IP6OPT_EXP_FE,        "Experimental (0xFE)"           },
    { 0, NULL }
};
static value_string_ext ipv6_opt_type_vals_ext = VALUE_STRING_EXT_INIT(ipv6_opt_type_vals);

static const value_string ipv6_opt_rtalert_vals[] = {
    { IP6OPT_RTALERT_MLD,       "MLD"            },
    { IP6OPT_RTALERT_RSVP,      "RSVP"           },
    { IP6OPT_RTALERT_ACTNET,    "Active Network" },
    { 0, NULL }
};

enum {
    IP6OPT_SMF_DPD_NULL = 0,
    IP6OPT_SMF_DPD_DFLT,
    IP6OPT_SMF_DPD_IPv4,
    IP6OPT_SMF_DPD_IPv6
};

static const value_string ipv6_opt_smf_dpd_tidty_vals[] = {
    { IP6OPT_SMF_DPD_NULL, "NULL"       },
    { IP6OPT_SMF_DPD_DFLT, "DEFAULT"    },
    { IP6OPT_SMF_DPD_IPv4, "IPv4"       },
    { IP6OPT_SMF_DPD_IPv6, "IPv6"       },
    { 0, NULL }
};

enum {
    IPv6_OPT_ACTION_SKIP = 0,
    IPv6_OPT_ACTION_DISC,
    IPv6_OPT_ACTION_ICMP,
    IPv6_OPT_ACTION_MCST,
};

static const value_string ipv6_opt_type_action_vals[] = {
    { IPv6_OPT_ACTION_SKIP, "Skip and continue" },
    { IPv6_OPT_ACTION_DISC, "Discard" },
    { IPv6_OPT_ACTION_ICMP, "Discard and send ICMP Parameter Problem" },
    { IPv6_OPT_ACTION_MCST, "Discard and send ICMP if not multicast" },
    { 0, NULL }
};

enum {
    IPv6_OPT_HDR_HBH = 0,
    IPv6_OPT_HDR_DST,
    IPv6_OPT_HDR_ANY
};

static const gint _ipv6_opt_type_hdr[][2] = {
    { IP6OPT_TEL,           IPv6_OPT_HDR_DST },
    { IP6OPT_RTALERT,       IPv6_OPT_HDR_HBH },
    { IP6OPT_PMTU,          IPv6_OPT_HDR_HBH },
    { IP6OPT_APN6,          IPv6_OPT_HDR_ANY },
    { IP6OPT_CALIPSO,       IPv6_OPT_HDR_HBH },
    { IP6OPT_SMF_DPD,       IPv6_OPT_HDR_HBH },
    { IP6OPT_PDM,           IPv6_OPT_HDR_DST },
    { IP6OPT_RPL,           IPv6_OPT_HDR_HBH },
    { IP6OPT_QUICKSTART,    IPv6_OPT_HDR_HBH },
    { IP6OPT_IOAM,          IPv6_OPT_HDR_HBH },
    { IP6OPT_TPF,           IPv6_OPT_HDR_DST },
    { IP6OPT_RPL_OLD,       IPv6_OPT_HDR_HBH },
    { IP6OPT_MPL,           IPv6_OPT_HDR_HBH },
    { IP6OPT_ILNP_NONCE,    IPv6_OPT_HDR_DST },
    { IP6OPT_LIO,           IPv6_OPT_HDR_DST },
    { IP6OPT_JUMBO,         IPv6_OPT_HDR_HBH },
    { IP6OPT_HOME_ADDRESS,  IPv6_OPT_HDR_DST },
    { IP6OPT_IP_DFF,        IPv6_OPT_HDR_HBH },
    { 0, IPv6_OPT_HDR_ANY }
};

static inline gint
ipv6_opt_type_hdr(gint type)
{
    const gint (*p)[2] = _ipv6_opt_type_hdr;

    for (; (*p)[1] != IPv6_OPT_HDR_ANY; p++) {
        if ((*p)[0] == type) {
            return (*p)[1];
        }
    }
    return IPv6_OPT_HDR_ANY;
}

enum {
    IPv6_RT_HEADER_SOURCE_ROUTING  = 0,     /* DEPRECATED */
    IPv6_RT_HEADER_NIMROD          = 1,     /* DEPRECATED */
    IPv6_RT_HEADER_MOBILE_IP       = 2,
    IPv6_RT_HEADER_RPL             = 3,
    IPv6_RT_HEADER_SEGMENT_ROUTING = 4,
    IPv6_RT_HEADER_COMPACT_16      = 5,
    IPv6_RT_HEADER_COMPACT_32      = 6,
    IPv6_RT_HEADER_EXP1            = 253,
    IPv6_RT_HEADER_EXP2            = 254
};

/* Routing Header Types */
static const value_string routing_header_type[] = {
    { IPv6_RT_HEADER_SOURCE_ROUTING,    "Source Route"     },
    { IPv6_RT_HEADER_NIMROD,            "Nimrod"           },
    { IPv6_RT_HEADER_MOBILE_IP,         "Type 2 Routing"   },
    { IPv6_RT_HEADER_RPL,               "RPL Source Route" },
    { IPv6_RT_HEADER_SEGMENT_ROUTING,   "Segment Routing"  },
    { IPv6_RT_HEADER_COMPACT_16,        "Compact Routing Header 16"  },
    { IPv6_RT_HEADER_COMPACT_32,        "Compact Routing Header 32"  },
    { IPv6_RT_HEADER_EXP1,              "Experiment 1"     },
    { IPv6_RT_HEADER_EXP2,              "Experiment 2"     },
    { 0, NULL }
};

static const value_string mpl_seed_id_len_vals[] = {
    { 0, "0" },
    { 1, "16-bit unsigned integer" },
    { 2, "64-bit unsigned integer" },
    { 3, "128-bit unsigned integer" },
    { 0, NULL }
};

static const value_string ipv6_multicast_scope_vals[] = {
    { 0x0, "Reserved" },
    { 0x1, "Interface-Local scope" },
    { 0x2, "Link-Local scope" },
    { 0x3, "Realm-Local scope" },
    { 0x4, "Admin-Local scope" },
    { 0x5, "Site-Local scope" },
    { 0x6, "Unassigned" },
    { 0x7, "Unassigned" },
    { 0x8, "Organization-Local scope" },
    { 0x9, "Unassigned" },
    { 0xA, "Unassigned" },
    { 0xB, "Unassigned" },
    { 0xC, "Unassigned" },
    { 0xD, "Unassigned" },
    { 0xE, "Global scope" },
    { 0xF, "Reserved" },
    { 0, NULL }
};

#define APN_ID_32BIT 1
#define APN_ID_64BIT 2
#define APN_ID_128BIT 3
static const value_string apn_id_type_strs[] = {
        { 0,             "Invalid" },
        { APN_ID_32BIT,  "32-bit"  },
        { APN_ID_64BIT,  "64-bit"  },
        { APN_ID_128BIT, "128-bit" },
        { 0, NULL }
};

static gboolean
capture_ipv6(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
{
    guint8 nxt;

    if (!BYTES_ARE_IN_FRAME(offset, len, IPv6_HDR_SIZE))
        return FALSE;

    capture_dissector_increment_count(cpinfo, proto_ipv6);

    nxt = pd[offset+6];           /* get the "next header" value */
    offset += IPv6_HDR_SIZE;      /* skip past the IPv6 header */

    return try_capture_dissector("ip.proto", nxt, pd, offset, len, cpinfo, pseudo_header);
}

static gboolean
capture_ipv6_exthdr(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
{
    guint8 nxt;
    int    advance;

    if (!BYTES_ARE_IN_FRAME(offset, len, 2))
        return FALSE;
    nxt = pd[offset];
    switch (nxt) {
        case IP_PROTO_FRAGMENT:
            advance = IPv6_FRAGMENT_HDR_SIZE;
            break;
        default:
            advance = (pd[offset+1] + 1) << 3;
            break;
    }
    if (!BYTES_ARE_IN_FRAME(offset, len, advance))
        return FALSE;
    offset += advance;

    return try_capture_dissector("ip.proto", nxt, pd, offset, len, cpinfo, pseudo_header);
}

static void
add_geoip_info_entry(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, const ws_in6_addr *ip6, gboolean isdst)
{
    const mmdb_lookup_t *lookup = maxmind_db_lookup_ipv6(ip6);
    if (!lookup->found) return;

    wmem_strbuf_t *summary = wmem_strbuf_new(pinfo->pool, "");
    if (lookup->city) {
        wmem_strbuf_append(summary, lookup->city);
    }
    if (lookup->country_iso) {
        if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
        wmem_strbuf_append(summary, lookup->country_iso);
    } else if (lookup->country) {
        if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
        wmem_strbuf_append(summary, lookup->country);
    }
    if (lookup->as_number > 0) {
        if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
        wmem_strbuf_append_printf(summary, "ASN %u", lookup->as_number);
    }
    if (lookup->as_org) {
        if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
        wmem_strbuf_append(summary, lookup->as_org);
    }

    int addr_offset = offset + (isdst ? IP6H_DST : IP6H_SRC);
    int dir_hf = isdst ? hf_geoip_dst_summary : hf_geoip_src_summary;
    proto_item *geoip_info_item = proto_tree_add_string(tree, dir_hf, tvb, addr_offset, 16, wmem_strbuf_finalize(summary));
    proto_item_set_generated(geoip_info_item);
    proto_tree *geoip_info_tree = proto_item_add_subtree(geoip_info_item, ett_geoip_info);

    proto_item *item;

    if (lookup->city) {
        dir_hf = isdst ? hf_geoip_dst_city : hf_geoip_src_city;
        item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->city);
        proto_item_set_generated(item);
        item = proto_tree_add_string(geoip_info_tree, hf_geoip_city, tvb, addr_offset, 16, lookup->city);
        proto_item_set_generated(item);
    }

    if (lookup->country) {
        dir_hf = isdst ? hf_geoip_dst_country : hf_geoip_src_country;
        item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->country);
        proto_item_set_generated(item);
        item = proto_tree_add_string(geoip_info_tree, hf_geoip_country, tvb, addr_offset, 16, lookup->country);
        proto_item_set_generated(item);
    }

    if (lookup->country_iso) {
        dir_hf = isdst ? hf_geoip_dst_country_iso : hf_geoip_src_country_iso;
        item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->country_iso);
        proto_item_set_generated(item);
        item = proto_tree_add_string(geoip_info_tree, hf_geoip_country_iso, tvb, addr_offset, 16, lookup->country_iso);
        proto_item_set_generated(item);
    }

    if (lookup->as_number > 0) {
        dir_hf = isdst ? hf_geoip_dst_as_number : hf_geoip_src_as_number;
        item = proto_tree_add_uint(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->as_number);
        proto_item_set_generated(item);
        item = proto_tree_add_uint(geoip_info_tree, hf_geoip_as_number, tvb, addr_offset, 16, lookup->as_number);
        proto_item_set_generated(item);
    }

    if (lookup->as_org) {
        dir_hf = isdst ? hf_geoip_dst_as_org : hf_geoip_src_as_org;
        item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->as_org);
        proto_item_set_generated(item);
        item = proto_tree_add_string(geoip_info_tree, hf_geoip_as_org, tvb, addr_offset, 16, lookup->as_org);
        proto_item_set_generated(item);
    }

    if (lookup->latitude >= -90.0 && lookup->latitude <= 90.0) {
        dir_hf = isdst ? hf_geoip_dst_latitude : hf_geoip_src_latitude;
        item = proto_tree_add_double(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->latitude);
        proto_item_set_generated(item);
        item = proto_tree_add_double(geoip_info_tree, hf_geoip_latitude, tvb, addr_offset, 16, lookup->latitude);
        proto_item_set_generated(item);
    }

    if (lookup->longitude >= -180.0 && lookup->longitude <= 180.0) {
        dir_hf = isdst ? hf_geoip_dst_longitude : hf_geoip_src_longitude;
        item = proto_tree_add_double(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->longitude);
        proto_item_set_generated(item);
        item = proto_tree_add_double(geoip_info_tree, hf_geoip_longitude, tvb, addr_offset, 16, lookup->longitude);
        proto_item_set_generated(item);
    }
}

static void
add_geoip_info(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, const ws_in6_addr *src, const ws_in6_addr *dst)
{
    add_geoip_info_entry(tree, pinfo, tvb, offset, src, FALSE);
    add_geoip_info_entry(tree, pinfo, tvb, offset, dst, TRUE);
}

/* Returns TRUE if reassembled */
static gboolean
ipv6_reassemble_do(tvbuff_t **tvb_ptr, gint *offset_ptr, packet_info *pinfo, proto_tree *ipv6_tree,
                    guint32 plen, guint16 frag_off, gboolean frag_flg, guint32 frag_ident,
                    gboolean *show_data_ptr)
{
    fragment_head   *ipfd_head;
    tvbuff_t        *next_tvb;
    gboolean         update_col_info = TRUE;

    pinfo->fragmented = TRUE;
    *show_data_ptr = TRUE;
    if (!ipv6_reassemble) {
        /* not reassembling */
        if (frag_off == 0) {
             /* first fragment */
            *show_data_ptr = FALSE;
        }
        return FALSE;
    }

    /* reassembling */
    if (tvb_bytes_exist(*tvb_ptr, *offset_ptr, plen)) {
        ipfd_head = fragment_add_check(&ipv6_reassembly_table,
                                       *tvb_ptr, *offset_ptr, pinfo, frag_ident, NULL,
                                       frag_off, plen, frag_flg);
        next_tvb = process_reassembled_data(*tvb_ptr, *offset_ptr, pinfo, "Reassembled IPv6",
                                            ipfd_head, &ipv6_frag_items, &update_col_info, ipv6_tree);
        if (next_tvb) {
            /* Process post-fragment headers after reassembly */
            *offset_ptr = 0;
            *tvb_ptr = next_tvb;
            pinfo->fragmented = FALSE;
            *show_data_ptr = FALSE;
            return TRUE;
        }
    }
    return FALSE;
}

static proto_item *
_proto_tree_add_ipv6_vector_address(proto_tree *tree, packet_info *pinfo, int hfindex, tvbuff_t *tvb, gint start,
                            gint length, const ws_in6_addr *value_ptr, int idx)
{
    address addr;
    gchar *str;

    set_address_ipv6(&addr, value_ptr);
    str = address_with_resolution_to_str(pinfo->pool, &addr);
    return proto_tree_add_ipv6_format(tree, hfindex, tvb, start, length,
                        value_ptr, "Address[%d]: %s", idx, str);
}

/* IPv6 Source Routing Header (Type 0) */
static int
dissect_routing6_rt0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    struct ws_rthdr *rt = (struct ws_rthdr *)data;
    proto_item *ti;
    int offset = 0;
    gint idx;
    gint rt0_addr_count;
    const ws_in6_addr *addr = NULL;

    proto_tree_add_item(tree, hf_ipv6_routing_src_reserved, tvb, offset, 4, ENC_NA);
    offset += 4;

    if (rt->hdr.ip6r_len % 2 != 0) {
        expert_add_info_format(pinfo, rt->ti_len, &ei_ipv6_routing_invalid_length,
                "IPv6 Routing Header extension header length must not be odd");
    }
    rt0_addr_count = rt->hdr.ip6r_len / 2;
    if (rt->hdr.ip6r_segleft > rt0_addr_count) {
        expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
                "IPv6 Type 0 Routing Header segments left field must not exceed address count (%u)", rt0_addr_count);
    }

    for (idx = 1; idx <= rt0_addr_count; idx++) {
        addr = tvb_get_ptr_ipv6(tvb, offset);
        ti = _proto_tree_add_ipv6_vector_address(tree, pinfo, hf_ipv6_routing_src_addr, tvb,
                            offset, IPv6_ADDR_SIZE, addr, idx);
        offset += IPv6_ADDR_SIZE;
        if (in6_addr_is_multicast(addr)) {
            expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
        }
    }

    if (addr != NULL && pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
        alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, addr);
    }

    expert_add_info(pinfo, rt->ti_type, &ei_ipv6_routing_deprecated);
    return tvb_captured_length(tvb);
}

/* Mobile IPv6 Routing Header (Type 2) */
static int
dissect_routing6_mipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    struct ws_rthdr *rt = (struct ws_rthdr *)data;
    proto_item *ti;
    int offset = 0;
    const ws_in6_addr *addr;

    proto_tree_add_item(tree, hf_ipv6_routing_mipv6_reserved, tvb, offset, 4, ENC_NA);
    offset += 4;

    if (rt->hdr.ip6r_len != 2) {
        expert_add_info_format(pinfo, rt->ti_len, &ei_ipv6_routing_invalid_length,
                "IPv6 Type 2 Routing Header extension header length must equal 2");
    }
    if (rt->hdr.ip6r_segleft != 1) {
        expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
                "IPv6 Type 2 Routing Header segments left field must equal 1");
    }

    addr = tvb_get_ptr_ipv6(tvb, offset);
    ti = _proto_tree_add_ipv6_vector_address(tree, pinfo, hf_ipv6_routing_mipv6_home_address, tvb,
                        offset, IPv6_ADDR_SIZE, addr, 1);
    if (in6_addr_is_multicast(addr)) {
        expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
    }

    if (pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
        alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, addr);
    }

    return tvb_captured_length(tvb);
}

/* RPL Source Routing Header (Type 3) */
static int
dissect_routing6_rpl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    struct ws_rthdr *rt = (struct ws_rthdr *)data;
    proto_item *ti;
    int offset = 0;
    guint8 cmprI, cmprE, cmprX, pad;
    guint32 reserved;
    gint idx;
    gint rpl_addr_count;
    ws_in6_addr rpl_fulladdr;
    const ws_in6_addr *ip6_dst_addr, *ip6_src_addr;
    wmem_array_t *rpl_addr_vector = NULL;
    guint i;

    /* Must be IPv6 addresses */
    if ((pinfo->dst.type != AT_IPv6) || (pinfo->src.type != AT_IPv6))
        return 0;

    /* IPv6 destination address used for elided bytes */
    ip6_dst_addr = (const ws_in6_addr *)pinfo->dst.data;
    /* IPv6 source address used for strict checking */
    ip6_src_addr = (const ws_in6_addr *)pinfo->src.data;

    /* from RFC6554: Multicast addresses MUST NOT appear in the IPv6 Destination Address field */
    if (in6_addr_is_multicast(ip6_dst_addr)) {
        expert_add_info(pinfo, proto_tree_get_parent(tree), &ei_ipv6_dst_addr_not_multicast);
    }

    proto_tree_add_item(tree, hf_ipv6_routing_rpl_cmprI, tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_ipv6_routing_rpl_cmprE, tvb, offset, 4, ENC_BIG_ENDIAN);
    ti = proto_tree_add_item(tree, hf_ipv6_routing_rpl_pad, tvb, offset, 4, ENC_BIG_ENDIAN);

    cmprI = tvb_get_guint8(tvb, offset) & 0xF0;
    cmprE = tvb_get_guint8(tvb, offset) & 0x0F;
    pad   = tvb_get_guint8(tvb, offset + 1) & 0xF0;

    /* Shift bytes over */
    cmprI >>= 4;
    pad >>= 4;

    /* from RFC6554: when CmprI and CmprE are both 0, Pad MUST carry a value of 0 */
    if (cmprI == 0 && cmprE == 0 && pad != 0) {
        expert_add_info_format(pinfo, ti, &ei_ipv6_routing_rpl_cmpri_cmpre_pad, "When cmprI equals 0 and cmprE equals 0, pad MUST equal 0 but instead was %d", pad);
    }

    ti = proto_tree_add_item(tree, hf_ipv6_routing_rpl_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
    reserved = tvb_get_bits32(tvb, ((offset + 1) * 8) + 4, 20, ENC_BIG_ENDIAN);

    if (reserved != 0) {
        expert_add_info_format(pinfo, ti, &ei_ipv6_routing_rpl_reserved, "Reserved field must equal 0 but instead was %d", reserved);
    }

    /* From RFC6554:
     *   n = (((Hdr Ext Len * 8) - Pad - (16 - CmprE)) / (16 - CmprI)) + 1
     */
    rpl_addr_count = 0;
    if (rt->hdr.ip6r_len > 0) {
        rpl_addr_count = (((rt->hdr.ip6r_len * 8) - pad - (16 - cmprE)) / (16 - cmprI)) + 1;
    }
    ti = proto_tree_add_int(tree, hf_ipv6_routing_rpl_addr_count, tvb, offset, 2, rpl_addr_count);
    proto_item_set_generated(ti);
    if (rpl_addr_count < 0) {
        /* This error should always be reported */
        expert_add_info_format(pinfo, ti, &ei_ipv6_routing_rpl_addr_count_ge0, "Calculated total address count must be greater than or equal to 0, instead was %d", rpl_addr_count);
    }
    else if (rt->hdr.ip6r_segleft > (guint)rpl_addr_count) {
        expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
            "IPv6 RPL Routing Header segments left field must not exceed address count (%d)", rpl_addr_count);
    }

    if (rpl_addr_count > 0) {
        offset += 4;

        if (g_ipv6_rpl_srh_strict_rfc_checking)
            rpl_addr_vector = wmem_array_sized_new(pinfo->pool, IPv6_ADDR_SIZE, rpl_addr_count);

        /* We use cmprI for internal (e.g.: not last) address for how many bytes to elide, so actual bytes present = 16-CmprI */
        for (idx = 1; idx <= rpl_addr_count; idx++) {
            if (idx == rpl_addr_count)
                cmprX = 16 - cmprE;
            else
                cmprX = 16 - cmprI;
            proto_tree_add_item(tree, hf_ipv6_routing_rpl_addr, tvb, offset, cmprX, ENC_NA);
            /* Display Full Address */
            memcpy(&rpl_fulladdr, ip6_dst_addr, IPv6_ADDR_SIZE);
            tvb_memcpy(tvb, &rpl_fulladdr.bytes[16-cmprX], offset, cmprX);
            ti = _proto_tree_add_ipv6_vector_address(tree, pinfo, hf_ipv6_routing_rpl_fulladdr, tvb,
                                offset, cmprX, &rpl_fulladdr, idx);
            proto_item_set_generated(ti);
            offset += cmprX;

            /* IPv6 Source and Destination addresses of the encapsulating datagram (MUST) not appear in the SRH*/
            if (memcmp(&rpl_fulladdr, ip6_src_addr, IPv6_ADDR_SIZE) == 0) {
                expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_src_addr);
            }
            if (memcmp(&rpl_fulladdr, ip6_dst_addr, IPv6_ADDR_SIZE) == 0) {
                expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_dst_addr);
            }

            /* Multicast addresses MUST NOT appear in the in SRH */
            if (in6_addr_is_multicast(&rpl_fulladdr)) {
                expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
            }

            if (g_ipv6_rpl_srh_strict_rfc_checking) {
                /* from RFC6554: */
                /* The SRH MUST NOT specify a path that visits a node more than once. */
                /* To do this, we will just check the current 'addr' against the previous addresses */
                for (i = 0; i < wmem_array_get_count(rpl_addr_vector); i++) {
                    /* Compare the addresses */
                    if (memcmp(&rpl_fulladdr, wmem_array_index(rpl_addr_vector, i), IPv6_ADDR_SIZE) == 0) {
                        /* Found a previous that is the same */
                        expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_mult_inst_same_addr);
                        break;
                    }
                }
                wmem_array_append(rpl_addr_vector, &rpl_fulladdr, 1);
            }

            if (pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
                alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, &rpl_fulladdr);
            }
        }
    }

    return tvb_captured_length(tvb);
}

/* Segment Routing Header (Type 4) */
static int
dissect_routing6_srh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    struct ws_rthdr *rt = (struct ws_rthdr *)data;
    int offset = 0;
    gint addr_offset;
    guint32 last_entry, addr_count;

    proto_tree_add_item_ret_uint(tree, hf_ipv6_routing_srh_last_entry,
                                    tvb, offset, 1, ENC_BIG_ENDIAN,
                                    &last_entry);
    addr_count = last_entry + 1;
    offset += 1;

    proto_tree_add_item(tree, hf_ipv6_routing_srh_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item(tree, hf_ipv6_routing_srh_tag, tvb, offset, 2, ENC_NA);
    offset += 2;

    if (rt->hdr.ip6r_segleft > addr_count) {
        expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
                               "IPv6 Type 4 Routing Header segments left field must not exceed address count (%u)", addr_count);
    }

    if (pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
        alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, tvb_get_ptr_ipv6(tvb, offset));
    }

    for (unsigned i = 0; i < addr_count; i++) {
        addr_offset = offset + i * IPv6_ADDR_SIZE;
        _proto_tree_add_ipv6_vector_address(tree, pinfo, hf_ipv6_routing_srh_addr, tvb,
                addr_offset, IPv6_ADDR_SIZE, tvb_get_ptr_ipv6(tvb, addr_offset), i);
    }

    /* TODO: dissect TLVs */

    return tvb_captured_length(tvb);
}

/* Compact Routing Header 16 (Type 5) and  Compact Routing Header 32 (Type 6).
    https://tools.ietf.org/html/draft-bonica-6man-comp-rtg-hdr-23. */
static int dissect_routing6_crh(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data)
{
    int offset, minimum_crh_length;
    gint sid;

    unsigned sid_count;
    unsigned octets_per_sid;
    unsigned sids_beyond_first_word;
    unsigned sids_per_word;
    struct ws_rthdr* rt = (struct ws_rthdr*)data;
    gboolean is_crh16 = rt->hdr.ip6r_type == IPv6_RT_HEADER_COMPACT_16;
    guint8 segments_left = rt->hdr.ip6r_segleft;

    /* Compute the minimum CRH length measured in 8-octet units, not including
    the first 8 octets */
    minimum_crh_length = -1;
    switch (rt->hdr.ip6r_type) {
    case IPv6_RT_HEADER_COMPACT_16:
        octets_per_sid = 2;
        sids_per_word = 4;
        sid_count = rt->hdr.ip6r_len * 4 + 2;
        if (segments_left <= 2)
            minimum_crh_length = 0;
        sids_beyond_first_word = segments_left - 2;
        break;
    case IPv6_RT_HEADER_COMPACT_32:
        octets_per_sid = 4;
        sids_per_word = 2;
        sid_count = rt->hdr.ip6r_len * 2 + 1;
        if (segments_left <= 1)
            minimum_crh_length = 0;
        sids_beyond_first_word = segments_left - 1;
        break;
    default:
        DISSECTOR_ASSERT_NOT_REACHED();
    }
    if (minimum_crh_length) {
        minimum_crh_length = sids_beyond_first_word / sids_per_word;
        if (sids_beyond_first_word % sids_per_word)
            minimum_crh_length++;
    }
    if (minimum_crh_length > rt->hdr.ip6r_len) {
        expert_add_info_format(pinfo, rt->ti_len, &ei_ipv6_routing_invalid_length,
            "IPv6 Compact Routing Header minimum length must not exceed header length (%u)",
            rt->hdr.ip6r_len);
    }

    offset = 0;
    if (is_crh16) {
        proto_item* current_sid_item = proto_tree_add_item(tree, hf_ipv6_routing_crh16_current_sid,
            tvb, offset + (octets_per_sid * segments_left), octets_per_sid, ENC_BIG_ENDIAN);
        proto_item_set_generated(current_sid_item);
    } else {
        proto_item* current_sid_item = proto_tree_add_item(tree, hf_ipv6_routing_crh32_current_sid,
            tvb, offset + (octets_per_sid * segments_left), octets_per_sid, ENC_BIG_ENDIAN);
        proto_item_set_generated(current_sid_item);
    }
    sid = is_crh16 ? tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN)
                   : tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
    proto_tree* segment_ids
        = proto_tree_add_subtree(tree, tvb, 0, -1, 0, NULL, "Segment Identifiers");
    for (unsigned i = 0; i < sid_count && sid; i++) {
        if (is_crh16) {
            proto_tree_add_uint_format(segment_ids, hf_ipv6_routing_crh16_segment_id, tvb, offset,
                octets_per_sid, sid, "SID[%d] = %d", i, sid);
        } else {
            proto_tree_add_uint_format(segment_ids, hf_ipv6_routing_crh32_segment_id, tvb, offset,
                octets_per_sid, sid, "SID[%d] = %d", i, sid);
        }
        offset += octets_per_sid;
        sid = is_crh16 ? tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN)
                       : tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
    }

    return tvb_captured_length(tvb);
}

/*
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |  Next Header  |  Hdr Ext Len  |  Routing Type | Segments Left |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                                                               |
    .                                                               .
    .                       type-specific data                      .
    .                                                               .
    |                                                               |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static int
dissect_routing6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
    struct ws_rthdr    rt;
    guint              nxt, hdr_len, total_len;
    proto_tree        *rt_tree, *root_tree;
    proto_item        *pi, *ti, *ti_hdr_len, *ti_type, *ti_segs;
    int                offset = 0;
    tvbuff_t          *next_tvb;
    int                type, type_len;
    dissector_handle_t type_dissector;

    col_append_sep_str(pinfo->cinfo, COL_INFO, " , ", "IPv6 routing");

    root_tree = p_ipv6_pinfo_select_root(pinfo, tree);

    pi = proto_tree_add_item(root_tree, proto_ipv6_routing, tvb, offset, -1, ENC_NA);
    rt_tree = proto_item_add_subtree(pi, ett_ipv6_routing_proto);

    proto_tree_add_item(rt_tree, hf_ipv6_routing_nxt, tvb, offset, 1, ENC_BIG_ENDIAN);
    nxt = tvb_get_guint8(tvb, offset);
    offset += 1;

    ti_hdr_len = proto_tree_add_item(rt_tree, hf_ipv6_routing_len, tvb, offset, 1, ENC_BIG_ENDIAN);
    hdr_len = tvb_get_guint8(tvb, offset);
    /*
          Hdr Ext Len         8-bit unsigned integer.  Length of the Routing
                              header in 8-octet units, not including the
                              first 8 octets.
    */
    total_len = (hdr_len + 1) * 8;
    type_len = total_len - 4;

    proto_item_set_len(pi, total_len);
    ti = proto_tree_add_uint(rt_tree, hf_ipv6_routing_len_oct, tvb, offset, 1, total_len);
    proto_item_set_generated(ti);
    if (ipv6_exthdr_hide_len_oct_field) {
        proto_item_set_hidden(ti);
        proto_item_append_text(ti_hdr_len, " (%d bytes)", total_len);
    }
    p_ipv6_pinfo_add_len(pinfo, total_len);
    offset += 1;

    ti_type = proto_tree_add_item(rt_tree, hf_ipv6_routing_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    type = tvb_get_guint8(tvb, offset);
    proto_item_append_text(pi, " (%s)", val_to_str(type, routing_header_type, "Unknown type %u"));
    offset += 1;

    ti_segs = proto_tree_add_item(rt_tree, hf_ipv6_routing_segleft, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    type_dissector = dissector_get_uint_handle(ipv6_routing_dissector_table, type);
    if (type_dissector != NULL) {
        tvb_memcpy(tvb, &(rt.hdr), 0, 4);
        rt.ti_len = ti_hdr_len;
        rt.ti_type = ti_type;
        rt.ti_segleft = ti_segs;
        call_dissector_with_data(type_dissector, tvb_new_subset_length(tvb, offset, type_len), pinfo, rt_tree, &rt);
    }
    else {
        /* Unknown Routing Header Type */
        ti = proto_tree_add_item(rt_tree, hf_ipv6_routing_unknown_data, tvb, offset, type_len, ENC_NA);
        expert_add_info(pinfo, ti, &ei_ipv6_routing_undecoded);
    }

    p_add_ipv6_nxt(pinfo, nxt);

    next_tvb = tvb_new_subset_remaining(tvb, total_len);
    ipv6_dissect_next(nxt, next_tvb, pinfo, tree, (ws_ip6 *)data);
    return tvb_captured_length(tvb);
}

static int
dissect_fraghdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
    proto_item      *pi, *ti;
    proto_tree      *frag_tree, *root_tree;
    guint8           nxt;
    guint16          offlg;
    guint16          frag_off;
    gboolean         frag_flg;
    guint32          frag_ident;
    gint             offset = 0;
    ipv6_pinfo_t    *ipv6_pinfo;
    gboolean         show_data = FALSE;
    gboolean         reassembled;
    tvbuff_t        *next_tvb;

    nxt = tvb_get_guint8(tvb, offset);
    offlg = tvb_get_ntohs(tvb, offset + 2);
    frag_off = offlg & IP6F_OFF_MASK; /* offset in bytes */
    frag_flg = offlg & IP6F_MORE_FRAG;
    frag_ident = tvb_get_ntohl(tvb, offset + 4);
    col_add_fstr(pinfo->cinfo, COL_INFO, "IPv6 fragment (off=%u more=%s ident=0x%08x nxt=%u)",
                        frag_off, frag_flg ? "y" : "n", frag_ident, nxt);

    root_tree = p_ipv6_pinfo_select_root(pinfo, tree);
    ipv6_pinfo = p_ipv6_pinfo_add_len(pinfo, IPv6_FRAGMENT_HDR_SIZE);

    /* IPv6 Fragmentation Header has fixed length of 8 bytes */
    pi = proto_tree_add_item(root_tree, proto_ipv6_fraghdr, tvb, offset, IPv6_FRAGMENT_HDR_SIZE, ENC_NA);
    if (ipv6_pinfo != NULL && ipv6_pinfo->jumbo_plen != 0) {
        expert_add_info(pinfo, pi, &ei_ipv6_opt_jumbo_fragment);
    }

    frag_tree = proto_item_add_subtree(pi, ett_ipv6_fraghdr_proto);

    proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_nxt, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_reserved_octet, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    ti = proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_offset, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_item_append_text(ti, " (%d bytes)", frag_off);

    proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_reserved_bits, tvb, offset, 2, ENC_BIG_ENDIAN);

    proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_more, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_ident, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset += 4;

    if (ipv6_pinfo != NULL && ipv6_pinfo->frag_plen > 0) {
        if ((frag_off != 0) || frag_flg) {
            reassembled = ipv6_reassemble_do(&tvb, &offset, pinfo, root_tree, ipv6_pinfo->frag_plen,
                                             frag_off, frag_flg, frag_ident, &show_data);
            if (show_data) {
                next_tvb = tvb_new_subset_remaining(tvb, offset);
                call_data_dissector(next_tvb, pinfo, tree);
                return tvb_captured_length(tvb);
            }
            if (reassembled) {
                ipv6_pinfo->frag_plen = 0;
                next_tvb = tvb_new_subset_remaining(tvb, offset);
                ipv6_dissect_next(nxt, next_tvb, pinfo, tree, (ws_ip6 *)data);
                return tvb_captured_length(tvb);
            }
        }
    }

    p_add_ipv6_nxt(pinfo, nxt);

    next_tvb = tvb_new_subset_remaining(tvb, offset);
    ipv6_dissect_next(nxt, next_tvb, pinfo, tree, (ws_ip6 *)data);
    return tvb_captured_length(tvb);
}

struct opt_proto_item {
    proto_item *type, *len;
};

/*
 * Jumbo Payload Option
 *
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                   |  Option Type  |  Opt Data Len |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                     Jumbo Payload Length                      |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_jumbo(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti, guint8 opt_len)
{
    proto_item *pi = proto_tree_get_parent(opt_tree);
    proto_item *ti;
    guint32 jumbo_plen = 0;
    ipv6_pinfo_t *ipv6_pinfo = p_get_ipv6_pinfo(pinfo);

    if (opt_len != 4) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "Jumbo Payload: Invalid length (%u bytes)", opt_len);
    }
    ti = proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_jumbo, tvb, offset, 4, ENC_BIG_ENDIAN, &jumbo_plen);
    offset += 4;

    if (ipv6_pinfo != NULL && ipv6_pinfo->ip6_plen != 0) {
        expert_add_info(pinfo, pi, &ei_ipv6_opt_jumbo_prohibited);
    }
    if (jumbo_plen < 65536) {
        expert_add_info(pinfo, ti, &ei_ipv6_opt_jumbo_truncated);
    }

    return offset;
}

/*
 * RPL Option
 *
      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                                     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                     |  Option Type  |  Opt Data Len |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |O|R|F|0|0|0|0|0| RPLInstanceID |          SenderRank           |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                         (sub-TLVs)                            |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_rpl(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti, guint8 opt_len)
{
    static int * const rpl_flags[] = {
        &hf_ipv6_opt_rpl_flag_o,
        &hf_ipv6_opt_rpl_flag_r,
        &hf_ipv6_opt_rpl_flag_f,
        &hf_ipv6_opt_rpl_flag_rsv,
        NULL
    };

    if (opt_len < 4) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "RPL Option: Invalid length (%u bytes)", opt_len);
    }
    proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_rpl_flag, ett_ipv6_opt_rpl, rpl_flags, ENC_NA);
    offset += 1;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_rpl_instance_id, tvb, offset, 1, ENC_NA);
    offset += 1;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_rpl_senderrank, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    /* TODO: Add dissection of sub-TLVs */

    return offset;
}

/*
 * Tunnel Encapsulation Limit Option
 *
      Option Type     Opt Data Len   Opt Data Len
    0 1 2 3 4 5 6 7
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |0 0 0 0 0 1 0 0|       1       | Tun Encap Lim |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_tel(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti, guint8 opt_len)
{
    if (opt_len != 1) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "Tunnel Encapsulation Limit: Invalid length (%u bytes)", opt_len);
    }
    proto_tree_add_item(opt_tree, hf_ipv6_opt_tel, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    return offset;
}

/*
 * IPv6 Minimum Path MTU Hop by Hop Option
 *

    Option    Option    Option
     Type    Data Len   Data
   +--------+--------+--------+--------+---------+-------+-+
   |BBCTTTTT|00000100|     Min-PMTU    |     Rtn-PMTU    |R|
   +--------+--------+--------+--------+---------+-------+-+

     Option Type:

     BB     00   Skip over this option and continue processing.

     C       1   Option data can change en route to the packet's final
                 destination.

     TTTTT 10000 Option Type assigned from IANA [IANA-HBH].

     Length:  4  The size of the each value field in Option Data
                 field supports Path MTU values from 0 to 65,535 octets.

     Min-PMTU: n 16-bits.  The minimum PMTU in octets, reflecting the
                 smallest link MTU that the packet experienced across
                 the path.  This is called the Reported PMTU.  A value
                 less than the IPv6 minimum link MTU [RFC8200]
                 should be ignored.

     Rtn-PMTU: n 15-bits.  The returned minimum PMTU, carrying the 15
                 most significant bits of the latest received Min-PMTU
                 field.  The value zero means that no Reported MTU is
                 being returned.

     R        n  1-bit.  R-Flag.   Set by the source to signal that
                 the destination should include the received
                 Reported PMTU in Rtn-PMTU field.

   [IANA-HBH]
              "Destination Options and Hop-by-Hop Options",
              <https://www.iana.org/assignments/ipv6-parameters/
              ipv6-parameters.xhtml#ipv6-parameters-2>
*/
static gint
dissect_opt_pmtu(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                        struct opt_proto_item *opt_ti, guint8 opt_len)
{
    guint16 val;

    if (opt_len != 4) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "PMTU Option: Invalid Length (%u bytes)", opt_len);
    }

    proto_tree_add_item(opt_tree, hf_ipv6_opt_pmtu_min, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    val = tvb_get_ntohs(tvb, offset);
    proto_tree_add_uint(opt_tree, hf_ipv6_opt_pmtu_rtn, tvb, offset, 2, val & 0xFFFE);
    offset += 1;
    proto_tree_add_boolean(opt_tree, hf_ipv6_opt_pmtu_rtn_flag, tvb, offset, 1, val & 0x0001);
    offset += 1;

    return offset;
}

/*
 * IETF APN6
 *
 * Application-Aware IPv6 Networking (APN6)
 *
 * https://datatracker.ietf.org/wg/apn/about/
 * https://datatracker.ietf.org/doc/draft-li-apn-header/
 * https://datatracker.ietf.org/doc/draft-li-apn-ipv6-encap/
 *
 *  0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  APN-ID-Type  |     Flags     |         APN-Para-Type         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                            APN-ID                             |
   |                    (32-bit/64-bit/128-bit)                    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * */
static gint
dissect_opt_apn6(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                 struct opt_proto_item *opt_ti, guint8 opt_len)
{
    if (opt_len < 8) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
              "APN6 Option: Invalid Length (%u bytes) for basic APN header and shortest APN ID(32-bit)", opt_len);
    }

    guint32 parsed_offset = 0; // offset is for DOH header; parsed_offset is for APN option.
    proto_tree *sub_tree = proto_tree_add_subtree(opt_tree, tvb, offset, opt_len, 0, NULL, "APN Header");

    guint8 apn_id_type = tvb_get_guint8(tvb, offset);
    proto_item *apn_id_type_i = proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_id_type, tvb, offset, 1, ENC_BIG_ENDIAN);

    offset++;
    parsed_offset++;

    if (apn_id_type < APN_ID_32BIT || apn_id_type > APN_ID_128BIT) {
        expert_add_info_format(pinfo, apn_id_type_i, &ei_ipv6_opt_apn_invalid_id_type,
                               "APN6 Option: Invalid APN ID Type (%u)", apn_id_type);
    }


    proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset++;
    parsed_offset++;

    proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_param_type, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    parsed_offset += 2;


    if (apn_id_type >= APN_ID_32BIT) {
        proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_id_part1, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
        parsed_offset += 4;
    }
    if (apn_id_type >= APN_ID_64BIT) {
        if (opt_len - parsed_offset < 4) {
            expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                                   "APN6 Option: Invalid Length (%u bytes) for 64-bit APN ID, parsed offset %u",
                                   opt_len, parsed_offset);
        }
        proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_id_part2, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
        parsed_offset += 4;
    }
    if (apn_id_type >= APN_ID_128BIT) {
        if (opt_len - parsed_offset < 8) {
            expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                                   "APN6 Option: Invalid Length (%u bytes) for 128-bit APN ID, parsed offset %u",
                                   opt_len, parsed_offset);
        }

        proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_id_part3, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        proto_tree_add_item(sub_tree, hf_ipv6_opt_apn_id_part4, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    return offset;
}


/*
 * IPv6 Router Alert Option
 *
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |0 0 0|0 0 1 0 1|0 0 0 0 0 0 1 0|        Value (2 octets)       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                      length = 2
*/
static gint
dissect_opt_rtalert(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                        struct opt_proto_item *opt_ti, guint8 opt_len)
{
    if (opt_len != 2) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "Router alert: Invalid Length (%u bytes)", opt_len);
    }
    proto_tree_add_item(opt_tree, hf_ipv6_opt_rtalert, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    return offset;
}

/*
 * Quick-Start Option for IPv6
 *
    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   Option      |  Length=6     | Func. | Rate  |   Not Used    |
   |               |               | 1000  | Report|               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                        QS Nonce                           | R |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_quickstart(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                        struct opt_proto_item *opt_ti, guint8 opt_len, ws_ip6 *iph)
{
    proto_item *pi = proto_tree_get_parent(opt_tree);
    proto_item *ti;
    guint8 command, function, rate;
    guint32 qs_ttl = 0;

    if (opt_len != 6) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "Quick-Start: Invalid Length (%u bytes)", opt_len);
    }

    command = tvb_get_guint8(tvb, offset);
    function = command >> 4;
    rate = command & QS_RATE_MASK;

    proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_func, tvb, offset, 1, ENC_BIG_ENDIAN);

    switch (function) {
    case QS_RATE_REQUEST:
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;
        proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_qs_ttl, tvb, offset, 1, ENC_BIG_ENDIAN, &qs_ttl);
        proto_item_append_text(pi, ", %s, QS TTL %u",
                               val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"),
                               qs_ttl);
        if (iph != NULL) {
            guint8 ttl_diff;

            ttl_diff = (iph->ip6_hop - qs_ttl) % 256;
            ti = proto_tree_add_uint(opt_tree, hf_ipv6_opt_qs_ttl_diff, tvb, offset, 1, ttl_diff);
            proto_item_set_generated(ti);
            proto_item_append_text(pi, ", QS TTL diff %u", ttl_diff);
        }
        offset += 1;
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
        break;
    case QS_RATE_REPORT:
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_item_append_text(pi, ", %s", val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"));
        offset += 1;
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_unused, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
        break;
    default:
        break;
    }

    return offset;
}

static const value_string ipv6_ioam_opt_types[] = {
    { IP6IOAM_PRE_TRACE,  "Pre-allocated Trace" },
    { IP6IOAM_INC_TRACE,  "Incremental Trace"   },
    { IP6IOAM_POT,        "Proof of Transit"    },
    { IP6IOAM_E2E,        "Edge to Edge"        },
    { 0, NULL}
};

static gint
dissect_opt_ioam_trace_node(tvbuff_t *tvb, gint offset,
                            proto_tree *opt_tree, guint32 trace_type)
{
    proto_tree* sub_tree;

    if (trace_type & IP6IOAM_TRACE_MASK_BIT0) {
        sub_tree = proto_tree_add_subtree(opt_tree, tvb, offset, 4, 0, NULL,
                                          "Hop_Lim and Node ID (short)");
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_hlim,
                            tvb, offset, 1, ENC_NA);
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_id,
                            tvb, offset + 1, 3, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT1) {
        sub_tree = proto_tree_add_subtree(opt_tree, tvb, offset, 4, 0, NULL,
                                          "Ingress and Egress IDs (short)");
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_iif,
                            tvb, offset, 2, ENC_BIG_ENDIAN);
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_eif,
                            tvb, offset + 2, 2, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT2) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_tss,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT3) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_tsf,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT4) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_trdelay,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT5) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_nsdata,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT6) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_qdepth,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT7) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_csum,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT8) {
        sub_tree = proto_tree_add_subtree(opt_tree, tvb, offset, 8, 0, NULL,
                                          "Hop_Lim and Node ID (wide)");
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_hlim,
                            tvb, offset, 1, ENC_NA);
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_id_wide,
                            tvb, offset + 1, 7, ENC_BIG_ENDIAN);
        offset += 8;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT9) {
        sub_tree = proto_tree_add_subtree(opt_tree, tvb, offset, 8, 0, NULL,
                                          "Ingress and Egress IDs (wide)");
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_iif_wide,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(sub_tree, hf_ipv6_opt_ioam_trace_node_eif_wide,
                            tvb, offset + 4, 4, ENC_BIG_ENDIAN);
        offset += 8;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT10) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_nsdata_wide,
                            tvb, offset, 8, ENC_BIG_ENDIAN);
        offset += 8;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT11) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_bufoccup,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT12) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT13) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT14) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT15) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT16) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT17) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT18) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT19) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT20) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    if (trace_type & IP6IOAM_TRACE_MASK_BIT21) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_node_undefined,
                            tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

    return offset;
}

/*
 * IOAM Trace Option Header
 *
      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |         Namespace-ID          | NodeLen | Flags | RemainingLen|
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                IOAM-Trace-Type                |   Reserved    |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<-+
     |                                                               |  |
     |                        node data list [0]                     |  |
     |                                                               |  |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  D
     |                                                               |  a
     |                        node data list [1]                     |  t
     |                                                               |  a
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     ~                             ........                          ~  S
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  p
     |                                                               |  a
     |                        node data list [n-1]                   |  c
     |                                                               |  e
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
     |                                                               |  |
     |                        node data list [n]                     |  |
     |                                                               |  |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<-+
*/
static gint
dissect_opt_ioam_trace(tvbuff_t *tvb, gint offset, packet_info *pinfo,
                       proto_tree *opt_tree, struct opt_proto_item *opt_ti, guint8 opt_len)
{
    proto_item *ti;
    guint32 trace_type, oss_scid;
    guint16 len;
    guint8 remlen, nodelen, oss_len, i = 0;
    gint new_offset;

    static int * const ioam_trace_flags[] = {
        &hf_ipv6_opt_ioam_trace_flag_o,
        &hf_ipv6_opt_ioam_trace_flag_l,
        &hf_ipv6_opt_ioam_trace_flag_a,
        &hf_ipv6_opt_ioam_trace_flag_rsv,
        NULL
    };

    static int * const ioam_trace_types[] = {
        &hf_ipv6_opt_ioam_trace_type_bit0,
        &hf_ipv6_opt_ioam_trace_type_bit1,
        &hf_ipv6_opt_ioam_trace_type_bit2,
        &hf_ipv6_opt_ioam_trace_type_bit3,
        &hf_ipv6_opt_ioam_trace_type_bit4,
        &hf_ipv6_opt_ioam_trace_type_bit5,
        &hf_ipv6_opt_ioam_trace_type_bit6,
        &hf_ipv6_opt_ioam_trace_type_bit7,
        &hf_ipv6_opt_ioam_trace_type_bit8,
        &hf_ipv6_opt_ioam_trace_type_bit9,
        &hf_ipv6_opt_ioam_trace_type_bit10,
        &hf_ipv6_opt_ioam_trace_type_bit11,
        &hf_ipv6_opt_ioam_trace_type_undef,
        &hf_ipv6_opt_ioam_trace_type_bit22,
        &hf_ipv6_opt_ioam_trace_type_rsv,
        NULL
    };

    if (opt_len < 10) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                               "IOAM Option: Invalid length (%u bytes)", opt_len);
    }

    proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_ns, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    nodelen = tvb_get_bits8(tvb, offset * 8, 5);
    ti = proto_tree_add_bits_item(opt_tree, hf_ipv6_opt_ioam_trace_nodelen, tvb,
                                  offset * 8, 5, ENC_BIG_ENDIAN);
    if (!nodelen)
        expert_add_info(pinfo, ti, &ei_ipv6_opt_ioam_invalid_nodelen);

    proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_ioam_trace_flags,
                           ett_ipv6_opt_ioam_trace_flags, ioam_trace_flags, ENC_NA);

    remlen = tvb_get_bits8(tvb, offset * 8 + 9, 7);
    ti = proto_tree_add_bits_item(opt_tree, hf_ipv6_opt_ioam_trace_remlen, tvb,
                                  offset * 8 + 9, 7, ENC_BIG_ENDIAN);
    if (remlen * 4 > opt_len - 10) {
        expert_add_info_format(pinfo, ti, &ei_ipv6_opt_ioam_invalid_remlen,
                               "IOAM RemLen: Invalid length (%u bytes)", remlen * 4);
    }

    offset += 2;

    trace_type = tvb_get_bits32(tvb, offset * 8, 24, ENC_BIG_ENDIAN);
    ti = proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_ioam_trace_type,
                                ett_ipv6_opt_ioam_trace_types, ioam_trace_types, ENC_BIG_ENDIAN);
    proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_trace_rsv, tvb, offset + 3, 1, ENC_NA);
    offset += 4;

    /* node data list parsing starts here */
    if (!nodelen || remlen * 4 > opt_len - 10)
        return offset;

    proto_tree* trace_tree
        = proto_tree_add_subtree(opt_tree, tvb, offset, opt_len - 10, 0, NULL, "Trace Data");

    if (remlen) {
        proto_tree_add_item(trace_tree, hf_ipv6_opt_ioam_trace_free_space, tvb,
                            offset, remlen * 4, ENC_NA);
        offset += remlen * 4;
    }

    len = opt_len - 10 - remlen * 4;
    while (len && len >= nodelen * 4) {
        proto_tree* node_tree
            = proto_tree_add_subtree_format(trace_tree, tvb, offset,
                                            nodelen * 4, 0, NULL, "Node %u", ++i);

        new_offset = dissect_opt_ioam_trace_node(tvb, offset, node_tree, trace_type);
        if (new_offset - offset != nodelen * 4) {
            expert_add_info(pinfo, ti, &ei_ipv6_opt_ioam_invalid_trace_type);
            return offset;
        }

        offset = new_offset;
        len -= nodelen * 4;

        /* Opaque State Snapshot */
        if (trace_type & IP6IOAM_TRACE_MASK_BIT22) {
            if (len < 4) {
                expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                                       "IOAM Option: Invalid length (%u bytes)", opt_len);
                return offset;
            }

            oss_len = tvb_get_guint8(tvb, offset);

            proto_tree* oss_tree
                = proto_tree_add_subtree(node_tree, tvb, offset, (oss_len + 1) * 4,
                                         0, NULL, "Opaque State Snapshot");
            proto_tree_add_item(oss_tree, hf_ipv6_opt_ioam_trace_node_oss_len,
                                tvb, offset, 1, ENC_NA);
            proto_tree_add_item_ret_uint(oss_tree, hf_ipv6_opt_ioam_trace_node_oss_scid,
                                         tvb, offset + 1, 3, ENC_BIG_ENDIAN, &oss_scid);
            offset += 4;

            len -= 4;
            if (len < oss_len * 4) {
                expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                                       "IOAM Option: Invalid length (%u bytes)", opt_len);
                return offset;
            }

            if (oss_len > 0) {
                proto_tree_add_item(oss_tree, hf_ipv6_opt_ioam_trace_node_oss_data,
                                    tvb, offset, oss_len * 4, ENC_NA);

                len -= oss_len * 4;
                offset += oss_len * 4;
            }
        }
    }

    if (len) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                               "IOAM Option: Invalid length (%u bytes)", opt_len);
    }

    return offset;
}

/*
 * IOAM Option Header
 *
      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |  Option Type  |  Opt Data Len |   Reserved    |   IOAM Type   |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_ioam(tvbuff_t *tvb, gint offset, packet_info *pinfo,
                 proto_tree *opt_tree, struct opt_proto_item *opt_ti, guint8 opt_len)
{
    guint32 opt_type;

    if (opt_len < 2) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                               "IOAM Option: Invalid length (%u bytes)", opt_len);
    }

    proto_tree_add_item(opt_tree, hf_ipv6_opt_ioam_rsv, tvb, offset, 1, ENC_NA);
    proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_ioam_opt_type, tvb,
                                 offset + 1, 1, ENC_NA, &opt_type);
    offset += 2;

    proto_tree* opt_type_tree
        = proto_tree_add_subtree(opt_tree, tvb, offset, opt_len - 2, 0, NULL,
                                 val_to_str_const(opt_type, ipv6_ioam_opt_types,
                                                  "Unknown Option-Type"));

    switch (opt_type) {
    case IP6IOAM_PRE_TRACE:
    case IP6IOAM_INC_TRACE:
        offset = dissect_opt_ioam_trace(tvb, offset, pinfo, opt_type_tree, opt_ti, opt_len);
        break;
    case IP6IOAM_POT:
        break;
    case IP6IOAM_E2E:
        break;
    }

    return offset;
}

/*
 * Tunnel Payload Forwarding Option for IPv6
 *
      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                                     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                     |  Option Type  | Option Length |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                        TPF Information                        |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_tpf(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                        struct opt_proto_item *opt_ti, guint8 opt_len)
{
    if (opt_len != 4) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "TPF: Invalid Length (%u bytes)", opt_len);
    }
    proto_tree_add_item(opt_tree, hf_ipv6_opt_tpf_information, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset += 4;

    return offset;
}

/*
   ------------------------------------------------------------
   | Next Header | Hdr Ext Len   | Option Type | Option Length|
   +-------------+---------------+-------------+--------------+
   |             CALIPSO Domain of Interpretation             |
   +-------------+---------------+-------------+--------------+
   | Cmpt Length |  Sens Level   |     Checksum (CRC-16)      |
   +-------------+---------------+-------------+--------------+
   |      Compartment Bitmap (Optional; variable length)      |
   +-------------+---------------+-------------+--------------+
*/
static gint
dissect_opt_calipso(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti, guint8 opt_len)
{
    guint32 cmpt_length = 0;

    if (opt_len < 8) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "CALIPSO: Invalid Length (%u bytes)", opt_len);
    }

    proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_doi, tvb,
                        offset, 4, ENC_BIG_ENDIAN);
    offset += 4;

    proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_calipso_cmpt_length, tvb,
                        offset, 1, ENC_BIG_ENDIAN, &cmpt_length);
    offset += 1;

    proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_sens_level, tvb,
                        offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_checksum(opt_tree, tvb, offset, hf_ipv6_opt_calipso_checksum, -1,
                                NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
    offset += 2;

    proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_cmpt_bitmap, tvb,
                        offset, cmpt_length*4, ENC_NA);
    offset += cmpt_length*4;

    return offset;
}

/*
 * IPv6 SMF_DPD Option Header
 *
       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                     ...              |0|0|0|  01000  | Opt. Data Len |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |0|TidTy| TidLen|             TaggerId (optional) ...           |
      +-+-+-+-+-+-+-+-+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                               |            Identifier  ...
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

           Figure 3: IPv6 SMF_DPD Option Header in I-DPD mode

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                     ...              |0|0|0| OptType | Opt. Data Len |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |1|    Hash Assist Value (HAV) ...
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

           Figure 4: IPv6 SMF_DPD Option Header in H-DPD Mode
*/
static gint
dissect_opt_smf_dpd(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti _U_, guint8 opt_len)
{
    guint8 hash_tid;
    guint8 tid_len;
    gint ident_len;

    proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_hash_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
    hash_tid = tvb_get_guint8(tvb, offset);

    if (hash_tid & 0x80) {
        /* H-DPD Mode */
        proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_hav, tvb, offset, opt_len, ENC_NA);
        return offset + opt_len;
    }

    /* I-DPD Mode */
    proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_tid_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_tid_len, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    ident_len = opt_len - 1;
    if (hash_tid & 0x70) {
        tid_len = (hash_tid & 0x0f) + 1;
        proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_tagger_id, tvb, offset, tid_len, ENC_NA);
        offset += tid_len;
        ident_len -= tid_len;
    }
    if (ident_len > 0) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_ident, tvb, offset, ident_len, ENC_NA);
        offset += ident_len;
    }

    return offset;
}

/*
 * Performance and Diagnostic Metrics Destination Option (ietf-ippm-6man-pdm-option-13)
 *
      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |  Option Type  | Option Length |    ScaleDTLR  |     ScaleDTLS |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |   PSN This Packet             |  PSN Last Received            |
      |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |   Delta Time Last Received    |  Delta Time Last Sent         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_pdm(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti _U_, guint8 opt_len)
{
    if (opt_len != 10) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "PDM: Invalid length (%u bytes)", opt_len);
    }
    proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_scale_dtlr, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_scale_dtls, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_psn_this_pkt, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_psn_last_recv, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_delta_last_recv, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_delta_last_sent, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    return offset;
}

/*
 * Home Address Option
 *
       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                                      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                      |  Option Type  | Option Length |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      +                                                               +
      |                                                               |
      +                          Home Address                         +
      |                                                               |
      +                                                               +
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_home_address(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                            struct opt_proto_item *opt_ti, guint8 opt_len)
{
    if (opt_len != 16) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "Home Address: Invalid length (%u bytes)", opt_len);
    }
    proto_tree_add_item(opt_tree, hf_ipv6_opt_mipv6_home_address, tvb, offset, IPv6_ADDR_SIZE, ENC_NA);
    alloc_address_tvb_ipv6(pinfo->pool, &pinfo->src, tvb, offset);
    offset += IPv6_ADDR_SIZE;

    return offset;
}

/*
 * ILNP Nonce Option
 *

     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    | Next Header   | Hdr Ext Len   |  Option Type  | Option Length |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    /                         Nonce Value                           /
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_ilnp_nonce(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
                            struct opt_proto_item *opt_ti _U_, guint8 opt_len)
{
    proto_tree_add_item(opt_tree, hf_ipv6_opt_ilnp_nonce, tvb, offset, opt_len, ENC_NA);
    offset += opt_len;

    return offset;
}

/*
 * Line-Identification Option
 *
    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                   |  Option Type  | Option Length |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | LineIDLen     |     Line ID...
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_lio(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
                            struct opt_proto_item *opt_ti _U_, guint8 opt_len)
{
    guint32 lid_len = 0;

    proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_lio_len, tvb, offset, 1, ENC_BIG_ENDIAN, &lid_len);
    offset += 1;

    if (lid_len + 1 > opt_len) {
        /* XXX Add expert info */
        lid_len = opt_len - 1;
    }
    proto_tree_add_item(opt_tree, hf_ipv6_opt_lio_id, tvb, offset, lid_len, ENC_BIG_ENDIAN|ENC_ASCII);
    offset += lid_len;

    return offset;
}

/*
 * MPL Option
 *
      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                                     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                     |  Option Type  |  Opt Data Len |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | S |M|V|  rsv  |   sequence    |      seed-id (optional)       |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_mpl(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
                    struct opt_proto_item *opt_ti _U_, guint8 opt_len _U_)
{
    static int * const mpl_flags[] = {
        &hf_ipv6_opt_mpl_flag_s,
        &hf_ipv6_opt_mpl_flag_m,
        &hf_ipv6_opt_mpl_flag_v,
        &hf_ipv6_opt_mpl_flag_rsv,
        NULL
    };
    static const guint8 seed_id_len_arr[4] = {0, 2, 8, 16};
    guint8 seed_id_len;

    proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_mpl_flag, ett_ipv6_opt_mpl, mpl_flags, ENC_NA);
    seed_id_len = seed_id_len_arr[tvb_get_guint8(tvb, offset) >> 6];
    offset +=1;

    proto_tree_add_item(opt_tree, hf_ipv6_opt_mpl_sequence, tvb, offset, 1, ENC_NA);
    offset +=1;
    if (seed_id_len > 0) {
        proto_tree_add_item(opt_tree, hf_ipv6_opt_mpl_seed_id, tvb, offset, seed_id_len, ENC_NA);
        offset += seed_id_len;
    }
    else {
        expert_add_info(pinfo, opt_ti->type, &ei_ipv6_opt_mpl_ipv6_src_seed_id);
    }

    return offset;
}

/*
 * IPv6 DFF Header
 *
                          1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |  Next Header  |  Hdr Ext Len  |  OptTypeDFF   | OptDataLenDFF |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |VER|D|R|0|0|0|0|        Sequence Number        |      Pad1     |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
static gint
dissect_opt_dff(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                            struct opt_proto_item *opt_ti, guint8 opt_len)
{
    static int * const dff_flags[] = {
        &hf_ipv6_opt_dff_flag_ver,
        &hf_ipv6_opt_dff_flag_dup,
        &hf_ipv6_opt_dff_flag_ret,
        &hf_ipv6_opt_dff_flag_rsv,
        NULL
    };

    /* Option length is 3 octets */
    /* http://www.rfc-editor.org/errata_search.php?eid=3937 */
    if (opt_len != 3) {
        expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
                "IPv6 DFF: Invalid length (%u bytes)", opt_len);
    }
    proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_dff_flags,
                            ett_ipv6_opt_dff_flags, dff_flags, ENC_NA);
    offset += 1;
    proto_tree_add_item(opt_tree, hf_ipv6_opt_dff_seqnum, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    return offset;
}

static gint
dissect_opt_unknown(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
                            struct opt_proto_item *opt_ti _U_, guint8 opt_len)
{
    proto_item *ti;

    ti = proto_tree_add_item(opt_tree, hf_ipv6_opt_unknown, tvb,
                        offset, opt_len, ENC_NA);
    expert_add_info(pinfo, ti, &ei_ipv6_opt_unknown_data);

    return offset + opt_len;
}

static int
dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info *pinfo, ws_ip6 *iph, const int exthdr_proto)
{
    gint            len, offset_end;
    guint8          nxt;
    proto_tree     *exthdr_tree, *opt_tree, *opt_type_tree, *root_tree;
    proto_item     *pi, *ti, *ti_len;
    int             hf_exthdr_item_nxt, hf_exthdr_item_len, hf_exthdr_item_len_oct;
    int             ett_exthdr_proto;
    guint8          opt_type, opt_len, opt_start;
    gint            opt_hdr_type;
    const gchar    *opt_name;
    gboolean        hopopts;
    struct opt_proto_item opt_ti;
    tvbuff_t       *next_tvb;

    hopopts = (exthdr_proto == proto_ipv6_hopopts);

    nxt = tvb_get_guint8(tvb, offset);
    len = (tvb_get_guint8(tvb, offset + 1) + 1) << 3;
    offset_end = offset + len;

    root_tree = p_ipv6_pinfo_select_root(pinfo, tree);
    p_ipv6_pinfo_add_len(pinfo, len);

    /* !!! specify length */
    ti = proto_tree_add_item(root_tree, exthdr_proto, tvb, offset, len, ENC_NA);

    if (hopopts && ipv6_previous_layer_id(pinfo) != proto_ipv6) {
        /* IPv6 Hop-by-Hop must appear immediately after IPv6 header (RFC 2460) */
        expert_add_info(pinfo, ti, &ei_ipv6_hopopts_not_first);
    }

    if (exthdr_proto == proto_ipv6_hopopts) {
        hf_exthdr_item_nxt = hf_ipv6_hopopts_nxt;
        hf_exthdr_item_len = hf_ipv6_hopopts_len;
        hf_exthdr_item_len_oct = hf_ipv6_hopopts_len_oct;
        ett_exthdr_proto = ett_ipv6_hopopts_proto;
    } else if (exthdr_proto == proto_ipv6_dstopts) {
        hf_exthdr_item_nxt = hf_ipv6_dstopts_nxt;
        hf_exthdr_item_len = hf_ipv6_dstopts_len;
        hf_exthdr_item_len_oct = hf_ipv6_dstopts_len_oct;
        ett_exthdr_proto = ett_ipv6_dstopts_proto;
    } else {
        DISSECTOR_ASSERT_NOT_REACHED();
    }

    exthdr_tree = proto_item_add_subtree(ti, ett_exthdr_proto);

    proto_tree_add_item(exthdr_tree, hf_exthdr_item_nxt, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    ti_len = proto_tree_add_item(exthdr_tree, hf_exthdr_item_len, tvb, offset, 1, ENC_BIG_ENDIAN);
    ti = proto_tree_add_uint(exthdr_tree, hf_exthdr_item_len_oct, tvb, offset, 1, len);
    proto_item_set_generated(ti);
    if (ipv6_exthdr_hide_len_oct_field) {
        proto_item_set_hidden(ti);
        proto_item_append_text(ti_len, " (%d bytes)", len);
    }
    offset += 1;

    while (offset < offset_end) {
        /* there are more options */

        opt_type = tvb_get_guint8(tvb, offset);
        opt_len = tvb_get_guint8(tvb, offset + 1);
        opt_name = val_to_str_ext(opt_type, &ipv6_opt_type_vals_ext, "Unknown IPv6 Option (%u)");

        pi = proto_tree_add_none_format(exthdr_tree, hf_ipv6_opt, tvb, offset, 2 + opt_len,
                    "%s", opt_name);
        opt_tree = proto_item_add_subtree(pi, ett_ipv6_opt);

        opt_ti.type = proto_tree_add_item(opt_tree, hf_ipv6_opt_type, tvb, offset, 1, ENC_BIG_ENDIAN);

        if (opt_type == IP6OPT_PAD1) {
            /* The Pad1 option is a special case, and contains no data. */
            proto_tree_add_item(opt_tree, hf_ipv6_opt_pad1, tvb, offset, 1, ENC_NA);
            offset += 1;
            continue;
        }

        if ((opt_hdr_type = ipv6_opt_type_hdr(opt_type)) != IPv6_OPT_HDR_ANY) {
            if (hopopts && (opt_hdr_type == IPv6_OPT_HDR_DST)) {
                expert_add_info_format(pinfo, opt_ti.type, &ei_ipv6_opt_header_mismatch,
                        "%s must use a destination options header", opt_name);
            }
            else if (!hopopts && (opt_hdr_type == IPv6_OPT_HDR_HBH)) {
                expert_add_info_format(pinfo, opt_ti.type, &ei_ipv6_opt_header_mismatch,
                        "%s must use a hop-by-hop options header", opt_name);
            }
        }

        opt_type_tree = proto_item_add_subtree(opt_ti.type, ett_ipv6_opt_type);
        proto_tree_add_item(opt_type_tree, hf_ipv6_opt_type_action, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(opt_type_tree, hf_ipv6_opt_type_change, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(opt_type_tree, hf_ipv6_opt_type_rest,   tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        opt_ti.len = proto_tree_add_item(opt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        if (opt_type == IP6OPT_PADN) {
            /* RFC 2460 states :
             * "The PadN option is used to insert two or more octets of
             * padding into the Options area of a header.  For N octets of
             * padding, the Opt Data Len field contains the value N-2, and
             * the Option Data consists of N-2 zero-valued octets."
             */
            proto_tree_add_item(opt_tree, hf_ipv6_opt_padn, tvb, offset, opt_len, ENC_NA);
            offset += opt_len;
            continue;
        }

        opt_start = offset;
        switch (opt_type) {
        case IP6OPT_JUMBO:
            offset = dissect_opt_jumbo(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_RPL:
        case IP6OPT_RPL_OLD:
            offset = dissect_opt_rpl(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_TEL:
            offset = dissect_opt_tel(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_RTALERT:
            offset = dissect_opt_rtalert(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_PMTU:
            offset = dissect_opt_pmtu(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_APN6:
            offset = dissect_opt_apn6(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_QUICKSTART:
            offset = dissect_opt_quickstart(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len, iph);
            break;
        case IP6OPT_IOAM:
            offset = dissect_opt_ioam(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_TPF:
            offset = dissect_opt_tpf(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_CALIPSO:
            offset = dissect_opt_calipso(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_SMF_DPD:
            offset = dissect_opt_smf_dpd(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_PDM:
            offset = dissect_opt_pdm(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_HOME_ADDRESS:
            offset = dissect_opt_home_address(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_ILNP_NONCE:
            offset = dissect_opt_ilnp_nonce(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_LIO:
            offset = dissect_opt_lio(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_MPL:
            offset = dissect_opt_mpl(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_IP_DFF:
            offset = dissect_opt_dff(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        case IP6OPT_ENDI:
            offset = dissect_opt_unknown(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            expert_add_info(pinfo, opt_ti.type, &ei_ipv6_opt_deprecated);
            break;
        case IP6OPT_EXP_1E:
        case IP6OPT_EXP_3E:
        case IP6OPT_EXP_5E:
        case IP6OPT_EXP_7E:
        case IP6OPT_EXP_9E:
        case IP6OPT_EXP_BE:
        case IP6OPT_EXP_DE:
        case IP6OPT_EXP_FE:
            proto_tree_add_item(opt_tree, hf_ipv6_opt_experimental, tvb,
                                offset, opt_len, ENC_NA);
            offset += opt_len;
            break;
        default:
            offset = dissect_opt_unknown(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
            break;
        }
        if (offset < opt_start + opt_len) {
            ti = proto_tree_add_item(opt_tree, hf_ipv6_opt_unknown_data, tvb,
                                offset, opt_start + opt_len - offset, ENC_NA);
            expert_add_info(pinfo, ti, &ei_ipv6_opt_unknown_data);
            offset = opt_start + opt_len;
        }
    }

    p_add_ipv6_nxt(pinfo, nxt);

    next_tvb = tvb_new_subset_remaining(tvb, len);
    ipv6_dissect_next(nxt, next_tvb, pinfo, tree, iph);
    return tvb_captured_length(tvb);
}

static int
dissect_hopopts(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    col_append_sep_str(pinfo->cinfo, COL_INFO, " , ", "IPv6 hop-by-hop options");

    return dissect_opts(tvb, 0, tree, pinfo, (ws_ip6 *)data, proto_ipv6_hopopts);
}

static int
dissect_dstopts(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    col_append_sep_str(pinfo->cinfo, COL_INFO, " , ", "IPv6 destination options");

    return dissect_opts(tvb, 0, tree, pinfo, (ws_ip6 *)data, proto_ipv6_dstopts);
}

/* return value is > G_MAXUINT16, else zero */
/* tvb + offset contains the Hbh header */
static guint32
ipv6_get_jumbo_plen(tvbuff_t *tvb, gint offset)
{
    gint         offset_end, hdr_len;
    gint         opt_type, opt_len;
    guint32      jumbo_plen;

    if (!tvb_bytes_exist(tvb, offset, 2)) {
        return 0;
    }
    hdr_len = (tvb_get_guint8(tvb, offset + 1) + 1) * 8;
    offset_end = offset + hdr_len;
    offset +=2;

    while (offset < offset_end && tvb_bytes_exist(tvb, offset, 6)) {
        opt_type = tvb_get_guint8(tvb, offset);
        offset += 1;
        if (opt_type == IP6OPT_PAD1) {
            continue;
        }
        opt_len = tvb_get_guint8(tvb, offset);
        offset += 1;
        if (opt_type == IP6OPT_JUMBO && opt_len == 4) {
            jumbo_plen = tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
            if (jumbo_plen > G_MAXUINT16) {
                return jumbo_plen;
            }
            return 0;
        }
        offset += opt_len;
    }
    return 0;
}

struct ipv6_addr_and_mask {
    uint8_t addr[16];
    uint8_t mask[16];
};

typedef struct ipv6_addr_and_mask ipv6_range_t;

/* https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml */
static struct ipv6_special_range_s {
    ipv6_range_t range;
    const char *name;
} ipv6_special_purpose_registry[] = {
    {
        {
            { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
        },
        "Loopback Address"
    },
    {
        {
            { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
        },
        "Unspecified Address"
    },
    {
        {
            { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
        },
        "IPv4-mapped Address"
    },
    {
        {
            { 0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
        },
        "IPv4-IPv6 Translat."
    },
    {
        {
            { 0x00, 0x64, 0xff, 0x9b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "IPv4-IPv6 Translat."
    },
    {
        {
            { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Discard-Only Address Block"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "IETF Protocol Assignments"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "TEREDO"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
        },
        "Port Control Protocol Anycast"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
        },
        "Traversal Using Relays around NAT Anycast"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Benchmarking"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "AMT"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x04, 0x01, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "AS112-v6"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "ORCHIDv2"
    },
    {
        {
            { 0x20, 0x01, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Drone Remote ID Protocol Entity Tags (DETs)"
    },
    {
        {
            { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Documentation"
    },
    {
        {
            { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "6to4"
    },
    {
        {
            { 0x26, 0x20, 0x00, 0x4f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Direct Delegation AS112 Service"
    },
    {
        {
            { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Unique-Local"
    },
    {
        {
            { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        "Link-Local Unicast"
    },
    {
        {
            { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
            { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        },
        NULL
    },
};

static bool
match_ipv6_range(const ipv6_range_t *range, const ws_in6_addr *addr)
{
    int i;

    for (i = 0; i < 16; i++) {
        if (range->addr[i] != (addr->bytes[i] & range->mask[i])) {
            return false;
        }
    }
    return true;
}

static void
add_ipv6_address_detail(packet_info *pinfo, proto_item *vis, proto_item *invis,
                        tvbuff_t *tvb, int offset, struct ipv6_addr_info_s *addr_info)
{
    proto_item *ti;
    proto_tree *vtree;      /* visible tree */
    proto_tree *itree;      /* invisible tree */

    vtree = proto_item_add_subtree(vis, ett_ipv6_detail);
    itree = proto_item_add_subtree(invis, ett_ipv6_detail);

    /*
     * Internet Protocol Version 6 Address Space
     * https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml
     */


    if (tvb_get_guint8(tvb, offset) == 0xFF) {
        /* RFC 4291 section 2.4: multicast prefix */
        ti = proto_tree_add_string(vtree, *addr_info->hf_addr_space, tvb, offset, 1, "Multicast");
        proto_item_set_generated(ti);
        if (addr_info == &ipv6_src_info) {
            /* "Shouldn't" see this one as a source */
            expert_add_info(pinfo, ti, &ei_ipv6_src_addr_not_multicast);
        }

        ti = proto_tree_add_string(itree, hf_ipv6_addr_space, tvb, offset, 1, "Multicast");
        proto_item_set_generated(ti);

        /*
         * Multicast address scope and flags.
         *
         * RFC 4291 Section 2.7:
         *   https://www.rfc-editor.org/rfc/rfc4291#section-2.7
         *
         * RFC 7346:
         *   https://www.rfc-editor.org/rfc/rfc7346.html
         *
         * IANA Registry:
         *   https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml#ipv6-scope
         */

        static int *const hf_ipv6_multicast_flags_bits[] = {
            &hf_ipv6_multicast_flags_reserved,
            &hf_ipv6_multicast_flags_embed_rp,
            &hf_ipv6_multicast_flags_network_prefix,
            &hf_ipv6_multicast_flags_transient,
            NULL
        };

        /* Add multicast address flags. */
        ti = proto_tree_add_bitmask(vtree, tvb, offset, *addr_info->hf_multicast_flags,
                    ett_ipv6_multicast_flags, addr_info->hf_multicast_flags_bits, ENC_BIG_ENDIAN);
        proto_item_set_generated(ti);
        ti = proto_tree_add_bitmask(itree, tvb, offset, hf_ipv6_multicast_flags,
                    ett_ipv6_multicast_flags, hf_ipv6_multicast_flags_bits, ENC_BIG_ENDIAN);
        proto_item_set_generated(ti);

        /* Add multicast address scope. */
        ti = proto_tree_add_item(vtree, *addr_info->hf_multicast_scope, tvb, offset, 2, ENC_BIG_ENDIAN);
        proto_item_set_generated(ti);
        ti = proto_tree_add_item(itree, hf_ipv6_multicast_scope, tvb, offset, 2, ENC_BIG_ENDIAN);
        proto_item_set_generated(ti);
    }
    else if ((tvb_get_ntohs(tvb, offset) & 0xFFC0) == 0xFE80) {
        ti = proto_tree_add_string(vtree, *addr_info->hf_addr_space, tvb, offset, 2, "Link-Local Unicast");
        proto_item_set_generated(ti);
        ti = proto_tree_add_string(itree, hf_ipv6_addr_space, tvb, offset, 2, "Link-Local Unicast");
        proto_item_set_generated(ti);
    }
    else if ((tvb_get_guint8(tvb, offset) & 0x30) == 0x20) {
        ti = proto_tree_add_string(vtree, *addr_info->hf_addr_space, tvb, offset, 2, "Global Unicast");
        proto_item_set_generated(ti);
        ti = proto_tree_add_string(itree, hf_ipv6_addr_space, tvb, offset, 2, "Global Unicast");
        proto_item_set_generated(ti);
    }
    else if ((tvb_get_guint8(tvb, offset) & 0xFE) == 0xFC) {
        ti = proto_tree_add_string(vtree, *addr_info->hf_addr_space, tvb, offset, 2, "Unique Local Unicast");
        proto_item_set_generated(ti);
        ti = proto_tree_add_string(itree, hf_ipv6_addr_space, tvb, offset, 2, "Unique Local Unicast");
        proto_item_set_generated(ti);
    }
    else {
        ti = proto_tree_add_string(vtree, *addr_info->hf_addr_space, tvb, offset, 2, "Reserved by IETF");
        proto_item_set_generated(ti);
        ti = proto_tree_add_string(itree, hf_ipv6_addr_space, tvb, offset, 2, "Reserved by IETF");
        proto_item_set_generated(ti);
    }

    /* Check for IPv6 address special-purpose ranges. */
    const ws_in6_addr *addr = tvb_get_ptr_ipv6(tvb, offset);
    const struct ipv6_special_range_s *rp;

    for (rp = ipv6_special_purpose_registry; rp->name != NULL; rp++) {
        if (match_ipv6_range(&rp->range, addr)) {
            ti = proto_tree_add_string(vtree, *addr_info->hf_special_purpose, tvb, offset, IPv6_ADDR_SIZE, rp->name);
            proto_item_set_generated(ti);
            ti = proto_tree_add_string(itree, hf_ipv6_addr_special_purpose, tvb, offset, IPv6_ADDR_SIZE, rp->name);
            proto_item_set_generated(ti);
            break;
        }
    }
}

static void
add_ipv6_address(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset,
                        struct ipv6_addr_info_s *addr_info)
{
    address addr;
    const char *name;
    proto_item *ti, *vis, *invis;

    vis = proto_tree_add_item(tree, *addr_info->hf_addr, tvb, offset, IPv6_ADDR_SIZE, ENC_NA);
    invis = proto_tree_add_item(tree, hf_ipv6_addr, tvb, offset, IPv6_ADDR_SIZE, ENC_NA);
    proto_item_set_hidden(invis);

    set_address_ipv6_tvb(&addr, tvb, offset);
    name = address_to_display(pinfo->pool, &addr);

    if (ipv6_address_detail) {
        add_ipv6_address_detail(pinfo, vis, invis, tvb, offset, addr_info);
    }

    ti = proto_tree_add_string(tree, *addr_info->hf_host, tvb, offset, IPv6_ADDR_SIZE, name);
    proto_item_set_generated(ti);
    proto_item_set_hidden(ti);
    ti = proto_tree_add_string(tree, hf_ipv6_host, tvb, offset, IPv6_ADDR_SIZE, name);
    proto_item_set_generated(ti);
    proto_item_set_hidden(ti);
}

#define ADDRESS_SET_GENERATED_HIDDEN(ti) \
    G_STMT_START {                              \
        proto_item_set_generated(ti);           \
        if (i > 0) proto_item_set_hidden(ti);   \
    } G_STMT_END

/* RFC 3056 section 2 */
static void
add_ipv6_address_6to4(proto_tree *tree, tvbuff_t *tvb, int offset,
                        gint hf_gateway, gint hf_sla_id)
{
    if (tvb_get_ntohs(tvb, offset) != 0x2002)
        return;

    struct { gint gateway, sla_id; } hf[2] = {
        { hf_gateway, hf_sla_id},
        { hf_ipv6_6to4_gateway_ipv4, hf_ipv6_6to4_sla_id}
    };
    proto_item *ti;
    for (int i = 0; i < 2; i++) {
        ti = proto_tree_add_item(tree, hf[i].gateway, tvb, offset + 2, 4, ENC_BIG_ENDIAN);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
        ti = proto_tree_add_item(tree, hf[i].sla_id, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
    }
}

/* RFC 4380 section 4 */
static void
add_ipv6_address_teredo(proto_tree *tree, tvbuff_t *tvb, int offset,
                        gint hf_server, gint hf_port, gint hf_client)
{
    if (tvb_get_ntohl(tvb, offset) != 0x20010000)
        return;

    guint16 mapped_port = tvb_get_ntohs(tvb, offset + 10) ^ 0xffff;
    guint32 client_v4 = tvb_get_ipv4(tvb, offset + 12) ^ 0xffffffff;

    struct { gint server, port, client; } hf[2] = {
        { hf_server, hf_port, hf_client },
        { hf_ipv6_teredo_server_ipv4, hf_ipv6_teredo_port, hf_ipv6_teredo_client_ipv4 }
    };
    proto_item *ti;
    for (int i = 0; i < 2; i++) {
        ti = proto_tree_add_item(tree, hf[i].server, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
        ti = proto_tree_add_uint(tree, hf[i].port, tvb, offset + 10, 2, mapped_port);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
        ti = proto_tree_add_ipv4(tree, hf[i].client, tvb, offset + 12, 4, client_v4);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
    }
}

/* RFC 4291 appendix A */
static void
add_ipv6_address_slaac(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_slaac)
{
    if (!(tvb_get_guint8(tvb, offset + 8) & 0x02) ||
                            !(tvb_get_ntohs(tvb, offset + 11) == 0xfffe)) {
        return;
    }

    guint8 *mac_addr = (guint8 *)wmem_alloc(pinfo->pool, 6);
    tvb_memcpy(tvb, mac_addr, offset + 8, 3);
    tvb_memcpy(tvb, mac_addr+3, offset + 13, 3);
    mac_addr[0] &= ~0x02;

    struct { gint mac; } hf[2] = {
        { hf_slaac },
        { hf_ipv6_slaac_mac }
    };
    proto_item *ti;
    for (int i = 0; i < 2; i++) {
        ti = proto_tree_add_ether(tree, hf[i].mac, tvb, offset + 8, 8, mac_addr);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
    }
}

/* RFC 5214 section 6.1 */
static void
add_ipv6_address_isatap(proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_isatap)
{
    if ((tvb_get_ntohl(tvb, offset + 8) & 0xfcffffff) != 0x00005efe)
        return;

    struct { gint ipv4; } hf[2] = {
        { hf_isatap },
        { hf_ipv6_isatap_ipv4 }
    };
    proto_item *ti;
    for (int i = 0; i < 2; i++) {
        ti = proto_tree_add_item(tree, hf[i].ipv4, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
        ADDRESS_SET_GENERATED_HIDDEN(ti);
    }
}

/* RFC 6052 */
static void
add_ipv6_address_embed_ipv4(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_embed)
{
    /* Section 2.1: Well-Known Prefix for IPv4-Embedded IPv6 Address: 64:FF9B::/96 */
    static const guint8 well_known_prefix[] = {
        0x00, 0x64, 0xFF, 0x9B,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00
    };

    ws_in6_addr ipv6_addr;
    ws_in4_addr ipv4_addr;
    gint ipv4_prefix;
    gint ipv4_offset;
    gboolean ipv6_embed_ipv4 = false;

    if (tvb_memeql(tvb, offset, well_known_prefix, sizeof well_known_prefix) == 0) {
        ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 96, 32, ENC_BIG_ENDIAN);
        ipv4_prefix = 96;
        ipv4_offset = 96;
        ipv6_embed_ipv4 = true;
    } else {
        for (size_t j = 0; j < number_of_nat64_prefix; j++) {
            if (nat64_prefix_uats[j].prefix_len <= nat64_prefix_uats[j].prefix_wildcard_len) {
                continue;
            }

            if (ws_inet_pton6(nat64_prefix_uats[j].ipaddr, &ipv6_addr)) {
                if (tvb_memeql(tvb, offset, (const guint8 *)&ipv6_addr,
                    (nat64_prefix_uats[j].prefix_len - nat64_prefix_uats[j].prefix_wildcard_len) / 8) == 0) {
                    switch (nat64_prefix_uats[j].prefix_len)
                    {
                        case 32:
                            ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 32, 32, ENC_BIG_ENDIAN);
                            break;
                        case 40:
                            ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 40, 24, ENC_BIG_ENDIAN) << 8;
                            ipv4_addr |= tvb_get_bits32(tvb, (offset * 8) + 72, 8, ENC_BIG_ENDIAN);
                            break;
                        case 48:
                            ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 48, 16, ENC_BIG_ENDIAN) << 16;
                            ipv4_addr |= tvb_get_bits32(tvb, (offset * 8) + 72, 16, ENC_BIG_ENDIAN);
                            break;
                        case 56:
                            ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 56, 8, ENC_BIG_ENDIAN) << 24;
                            ipv4_addr |= tvb_get_bits32(tvb, (offset * 8) + 72, 24, ENC_BIG_ENDIAN);
                            break;
                        case 64:
                            ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 72, 32, ENC_BIG_ENDIAN);
                            break;
                        case 96:
                            ipv4_addr = tvb_get_bits32(tvb, (offset * 8) + 96, 32, ENC_BIG_ENDIAN);
                            break;
                        default:
                            DISSECTOR_ASSERT_NOT_REACHED();
                    }

                    ipv4_prefix = nat64_prefix_uats[j].prefix_len;
                    if (ipv4_prefix != 64) {
                        ipv4_offset = ipv4_prefix;
                    } else {
                        ipv4_offset = 72;
                    }
                    ipv6_embed_ipv4 = true;
                    break;
                }
            }
        }
    }

    if (ipv6_embed_ipv4) {
        proto_item *ti;

        // The prefix
        ti = proto_tree_add_item(tree, hf_ipv6_embed_ipv4_prefix, tvb, offset, ipv4_prefix / 8, ENC_NA);
        proto_item_set_generated(ti);

        // Majority of IPv4 address is after u-field
        if (ipv4_prefix >= 56) {
            if (ipv4_prefix < 96) {
                ti = proto_tree_add_item(tree, hf_ipv6_embed_ipv4_u, tvb, offset + 8, 1, ENC_NA);
                proto_item_set_generated(ti);
            }
            if (tvb_get_guint8(tvb, offset + 8)) {
                expert_add_info(pinfo, ti, &ei_ipv6_embed_ipv4_u_value);
            }
        }

        // IPv4 embedded address
        ipv4_addr = g_ntohl(ipv4_addr);
        ti = proto_tree_add_ipv4(tree, hf_embed, tvb,
                                 offset + (ipv4_offset / 8),
                                 (ipv4_offset > 32 && ipv4_offset < 64) ? 5 : 4, ipv4_addr);
        proto_item_set_generated(ti);

        ti = proto_tree_add_ipv4(tree, hf_ipv6_embed_ipv4, tvb,
                                 offset + (ipv4_offset / 8),
                                 (ipv4_offset > 32 && ipv4_offset < 64) ? 5 : 4, ipv4_addr);
        proto_item_set_generated(ti);

        // Majority of IPv4 address is before u-field
        if (ipv4_prefix < 56) {
            ti = proto_tree_add_item(tree, hf_ipv6_embed_ipv4_u, tvb, offset + 8, 1, ENC_NA);
            proto_item_set_generated(ti);
            if (tvb_get_guint8(tvb, offset + 8)) {
                expert_add_info(pinfo, ti, &ei_ipv6_embed_ipv4_u_value);
            }
        }

        // Suffix, if present
        if (ipv4_prefix < 96) {
            ti = proto_tree_add_item(tree, hf_ipv6_embed_ipv4_suffix, tvb,
                                     offset + ((72 + ipv4_prefix - 32) / 8),
                                     (56 - (ipv4_prefix - 32)) / 8,
                                     ENC_NA);
            proto_item_set_generated(ti);
        }
    }
}

static void
export_pdu(tvbuff_t *tvb, packet_info *pinfo)
{
  if (have_tap_listener(exported_pdu_tap)) {
    exp_pdu_data_t *exp_pdu_data = wmem_new0(pinfo->pool, exp_pdu_data_t);

    exp_pdu_data->tvb_captured_length = tvb_captured_length(tvb);
    exp_pdu_data->tvb_reported_length = tvb_reported_length(tvb);
    exp_pdu_data->pdu_tvb = tvb;
    tap_queue_packet(exported_pdu_tap, pinfo, exp_pdu_data);
  }
}

static int
dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    proto_tree    *ipv6_tree, *pt;
    proto_item    *ipv6_item, *ti, *pi;
    proto_item    *ti_ipv6_plen = NULL, *ti_ipv6_version;
    guint8         ip6_tcls, ip6_nxt, ip6_hlim;
    guint32        ip6_flow;
    const ws_in6_addr *ip6_src, *ip6_dst;
    guint32        ip6_plen = 0, jumbo_plen = 0;
    guint32        plen;
    int            offset;
    guint          reported_plen;
    tvbuff_t      *next_tvb;
    gboolean       save_fragmented;
    int            version;
    ws_ip6        *iph;

    offset = 0;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPv6");
    col_clear(pinfo->cinfo, COL_INFO);

    ipv6_item = proto_tree_add_item(tree, proto_ipv6, tvb, offset, IPv6_HDR_SIZE, ENC_NA);
    ipv6_tree = proto_item_add_subtree(ipv6_item, ett_ipv6_proto);

    /* Validate IP version (6) */
    version = tvb_get_bits8(tvb, (offset + IP6H_CTL_VFC) * 8, 4);
    ti_ipv6_version = proto_tree_add_bits_item(ipv6_tree, hf_ipv6_version, tvb,
                                 (offset + IP6H_CTL_VFC) * 8, 4, ENC_BIG_ENDIAN);
    pi = proto_tree_add_item(ipv6_tree, hf_ip_version, tvb,
                                 offset + IP6H_CTL_VFC, 1, ENC_BIG_ENDIAN);
    proto_item_append_text(pi, " [This field makes the filter match on \"ip.version == 6\" possible]");
    proto_item_set_hidden(pi);
    if (version != 6) {
        col_add_fstr(pinfo->cinfo, COL_INFO,
                 "Bogus IPv6 version (%u, must be 6)", version);
        expert_add_info_format(pinfo, ti_ipv6_version, &ei_ipv6_bogus_ipv6_version, "Bogus IPv6 version");
        return offset + IP6H_CTL_VFC;
    }

    /* Validate header size (40 bytes) */
    if (tvb_reported_length(tvb) < IPv6_HDR_SIZE) {
        col_add_fstr(pinfo->cinfo, COL_INFO,
                        "Invalid IPv6 header (%u bytes, need exactly 40)",
                        tvb_reported_length(tvb));
        expert_add_info_format(pinfo, ipv6_item, &ei_ipv6_invalid_header,
                        "IPv6 header must be exactly 40 bytes");
    }

    /* !!! warning: (4-bit) version, (6-bit) DSCP, (2-bit) ECN and (20-bit) Flow */
    ti = proto_tree_add_item(ipv6_tree, hf_ipv6_tclass, tvb,
                        offset + IP6H_CTL_VFC, 4, ENC_BIG_ENDIAN);
    ip6_tcls = tvb_get_bits8(tvb, (offset + IP6H_CTL_VFC) * 8 + 4, 8);
    proto_item_append_text(ti, " (DSCP: %s, ECN: %s)",
                        val_to_str_ext_const(IPDSFIELD_DSCP(ip6_tcls), &dscp_short_vals_ext, "Unknown"),
                        val_to_str_ext_const(IPDSFIELD_ECN(ip6_tcls), &ecn_short_vals_ext, "Unknown"));

    pt = proto_item_add_subtree(ti, ett_ipv6_traffic_class);
    proto_tree_add_item(pt, hf_ipv6_tclass_dscp, tvb,
                        offset + IP6H_CTL_VFC, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(pt, hf_ipv6_tclass_ecn, tvb,
                        offset + IP6H_CTL_VFC, 4, ENC_BIG_ENDIAN);

    /* Set DSCP column */
    col_add_str(pinfo->cinfo, COL_DSCP_VALUE,
                val_to_str_ext(IPDSFIELD_DSCP(ip6_tcls), &dscp_short_vals_ext, "%u"));

    proto_tree_add_item_ret_uint(ipv6_tree, hf_ipv6_flow, tvb,
                        offset + IP6H_CTL_FLOW + 1, 3, ENC_BIG_ENDIAN, &ip6_flow);

    ip6_plen = tvb_get_guint16(tvb, offset + IP6H_CTL_PLEN, ENC_BIG_ENDIAN);

    ip6_nxt = tvb_get_guint8(tvb, offset + IP6H_CTL_NXT);

    if (ipv6_tso_supported && ip6_plen == 0 &&
                    ip6_nxt != IP_PROTO_HOPOPTS && ip6_nxt != IP_PROTO_NONE) {
        ip6_plen = tvb_reported_length(tvb) - IPv6_HDR_SIZE;
        pi = proto_tree_add_uint_format_value(ipv6_tree, hf_ipv6_plen, tvb,
                                offset + IP6H_CTL_PLEN, 2, ip6_plen,
                                "%u bytes (reported as 0, presumed to be because "
                                "of \"TCP segmentation offload\" (TSO))",
                                ip6_plen);
        proto_item_set_generated(pi);
    } else {
        ti_ipv6_plen = proto_tree_add_item(ipv6_tree, hf_ipv6_plen, tvb,
                                offset + IP6H_CTL_PLEN, 2, ENC_BIG_ENDIAN);
        if (ip6_plen == 0 && ip6_nxt != IP_PROTO_HOPOPTS && ip6_nxt != IP_PROTO_NONE) {
            expert_add_info(pinfo, ti_ipv6_plen, &ei_ipv6_plen_zero);
        }
    }

    proto_tree_add_item(ipv6_tree, hf_ipv6_nxt, tvb, offset + IP6H_CTL_NXT, 1, ENC_NA);

    proto_tree_add_item(ipv6_tree, hf_ipv6_hlim, tvb,
                        offset + IP6H_CTL_HLIM, 1, ENC_BIG_ENDIAN);
    ip6_hlim = tvb_get_guint8(tvb, offset + IP6H_CTL_HLIM);

    /* Source address */
    add_ipv6_address(pinfo, ipv6_tree, tvb, offset + IP6H_SRC, &ipv6_src_info);
    ip6_src = tvb_get_ptr_ipv6(tvb, offset + IP6H_SRC);
    alloc_address_wmem_ipv6(pinfo->pool, &pinfo->net_src, ip6_src);
    copy_address_shallow(&pinfo->src, &pinfo->net_src);

    /* Destination address */
    add_ipv6_address(pinfo, ipv6_tree, tvb, offset + IP6H_DST, &ipv6_dst_info);
    ip6_dst = tvb_get_ptr_ipv6(tvb, offset + IP6H_DST);
    alloc_address_wmem_ipv6(pinfo->pool, &pinfo->net_dst, ip6_dst);
    copy_address_shallow(&pinfo->dst, &pinfo->net_dst);

    if (tree) {
        if (ipv6_summary_in_tree) {
            proto_item_append_text(ipv6_item, ", Src: %s, Dst: %s",
                    address_with_resolution_to_str(pinfo->pool, &pinfo->src),
                    address_with_resolution_to_str(pinfo->pool, &pinfo->dst));
        }

        /* Add the different items for the address */
        add_ipv6_address_6to4(ipv6_tree, tvb, offset + IP6H_SRC,
                hf_ipv6_src_6to4_gateway_ipv4, hf_ipv6_src_6to4_sla_id);
        add_ipv6_address_6to4(ipv6_tree, tvb, offset + IP6H_DST,
                hf_ipv6_dst_6to4_gateway_ipv4, hf_ipv6_dst_6to4_sla_id);

        add_ipv6_address_teredo(ipv6_tree, tvb, offset + IP6H_SRC,
                hf_ipv6_src_teredo_server_ipv4, hf_ipv6_src_teredo_port, hf_ipv6_src_teredo_client_ipv4);
        add_ipv6_address_teredo(ipv6_tree, tvb, offset + IP6H_DST,
                hf_ipv6_dst_teredo_server_ipv4, hf_ipv6_dst_teredo_port, hf_ipv6_dst_teredo_client_ipv4);

        add_ipv6_address_slaac(pinfo, ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src_slaac_mac);
        add_ipv6_address_slaac(pinfo, ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst_slaac_mac);

        add_ipv6_address_isatap(ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src_isatap_ipv4);
        add_ipv6_address_isatap(ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst_isatap_ipv4);

        add_ipv6_address_embed_ipv4(pinfo, ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src_embed_ipv4);
        add_ipv6_address_embed_ipv4(pinfo, ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst_embed_ipv4);

        if (gbl_resolv_flags.maxmind_geoip) {
            add_geoip_info(ipv6_tree, pinfo, tvb, offset, ip6_src, ip6_dst);
        }
    }

    /* Increment offset to point to next header (may be an extension header) */
    offset += IPv6_HDR_SIZE;

    /* Check for Jumbo option */
    plen = ip6_plen;
    if (plen == 0 && ip6_nxt == IP_PROTO_HOPOPTS) {
        jumbo_plen = ipv6_get_jumbo_plen(tvb, offset);
        if (jumbo_plen != 0) {
            proto_item_append_text(ti_ipv6_plen, " (Jumbogram)");
            plen = jumbo_plen;
        } else {
            /* IPv6 length zero is invalid if there is a hop-by-hop header without jumbo option */
            col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid IPv6 payload length");
            expert_add_info(pinfo, ti_ipv6_plen, &ei_ipv6_opt_jumbo_missing);
        }
    }

    reported_plen = tvb_reported_length(tvb) - IPv6_HDR_SIZE;
    if (!pinfo->flags.in_error_pkt && plen > reported_plen) {
        expert_add_info_format(pinfo, ti_ipv6_plen, &ei_ipv6_plen_exceeds_framing,
                    "IPv6 payload length exceeds framing length (%d bytes)", reported_plen);
    }

    /* Fill in IP header fields for subdissectors */
    iph = wmem_new0(pinfo->pool, ws_ip6);
    iph->ip6_ver = 6;
    iph->ip6_tc = ip6_tcls;
    iph->ip6_flw = ip6_flow;
    iph->ip6_len = plen;
    iph->ip6_nxt = ip6_nxt;
    iph->ip6_hop = ip6_hlim;
    alloc_address_wmem_ipv6(pinfo->pool, &iph->ip6_src, ip6_src);
    alloc_address_wmem_ipv6(pinfo->pool, &iph->ip6_dst, ip6_dst);

    /* Shared state between IPv6 header and extensions. */
    ipv6_pinfo_t  *ipv6_pinfo = wmem_new0(pinfo->pool, ipv6_pinfo_t);
    ipv6_pinfo->ip6_plen = ip6_plen;
    ipv6_pinfo->jumbo_plen = jumbo_plen;
    ipv6_pinfo->frag_plen = ip6_plen; /* updated by extension header dissectors, if any */
    if (!ipv6_exthdr_under_root) {
        ipv6_pinfo->ipv6_tree = ipv6_tree;
        ipv6_pinfo->ipv6_item_len = IPv6_HDR_SIZE;
    }
    p_add_proto_data(pinfo->pool, pinfo, proto_ipv6, IPV6_PROTO_PINFO, ipv6_pinfo);

    /* Adjust the length of this tvbuff to include only the IPv6 datagram. */
    set_actual_length(tvb, IPv6_HDR_SIZE + plen);
    /* Only export after adjusting the length */
    export_pdu(tvb, pinfo);
    save_fragmented = pinfo->fragmented;

    p_add_ipv6_nxt(pinfo, ip6_nxt);

    next_tvb = tvb_new_subset_remaining(tvb, offset);
    ipv6_dissect_next(ip6_nxt, next_tvb, pinfo, tree, iph);

    pinfo->fragmented = save_fragmented;
    return tvb_captured_length(tvb);
}

void
ipv6_dissect_next(guint nxt, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ws_ip6 *iph)
{
    dissector_handle_t nxt_handle;
    ipv6_pinfo_t *ipv6_pinfo = p_get_ipv6_pinfo(pinfo);

    /* https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml#extension-header */

    switch (nxt) {
        case IP_PROTO_HOPOPTS:
        case IP_PROTO_ROUTING:
        case IP_PROTO_FRAGMENT:
        //case IP_PROTO_ESP:    Even though ESP is technically an extension header,
        //                      we treat it as a payload container.
        case IP_PROTO_AH:
        case IP_PROTO_DSTOPTS:
        case IP_PROTO_MIPV6:
        //case IP_PROTO_HIP:    Even though HIP is technically an extension header, the only defined
        //                      next header is IP_NONE. Also the HIP dissector is not ready for this.
        case IP_PROTO_SHIM6:
            nxt_handle = dissector_get_uint_handle(ip_dissector_table, nxt);
            break;
        default:
            nxt_handle = NULL;
            break;
    }
    if (nxt_handle != NULL) {
        call_dissector_with_data(nxt_handle, tvb, pinfo, tree, iph);
        return;
    }

    /*
     * Done with extension header chain
     */

    if (ipv6_pinfo != NULL && ipv6_pinfo->ipv6_tree != NULL) {
        /* Set IPv6 Header length */
        proto_item_set_len(proto_tree_get_parent(ipv6_pinfo->ipv6_tree), ipv6_pinfo->ipv6_item_len);
        ipv6_pinfo->ipv6_tree = NULL;
    }

    if (iph != NULL && iph->ip6_ver == 6) {
        iph->ip6_nxt = nxt; /* upper-layer protocol more useful */
        tap_queue_packet(ipv6_tap, pinfo, iph);
    }

    if (nxt == IP_PROTO_NONE) {
        col_set_str(pinfo->cinfo, COL_INFO, "IPv6 no next header");
        call_data_dissector(tvb, pinfo, tree);
        return;
    }

    if (ip_try_dissect(try_heuristic_first, nxt, tvb, pinfo, tree, iph)) {
        return;
    }

    /* Unknown protocol. */
    col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown IP Protocol: %s (%u)", ipprotostr(nxt), nxt);
    call_data_dissector(tvb, pinfo, tree);
}

void
proto_register_ipv6(void)
{
    static hf_register_info hf_ipv6[] = {
        { &hf_ipv6_version,
            { "Version", "ipv6.version",
                FT_UINT8, BASE_DEC, NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_ip_version,
            { "Version", "ip.version",
                FT_UINT8, BASE_DEC, NULL, 0xF0,
                NULL, HFILL }
        },
        { &hf_ipv6_tclass,
            { "Traffic Class", "ipv6.tclass",
                FT_UINT32, BASE_HEX, NULL, 0x0FF00000,
                NULL, HFILL }
        },
        { &hf_ipv6_tclass_dscp,
            { "Differentiated Services Codepoint", "ipv6.tclass.dscp",
                FT_UINT32, BASE_DEC | BASE_EXT_STRING, &dscp_vals_ext, 0x0FC00000,
                NULL, HFILL }
        },
        { &hf_ipv6_tclass_ecn,
            { "Explicit Congestion Notification", "ipv6.tclass.ecn",
                FT_UINT32, BASE_DEC | BASE_EXT_STRING, &ecn_vals_ext, 0x00300000,
                NULL, HFILL }
        },
        { &hf_ipv6_flow,
            { "Flow Label", "ipv6.flow",
                FT_UINT24, BASE_HEX, NULL, 0x0FFFFF,
                NULL, HFILL }
        },
        { &hf_ipv6_plen,
            { "Payload Length", "ipv6.plen",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_nxt,
            { "Next Header", "ipv6.nxt",
                FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_hlim,
            { "Hop Limit", "ipv6.hlim",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_src,
            { "Source Address", "ipv6.src",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                "Source IPv6 Address", HFILL }
        },
        { &hf_ipv6_src_addr_space,
            { "Source Address Space", "ipv6.src_addr_space",
                FT_STRING, BASE_NONE, NULL, 0x0,
                "Source IPv6 Address Space", HFILL }
        },
        { &hf_ipv6_src_multicast_flags,
            { "Source Address Multicast Flags", "ipv6.src_multicast_flags",
                FT_UINT16, BASE_HEX, NULL, 0x00F0,
                NULL, HFILL }
        },
        { &hf_ipv6_src_multicast_flags_transient,
            { "Source Address Transient Multicast Flag", "ipv6.src_multicast_flags.transient",
                FT_BOOLEAN, 16, NULL, 0x0010,
                NULL, HFILL }
        },
        { &hf_ipv6_src_multicast_flags_network_prefix,
            { "Source Address Network Prefix Multicast Flag", "ipv6.src_multicast_flags.network_prefix",
                FT_BOOLEAN, 16, NULL, 0x0020,
                NULL, HFILL }
        },
        { &hf_ipv6_src_multicast_flags_embed_rp,
            { "Source Address RP Multicast Flag", "ipv6.src_multicast_flags.embed_rp",
                FT_BOOLEAN, 16, NULL, 0x0040,
                NULL, HFILL }
        },
        { &hf_ipv6_src_multicast_flags_reserved,
            { "Source Address Reserved Multicast Flag", "ipv6.src_multicast_flags.reserved",
                FT_UINT16, BASE_DEC, NULL, 0x0080,
                NULL, HFILL }
        },
        { &hf_ipv6_src_multicast_scope,
            { "Source Address Multicast Scope", "ipv6.src_multicast_scope",
                FT_UINT16, BASE_HEX, VALS(ipv6_multicast_scope_vals), 0x000F,
                NULL, HFILL }
        },
        { &hf_ipv6_src_special_purpose,
            { "Source Address Special-Purpose Allocation", "ipv6.src_special_purpose",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_src_host,
            { "Source Host", "ipv6.src_host",
                FT_STRING, BASE_NONE, NULL, 0x0,
                "Source IPv6 Host", HFILL }
        },
        { &hf_ipv6_src_slaac_mac,
            { "Source SLAAC MAC", "ipv6.src_slaac_mac",
                FT_ETHER, BASE_NONE, NULL, 0x0,
                "Source IPv6 Stateless Address Autoconfiguration (SLAAC) 48-bit MAC Identifier", HFILL }
        },
        { &hf_ipv6_src_isatap_ipv4,
            { "Source ISATAP IPv4", "ipv6.src_isatap_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Source IPv6 ISATAP Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_src_6to4_gateway_ipv4,
            { "Source 6to4 Gateway IPv4", "ipv6.src_6to4_gw_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Source IPv6 6to4 Gateway IPv4 Address", HFILL }
        },
        { &hf_ipv6_src_6to4_sla_id,
            { "Source 6to4 SLA ID", "ipv6.src_6to4_sla_id",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Source IPv6 6to4 SLA ID", HFILL }
        },
        { &hf_ipv6_src_teredo_server_ipv4,
            { "Source Teredo Server IPv4", "ipv6.src_ts_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Source IPv6 Teredo Server Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_src_teredo_port,
            { "Source Teredo Port", "ipv6.src_tc_port",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Source IPv6 Teredo Client Mapped Port", HFILL }
        },
        { &hf_ipv6_src_teredo_client_ipv4,
            { "Source Teredo Client IPv4", "ipv6.src_tc_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Source IPv6 Teredo Client Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_src_embed_ipv4,
            { "Source Embedded IPv4", "ipv6.src_embed_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Source IPv4-Embedded IPv6 Address", HFILL }
        },
        { &hf_ipv6_dst,
            { "Destination Address", "ipv6.dst",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                "Destination IPv6 Address", HFILL }
        },
        { &hf_ipv6_dst_addr_space,
            { "Destination Address Space", "ipv6.dst_addr_space",
                FT_STRING, BASE_NONE, NULL, 0x0,
                "Destination IPv6 Address Space", HFILL }
        },
        { &hf_ipv6_dst_multicast_flags,
            { "Destination Address Multicast Flags", "ipv6.dst_multicast_flags",
                FT_UINT16, BASE_HEX, NULL, 0x00F0,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_multicast_flags_transient,
            { "Destination Address Transient Multicast Flag", "ipv6.dst_multicast_flags.transient",
                FT_BOOLEAN, 16, NULL, 0x0010,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_multicast_flags_network_prefix,
            { "Destination Address Network Prefix Multicast Flag", "ipv6.dst_multicast_flags.network_prefix",
                FT_BOOLEAN, 16, NULL, 0x0020,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_multicast_flags_embed_rp,
            { "Destination Address RP Multicast Flag", "ipv6.dst_multicast_flags.embed_rp",
                FT_BOOLEAN, 16, NULL, 0x0040,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_multicast_flags_reserved,
            { "Destination Address Reserved Multicast Flag", "ipv6.dst_multicast_flags.reserved",
                FT_UINT16, BASE_DEC, NULL, 0x0080,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_multicast_scope,
            { "Destination Address Multicast Scope", "ipv6.dst_multicast_scope",
                FT_UINT16, BASE_HEX, VALS(ipv6_multicast_scope_vals), 0x000F,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_special_purpose,
            { "Destination Address Special-Purpose Allocation", "ipv6.dst_special_purpose",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_dst_host,
            { "Destination Host", "ipv6.dst_host",
                FT_STRING, BASE_NONE, NULL, 0x0,
                "Destination IPv6 Host", HFILL }
        },
        { &hf_ipv6_dst_slaac_mac,
            { "Destination SLAAC MAC", "ipv6.dst_slaac_mac",
                FT_ETHER, BASE_NONE, NULL, 0x0,
                "Destination IPv6 Stateless Address Autoconfiguration (SLAAC) 48-bit MAC Identifier", HFILL }
        },
        { &hf_ipv6_dst_isatap_ipv4,
            { "Destination ISATAP IPv4", "ipv6.dst_isatap_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Destination IPv6 ISATAP Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_dst_6to4_gateway_ipv4,
            { "Destination 6to4 Gateway IPv4", "ipv6.dst_6to4_gw_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Destination IPv6 6to4 Gateway IPv4 Address", HFILL }
        },
        { &hf_ipv6_dst_6to4_sla_id,
            { "Destination 6to4 SLA ID", "ipv6.dst_6to4_sla_id",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Destination IPv6 6to4 SLA ID", HFILL }
        },
        { &hf_ipv6_dst_teredo_server_ipv4,
            { "Destination Teredo Server IPv4", "ipv6.dst_ts_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Destination IPv6 Teredo Server Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_dst_teredo_port,
            { "Destination Teredo Port", "ipv6.dst_tc_port",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Destination IPv6 Teredo Client Mapped Port", HFILL }
        },
        { &hf_ipv6_dst_teredo_client_ipv4,
            { "Destination Teredo Client IPv4", "ipv6.dst_tc_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Destination IPv6 Teredo Client Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_dst_embed_ipv4,
            { "Destination Embedded IPv4", "ipv6.dst_embed_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "Destination IPv4-Embedded IPv6 Address", HFILL }
        },
        { &hf_ipv6_addr,
            { "Source or Destination Address", "ipv6.addr",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_addr_space,
            { "Source or Destination Address Space", "ipv6.addr_space",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_multicast_flags,
            { "Source or Destination Address Multicast Flags", "ipv6.multicast_flags",
                FT_UINT16, BASE_HEX, NULL, 0x00F0,
                NULL, HFILL }
        },
        { &hf_ipv6_multicast_flags_transient,
            { "Source or Destination Address Transient Multicast Flag", "ipv6.multicast_flags.transient",
                FT_BOOLEAN, 16, NULL, 0x0010,
                NULL, HFILL }
        },
        { &hf_ipv6_multicast_flags_network_prefix,
            { "Source or Destination Address Network Prefix Multicast Flag", "ipv6.multicast_flags.network_prefix",
                FT_BOOLEAN, 16, NULL, 0x0020,
                NULL, HFILL }
        },
        { &hf_ipv6_multicast_flags_embed_rp,
            { "Source or Destination Address RP Multicast Flag", "ipv6.multicast_flags.embed_rp",
                FT_BOOLEAN, 16, NULL, 0x0040,
                NULL, HFILL }
        },
        { &hf_ipv6_multicast_flags_reserved,
            { "Source or Destination Address Reserved Multicast Flag", "ipv6.multicast_flags.reserved",
                FT_UINT16, BASE_DEC, NULL, 0x0080,
                NULL, HFILL }
        },
        { &hf_ipv6_multicast_scope,
            { "Source or Destination Address Multicast Scope", "ipv6.multicast_scope",
                FT_UINT16, BASE_HEX, VALS(ipv6_multicast_scope_vals), 0x000F,
                NULL, HFILL }
        },
        { &hf_ipv6_addr_special_purpose,
            { "Source or Destination Address Special-Purpose Allocation", "ipv6.addr_special_purpose",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_host,
            { "Source or Destination Host", "ipv6.host",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_slaac_mac,
            { "SLAAC MAC", "ipv6.slaac_mac",
                FT_ETHER, BASE_NONE, NULL, 0x0,
                "IPv6 Stateless Address Autoconfiguration (SLAAC) 48-bit MAC Identifier", HFILL }
        },
        { &hf_ipv6_isatap_ipv4,
            { "ISATAP IPv4", "ipv6.isatap_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "IPv6 ISATAP Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_6to4_gateway_ipv4,
            { "6to4 Gateway IPv4", "ipv6.6to4_gw_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "IPv6 6to4 Gateway IPv4 Address", HFILL }
        },
        { &hf_ipv6_6to4_sla_id,
            { "6to4 SLA ID", "ipv6.6to4_sla_id",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "IPv6 6to4 SLA ID", HFILL }
        },
        { &hf_ipv6_teredo_server_ipv4,
            { "Teredo Server IPv4", "ipv6.ts_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "IPv6 Teredo Server Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_teredo_port,
            { "Teredo Port", "ipv6.tc_port",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "IPv6 Teredo Client Mapped Port", HFILL }
        },
        { &hf_ipv6_teredo_client_ipv4,
            { "Teredo Client IPv4", "ipv6.tc_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "IPv6 Teredo Client Encapsulated IPv4 Address", HFILL }
        },
        { &hf_ipv6_embed_ipv4_prefix,
            { "Embedded IPv4 Prefix", "ipv6.embed_ipv4_prefix",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "IPv4-Embedded IPv6 Address Prefix", HFILL }
        },
        { &hf_ipv6_embed_ipv4,
            { "Embedded IPv4", "ipv6.embed_ipv4",
                FT_IPv4, BASE_NONE, NULL, 0x0,
                "IPv4-Embedded IPv6 Address", HFILL }
        },
        { &hf_ipv6_embed_ipv4_u,
            { "Embedded IPv4 u field", "ipv6.embed_ipv4_u",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "IPv4-Embedded IPv6 Address u field", HFILL }
        },
        { &hf_ipv6_embed_ipv4_suffix,
            { "Embedded IPv4 Suffix", "ipv6.embed_ipv4_suffix",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "IPv4-Embedded IPv6 Address Suffix", HFILL }
        },

        { &hf_geoip_country,
            { "Source or Destination GeoIP Country", "ipv6.geoip.country",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_country_iso,
            { "Source or Destination GeoIP ISO Two Letter Country Code", "ipv6.geoip.country_iso",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_city,
            { "Source or Destination GeoIP City", "ipv6.geoip.city",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_as_number,
            { "Source or Destination GeoIP AS Number", "ipv6.geoip.asnum",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_as_org,
            { "Source or Destination GeoIP AS Organization", "ipv6.geoip.org",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_latitude,
            { "Source or Destination GeoIP Latitude", "ipv6.geoip.lat",
                FT_DOUBLE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_longitude,
            { "Source or Destination GeoIP Longitude", "ipv6.geoip.lon",
                FT_DOUBLE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_summary,
            { "Source GeoIP", "ipv6.geoip.src_summary",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_country,
            { "Source GeoIP Country", "ipv6.geoip.src_country",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_country_iso,
            { "Source GeoIP ISO Two Letter Country Code", "ipv6.geoip.src_country_iso",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_city,
            { "Source GeoIP City", "ipv6.geoip.src_city",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_as_number,
            { "Source GeoIP AS Number", "ipv6.geoip.src_asnum",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_as_org,
            { "Source GeoIP AS Organization", "ipv6.geoip.src_org",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_latitude,
            { "Source GeoIP Latitude", "ipv6.geoip.src_lat",
                FT_DOUBLE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_src_longitude,
            { "Source GeoIP Longitude", "ipv6.geoip.src_lon",
                FT_DOUBLE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_summary,
            { "Destination GeoIP", "ipv6.geoip.dst_summary",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_country,
            { "Destination GeoIP Country", "ipv6.geoip.dst_country",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_country_iso,
            { "Destination GeoIP ISO Two Letter Country Code", "ipv6.geoip.dst_country_iso",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_city,
            { "Destination GeoIP City", "ipv6.geoip.dst_city",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_as_number,
            { "Destination GeoIP AS Number", "ipv6.geoip.dst_asnum",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_as_org,
            { "Destination GeoIP AS Organization", "ipv6.geoip.dst_org",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_latitude,
            { "Destination GeoIP Latitude", "ipv6.geoip.dst_lat",
                FT_DOUBLE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_geoip_dst_longitude,
            { "Destination GeoIP Longitude", "ipv6.geoip.dst_lon",
                FT_DOUBLE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },

        { &hf_ipv6_opt,
            { "IPv6 Option", "ipv6.opt",
                FT_NONE, BASE_NONE, NULL, 0x0,
                "Option", HFILL }
        },
        { &hf_ipv6_opt_type,
            { "Type", "ipv6.opt.type",
                FT_UINT8, BASE_HEX | BASE_EXT_STRING, &ipv6_opt_type_vals_ext, 0x0,
                "Option type", HFILL }
        },
        { &hf_ipv6_opt_type_action,
            { "Action", "ipv6.opt.type.action",
                FT_UINT8, BASE_DEC, VALS(ipv6_opt_type_action_vals), 0xC0,
                "Action for unrecognized option type", HFILL }
        },
        { &hf_ipv6_opt_type_change,
            { "May Change", "ipv6.opt.type.change",
                FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
                "Whether the option data may change en-route", HFILL }
        },
        { &hf_ipv6_opt_type_rest,
            { "Low-Order Bits", "ipv6.opt.type.rest",
                FT_UINT8, BASE_HEX, NULL, 0x1F,
                "Remaining low-order bits", HFILL }
        },
        { &hf_ipv6_opt_length,
            { "Length", "ipv6.opt.length",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Option length in octets", HFILL }
        },
        { &hf_ipv6_opt_pad1,
            { "Pad1", "ipv6.opt.pad1",
                FT_NONE, BASE_NONE, NULL, 0x0,
                "Pad1 Option", HFILL }
        },
        { &hf_ipv6_opt_padn,
            { "PadN", "ipv6.opt.padn",
                FT_BYTES, BASE_NONE|BASE_ALLOW_ZERO, NULL, 0x0,
                "PadN Option", HFILL }
        },
        { &hf_ipv6_opt_pmtu_min,
            { "Minimum Reported PMTU", "ipv6.opt.pmtu.min",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "The minimum reported PMTU in octets", HFILL }
        },
        { &hf_ipv6_opt_pmtu_rtn,
            { "Return Minimum PMTU", "ipv6.opt.pmtu.rtn",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "The Return Min-PMTU in octets", HFILL }
        },
        { &hf_ipv6_opt_pmtu_rtn_flag,
            { "Return Flag", "ipv6.opt.pmtu.r_flag",
                FT_BOOLEAN, BASE_NONE, NULL, 0x0,
                "Destination should include the received reported PMTU", HFILL }
        },
        { &hf_ipv6_opt_apn_id_type,
            { "ID Type", "ipv6.opt.apn.id.type",
                FT_UINT8, BASE_DEC, VALS(apn_id_type_strs), 0x0,
                "The type of the APN ID", HFILL }
        },
        { &hf_ipv6_opt_apn_flags,
            { "Flags", "ipv6.opt.apn.flags",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                "Flags for advanced processing", HFILL }
        },
        { &hf_ipv6_opt_apn_param_type,
            { "Parameters Types", "ipv6.opt.apn.param.type",
                FT_UINT16, BASE_HEX, NULL, 0x0,
                "Bitmap to identify the existence of APN Parameters", HFILL }
        },
        { &hf_ipv6_opt_apn_id_part1,
            { "ID Part1", "ipv6.opt.apn.id.part1",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                "The first 32-bit of the APN ID", HFILL }
        },
        { &hf_ipv6_opt_apn_id_part2,
            { "ID Part2", "ipv6.opt.apn.id.part2",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                "The second 32-bit of the APN ID", HFILL }
        },
        { &hf_ipv6_opt_apn_id_part3,
            { "ID Part3", "ipv6.opt.apn.id.part3",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                "The third 32-bit of the APN ID", HFILL }
        },
        { &hf_ipv6_opt_apn_id_part4,
            { "ID Part4", "ipv6.opt.apn.id.part4",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                "The last 32-bit of the APN ID", HFILL }
        },
        { &hf_ipv6_opt_rtalert,
            { "Router Alert", "ipv6.opt.router_alert",
                FT_UINT16, BASE_DEC, VALS(ipv6_opt_rtalert_vals), 0x0,
                "Router Alert Option", HFILL }
        },
        { &hf_ipv6_opt_tel,
            { "Tunnel Encapsulation Limit", "ipv6.opt.tel",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "How many further levels of encapsulation are permitted", HFILL }
        },
        { &hf_ipv6_opt_jumbo,
            { "Payload Length", "ipv6.opt.jumbo",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                "IPv6 (Jumbo) Payload Length", HFILL }
        },
        { &hf_ipv6_opt_calipso_doi,
            { "CALIPSO Domain of Interpretation", "ipv6.opt.calipso.doi",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_calipso_cmpt_length,
            { "Compartment Length", "ipv6.opt.calipso.cmpt.length",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_calipso_sens_level,
            { "Sensitivity Level", "ipv6.opt.calipso.sens_level",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_calipso_checksum,
            { "Checksum", "ipv6.opt.calipso.checksum",
                FT_UINT16, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_calipso_cmpt_bitmap,
            { "Compartment Bitmap", "ipv6.opt.calipso.cmpt_bitmap",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_smf_dpd_hash_bit,
            { "H-bit", "ipv6.opt.smf_dpd.hash_bit",
                FT_BOOLEAN, 8, NULL, 0x80,
                "Hash indicator", HFILL }
        },
        { &hf_ipv6_opt_smf_dpd_tid_type,
            { "TaggerID Type", "ipv6.opt.smf_dpd.tid_type",
                FT_UINT8, BASE_DEC, VALS(ipv6_opt_smf_dpd_tidty_vals), 0x70,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_smf_dpd_tid_len,
            { "TaggerID Length", "ipv6.opt.smf_dpd.tid_len",
                FT_UINT8, BASE_DEC, NULL, 0x0F,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_smf_dpd_tagger_id,
            { "TaggerID", "ipv6.opt.smf_dpd.tagger_id",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_smf_dpd_ident,
            { "Identifier", "ipv6.opt.smf_dpd.ident",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_smf_dpd_hav,
            { "Hash Assist Value", "ipv6.opt.smf_dpd.hav",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_pdm_scale_dtlr,
            { "Scale DTLR", "ipv6.opt.pdm.scale_dtlr",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Scale for Delta Time Last Received", HFILL }
        },
        { &hf_ipv6_opt_pdm_scale_dtls,
            { "Scale DTLS", "ipv6.opt.pdm.scale_dtls",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Scale for Delta Time Last Sent", HFILL }
        },
        { &hf_ipv6_opt_pdm_psn_this_pkt,
            { "PSN This Packet", "ipv6.opt.pdm.psn_this_pkt",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Packet Sequence Number This Packet", HFILL }
        },
        { &hf_ipv6_opt_pdm_psn_last_recv,
            { "PSN Last Received", "ipv6.opt.pdm.psn_last_recv",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Packet Sequence Number Last Received", HFILL }
        },
        { &hf_ipv6_opt_pdm_delta_last_recv,
            { "Delta Time Last Received", "ipv6.opt.pdm.delta_last_recv",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_pdm_delta_last_sent,
            { "Delta Time Last Sent", "ipv6.opt.pdm.delta_last_sent",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_func,
            { "Function", "ipv6.opt.qs_func",
                FT_UINT8, BASE_DEC, VALS(qs_func_vals), QS_FUNC_MASK,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_rate,
            { "Rate", "ipv6.opt.qs_rate",
                FT_UINT8, BASE_DEC | BASE_EXT_STRING, &qs_rate_vals_ext, QS_RATE_MASK,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_ttl,
            { "QS TTL", "ipv6.opt.qs_ttl",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_ttl_diff,
            { "TTL Diff", "ipv6.opt.qs_ttl_diff",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_unused,
            { "Not Used", "ipv6.opt.qs_unused",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_nonce,
            { "QS Nonce", "ipv6.opt.qs_nonce",
                FT_UINT32, BASE_HEX, NULL, 0xFFFFFFFC,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_qs_reserved,
            { "Reserved", "ipv6.opt.qs_reserved",
                FT_UINT32, BASE_HEX, NULL, 0x0003,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_rsv,
            { "Reserved", "ipv6.opt.ioam.rsv",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Reserved (must be zero)", HFILL }
        },
        { &hf_ipv6_opt_ioam_opt_type,
            { "Option-Type", "ipv6.opt.ioam.opt_type",
                FT_UINT8, BASE_DEC, VALS(ipv6_ioam_opt_types), 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_ns,
            { "Namespace ID", "ipv6.opt.ioam.trace.ns",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_nodelen,
            { "Node Length", "ipv6.opt.ioam.trace.nodelen",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_flags,
            { "Flags", "ipv6.opt.ioam.trace.flags",
                FT_UINT16, BASE_HEX, NULL, 0x0780,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_flag_o,
            { "Overflow", "ipv6.opt.ioam.trace.flag.o",
                FT_BOOLEAN, 16, NULL, 0x0400,
                "Not enough free space", HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_flag_l,
            { "Loopback", "ipv6.opt.ioam.trace.flag.l",
                FT_BOOLEAN, 16, NULL, 0x0200,
                "Send a copy of the packet back towards the source", HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_flag_a,
            { "Active", "ipv6.opt.ioam.trace.flag.a",
                FT_BOOLEAN, 16, NULL, 0x0100,
                "Active measurement packet", HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_flag_rsv,
            { "Reserved", "ipv6.opt.ioam.trace.flag.rsv",
                FT_BOOLEAN, 16, NULL, 0x0080,
                "Reserved (must be zero)", HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_remlen,
            { "Remaining Length", "ipv6.opt.ioam.trace.remlen",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type,
            { "Trace Type", "ipv6.opt.ioam.trace.type",
                FT_UINT24, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit0,
            { "Hop_Lim and Node ID (short)", "ipv6.opt.ioam.trace.type.bit0",
                FT_BOOLEAN, 24, NULL, 0x800000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit1,
            { "Ingress and Egress IDs (short)", "ipv6.opt.ioam.trace.type.bit1",
                FT_BOOLEAN, 24, NULL, 0x400000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit2,
            { "Timestamp seconds", "ipv6.opt.ioam.trace.type.bit2",
                FT_BOOLEAN, 24, NULL, 0x200000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit3,
            { "Timestamp fraction", "ipv6.opt.ioam.trace.type.bit3",
                FT_BOOLEAN, 24, NULL, 0x100000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit4,
            { "Transit delay", "ipv6.opt.ioam.trace.type.bit4",
                FT_BOOLEAN, 24, NULL, 0x080000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit5,
            { "IOAM-Namespace specific data (short)", "ipv6.opt.ioam.trace.type.bit5",
                FT_BOOLEAN, 24, NULL, 0x040000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit6,
            { "Queue depth", "ipv6.opt.ioam.trace.type.bit6",
                FT_BOOLEAN, 24, NULL, 0x020000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit7,
            { "Checksum complement", "ipv6.opt.ioam.trace.type.bit7",
                FT_BOOLEAN, 24, NULL, 0x010000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit8,
            { "Hop_Lim and Node ID (wide)", "ipv6.opt.ioam.trace.type.bit8",
                FT_BOOLEAN, 24, NULL, 0x008000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit9,
            { "Ingress and Egress IDs (wide)", "ipv6.opt.ioam.trace.type.bit9",
                FT_BOOLEAN, 24, NULL, 0x004000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit10,
            { "IOAM-Namespace specific data (wide)", "ipv6.opt.ioam.trace.type.bit10",
                FT_BOOLEAN, 24, NULL, 0x002000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit11,
            { "Buffer occupancy", "ipv6.opt.ioam.trace.type.bit11",
                FT_BOOLEAN, 24, NULL, 0x001000,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_undef,
            { "Undefined", "ipv6.opt.ioam.trace.type.undef",
                FT_BOOLEAN, 24, NULL, 0x000ffc,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_bit22,
            { "Opaque State Snapshot", "ipv6.opt.ioam.trace.type.bit22",
                FT_BOOLEAN, 24, NULL, 0x000002,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_type_rsv,
            { "Reserved", "ipv6.opt.ioam.trace.type.rsv",
                FT_BOOLEAN, 24, NULL, 0x000001,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_rsv,
            { "Reserved", "ipv6.opt.ioam.trace.rsv",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Reserved (must be zero)", HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_free_space,
            { "Free space", "ipv6.opt.ioam.trace.free_space",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_hlim,
            { "Hop Limit", "ipv6.opt.ioam.trace.node.hlim",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_id,
            { "ID", "ipv6.opt.ioam.trace.node.id",
                FT_UINT24, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_iif,
            { "Ingress ID", "ipv6.opt.ioam.trace.node.iif",
                FT_UINT16, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_eif,
            { "Egress ID", "ipv6.opt.ioam.trace.node.eif",
                FT_UINT16, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_tss,
            { "Timestamp Seconds", "ipv6.opt.ioam.trace.node.tss",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_tsf,
            { "Timestamp Fraction", "ipv6.opt.ioam.trace.node.tsf",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_trdelay,
            { "Transit Delay", "ipv6.opt.ioam.trace.node.trdelay",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_nsdata,
            { "Namespace Data (short)", "ipv6.opt.ioam.trace.node.nsdata",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_qdepth,
            { "Queue Depth", "ipv6.opt.ioam.trace.node.qdepth",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_csum,
            { "Checksum Complement", "ipv6.opt.ioam.trace.node.csum",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_id_wide,
            { "ID", "ipv6.opt.ioam.trace.node.id_wide",
                FT_UINT56, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_iif_wide,
            { "Ingress ID", "ipv6.opt.ioam.trace.node.iif_wide",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_eif_wide,
            { "Egress ID", "ipv6.opt.ioam.trace.node.eif_wide",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_nsdata_wide,
            { "Namespace Data (wide)", "ipv6.opt.ioam.trace.node.nsdata_wide",
                FT_UINT64, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_bufoccup,
            { "Buffer Occupancy", "ipv6.opt.ioam.trace.node.bufoccup",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_undefined,
            { "Undefined bit", "ipv6.opt.ioam.trace.node.undefined",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_oss_len,
            { "Length", "ipv6.opt.ioam.trace.node.oss.len",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_oss_scid,
            { "Schema ID", "ipv6.opt.ioam.trace.node.oss.scid",
                FT_UINT24, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_ioam_trace_node_oss_data,
            { "Data", "ipv6.opt.ioam.trace.node.oss.data",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_tpf_information,
            { "TPF Information", "ipv6.opt.tpf_information",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                "Tunnel Payload Forwarding Information", HFILL }
        },
        { &hf_ipv6_opt_mipv6_home_address,
            { "MIPv6 Home Address", "ipv6.opt.mipv6.home_address",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_rpl_flag,
            { "Flag", "ipv6.opt.rpl.flag",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_rpl_flag_o,
            { "Down", "ipv6.opt.rpl.flag.o",
                FT_BOOLEAN, 8, NULL, 0x80,
                "The packet is expected to progress Up or Down", HFILL }
        },
        { &hf_ipv6_opt_rpl_flag_r,
            { "Rank Error", "ipv6.opt.rpl.flag.r",
                FT_BOOLEAN, 8, NULL, 0x40,
                "Whether a rank error was detected", HFILL }
        },
        { &hf_ipv6_opt_rpl_flag_f,
            { "Forwarding Error", "ipv6.opt.rpl.flag.f",
                FT_BOOLEAN, 8, NULL, 0x20,
                "Set if the node cannot forward the packet further towards the destination", HFILL }
        },
        { &hf_ipv6_opt_rpl_flag_rsv,
            { "Reserved", "ipv6.opt.rpl.flag.rsv",
                FT_UINT8, BASE_HEX, NULL, 0x1F,
                "Reserved (must be zero)", HFILL }
        },
        { &hf_ipv6_opt_rpl_instance_id,
            { "RPLInstanceID", "ipv6.opt.rpl.instance_id",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                "The DODAG instance along which the packet is sent", HFILL }
        },
        { &hf_ipv6_opt_rpl_senderrank,
            { "Sender Rank", "ipv6.opt.rpl.sender_rank",
                FT_UINT16, BASE_HEX, NULL, 0x0,
                "Set to zero by the source and to DAGRank(rank) by a router that forwards inside the RPL network", HFILL }
        },
        { &hf_ipv6_opt_ilnp_nonce,
            { "ILNP Nonce", "ipv6.opt.ilnp_nonce",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_lio_len,
            { "LineIDLen", "ipv6.opt.lio.length",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_lio_id,
            { "Line ID", "ipv6.opt.lio.line_id",
                FT_STRING, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_mpl_flag,
            { "Flag", "ipv6.opt.mpl.flag",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_mpl_flag_s,
            { "Seed ID Length", "ipv6.opt.mpl.flag.s",
                FT_UINT8, BASE_DEC, VALS(mpl_seed_id_len_vals), 0xC0,
                "Identifies the length of Seed ID", HFILL }
        },
        { &hf_ipv6_opt_mpl_flag_m,
            { "Largest Sequence", "ipv6.opt.mpl.flag.m",
                FT_BOOLEAN, 8, NULL, 0x20,
                "Indicates Sequence is known to be the largest sequence number", HFILL }
        },
        { &hf_ipv6_opt_mpl_flag_v,
            { "Version", "ipv6.opt.mpl.flag.v",
                FT_BOOLEAN, 8, NULL, 0x10,
                "0 indicates this option conforms to RFC<TBC>", HFILL }
        },
        { &hf_ipv6_opt_mpl_flag_rsv,
            { "Reserved", "ipv6.opt.mpl.flag.rsv",
                FT_UINT8, BASE_HEX, NULL, 0x0F,
                "Reserved (must be zero)", HFILL }
        },
        { &hf_ipv6_opt_mpl_sequence,
            { "Sequence", "ipv6.opt.mpl.sequence",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                "Identifies relative ordering of MPL Data Messages from the MPL Seed identified by Seed ID", HFILL }
        },
        { &hf_ipv6_opt_mpl_seed_id,
            { "Seed ID", "ipv6.opt.mpl.seed_id",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "Uniquely identifies the MPL Seed that initiated dissemination of the MPL Data Message", HFILL }
        },
        { &hf_ipv6_opt_dff_flags,
            { "Flags", "ipv6.opt.dff.flags",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_dff_flag_ver,
            { "Version (VER)", "ipv6.opt.dff.flag.ver",
                FT_UINT8, BASE_DEC, NULL, 0xC0,
                "The version of DFF that is used", HFILL }
        },
        { &hf_ipv6_opt_dff_flag_dup,
            { "Duplicate (DUP)", "ipv6.opt.dff.flag.dup",
                FT_BOOLEAN, 8, NULL, 0x20,
                "Indicates the packet is being retransmitted", HFILL }
        },
        { &hf_ipv6_opt_dff_flag_ret,
            { "Return (RET)", "ipv6.opt.dff.flag.ret",
                FT_BOOLEAN, 8, NULL, 0x10,
                "Must be set to 1 prior to sending the packet back to the Previous Hop", HFILL }
        },
        { &hf_ipv6_opt_dff_flag_rsv,
            { "Reserved", "ipv6.opt.dff.flag.rsv",
                FT_UINT8, BASE_HEX, NULL, 0x0F,
                "Reserved (must be zero)", HFILL }
        },
        { &hf_ipv6_opt_dff_seqnum,
            { "Sequence Number", "ipv6.opt.dff.sequence_number",
                FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_experimental,
            { "Experimental Option", "ipv6.opt.experimental",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_opt_unknown_data,
            { "Unknown Data", "ipv6.opt_unknown_data",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "Not interpreted data", HFILL }
        },
        { &hf_ipv6_opt_unknown,
            { "Unknown Option Payload", "ipv6.opt.unknown",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_fragment,
            { "IPv6 Fragment", "ipv6.fragment",
                FT_FRAMENUM, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_fragment_overlap,
            { "Fragment overlap", "ipv6.fragment.overlap",
                FT_BOOLEAN, BASE_NONE, NULL, 0x0,
                "Fragment overlaps with other fragments", HFILL }
        },
        { &hf_ipv6_fragment_overlap_conflict,
            { "Conflicting data in fragment overlap", "ipv6.fragment.overlap.conflict",
                FT_BOOLEAN, BASE_NONE, NULL, 0x0,
                "Overlapping fragments contained conflicting data", HFILL }
        },
        { &hf_ipv6_fragment_multiple_tails,
            { "Multiple tail fragments found", "ipv6.fragment.multipletails",
                FT_BOOLEAN, BASE_NONE, NULL, 0x0,
                "Several tails were found when defragmenting the packet", HFILL }
        },
        { &hf_ipv6_fragment_too_long_fragment,
            { "Fragment too long", "ipv6.fragment.toolongfragment",
                FT_BOOLEAN, BASE_NONE, NULL, 0x0,
                "Fragment contained data past end of packet", HFILL }
        },
        { &hf_ipv6_fragment_error,
            { "Defragmentation error", "ipv6.fragment.error",
                FT_FRAMENUM, BASE_NONE, NULL, 0x0,
                "Defragmentation error due to illegal fragments", HFILL }
        },
        { &hf_ipv6_fragment_count,
            { "Fragment count", "ipv6.fragment.count",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_fragments,
            { "IPv6 Fragments", "ipv6.fragments",
                FT_NONE, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_reassembled_in,
            { "Reassembled IPv6 in frame", "ipv6.reassembled.in",
                FT_FRAMENUM, BASE_NONE, NULL, 0x0,
                "This IPv6 packet is reassembled in this frame", HFILL }
        },
        { &hf_ipv6_reassembled_length,
            { "Reassembled IPv6 length", "ipv6.reassembled.length",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                "The total length of the reassembled payload", HFILL }
        },
        { &hf_ipv6_reassembled_data,
            { "Reassembled IPv6 data", "ipv6.reassembled.data",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "The reassembled payload", HFILL }
        }
    };

    static hf_register_info hf_ipv6_hopopts[] = {
        { &hf_ipv6_hopopts_nxt,
            { "Next Header", "ipv6.hopopts.nxt",
                FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_hopopts_len,
            { "Length", "ipv6.hopopts.len",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Extension header length in 8-octet words (minus 1)", HFILL }
        },
        { &hf_ipv6_hopopts_len_oct,
            { "Length", "ipv6.hopopts.len_oct",
                FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
                "Extension header length in octets", HFILL }
        }
    };

    static hf_register_info hf_ipv6_dstopts[] = {
        { &hf_ipv6_dstopts_nxt,
            { "Next Header", "ipv6.dstopts.nxt",
                FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_dstopts_len,
            { "Length", "ipv6.dstopts.len",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Extension header length in 8-octet words (minus 1)", HFILL }
        },
        { &hf_ipv6_dstopts_len_oct,
            { "Length", "ipv6.dstopts.len_oct",
                FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
                "Extension header length in octets", HFILL }
        }
    };

    static hf_register_info hf_ipv6_routing[] = {

        /* IPv6 Routing Header */
        { &hf_ipv6_routing_nxt,
            { "Next Header", "ipv6.routing.nxt",
                FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_routing_len,
            { "Length", "ipv6.routing.len",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Extension header length in 8-octet words (minus 1)", HFILL }
        },
        { &hf_ipv6_routing_len_oct,
            { "Length", "ipv6.routing.len_oct",
                FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
                "Extension header length in octets", HFILL }
        },
        { &hf_ipv6_routing_type,
            { "Type", "ipv6.routing.type",
                FT_UINT8, BASE_DEC, VALS(routing_header_type), 0x0,
                "Routing Header Type", HFILL }
        },
        { &hf_ipv6_routing_segleft,
            { "Segments Left", "ipv6.routing.segleft",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Routing Header Segments Left", HFILL }
        },
        { &hf_ipv6_routing_unknown_data,
            { "Type-Specific Data", "ipv6.routing.unknown_data",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "Unknown routing header type-specific data", HFILL }
        },

        /* Source Routing Header */
        { &hf_ipv6_routing_src_reserved,
            { "Reserved", "ipv6.routing.src.reserved",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "Must be zero", HFILL }
        },
        { &hf_ipv6_routing_src_addr,
            { "Address", "ipv6.routing.src.addr",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                "Source Routing Header Address", HFILL }},

        /* Mobile IPv6 */
        { &hf_ipv6_routing_mipv6_reserved,
            { "Reserved", "ipv6.routing.mipv6.reserved",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "Must be zero", HFILL }
        },
        { &hf_ipv6_routing_mipv6_home_address,
            { "Home Address", "ipv6.routing.mipv6.home_address",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                NULL, HFILL }
        },

        /* RPL Routing Header */
        { &hf_ipv6_routing_rpl_cmprI,
            { "Compressed Internal Octets (CmprI)", "ipv6.routing.rpl.cmprI",
                FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_CMPRI,
                "Elided octets from all but last segment", HFILL }
        },
        { &hf_ipv6_routing_rpl_cmprE,
            { "Compressed Final Octets (CmprE)", "ipv6.routing.rpl.cmprE",
                FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_CMPRE,
                "Elided octets from last segment address", HFILL }
        },
        { &hf_ipv6_routing_rpl_pad,
            { "Padding Bytes", "ipv6.routing.rpl.pad",
                FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_PAD,
                NULL, HFILL }
        },
        { &hf_ipv6_routing_rpl_reserved,
            { "Reserved", "ipv6.routing.rpl.reserved",
                FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_RESERVED,
                "Must be zero", HFILL }
        },
        { &hf_ipv6_routing_rpl_addr_count,
            { "Total Address Count", "ipv6.routing.rpl.addr_count",
                FT_INT32, BASE_DEC, NULL, 0,
                NULL, HFILL }
        },
        { &hf_ipv6_routing_rpl_addr,
            { "Address", "ipv6.routing.rpl.address",
                FT_BYTES, BASE_NONE, NULL, 0,
                NULL, HFILL }
        },
        { &hf_ipv6_routing_rpl_fulladdr,
            { "Full Address", "ipv6.routing.rpl.full_address",
                FT_IPv6, BASE_NONE, NULL, 0,
                "Uncompressed IPv6 Address", HFILL }
        },

        /* Segment Routing Header */
        { &hf_ipv6_routing_srh_last_entry,
            { "Last Entry", "ipv6.routing.srh.last_entry",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                "Index (zero based) of the last element of the Segment List", HFILL }
        },
        { &hf_ipv6_routing_srh_flags,
            { "Flags", "ipv6.routing.srh.flags",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                "Unused, 8 bits of flags", HFILL }
        },
        { &hf_ipv6_routing_srh_tag,
            { "Tag", "ipv6.routing.srh.tag",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                "Tag a packet as part of a class or group of packets", HFILL }
        },
        { &hf_ipv6_routing_srh_addr,
            { "Address", "ipv6.routing.srh.addr",
                FT_IPv6, BASE_NONE, NULL, 0x0,
                "Segment address", HFILL }
        },

        /* Compact Routing Header */
        { &hf_ipv6_routing_crh16_current_sid,
            { "Current SID", "ipv6.routing.crh16.current_sid",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Value of the current Segment ID", HFILL }
        },
        { &hf_ipv6_routing_crh32_current_sid,
            { "Current SID", "ipv6.routing.crh32.current_sid",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                "Value of the current Segment ID", HFILL }
        },
        { &hf_ipv6_routing_crh16_segment_id,
            { "Segment ID", "ipv6.routing.crh16.sid",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                "Segment address", HFILL }
        },
        { &hf_ipv6_routing_crh32_segment_id,
            { "Segment ID", "ipv6.routing.crh32.sid",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                "Segment address", HFILL }
        }
    };

    static hf_register_info hf_ipv6_fraghdr[] = {
        { &hf_ipv6_fraghdr_nxt,
            { "Next header", "ipv6.fraghdr.nxt",
                FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
                NULL, HFILL }
        },
        { &hf_ipv6_fraghdr_reserved_octet,
            { "Reserved octet", "ipv6.fraghdr.reserved_octet",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                "Should always be 0", HFILL }
        },
        { &hf_ipv6_fraghdr_offset,
            { "Offset", "ipv6.fraghdr.offset",
                FT_UINT16, BASE_DEC, NULL, IP6F_OFF_MASK,
                "Fragment Offset", HFILL }
        },
        { &hf_ipv6_fraghdr_reserved_bits,
            { "Reserved bits", "ipv6.fraghdr.reserved_bits",
                FT_UINT16, BASE_DEC, NULL, IP6F_RESERVED_MASK,
                NULL, HFILL }
        },
        { &hf_ipv6_fraghdr_more,
            { "More Fragments", "ipv6.fraghdr.more",
                FT_BOOLEAN, 16, TFS(&tfs_yes_no), IP6F_MORE_FRAG,
                NULL, HFILL }
        },
        { &hf_ipv6_fraghdr_ident,
            { "Identification", "ipv6.fraghdr.ident",
                FT_UINT32, BASE_HEX, NULL, 0x0,
                "Fragment Identification", HFILL }
        }
    };

    static gint *ett_ipv6[] = {
        &ett_ipv6_proto,
        &ett_ipv6_detail,
        &ett_ipv6_multicast_flags,
        &ett_ipv6_traffic_class,
        &ett_geoip_info,
        &ett_ipv6_opt,
        &ett_ipv6_opt_type,
        &ett_ipv6_opt_rpl,
        &ett_ipv6_opt_mpl,
        &ett_ipv6_opt_dff_flags,
        &ett_ipv6_opt_ioam_trace_flags,
        &ett_ipv6_opt_ioam_trace_types,
        &ett_ipv6_fragment,
        &ett_ipv6_fragments
    };

    static gint *ett_ipv6_hopopts[] = {
        &ett_ipv6_hopopts_proto
    };

    static gint *ett_ipv6_routing[] = {
        &ett_ipv6_routing_proto,
        &ett_ipv6_routing_srh_vect
    };

    static gint *ett_ipv6_fraghdr[] = {
        &ett_ipv6_fraghdr_proto
    };

    static gint *ett_ipv6_dstopts[] = {
        &ett_ipv6_dstopts_proto
    };

    static ei_register_info ei_ipv6[] = {
        { &ei_ipv6_opt_jumbo_missing,
            { "ipv6.opt.jumbo.missing", PI_MALFORMED, PI_ERROR,
                "IPv6 payload length equals 0 and Hop-By-Hop present and Jumbo Payload option missing", EXPFILL }
        },
        { &ei_ipv6_opt_jumbo_prohibited,
            { "ipv6.opt.jumbo.prohibited", PI_PROTOCOL, PI_WARN,
                "When IPv6 payload length does not equal 0 a Jumbo Payload option must not be present", EXPFILL }
        },
        { &ei_ipv6_opt_jumbo_truncated,
            { "ipv6.opt.jumbo.truncated", PI_PROTOCOL, PI_WARN,
                "Jumbo Payload option present and jumbo length < 65536", EXPFILL }
        },
        { &ei_ipv6_opt_jumbo_fragment,
            { "ipv6.opt.jumbo.fragment", PI_PROTOCOL, PI_WARN,
                "Jumbo Payload option cannot be used with a fragment header", EXPFILL }
        },
        { &ei_ipv6_opt_invalid_len,
            { "ipv6.opt.invalid_len", PI_MALFORMED, PI_ERROR,
                "Invalid IPv6 option length", EXPFILL }
        },
        { &ei_ipv6_opt_apn_invalid_id_type,
            { "ipv6.opt.apn.invalid.id_type", PI_MALFORMED, PI_ERROR,
                "Invalid APN ID Type", EXPFILL }
        },
        { &ei_ipv6_opt_unknown_data,
            { "ipv6.opt.unknown_data.expert", PI_UNDECODED, PI_NOTE,
                "Unknown Data (not interpreted)", EXPFILL }
        },
        { &ei_ipv6_plen_exceeds_framing,
            { "ipv6.plen_exceeds_framing", PI_PROTOCOL, PI_WARN,
                "IPv6 payload length does not match expected framing length", EXPFILL }
        },
        { &ei_ipv6_plen_zero,
            { "ipv6.plen_zero", PI_PROTOCOL, PI_CHAT,
                "IPv6 payload length equals 0 (maybe because of \"TCP segmentation offload\" (TSO))", EXPFILL }
        },
        { &ei_ipv6_bogus_ipv6_version,
            { "ipv6.bogus_ipv6_version", PI_MALFORMED, PI_ERROR,
                "Bogus IP version", EXPFILL }
            },
        { &ei_ipv6_invalid_header,
            { "ipv6.invalid_header", PI_MALFORMED, PI_ERROR,
                "Invalid IPv6 header", EXPFILL }
        },
        { &ei_ipv6_opt_header_mismatch,
            { "ipv6.opt.header_mismatch", PI_PROTOCOL, PI_WARN,
                "Wrong options extension header for type", EXPFILL }
        },
        { &ei_ipv6_opt_deprecated,
            { "ipv6.opt.deprecated", PI_DEPRECATED, PI_NOTE,
                "Option type is deprecated", EXPFILL }
        },
        { &ei_ipv6_opt_mpl_ipv6_src_seed_id,
            { "ipv6.opt.mpl.ipv6_src_seed_id", PI_PROTOCOL, PI_COMMENT,
                "Seed ID is the IPv6 Source Address", EXPFILL }
        },
        { &ei_ipv6_opt_ioam_invalid_nodelen,
            { "ipv6.opt.ioam.trace.invalid_nodelen", PI_PROTOCOL, PI_ERROR,
                "Invalid \"NodeLen\" value: cannot be 0", EXPFILL }
        },
        { &ei_ipv6_opt_ioam_invalid_remlen,
            { "ipv6.opt.ioam.trace.invalid_remlen", PI_PROTOCOL, PI_ERROR,
                "Invalid \"RemLen\" value", EXPFILL }
        },
        { &ei_ipv6_opt_ioam_invalid_trace_type,
            { "ipv6.opt.ioam.trace.invalid_type", PI_PROTOCOL, PI_ERROR,
                "Mismatch between Trace Type and NodeLen", EXPFILL }
        },
        { &ei_ipv6_embed_ipv4_u_value,
            { "ipv6.embed_ipv4.u.nonzero", PI_PROTOCOL, PI_WARN,
                "IPv4-Embedded IPv6 address bit 64 to 71 must be zero", EXPFILL }
        },
        { &ei_ipv6_dst_addr_not_unspecified,
            { "ipv6.addr.not_unspecified", PI_PROTOCOL, PI_WARN,
                "Unspecified address cannot appear as a destination", EXPFILL }
        }
    };

    static ei_register_info ei_ipv6_hopopts[] = {
        { &ei_ipv6_hopopts_not_first,
            { "ipv6.hopopts.not_first", PI_PROTOCOL, PI_ERROR,
                "IPv6 Hop-by-Hop extension header must appear immediately after IPv6 header", EXPFILL }
        }
    };

    static ei_register_info ei_ipv6_routing[] = {
        { &ei_ipv6_src_addr_not_multicast,
            { "ipv6.src_addr.not_multicast", PI_PROTOCOL, PI_WARN,
                "Source address must not be a multicast address", EXPFILL }
        },
        { &ei_ipv6_dst_addr_not_multicast,
            { "ipv6.dst_addr.not_multicast", PI_PROTOCOL, PI_WARN,
                "Destination address must not be a multicast address", EXPFILL }
        },
        { &ei_ipv6_src_route_list_mult_inst_same_addr,
            { "ipv6.src_route_list.mult_inst_same_addr", PI_PROTOCOL, PI_WARN,
                "Multiple instances of the same address must not appear in the source route list", EXPFILL }
        },
        { &ei_ipv6_src_route_list_src_addr,
            { "ipv6.src_route_list.src_addr", PI_PROTOCOL, PI_WARN,
                "Source address must not appear in the source route list", EXPFILL }
        },
        { &ei_ipv6_src_route_list_dst_addr,
            { "ipv6.src_route_list.dst_addr", PI_PROTOCOL, PI_WARN,
                "Destination address must not appear in the source route list", EXPFILL }
        },
        { &ei_ipv6_src_route_list_multicast_addr,
            { "ipv6.src_route_list.multicast_addr", PI_PROTOCOL, PI_WARN,
                "Multicast addresses must not appear in the source route list", EXPFILL }
        },
        { &ei_ipv6_routing_rpl_cmpri_cmpre_pad,
            { "ipv6.routing.rpl.cmprI_cmprE_pad", PI_PROTOCOL, PI_WARN,
                "When cmprI equals 0 and cmprE equals 0, pad MUST equal 0 but instead was X", EXPFILL }
        },
        { &ei_ipv6_routing_rpl_addr_count_ge0,
            { "ipv6.routing.rpl.addr_count_ge0", PI_MALFORMED, PI_ERROR,
                "Calculated total address count must be greater than or equal to 0, instead was X", EXPFILL }
        },
        { &ei_ipv6_routing_rpl_reserved,
            { "ipv6.routing.rpl.reserved_not0", PI_PROTOCOL, PI_NOTE,
                "Reserved field must equal 0 but instead was X", EXPFILL }
        },
        { &ei_ipv6_routing_invalid_length,
            { "ipv6.routing.invalid_length", PI_MALFORMED, PI_ERROR,
                "Invalid IPv6 Routing header length", EXPFILL }
            },
        { &ei_ipv6_routing_invalid_segleft,
            { "ipv6.routing.invalid_segleft", PI_PROTOCOL, PI_WARN,
                "IPv6 Routing Header segments left field must not exceed address count", EXPFILL }
        },
        { &ei_ipv6_routing_undecoded,
            { "ipv6.routing.undecoded", PI_UNDECODED, PI_NOTE,
                "Undecoded IPv6 routing header field", EXPFILL }
        },
        { &ei_ipv6_routing_deprecated,
            { "ipv6.routing.deprecated", PI_DEPRECATED, PI_NOTE,
                "Routing header type is deprecated", EXPFILL }
        }
    };

    /* Decode As handling */
    static build_valid_func ipv6_da_build_value[1] = {ipv6_value};
    static decode_as_value_t ipv6_da_values = {ipv6_prompt, 1, ipv6_da_build_value};

    static decode_as_t ipv6_da = {"ipv6", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
                                  decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};

    static decode_as_t ipv6_hopopts_da = {"ipv6.hopopts", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
                                  decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};

    static decode_as_t ipv6_routing_da = {"ipv6.routing", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
                                  decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};

    static decode_as_t ipv6_fraghdr_da = {"ipv6.fraghdr", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
                                  decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};

    static decode_as_t ipv6_dstopts_da = {"ipv6.dstopts", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
                                  decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};

    module_t *ipv6_module;
    expert_module_t* expert_ipv6;
    expert_module_t* expert_ipv6_hopopts;
    expert_module_t* expert_ipv6_routing;

    proto_ipv6 = proto_register_protocol("Internet Protocol Version 6", "IPv6", "ipv6");
    proto_register_field_array(proto_ipv6, hf_ipv6, array_length(hf_ipv6));
    proto_register_subtree_array(ett_ipv6, array_length(ett_ipv6));
    expert_ipv6 = expert_register_protocol(proto_ipv6);
    expert_register_field_array(expert_ipv6, ei_ipv6, array_length(ei_ipv6));

    proto_ipv6_hopopts = proto_register_protocol("IPv6 Hop-by-Hop Option", "IPv6 Hop-by-Hop", "ipv6.hopopts");
    proto_register_field_array(proto_ipv6_hopopts, hf_ipv6_hopopts, array_length(hf_ipv6_hopopts));
    proto_register_subtree_array(ett_ipv6_hopopts, array_length(ett_ipv6_hopopts));
    expert_ipv6_hopopts = expert_register_protocol(proto_ipv6_hopopts);
    expert_register_field_array(expert_ipv6_hopopts, ei_ipv6_hopopts, array_length(ei_ipv6_hopopts));

    proto_ipv6_routing = proto_register_protocol("Routing Header for IPv6", "IPv6 Routing", "ipv6.routing");
    proto_register_field_array(proto_ipv6_routing, hf_ipv6_routing, array_length(hf_ipv6_routing));
    proto_register_subtree_array(ett_ipv6_routing, array_length(ett_ipv6_routing));
    expert_ipv6_routing = expert_register_protocol(proto_ipv6_routing);
    expert_register_field_array(expert_ipv6_routing, ei_ipv6_routing, array_length(ei_ipv6_routing));

    ipv6_routing_dissector_table = register_dissector_table("ipv6.routing.type", "IPv6 Routing Type",
                                                proto_ipv6_routing, FT_UINT8, BASE_DEC);

    proto_ipv6_routing_rt0 = proto_register_protocol_in_name_only("IPv6 Routing Type - Source Route", "Source Route", "ipv6.routing.type.rt0", proto_ipv6, FT_BYTES);
    proto_ipv6_routing_mipv6 = proto_register_protocol_in_name_only("IPv6 Routing Type - Type 2", "Type 2", "ipv6.routing.type.mipv6", proto_ipv6, FT_BYTES);
    proto_ipv6_routing_rpl = proto_register_protocol_in_name_only("IPv6 Routing Type - RPL Source Route", "RPL Source Route", "ipv6.routing.type.mipv6", proto_ipv6, FT_BYTES);
    proto_ipv6_routing_srh = proto_register_protocol_in_name_only("IPv6 Routing Types - Segment Routing", "Segment Routing", "ipv6.routing.type.srh", proto_ipv6, FT_BYTES);
    proto_ipv6_routing_crh = proto_register_protocol_in_name_only("IPv6 Routing Types - Compact Routing", "Compact Routing", "ipv6.routing.type.crh", proto_ipv6, FT_BYTES);

    proto_ipv6_fraghdr = proto_register_protocol("Fragment Header for IPv6", "IPv6 Fragment", "ipv6.fraghdr");
    proto_register_field_array(proto_ipv6_fraghdr, hf_ipv6_fraghdr, array_length(hf_ipv6_fraghdr));
    proto_register_subtree_array(ett_ipv6_fraghdr, array_length(ett_ipv6_fraghdr));

    proto_ipv6_dstopts = proto_register_protocol("Destination Options for IPv6", "IPv6 Destination", "ipv6.dstopts");
    proto_register_field_array(proto_ipv6_dstopts, hf_ipv6_dstopts, array_length(hf_ipv6_dstopts));
    proto_register_subtree_array(ett_ipv6_dstopts, array_length(ett_ipv6_dstopts));

    /* Register configuration options */
    ipv6_module = prefs_register_protocol(proto_ipv6, NULL);
    prefs_register_bool_preference(ipv6_module, "defragment",
                                   "Reassemble fragmented IPv6 datagrams",
                                   "Whether fragmented IPv6 datagrams should be reassembled",
                                   &ipv6_reassemble);
    prefs_register_bool_preference(ipv6_module, "summary_in_tree",
                                   "Show IPv6 summary in protocol tree",
                                   "Whether the IPv6 summary line should be shown in the protocol tree",
                                   &ipv6_summary_in_tree);
    prefs_register_bool_preference(ipv6_module, "address_detail" ,
                                   "Show details about IPv6 addresses",
                                   "Whether to show extended information about IPv6 addresses",
                                   &ipv6_address_detail);

    prefs_register_obsolete_preference(ipv6_module, "use_geoip");

    /* RPL Strict Header Checking */
    prefs_register_bool_preference(ipv6_module, "perform_strict_rpl_srh_rfc_checking",
                                   "Perform strict checking for RPL Source Routing Headers (RFC 6554)",
                                   "Check that all RPL Source Routed packets conform to RFC 6554 and do not visit a node more than once",
                                   &g_ipv6_rpl_srh_strict_rfc_checking);

    prefs_register_bool_preference(ipv6_module, "try_heuristic_first",
                                   "Try heuristic sub-dissectors first",
                                   "Try to decode a packet using an heuristic sub-dissector before using a sub-dissector registered to a specific port",
                                   &try_heuristic_first);

    prefs_register_bool_preference(ipv6_module, "exthdr_under_root_protocol_tree",
                                   "Display IPv6 extension headers under the root protocol tree",
                                   "Whether to display IPv6 extension headers as a separate protocol or a sub-protocol of the IPv6 packet",
                                   &ipv6_exthdr_under_root);

    prefs_register_bool_preference(ipv6_module, "exthdr_hide_len_oct_field",
                                   "Use a single field for IPv6 extension header length",
                                   "If enabled the Length field in octets will be hidden",
                                   &ipv6_exthdr_hide_len_oct_field);

    prefs_register_bool_preference(ipv6_module, "tso_support",
                                    "Support packet-capture from IPv6 TSO-enabled hardware",
                                    "Whether to correct for TSO-enabled (TCP segmentation offload) hardware "
                                    "captures, such as spoofing the IPv6 packet length", &ipv6_tso_supported);

    prefs_register_static_text_preference(ipv6_module, "text_use_geoip" ,
                                   "IP geolocation settings can be changed in the Name Resolution preferences",
                                   "IP geolocation settings can be changed in the Name Resolution preferences");

    static uat_field_t nat64_uats_flds[] = {
        UAT_FLD_CSTRING_OTHER(nat64_prefix_uats, ipaddr, "NAT64 Prefix", nat64_prefix_uat_fld_ip_chk_cb, "IPv6 prefix address"),
        UAT_FLD_VS(nat64_prefix_uats, prefix_len, "Prefix length", nat64_prefix_length_vals, "IPv6 prefix address length"),
        UAT_FLD_VS(nat64_prefix_uats, prefix_wildcard_len, "Prefix wildcard length", nat64_prefix_wildcard_length_vals, "IPv6 prefix address wildcard length"),
        UAT_END_FIELDS
    };

    nat64_prefix_uat = uat_new("NAT64 Network-Specific Prefixes",
        sizeof(struct nat64_prefix_data),
        "NAT64_NSP_list",               /* filename */
        TRUE,                           /* from_profile */
        &nat64_prefix_uats,             /* data_ptr */
        &number_of_nat64_prefix,        /* numitems_ptr */
        UAT_AFFECTS_DISSECTION,
        NULL,
        nat64_prefix_copy_cb,
        NULL,
        nat64_prefix_free_cb,
        NULL,
        NULL,
        nat64_uats_flds);

    prefs_register_uat_preference(ipv6_module, "nat64_prefixes",
        "NAT64 Prefixes",
        "A list of IPv6 prefixes used for NAT64s",
        nat64_prefix_uat);

    ipv6_handle = register_dissector("ipv6", dissect_ipv6, proto_ipv6);
    reassembly_table_register(&ipv6_reassembly_table,
                          &addresses_reassembly_table_functions);
    ipv6_tap = register_tap("ipv6");

    register_decode_as(&ipv6_da);
    register_decode_as(&ipv6_hopopts_da);
    register_decode_as(&ipv6_routing_da);
    register_decode_as(&ipv6_fraghdr_da);
    register_decode_as(&ipv6_dstopts_da);

    register_conversation_table(proto_ipv6, TRUE, ipv6_conversation_packet, ipv6_endpoint_packet);
    register_conversation_filter("ipv6", "IPv6", ipv6_filter_valid, ipv6_build_filter, NULL);

    register_capture_dissector("ipv6", capture_ipv6, proto_ipv6);
}

void
proto_reg_handoff_ipv6(void)
{
    dissector_handle_t ipv6_hopopts_handle;
    dissector_handle_t ipv6_routing_handle;
    dissector_handle_t ipv6_fraghdr_handle;
    dissector_handle_t ipv6_dstopts_handle;
    capture_dissector_handle_t ipv6_cap_handle;
    capture_dissector_handle_t ipv6_ext_cap_handle;
    dissector_handle_t h;

    dissector_add_uint("ethertype", ETHERTYPE_IPv6, ipv6_handle);
    dissector_add_uint("erf.types.type", ERF_TYPE_IPV6, ipv6_handle);
    dissector_add_uint("ppp.protocol", PPP_IPV6, ipv6_handle);
    dissector_add_uint("ppp.protocol", ETHERTYPE_IPv6, ipv6_handle);
    dissector_add_uint("gre.proto", ETHERTYPE_IPv6, ipv6_handle);
    dissector_add_uint("ip.proto", IP_PROTO_IPV6, ipv6_handle);
    dissector_add_uint("null.type", BSD_AF_INET6_BSD, ipv6_handle);
    dissector_add_uint("null.type", BSD_AF_INET6_FREEBSD, ipv6_handle);
    dissector_add_uint("null.type", BSD_AF_INET6_DARWIN, ipv6_handle);
    dissector_add_uint("chdlc.protocol", ETHERTYPE_IPv6, ipv6_handle);
    dissector_add_uint("fr.nlpid", NLPID_IP6, ipv6_handle);
    dissector_add_uint("osinl.excl", NLPID_IP6, ipv6_handle);
    dissector_add_uint("x.25.spi", NLPID_IP6, ipv6_handle);
    dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_IPv6, ipv6_handle);
    dissector_add_uint("juniper.proto", JUNIPER_PROTO_IP6, ipv6_handle);
    dissector_add_uint("juniper.proto", JUNIPER_PROTO_MPLS_IP6, ipv6_handle);
    dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_IPV6, ipv6_handle);
    dissector_add_uint("mcc.proto", PW_ACH_TYPE_IPV6, ipv6_handle);
    dissector_add_uint("sflow_245.header_protocol", SFLOW_245_HEADER_IPv6, ipv6_handle);
    dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP6, ipv6_handle);
    dissector_add_uint("enc", BSD_AF_INET6_BSD, ipv6_handle);
    dissector_add_uint("vxlan.next_proto", VXLAN_IPV6, ipv6_handle);
    dissector_add_uint("nsh.next_proto", NSH_IPV6, ipv6_handle);

    dissector_add_for_decode_as_with_preference("udp.port", ipv6_handle);

    ipv6_hopopts_handle = create_dissector_handle(dissect_hopopts, proto_ipv6_hopopts);
    dissector_add_uint("ip.proto", IP_PROTO_HOPOPTS, ipv6_hopopts_handle);

    ipv6_routing_handle = create_dissector_handle(dissect_routing6, proto_ipv6_routing);
    dissector_add_uint("ip.proto", IP_PROTO_ROUTING, ipv6_routing_handle);

    ipv6_fraghdr_handle = create_dissector_handle(dissect_fraghdr, proto_ipv6_fraghdr);
    dissector_add_uint("ip.proto", IP_PROTO_FRAGMENT, ipv6_fraghdr_handle);

    ipv6_dstopts_handle = create_dissector_handle(dissect_dstopts, proto_ipv6_dstopts);
    dissector_add_uint("ip.proto", IP_PROTO_DSTOPTS, ipv6_dstopts_handle);

    ip_dissector_table = find_dissector_table("ip.proto");

    ipv6_cap_handle = find_capture_dissector("ipv6");
    capture_dissector_add_uint("ethertype", ETHERTYPE_IPv6, ipv6_cap_handle);
    capture_dissector_add_uint("enc", BSD_AF_INET6_BSD, ipv6_cap_handle);
    capture_dissector_add_uint("null.bsd", BSD_AF_INET6_BSD, ipv6_cap_handle);
    capture_dissector_add_uint("null.bsd", BSD_AF_INET6_FREEBSD, ipv6_cap_handle);
    capture_dissector_add_uint("null.bsd", BSD_AF_INET6_DARWIN, ipv6_cap_handle);
    capture_dissector_add_uint("fr.nlpid", NLPID_IP6, ipv6_cap_handle);

    ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_hopopts);
    capture_dissector_add_uint("ip.proto", IP_PROTO_HOPOPTS, ipv6_ext_cap_handle);
    ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_routing);
    capture_dissector_add_uint("ip.proto", IP_PROTO_ROUTING, ipv6_ext_cap_handle);
    ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_fraghdr);
    capture_dissector_add_uint("ip.proto", IP_PROTO_FRAGMENT, ipv6_ext_cap_handle);
    ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_dstopts);
    capture_dissector_add_uint("ip.proto", IP_PROTO_DSTOPTS, ipv6_ext_cap_handle);

    h = create_dissector_handle(dissect_routing6_rt0, proto_ipv6_routing_rt0);
    dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_SOURCE_ROUTING, h);
    h = create_dissector_handle(dissect_routing6_mipv6, proto_ipv6_routing_mipv6);
    dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_MOBILE_IP, h);
    h = create_dissector_handle(dissect_routing6_rpl, proto_ipv6_routing_rpl);
    dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_RPL, h);
    h = create_dissector_handle(dissect_routing6_srh, proto_ipv6_routing_srh);
    dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_SEGMENT_ROUTING, h);
    h = create_dissector_handle(dissect_routing6_crh, proto_ipv6_routing_crh);
    dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_COMPACT_16, h);
    dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_COMPACT_32, h);

    exported_pdu_tap = find_tap_id("IP");
}

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */