Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d5222f6
net/pkt: Add dummy getter/setters for IPv4/IPv6 attributes
Nov 26, 2018
cecd4c4
net/pkt: Add new allocators
Nov 23, 2018
8e859dd
net/pkt: Add an API to read/write into the buffer in a simpler way
Nov 26, 2018
881ebea
net/pkt: Add generic get/set data functions
Nov 27, 2018
f62f755
net/ipv4: Add new API to create/finalize IPv4 headers.
Nov 27, 2018
d97b466
net/udp: Add new API to create/finalize UDP headers
Nov 27, 2018
0f1b031
net/icmpv4: Switch echo request to new net pkt allocator and API
Nov 27, 2018
7c8d675
drivers/ethernet: Use new net_pkt API for sending and receiving
Nov 27, 2018
2f7a89d
net/dhcpv4: Switch to new net_pkt API
Nov 29, 2018
5bd6cf6
net: Adapt checksum calculation to new net_pkt API
Dec 3, 2018
04c3eb6
net/core: Each and every received packet are being set to overwrite
Dec 5, 2018
b086db8
net/core: Set cursor relevantly
Dec 12, 2018
b88b5fd
net/ipv4: Input headers are gathered through new API
Dec 11, 2018
5e81334
net/icmpv4: Input headers are gathered through new API
Dec 11, 2018
dca2c19
net/icmpv4: Add a new function to finalize the ICMPv4 packet
Dec 11, 2018
50e2059
net/icmpv4: Rework relevant signatures to pass ipv4 header pointer
Dec 11, 2018
fb4917e
net/icmpv4: Switch echo request handler to new API
Dec 11, 2018
33f82b0
net/icmpv4: Switch error message to new API
Dec 11, 2018
574d58e
net/icmpv4: Remove useless create, get and set header functions
Dec 11, 2018
f63df4e
net/context: Create new send sendto functions using new net_pkt API
Dec 13, 2018
cef38c4
net/sockets: Use the new send/sendto from net_context
Dec 14, 2018
6d40a8d
net/udp: Add an input function
Dec 13, 2018
f375075
net/tcp: Add an input function for pre-validation
Dec 13, 2018
8b3ca29
net/connection: Modify input function
Dec 13, 2018
8a75403
net/ipv4: Rework input function
Dec 13, 2018
c5601df
tests/net: Avoid using net_udp_get_chksum()
Dec 17, 2018
5069768
net/udp: Remove now useless net_udp_get_chksum function
Dec 17, 2018
48d6cb5
net/icmpv6: Add a new function to finalize the ICMPv6 packet
Dec 17, 2018
f5bfaff
net/ipv6: Add new API to create/finalize IPv6 headers.
Dec 17, 2018
e87cb7d
net/pkt: Use next_hdr field only for IPv6
Jan 25, 2019
895d91a
net/ipv6: Account for extension headers when finalizing
Jan 28, 2019
2ffabb2
net/icmpv6: Switch echo request to new net pkt allocator and API
Dec 17, 2018
ed2d19a
net/ipv6: Rework input function
Dec 18, 2018
6be52d2
net/icmpv6: Rework relevant signatures to pass ipv6 header pointer
Dec 18, 2018
49aaaa3
net/icmpv6: Switch echo request handler to new API
Dec 18, 2018
67fa056
net/icmpv6: Switch error message to new API
Dec 19, 2018
071ac16
net/context: Add support for IPv6 on the new send/sendto functions
Dec 19, 2018
49d8bdd
net/icmpv6: Make header creation function public
Dec 20, 2018
b5f140a
net/ipv6: Switch NA msg sending to new net_pkt API
Dec 20, 2018
b3aa094
net/ipv6: Switch NS msg sending to new net_pkt API
Dec 20, 2018
d2dba81
net/ipv6: Switch RS msg sending to new net_pkt API
Dec 20, 2018
d7d344e
net/ipv6: Removing useless macros in nbr code
Dec 20, 2018
103f453
net/icmpv6: Improve callback signature to pass icmp header
Dec 20, 2018
dcf8034
net/ipv6: Switch NA msg handler to new net_pkt API
Dec 20, 2018
8b26a74
net/ipv6: Switch NS msg handler to new net_pkt API
Dec 20, 2018
046e08c
net/ipv6: Switch RA msg handler to new net_pkt API
Dec 20, 2018
c8818ea
net/ipv6: Switch MLD query msg handler to new net_pkt API
Dec 21, 2018
dd976c2
net/icmpv6: Remove various useless get/set hdr functions
Dec 20, 2018
96d00cb
net/ipv6: Switch IPv6 sending preparation to new net_pkt API
Dec 21, 2018
f491728
net/ipv6: Switch MLD join, leave and report to new net_pkt API
Dec 21, 2018
fb9c76d
net/ipv6: Re-enable support for fragmented packet at input
Jan 9, 2019
510f769
net/ipv6: Switch sending fragmented IPv6 packet to new API
Jan 10, 2019
3dad861
net/ipv4: Move autoconf to new net_pkt API
Jan 11, 2019
27d464e
net/arp: Switch ARP to new net_pkt API
Jan 11, 2019
b580d6a
net/gptp: Switch GPTP to new net_pkt API
Jan 11, 2019
dd15518
net/pkt: Add a marker to identify LLDP message
Jan 11, 2019
74ae9c6
net/lldp: Fix where Ethernet PTYPE is set for LLDP message
Jan 11, 2019
22cbf3f
net/lldp: Switch LLDP to new net_pkt API
Jan 11, 2019
f8eae38
net/context: Expose new functions to create ipv4/6 packet from context
Jan 14, 2019
c775fd8
net/tcp: Switch TCP segment preparation to new net_pkt API
Jan 14, 2019
7035c8a
net/conn: Change callback signature to pass TCP/IP headers
Jan 14, 2019
2cbf1d0
net/tcp: Apply connection callback signature change
Jan 14, 2019
0143e4c
net/tcp: Switch rest of TCP to new net_pkt API
Jan 15, 2019
51d24c2
tests/icmpv6: Real packet length must be given
Jan 16, 2019
ff9d543
net/context: Enable support for TCP on new sendto function
Jan 18, 2019
e0b5340
net/tcp: Fix net_tcp_print_recv/send_info macros
Jan 18, 2019
4e0eba9
test/net: Quick sample explaining/testing the new net_pkt buffer API
Oct 3, 2018
8e01acc
net/pkt: Add a debug option to track free pkt access more easily
Jan 24, 2019
bb50b7a
net/ip: Let's make public the 2 utility unions for ip/proto headers
Jan 30, 2019
76fc11e
net/context: Make recv_cb providing the ip and protocol headers
Jan 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drivers/console/telnet_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ static inline void telnet_handle_input(struct net_pkt *pkt)

static void telnet_recv(struct net_context *client,
struct net_pkt *pkt,
union net_ip_header *ip_hdr,
union net_proto_header *proto_hdr,
int status,
void *user_data)
{
Expand Down
6 changes: 3 additions & 3 deletions drivers/ethernet/eth_dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ static void eth_rx(struct device *dev)
frm_len -= sizeof(u32_t);
}

pkt = net_pkt_get_reserve_rx(K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(context->iface, frm_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("Failed to obtain RX buffer");
goto error;
}

if (!net_pkt_append_all(pkt, frm_len, (u8_t *)context->rx_buf,
K_NO_WAIT)) {
if (net_pkt_write_new(pkt, (void *)context->rx_buf, frm_len)) {
LOG_ERR("Failed to append RX buffer to context buffer");
net_pkt_unref(pkt);
goto error;
Expand Down
30 changes: 11 additions & 19 deletions drivers/ethernet/eth_e1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ static enum ethernet_hw_caps e1000_caps(struct device *dev)
ETHERNET_LINK_1000BASE_T;
}

static size_t e1000_linearize(struct net_pkt *pkt, void *buf, size_t bufsize)
{
size_t len = 0;
struct net_buf *nb;

for (nb = pkt->frags; nb; nb = nb->frags) {
memcpy((u8_t *) buf + len, nb->data, nb->len);
len += nb->len;
}

return len;
}

static int e1000_tx(struct e1000_dev *dev, void *data, size_t data_len)
{
dev->tx.addr = POINTER_TO_INT(data);
Expand All @@ -83,7 +70,11 @@ static int e1000_tx(struct e1000_dev *dev, void *data, size_t data_len)
static int e1000_send(struct device *device, struct net_pkt *pkt)
{
struct e1000_dev *dev = device->driver_data;
size_t len = e1000_linearize(pkt, dev->txb, sizeof(dev->txb));
size_t len = net_pkt_get_len(pkt);

if (net_pkt_read_new(pkt, dev->txb, len)) {
return -EIO;
}

return e1000_tx(dev, dev->txb, len);
}
Expand All @@ -99,19 +90,20 @@ static struct net_pkt *e1000_rx(struct e1000_dev *dev)
goto out;
}

pkt = net_pkt_get_reserve_rx(K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(dev->iface, dev->rx.len - 4,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("Out of RX buffers");
LOG_ERR("Out of buffers");
goto out;
}

if (!net_pkt_append_all(pkt, dev->rx.len - 4,
INT_TO_POINTER((u32_t) dev->rx.addr),
K_NO_WAIT)) {
if (net_pkt_write_new(pkt, INT_TO_POINTER((u32_t) dev->rx.addr),
dev->rx.len - 4)) {
LOG_ERR("Out of memory for received frame");
net_pkt_unref(pkt);
pkt = NULL;
}

out:
return pkt;
}
Expand Down
30 changes: 9 additions & 21 deletions drivers/ethernet/eth_enc28j60.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ static int eth_enc28j60_rx(struct device *dev)

do {
struct net_buf *pkt_buf = NULL;
struct net_buf *last_buf = NULL;
u16_t frm_len = 0U;
u8_t info[RSV_SIZE];
struct net_pkt *pkt;
Expand Down Expand Up @@ -538,36 +537,22 @@ static int eth_enc28j60_rx(struct device *dev)
lengthfr = frm_len;

/* Get the frame from the buffer */
pkt = net_pkt_get_reserve_rx(config->timeout);
pkt = net_pkt_rx_alloc_with_buffer(context->iface, frm_len,
AF_UNSPEC, 0,
config->timeout);
if (!pkt) {
LOG_ERR("Could not allocate rx buffer");
eth_stats_update_errors_rx(context->iface);
goto done;
}

pkt_buf = pkt->buffer;

do {
size_t frag_len;
u8_t *data_ptr;
size_t spi_frame_len;

/* Reserve a data frag to receive the frame */
pkt_buf = net_pkt_get_frag(pkt, config->timeout);
if (!pkt_buf) {
LOG_ERR("Could not allocate data buffer");
eth_stats_update_errors_rx(context->iface);
net_pkt_unref(pkt);

goto done;
}

if (!last_buf) {
net_pkt_frag_insert(pkt, pkt_buf);
} else {
net_buf_frag_insert(last_buf, pkt_buf);
}

last_buf = pkt_buf;

data_ptr = pkt_buf->data;

/* Review the space available for the new frag */
Expand All @@ -585,6 +570,7 @@ static int eth_enc28j60_rx(struct device *dev)

/* One fragment has been written via SPI */
frm_len -= spi_frame_len;
pkt_buf = pkt_buf->frags;
} while (frm_len > 0);

/* Let's pop the useless CRC */
Expand All @@ -599,7 +585,9 @@ static int eth_enc28j60_rx(struct device *dev)

/* Feed buffer frame to IP stack */
LOG_DBG("Received packet of length %u", lengthfr);
net_recv_data(context->iface, pkt);
if (net_recv_data(context->iface, pkt) < 0) {
net_pkt_unref(pkt);
}
done:
/* Free buffer memory and decrement rx counter */
eth_enc28j60_set_bank(dev, ENC28J60_REG_ERXRDPTL);
Expand Down
64 changes: 15 additions & 49 deletions drivers/ethernet/eth_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,30 +490,23 @@ static bool eth_get_ptp_data(struct net_if *iface, struct net_pkt *pkt,
static int eth_tx(struct device *dev, struct net_pkt *pkt)
{
struct eth_context *context = dev->driver_data;
const struct net_buf *frag;
u8_t *dst;
u16_t total_len = net_pkt_get_len(pkt);
status_t status;
unsigned int imask;
#if defined(CONFIG_PTP_CLOCK_MCUX)
bool timestamped_frame;
#endif

u16_t total_len = net_pkt_get_len(pkt);

k_sem_take(&context->tx_buf_sem, K_FOREVER);

/* As context->frame_buf is shared resource used by both eth_tx
* and eth_rx, we need to protect it with irq_lock.
*/
imask = irq_lock();

/* Copy the fragments */
dst = context->frame_buf;
frag = pkt->frags;
while (frag) {
memcpy(dst, frag->data, frag->len);
dst += frag->len;
frag = frag->frags;
if (net_pkt_read_new(pkt, context->frame_buf, total_len)) {
irq_unlock(imask);
return -EIO;
}

/* FIXME: Dirty workaround.
Expand Down Expand Up @@ -559,13 +552,11 @@ static int eth_tx(struct device *dev, struct net_pkt *pkt)
static void eth_rx(struct device *iface)
{
struct eth_context *context = iface->driver_data;
struct net_buf *prev_buf;
struct net_pkt *pkt;
const u8_t *src;
u16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
u32_t frame_length = 0U;
struct net_pkt *pkt;
status_t status;
unsigned int imask;
u16_t vlan_tag = NET_VLAN_TAG_UNSPEC;

#if defined(CONFIG_PTP_CLOCK_MCUX)
enet_ptp_time_data_t ptpTimeData;
Expand All @@ -588,7 +579,9 @@ static void eth_rx(struct device *iface)
goto flush;
}

pkt = net_pkt_get_reserve_rx(K_NO_WAIT);
/* Using root iface. It will be updated in net_recv_data() */
pkt = net_pkt_rx_alloc_with_buffer(context->iface, frame_length,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
goto flush;
}
Expand All @@ -607,39 +600,12 @@ static void eth_rx(struct device *iface)
goto error;
}

src = context->frame_buf;
prev_buf = NULL;
do {
struct net_buf *pkt_buf;
size_t frag_len;

pkt_buf = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!pkt_buf) {
irq_unlock(imask);
LOG_ERR("Failed to get fragment buf");
net_pkt_unref(pkt);
assert(status == kStatus_Success);
goto error;
}

if (!prev_buf) {
net_pkt_frag_insert(pkt, pkt_buf);
} else {
net_buf_frag_insert(prev_buf, pkt_buf);
}

prev_buf = pkt_buf;

frag_len = net_buf_tailroom(pkt_buf);
if (frag_len > frame_length) {
frag_len = frame_length;
}

memcpy(pkt_buf->data, src, frag_len);
net_buf_add(pkt_buf, frag_len);
src += frag_len;
frame_length -= frag_len;
} while (frame_length > 0);
if (net_pkt_write_new(pkt, context->frame_buf, frame_length)) {
irq_unlock(imask);
LOG_ERR("Unable to write frame into the pkt");
net_pkt_unref(pkt);
goto error;
}

#if defined(CONFIG_NET_VLAN)
{
Expand Down
43 changes: 13 additions & 30 deletions drivers/ethernet/eth_native_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,12 @@ static void update_gptp(struct net_if *iface, struct net_pkt *pkt,
static int eth_send(struct device *dev, struct net_pkt *pkt)
{
struct eth_context *ctx = dev->driver_data;
struct net_buf *frag;
int count = 0;
int count = net_pkt_get_len(pkt);
int ret;

frag = pkt->frags;
while (frag) {
memcpy(ctx->send + count, frag->data, frag->len);
count += frag->len;
frag = frag->frags;
ret = net_pkt_read_new(pkt, ctx->send, count);
if (ret) {
return ret;
}

update_gptp(net_pkt_iface(pkt), pkt, true);
Expand Down Expand Up @@ -269,37 +266,24 @@ static inline struct net_if *get_iface(struct eth_context *ctx,
static int read_data(struct eth_context *ctx, int fd)
{
u16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
int count = 0;
struct net_if *iface;
struct net_pkt *pkt;
struct net_buf *frag;
u32_t pkt_len;
int ret;
int count;

ret = eth_read_data(fd, ctx->recv, sizeof(ctx->recv));
if (ret <= 0) {
count = eth_read_data(fd, ctx->recv, sizeof(ctx->recv));
if (count <= 0) {
return 0;
}

pkt = net_pkt_get_reserve_rx(NET_BUF_TIMEOUT);
pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, count,
AF_UNSPEC, 0, NET_BUF_TIMEOUT);
if (!pkt) {
return -ENOMEM;
}

do {
frag = net_pkt_get_frag(pkt, NET_BUF_TIMEOUT);
if (!frag) {
net_pkt_unref(pkt);
return -ENOMEM;
}

net_pkt_frag_add(pkt, frag);

net_buf_add_mem(frag, ctx->recv + count,
min(net_buf_tailroom(frag), ret));
ret -= frag->len;
count += frag->len;
} while (ret > 0);
if (net_pkt_write_new(pkt, ctx->recv, count)) {
return -ENOBUFS;
}

#if defined(CONFIG_NET_VLAN)
{
Expand All @@ -325,9 +309,8 @@ static int read_data(struct eth_context *ctx, int fd)
#endif

iface = get_iface(ctx, vlan_tag);
pkt_len = net_pkt_get_len(pkt);

LOG_DBG("Recv pkt %p len %d", pkt, pkt_len);
LOG_DBG("Recv pkt %p len %d", pkt, count);

update_gptp(iface, pkt, false);

Expand Down
14 changes: 6 additions & 8 deletions drivers/ethernet/eth_stm32_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static int eth_tx(struct device *dev, struct net_pkt *pkt)
ETH_HandleTypeDef *heth;
u8_t *dma_buffer;
int res;
struct net_buf *frag;
u16_t total_len;
__IO ETH_DMADescTypeDef *dma_tx_desc;

Expand All @@ -88,11 +87,9 @@ static int eth_tx(struct device *dev, struct net_pkt *pkt)

dma_buffer = (u8_t *)(dma_tx_desc->Buffer1Addr);

frag = pkt->frags;
while (frag) {
memcpy(dma_buffer, frag->data, frag->len);
dma_buffer += frag->len;
frag = frag->frags;
if (net_pkt_read_new(pkt, dma_buffer, total_len)) {
res = -EIO;
goto error;
}

if (HAL_ETH_TransmitFrame(heth, total_len) != HAL_OK) {
Expand Down Expand Up @@ -146,13 +143,14 @@ static struct net_pkt *eth_rx(struct device *dev)
total_len = heth->RxFrameInfos.length;
dma_buffer = (u8_t *)heth->RxFrameInfos.buffer;

pkt = net_pkt_get_reserve_rx(K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(dev_data->iface, total_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("Failed to obtain RX buffer");
goto release_desc;
}

if (!net_pkt_append_all(pkt, total_len, dma_buffer, K_NO_WAIT)) {
if (net_pkt_write_new(pkt, dma_buffer, total_len)) {
LOG_ERR("Failed to append RX buffer to context buffer");
net_pkt_unref(pkt);
pkt = NULL;
Expand Down
3 changes: 2 additions & 1 deletion drivers/modem/wncm14a2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@ static void sockreadrecv_cb_work(struct k_work *work)
pkt = sock->recv_pkt;
sock->recv_pkt = NULL;
if (sock->recv_cb) {
sock->recv_cb(sock->context, pkt, 0, sock->recv_user_data);
sock->recv_cb(sock->context, pkt, NULL, NULL,
0, sock->recv_user_data);
} else {
net_pkt_unref(pkt);
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/wifi/eswifi/eswifi_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ static void eswifi_off_read_work(struct k_work *work)
LOG_WRN("Incomplete buffer copy");
}

socket->recv_cb(socket->context, pkt, 0, socket->user_data);
socket->recv_cb(socket->context, pkt,
NULL, NULL, 0, socket->user_data);
k_sem_give(&socket->read_sem);
k_yield();

Expand Down
Loading