@@ -55,7 +55,6 @@ static const unsigned char icmpv4_echo_rep[] = {
55
55
0x16 , 0x50 , 0x00 , 0x00 , 0x01 , 0xfd , 0x56 , 0xa0 };
56
56
57
57
static const unsigned char icmpv4_echo_req_opt [] = {
58
-
59
58
/* IPv4 Header */
60
59
0x4e , 0x00 , 0x00 , 0x78 , 0xe1 , 0x4b , 0x40 , 0x00 ,
61
60
0x40 , 0x01 , 0x9a , 0x83 , 0xc0 , 0x00 , 0x02 , 0x02 ,
@@ -78,6 +77,35 @@ static const unsigned char icmpv4_echo_req_opt[] = {
78
77
0x28 , 0x29 , 0x2a , 0x2b , 0x2c , 0x2d , 0x2e , 0x2f ,
79
78
0x30 , 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 };
80
79
80
+ static const unsigned char icmpv4_echo_req_opt_bad [] = {
81
+ /* IPv4 Header */
82
+ 0x46 , 0x00 , 0x00 , 0xa0 , 0xf8 , 0x6c , 0x00 , 0x00 ,
83
+ 0x64 , 0x01 , 0x56 , 0xa8 , 0xc0 , 0x00 , 0x02 , 0x02 ,
84
+ 0xc0 , 0x00 , 0x02 , 0x01 ,
85
+
86
+ /* IPv4 Header Options (Wrong length) */
87
+ 0x41 , 0x03 , 0x41 , 0x41 ,
88
+
89
+ /* ICMP Header (Echo Request) */
90
+ 0x08 , 0x00 , 0x06 , 0xb8 , 0x30 , 0x31 , 0x32 , 0x07 ,
91
+ /* Payload */
92
+ 0x80 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
93
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
94
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
95
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
96
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
97
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
98
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
99
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
100
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
101
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
102
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
103
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
104
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
105
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
106
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 ,
107
+ 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x41 , 0x00 };
108
+
81
109
static enum net_verdict handle_reply_msg (struct net_pkt * pkt ,
82
110
struct net_ipv4_hdr * ip_hdr ,
83
111
struct net_icmp_hdr * icmp_hdr )
@@ -272,6 +300,36 @@ void test_icmpv4(void)
272
300
net_icmpv4_unregister_handler (& echo_req_opt_handler );
273
301
274
302
net_pkt_unref (pkt );
303
+
304
+ /* ================ Echo Request with Bad Options ================= */
305
+ net_icmpv4_register_handler (& echo_req_opt_handler );
306
+
307
+ pkt = net_pkt_alloc_with_buffer (NULL , sizeof (icmpv4_echo_req_opt_bad ),
308
+ AF_UNSPEC , 0 , K_SECONDS (1 ));
309
+ zassert_not_null (pkt , "Allocation failed" );
310
+
311
+ net_pkt_set_ip_hdr_len (pkt , sizeof (struct net_ipv4_hdr ));
312
+ net_pkt_write (pkt , icmpv4_echo_req_opt_bad ,
313
+ sizeof (icmpv4_echo_req_opt_bad ));
314
+
315
+ net_pkt_cursor_init (pkt );
316
+
317
+ net_pkt_set_ipv4_opts_len (pkt , 4 );
318
+ net_pkt_set_overwrite (pkt , true);
319
+
320
+ net_pkt_skip (pkt , sizeof (struct net_ipv4_hdr )); /* Header*/
321
+ net_pkt_skip (pkt , 4 ); /* Options length */
322
+
323
+ hdr = (struct net_ipv4_hdr * )pkt -> buffer -> data ;
324
+
325
+ ret = net_icmpv4_input (pkt , hdr );
326
+
327
+ /** TESTPOINT: Check input */
328
+ zassert_true ((ret == NET_DROP ), "Packet should drop" );
329
+
330
+ net_icmpv4_unregister_handler (& echo_req_opt_handler );
331
+
332
+ net_pkt_unref (pkt );
275
333
}
276
334
277
335
/**test case main entry*/
0 commit comments