1 /* main.c - Application main entry point */
2 
3 /*
4  * Copyright (c) 2017 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <zephyr/logging/log.h>
10 LOG_MODULE_REGISTER(net_test, CONFIG_NET_IPV6_LOG_LEVEL);
11 
12 #include <zephyr/types.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <zephyr/sys/printk.h>
18 #include <zephyr/linker/sections.h>
19 #include <zephyr/random/random.h>
20 
21 #include <zephyr/ztest.h>
22 
23 #include <zephyr/net/ethernet.h>
24 #include <zephyr/net/dummy.h>
25 #include <zephyr/net_buf.h>
26 #include <zephyr/net/net_ip.h>
27 #include <zephyr/net/net_if.h>
28 
29 #define NET_LOG_ENABLED 1
30 #include "net_private.h"
31 
32 #include "ipv6.h"
33 #include "udp_internal.h"
34 
35 /* Interface 1 addresses */
36 static struct in6_addr my_addr1 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
37 					0, 0, 0, 0, 0, 0, 0, 0x1 } } };
38 
39 /* Interface 2 addresses */
40 static struct in6_addr my_addr2 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
41 					0, 0, 0, 0, 0, 0, 0, 0x2 } } };
42 
43 /* Extra address is assigned to ll_addr */
44 static struct in6_addr ll_addr = { { { 0xfe, 0x80, 0x43, 0xb8, 0, 0, 0, 0,
45 				       0, 0, 0, 0xf2, 0xaa, 0x29, 0x02,
46 				       0x04 } } };
47 
48 static struct net_linkaddr ll_addr2 = {
49 	.addr = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x02 },
50 	.len = 6,
51 };
52 
53 /* No extension header */
54 static const unsigned char ipv6_udp[] = {
55 /* IPv6 header starts here */
56 0x60, 0x00, 0x00, 0x00, 0x00, 0x36, 0x11, 0x3f, /* `....6.? */
57 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
59 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
61 /* UDP header starts here (leave checksum field empty) */
62 0xaa, 0xdc, 0xbf, 0xd7, 0x00, 0x2e, 0x00, 0x00, /* ......M. */
63 /* User data starts here and is appended in corresponding function */
64 };
65 
66 /* IPv6 hop-by-hop option in the message */
67 static const unsigned char ipv6_hbho[] = {
68 /* IPv6 header starts here */
69 0x60, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x3f, /* `....6.? */
70 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
72 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
74 /* Hop-by-hop option starts here */
75 0x11, 0x00,
76 /* RPL sub-option starts here */
77 0x63, 0x04, 0x80, 0x1e, 0x01, 0x00, /* ..c..... */
78 /* UDP header starts here (leave checksum field empty) */
79 0xaa, 0xdc, 0xbf, 0xd7, 0x00, 0x2e, 0x00, 0x00, /* ......M. */
80 /* User data starts here and is appended in corresponding function */
81 };
82 
83 /* IPv6 hop-by-hop option in the message HBHO (72 Bytes) */
84 static const unsigned char ipv6_hbho_1[] = {
85 /* IPv6 header starts here */
86 0x60, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x40,
87 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x08, 0xc0, 0xde, 0xff, 0xfe, 0x9b, 0xb4, 0x47,
89 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
91 /* Hop-by-hop option starts here */
92 0x11, 0x08,
93 /* Padding */
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 /* UDP header starts here (8 bytes) */
104 0x4e, 0x20, 0x10, 0x92, 0x00, 0x30, 0xa1, 0xc5,
105 /* User data starts here (40 bytes) */
106 0x30, 0x26, 0x02, 0x01, 0x00, 0x04, 0x06, 0x70,
107 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa0, 0x19, 0x02,
108 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00,
109 0x30, 0x0e, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06,
110 0x01, 0x02, 0x01, 0x01, 0x05, 0x00, 0x05, 0x00 };
111 
112 /* IPv6 hop-by-hop option in the message HBHO (104 Bytes) */
113 static const unsigned char ipv6_hbho_2[] = {
114 /* IPv6 header starts here */
115 0x60, 0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x40,
116 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117 0x08, 0xc0, 0xde, 0xff, 0xfe, 0x9b, 0xb4, 0x47,
118 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
120 /* Hop-by-hop option starts here */
121 0x11, 0x0c,
122 /* padding */
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 0x01, 0x04, 0x00, 0x00, 0x00, 0x00,
136 /* udp header starts here (8 bytes) */
137 0x4e, 0x20, 0x10, 0x92, 0x00, 0x30, 0xa1, 0xc5,
138 /* User data starts here (40 bytes) */
139 0x30, 0x26, 0x02, 0x01, 0x00, 0x04, 0x06, 0x70,
140 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa0, 0x19, 0x02,
141 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00,
142 0x30, 0x0e, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06,
143 0x01, 0x02, 0x01, 0x01, 0x05, 0x00, 0x05, 0x00 };
144 
145 /* IPv6 hop-by-hop option in the message HBHO (920 bytes) */
146 static const unsigned char ipv6_hbho_3[] = {
147 /* IPv6 header starts here */
148 0x60, 0x00, 0x00, 0x00, 0x03, 0xc8, 0x00, 0x40,
149 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x08, 0xc0, 0xde, 0xff, 0xfe, 0x9b, 0xb4, 0x47,
151 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
153 /* Hop-by-hop option starts here */
154 0x11, 0x72,
155 /* padding */
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x01, 0x04, 0x00, 0x00, 0x00, 0x00,
271 /* udp header starts here (8 bytes) */
272 0x4e, 0x20, 0x10, 0x92, 0x00, 0x30, 0xa1, 0xc5,
273 /* User data starts here (40 bytes) */
274 0x30, 0x26, 0x02, 0x01, 0x00, 0x04, 0x06, 0x70,
275 0x75, 0x62, 0x6c, 0x69, 0x63, 0xa0, 0x19, 0x02,
276 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00,
277 0x30, 0x0e, 0x30, 0x0c, 0x06, 0x08, 0x2b, 0x06,
278 0x01, 0x02, 0x01, 0x01, 0x05, 0x00, 0x05, 0x00
279 };
280 
281 /* IPv6 hop-by-hop option in the message */
282 static const unsigned char ipv6_hbho_frag[] = {
283 /* IPv6 header starts here */
284 0x60, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x3f, /* `....6.? */
285 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
287 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
289 /* Hop-by-hop option starts here */
290 0x2c, 0x00,
291 /* RPL sub-option starts here */
292 0x63, 0x04, 0x80, 0x1e, 0x01, 0x00, /* ..c..... */
293 /* IPv6 fragment header */
294 0x11, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
295 /* UDP header starts here (checksum is "fixed" in this example) */
296 0xaa, 0xdc, 0xbf, 0xd7, 0x00, 0x2e, 0xa2, 0x55, /* ......M. */
297 /* User data starts here and is appended in corresponding function */
298 };
299 
300 /* IPv6 hop-by-hop option in the message */
301 static const unsigned char ipv6_hbho_frag_1[] = {
302 /* IPv6 header starts here */
303 0x60, 0x00, 0x00, 0x00, 0x05, 0xb0, 0x00, 0x40
304 , 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
305 , 0x08, 0xc0, 0xde, 0xff, 0xfe, 0xc9, 0xa0, 0x4b
306 , 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00
307 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
308 /* Hop-by-hop option starts here */
309 , 0x2c, 0x80
310 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
311 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
312 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
313 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
314 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
315 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
316 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
317 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
318 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
319 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
320 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
321 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
322 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
323 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
324 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
325 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
326 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
327 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
328 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
329 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
330 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
331 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
332 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
333 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
334 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
335 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
336 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
337 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
338 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
339 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
340 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
341 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
342 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
343 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
344 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
345 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
346 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
347 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
348 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
349 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
350 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
351 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
352 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
353 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
354 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
355 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
356 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
357 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
358 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
359 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
360 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
361 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
362 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
363 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
364 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
365 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
366 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
367 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
368 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
369 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
370 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
371 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
372 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
373 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
374 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
375 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
376 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
377 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
378 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
379 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
380 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
381 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
382 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
383 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
384 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
385 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
386 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
387 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
388 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
389 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
390 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
391 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
392 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
393 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
394 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
395 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
396 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
397 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
398 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
399 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
400 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
401 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
402 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
403 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
404 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
405 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
406 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
407 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
408 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
409 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
410 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
411 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
412 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
413 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
414 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
415 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
416 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
417 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
418 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
419 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
420 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
421 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
422 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
423 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
424 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
425 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
426 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
427 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
428 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
429 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
430 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
431 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
432 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
433 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
434 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
435 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
436 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
437 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
438 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
439 /* IPv6 fragment header */
440 , 0x3a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02
441 /* ICMPv6 header and Data*/
442 , 0x80, 0x00, 0x13, 0xdf, 0x19, 0xc7, 0x19, 0xc7
443 , 0x54, 0x65, 0x73, 0x74, 0x2d, 0x67, 0x72, 0x6f
444 , 0x75, 0x70, 0x3a, 0x49, 0x50, 0x76, 0x36, 0x2e
445 , 0x49, 0x50, 0x76, 0x36, 0x2e, 0x49, 0x43, 0x4d
446 , 0x50, 0x76, 0x36, 0x2e, 0x45, 0x63, 0x68, 0x6f
447 , 0x2d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74
448 , 0x2e, 0x49, 0x50, 0x76, 0x36, 0x2d, 0x50, 0x61
449 , 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x70, 0x61, 0x79
450 , 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x69, 0x70, 0x76
451 , 0x36, 0x2d, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73
452 , 0x69, 0x6f, 0x6e, 0x2d, 0x68, 0x65, 0x61, 0x64
453 , 0x65, 0x72, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65
454 , 0x72, 0x2d, 0x68, 0x6f, 0x70, 0x2d, 0x62, 0x79
455 , 0x2d, 0x68, 0x6f, 0x70, 0x2d, 0x6f, 0x70, 0x74
456 , 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x6f, 0x70, 0x74
457 , 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x65, 0x6c, 0x65
458 , 0x6d, 0x65, 0x6e, 0x74, 0x3b, 0x54, 0x65, 0x73
459 , 0x74, 0x2d, 0x63, 0x61, 0x73, 0x65, 0x3a, 0x32
460 , 0x31, 0x33, 0x30, 0x01, 0x02, 0x03, 0x04, 0x01
461 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
462 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
463 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
464 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
465 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
466 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
467 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
468 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
469 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
470 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
471 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
472 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
473 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
474 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
475 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
476 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
477 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
478 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
479 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
480 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
481 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
482 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
483 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
484 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
485 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
486 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
487 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
488 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
489 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
490 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
491 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
492 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
493 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
494 };
495 
496 /* IPv6 hop-by-hop option in the message */
497 static const unsigned char ipv6_large_hbho[] = {
498 /* IPv6 header starts here */
499 0x60, 0x00, 0x00, 0x00, 0x05, 0xa8, 0x00, 0x40
500 , 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00
501 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
502 , 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00
503 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
504 /* Hop-by-hop option starts here */
505 , 0x3a, 0x80
506 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
507 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
508 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
509 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
510 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
511 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
512 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
513 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
514 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
515 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
516 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
517 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
518 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
519 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
520 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
521 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
522 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
523 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
524 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
525 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
526 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
527 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
528 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
529 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
530 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
531 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
532 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
533 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
534 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
535 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
536 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
537 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
538 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
539 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
540 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
541 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
542 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
543 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
544 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
545 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
546 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
547 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
548 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
549 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
550 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
551 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
552 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
553 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
554 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
555 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
556 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
557 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
558 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
559 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
560 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
561 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
562 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
563 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
564 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
565 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
566 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
567 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
568 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
569 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
570 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
571 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
572 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
573 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
574 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
575 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
576 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
577 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
578 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
579 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
580 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
581 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
582 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
583 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
584 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
585 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
586 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
587 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
588 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
589 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
590 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
591 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
592 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
593 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
594 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
595 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
596 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
597 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
598 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
599 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
600 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
601 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
602 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
603 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
604 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
605 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
606 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
607 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
608 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
609 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
610 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
611 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
612 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
613 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
614 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
615 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
616 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
617 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
618 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
619 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
620 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
621 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
622 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
623 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
624 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
625 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
626 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
627 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
628 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
629 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
630 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
631 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
632 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
633 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
634 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
635 /* ICMPv6 header and Data*/
636 , 0x80, 0x00, 0x13, 0xdf, 0x19, 0xc7, 0x19, 0xc7
637 , 0x54, 0x65, 0x73, 0x74, 0x2d, 0x67, 0x72, 0x6f
638 , 0x75, 0x70, 0x3a, 0x49, 0x50, 0x76, 0x36, 0x2e
639 , 0x49, 0x50, 0x76, 0x36, 0x2e, 0x49, 0x43, 0x4d
640 , 0x50, 0x76, 0x36, 0x2e, 0x45, 0x63, 0x68, 0x6f
641 , 0x2d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74
642 , 0x2e, 0x49, 0x50, 0x76, 0x36, 0x2d, 0x50, 0x61
643 , 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x70, 0x61, 0x79
644 , 0x6c, 0x6f, 0x61, 0x64, 0x2e, 0x69, 0x70, 0x76
645 , 0x36, 0x2d, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73
646 , 0x69, 0x6f, 0x6e, 0x2d, 0x68, 0x65, 0x61, 0x64
647 , 0x65, 0x72, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65
648 , 0x72, 0x2d, 0x68, 0x6f, 0x70, 0x2d, 0x62, 0x79
649 , 0x2d, 0x68, 0x6f, 0x70, 0x2d, 0x6f, 0x70, 0x74
650 , 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x6f, 0x70, 0x74
651 , 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x65, 0x6c, 0x65
652 , 0x6d, 0x65, 0x6e, 0x74, 0x3b, 0x54, 0x65, 0x73
653 , 0x74, 0x2d, 0x63, 0x61, 0x73, 0x65, 0x3a, 0x32
654 , 0x31, 0x33, 0x30, 0x01, 0x02, 0x03, 0x04, 0x01
655 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
656 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
657 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
658 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
659 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
660 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
661 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
662 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
663 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
664 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
665 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
666 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
667 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
668 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
669 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
670 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
671 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
672 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
673 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
674 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
675 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
676 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
677 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
678 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
679 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
680 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
681 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
682 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
683 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
684 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
685 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
686 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
687 , 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01
688 };
689 
690 static unsigned char ipv6_first_frag[] = {
691 /* IPv6 header starts here */
692 0x60, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x3f, /* `....6.? */
693 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
694 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
695 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
696 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
697 /* Hop-by-hop option starts here */
698 0x2C, 0x00,
699 /* RPL sub-option starts here */
700 0x63, 0x04, 0x80, 0x1e, 0x01, 0x00, /* ..c..... */
701 /* IPv6 fragment header */
702 0x11, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04,
703 /* UDP header starts here (checksum is "fixed" in this example) */
704 0xaa, 0xdc, 0xbf, 0xd7, 0x00, 0x2e, 0xa2, 0x55, /* ......M. */
705 /* User data starts here and is appended in corresponding function */
706 };
707 
708 static unsigned char ipv6_second_frag[] = {
709 /* IPv6 header starts here */
710 0x60, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x3f, /* `....6.? */
711 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
712 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
713 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
714 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
715 /* Hop-by-hop option starts here */
716 0x2C, 0x00,
717 /* RPL sub-option starts here */
718 0x63, 0x04, 0x80, 0x1e, 0x01, 0x00, /* ..c..... */
719 /* IPv6 fragment header */
720 0x11, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
721 };
722 
723 static unsigned char ipv6_frag_wo_hbho[] = {
724 0x60, 0x08, 0xd7, 0x22, 0x05, 0x1c, 0x3a, 0x40,
725 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
726 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
727 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
728 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
729 /* ICMPv6 header */
730 0x80, 0x00, 0xb2, 0xb2, 0x28, 0x5b, 0x00, 0x01,
731 /* Payload */
732 0x55, 0x85, 0x93, 0x5c, 0x00, 0x00, 0x00, 0x00,
733 0x72, 0xe0, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
734 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
735 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
736 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
737 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
738 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
739 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
740 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
741 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
742 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
743 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
744 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
745 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
746 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
747 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
748 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
749 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
750 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
751 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
752 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
753 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
754 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
755 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
756 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
757 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
758 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
759 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
760 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
761 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
762 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
763 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
764 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
765 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
766 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
767 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
768 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
769 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
770 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
771 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
772 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
773 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
774 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
775 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
776 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
777 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
778 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
779 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
780 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
781 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
782 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
783 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
784 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
785 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
786 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
787 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
788 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
789 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
790 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
791 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
792 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
793 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
794 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
795 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
796 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
797 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
798 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
799 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
800 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
801 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
802 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
803 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
804 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
805 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
806 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
807 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
808 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
809 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
810 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
811 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
812 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
813 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
814 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
815 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
816 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
817 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
818 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
819 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
820 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
821 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
822 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
823 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
824 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
825 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
826 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
827 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
828 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
829 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
830 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
831 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
832 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
833 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
834 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
835 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
836 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
837 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
838 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
839 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
840 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
841 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
842 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
843 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
844 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
845 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
846 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
847 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
848 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
849 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
850 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
851 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
852 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
853 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
854 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
855 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
856 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
857 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
858 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
859 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
860 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
861 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
862 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
863 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
864 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
865 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
866 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
867 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
868 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
869 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
870 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
871 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
872 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
873 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
874 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
875 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
876 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
877 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
878 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
879 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
880 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
881 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
882 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
883 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
884 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
885 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
886 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
887 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
888 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
889 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
890 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
891 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
892 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
893 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
894 0x10, 0x11, 0x12, 0x13
895 };
896 
897 static int frag_count;
898 
899 static struct net_if *iface1;
900 
901 static bool test_failed;
902 static bool test_started;
903 static bool test_complete;
904 static struct k_sem wait_data;
905 
906 static uint16_t pkt_data_len;
907 static uint16_t pkt_recv_data_len;
908 
909 #define WAIT_TIME K_SECONDS(1)
910 
911 #define ALLOC_TIMEOUT K_MSEC(500)
912 
913 struct net_if_test {
914 	uint8_t idx;
915 	uint8_t mac_addr[sizeof(struct net_eth_addr)];
916 	struct net_linkaddr ll_addr;
917 };
918 
919 enum net_test_type {
920 	NO_TEST_TYPE,
921 	IPV6_SMALL_HBHO_FRAG,
922 	IPV6_LARGE_HBHO_FRAG,
923 	IPV6_WITHOUT_HBHO_FRAG,
924 	IPV6_UDP_LOOPBACK,
925 };
926 
927 static enum net_test_type test_type = NO_TEST_TYPE;
928 
net_iface_get_mac(const struct device * dev)929 static uint8_t *net_iface_get_mac(const struct device *dev)
930 {
931 	struct net_if_test *data = dev->data;
932 
933 	if (data->mac_addr[2] == 0x00) {
934 		/* 00-00-5E-00-53-xx Documentation RFC 7042 */
935 		data->mac_addr[0] = 0x00;
936 		data->mac_addr[1] = 0x00;
937 		data->mac_addr[2] = 0x5E;
938 		data->mac_addr[3] = 0x00;
939 		data->mac_addr[4] = 0x53;
940 		data->mac_addr[5] = sys_rand8_get();
941 	}
942 
943 	memcpy(data->ll_addr.addr, data->mac_addr, sizeof(data->mac_addr));
944 	data->ll_addr.len = 6U;
945 
946 	return data->mac_addr;
947 }
948 
net_iface_init(struct net_if * iface)949 static void net_iface_init(struct net_if *iface)
950 {
951 	uint8_t *mac = net_iface_get_mac(net_if_get_device(iface));
952 
953 	net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
954 			     NET_LINK_ETHERNET);
955 }
956 
test_pkt_loopback(struct net_pkt * pkt)957 static void test_pkt_loopback(struct net_pkt *pkt)
958 {
959 	struct net_pkt *recv_pkt;
960 	uint8_t buf_ip_src[NET_IPV6_ADDR_SIZE];
961 	uint8_t buf_ip_dst[NET_IPV6_ADDR_SIZE];
962 	uint16_t buf_port_src;
963 	uint16_t buf_port_dst;
964 	int ret;
965 
966 	/* Duplicate the packet and flip the source/destination IPs and ports then
967 	 * re-insert the packets back into the same interface
968 	 */
969 	recv_pkt = net_pkt_rx_clone(pkt, K_NO_WAIT);
970 	net_pkt_set_overwrite(recv_pkt, true);
971 
972 	/* Read IPs */
973 	net_pkt_cursor_init(recv_pkt);
974 	net_pkt_skip(recv_pkt, 8);
975 	net_pkt_read(recv_pkt, buf_ip_src, sizeof(buf_ip_src));
976 	net_pkt_read(recv_pkt, buf_ip_dst, sizeof(buf_ip_dst));
977 
978 	/* Write opposite IPs */
979 	net_pkt_cursor_init(recv_pkt);
980 	net_pkt_skip(recv_pkt, 8);
981 	net_pkt_write(recv_pkt, buf_ip_dst, sizeof(buf_ip_dst));
982 	net_pkt_write(recv_pkt, buf_ip_src, sizeof(buf_ip_src));
983 
984 	if (frag_count == 1) {
985 		/* Offset is 0, flip ports of packet */
986 		net_pkt_cursor_init(recv_pkt);
987 		net_pkt_skip(recv_pkt, NET_IPV6H_LEN + NET_IPV6_FRAGH_LEN);
988 		net_pkt_read_be16(recv_pkt, &buf_port_src);
989 		net_pkt_read_be16(recv_pkt, &buf_port_dst);
990 
991 		net_pkt_cursor_init(recv_pkt);
992 		net_pkt_skip(recv_pkt, NET_IPV6H_LEN + NET_IPV6_FRAGH_LEN);
993 		net_pkt_write_be16(recv_pkt, buf_port_dst);
994 		net_pkt_write_be16(recv_pkt, buf_port_src);
995 	}
996 
997 	/* Reset position to beginning and ready packet for insertion */
998 	net_pkt_cursor_init(recv_pkt);
999 	net_pkt_set_overwrite(recv_pkt, false);
1000 	net_pkt_set_iface(recv_pkt, net_pkt_iface(pkt));
1001 
1002 	ret = net_recv_data(net_pkt_iface(recv_pkt), recv_pkt);
1003 	zassert_equal(ret, 0, "Cannot receive data (%d)", ret);
1004 }
1005 
verify_fragment(struct net_pkt * pkt)1006 static int verify_fragment(struct net_pkt *pkt)
1007 {
1008 	/* The fragment needs to have
1009 	 *  1) IPv6 header
1010 	 *  2) HBH option (if any)
1011 	 *  3) IPv6 fragment header
1012 	 *  4) UDP/ICMPv6/TCP header
1013 	 *  5) data
1014 	 */
1015 	uint16_t offset;
1016 
1017 	frag_count++;
1018 
1019 	NET_DBG("test_type %d, frag count %d", test_type, frag_count);
1020 
1021 	switch (test_type) {
1022 	case IPV6_SMALL_HBHO_FRAG:
1023 		goto small;
1024 	case IPV6_LARGE_HBHO_FRAG:
1025 		goto large;
1026 	case IPV6_WITHOUT_HBHO_FRAG:
1027 		goto without;
1028 	case IPV6_UDP_LOOPBACK:
1029 		goto udp_loopback;
1030 	default:
1031 		return 0;
1032 	}
1033 
1034 small:
1035 	if (frag_count == 1) {
1036 		/* First fragment received. Make sure that all the
1037 		 * things are correct before the fragment header.
1038 		 */
1039 		size_t total_len = net_pkt_get_len(pkt);
1040 
1041 		total_len -= sizeof(struct net_ipv6_hdr);
1042 
1043 		ipv6_first_frag[4] = total_len / 256;
1044 		ipv6_first_frag[5] = total_len -
1045 			ipv6_first_frag[4] * 256U;
1046 
1047 		if ((total_len / 256) != pkt->buffer->data[4]) {
1048 			NET_DBG("Invalid length, 1st byte");
1049 			return -EINVAL;
1050 		}
1051 
1052 		if ((total_len - pkt->buffer->data[4] * 256U) !=
1053 		    pkt->buffer->data[5]) {
1054 			NET_DBG("Invalid length, 2nd byte");
1055 			return -EINVAL;
1056 		}
1057 
1058 		offset = pkt->buffer->data[6 * 8 + 2] * 256U +
1059 			(pkt->buffer->data[6 * 8 + 3] & 0xfe);
1060 
1061 		if (offset != 0U) {
1062 			NET_DBG("Invalid offset %d", offset);
1063 			return -EINVAL;
1064 		}
1065 
1066 		if ((ipv6_first_frag[6 * 8 + 3] & 0x01) != 1) {
1067 			NET_DBG("Invalid MORE flag for first fragment");
1068 			return -EINVAL;
1069 		}
1070 
1071 		pkt_recv_data_len += total_len - 8 /* HBHO */ -
1072 			sizeof(struct net_ipv6_frag_hdr);
1073 
1074 		/* Rewrite the fragment id so that the memcmp() will not fail */
1075 		ipv6_first_frag[6 * 8 + 4] = pkt->buffer->data[6 * 8 + 4];
1076 		ipv6_first_frag[6 * 8 + 5] = pkt->buffer->data[6 * 8 + 5];
1077 		ipv6_first_frag[6 * 8 + 6] = pkt->buffer->data[6 * 8 + 6];
1078 		ipv6_first_frag[6 * 8 + 7] = pkt->buffer->data[6 * 8 + 7];
1079 
1080 		if (memcmp(pkt->buffer->data, ipv6_first_frag, 7 * 8) != 0) {
1081 			net_hexdump("received", pkt->buffer->data, 7 * 8);
1082 			NET_DBG("");
1083 			net_hexdump("expected", ipv6_first_frag, 7 * 8);
1084 
1085 			return -EINVAL;
1086 		}
1087 	}
1088 
1089 	if (frag_count == 2) {
1090 		/* Second fragment received. */
1091 		size_t total_len = net_pkt_get_len(pkt);
1092 
1093 		total_len -= sizeof(struct net_ipv6_hdr);
1094 
1095 		ipv6_second_frag[4] = total_len / 256;
1096 		ipv6_second_frag[5] = total_len -
1097 			ipv6_second_frag[4] * 256U;
1098 
1099 		if ((total_len / 256) != pkt->buffer->data[4]) {
1100 			NET_DBG("Invalid length, 1st byte");
1101 			return -EINVAL;
1102 		}
1103 
1104 		if ((total_len - pkt->buffer->data[4] * 256U) !=
1105 		    pkt->buffer->data[5]) {
1106 			NET_DBG("Invalid length, 2nd byte");
1107 			return -EINVAL;
1108 		}
1109 
1110 		offset = pkt->buffer->data[6 * 8 + 2] * 256U +
1111 			(pkt->buffer->data[6 * 8 + 3] & 0xfe);
1112 
1113 		if (offset != pkt_recv_data_len) {
1114 			NET_DBG("Invalid offset %d received %d",
1115 				offset, pkt_recv_data_len);
1116 			return -EINVAL;
1117 		}
1118 
1119 		/* Make sure the MORE flag is set correctly */
1120 		if ((pkt->buffer->data[6 * 8 + 3] & 0x01) != 0U) {
1121 			NET_DBG("Invalid MORE flag for second fragment");
1122 			return -EINVAL;
1123 		}
1124 
1125 		pkt_recv_data_len += total_len - 8 /* HBHO */ - 8 /* UDP */ -
1126 			sizeof(struct net_ipv6_frag_hdr);
1127 
1128 		ipv6_second_frag[6 * 8 + 2] = pkt->buffer->data[6 * 8 + 2];
1129 		ipv6_second_frag[6 * 8 + 3] = pkt->buffer->data[6 * 8 + 3];
1130 
1131 		/* Rewrite the fragment id so that the memcmp() will not fail */
1132 		ipv6_second_frag[6 * 8 + 4] = pkt->buffer->data[6 * 8 + 4];
1133 		ipv6_second_frag[6 * 8 + 5] = pkt->buffer->data[6 * 8 + 5];
1134 		ipv6_second_frag[6 * 8 + 6] = pkt->buffer->data[6 * 8 + 6];
1135 		ipv6_second_frag[6 * 8 + 7] = pkt->buffer->data[6 * 8 + 7];
1136 
1137 		if (memcmp(pkt->buffer->data, ipv6_second_frag, 7 * 8) != 0) {
1138 			net_hexdump("received 2", pkt->buffer->data, 7 * 8);
1139 			NET_DBG("");
1140 			net_hexdump("expected 2", ipv6_second_frag, 7 * 8);
1141 
1142 			return -EINVAL;
1143 		}
1144 
1145 		if (pkt_data_len != pkt_recv_data_len) {
1146 			NET_DBG("Invalid amount of data received (%d vs %d)",
1147 				pkt_data_len, pkt_recv_data_len);
1148 			return -EINVAL;
1149 		}
1150 
1151 		test_complete = true;
1152 	}
1153 
1154 	return 0;
1155 
1156 large:
1157 	net_pkt_cursor_init(pkt);
1158 
1159 	if (frag_count == 1) {
1160 		uint16_t exp_ext_len = 1040U; /* 1032 (HBHO) + 8 (FRAG)*/
1161 		uint16_t recv_ext_len;
1162 		uint16_t exp_payload_len = 200U;
1163 		uint16_t recv_payload_len;
1164 		uint16_t frag_offset;
1165 
1166 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1167 		if (recv_ext_len != exp_ext_len) {
1168 			NET_DBG("Expected amount of Ext headers len is %d,"
1169 				"but received %d", exp_ext_len, recv_ext_len);
1170 			return -EINVAL;
1171 		}
1172 
1173 		/* IPv6 + HBHO + FRAG */
1174 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 1032 - 8;
1175 		if (recv_payload_len != exp_payload_len) {
1176 			NET_DBG("Expected amount of payload len is %d,"
1177 				"but received %d", exp_payload_len,
1178 				recv_payload_len);
1179 			return -EINVAL;
1180 		}
1181 
1182 		if (net_pkt_skip(pkt, 40 + 1032 + 2) ||
1183 		    net_pkt_read_be16(pkt, &frag_offset)) {
1184 			return -EINVAL;
1185 		}
1186 
1187 		if ((frag_offset & 0xfff8) != 0U) {
1188 			NET_DBG("Invalid fragment offset %d",
1189 				frag_offset & 0xfff8);
1190 			return -EINVAL;
1191 		}
1192 
1193 		if ((frag_offset & 0x0001) != 1U) {
1194 			NET_DBG("Fragment More flag should be set");
1195 			return -EINVAL;
1196 		}
1197 	}
1198 
1199 	if (frag_count == 2) {
1200 		uint16_t exp_ext_len = 1040U; /* 1032 (HBHO) + 8 (FRAG)*/
1201 		uint16_t recv_ext_len;
1202 		uint16_t exp_payload_len = 200U;
1203 		uint16_t recv_payload_len;
1204 		uint16_t frag_offset;
1205 
1206 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1207 		if (recv_ext_len != exp_ext_len) {
1208 			NET_DBG("Expected amount of Ext headers len is %d,"
1209 				"but received %d", exp_ext_len, recv_ext_len);
1210 			return -EINVAL;
1211 		}
1212 
1213 		/* IPv6 + HBHO + FRAG */
1214 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 1032 - 8;
1215 		if (recv_payload_len != exp_payload_len) {
1216 			NET_DBG("Expected amount of payload len is %d,"
1217 				"but received %d", exp_payload_len,
1218 				recv_payload_len);
1219 			return -EINVAL;
1220 		}
1221 
1222 		if (net_pkt_skip(pkt, 40 + 1032 + 2) ||
1223 		    net_pkt_read_be16(pkt, &frag_offset)) {
1224 			return -EINVAL;
1225 		}
1226 
1227 		if ((frag_offset & 0xfff8) != 200U) {
1228 			NET_DBG("Invalid fragment offset %d",
1229 				frag_offset & 0xfff8);
1230 			return -EINVAL;
1231 		}
1232 
1233 		if ((frag_offset & 0x0001) != 1U) {
1234 			NET_DBG("Fragment More flag should be set");
1235 			return -EINVAL;
1236 		}
1237 	}
1238 
1239 	if (frag_count == 3) {
1240 		uint16_t exp_ext_len = 1040U; /* 1032 (HBHO) + 8 (FRAG)*/
1241 		uint16_t recv_ext_len;
1242 		uint16_t exp_payload_len = 16U;
1243 		uint16_t recv_payload_len;
1244 		uint16_t frag_offset;
1245 
1246 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1247 		if (recv_ext_len != exp_ext_len) {
1248 			NET_DBG("Expected amount of Ext headers len is %d,"
1249 				"but received %d", exp_ext_len, recv_ext_len);
1250 			return -EINVAL;
1251 		}
1252 
1253 		/* IPv6 + HBHO + FRAG */
1254 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 1032 - 8;
1255 		if (recv_payload_len != exp_payload_len) {
1256 			NET_DBG("Expected amount of payload len is %d,"
1257 				"but received %d", exp_payload_len,
1258 				recv_payload_len);
1259 			return -EINVAL;
1260 		}
1261 
1262 		if (net_pkt_skip(pkt, 40 + 1032 + 2) ||
1263 		    net_pkt_read_be16(pkt, &frag_offset)) {
1264 			return -EINVAL;
1265 		}
1266 
1267 		if ((frag_offset & 0xfff8) != 400U) {
1268 			NET_DBG("Invalid fragment offset %d",
1269 				frag_offset & 0xfff8);
1270 			return -EINVAL;
1271 		}
1272 
1273 		if ((frag_offset & 0x0001) != 0U) {
1274 			NET_DBG("Fragment More flag should be unset");
1275 			return -EINVAL;
1276 		}
1277 
1278 		test_complete = true;
1279 	}
1280 
1281 	return 0;
1282 
1283 without:
1284 	net_pkt_cursor_init(pkt);
1285 
1286 	if (frag_count == 1) {
1287 		uint16_t exp_ext_len = 8U; /* 0 (HBHO) + 8 (FRAG)*/
1288 		uint16_t recv_ext_len;
1289 		uint16_t exp_payload_len = 1232U;
1290 		uint16_t recv_payload_len;
1291 		uint16_t frag_offset;
1292 
1293 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1294 		if (recv_ext_len != exp_ext_len) {
1295 			NET_DBG("Expected amount of Ext headers len is %d,"
1296 				"but received %d", exp_ext_len, recv_ext_len);
1297 			return -EINVAL;
1298 		}
1299 
1300 		/* IPv6 + FRAG */
1301 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 8;
1302 		if (recv_payload_len != exp_payload_len) {
1303 			NET_DBG("Expected amount of payload len is %d,"
1304 				"but received %d", exp_payload_len,
1305 				recv_payload_len);
1306 			return -EINVAL;
1307 		}
1308 
1309 		if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) {
1310 			NET_DBG("Invalid IPv6 next header %d",
1311 				pkt->buffer->data[6]);
1312 			return -EINVAL;
1313 		}
1314 
1315 		if (net_pkt_skip(pkt, 40 + 2) ||
1316 		    net_pkt_read_be16(pkt, &frag_offset)) {
1317 			return -EINVAL;
1318 		}
1319 
1320 		if ((frag_offset & 0xfff8) != 0U) {
1321 			NET_DBG("Invalid fragment offset %d",
1322 				frag_offset & 0xfff8);
1323 			return -EINVAL;
1324 		}
1325 
1326 		if ((frag_offset & 0x0001) != 1U) {
1327 			NET_DBG("Fragment More flag should be set");
1328 			return -EINVAL;
1329 		}
1330 	}
1331 
1332 	if (frag_count == 2) {
1333 		uint16_t exp_ext_len = 8U; /* 0 (HBHO) + 8 (FRAG)*/
1334 		uint16_t recv_ext_len;
1335 		uint16_t exp_payload_len = 76U;
1336 		uint16_t recv_payload_len;
1337 		uint16_t frag_offset;
1338 
1339 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1340 		if (recv_ext_len != exp_ext_len) {
1341 			NET_DBG("Expected amount of Ext headers len is %d,"
1342 				"but received %d", exp_ext_len, recv_ext_len);
1343 			return -EINVAL;
1344 		}
1345 
1346 		if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) {
1347 			NET_DBG("Invalid IPv6 next header %d",
1348 				pkt->buffer->data[6]);
1349 			return -EINVAL;
1350 		}
1351 
1352 		/* IPv6 + FRAG */
1353 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 8;
1354 		if (recv_payload_len != exp_payload_len) {
1355 			NET_DBG("Expected amount of payload len is %d,"
1356 				"but received %d", exp_payload_len,
1357 				recv_payload_len);
1358 			return -EINVAL;
1359 		}
1360 
1361 		if (net_pkt_skip(pkt, 40 + 2) ||
1362 		    net_pkt_read_be16(pkt, &frag_offset)) {
1363 			return -EINVAL;
1364 		}
1365 
1366 		if ((frag_offset & 0xfff8) != 1232U) {
1367 			NET_DBG("Invalid fragment offset %d",
1368 				frag_offset & 0xfff8);
1369 			return -EINVAL;
1370 		}
1371 
1372 		if ((frag_offset & 0x0001) != 0U) {
1373 			NET_DBG("Fragment More flag should be unset");
1374 			return -EINVAL;
1375 		}
1376 
1377 		test_complete = true;
1378 	}
1379 
1380 	return 0;
1381 
1382 udp_loopback:
1383 	net_pkt_cursor_init(pkt);
1384 
1385 	if (frag_count == 1) {
1386 		uint16_t exp_ext_len = 8U; /* 8 (FRAG)*/
1387 		uint16_t recv_ext_len;
1388 		uint16_t exp_payload_len = 1232U;
1389 		uint16_t recv_payload_len;
1390 		uint16_t frag_offset;
1391 
1392 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1393 		if (recv_ext_len != exp_ext_len) {
1394 			NET_DBG("Expected amount of Ext headers len is %d,"
1395 				"but received %d", exp_ext_len, recv_ext_len);
1396 			return -EINVAL;
1397 		}
1398 
1399 		/* IPv6 + FRAG */
1400 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 8;
1401 		if (recv_payload_len != exp_payload_len) {
1402 			NET_DBG("Expected amount of payload len is %d,"
1403 				"but received %d", exp_payload_len,
1404 				recv_payload_len);
1405 			return -EINVAL;
1406 		}
1407 
1408 		if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) {
1409 			NET_DBG("Invalid IPv6 next header %d",
1410 				pkt->buffer->data[6]);
1411 			return -EINVAL;
1412 		}
1413 
1414 		if (net_pkt_skip(pkt, 40 + 2) ||
1415 		    net_pkt_read_be16(pkt, &frag_offset)) {
1416 			return -EINVAL;
1417 		}
1418 
1419 		if ((frag_offset & 0xfff8) != 0U) {
1420 			NET_DBG("Invalid fragment offset %d",
1421 				frag_offset & 0xfff8);
1422 			return -EINVAL;
1423 		}
1424 
1425 		if ((frag_offset & 0x0001) != 1U) {
1426 			NET_DBG("Fragment More flag should be set");
1427 			return -EINVAL;
1428 		}
1429 	}
1430 
1431 	if (frag_count == 2) {
1432 		uint16_t exp_ext_len = 8U; /* 8 (FRAG)*/
1433 		uint16_t recv_ext_len;
1434 		uint16_t exp_payload_len = 376U; /* 1608 (data + UDP) - 1232 (fragment 1) */
1435 		uint16_t recv_payload_len;
1436 		uint16_t frag_offset;
1437 
1438 		recv_ext_len = net_pkt_ipv6_ext_len(pkt);
1439 		if (recv_ext_len != exp_ext_len) {
1440 			NET_DBG("Expected amount of Ext headers len is %d,"
1441 				"but received %d", exp_ext_len, recv_ext_len);
1442 			return -EINVAL;
1443 		}
1444 
1445 		if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) {
1446 			NET_DBG("Invalid IPv6 next header %d",
1447 				pkt->buffer->data[6]);
1448 			return -EINVAL;
1449 		}
1450 
1451 		/* IPv6 + FRAG */
1452 		recv_payload_len = net_pkt_get_len(pkt) - 40 - 8;
1453 		if (recv_payload_len != exp_payload_len) {
1454 			NET_DBG("Expected amount of payload len is %d,"
1455 				"but received %d", exp_payload_len,
1456 				recv_payload_len);
1457 			return -EINVAL;
1458 		}
1459 
1460 		if (net_pkt_skip(pkt, 40 + 2) ||
1461 		    net_pkt_read_be16(pkt, &frag_offset)) {
1462 			return -EINVAL;
1463 		}
1464 
1465 		if ((frag_offset & 0xfff8) != 1232U) {
1466 			NET_DBG("Invalid fragment offset %d",
1467 				frag_offset & 0xfff8);
1468 			return -EINVAL;
1469 		}
1470 
1471 		if ((frag_offset & 0x0001) != 0U) {
1472 			NET_DBG("Fragment More flag should be unset");
1473 			return -EINVAL;
1474 		}
1475 	}
1476 
1477 	test_pkt_loopback(pkt);
1478 
1479 	return 0;
1480 }
1481 
udp_data_received(struct net_conn * conn,struct net_pkt * pkt,union net_ip_header * ip_hdr,union net_proto_header * proto_hdr,void * user_data)1482 static enum net_verdict udp_data_received(struct net_conn *conn,
1483 					  struct net_pkt *pkt,
1484 					  union net_ip_header *ip_hdr,
1485 					  union net_proto_header *proto_hdr,
1486 					  void *user_data)
1487 {
1488 	const struct net_ipv6_hdr *hdr = NET_IPV6_HDR(pkt);
1489 	uint8_t verify_buf[NET_IPV6H_LEN];
1490 	size_t expected_pkt_length = NET_IPV6H_LEN + NET_UDPH_LEN + 1600U;
1491 	uint16_t expected_udp_length = htons(1600U + NET_UDPH_LEN);
1492 	static const char expected_data[] = "123456789.";
1493 	const size_t expected_data_len = sizeof(expected_data) - 1;
1494 	uint16_t i;
1495 
1496 	NET_DBG("Data %p received", pkt);
1497 
1498 	zassert_equal(test_type, IPV6_UDP_LOOPBACK,
1499 		      "Packet should only be received in UDP loopback test");
1500 	zassert_equal(net_pkt_get_len(pkt), expected_pkt_length, "Invalid packet length");
1501 
1502 	/* Verify IPv6 header is valid */
1503 	zassert_equal(hdr->vtc, ipv6_udp[offsetof(struct net_ipv6_hdr, vtc)],
1504 		      "IPv6 header vtc mismatch");
1505 	zassert_equal(hdr->tcflow, ipv6_udp[offsetof(struct net_ipv6_hdr, tcflow)],
1506 		      "IPv6 header tcflow mismatch");
1507 	zassert_mem_equal(&hdr->flow, &ipv6_udp[offsetof(struct net_ipv6_hdr, flow)],
1508 			  sizeof(hdr->flow), "IPv6 header flow mismatch");
1509 	zassert_equal(hdr->len, expected_udp_length, "IPv6 header len mismatch");
1510 	zassert_equal(hdr->nexthdr, ipv6_udp[offsetof(struct net_ipv6_hdr, nexthdr)],
1511 		      "IPv6 header nexthdr mismatch");
1512 	zassert_equal(hdr->hop_limit, ipv6_udp[offsetof(struct net_ipv6_hdr, hop_limit)],
1513 		      "IPv6 header hop_limit mismatch");
1514 	zassert_mem_equal(hdr->src, &ipv6_udp[offsetof(struct net_ipv6_hdr, dst)],
1515 			  NET_IPV6_ADDR_SIZE, "IPv6 header source IP mismatch");
1516 	zassert_mem_equal(hdr->dst, &ipv6_udp[offsetof(struct net_ipv6_hdr, src)],
1517 			  NET_IPV6_ADDR_SIZE, "IPv6 header destination IP mismatch");
1518 
1519 	/* Verify UDP header is valid */
1520 	net_pkt_cursor_init(pkt);
1521 	net_pkt_read(pkt, verify_buf, NET_IPV6H_LEN);
1522 	net_pkt_read(pkt, verify_buf, NET_UDPH_LEN);
1523 	zassert_mem_equal(verify_buf, &ipv6_udp[NET_IPV6H_LEN + 2], 2,
1524 			  "UDP header source port mismatch");
1525 	zassert_mem_equal(verify_buf + 2, &ipv6_udp[NET_IPV6H_LEN], 2,
1526 			  "UDP header destination port mismatch");
1527 	zassert_mem_equal(verify_buf + 4, &expected_udp_length, 2,
1528 			  "UDP header length mismatch");
1529 	zassert_equal(net_calc_verify_chksum_udp(pkt), 0,
1530 		      "UDP header invalid checksum");
1531 
1532 	/* Verify data is valid */
1533 	i = NET_IPV6H_LEN + NET_UDPH_LEN;
1534 	while (i < net_pkt_get_len(pkt)) {
1535 		memset(verify_buf, 0, sizeof(verify_buf));
1536 		net_pkt_read(pkt, verify_buf, expected_data_len);
1537 
1538 		zassert_mem_equal(verify_buf, expected_data, expected_data_len,
1539 				  "UDP data verification failure");
1540 
1541 		i += expected_data_len;
1542 	}
1543 
1544 	net_pkt_unref(pkt);
1545 
1546 	test_complete = true;
1547 
1548 	return NET_OK;
1549 }
1550 
sender_iface(const struct device * dev,struct net_pkt * pkt)1551 static int sender_iface(const struct device *dev, struct net_pkt *pkt)
1552 {
1553 	if (!pkt->buffer) {
1554 		NET_DBG("No data to send!");
1555 		return -ENODATA;
1556 	}
1557 
1558 	if (test_started) {
1559 		/* Verify the fragments */
1560 		if (verify_fragment(pkt) < 0) {
1561 			NET_DBG("Fragments cannot be verified");
1562 			test_failed = true;
1563 		}
1564 	}
1565 
1566 	zassert_false(test_failed, "Fragment verify failed");
1567 
1568 	if (test_complete) {
1569 		k_sem_give(&wait_data);
1570 	}
1571 
1572 	return 0;
1573 }
1574 
1575 struct net_if_test net_iface1_data;
1576 
1577 static struct dummy_api net_iface_api = {
1578 	.iface_api.init = net_iface_init,
1579 	.send = sender_iface,
1580 };
1581 
1582 #define _ETH_L2_LAYER DUMMY_L2
1583 #define _ETH_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(DUMMY_L2)
1584 
1585 NET_DEVICE_INIT_INSTANCE(net_iface1_test,
1586 			 "iface1",
1587 			 iface1,
1588 			 NULL,
1589 			 NULL,
1590 			 &net_iface1_data,
1591 			 NULL,
1592 			 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
1593 			 &net_iface_api,
1594 			 _ETH_L2_LAYER,
1595 			 _ETH_L2_CTX_TYPE,
1596 			 NET_IPV6_MTU);
1597 
add_nbr(struct net_if * iface,struct in6_addr * addr,struct net_linkaddr * lladdr)1598 static void add_nbr(struct net_if *iface,
1599 		    struct in6_addr *addr,
1600 		    struct net_linkaddr *lladdr)
1601 {
1602 	struct net_nbr *nbr;
1603 
1604 	nbr = net_ipv6_nbr_add(iface, addr, lladdr, false,
1605 			       NET_IPV6_NBR_STATE_REACHABLE);
1606 	zassert_not_null(nbr, "Cannot add neighbor");
1607 }
1608 
setup_udp_handler(const struct in6_addr * raddr,const struct in6_addr * laddr,uint16_t remote_port,uint16_t local_port)1609 static void setup_udp_handler(const struct in6_addr *raddr,
1610 			      const struct in6_addr *laddr,
1611 			      uint16_t remote_port,
1612 			      uint16_t local_port)
1613 {
1614 	static struct net_conn_handle *handle;
1615 	struct sockaddr remote_addr = { 0 };
1616 	struct sockaddr local_addr = { 0 };
1617 	int ret;
1618 
1619 	net_ipaddr_copy(&net_sin6(&local_addr)->sin6_addr, laddr);
1620 	local_addr.sa_family = AF_INET6;
1621 
1622 	net_ipaddr_copy(&net_sin6(&remote_addr)->sin6_addr, raddr);
1623 	remote_addr.sa_family = AF_INET6;
1624 
1625 	ret = net_udp_register(AF_INET6, &remote_addr, &local_addr,
1626 			       remote_port, local_port, NULL, udp_data_received,
1627 			       NULL, &handle);
1628 	zassert_equal(ret, 0, "Cannot register UDP handler");
1629 }
1630 
test_setup(void)1631 static void *test_setup(void)
1632 {
1633 	struct net_if_addr *ifaddr;
1634 	int idx;
1635 
1636 	/* The semaphore is there to wait the data to be received. */
1637 	k_sem_init(&wait_data, 0, UINT_MAX);
1638 
1639 	iface1 = net_if_get_by_index(1);
1640 
1641 	((struct net_if_test *) net_if_get_device(iface1)->data)->idx =
1642 		net_if_get_by_iface(iface1);
1643 
1644 	idx = net_if_get_by_iface(iface1);
1645 	zassert_equal(idx, 1, "Invalid index iface1");
1646 
1647 	zassert_not_null(iface1, "Interface 1");
1648 
1649 	ifaddr = net_if_ipv6_addr_add(iface1, &my_addr1,
1650 				      NET_ADDR_MANUAL, 0);
1651 	if (!ifaddr) {
1652 		NET_DBG("Cannot add IPv6 address %s",
1653 			net_sprint_ipv6_addr(&my_addr1));
1654 		zassert_not_null(ifaddr, "addr1");
1655 	}
1656 
1657 	ifaddr = net_if_ipv6_addr_add(iface1, &ll_addr,
1658 				      NET_ADDR_MANUAL, 0);
1659 	if (!ifaddr) {
1660 		NET_DBG("Cannot add IPv6 address %s",
1661 			net_sprint_ipv6_addr(&ll_addr));
1662 		zassert_not_null(ifaddr, "ll_addr");
1663 	} else {
1664 		/* we need to set the addresses preferred */
1665 		ifaddr->addr_state = NET_ADDR_PREFERRED;
1666 	}
1667 
1668 	net_if_up(iface1);
1669 
1670 	add_nbr(iface1, &my_addr2, &ll_addr2);
1671 
1672 	/* Remote and local are swapped so that we can receive the sent
1673 	 * packet.
1674 	 */
1675 	setup_udp_handler(&my_addr2, &my_addr1, 49111, 43740);
1676 
1677 	/* The interface might receive data which might fail the checks
1678 	 * in the iface sending function, so we need to reset the failure
1679 	 * flag.
1680 	 */
1681 	test_failed = false;
1682 
1683 	test_started = true;
1684 
1685 	return NULL;
1686 }
1687 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_udp)1688 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_udp)
1689 {
1690 	uint16_t next_hdr_pos = 0U;
1691 	uint16_t last_hdr_pos = 0U;
1692 	struct net_pkt *pkt;
1693 	int ret;
1694 
1695 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_udp), AF_INET6,
1696 					IPPROTO_UDP, ALLOC_TIMEOUT);
1697 	zassert_not_null(pkt, "packet");
1698 
1699 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1700 	net_pkt_set_ipv6_ext_len(pkt, sizeof(ipv6_udp) -
1701 				 sizeof(struct net_ipv6_hdr));
1702 
1703 	/* Add IPv6 header + UDP */
1704 	ret = net_pkt_write(pkt, ipv6_udp, sizeof(ipv6_udp));
1705 
1706 	zassert_true(ret == 0, "IPv6 header append failed");
1707 
1708 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1709 	zassert_equal(ret, 0, "Cannot find last header");
1710 
1711 	zassert_equal(next_hdr_pos, 6, "Next header index wrong");
1712 	zassert_equal(last_hdr_pos, sizeof(struct net_ipv6_hdr),
1713 		      "Last header position wrong");
1714 
1715 	zassert_equal(NET_IPV6_HDR(pkt)->nexthdr, 0x11, "Invalid next header");
1716 	zassert_equal(pkt->buffer->data[next_hdr_pos], 0x11, "Invalid next "
1717 		      "header");
1718 
1719 	net_pkt_unref(pkt);
1720 }
1721 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_hbho_udp)1722 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_hbho_udp)
1723 {
1724 	uint16_t next_hdr_pos = 0U;
1725 	uint16_t last_hdr_pos = 0U;
1726 	struct net_pkt *pkt;
1727 	int ret;
1728 
1729 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho) +
1730 					sizeof(struct net_ipv6_hdr) + 6,
1731 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1732 	zassert_not_null(pkt, "packet");
1733 
1734 	net_pkt_set_family(pkt, AF_INET6);
1735 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1736 	net_pkt_set_ipv6_ext_len(pkt, sizeof(ipv6_hbho) -
1737 				 sizeof(struct net_ipv6_hdr));
1738 	/* Add IPv6 header + HBH option */
1739 	ret = net_pkt_write(pkt, ipv6_hbho, sizeof(ipv6_hbho));
1740 	zassert_true(ret == 0, "IPv6 header append failed");
1741 
1742 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1743 	zassert_equal(ret, 0, "Cannot find last header");
1744 
1745 	zassert_equal(next_hdr_pos, sizeof(struct net_ipv6_hdr),
1746 		      "Next header index wrong");
1747 	zassert_equal(last_hdr_pos, sizeof(struct net_ipv6_hdr) + 8,
1748 		      "Last header position wrong");
1749 
1750 	zassert_equal(NET_IPV6_HDR(pkt)->nexthdr, 0, "Invalid next header");
1751 	zassert_equal(pkt->buffer->data[next_hdr_pos], 0x11, "Invalid next "
1752 		      "header");
1753 
1754 	net_pkt_unref(pkt);
1755 }
1756 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_hbho_1)1757 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_hbho_1)
1758 {
1759 	uint16_t next_hdr_pos = 0U;
1760 	uint16_t last_hdr_pos = 0U;
1761 	struct net_pkt *pkt;
1762 	uint8_t next_hdr;
1763 	uint8_t last_hdr;
1764 	int ret;
1765 
1766 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_1),
1767 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1768 	zassert_not_null(pkt, "packet");
1769 
1770 	net_pkt_set_family(pkt, AF_INET6);
1771 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1772 
1773 	/* Add IPv6 header + HBH option + fragment header */
1774 	ret = net_pkt_write(pkt, ipv6_hbho_1, sizeof(ipv6_hbho_1));
1775 	zassert_true(ret == 0, "IPv6 header append failed");
1776 
1777 	net_pkt_set_overwrite(pkt, true);
1778 
1779 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1780 	zassert_equal(ret, 0, "Cannot find last header");
1781 
1782 	zassert_equal(next_hdr_pos, 40, "Next header position wrong");
1783 	zassert_equal(last_hdr_pos, 112, "Last header position wrong");
1784 
1785 	net_pkt_cursor_init(pkt);
1786 	net_pkt_skip(pkt, next_hdr_pos);
1787 	net_pkt_read_u8(pkt, &next_hdr);
1788 
1789 	zassert_equal(next_hdr, 0x11, "Invalid next header");
1790 
1791 	net_pkt_cursor_init(pkt);
1792 	net_pkt_skip(pkt, last_hdr_pos);
1793 	net_pkt_read_u8(pkt, &last_hdr);
1794 
1795 	zassert_equal(last_hdr, 0x4e, "Invalid last header");
1796 
1797 	net_pkt_unref(pkt);
1798 }
1799 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_hbho_2)1800 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_hbho_2)
1801 {
1802 	uint16_t next_hdr_pos = 0U;
1803 	uint16_t last_hdr_pos = 0U;
1804 	struct net_pkt *pkt;
1805 	uint8_t next_hdr;
1806 	uint8_t last_hdr;
1807 	int ret;
1808 
1809 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_2),
1810 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1811 	zassert_not_null(pkt, "packet");
1812 
1813 	net_pkt_set_family(pkt, AF_INET6);
1814 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1815 
1816 	/* Add IPv6 header + HBH option + fragment header */
1817 	ret = net_pkt_write(pkt, ipv6_hbho_2, sizeof(ipv6_hbho_2));
1818 	zassert_true(ret == 0, "IPv6 header append failed");
1819 
1820 	net_pkt_set_overwrite(pkt, true);
1821 
1822 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1823 	zassert_equal(ret, 0, "Cannot find last header");
1824 
1825 	zassert_equal(next_hdr_pos, 40, "Next header position wrong");
1826 	zassert_equal(last_hdr_pos, 144, "Last header position wrong");
1827 
1828 	net_pkt_cursor_init(pkt);
1829 	net_pkt_skip(pkt, next_hdr_pos);
1830 	net_pkt_read_u8(pkt, &next_hdr);
1831 
1832 	zassert_equal(next_hdr, 0x11, "Invalid next header");
1833 
1834 	net_pkt_cursor_init(pkt);
1835 	net_pkt_skip(pkt, last_hdr_pos);
1836 	net_pkt_read_u8(pkt, &last_hdr);
1837 
1838 	zassert_equal(last_hdr, 0x4e, "Invalid last header");
1839 
1840 	net_pkt_unref(pkt);
1841 }
1842 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_hbho_3)1843 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_hbho_3)
1844 {
1845 	uint16_t next_hdr_pos = 0U;
1846 	uint16_t last_hdr_pos = 0U;
1847 	struct net_pkt *pkt;
1848 	uint8_t next_hdr;
1849 	uint8_t last_hdr;
1850 	int ret;
1851 
1852 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_3),
1853 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1854 	zassert_not_null(pkt, "packet");
1855 
1856 	net_pkt_set_family(pkt, AF_INET6);
1857 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1858 
1859 	/* Add IPv6 header + HBH option + fragment header */
1860 	ret = net_pkt_write(pkt, ipv6_hbho_3, sizeof(ipv6_hbho_3));
1861 	zassert_true(ret == 0, "IPv6 header append failed");
1862 
1863 	net_pkt_set_overwrite(pkt, true);
1864 
1865 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1866 	zassert_equal(ret, 0, "Cannot find last header");
1867 
1868 	zassert_equal(next_hdr_pos, 40, "Next header position wrong");
1869 	zassert_equal(last_hdr_pos, 960, "Last header position wrong");
1870 
1871 	net_pkt_cursor_init(pkt);
1872 	net_pkt_skip(pkt, next_hdr_pos);
1873 	net_pkt_read_u8(pkt, &next_hdr);
1874 
1875 	zassert_equal(next_hdr, 0x11, "Invalid next header");
1876 
1877 	net_pkt_cursor_init(pkt);
1878 	net_pkt_skip(pkt, last_hdr_pos);
1879 	net_pkt_read_u8(pkt, &last_hdr);
1880 
1881 	zassert_equal(last_hdr, 0x4e, "Invalid last header");
1882 
1883 	net_pkt_unref(pkt);
1884 }
1885 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_hbho_frag)1886 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_hbho_frag)
1887 {
1888 	uint16_t next_hdr_pos = 0U;
1889 	uint16_t last_hdr_pos = 0U;
1890 	struct net_pkt *pkt;
1891 	int ret;
1892 
1893 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_frag),
1894 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1895 	zassert_not_null(pkt, "packet");
1896 
1897 	net_pkt_set_family(pkt, AF_INET6);
1898 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1899 
1900 	/* Add IPv6 header + HBH option + fragment header */
1901 	ret = net_pkt_write(pkt, ipv6_hbho_frag, sizeof(ipv6_hbho_frag));
1902 	zassert_true(ret == 0, "IPv6 header append failed");
1903 
1904 	net_pkt_set_overwrite(pkt, true);
1905 
1906 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1907 	zassert_equal(ret, 0, "Cannot find last header");
1908 
1909 	zassert_equal(next_hdr_pos, sizeof(struct net_ipv6_hdr) + 8,
1910 		      "Next header position wrong");
1911 	zassert_equal(last_hdr_pos, sizeof(struct net_ipv6_hdr) + 8 + 8,
1912 		      "Last header position wrong");
1913 
1914 	zassert_equal(NET_IPV6_HDR(pkt)->nexthdr, 0, "Invalid next header");
1915 	zassert_equal(pkt->buffer->data[next_hdr_pos], 0x11,
1916 		      "Invalid next header");
1917 
1918 	net_pkt_unref(pkt);
1919 }
1920 
ZTEST(net_ipv6_fragment,test_find_last_ipv6_fragment_hbho_frag_1)1921 ZTEST(net_ipv6_fragment, test_find_last_ipv6_fragment_hbho_frag_1)
1922 {
1923 	uint16_t next_hdr_pos = 0U;
1924 	uint16_t last_hdr_pos = 0U;
1925 	struct net_pkt *pkt;
1926 	uint8_t next_hdr;
1927 	uint8_t last_hdr;
1928 	int ret;
1929 
1930 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_frag_1),
1931 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1932 	zassert_not_null(pkt, "packet");
1933 
1934 	net_pkt_set_family(pkt, AF_INET6);
1935 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1936 
1937 	/* Add IPv6 header + HBH option + fragment header */
1938 	ret = net_pkt_write(pkt, ipv6_hbho_frag_1,
1939 			    sizeof(ipv6_hbho_frag_1));
1940 	zassert_true(ret == 0, "IPv6 header append failed");
1941 
1942 	net_pkt_set_overwrite(pkt, true);
1943 
1944 	ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos);
1945 	zassert_equal(ret, 0, "Cannot find last header");
1946 
1947 	zassert_equal(next_hdr_pos, 1072, "Next header position wrong");
1948 	zassert_equal(last_hdr_pos, 1080, "Last header position wrong");
1949 
1950 	net_pkt_cursor_init(pkt);
1951 	net_pkt_skip(pkt, next_hdr_pos);
1952 	net_pkt_read_u8(pkt, &next_hdr);
1953 
1954 	zassert_equal(next_hdr, 0x3a, "Invalid next header");
1955 
1956 	net_pkt_cursor_init(pkt);
1957 	net_pkt_skip(pkt, last_hdr_pos);
1958 	net_pkt_read_u8(pkt, &last_hdr);
1959 
1960 	zassert_equal(last_hdr, 0x80, "Invalid next header");
1961 
1962 	net_pkt_unref(pkt);
1963 }
1964 
ZTEST(net_ipv6_fragment,test_send_ipv6_fragment)1965 ZTEST(net_ipv6_fragment, test_send_ipv6_fragment)
1966 {
1967 #define MAX_LEN 1600
1968 	static char data[] = "123456789.";
1969 	int data_len = sizeof(data) - 1;
1970 	int count = MAX_LEN / data_len;
1971 	struct net_pkt *pkt;
1972 	size_t total_len;
1973 	int i, ret;
1974 
1975 	test_type = IPV6_SMALL_HBHO_FRAG;
1976 	pkt_data_len = 0U;
1977 
1978 	pkt = net_pkt_alloc_with_buffer(iface1,
1979 					sizeof(ipv6_hbho) + (count * data_len),
1980 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
1981 	zassert_not_null(pkt, "packet");
1982 
1983 	net_pkt_set_iface(pkt, iface1);
1984 	net_pkt_set_family(pkt, AF_INET6);
1985 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
1986 	net_pkt_set_ipv6_ext_len(pkt, 8); /* hbho */
1987 
1988 	/* Add IPv6 header + HBH option */
1989 	ret = net_pkt_write(pkt, ipv6_hbho, sizeof(ipv6_hbho));
1990 	zassert_true(ret == 0, "IPv6 header append failed");
1991 
1992 	/* Then add some data that is over 1280 bytes long */
1993 	for (i = 0; i < count; i++) {
1994 		ret = net_pkt_write(pkt, data, data_len);
1995 
1996 		zassert_true(ret == 0, "Cannot append data");
1997 
1998 		pkt_data_len += data_len;
1999 	}
2000 
2001 	zassert_equal(pkt_data_len, count * data_len, "Data size mismatch");
2002 
2003 	total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr);
2004 
2005 	NET_DBG("Sending %zd bytes of which ext %d and data %d bytes",
2006 		total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len);
2007 
2008 	zassert_equal(total_len - net_pkt_ipv6_ext_len(pkt) - 8, pkt_data_len,
2009 		      "Packet size invalid");
2010 
2011 	NET_IPV6_HDR(pkt)->len = htons(total_len);
2012 
2013 	net_pkt_cursor_init(pkt);
2014 	net_pkt_set_overwrite(pkt, true);
2015 	net_pkt_skip(pkt, net_pkt_ip_hdr_len(pkt) + net_pkt_ipv6_ext_len(pkt));
2016 
2017 	net_udp_finalize(pkt, false);
2018 
2019 	test_failed = false;
2020 	test_complete = false;
2021 
2022 	ret = net_send_data(pkt);
2023 	if (ret < 0) {
2024 		NET_DBG("Cannot send test packet (%d)", ret);
2025 		zassert_equal(ret, 0, "Cannot send");
2026 	}
2027 
2028 	if (k_sem_take(&wait_data, WAIT_TIME)) {
2029 		NET_DBG("Timeout while waiting interface data");
2030 		zassert_true(false, "Timeout");
2031 	}
2032 }
2033 
ZTEST(net_ipv6_fragment,test_send_ipv6_fragment_large_hbho)2034 ZTEST(net_ipv6_fragment, test_send_ipv6_fragment_large_hbho)
2035 {
2036 	struct net_pkt *pkt;
2037 	size_t total_len;
2038 	int ret;
2039 
2040 	frag_count = 0;
2041 	pkt_data_len = 416U;
2042 	test_type = IPV6_LARGE_HBHO_FRAG;
2043 
2044 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_large_hbho),
2045 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
2046 	zassert_not_null(pkt, "packet");
2047 
2048 	net_pkt_set_family(pkt, AF_INET6);
2049 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
2050 	net_pkt_set_ipv6_ext_len(pkt, 1032); /* hbho */
2051 
2052 	ret = net_pkt_write(pkt, ipv6_large_hbho, sizeof(ipv6_large_hbho));
2053 	zassert_true(ret == 0, "IPv6 header append failed");
2054 
2055 	net_pkt_set_overwrite(pkt, true);
2056 
2057 	total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr);
2058 
2059 	NET_DBG("Sending %zd bytes of which ext %d and data %d bytes",
2060 		total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len);
2061 
2062 	test_failed = false;
2063 	test_complete = false;
2064 
2065 	ret = net_send_data(pkt);
2066 	if (ret < 0) {
2067 		NET_DBG("Cannot send test packet (%d)", ret);
2068 		zassert_equal(ret, 0, "Cannot send");
2069 	}
2070 
2071 	if (k_sem_take(&wait_data, WAIT_TIME)) {
2072 		NET_DBG("Timeout while waiting interface data");
2073 		zassert_true(false, "Timeout");
2074 	}
2075 }
2076 
ZTEST(net_ipv6_fragment,test_send_ipv6_fragment_without_hbho)2077 ZTEST(net_ipv6_fragment, test_send_ipv6_fragment_without_hbho)
2078 {
2079 	struct net_pkt *pkt;
2080 	size_t total_len;
2081 	int ret;
2082 
2083 	frag_count = 0;
2084 	pkt_data_len = sizeof(ipv6_frag_wo_hbho) -
2085 			sizeof(struct net_ipv6_hdr) -
2086 			NET_IPV6_FRAGH_LEN;
2087 	test_type = IPV6_WITHOUT_HBHO_FRAG;
2088 
2089 	pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_frag_wo_hbho),
2090 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
2091 	zassert_not_null(pkt, "packet");
2092 
2093 	net_pkt_set_family(pkt, AF_INET6);
2094 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
2095 	net_pkt_set_ipv6_ext_len(pkt, NET_IPV6_FRAGH_LEN); /* without hbho*/
2096 
2097 	ret = net_pkt_write(pkt, ipv6_frag_wo_hbho,
2098 			    sizeof(ipv6_frag_wo_hbho));
2099 	zassert_true(ret == 0, "IPv6 header append failed");
2100 
2101 	net_pkt_set_overwrite(pkt, true);
2102 
2103 	total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr) -
2104 		    NET_IPV6_FRAGH_LEN;
2105 
2106 	NET_DBG("Sending %zd bytes of which ext %d and data %d bytes",
2107 		total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len);
2108 
2109 	test_failed = false;
2110 	test_complete = false;
2111 
2112 	ret = net_send_data(pkt);
2113 	if (ret < 0) {
2114 		NET_DBG("Cannot send test packet (%d)", ret);
2115 		zassert_equal(ret, 0, "Cannot send");
2116 	}
2117 
2118 	if (k_sem_take(&wait_data, WAIT_TIME)) {
2119 		NET_DBG("Timeout while waiting interface data");
2120 		zassert_true(false, "Timeout");
2121 	}
2122 }
2123 
ZTEST(net_ipv6_fragment,test_send_ipv6_fragment_udp_loopback)2124 ZTEST(net_ipv6_fragment, test_send_ipv6_fragment_udp_loopback)
2125 {
2126 #define MAX_LEN 1600
2127 	static const char data[] = "123456789.";
2128 	int data_len = sizeof(data) - 1;
2129 	int count = MAX_LEN / data_len;
2130 	struct net_pkt *pkt;
2131 	size_t total_len;
2132 	int i, ret;
2133 
2134 	frag_count = 0;
2135 	test_type = IPV6_UDP_LOOPBACK;
2136 	pkt_data_len = 0U;
2137 
2138 	pkt = net_pkt_alloc_with_buffer(iface1,
2139 					sizeof(ipv6_udp) + (count * data_len),
2140 					AF_UNSPEC, 0, ALLOC_TIMEOUT);
2141 	zassert_not_null(pkt, "packet");
2142 
2143 	net_pkt_set_iface(pkt, iface1);
2144 	net_pkt_set_family(pkt, AF_INET6);
2145 	net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
2146 	net_pkt_set_ipv6_ext_len(pkt, 0);
2147 
2148 	/* Add IPv6 header + HBH option */
2149 	ret = net_pkt_write(pkt, ipv6_udp, sizeof(ipv6_udp));
2150 	zassert_true(ret == 0, "IPv6 header append failed");
2151 
2152 	/* Then add some data that is over 1280 bytes long */
2153 	for (i = 0; i < count; i++) {
2154 		ret = net_pkt_write(pkt, data, data_len);
2155 
2156 		zassert_true(ret == 0, "Cannot append data");
2157 
2158 		pkt_data_len += data_len;
2159 	}
2160 
2161 	zassert_equal(pkt_data_len, count * data_len, "Data size mismatch");
2162 
2163 	total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr);
2164 
2165 	NET_DBG("Sending %zd bytes of which ext %d and data %d bytes",
2166 		total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len);
2167 
2168 	zassert_equal(total_len - net_pkt_ipv6_ext_len(pkt) - 8, pkt_data_len,
2169 		      "Packet size invalid");
2170 
2171 	NET_IPV6_HDR(pkt)->len = htons(total_len);
2172 
2173 	net_pkt_cursor_init(pkt);
2174 	net_pkt_set_overwrite(pkt, true);
2175 	net_pkt_skip(pkt, net_pkt_ip_hdr_len(pkt) + net_pkt_ipv6_ext_len(pkt));
2176 
2177 	net_udp_finalize(pkt, false);
2178 
2179 	test_failed = false;
2180 	test_complete = false;
2181 
2182 	ret = net_send_data(pkt);
2183 	if (ret < 0) {
2184 		NET_DBG("Cannot send test packet (%d)", ret);
2185 		zassert_equal(ret, 0, "Cannot send");
2186 	}
2187 
2188 	if (k_sem_take(&wait_data, WAIT_TIME)) {
2189 		NET_DBG("Timeout while waiting interface data");
2190 		zassert_true(false, "Timeout");
2191 	}
2192 }
2193 
2194 static uint8_t ipv6_reass_frag1[] = {
2195 0x60, 0x00, 0x00, 0x00, 0x04, 0xd8, 0x2c, 0x40,
2196 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
2197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
2198 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
2199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
2200 0x3a, 0x00, 0x00, 0x01, 0x7c, 0x8e, 0x53, 0x49,
2201 0x81, 0x00, 0xda, 0x34, 0x28, 0x5b, 0x00, 0x01
2202 };
2203 
2204 static uint8_t ipv6_reass_frag2[] = {
2205 0x60, 0x00, 0x00, 0x00, 0x00, 0x54, 0x2c, 0x40,
2206 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
2207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
2208 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
2209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
2210 0x3a, 0x00, 0x04, 0xd0, 0x7c, 0x8e, 0x53, 0x49
2211 };
2212 
2213 #define ECHO_REPLY_H_LEN 8
2214 #define ECHO_REPLY_ID_OFFSET (NET_IPV6H_LEN + NET_IPV6_FRAGH_LEN + 4)
2215 #define ECHO_REPLY_SEQ_OFFSET (NET_IPV6H_LEN + NET_IPV6_FRAGH_LEN + 6)
2216 
2217 static uint16_t test_recv_payload_len = 1300U;
2218 
handle_ipv6_echo_reply(struct net_icmp_ctx * ctx,struct net_pkt * pkt,struct net_icmp_ip_hdr * ip_hdr,struct net_icmp_hdr * icmp_hdr,void * user_data)2219 static int handle_ipv6_echo_reply(struct net_icmp_ctx *ctx,
2220 				  struct net_pkt *pkt,
2221 				  struct net_icmp_ip_hdr *ip_hdr,
2222 				  struct net_icmp_hdr *icmp_hdr,
2223 				  void *user_data)
2224 {
2225 	const struct net_ipv6_hdr *hdr = NET_IPV6_HDR(pkt);
2226 	uint8_t verify_buf[NET_IPV6H_LEN];
2227 	size_t expected_pkt_length = NET_IPV6H_LEN + ECHO_REPLY_H_LEN + test_recv_payload_len;
2228 	uint16_t expected_icmpv6_length = htons(test_recv_payload_len + ECHO_REPLY_H_LEN);
2229 	uint16_t i;
2230 	uint8_t expected_data = 0;
2231 
2232 	ARG_UNUSED(ctx);
2233 	ARG_UNUSED(ip_hdr);
2234 	ARG_UNUSED(icmp_hdr);
2235 	ARG_UNUSED(user_data);
2236 
2237 	NET_DBG("Data %p received", pkt);
2238 
2239 	zassert_equal(net_pkt_get_len(pkt), expected_pkt_length, "Invalid packet length");
2240 
2241 	/* Verify IPv6 header is valid */
2242 	zassert_equal(hdr->vtc, ipv6_reass_frag1[offsetof(struct net_ipv6_hdr, vtc)],
2243 		      "IPv6 header vtc mismatch");
2244 	zassert_equal(hdr->tcflow, ipv6_reass_frag1[offsetof(struct net_ipv6_hdr, tcflow)],
2245 		      "IPv6 header tcflow mismatch");
2246 	zassert_mem_equal(&hdr->flow, &ipv6_reass_frag1[offsetof(struct net_ipv6_hdr, flow)],
2247 			  sizeof(hdr->flow), "IPv6 header flow mismatch");
2248 	zassert_equal(hdr->len, expected_icmpv6_length, "IPv6 header len mismatch");
2249 	zassert_equal(hdr->nexthdr, IPPROTO_ICMPV6, "IPv6 header nexthdr mismatch");
2250 	zassert_equal(hdr->hop_limit, ipv6_reass_frag1[offsetof(struct net_ipv6_hdr, hop_limit)],
2251 		      "IPv6 header hop_limit mismatch");
2252 	zassert_mem_equal(hdr->src, &ipv6_reass_frag1[offsetof(struct net_ipv6_hdr, src)],
2253 			  NET_IPV6_ADDR_SIZE, "IPv6 header source IP mismatch");
2254 	zassert_mem_equal(hdr->dst, &ipv6_reass_frag1[offsetof(struct net_ipv6_hdr, dst)],
2255 			  NET_IPV6_ADDR_SIZE, "IPv6 header destination IP mismatch");
2256 
2257 	/* Verify Echo Reply header is valid */
2258 	net_pkt_cursor_init(pkt);
2259 	net_pkt_read(pkt, verify_buf, NET_IPV6H_LEN);
2260 	net_pkt_read(pkt, verify_buf, ECHO_REPLY_H_LEN);
2261 
2262 	zassert_equal(verify_buf[0], NET_ICMPV6_ECHO_REPLY,
2263 		      "Echo reply header invalid type");
2264 	zassert_equal(verify_buf[1], 0, "Echo reply header invalid code");
2265 	zassert_equal(net_calc_chksum_icmpv6(pkt), 0,
2266 		      "Echo reply header invalid checksum");
2267 	zassert_mem_equal(verify_buf + 4, ipv6_reass_frag1 + ECHO_REPLY_ID_OFFSET, 2,
2268 			  "Echo reply header invalid identifier");
2269 	zassert_mem_equal(verify_buf + 6, ipv6_reass_frag1 + ECHO_REPLY_SEQ_OFFSET, 2,
2270 			  "Echo reply header invalid sequence");
2271 
2272 	/* Verify data is valid */
2273 	i = NET_IPV6H_LEN + ECHO_REPLY_H_LEN;
2274 	while (i < net_pkt_get_len(pkt)) {
2275 		uint8_t data;
2276 
2277 		net_pkt_read_u8(pkt, &data);
2278 		zassert_equal(data, expected_data,
2279 			      "Echo reply data verification failure");
2280 		expected_data++;
2281 		i++;
2282 	}
2283 
2284 	k_sem_give(&wait_data);
2285 
2286 	return NET_OK;
2287 }
2288 
ZTEST(net_ipv6_fragment,test_recv_ipv6_fragment)2289 ZTEST(net_ipv6_fragment, test_recv_ipv6_fragment)
2290 {
2291 	struct net_ipv6_hdr ipv6_hdr;
2292 	struct net_pkt_cursor backup;
2293 	struct net_pkt *pkt1;
2294 	struct net_pkt *pkt2;
2295 	uint16_t payload1_len;
2296 	uint16_t payload2_len;
2297 	uint8_t data;
2298 	int ret;
2299 	struct net_icmp_ctx ctx;
2300 
2301 	ret = net_icmp_init_ctx(&ctx, NET_ICMPV6_ECHO_REPLY,
2302 				0, handle_ipv6_echo_reply);
2303 	zassert_equal(ret, 0, "Cannot register %s handler (%d)",
2304 		      STRINGIFY(NET_ICMPV6_ECHO_REPLY), ret);
2305 
2306 	/* Fragment 1 */
2307 	data = 0U;
2308 	payload1_len = NET_IPV6_MTU - sizeof(ipv6_reass_frag1);
2309 	payload2_len = test_recv_payload_len - payload1_len;
2310 
2311 	pkt1 = net_pkt_alloc_with_buffer(iface1, NET_IPV6_MTU, AF_UNSPEC,
2312 					 0, ALLOC_TIMEOUT);
2313 	zassert_not_null(pkt1, "packet");
2314 
2315 	net_pkt_set_family(pkt1, AF_INET6);
2316 	net_pkt_set_ip_hdr_len(pkt1, sizeof(struct net_ipv6_hdr));
2317 	net_pkt_cursor_init(pkt1);
2318 
2319 	memcpy(&ipv6_hdr, ipv6_reass_frag1, sizeof(struct net_ipv6_hdr));
2320 
2321 	ret = net_pkt_write(pkt1, ipv6_reass_frag1,
2322 			    sizeof(struct net_ipv6_hdr) + 1);
2323 	zassert_true(ret == 0, "IPv6 header append failed");
2324 
2325 	net_pkt_cursor_backup(pkt1, &backup);
2326 
2327 	ret = net_pkt_write(pkt1,
2328 			    ipv6_reass_frag1 + sizeof(struct net_ipv6_hdr) + 1,
2329 			    sizeof(ipv6_reass_frag1) -
2330 			    sizeof(struct net_ipv6_hdr) - 1);
2331 	zassert_true(ret == 0, "IPv6 fragment header append failed");
2332 
2333 	while (payload1_len--) {
2334 		ret = net_pkt_write_u8(pkt1, data++);
2335 		zassert_true(ret == 0, "IPv6 header append failed");
2336 	}
2337 
2338 	net_pkt_set_ipv6_hdr_prev(pkt1, offsetof(struct net_ipv6_hdr, nexthdr));
2339 	net_pkt_set_ipv6_fragment_start(pkt1, sizeof(struct net_ipv6_hdr));
2340 	net_pkt_set_overwrite(pkt1, true);
2341 
2342 	net_pkt_cursor_restore(pkt1, &backup);
2343 
2344 	ret = net_ipv6_handle_fragment_hdr(pkt1, &ipv6_hdr,
2345 					   NET_IPV6_NEXTHDR_FRAG);
2346 	zassert_true(ret == NET_OK, "IPv6 frag1 reassembly failed");
2347 
2348 	/* Fragment 2 */
2349 
2350 	pkt2 = net_pkt_alloc_with_buffer(iface1, payload2_len +
2351 					 sizeof(ipv6_reass_frag2),
2352 					 AF_UNSPEC, 0, ALLOC_TIMEOUT);
2353 	zassert_not_null(pkt2, "packet");
2354 
2355 	net_pkt_set_family(pkt2, AF_INET6);
2356 	net_pkt_set_ip_hdr_len(pkt2, sizeof(struct net_ipv6_hdr));
2357 	net_pkt_cursor_init(pkt2);
2358 
2359 	memcpy(&ipv6_hdr, ipv6_reass_frag2, sizeof(struct net_ipv6_hdr));
2360 
2361 	ret = net_pkt_write(pkt2, ipv6_reass_frag2,
2362 			    sizeof(struct net_ipv6_hdr) + 1);
2363 	zassert_true(ret == 0, "IPv6 header append failed");
2364 
2365 	net_pkt_cursor_backup(pkt2, &backup);
2366 
2367 	ret = net_pkt_write(pkt2,
2368 			    ipv6_reass_frag2 + sizeof(struct net_ipv6_hdr) + 1,
2369 			    sizeof(ipv6_reass_frag2) -
2370 			    sizeof(struct net_ipv6_hdr) - 1);
2371 	zassert_true(ret == 0, "IPv6 fragment header append failed");
2372 
2373 	while (payload2_len--) {
2374 		ret = net_pkt_write_u8(pkt2, data++);
2375 		zassert_true(ret == 0, "IPv6 header append failed");
2376 	}
2377 
2378 	net_pkt_set_ipv6_hdr_prev(pkt2, offsetof(struct net_ipv6_hdr, nexthdr));
2379 	net_pkt_set_ipv6_fragment_start(pkt2, sizeof(struct net_ipv6_hdr));
2380 	net_pkt_set_overwrite(pkt2, true);
2381 
2382 	net_pkt_cursor_restore(pkt2, &backup);
2383 
2384 	ret = net_ipv6_handle_fragment_hdr(pkt2, &ipv6_hdr,
2385 					   NET_IPV6_NEXTHDR_FRAG);
2386 	zassert_true(ret == NET_OK, "IPv6 frag2 reassembly failed");
2387 
2388 	if (k_sem_take(&wait_data, WAIT_TIME)) {
2389 		NET_DBG("Timeout while waiting interface data");
2390 		zassert_true(false, "Timeout");
2391 	}
2392 
2393 	net_icmp_cleanup_ctx(&ctx);
2394 }
2395 
2396 ZTEST_SUITE(net_ipv6_fragment, NULL, test_setup, NULL, NULL, NULL);
2397