Skip to content

Commit

Permalink
tests/net: Fix IPv6 and UDP test as UDP got stricter on checking header
Browse files Browse the repository at this point in the history
Now length of the UDP header is checked, and obviously these test were
avoiding setting it properly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
  • Loading branch information
Tomasz Bursztyka authored and jukkar committed May 30, 2019
1 parent a5b90a4 commit c3c6dfa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
35 changes: 16 additions & 19 deletions tests/net/ipv6/src/main.c
Expand Up @@ -27,6 +27,8 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_IPV6_LOG_LEVEL);
#include "icmpv6.h" #include "icmpv6.h"
#include "ipv6.h" #include "ipv6.h"


#include "udp_internal.h"

#define NET_LOG_ENABLED 1 #define NET_LOG_ENABLED 1
#include "net_private.h" #include "net_private.h"


Expand Down Expand Up @@ -1088,28 +1090,23 @@ static struct net_pkt *setup_ipv6_udp(struct net_if *iface,
return NULL; return NULL;
} }


NET_IPV6_HDR(pkt)->vtc = 0x60; if (net_ipv6_create(pkt, local_addr, remote_addr)) {
NET_IPV6_HDR(pkt)->tcflow = 0U; printk("Cannot create IPv6 pkt %p", pkt);
NET_IPV6_HDR(pkt)->flow = 0U; zassert_true(0, "exiting");
NET_IPV6_HDR(pkt)->len = htons(NET_UDPH_LEN + strlen(payload)); }

NET_IPV6_HDR(pkt)->nexthdr = IPPROTO_UDP;
NET_IPV6_HDR(pkt)->hop_limit = 255U;

net_ipaddr_copy(&NET_IPV6_HDR(pkt)->src, local_addr);
net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, remote_addr);

net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
net_pkt_set_ipv6_ext_len(pkt, 0);

net_buf_add(pkt->buffer, net_pkt_ip_hdr_len(pkt) +
sizeof(struct net_udp_hdr));


NET_UDP_HDR(pkt)->src_port = htons(local_port); if (net_udp_create(pkt, htons(local_port), htons(remote_port))) {
NET_UDP_HDR(pkt)->dst_port = htons(remote_port); printk("Cannot create IPv6 pkt %p", pkt);
zassert_true(0, "exiting");
}


net_buf_add_mem(pkt->buffer, payload, strlen(payload)); if (net_pkt_write(pkt, (u8_t *)payload, strlen(payload))) {
printk("Cannot write IPv6 ext header pkt %p", pkt);
zassert_true(0, "exiting");
}


net_pkt_cursor_init(pkt);
net_ipv6_finalize(pkt, IPPROTO_UDP);
net_pkt_cursor_init(pkt); net_pkt_cursor_init(pkt);


return pkt; return pkt;
Expand Down
5 changes: 4 additions & 1 deletion tests/net/udp/src/main.c
Expand Up @@ -303,6 +303,9 @@ static bool send_ipv6_udp_long_msg(struct net_if *iface,
zassert_true(0, "exiting"); zassert_true(0, "exiting");
} }


net_pkt_set_ipv6_ext_len(pkt, sizeof(ipv6_hop_by_hop_ext_hdr));
net_pkt_set_ipv6_next_hdr(pkt, NET_IPV6_NEXTHDR_HBHO);

if (net_udp_create(pkt, htons(src_port), htons(dst_port))) { if (net_udp_create(pkt, htons(src_port), htons(dst_port))) {
printk("Cannot create IPv6 pkt %p", pkt); printk("Cannot create IPv6 pkt %p", pkt);
zassert_true(0, "exiting"); zassert_true(0, "exiting");
Expand All @@ -314,7 +317,7 @@ static bool send_ipv6_udp_long_msg(struct net_if *iface,
} }


net_pkt_cursor_init(pkt); net_pkt_cursor_init(pkt);
net_ipv6_finalize(pkt, 0); net_ipv6_finalize(pkt, IPPROTO_UDP);


ret = net_recv_data(iface, pkt); ret = net_recv_data(iface, pkt);
if (ret < 0) { if (ret < 0) {
Expand Down

0 comments on commit c3c6dfa

Please sign in to comment.