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