diff --git a/tests/net/icmpv4/src/main.c b/tests/net/icmpv4/src/main.c index 27a688dccc9..d1e0c06a75f 100644 --- a/tests/net/icmpv4/src/main.c +++ b/tests/net/icmpv4/src/main.c @@ -55,7 +55,6 @@ static const unsigned char icmpv4_echo_rep[] = { 0x16, 0x50, 0x00, 0x00, 0x01, 0xfd, 0x56, 0xa0 }; static const unsigned char icmpv4_echo_req_opt[] = { - /* IPv4 Header */ 0x4e, 0x00, 0x00, 0x78, 0xe1, 0x4b, 0x40, 0x00, 0x40, 0x01, 0x9a, 0x83, 0xc0, 0x00, 0x02, 0x02, @@ -78,6 +77,35 @@ static const unsigned char icmpv4_echo_req_opt[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 }; +static const unsigned char icmpv4_echo_req_opt_bad[] = { + /* IPv4 Header */ + 0x46, 0x00, 0x00, 0xa0, 0xf8, 0x6c, 0x00, 0x00, + 0x64, 0x01, 0x56, 0xa8, 0xc0, 0x00, 0x02, 0x02, + 0xc0, 0x00, 0x02, 0x01, + + /* IPv4 Header Options (Wrong length) */ + 0x41, 0x03, 0x41, 0x41, + + /* ICMP Header (Echo Request) */ + 0x08, 0x00, 0x06, 0xb8, 0x30, 0x31, 0x32, 0x07, + /* Payload */ + 0x80, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, + 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00 }; + static enum net_verdict handle_reply_msg(struct net_pkt *pkt, struct net_ipv4_hdr *ip_hdr, struct net_icmp_hdr *icmp_hdr) @@ -272,6 +300,36 @@ void test_icmpv4(void) net_icmpv4_unregister_handler(&echo_req_opt_handler); net_pkt_unref(pkt); + + /* ================ Echo Request with Bad Options ================= */ + net_icmpv4_register_handler(&echo_req_opt_handler); + + pkt = net_pkt_alloc_with_buffer(NULL, sizeof(icmpv4_echo_req_opt_bad), + AF_UNSPEC, 0, K_SECONDS(1)); + zassert_not_null(pkt, "Allocation failed"); + + net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr)); + net_pkt_write(pkt, icmpv4_echo_req_opt_bad, + sizeof(icmpv4_echo_req_opt_bad)); + + net_pkt_cursor_init(pkt); + + net_pkt_set_ipv4_opts_len(pkt, 4); + net_pkt_set_overwrite(pkt, true); + + net_pkt_skip(pkt, sizeof(struct net_ipv4_hdr)); /* Header*/ + net_pkt_skip(pkt, 4); /* Options length */ + + hdr = (struct net_ipv4_hdr *)pkt->buffer->data; + + ret = net_icmpv4_input(pkt, hdr); + + /** TESTPOINT: Check input */ + zassert_true((ret == NET_DROP), "Packet should drop"); + + net_icmpv4_unregister_handler(&echo_req_opt_handler); + + net_pkt_unref(pkt); } /**test case main entry*/