Lines Matching refs:pkt
958 static void test_pkt_loopback(struct net_pkt *pkt) in test_pkt_loopback() argument
970 recv_pkt = net_pkt_rx_clone(pkt, K_NO_WAIT); in test_pkt_loopback()
1001 net_pkt_set_iface(recv_pkt, net_pkt_iface(pkt)); in test_pkt_loopback()
1007 static int verify_fragment(struct net_pkt *pkt) in verify_fragment() argument
1040 size_t total_len = net_pkt_get_len(pkt); in verify_fragment()
1048 if ((total_len / 256) != pkt->buffer->data[4]) { in verify_fragment()
1053 if ((total_len - pkt->buffer->data[4] * 256U) != in verify_fragment()
1054 pkt->buffer->data[5]) { in verify_fragment()
1059 offset = pkt->buffer->data[6 * 8 + 2] * 256U + in verify_fragment()
1060 (pkt->buffer->data[6 * 8 + 3] & 0xfe); in verify_fragment()
1076 ipv6_first_frag[6 * 8 + 4] = pkt->buffer->data[6 * 8 + 4]; in verify_fragment()
1077 ipv6_first_frag[6 * 8 + 5] = pkt->buffer->data[6 * 8 + 5]; in verify_fragment()
1078 ipv6_first_frag[6 * 8 + 6] = pkt->buffer->data[6 * 8 + 6]; in verify_fragment()
1079 ipv6_first_frag[6 * 8 + 7] = pkt->buffer->data[6 * 8 + 7]; in verify_fragment()
1081 if (memcmp(pkt->buffer->data, ipv6_first_frag, 7 * 8) != 0) { in verify_fragment()
1082 net_hexdump("received", pkt->buffer->data, 7 * 8); in verify_fragment()
1092 size_t total_len = net_pkt_get_len(pkt); in verify_fragment()
1100 if ((total_len / 256) != pkt->buffer->data[4]) { in verify_fragment()
1105 if ((total_len - pkt->buffer->data[4] * 256U) != in verify_fragment()
1106 pkt->buffer->data[5]) { in verify_fragment()
1111 offset = pkt->buffer->data[6 * 8 + 2] * 256U + in verify_fragment()
1112 (pkt->buffer->data[6 * 8 + 3] & 0xfe); in verify_fragment()
1121 if ((pkt->buffer->data[6 * 8 + 3] & 0x01) != 0U) { in verify_fragment()
1129 ipv6_second_frag[6 * 8 + 2] = pkt->buffer->data[6 * 8 + 2]; in verify_fragment()
1130 ipv6_second_frag[6 * 8 + 3] = pkt->buffer->data[6 * 8 + 3]; in verify_fragment()
1133 ipv6_second_frag[6 * 8 + 4] = pkt->buffer->data[6 * 8 + 4]; in verify_fragment()
1134 ipv6_second_frag[6 * 8 + 5] = pkt->buffer->data[6 * 8 + 5]; in verify_fragment()
1135 ipv6_second_frag[6 * 8 + 6] = pkt->buffer->data[6 * 8 + 6]; in verify_fragment()
1136 ipv6_second_frag[6 * 8 + 7] = pkt->buffer->data[6 * 8 + 7]; in verify_fragment()
1138 if (memcmp(pkt->buffer->data, ipv6_second_frag, 7 * 8) != 0) { in verify_fragment()
1139 net_hexdump("received 2", pkt->buffer->data, 7 * 8); in verify_fragment()
1158 net_pkt_cursor_init(pkt); in verify_fragment()
1167 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1175 recv_payload_len = net_pkt_get_len(pkt) - 40 - 1032 - 8; in verify_fragment()
1183 if (net_pkt_skip(pkt, 40 + 1032 + 2) || in verify_fragment()
1184 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1207 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1215 recv_payload_len = net_pkt_get_len(pkt) - 40 - 1032 - 8; in verify_fragment()
1223 if (net_pkt_skip(pkt, 40 + 1032 + 2) || in verify_fragment()
1224 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1247 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1255 recv_payload_len = net_pkt_get_len(pkt) - 40 - 1032 - 8; in verify_fragment()
1263 if (net_pkt_skip(pkt, 40 + 1032 + 2) || in verify_fragment()
1264 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1285 net_pkt_cursor_init(pkt); in verify_fragment()
1294 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1302 recv_payload_len = net_pkt_get_len(pkt) - 40 - 8; in verify_fragment()
1310 if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) { in verify_fragment()
1312 pkt->buffer->data[6]); in verify_fragment()
1316 if (net_pkt_skip(pkt, 40 + 2) || in verify_fragment()
1317 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1340 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1347 if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) { in verify_fragment()
1349 pkt->buffer->data[6]); in verify_fragment()
1354 recv_payload_len = net_pkt_get_len(pkt) - 40 - 8; in verify_fragment()
1362 if (net_pkt_skip(pkt, 40 + 2) || in verify_fragment()
1363 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1384 net_pkt_cursor_init(pkt); in verify_fragment()
1393 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1401 recv_payload_len = net_pkt_get_len(pkt) - 40 - 8; in verify_fragment()
1409 if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) { in verify_fragment()
1411 pkt->buffer->data[6]); in verify_fragment()
1415 if (net_pkt_skip(pkt, 40 + 2) || in verify_fragment()
1416 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1439 recv_ext_len = net_pkt_ipv6_ext_len(pkt); in verify_fragment()
1446 if (pkt->buffer->data[6] != NET_IPV6_NEXTHDR_FRAG) { in verify_fragment()
1448 pkt->buffer->data[6]); in verify_fragment()
1453 recv_payload_len = net_pkt_get_len(pkt) - 40 - 8; in verify_fragment()
1461 if (net_pkt_skip(pkt, 40 + 2) || in verify_fragment()
1462 net_pkt_read_be16(pkt, &frag_offset)) { in verify_fragment()
1478 test_pkt_loopback(pkt); in verify_fragment()
1484 struct net_pkt *pkt, in udp_data_received() argument
1489 const struct net_ipv6_hdr *hdr = NET_IPV6_HDR(pkt); in udp_data_received()
1497 NET_DBG("Data %p received", pkt); in udp_data_received()
1501 zassert_equal(net_pkt_get_len(pkt), expected_pkt_length, "Invalid packet length"); in udp_data_received()
1521 net_pkt_cursor_init(pkt); in udp_data_received()
1522 net_pkt_read(pkt, verify_buf, NET_IPV6H_LEN); in udp_data_received()
1523 net_pkt_read(pkt, verify_buf, NET_UDPH_LEN); in udp_data_received()
1530 zassert_equal(net_calc_verify_chksum_udp(pkt), 0, in udp_data_received()
1535 while (i < net_pkt_get_len(pkt)) { in udp_data_received()
1537 net_pkt_read(pkt, verify_buf, expected_data_len); in udp_data_received()
1545 net_pkt_unref(pkt); in udp_data_received()
1552 static int sender_iface(const struct device *dev, struct net_pkt *pkt) in sender_iface() argument
1554 if (!pkt->buffer) { in sender_iface()
1561 if (verify_fragment(pkt) < 0) { in sender_iface()
1693 struct net_pkt *pkt; in ZTEST() local
1696 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_udp), AF_INET6, in ZTEST()
1698 zassert_not_null(pkt, "packet"); in ZTEST()
1700 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1701 net_pkt_set_ipv6_ext_len(pkt, sizeof(ipv6_udp) - in ZTEST()
1705 ret = net_pkt_write(pkt, ipv6_udp, sizeof(ipv6_udp)); in ZTEST()
1709 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1716 zassert_equal(NET_IPV6_HDR(pkt)->nexthdr, 0x11, "Invalid next header"); in ZTEST()
1717 zassert_equal(pkt->buffer->data[next_hdr_pos], 0x11, "Invalid next " in ZTEST()
1720 net_pkt_unref(pkt); in ZTEST()
1727 struct net_pkt *pkt; in ZTEST() local
1730 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho) + in ZTEST()
1733 zassert_not_null(pkt, "packet"); in ZTEST()
1735 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1736 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1737 net_pkt_set_ipv6_ext_len(pkt, sizeof(ipv6_hbho) - in ZTEST()
1740 ret = net_pkt_write(pkt, ipv6_hbho, sizeof(ipv6_hbho)); in ZTEST()
1743 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1751 zassert_equal(NET_IPV6_HDR(pkt)->nexthdr, 0, "Invalid next header"); in ZTEST()
1752 zassert_equal(pkt->buffer->data[next_hdr_pos], 0x11, "Invalid next " in ZTEST()
1755 net_pkt_unref(pkt); in ZTEST()
1762 struct net_pkt *pkt; in ZTEST() local
1767 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_1), in ZTEST()
1769 zassert_not_null(pkt, "packet"); in ZTEST()
1771 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1772 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1775 ret = net_pkt_write(pkt, ipv6_hbho_1, sizeof(ipv6_hbho_1)); in ZTEST()
1778 net_pkt_set_overwrite(pkt, true); in ZTEST()
1780 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1786 net_pkt_cursor_init(pkt); in ZTEST()
1787 net_pkt_skip(pkt, next_hdr_pos); in ZTEST()
1788 net_pkt_read_u8(pkt, &next_hdr); in ZTEST()
1792 net_pkt_cursor_init(pkt); in ZTEST()
1793 net_pkt_skip(pkt, last_hdr_pos); in ZTEST()
1794 net_pkt_read_u8(pkt, &last_hdr); in ZTEST()
1798 net_pkt_unref(pkt); in ZTEST()
1805 struct net_pkt *pkt; in ZTEST() local
1810 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_2), in ZTEST()
1812 zassert_not_null(pkt, "packet"); in ZTEST()
1814 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1815 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1818 ret = net_pkt_write(pkt, ipv6_hbho_2, sizeof(ipv6_hbho_2)); in ZTEST()
1821 net_pkt_set_overwrite(pkt, true); in ZTEST()
1823 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1829 net_pkt_cursor_init(pkt); in ZTEST()
1830 net_pkt_skip(pkt, next_hdr_pos); in ZTEST()
1831 net_pkt_read_u8(pkt, &next_hdr); in ZTEST()
1835 net_pkt_cursor_init(pkt); in ZTEST()
1836 net_pkt_skip(pkt, last_hdr_pos); in ZTEST()
1837 net_pkt_read_u8(pkt, &last_hdr); in ZTEST()
1841 net_pkt_unref(pkt); in ZTEST()
1848 struct net_pkt *pkt; in ZTEST() local
1853 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_3), in ZTEST()
1855 zassert_not_null(pkt, "packet"); in ZTEST()
1857 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1858 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1861 ret = net_pkt_write(pkt, ipv6_hbho_3, sizeof(ipv6_hbho_3)); in ZTEST()
1864 net_pkt_set_overwrite(pkt, true); in ZTEST()
1866 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1872 net_pkt_cursor_init(pkt); in ZTEST()
1873 net_pkt_skip(pkt, next_hdr_pos); in ZTEST()
1874 net_pkt_read_u8(pkt, &next_hdr); in ZTEST()
1878 net_pkt_cursor_init(pkt); in ZTEST()
1879 net_pkt_skip(pkt, last_hdr_pos); in ZTEST()
1880 net_pkt_read_u8(pkt, &last_hdr); in ZTEST()
1884 net_pkt_unref(pkt); in ZTEST()
1891 struct net_pkt *pkt; in ZTEST() local
1894 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_frag), in ZTEST()
1896 zassert_not_null(pkt, "packet"); in ZTEST()
1898 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1899 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1902 ret = net_pkt_write(pkt, ipv6_hbho_frag, sizeof(ipv6_hbho_frag)); in ZTEST()
1905 net_pkt_set_overwrite(pkt, true); in ZTEST()
1907 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1915 zassert_equal(NET_IPV6_HDR(pkt)->nexthdr, 0, "Invalid next header"); in ZTEST()
1916 zassert_equal(pkt->buffer->data[next_hdr_pos], 0x11, in ZTEST()
1919 net_pkt_unref(pkt); in ZTEST()
1926 struct net_pkt *pkt; in ZTEST() local
1931 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_hbho_frag_1), in ZTEST()
1933 zassert_not_null(pkt, "packet"); in ZTEST()
1935 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1936 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1939 ret = net_pkt_write(pkt, ipv6_hbho_frag_1, in ZTEST()
1943 net_pkt_set_overwrite(pkt, true); in ZTEST()
1945 ret = net_ipv6_find_last_ext_hdr(pkt, &next_hdr_pos, &last_hdr_pos); in ZTEST()
1951 net_pkt_cursor_init(pkt); in ZTEST()
1952 net_pkt_skip(pkt, next_hdr_pos); in ZTEST()
1953 net_pkt_read_u8(pkt, &next_hdr); in ZTEST()
1957 net_pkt_cursor_init(pkt); in ZTEST()
1958 net_pkt_skip(pkt, last_hdr_pos); in ZTEST()
1959 net_pkt_read_u8(pkt, &last_hdr); in ZTEST()
1963 net_pkt_unref(pkt); in ZTEST()
1972 struct net_pkt *pkt; in ZTEST() local
1979 pkt = net_pkt_alloc_with_buffer(iface1, in ZTEST()
1982 zassert_not_null(pkt, "packet"); in ZTEST()
1984 net_pkt_set_iface(pkt, iface1); in ZTEST()
1985 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
1986 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
1987 net_pkt_set_ipv6_ext_len(pkt, 8); /* hbho */ in ZTEST()
1990 ret = net_pkt_write(pkt, ipv6_hbho, sizeof(ipv6_hbho)); in ZTEST()
1995 ret = net_pkt_write(pkt, data, data_len); in ZTEST()
2004 total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr); in ZTEST()
2007 total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len); in ZTEST()
2009 zassert_equal(total_len - net_pkt_ipv6_ext_len(pkt) - 8, pkt_data_len, in ZTEST()
2012 NET_IPV6_HDR(pkt)->len = htons(total_len); in ZTEST()
2014 net_pkt_cursor_init(pkt); in ZTEST()
2015 net_pkt_set_overwrite(pkt, true); in ZTEST()
2016 net_pkt_skip(pkt, net_pkt_ip_hdr_len(pkt) + net_pkt_ipv6_ext_len(pkt)); in ZTEST()
2018 net_udp_finalize(pkt, false); in ZTEST()
2023 ret = net_send_data(pkt); in ZTEST()
2037 struct net_pkt *pkt; in ZTEST() local
2045 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_large_hbho), in ZTEST()
2047 zassert_not_null(pkt, "packet"); in ZTEST()
2049 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
2050 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
2051 net_pkt_set_ipv6_ext_len(pkt, 1032); /* hbho */ in ZTEST()
2053 ret = net_pkt_write(pkt, ipv6_large_hbho, sizeof(ipv6_large_hbho)); in ZTEST()
2056 net_pkt_set_overwrite(pkt, true); in ZTEST()
2058 total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr); in ZTEST()
2061 total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len); in ZTEST()
2066 ret = net_send_data(pkt); in ZTEST()
2080 struct net_pkt *pkt; in ZTEST() local
2090 pkt = net_pkt_alloc_with_buffer(iface1, sizeof(ipv6_frag_wo_hbho), in ZTEST()
2092 zassert_not_null(pkt, "packet"); in ZTEST()
2094 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
2095 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
2096 net_pkt_set_ipv6_ext_len(pkt, NET_IPV6_FRAGH_LEN); /* without hbho*/ in ZTEST()
2098 ret = net_pkt_write(pkt, ipv6_frag_wo_hbho, in ZTEST()
2102 net_pkt_set_overwrite(pkt, true); in ZTEST()
2104 total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr) - in ZTEST()
2108 total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len); in ZTEST()
2113 ret = net_send_data(pkt); in ZTEST()
2131 struct net_pkt *pkt; in ZTEST() local
2139 pkt = net_pkt_alloc_with_buffer(iface1, in ZTEST()
2142 zassert_not_null(pkt, "packet"); in ZTEST()
2144 net_pkt_set_iface(pkt, iface1); in ZTEST()
2145 net_pkt_set_family(pkt, AF_INET6); in ZTEST()
2146 net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); in ZTEST()
2147 net_pkt_set_ipv6_ext_len(pkt, 0); in ZTEST()
2150 ret = net_pkt_write(pkt, ipv6_udp, sizeof(ipv6_udp)); in ZTEST()
2155 ret = net_pkt_write(pkt, data, data_len); in ZTEST()
2164 total_len = net_pkt_get_len(pkt) - sizeof(struct net_ipv6_hdr); in ZTEST()
2167 total_len, net_pkt_ipv6_ext_len(pkt), pkt_data_len); in ZTEST()
2169 zassert_equal(total_len - net_pkt_ipv6_ext_len(pkt) - 8, pkt_data_len, in ZTEST()
2172 NET_IPV6_HDR(pkt)->len = htons(total_len); in ZTEST()
2174 net_pkt_cursor_init(pkt); in ZTEST()
2175 net_pkt_set_overwrite(pkt, true); in ZTEST()
2176 net_pkt_skip(pkt, net_pkt_ip_hdr_len(pkt) + net_pkt_ipv6_ext_len(pkt)); in ZTEST()
2178 net_udp_finalize(pkt, false); in ZTEST()
2183 ret = net_send_data(pkt); in ZTEST()
2221 struct net_pkt *pkt, in handle_ipv6_echo_reply() argument
2226 const struct net_ipv6_hdr *hdr = NET_IPV6_HDR(pkt); in handle_ipv6_echo_reply()
2238 NET_DBG("Data %p received", pkt); in handle_ipv6_echo_reply()
2240 zassert_equal(net_pkt_get_len(pkt), expected_pkt_length, "Invalid packet length"); in handle_ipv6_echo_reply()
2259 net_pkt_cursor_init(pkt); in handle_ipv6_echo_reply()
2260 net_pkt_read(pkt, verify_buf, NET_IPV6H_LEN); in handle_ipv6_echo_reply()
2261 net_pkt_read(pkt, verify_buf, ECHO_REPLY_H_LEN); in handle_ipv6_echo_reply()
2266 zassert_equal(net_calc_chksum_icmpv6(pkt), 0, in handle_ipv6_echo_reply()
2275 while (i < net_pkt_get_len(pkt)) { in handle_ipv6_echo_reply()
2278 net_pkt_read_u8(pkt, &data); in handle_ipv6_echo_reply()