net/dummy: Switch to L2 sending path

And adapt loopback and slip drivers relevantly

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-10-11 10:49:11 +02:00 committed by Anas Nashif
commit 7f2cb02720
4 changed files with 77 additions and 18 deletions

View file

@ -22,8 +22,12 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <net/net_ip.h>
#include <net/net_if.h>
#include <net/dummy.h>
int loopback_dev_init(struct device *dev)
{
ARG_UNUSED(dev);
return 0;
}
@ -34,11 +38,13 @@ static void loopback_init(struct net_if *iface)
NET_LINK_DUMMY);
}
static int loopback_send(struct net_if *iface, struct net_pkt *pkt)
static int loopback_send(struct device *dev, struct net_pkt *pkt)
{
struct net_pkt *cloned;
int res;
ARG_UNUSED(dev);
if (!pkt->frags) {
LOG_ERR("No data to send");
return -ENODATA;
@ -75,14 +81,11 @@ static int loopback_send(struct net_if *iface, struct net_pkt *pkt)
goto out;
}
res = net_recv_data(iface, cloned);
res = net_recv_data(net_pkt_iface(cloned), cloned);
if (res < 0) {
LOG_ERR("Data receive failed.");
goto out;
}
net_pkt_unref(pkt);
out:
/* Let the receiving thread run now */
k_yield();
@ -90,13 +93,14 @@ out:
return res;
}
static struct net_if_api loopback_if_api = {
.init = loopback_init,
static struct dummy_api loopback_api = {
.iface_api.init = loopback_init,
.send = loopback_send,
};
NET_DEVICE_INIT(loopback, "lo",
loopback_dev_init, NULL, NULL,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&loopback_if_api, DUMMY_L2,
&loopback_api, DUMMY_L2,
NET_L2_GET_CTX_TYPE(DUMMY_L2), 536);

View file

@ -135,7 +135,7 @@ static void slip_writeb_esc(unsigned char c)
}
}
static int slip_send(struct net_if *iface, struct net_pkt *pkt)
static int slip_send(struct device *dev, struct net_pkt *pkt)
{
struct net_buf *frag;
#if defined(CONFIG_SLIP_TAP)
@ -146,6 +146,8 @@ static int slip_send(struct net_if *iface, struct net_pkt *pkt)
u16_t i;
u8_t c;
ARG_UNUSED(dev);
if (!pkt->frags) {
/* No data? */
return -ENODATA;
@ -164,7 +166,8 @@ static int slip_send(struct net_if *iface, struct net_pkt *pkt)
}
}
if (net_if_get_mtu(iface) > net_buf_headroom(frag)) {
if (net_if_get_mtu(net_pkt_iface(pkt)) >
net_buf_headroom(frag)) {
/* Do not add link layer header if the mtu is bigger
* than fragment size. The first packet needs the
* link layer header always.
@ -203,7 +206,6 @@ static int slip_send(struct net_if *iface, struct net_pkt *pkt)
}
}
net_pkt_unref(pkt);
slip_writeb(SLIP_END);
return 0;
@ -507,9 +509,9 @@ static enum ethernet_hw_caps eth_capabilities(struct device *dev)
#if defined(CONFIG_SLIP_TAP) && defined(CONFIG_NET_L2_ETHERNET)
static const struct ethernet_api slip_if_api = {
.iface_api.init = slip_iface_init,
.iface_api.send = slip_send,
.get_capabilities = eth_capabilities,
.send = slip_send,
};
#define _SLIP_L2_LAYER ETHERNET_L2
@ -521,8 +523,9 @@ ETH_NET_DEVICE_INIT(slip, CONFIG_SLIP_DRV_NAME, slip_init, &slip_context_data,
_SLIP_MTU);
#else
static const struct net_if_api slip_if_api = {
.init = slip_iface_init,
static const struct dummy_api slip_if_api = {
.iface_init.init = slip_iface_init,
.send = slip_send,
};

44
include/net/dummy.h Normal file
View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_NET_DUMMY_H_
#define ZEPHYR_INCLUDE_NET_DUMMY_H_
#include <net/net_if.h>
#include <net/net_pkt.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Dummy L2/driver support functions
* @defgroup dummy Dummy L2/driver Support Functions
* @ingroup networking
* @{
*/
struct dummy_api {
/**
* The net_if_api must be placed in first position in this
* struct so that we are compatible with network interface API.
*/
struct net_if_api iface_api;
/** Send a network packet */
int (*send)(struct device *dev, struct net_pkt *pkt);
};
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_NET_DUMMY_H_ */

View file

@ -12,6 +12,8 @@
#include <net/net_if.h>
#include <net/net_pkt.h>
#include <net/dummy.h>
static inline enum net_verdict dummy_recv(struct net_if *iface,
struct net_pkt *pkt)
{
@ -25,12 +27,18 @@ static inline enum net_verdict dummy_recv(struct net_if *iface,
return NET_CONTINUE;
}
static inline enum net_verdict dummy_send(struct net_if *iface,
struct net_pkt *pkt)
static inline int dummy_send(struct net_if *iface, struct net_pkt *pkt)
{
net_if_queue_tx(iface, pkt);
const struct dummy_api *api = net_if_get_device(iface)->driver_api;
int ret;
return NET_OK;
ret = api->send(net_if_get_device(iface), pkt);
if (!ret) {
ret = net_pkt_get_len(pkt);
net_pkt_unref(pkt);
}
return ret;
}
static inline u16_t dummy_reserve(struct net_if *iface, void *unused)