tests/net: Apply L2 change everywhere where relevant

Many tests use either Ethernet or Dummy L2 and as such require
modifications towards the driver API on their fake devices.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-10-11 21:23:11 +02:00 committed by Anas Nashif
parent 2b3046df70
commit 72e1c2b4c1
25 changed files with 201 additions and 308 deletions

View file

@ -23,6 +23,7 @@
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/dummy.h>
#include <tc_util.h>
@ -201,14 +202,13 @@ static void net_6lo_iface_init(struct net_if *iface)
net_if_set_link_addr(iface, src_mac, 8, NET_LINK_IEEE802154);
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
net_pkt_unref(pkt);
return NET_OK;
return 0;
}
static struct net_if_api net_6lo_if_api = {
.init = net_6lo_iface_init,
static struct dummy_api net_6lo_if_api = {
.iface_api.init = net_6lo_iface_init,
.send = tester_send,
};

View file

@ -17,6 +17,7 @@
#include <net/net_if.h>
#include <net/net_pkt.h>
#include <net/dummy.h>
static struct offload_context {
void *none;
@ -24,8 +25,8 @@ static struct offload_context {
.none = NULL
};
static struct net_if_api offload_if_api = {
.init = NULL,
static struct dummy_api offload_if_api = {
.iface_api.init = NULL,
.send = NULL,
};

View file

@ -19,6 +19,7 @@
#include <ztest.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -105,7 +106,7 @@ static void net_iface_init(struct net_if *iface)
NET_LINK_ETHERNET);
}
static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
static int sender_iface(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -113,27 +114,15 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
}
if (test_started) {
struct net_if_test *data =
net_if_get_device(iface)->driver_data;
struct net_if_test *data = dev->driver_data;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface);
if (net_pkt_iface(pkt) != iface) {
DBG("Invalid interface %p, expecting %p\n",
net_pkt_iface(pkt), iface);
test_failed = true;
}
if (net_if_get_by_iface(iface) != data->idx) {
if (net_if_get_by_iface(net_pkt_iface(pkt)) != data->idx) {
DBG("Invalid interface %d index, expecting %d\n",
data->idx, net_if_get_by_iface(iface));
data->idx, net_if_get_by_iface(net_pkt_iface(pkt)));
test_failed = true;
}
}
net_pkt_unref(pkt);
k_sem_give(&wait_data);
return 0;
@ -141,8 +130,8 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
struct net_if_test net_iface1_data;
static struct net_if_api net_iface_api = {
.init = net_iface_init,
static struct dummy_api net_iface_api = {
.iface_api.init = net_iface_init,
.send = sender_iface,
};

View file

@ -23,6 +23,7 @@
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/dummy.h>
#include <ztest.h>
#include "arp.h"
@ -81,7 +82,7 @@ static void net_arp_iface_init(struct net_if *iface)
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
struct net_eth_hdr *hdr;
@ -118,7 +119,7 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
net_sprint_ll_addr(
(u8_t *)&hdr->dst,
sizeof(struct net_eth_addr)));
printk("Invalid hwaddr %s, should be %s\n",
printk("Invalid dst hwaddr %s, should be %s\n",
out,
net_sprint_ll_addr(
(u8_t *)&hwaddr,
@ -136,7 +137,7 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
net_sprint_ll_addr(
(u8_t *)&hdr->src,
sizeof(struct net_eth_addr)));
printk("Invalid hwaddr %s, should be %s\n",
printk("Invalid src hwaddr %s, should be %s\n",
out,
net_sprint_ll_addr(
(u8_t *)&hwaddr,
@ -146,7 +147,6 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
}
}
}
net_pkt_unref(pkt);
send_status = 0;
@ -296,14 +296,14 @@ struct net_arp_context net_arp_context_data;
#if defined(CONFIG_NET_ARP) && defined(CONFIG_NET_L2_ETHERNET)
static const struct ethernet_api net_arp_if_api = {
.iface_api.init = net_arp_iface_init,
.iface_api.send = tester_send,
.send = tester_send,
};
#define _ETH_L2_LAYER ETHERNET_L2
#define _ETH_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(ETHERNET_L2)
#else
static const struct net_if_api net_arp_if_api = {
.init = net_arp_iface_init,
static const struct dummy_api net_arp_if_api = {
.iface_api.init = net_arp_iface_init,
.send = tester_send,
};
@ -337,7 +337,6 @@ void test_arp(void)
struct net_if_addr *ifaddr;
struct net_arp_hdr *arp_hdr;
struct net_ipv4_hdr *ipv4;
struct net_eth_hdr *eth_hdr;
int len;
struct in_addr dst = { { { 192, 168, 0, 2 } } };
@ -374,9 +373,11 @@ void test_arp(void)
net_pkt_frag_add(pkt, frag);
net_pkt_set_family(pkt, AF_INET);
net_pkt_set_iface(pkt, iface);
setup_eth_header(iface, pkt, &hwaddr, NET_ETH_PTYPE_IP);
net_pkt_lladdr_src(pkt)->addr = (u8_t *)net_if_get_link_addr(iface);
net_pkt_lladdr_src(pkt)->len = sizeof(struct net_eth_addr);
len = strlen(app_data);
@ -418,38 +419,7 @@ void test_arp(void)
pending_pkt = pkt;
/* pkt2 should contain the arp header, verify it */
if (memcmp(net_pkt_ll(pkt2), net_eth_broadcast_addr(),
sizeof(struct net_eth_addr))) {
printk("ARP ETH dest address invalid\n");
net_hexdump("ETH dest wrong ", net_pkt_ll(pkt2),
sizeof(struct net_eth_addr));
net_hexdump("ETH dest correct",
(u8_t *)net_eth_broadcast_addr(),
sizeof(struct net_eth_addr));
zassert_true(0, "exiting");
}
if (memcmp(net_pkt_ll(pkt2) + sizeof(struct net_eth_addr),
net_if_get_link_addr(iface)->addr,
sizeof(struct net_eth_addr))) {
printk("ARP ETH source address invalid\n");
net_hexdump("ETH src correct",
net_if_get_link_addr(iface)->addr,
sizeof(struct net_eth_addr));
net_hexdump("ETH src wrong ",
net_pkt_ll(pkt2) + sizeof(struct net_eth_addr),
sizeof(struct net_eth_addr));
zassert_true(0, "exiting");
}
arp_hdr = NET_ARP_HDR(pkt2);
eth_hdr = NET_ETH_HDR(pkt2);
if (eth_hdr->type != htons(NET_ETH_PTYPE_ARP)) {
printk("ETH type 0x%x, should be 0x%x\n",
eth_hdr->type, htons(NET_ETH_PTYPE_ARP));
zassert_true(0, "exiting");
}
if (arp_hdr->hwtype != htons(NET_ARP_HTYPE_ETH)) {
printk("ARP hwtype 0x%x, should be 0x%x\n",

View file

@ -106,9 +106,9 @@ static void eth_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_tx_offloading_disabled(struct net_if *iface, struct net_pkt *pkt)
static int eth_tx_offloading_disabled(struct device *dev, struct net_pkt *pkt)
{
struct eth_context *context = net_if_get_device(iface)->driver_data;
struct eth_context *context = dev->driver_data;
zassert_equal_ptr(&eth_context_offloading_disabled, context,
"Context pointers do not match (%p vs %p)",
@ -165,8 +165,11 @@ static int eth_tx_offloading_disabled(struct net_if *iface, struct net_pkt *pkt)
pkt->frags->len += net_pkt_ll_reserve(pkt);
net_pkt_set_ll_reserve(pkt, 0);
net_pkt_ref(pkt);
if (net_recv_data(net_pkt_iface(pkt), pkt) < 0) {
test_failed = true;
net_pkt_unref(pkt);
zassert_true(false, "Packet %p receive failed\n", pkt);
}
@ -185,14 +188,12 @@ static int eth_tx_offloading_disabled(struct net_if *iface, struct net_pkt *pkt)
k_sem_give(&wait_data);
}
net_pkt_unref(pkt);
return 0;
}
static int eth_tx_offloading_enabled(struct net_if *iface, struct net_pkt *pkt)
static int eth_tx_offloading_enabled(struct device *dev, struct net_pkt *pkt)
{
struct eth_context *context = net_if_get_device(iface)->driver_data;
struct eth_context *context = dev->driver_data;
zassert_equal_ptr(&eth_context_offloading_enabled, context,
"Context pointers do not match (%p vs %p)",
@ -215,8 +216,6 @@ static int eth_tx_offloading_enabled(struct net_if *iface, struct net_pkt *pkt)
k_sem_give(&wait_data);
}
net_pkt_unref(pkt);
return 0;
}
@ -233,16 +232,16 @@ static enum ethernet_hw_caps eth_offloading_disabled(struct device *dev)
static struct ethernet_api api_funcs_offloading_disabled = {
.iface_api.init = eth_iface_init,
.iface_api.send = eth_tx_offloading_disabled,
.get_capabilities = eth_offloading_disabled,
.send = eth_tx_offloading_disabled,
};
static struct ethernet_api api_funcs_offloading_enabled = {
.iface_api.init = eth_iface_init,
.iface_api.send = eth_tx_offloading_enabled,
.get_capabilities = eth_offloading_enabled,
.send = eth_tx_offloading_enabled,
};
static void generate_mac(u8_t *mac_addr)
@ -768,6 +767,8 @@ static void rx_chksum_offload_disabled_test_v6(void)
NULL);
zassert_equal(ret, 0, "Recv UDP failed (%d)\n", ret);
start_receiving = false;
ret = net_context_sendto(pkt, (struct sockaddr *)&dst_addr6,
sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
@ -831,6 +832,8 @@ static void rx_chksum_offload_disabled_test_v4(void)
NULL);
zassert_equal(ret, 0, "Recv UDP failed (%d)\n", ret);
start_receiving = false;
ret = net_context_sendto(pkt, (struct sockaddr *)&dst_addr4,
sizeof(struct sockaddr_in),
NULL, 0, NULL, NULL);

View file

@ -21,6 +21,7 @@
#include <tc_util.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -968,7 +969,7 @@ static void net_context_iface_init(struct net_if *iface)
NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
struct net_udp_hdr hdr, *udp_hdr;
@ -1019,19 +1020,22 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
udp_hdr->dst_port = port;
net_udp_set_hdr(pkt, udp_hdr);
if (net_recv_data(iface, pkt) < 0) {
if (net_recv_data(net_pkt_iface(pkt), pkt) < 0) {
TC_ERROR("Data receive failed.");
goto out;
}
/* L2 or net_if will unref the pkt, but we are pushing it
* to rx path, so let's reference it or it will be freed.
*/
net_pkt_ref(pkt);
timeout_token = 0;
return 0;
}
out:
net_pkt_unref(pkt);
if (data_failure) {
test_failed = true;
}
@ -1041,8 +1045,8 @@ out:
struct net_context_test net_context_data;
static struct net_if_api net_context_if_api = {
.init = net_context_iface_init,
static struct dummy_api net_context_if_api = {
.iface_api.init = net_context_iface_init,
.send = tester_send,
};

View file

@ -26,6 +26,7 @@
#include <net/ethernet.h>
#include <net/net_mgmt.h>
#include <net/udp.h>
#include <net/dummy.h>
#include <tc_util.h>
#include <ztest.h>
@ -464,7 +465,7 @@ static int parse_dhcp_message(struct net_pkt *pkt, struct dhcp_msg *msg)
return 0;
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
struct net_pkt *rpkt;
struct dhcp_msg msg;
@ -481,13 +482,13 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
if (msg.type == DISCOVER) {
/* Reply with DHCPv4 offer message */
rpkt = prepare_dhcp_offer(iface, msg.xid);
rpkt = prepare_dhcp_offer(net_pkt_iface(pkt), msg.xid);
if (!rpkt) {
return -EINVAL;
}
} else if (msg.type == REQUEST) {
/* Reply with DHCPv4 ACK message */
rpkt = prepare_dhcp_ack(iface, msg.xid);
rpkt = prepare_dhcp_ack(net_pkt_iface(pkt), msg.xid);
if (!rpkt) {
return -EINVAL;
}
@ -497,20 +498,19 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
return -EINVAL;
}
if (net_recv_data(iface, rpkt)) {
if (net_recv_data(net_pkt_iface(rpkt), rpkt)) {
net_pkt_unref(rpkt);
return -EINVAL;
}
net_pkt_unref(pkt);
return NET_OK;
return 0;
}
struct net_dhcpv4_context net_dhcpv4_context_data;
static struct net_if_api net_dhcpv4_if_api = {
.init = net_dhcpv4_iface_init,
static struct dummy_api net_dhcpv4_if_api = {
.iface_api.init = net_dhcpv4_iface_init,
.send = tester_send,
};

View file

@ -53,12 +53,11 @@ static void eth_fake_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_fake_send(struct net_if *iface,
static int eth_fake_send(struct device *dev,
struct net_pkt *pkt)
{
ARG_UNUSED(iface);
net_pkt_unref(pkt);
ARG_UNUSED(dev);
ARG_UNUSED(pkt);
return 0;
}
@ -266,11 +265,11 @@ static int eth_fake_get_config(struct device *dev,
static struct ethernet_api eth_fake_api_funcs = {
.iface_api.init = eth_fake_iface_init,
.iface_api.send = eth_fake_send,
.get_capabilities = eth_fake_get_capabilities,
.set_config = eth_fake_set_config,
.get_config = eth_fake_get_config,
.send = eth_fake_send,
};
static int eth_fake_init(struct device *dev)

View file

@ -23,6 +23,7 @@
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/dummy.h>
#include <tc_util.h>
@ -158,14 +159,13 @@ static void net_fragment_iface_init(struct net_if *iface)
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
net_pkt_unref(pkt);
return NET_OK;
return 0;
}
static struct net_if_api net_fragment_if_api = {
.init = net_fragment_iface_init,
static struct dummy_api net_fragment_if_api = {
.iface_api.init = net_fragment_iface_init,
.send = tester_send,
};

View file

@ -20,6 +20,7 @@
#include <ztest.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -104,7 +105,7 @@ static void net_iface_init(struct net_if *iface)
NET_LINK_ETHERNET);
}
static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
static int sender_iface(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -112,27 +113,19 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
}
if (test_started) {
struct net_if_test *data =
net_if_get_device(iface)->driver_data;
struct net_if_test *data = dev->driver_data;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface);
DBG("Sending at iface %d %p\n",
net_if_get_by_iface(net_pkt_iface(pkt)),
net_pkt_iface(pkt));
if (net_pkt_iface(pkt) != iface) {
DBG("Invalid interface %p, expecting %p\n",
net_pkt_iface(pkt), iface);
test_failed = true;
}
if (net_if_get_by_iface(iface) != data->idx) {
if (net_if_get_by_iface(net_pkt_iface(pkt)) != data->idx) {
DBG("Invalid interface %d index, expecting %d\n",
data->idx, net_if_get_by_iface(iface));
data->idx, net_if_get_by_iface(net_pkt_iface(pkt)));
test_failed = true;
}
}
net_pkt_unref(pkt);
k_sem_give(&wait_data);
return 0;
@ -142,8 +135,8 @@ struct net_if_test net_iface1_data;
struct net_if_test net_iface2_data;
struct net_if_test net_iface3_data;
static struct net_if_api net_iface_api = {
.init = net_iface_init,
static struct dummy_api net_iface_api = {
.iface_api.init = net_iface_init,
.send = sender_iface,
};
@ -208,12 +201,11 @@ static void eth_fake_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_fake_send(struct net_if *iface,
static int eth_fake_send(struct device *dev,
struct net_pkt *pkt)
{
ARG_UNUSED(iface);
net_pkt_unref(pkt);
ARG_UNUSED(dev);
ARG_UNUSED(pkt);
return 0;
}
@ -248,10 +240,10 @@ static int eth_fake_set_config(struct device *dev,
static struct ethernet_api eth_fake_api_funcs = {
.iface_api.init = eth_fake_iface_init,
.iface_api.send = eth_fake_send,
.get_capabilities = eth_fake_get_capabilities,
.set_config = eth_fake_set_config,
.send = eth_fake_send,
};
static int eth_fake_init(struct device *dev)

View file

@ -22,6 +22,7 @@
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/dummy.h>
#define NET_LOG_ENABLED 1
#include "net_private.h"
@ -136,16 +137,15 @@ static void net_test_iface_init(struct net_if *iface)
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
net_pkt_unref(pkt);
return 0;
}
struct net_test_context net_test_context_data;
static struct net_if_api net_test_if_api = {
.init = net_test_iface_init,
static struct dummy_api net_test_if_api = {
.iface_api.init = net_test_iface_init,
.send = tester_send,
};

View file

@ -83,7 +83,7 @@ static const unsigned char icmpv6_ra[] = {
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
/* ICMPv6 RA header starts here */
0x86, 0x00, 0x46, 0x25, 0x40, 0x00, 0x07, 0x08,
0x86, 0x00, 0x8b, 0xaa, 0x40, 0x00, 0x07, 0x08,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
/* SLLAO */
0x01, 0x01, 0x00, 0x60, 0x97, 0x07, 0x69, 0xea,
@ -169,65 +169,37 @@ static void net_test_iface_init(struct net_if *iface)
/**
* @brief IPv6 handle RA message
*/
static struct net_pkt *prepare_ra_message(void)
static void prepare_ra_message(struct net_pkt *pkt)
{
struct ethernet_context *ctx;
struct net_linkaddr lladdr_src;
struct net_linkaddr lladdr_dst;
struct net_pkt *pkt;
struct net_buf *frag, *frag_ll;
struct net_if *iface;
struct net_eth_hdr *hdr;
struct net_buf *frag;
iface = net_if_get_default();
ctx = net_if_l2_data(iface);
/* Let's cleanup the frag entirely */
frag = pkt->frags;
pkt->frags = NULL;
pkt = net_pkt_get_reserve_rx(net_if_get_ll_reserve(iface, NULL),
K_FOREVER);
NET_ASSERT_INFO(pkt, "Out of RX packets");
net_buf_unref(frag);
frag = net_pkt_get_frag(pkt, K_FOREVER);
net_pkt_frag_add(pkt, frag);
net_pkt_set_iface(pkt, iface);
net_pkt_set_family(pkt, AF_INET6);
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
net_pkt_set_ipv6_ext_len(pkt, 0);
hdr = (struct net_eth_hdr *)frag->data;
memset(&hdr->src, 0, sizeof(struct net_eth_addr));
memcpy(&hdr->dst, net_pkt_iface(pkt)->if_dev->link_addr.addr,
sizeof(struct net_eth_addr));
hdr->type = htons(NET_ETH_PTYPE_IPV6);
net_buf_add(frag, sizeof(struct net_eth_hdr));
net_pkt_set_ll_reserve(pkt, 0);
/* First fragment contains now IPv6 header and not ethernet frame
* because ICMPv6 calculation function does not understand ethernet
* header.
*/
memcpy(net_buf_add(frag, sizeof(icmpv6_ra)),
icmpv6_ra, sizeof(icmpv6_ra));
zassert_false(net_icmpv6_set_chksum(pkt) < 0, "Cannot set checksum");
/* Then create ethernet fragment */
frag_ll = net_pkt_get_frag(pkt, K_FOREVER);
lladdr_dst.addr = iface->if_dev->link_addr.addr;
lladdr_dst.len = 6;
lladdr_src.addr = NULL;
lladdr_src.len = 0;
net_pkt_frag_insert(pkt, frag_ll);
net_eth_fill_header(ctx, pkt, htons(NET_ETH_PTYPE_IPV6),
lladdr_src.addr, lladdr_dst.addr);
net_buf_add(frag_ll, net_pkt_ll_reserve(pkt));
net_pkt_compact(pkt);
return pkt;
}
#define NET_ICMP_HDR(pkt) ((struct net_icmp_hdr *)net_pkt_icmp_data(pkt))
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
struct net_icmp_hdr *icmp;
@ -240,10 +212,8 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
/* Reply with RA messge */
if (icmp->type == NET_ICMPV6_RS) {
net_pkt_unref(pkt);
if (expecting_ra) {
pkt = prepare_ra_message();
prepare_ra_message(pkt);
} else {
goto out;
}
@ -251,8 +221,6 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
if (icmp->type == NET_ICMPV6_NS) {
if (expecting_dad) {
net_pkt_unref(pkt);
if (dad_time[0] == 0) {
dad_time[0] = k_uptime_get_32();
} else if (dad_time[1] == 0) {
@ -266,15 +234,19 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
}
/* Feed this data back to us */
if (net_recv_data(iface, pkt) < 0) {
if (net_recv_data(net_pkt_iface(pkt), pkt) < 0) {
TC_ERROR("Data receive failed.");
goto out;
}
/* L2 will unref pkt, so since it got to rx path we need to ref it again
* or it will be freed.
*/
net_pkt_ref(pkt);
return 0;
out:
net_pkt_unref(pkt);
test_failed = true;
return 0;
@ -284,7 +256,7 @@ struct net_test_ipv6 net_test_data;
static const struct ethernet_api net_test_if_api = {
.iface_api.init = net_test_iface_init,
.iface_api.send = tester_send,
.send = tester_send,
};
#define _ETH_L2_LAYER ETHERNET_L2
@ -601,11 +573,14 @@ static void test_ra_message(void)
expecting_ra = false;
zassert_false(!net_if_ipv6_prefix_lookup(net_if_get_default(), &prefix, 32),
"Prefix %s should be here\n", net_sprint_ipv6_addr(&addr));
zassert_false(!net_if_ipv6_prefix_lookup(net_if_get_default(),
&prefix, 32),
"Prefix %s should be here\n",
net_sprint_ipv6_addr(&prefix));
zassert_false(!net_if_ipv6_router_lookup(net_if_get_default(), &addr),
"Router %s should be here\n", net_sprint_ipv6_addr(&addr));
"Router %s should be here\n",
net_sprint_ipv6_addr(&addr));
}
/**

View file

@ -20,6 +20,7 @@
#include <ztest.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -1054,7 +1055,7 @@ large:
return 0;
}
static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
static int sender_iface(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -1062,24 +1063,6 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
}
if (test_started) {
struct net_if_test *data =
net_if_get_device(iface)->driver_data;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface);
if (net_pkt_iface(pkt) != iface) {
DBG("Invalid interface %p, expecting %p\n",
net_pkt_iface(pkt), iface);
test_failed = true;
}
if (net_if_get_by_iface(iface) != data->idx) {
DBG("Invalid interface %d index, expecting %d\n",
data->idx, net_if_get_by_iface(iface));
test_failed = true;
}
/* Verify the fragments */
if (verify_fragment(pkt) < 0) {
DBG("Fragments cannot be verified\n");
@ -1091,16 +1074,14 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
zassert_false(test_failed, "Fragment verify failed");
net_pkt_unref(pkt);
return 0;
}
struct net_if_test net_iface1_data;
struct net_if_test net_iface2_data;
static struct net_if_api net_iface_api = {
.init = net_iface_init,
static struct dummy_api net_iface_api = {
.iface_api.init = net_iface_init,
.send = sender_iface,
};

View file

@ -17,6 +17,7 @@
#include <ztest.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -122,7 +123,7 @@ static inline int get_slot_by_id(struct dns_resolve_context *ctx,
return -1;
}
static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
static int sender_iface(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -130,23 +131,13 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
}
if (!timeout_query) {
struct net_if_test *data =
net_if_get_device(iface)->driver_data;
struct net_if_test *data = dev->driver_data;
struct dns_resolve_context *ctx;
int slot;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface);
if (net_pkt_iface(pkt) != iface) {
DBG("Invalid interface %p, expecting %p\n",
net_pkt_iface(pkt), iface);
test_failed = true;
}
if (net_if_get_by_iface(iface) != data->idx) {
if (net_if_get_by_iface(net_pkt_iface(pkt)) != data->idx) {
DBG("Invalid interface %d index, expecting %d\n",
data->idx, net_if_get_by_iface(iface));
data->idx, net_if_get_by_iface(net_pkt_iface(pkt)));
test_failed = true;
}
@ -178,15 +169,13 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
}
out:
net_pkt_unref(pkt);
return 0;
}
struct net_if_test net_iface1_data;
static struct net_if_api net_iface_api = {
.init = net_iface_init,
static struct dummy_api net_iface_api = {
.iface_api.init = net_iface_init,
.send = sender_iface,
};

View file

@ -13,6 +13,7 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <net/dummy.h>
#include <net/net_mgmt.h>
#include <net/net_pkt.h>
#include <ztest.h>
@ -73,15 +74,13 @@ static void fake_iface_init(struct net_if *iface)
net_if_set_link_addr(iface, mac, 8, NET_LINK_DUMMY);
}
static int fake_iface_send(struct net_if *iface, struct net_pkt *pkt)
static int fake_iface_send(struct device *dev, struct net_pkt *pkt)
{
net_pkt_unref(pkt);
return NET_OK;
return 0;
}
static struct net_if_api fake_iface_api = {
.init = fake_iface_init,
static struct dummy_api fake_iface_api = {
.iface_api.init = fake_iface_init,
.send = fake_iface_send,
};

View file

@ -23,6 +23,7 @@
#include <net/net_ip.h>
#include <net/net_core.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/net_mgmt.h>
#include <net/net_event.h>
@ -97,7 +98,7 @@ static void net_test_iface_init(struct net_if *iface)
#define NET_ICMP_HDR(pkt) ((struct net_icmp_hdr *)net_pkt_icmp_data(pkt))
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
struct net_icmp_hdr *icmp = NET_ICMP_HDR(pkt);
@ -117,15 +118,13 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
k_sem_give(&wait_data);
}
net_pkt_unref(pkt);
return 0;
}
struct net_test_mld net_test_data;
static struct net_if_api net_test_if_api = {
.init = net_test_iface_init,
static struct dummy_api net_test_if_api = {
.iface_api.init = net_test_iface_init,
.send = tester_send,
};

View file

@ -86,12 +86,11 @@ static void eth_fake_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_fake_send(struct net_if *iface,
static int eth_fake_send(struct device *dev,
struct net_pkt *pkt)
{
ARG_UNUSED(iface);
net_pkt_unref(pkt);
ARG_UNUSED(dev);
ARG_UNUSED(pkt);
return 0;
}
@ -126,10 +125,10 @@ static int eth_fake_set_config(struct device *dev,
static struct ethernet_api eth_fake_api_funcs = {
.iface_api.init = eth_fake_iface_init,
.iface_api.send = eth_fake_send,
.get_capabilities = eth_fake_get_capabilities,
.set_config = eth_fake_set_config,
.send = eth_fake_send,
};
static int eth_fake_init(struct device *dev)

View file

@ -91,9 +91,9 @@ static void eth_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
static int eth_tx(struct device *dev, struct net_pkt *pkt)
{
struct eth_context *context = net_if_get_device(iface)->driver_data;
struct eth_context *context = dev->driver_data;
if (&eth_context_1 != context && &eth_context_2 != context) {
zassert_true(false, "Context pointers do not match\n");
@ -105,11 +105,9 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
}
if (test_started) {
k_sem_give(&wait_data);
}
net_pkt_unref(pkt);
return 0;
}
@ -128,10 +126,10 @@ static struct device *eth_get_ptp_clock(struct device *dev)
static struct ethernet_api api_funcs = {
.iface_api.init = eth_iface_init,
.iface_api.send = eth_tx,
.get_capabilities = eth_capabilities,
.get_ptp_clock = eth_get_ptp_clock,
.send = eth_tx,
};
static void generate_mac(u8_t *mac_addr)

View file

@ -21,6 +21,7 @@
#include <tc_util.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -124,7 +125,7 @@ static void net_route_iface_init(struct net_if *iface)
NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
TC_ERROR("No data to send!\n");
@ -136,7 +137,9 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
if (feed_data) {
DBG("Received at iface %p and feeding it into iface %p\n",
iface, recipient);
net_pkt_iface(pkt), recipient);
net_pkt_ref(pkt);
if (net_recv_data(recipient, pkt) < 0) {
TC_ERROR("Data receive failed.");
@ -144,27 +147,23 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
test_failed = true;
}
k_sem_give(&wait_data);
return 0;
goto out;
}
DBG("pkt %p to be sent len %lu\n", pkt, net_pkt_get_len(pkt));
net_pkt_unref(pkt);
if (data_failure) {
test_failed = true;
}
msg_sending = 0;
out:
k_sem_give(&wait_data);
return 0;
}
static int tester_send_peer(struct net_if *iface, struct net_pkt *pkt)
static int tester_send_peer(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
TC_ERROR("No data to send!\n");
@ -176,29 +175,26 @@ static int tester_send_peer(struct net_if *iface, struct net_pkt *pkt)
if (feed_data) {
DBG("Received at iface %p and feeding it into iface %p\n",
iface, recipient);
net_pkt_iface(pkt), recipient);
net_pkt_ref(pkt);
if (net_recv_data(recipient, pkt) < 0) {
TC_ERROR("Data receive failed.");
net_pkt_unref(pkt);
test_failed = true;
}
k_sem_give(&wait_data);
return 0;
goto out;
}
DBG("pkt %p to be sent len %lu\n", pkt, net_pkt_get_len(pkt));
net_pkt_unref(pkt);
if (data_failure) {
test_failed = true;
}
msg_sending = 0;
out:
k_sem_give(&wait_data);
return 0;
@ -207,13 +203,13 @@ static int tester_send_peer(struct net_if *iface, struct net_pkt *pkt)
struct net_route_test net_route_data;
struct net_route_test net_route_data_peer;
static struct net_if_api net_route_if_api = {
.init = net_route_iface_init,
static struct dummy_api net_route_if_api = {
.iface_api.init = net_route_iface_init,
.send = tester_send,
};
static struct net_if_api net_route_if_api_peer = {
.init = net_route_iface_init,
static struct dummy_api net_route_if_api_peer = {
.iface_api.init = net_route_iface_init,
.send = tester_send_peer,
};

View file

@ -21,6 +21,7 @@
#include <tc_util.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_if.h>
@ -125,14 +126,14 @@ static void set_pkt_ll_addr(struct device *dev, struct net_pkt *pkt)
#define NET_ICMP_HDR(pkt) ((struct net_icmp_hdr *)net_pkt_icmp_data(pkt))
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
TC_ERROR("No data to send!\n");
return -ENODATA;
}
set_pkt_ll_addr(net_if_get_device(iface), pkt);
set_pkt_ll_addr(dev, pkt);
/* By default we assume that the test is ok */
data_failure = false;
@ -140,7 +141,8 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
if (feed_data) {
net_pkt_lladdr_swap(pkt);
if (net_recv_data(iface, pkt) < 0) {
net_pkt_ref(pkt);
if (net_recv_data(net_pkt_iface(pkt), pkt) < 0) {
TC_ERROR("Data receive failed.");
net_pkt_unref(pkt);
test_failed = true;
@ -177,19 +179,20 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
if (msg_sending == NET_RPL_DODAG_INFO_OBJ) {
net_pkt_lladdr_swap(pkt);
if (!net_recv_data(iface, pkt)) {
net_pkt_ref(pkt);
if (!net_recv_data(net_pkt_iface(pkt), pkt)) {
/* We must not unref the msg,
* as it should be unfreed by
* the upper stack.
*/
goto out;
}
net_pkt_unref(pkt);
}
}
}
net_pkt_unref(pkt);
out:
if (data_failure) {
test_failed = true;
@ -204,8 +207,8 @@ out:
struct net_rpl_test net_rpl_data;
static struct net_if_api net_rpl_if_api = {
.init = net_rpl_iface_init,
static struct dummy_api net_rpl_if_api = {
.iface_api.init = net_rpl_iface_init,
.send = tester_send,
};

View file

@ -24,6 +24,7 @@
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/tcp.h>
#include <net/dummy.h>
#include <tc_util.h>
@ -95,8 +96,9 @@ static void net_tcp_iface_init(struct net_if *iface)
return;
}
static void v6_send_syn_ack(struct net_if *iface, struct net_pkt *req)
static void v6_send_syn_ack(struct net_pkt *req)
{
struct net_if *iface = net_pkt_iface(req);
struct net_pkt *rsp = NULL;
int ret;
@ -138,7 +140,7 @@ static void v6_send_syn_ack(struct net_if *iface, struct net_pkt *req)
static int send_status = -EINVAL;
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -147,17 +149,15 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
if (syn_v6_sent && net_pkt_family(pkt) == AF_INET6) {
DBG("v6 SYN was sent successfully\n");
syn_v6_sent = false;
v6_send_syn_ack(iface, pkt);
v6_send_syn_ack(pkt);
}
net_pkt_unref(pkt);
send_status = 0;
return 0;
}
static int tester_send_peer(struct net_if *iface, struct net_pkt *pkt)
static int tester_send_peer(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -166,8 +166,6 @@ static int tester_send_peer(struct net_if *iface, struct net_pkt *pkt)
DBG("Peer data was sent successfully\n");
net_pkt_unref(pkt);
return 0;
}
@ -1308,13 +1306,13 @@ static bool test_create_v6_data_packet(void)
struct net_tcp_context net_tcp_context_data;
struct net_tcp_context net_tcp_context_data_peer;
static struct net_if_api net_tcp_if_api = {
.init = net_tcp_iface_init,
static struct dummy_api net_tcp_if_api = {
.iface_api.init = net_tcp_iface_init,
.send = tester_send,
};
static struct net_if_api net_tcp_if_api_peer = {
.init = net_tcp_iface_init,
static struct dummy_api net_tcp_if_api_peer = {
.iface_api.init = net_tcp_iface_init,
.send = tester_send_peer,
};
@ -1660,7 +1658,7 @@ static bool test_init(void)
{
struct net_if *iface = net_if_get_default();
struct net_if_addr *ifaddr;
const struct net_if_api *api;
const struct dummy_api *api;
if (!iface) {
TC_ERROR("Interface is NULL\n");

View file

@ -20,6 +20,7 @@
#include <ztest.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/net_l2.h>
@ -151,7 +152,7 @@ static bool check_higher_priority_pkt_recv(int tc, struct net_pkt *pkt)
/* The eth_tx() will handle both sent packets or and it will also
* simulate the receiving of the packets.
*/
static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
static int eth_tx(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -180,8 +181,11 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
udp_hdr->src_port = udp_hdr->dst_port;
udp_hdr->dst_port = port;
net_pkt_ref(pkt);
if (net_recv_data(net_pkt_iface(pkt), pkt) < 0) {
test_failed = true;
net_pkt_unref(pkt);
zassert_true(false, "Packet %p receive failed\n", pkt);
}
@ -229,13 +233,11 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
}
fail:
net_pkt_unref(pkt);
return 0;
}
static struct net_if_api api_funcs = {
.init = eth_iface_init,
static struct dummy_api api_funcs = {
.iface_api.init = eth_iface_init,
.send = eth_tx,
};

View file

@ -23,6 +23,7 @@
#include <net/net_ip.h>
#include <net/net_pkt.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/net_l2.h>
#include "ipv6.h"
@ -94,7 +95,7 @@ static void eth_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
static int eth_tx(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -112,7 +113,6 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
}
}
net_pkt_unref(pkt);
test_started = false;
return 0;
@ -125,9 +125,9 @@ static enum ethernet_hw_caps eth_get_capabilities(struct device *dev)
static struct ethernet_api api_funcs = {
.iface_api.init = eth_iface_init,
.iface_api.send = eth_tx,
.get_capabilities = eth_get_capabilities,
.send = eth_tx,
};
static void generate_mac(u8_t *mac_addr)

View file

@ -25,6 +25,7 @@
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/udp.h>
#include <ztest.h>
@ -87,7 +88,7 @@ static void net_udp_iface_init(struct net_if *iface)
static int send_status = -EINVAL;
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
static int tester_send(struct device *dev, struct net_pkt *pkt)
{
if (!pkt->frags) {
DBG("No data to send!\n");
@ -96,8 +97,6 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
DBG("Data was sent successfully\n");
net_pkt_unref(pkt);
send_status = 0;
return 0;
@ -123,8 +122,8 @@ static inline struct in_addr *if_get_addr(struct net_if *iface)
struct net_udp_context net_udp_context_data;
static struct net_if_api net_udp_if_api = {
.init = net_udp_iface_init,
static struct dummy_api net_udp_if_api = {
.iface_api.init = net_udp_iface_init,
.send = tester_send,
};

View file

@ -20,6 +20,7 @@
#include <ztest.h>
#include <net/ethernet.h>
#include <net/dummy.h>
#include <net/buf.h>
#include <net/net_ip.h>
#include <net/ethernet_vlan.h>
@ -102,9 +103,9 @@ static void eth_vlan_iface_init(struct net_if *iface)
ethernet_init(iface);
}
static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
static int eth_tx(struct device *dev, struct net_pkt *pkt)
{
struct eth_context *context = net_if_get_device(iface)->driver_data;
struct eth_context *context = dev->driver_data;
zassert_equal_ptr(&eth_vlan_context, context,
"Context pointers do not match (%p vs %p)",
@ -132,8 +133,6 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
k_sem_give(&wait_data);
}
net_pkt_unref(pkt);
return 0;
}
@ -144,9 +143,9 @@ static enum ethernet_hw_caps eth_capabilities(struct device *dev)
static struct ethernet_api api_funcs = {
.iface_api.init = eth_vlan_iface_init,
.iface_api.send = eth_tx,
.get_capabilities = eth_capabilities,
.send = eth_tx,
};
static void generate_mac(u8_t *mac_addr)
@ -229,18 +228,16 @@ static void net_iface_init(struct net_if *iface)
NET_LINK_ETHERNET);
}
static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
static int sender_iface(struct device *dev, struct net_pkt *pkt)
{
net_pkt_unref(pkt);
return 0;
}
struct net_if_test net_iface1_data;
struct net_if_test net_iface2_data;
static struct net_if_api net_iface_api = {
.init = net_iface_init,
static struct dummy_api net_iface_api = {
.iface_api.init = net_iface_init,
.send = sender_iface,
};