net/net_pkt: Fully separate struct net_pkt from struct net_buf

- net_pkt becomes a stand-alone structure with network packet meta
  information.
- network packet data is still managed through net_buf, mostly named
  'frag'.
- net_pkt memory management is done through k_mem_slab
- function got introduced or relevantly renamed to target eithe net_pkt
  or net_buf fragments.
- net_buf's sent_list ends up in net_pkt now, and thus helps to save
  memory when TCP is enabled.

Change-Id: Ibd5c17df4f75891dec79db723a4c9fc704eb843d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2017-04-05 08:37:44 +02:00 committed by Jukka Rissanen
commit db11fcd174
122 changed files with 5510 additions and 5480 deletions

View file

@ -80,7 +80,7 @@ static K_TIMER_DEFINE(send_timer, telnet_send_prematurely, NULL);
/* For now we handle a unique telnet client connection */
static struct net_context *client_cnx;
static struct net_buf *out_buf;
static struct net_pkt *out_pkt;
static int (*orig_printk_hook)(int);
static struct k_fifo *avail_queue;
@ -116,17 +116,17 @@ static void telnet_end_client_connection(void)
net_context_put(client_cnx);
client_cnx = NULL;
if (out_buf) {
net_buf_unref(out_buf);
if (out_pkt) {
net_pkt_unref(out_pkt);
}
telnet_rb_init();
}
static int telnet_setup_out_buf(struct net_context *client)
static int telnet_setup_out_pkt(struct net_context *client)
{
out_buf = net_pkt_get_tx(client, K_FOREVER);
if (!out_buf) {
out_pkt = net_pkt_get_tx(client, K_FOREVER);
if (!out_pkt) {
/* Cannot happen atm, net_pkt waits indefinitely */
return -ENOBUFS;
}
@ -225,7 +225,7 @@ static void telnet_sent_cb(struct net_context *client,
{
if (status) {
telnet_end_client_connection();
SYS_LOG_ERR("Could not sent last buffer");
SYS_LOG_ERR("Could not sent last packet");
}
}
@ -234,14 +234,14 @@ static inline bool telnet_send(void)
struct line_buf *lb = telnet_rb_get_line_out();
if (lb) {
net_pkt_append(out_buf, lb->len, lb->buf, K_FOREVER);
net_pkt_append(out_pkt, lb->len, lb->buf, K_FOREVER);
/* We reinitialize the line buffer */
lb->len = 0;
if (net_context_send(out_buf, telnet_sent_cb,
if (net_context_send(out_pkt, telnet_sent_cb,
K_NO_WAIT, NULL, NULL) ||
telnet_setup_out_buf(client_cnx)) {
telnet_setup_out_pkt(client_cnx)) {
return false;
}
}
@ -258,12 +258,12 @@ static int telnet_console_out_nothing(int c)
static inline void telnet_command_send_reply(uint8_t *msg, uint16_t len)
{
net_pkt_append(out_buf, len, msg, K_FOREVER);
net_pkt_append(out_pkt, len, msg, K_FOREVER);
net_context_send(out_buf, telnet_sent_cb,
net_context_send(out_pkt, telnet_sent_cb,
K_NO_WAIT, NULL, NULL);
telnet_setup_out_buf(client_cnx);
telnet_setup_out_pkt(client_cnx);
}
static inline void telnet_reply_ay_command(void)
@ -326,10 +326,10 @@ out:
#define telnet_reply_command()
#endif /* CONFIG_TELNET_CONSOLE_SUPPORT_COMMAND */
static inline bool telnet_handle_command(struct net_buf *buf)
static inline bool telnet_handle_command(struct net_pkt *pkt)
{
struct telnet_simple_command *cmd =
(struct telnet_simple_command *)net_pkt_appdata(buf);
(struct telnet_simple_command *)net_pkt_appdata(pkt);
if (cmd->iac != NVT_CMD_IAC) {
return false;
@ -351,17 +351,17 @@ static inline bool telnet_handle_command(struct net_buf *buf)
return true;
}
static inline void telnet_handle_input(struct net_buf *buf)
static inline void telnet_handle_input(struct net_pkt *pkt)
{
struct console_input *input;
uint16_t len, offset, pos;
len = net_pkt_appdatalen(buf);
len = net_pkt_appdatalen(pkt);
if (len > CONSOLE_MAX_LINE_LEN || len < TELNET_MIN_MSG) {
return;
}
if (telnet_handle_command(buf)) {
if (telnet_handle_command(pkt)) {
return;
}
@ -374,8 +374,8 @@ static inline void telnet_handle_input(struct net_buf *buf)
return;
}
offset = net_buf_frags_len(buf) - len;
net_pkt_read(buf->frags, offset, &pos, len, input->line);
offset = net_pkt_get_len(pkt) - len;
net_frag_read(pkt->frags, offset, &pos, len, input->line);
/* LF/CR will be removed if only the line is not NUL terminated */
if (input->line[len-1] != NVT_NUL) {
@ -392,11 +392,11 @@ static inline void telnet_handle_input(struct net_buf *buf)
}
static void telnet_recv(struct net_context *client,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
if (!buf || status) {
if (!pkt || status) {
telnet_end_client_connection();
SYS_LOG_DBG("Telnet client dropped (AF_INET%s) status %d",
@ -405,9 +405,9 @@ static void telnet_recv(struct net_context *client,
return;
}
telnet_handle_input(buf);
telnet_handle_input(pkt);
net_buf_unref(buf);
net_pkt_unref(pkt);
}
/* Telnet server loop, used to send buffered output in the RB */
@ -446,7 +446,7 @@ static void telnet_accept(struct net_context *client,
goto error;
}
if (telnet_setup_out_buf(client)) {
if (telnet_setup_out_pkt(client)) {
goto error;
}

View file

@ -424,7 +424,7 @@ static int eth_enc28j60_init(struct device *dev)
return 0;
}
static int eth_enc28j60_tx(struct device *dev, struct net_buf *buf,
static int eth_enc28j60_tx(struct device *dev, struct net_pkt *pkt,
uint16_t len)
{
struct eth_enc28j60_runtime *context = dev->driver_data;
@ -461,13 +461,13 @@ static int eth_enc28j60_tx(struct device *dev, struct net_buf *buf,
per_packet_control = ENC28J60_PPCTL_BYTE;
eth_enc28j60_write_mem(dev, &per_packet_control, 1);
for (frag = buf->frags; frag; frag = frag->frags) {
for (frag = pkt->frags; frag; frag = frag->frags) {
uint8_t *data_ptr;
uint16_t data_len;
if (first_frag) {
data_ptr = net_pkt_ll(buf);
data_len = net_pkt_ll_reserve(buf) + frag->len;
data_ptr = net_pkt_ll(pkt);
data_len = net_pkt_ll_reserve(pkt) + frag->len;
first_frag = false;
} else {
data_ptr = frag->data;
@ -522,10 +522,9 @@ static int eth_enc28j60_rx(struct device *dev)
k_sem_take(&context->tx_rx_sem, K_FOREVER);
do {
struct net_buf *last_frag;
struct net_buf *pkt_buf = NULL;
uint16_t frm_len = 0;
struct net_buf *buf;
struct net_pkt *pkt;
uint16_t next_packet;
uint8_t np[2];
@ -552,32 +551,29 @@ static int eth_enc28j60_rx(struct device *dev)
lengthfr = frm_len;
/* Get the frame from the buffer */
buf = net_pkt_get_reserve_rx(0, config->timeout);
if (!buf) {
pkt = net_pkt_get_reserve_rx(0, config->timeout);
if (!pkt) {
SYS_LOG_ERR("Could not allocate rx buffer");
goto done;
}
last_frag = buf;
do {
size_t frag_len;
uint8_t *data_ptr;
size_t spi_frame_len;
/* Reserve a data frag to receive the frame */
pkt_buf = net_pkt_get_frag(buf, config->timeout);
pkt_buf = net_pkt_get_frag(pkt, config->timeout);
if (!pkt_buf) {
SYS_LOG_ERR("Could not allocate data buffer");
net_buf_unref(buf);
net_pkt_unref(pkt);
goto done;
}
net_buf_frag_insert(last_frag, pkt_buf);
data_ptr = pkt_buf->data;
net_pkt_frag_insert(pkt, pkt_buf);
last_frag = pkt_buf;
data_ptr = pkt_buf->data;
/* Review the space available for the new frag */
frag_len = net_buf_tailroom(pkt_buf);
@ -608,7 +604,7 @@ static int eth_enc28j60_rx(struct device *dev)
/* Feed buffer frame to IP stack */
SYS_LOG_DBG("Received packet of length %u", lengthfr);
net_recv_data(context->iface, buf);
net_recv_data(context->iface, pkt);
done:
/* Free buffer memory and decrement rx counter */
eth_enc28j60_set_bank(dev, ENC28J60_REG_ERXRDPTL);
@ -654,16 +650,16 @@ static void enc28j60_thread_main(void *arg1, void *unused1, void *unused2)
}
}
static int eth_net_tx(struct net_if *iface, struct net_buf *buf)
static int eth_net_tx(struct net_if *iface, struct net_pkt *pkt)
{
uint16_t len = net_pkt_ll_reserve(buf) + net_buf_frags_len(buf);
uint16_t len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
int ret;
SYS_LOG_DBG("buf %p (len %u)", buf, len);
SYS_LOG_DBG("pkt %p (len %u)", pkt, len);
ret = eth_enc28j60_tx(iface->dev, buf, len);
ret = eth_enc28j60_tx(iface->dev, pkt, len);
if (ret == 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return ret;

View file

@ -306,7 +306,7 @@ static void eth_mcux_delayed_phy_work(struct k_work *item)
eth_mcux_phy_event(context);
}
static int eth_tx(struct net_if *iface, struct net_buf *buf)
static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
{
struct eth_context *context = iface->dev->driver_data;
const struct net_buf *frag;
@ -314,7 +314,7 @@ static int eth_tx(struct net_if *iface, struct net_buf *buf)
status_t status;
unsigned int imask;
uint16_t total_len = net_pkt_ll_reserve(buf) + net_buf_frags_len(buf);
uint16_t total_len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
k_sem_take(&context->tx_buf_sem, K_FOREVER);
@ -329,12 +329,12 @@ static int eth_tx(struct net_if *iface, struct net_buf *buf)
* in our case) headers and must be treated specially.
*/
dst = context->frame_buf;
memcpy(dst, net_pkt_ll(buf),
net_pkt_ll_reserve(buf) + buf->frags->len);
dst += net_pkt_ll_reserve(buf) + buf->frags->len;
memcpy(dst, net_pkt_ll(pkt),
net_pkt_ll_reserve(pkt) + pkt->frags->len);
dst += net_pkt_ll_reserve(pkt) + pkt->frags->len;
/* Continue with the rest of fragments (which contain only data) */
frag = buf->frags->frags;
frag = pkt->frags->frags;
while (frag) {
memcpy(dst, frag->data, frag->len);
dst += frag->len;
@ -351,14 +351,14 @@ static int eth_tx(struct net_if *iface, struct net_buf *buf)
return -1;
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
return 0;
}
static void eth_rx(struct device *iface)
{
struct eth_context *context = iface->driver_data;
struct net_buf *buf, *prev_frag;
struct net_pkt *pkt;
const uint8_t *src;
uint32_t frame_length = 0;
status_t status;
@ -381,8 +381,8 @@ static void eth_rx(struct device *iface)
return;
}
buf = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!buf) {
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
/* We failed to get a receive buffer. We don't add
* any further logging here because the allocator
* issued a diagnostic when it failed to allocate.
@ -398,7 +398,7 @@ static void eth_rx(struct device *iface)
if (sizeof(context->frame_buf) < frame_length) {
SYS_LOG_ERR("frame too large (%d)\n", frame_length);
net_pkt_unref(buf);
net_pkt_unref(pkt);
status = ENET_ReadFrame(ENET, &context->enet_handle, NULL, 0);
assert(status == kStatus_Success);
return;
@ -414,27 +414,25 @@ static void eth_rx(struct device *iface)
if (status) {
irq_unlock(imask);
SYS_LOG_ERR("ENET_ReadFrame failed: %d\n", status);
net_pkt_unref(buf);
net_pkt_unref(pkt);
return;
}
src = context->frame_buf;
prev_frag = buf;
do {
struct net_buf *pkt_buf;
size_t frag_len;
pkt_buf = net_pkt_get_frag(buf, K_NO_WAIT);
pkt_buf = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!pkt_buf) {
irq_unlock(imask);
SYS_LOG_ERR("Failed to get fragment buf\n");
net_pkt_unref(buf);
net_pkt_unref(pkt);
assert(status == kStatus_Success);
return;
}
net_buf_frag_insert(prev_frag, pkt_buf);
prev_frag = pkt_buf;
net_pkt_frag_insert(pkt, pkt_buf);
frag_len = net_buf_tailroom(pkt_buf);
if (frag_len > frame_length) {
frag_len = frame_length;
@ -448,8 +446,8 @@ static void eth_rx(struct device *iface)
irq_unlock(imask);
if (net_recv_data(context->iface, buf) < 0) {
net_pkt_unref(buf);
if (net_recv_data(context->iface, pkt) < 0) {
net_pkt_unref(pkt);
}
}

View file

@ -77,7 +77,7 @@ static struct gmac_desc tx_desc_que12[PRIORITY_QUEUE_DESC_COUNT]
/* RX buffer accounting list */
static struct net_buf *rx_buf_list_que0[MAIN_QUEUE_RX_DESC_COUNT];
/* TX frames accounting list */
static struct net_buf *tx_frame_list_que0[CONFIG_NET_PKT_TX_COUNT + 1];
static struct net_pkt *tx_frame_list_que0[CONFIG_NET_PKT_TX_COUNT + 1];
#define MODULO_INC(val, max) {val = (++val < max) ? val : 0; }
@ -219,7 +219,7 @@ static void tx_completed(Gmac *gmac, struct gmac_queue *queue)
{
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
struct gmac_desc *tx_desc;
struct net_buf *buf;
struct net_pkt *pkt;
__ASSERT(tx_desc_list->buf[tx_desc_list->tail].w1 & GMAC_TXW1_USED,
"first buffer of a frame is not marked as own by GMAC");
@ -232,9 +232,9 @@ static void tx_completed(Gmac *gmac, struct gmac_queue *queue)
if (tx_desc->w1 & GMAC_TXW1_LASTBUFFER) {
/* Release net buffer to the buffer pool */
buf = UINT_TO_POINTER(ring_buf_get(&queue->tx_frames));
net_buf_unref(buf);
SYS_LOG_DBG("Dropping buf %p", buf);
pkt = UINT_TO_POINTER(ring_buf_get(&queue->tx_frames));
net_pkt_unref(pkt);
SYS_LOG_DBG("Dropping pkt %p", pkt);
break;
}
@ -246,7 +246,7 @@ static void tx_completed(Gmac *gmac, struct gmac_queue *queue)
*/
static void tx_error_handler(Gmac *gmac, struct gmac_queue *queue)
{
struct net_buf *buf;
struct net_pkt *pkt;
struct ring_buf *tx_frames = &queue->tx_frames;
queue->err_tx_flushed_count++;
@ -257,9 +257,9 @@ static void tx_error_handler(Gmac *gmac, struct gmac_queue *queue)
/* Free all pkt resources in the TX path */
while (tx_frames->tail != tx_frames->head) {
/* Release net buffer to the buffer pool */
buf = UINT_TO_POINTER(tx_frames->buf[tx_frames->tail]);
net_buf_unref(buf);
SYS_LOG_DBG("Dropping buf %p", buf);
pkt = UINT_TO_POINTER(tx_frames->buf[tx_frames->tail]);
net_pkt_unref(pkt);
SYS_LOG_DBG("Dropping pkt %p", pkt);
MODULO_INC(tx_frames->tail, tx_frames->len);
}
@ -472,9 +472,8 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
struct gmac_desc *rx_desc;
struct ring_buf *rx_pkt_list = &queue->rx_pkt_list;
struct net_buf *rx_frame;
struct net_pkt *rx_frame;
bool frame_is_complete;
struct net_buf *prev_frag;
struct net_buf *frag;
struct net_buf *new_frag;
uint8_t *frag_data;
@ -501,7 +500,6 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
rx_frame = net_pkt_get_reserve_rx(0, K_NO_WAIT);
/* Process a frame */
prev_frag = rx_frame;
tail = rx_desc_list->tail;
rx_desc = &rx_desc_list->buf[tail];
frame_is_complete = false;
@ -540,12 +538,11 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
new_frag = net_pkt_get_frag(rx_frame, K_NO_WAIT);
if (new_frag == NULL) {
queue->err_rx_frames_dropped++;
net_buf_unref(rx_frame);
net_pkt_unref(rx_frame);
rx_frame = NULL;
} else {
net_buf_add(frag, frag_len);
net_buf_frag_insert(prev_frag, frag);
prev_frag = frag;
net_pkt_frag_insert(rx_frame, frag);
frag = new_frag;
rx_pkt_list->buf[tail] = (uint32_t)frag;
}
@ -577,7 +574,7 @@ static void eth_rx(struct gmac_queue *queue)
{
struct eth_sam_dev_data *dev_data =
CONTAINER_OF(queue, struct eth_sam_dev_data, queue_list);
struct net_buf *rx_frame;
struct net_pkt *rx_frame;
/* More than one frame could have been received by GMAC, get all
* complete frames stored in the GMAC RX descriptor list.
@ -594,7 +591,7 @@ static void eth_rx(struct gmac_queue *queue)
}
}
static int eth_tx(struct net_if *iface, struct net_buf *buf)
static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
{
struct device *const dev = net_if_get_device(iface);
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
@ -609,8 +606,8 @@ static int eth_tx(struct net_if *iface, struct net_buf *buf)
uint32_t err_tx_flushed_count_at_entry = queue->err_tx_flushed_count;
unsigned int key;
__ASSERT(buf, "buf pointer is NULL");
__ASSERT(buf->frags, "Frame data missing");
__ASSERT(pkt, "buf pointer is NULL");
__ASSERT(pkt->frags, "Frame data missing");
SYS_LOG_DBG("ETH tx");
@ -618,10 +615,9 @@ static int eth_tx(struct net_if *iface, struct net_buf *buf)
* in our case) header. Modify the data pointer to account for more data
* in the beginning of the buffer.
*/
net_buf_push(buf->frags, net_pkt_ll_reserve(buf));
frag = buf->frags;
net_buf_push(pkt->frags, net_pkt_ll_reserve(pkt));
frag = pkt->frags;
while (frag) {
frag_data = frag->data;
frag_len = frag->len;
@ -683,7 +679,7 @@ static int eth_tx(struct net_if *iface, struct net_buf *buf)
tx_desc->w1 |= GMAC_TXW1_USED;
/* Account for a sent frame */
ring_buf_put(&queue->tx_frames, POINTER_TO_UINT(buf));
ring_buf_put(&queue->tx_frames, POINTER_TO_UINT(pkt));
irq_unlock(key);

View file

@ -517,7 +517,7 @@ static inline uint8_t read_rxfifo_length(struct cc2520_spi *spi)
}
static inline bool read_rxfifo_content(struct cc2520_spi *spi,
struct net_buf *buf, uint8_t len)
struct net_buf *frag, uint8_t len)
{
uint8_t data[128+1];
@ -535,14 +535,14 @@ static inline bool read_rxfifo_content(struct cc2520_spi *spi,
return false;
}
memcpy(buf->data, &data[1], len);
net_buf_add(buf, len);
memcpy(frag->data, &data[1], len);
net_buf_add(frag, len);
return true;
}
static inline bool verify_crc(struct cc2520_context *cc2520,
struct net_buf *buf)
struct net_pkt *pkt)
{
cc2520->spi.cmd_buf[0] = CC2520_INS_RXBUF;
cc2520->spi.cmd_buf[1] = 0;
@ -559,7 +559,7 @@ static inline bool verify_crc(struct cc2520_context *cc2520,
return false;
}
net_pkt_set_ieee802154_rssi(buf, cc2520->spi.cmd_buf[1]);
net_pkt_set_ieee802154_rssi(pkt, cc2520->spi.cmd_buf[1]);
/**
* CC2520 does not provide an LQI but a correlation factor.
@ -597,12 +597,12 @@ static void cc2520_rx(int arg)
{
struct device *dev = INT_TO_POINTER(arg);
struct cc2520_context *cc2520 = dev->driver_data;
struct net_buf *pkt_buf = NULL;
struct net_buf *buf;
struct net_buf *pkt_frag = NULL;
struct net_pkt *pkt;
uint8_t pkt_len;
while (1) {
buf = NULL;
pkt = NULL;
k_sem_take(&cc2520->rx_lock, K_FOREVER);
@ -619,9 +619,9 @@ static void cc2520_rx(int arg)
goto flush;
}
buf = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!buf) {
SYS_LOG_ERR("No buf available");
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
SYS_LOG_ERR("No pkt available");
goto flush;
}
@ -629,27 +629,27 @@ static void cc2520_rx(int arg)
/**
* Reserve 1 byte for length
*/
net_pkt_set_ll_reserve(buf, 1);
net_pkt_set_ll_reserve(pkt, 1);
#endif
pkt_buf = net_pkt_get_frag(buf, K_NO_WAIT);
if (!pkt_buf) {
SYS_LOG_ERR("No pkt_buf available");
pkt_frag = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!pkt_frag) {
SYS_LOG_ERR("No pkt_frag available");
goto flush;
}
net_buf_frag_insert(buf, pkt_buf);
net_pkt_frag_insert(pkt, pkt_frag);
#if defined(CONFIG_IEEE802154_CC2520_RAW)
if (!read_rxfifo_content(&cc2520->spi, pkt_buf, pkt_len)) {
if (!read_rxfifo_content(&cc2520->spi, pkt_frag, pkt_len)) {
SYS_LOG_ERR("No content read");
goto flush;
}
if (!(pkt_buf->data[pkt_len - 1] & CC2520_FCS_CRC_OK)) {
if (!(pkt_frag->data[pkt_len - 1] & CC2520_FCS_CRC_OK)) {
goto out;
}
cc2520->lqi = pkt_buf->data[pkt_len - 1] &
cc2520->lqi = pkt_frag->data[pkt_len - 1] &
CC2520_FCS_CORRELATION;
if (cc2520->lqi <= 50) {
cc2520->lqi = 0;
@ -659,30 +659,30 @@ static void cc2520_rx(int arg)
cc2520->lqi = (cc2520->lqi - 50) << 2;
}
#else
if (!read_rxfifo_content(&cc2520->spi, pkt_buf, pkt_len - 2)) {
if (!read_rxfifo_content(&cc2520->spi, pkt_frag, pkt_len - 2)) {
SYS_LOG_ERR("No content read");
goto flush;
}
if (!verify_crc(cc2520, buf)) {
if (!verify_crc(cc2520, pkt)) {
SYS_LOG_ERR("Bad packet CRC");
goto out;
}
#endif
if (ieee802154_radio_handle_ack(cc2520->iface, buf) == NET_OK) {
if (ieee802154_radio_handle_ack(cc2520->iface, pkt) == NET_OK) {
SYS_LOG_DBG("ACK packet handled");
goto out;
}
#if defined(CONFIG_IEEE802154_CC2520_RAW)
net_buf_add_u8(pkt_buf, cc2520->lqi);
net_buf_add_u8(pkt_frag, cc2520->lqi);
#endif
SYS_LOG_DBG("Caught a packet (%u) (LQI: %u)",
pkt_len, cc2520->lqi);
if (net_recv_data(cc2520->iface, buf) < 0) {
if (net_recv_data(cc2520->iface, pkt) < 0) {
SYS_LOG_DBG("Packet dropped by NET stack");
goto out;
}
@ -696,8 +696,8 @@ flush:
_cc2520_print_errors(cc2520);
flush_rxfifo(cc2520);
out:
if (buf) {
net_buf_unref(buf);
if (pkt) {
net_pkt_unref(pkt);
}
}
}
@ -837,11 +837,11 @@ error:
}
static int cc2520_tx(struct device *dev,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
uint8_t *frame = frag->data - net_pkt_ll_reserve(buf);
uint8_t len = net_pkt_ll_reserve(buf) + frag->len;
uint8_t *frame = frag->data - net_pkt_ll_reserve(pkt);
uint8_t len = net_pkt_ll_reserve(pkt) + frag->len;
struct cc2520_context *cc2520 = dev->driver_data;
uint8_t retry = 2;
bool status;

View file

@ -539,16 +539,14 @@ static inline bool read_rxfifo_content(struct mcr20a_spi *spi,
static inline void mcr20a_rx(struct mcr20a_context *mcr20a, uint8_t len)
{
struct net_buf *pkt_buf = NULL;
struct net_buf *buf;
struct net_pkt *pkt = NULL;
struct net_buf *frag;
uint8_t pkt_len;
buf = NULL;
pkt_len = len - MCR20A_FCS_LENGTH;
buf = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!buf) {
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
SYS_LOG_ERR("No buf available");
goto out;
}
@ -558,22 +556,22 @@ static inline void mcr20a_rx(struct mcr20a_context *mcr20a, uint8_t len)
/**
* Reserve 1 byte for length
*/
net_pkt_set_ll_reserve(buf, 1);
net_pkt_set_ll_reserve(pkt, 1);
#endif
pkt_buf = net_pkt_get_frag(buf, K_NO_WAIT);
if (!pkt_buf) {
SYS_LOG_ERR("No pkt_buf available");
frag = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!frag) {
SYS_LOG_ERR("No frag available");
goto out;
}
net_buf_frag_insert(buf, pkt_buf);
net_pkt_frag_insert(pkt, frag);
if (!read_rxfifo_content(&mcr20a->spi, pkt_buf, pkt_len)) {
if (!read_rxfifo_content(&mcr20a->spi, frag, pkt_len)) {
SYS_LOG_ERR("No content read");
goto out;
}
if (ieee802154_radio_handle_ack(mcr20a->iface, buf) == NET_OK) {
if (ieee802154_radio_handle_ack(mcr20a->iface, pkt) == NET_OK) {
SYS_LOG_DBG("ACK packet handled");
goto out;
}
@ -584,10 +582,10 @@ static inline void mcr20a_rx(struct mcr20a_context *mcr20a, uint8_t len)
mcr20a_get_rssi(mcr20a->lqi));
#if defined(CONFIG_IEEE802154_MCR20A_RAW)
net_buf_add_u8(pkt_buf, mcr20a->lqi);
net_buf_add_u8(frag, mcr20a->lqi);
#endif
if (net_recv_data(mcr20a->iface, buf) < 0) {
if (net_recv_data(mcr20a->iface, pkt) < 0) {
SYS_LOG_DBG("Packet dropped by NET stack");
goto out;
}
@ -597,8 +595,8 @@ static inline void mcr20a_rx(struct mcr20a_context *mcr20a, uint8_t len)
CONFIG_IEEE802154_MCR20A_RX_STACK_SIZE);
return;
out:
if (buf) {
net_buf_unref(buf);
if (pkt) {
net_pkt_unref(pkt);
}
}
@ -1031,12 +1029,12 @@ error:
}
static inline bool write_txfifo_content(struct mcr20a_spi *spi,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
uint8_t cmd[2 + MCR20A_PSDU_LENGTH];
uint8_t payload_len = net_pkt_ll_reserve(buf) + frag->len;
uint8_t *payload = frag->data - net_pkt_ll_reserve(buf);
uint8_t payload_len = net_pkt_ll_reserve(pkt) + frag->len;
uint8_t *payload = frag->data - net_pkt_ll_reserve(pkt);
bool retval;
k_sem_take(&spi->spi_sem, K_FOREVER);
@ -1067,7 +1065,7 @@ static inline bool write_txfifo_content(struct mcr20a_spi *spi,
}
static int mcr20a_tx(struct device *dev,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
struct mcr20a_context *mcr20a = dev->driver_data;
@ -1077,7 +1075,7 @@ static int mcr20a_tx(struct device *dev,
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
SYS_LOG_DBG("%p (%u)",
frag, net_pkt_ll_reserve(buf) + frag->len);
frag, net_pkt_ll_reserve(pkt) + frag->len);
if (!mcr20a_mask_irqb(mcr20a, true)) {
SYS_LOG_ERR("Failed to mask IRQ_B");
@ -1089,7 +1087,7 @@ static int mcr20a_tx(struct device *dev,
goto error;
}
if (!write_txfifo_content(&mcr20a->spi, buf, frag)) {
if (!write_txfifo_content(&mcr20a->spi, pkt, frag)) {
SYS_LOG_ERR("Did not write properly into TX FIFO");
goto error;
}

View file

@ -55,25 +55,25 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
{
struct device *dev = (struct device *)arg1;
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
struct net_buf *pkt_buf = NULL;
struct net_buf *frag = NULL;
enum net_verdict ack_result;
struct net_buf *buf;
struct net_pkt *pkt;
uint8_t pkt_len;
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
while (1) {
buf = NULL;
pkt = NULL;
SYS_LOG_DBG("Waiting for frame");
k_sem_take(&nrf5_radio->rx_wait, K_FOREVER);
SYS_LOG_DBG("Frame received");
buf = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!buf) {
SYS_LOG_ERR("No buf available");
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
SYS_LOG_ERR("No pkt available");
goto out;
}
@ -81,16 +81,16 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
/**
* Reserve 1 byte for length
*/
net_pkt_set_ll_reserve(buf, 1);
net_pkt_set_ll_reserve(pkt, 1);
#endif
pkt_buf = net_pkt_get_frag(buf, K_NO_WAIT);
if (!pkt_buf) {
SYS_LOG_ERR("No pkt_buf available");
frag = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!frag) {
SYS_LOG_ERR("No frag available");
goto out;
}
net_buf_frag_insert(buf, pkt_buf);
net_pkt_frag_insert(pkt, frag);
/* rx_mpdu contains length, psdu, fcs|lqi
* The last 2 bytes contain LQI or FCS, depending if
@ -103,13 +103,13 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
#endif
/* Skip length (first byte) and copy the payload */
memcpy(pkt_buf->data, nrf5_radio->rx_psdu + 1, pkt_len);
net_buf_add(pkt_buf, pkt_len);
memcpy(frag->data, nrf5_radio->rx_psdu + 1, pkt_len);
net_buf_add(frag, pkt_len);
nrf_drv_radio802154_buffer_free(nrf5_radio->rx_psdu);
ack_result = ieee802154_radio_handle_ack(nrf5_radio->iface,
buf);
pkt);
if (ack_result == NET_OK) {
SYS_LOG_DBG("ACK packet handled");
goto out;
@ -118,7 +118,7 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
SYS_LOG_DBG("Caught a packet (%u) (LQI: %u)",
pkt_len, nrf5_radio->lqi);
if (net_recv_data(nrf5_radio->iface, buf) < 0) {
if (net_recv_data(nrf5_radio->iface, pkt) < 0) {
SYS_LOG_DBG("Packet dropped by NET stack");
goto out;
}
@ -129,8 +129,8 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
continue;
out:
if (buf) {
net_buf_unref(buf);
if (pkt) {
net_pkt_unref(pkt);
}
}
}
@ -230,12 +230,12 @@ static int nrf5_set_txpower(struct device *dev, int16_t dbm)
}
static int nrf5_tx(struct device *dev,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
uint8_t payload_len = net_pkt_ll_reserve(buf) + frag->len;
uint8_t *payload = frag->data - net_pkt_ll_reserve(buf);
uint8_t payload_len = net_pkt_ll_reserve(pkt) + frag->len;
uint8_t *payload = frag->data - net_pkt_ll_reserve(pkt);
SYS_LOG_DBG("%p (%u)", payload, payload_len);

View file

@ -30,8 +30,8 @@ static struct device *upipe_dev;
static uint8_t *upipe_rx(uint8_t *buf, size_t *off)
{
struct upipe_context *upipe = upipe_dev->driver_data;
struct net_buf *pkt_buf = NULL;
struct net_buf *pkt = NULL;
struct net_pkt *pkt = NULL;
struct net_buf *frag = NULL;
if (!upipe_dev) {
goto done;
@ -56,20 +56,20 @@ static uint8_t *upipe_rx(uint8_t *buf, size_t *off)
if (upipe->rx_len == upipe->rx_off) {
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
SYS_LOG_DBG("No buf available");
SYS_LOG_DBG("No pkt available");
goto flush;
}
pkt_buf = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!pkt_buf) {
frag = net_pkt_get_frag(pkt, K_NO_WAIT);
if (!frag) {
SYS_LOG_DBG("No fragment available");
goto out;
}
net_buf_frag_insert(pkt, pkt_buf);
net_pkt_frag_insert(pkt, frag);
memcpy(pkt_buf->data, upipe->rx_buf, upipe->rx_len - 2);
net_buf_add(pkt_buf, upipe->rx_len - 2);
memcpy(frag->data, upipe->rx_buf, upipe->rx_len - 2);
net_buf_add(frag, upipe->rx_len - 2);
if (ieee802154_radio_handle_ack(upipe->iface, pkt) == NET_OK) {
SYS_LOG_DBG("ACK packet handled");
@ -93,7 +93,7 @@ flush:
done:
*off = 0;
return buf;
return pkt;
}
static int upipe_cca(struct device *dev)
@ -163,11 +163,11 @@ static int upipe_set_txpower(struct device *dev, int16_t dbm)
}
static int upipe_tx(struct device *dev,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
uint8_t *pkt_buf = frag->data - net_pkt_ll_reserve(buf);
uint8_t len = net_pkt_ll_reserve(buf) + frag->len;
uint8_t *pkt_buf = frag->data - net_pkt_ll_reserve(pkt);
uint8_t len = net_pkt_ll_reserve(pkt) + frag->len;
struct upipe_context *upipe = dev->driver_data;
uint8_t i, data;

View file

@ -45,9 +45,9 @@ struct slip_context {
* driver initialization or SLIP_END byte.
*/
uint8_t buf[1]; /* SLIP data is read into this buf */
struct net_buf *rx; /* and then placed into this net_buf */
struct net_pkt *rx; /* and then placed into this net_pkt */
struct net_buf *last; /* Pointer to last fragment in the list */
uint8_t *ptr; /* Where in net_buf to add data */
uint8_t *ptr; /* Where in net_pkt to add data */
struct net_if *iface;
uint8_t state;
@ -125,25 +125,25 @@ static inline void slip_writeb(unsigned char c)
uart_pipe_send(&buf[0], 1);
}
static int slip_send(struct net_if *iface, struct net_buf *buf)
static int slip_send(struct net_if *iface, struct net_pkt *pkt)
{
struct net_buf *frag;
#if defined(CONFIG_SLIP_TAP)
uint16_t ll_reserve = net_pkt_ll_reserve(buf);
uint16_t ll_reserve = net_pkt_ll_reserve(pkt);
bool send_header_once = false;
#endif
uint8_t *ptr;
uint16_t i;
uint8_t c;
if (!buf->frags) {
if (!pkt->frags) {
/* No data? */
return -ENODATA;
}
slip_writeb(SLIP_END);
for (frag = buf->frags; frag; frag = frag->frags) {
for (frag = pkt->frags; frag; frag = frag->frags) {
#if defined(CONFIG_SLIP_DEBUG)
int frag_count = 0;
#endif
@ -201,26 +201,26 @@ static int slip_send(struct net_if *iface, struct net_buf *buf)
#if defined(CONFIG_SLIP_DEBUG)
SYS_LOG_DBG("sent data %d bytes",
frag->len + net_pkt_ll_reserve(buf));
frag->len + net_pkt_ll_reserve(pkt));
if (frag->len + ll_reserve) {
char msg[8 + 1];
snprintf(msg, sizeof(msg), "<slip %2d", frag_count++);
hexdump(msg, net_pkt_ll(buf),
frag->len + net_pkt_ll_reserve(buf),
net_pkt_ll_reserve(buf));
hexdump(msg, net_pkt_ll(pkt),
frag->len + net_pkt_ll_reserve(pkt),
net_pkt_ll_reserve(pkt));
}
#endif
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
slip_writeb(SLIP_END);
return 0;
}
static struct net_buf *slip_poll_handler(struct slip_context *slip)
static struct net_pkt *slip_poll_handler(struct slip_context *slip)
{
if (slip->last && slip->last->len) {
return slip->rx;
@ -231,18 +231,19 @@ static struct net_buf *slip_poll_handler(struct slip_context *slip)
static void process_msg(struct slip_context *slip)
{
struct net_buf *buf;
struct net_pkt *pkt;
buf = slip_poll_handler(slip);
if (!buf || !buf->frags) {
pkt = slip_poll_handler(slip);
if (!pkt || !pkt->frags) {
return;
}
if (net_recv_data(slip->iface, buf) < 0) {
net_pkt_unref(buf);
if (net_recv_data(slip->iface, pkt) < 0) {
net_pkt_unref(pkt);
}
slip->rx = slip->last = NULL;
slip->rx = NULL;
slip->last = NULL;
}
static inline int slip_input_byte(struct slip_context *slip,
@ -306,7 +307,7 @@ static inline int slip_input_byte(struct slip_context *slip,
return 0;
}
net_buf_frag_add(slip->rx, slip->last);
net_pkt_frag_add(slip->rx, slip->last);
slip->ptr = net_pkt_ip_data(slip->rx);
}

View file

@ -17,7 +17,7 @@
#include <net/ethernet.h>
#define NET_ARP_BUF(buf) ((struct net_arp_hdr *)net_pkt_ip_data(buf))
#define NET_ARP_BUF(pkt) ((struct net_arp_hdr *)net_pkt_ip_data(pkt))
struct net_arp_hdr {
uint16_t hwtype; /* HTYPE */
@ -36,8 +36,8 @@ struct net_arp_hdr {
#define NET_ARP_REQUEST 1
#define NET_ARP_REPLY 2
struct net_buf *net_arp_prepare(struct net_buf *buf);
enum net_verdict net_arp_input(struct net_buf *buf);
struct net_pkt *net_arp_prepare(struct net_pkt *pkt);
enum net_verdict net_arp_input(struct net_pkt *pkt);
void net_arp_init(void);

View file

@ -401,11 +401,6 @@ struct net_buf {
struct net_buf *frags;
};
#if defined(CONFIG_NET_TCP)
/** List pointer used for TCP retransmit buffering */
sys_snode_t sent_list;
#endif /* CONFIG_NET_TCP */
/** Reference count. */
uint8_t ref;

View file

@ -20,7 +20,7 @@
#include <net/net_pkt.h>
#include <misc/util.h>
#define NET_ETH_BUF(buf) ((struct net_eth_hdr *)net_pkt_ll(buf))
#define NET_ETH_BUF(pkt) ((struct net_eth_hdr *)net_pkt_ll(pkt))
#define NET_ETH_PTYPE_ARP 0x0806
#define NET_ETH_PTYPE_IP 0x0800

View file

@ -42,9 +42,9 @@ struct ieee802154_radio_api {
/** Set TX power level in dbm */
int (*set_txpower)(struct device *dev, int16_t dbm);
/** Transmit a buffer fragment */
/** Transmit a packet fragment */
int (*tx)(struct device *dev,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag);
/** Start the device */
@ -63,12 +63,12 @@ struct ieee802154_radio_api {
* @details This function should be used to fill in struct net_if's send pointer.
*
* @param iface A valid pointer on a network interface to send from
* @param buf A valid pointer on a buffer to send
* @param pkt A valid pointer on a packet to send
*
* @return 0 on success, negative value otherwise
*/
extern int ieee802154_radio_send(struct net_if *iface,
struct net_buf *buf);
struct net_pkt *pkt);
/**
* @brief Radio driver ACK handling function that hw drivers should use
@ -77,12 +77,12 @@ extern int ieee802154_radio_send(struct net_if *iface,
* helps to hook direcly the hw drivers to the radio driver.
*
* @param iface A valid pointer on a network interface that received the packet
* @param buf A valid pointer on a buffer to check
* @param pkt A valid pointer on a packet to check
*
* @return NET_OK if it was handled, NET_CONTINUE otherwise
*/
extern enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
struct net_buf *buf);
struct net_pkt *pkt);
/**
* @brief Initialize L2 stack for a given interface

View file

@ -148,7 +148,7 @@ struct mqtt_ctx {
void (*malformed)(struct mqtt_ctx *ctx, uint16_t pkt_type);
/* Internal use only */
int (*rcv)(struct mqtt_ctx *ctx, struct net_buf *);
int (*rcv)(struct mqtt_ctx *ctx, struct net_pkt *);
/** Application type, see: enum mqtt_app */
uint8_t app_type;

View file

@ -70,16 +70,16 @@ struct net_context;
* received.
*
* @param context The context to use.
* @param buf Network buffer that is received. If the buf is not NULL,
* then the callback will own the buffer and it needs to to unref the buf
* as soon as it has finished working with it. On EOF, buf will be NULL.
* @param pkt Network buffer that is received. If the pkt is not NULL,
* then the callback will own the buffer and it needs to to unref the pkt
* as soon as it has finished working with it. On EOF, pkt will be NULL.
* @param status Value is set to 0 if some data or the connection is
* at EOF, <0 if there was an error receiving data, in this case the
* buf parameter is set to NULL.
* pkt parameter is set to NULL.
* @param user_data The user data given in net_recv() call.
*/
typedef void (*net_context_recv_cb_t)(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data);
@ -139,6 +139,19 @@ typedef void (*net_context_connect_cb_t)(struct net_context *context,
int status,
void *user_data);
/* The net_pkt_get_slab_func_t is here in order to avoid circular
* dependency between net_pkt.h and net_context.h
*/
/**
* @typedef net_pkt_get_slab_func_t
*
* @brief Function that is called to get the slab that is used
* for net_pkt allocations.
*
* @return Pointer to valid struct k_mem_slab instance.
*/
typedef struct k_mem_slab *(*net_pkt_get_slab_func_t)(void);
/* The net_pkt_get_pool_func_t is here in order to avoid circular
* dependency between net_pkt.h and net_context.h
*/
@ -200,7 +213,7 @@ struct net_context {
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
/** Get TX net_buf pool for this context.
*/
net_pkt_get_pool_func_t tx_pool;
net_pkt_get_slab_func_t tx_slab;
/** Get DATA net_buf pool for this context.
*/
@ -611,7 +624,7 @@ int net_context_accept(struct net_context *context,
* net_context_connect().
* This is similar as BSD send() function.
*
* @param buf The network buffer to send.
* @param pkt The network buffer to send.
* @param cb Caller supplied callback function.
* @param timeout Timeout for the connection. Possible values
* are K_FOREVER, K_NO_WAIT, >0.
@ -620,7 +633,7 @@ int net_context_accept(struct net_context *context,
*
* @return 0 if ok, < 0 if error
*/
int net_context_send(struct net_buf *buf,
int net_context_send(struct net_pkt *pkt,
net_context_send_cb_t cb,
int32_t timeout,
void *token,
@ -641,7 +654,7 @@ int net_context_send(struct net_buf *buf,
* timeout expires.
* This is similar as BSD sendto() function.
*
* @param buf The network buffer to send.
* @param pkt The network buffer to send.
* @param dst_addr Destination address. This will override the address
* already set in network buffer.
* @param addrlen Length of the address.
@ -653,7 +666,7 @@ int net_context_send(struct net_buf *buf,
*
* @return 0 if ok, < 0 if error
*/
int net_context_sendto(struct net_buf *buf,
int net_context_sendto(struct net_pkt *pkt,
const struct sockaddr *dst_addr,
socklen_t addrlen,
net_context_send_cb_t cb,
@ -728,21 +741,21 @@ void net_context_foreach(net_context_cb_t cb, void *user_data);
* @param context Context that will use the given net_buf pools.
* @param tx_pool Pointer to the function that will return TX pool
* to the caller. The TX pool is used when sending data to network.
* There is one TX net_buf for each network packet that is sent.
* There is one TX net_pkt for each network packet that is sent.
* @param data_pool Pointer to the function that will return DATA pool
* to the caller. The DATA pool is used to store data that is sent to
* the network.
*/
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
static inline void net_context_setup_pools(struct net_context *context,
net_pkt_get_pool_func_t tx_pool,
net_pkt_get_slab_func_t tx_slab,
net_pkt_get_pool_func_t data_pool)
{
NET_ASSERT(context);
NET_ASSERT(tx_pool);
NET_ASSERT(tx_slab);
NET_ASSERT(data_pool);
context->tx_pool = tx_pool;
context->tx_slab = tx_slab;
context->data_pool = data_pool;
}
#else

View file

@ -57,6 +57,7 @@ extern "C" {
#include <kernel.h>
struct net_buf;
struct net_pkt;
struct net_context;
struct net_if;
@ -71,21 +72,21 @@ enum net_verdict {
};
/* Called by lower network stack when a network packet has been received */
int net_recv_data(struct net_if *iface, struct net_buf *buf);
int net_recv_data(struct net_if *iface, struct net_pkt *pkt);
/**
* @brief Send data to network.
*
* @details Send data to network. This should not be used normally by
* applications as it requires that the buffer and fragments are properly
* applications as it requires that the pktfer and fragments are properly
* constructed.
*
* @param buf Network buffer.
* @param pkt Network packet.
*
* @return 0 if ok, <0 if error. If <0 is returned, then the caller needs
* to unref the buf in order to avoid buffer leak.
* to unref the pkt in order to avoid memory leak.
*/
int net_send_data(struct net_buf *buf);
int net_send_data(struct net_pkt *pkt);
struct net_stack_info {
char *stack;

View file

@ -22,7 +22,6 @@
#include <misc/slist.h>
#include <net/net_core.h>
#include <net/buf.h>
#include <net/net_linkaddr.h>
#include <net/net_ip.h>
#include <net/net_l2.h>
@ -315,27 +314,27 @@ struct net_if {
} __net_if_align;
/**
* @brief Send a buffer through a net iface
* @brief Send a packet through a net iface
*
* @param iface Pointer to a network interface structure
* @param buf Pointer on a net buffer to send
* @param pkt Pointer on a net packet to send
*
* return verdict about the packet
*/
enum net_verdict net_if_send_data(struct net_if *iface, struct net_buf *buf);
enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt);
/**
* @brief Input a buffer through a net iface
* @brief Input a packet through a net iface
*
* @param iface Pointer to a network interface structure
* @param buf Pointer on a net buffer to input
* @param pkt Pointer on a net packet to input
*
* @return verdict about the packet
*/
static inline enum net_verdict net_if_recv_data(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
return iface->l2->recv(iface, buf);
return iface->l2->recv(iface, pkt);
}
/**
@ -380,11 +379,11 @@ static inline struct device *net_if_get_device(struct net_if *iface)
* @brief Queue a packet into net if's TX queue
*
* @param iface Pointer to a network interface structure
* @param buf Pointer on a net buffer to queue
* @param pkt Pointer on a net pktfer to queue
*/
static inline void net_if_queue_tx(struct net_if *iface, struct net_buf *buf)
static inline void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
{
net_buf_put(&iface->tx_queue, buf);
k_fifo_put(&iface->tx_queue, pkt);
}
#if defined(CONFIG_NET_OFFLOAD)
@ -1087,7 +1086,7 @@ static inline void net_if_ipv4_set_gw(struct net_if *iface,
* @brief Define callback that is called after a network packet
* has been sent.
* @param "struct net_if *iface" A pointer on a struct net_if to which the
* the net_buf was sent to.
* the net_pkt was sent to.
* @param "struct net_linkaddr *dst" Link layer address of the destination
* where the network packet was sent.
* @param "int status" Send status, 0 is ok, < 0 error.
@ -1194,7 +1193,7 @@ int net_if_down(struct net_if *iface);
struct net_if_api {
void (*init)(struct net_if *iface);
int (*send)(struct net_if *iface, struct net_buf *buf);
int (*send)(struct net_if *iface, struct net_pkt *pkt);
};
#if defined(CONFIG_NET_DHCPV4)

View file

@ -25,18 +25,18 @@ struct net_l2 {
* This function is used by net core to get iface's L2 layer parsing
* what's relevant to itself.
*/
enum net_verdict (*recv)(struct net_if *iface, struct net_buf *buf);
enum net_verdict (*recv)(struct net_if *iface, struct net_pkt *pkt);
/**
* This function is used by net core to push a buffer to lower layer
* (interface's L2), which in turn might work on the buffer relevantly.
* This function is used by net core to push a packet to lower layer
* (interface's L2), which in turn might work on the packet relevantly.
* (adding proper header etc...)
*/
enum net_verdict (*send)(struct net_if *iface, struct net_buf *buf);
enum net_verdict (*send)(struct net_if *iface, struct net_pkt *pkt);
/**
* This function is used to get the amount of bytes the net core should
* reserve as headroom in a net buffer. Such space is relevant to L2
* reserve as headroom in a net packet. Such space is relevant to L2
* layer only.
*/
uint16_t (*reserve)(struct net_if *iface, void *data);

View file

@ -70,7 +70,7 @@ struct net_offload {
/**
* This function is called when user wants to send data to peer host.
*/
int (*send)(struct net_buf *buf,
int (*send)(struct net_pkt *pkt,
net_context_send_cb_t cb,
int32_t timeout,
void *token,
@ -79,7 +79,7 @@ struct net_offload {
/**
* This function is called when user wants to send data to peer host.
*/
int (*sendto)(struct net_buf *buf,
int (*sendto)(struct net_pkt *pkt,
const struct sockaddr *dst_addr,
socklen_t addrlen,
net_context_send_cb_t cb,
@ -266,13 +266,13 @@ static inline int net_offload_accept(struct net_if *iface,
}
/**
* @brief Send a network buffer to a peer.
* @brief Send a network packet to a peer.
*
* @details This function can be used to send network data to a peer
* connection. This function will return immediately if the timeout
* is set to K_NO_WAIT. If the timeout is set to K_FOREVER, the function
* will wait until the network buffer is sent. Timeout value > 0 will
* wait as many ms. After the network buffer is sent,
* will wait until the network packet is sent. Timeout value > 0 will
* wait as many ms. After the network packet is sent,
* a caller supplied callback is called. The callback is called even
* if timeout was set to K_FOREVER, the callback is called
* before this function will return in this case. The callback is not
@ -283,7 +283,7 @@ static inline int net_offload_accept(struct net_if *iface,
*
* @param iface Network interface where the offloaded IP stack can be
* reached.
* @param buf The network buffer to send.
* @param pkt The network packet to send.
* @param cb Caller supplied callback function.
* @param timeout Timeout for the connection. Possible values
* are K_FOREVER, K_NO_WAIT, >0.
@ -293,7 +293,7 @@ static inline int net_offload_accept(struct net_if *iface,
* @return 0 if ok, < 0 if error
*/
static inline int net_offload_send(struct net_if *iface,
struct net_buf *buf,
struct net_pkt *pkt,
net_context_send_cb_t cb,
int32_t timeout,
void *token,
@ -303,18 +303,18 @@ static inline int net_offload_send(struct net_if *iface,
NET_ASSERT(iface->offload);
NET_ASSERT(iface->offload->send);
return iface->offload->send(buf, cb, timeout, token, user_data);
return iface->offload->send(pkt, cb, timeout, token, user_data);
}
/**
* @brief Send a network buffer to a peer specified by address.
* @brief Send a network packet to a peer specified by address.
*
* @details This function can be used to send network data to a peer
* specified by address. This variant can only be used for datagram
* connections of type SOCK_DGRAM. This function will return immediately
* if the timeout is set to K_NO_WAIT. If the timeout is set to K_FOREVER,
* the function will wait until the network buffer is sent. Timeout
* value > 0 will wait as many ms. After the network buffer
* the function will wait until the network packet is sent. Timeout
* value > 0 will wait as many ms. After the network packet
* is sent, a caller supplied callback is called. The callback is called
* even if timeout was set to K_FOREVER, the callback is called
* before this function will return. The callback is not called if the
@ -323,9 +323,9 @@ static inline int net_offload_send(struct net_if *iface,
*
* @param iface Network interface where the offloaded IP stack can be
* reached.
* @param buf The network buffer to send.
* @param pkt The network packet to send.
* @param dst_addr Destination address. This will override the address
* already set in network buffer.
* already set in network packet.
* @param addrlen Length of the address.
* @param cb Caller supplied callback function.
* @param timeout Timeout for the connection. Possible values
@ -336,7 +336,7 @@ static inline int net_offload_send(struct net_if *iface,
* @return 0 if ok, < 0 if error
*/
static inline int net_offload_sendto(struct net_if *iface,
struct net_buf *buf,
struct net_pkt *pkt,
const struct sockaddr *dst_addr,
socklen_t addrlen,
net_context_send_cb_t cb,
@ -348,7 +348,7 @@ static inline int net_offload_sendto(struct net_if *iface,
NET_ASSERT(iface->offload);
NET_ASSERT(iface->offload->sendto);
return iface->offload->sendto(buf, dst_addr, addrlen, cb,
return iface->offload->sendto(pkt, dst_addr, addrlen, cb,
timeout, token, user_data);
}
@ -364,8 +364,8 @@ static inline int net_offload_sendto(struct net_if *iface,
* multiple times to register new values.
* This function will return immediately if the timeout is set to K_NO_WAIT.
* If the timeout is set to K_FOREVER, the function will wait until the
* network buffer is received. Timeout value > 0 will wait as many ms.
* After the network buffer is received, a caller supplied callback is
* network packet is received. Timeout value > 0 will wait as many ms.
* After the network packet is received, a caller supplied callback is
* called. The callback is called even if timeout was set to K_FOREVER,
* the callback is called before this function will return in this case.
* The callback is not called if the timeout expires. The timeout functionality

File diff suppressed because it is too large Load diff

View file

@ -193,7 +193,7 @@ struct zoap_observer {
* @brief Representation of a CoAP packet.
*/
struct zoap_packet {
struct net_buf *buf;
struct net_pkt *pkt;
uint8_t *start; /* Start of the payload */
uint16_t total_size;
};
@ -211,7 +211,7 @@ typedef int (*zoap_reply_t)(const struct zoap_packet *response,
* @brief Represents a request awaiting for an acknowledgment (ACK).
*/
struct zoap_pending {
struct net_buf *buf;
struct net_pkt *pkt;
struct sockaddr addr;
int32_t timeout;
uint16_t id;
@ -309,35 +309,35 @@ struct zoap_option {
};
/**
* @brief Parses the CoAP packet in @a buf, validating it and
* initializing @a pkt. @a buf must remain valid while @a pkt is used.
* @brief Parses the CoAP packet in @a pkt, validating it and
* initializing @a zpkt. @a pkt must remain valid while @a zpkt is used.
*
* @param pkt Packet to be initialized from received @a buf.
* @param buf Buffer containing a CoAP packet, its @a data pointer is
* @param zpkt Packet to be initialized from received @a pkt.
* @param pkt Network Packet containing a CoAP packet, its @a data pointer is
* positioned on the start of the CoAP packet.
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_packet_parse(struct zoap_packet *pkt, struct net_buf *buf);
int zoap_packet_parse(struct zoap_packet *zpkt, struct net_pkt *pkt);
/**
* @brief Creates a new CoAP packet from a net_buf. @a buf must remain
* valid while @a pkt is used.
* @brief Creates a new CoAP packet from a net_pkt. @a pkt must remain
* valid while @a zpkt is used.
*
* @param pkt New packet to be initialized using the storage from @a
* buf.
* @param buf Buffer that will contain a CoAP packet
* @param zpkt New packet to be initialized using the storage from @a
* pkt.
* @param pkt Network Packet that will contain a CoAP packet
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_packet_init(struct zoap_packet *pkt, struct net_buf *buf);
int zoap_packet_init(struct zoap_packet *zpkt, struct net_pkt *pkt);
/**
* @brief Initialize a pending request with a request.
*
* The request's fields are copied into the pending struct, so @a
* request doesn't have to live for as long as the pending struct
* lives, but net_buf needs to live for at least that long.
* lives, but net_pkt needs to live for at least that long.
*
* @param pending Structure representing the waiting for a
* confirmation message, initialized with data from @a request
@ -451,13 +451,13 @@ void zoap_reply_clear(struct zoap_reply *reply);
* @brief When a request is received, call the appropriate methods of
* the matching resources.
*
* @param pkt Packet received
* @param zpkt Packet received
* @param resources Array of known resources
* @param from Address from which the packet was received
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_handle_request(struct zoap_packet *pkt,
int zoap_handle_request(struct zoap_packet *zpkt,
struct zoap_resource *resources,
const struct sockaddr *from);
@ -487,12 +487,12 @@ bool zoap_request_is_observe(const struct zoap_packet *request);
* It will insert the COAP_MARKER (0xFF), if its not set, and return the
* available size for the payload.
*
* @param pkt Packet to get (or insert) the payload
* @param zpkt Packet to get (or insert) the payload
* @param len Amount of space for the payload
*
* @return pointer to the start of the payload, NULL in case of error.
*/
uint8_t *zoap_packet_get_payload(struct zoap_packet *pkt, uint16_t *len);
uint8_t *zoap_packet_get_payload(struct zoap_packet *zpkt, uint16_t *len);
/**
* @brief Sets how much space was used by the payload.
@ -501,26 +501,26 @@ uint8_t *zoap_packet_get_payload(struct zoap_packet *pkt, uint16_t *len);
* update the internal representation with the amount of data that was
* added to the packet.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param len Amount of data that was added to the payload
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_packet_set_used(struct zoap_packet *pkt, uint16_t len);
int zoap_packet_set_used(struct zoap_packet *zpkt, uint16_t len);
/**
* @brief Adds an option to the packet.
*
* Note: ptions must be added in numeric order of their codes.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param code Option code to add to the packet, see #zoap_option_num
* @param value Pointer to the value of the option, will be copied to the packet
* @param len Size of the data to be added
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_add_option(struct zoap_packet *pkt, uint16_t code,
int zoap_add_option(struct zoap_packet *zpkt, uint16_t code,
const void *value, uint16_t len);
/**
@ -542,20 +542,20 @@ unsigned int zoap_option_value_to_int(const struct zoap_option *option);
* The option must be added in numeric order of their codes, and the
* least amount of bytes will be used to encode the value.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param code Option code to add to the packet, see #zoap_option_num
* @param val Integer value to be added
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_add_option_int(struct zoap_packet *pkt, uint16_t code,
int zoap_add_option_int(struct zoap_packet *zpkt, uint16_t code,
unsigned int val);
/**
* @brief Return the values associated with the option of value @a
* code.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param code Option number to look for
* @param options Array of #zoap_option where to store the value
* of the options found
@ -564,7 +564,7 @@ int zoap_add_option_int(struct zoap_packet *pkt, uint16_t code,
* @return The number of options found in packet matching code,
* negative on error.
*/
int zoap_find_options(const struct zoap_packet *pkt, uint16_t code,
int zoap_find_options(const struct zoap_packet *zpkt, uint16_t code,
struct zoap_option *options, uint16_t veclen);
/**
@ -624,61 +624,61 @@ int zoap_block_transfer_init(struct zoap_block_context *ctx,
/**
* @brief Add BLOCK1 option to the packet.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param ctx Block context from which to retrieve the
* information for the Block1 option
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_add_block1_option(struct zoap_packet *pkt,
int zoap_add_block1_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx);
/**
* @brief Add BLOCK2 option to the packet.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param ctx Block context from which to retrieve the
* information for the Block2 option
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_add_block2_option(struct zoap_packet *pkt,
int zoap_add_block2_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx);
/**
* @brief Add SIZE1 option to the packet.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param ctx Block context from which to retrieve the
* information for the Size1 option
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_add_size1_option(struct zoap_packet *pkt,
int zoap_add_size1_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx);
/**
* @brief Add SIZE2 option to the packet.
*
* @param pkt Packet to be updated
* @param zpkt Packet to be updated
* @param ctx Block context from which to retrieve the
* information for the Size2 option
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_add_size2_option(struct zoap_packet *pkt,
int zoap_add_size2_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx);
/**
* @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a pkt and updates
* @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a zpkt and updates
* @a ctx accordingly.
*
* @param pkt Packet in which to look for block-wise transfers options
* @param zpkt Packet in which to look for block-wise transfers options
* @param ctx Block context to be updated
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_update_from_block(const struct zoap_packet *pkt,
int zoap_update_from_block(const struct zoap_packet *zpkt,
struct zoap_block_context *ctx);
/**
@ -696,93 +696,93 @@ size_t zoap_next_block(struct zoap_block_context *ctx);
/**
* @brief Returns the version present in a CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
*
* @return the CoAP version in packet
*/
uint8_t zoap_header_get_version(const struct zoap_packet *pkt);
uint8_t zoap_header_get_version(const struct zoap_packet *zpkt);
/**
* @brief Returns the type of the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
*
* @return the type of the packet
*/
uint8_t zoap_header_get_type(const struct zoap_packet *pkt);
uint8_t zoap_header_get_type(const struct zoap_packet *zpkt);
/**
* @brief Returns the token (if any) in the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param len Where to store the length of the token
*
* @return pointer to the start of the token in the CoAP packet.
*/
const uint8_t *zoap_header_get_token(const struct zoap_packet *pkt,
const uint8_t *zoap_header_get_token(const struct zoap_packet *zpkt,
uint8_t *len);
/**
* @brief Returns the code of the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
*
* @return the code present in the packet
*/
uint8_t zoap_header_get_code(const struct zoap_packet *pkt);
uint8_t zoap_header_get_code(const struct zoap_packet *zpkt);
/**
* @brief Returns the message id associated with the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
*
* @return the message id present in the packet
*/
uint16_t zoap_header_get_id(const struct zoap_packet *pkt);
uint16_t zoap_header_get_id(const struct zoap_packet *zpkt);
/**
* @brief Sets the version of the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param ver The CoAP version to set in the packet
*/
void zoap_header_set_version(struct zoap_packet *pkt, uint8_t ver);
void zoap_header_set_version(struct zoap_packet *zpkt, uint8_t ver);
/**
* @brief Sets the type of the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param type The packet type to set
*/
void zoap_header_set_type(struct zoap_packet *pkt, uint8_t type);
void zoap_header_set_type(struct zoap_packet *zpkt, uint8_t type);
/**
* @brief Sets the token in the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param token Token to set in the packet, will be copied
* @param tokenlen Size of the token to be set, 8 bytes maximum
*
* @return 0 in case of success or negative in case of error.
*/
int zoap_header_set_token(struct zoap_packet *pkt, const uint8_t *token,
int zoap_header_set_token(struct zoap_packet *zpkt, const uint8_t *token,
uint8_t tokenlen);
/**
* @brief Sets the code present in the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param code The code set in the packet
*/
void zoap_header_set_code(struct zoap_packet *pkt, uint8_t code);
void zoap_header_set_code(struct zoap_packet *zpkt, uint8_t code);
/**
* @brief Sets the message id present in the CoAP packet.
*
* @param pkt CoAP packet representation
* @param zpkt CoAP packet representation
* @param id The message id to set in the packet
*/
void zoap_header_set_id(struct zoap_packet *pkt, uint16_t id);
void zoap_header_set_id(struct zoap_packet *zpkt, uint16_t id);
/**
* @brief Helper to generate message ids

View file

@ -150,28 +150,29 @@ static inline bool get_context(struct net_context **udp_recv6,
return true;
}
static struct net_buf *build_reply_buf(const char *name,
static struct net_pkt *build_reply_pkt(const char *name,
struct net_context *context,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct net_buf *reply_buf, *tmp;
struct net_pkt *reply_pkt;
struct net_buf *tmp;
int header_len, recv_len, reply_len;
printk("%s received %d bytes", name,
net_pkt_appdatalen(buf));
net_pkt_appdatalen(pkt));
reply_buf = net_pkt_get_tx(context, K_FOREVER);
reply_pkt = net_pkt_get_tx(context, K_FOREVER);
recv_len = net_buf_frags_len(buf->frags);
recv_len = net_pkt_get_len(pkt);
tmp = buf->frags;
/* Remove frag link so original buf can be unrefed */
buf->frags = NULL;
tmp = pkt->frags;
/* Remove frag link so original pkt can be unrefed */
pkt->frags = NULL;
/* First fragment will contain IP header so move the data
* down in order to get rid of it.
*/
header_len = net_pkt_appdata(buf) - tmp->data;
header_len = net_pkt_appdata(pkt) - tmp->data;
/* After this pull, the tmp->data points directly to application
* data.
@ -179,14 +180,14 @@ static struct net_buf *build_reply_buf(const char *name,
net_buf_pull(tmp, header_len);
/* Add the entire chain into reply */
net_buf_frag_add(reply_buf, tmp);
net_pkt_frag_add(reply_pkt, tmp);
reply_len = net_buf_frags_len(reply_buf->frags);
reply_len = net_pkt_get_len(reply_pkt);
printk("Received %d bytes, sending %d bytes", recv_len - header_len,
reply_len);
return reply_buf;
return reply_pkt;
}
static inline void pkt_sent(struct net_context *context,
@ -200,45 +201,45 @@ static inline void pkt_sent(struct net_context *context,
}
static inline void set_dst_addr(sa_family_t family,
struct net_buf *buf,
struct net_pkt *pkt,
struct sockaddr *dst_addr)
{
net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr,
&NET_IPV6_BUF(buf)->src);
&NET_IPV6_BUF(pkt)->src);
net_sin6(dst_addr)->sin6_family = AF_INET6;
net_sin6(dst_addr)->sin6_port = NET_UDP_BUF(buf)->src_port;
net_sin6(dst_addr)->sin6_port = NET_UDP_BUF(pkt)->src_port;
}
static void udp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
struct net_buf *reply_buf;
struct net_pkt *reply_pkt;
struct sockaddr dst_addr;
sa_family_t family = net_pkt_family(buf);
sa_family_t family = net_pkt_family(pkt);
static char dbg[MAX_DBG_PRINT + 1];
int ret;
snprintf(dbg, MAX_DBG_PRINT, "UDP IPv%c",
family == AF_INET6 ? '6' : '4');
set_dst_addr(family, buf, &dst_addr);
set_dst_addr(family, pkt, &dst_addr);
reply_buf = build_reply_buf(dbg, context, buf);
reply_pkt = build_reply_pkt(dbg, context, pkt);
net_pkt_unref(buf);
net_pkt_unref(pkt);
ret = net_context_sendto(reply_buf, &dst_addr,
ret = net_context_sendto(reply_pkt, &dst_addr,
family == AF_INET6 ?
sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in),
pkt_sent, 0,
UINT_TO_POINTER(net_buf_frags_len(reply_buf)),
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)),
user_data);
if (ret < 0) {
printk("Cannot send data to peer (%d)", ret);
net_pkt_unref(reply_buf);
net_pkt_unref(reply_pkt);
}
}
@ -253,28 +254,28 @@ static void setup_udp_recv(struct net_context *udp_recv6)
}
static void tcp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
static char dbg[MAX_DBG_PRINT + 1];
sa_family_t family = net_pkt_family(buf);
struct net_buf *reply_buf;
sa_family_t family = net_pkt_family(pkt);
struct net_pkt *reply_pkt;
int ret;
snprintf(dbg, MAX_DBG_PRINT, "TCP IPv%c",
family == AF_INET6 ? '6' : '4');
reply_buf = build_reply_buf(dbg, context, buf);
reply_pkt = build_reply_pkt(dbg, context, pkt);
net_buf_unref(buf);
net_pkt_unref(pkt);
ret = net_context_send(reply_buf, pkt_sent, K_NO_WAIT,
UINT_TO_POINTER(net_buf_frags_len(reply_buf)),
ret = net_context_send(reply_pkt, pkt_sent, K_NO_WAIT,
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)),
NULL);
if (ret < 0) {
printk("Cannot send data to peer (%d)", ret);
net_pkt_unref(reply_buf);
net_pkt_unref(reply_pkt);
quit();
}

View file

@ -70,7 +70,7 @@ struct zoap_reply replies[NUM_REPLIES];
#define ZOAP_BUF_SIZE 128
NET_BUF_POOL_DEFINE(zoap_pkt_pool, 4, 0, sizeof(struct net_pkt), NULL);
NET_PKT_TX_SLAB_DEFINE(zoap_pkt_slab, 4);
NET_BUF_POOL_DEFINE(zoap_data_pool, 4, ZOAP_BUF_SIZE, 0, NULL);
static const char *const test_path[] = { "test", NULL };
@ -100,7 +100,7 @@ static int resource_reply_cb(const struct zoap_packet *response,
const struct sockaddr *from)
{
struct net_buf *frag = response->buf->frags;
struct net_buf *frag = response->pkt->frags;
while (frag) {
msg_dump("reply", frag->data, frag->len);
@ -184,9 +184,10 @@ void dtls_client(void)
int ret;
struct udp_context ctx;
struct dtls_timing_context timer;
struct zoap_packet request, pkt;
struct zoap_packet request, zkt;
struct zoap_reply *reply;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint8_t observe = 0;
const char *const *p;
uint16_t len;
@ -281,8 +282,8 @@ void dtls_client(void)
/* Write to server */
retry:
buf = net_buf_alloc(&zoap_pkt_pool, K_NO_WAIT);
if (!buf) {
pkt = net_pkt_get_reserve(&zoap_pkt_slab, 0, K_NO_WAIT);
if (!pkt) {
goto exit;
}
@ -291,9 +292,9 @@ retry:
goto exit;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
ret = zoap_packet_init(&request, buf);
ret = zoap_packet_init(&request, pkt);
if (ret < 0) {
goto exit;
}
@ -336,7 +337,7 @@ retry:
} while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE);
net_buf_unref(buf);
net_pkt_unref(pkt);
if (ret <= 0) {
mbedtls_printf("mbedtls_ssl_write failed returned 0x%x\n",
@ -344,9 +345,9 @@ retry:
goto exit;
}
buf = net_buf_alloc(&zoap_pkt_pool, K_NO_WAIT);
if (!buf) {
mbedtls_printf("Could not get buffer from pool\n");
pkt = net_pkt_get_reserve(&zoap_pkt_slab, 0, K_NO_WAIT);
if (!pkt) {
mbedtls_printf("Could not get packet from pool\n");
goto exit;
}
@ -356,7 +357,7 @@ retry:
goto exit;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
len = ZOAP_BUF_SIZE - 1;
memset(frag->data, 0, ZOAP_BUF_SIZE);
@ -366,7 +367,7 @@ retry:
ret == MBEDTLS_ERR_SSL_WANT_WRITE);
if (ret <= 0) {
net_buf_unref(buf);
net_pkt_unref(pkt);
switch (ret) {
case MBEDTLS_ERR_SSL_TIMEOUT:
@ -388,18 +389,18 @@ retry:
len = ret;
frag->len = len;
ret = zoap_packet_parse(&pkt, buf);
ret = zoap_packet_parse(&zpkt, pkt);
if (ret) {
mbedtls_printf("Could not parse packet\n");
goto exit;
}
reply = zoap_response_received(&pkt, NULL, replies, NUM_REPLIES);
reply = zoap_response_received(&zpkt, NULL, replies, NUM_REPLIES);
if (!reply) {
mbedtls_printf("No handler for response (%d)\n", ret);
}
net_buf_unref(buf);
net_pkt_unref(pkt);
mbedtls_ssl_close_notify(&ssl);
exit:

View file

@ -37,14 +37,14 @@ static void set_destination(struct sockaddr *addr)
}
static void udp_received(struct net_context *context,
struct net_buf *buf, int status, void *user_data)
struct net_pkt *pkt, int status, void *user_data)
{
struct udp_context *ctx = user_data;
ARG_UNUSED(context);
ARG_UNUSED(status);
ctx->rx_pkt = buf;
ctx->rx_pkt = pkt;
k_sem_give(&ctx->rx_sem);
}
@ -52,30 +52,30 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
{
struct udp_context *ctx = context;
struct net_context *udp_ctx;
struct net_buf *send_buf;
struct net_pkt *send_pkt;
struct sockaddr dst_addr;
int rc, len;
udp_ctx = ctx->net_ctx;
send_buf = net_pkt_get_tx(udp_ctx, K_FOREVER);
if (!send_buf) {
send_pkt = net_pkt_get_tx(udp_ctx, K_FOREVER);
if (!send_pkt) {
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
}
rc = net_pkt_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
rc = net_pkt_append(send_pkt, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
}
set_destination(&dst_addr);
len = net_buf_frags_len(send_buf);
len = net_pkt_frags_len(send_pkt);
k_sleep(UDP_TX_TIMEOUT);
rc = net_context_sendto(send_buf, &dst_addr,
rc = net_context_sendto(send_pkt, &dst_addr,
addrlen, NULL, K_FOREVER, NULL, NULL);
if (rc < 0) {
net_pkt_unref(send_buf);
net_pkt_unref(send_pkt);
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
} else {
return len;

View file

@ -11,7 +11,7 @@
struct udp_context {
struct net_context *net_ctx;
struct net_buf *rx_pkt;
struct net_pkt *rx_pkt;
struct k_sem rx_sem;
int remaining;
};

View file

@ -60,7 +60,7 @@ static unsigned char heap[8192];
#define ZOAP_BUF_SIZE 128
NET_BUF_POOL_DEFINE(zoap_pkt_pool, 4, 0, sizeof(struct net_pkt), NULL);
NET_PKT_TX_SLAB_DEFINE(zoap_pkt_slab, 4);
NET_BUF_POOL_DEFINE(zoap_data_pool, 4, ZOAP_BUF_SIZE, 0, NULL);
/*
@ -78,7 +78,8 @@ static mbedtls_ssl_context *curr_ctx;
static int send_response(struct zoap_packet *request, uint8_t response_code)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t code, type;
uint16_t id;
@ -92,8 +93,8 @@ static int send_response(struct zoap_packet *request, uint8_t response_code)
printk("type: %u code %u id %u\n", type, code, id);
printk("*******\n");
buf = net_buf_alloc(&zoap_pkt_pool, K_NO_WAIT);
if (!buf) {
pkt = net_pkt_get_reserve(&zoap_pkt_slab, 0, K_NO_WAIT);
if (!pkt) {
return -ENOMEM;
}
@ -102,9 +103,9 @@ static int send_response(struct zoap_packet *request, uint8_t response_code)
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -123,7 +124,7 @@ static int send_response(struct zoap_packet *request, uint8_t response_code)
r = 0;
}
net_buf_unref(buf);
net_pkt_unref(pkt);
return r;
}
@ -150,7 +151,8 @@ static int piggyback_get(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, code, type;
uint16_t len, id;
@ -164,8 +166,8 @@ static int piggyback_get(struct zoap_resource *resource,
printk("type: %u code %u id %u\n", type, code, id);
printk("*******\n");
buf = net_buf_alloc(&zoap_pkt_pool, K_NO_WAIT);
if (!buf) {
pkt = net_pkt_get_reserve(&zoap_pkt_slab, 0, K_NO_WAIT);
if (!pkt) {
return -ENOMEM;
}
@ -174,9 +176,9 @@ static int piggyback_get(struct zoap_resource *resource,
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -212,7 +214,7 @@ static int piggyback_get(struct zoap_resource *resource,
r = 0;
}
net_buf_unref(buf);
net_pkt_unref(pkt);
return r;
}
@ -221,7 +223,8 @@ static int query_get(struct zoap_resource *resource,
struct zoap_packet *request, const struct sockaddr *from)
{
struct zoap_option options[4];
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, code, type;
uint16_t len, id;
@ -258,8 +261,8 @@ static int query_get(struct zoap_resource *resource,
printk("*******\n");
buf = net_buf_alloc(&zoap_pkt_pool, K_NO_WAIT);
if (!buf) {
pkt = net_pkt_get_reserve(&zoap_pkt_slab, 0, K_NO_WAIT);
if (!pkt) {
return -ENOMEM;
}
@ -268,9 +271,9 @@ static int query_get(struct zoap_resource *resource,
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -307,7 +310,7 @@ static int query_get(struct zoap_resource *resource,
r = 0;
}
net_buf_unref(buf);
net_pkt_unref(pkt);
return r;
}
@ -416,8 +419,9 @@ void dtls_server(void)
int len, ret = 0;
struct udp_context ctx;
struct dtls_timing_context timer;
struct zoap_packet pkt;
struct net_buf *buf, *frag;
struct zoap_packet zpkt;
struct net_pkt *pkt;
struct net_buf *frag;
mbedtls_ssl_cookie_ctx cookie_ctx;
mbedtls_entropy_context entropy;
@ -549,9 +553,9 @@ reset:
do {
/* Read the request */
buf = net_buf_alloc(&zoap_pkt_pool, K_NO_WAIT);
if (!buf) {
mbedtls_printf("Could not get buffer from pool\n");
pkt = net_pkt_get_reserve(&zoap_pkt_slab, 0, K_NO_WAIT);
if (!pkt) {
mbedtls_printf("Could not get packet from slab\n");
goto exit;
}
@ -561,7 +565,7 @@ reset:
goto exit;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
len = ZOAP_BUF_SIZE - 1;
memset(frag->data, 0, ZOAP_BUF_SIZE);
@ -572,7 +576,7 @@ reset:
}
if (ret <= 0) {
net_buf_unref(buf);
net_pkt_unref(pkt);
switch (ret) {
case MBEDTLS_ERR_SSL_TIMEOUT:
@ -594,20 +598,20 @@ reset:
len = ret;
frag->len = len;
ret = zoap_packet_parse(&pkt, buf);
ret = zoap_packet_parse(&zpkt, pkt);
if (ret) {
mbedtls_printf("Could not parse packet\n");
goto exit;
}
ret = zoap_handle_request(&pkt, resources,
ret = zoap_handle_request(&zpkt, resources,
(const struct sockaddr *)&ssl);
if (ret < 0) {
mbedtls_printf("No handler for such request (%d)\n",
ret);
}
net_buf_unref(buf);
net_pkt_unref(pkt);
} while (1);

View file

@ -18,22 +18,22 @@
static const socklen_t addrlen = sizeof(struct sockaddr_in6);
static void set_client_address(struct sockaddr *addr, struct net_buf *rx_buf)
static void set_client_address(struct sockaddr *addr, struct net_pkt *rx_pkt)
{
net_ipaddr_copy(&net_sin6(addr)->sin6_addr, &NET_IPV6_BUF(rx_buf)->src);
net_ipaddr_copy(&net_sin6(addr)->sin6_addr, &NET_IPV6_BUF(rx_pkt)->src);
net_sin6(addr)->sin6_family = AF_INET6;
net_sin6(addr)->sin6_port = NET_UDP_BUF(rx_buf)->src_port;
net_sin6(addr)->sin6_port = NET_UDP_BUF(rx_pkt)->src_port;
}
static void udp_received(struct net_context *context,
struct net_buf *buf, int status, void *user_data)
struct net_pkt *pkt, int status, void *user_data)
{
struct udp_context *ctx = user_data;
ARG_UNUSED(context);
ARG_UNUSED(status);
ctx->rx_pkt = buf;
ctx->rx_pkt = pkt;
k_sem_give(&ctx->rx_sem);
}
@ -41,32 +41,32 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
{
struct udp_context *ctx = context;
struct net_context *net_ctx;
struct net_buf *send_buf;
struct net_pkt *send_pkt;
int rc, len;
net_ctx = ctx->net_ctx;
send_buf = net_pkt_get_tx(net_ctx, K_FOREVER);
if (!send_buf) {
printk("cannot create buf\n");
send_pkt = net_pkt_get_tx(net_ctx, K_FOREVER);
if (!send_pkt) {
printk("cannot create pkt\n");
return -EIO;
}
rc = net_pkt_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
rc = net_pkt_append(send_pkt, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
printk("cannot write buf\n");
return -EIO;
}
len = net_buf_frags_len(send_buf);
len = net_pkt_frags_len(send_pkt);
rc = net_context_sendto(send_buf, &net_ctx->remote,
rc = net_context_sendto(send_pkt, &net_ctx->remote,
addrlen, NULL, K_FOREVER, NULL, NULL);
if (rc < 0) {
printk("Cannot send data to peer (%d)\n", rc);
net_pkt_unref(send_buf);
net_pkt_unref(send_pkt);
return -EIO;
} else {
return len;
@ -77,7 +77,8 @@ int udp_rx(void *context, unsigned char *buf, size_t size)
{
struct udp_context *ctx = context;
struct net_context *net_ctx = ctx->net_ctx;
struct net_buf *rx_buf = NULL;
struct net_pkt *rx_pkt = NULL;
struct net_buf *rx_buf;
uint16_t read_bytes;
uint8_t *ptr;
int pos;
@ -91,12 +92,12 @@ int udp_rx(void *context, unsigned char *buf, size_t size)
return -ENOMEM;
}
rx_buf = ctx->rx_pkt;
rx_pkt = ctx->rx_pkt;
set_client_address(&net_ctx->remote, rx_buf);
set_client_address(&net_ctx->remote, rx_pkt);
ptr = net_pkt_appdata(rx_buf);
rx_buf = rx_buf->frags;
ptr = net_pkt_appdata(rx_pkt);
rx_buf = rx_pkt->frags;
len = rx_buf->len - (ptr - rx_buf->data);
pos = 0;

View file

@ -11,7 +11,7 @@
struct udp_context {
struct net_context *net_ctx;
struct net_buf *rx_pkt;
struct net_pkt *rx_pkt;
struct k_sem rx_sem;
int remaining;
char client_id;

View file

@ -77,10 +77,10 @@ static int ipsum_len;
*/
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
#if defined(CONFIG_NET_TCP)
NET_PKT_TX_POOL_DEFINE(echo_tx_tcp, 15);
NET_PKT_TX_SLAB_DEFINE(echo_tx_tcp, 15);
NET_PKT_DATA_POOL_DEFINE(echo_data_tcp, 30);
static struct net_buf_pool *tx_tcp_pool(void)
static struct k_mem_slab *tx_tcp_slab(void)
{
return &echo_tx_tcp;
}
@ -92,10 +92,10 @@ static struct net_buf_pool *data_tcp_pool(void)
#endif
#if defined(CONFIG_NET_UDP)
NET_PKT_TX_POOL_DEFINE(echo_tx_udp, 5);
NET_PKT_TX_SLAB_DEFINE(echo_tx_udp, 5);
NET_PKT_DATA_POOL_DEFINE(echo_data_udp, 20);
static struct net_buf_pool *tx_udp_pool(void)
static struct k_mem_slab *tx_udp_slab(void)
{
return &echo_tx_udp;
}
@ -294,7 +294,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*udp_recv6, tx_udp_pool, data_udp_pool);
net_context_setup_pools(*udp_recv6, tx_udp_slab, data_udp_pool);
ret = net_context_bind(*udp_recv6, (struct sockaddr *)&my_addr6,
sizeof(struct sockaddr_in6));
@ -313,7 +313,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*udp_recv4, tx_udp_pool, data_udp_pool);
net_context_setup_pools(*udp_recv4, tx_udp_slab, data_udp_pool);
ret = net_context_bind(*udp_recv4, (struct sockaddr *)&my_addr4,
sizeof(struct sockaddr_in));
@ -334,7 +334,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*tcp_recv6, tx_tcp_pool, data_tcp_pool);
net_context_setup_pools(*tcp_recv6, tx_tcp_slab, data_tcp_pool);
ret = net_context_bind(*tcp_recv6,
(struct sockaddr *)&my_addr6,
@ -356,7 +356,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*tcp_recv4, tx_tcp_pool, data_tcp_pool);
net_context_setup_pools(*tcp_recv4, tx_tcp_slab, data_tcp_pool);
ret = net_context_bind(*tcp_recv4,
(struct sockaddr *)&my_addr4,
@ -389,25 +389,25 @@ static inline bool wait_reply(const char *name,
return false;
}
static struct net_buf *prepare_send_buf(const char *name,
static struct net_pkt *prepare_send_pkt(const char *name,
struct net_context *context,
int expecting_len)
{
struct net_buf *send_buf;
struct net_pkt *send_pkt;
bool status;
send_buf = net_pkt_get_tx(context, K_FOREVER);
send_pkt = net_pkt_get_tx(context, K_FOREVER);
NET_ASSERT(send_buf);
NET_ASSERT(send_pkt);
status = net_pkt_append(send_buf, expecting_len, lorem_ipsum,
status = net_pkt_append(send_pkt, expecting_len, lorem_ipsum,
K_FOREVER);
if (!status) {
NET_ERR("%s: cannot create send buf", name);
NET_ERR("%s: cannot create send pkt", name);
return NULL;
}
return send_buf;
return send_pkt;
}
static inline void udp_sent(struct net_context *context,
@ -424,10 +424,10 @@ static inline void udp_sent(struct net_context *context,
}
static inline void set_dst_addr(sa_family_t family,
struct net_buf *buf,
struct net_pkt *pkt,
struct sockaddr *dst_addr)
{
ARG_UNUSED(buf);
ARG_UNUSED(pkt);
#if defined(CONFIG_NET_IPV6)
if (family == AF_INET6) {
@ -453,37 +453,38 @@ static inline void set_dst_addr(sa_family_t family,
}
#if defined(CONFIG_NET_UDP)
static bool compare_udp_data(struct net_buf *buf, int expecting_len)
static bool compare_udp_data(struct net_pkt *pkt, int expecting_len)
{
uint8_t *ptr = net_pkt_appdata(buf);
uint8_t *ptr = net_pkt_appdata(pkt);
struct net_buf *frag;
int pos = 0;
int len;
/* Buf will now point to first fragment with IP header
/* frag will now point to first fragment with IP header
* in it.
*/
buf = buf->frags;
frag = pkt->frags;
/* Do not include the protocol headers in the first fragment.
* The remaining fragments contain only data so the user data
* length is directly the fragment len.
*/
len = buf->len - (ptr - buf->data);
len = frag->len - (ptr - frag->data);
while (buf) {
while (frag) {
if (memcmp(ptr, lorem_ipsum + pos, len)) {
NET_DBG("Invalid data received");
return false;
} else {
pos += len;
buf = buf->frags;
if (!buf) {
frag = frag->frags;
if (!frag) {
break;
}
ptr = buf->data;
len = buf->len;
ptr = frag->data;
len = frag->len;
}
}
@ -509,7 +510,7 @@ static bool send_udp_data(struct net_context *udp,
struct data *data)
{
bool status = false;
struct net_buf *send_buf;
struct net_pkt *send_pkt;
struct sockaddr dst_addr;
socklen_t addrlen;
size_t len;
@ -517,18 +518,18 @@ static bool send_udp_data(struct net_context *udp,
data->expecting_udp = sys_rand32_get() % ipsum_len;
send_buf = prepare_send_buf(proto, udp, data->expecting_udp);
if (!send_buf) {
send_pkt = prepare_send_pkt(proto, udp, data->expecting_udp);
if (!send_pkt) {
goto out;
}
len = net_buf_frags_len(send_buf);
len = net_pkt_get_len(send_pkt);
NET_ASSERT_INFO(data->expecting_udp == len,
"Data to send %d bytes, real len %zu",
data->expecting_udp, len);
set_dst_addr(family, send_buf, &dst_addr);
set_dst_addr(family, send_pkt, &dst_addr);
if (family == AF_INET6) {
addrlen = sizeof(struct sockaddr_in6);
@ -536,13 +537,13 @@ static bool send_udp_data(struct net_context *udp,
addrlen = sizeof(struct sockaddr_in);
}
ret = net_context_sendto(send_buf, &dst_addr,
ret = net_context_sendto(send_pkt, &dst_addr,
addrlen, udp_sent, 0,
UINT_TO_POINTER(len),
proto);
if (ret < 0) {
NET_ERR("Cannot send %s data to peer (%d)", proto, ret);
net_pkt_unref(send_buf);
net_pkt_unref(send_pkt);
} else {
status = true;
}
@ -552,11 +553,11 @@ out:
}
static void udp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
sa_family_t family = net_pkt_family(buf);
sa_family_t family = net_pkt_family(pkt);
struct data *data = user_data;
struct k_sem *recv;
@ -569,16 +570,16 @@ static void udp_received(struct net_context *context,
recv = &conf.recv_ipv6;
}
if (data->expecting_udp != net_pkt_appdatalen(buf)) {
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
NET_ERR("Sent %d bytes, received %u bytes",
data->expecting_udp, net_pkt_appdatalen(buf));
data->expecting_udp, net_pkt_appdatalen(pkt));
}
if (!compare_udp_data(buf, data->expecting_udp)) {
if (!compare_udp_data(pkt, data->expecting_udp)) {
NET_DBG("Data mismatch");
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
k_sem_give(recv);
}
@ -613,17 +614,17 @@ static void send_udp(struct net_context *udp,
#endif /* CONFIG_NET_UDP */
#if defined(CONFIG_NET_TCP)
static bool compare_tcp_data(struct net_buf *buf, int expecting_len,
static bool compare_tcp_data(struct net_pkt *pkt, int expecting_len,
int received_len)
{
uint8_t *ptr = net_pkt_appdata(buf), *start;
uint8_t *ptr = net_pkt_appdata(pkt), *start;
int pos = 0;
struct net_buf *frag;
int len;
/* frag will point to first fragment with IP header in it.
*/
frag = buf->frags;
frag = pkt->frags;
/* Do not include the protocol headers for the first fragment.
* The remaining fragments contain only data so the user data
@ -650,13 +651,13 @@ static bool compare_tcp_data(struct net_buf *buf, int expecting_len,
len = frag->len;
}
NET_DBG("Compared %d bytes, all ok", net_pkt_appdatalen(buf));
NET_DBG("Compared %d bytes, all ok", net_pkt_appdatalen(pkt));
return true;
}
static void tcp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
@ -665,27 +666,27 @@ static void tcp_received(struct net_context *context,
ARG_UNUSED(status);
if (!buf || net_pkt_appdatalen(buf) == 0) {
if (buf) {
net_pkt_unref(buf);
if (!pkt || net_pkt_appdatalen(pkt) == 0) {
if (pkt) {
net_pkt_unref(pkt);
}
return;
}
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
proto = "IPv6";
} else {
proto = "IPv4";
}
NET_DBG("Sent %d bytes, received %u bytes",
data->expecting_tcp, net_pkt_appdatalen(buf));
data->expecting_tcp, net_pkt_appdatalen(pkt));
if (!compare_tcp_data(buf, data->expecting_tcp, data->received_tcp)) {
if (!compare_tcp_data(pkt, data->expecting_tcp, data->received_tcp)) {
NET_DBG("Data mismatch");
} else {
data->received_tcp += net_pkt_appdatalen(buf);
data->received_tcp += net_pkt_appdatalen(pkt);
}
if (data->expecting_tcp <= data->received_tcp) {
@ -693,7 +694,7 @@ static void tcp_received(struct net_context *context,
send_tcp_data(context, proto, data);
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
static void setup_tcp_recv(struct net_context *tcp,
@ -729,7 +730,7 @@ static bool send_tcp_data(struct net_context *ctx,
char *proto,
struct data *data)
{
struct net_buf *send_buf;
struct net_pkt *send_pkt;
bool status = false;
size_t len;
int ret;
@ -737,22 +738,22 @@ static bool send_tcp_data(struct net_context *ctx,
data->expecting_tcp = sys_rand32_get() % ipsum_len;
data->received_tcp = 0;
send_buf = prepare_send_buf(proto, ctx, data->expecting_tcp);
if (!send_buf) {
send_pkt = prepare_send_pkt(proto, ctx, data->expecting_tcp);
if (!send_pkt) {
goto out;
}
len = net_buf_frags_len(send_buf);
len = net_pkt_get_len(send_pkt);
NET_ASSERT_INFO(data->expecting_tcp == len,
"%s data to send %d bytes, real len %zu",
proto, data->expecting_tcp, len);
ret = net_context_send(send_buf, tcp_sent, 0,
ret = net_context_send(send_pkt, tcp_sent, 0,
UINT_TO_POINTER(len), proto);
if (ret < 0) {
NET_ERR("Cannot send %s data to peer (%d)", proto, ret);
net_pkt_unref(send_buf);
net_pkt_unref(send_pkt);
} else {
status = true;
}

View file

@ -56,10 +56,10 @@ static struct in_addr in4addr_my = MY_IP4ADDR;
*/
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
#if defined(CONFIG_NET_TCP)
NET_PKT_TX_POOL_DEFINE(echo_tx_tcp, 15);
NET_PKT_TX_SLAB_DEFINE(echo_tx_tcp, 15);
NET_PKT_DATA_POOL_DEFINE(echo_data_tcp, 30);
static struct net_buf_pool *tx_tcp_pool(void)
static struct k_mem_slab *tx_tcp_slab(void)
{
return &echo_tx_tcp;
}
@ -71,10 +71,10 @@ static struct net_buf_pool *data_tcp_pool(void)
#endif
#if defined(CONFIG_NET_UDP)
NET_PKT_TX_POOL_DEFINE(echo_tx_udp, 5);
NET_PKT_TX_SLAB_DEFINE(echo_tx_udp, 5);
NET_PKT_DATA_POOL_DEFINE(echo_data_udp, 20);
static struct net_buf_pool *tx_udp_pool(void)
static struct k_mem_slab *tx_udp_slab(void)
{
return &echo_tx_udp;
}
@ -184,7 +184,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*udp_recv6, tx_udp_pool, data_udp_pool);
net_context_setup_pools(*udp_recv6, tx_udp_slab, data_udp_pool);
ret = net_context_bind(*udp_recv6, (struct sockaddr *)&my_addr6,
sizeof(struct sockaddr_in6));
@ -203,7 +203,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*udp_recv4, tx_udp_pool, data_udp_pool);
net_context_setup_pools(*udp_recv4, tx_udp_slab, data_udp_pool);
ret = net_context_bind(*udp_recv4, (struct sockaddr *)&my_addr4,
sizeof(struct sockaddr_in));
@ -224,7 +224,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*tcp_recv6, tx_tcp_pool, data_tcp_pool);
net_context_setup_pools(*tcp_recv6, tx_tcp_slab, data_tcp_pool);
ret = net_context_bind(*tcp_recv6,
(struct sockaddr *)&my_addr6,
@ -252,7 +252,7 @@ static inline bool get_context(struct net_context **udp_recv4,
return false;
}
net_context_setup_pools(*tcp_recv4, tx_tcp_pool, data_tcp_pool);
net_context_setup_pools(*tcp_recv4, tx_tcp_slab, data_tcp_pool);
ret = net_context_bind(*tcp_recv4,
(struct sockaddr *)&my_addr4,
@ -274,32 +274,33 @@ static inline bool get_context(struct net_context **udp_recv4,
return true;
}
static struct net_buf *build_reply_buf(const char *name,
static struct net_pkt *build_reply_pkt(const char *name,
struct net_context *context,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct net_buf *reply_buf, *frag, *tmp;
struct net_pkt *reply_pkt;
struct net_buf *frag, *tmp;
int header_len, recv_len, reply_len;
NET_INFO("%s received %d bytes", name,
net_pkt_appdatalen(buf));
net_pkt_appdatalen(pkt));
if (net_pkt_appdatalen(buf) == 0) {
if (net_pkt_appdatalen(pkt) == 0) {
return NULL;
}
reply_buf = net_pkt_get_tx(context, K_FOREVER);
reply_pkt = net_pkt_get_tx(context, K_FOREVER);
NET_ASSERT(reply_buf);
NET_ASSERT(reply_pkt);
recv_len = net_buf_frags_len(buf->frags);
recv_len = net_pkt_get_len(pkt);
tmp = buf->frags;
tmp = pkt->frags;
/* First fragment will contain IP header so move the data
* down in order to get rid of it.
*/
header_len = net_pkt_appdata(buf) - tmp->data;
header_len = net_pkt_appdata(pkt) - tmp->data;
NET_ASSERT(header_len < CONFIG_NET_BUF_DATA_SIZE);
@ -326,25 +327,25 @@ static struct net_buf *build_reply_buf(const char *name,
* in sending side we add the link layer
* header if needed.
*/
net_pkt_set_ll_reserve(reply_buf, 0);
net_pkt_set_ll_reserve(reply_pkt, 0);
}
NET_ASSERT(net_buf_tailroom(frag) >= tmp->len);
memcpy(net_buf_add(frag, tmp->len), tmp->data, tmp->len);
net_buf_frag_add(reply_buf, frag);
net_pkt_frag_add(reply_pkt, frag);
tmp = net_pkt_frag_del(buf, tmp);
tmp = net_pkt_frag_del(pkt, NULL, tmp);
}
reply_len = net_buf_frags_len(reply_buf->frags);
reply_len = net_pkt_get_len(reply_pkt);
NET_ASSERT_INFO((recv_len - header_len) == reply_len,
"Received %d bytes, sending %d bytes",
recv_len - header_len, reply_len);
return reply_buf;
return reply_pkt;
}
static inline void pkt_sent(struct net_context *context,
@ -359,62 +360,62 @@ static inline void pkt_sent(struct net_context *context,
#if defined(CONFIG_NET_UDP)
static inline void set_dst_addr(sa_family_t family,
struct net_buf *buf,
struct net_pkt *pkt,
struct sockaddr *dst_addr)
{
#if defined(CONFIG_NET_IPV6)
if (family == AF_INET6) {
net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr,
&NET_IPV6_BUF(buf)->src);
&NET_IPV6_BUF(pkt)->src);
net_sin6(dst_addr)->sin6_family = AF_INET6;
net_sin6(dst_addr)->sin6_port = NET_UDP_BUF(buf)->src_port;
net_sin6(dst_addr)->sin6_port = NET_UDP_BUF(pkt)->src_port;
}
#endif /* CONFIG_NET_IPV6) */
#if defined(CONFIG_NET_IPV4)
if (family == AF_INET) {
net_ipaddr_copy(&net_sin(dst_addr)->sin_addr,
&NET_IPV4_BUF(buf)->src);
&NET_IPV4_BUF(pkt)->src);
net_sin(dst_addr)->sin_family = AF_INET;
net_sin(dst_addr)->sin_port = NET_UDP_BUF(buf)->src_port;
net_sin(dst_addr)->sin_port = NET_UDP_BUF(pkt)->src_port;
}
#endif /* CONFIG_NET_IPV6) */
}
static void udp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
struct net_buf *reply_buf;
struct net_pkt *reply_pkt;
struct sockaddr dst_addr;
sa_family_t family = net_pkt_family(buf);
sa_family_t family = net_pkt_family(pkt);
static char dbg[MAX_DBG_PRINT + 1];
int ret;
snprintk(dbg, MAX_DBG_PRINT, "UDP IPv%c",
family == AF_INET6 ? '6' : '4');
set_dst_addr(family, buf, &dst_addr);
set_dst_addr(family, pkt, &dst_addr);
reply_buf = build_reply_buf(dbg, context, buf);
reply_pkt = build_reply_pkt(dbg, context, pkt);
net_pkt_unref(buf);
net_pkt_unref(pkt);
if (!reply_buf) {
if (!reply_pkt) {
return;
}
ret = net_context_sendto(reply_buf, &dst_addr,
ret = net_context_sendto(reply_pkt, &dst_addr,
family == AF_INET6 ?
sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in),
pkt_sent, 0,
UINT_TO_POINTER(net_buf_frags_len(reply_buf)),
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)),
user_data);
if (ret < 0) {
NET_ERR("Cannot send data to peer (%d)", ret);
net_pkt_unref(reply_buf);
net_pkt_unref(reply_pkt);
}
}
@ -441,39 +442,39 @@ static void setup_udp_recv(struct net_context *udp_recv4,
#if defined(CONFIG_NET_TCP)
static void tcp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
static char dbg[MAX_DBG_PRINT + 1];
struct net_buf *reply_buf;
struct net_pkt *reply_pkt;
sa_family_t family;
int ret;
if (!buf) {
if (!pkt) {
/* EOF condition */
return;
}
family = net_pkt_family(buf);
family = net_pkt_family(pkt);
snprintk(dbg, MAX_DBG_PRINT, "TCP IPv%c",
family == AF_INET6 ? '6' : '4');
reply_buf = build_reply_buf(dbg, context, buf);
reply_pkt = build_reply_pkt(dbg, context, pkt);
net_pkt_unref(buf);
net_pkt_unref(pkt);
if (!reply_buf) {
if (!reply_pkt) {
return;
}
ret = net_context_send(reply_buf, pkt_sent, K_NO_WAIT,
UINT_TO_POINTER(net_buf_frags_len(reply_buf)),
ret = net_context_send(reply_pkt, pkt_sent, K_NO_WAIT,
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)),
NULL);
if (ret < 0) {
NET_ERR("Cannot send data to peer (%d)", ret);
net_pkt_unref(reply_buf);
net_pkt_unref(reply_pkt);
quit();
}

View file

@ -14,7 +14,7 @@
NET_BUF_POOL_DEFINE(http_pool, HTTP_POOL_BUF_CTR, HTTP_POOL_BUF_SIZE, 0, NULL);
void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx)
void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_pkt *rx)
{
struct http_client_ctx *http_ctx;
struct net_buf *data_buf = NULL;
@ -32,9 +32,9 @@ void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx)
}
data_len = min(net_pkt_appdatalen(rx), HTTP_POOL_BUF_SIZE);
offset = net_buf_frags_len(rx) - data_len;
offset = net_pkt_get_len(rx) - data_len;
rc = net_pkt_linear_copy(data_buf, rx, offset, data_len);
rc = net_frag_linear_copy(data_buf, rx->frags, offset, data_len);
if (rc != 0) {
rc = -ENOMEM;
goto lb_exit;
@ -50,15 +50,15 @@ void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx)
lb_exit:
net_buf_unref(data_buf);
net_buf_unref(rx);
net_pkt_unref(rx);
}
#else
void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx)
void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_pkt *rx)
{
struct http_client_ctx *http_ctx;
struct net_buf *buf = rx;
struct net_buf *frag = rx->frags;
uint16_t offset;
if (!rx) {
@ -67,19 +67,19 @@ void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx)
http_ctx = CONTAINER_OF(tcp_ctx, struct http_client_ctx, tcp_ctx);
offset = net_buf_frags_len(buf) - net_pkt_appdatalen(buf);
offset = net_pkt_frags_len(rx) - net_pkt_appdatalen(rx);
/* find the fragment */
while (buf && offset >= buf->len) {
offset -= buf->len;
buf = buf->frags;
while (frag && offset >= frag->len) {
offset -= frag->len;
frag = frag->frags;
}
while (buf) {
while (frag) {
(void)http_parser_execute(&http_ctx->parser,
&http_ctx->settings,
buf->data + offset,
buf->len - offset);
frag->data + offset,
frag->len - offset);
/* after the first iteration, we set offset to 0 */
offset = 0;
@ -91,11 +91,11 @@ void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx)
goto lb_exit;
}
buf = buf->frags;
frag = frag->frags;
}
lb_exit:
net_buf_unref(rx);
net_pkt_unref(rx);
}
#endif

View file

@ -10,6 +10,6 @@
#include "tcp_client.h"
/* HTTP reception callback */
void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_buf *rx);
void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_pkt *rx);
#endif

View file

@ -78,7 +78,7 @@ lb_exit:
}
static
void recv_cb(struct net_context *net_ctx, struct net_buf *rx, int status,
void recv_cb(struct net_context *net_ctx, struct net_pkt *rx, int status,
void *data)
{
struct tcp_client_ctx *ctx = (struct tcp_client_ctx *)data;
@ -93,14 +93,14 @@ void recv_cb(struct net_context *net_ctx, struct net_buf *rx, int status,
goto lb_exit;
}
/* receive_cb must take ownership of the rx buffer */
/* receive_cb must take ownership of the rx packet */
if (ctx->receive_cb) {
ctx->receive_cb(ctx, rx);
return;
}
lb_exit:
net_buf_unref(rx);
net_pkt_unref(rx);
}
int tcp_connect(struct tcp_client_ctx *ctx, const char *server_addr,

View file

@ -18,7 +18,7 @@ struct tcp_client_ctx {
/* Network timeout */
int32_t timeout;
/* User defined call back*/
void (*receive_cb)(struct tcp_client_ctx *ctx, struct net_buf *rx);
void (*receive_cb)(struct tcp_client_ctx *ctx, struct net_pkt *rx);
};
int tcp_set_local_addr(struct tcp_client_ctx *ctx, const char *local_addr);

View file

@ -82,7 +82,7 @@ static int http_url_cmp(const char *url, uint16_t url_len,
static void http_tx(struct http_server_ctx *http_ctx);
void http_rx_tx(struct net_context *net_ctx, struct net_buf *rx, int status,
void http_rx_tx(struct net_context *net_ctx, struct net_pkt *rx, int status,
void *user_data)
{
struct http_server_ctx *http_ctx = NULL;
@ -128,8 +128,8 @@ void http_rx_tx(struct net_context *net_ctx, struct net_buf *rx, int status,
goto lb_exit;
}
offset = net_buf_frags_len(rx) - rcv_len;
rc = net_pkt_linear_copy(data, rx, offset, rcv_len);
offset = net_pkt_get_len(rx) - rcv_len;
rc = net_frag_linear_copy(data, rx->frags, offset, rcv_len);
if (rc != 0) {
printf("[%s:%d] Linear copy error\n", __func__, __LINE__);
goto lb_exit;
@ -151,8 +151,8 @@ void http_rx_tx(struct net_context *net_ctx, struct net_buf *rx, int status,
}
lb_exit:
net_buf_unref(data);
net_buf_unref(rx);
net_pkt_frag_unref(data);
net_pkt_unref(rx);
http_ctx_release(http_ctx);
}

View file

@ -18,11 +18,11 @@ void http_accept_cb(struct net_context *net_ctx, struct sockaddr *addr,
* and writes an HTTP 1.1 200 OK response with client
* header fields or an error message
* @param ctx The network context
* @param rx The reception buffer
* @param rx The received packet
* @param status Connection status, see `net_context_recv_cb_t`
* @param user_data User-provided data
*/
void http_rx_tx(struct net_context *ctx, struct net_buf *rx, int status,
void http_rx_tx(struct net_context *ctx, struct net_pkt *rx, int status,
void *user_data);
/**

View file

@ -138,18 +138,18 @@ panic(const char *msg)
static int
transmit(struct net_context *ctx, char buffer[], size_t len)
{
struct net_buf *send_buf;
struct net_pkt *send_pkt;
send_buf = net_pkt_get_tx(ctx, K_FOREVER);
if (!send_buf) {
send_pkt = net_pkt_get_tx(ctx, K_FOREVER);
if (!send_pkt) {
return -ENOMEM;
}
if (!net_pkt_append(send_buf, len, buffer, K_FOREVER)) {
if (!net_pkt_append(send_pkt, len, buffer, K_FOREVER)) {
return -EINVAL;
}
return net_context_send(send_buf, NULL, K_NO_WAIT, NULL, NULL);
return net_context_send(send_pkt, NULL, K_NO_WAIT, NULL, NULL);
}
static void
@ -271,7 +271,7 @@ process_command(struct zirc *irc, char *cmd, size_t len)
#undef CMD
static void
on_context_recv(struct net_context *ctx, struct net_buf *buf,
on_context_recv(struct net_context *ctx, struct net_pkt *pkt,
int status, void *data)
{
struct zirc *irc = data;
@ -280,7 +280,7 @@ on_context_recv(struct net_context *ctx, struct net_buf *buf,
size_t len;
uint16_t pos = 0, cmd_len = 0;
if (!buf) {
if (!pkt) {
/* TODO: notify of disconnection, maybe reconnect? */
NET_ERR("Disconnected\n");
return;
@ -289,14 +289,14 @@ on_context_recv(struct net_context *ctx, struct net_buf *buf,
if (status) {
/* TODO: handle connection error */
NET_ERR("Connection error: %d\n", -status);
net_pkt_unref(buf);
net_pkt_unref(pkt);
return;
}
/* tmp points to fragment containing IP header */
tmp = buf->frags;
tmp = pkt->frags;
/* skip pos to the first TCP payload */
pos = net_pkt_appdata(buf) - tmp->data;
pos = net_pkt_appdata(pkt) - tmp->data;
while (tmp) {
len = tmp->len - pos;
@ -314,13 +314,13 @@ on_context_recv(struct net_context *ctx, struct net_buf *buf,
break;
}
tmp = net_pkt_read(tmp, pos, &pos, len, cmd_buf + cmd_len);
tmp = net_frag_read(tmp, pos, &pos, len, cmd_buf + cmd_len);
cmd_len += len;
if (end_of_line) {
/* skip the /n char after /r */
if (tmp) {
tmp = net_pkt_read(tmp, pos, &pos, 1, NULL);
tmp = net_frag_read(tmp, pos, &pos, 1, NULL);
}
cmd_buf[cmd_len] = '\0';
@ -329,7 +329,7 @@ on_context_recv(struct net_context *ctx, struct net_buf *buf,
}
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
/* TODO: handle messages that spans multiple packets? */
}

View file

@ -95,7 +95,8 @@ static int led_get(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const char *str;
uint8_t *payload;
@ -104,8 +105,8 @@ static int led_get(struct zoap_resource *resource,
id = zoap_header_get_id(request);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
@ -114,9 +115,9 @@ static int led_get(struct zoap_resource *resource,
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -147,10 +148,10 @@ static int led_get(struct zoap_resource *resource,
return -EINVAL;
}
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return r;
@ -160,7 +161,8 @@ static int led_post(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const char *str;
uint8_t *payload;
@ -176,8 +178,8 @@ static int led_post(struct zoap_resource *resource,
id = zoap_header_get_id(request);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
@ -186,9 +188,9 @@ static int led_post(struct zoap_resource *resource,
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -225,10 +227,10 @@ static int led_post(struct zoap_resource *resource,
return -EINVAL;
}
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return r;
@ -238,7 +240,8 @@ static int led_put(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const char *str;
uint8_t *payload;
@ -259,8 +262,8 @@ static int led_put(struct zoap_resource *resource,
id = zoap_header_get_id(request);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
@ -269,9 +272,9 @@ static int led_put(struct zoap_resource *resource,
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -304,10 +307,10 @@ static int led_put(struct zoap_resource *resource,
return -EINVAL;
}
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return r;
@ -318,7 +321,8 @@ static int dummy_get(struct zoap_resource *resource,
const struct sockaddr *from)
{
static const char dummy_str[] = "Just a test\n";
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload;
uint16_t len, id;
@ -326,8 +330,8 @@ static int dummy_get(struct zoap_resource *resource,
id = zoap_header_get_id(request);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
@ -336,9 +340,9 @@ static int dummy_get(struct zoap_resource *resource,
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -361,10 +365,10 @@ static int dummy_get(struct zoap_resource *resource,
return -EINVAL;
}
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return r;
@ -402,7 +406,7 @@ static struct zoap_resource resources[] = {
};
static void udp_receive(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
@ -410,28 +414,28 @@ static void udp_receive(struct net_context *context,
struct sockaddr_in6 from;
int r, header_len;
net_ipaddr_copy(&from.sin6_addr, &NET_IPV6_BUF(buf)->src);
from.sin6_port = NET_UDP_BUF(buf)->src_port;
net_ipaddr_copy(&from.sin6_addr, &NET_IPV6_BUF(pkt)->src);
from.sin6_port = NET_UDP_BUF(pkt)->src_port;
from.sin6_family = AF_INET6;
/*
* zoap expects that buffer->data starts at the
* beginning of the CoAP header
*/
header_len = net_pkt_appdata(buf) - buf->frags->data;
net_buf_pull(buf->frags, header_len);
header_len = net_pkt_appdata(pkt) - pkt->frags->data;
net_buf_pull(pkt->frags, header_len);
r = zoap_packet_parse(&request, buf);
r = zoap_packet_parse(&request, pkt);
if (r < 0) {
NET_ERR("Invalid data received (%d)\n", r);
net_pkt_unref(buf);
net_pkt_unref(pkt);
return;
}
r = zoap_handle_request(&request, resources,
(const struct sockaddr *) &from);
net_pkt_unref(buf);
net_pkt_unref(pkt);
if (r < 0) {
NET_ERR("No handler for such request (%d)\n", r);

View file

@ -32,42 +32,42 @@
NET_BUF_POOL_DEFINE(tcp_msg_pool, TCP_BUF_CTR, TCP_BUF_SIZE, 0, NULL);
static void tcp_received(struct net_context *context,
struct net_buf *buf, int status, void *user_data)
struct net_pkt *pkt, int status, void *user_data)
{
ARG_UNUSED(context);
struct tcp_context *ctx = user_data;
ctx->rx_pkt = buf;
ctx->rx_pkt = pkt;
}
int tcp_tx(void *context, const unsigned char *buf, size_t size)
{
struct tcp_context *ctx = context;
struct net_context *tcp_ctx;
struct net_buf *send_buf;
struct net_pkt *send_pkt;
int rc, len;
tcp_ctx = ctx->net_ctx;
send_buf = net_pkt_get_tx(tcp_ctx, K_FOREVER);
if (!send_buf) {
printk("cannot create buf\n");
send_pkt = net_pkt_get_tx(tcp_ctx, K_FOREVER);
if (!send_pkt) {
printk("cannot create pkt\n");
return -EIO;
}
rc = net_pkt_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
rc = net_pkt_append(send_pkt, size, (uint8_t *) buf, K_FOREVER);
if (!rc) {
printk("cannot write buf\n");
return -EIO;
}
len = net_buf_frags_len(send_buf);
len = net_pkt_get_len(send_pkt);
rc = net_context_send(send_buf, NULL, ctx->timeout, NULL, NULL);
rc = net_context_send(send_pkt, NULL, ctx->timeout, NULL, NULL);
if (rc < 0) {
printk("Cannot send IPv4 data to peer (%d)\n", rc);
net_pkt_unref(send_buf);
net_pkt_unref(send_pkt);
return -EIO;
} else {
return len;
@ -97,13 +97,13 @@ int tcp_rx(void *context, unsigned char *buf, size_t size)
return -EIO;
}
offset = net_buf_frags_len(ctx->rx_pkt) - read_bytes;
rc = net_pkt_linear_copy(data, ctx->rx_pkt, offset, read_bytes);
ptr = net_pkt_appdata(data);
offset = net_pkt_get_len(ctx->rx_pkt) - read_bytes;
rc = net_frag_linear_copy(data, ctx->rx_pkt->frags, offset, read_bytes);
ptr = net_pkt_appdata(ctx->rx_pkt);
memcpy(buf, ptr, read_bytes);
net_pkt_unref(ctx->rx_pkt);
net_pkt_unref(data);
net_buf_unref(data);
return read_bytes;
}

View file

@ -9,12 +9,12 @@
#include <net/net_context.h>
#include <net/net_ip.h>
#include <net/buf.h>
#include <net/net_pkt.h>
struct tcp_context {
struct net_context *net_ctx;
struct sockaddr local_sock;
struct net_buf *rx_pkt;
struct net_pkt *rx_pkt;
int32_t timeout;
};

View file

@ -98,23 +98,23 @@ static bool is_sid_valid(const char *sid, size_t len)
static int transmitv(struct net_context *conn, int iovcnt,
struct io_vec *iov)
{
struct net_buf *buf;
struct net_pkt *pkt;
int i;
buf = net_pkt_get_tx(conn, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(conn, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
for (i = 0; i < iovcnt; i++) {
if (!net_pkt_append(buf, iov[i].len, iov[i].base, K_FOREVER)) {
net_pkt_unref(buf);
if (!net_pkt_append(pkt, iov[i].len, iov[i].base, K_FOREVER)) {
net_pkt_unref(pkt);
return -ENOMEM;
}
}
return net_context_send(buf, NULL, K_NO_WAIT, NULL, NULL);
return net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL);
}
static inline int transmit(struct net_context *conn, const char buffer[],
@ -531,7 +531,7 @@ int nats_publish(const struct nats *nats,
});
}
static void receive_cb(struct net_context *ctx, struct net_buf *buf, int status,
static void receive_cb(struct net_context *ctx, struct net_pkt *pkt, int status,
void *user_data)
{
struct nats *nats = user_data;
@ -541,19 +541,19 @@ static void receive_cb(struct net_context *ctx, struct net_buf *buf, int status,
size_t len;
uint8_t *end_of_line;
if (!buf) {
if (!pkt) {
/* FIXME: How to handle disconnection? */
return;
}
if (status) {
/* FIXME: How to handle connectio error? */
net_buf_unref(buf);
net_pkt_unref(pkt);
return;
}
tmp = buf->frags;
pos = net_pkt_appdata(buf) - tmp->data;
tmp = pkt->frags;
pos = net_pkt_appdata(pkt) - tmp->data;
while (tmp) {
len = tmp->len - pos;
@ -567,14 +567,14 @@ static void receive_cb(struct net_context *ctx, struct net_buf *buf, int status,
break;
}
tmp = net_pkt_read(tmp, pos, &pos, len, cmd_buf + cmd_len);
tmp = net_frag_read(tmp, pos, &pos, len, cmd_buf + cmd_len);
cmd_len += len;
if (end_of_line) {
int ret;
if (tmp) {
tmp = net_pkt_read(tmp, pos, &pos, 1, NULL);
tmp = net_frag_read(tmp, pos, &pos, 1, NULL);
}
cmd_buf[cmd_len] = '\0';
@ -589,7 +589,7 @@ static void receive_cb(struct net_context *ctx, struct net_buf *buf, int status,
}
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
int nats_connect(struct nats *nats, struct sockaddr *addr, socklen_t addrlen)

View file

@ -63,7 +63,7 @@ static struct device *uart_dev;
/* SLIP state machine */
static uint8_t slip_state = STATE_OK;
static struct net_buf *pkt_curr;
static struct net_pkt *pkt_curr;
/* General helpers */
@ -154,9 +154,9 @@ static int slip_process_byte(unsigned char c)
net_pkt_unref(pkt_curr);
return 0;
}
net_buf_frag_insert(pkt_curr, buf);
net_pkt_frag_insert(pkt_curr, buf);
} else {
buf = net_buf_frag_last(pkt_curr);
buf = net_buf_frag_last(pkt_curr->frags);
}
if (!net_buf_tailroom(buf)) {
@ -207,7 +207,7 @@ static void interrupt_handler(struct device *dev)
SYS_LOG_DBG("Full packet %p", pkt_curr);
net_buf_put(&rx_queue, pkt_curr);
k_fifo_put(&rx_queue, pkt_curr);
pkt_curr = NULL;
}
}
@ -218,11 +218,12 @@ static void interrupt_handler(struct device *dev)
/* Allocate and send data to USB Host */
static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
{
struct net_buf *buf, *pkt;
struct net_pkt *pkt;
struct net_buf *buf;
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
if (!pkt) {
SYS_LOG_DBG("No buf available");
SYS_LOG_DBG("No pkt available");
return;
}
@ -233,7 +234,7 @@ static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
return;
}
net_buf_frag_insert(pkt, buf);
net_pkt_frag_insert(pkt, buf);
SYS_LOG_DBG("queue pkt %p buf %p len %u", pkt, buf, len);
@ -247,7 +248,7 @@ static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
/* simulate FCS */
net_buf_add(buf, 2);
net_buf_put(&tx_queue, pkt);
k_fifo_put(&tx_queue, pkt);
}
static void get_ieee_addr(void)
@ -290,9 +291,9 @@ static void send_pkt_report(uint8_t seq, uint8_t status, uint8_t num_tx)
send_data(cfg, report, sizeof(report));
}
static void process_data(struct net_buf *pkt)
static void process_data(struct net_pkt *pkt)
{
struct net_buf *buf = net_buf_frag_last(pkt);
struct net_buf *buf = net_buf_frag_last(pkt->frags);
uint8_t seq, num_attr;
int ret, i;
@ -333,9 +334,9 @@ static void set_channel(uint8_t chan)
radio_api->set_channel(ieee802154_dev, chan);
}
static void process_config(struct net_buf *pkt)
static void process_config(struct net_pkt *pkt)
{
struct net_buf *buf = net_buf_frag_last(pkt);
struct net_buf *buf = net_buf_frag_last(pkt->frags);
uint8_t cmd = net_buf_pull_u8(buf);
SYS_LOG_DBG("Process config %c", cmd);
@ -357,11 +358,12 @@ static void rx_thread(void)
SYS_LOG_INF("RX thread started");
while (1) {
struct net_buf *pkt, *buf;
struct net_pkt *pkt;
struct net_buf *buf;
uint8_t specifier;
pkt = net_buf_get(&rx_queue, K_FOREVER);
buf = net_buf_frag_last(pkt);
pkt = k_fifo_get(&rx_queue, K_FOREVER);
buf = net_buf_frag_last(pkt->frags);
SYS_LOG_DBG("Got pkt %p buf %p", pkt, buf);
@ -431,14 +433,15 @@ static void tx_thread(void)
k_sem_give(&tx_sem);
while (1) {
struct net_buf *pkt, *buf;
struct net_pkt *pkt;
struct net_buf *buf;
size_t len;
k_sem_take(&tx_sem, K_FOREVER);
pkt = net_buf_get(&tx_queue, K_FOREVER);
buf = net_buf_frag_last(pkt);
len = net_buf_frags_len(pkt);
pkt = k_fifo_get(&tx_queue, K_FOREVER);
buf = net_buf_frag_last(pkt->frags);
len = net_pkt_get_len(pkt);
SYS_LOG_DBG("Send pkt %p buf %p len %d", pkt, buf, len);
@ -616,18 +619,18 @@ void ieee802154_init(struct net_if *iface)
SYS_LOG_DBG("");
}
int net_recv_data(struct net_if *iface, struct net_buf *pkt)
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
{
SYS_LOG_DBG("Got data, buf %p, len %d frags->len %d",
pkt, pkt->len, net_buf_frags_len(pkt));
SYS_LOG_DBG("Got data, pkt %p, frags->len %d",
pkt, net_pkt_get_len(pkt));
net_buf_put(&tx_queue, pkt);
k_fifo_put(&tx_queue, pkt);
return 0;
}
extern enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
SYS_LOG_DBG("");
@ -635,7 +638,7 @@ extern enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
return NET_CONTINUE;
}
int ieee802154_radio_send(struct net_if *iface, struct net_buf *buf)
int ieee802154_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
SYS_LOG_DBG("");

View file

@ -70,7 +70,7 @@ static struct device *wpanusb_dev;
static struct ieee802154_radio_api *radio_api;
static struct device *ieee802154_dev;
static struct nano_fifo tx_queue;
static struct k_fifo tx_queue;
/**
* Stack for the tx thread.
@ -349,9 +349,9 @@ static int stop(void)
return radio_api->stop(ieee802154_dev);
}
static int tx(struct net_buf *pkt)
static int tx(struct net_pkt *pkt)
{
struct net_buf *buf = net_buf_frag_last(pkt);
struct net_buf *buf = net_buf_frag_last(pkt->frags);
uint8_t seq = net_buf_pull_u8(buf);
int retries = 3;
int ret;
@ -380,7 +380,8 @@ static int tx(struct net_buf *pkt)
static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
int32_t *len, uint8_t **data)
{
struct net_buf *pkt, *buf;
struct net_pkt *pkt;
struct net_buf *buf;
pkt = net_pkt_get_reserve_tx(0, K_NO_WAIT);
if (!pkt) {
@ -393,7 +394,7 @@ static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
return -ENOMEM;
}
net_buf_frag_insert(pkt, buf);
net_pkt_frag_insert(pkt, buf);
net_buf_add_u8(buf, setup->bRequest);
@ -406,7 +407,7 @@ static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
SYS_LOG_DBG("len %u seq %u", *len, setup->wIndex);
net_buf_put(&tx_queue, pkt);
k_fifo_put(&tx_queue, pkt);
return 0;
}
@ -417,10 +418,11 @@ static void tx_thread(void)
while (1) {
uint8_t cmd;
struct net_buf *pkt, *buf;
struct net_pkt *pkt;
struct net_buf *buf;
pkt = net_buf_get(&tx_queue, K_FOREVER);
buf = net_buf_frag_last(pkt);
pkt = k_fifo_get(&tx_queue, K_FOREVER);
buf = net_buf_frag_last(pkt->frags);
cmd = net_buf_pull_u8(buf);
hexdump(">", buf->data, buf->len);
@ -533,13 +535,13 @@ static void init_tx_queue(void)
}
extern enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
/* parse on higher layer */
return NET_CONTINUE;
}
int ieee802154_radio_send(struct net_if *iface, struct net_buf *buf)
int ieee802154_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
SYS_LOG_DBG("");
@ -551,25 +553,25 @@ void ieee802154_init(struct net_if *iface)
SYS_LOG_DBG("");
}
int net_recv_data(struct net_if *iface, struct net_buf *buf)
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
{
struct net_buf *frag;
SYS_LOG_DBG("Got data, buf %p, len %d frags->len %d",
buf, buf->len, net_buf_frags_len(buf));
SYS_LOG_DBG("Got data, pkt %p, frags->len %d",
pkt, net_pkt_get_len(pkt));
frag = net_buf_frag_last(buf);
frag = net_buf_frag_last(pkt->frags);
/**
* Add length 1 byte, do not forget to reserve it
*/
net_buf_push_u8(frag, net_buf_frags_len(buf) - 1);
net_buf_push_u8(frag, net_pkt_get_len(pkt) - 1);
hexdump("<", frag->data, net_buf_frags_len(buf));
hexdump("<", frag->data, net_pkt_get_len(pkt));
try_write(WPANUSB_ENDP_BULK_IN, frag->data, net_buf_frags_len(buf));
try_write(WPANUSB_ENDP_BULK_IN, frag->data, net_pkt_get_len(pkt));
net_pkt_unref(buf);
net_pkt_unref(pkt);
return 0;
}

View file

@ -60,15 +60,15 @@ static int resource_reply_cb(const struct zoap_packet *response,
struct zoap_reply *reply,
const struct sockaddr *from)
{
struct net_buf *buf = response->buf;
struct net_pkt *pkt = response->pkt;
msg_dump("reply", buf->data, buf->len);
msg_dump("reply", pkt->frags->data, pkt->frags->len);
return 0;
}
static void udp_receive(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
@ -82,10 +82,10 @@ static void udp_receive(struct net_context *context,
* zoap expects that buffer->data starts at the
* beginning of the CoAP header
*/
header_len = net_pkt_appdata(buf) - buf->frags->data;
net_buf_pull(buf->frags, header_len);
header_len = net_pkt_appdata(pkt) - pkt->frags->data;
net_buf_pull(pkt->frags, header_len);
r = zoap_packet_parse(&response, buf);
r = zoap_packet_parse(&response, pkt);
if (r < 0) {
printk("Invalid data received (%d)\n", r);
return;
@ -97,8 +97,8 @@ static void udp_receive(struct net_context *context,
/* If necessary cancel retransmissions */
}
net_ipaddr_copy(&from.sin6_addr, &NET_IPV6_BUF(buf)->src);
from.sin6_port = NET_UDP_BUF(buf)->src_port;
net_ipaddr_copy(&from.sin6_addr, &NET_IPV6_BUF(pkt)->src);
from.sin6_port = NET_UDP_BUF(pkt)->src_port;
reply = zoap_response_received(&response,
(const struct sockaddr *) &from,
@ -119,7 +119,7 @@ static void retransmit_request(struct k_work *work)
return;
}
r = net_context_sendto(pending->buf, (struct sockaddr *) &mcast_addr,
r = net_context_sendto(pending->pkt, (struct sockaddr *) &mcast_addr,
sizeof(mcast_addr), NULL, 0, NULL, NULL);
if (r < 0) {
return;
@ -142,7 +142,8 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
struct zoap_pending *pending;
struct zoap_reply *reply;
const char * const *p;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
int r;
uint8_t observe = 0;
@ -167,9 +168,9 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
k_delayed_work_init(&retransmit_work, retransmit_request);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
printk("Unable to get TX buffer, not enough memory.\n");
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
printk("Unable to get TX packet, not enough memory.\n");
return;
}
@ -179,9 +180,9 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
return;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&request, frag);
r = zoap_packet_init(&request, pkt);
if (r < 0) {
return;
}
@ -233,7 +234,7 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
zoap_reply_init(reply, &request);
reply->reply = resource_reply_cb;
r = net_context_sendto(buf, (struct sockaddr *) &mcast_addr,
r = net_context_sendto(pkt, (struct sockaddr *) &mcast_addr,
sizeof(mcast_addr),
NULL, 0, NULL, NULL);
if (r < 0) {

View file

@ -72,7 +72,8 @@ static int test_del(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t tkl, code, type;
const uint8_t *token;
@ -88,12 +89,12 @@ static int test_del(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -111,7 +112,7 @@ static int test_del(struct zoap_resource *resource,
zoap_header_set_id(&response, id);
zoap_header_set_token(&response, token, tkl);
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -119,7 +120,8 @@ static int test_put(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, code, type, tkl;
const uint8_t *token;
@ -140,12 +142,12 @@ static int test_put(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -163,7 +165,7 @@ static int test_put(struct zoap_resource *resource,
zoap_header_set_id(&response, id);
zoap_header_set_token(&response, token, tkl);
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -176,7 +178,8 @@ static int test_post(struct zoap_resource *resource,
"location3",
NULL };
const char * const *p;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, code, type, tkl;
const uint8_t *token;
@ -198,12 +201,12 @@ static int test_post(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -226,7 +229,7 @@ static int test_post(struct zoap_resource *resource,
*p, strlen(*p));
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -238,7 +241,8 @@ static int location_query_post(struct zoap_resource *resource,
"second=2",
NULL };
const char * const *p;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, code, type, tkl;
const uint8_t *token;
@ -260,12 +264,12 @@ static int location_query_post(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -288,7 +292,7 @@ static int location_query_post(struct zoap_resource *resource,
*p, strlen(*p));
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -296,7 +300,8 @@ static int piggyback_get(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const uint8_t *token;
uint8_t *payload, code, type;
@ -313,12 +318,12 @@ static int piggyback_get(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -360,7 +365,7 @@ static int piggyback_get(struct zoap_resource *resource,
return -EINVAL;
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -369,7 +374,8 @@ static int query_get(struct zoap_resource *resource,
const struct sockaddr *from)
{
struct zoap_option options[4];
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, code, type, tkl;
const uint8_t *token;
@ -408,12 +414,12 @@ static int query_get(struct zoap_resource *resource,
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -448,7 +454,7 @@ static int query_get(struct zoap_resource *resource,
return -EINVAL;
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -456,7 +462,8 @@ static int separate_get(struct zoap_resource *resource,
struct zoap_packet *request,
const struct sockaddr *from)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
struct zoap_pending *pending;
uint8_t *payload, code, type, tkl;
@ -477,12 +484,12 @@ static int separate_get(struct zoap_resource *resource,
goto done;
}
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -494,19 +501,19 @@ static int separate_get(struct zoap_resource *resource,
zoap_header_set_id(&response, id);
zoap_header_set_token(&response, token, tkl);
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
return -EINVAL;
}
done:
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -564,7 +571,7 @@ done:
k_delayed_work_submit(&retransmit_work, pending->timeout);
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -573,7 +580,8 @@ static int large_get(struct zoap_resource *resource,
const struct sockaddr *from)
{
static struct zoap_block_context ctx;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const uint8_t *token;
uint8_t *payload, code, type;
@ -600,12 +608,12 @@ static int large_get(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -653,7 +661,7 @@ static int large_get(struct zoap_resource *resource,
memset(&ctx, 0, sizeof(ctx));
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -662,7 +670,8 @@ static int large_update_put(struct zoap_resource *resource,
const struct sockaddr *from)
{
static struct zoap_block_context ctx;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const uint8_t *token;
uint8_t *payload, code, type;
@ -703,12 +712,12 @@ static int large_update_put(struct zoap_resource *resource,
/* Do something with the payload */
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -732,7 +741,7 @@ static int large_update_put(struct zoap_resource *resource,
return -EINVAL;
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -741,7 +750,8 @@ static int large_create_post(struct zoap_resource *resource,
const struct sockaddr *from)
{
static struct zoap_block_context ctx;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
const uint8_t *token;
uint8_t *payload, code, type;
@ -773,12 +783,12 @@ static int large_create_post(struct zoap_resource *resource,
NET_INFO("type: %u code %u id %u\n", type, code, id);
NET_INFO("*******\n");
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -802,7 +812,7 @@ static int large_create_post(struct zoap_resource *resource,
return -EINVAL;
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -824,17 +834,18 @@ static int send_notification_packet(const struct sockaddr *addr, uint16_t age,
{
struct zoap_packet response;
struct zoap_pending *pending;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint8_t *payload, type = ZOAP_TYPE_CON;
uint16_t len;
int r;
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -899,7 +910,7 @@ static int send_notification_packet(const struct sockaddr *addr, uint16_t age,
k_delayed_work_submit(&retransmit_work, pending->timeout);
}
return net_context_sendto(buf, addr, addrlen, NULL, 0, NULL, NULL);
return net_context_sendto(pkt, addr, addrlen, NULL, 0, NULL, NULL);
}
static int obs_get(struct zoap_resource *resource,
@ -957,7 +968,8 @@ static int core_get(struct zoap_resource *resource,
const struct sockaddr *from)
{
static const char dummy_str[] = "Just a test\n";
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct zoap_packet response;
uint8_t *payload, tkl;
const uint8_t *token;
@ -967,12 +979,12 @@ static int core_get(struct zoap_resource *resource,
id = zoap_header_get_id(request);
token = zoap_header_get_token(request, &tkl);
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
return -EINVAL;
}
@ -996,7 +1008,7 @@ static int core_get(struct zoap_resource *resource,
return -EINVAL;
}
return net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
return net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
}
@ -1096,7 +1108,7 @@ static struct zoap_resource *find_resouce_by_observer(
}
static void udp_receive(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
@ -1105,28 +1117,28 @@ static void udp_receive(struct net_context *context,
struct sockaddr_in6 from;
int r, header_len;
net_ipaddr_copy(&from.sin6_addr, &NET_IPV6_BUF(buf)->src);
from.sin6_port = NET_UDP_BUF(buf)->src_port;
net_ipaddr_copy(&from.sin6_addr, &NET_IPV6_BUF(pkt)->src);
from.sin6_port = NET_UDP_BUF(pkt)->src_port;
from.sin6_family = AF_INET6;
/*
* zoap expects that buffer->data starts at the
* beginning of the CoAP header
*/
header_len = net_pkt_appdata(buf) - buf->frags->data;
net_buf_pull(buf->frags, header_len);
header_len = net_pkt_appdata(pkt) - pkt->frags->data;
net_buf_pull(pkt->frags, header_len);
r = zoap_packet_parse(&request, buf);
r = zoap_packet_parse(&request, pkt);
if (r < 0) {
NET_ERR("Invalid data received (%d)\n", r);
net_pkt_unref(buf);
net_pkt_unref(pkt);
return;
}
pending = zoap_pending_received(&request, pendings,
NUM_PENDINGS);
if (pending) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return;
}
@ -1152,7 +1164,7 @@ not_found:
r = zoap_handle_request(&request, resources,
(const struct sockaddr *) &from);
net_pkt_unref(buf);
net_pkt_unref(pkt);
if (r < 0) {
NET_ERR("No handler for such request (%d)\n", r);
@ -1208,7 +1220,7 @@ static void retransmit_request(struct k_work *work)
return;
}
r = net_context_sendto(pending->buf, &pending->addr,
r = net_context_sendto(pending->pkt, &pending->addr,
sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {

View file

@ -15,7 +15,7 @@
static struct session sessions[SESSION_PROTO_END][SESSION_MAX];
/* Get session from a given packet */
struct session *get_session(struct net_buf *buf, enum session_proto proto)
struct session *get_session(struct net_pkt *pkt, enum session_proto proto)
{
struct session *active = NULL;
struct session *free = NULL;
@ -24,8 +24,8 @@ struct session *get_session(struct net_buf *buf, enum session_proto proto)
int i = 0;
uint16_t port;
if (!buf) {
printk("Error! null buf detected.\n");
if (!pkt) {
printk("Error! null pkt detected.\n");
return NULL;
}
@ -35,15 +35,15 @@ struct session *get_session(struct net_buf *buf, enum session_proto proto)
}
/* Get tuple of the remote connection */
port = NET_UDP_BUF(buf)->src_port;
port = NET_UDP_BUF(pkt)->src_port;
if (net_pkt_family(buf) == AF_INET6) {
net_ipaddr_copy(&ipv6, &NET_IPV6_BUF(buf)->src);
} else if (net_pkt_family(buf) == AF_INET) {
net_ipaddr_copy(&ipv4, &NET_IPV4_BUF(buf)->src);
if (net_pkt_family(pkt) == AF_INET6) {
net_ipaddr_copy(&ipv6, &NET_IPV6_BUF(pkt)->src);
} else if (net_pkt_family(pkt) == AF_INET) {
net_ipaddr_copy(&ipv4, &NET_IPV4_BUF(pkt)->src);
} else {
printk("Error! unsupported protocol %d\n",
net_pkt_family(buf));
net_pkt_family(pkt));
return NULL;
}
@ -53,7 +53,7 @@ struct session *get_session(struct net_buf *buf, enum session_proto proto)
#if defined(CONFIG_NET_IPV4)
if (ptr->port == port &&
net_pkt_family(buf) == AF_INET &&
net_pkt_family(pkt) == AF_INET &&
net_ipv4_addr_cmp(&ptr->ip.in_addr, &ipv4)) {
/* We found an active session */
active = ptr;
@ -61,7 +61,7 @@ struct session *get_session(struct net_buf *buf, enum session_proto proto)
#endif
#if defined(CONFIG_NET_IPV6)
if (ptr->port == port &&
net_pkt_family(buf) == AF_INET6 &&
net_pkt_family(pkt) == AF_INET6 &&
net_ipv6_addr_cmp(&ptr->ip.in6_addr, &ipv6)) {
/* We found an active session */
active = ptr;
@ -82,12 +82,12 @@ struct session *get_session(struct net_buf *buf, enum session_proto proto)
active->port = port;
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
net_ipaddr_copy(&active->ip.in6_addr, &ipv6);
}
#endif
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
net_ipaddr_copy(&active->ip.in_addr, &ipv4);
}
#endif

View file

@ -56,7 +56,7 @@ struct session {
struct zperf_server_hdr stat;
};
struct session *get_session(struct net_buf *buf, enum session_proto proto);
struct session *get_session(struct net_pkt *pkt, enum session_proto proto);
void zperf_session_init(void);
void zperf_reset_session_stats(struct session *session);

View file

@ -38,20 +38,20 @@ static struct sockaddr_in *in4_addr_my;
#endif
static void tcp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
struct session *session;
uint32_t time;
if (!buf) {
if (!pkt) {
return;
}
time = k_cycle_get_32();
session = get_session(buf, SESSION_TCP);
session = get_session(pkt, SESSION_TCP);
if (!session) {
printk(TAG "ERROR! cannot get a session!\n");
return;
@ -68,11 +68,11 @@ static void tcp_received(struct net_context *context,
case STATE_ONGOING:
session->counter++;
if (buf) {
session->length += net_pkt_appdatalen(buf);
if (pkt) {
session->length += net_pkt_appdatalen(pkt);
}
if (!buf && status == 0) { /* EOF */
if (!pkt && status == 0) { /* EOF */
uint32_t rate_in_kbps;
uint32_t duration = HW_CYCLES_TO_USEC(
time_delta(session->start_time, time));
@ -107,7 +107,7 @@ static void tcp_received(struct net_context *context,
printk(TAG "Error! Unsupported case\n");
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
static void tcp_accepted(struct net_context *context,

View file

@ -46,7 +46,8 @@ void zperf_tcp_upload(struct net_context *ctx,
do {
int ret = 0;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint32_t loop_time;
bool st;
@ -54,39 +55,39 @@ void zperf_tcp_upload(struct net_context *ctx,
loop_time = k_cycle_get_32();
last_loop_time = loop_time;
buf = net_pkt_get_tx(ctx, K_FOREVER);
if (!buf) {
printk(TAG "ERROR! Failed to retrieve a buffer\n");
pkt = net_pkt_get_tx(ctx, K_FOREVER);
if (!pkt) {
printk(TAG "ERROR! Failed to retrieve a packet\n");
break;
}
frag = net_pkt_get_data(ctx, K_FOREVER);
if (!frag) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
printk(TAG "ERROR! Failed to retrieve a fragment\n");
break;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
/* Fill in the TCP payload */
st = net_pkt_append(buf, sizeof(sample_packet),
st = net_pkt_append(pkt, sizeof(sample_packet),
sample_packet, K_FOREVER);
if (!st) {
printk(TAG "ERROR! Failed to fill packet\n");
net_pkt_unref(buf);
net_pkt_unref(pkt);
nb_errors++;
break;
}
/* Send the packet */
ret = net_context_send(buf, NULL, K_NO_WAIT, NULL, NULL);
ret = net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL);
if (ret < 0) {
printk(TAG "ERROR! Failed to send the buffer (%d)\n",
printk(TAG "ERROR! Failed to send the packet (%d)\n",
ret);
net_pkt_unref(buf);
net_pkt_unref(pkt);
nb_errors++;
break;
} else {

View file

@ -36,95 +36,96 @@ static struct sockaddr_in *in4_addr_my;
#define MAX_DBG_PRINT 64
static inline void set_dst_addr(sa_family_t family,
struct net_buf *buf,
struct net_pkt *pkt,
struct sockaddr *dst_addr)
{
#if defined(CONFIG_NET_IPV6)
if (family == AF_INET6) {
net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr,
&NET_IPV6_BUF(buf)->src);
&NET_IPV6_BUF(pkt)->src);
net_sin6(dst_addr)->sin6_family = AF_INET6;
net_sin6(dst_addr)->sin6_port = NET_UDP_BUF(buf)->src_port;
net_sin6(dst_addr)->sin6_port = NET_UDP_BUF(pkt)->src_port;
}
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
if (family == AF_INET) {
net_ipaddr_copy(&net_sin(dst_addr)->sin_addr,
&NET_IPV4_BUF(buf)->src);
&NET_IPV4_BUF(pkt)->src);
net_sin(dst_addr)->sin_family = AF_INET;
net_sin(dst_addr)->sin_port = NET_UDP_BUF(buf)->src_port;
net_sin(dst_addr)->sin_port = NET_UDP_BUF(pkt)->src_port;
}
#endif /* CONFIG_NET_IPV4 */
}
static inline struct net_buf *build_reply_buf(struct net_context *context,
struct net_buf *buf,
static inline struct net_pkt *build_reply_pkt(struct net_context *context,
struct net_pkt *pkt,
struct zperf_udp_datagram *hdr,
struct zperf_server_hdr *stat)
{
struct net_buf *reply_buf, *frag;
struct net_pkt *reply_pkt;
struct net_buf *frag;
printk(TAG "received %d bytes\n", net_pkt_appdatalen(buf));
printk(TAG "received %d bytes\n", net_pkt_appdatalen(pkt));
reply_buf = net_pkt_get_tx(context, K_FOREVER);
reply_pkt = net_pkt_get_tx(context, K_FOREVER);
frag = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(reply_buf, frag);
net_pkt_frag_add(reply_pkt, frag);
net_pkt_append_be32(reply_buf, hdr->id);
net_pkt_append_be32(reply_buf, hdr->tv_sec);
net_pkt_append_be32(reply_buf, hdr->tv_usec);
net_pkt_append_be32(reply_pkt, hdr->id);
net_pkt_append_be32(reply_pkt, hdr->tv_sec);
net_pkt_append_be32(reply_pkt, hdr->tv_usec);
net_pkt_append_be32(reply_buf, stat->flags);
net_pkt_append_be32(reply_buf, stat->total_len1);
net_pkt_append_be32(reply_buf, stat->total_len2);
net_pkt_append_be32(reply_buf, stat->stop_sec);
net_pkt_append_be32(reply_buf, stat->stop_usec);
net_pkt_append_be32(reply_buf, stat->error_cnt);
net_pkt_append_be32(reply_buf, stat->outorder_cnt);
net_pkt_append_be32(reply_buf, stat->datagrams);
net_pkt_append_be32(reply_buf, stat->jitter1);
net_pkt_append_be32(reply_buf, stat->jitter2);
net_pkt_append_be32(reply_pkt, stat->flags);
net_pkt_append_be32(reply_pkt, stat->total_len1);
net_pkt_append_be32(reply_pkt, stat->total_len2);
net_pkt_append_be32(reply_pkt, stat->stop_sec);
net_pkt_append_be32(reply_pkt, stat->stop_usec);
net_pkt_append_be32(reply_pkt, stat->error_cnt);
net_pkt_append_be32(reply_pkt, stat->outorder_cnt);
net_pkt_append_be32(reply_pkt, stat->datagrams);
net_pkt_append_be32(reply_pkt, stat->jitter1);
net_pkt_append_be32(reply_pkt, stat->jitter2);
return reply_buf;
return reply_pkt;
}
/* Send statistics to the remote client */
static int zperf_receiver_send_stat(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
struct zperf_udp_datagram *hdr,
struct zperf_server_hdr *stat)
{
struct net_buf *reply_buf;
struct net_pkt *reply_pkt;
struct sockaddr dst_addr;
int ret;
set_dst_addr(net_pkt_family(buf), buf, &dst_addr);
set_dst_addr(net_pkt_family(pkt), pkt, &dst_addr);
reply_buf = build_reply_buf(context, buf, hdr, stat);
reply_pkt = build_reply_pkt(context, pkt, hdr, stat);
net_pkt_unref(buf);
net_pkt_unref(pkt);
ret = net_context_sendto(reply_buf, &dst_addr,
net_pkt_family(buf) == AF_INET6 ?
ret = net_context_sendto(reply_pkt, &dst_addr,
net_pkt_family(pkt) == AF_INET6 ?
sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in),
NULL, 0, NULL, NULL);
if (ret < 0) {
printk(TAG " Cannot send data to peer (%d)", ret);
net_pkt_unref(reply_buf);
net_pkt_unref(reply_pkt);
}
return ret;
}
static void udp_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
struct net_buf *frag = buf->frags;
struct net_buf *frag = pkt->frags;
struct zperf_udp_datagram hdr;
struct session *session;
uint16_t offset, pos;
@ -132,28 +133,28 @@ static void udp_received(struct net_context *context,
uint32_t time;
int32_t id;
if (!buf) {
if (!pkt) {
return;
}
if (net_pkt_appdatalen(buf) < sizeof(struct zperf_udp_datagram)) {
net_pkt_unref(buf);
if (net_pkt_appdatalen(pkt) < sizeof(struct zperf_udp_datagram)) {
net_pkt_unref(pkt);
return;
}
time = k_cycle_get_32();
session = get_session(buf, SESSION_UDP);
session = get_session(pkt, SESSION_UDP);
if (!session) {
printk(TAG "ERROR! cannot get a session!\n");
return;
}
offset = net_pkt_appdata(buf) - net_pkt_ip_data(buf);
offset = net_pkt_appdata(pkt) - net_pkt_ip_data(pkt);
frag = net_pkt_read_be32(frag, offset, &pos, (uint32_t *)&hdr.id);
frag = net_pkt_read_be32(frag, pos, &pos, &hdr.tv_sec);
frag = net_pkt_read_be32(frag, pos, &pos, &hdr.tv_usec);
frag = net_frag_read_be32(frag, offset, &pos, (uint32_t *)&hdr.id);
frag = net_frag_read_be32(frag, pos, &pos, &hdr.tv_sec);
frag = net_frag_read_be32(frag, pos, &pos, &hdr.tv_usec);
id = hdr.id;
@ -162,15 +163,15 @@ static void udp_received(struct net_context *context,
printk(TAG "End of session!\n");
if (session->state == STATE_COMPLETED) {
/* Session is already completed: Resend the stat buffer
/* Session is already completed: Resend the stat packet
* and continue
*/
if (zperf_receiver_send_stat(context, buf, &hdr,
if (zperf_receiver_send_stat(context, pkt, &hdr,
&session->stat) < 0) {
printk(TAG "ERROR! Failed to send the "
"buffer\n");
"packet\n");
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
} else {
session->state = STATE_LAST_PACKET_RECEIVED;
@ -200,7 +201,7 @@ static void udp_received(struct net_context *context,
/* Update counter */
session->counter++;
session->length += net_pkt_appdatalen(buf);
session->length += net_pkt_appdatalen(pkt);
/* Compute jitter */
transit_time = time_delta(HW_CYCLES_TO_USEC(time),
@ -249,12 +250,12 @@ static void udp_received(struct net_context *context,
session->stat.jitter1 = 0;
session->stat.jitter2 = session->jitter;
if (zperf_receiver_send_stat(context, buf, &hdr,
if (zperf_receiver_send_stat(context, pkt, &hdr,
&session->stat) < 0) {
printk(TAG "ERROR! Failed to send the "
"buffer\n");
"packet\n");
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
printk(TAG " duration:\t\t");
@ -277,7 +278,7 @@ static void udp_received(struct net_context *context,
printk("\n");
}
} else {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
}

View file

@ -19,40 +19,40 @@
static char sample_packet[PACKET_SIZE_MAX];
static inline void zperf_upload_decode_stat(struct net_buf *buf,
static inline void zperf_upload_decode_stat(struct net_pkt *pkt,
struct zperf_results *results)
{
struct net_buf *frag = buf->frags;
struct net_buf *frag = pkt->frags;
struct zperf_server_hdr hdr;
uint16_t offset;
uint16_t pos;
offset = net_pkt_udp_data(buf) - net_pkt_ip_data(buf);
offset = net_pkt_udp_data(pkt) - net_pkt_ip_data(pkt);
offset += sizeof(struct net_udp_hdr) +
sizeof(struct zperf_udp_datagram);
/* Decode stat */
if (!buf) {
if (!pkt) {
printk(TAG "ERROR! Failed to receive statistic\n");
return;
} else if (net_pkt_appdatalen(buf) <
} else if (net_pkt_appdatalen(pkt) <
(sizeof(struct zperf_server_hdr) +
sizeof(struct zperf_udp_datagram))) {
printk(TAG "ERROR! Statistics too small\n");
return;
}
frag = net_pkt_read_be32(frag, offset, &pos, (uint32_t *)&hdr.flags);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.total_len1);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.total_len2);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.stop_sec);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.stop_usec);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.error_cnt);
frag = net_pkt_read_be32(frag, pos, &pos,
frag = net_frag_read_be32(frag, offset, &pos, (uint32_t *)&hdr.flags);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.total_len1);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.total_len2);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.stop_sec);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.stop_usec);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.error_cnt);
frag = net_frag_read_be32(frag, pos, &pos,
(uint32_t *)&hdr.outorder_cnt);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.datagrams);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.jitter1);
frag = net_pkt_read_be32(frag, pos, &pos, (uint32_t *)&hdr.jitter2);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.datagrams);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.jitter1);
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.jitter2);
results->nb_packets_rcvd = hdr.datagrams;
results->nb_packets_lost = hdr.error_cnt;
@ -63,13 +63,13 @@ static inline void zperf_upload_decode_stat(struct net_buf *buf,
}
static void stat_received(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
struct net_buf **stat = user_data;
struct net_pkt **stat = user_data;
*stat = buf;
*stat = pkt;
}
static inline void zperf_upload_fin(struct net_context *context,
@ -78,18 +78,19 @@ static inline void zperf_upload_fin(struct net_context *context,
uint32_t packet_size,
struct zperf_results *results)
{
struct net_buf *stat = NULL;
struct net_pkt *stat = NULL;
struct zperf_udp_datagram datagram;
int loop = 2;
int ret;
while (!stat && loop-- > 0) {
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
bool status;
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
printk(TAG "ERROR! Failed to retrieve a buffer\n");
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
printk(TAG "ERROR! Failed to retrieve a packet\n");
continue;
}
@ -99,7 +100,7 @@ static inline void zperf_upload_fin(struct net_context *context,
continue;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
/* Fill the packet header */
datagram.id = htonl(-nb_packets);
@ -107,7 +108,7 @@ static inline void zperf_upload_fin(struct net_context *context,
datagram.tv_usec = htonl(HW_CYCLES_TO_USEC(end_time) %
USEC_PER_SEC);
status = net_pkt_append(buf, sizeof(datagram),
status = net_pkt_append(pkt, sizeof(datagram),
(uint8_t *)&datagram, K_FOREVER);
if (!status) {
printk(TAG "ERROR! Cannot append datagram data\n");
@ -120,7 +121,7 @@ static inline void zperf_upload_fin(struct net_context *context,
sizeof(struct zperf_udp_datagram);
uint16_t pos;
frag = net_pkt_write(buf, net_buf_frag_last(buf),
frag = net_pkt_write(pkt, net_buf_frag_last(pkt->frags),
sizeof(struct zperf_udp_datagram),
&pos, size,
(uint8_t *)sample_packet,
@ -128,11 +129,11 @@ static inline void zperf_upload_fin(struct net_context *context,
}
/* Send the packet */
ret = net_context_send(buf, NULL, K_NO_WAIT, NULL, NULL);
ret = net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL);
if (ret < 0) {
printk(TAG "ERROR! Failed to send the buffer (%d)\n",
printk(TAG "ERROR! Failed to send the packet (%d)\n",
ret);
net_pkt_unref(buf);
net_pkt_unref(pkt);
continue;
}
@ -205,7 +206,8 @@ void zperf_udp_upload(struct net_context *context,
do {
struct zperf_udp_datagram datagram;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint32_t loop_time;
int32_t adjust;
bool status;
@ -232,9 +234,9 @@ void zperf_udp_upload(struct net_context *context,
last_loop_time = loop_time;
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
printk(TAG "ERROR! Failed to retrieve a buffer\n");
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
printk(TAG "ERROR! Failed to retrieve a packet\n");
continue;
}
@ -244,7 +246,7 @@ void zperf_udp_upload(struct net_context *context,
continue;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
/* Fill the packet header */
datagram.id = htonl(nb_packets);
@ -252,7 +254,7 @@ void zperf_udp_upload(struct net_context *context,
datagram.tv_usec =
htonl(HW_CYCLES_TO_USEC(loop_time) % USEC_PER_SEC);
status = net_pkt_append(buf, sizeof(datagram),
status = net_pkt_append(pkt, sizeof(datagram),
(uint8_t *)&datagram, K_FOREVER);
if (!status) {
printk(TAG "ERROR! Cannot append datagram data\n");
@ -265,19 +267,19 @@ void zperf_udp_upload(struct net_context *context,
sizeof(struct zperf_udp_datagram);
uint16_t pos;
frag = net_pkt_write(buf, net_buf_frag_last(buf),
frag = net_pkt_write(pkt, net_buf_frag_last(pkt->frags),
sizeof(struct zperf_udp_datagram),
&pos, size, sample_packet,
K_FOREVER);
}
/* Send the packet */
ret = net_context_send(buf, NULL, K_NO_WAIT, NULL, NULL);
ret = net_context_send(pkt, NULL, K_NO_WAIT, NULL, NULL);
if (ret < 0) {
printk(TAG "ERROR! Failed to send the buffer (%d)\n",
printk(TAG "ERROR! Failed to send the packet (%d)\n",
ret);
net_pkt_unref(buf);
net_pkt_unref(pkt);
break;
} else {
nb_packets++;

View file

@ -285,7 +285,7 @@ static inline uint8_t compress_nh(struct net_ipv6_hdr *ipv6,
/* Helpers to compress Source Address */
static inline uint8_t compress_sa(struct net_ipv6_hdr *ipv6,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag,
uint8_t offset)
{
@ -314,13 +314,13 @@ static inline uint8_t compress_sa(struct net_ipv6_hdr *ipv6,
memcpy(&IPHC[offset], &ipv6->src.s6_addr[14], 2);
offset += 2;
} else {
if (!net_pkt_ll_src(buf)) {
if (!net_pkt_ll_src(pkt)) {
NET_ERR("Invalid src ll address");
return 0;
}
if (net_ipv6_addr_based_on_ll(&ipv6->src,
net_pkt_ll_src(buf))) {
net_pkt_ll_src(pkt))) {
NET_DBG("SAM_11 src address is fully elided");
/* Address is fully elided */
@ -350,13 +350,13 @@ static inline uint8_t compress_sa(struct net_ipv6_hdr *ipv6,
#if defined(CONFIG_NET_6LO_CONTEXT)
static inline uint8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag,
uint8_t offset,
struct net_6lo_context *src)
{
if (!src) {
return compress_sa(ipv6, buf, frag, offset);
return compress_sa(ipv6, pkt, frag, offset);
}
IPHC[1] |= NET_6LO_IPHC_SAC_1;
@ -370,7 +370,7 @@ static inline uint8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6,
memcpy(&IPHC[offset], &ipv6->src.s6_addr[14], 2);
offset += 2;
} else if (net_ipv6_addr_based_on_ll(&ipv6->src,
net_pkt_ll_src(buf))) {
net_pkt_ll_src(pkt))) {
NET_DBG("SAM_11 src address is fully elided");
/* Address is fully elided */
@ -391,7 +391,7 @@ static inline uint8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6,
/* Helpers to compress Destination Address */
static inline uint8_t compress_da_mcast(struct net_ipv6_hdr *ipv6,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag,
uint8_t offset)
{
@ -442,13 +442,13 @@ static inline uint8_t compress_da_mcast(struct net_ipv6_hdr *ipv6,
}
static inline uint8_t compress_da(struct net_ipv6_hdr *ipv6,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag,
uint8_t offset)
{
/* If destination address is multicast */
if (net_is_ipv6_addr_mcast(&ipv6->dst)) {
return compress_da_mcast(ipv6, buf, frag, offset);
return compress_da_mcast(ipv6, pkt, frag, offset);
}
/* If address is link-local prefix and padded with zeros */
@ -466,13 +466,13 @@ static inline uint8_t compress_da(struct net_ipv6_hdr *ipv6,
memcpy(&IPHC[offset], &ipv6->dst.s6_addr[14], 2);
offset += 2;
} else {
if (!net_pkt_ll_dst(buf)) {
if (!net_pkt_ll_dst(pkt)) {
NET_ERR("Invalid dst ll address");
return 0;
}
if (net_ipv6_addr_based_on_ll(&ipv6->dst,
net_pkt_ll_dst(buf))) {
net_pkt_ll_dst(pkt))) {
NET_DBG("DAM_11 dst addr fully elided");
/* Address is fully elided */
@ -500,13 +500,13 @@ static inline uint8_t compress_da(struct net_ipv6_hdr *ipv6,
#if defined(CONFIG_NET_6LO_CONTEXT)
static inline uint8_t compress_da_ctx(struct net_ipv6_hdr *ipv6,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag,
uint8_t offset,
struct net_6lo_context *dst)
{
if (!dst) {
return compress_da(ipv6, buf, frag, offset);
return compress_da(ipv6, pkt, frag, offset);
}
IPHC[1] |= NET_6LO_IPHC_DAC_1;
@ -521,7 +521,7 @@ static inline uint8_t compress_da_ctx(struct net_ipv6_hdr *ipv6,
offset += 2;
} else {
if (net_ipv6_addr_based_on_ll(&ipv6->dst,
net_pkt_ll_dst(buf))) {
net_pkt_ll_dst(pkt))) {
NET_DBG("DAM_11 dst addr fully elided");
/* Address is fully elided */
@ -627,19 +627,19 @@ static inline uint8_t compress_nh_udp(struct net_udp_hdr *udp,
#if defined(CONFIG_NET_6LO_CONTEXT)
static inline bool is_src_and_dst_addr_ctx_based(struct net_ipv6_hdr *ipv6,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag,
struct net_6lo_context **src,
struct net_6lo_context **dst)
{
/* If compress flag is unset means use only in uncompression. */
*src = get_6lo_context_by_addr(net_pkt_iface(buf), &ipv6->src);
*src = get_6lo_context_by_addr(net_pkt_iface(pkt), &ipv6->src);
if (*src && !((*src)->compress)) {
*src = NULL;
}
*dst = get_6lo_context_by_addr(net_pkt_iface(buf), &ipv6->dst);
*dst = get_6lo_context_by_addr(net_pkt_iface(pkt), &ipv6->dst);
if (*dst && !((*dst)->compress)) {
*dst = NULL;
}
@ -675,39 +675,39 @@ static inline bool is_src_and_dst_addr_ctx_based(struct net_ipv6_hdr *ipv6,
* | 0 | 1 | 1 | TF |NH | HLIM |CID|SAC| SAM | M |DAC| DAM |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
*/
static inline bool compress_IPHC_header(struct net_buf *buf,
static inline bool compress_IPHC_header(struct net_pkt *pkt,
fragment_handler_t fragment)
{
#if defined(CONFIG_NET_6LO_CONTEXT)
struct net_6lo_context *src = NULL;
struct net_6lo_context *dst = NULL;
#endif
struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(buf);
struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(pkt);
uint8_t offset = 0;
struct net_udp_hdr *udp;
struct net_buf *frag;
uint8_t compressed;
if (buf->frags->len < NET_IPV6H_LEN) {
if (pkt->frags->len < NET_IPV6H_LEN) {
NET_ERR("Invalid length %d, min %d",
buf->frags->len, NET_IPV6H_LEN);
pkt->frags->len, NET_IPV6H_LEN);
return false;
}
if (ipv6->nexthdr == IPPROTO_UDP &&
buf->frags->len < NET_IPV6UDPH_LEN) {
pkt->frags->len < NET_IPV6UDPH_LEN) {
NET_ERR("Invalid length %d, min %d",
buf->frags->len, NET_IPV6UDPH_LEN);
pkt->frags->len, NET_IPV6UDPH_LEN);
return false;
}
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
IPHC[offset++] = NET_6LO_DISPATCH_IPHC;
IPHC[offset++] = 0;
#if defined(CONFIG_NET_6LO_CONTEXT)
if (is_src_and_dst_addr_ctx_based(ipv6, buf, frag, &src, &dst)) {
if (is_src_and_dst_addr_ctx_based(ipv6, pkt, frag, &src, &dst)) {
offset++;
}
#endif
@ -723,24 +723,24 @@ static inline bool compress_IPHC_header(struct net_buf *buf,
/* Source Address Compression */
#if defined(CONFIG_NET_6LO_CONTEXT)
offset = compress_sa_ctx(ipv6, buf, frag, offset, src);
offset = compress_sa_ctx(ipv6, pkt, frag, offset, src);
#else
offset = compress_sa(ipv6, buf, frag, offset);
offset = compress_sa(ipv6, pkt, frag, offset);
#endif
if (!offset) {
net_pkt_unref(frag);
net_pkt_frag_unref(frag);
return false;
}
/* Destination Address Compression */
#if defined(CONFIG_NET_6LO_CONTEXT)
offset = compress_da_ctx(ipv6, buf, frag, offset, dst);
offset = compress_da_ctx(ipv6, pkt, frag, offset, dst);
#else
offset = compress_da(ipv6, buf, frag, offset);
offset = compress_da(ipv6, pkt, frag, offset);
#endif
if (!offset) {
net_pkt_unref(frag);
net_pkt_frag_unref(frag);
return false;
}
@ -752,7 +752,7 @@ static inline bool compress_IPHC_header(struct net_buf *buf,
}
/* UDP header compression */
udp = NET_UDP_BUF(buf);
udp = NET_UDP_BUF(pkt);
IPHC[offset] = NET_6LO_NHC_UDP_BARE;
offset = compress_nh_udp(udp, frag, offset);
@ -762,28 +762,28 @@ end:
net_buf_add(frag, offset);
/* Copy the rest of the data to compressed fragment */
memcpy(&IPHC[offset], buf->frags->data + compressed,
buf->frags->len - compressed);
net_buf_add(frag, buf->frags->len - compressed);
memcpy(&IPHC[offset], pkt->frags->data + compressed,
pkt->frags->len - compressed);
net_buf_add(frag, pkt->frags->len - compressed);
/* Delete uncompressed(original) header fragment */
net_pkt_frag_del(buf, buf->frags);
net_pkt_frag_del(pkt, NULL, pkt->frags);
/* Insert compressed header fragment */
net_buf_frag_insert(buf, frag);
net_pkt_frag_insert(pkt, frag);
/* Compact the fragments, so that gaps will be filled */
net_pkt_compact(buf);
net_pkt_compact(pkt);
if (fragment) {
return fragment(buf, compressed - offset);
return fragment(pkt, compressed - offset);
}
return true;
}
/* Helper to uncompress Traffic class and Flow label */
static inline uint8_t uncompress_tfl(struct net_buf *buf,
static inline uint8_t uncompress_tfl(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset)
{
@ -835,7 +835,7 @@ static inline uint8_t uncompress_tfl(struct net_buf *buf,
}
/* Helper to uncompress Hoplimit */
static inline uint8_t uncompress_hoplimit(struct net_buf *buf,
static inline uint8_t uncompress_hoplimit(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset)
{
@ -858,7 +858,7 @@ static inline uint8_t uncompress_hoplimit(struct net_buf *buf,
}
/* Helper to uncompress Source Address */
static inline uint8_t uncompress_sa(struct net_buf *buf,
static inline uint8_t uncompress_sa(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset)
{
@ -900,7 +900,7 @@ static inline uint8_t uncompress_sa(struct net_buf *buf,
case NET_6LO_IPHC_SAM_11:
NET_DBG("SAM_11 generate src addr from ll");
net_ipv6_addr_create_iid(&ipv6->src, net_pkt_ll_src(buf));
net_ipv6_addr_create_iid(&ipv6->src, net_pkt_ll_src(pkt));
break;
}
@ -908,13 +908,13 @@ static inline uint8_t uncompress_sa(struct net_buf *buf,
}
#if defined(CONFIG_NET_6LO_CONTEXT)
static inline uint8_t uncompress_sa_ctx(struct net_buf *buf,
static inline uint8_t uncompress_sa_ctx(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset,
struct net_6lo_context *ctx)
{
if (!ctx) {
return uncompress_sa(buf, ipv6, offset);
return uncompress_sa(pkt, ipv6, offset);
}
switch (CIPHC[1] & NET_6LO_IPHC_SAM_11) {
@ -950,7 +950,7 @@ static inline uint8_t uncompress_sa_ctx(struct net_buf *buf,
* the encapsulating header.
* (e.g., 802.15.4 or IPv6 source address).
*/
net_ipv6_addr_create_iid(&ipv6->src, net_pkt_ll_src(buf));
net_ipv6_addr_create_iid(&ipv6->src, net_pkt_ll_src(pkt));
/* net_ipv6_addr_create_iid will copy first 8 bytes
* as link local prefix.
@ -965,7 +965,7 @@ static inline uint8_t uncompress_sa_ctx(struct net_buf *buf,
#endif
/* Helpers to uncompress Destination Address */
static inline uint8_t uncompress_da_mcast(struct net_buf *buf,
static inline uint8_t uncompress_da_mcast(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset)
{
@ -1023,12 +1023,12 @@ static inline uint8_t uncompress_da_mcast(struct net_buf *buf,
}
/* Helper to uncompress Destination Address */
static inline uint8_t uncompress_da(struct net_buf *buf,
static inline uint8_t uncompress_da(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset)
{
if (CIPHC[1] & NET_6LO_IPHC_M_1) {
return uncompress_da_mcast(buf, ipv6, offset);
return uncompress_da_mcast(pkt, ipv6, offset);
}
if (CIPHC[1] & NET_6LO_IPHC_DAC_1) {
@ -1068,7 +1068,7 @@ static inline uint8_t uncompress_da(struct net_buf *buf,
case NET_6LO_IPHC_DAM_11:
NET_DBG("DAM_11 generate dst addr from ll");
net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_ll_dst(buf));
net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_ll_dst(pkt));
break;
}
@ -1076,17 +1076,17 @@ static inline uint8_t uncompress_da(struct net_buf *buf,
}
#if defined(CONFIG_NET_6LO_CONTEXT)
static inline uint8_t uncompress_da_ctx(struct net_buf *buf,
static inline uint8_t uncompress_da_ctx(struct net_pkt *pkt,
struct net_ipv6_hdr *ipv6,
uint8_t offset,
struct net_6lo_context *ctx)
{
if (!ctx) {
return uncompress_da(buf, ipv6, offset);
return uncompress_da(pkt, ipv6, offset);
}
if (CIPHC[1] & NET_6LO_IPHC_M_1) {
return uncompress_da_mcast(buf, ipv6, offset);
return uncompress_da_mcast(pkt, ipv6, offset);
}
if (!(CIPHC[1] & NET_6LO_IPHC_DAC_1)) {
@ -1130,7 +1130,7 @@ static inline uint8_t uncompress_da_ctx(struct net_buf *buf,
* the encapsulating header.
* (e.g., 802.15.4 or IPv6 source address).
*/
net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_ll_dst(buf));
net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_ll_dst(pkt));
/* net_ipv6_addr_create_iid will copy first 8 bytes
* as link local prefix.
@ -1145,7 +1145,7 @@ static inline uint8_t uncompress_da_ctx(struct net_buf *buf,
#endif
/* Helper to uncompress NH UDP */
static inline uint8_t uncompress_nh_udp(struct net_buf *buf,
static inline uint8_t uncompress_nh_udp(struct net_pkt *pkt,
struct net_udp_hdr *udp,
uint8_t offset)
{
@ -1204,7 +1204,7 @@ static inline uint8_t uncompress_nh_udp(struct net_buf *buf,
#if defined(CONFIG_NET_6LO_CONTEXT)
/* Helper function to uncompress src and dst contexts */
static inline bool uncompress_cid(struct net_buf *buf,
static inline bool uncompress_cid(struct net_pkt *pkt,
struct net_6lo_context **src,
struct net_6lo_context **dst)
{
@ -1214,13 +1214,13 @@ static inline bool uncompress_cid(struct net_buf *buf,
* Either src or dest address is context based or both.
*/
cid = (CIPHC[2] >> 4) & 0x0F;
*src = get_6lo_context_by_cid(net_pkt_iface(buf), cid);
*src = get_6lo_context_by_cid(net_pkt_iface(pkt), cid);
if (!(*src)) {
NET_DBG("Unknown src cid %d", cid);
}
cid = CIPHC[2] & 0x0F;
*dst = get_6lo_context_by_cid(net_pkt_iface(buf), cid);
*dst = get_6lo_context_by_cid(net_pkt_iface(pkt), cid);
if (!(*dst)) {
NET_DBG("Unknown dst cid %d", cid);
}
@ -1238,7 +1238,7 @@ static inline bool uncompress_cid(struct net_buf *buf,
}
#endif
static inline bool uncompress_IPHC_header(struct net_buf *buf)
static inline bool uncompress_IPHC_header(struct net_pkt *pkt)
{
struct net_udp_hdr *udp = NULL;
uint8_t offset = 2;
@ -1253,7 +1253,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
if (CIPHC[1] & NET_6LO_IPHC_CID_1) {
#if defined(CONFIG_NET_6LO_CONTEXT)
if (!uncompress_cid(buf, &src, &dst)) {
if (!uncompress_cid(pkt, &src, &dst)) {
return false;
}
@ -1264,7 +1264,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
#endif
}
frag = net_pkt_get_frag(buf, NET_6LO_RX_PKT_TIMEOUT);
frag = net_pkt_get_frag(pkt, NET_6LO_RX_PKT_TIMEOUT);
if (!frag) {
return false;
}
@ -1273,10 +1273,10 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
/* Version is always 6 */
ipv6->vtc = 0x60;
net_pkt_set_ip_hdr_len(buf, NET_IPV6H_LEN);
net_pkt_set_ip_hdr_len(pkt, NET_IPV6H_LEN);
/* Uncompress Traffic class and Flow label */
offset = uncompress_tfl(buf, ipv6, offset);
offset = uncompress_tfl(pkt, ipv6, offset);
if (!(CIPHC[0] & NET_6LO_IPHC_NH_1)) {
ipv6->nexthdr = CIPHC[offset];
@ -1284,7 +1284,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
}
/* Uncompress Hoplimit */
offset = uncompress_hoplimit(buf, ipv6, offset);
offset = uncompress_hoplimit(pkt, ipv6, offset);
/* First set to zero and copy relevant bits */
memset(&ipv6->src.s6_addr[0], 0, 16);
@ -1292,22 +1292,22 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
/* Uncompress Source Address */
#if defined(CONFIG_NET_6LO_CONTEXT)
offset = uncompress_sa_ctx(buf, ipv6, offset, src);
offset = uncompress_sa_ctx(pkt, ipv6, offset, src);
if (!offset) {
goto fail;
}
#else
offset = uncompress_sa(buf, ipv6, offset);
offset = uncompress_sa(pkt, ipv6, offset);
#endif
/* Uncompress Destination Address */
#if defined(CONFIG_NET_6LO_CONTEXT)
offset = uncompress_da_ctx(buf, ipv6, offset, dst);
offset = uncompress_da_ctx(pkt, ipv6, offset, dst);
if (!offset) {
goto fail;
}
#else
offset = uncompress_da(buf, ipv6, offset);
offset = uncompress_da(pkt, ipv6, offset);
if (!offset) {
goto fail;
}
@ -1333,7 +1333,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
udp = (struct net_udp_hdr *)(frag->data + NET_IPV6H_LEN);
chksum = CIPHC[offset] & NET_6LO_NHC_UDP_CHKSUM_1;
offset = uncompress_nh_udp(buf, udp, offset);
offset = uncompress_nh_udp(pkt, udp, offset);
if (!chksum) {
memcpy(&udp->chksum, &CIPHC[offset], 2);
@ -1345,22 +1345,22 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
end:
/* Move the data to beginning, no need for headers now */
NET_DBG("Removing %u bytes of compressed hdr", offset);
memmove(buf->frags->data, buf->frags->data + offset,
buf->frags->len - offset);
buf->frags->len -= offset;
memmove(pkt->frags->data, pkt->frags->data + offset,
pkt->frags->len - offset);
pkt->frags->len -= offset;
/* Copying ll part, if any */
if (net_pkt_ll_reserve(buf)) {
memcpy(frag->data - net_pkt_ll_reserve(buf),
net_pkt_ll(buf), net_pkt_ll_reserve(buf));
if (net_pkt_ll_reserve(pkt)) {
memcpy(frag->data - net_pkt_ll_reserve(pkt),
net_pkt_ll(pkt), net_pkt_ll_reserve(pkt));
}
/* Insert the fragment (this one holds uncompressed headers) */
net_buf_frag_insert(buf, frag);
net_pkt_compact(buf);
net_pkt_frag_insert(pkt, frag);
net_pkt_compact(pkt);
/* Set IPv6 header and UDP (if next header is) length */
len = net_buf_frags_len(buf) - NET_IPV6H_LEN;
len = net_pkt_get_len(pkt) - NET_IPV6H_LEN;
ipv6->len[0] = len >> 8;
ipv6->len[1] = (uint8_t)len;
@ -1368,43 +1368,43 @@ end:
udp->len = htons(len);
if (chksum) {
udp->chksum = ~net_calc_chksum_udp(buf);
udp->chksum = ~net_calc_chksum_udp(pkt);
}
}
return true;
fail:
net_pkt_unref(frag);
net_pkt_frag_unref(frag);
return false;
}
/* Adds IPv6 dispatch as first byte and adjust fragments */
static inline bool compress_ipv6_header(struct net_buf *buf,
static inline bool compress_ipv6_header(struct net_pkt *pkt,
fragment_handler_t fragment)
{
struct net_buf *frag;
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
frag->data[0] = NET_6LO_DISPATCH_IPV6;
net_buf_add(frag, 1);
net_buf_frag_insert(buf, frag);
net_pkt_frag_insert(pkt, frag);
/* Compact the fragments, so that gaps will be filled */
net_pkt_compact(buf);
net_pkt_compact(pkt);
if (fragment) {
return fragment(buf, -1);
return fragment(pkt, -1);
}
return true;
}
static inline bool uncompress_ipv6_header(struct net_buf *buf)
static inline bool uncompress_ipv6_header(struct net_pkt *pkt)
{
struct net_buf *frag = buf->frags;
struct net_buf *frag = pkt->frags;
/* Pull off IPv6 dispatch header and adjust data and length */
memmove(frag->data, frag->data + 1, frag->len - 1);
@ -1413,33 +1413,33 @@ static inline bool uncompress_ipv6_header(struct net_buf *buf)
return true;
}
bool net_6lo_compress(struct net_buf *buf, bool iphc,
bool net_6lo_compress(struct net_pkt *pkt, bool iphc,
fragment_handler_t fragment)
{
if (iphc) {
return compress_IPHC_header(buf, fragment);
return compress_IPHC_header(pkt, fragment);
} else {
return compress_ipv6_header(buf, fragment);
return compress_ipv6_header(pkt, fragment);
}
}
bool net_6lo_uncompress(struct net_buf *buf)
bool net_6lo_uncompress(struct net_pkt *pkt)
{
NET_ASSERT(buf && buf->frags);
NET_ASSERT(pkt && pkt->frags);
if ((buf->frags->data[0] & NET_6LO_DISPATCH_IPHC) ==
if ((pkt->frags->data[0] & NET_6LO_DISPATCH_IPHC) ==
NET_6LO_DISPATCH_IPHC) {
/* Uncompress IPHC header */
return uncompress_IPHC_header(buf);
return uncompress_IPHC_header(pkt);
} else if ((buf->frags->data[0] & NET_6LO_DISPATCH_IPV6) ==
} else if ((pkt->frags->data[0] & NET_6LO_DISPATCH_IPV6) ==
NET_6LO_DISPATCH_IPV6) {
/* Uncompress IPv6 header, it has only IPv6 dispatch in the
* beginning */
return uncompress_ipv6_header(buf);
return uncompress_ipv6_header(pkt);
}
NET_DBG("Buf is not compressed");
NET_DBG("Pkt is not compressed");
return true;
}

View file

@ -19,7 +19,7 @@
#include <net/net_pkt.h>
#include "icmpv6.h"
typedef bool (*fragment_handler_t)(struct net_buf *, int);
typedef bool (*fragment_handler_t)(struct net_pkt *, int);
/**
* @brief Compress IPv6 packet as per RFC 6282
@ -28,13 +28,13 @@ typedef bool (*fragment_handler_t)(struct net_buf *, int);
* are compressed as per RFC 6282. After header compression data
* will be adjusted according to remaining space in fragments.
*
* @param Pointer to network buffer
* @param Pointer to network packet
* @param iphc true for IPHC compression, false for IPv6 dispatch header
* @param Pointer to fragment function
*
* @return True on success, false otherwise
*/
bool net_6lo_compress(struct net_buf *buf, bool iphc,
bool net_6lo_compress(struct net_pkt *pkt, bool iphc,
fragment_handler_t fragment);
/**
@ -44,11 +44,11 @@ bool net_6lo_compress(struct net_buf *buf, bool iphc,
* are uncompressed as per RFC 6282. After header uncompression data
* will be adjusted according to remaining space in fragments.
*
* @param Pointer to network buffer
* @param Pointer to network packet
*
* @return True on success, false otherwise
*/
bool net_6lo_uncompress(struct net_buf *buf);
bool net_6lo_uncompress(struct net_pkt *pkt);
/**
* @brief Set 6lowpan context information

View file

@ -85,7 +85,7 @@
#define NET_6LO_NHC_UDP_4_BIT_PORT 0xF0B
#define IPHC ((frag)->data)
#define CIPHC ((buf->frags)->data)
#define CIPHC ((pkt->frags)->data)
#define NET_6LO_FRAG1_HDR_LEN 4
#define NET_6LO_FRAGN_HDR_LEN 5

View file

@ -48,7 +48,7 @@ static struct net_conn conns[CONFIG_NET_MAX_CONN];
* both TCP and UDP header have these in the same location, we can check
* them both using the UDP struct.
*/
#define NET_CONN_BUF(buf) ((struct net_udp_hdr *)(net_pkt_udp_data(buf)))
#define NET_CONN_BUF(pkt) ((struct net_udp_hdr *)(net_pkt_udp_data(pkt)))
#if defined(CONFIG_NET_CONN_CACHE)
@ -210,16 +210,16 @@ static int32_t check_hash(enum net_ip_protocol proto,
static inline int32_t get_conn(enum net_ip_protocol proto,
sa_family_t family,
struct net_buf *buf,
struct net_pkt *pkt,
uint32_t *cache_value)
{
#if defined(CONFIG_NET_IPV4)
if (family == AF_INET) {
return check_hash(proto, family,
&NET_IPV4_BUF(buf)->src,
&NET_IPV4_BUF(buf)->dst,
NET_UDP_BUF(buf)->src_port,
NET_UDP_BUF(buf)->dst_port,
&NET_IPV4_BUF(pkt)->src,
&NET_IPV4_BUF(pkt)->dst,
NET_UDP_BUF(pkt)->src_port,
NET_UDP_BUF(pkt)->dst_port,
cache_value);
}
#endif
@ -227,10 +227,10 @@ static inline int32_t get_conn(enum net_ip_protocol proto,
#if defined(CONFIG_NET_IPV6)
if (family == AF_INET6) {
return check_hash(proto, family,
&NET_IPV6_BUF(buf)->src,
&NET_IPV6_BUF(buf)->dst,
NET_UDP_BUF(buf)->src_port,
NET_UDP_BUF(buf)->dst_port,
&NET_IPV6_BUF(pkt)->src,
&NET_IPV6_BUF(pkt)->dst,
NET_UDP_BUF(pkt)->src_port,
NET_UDP_BUF(pkt)->dst_port,
cache_value);
}
#endif
@ -280,11 +280,11 @@ static void cache_clear(void)
}
static inline enum net_verdict cache_check(enum net_ip_protocol proto,
struct net_buf *buf,
struct net_pkt *pkt,
uint32_t *cache_value,
int32_t *pos)
{
*pos = get_conn(proto, net_pkt_family(buf), buf, cache_value);
*pos = get_conn(proto, net_pkt_family(pkt), pkt, cache_value);
if (*pos >= 0) {
if (conn_cache[*pos].idx >= 0) {
/* Connection is in the cache */
@ -292,15 +292,15 @@ static inline enum net_verdict cache_check(enum net_ip_protocol proto,
conn = &conns[conn_cache[*pos].idx];
NET_DBG("Cache %s listener for buf %p src port %u "
NET_DBG("Cache %s listener for pkt %p src port %u "
"dst port %u family %d cache[%d] 0x%x",
net_proto2str(proto), buf,
ntohs(NET_CONN_BUF(buf)->src_port),
ntohs(NET_CONN_BUF(buf)->dst_port),
net_pkt_family(buf), *pos,
net_proto2str(proto), pkt,
ntohs(NET_CONN_BUF(pkt)->src_port),
ntohs(NET_CONN_BUF(pkt)->dst_port),
net_pkt_family(pkt), *pos,
conn_cache[*pos].value);
return conn->cb(conn, buf, conn->user_data);
return conn->cb(conn, pkt, conn->user_data);
}
} else if (*cache_value > 0) {
if (cache_check_neg(*cache_value)) {
@ -557,22 +557,22 @@ int net_conn_register(enum net_ip_protocol proto,
return -ENOENT;
}
static bool check_addr(struct net_buf *buf,
static bool check_addr(struct net_pkt *pkt,
struct sockaddr *addr,
bool is_remote)
{
if (addr->family != net_pkt_family(buf)) {
if (addr->family != net_pkt_family(pkt)) {
return false;
}
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6 && addr->family == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6 && addr->family == AF_INET6) {
struct in6_addr *addr6;
if (is_remote) {
addr6 = &NET_IPV6_BUF(buf)->src;
addr6 = &NET_IPV6_BUF(pkt)->src;
} else {
addr6 = &NET_IPV6_BUF(buf)->dst;
addr6 = &NET_IPV6_BUF(pkt)->dst;
}
if (!net_is_ipv6_addr_unspecified(
@ -588,13 +588,13 @@ static bool check_addr(struct net_buf *buf,
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET && addr->family == AF_INET) {
if (net_pkt_family(pkt) == AF_INET && addr->family == AF_INET) {
struct in_addr *addr4;
if (is_remote) {
addr4 = &NET_IPV4_BUF(buf)->src;
addr4 = &NET_IPV4_BUF(pkt)->src;
} else {
addr4 = &NET_IPV4_BUF(buf)->dst;
addr4 = &NET_IPV4_BUF(pkt)->dst;
}
if (net_sin(addr)->sin_addr.s_addr[0]) {
@ -609,24 +609,24 @@ static bool check_addr(struct net_buf *buf,
return true;
}
static inline void send_icmp_error(struct net_buf *buf)
static inline void send_icmp_error(struct net_pkt *pkt)
{
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
#if defined(CONFIG_NET_IPV6)
net_icmpv6_send_error(buf, NET_ICMPV6_DST_UNREACH,
net_icmpv6_send_error(pkt, NET_ICMPV6_DST_UNREACH,
NET_ICMPV6_DST_UNREACH_NO_PORT, 0);
#endif /* CONFIG_NET_IPV6 */
} else {
#if defined(CONFIG_NET_IPV4)
net_icmpv4_send_error(buf, NET_ICMPV4_DST_UNREACH,
net_icmpv4_send_error(pkt, NET_ICMPV4_DST_UNREACH,
NET_ICMPV4_DST_UNREACH_NO_PORT);
#endif /* CONFIG_NET_IPV4 */
}
}
enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_pkt *pkt)
{
int i, best_match = -1;
int16_t best_rank = -1;
@ -636,7 +636,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
uint32_t cache_value = 0;
int32_t pos;
verdict = cache_check(proto, buf, &cache_value, &pos);
verdict = cache_check(proto, pkt, &cache_value, &pos);
if (verdict != NET_CONTINUE) {
return verdict;
}
@ -646,16 +646,16 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
uint16_t chksum;
if (proto == IPPROTO_TCP) {
chksum = NET_TCP_BUF(buf)->chksum;
chksum = NET_TCP_BUF(pkt)->chksum;
} else {
chksum = NET_UDP_BUF(buf)->chksum;
chksum = NET_UDP_BUF(pkt)->chksum;
}
NET_DBG("Check %s listener for buf %p src port %u dst port %u "
"family %d chksum 0x%04x", net_proto2str(proto), buf,
ntohs(NET_CONN_BUF(buf)->src_port),
ntohs(NET_CONN_BUF(buf)->dst_port),
net_pkt_family(buf), ntohs(chksum));
NET_DBG("Check %s listener for pkt %p src port %u dst port %u "
"family %d chksum 0x%04x", net_proto2str(proto), pkt,
ntohs(NET_CONN_BUF(pkt)->src_port),
ntohs(NET_CONN_BUF(pkt)->dst_port),
net_pkt_family(pkt), ntohs(chksum));
}
for (i = 0; i < CONFIG_NET_MAX_CONN; i++) {
@ -669,26 +669,26 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
if (net_sin(&conns[i].remote_addr)->sin_port) {
if (net_sin(&conns[i].remote_addr)->sin_port !=
NET_CONN_BUF(buf)->src_port) {
NET_CONN_BUF(pkt)->src_port) {
continue;
}
}
if (net_sin(&conns[i].local_addr)->sin_port) {
if (net_sin(&conns[i].local_addr)->sin_port !=
NET_CONN_BUF(buf)->dst_port) {
NET_CONN_BUF(pkt)->dst_port) {
continue;
}
}
if (conns[i].flags & NET_CONN_REMOTE_ADDR_SET) {
if (!check_addr(buf, &conns[i].remote_addr, true)) {
if (!check_addr(pkt, &conns[i].remote_addr, true)) {
continue;
}
}
if (conns[i].flags & NET_CONN_LOCAL_ADDR_SET) {
if (!check_addr(buf, &conns[i].local_addr, false)) {
if (!check_addr(pkt, &conns[i].local_addr, false)) {
continue;
}
}
@ -728,7 +728,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
conns[best_match].rank);
#endif /* CONFIG_NET_CONN_CACHE */
if (conns[best_match].cb(&conns[best_match], buf,
if (conns[best_match].cb(&conns[best_match], pkt,
conns[best_match].user_data) == NET_DROP) {
goto drop;
}
@ -748,19 +748,19 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
/* If the destination address is multicast address,
* we do not send ICMP error as that makes no sense.
*/
if (net_pkt_family(buf) == AF_INET6 &&
net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) {
if (net_pkt_family(pkt) == AF_INET6 &&
net_is_ipv6_addr_mcast(&NET_IPV6_BUF(pkt)->dst)) {
;
} else
#endif
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET &&
net_is_ipv4_addr_mcast(&NET_IPV4_BUF(buf)->dst)) {
if (net_pkt_family(pkt) == AF_INET &&
net_is_ipv4_addr_mcast(&NET_IPV4_BUF(pkt)->dst)) {
;
} else
#endif
{
send_icmp_error(buf);
send_icmp_error(pkt);
}
drop:

View file

@ -35,7 +35,7 @@ struct net_conn_handle;
* and port.
*/
typedef enum net_verdict (*net_conn_cb_t)(struct net_conn *conn,
struct net_buf *buf,
struct net_pkt *pkt,
void *user_data);
/**
@ -125,7 +125,7 @@ int net_conn_change_callback(struct net_conn_handle *handle,
/**
* @brief Called by net_core.c when a network packet is received.
*
* @param buf Network buffer holding received data
* @param pkt Network packet holding received data
*
* @return NET_OK if the packet was consumed, NET_DROP if
* the packet parsing failed and the caller should handle
@ -134,10 +134,10 @@ int net_conn_change_callback(struct net_conn_handle *handle,
*/
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
enum net_verdict net_conn_input(enum net_ip_protocol proto,
struct net_buf *buf);
struct net_pkt *pkt);
#else
static inline enum net_verdict net_conn_input(enum net_ip_protocol proto,
struct net_buf *buf)
struct net_pkt *pkt)
{
return NET_DROP;
}

View file

@ -155,25 +155,25 @@ net_dhcpv4_msg_type_name(enum dhcpv4_msg_type msg_type)
}
/* Add magic cookie to DCHPv4 messages */
static inline bool add_cookie(struct net_buf *buf)
static inline bool add_cookie(struct net_pkt *pkt)
{
return net_pkt_append(buf, sizeof(magic_cookie), magic_cookie,
K_FOREVER);
return net_pkt_append(pkt, sizeof(magic_cookie),
magic_cookie, K_FOREVER);
}
/* Add a an option with the form OPTION LENGTH VALUE. */
static bool add_option_length_value(struct net_buf *buf, uint8_t option,
static bool add_option_length_value(struct net_pkt *pkt, uint8_t option,
uint8_t size, const uint8_t *value)
{
if (!net_pkt_append_u8(buf, option)) {
if (!net_pkt_append_u8(pkt, option)) {
return false;
}
if (!net_pkt_append_u8(buf, size)) {
if (!net_pkt_append_u8(pkt, size)) {
return false;
}
if (!net_pkt_append(buf, size, value, K_FOREVER)) {
if (!net_pkt_append(pkt, size, value, K_FOREVER)) {
return false;
}
@ -181,15 +181,15 @@ static bool add_option_length_value(struct net_buf *buf, uint8_t option,
}
/* Add DHCPv4 message type */
static bool add_msg_type(struct net_buf *buf, uint8_t type)
static bool add_msg_type(struct net_pkt *pkt, uint8_t type)
{
return add_option_length_value(buf, DHCPV4_OPTIONS_MSG_TYPE, 1, &type);
return add_option_length_value(pkt, DHCPV4_OPTIONS_MSG_TYPE, 1, &type);
}
/* Add DHCPv4 minimum required options for server to reply.
* Can be added more if needed.
*/
static bool add_req_options(struct net_buf *buf)
static bool add_req_options(struct net_pkt *pkt)
{
static const uint8_t data[5] = { DHCPV4_OPTIONS_REQ_LIST,
3, /* Length */
@ -197,34 +197,34 @@ static bool add_req_options(struct net_buf *buf)
DHCPV4_OPTIONS_ROUTER,
DHCPV4_OPTIONS_DNS_SERVER };
return net_pkt_append(buf, sizeof(data), data, K_FOREVER);
return net_pkt_append(pkt, sizeof(data), data, K_FOREVER);
}
static bool add_server_id(struct net_buf *buf, const struct in_addr *addr)
static bool add_server_id(struct net_pkt *pkt, const struct in_addr *addr)
{
return add_option_length_value(buf, DHCPV4_OPTIONS_SERVER_ID, 4,
return add_option_length_value(pkt, DHCPV4_OPTIONS_SERVER_ID, 4,
addr->s4_addr);
}
static bool add_req_ipaddr(struct net_buf *buf, const struct in_addr *addr)
static bool add_req_ipaddr(struct net_pkt *pkt, const struct in_addr *addr)
{
return add_option_length_value(buf, DHCPV4_OPTIONS_REQ_IPADDR, 4,
return add_option_length_value(pkt, DHCPV4_OPTIONS_REQ_IPADDR, 4,
addr->s4_addr);
}
/* Add DHCPv4 Options end, rest of the message can be padded wit zeros */
static inline bool add_end(struct net_buf *buf)
static inline bool add_end(struct net_pkt *pkt)
{
return net_pkt_append_u8(buf, DHCPV4_OPTIONS_END);
return net_pkt_append_u8(pkt, DHCPV4_OPTIONS_END);
}
/* File is empty ATM */
static inline bool add_file(struct net_buf *buf)
static inline bool add_file(struct net_pkt *pkt)
{
uint8_t len = SIZE_OF_FILE;
while (len-- > 0) {
if (!net_pkt_append_u8(buf, 0)) {
if (!net_pkt_append_u8(pkt, 0)) {
return false;
}
}
@ -233,12 +233,12 @@ static inline bool add_file(struct net_buf *buf)
}
/* SNAME is empty ATM */
static inline bool add_sname(struct net_buf *buf)
static inline bool add_sname(struct net_pkt *pkt)
{
uint8_t len = SIZE_OF_SNAME;
while (len-- > 0) {
if (!net_pkt_append_u8(buf, 0)) {
if (!net_pkt_append_u8(pkt, 0)) {
return false;
}
}
@ -247,16 +247,16 @@ static inline bool add_sname(struct net_buf *buf)
}
/* Setup IPv4 + UDP header */
static void setup_header(struct net_buf *buf, const struct in_addr *server_addr)
static void setup_header(struct net_pkt *pkt, const struct in_addr *server_addr)
{
struct net_ipv4_hdr *ipv4;
struct net_udp_hdr *udp;
uint16_t len;
ipv4 = NET_IPV4_BUF(buf);
udp = NET_UDP_BUF(buf);
ipv4 = NET_IPV4_BUF(pkt);
udp = NET_UDP_BUF(pkt);
len = net_buf_frags_len(buf->frags);
len = net_pkt_get_len(pkt);
/* Setup IPv4 header */
memset(ipv4, 0, sizeof(struct net_ipv4_hdr));
@ -266,7 +266,7 @@ static void setup_header(struct net_buf *buf, const struct in_addr *server_addr)
ipv4->proto = IPPROTO_UDP;
ipv4->len[0] = len >> 8;
ipv4->len[1] = (uint8_t)len;
ipv4->chksum = ~net_calc_chksum_ipv4(buf);
ipv4->chksum = ~net_calc_chksum_ipv4(pkt);
net_ipaddr_copy(&ipv4->dst, server_addr);
@ -276,30 +276,30 @@ static void setup_header(struct net_buf *buf, const struct in_addr *server_addr)
udp->dst_port = htons(DHCPV4_SERVER_PORT);
udp->len = htons(len);
udp->chksum = 0;
udp->chksum = ~net_calc_chksum_udp(buf);
udp->chksum = ~net_calc_chksum_udp(pkt);
}
/* Prepare initial DHCPv4 message and add options as per message type */
static struct net_buf *prepare_message(struct net_if *iface, uint8_t type,
static struct net_pkt *prepare_message(struct net_if *iface, uint8_t type,
const struct in_addr *ciaddr)
{
struct net_buf *buf;
struct net_pkt *pkt;
struct net_buf *frag;
struct dhcp_msg *msg;
buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
pkt = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
K_FOREVER);
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
net_pkt_set_iface(buf, iface);
net_pkt_set_family(buf, AF_INET);
net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr));
net_pkt_set_iface(pkt, iface);
net_pkt_set_family(pkt, AF_INET);
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr));
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
/* Leave room for IPv4 + UDP headers */
net_buf_add(buf->frags, NET_IPV4UDPH_LEN);
net_buf_add(pkt->frags, NET_IPV4UDPH_LEN);
if (net_buf_tailroom(frag) < sizeof(struct dhcp_msg)) {
goto fail;
@ -328,24 +328,24 @@ static struct net_buf *prepare_message(struct net_if *iface, uint8_t type,
net_buf_add(frag, sizeof(struct dhcp_msg));
if (!add_sname(buf) ||
!add_file(buf) ||
!add_cookie(buf) ||
!add_msg_type(buf, type)) {
if (!add_sname(pkt) ||
!add_file(pkt) ||
!add_cookie(pkt) ||
!add_msg_type(pkt, type)) {
goto fail;
}
return buf;
return pkt;
fail:
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NULL;
}
/* Prepare DHCPv4 Message request and send it to peer */
static void send_request(struct net_if *iface)
{
struct net_buf *buf;
struct net_pkt *pkt;
uint32_t timeout;
const struct in_addr *server_addr = net_ipv4_broadcast_address();
const struct in_addr *ciaddr = NULL;
@ -388,27 +388,27 @@ static void send_request(struct net_if *iface)
break;
}
buf = prepare_message(iface, DHCPV4_MSG_TYPE_REQUEST, ciaddr);
if (!buf) {
pkt = prepare_message(iface, DHCPV4_MSG_TYPE_REQUEST, ciaddr);
if (!pkt) {
goto fail;
}
if (with_server_id && !add_server_id(buf, &iface->dhcpv4.server_id)) {
if (with_server_id && !add_server_id(pkt, &iface->dhcpv4.server_id)) {
goto fail;
}
if (with_requested_ip
&& !add_req_ipaddr(buf, &iface->dhcpv4.requested_ip)) {
&& !add_req_ipaddr(pkt, &iface->dhcpv4.requested_ip)) {
goto fail;
}
if (!add_end(buf)) {
if (!add_end(pkt)) {
goto fail;
}
setup_header(buf, server_addr);
setup_header(pkt, server_addr);
if (net_send_data(buf) < 0) {
if (net_send_data(pkt) < 0) {
goto fail;
}
@ -441,32 +441,32 @@ static void send_request(struct net_if *iface)
fail:
NET_DBG("Message preparation failed");
if (!buf) {
net_pkt_unref(buf);
if (!pkt) {
net_pkt_unref(pkt);
}
}
/* Prepare DHCPv4 Discover message and broadcast it */
static void send_discover(struct net_if *iface)
{
struct net_buf *buf;
struct net_pkt *pkt;
uint32_t timeout;
iface->dhcpv4.xid++;
buf = prepare_message(iface, DHCPV4_MSG_TYPE_DISCOVER, NULL);
if (!buf) {
pkt = prepare_message(iface, DHCPV4_MSG_TYPE_DISCOVER, NULL);
if (!pkt) {
goto fail;
}
if (!add_req_options(buf) ||
!add_end(buf)) {
if (!add_req_options(pkt) ||
!add_end(pkt)) {
goto fail;
}
setup_header(buf, net_ipv4_broadcast_address());
setup_header(pkt, net_ipv4_broadcast_address());
if (net_send_data(buf) < 0) {
if (net_send_data(pkt) < 0) {
goto fail;
}
@ -484,8 +484,8 @@ static void send_discover(struct net_if *iface)
fail:
NET_DBG("Message preparation failed");
if (!buf) {
net_pkt_unref(buf);
if (!pkt) {
net_pkt_unref(pkt);
}
}
@ -662,17 +662,17 @@ static void dhcpv4_timeout(struct k_work *work)
/* Parse DHCPv4 options and retrieve relavant information
* as per RFC 2132.
*/
static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
static enum net_verdict parse_options(struct net_if *iface,
struct net_buf *frag,
uint16_t offset,
enum dhcpv4_msg_type *msg_type)
{
struct net_buf *frag;
uint8_t cookie[4];
uint8_t length;
uint8_t type;
uint16_t pos;
frag = net_pkt_read(buf, offset, &pos, sizeof(magic_cookie),
frag = net_frag_read(frag, offset, &pos, sizeof(magic_cookie),
(uint8_t *)cookie);
if (!frag || memcmp(magic_cookie, cookie, sizeof(magic_cookie))) {
@ -681,14 +681,14 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
}
while (frag) {
frag = net_pkt_read_u8(frag, pos, &pos, &type);
frag = net_frag_read_u8(frag, pos, &pos, &type);
if (type == DHCPV4_OPTIONS_END) {
NET_DBG("options_end");
return NET_OK;
}
frag = net_pkt_read_u8(frag, pos, &pos, &length);
frag = net_frag_read_u8(frag, pos, &pos, &length);
if (!frag) {
NET_ERR("option parsing, bad length");
return NET_DROP;
@ -703,7 +703,7 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read(frag, pos, &pos, length,
frag = net_frag_read(frag, pos, &pos, length,
netmask.s4_addr);
if (!frag && pos) {
NET_ERR("options_subnet_mask, short packet");
@ -728,8 +728,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read(frag, pos, &pos, 4, router.s4_addr);
frag = net_pkt_skip(frag, pos, &pos, length - 4);
frag = net_frag_read(frag, pos, &pos, 4, router.s4_addr);
frag = net_frag_skip(frag, pos, &pos, length - 4);
if (!frag && pos) {
NET_ERR("options_router, short packet");
return NET_DROP;
@ -746,7 +746,7 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read_be32(frag, pos, &pos,
frag = net_frag_read_be32(frag, pos, &pos,
&iface->dhcpv4.lease_time);
NET_DBG("options_lease_time: %u",
iface->dhcpv4.lease_time);
@ -761,7 +761,7 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read_be32(frag, pos, &pos,
frag = net_frag_read_be32(frag, pos, &pos,
&iface->dhcpv4.renewal_time);
NET_DBG("options_renewal: %u",
iface->dhcpv4.renewal_time);
@ -776,7 +776,7 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read_be32(frag, pos, &pos,
frag = net_frag_read_be32(frag, pos, &pos,
&iface->dhcpv4.rebinding_time);
NET_DBG("options_rebinding: %u",
iface->dhcpv4.rebinding_time);
@ -791,7 +791,7 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read(frag, pos, &pos, length,
frag = net_frag_read(frag, pos, &pos, length,
iface->dhcpv4.server_id.s4_addr);
NET_DBG("options_server_id: %s",
net_sprint_ipv4_addr(&iface->dhcpv4.server_id));
@ -804,13 +804,13 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
return NET_DROP;
}
frag = net_pkt_read_u8(frag, pos, &pos, &v);
frag = net_frag_read_u8(frag, pos, &pos, &v);
*msg_type = v;
break;
}
default:
NET_DBG("option unknown: %d", type);
frag = net_pkt_skip(frag, pos, &pos, length);
frag = net_frag_skip(frag, pos, &pos, length);
break;
}
@ -918,7 +918,7 @@ static void handle_dhcpv4_reply(struct net_if *iface,
}
static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
struct net_buf *buf,
struct net_pkt *pkt,
void *user_data)
{
struct dhcp_msg *msg;
@ -933,24 +933,24 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
return NET_DROP;
}
if (!buf || !buf->frags) {
NET_DBG("Invalid buffer, no fragments");
if (!pkt || !pkt->frags) {
NET_DBG("Invalid packet, no fragments");
return NET_DROP;
}
iface = net_pkt_iface(buf);
iface = net_pkt_iface(pkt);
if (!iface) {
NET_DBG("no iface");
return NET_DROP;
}
frag = buf->frags;
frag = pkt->frags;
min = NET_IPV4UDPH_LEN + sizeof(struct dhcp_msg);
/* If the message is not DHCP then continue passing to
* related handlers.
*/
if (net_buf_frags_len(frag) < min) {
if (net_pkt_get_len(pkt) < min) {
NET_DBG("Input msg is not related to DHCPv4");
return NET_CONTINUE;
@ -983,7 +983,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
sizeof(msg->yiaddr));
/* SNAME, FILE are not used at the moment, skip it */
frag = net_pkt_skip(frag, min, &pos, SIZE_OF_SNAME + SIZE_OF_FILE);
frag = net_frag_skip(frag, min, &pos, SIZE_OF_SNAME + SIZE_OF_FILE);
if (!frag && pos) {
NET_DBG("short packet while skipping sname");
goto drop;
@ -994,7 +994,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
goto drop;
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
handle_dhcpv4_reply(iface, msg_type);

View file

@ -22,13 +22,13 @@
#include "icmpv4.h"
#include "net_stats.h"
#define BUF_WAIT_TIME K_SECONDS(1)
#define PKT_WAIT_TIME K_SECONDS(1)
static sys_slist_t handlers;
static inline enum net_verdict handle_echo_request(struct net_buf *buf)
static inline enum net_verdict handle_echo_request(struct net_pkt *pkt)
{
/* Note that we send the same data buffers back and just swap
/* Note that we send the same data packets back and just swap
* the addresses etc.
*/
struct in_addr addr;
@ -37,29 +37,29 @@ static inline enum net_verdict handle_echo_request(struct net_buf *buf)
char out[sizeof("xxx.xxx.xxx.xxx")];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->dst));
NET_DBG("Received Echo Request from %s to %s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out);
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src), out);
#endif /* CONFIG_NET_DEBUG_ICMPV4 */
net_ipaddr_copy(&addr, &NET_IPV4_BUF(buf)->src);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->src,
&NET_IPV4_BUF(buf)->dst);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->dst, &addr);
net_ipaddr_copy(&addr, &NET_IPV4_BUF(pkt)->src);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->src,
&NET_IPV4_BUF(pkt)->dst);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->dst, &addr);
NET_ICMP_BUF(buf)->type = NET_ICMPV4_ECHO_REPLY;
NET_ICMP_BUF(buf)->code = 0;
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv4(buf);
NET_ICMP_BUF(pkt)->type = NET_ICMPV4_ECHO_REPLY;
NET_ICMP_BUF(pkt)->code = 0;
NET_ICMP_BUF(pkt)->chksum = 0;
NET_ICMP_BUF(pkt)->chksum = ~net_calc_chksum_icmpv4(pkt);
#if defined(CONFIG_NET_DEBUG_ICMPV4)
snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->dst));
NET_DBG("Sending Echo Reply from %s to %s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out);
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src), out);
#endif /* CONFIG_NET_DEBUG_ICMPV4 */
if (net_send_data(buf) < 0) {
if (net_send_data(pkt) < 0) {
net_stats_update_icmp_drop();
return NET_DROP;
}
@ -71,30 +71,30 @@ static inline enum net_verdict handle_echo_request(struct net_buf *buf)
#define NET_ICMPV4_UNUSED_LEN 4
static inline void setup_ipv4_header(struct net_buf *buf, uint8_t extra_len,
static inline void setup_ipv4_header(struct net_pkt *pkt, uint8_t extra_len,
uint8_t ttl, uint8_t icmp_type,
uint8_t icmp_code)
{
NET_IPV4_BUF(buf)->vhl = 0x45;
NET_IPV4_BUF(buf)->tos = 0x00;
NET_IPV4_BUF(buf)->len[0] = 0;
NET_IPV4_BUF(buf)->len[1] = sizeof(struct net_ipv4_hdr) +
NET_IPV4_BUF(pkt)->vhl = 0x45;
NET_IPV4_BUF(pkt)->tos = 0x00;
NET_IPV4_BUF(pkt)->len[0] = 0;
NET_IPV4_BUF(pkt)->len[1] = sizeof(struct net_ipv4_hdr) +
NET_ICMPH_LEN + extra_len + NET_ICMPV4_UNUSED_LEN;
NET_IPV4_BUF(buf)->proto = IPPROTO_ICMP;
NET_IPV4_BUF(buf)->ttl = ttl;
NET_IPV4_BUF(buf)->offset[0] = NET_IPV4_BUF(buf)->offset[1] = 0;
NET_IPV4_BUF(buf)->id[0] = NET_IPV4_BUF(buf)->id[1] = 0;
NET_IPV4_BUF(pkt)->proto = IPPROTO_ICMP;
NET_IPV4_BUF(pkt)->ttl = ttl;
NET_IPV4_BUF(pkt)->offset[0] = NET_IPV4_BUF(pkt)->offset[1] = 0;
NET_IPV4_BUF(pkt)->id[0] = NET_IPV4_BUF(pkt)->id[1] = 0;
net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr));
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr));
NET_IPV4_BUF(buf)->chksum = 0;
NET_IPV4_BUF(buf)->chksum = ~net_calc_chksum_ipv4(buf);
NET_IPV4_BUF(pkt)->chksum = 0;
NET_IPV4_BUF(pkt)->chksum = ~net_calc_chksum_ipv4(pkt);
NET_ICMP_BUF(buf)->type = icmp_type;
NET_ICMP_BUF(buf)->code = icmp_code;
NET_ICMP_BUF(pkt)->type = icmp_type;
NET_ICMP_BUF(pkt)->code = icmp_code;
memset(net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr), 0,
memset(net_pkt_icmp_data(pkt) + sizeof(struct net_icmp_hdr), 0,
NET_ICMPV4_UNUSED_LEN);
}
@ -104,7 +104,8 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
uint16_t sequence)
{
const struct in_addr *src;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
/* Take the first address of the network interface */
src = &iface->ipv4.unicast[0].address.in_addr;
@ -113,59 +114,60 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
* as IPv4 cannot be used in 802.15.4 where it is the reserve
* size can change depending on address.
*/
buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface,
pkt = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface,
(const struct in6_addr *)dst),
K_FOREVER);
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
net_buf_frag_add(buf, frag);
net_pkt_set_family(buf, AF_INET);
net_pkt_set_iface(buf, iface);
net_pkt_frag_add(pkt, frag);
net_pkt_set_family(pkt, AF_INET);
net_pkt_set_iface(pkt, iface);
setup_ipv4_header(buf, 0, net_if_ipv4_get_ttl(iface),
setup_ipv4_header(pkt, 0, net_if_ipv4_get_ttl(iface),
NET_ICMPV4_ECHO_REQUEST, 0);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->src, src);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->dst, dst);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->src, src);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->dst, dst);
NET_ICMPV4_ECHO_REQ_BUF(buf)->identifier = htons(identifier);
NET_ICMPV4_ECHO_REQ_BUF(buf)->sequence = htons(sequence);
NET_ICMPV4_ECHO_REQ_BUF(pkt)->identifier = htons(identifier);
NET_ICMPV4_ECHO_REQ_BUF(pkt)->sequence = htons(sequence);
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv4(buf);
NET_ICMP_BUF(pkt)->chksum = 0;
NET_ICMP_BUF(pkt)->chksum = ~net_calc_chksum_icmpv4(pkt);
#if defined(CONFIG_NET_DEBUG_ICMPV4)
do {
char out[NET_IPV4_ADDR_LEN];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->dst));
NET_DBG("Sending ICMPv4 Echo Request type %d"
" from %s to %s", NET_ICMPV4_ECHO_REQUEST,
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out);
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src), out);
} while (0);
#endif /* CONFIG_NET_DEBUG_ICMPV4 */
net_buf_add(buf->frags, sizeof(struct net_ipv4_hdr) +
net_buf_add(pkt->frags, sizeof(struct net_ipv4_hdr) +
sizeof(struct net_icmp_hdr) +
sizeof(struct net_icmpv4_echo_req));
if (net_send_data(buf) >= 0) {
if (net_send_data(pkt) >= 0) {
net_stats_update_icmp_sent();
return 0;
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
net_stats_update_icmp_drop();
return -EIO;
}
int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
int net_icmpv4_send_error(struct net_pkt *orig, uint8_t type, uint8_t code)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct net_if *iface = net_pkt_iface(orig);
size_t extra_len, reserve;
struct in_addr addr, *src, *dst;
@ -175,16 +177,16 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
if (NET_ICMP_BUF(orig)->code < 8) {
/* We must not send ICMP errors back */
err = -EINVAL;
goto drop_no_buf;
goto drop_no_pkt;
}
}
iface = net_pkt_iface(orig);
buf = net_pkt_get_reserve_tx(0, BUF_WAIT_TIME);
if (!buf) {
pkt = net_pkt_get_reserve_tx(0, PKT_WAIT_TIME);
if (!pkt) {
err = -ENOMEM;
goto drop_no_buf;
goto drop_no_pkt;
}
reserve = sizeof(struct net_ipv4_hdr) + sizeof(struct net_icmp_hdr) +
@ -208,7 +210,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
}
/* We need to remember the original location of source and destination
* addresses as the net_pkt_copy() will mangle the original buffer.
* addresses as the net_pkt_copy() will mangle the original packet.
*/
src = &NET_IPV4_BUF(orig)->src;
dst = &NET_IPV4_BUF(orig)->dst;
@ -216,53 +218,53 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
/* We only copy minimal IPv4 + next header from original message.
* This is so that the memory pressure is minimized.
*/
frag = net_pkt_copy(orig, extra_len, reserve, BUF_WAIT_TIME);
frag = net_pkt_copy(orig, extra_len, reserve, PKT_WAIT_TIME);
if (!frag) {
err = -ENOMEM;
goto drop;
}
net_buf_frag_add(buf, frag);
net_pkt_set_family(buf, AF_INET);
net_pkt_set_iface(buf, iface);
net_pkt_set_ll_reserve(buf, net_buf_headroom(frag));
net_pkt_frag_add(pkt, frag);
net_pkt_set_family(pkt, AF_INET);
net_pkt_set_iface(pkt, iface);
net_pkt_set_ll_reserve(pkt, net_buf_headroom(frag));
setup_ipv4_header(buf, extra_len, net_if_ipv4_get_ttl(iface),
setup_ipv4_header(pkt, extra_len, net_if_ipv4_get_ttl(iface),
type, code);
net_ipaddr_copy(&addr, src);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->src, dst);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->dst, &addr);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->src, dst);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->dst, &addr);
net_pkt_ll_src(buf)->addr = net_pkt_ll_dst(orig)->addr;
net_pkt_ll_src(buf)->len = net_pkt_ll_dst(orig)->len;
net_pkt_ll_dst(buf)->addr = net_pkt_ll_src(orig)->addr;
net_pkt_ll_dst(buf)->len = net_pkt_ll_src(orig)->len;
net_pkt_ll_src(pkt)->addr = net_pkt_ll_dst(orig)->addr;
net_pkt_ll_src(pkt)->len = net_pkt_ll_dst(orig)->len;
net_pkt_ll_dst(pkt)->addr = net_pkt_ll_src(orig)->addr;
net_pkt_ll_dst(pkt)->len = net_pkt_ll_src(orig)->len;
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv4(buf);
NET_ICMP_BUF(pkt)->chksum = 0;
NET_ICMP_BUF(pkt)->chksum = ~net_calc_chksum_icmpv4(pkt);
#if defined(CONFIG_NET_DEBUG_ICMPV4)
do {
char out[sizeof("xxx.xxx.xxx.xxx")];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->dst));
NET_DBG("Sending ICMPv4 Error Message type %d code %d "
"from %s to %s", type, code,
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), out);
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src), out);
} while (0);
#endif /* CONFIG_NET_DEBUG_ICMPV4 */
if (net_send_data(buf) >= 0) {
if (net_send_data(pkt) >= 0) {
net_stats_update_icmp_sent();
return 0;
}
drop:
net_pkt_unref(buf);
net_pkt_unref(pkt);
drop_no_buf:
drop_no_pkt:
net_stats_update_icmp_drop();
return err;
@ -278,7 +280,7 @@ void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler)
sys_slist_find_and_remove(&handlers, &handler->node);
}
enum net_verdict net_icmpv4_input(struct net_buf *buf,
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
uint8_t type, uint8_t code)
{
struct net_icmpv4_handler *cb;
@ -287,7 +289,7 @@ enum net_verdict net_icmpv4_input(struct net_buf *buf,
SYS_SLIST_FOR_EACH_CONTAINER(&handlers, cb, node) {
if (cb->type == type && (cb->code == code || cb->code == 0)) {
return cb->handler(buf);
return cb->handler(pkt);
}
}

View file

@ -30,11 +30,11 @@ struct net_icmpv4_echo_req {
uint16_t sequence;
} __packed;
#define NET_ICMPV4_ECHO_REQ_BUF(buf) \
((struct net_icmpv4_echo_req *)(net_pkt_icmp_data(buf) + \
#define NET_ICMPV4_ECHO_REQ_BUF(pkt) \
((struct net_icmpv4_echo_req *)(net_pkt_icmp_data(pkt) + \
sizeof(struct net_icmp_hdr)))
typedef enum net_verdict (*icmpv4_callback_handler_t)(struct net_buf *buf);
typedef enum net_verdict (*icmpv4_callback_handler_t)(struct net_pkt *pkt);
struct net_icmpv4_handler {
sys_snode_t node;
@ -45,12 +45,12 @@ struct net_icmpv4_handler {
/**
* @brief Send ICMPv4 error message.
* @param buf Network buffer that this error is related to.
* @param pkt Network packet that this error is related to.
* @param type Type of the error message.
* @param code Code of the type of the error message.
* @return Return 0 if the sending succeed, <0 otherwise.
*/
int net_icmpv4_send_error(struct net_buf *buf, uint8_t type, uint8_t code);
int net_icmpv4_send_error(struct net_pkt *pkt, uint8_t type, uint8_t code);
/**
* @brief Send ICMPv4 echo request message.
@ -73,7 +73,7 @@ void net_icmpv4_register_handler(struct net_icmpv4_handler *handler);
void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler);
enum net_verdict net_icmpv4_input(struct net_buf *buf,
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
uint8_t type, uint8_t code);
#if defined(CONFIG_NET_IPV4)

View file

@ -28,7 +28,7 @@
#include "rpl.h"
#endif
#define BUF_WAIT_TIME K_SECONDS(1)
#define PKT_WAIT_TIME K_SECONDS(1)
static sys_slist_t handlers;
@ -74,59 +74,59 @@ void net_icmpv6_unregister_handler(struct net_icmpv6_handler *handler)
sys_slist_find_and_remove(&handlers, &handler->node);
}
static inline void setup_ipv6_header(struct net_buf *buf, uint16_t extra_len,
static inline void setup_ipv6_header(struct net_pkt *pkt, uint16_t extra_len,
uint8_t hop_limit, uint8_t icmp_type,
uint8_t icmp_code)
{
NET_IPV6_BUF(buf)->vtc = 0x60;
NET_IPV6_BUF(buf)->tcflow = 0;
NET_IPV6_BUF(buf)->flow = 0;
NET_IPV6_BUF(pkt)->vtc = 0x60;
NET_IPV6_BUF(pkt)->tcflow = 0;
NET_IPV6_BUF(pkt)->flow = 0;
sys_put_be16(NET_ICMPH_LEN + extra_len + NET_ICMPV6_UNUSED_LEN,
NET_IPV6_BUF(buf)->len);
NET_IPV6_BUF(pkt)->len);
NET_IPV6_BUF(buf)->nexthdr = IPPROTO_ICMPV6;
NET_IPV6_BUF(buf)->hop_limit = hop_limit;
NET_IPV6_BUF(pkt)->nexthdr = IPPROTO_ICMPV6;
NET_IPV6_BUF(pkt)->hop_limit = hop_limit;
net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr));
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
NET_ICMP_BUF(buf)->type = icmp_type;
NET_ICMP_BUF(buf)->code = icmp_code;
NET_ICMP_BUF(pkt)->type = icmp_type;
NET_ICMP_BUF(pkt)->code = icmp_code;
/* ICMPv6 header has 4 unused bytes that must be zero, RFC 4443 ch 3.1
*/
memset(net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr), 0,
memset(net_pkt_icmp_data(pkt) + sizeof(struct net_icmp_hdr), 0,
NET_ICMPV6_UNUSED_LEN);
}
#if defined(CONFIG_NET_DEBUG_ICMPV6)
static inline void echo_request_debug(struct net_buf *buf)
static inline void echo_request_debug(struct net_pkt *pkt)
{
char out[NET_IPV6_ADDR_LEN];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->dst));
NET_DBG("Received Echo Request from %s to %s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out);
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->src), out);
}
static inline void echo_reply_debug(struct net_buf *buf)
static inline void echo_reply_debug(struct net_pkt *pkt)
{
char out[NET_IPV6_ADDR_LEN];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->dst));
NET_DBG("Sending Echo Reply from %s to %s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out);
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->src), out);
}
#else
#define echo_request_debug(buf)
#define echo_reply_debug(buf)
#define echo_request_debug(pkt)
#define echo_reply_debug(pkt)
#endif /* CONFIG_NET_DEBUG_ICMPV6 */
static enum net_verdict handle_echo_request(struct net_buf *orig)
static enum net_verdict handle_echo_request(struct net_pkt *orig)
{
struct net_buf *buf;
struct net_pkt *pkt;
struct net_buf *frag;
struct net_if *iface;
uint16_t payload_len;
@ -135,83 +135,83 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
iface = net_pkt_iface(orig);
buf = net_pkt_get_reserve_tx(0, BUF_WAIT_TIME);
if (!buf) {
goto drop_no_buf;
pkt = net_pkt_get_reserve_tx(0, PKT_WAIT_TIME);
if (!pkt) {
goto drop_no_pkt;
}
payload_len = sys_get_be16(NET_IPV6_BUF(orig)->len) -
sizeof(NET_ICMPH_LEN) - NET_ICMPV6_UNUSED_LEN;
frag = net_pkt_copy_all(orig, 0, BUF_WAIT_TIME);
frag = net_pkt_copy_all(orig, 0, PKT_WAIT_TIME);
if (!frag) {
goto drop;
}
net_buf_frag_add(buf, frag);
net_pkt_set_family(buf, AF_INET6);
net_pkt_set_iface(buf, iface);
net_pkt_set_ll_reserve(buf, net_buf_headroom(frag));
net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr));
net_pkt_frag_add(pkt, frag);
net_pkt_set_family(pkt, AF_INET6);
net_pkt_set_iface(pkt, iface);
net_pkt_set_ll_reserve(pkt, net_buf_headroom(frag));
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr));
if (net_pkt_ext_len(orig)) {
net_pkt_set_ext_len(buf, net_pkt_ext_len(orig));
net_pkt_set_ext_len(pkt, net_pkt_ext_len(orig));
} else {
net_pkt_set_ext_len(buf, 0);
net_pkt_set_ext_len(pkt, 0);
}
/* Set up IPv6 Header fields */
NET_IPV6_BUF(buf)->vtc = 0x60;
NET_IPV6_BUF(buf)->tcflow = 0;
NET_IPV6_BUF(buf)->flow = 0;
NET_IPV6_BUF(buf)->hop_limit = net_if_ipv6_get_hop_limit(iface);
NET_IPV6_BUF(pkt)->vtc = 0x60;
NET_IPV6_BUF(pkt)->tcflow = 0;
NET_IPV6_BUF(pkt)->flow = 0;
NET_IPV6_BUF(pkt)->hop_limit = net_if_ipv6_get_hop_limit(iface);
/* ICMPv6 fields */
NET_ICMP_BUF(buf)->type = NET_ICMPV6_ECHO_REPLY;
NET_ICMP_BUF(buf)->code = 0;
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(pkt)->type = NET_ICMPV6_ECHO_REPLY;
NET_ICMP_BUF(pkt)->code = 0;
NET_ICMP_BUF(pkt)->chksum = 0;
if (net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) {
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst,
if (net_is_ipv6_addr_mcast(&NET_IPV6_BUF(pkt)->dst)) {
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->dst,
&NET_IPV6_BUF(orig)->src);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src,
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->src,
net_if_ipv6_select_src_addr(iface,
&NET_IPV6_BUF(orig)->dst));
} else {
struct in6_addr addr;
net_ipaddr_copy(&addr, &NET_IPV6_BUF(orig)->src);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src,
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->src,
&NET_IPV6_BUF(orig)->dst);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, &addr);
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->dst, &addr);
}
if (NET_IPV6_BUF(buf)->nexthdr == NET_IPV6_NEXTHDR_HBHO) {
if (NET_IPV6_BUF(pkt)->nexthdr == NET_IPV6_NEXTHDR_HBHO) {
#if defined(CONFIG_NET_RPL)
uint16_t offset = NET_IPV6H_LEN;
if (net_rpl_revert_header(buf, offset, &offset) < 0) {
if (net_rpl_revert_header(pkt, offset, &offset) < 0) {
/* TODO: Handle error cases */
goto drop;
}
#endif
}
net_pkt_ll_src(buf)->addr = net_pkt_ll_dst(orig)->addr;
net_pkt_ll_src(buf)->len = net_pkt_ll_dst(orig)->len;
net_pkt_ll_src(pkt)->addr = net_pkt_ll_dst(orig)->addr;
net_pkt_ll_src(pkt)->len = net_pkt_ll_dst(orig)->len;
/* We must not set the destination ll address here but trust
* that it is set properly using a value from neighbor cache.
*/
net_pkt_ll_dst(buf)->addr = NULL;
net_pkt_ll_dst(pkt)->addr = NULL;
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf);
NET_ICMP_BUF(pkt)->chksum = 0;
NET_ICMP_BUF(pkt)->chksum = ~net_calc_chksum_icmpv6(pkt);
echo_reply_debug(buf);
echo_reply_debug(pkt);
if (net_send_data(buf) < 0) {
if (net_send_data(pkt) < 0) {
goto drop;
}
@ -221,18 +221,19 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
return NET_OK;
drop:
net_pkt_unref(buf);
net_pkt_unref(pkt);
drop_no_buf:
drop_no_pkt:
net_stats_update_icmp_drop();
return NET_DROP;
}
int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
int net_icmpv6_send_error(struct net_pkt *orig, uint8_t type, uint8_t code,
uint32_t param)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct net_if *iface;
size_t extra_len, reserve;
int err = -EIO;
@ -241,16 +242,16 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
if (NET_ICMP_BUF(orig)->code < 128) {
/* We must not send ICMP errors back */
err = -EINVAL;
goto drop_no_buf;
goto drop_no_pkt;
}
}
iface = net_pkt_iface(orig);
buf = net_pkt_get_reserve_tx(0, BUF_WAIT_TIME);
if (!buf) {
pkt = net_pkt_get_reserve_tx(0, PKT_WAIT_TIME);
if (!pkt) {
err = -ENOMEM;
goto drop_no_buf;
goto drop_no_pkt;
}
/* There is unsed part in ICMPv6 error msg header what we might need
@ -280,72 +281,72 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
/* We only copy minimal IPv6 + next header from original message.
* This is so that the memory pressure is minimized.
*/
frag = net_pkt_copy(orig, extra_len, reserve, BUF_WAIT_TIME);
frag = net_pkt_copy(orig, extra_len, reserve, PKT_WAIT_TIME);
if (!frag) {
err = -ENOMEM;
goto drop;
}
net_buf_frag_add(buf, frag);
net_pkt_set_family(buf, AF_INET6);
net_pkt_set_iface(buf, iface);
net_pkt_set_ll_reserve(buf, net_buf_headroom(frag));
net_pkt_set_ext_len(buf, 0);
net_pkt_frag_add(pkt, frag);
net_pkt_set_family(pkt, AF_INET6);
net_pkt_set_iface(pkt, iface);
net_pkt_set_ll_reserve(pkt, net_buf_headroom(frag));
net_pkt_set_ext_len(pkt, 0);
setup_ipv6_header(buf, extra_len, net_if_ipv6_get_hop_limit(iface),
setup_ipv6_header(pkt, extra_len, net_if_ipv6_get_hop_limit(iface),
type, code);
/* Depending on error option, we store the param into the ICMP message.
*/
if (type == NET_ICMPV6_PARAM_PROBLEM) {
sys_put_be32(param, net_pkt_icmp_data(buf) +
sys_put_be32(param, net_pkt_icmp_data(pkt) +
sizeof(struct net_icmp_hdr));
}
if (net_is_ipv6_addr_mcast(&NET_IPV6_BUF(orig)->dst)) {
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst,
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->dst,
&NET_IPV6_BUF(orig)->src);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src,
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->src,
net_if_ipv6_select_src_addr(iface,
&NET_IPV6_BUF(orig)->dst));
} else {
struct in6_addr addr;
net_ipaddr_copy(&addr, &NET_IPV6_BUF(orig)->src);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src,
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->src,
&NET_IPV6_BUF(orig)->dst);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, &addr);
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->dst, &addr);
}
net_pkt_ll_src(buf)->addr = net_pkt_ll_dst(orig)->addr;
net_pkt_ll_src(buf)->len = net_pkt_ll_dst(orig)->len;
net_pkt_ll_dst(buf)->addr = net_pkt_ll_src(orig)->addr;
net_pkt_ll_dst(buf)->len = net_pkt_ll_src(orig)->len;
net_pkt_ll_src(pkt)->addr = net_pkt_ll_dst(orig)->addr;
net_pkt_ll_src(pkt)->len = net_pkt_ll_dst(orig)->len;
net_pkt_ll_dst(pkt)->addr = net_pkt_ll_src(orig)->addr;
net_pkt_ll_dst(pkt)->len = net_pkt_ll_src(orig)->len;
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf);
NET_ICMP_BUF(pkt)->chksum = 0;
NET_ICMP_BUF(pkt)->chksum = ~net_calc_chksum_icmpv6(pkt);
#if defined(CONFIG_NET_DEBUG_ICMPV6)
do {
char out[NET_IPV6_ADDR_LEN];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->dst));
NET_DBG("Sending ICMPv6 Error Message type %d code %d param %d"
" from %s to %s", type, code, param,
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out);
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->src), out);
} while (0);
#endif /* CONFIG_NET_DEBUG_ICMPV6 */
if (net_send_data(buf) >= 0) {
if (net_send_data(pkt) >= 0) {
net_stats_update_icmp_sent();
return 0;
}
drop:
net_pkt_unref(buf);
net_pkt_unref(pkt);
drop_no_buf:
drop_no_pkt:
net_stats_update_icmp_drop();
return err;
@ -357,31 +358,31 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
uint16_t sequence)
{
const struct in6_addr *src;
struct net_buf *buf;
struct net_pkt *pkt;
src = net_if_ipv6_select_src_addr(iface, dst);
buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
pkt = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
K_FOREVER);
buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6);
pkt = net_ipv6_create_raw(pkt, src, dst, iface, IPPROTO_ICMPV6);
net_pkt_set_family(buf, AF_INET6);
net_pkt_set_iface(buf, iface);
net_pkt_set_family(pkt, AF_INET6);
net_pkt_set_iface(pkt, iface);
net_pkt_append_u8(buf, NET_ICMPV6_ECHO_REQUEST);
net_pkt_append_u8(buf, 0); /* code */
net_pkt_append_be16(buf, 0); /* checksum */
net_pkt_append_be16(buf, identifier);
net_pkt_append_be16(buf, sequence);
net_pkt_append_u8(pkt, NET_ICMPV6_ECHO_REQUEST);
net_pkt_append_u8(pkt, 0); /* code */
net_pkt_append_be16(pkt, 0); /* checksum */
net_pkt_append_be16(pkt, identifier);
net_pkt_append_be16(pkt, sequence);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, src);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst);
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->src, src);
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->dst, dst);
NET_ICMP_BUF(buf)->chksum = 0;
NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf);
NET_ICMP_BUF(pkt)->chksum = 0;
NET_ICMP_BUF(pkt)->chksum = ~net_calc_chksum_icmpv6(pkt);
if (net_ipv6_finalize_raw(buf, IPPROTO_ICMPV6) < 0) {
if (net_ipv6_finalize_raw(pkt, IPPROTO_ICMPV6) < 0) {
goto drop;
}
@ -390,26 +391,26 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
char out[NET_IPV6_ADDR_LEN];
snprintk(out, sizeof(out), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->dst));
NET_DBG("Sending ICMPv6 Echo Request type %d"
" from %s to %s", NET_ICMPV6_ECHO_REQUEST,
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), out);
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->src), out);
} while (0);
#endif /* CONFIG_NET_DEBUG_ICMPV6 */
if (net_send_data(buf) >= 0) {
if (net_send_data(pkt) >= 0) {
net_stats_update_icmp_sent();
return 0;
}
drop:
net_pkt_unref(buf);
net_pkt_unref(pkt);
net_stats_update_icmp_drop();
return -EIO;
}
enum net_verdict net_icmpv6_input(struct net_buf *buf,
enum net_verdict net_icmpv6_input(struct net_pkt *pkt,
uint8_t type, uint8_t code)
{
struct net_icmpv6_handler *cb;
@ -418,7 +419,7 @@ enum net_verdict net_icmpv6_input(struct net_buf *buf,
SYS_SLIST_FOR_EACH_CONTAINER(&handlers, cb, node) {
if (cb->type == type && (cb->code == code || cb->code == 0)) {
return cb->handler(buf);
return cb->handler(pkt);
}
}

View file

@ -75,25 +75,25 @@ struct net_icmpv6_nd_opt_6co {
struct in6_addr prefix;
} __packed;
#define NET_ICMPV6_NS_BUF(buf) \
((struct net_icmpv6_ns_hdr *)(net_pkt_icmp_data(buf) + \
#define NET_ICMPV6_NS_BUF(pkt) \
((struct net_icmpv6_ns_hdr *)(net_pkt_icmp_data(pkt) + \
sizeof(struct net_icmp_hdr)))
#define NET_ICMPV6_ND_OPT_HDR_BUF(buf) \
((struct net_icmpv6_nd_opt_hdr *)(net_pkt_icmp_data(buf) + \
#define NET_ICMPV6_ND_OPT_HDR_BUF(pkt) \
((struct net_icmpv6_nd_opt_hdr *)(net_pkt_icmp_data(pkt) + \
sizeof(struct net_icmp_hdr) + \
net_pkt_ext_opt_len(buf)))
net_pkt_ext_opt_len(pkt)))
#define NET_ICMPV6_NA_BUF(buf) \
((struct net_icmpv6_na_hdr *)(net_pkt_icmp_data(buf) + \
#define NET_ICMPV6_NA_BUF(pkt) \
((struct net_icmpv6_na_hdr *)(net_pkt_icmp_data(pkt) + \
sizeof(struct net_icmp_hdr)))
#define NET_ICMPV6_RS_BUF(buf) \
((struct net_icmpv6_rs_hdr *)(net_pkt_icmp_data(buf) + \
#define NET_ICMPV6_RS_BUF(pkt) \
((struct net_icmpv6_rs_hdr *)(net_pkt_icmp_data(pkt) + \
sizeof(struct net_icmp_hdr)))
#define NET_ICMPV6_RA_BUF(buf) \
((struct net_icmpv6_ra_hdr *)(net_pkt_icmp_data(buf) + \
#define NET_ICMPV6_RA_BUF(pkt) \
((struct net_icmpv6_ra_hdr *)(net_pkt_icmp_data(pkt) + \
sizeof(struct net_icmp_hdr)))
#define NET_ICMPV6_ND_O_FLAG(flag) ((flag) & 0x40)
@ -148,7 +148,7 @@ struct net_icmpv6_nd_opt_6co {
/* ICMPv6 header has 4 unused bytes that must be zero, RFC 4443 ch 3.1 */
#define NET_ICMPV6_UNUSED_LEN 4
typedef enum net_verdict (*icmpv6_callback_handler_t)(struct net_buf *buf);
typedef enum net_verdict (*icmpv6_callback_handler_t)(struct net_pkt *pkt);
const char *net_icmpv6_type2str(int icmpv6_type);
@ -161,7 +161,7 @@ struct net_icmpv6_handler {
/**
* @brief Send ICMPv6 error message.
* @param buf Network buffer that this error is related to.
* @param pkt Network packet that this error is related to.
* @param type Type of the error message.
* @param code Code of the type of the error message.
* @param param Optional parameter value for this error. Depending on type
@ -169,7 +169,7 @@ struct net_icmpv6_handler {
* what value to use.
* @return Return 0 if the sending succeed, <0 otherwise.
*/
int net_icmpv6_send_error(struct net_buf *buf, uint8_t type, uint8_t code,
int net_icmpv6_send_error(struct net_pkt *pkt, uint8_t type, uint8_t code,
uint32_t param);
/**
@ -191,7 +191,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
void net_icmpv6_register_handler(struct net_icmpv6_handler *handler);
void net_icmpv6_unregister_handler(struct net_icmpv6_handler *handler);
enum net_verdict net_icmpv6_input(struct net_buf *buf,
enum net_verdict net_icmpv6_input(struct net_pkt *pkt,
uint8_t type, uint8_t code);
#if defined(CONFIG_NET_IPV6)
void net_icmpv6_init(void);

View file

@ -24,7 +24,7 @@
#include "icmpv4.h"
#include "ipv4.h"
struct net_buf *net_ipv4_create_raw(struct net_buf *buf,
struct net_pkt *net_ipv4_create_raw(struct net_pkt *pkt,
const struct in_addr *src,
const struct in_addr *dst,
struct net_if *iface,
@ -32,33 +32,33 @@ struct net_buf *net_ipv4_create_raw(struct net_buf *buf,
{
struct net_buf *header;
header = net_pkt_get_frag(buf, K_FOREVER);
header = net_pkt_get_frag(pkt, K_FOREVER);
net_buf_frag_insert(buf, header);
net_pkt_frag_insert(pkt, header);
NET_IPV4_BUF(buf)->vhl = 0x45;
NET_IPV4_BUF(buf)->tos = 0x00;
NET_IPV4_BUF(buf)->proto = 0;
NET_IPV4_BUF(pkt)->vhl = 0x45;
NET_IPV4_BUF(pkt)->tos = 0x00;
NET_IPV4_BUF(pkt)->proto = 0;
NET_IPV4_BUF(buf)->ttl = net_if_ipv4_get_ttl(iface);
NET_IPV4_BUF(buf)->offset[0] = NET_IPV4_BUF(buf)->offset[1] = 0;
NET_IPV4_BUF(buf)->id[0] = NET_IPV4_BUF(buf)->id[1] = 0;
NET_IPV4_BUF(pkt)->ttl = net_if_ipv4_get_ttl(iface);
NET_IPV4_BUF(pkt)->offset[0] = NET_IPV4_BUF(pkt)->offset[1] = 0;
NET_IPV4_BUF(pkt)->id[0] = NET_IPV4_BUF(pkt)->id[1] = 0;
net_ipaddr_copy(&NET_IPV4_BUF(buf)->dst, dst);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->src, src);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->dst, dst);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->src, src);
NET_IPV4_BUF(buf)->proto = next_header;
NET_IPV4_BUF(pkt)->proto = next_header;
net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr));
net_pkt_set_family(buf, AF_INET);
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr));
net_pkt_set_family(pkt, AF_INET);
net_buf_add(header, sizeof(struct net_ipv4_hdr));
return buf;
return pkt;
}
struct net_buf *net_ipv4_create(struct net_context *context,
struct net_buf *buf,
struct net_pkt *net_ipv4_create(struct net_context *context,
struct net_pkt *pkt,
const struct in_addr *src,
const struct in_addr *dst)
{
@ -70,50 +70,50 @@ struct net_buf *net_ipv4_create(struct net_context *context,
if (net_is_ipv4_addr_unspecified(src)
|| net_is_ipv4_addr_mcast(src)) {
src = &net_pkt_iface(buf)->ipv4.unicast[0].address.in_addr;
src = &net_pkt_iface(pkt)->ipv4.unicast[0].address.in_addr;
}
return net_ipv4_create_raw(buf,
return net_ipv4_create_raw(pkt,
src,
dst,
net_context_get_iface(context),
net_context_get_ip_proto(context));
}
int net_ipv4_finalize_raw(struct net_buf *buf, uint8_t next_header)
int net_ipv4_finalize_raw(struct net_pkt *pkt, uint8_t next_header)
{
/* Set the length of the IPv4 header */
size_t total_len;
net_pkt_compact(buf);
net_pkt_compact(pkt);
total_len = net_buf_frags_len(buf->frags);
total_len = net_pkt_get_len(pkt);
NET_IPV4_BUF(buf)->len[0] = total_len / 256;
NET_IPV4_BUF(buf)->len[1] = total_len - NET_IPV4_BUF(buf)->len[0] * 256;
NET_IPV4_BUF(pkt)->len[0] = total_len / 256;
NET_IPV4_BUF(pkt)->len[1] = total_len - NET_IPV4_BUF(pkt)->len[0] * 256;
NET_IPV4_BUF(buf)->chksum = 0;
NET_IPV4_BUF(buf)->chksum = ~net_calc_chksum_ipv4(buf);
NET_IPV4_BUF(pkt)->chksum = 0;
NET_IPV4_BUF(pkt)->chksum = ~net_calc_chksum_ipv4(pkt);
#if defined(CONFIG_NET_UDP)
if (next_header == IPPROTO_UDP) {
NET_UDP_BUF(buf)->chksum = 0;
NET_UDP_BUF(buf)->chksum = ~net_calc_chksum_udp(buf);
NET_UDP_BUF(pkt)->chksum = 0;
NET_UDP_BUF(pkt)->chksum = ~net_calc_chksum_udp(pkt);
}
#endif
#if defined(CONFIG_NET_TCP)
if (next_header == IPPROTO_TCP) {
NET_TCP_BUF(buf)->chksum = 0;
NET_TCP_BUF(buf)->chksum = ~net_calc_chksum_tcp(buf);
NET_TCP_BUF(pkt)->chksum = 0;
NET_TCP_BUF(pkt)->chksum = ~net_calc_chksum_tcp(pkt);
}
#endif
return 0;
}
int net_ipv4_finalize(struct net_context *context, struct net_buf *buf)
int net_ipv4_finalize(struct net_context *context, struct net_pkt *pkt)
{
return net_ipv4_finalize_raw(buf,
return net_ipv4_finalize_raw(pkt,
net_context_get_ip_proto(context));
}
@ -131,26 +131,26 @@ const struct in_addr *net_ipv4_broadcast_address(void)
return &addr;
}
static inline enum net_verdict process_icmpv4_pkt(struct net_buf *buf,
static inline enum net_verdict process_icmpv4_pkt(struct net_pkt *pkt,
struct net_ipv4_hdr *ipv4)
{
struct net_icmp_hdr *hdr = NET_ICMP_BUF(buf);
struct net_icmp_hdr *hdr = NET_ICMP_BUF(pkt);
NET_DBG("ICMPv4 packet received type %d code %d",
hdr->type, hdr->code);
return net_icmpv4_input(buf, hdr->type, hdr->code);
return net_icmpv4_input(pkt, hdr->type, hdr->code);
}
enum net_verdict net_ipv4_process_pkt(struct net_buf *buf)
enum net_verdict net_ipv4_process_pkt(struct net_pkt *pkt)
{
struct net_ipv4_hdr *hdr = NET_IPV4_BUF(buf);
int real_len = net_buf_frags_len(buf);
struct net_ipv4_hdr *hdr = NET_IPV4_BUF(pkt);
int real_len = net_pkt_get_len(pkt);
int pkt_len = (hdr->len[0] << 8) + hdr->len[1];
enum net_verdict verdict = NET_DROP;
if (real_len != pkt_len) {
NET_DBG("IPv4 packet size %d buf len %d", pkt_len, real_len);
NET_DBG("IPv4 packet size %d pkt len %d", pkt_len, real_len);
goto drop;
}
@ -165,7 +165,7 @@ enum net_verdict net_ipv4_process_pkt(struct net_buf *buf)
} while (0);
#endif /* CONFIG_NET_DEBUG_IPV4 */
net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr));
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr));
if (!net_is_my_ipv4_addr(&hdr->dst)) {
#if defined(CONFIG_NET_DHCPV4)
@ -173,25 +173,25 @@ enum net_verdict net_ipv4_process_pkt(struct net_buf *buf)
net_ipv4_addr_cmp(&hdr->dst,
net_ipv4_broadcast_address())) {
verdict = net_conn_input(IPPROTO_UDP, buf);
verdict = net_conn_input(IPPROTO_UDP, pkt);
if (verdict != NET_DROP) {
return verdict;
}
}
#endif
NET_DBG("IPv4 packet in buf %p not for me", buf);
NET_DBG("IPv4 packet in pkt %p not for me", pkt);
goto drop;
}
switch (hdr->proto) {
case IPPROTO_ICMP:
verdict = process_icmpv4_pkt(buf, hdr);
verdict = process_icmpv4_pkt(pkt, hdr);
break;
case IPPROTO_UDP:
verdict = net_conn_input(IPPROTO_UDP, buf);
verdict = net_conn_input(IPPROTO_UDP, pkt);
break;
case IPPROTO_TCP:
verdict = net_conn_input(IPPROTO_TCP, buf);
verdict = net_conn_input(IPPROTO_TCP, pkt);
break;
}

View file

@ -23,34 +23,34 @@
#include "ipv4.h"
/**
* @brief Create IPv4 packet in provided net_buf.
* @brief Create IPv4 packet in provided net_pkt.
*
* @param buf Network buffer
* @param pkt Network packet
* @param src Source IPv4 address
* @param dst Destination IPv4 address
* @param iface Network interface
* @param next_header Protocol type of the next header after IPv4 header.
*
* @return Return network buffer that contains the IPv4 packet.
* @return Return network packet that contains the IPv4 packet.
*/
struct net_buf *net_ipv4_create_raw(struct net_buf *buf,
struct net_pkt *net_ipv4_create_raw(struct net_pkt *pkt,
const struct in_addr *src,
const struct in_addr *dst,
struct net_if *iface,
uint8_t next_header);
/**
* @brief Create IPv4 packet in provided net_buf.
* @brief Create IPv4 packet in provided net_pkt.
*
* @param context Network context for a connection
* @param buf Network buffer
* @param pkt Network packet
* @param src_addr Source address, or NULL to choose a default
* @param dst_addr Destination IPv4 address
*
* @return Return network buffer that contains the IPv6 packet.
* @return Return network packet that contains the IPv6 packet.
*/
struct net_buf *net_ipv4_create(struct net_context *context,
struct net_buf *buf,
struct net_pkt *net_ipv4_create(struct net_context *context,
struct net_pkt *pkt,
const struct in_addr *src_addr,
const struct in_addr *dst_addr);
@ -60,12 +60,12 @@ struct net_buf *net_ipv4_create(struct net_context *context,
* the packet. This function will set the length of the
* packet and calculate the higher protocol checksum if needed.
*
* @param buf Network buffer
* @param pkt Network packet
* @param next_header Protocol type of the next header after IPv4 header.
*
* @return Return 0 on Success, < 0 on Failure.
*/
int net_ipv4_finalize_raw(struct net_buf *buf, uint8_t next_header);
int net_ipv4_finalize_raw(struct net_pkt *pkt, uint8_t next_header);
/**
* @brief Finalize IPv4 packet. It should be called right before
@ -74,10 +74,10 @@ int net_ipv4_finalize_raw(struct net_buf *buf, uint8_t next_header);
* packet and calculate the higher protocol checksum if needed.
*
* @param context Network context for a connection
* @param buf Network buffer
* @param pkt Network packet
*
* @return Return 0 on Success, < 0 on Failure.
*/
int net_ipv4_finalize(struct net_context *context, struct net_buf *buf);
int net_ipv4_finalize(struct net_context *context, struct net_pkt *pkt);
#endif /* __IPV4_H */

File diff suppressed because it is too large Load diff

View file

@ -78,8 +78,8 @@ const char *net_ipv6_nbr_state2str(enum net_ipv6_nbr_state state);
* @brief IPv6 neighbor information.
*/
struct net_ipv6_nbr_data {
/** Any pending buffer waiting ND to finish. */
struct net_buf *pending;
/** Any pending packet waiting ND to finish. */
struct net_pkt *pending;
/** IPv6 address. */
struct in6_addr addr;
@ -121,7 +121,7 @@ struct net_ipv6_nbr_data *net_ipv6_get_nbr_by_index(uint8_t idx);
int net_ipv6_start_dad(struct net_if *iface, struct net_if_addr *ifaddr);
#endif
int net_ipv6_send_ns(struct net_if *iface, struct net_buf *pending,
int net_ipv6_send_ns(struct net_if *iface, struct net_pkt *pending,
struct in6_addr *src, struct in6_addr *dst,
struct in6_addr *tgt, bool is_my_address);
@ -133,34 +133,34 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src,
uint8_t flags);
/**
* @brief Create IPv6 packet in provided net_buf.
* @brief Create IPv6 packet in provided net_pkt.
*
* @param buf Network buffer
* @param pkt Network packet
* @param src Source IPv6 address
* @param dst Destination IPv6 address
* @param iface Network interface
* @param next_header Protocol type of the next header after IPv6 header.
*
* @return Return network buffer that contains the IPv6 packet.
* @return Return network packet that contains the IPv6 packet.
*/
struct net_buf *net_ipv6_create_raw(struct net_buf *buf,
struct net_pkt *net_ipv6_create_raw(struct net_pkt *pkt,
const struct in6_addr *src,
const struct in6_addr *dst,
struct net_if *iface,
uint8_t next_header);
/**
* @brief Create IPv6 packet in provided net_buf.
* @brief Create IPv6 packet in provided net_pkt.
*
* @param context Network context for a connection
* @param buf Network buffer
* @param pkt Network packet
* @param src_addr Source address, or NULL to choose a default from context
* @param dst_addr Destination IPv6 address
*
* @return Return network buffer that contains the IPv6 packet.
* @return Return network packet that contains the IPv6 packet.
*/
struct net_buf *net_ipv6_create(struct net_context *context,
struct net_buf *buf,
struct net_pkt *net_ipv6_create(struct net_context *context,
struct net_pkt *pkt,
const struct in6_addr *src_addr,
const struct in6_addr *dst_addr);
@ -170,12 +170,12 @@ struct net_buf *net_ipv6_create(struct net_context *context,
* the packet. This function will set the length of the
* packet and calculate the higher protocol checksum if needed.
*
* @param buf Network buffer
* @param pkt Network packet
* @param next_header Protocol type of the next header after IPv6 header.
*
* @return Return 0 on Success, < 0 on Failure.
*/
int net_ipv6_finalize_raw(struct net_buf *buf, uint8_t next_header);
int net_ipv6_finalize_raw(struct net_pkt *pkt, uint8_t next_header);
/**
* @brief Finalize IPv6 packet. It should be called right before
@ -184,11 +184,11 @@ int net_ipv6_finalize_raw(struct net_buf *buf, uint8_t next_header);
* packet and calculate the higher protocol checksum if needed.
*
* @param context Network context for a connection
* @param buf Network buffer
* @param pkt Network packet
*
* @return Return 0 on Success, < 0 on Failure.
*/
int net_ipv6_finalize(struct net_context *context, struct net_buf *buf);
int net_ipv6_finalize(struct net_context *context, struct net_pkt *pkt);
#if defined(CONFIG_NET_IPV6_MLD)
/**
@ -233,11 +233,11 @@ typedef void (*net_nbr_cb_t)(struct net_nbr *nbr, void *user_data);
* and the original message is sent after Neighbor Advertisement
* message is received.
*
* @param buf Network buffer
* @param pkt Network packet
*
* @return Return network buffer to be sent.
* @return Return network packet to be sent.
*/
struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf);
struct net_pkt *net_ipv6_prepare_for_send(struct net_pkt *pkt);
/**
* @brief Look for a neighbor from it's address on an iface
@ -313,9 +313,9 @@ bool net_ipv6_nbr_rm(struct net_if *iface, struct in6_addr *addr);
void net_ipv6_nbr_foreach(net_nbr_cb_t cb, void *user_data);
#else /* CONFIG_NET_IPV6_NBR_CACHE */
static inline struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf)
static inline struct net_pkt *net_ipv6_prepare_for_send(struct net_pkt *pkt)
{
return buf;
return pkt;
}
static inline struct net_nbr *net_ipv6_nbr_lookup(struct net_if *iface,
@ -373,7 +373,7 @@ static inline void net_ipv6_nbr_set_reachable_timer(struct net_if *iface,
* This means that we should receive everything within first two fragments.
* The first one being 1280 bytes and the second one 220 bytes.
*/
#define NET_IPV6_FRAGMENTS_MAX_BUF 2
#define NET_IPV6_FRAGMENTS_MAX_PKT 2
/** Store pending IPv6 fragment information that is needed for reassembly. */
struct net_ipv6_reassembly {
@ -390,7 +390,7 @@ struct net_ipv6_reassembly {
struct k_delayed_work timer;
/** Pointers to pending fragments */
struct net_buf *buf[NET_IPV6_FRAGMENTS_MAX_BUF];
struct net_pkt *pkt[NET_IPV6_FRAGMENTS_MAX_PKT];
/** IPv6 fragment identification */
uint32_t id;
@ -419,12 +419,12 @@ void net_ipv6_frag_foreach(net_ipv6_frag_cb_t cb, void *user_data);
/**
* @brief Find the last IPv6 extension header in the network packet.
*
* @param buf Network head buffer.
* @param pkt Network head packet.
*
* @return Offset to the extension header within the first fragment of net_buf.
* @return Offset to the extension header within the first fragment of net_pkt.
* Return <0 if the packet is malformed.
*/
int net_ipv6_find_last_ext_hdr(struct net_buf *buf);
int net_ipv6_find_last_ext_hdr(struct net_pkt *pkt);
#if defined(CONFIG_NET_IPV6)
void net_ipv6_init(void);

View file

@ -24,7 +24,7 @@
struct arp_entry {
uint32_t time; /* FIXME - implement timeout functionality */
struct net_if *iface;
struct net_buf *pending;
struct net_pkt *pending;
struct in_addr ip;
struct net_eth_addr eth;
};
@ -97,41 +97,42 @@ static inline struct in_addr *if_get_addr(struct net_if *iface)
return NULL;
}
static inline struct net_buf *prepare_arp(struct net_if *iface,
static inline struct net_pkt *prepare_arp(struct net_if *iface,
struct in_addr *next_addr,
struct arp_entry *entry,
struct net_buf *pending)
struct net_pkt *pending)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct net_arp_hdr *hdr;
struct net_eth_hdr *eth;
struct in_addr *my_addr;
buf = net_pkt_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
if (!buf) {
pkt = net_pkt_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
if (!pkt) {
goto fail;
}
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
if (!frag) {
goto fail;
}
net_buf_frag_add(buf, frag);
net_pkt_set_iface(buf, iface);
net_pkt_set_family(buf, AF_INET);
net_pkt_frag_add(pkt, frag);
net_pkt_set_iface(pkt, iface);
net_pkt_set_family(pkt, AF_INET);
hdr = NET_ARP_BUF(buf);
eth = NET_ETH_BUF(buf);
hdr = NET_ARP_BUF(pkt);
eth = NET_ETH_BUF(pkt);
/* If entry is not set, then we are just about to send
* an ARP request using the data in pending net_buf.
* an ARP request using the data in pending net_pkt.
* This can happen if there is already a pending ARP
* request and we want to send it again.
*/
if (entry) {
entry->pending = net_pkt_ref(pending);
entry->iface = net_pkt_iface(buf);
entry->iface = net_pkt_iface(pkt);
net_ipaddr_copy(&entry->ip, next_addr);
@ -174,15 +175,15 @@ static inline struct net_buf *prepare_arp(struct net_if *iface,
net_buf_add(frag, sizeof(struct net_arp_hdr));
return buf;
return pkt;
fail:
net_pkt_unref(buf);
net_pkt_unref(pkt);
net_pkt_unref(pending);
return NULL;
}
struct net_buf *net_arp_prepare(struct net_buf *buf)
struct net_pkt *net_arp_prepare(struct net_pkt *pkt)
{
struct net_buf *frag;
struct arp_entry *entry, *free_entry = NULL, *non_pending = NULL;
@ -190,57 +191,57 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
struct net_eth_hdr *hdr;
struct in_addr *addr;
if (!buf || !buf->frags) {
if (!pkt || !pkt->frags) {
return NULL;
}
if (net_pkt_ll_reserve(buf) != sizeof(struct net_eth_hdr)) {
if (net_pkt_ll_reserve(pkt) != sizeof(struct net_eth_hdr)) {
/* Add the ethernet header if it is missing. */
struct net_buf *header;
struct net_linkaddr *ll;
net_pkt_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
net_pkt_set_ll_reserve(pkt, sizeof(struct net_eth_hdr));
header = net_pkt_get_frag(buf, K_FOREVER);
header = net_pkt_get_frag(pkt, K_FOREVER);
hdr = (struct net_eth_hdr *)(header->data -
net_pkt_ll_reserve(buf));
net_pkt_ll_reserve(pkt));
hdr->type = htons(NET_ETH_PTYPE_IP);
ll = net_pkt_ll_dst(buf);
ll = net_pkt_ll_dst(pkt);
if (ll->addr) {
memcpy(&hdr->dst.addr, ll->addr,
sizeof(struct net_eth_addr));
}
ll = net_pkt_ll_src(buf);
ll = net_pkt_ll_src(pkt);
if (ll->addr) {
memcpy(&hdr->src.addr, ll->addr,
sizeof(struct net_eth_addr));
}
net_buf_frag_insert(buf, header);
net_pkt_frag_insert(pkt, header);
net_pkt_compact(buf);
net_pkt_compact(pkt);
}
hdr = (struct net_eth_hdr *)net_pkt_ll(buf);
hdr = (struct net_eth_hdr *)net_pkt_ll(pkt);
/* Is the destination in the local network, if not route via
* the gateway address.
*/
if (!net_if_ipv4_addr_mask_cmp(net_pkt_iface(buf),
&NET_IPV4_BUF(buf)->dst)) {
addr = &net_pkt_iface(buf)->ipv4.gw;
if (!net_if_ipv4_addr_mask_cmp(net_pkt_iface(pkt),
&NET_IPV4_BUF(pkt)->dst)) {
addr = &net_pkt_iface(pkt)->ipv4.gw;
} else {
addr = &NET_IPV4_BUF(buf)->dst;
addr = &NET_IPV4_BUF(pkt)->dst;
}
/* If the destination address is already known, we do not need
* to send any ARP packet.
*/
entry = find_entry(net_pkt_iface(buf),
entry = find_entry(net_pkt_iface(pkt),
addr, &free_entry, &non_pending);
if (!entry) {
if (!free_entry) {
@ -253,13 +254,13 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
* pending query to this IP address,
* so this packet must be discarded.
*/
struct net_buf *req;
struct net_pkt *req;
req = prepare_arp(net_pkt_iface(buf),
addr, NULL, buf);
req = prepare_arp(net_pkt_iface(pkt),
addr, NULL, pkt);
NET_DBG("Resending ARP %p", req);
net_pkt_unref(buf);
net_pkt_unref(pkt);
return req;
}
@ -267,16 +268,16 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
free_entry = non_pending;
}
return prepare_arp(net_pkt_iface(buf), addr, free_entry, buf);
return prepare_arp(net_pkt_iface(pkt), addr, free_entry, pkt);
}
ll = net_if_get_link_addr(entry->iface);
NET_DBG("ARP using ll %s for IP %s",
net_sprint_ll_addr(ll->addr, sizeof(struct net_eth_addr)),
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src));
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src));
frag = buf->frags;
frag = pkt->frags;
while (frag) {
/* If there is no room for link layer header, then
* just send the packet as is.
@ -287,7 +288,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
}
hdr = (struct net_eth_hdr *)(frag->data -
net_pkt_ll_reserve(buf));
net_pkt_ll_reserve(pkt));
hdr->type = htons(NET_ETH_PTYPE_IP);
memcpy(&hdr->src.addr, ll->addr,
@ -298,25 +299,25 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
frag = frag->frags;
}
return buf;
return pkt;
}
static inline void send_pending(struct net_if *iface, struct net_buf **buf)
static inline void send_pending(struct net_if *iface, struct net_pkt **pkt)
{
struct net_buf *pending = *buf;
struct net_pkt *pending = *pkt;
NET_DBG("dst %s pending %p frag %p",
net_sprint_ipv4_addr(&NET_IPV4_BUF(pending)->dst), pending,
pending->frags);
*buf = NULL;
*pkt = NULL;
if (net_if_send_data(iface, pending) == NET_DROP) {
/* This is to unref the original ref */
net_pkt_unref(pending);
}
/* The pending buf was referenced when
/* The pending pkt was referenced when
* it was added to cache so we need to
* unref it now when it is removed from
* the cache.
@ -365,29 +366,30 @@ static inline void arp_update(struct net_if *iface,
}
}
static inline struct net_buf *prepare_arp_reply(struct net_if *iface,
struct net_buf *req)
static inline struct net_pkt *prepare_arp_reply(struct net_if *iface,
struct net_pkt *req)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
struct net_arp_hdr *hdr, *query;
struct net_eth_hdr *eth, *eth_query;
buf = net_pkt_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
if (!buf) {
pkt = net_pkt_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
if (!pkt) {
goto fail;
}
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
if (!frag) {
goto fail;
}
net_buf_frag_add(buf, frag);
net_pkt_set_iface(buf, iface);
net_pkt_set_family(buf, AF_INET);
net_pkt_frag_add(pkt, frag);
net_pkt_set_iface(pkt, iface);
net_pkt_set_family(pkt, AF_INET);
hdr = NET_ARP_BUF(buf);
eth = NET_ETH_BUF(buf);
hdr = NET_ARP_BUF(pkt);
eth = NET_ETH_BUF(pkt);
query = NET_ARP_BUF(req);
eth_query = NET_ETH_BUF(req);
@ -414,34 +416,34 @@ static inline struct net_buf *prepare_arp_reply(struct net_if *iface,
net_buf_add(frag, sizeof(struct net_arp_hdr));
return buf;
return pkt;
fail:
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NULL;
}
enum net_verdict net_arp_input(struct net_buf *buf)
enum net_verdict net_arp_input(struct net_pkt *pkt)
{
struct net_arp_hdr *arp_hdr;
struct net_buf *reply;
struct net_pkt *reply;
if (net_buf_frags_len(buf) < (sizeof(struct net_arp_hdr) -
net_pkt_ll_reserve(buf))) {
if (net_pkt_get_len(pkt) < (sizeof(struct net_arp_hdr) -
net_pkt_ll_reserve(pkt))) {
NET_DBG("Invalid ARP header (len %zu, min %zu bytes)",
net_buf_frags_len(buf),
net_pkt_get_len(pkt),
sizeof(struct net_arp_hdr) -
net_pkt_ll_reserve(buf));
net_pkt_ll_reserve(pkt));
return NET_DROP;
}
arp_hdr = NET_ARP_BUF(buf);
arp_hdr = NET_ARP_BUF(pkt);
switch (ntohs(arp_hdr->opcode)) {
case NET_ARP_REQUEST:
/* Someone wants to know our ll address */
if (!net_ipv4_addr_cmp(&arp_hdr->dst_ipaddr,
if_get_addr(net_pkt_iface(buf)))) {
if_get_addr(net_pkt_iface(pkt)))) {
/* Not for us so drop the packet silently */
return NET_DROP;
}
@ -461,7 +463,7 @@ enum net_verdict net_arp_input(struct net_buf *buf)
#endif /* CONFIG_NET_DEBUG_ARP */
/* Send reply */
reply = prepare_arp_reply(net_pkt_iface(buf), buf);
reply = prepare_arp_reply(net_pkt_iface(pkt), pkt);
if (reply) {
net_if_queue_tx(net_pkt_iface(reply), reply);
}
@ -469,13 +471,13 @@ enum net_verdict net_arp_input(struct net_buf *buf)
case NET_ARP_REPLY:
if (net_is_my_ipv4_addr(&arp_hdr->dst_ipaddr)) {
arp_update(net_pkt_iface(buf), &arp_hdr->src_ipaddr,
arp_update(net_pkt_iface(pkt), &arp_hdr->src_ipaddr,
&arp_hdr->src_hwaddr);
}
break;
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NET_OK;
}

View file

@ -50,11 +50,11 @@ struct bt_context {
bt_addr_t dst;
};
static enum net_verdict net_bt_recv(struct net_if *iface, struct net_buf *buf)
static enum net_verdict net_bt_recv(struct net_if *iface, struct net_pkt *pkt)
{
NET_DBG("iface %p buf %p len %zu", iface, buf, net_buf_frags_len(buf));
NET_DBG("iface %p pkt %p len %zu", iface, pkt, net_pkt_get_len(pkt));
if (!net_6lo_uncompress(buf)) {
if (!net_6lo_uncompress(pkt)) {
NET_DBG("Packet decompression failed");
return NET_DROP;
}
@ -62,23 +62,23 @@ static enum net_verdict net_bt_recv(struct net_if *iface, struct net_buf *buf)
return NET_CONTINUE;
}
static enum net_verdict net_bt_send(struct net_if *iface, struct net_buf *buf)
static enum net_verdict net_bt_send(struct net_if *iface, struct net_pkt *pkt)
{
struct bt_context *ctxt = net_if_get_device(iface)->driver_data;
NET_DBG("iface %p buf %p len %zu", iface, buf, net_buf_frags_len(buf));
NET_DBG("iface %p pkt %p len %zu", iface, pkt, net_pkt_get_len(pkt));
/* Only accept IPv6 packets */
if (net_pkt_family(buf) != AF_INET6) {
if (net_pkt_family(pkt) != AF_INET6) {
return NET_DROP;
}
if (!net_6lo_compress(buf, true, NULL)) {
if (!net_6lo_compress(pkt, true, NULL)) {
NET_DBG("Packet compression failed");
return NET_DROP;
}
net_if_queue_tx(ctxt->iface, buf);
net_if_queue_tx(ctxt->iface, pkt);
return NET_OK;
}
@ -173,12 +173,12 @@ static void ipsp_disconnected(struct bt_l2cap_chan *chan)
static void ipsp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
{
struct bt_context *ctxt = CHAN_CTXT(chan);
struct net_buf *pkt;
struct net_pkt *pkt;
NET_DBG("Incoming data channel %p len %zu", chan,
net_buf_frags_len(buf));
/* Get buffer for bearer / protocol related data */
/* Get packet for bearer / protocol related data */
pkt = net_pkt_get_reserve_rx(0, K_FOREVER);
/* Set destination address */
@ -194,7 +194,7 @@ static void ipsp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
/* Add data buffer as fragment of RX buffer, take a reference while
* doing so since L2CAP will unref the buffer after return.
*/
net_buf_frag_add(pkt, net_pkt_ref(buf));
net_pkt_frag_add(pkt, net_buf_ref(buf));
if (net_recv_data(ctxt->iface, pkt) < 0) {
NET_DBG("Packet dropped by NET stack");
@ -222,14 +222,14 @@ static struct bt_context bt_context_data = {
.ipsp_chan.rx.mtu = L2CAP_IPSP_MTU,
};
static int bt_iface_send(struct net_if *iface, struct net_buf *buf)
static int bt_iface_send(struct net_if *iface, struct net_pkt *pkt)
{
struct bt_context *ctxt = net_if_get_device(iface)->driver_data;
int ret;
NET_DBG("iface %p buf %p len %zu", iface, buf, net_buf_frags_len(buf));
NET_DBG("iface %p pkt %p len %zu", iface, pkt, net_pkt_get_len(pkt));
ret = bt_l2cap_chan_send(&ctxt->ipsp_chan.chan, buf);
ret = bt_l2cap_chan_send(&ctxt->ipsp_chan.chan, pkt->frags);
if (ret < 0) {
return ret;
}

View file

@ -10,22 +10,22 @@
#include <net/net_pkt.h>
static inline enum net_verdict dummy_recv(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
net_pkt_ll_src(buf)->addr = NULL;
net_pkt_ll_src(buf)->len = 0;
net_pkt_ll_src(buf)->type = NET_LINK_DUMMY;
net_pkt_ll_dst(buf)->addr = NULL;
net_pkt_ll_dst(buf)->len = 0;
net_pkt_ll_dst(buf)->type = NET_LINK_DUMMY;
net_pkt_ll_src(pkt)->addr = NULL;
net_pkt_ll_src(pkt)->len = 0;
net_pkt_ll_src(pkt)->type = NET_LINK_DUMMY;
net_pkt_ll_dst(pkt)->addr = NULL;
net_pkt_ll_dst(pkt)->len = 0;
net_pkt_ll_dst(pkt)->type = NET_LINK_DUMMY;
return NET_CONTINUE;
}
static inline enum net_verdict dummy_send(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
net_if_queue_tx(iface, buf);
net_if_queue_tx(iface, pkt);
return NET_OK;
}

View file

@ -32,16 +32,16 @@ const struct net_eth_addr *net_eth_broadcast_addr(void)
}
#if defined(CONFIG_NET_DEBUG_L2_ETHERNET)
#define print_ll_addrs(buf, type, len) \
#define print_ll_addrs(pkt, type, len) \
do { \
char out[sizeof("xx:xx:xx:xx:xx:xx")]; \
\
snprintk(out, sizeof(out), "%s", \
net_sprint_ll_addr(net_pkt_ll_src(buf)->addr, \
net_sprint_ll_addr(net_pkt_ll_src(pkt)->addr, \
sizeof(struct net_eth_addr))); \
\
NET_DBG("src %s dst %s type 0x%x len %zu", out, \
net_sprint_ll_addr(net_pkt_ll_dst(buf)->addr, \
net_sprint_ll_addr(net_pkt_ll_dst(pkt)->addr, \
sizeof(struct net_eth_addr)), \
type, (size_t)len); \
} while (0)
@ -50,7 +50,7 @@ const struct net_eth_addr *net_eth_broadcast_addr(void)
#endif /* CONFIG_NET_DEBUG_L2_ETHERNET */
static inline void ethernet_update_length(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
uint16_t len;
@ -60,19 +60,19 @@ static inline void ethernet_update_length(struct net_if *iface,
* frame size of 60 bytes. In that case, we need to get rid of it.
*/
if (net_pkt_family(buf) == AF_INET) {
len = ((NET_IPV4_BUF(buf)->len[0] << 8) +
NET_IPV4_BUF(buf)->len[1]);
if (net_pkt_family(pkt) == AF_INET) {
len = ((NET_IPV4_BUF(pkt)->len[0] << 8) +
NET_IPV4_BUF(pkt)->len[1]);
} else {
len = ((NET_IPV6_BUF(buf)->len[0] << 8) +
NET_IPV6_BUF(buf)->len[1]) +
len = ((NET_IPV6_BUF(pkt)->len[0] << 8) +
NET_IPV6_BUF(pkt)->len[1]) +
NET_IPV6H_LEN;
}
if (len < NET_ETH_MINIMAL_FRAME_SIZE - sizeof(struct net_eth_hdr)) {
struct net_buf *frag;
for (frag = buf->frags; frag; frag = frag->frags) {
for (frag = pkt->frags; frag; frag = frag->frags) {
if (frag->len < len) {
len -= frag->len;
} else {
@ -84,20 +84,20 @@ static inline void ethernet_update_length(struct net_if *iface,
}
static enum net_verdict ethernet_recv(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct net_eth_hdr *hdr = NET_ETH_BUF(buf);
struct net_eth_hdr *hdr = NET_ETH_BUF(pkt);
struct net_linkaddr *lladdr;
sa_family_t family;
switch (ntohs(hdr->type)) {
case NET_ETH_PTYPE_IP:
case NET_ETH_PTYPE_ARP:
net_pkt_set_family(buf, AF_INET);
net_pkt_set_family(pkt, AF_INET);
family = AF_INET;
break;
case NET_ETH_PTYPE_IPV6:
net_pkt_set_family(buf, AF_INET6);
net_pkt_set_family(pkt, AF_INET6);
family = AF_INET6;
break;
default:
@ -106,17 +106,17 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
}
/* Set the pointers to ll src and dst addresses */
lladdr = net_pkt_ll_src(buf);
lladdr->addr = ((struct net_eth_hdr *)net_pkt_ll(buf))->src.addr;
lladdr = net_pkt_ll_src(pkt);
lladdr->addr = ((struct net_eth_hdr *)net_pkt_ll(pkt))->src.addr;
lladdr->len = sizeof(struct net_eth_addr);
lladdr->type = NET_LINK_ETHERNET;
lladdr = net_pkt_ll_dst(buf);
lladdr->addr = ((struct net_eth_hdr *)net_pkt_ll(buf))->dst.addr;
lladdr = net_pkt_ll_dst(pkt);
lladdr->addr = ((struct net_eth_hdr *)net_pkt_ll(pkt))->dst.addr;
lladdr->len = sizeof(struct net_eth_addr);
lladdr->type = NET_LINK_ETHERNET;
print_ll_addrs(buf, ntohs(hdr->type), net_buf_frags_len(buf));
print_ll_addrs(pkt, ntohs(hdr->type), net_pkt_get_len(pkt));
if (!net_eth_is_addr_broadcast((struct net_eth_addr *)lladdr->addr) &&
!net_eth_is_addr_multicast((struct net_eth_addr *)lladdr->addr) &&
@ -131,48 +131,48 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
return NET_DROP;
}
net_pkt_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
net_buf_pull(buf->frags, net_pkt_ll_reserve(buf));
net_pkt_set_ll_reserve(pkt, sizeof(struct net_eth_hdr));
net_buf_pull(pkt->frags, net_pkt_ll_reserve(pkt));
#ifdef CONFIG_NET_ARP
if (family == AF_INET && hdr->type == htons(NET_ETH_PTYPE_ARP)) {
NET_DBG("ARP packet from %s received",
net_sprint_ll_addr((uint8_t *)hdr->src.addr,
sizeof(struct net_eth_addr)));
return net_arp_input(buf);
return net_arp_input(pkt);
}
#endif
ethernet_update_length(iface, buf);
ethernet_update_length(iface, pkt);
return NET_CONTINUE;
}
static inline bool check_if_dst_is_broadcast_or_mcast(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct net_eth_hdr *hdr = NET_ETH_BUF(buf);
struct net_eth_hdr *hdr = NET_ETH_BUF(pkt);
if (net_ipv4_addr_cmp(&NET_IPV4_BUF(buf)->dst,
if (net_ipv4_addr_cmp(&NET_IPV4_BUF(pkt)->dst,
net_ipv4_broadcast_address())) {
/* Broadcast address */
net_pkt_ll_dst(buf)->addr = (uint8_t *)broadcast_eth_addr.addr;
net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_src(buf)->addr = net_if_get_link_addr(iface)->addr;
net_pkt_ll_src(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_dst(pkt)->addr = (uint8_t *)broadcast_eth_addr.addr;
net_pkt_ll_dst(pkt)->len = sizeof(struct net_eth_addr);
net_pkt_ll_src(pkt)->addr = net_if_get_link_addr(iface)->addr;
net_pkt_ll_src(pkt)->len = sizeof(struct net_eth_addr);
return true;
} else if (NET_IPV4_BUF(buf)->dst.s4_addr[0] == 224) {
} else if (NET_IPV4_BUF(pkt)->dst.s4_addr[0] == 224) {
/* Multicast address */
hdr->dst.addr[0] = 0x01;
hdr->dst.addr[1] = 0x00;
hdr->dst.addr[2] = 0x5e;
hdr->dst.addr[3] = NET_IPV4_BUF(buf)->dst.s4_addr[1];
hdr->dst.addr[4] = NET_IPV4_BUF(buf)->dst.s4_addr[2];
hdr->dst.addr[5] = NET_IPV4_BUF(buf)->dst.s4_addr[3];
hdr->dst.addr[3] = NET_IPV4_BUF(pkt)->dst.s4_addr[1];
hdr->dst.addr[4] = NET_IPV4_BUF(pkt)->dst.s4_addr[2];
hdr->dst.addr[5] = NET_IPV4_BUF(pkt)->dst.s4_addr[3];
net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_src(buf)->addr = net_if_get_link_addr(iface)->addr;
net_pkt_ll_src(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_dst(pkt)->len = sizeof(struct net_eth_addr);
net_pkt_ll_src(pkt)->addr = net_if_get_link_addr(iface)->addr;
net_pkt_ll_src(pkt)->len = sizeof(struct net_eth_addr);
return true;
}
@ -181,34 +181,34 @@ static inline bool check_if_dst_is_broadcast_or_mcast(struct net_if *iface,
}
static enum net_verdict ethernet_send(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct net_eth_hdr *hdr = NET_ETH_BUF(buf);
struct net_eth_hdr *hdr = NET_ETH_BUF(pkt);
struct net_buf *frag;
uint16_t ptype;
#ifdef CONFIG_NET_ARP
if (net_pkt_family(buf) == AF_INET) {
struct net_buf *arp_buf;
if (net_pkt_family(pkt) == AF_INET) {
struct net_pkt *arp_pkt;
if (check_if_dst_is_broadcast_or_mcast(iface, buf)) {
if (check_if_dst_is_broadcast_or_mcast(iface, pkt)) {
goto setup_hdr;
}
arp_buf = net_arp_prepare(buf);
if (!arp_buf) {
arp_pkt = net_arp_prepare(pkt);
if (!arp_pkt) {
return NET_DROP;
}
NET_DBG("Sending arp buf %p (orig %p) to iface %p",
arp_buf, buf, iface);
NET_DBG("Sending arp pkt %p (orig %p) to iface %p",
arp_pkt, pkt, iface);
buf = arp_buf;
pkt = arp_pkt;
net_pkt_ll_src(buf)->addr = (uint8_t *)&NET_ETH_BUF(buf)->src;
net_pkt_ll_src(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_dst(buf)->addr = (uint8_t *)&NET_ETH_BUF(buf)->dst;
net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_src(pkt)->addr = (uint8_t *)&NET_ETH_BUF(pkt)->src;
net_pkt_ll_src(pkt)->len = sizeof(struct net_eth_addr);
net_pkt_ll_dst(pkt)->addr = (uint8_t *)&NET_ETH_BUF(pkt)->dst;
net_pkt_ll_dst(pkt)->len = sizeof(struct net_eth_addr);
/* For ARP message, we do not touch the packet further but will
* send it as it is because the arp.c has prepared the packet
@ -217,7 +217,7 @@ static enum net_verdict ethernet_send(struct net_if *iface,
goto send;
}
#else
NET_DBG("Sending buf %p to iface %p", buf, iface);
NET_DBG("Sending pkt %p to iface %p", pkt, iface);
#endif
/* If the src ll address is multicast or broadcast, then
@ -226,47 +226,47 @@ static enum net_verdict ethernet_send(struct net_if *iface,
* substitute the src address using the real ll address.
*/
if (net_eth_is_addr_broadcast((struct net_eth_addr *)
net_pkt_ll_src(buf)->addr) ||
net_pkt_ll_src(pkt)->addr) ||
net_eth_is_addr_multicast((struct net_eth_addr *)
net_pkt_ll_src(buf)->addr)) {
net_pkt_ll_src(buf)->addr = net_pkt_ll_if(buf)->addr;
net_pkt_ll_src(buf)->len = net_pkt_ll_if(buf)->len;
net_pkt_ll_src(pkt)->addr)) {
net_pkt_ll_src(pkt)->addr = net_pkt_ll_if(pkt)->addr;
net_pkt_ll_src(pkt)->len = net_pkt_ll_if(pkt)->len;
}
/* If the destination address is not set, then use broadcast
* or multicast address.
*/
if (!net_pkt_ll_dst(buf)->addr) {
if (!net_pkt_ll_dst(pkt)->addr) {
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6 &&
net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) {
struct net_eth_addr *dst = &NET_ETH_BUF(buf)->dst;
if (net_pkt_family(pkt) == AF_INET6 &&
net_is_ipv6_addr_mcast(&NET_IPV6_BUF(pkt)->dst)) {
struct net_eth_addr *dst = &NET_ETH_BUF(pkt)->dst;
memcpy(dst, (uint8_t *)multicast_eth_addr.addr,
sizeof(struct net_eth_addr) - 4);
memcpy((uint8_t *)dst + 2,
(uint8_t *)(&NET_IPV6_BUF(buf)->dst) + 12,
(uint8_t *)(&NET_IPV6_BUF(pkt)->dst) + 12,
sizeof(struct net_eth_addr) - 2);
net_pkt_ll_dst(buf)->addr = (uint8_t *)dst->addr;
net_pkt_ll_dst(pkt)->addr = (uint8_t *)dst->addr;
} else
#endif
{
net_pkt_ll_dst(buf)->addr =
net_pkt_ll_dst(pkt)->addr =
(uint8_t *)broadcast_eth_addr.addr;
}
net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr);
net_pkt_ll_dst(pkt)->len = sizeof(struct net_eth_addr);
NET_DBG("Destination address was not set, using %s",
net_sprint_ll_addr(net_pkt_ll_dst(buf)->addr,
net_pkt_ll_dst(buf)->len));
net_sprint_ll_addr(net_pkt_ll_dst(pkt)->addr,
net_pkt_ll_dst(pkt)->len));
}
setup_hdr:
__unused;
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
ptype = htons(NET_ETH_PTYPE_IP);
} else {
ptype = htons(NET_ETH_PTYPE_IPV6);
@ -274,7 +274,7 @@ setup_hdr:
/* Then go through the fragments and set the ethernet header.
*/
frag = buf->frags;
frag = pkt->frags;
NET_ASSERT_INFO(frag, "No data!");
@ -282,13 +282,13 @@ setup_hdr:
NET_ASSERT(net_buf_headroom(frag) > sizeof(struct net_eth_addr));
hdr = (struct net_eth_hdr *)(frag->data -
net_pkt_ll_reserve(buf));
memcpy(&hdr->dst, net_pkt_ll_dst(buf)->addr,
net_pkt_ll_reserve(pkt));
memcpy(&hdr->dst, net_pkt_ll_dst(pkt)->addr,
sizeof(struct net_eth_addr));
memcpy(&hdr->src, net_pkt_ll_src(buf)->addr,
memcpy(&hdr->src, net_pkt_ll_src(pkt)->addr,
sizeof(struct net_eth_addr));
hdr->type = ptype;
print_ll_addrs(buf, ntohs(hdr->type), frag->len);
print_ll_addrs(pkt, ntohs(hdr->type), frag->len);
frag = frag->frags;
}
@ -297,7 +297,7 @@ setup_hdr:
send:
#endif /* CONFIG_NET_ARP */
net_if_queue_tx(iface, buf);
net_if_queue_tx(iface, pkt);
return NET_OK;
}

View file

@ -63,14 +63,14 @@ static inline void hexdump(uint8_t *pkt, uint16_t length, uint8_t reserve)
}
}
static void pkt_hexdump(struct net_buf *buf, bool each_frag_reserve)
static void pkt_hexdump(struct net_pkt *pkt, bool each_frag_reserve)
{
uint16_t reserve = each_frag_reserve ? net_pkt_ll_reserve(buf) : 0;
uint16_t reserve = each_frag_reserve ? net_pkt_ll_reserve(pkt) : 0;
struct net_buf *frag;
printk("IEEE 802.15.4 packet content:\n");
frag = buf->frags;
frag = pkt->frags;
while (frag) {
hexdump(each_frag_reserve ?
frag->data - reserve : frag->data,
@ -87,31 +87,32 @@ static void pkt_hexdump(struct net_buf *buf, bool each_frag_reserve)
static inline void ieee802154_acknowledge(struct net_if *iface,
struct ieee802154_mpdu *mpdu)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
if (!mpdu->mhr.fs->fc.ar) {
return;
}
buf = net_pkt_get_reserve_tx(IEEE802154_ACK_PKT_LENGTH, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_reserve_tx(IEEE802154_ACK_PKT_LENGTH, K_FOREVER);
if (!pkt) {
return;
}
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
net_buf_frag_insert(buf, frag);
net_pkt_frag_insert(pkt, frag);
if (ieee802154_create_ack_frame(iface, buf, mpdu->mhr.fs->sequence)) {
if (ieee802154_create_ack_frame(iface, pkt, mpdu->mhr.fs->sequence)) {
const struct ieee802154_radio_api *radio =
iface->dev->driver_api;
net_buf_add(frag, IEEE802154_ACK_PKT_LENGTH);
radio->tx(iface->dev, buf, frag);
radio->tx(iface->dev, pkt, frag);
}
net_pkt_unref(buf);
net_pkt_unref(pkt);
return;
}
@ -119,7 +120,7 @@ static inline void ieee802154_acknowledge(struct net_if *iface,
#define ieee802154_acknowledge(...)
#endif /* CONFIG_NET_L2_IEEE802154_ACK_REPLY */
static inline void set_buf_ll_addr(struct net_linkaddr *addr, bool comp,
static inline void set_pkt_ll_addr(struct net_linkaddr *addr, bool comp,
enum ieee802154_addressing_mode mode,
struct ieee802154_address_field *ll)
{
@ -146,8 +147,8 @@ static inline void set_buf_ll_addr(struct net_linkaddr *addr, bool comp,
#ifdef CONFIG_NET_6LO
static inline
enum net_verdict ieee802154_manage_recv_buffer(struct net_if *iface,
struct net_buf *buf)
enum net_verdict ieee802154_manage_recv_packet(struct net_if *iface,
struct net_pkt *pkt)
{
enum net_verdict verdict = NET_CONTINUE;
uint32_t src;
@ -156,78 +157,78 @@ enum net_verdict ieee802154_manage_recv_buffer(struct net_if *iface,
/* Upper IP stack expects the link layer address to be in
* big endian format so we must swap it here.
*/
if (net_pkt_ll_src(buf)->addr &&
net_pkt_ll_src(buf)->len == IEEE802154_EXT_ADDR_LENGTH) {
sys_mem_swap(net_pkt_ll_src(buf)->addr,
net_pkt_ll_src(buf)->len);
if (net_pkt_ll_src(pkt)->addr &&
net_pkt_ll_src(pkt)->len == IEEE802154_EXT_ADDR_LENGTH) {
sys_mem_swap(net_pkt_ll_src(pkt)->addr,
net_pkt_ll_src(pkt)->len);
}
if (net_pkt_ll_dst(buf)->addr &&
net_pkt_ll_dst(buf)->len == IEEE802154_EXT_ADDR_LENGTH) {
sys_mem_swap(net_pkt_ll_dst(buf)->addr,
net_pkt_ll_dst(buf)->len);
if (net_pkt_ll_dst(pkt)->addr &&
net_pkt_ll_dst(pkt)->len == IEEE802154_EXT_ADDR_LENGTH) {
sys_mem_swap(net_pkt_ll_dst(pkt)->addr,
net_pkt_ll_dst(pkt)->len);
}
/** Uncompress will drop the current fragment. Buf ll src/dst address
/** Uncompress will drop the current fragment. Pkt ll src/dst address
* will then be wrong and must be updated according to the new fragment.
*/
src = net_pkt_ll_src(buf)->addr ?
net_pkt_ll_src(buf)->addr - net_pkt_ll(buf) : 0;
dst = net_pkt_ll_dst(buf)->addr ?
net_pkt_ll_dst(buf)->addr - net_pkt_ll(buf) : 0;
src = net_pkt_ll_src(pkt)->addr ?
net_pkt_ll_src(pkt)->addr - net_pkt_ll(pkt) : 0;
dst = net_pkt_ll_dst(pkt)->addr ?
net_pkt_ll_dst(pkt)->addr - net_pkt_ll(pkt) : 0;
#ifdef CONFIG_NET_L2_IEEE802154_FRAGMENT
verdict = ieee802154_reassemble(buf);
verdict = ieee802154_reassemble(pkt);
if (verdict == NET_DROP) {
goto out;
}
#else
if (!net_6lo_uncompress(buf)) {
if (!net_6lo_uncompress(pkt)) {
NET_DBG("Packet decompression failed");
verdict = NET_DROP;
goto out;
}
#endif
net_pkt_ll_src(buf)->addr = src ? net_pkt_ll(buf) + src : NULL;
net_pkt_ll_dst(buf)->addr = dst ? net_pkt_ll(buf) + dst : NULL;
net_pkt_ll_src(pkt)->addr = src ? net_pkt_ll(pkt) + src : NULL;
net_pkt_ll_dst(pkt)->addr = dst ? net_pkt_ll(pkt) + dst : NULL;
pkt_hexdump(buf, false);
pkt_hexdump(pkt, false);
out:
return verdict;
}
static inline bool ieee802154_manage_send_buffer(struct net_if *iface,
struct net_buf *buf)
static inline bool ieee802154_manage_send_packet(struct net_if *iface,
struct net_pkt *pkt)
{
bool ret;
pkt_hexdump(buf, false);
pkt_hexdump(pkt, false);
#ifdef CONFIG_NET_L2_IEEE802154_FRAGMENT
ret = net_6lo_compress(buf, true, ieee802154_fragment);
ret = net_6lo_compress(pkt, true, ieee802154_fragment);
#else
ret = net_6lo_compress(buf, true, NULL);
ret = net_6lo_compress(pkt, true, NULL);
#endif
pkt_hexdump(buf, false);
pkt_hexdump(pkt, false);
return ret;
}
#else /* CONFIG_NET_6LO */
#define ieee802154_manage_recv_buffer(...) NET_CONTINUE
#define ieee802154_manage_send_buffer(...) true
#define ieee802154_manage_recv_packet(...) NET_CONTINUE
#define ieee802154_manage_send_packet(...) true
#endif /* CONFIG_NET_6LO */
static enum net_verdict ieee802154_recv(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct ieee802154_mpdu mpdu;
if (!ieee802154_validate_frame(net_pkt_ll(buf),
net_buf_frags_len(buf), &mpdu)) {
if (!ieee802154_validate_frame(net_pkt_ll(pkt),
net_pkt_get_len(pkt), &mpdu)) {
return NET_DROP;
}
@ -247,40 +248,40 @@ static enum net_verdict ieee802154_recv(struct net_if *iface,
ieee802154_acknowledge(iface, &mpdu);
net_pkt_set_ll_reserve(buf, mpdu.payload - (void *)net_pkt_ll(buf));
net_buf_pull(buf->frags, net_pkt_ll_reserve(buf));
net_pkt_set_ll_reserve(pkt, mpdu.payload - (void *)net_pkt_ll(pkt));
net_buf_pull(pkt->frags, net_pkt_ll_reserve(pkt));
set_buf_ll_addr(net_pkt_ll_src(buf), mpdu.mhr.fs->fc.pan_id_comp,
set_pkt_ll_addr(net_pkt_ll_src(pkt), mpdu.mhr.fs->fc.pan_id_comp,
mpdu.mhr.fs->fc.src_addr_mode, mpdu.mhr.src_addr);
set_buf_ll_addr(net_pkt_ll_dst(buf), false,
set_pkt_ll_addr(net_pkt_ll_dst(pkt), false,
mpdu.mhr.fs->fc.dst_addr_mode, mpdu.mhr.dst_addr);
if (!ieee802154_decipher_data_frame(iface, buf, &mpdu)) {
if (!ieee802154_decipher_data_frame(iface, pkt, &mpdu)) {
return NET_DROP;
}
pkt_hexdump(buf, true);
pkt_hexdump(pkt, true);
return ieee802154_manage_recv_buffer(iface, buf);
return ieee802154_manage_recv_packet(iface, pkt);
}
static enum net_verdict ieee802154_send(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct ieee802154_context *ctx = net_if_l2_data(iface);
uint8_t reserved_space = net_pkt_ll_reserve(buf);
uint8_t reserved_space = net_pkt_ll_reserve(pkt);
struct net_buf *frag;
if (net_pkt_family(buf) != AF_INET6) {
if (net_pkt_family(pkt) != AF_INET6) {
return NET_DROP;
}
if (!ieee802154_manage_send_buffer(iface, buf)) {
if (!ieee802154_manage_send_packet(iface, pkt)) {
return NET_DROP;
}
frag = buf->frags;
frag = pkt->frags;
while (frag) {
if (frag->len > IEEE802154_MTU) {
NET_ERR("Frag %p as too big length %u",
@ -288,7 +289,7 @@ static enum net_verdict ieee802154_send(struct net_if *iface,
return NET_DROP;
}
if (!ieee802154_create_data_frame(ctx, net_pkt_ll_dst(buf),
if (!ieee802154_create_data_frame(ctx, net_pkt_ll_dst(pkt),
frag, reserved_space)) {
return NET_DROP;
}
@ -296,9 +297,9 @@ static enum net_verdict ieee802154_send(struct net_if *iface,
frag = frag->frags;
}
pkt_hexdump(buf, true);
pkt_hexdump(pkt, true);
net_if_queue_tx(iface, buf);
net_if_queue_tx(iface, pkt);
return NET_OK;
}

View file

@ -37,7 +37,7 @@ static uint16_t datagram_tag;
*/
struct frag_cache {
struct k_delayed_work timer; /* Reassemble timer */
struct net_buf *buf; /* Reassemble buffer */
struct net_pkt *pkt; /* Reassemble packet */
uint16_t size; /* Datagram size */
uint16_t tag; /* Datagram tag */
bool used;
@ -78,12 +78,12 @@ static struct frag_cache cache[REASS_CACHE_SIZE];
* +-+-+-+-+-+-+-+-+
*/
static inline struct net_buf *prepare_new_fragment(struct net_buf *buf,
static inline struct net_buf *prepare_new_fragment(struct net_pkt *pkt,
uint8_t offset)
{
struct net_buf *frag;
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
if (!frag) {
return NULL;
}
@ -95,7 +95,7 @@ static inline struct net_buf *prepare_new_fragment(struct net_buf *buf,
net_buf_add(frag, NET_6LO_FRAGN_HDR_LEN);
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
return frag;
}
@ -134,13 +134,13 @@ static inline void set_up_frag_hdr(struct net_buf *frag, uint16_t size,
}
}
static inline uint8_t calc_max_payload(struct net_buf *buf,
static inline uint8_t calc_max_payload(struct net_pkt *pkt,
struct net_buf *frag,
uint8_t offset)
{
uint8_t max;
max = frag->size - net_pkt_ll_reserve(buf);
max = frag->size - net_pkt_ll_reserve(pkt);
max -= offset ? NET_6LO_FRAGN_HDR_LEN : NET_6LO_FRAG1_HDR_LEN;
return (max & 0xF8);
@ -213,15 +213,15 @@ static inline void compact_frag(struct net_buf *frag, uint8_t moved)
* |fh + p + e | fh + p + e | fh + p + e | fh + p + e | fh + p + e |
*
* Space in every fragment is because fragment payload should be multiple
* of 8 octets (we have predefined buffers at compile time, data buffer mtu
* of 8 octets (we have predefined packets at compile time, data packet mtu
* is set already).
*
* Create the first fragment, add fragmentation header and insert
* fragment at beginning of buf, move data from next fragments to
* fragment at beginning of pkt, move data from next fragments to
* previous one, from here on insert fragmentation header and adjust
* data on subsequent buffers.
* data on subsequent packets.
*/
bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
bool ieee802154_fragment(struct net_pkt *pkt, int hdr_diff)
{
struct net_buf *frag;
struct net_buf *next;
@ -233,17 +233,17 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
uint8_t max;
bool first;
if (!buf || !buf->frags) {
if (!pkt || !pkt->frags) {
return false;
}
/* If it is a single fragment do not add fragmentation header */
if (!buf->frags->frags) {
if (!pkt->frags->frags) {
return true;
}
/* Datagram_size: total length before compression */
size = net_buf_frags_len(buf) + hdr_diff;
size = net_pkt_get_len(pkt) + hdr_diff;
room = 0;
offset = 0;
@ -251,8 +251,8 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
first = true;
datagram_tag++;
next = buf->frags;
buf->frags = NULL;
next = pkt->frags;
pkt->frags = NULL;
/* First fragment has compressed header, but SIZE and OFFSET
* values in fragmentation header are based on uncompressed
@ -261,7 +261,7 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
while (1) {
if (!room) {
/* Prepare new fragment based on offset */
frag = prepare_new_fragment(buf, offset);
frag = prepare_new_fragment(pkt, offset);
if (!frag) {
return false;
}
@ -270,7 +270,7 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
set_up_frag_hdr(frag, size, offset);
/* Calculate max payload in multiples of 8 bytes */
max = calc_max_payload(buf, frag, offset);
max = calc_max_payload(pkt, frag, offset);
/* Calculate how much data is processed */
processed += max;
@ -286,7 +286,7 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
compact_frag(next, move);
if (!next->len) {
next = net_pkt_frag_del(NULL, next);
next = net_pkt_frag_del(pkt, NULL, next);
if (!next) {
break;
}
@ -312,15 +312,15 @@ static inline void remove_frag_header(struct net_buf *frag, uint8_t hdr_len)
frag->len -= hdr_len;
}
static void update_protocol_header_lengths(struct net_buf *buf, uint16_t size)
static void update_protocol_header_lengths(struct net_pkt *pkt, uint16_t size)
{
net_pkt_set_ip_hdr_len(buf, NET_IPV6H_LEN);
net_pkt_set_ip_hdr_len(pkt, NET_IPV6H_LEN);
NET_IPV6_BUF(buf)->len[0] = (size - NET_IPV6H_LEN) >> 8;
NET_IPV6_BUF(buf)->len[1] = (uint8_t) (size - NET_IPV6H_LEN);
NET_IPV6_BUF(pkt)->len[0] = (size - NET_IPV6H_LEN) >> 8;
NET_IPV6_BUF(pkt)->len[1] = (uint8_t) (size - NET_IPV6H_LEN);
if (NET_IPV6_BUF(buf)->nexthdr == IPPROTO_UDP) {
NET_UDP_BUF(buf)->len = htons(size - NET_IPV6H_LEN);
if (NET_IPV6_BUF(pkt)->nexthdr == IPPROTO_UDP) {
NET_UDP_BUF(pkt)->len = htons(size - NET_IPV6H_LEN);
}
}
@ -333,11 +333,11 @@ static inline void clear_reass_cache(uint16_t size, uint16_t tag)
continue;
}
if (cache[i].buf) {
net_pkt_unref(cache[i].buf);
if (cache[i].pkt) {
net_pkt_unref(cache[i].pkt);
}
cache[i].buf = NULL;
cache[i].pkt = NULL;
cache[i].size = 0;
cache[i].tag = 0;
cache[i].used = false;
@ -353,11 +353,11 @@ static void reass_timeout(struct k_work *work)
{
struct frag_cache *cache = CONTAINER_OF(work, struct frag_cache, timer);
if (cache->buf) {
net_pkt_unref(cache->buf);
if (cache->pkt) {
net_pkt_unref(cache->pkt);
}
cache->buf = NULL;
cache->pkt = NULL;
cache->size = 0;
cache->tag = 0;
cache->used = false;
@ -368,7 +368,7 @@ static void reass_timeout(struct k_work *work)
* create a new cache. If number of unused cache are out then
* discard the fragments.
*/
static inline struct frag_cache *set_reass_cache(struct net_buf *buf,
static inline struct frag_cache *set_reass_cache(struct net_pkt *pkt,
uint16_t size, uint16_t tag)
{
int i;
@ -378,7 +378,7 @@ static inline struct frag_cache *set_reass_cache(struct net_buf *buf,
continue;
}
cache[i].buf = buf;
cache[i].pkt = pkt;
cache[i].size = size;
cache[i].tag = tag;
cache[i].used = true;
@ -411,8 +411,8 @@ static inline struct frag_cache *get_reass_cache(uint16_t size, uint16_t tag)
return NULL;
}
/* Helper function to write fragment data to Rx buffer based on offset. */
static inline bool copy_frag(struct net_buf *buf,
/* Helper function to write fragment data to Rx packet based on offset. */
static inline bool copy_frag(struct net_pkt *pkt,
struct net_buf *frag,
uint16_t offset)
{
@ -420,17 +420,17 @@ static inline bool copy_frag(struct net_buf *buf,
struct net_buf *write;
uint16_t pos = offset;
write = buf->frags;
write = pkt->frags;
while (input) {
write = net_pkt_write(buf, write, pos, &pos, input->len,
write = net_pkt_write(pkt, write, pos, &pos, input->len,
input->data, NET_6LO_RX_PKT_TIMEOUT);
if (!write && pos == 0xffff) {
/* Free the new bufs we tried to get, we need to discard
* the whole fragment chain.
*/
net_pkt_unref(buf->frags);
buf->frags = NULL;
net_pkt_frag_unref(pkt->frags);
pkt->frags = NULL;
return false;
}
@ -438,7 +438,7 @@ static inline bool copy_frag(struct net_buf *buf,
input = input->frags;
}
net_pkt_unref(frag);
net_pkt_frag_unref(frag);
return true;
}
@ -449,9 +449,9 @@ static inline bool copy_frag(struct net_buf *buf,
* Remove the fragmentation header and uncompress IPv6 and related headers.
* Cache Rx part of fragment along with data buf for the first fragment
* in the cache, remaining fragments just cache data fragment, unref
* RX buf. So in both the cases caller can assume buffer is consumed.
* RX pkt. So in both the cases caller can assume packet is consumed.
*/
static inline enum net_verdict add_frag_to_cache(struct net_buf *buf,
static inline enum net_verdict add_frag_to_cache(struct net_pkt *pkt,
bool first)
{
struct frag_cache *cache;
@ -462,23 +462,23 @@ static inline enum net_verdict add_frag_to_cache(struct net_buf *buf,
uint8_t pos = 0;
/* Parse total size of packet */
size = get_datagram_size(buf->frags->data);
size = get_datagram_size(pkt->frags->data);
pos += NET_6LO_FRAG_DATAGRAM_SIZE_LEN;
/* Parse the datagram tag */
tag = get_datagram_tag(buf->frags->data + pos);
tag = get_datagram_tag(pkt->frags->data + pos);
pos += NET_6LO_FRAG_DATAGRAM_OFFSET_LEN;
if (!first) {
offset = ((uint16_t)buf->frags->data[pos]) << 3;
offset = ((uint16_t)pkt->frags->data[pos]) << 3;
pos++;
}
/* Remove frag header and update data */
remove_frag_header(buf->frags, pos);
remove_frag_header(pkt->frags, pos);
/* Uncompress the IP headers */
if (first && !net_6lo_uncompress(buf)) {
if (first && !net_6lo_uncompress(pkt)) {
NET_ERR("Could not uncompress first frag's 6lo hdr");
clear_reass_cache(size, tag);
@ -486,33 +486,33 @@ static inline enum net_verdict add_frag_to_cache(struct net_buf *buf,
}
/* If there are no fragments in the cache means this frag
* is the first one. So cache Rx buf otherwise not.
* is the first one. So cache Rx pkt otherwise not.
* Write data fragment data to cached Rx based on offset parameter.
* (Detach data fragment from incoming Rx and copy that data).
*/
frag = buf->frags;
buf->frags = NULL;
frag = pkt->frags;
pkt->frags = NULL;
cache = get_reass_cache(size, tag);
if (!cache) {
cache = set_reass_cache(buf, size, tag);
cache = set_reass_cache(pkt, size, tag);
if (!cache) {
NET_ERR("Could not get a cache entry");
buf->frags = frag;
pkt->frags = frag;
return NET_DROP;
}
/* If write failed, then attach frag back to incoming buffer
/* If write failed, then attach frag back to incoming packet
* and return NET_DROP, caller will take care of freeing it.
*/
if (!copy_frag(cache->buf, frag, offset)) {
buf->frags = frag;
if (!copy_frag(cache->pkt, frag, offset)) {
pkt->frags = frag;
/* Initialize to NULL to prevent duble free. It's only
* needed here because this is the first fragment.
*/
cache->buf = NULL;
cache->pkt = NULL;
clear_reass_cache(size, tag);
@ -521,14 +521,14 @@ static inline enum net_verdict add_frag_to_cache(struct net_buf *buf,
return NET_DROP;
}
NET_DBG("buffer inserted into cache");
NET_DBG("packet inserted into cache");
return NET_OK;
}
/* Add data buffer to reassembly buffer */
if (!copy_frag(cache->buf, frag, offset)) {
buf->frags = frag;
/* Add data packet to reassembly packet */
if (!copy_frag(cache->pkt, frag, offset)) {
pkt->frags = frag;
clear_reass_cache(size, tag);
@ -536,13 +536,13 @@ static inline enum net_verdict add_frag_to_cache(struct net_buf *buf,
}
/* Check if all the fragments are received or not */
if (net_buf_frags_len(cache->buf->frags) == size) {
/* Assign frags back to input buffer. */
buf->frags = cache->buf->frags;
cache->buf->frags = NULL;
if (net_pkt_get_len(cache->pkt) == size) {
/* Assign frags back to input packet. */
pkt->frags = cache->pkt->frags;
cache->pkt->frags = NULL;
/* Lengths are elided in compression, so calculate it. */
update_protocol_header_lengths(buf, cache->size);
update_protocol_header_lengths(pkt, cache->size);
/* Once reassemble is done, cache is no longer needed. */
clear_reass_cache(size, tag);
@ -552,30 +552,30 @@ static inline enum net_verdict add_frag_to_cache(struct net_buf *buf,
return NET_CONTINUE;
}
/* Unref Rx part of original buffer */
net_pkt_unref(buf);
/* Unref Rx part of original packet */
net_pkt_unref(pkt);
return NET_OK;
}
enum net_verdict ieee802154_reassemble(struct net_buf *buf)
enum net_verdict ieee802154_reassemble(struct net_pkt *pkt)
{
if (!buf || !buf->frags) {
if (!pkt || !pkt->frags) {
NET_ERR("Nothing to reassemble");
return NET_DROP;
}
switch (buf->frags->data[0] & 0xF0) {
switch (pkt->frags->data[0] & 0xF0) {
case NET_6LO_DISPATCH_FRAG1:
/* First fragment with IP headers */
return add_frag_to_cache(buf, true);
return add_frag_to_cache(pkt, true);
case NET_6LO_DISPATCH_FRAGN:
/* Further fragments */
return add_frag_to_cache(buf, false);
return add_frag_to_cache(pkt, false);
default:
NET_DBG("No frag dispatch (%02x)", buf->frags->data[0]);
NET_DBG("No frag dispatch (%02x)", pkt->frags->data[0]);
/* Received unfragmented packet, uncompress */
if (net_6lo_uncompress(buf)) {
if (net_6lo_uncompress(pkt)) {
return NET_CONTINUE;
}

View file

@ -25,12 +25,12 @@
* needs to be fragmented. Every fragment will have fragmentation header
* data size, data offset, data tag and payload.
*
* @param Pointer to network buffer
* @param Pointer to network packet
* @param Header difference between original IPv6 header and compressed header
*
* @return True in case of success, false otherwise
*/
bool ieee802154_fragment(struct net_buf *buf, int hdr_diff);
bool ieee802154_fragment(struct net_pkt *pkt, int hdr_diff);
/**
* @brief Reassemble 802.15.4 fragments as per RFC 6282
@ -43,11 +43,11 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff);
* @param Pointer to network fragment, which gets updated to full reassembled
* packet when verdict is NET_CONTINUE
*
* @return NET_CONTINUE reassembly done, buf is complete
* @return NET_CONTINUE reassembly done, pkt is complete
* NET_OK waiting for other fragments,
* NET_DROP invalid fragment.
*/
enum net_verdict ieee802154_reassemble(struct net_buf *buf);
enum net_verdict ieee802154_reassemble(struct net_pkt *pkt);
#endif /* __NET_IEEE802154_FRAGMENT_H__ */

View file

@ -472,7 +472,7 @@ uint16_t ieee802154_compute_header_size(struct net_if *iface,
hdr_len += IEEE8021254_KEY_ID_FIELD_SRC_8_INDEX_LENGTH;
}
/* This is a _HACK_: as net buf do not let the possibility to
/* This is a _HACK_: as net pkt do not let the possibility to
* reserve tailroom - here for authentication tag - it reserves
* it in headroom so the payload won't occupy all the left space
* and then when it will come to finalize the data frame it will
@ -808,27 +808,28 @@ static inline uint8_t mac_command_length(enum ieee802154_cfi cfi)
return reserve;
}
struct net_buf *
struct net_pkt *
ieee802154_create_mac_cmd_frame(struct ieee802154_context *ctx,
enum ieee802154_cfi type,
struct ieee802154_frame_params *params)
{
struct ieee802154_fcf_seq *fs;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint8_t *p_buf;
buf = net_pkt_get_reserve_tx(0, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_reserve_tx(0, K_FOREVER);
if (!pkt) {
return NULL;
}
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
if (!frag) {
goto error;
}
net_buf_frag_add(buf, frag);
p_buf = net_pkt_ll(buf);
net_pkt_frag_add(pkt, frag);
p_buf = net_pkt_ll(pkt);
fs = generate_fcf_grounds(&p_buf,
type == IEEE802154_CFI_BEACON_REQUEST ?
@ -851,20 +852,20 @@ ieee802154_create_mac_cmd_frame(struct ieee802154_context *ctx,
* to be easy to handle afterwards to point directly to MAC
* command space, in order to fill-in its content.
*/
net_pkt_set_ll_reserve(buf, p_buf - net_pkt_ll(buf));
net_buf_pull(frag, net_pkt_ll_reserve(buf));
net_pkt_set_ll_reserve(pkt, p_buf - net_pkt_ll(pkt));
net_buf_pull(frag, net_pkt_ll_reserve(pkt));
/* Thus setting the right MAC command length
* Now up to the caller to fill-in this space relevantly.
* See ieee802154_mac_command() helper.
*/
net_pkt_set_len(frag, mac_command_length(type));
frag->len = mac_command_length(type);
dbg_print_fs(fs);
return buf;
return pkt;
error:
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NULL;
}
@ -872,9 +873,9 @@ error:
#ifdef CONFIG_NET_L2_IEEE802154_ACK_REPLY
bool ieee802154_create_ack_frame(struct net_if *iface,
struct net_buf *buf, uint8_t seq)
struct net_pkt *pkt, uint8_t seq)
{
uint8_t *p_buf = net_pkt_ll(buf);
uint8_t *p_buf = net_pkt_ll(pkt);
struct ieee802154_fcf_seq *fs;
if (!p_buf) {
@ -894,7 +895,7 @@ bool ieee802154_create_ack_frame(struct net_if *iface,
#endif /* CONFIG_NET_L2_IEEE802154_ACK_REPLY */
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_buf *buf,
bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
struct ieee802154_mpdu *mpdu)
{
struct ieee802154_context *ctx = net_if_l2_data(iface);
@ -916,10 +917,10 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_buf *buf,
* This will require to look up in nbr cache with short addr
* in order to get the extended address related to it
*/
if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_pkt_ll(buf),
net_pkt_ll_reserve(buf),
net_buf_frags_len(buf),
net_pkt_ll_src(buf)->addr,
if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_pkt_ll(pkt),
net_pkt_ll_reserve(pkt),
net_pkt_get_len(pkt),
net_pkt_ll_src(pkt)->addr,
sys_le32_to_cpu(
mpdu->mhr.aux_sec->frame_counter))) {
NET_ERR("Could not decipher the frame");
@ -932,7 +933,7 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_buf *buf,
}
/* We remove tag size from frag's length, it is now useless */
buf->frags->len -= level_2_tag_size[level];
pkt->frags->len -= level_2_tag_size[level];
return true;
}

View file

@ -464,32 +464,32 @@ bool ieee802154_create_data_frame(struct ieee802154_context *ctx,
struct net_buf *frag,
uint8_t reserved_len);
struct net_buf *
struct net_pkt *
ieee802154_create_mac_cmd_frame(struct ieee802154_context *ctx,
enum ieee802154_cfi type,
struct ieee802154_frame_params *params);
static inline
struct ieee802154_command *ieee802154_get_mac_command(struct net_buf *buf)
struct ieee802154_command *ieee802154_get_mac_command(struct net_pkt *pkt)
{
return (struct ieee802154_command *)net_pkt_ip_data(buf);
return (struct ieee802154_command *)net_pkt_ip_data(pkt);
}
#ifdef CONFIG_NET_L2_IEEE802154_ACK_REPLY
bool ieee802154_create_ack_frame(struct net_if *iface,
struct net_buf *buf, uint8_t seq);
struct net_pkt *pkt, uint8_t seq);
#endif
static inline bool ieee802154_ack_required(struct net_buf *buf)
static inline bool ieee802154_ack_required(struct net_pkt *pkt)
{
struct ieee802154_fcf_seq *fs =
(struct ieee802154_fcf_seq *)net_pkt_ll(buf);
(struct ieee802154_fcf_seq *)net_pkt_ll(pkt);
return fs->fc.ar;
}
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_buf *buf,
bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
struct ieee802154_mpdu *mpdu);
#else
#define ieee802154_decipher_data_frame(...) true

View file

@ -87,7 +87,7 @@ static int ieee802154_scan(uint32_t mgmt_request, struct net_if *iface,
struct ieee802154_context *ctx = net_if_l2_data(iface);
struct ieee802154_req_params *scan =
(struct ieee802154_req_params *)data;
struct net_buf *buf = NULL;
struct net_pkt *pkt = NULL;
uint8_t channel;
int ret;
@ -105,9 +105,9 @@ static int ieee802154_scan(uint32_t mgmt_request, struct net_if *iface,
params.dst.short_addr = IEEE802154_BROADCAST_ADDRESS;
params.dst.pan_id = IEEE802154_BROADCAST_PAN_ID;
buf = ieee802154_create_mac_cmd_frame(
pkt = ieee802154_create_mac_cmd_frame(
ctx, IEEE802154_CFI_BEACON_REQUEST, &params);
if (!buf) {
if (!pkt) {
NET_DBG("Could not create Beacon Request");
return -ENOBUFS;
}
@ -138,14 +138,14 @@ static int ieee802154_scan(uint32_t mgmt_request, struct net_if *iface,
/* Active scan sends a beacon request */
if (mgmt_request == NET_REQUEST_IEEE802154_ACTIVE_SCAN) {
net_pkt_ref(buf);
net_pkt_ref(buf->frags);
net_pkt_ref(pkt);
net_pkt_frag_ref(pkt->frags);
ret = ieee802154_radio_send(iface, buf);
ret = ieee802154_radio_send(iface, pkt);
if (ret) {
NET_DBG("Could not send Beacon Request (%d)",
ret);
net_pkt_unref(buf);
net_pkt_unref(pkt);
break;
}
@ -168,8 +168,8 @@ static int ieee802154_scan(uint32_t mgmt_request, struct net_if *iface,
out:
ctx->scan_ctx = NULL;
if (buf) {
net_pkt_unref(buf);
if (pkt) {
net_pkt_unref(pkt);
}
return ret;
@ -229,7 +229,7 @@ static int ieee802154_associate(uint32_t mgmt_request, struct net_if *iface,
(struct ieee802154_req_params *)data;
struct ieee802154_frame_params params;
struct ieee802154_command *cmd;
struct net_buf *buf;
struct net_pkt *pkt;
int ret = 0;
k_sem_take(&ctx->req_lock, K_FOREVER);
@ -250,14 +250,14 @@ static int ieee802154_associate(uint32_t mgmt_request, struct net_if *iface,
goto out;
}
buf = ieee802154_create_mac_cmd_frame(
pkt = ieee802154_create_mac_cmd_frame(
ctx, IEEE802154_CFI_ASSOCIATION_REQUEST, &params);
if (!buf) {
if (!pkt) {
ret = -ENOBUFS;
goto out;
}
cmd = ieee802154_get_mac_command(buf);
cmd = ieee802154_get_mac_command(pkt);
cmd->assoc_req.ci.dev_type = 0; /* RFD */
cmd->assoc_req.ci.power_src = 0; /* ToDo: set right power source */
cmd->assoc_req.ci.rx_on = 1; /* ToDo: that will depends on PM */
@ -266,8 +266,8 @@ static int ieee802154_associate(uint32_t mgmt_request, struct net_if *iface,
ctx->associated = false;
if (net_if_send_data(iface, buf)) {
net_pkt_unref(buf);
if (net_if_send_data(iface, pkt)) {
net_pkt_unref(pkt);
ret = -EIO;
goto out;
}
@ -305,7 +305,7 @@ static int ieee802154_disassociate(uint32_t mgmt_request, struct net_if *iface,
struct ieee802154_context *ctx = net_if_l2_data(iface);
struct ieee802154_frame_params params;
struct ieee802154_command *cmd;
struct net_buf *buf;
struct net_pkt *pkt;
if (!ctx->associated) {
return -EALREADY;
@ -321,17 +321,17 @@ static int ieee802154_disassociate(uint32_t mgmt_request, struct net_if *iface,
params.pan_id = ctx->pan_id;
buf = ieee802154_create_mac_cmd_frame(
pkt = ieee802154_create_mac_cmd_frame(
ctx, IEEE802154_CFI_DISASSOCIATION_NOTIFICATION, &params);
if (!buf) {
if (!pkt) {
return -ENOBUFS;
}
cmd = ieee802154_get_mac_command(buf);
cmd = ieee802154_get_mac_command(pkt);
cmd->disassoc_note.reason = IEEE802154_DRF_DEVICE_WISH;
if (net_if_send_data(iface, buf)) {
net_pkt_unref(buf);
if (net_if_send_data(iface, pkt)) {
net_pkt_unref(pkt);
return -EIO;
}

View file

@ -20,12 +20,12 @@
#include "ieee802154_radio_utils.h"
static inline int aloha_tx_fragment(struct net_if *iface,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
uint8_t retries = CONFIG_NET_L2_IEEE802154_RADIO_TX_RETRIES;
struct ieee802154_context *ctx = net_if_l2_data(iface);
bool ack_required = prepare_for_ack(ctx, buf);
bool ack_required = prepare_for_ack(ctx, pkt);
const struct ieee802154_radio_api *radio = iface->dev->driver_api;
int ret = -EIO;
@ -34,7 +34,7 @@ static inline int aloha_tx_fragment(struct net_if *iface,
while (retries) {
retries--;
ret = radio->tx(iface->dev, buf, frag);
ret = radio->tx(iface->dev, pkt, frag);
if (ret) {
continue;
}
@ -48,19 +48,19 @@ static inline int aloha_tx_fragment(struct net_if *iface,
return ret;
}
static int aloha_radio_send(struct net_if *iface, struct net_buf *buf)
static int aloha_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
NET_DBG("buf %p (frags %p)", buf, buf->frags);
NET_DBG("pkt %p (frags %p)", pkt, pkt->frags);
return tx_buffer_fragments(iface, buf, aloha_tx_fragment);
return tx_packet_fragments(iface, pkt, aloha_tx_fragment);
}
static enum net_verdict aloha_radio_handle_ack(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct ieee802154_context *ctx = net_if_l2_data(iface);
return handle_ack(ctx, buf);
return handle_ack(ctx, pkt);
}
/* Declare the public Radio driver function used by the HW drivers */

View file

@ -23,7 +23,7 @@
#include "ieee802154_radio_utils.h"
static inline int csma_ca_tx_fragment(struct net_if *iface,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag)
{
const uint8_t max_bo = CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA_MAX_BO;
@ -31,7 +31,7 @@ static inline int csma_ca_tx_fragment(struct net_if *iface,
uint8_t retries = CONFIG_NET_L2_IEEE802154_RADIO_TX_RETRIES;
struct ieee802154_context *ctx = net_if_l2_data(iface);
const struct ieee802154_radio_api *radio = iface->dev->driver_api;
bool ack_required = prepare_for_ack(ctx, buf);
bool ack_required = prepare_for_ack(ctx, pkt);
uint8_t be = CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA_MIN_BE;
uint8_t nb = 0;
int ret = -EIO;
@ -61,7 +61,7 @@ loop:
}
}
ret = radio->tx(iface->dev, buf, frag);
ret = radio->tx(iface->dev, pkt, frag);
if (ret) {
continue;
}
@ -75,19 +75,19 @@ loop:
return ret;
}
static int csma_ca_radio_send(struct net_if *iface, struct net_buf *buf)
static int csma_ca_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
NET_DBG("buf %p (frags %p)", buf, buf->frags);
NET_DBG("pkt %p (frags %p)", pkt, pkt->frags);
return tx_buffer_fragments(iface, buf, csma_ca_tx_fragment);
return tx_packet_fragments(iface, pkt, csma_ca_tx_fragment);
}
static enum net_verdict csma_ca_radio_handle_ack(struct net_if *iface,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct ieee802154_context *ctx = net_if_l2_data(iface);
return handle_ack(ctx, buf);
return handle_ack(ctx, pkt);
}
/* Declare the public Radio driver function used by the HW drivers */

View file

@ -8,13 +8,13 @@
#define __IEEE802154_RADIO_UTILS_H__
typedef int (ieee802154_radio_tx_frag_t)(struct net_if *iface,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *frag);
static inline bool prepare_for_ack(struct ieee802154_context *ctx,
struct net_buf *buf)
struct net_pkt *pkt)
{
if (ieee802154_ack_required(buf)) {
if (ieee802154_ack_required(pkt)) {
ctx->ack_received = false;
k_sem_init(&ctx->ack_lock, 0, UINT_MAX);
@ -43,9 +43,9 @@ static inline int wait_for_ack(struct ieee802154_context *ctx,
}
static inline int handle_ack(struct ieee802154_context *ctx,
struct net_buf *buf)
struct net_pkt *pkt)
{
if (buf->len == IEEE802154_ACK_PKT_LENGTH) {
if (pkt->frags->len == IEEE802154_ACK_PKT_LENGTH) {
ctx->ack_received = true;
k_sem_give(&ctx->ack_lock);
@ -55,16 +55,16 @@ static inline int handle_ack(struct ieee802154_context *ctx,
return NET_CONTINUE;
}
static inline int tx_buffer_fragments(struct net_if *iface,
struct net_buf *buf,
static inline int tx_packet_fragments(struct net_if *iface,
struct net_pkt *pkt,
ieee802154_radio_tx_frag_t *tx_func)
{
int ret = 0;
struct net_buf *frag;
frag = buf->frags;
frag = pkt->frags;
while (frag) {
ret = tx_func(iface, buf, frag);
ret = tx_func(iface, pkt, frag);
if (ret) {
break;
}
@ -73,7 +73,7 @@ static inline int tx_buffer_fragments(struct net_if *iface,
}
if (!ret) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return ret;

View file

@ -43,21 +43,21 @@
*/
#define NET_CONN_CB(name) \
static enum net_verdict _##name(struct net_conn *conn, \
struct net_buf *buf, \
struct net_pkt *pkt, \
void *user_data); \
static enum net_verdict name(struct net_conn *conn, \
struct net_buf *buf, \
struct net_pkt *pkt, \
void *user_data) \
{ \
enum net_verdict result; \
\
net_context_ref(user_data); \
result = _##name(conn, buf, user_data); \
result = _##name(conn, pkt, user_data); \
net_context_unref(user_data); \
return result; \
} \
static enum net_verdict _##name(struct net_conn *conn, \
struct net_buf *buf, \
struct net_pkt *pkt, \
void *user_data) \
@ -69,29 +69,29 @@ static struct net_context contexts[NET_MAX_CONTEXT];
static struct k_sem contexts_lock;
static enum net_verdict packet_received(struct net_conn *conn,
struct net_buf *buf,
struct net_pkt *pkt,
void *user_data);
static void set_appdata_values(struct net_buf *buf, enum net_ip_protocol proto);
static void set_appdata_values(struct net_pkt *pkt, enum net_ip_protocol proto);
#if defined(CONFIG_NET_TCP)
static struct sockaddr *create_sockaddr(struct net_buf *buf,
static struct sockaddr *create_sockaddr(struct net_pkt *pkt,
struct sockaddr *addr)
{
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
net_ipaddr_copy(&net_sin6(addr)->sin6_addr,
&NET_IPV6_BUF(buf)->src);
net_sin6(addr)->sin6_port = NET_TCP_BUF(buf)->src_port;
&NET_IPV6_BUF(pkt)->src);
net_sin6(addr)->sin6_port = NET_TCP_BUF(pkt)->src_port;
net_sin6(addr)->sin6_family = AF_INET6;
} else
#endif
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
net_ipaddr_copy(&net_sin(addr)->sin_addr,
&NET_IPV4_BUF(buf)->src);
net_sin(addr)->sin_port = NET_TCP_BUF(buf)->src_port;
&NET_IPV4_BUF(pkt)->src);
net_sin(addr)->sin_port = NET_TCP_BUF(pkt)->src_port;
net_sin(addr)->sin_family = AF_INET;
} else
#endif
@ -344,20 +344,20 @@ int net_context_get(sa_family_t family,
#if defined(CONFIG_NET_TCP)
static void queue_fin(struct net_context *ctx)
{
struct net_buf *buf = NULL;
struct net_pkt *pkt = NULL;
int ret;
ret = net_tcp_prepare_segment(ctx->tcp, NET_TCP_FIN, NULL, 0,
NULL, &ctx->remote, &buf);
if (ret || !buf) {
NULL, &ctx->remote, &pkt);
if (ret || !pkt) {
return;
}
ctx->tcp->fin_queued = 1;
ret = net_tcp_send_buf(buf);
ret = net_tcp_send_pkt(pkt);
if (ret < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
}
@ -663,28 +663,28 @@ int net_context_listen(struct net_context *context, int backlog)
#if defined(CONFIG_NET_TCP)
#if defined(CONFIG_NET_DEBUG_CONTEXT)
#define net_tcp_print_recv_info(str, buf, port) \
#define net_tcp_print_recv_info(str, pkt, port) \
do { \
if (net_context_get_family(context) == AF_INET6) { \
NET_DBG("%s received from %s port %d", str, \
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src),\
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->src),\
ntohs(port)); \
} else if (net_context_get_family(context) == AF_INET) {\
NET_DBG("%s received from %s port %d", str, \
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src),\
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src),\
ntohs(port)); \
} \
} while (0)
#define net_tcp_print_send_info(str, buf, port) \
#define net_tcp_print_send_info(str, pkt, port) \
do { \
if (net_context_get_family(context) == AF_INET6) { \
NET_DBG("%s sent to %s port %d", str, \
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst),\
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->dst),\
ntohs(port)); \
} else if (net_context_get_family(context) == AF_INET) {\
NET_DBG("%s sent to %s port %d", str, \
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst),\
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->dst),\
ntohs(port)); \
} \
} while (0)
@ -698,21 +698,21 @@ static inline int send_control_segment(struct net_context *context,
const struct sockaddr *remote,
int flags, const char *msg)
{
struct net_buf *buf = NULL;
struct net_pkt *pkt = NULL;
int ret;
ret = net_tcp_prepare_segment(context->tcp, flags, NULL, 0,
local, remote, &buf);
local, remote, &pkt);
if (ret) {
return ret;
}
ret = net_send_data(buf);
ret = net_send_data(pkt);
if (ret < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
net_tcp_print_send_info(msg, buf, NET_TCP_BUF(buf)->dst_port);
net_tcp_print_send_info(msg, pkt, NET_TCP_BUF(pkt)->dst_port);
return ret;
}
@ -737,7 +737,7 @@ static inline int send_syn_ack(struct net_context *context,
static inline int send_ack(struct net_context *context,
struct sockaddr *remote)
{
struct net_buf *buf = NULL;
struct net_pkt *pkt = NULL;
int ret;
/* Something (e.g. a data transmission under the user
@ -747,16 +747,16 @@ static inline int send_ack(struct net_context *context,
return 0;
}
ret = net_tcp_prepare_ack(context->tcp, remote, &buf);
ret = net_tcp_prepare_ack(context->tcp, remote, &pkt);
if (ret) {
return ret;
}
net_tcp_print_send_info("ACK", buf, NET_TCP_BUF(buf)->dst_port);
net_tcp_print_send_info("ACK", pkt, NET_TCP_BUF(pkt)->dst_port);
ret = net_tcp_send_buf(buf);
ret = net_tcp_send_pkt(pkt);
if (ret < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return ret;
@ -765,28 +765,28 @@ static inline int send_ack(struct net_context *context,
static int send_reset(struct net_context *context,
struct sockaddr *remote)
{
struct net_buf *buf = NULL;
struct net_pkt *pkt = NULL;
int ret;
ret = net_tcp_prepare_reset(context->tcp, remote, &buf);
ret = net_tcp_prepare_reset(context->tcp, remote, &pkt);
if (ret) {
return ret;
}
net_tcp_print_send_info("RST", buf, NET_TCP_BUF(buf)->dst_port);
net_tcp_print_send_info("RST", pkt, NET_TCP_BUF(pkt)->dst_port);
ret = net_send_data(buf);
ret = net_send_data(pkt);
if (ret < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return ret;
}
static int tcp_hdr_len(struct net_buf *buf)
static int tcp_hdr_len(struct net_pkt *pkt)
{
/* "Offset": 4-bit field in high nibble, units of dwords */
struct net_tcp_hdr *hdr = (void *)net_pkt_tcp_data(buf);
struct net_tcp_hdr *hdr = (void *)net_pkt_tcp_data(pkt);
return 4 * (hdr->offset >> 4);
}
@ -808,15 +808,15 @@ NET_CONN_CB(tcp_established)
return NET_DROP;
}
net_tcp_print_recv_info("DATA", buf, NET_TCP_BUF(buf)->src_port);
net_tcp_print_recv_info("DATA", pkt, NET_TCP_BUF(pkt)->src_port);
tcp_flags = NET_TCP_FLAGS(buf);
tcp_flags = NET_TCP_FLAGS(pkt);
if (tcp_flags & NET_TCP_ACK) {
net_tcp_ack_received(context,
sys_get_be32(NET_TCP_BUF(buf)->ack));
sys_get_be32(NET_TCP_BUF(pkt)->ack));
}
if (sys_get_be32(NET_TCP_BUF(buf)->seq) - context->tcp->send_ack) {
if (sys_get_be32(NET_TCP_BUF(pkt)->seq) - context->tcp->send_ack) {
/* Don't try to reorder packets. If it doesn't
* match the next segment exactly, drop and wait for
* retransmit
@ -824,10 +824,10 @@ NET_CONN_CB(tcp_established)
return NET_DROP;
}
set_appdata_values(buf, IPPROTO_TCP);
context->tcp->send_ack += net_pkt_appdatalen(buf);
set_appdata_values(pkt, IPPROTO_TCP);
context->tcp->send_ack += net_pkt_appdatalen(pkt);
ret = packet_received(conn, buf, context->tcp->recv_user_data);
ret = packet_received(conn, pkt, context->tcp->recv_user_data);
if (tcp_flags & NET_TCP_FIN) {
/* Sending an ACK in the CLOSE_WAIT state will transition to
@ -868,7 +868,7 @@ NET_CONN_CB(tcp_synack_received)
switch (net_tcp_get_state(context->tcp)) {
case NET_TCP_SYN_SENT:
net_context_set_iface(context, net_pkt_iface(buf));
net_context_set_iface(context, net_pkt_iface(pkt));
break;
default:
NET_DBG("Context %p in wrong state %d",
@ -876,11 +876,11 @@ NET_CONN_CB(tcp_synack_received)
return NET_DROP;
}
net_pkt_set_context(buf, context);
net_pkt_set_context(pkt, context);
NET_ASSERT(net_pkt_iface(buf));
NET_ASSERT(net_pkt_iface(pkt));
if (NET_TCP_FLAGS(buf) & NET_TCP_RST) {
if (NET_TCP_FLAGS(pkt) & NET_TCP_RST) {
if (context->connect_cb) {
context->connect_cb(context, -ECONNREFUSED,
context->user_data);
@ -889,15 +889,15 @@ NET_CONN_CB(tcp_synack_received)
return NET_DROP;
}
if (NET_TCP_FLAGS(buf) & NET_TCP_SYN) {
if (NET_TCP_FLAGS(pkt) & NET_TCP_SYN) {
context->tcp->send_ack =
sys_get_be32(NET_TCP_BUF(buf)->seq) + 1;
sys_get_be32(NET_TCP_BUF(pkt)->seq) + 1;
context->tcp->recv_max_ack = context->tcp->send_seq + 1;
}
/*
* If we receive SYN, we send SYN-ACK and go to SYN_RCVD state.
*/
if (NET_TCP_FLAGS(buf) == (NET_TCP_SYN | NET_TCP_ACK)) {
if (NET_TCP_FLAGS(pkt) == (NET_TCP_SYN | NET_TCP_ACK)) {
struct sockaddr *laddr;
struct sockaddr *raddr;
@ -911,39 +911,39 @@ NET_CONN_CB(tcp_synack_received)
#endif
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
laddr = (struct sockaddr *)&l6addr;
raddr = (struct sockaddr *)&r6addr;
r6addr.sin6_family = AF_INET6;
r6addr.sin6_port = NET_TCP_BUF(buf)->src_port;
r6addr.sin6_port = NET_TCP_BUF(pkt)->src_port;
net_ipaddr_copy(&r6addr.sin6_addr,
&NET_IPV6_BUF(buf)->src);
&NET_IPV6_BUF(pkt)->src);
l6addr.sin6_family = AF_INET6;
l6addr.sin6_port = NET_TCP_BUF(buf)->dst_port;
l6addr.sin6_port = NET_TCP_BUF(pkt)->dst_port;
net_ipaddr_copy(&l6addr.sin6_addr,
&NET_IPV6_BUF(buf)->dst);
&NET_IPV6_BUF(pkt)->dst);
} else
#endif
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
laddr = (struct sockaddr *)&l4addr;
raddr = (struct sockaddr *)&r4addr;
r4addr.sin_family = AF_INET;
r4addr.sin_port = NET_TCP_BUF(buf)->src_port;
r4addr.sin_port = NET_TCP_BUF(pkt)->src_port;
net_ipaddr_copy(&r4addr.sin_addr,
&NET_IPV4_BUF(buf)->src);
&NET_IPV4_BUF(pkt)->src);
l4addr.sin_family = AF_INET;
l4addr.sin_port = NET_TCP_BUF(buf)->dst_port;
l4addr.sin_port = NET_TCP_BUF(pkt)->dst_port;
net_ipaddr_copy(&l4addr.sin_addr,
&NET_IPV4_BUF(buf)->dst);
&NET_IPV4_BUF(pkt)->dst);
} else
#endif
{
NET_DBG("Invalid family (%d)", net_pkt_family(buf));
NET_DBG("Invalid family (%d)", net_pkt_family(pkt));
return NET_DROP;
}
@ -954,8 +954,8 @@ NET_CONN_CB(tcp_synack_received)
ret = net_tcp_register(raddr,
laddr,
ntohs(NET_TCP_BUF(buf)->src_port),
ntohs(NET_TCP_BUF(buf)->dst_port),
ntohs(NET_TCP_BUF(pkt)->src_port),
ntohs(NET_TCP_BUF(pkt)->dst_port),
tcp_established,
context,
&context->conn_handler);
@ -1185,7 +1185,7 @@ static void ack_timeout(struct k_work *work)
net_tcp_change_state(tcp, NET_TCP_LISTEN);
}
static void buf_get_sockaddr(sa_family_t family, struct net_buf *buf,
static void pkt_get_sockaddr(sa_family_t family, struct net_pkt *pkt,
struct sockaddr_ptr *addr)
{
memset(addr, 0, sizeof(*addr));
@ -1195,8 +1195,8 @@ static void buf_get_sockaddr(sa_family_t family, struct net_buf *buf,
struct sockaddr_in_ptr *addr4 = net_sin_ptr(addr);
addr4->sin_family = AF_INET;
addr4->sin_port = NET_TCP_BUF(buf)->dst_port;
addr4->sin_addr = &NET_IPV4_BUF(buf)->dst;
addr4->sin_port = NET_TCP_BUF(pkt)->dst_port;
addr4->sin_addr = &NET_IPV4_BUF(pkt)->dst;
}
#endif
@ -1205,8 +1205,8 @@ static void buf_get_sockaddr(sa_family_t family, struct net_buf *buf,
struct sockaddr_in6_ptr *addr6 = net_sin6_ptr(addr);
addr6->sin6_family = AF_INET6;
addr6->sin6_port = NET_TCP_BUF(buf)->dst_port;
addr6->sin6_addr = &NET_IPV6_BUF(buf)->dst;
addr6->sin6_port = NET_TCP_BUF(pkt)->dst_port;
addr6->sin6_addr = &NET_IPV6_BUF(pkt)->dst;
}
#endif
}
@ -1215,7 +1215,7 @@ static void buf_get_sockaddr(sa_family_t family, struct net_buf *buf,
static inline void copy_pool_vars(struct net_context *new_context,
struct net_context *listen_context)
{
new_context->tx_pool = listen_context->tx_pool;
new_context->tx_slab = listen_context->tx_slab;
new_context->data_pool = listen_context->data_pool;
}
#else
@ -1231,7 +1231,7 @@ NET_CONN_CB(tcp_syn_rcvd)
{
struct net_context *context = (struct net_context *)user_data;
struct net_tcp *tcp;
struct sockaddr_ptr buf_src_addr;
struct sockaddr_ptr pkt_src_addr;
NET_ASSERT(context && context->tcp);
@ -1239,10 +1239,10 @@ NET_CONN_CB(tcp_syn_rcvd)
switch (net_tcp_get_state(tcp)) {
case NET_TCP_LISTEN:
net_context_set_iface(context, net_pkt_iface(buf));
net_context_set_iface(context, net_pkt_iface(pkt));
break;
case NET_TCP_SYN_RCVD:
if (net_pkt_iface(buf) != net_context_get_iface(context)) {
if (net_pkt_iface(pkt) != net_context_get_iface(context)) {
return NET_DROP;
}
break;
@ -1252,30 +1252,30 @@ NET_CONN_CB(tcp_syn_rcvd)
return NET_DROP;
}
net_pkt_set_context(buf, context);
net_pkt_set_context(pkt, context);
NET_ASSERT(net_pkt_iface(buf));
NET_ASSERT(net_pkt_iface(pkt));
/*
* If we receive SYN, we send SYN-ACK and go to SYN_RCVD state.
*/
if (NET_TCP_FLAGS(buf) == NET_TCP_SYN) {
if (NET_TCP_FLAGS(pkt) == NET_TCP_SYN) {
struct sockaddr peer, *remote;
net_tcp_print_recv_info("SYN", buf, NET_TCP_BUF(buf)->src_port);
net_tcp_print_recv_info("SYN", pkt, NET_TCP_BUF(pkt)->src_port);
net_tcp_change_state(tcp, NET_TCP_SYN_RCVD);
remote = create_sockaddr(buf, &peer);
remote = create_sockaddr(pkt, &peer);
/* FIXME: Is this the correct place to set tcp->send_ack? */
context->tcp->send_ack =
sys_get_be32(NET_TCP_BUF(buf)->seq) + 1;
sys_get_be32(NET_TCP_BUF(pkt)->seq) + 1;
context->tcp->recv_max_ack = context->tcp->send_seq + 1;
buf_get_sockaddr(net_context_get_family(context),
buf, &buf_src_addr);
send_syn_ack(context, &buf_src_addr, remote);
pkt_get_sockaddr(net_context_get_family(context),
pkt, &pkt_src_addr);
send_syn_ack(context, &pkt_src_addr, remote);
/* We might be entering this section multiple times
* if the SYN is sent more than once. So we need to cancel
@ -1291,10 +1291,10 @@ NET_CONN_CB(tcp_syn_rcvd)
/*
* If we receive RST, we go back to LISTEN state.
*/
if (NET_TCP_FLAGS(buf) == NET_TCP_RST) {
if (NET_TCP_FLAGS(pkt) == NET_TCP_RST) {
k_delayed_work_cancel(&tcp->ack_timer);
net_tcp_print_recv_info("RST", buf, NET_TCP_BUF(buf)->src_port);
net_tcp_print_recv_info("RST", pkt, NET_TCP_BUF(pkt)->src_port);
net_tcp_change_state(tcp, NET_TCP_LISTEN);
@ -1304,7 +1304,7 @@ NET_CONN_CB(tcp_syn_rcvd)
/*
* If we receive ACK, we go to ESTABLISHED state.
*/
if (NET_TCP_FLAGS(buf) == NET_TCP_ACK) {
if (NET_TCP_FLAGS(pkt) == NET_TCP_ACK) {
struct net_context *new_context;
struct sockaddr local_addr;
struct sockaddr remote_addr;
@ -1321,7 +1321,7 @@ NET_CONN_CB(tcp_syn_rcvd)
goto reset;
}
net_tcp_print_recv_info("ACK", buf, NET_TCP_BUF(buf)->src_port);
net_tcp_print_recv_info("ACK", pkt, NET_TCP_BUF(pkt)->src_port);
if (!context->tcp->accept_cb) {
NET_DBG("No accept callback, connection reset.");
@ -1330,7 +1330,7 @@ NET_CONN_CB(tcp_syn_rcvd)
/* We create a new context that starts to wait data.
*/
ret = net_context_get(net_pkt_family(buf),
ret = net_context_get(net_pkt_family(pkt),
SOCK_STREAM, IPPROTO_TCP,
&new_context);
if (ret < 0) {
@ -1353,13 +1353,13 @@ NET_CONN_CB(tcp_syn_rcvd)
remote_addr6->sin6_family = AF_INET6;
local_addr6->sin6_family = AF_INET6;
local_addr6->sin6_port = NET_TCP_BUF(buf)->dst_port;
remote_addr6->sin6_port = NET_TCP_BUF(buf)->src_port;
local_addr6->sin6_port = NET_TCP_BUF(pkt)->dst_port;
remote_addr6->sin6_port = NET_TCP_BUF(pkt)->src_port;
net_ipaddr_copy(&local_addr6->sin6_addr,
&NET_IPV6_BUF(buf)->dst);
&NET_IPV6_BUF(pkt)->dst);
net_ipaddr_copy(&remote_addr6->sin6_addr,
&NET_IPV6_BUF(buf)->src);
&NET_IPV6_BUF(pkt)->src);
addrlen = sizeof(struct sockaddr_in6);
} else
#endif /* CONFIG_NET_IPV6 */
@ -1374,13 +1374,13 @@ NET_CONN_CB(tcp_syn_rcvd)
remote_addr4->sin_family = AF_INET;
local_addr4->sin_family = AF_INET;
local_addr4->sin_port = NET_TCP_BUF(buf)->dst_port;
remote_addr4->sin_port = NET_TCP_BUF(buf)->src_port;
local_addr4->sin_port = NET_TCP_BUF(pkt)->dst_port;
remote_addr4->sin_port = NET_TCP_BUF(pkt)->src_port;
net_ipaddr_copy(&local_addr4->sin_addr,
&NET_IPV4_BUF(buf)->dst);
&NET_IPV4_BUF(pkt)->dst);
net_ipaddr_copy(&remote_addr4->sin_addr,
&NET_IPV4_BUF(buf)->src);
&NET_IPV4_BUF(pkt)->src);
addrlen = sizeof(struct sockaddr_in);
} else
#endif /* CONFIG_NET_IPV4 */
@ -1453,7 +1453,7 @@ reset:
{
struct sockaddr peer;
send_reset(tcp->context, create_sockaddr(buf, &peer));
send_reset(tcp->context, create_sockaddr(pkt, &peer));
}
return NET_DROP;
@ -1562,7 +1562,7 @@ int net_context_accept(struct net_context *context,
}
static int send_data(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
net_context_send_cb_t cb,
int32_t timeout,
void *token,
@ -1570,10 +1570,10 @@ static int send_data(struct net_context *context,
{
context->send_cb = cb;
context->user_data = user_data;
net_pkt_set_token(buf, token);
net_pkt_set_token(pkt, token);
if (net_context_get_ip_proto(context) == IPPROTO_UDP) {
return net_send_data(buf);
return net_send_data(pkt);
}
#if defined(CONFIG_NET_TCP)
@ -1599,42 +1599,42 @@ static int send_data(struct net_context *context,
#if defined(CONFIG_NET_UDP)
static int create_udp_packet(struct net_context *context,
struct net_buf *buf,
struct net_pkt *pkt,
const struct sockaddr *dst_addr,
struct net_buf **out_buf)
struct net_pkt **out_pkt)
{
int r = 0;
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)dst_addr;
buf = net_ipv6_create(context, buf, NULL, &addr6->sin6_addr);
buf = net_udp_append(context, buf, ntohs(addr6->sin6_port));
r = net_ipv6_finalize(context, buf);
pkt = net_ipv6_create(context, pkt, NULL, &addr6->sin6_addr);
pkt = net_udp_append(context, pkt, ntohs(addr6->sin6_port));
r = net_ipv6_finalize(context, pkt);
} else
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
struct sockaddr_in *addr4 = (struct sockaddr_in *)dst_addr;
buf = net_ipv4_create(context, buf, NULL, &addr4->sin_addr);
buf = net_udp_append(context, buf, ntohs(addr4->sin_port));
r = net_ipv4_finalize(context, buf);
pkt = net_ipv4_create(context, pkt, NULL, &addr4->sin_addr);
pkt = net_udp_append(context, pkt, ntohs(addr4->sin_port));
r = net_ipv4_finalize(context, pkt);
} else
#endif /* CONFIG_NET_IPV4 */
{
return -EPROTONOSUPPORT;
}
*out_buf = buf;
*out_pkt = pkt;
return r;
}
#endif /* CONFIG_NET_UDP */
static int sendto(struct net_buf *buf,
static int sendto(struct net_pkt *pkt,
const struct sockaddr *dst_addr,
socklen_t addrlen,
net_context_send_cb_t cb,
@ -1642,7 +1642,7 @@ static int sendto(struct net_buf *buf,
void *token,
void *user_data)
{
struct net_context *context = net_pkt_context(buf);
struct net_context *context = net_pkt_context(pkt);
int ret;
if (!net_context_is_used(context)) {
@ -1667,16 +1667,16 @@ static int sendto(struct net_buf *buf,
}
#if defined(CONFIG_NET_OFFLOAD)
if (net_if_is_ip_offloaded(net_pkt_iface(buf))) {
if (net_if_is_ip_offloaded(net_pkt_iface(pkt))) {
return net_offload_sendto(
net_pkt_iface(buf),
buf, dst_addr, addrlen,
net_pkt_iface(pkt),
pkt, dst_addr, addrlen,
cb, timeout, token, user_data);
}
#endif /* CONFIG_NET_OFFLOAD */
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)dst_addr;
if (addrlen < sizeof(struct sockaddr_in6)) {
@ -1690,7 +1690,7 @@ static int sendto(struct net_buf *buf,
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
struct sockaddr_in *addr4 = (struct sockaddr_in *)dst_addr;
if (addrlen < sizeof(struct sockaddr_in)) {
@ -1703,19 +1703,19 @@ static int sendto(struct net_buf *buf,
} else
#endif /* CONFIG_NET_IPV4 */
{
NET_DBG("Invalid protocol family %d", net_pkt_family(buf));
NET_DBG("Invalid protocol family %d", net_pkt_family(pkt));
return -EINVAL;
}
#if defined(CONFIG_NET_UDP)
if (net_context_get_ip_proto(context) == IPPROTO_UDP) {
ret = create_udp_packet(context, buf, dst_addr, &buf);
ret = create_udp_packet(context, pkt, dst_addr, &pkt);
} else
#endif /* CONFIG_NET_UDP */
#if defined(CONFIG_NET_TCP)
if (net_context_get_ip_proto(context) == IPPROTO_TCP) {
ret = net_tcp_queue_data(context, buf);
ret = net_tcp_queue_data(context, pkt);
} else
#endif /* CONFIG_NET_TCP */
{
@ -1729,25 +1729,25 @@ static int sendto(struct net_buf *buf,
return ret;
}
return send_data(context, buf, cb, timeout, token, user_data);
return send_data(context, pkt, cb, timeout, token, user_data);
}
int net_context_send(struct net_buf *buf,
int net_context_send(struct net_pkt *pkt,
net_context_send_cb_t cb,
int32_t timeout,
void *token,
void *user_data)
{
struct net_context *context = net_pkt_context(buf);
struct net_context *context = net_pkt_context(pkt);
socklen_t addrlen;
NET_ASSERT(PART_OF_ARRAY(contexts, context));
#if defined(CONFIG_NET_OFFLOAD)
if (net_if_is_ip_offloaded(net_pkt_iface(buf))) {
if (net_if_is_ip_offloaded(net_pkt_iface(pkt))) {
return net_offload_send(
net_pkt_iface(buf),
buf, cb, timeout,
net_pkt_iface(pkt),
pkt, cb, timeout,
token, user_data);
}
#endif /* CONFIG_NET_OFFLOAD */
@ -1758,13 +1758,13 @@ int net_context_send(struct net_buf *buf,
}
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_pkt_family(pkt) == AF_INET6) {
addrlen = sizeof(struct sockaddr_in6);
} else
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_pkt_family(pkt) == AF_INET) {
addrlen = sizeof(struct sockaddr_in);
} else
#endif /* CONFIG_NET_IPV4 */
@ -1772,11 +1772,11 @@ int net_context_send(struct net_buf *buf,
addrlen = 0;
}
return sendto(buf, &context->remote, addrlen, cb, timeout, token,
return sendto(pkt, &context->remote, addrlen, cb, timeout, token,
user_data);
}
int net_context_sendto(struct net_buf *buf,
int net_context_sendto(struct net_pkt *pkt,
const struct sockaddr *dst_addr,
socklen_t addrlen,
net_context_send_cb_t cb,
@ -1785,61 +1785,61 @@ int net_context_sendto(struct net_buf *buf,
void *user_data)
{
#if defined(CONFIG_NET_TCP)
struct net_context *context = net_pkt_context(buf);
struct net_context *context = net_pkt_context(pkt);
NET_ASSERT(PART_OF_ARRAY(contexts, context));
if (net_context_get_ip_proto(context) == IPPROTO_TCP) {
/* Match POSIX behavior and ignore dst_address and addrlen */
return net_context_send(buf, cb, timeout, token, user_data);
return net_context_send(pkt, cb, timeout, token, user_data);
}
#endif /* CONFIG_NET_TCP */
return sendto(buf, dst_addr, addrlen, cb, timeout, token, user_data);
return sendto(pkt, dst_addr, addrlen, cb, timeout, token, user_data);
}
static void set_appdata_values(struct net_buf *buf, enum net_ip_protocol proto)
static void set_appdata_values(struct net_pkt *pkt, enum net_ip_protocol proto)
{
size_t total_len = net_buf_frags_len(buf);
size_t total_len = net_pkt_get_len(pkt);
#if defined(CONFIG_NET_UDP)
if (proto == IPPROTO_UDP) {
net_pkt_set_appdata(buf, net_pkt_udp_data(buf) +
net_pkt_set_appdata(pkt, net_pkt_udp_data(pkt) +
sizeof(struct net_udp_hdr));
} else
#endif /* CONFIG_NET_UDP */
#if defined(CONFIG_NET_TCP)
if (proto == IPPROTO_TCP) {
net_pkt_set_appdata(buf, net_pkt_udp_data(buf) +
tcp_hdr_len(buf));
net_pkt_set_appdata(pkt, net_pkt_udp_data(pkt) +
tcp_hdr_len(pkt));
} else
#endif /* CONFIG_NET_TCP */
{
net_pkt_set_appdata(buf, net_pkt_ip_data(buf) +
net_pkt_ip_hdr_len(buf));
net_pkt_set_appdata(pkt, net_pkt_ip_data(pkt) +
net_pkt_ip_hdr_len(pkt));
}
net_pkt_set_appdatalen(buf, total_len -
(net_pkt_appdata(buf) -
net_pkt_ip_data(buf)));
net_pkt_set_appdatalen(pkt, total_len -
(net_pkt_appdata(pkt) -
net_pkt_ip_data(pkt)));
NET_ASSERT_INFO(net_pkt_appdatalen(buf) < total_len,
NET_ASSERT_INFO(net_pkt_appdatalen(pkt) < total_len,
"Wrong appdatalen %u, total %zu",
net_pkt_appdatalen(buf), total_len);
net_pkt_appdatalen(pkt), total_len);
}
static enum net_verdict packet_received(struct net_conn *conn,
struct net_buf *buf,
struct net_pkt *pkt,
void *user_data)
{
struct net_context *context = find_context(conn);
NET_ASSERT(context);
NET_ASSERT(net_pkt_iface(buf));
NET_ASSERT(net_pkt_iface(pkt));
net_context_set_iface(context, net_pkt_iface(buf));
net_pkt_set_context(buf, context);
net_context_set_iface(context, net_pkt_iface(pkt));
net_pkt_set_context(pkt, context);
/* If there is no callback registered, then we can only drop
* the packet.
@ -1851,21 +1851,21 @@ static enum net_verdict packet_received(struct net_conn *conn,
if (net_context_get_ip_proto(context) != IPPROTO_TCP) {
/* TCP packets get appdata earlier in tcp_established(). */
set_appdata_values(buf, IPPROTO_UDP);
set_appdata_values(pkt, IPPROTO_UDP);
}
#if defined(CONFIG_NET_TCP)
else if (net_context_get_type(context) == SOCK_STREAM) {
if (net_pkt_appdatalen(buf) == 0) {
net_pkt_unref(buf);
if (net_pkt_appdatalen(pkt) == 0) {
net_pkt_unref(pkt);
return NET_OK;
}
}
#endif /* CONFIG_NET_TCP */
NET_DBG("Set appdata %p to len %u (total %zu)",
net_pkt_appdata(buf), net_pkt_appdatalen(buf),
net_buf_frags_len(buf));
net_pkt_appdata(pkt), net_pkt_appdatalen(pkt),
net_pkt_get_len(pkt));
context->recv_cb(context, buf, 0, user_data);
context->recv_cb(context, pkt, 0, user_data);
#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
k_sem_give(&context->recv_data_wait);

View file

@ -64,7 +64,7 @@ static struct k_fifo rx_queue;
static k_tid_t rx_tid;
static K_SEM_DEFINE(startup_sync, 0, UINT_MAX);
static inline enum net_verdict process_data(struct net_buf *buf,
static inline enum net_verdict process_data(struct net_pkt *pkt,
bool is_loopback)
{
int ret;
@ -75,30 +75,24 @@ static inline enum net_verdict process_data(struct net_buf *buf,
* an IPv6 packet, then do not pass it to L2 as the packet does
* not have link layer headers in it.
*/
if (net_pkt_ipv6_fragment_start(buf)) {
if (net_pkt_ipv6_fragment_start(pkt)) {
locally_routed = true;
}
#endif
/* If there is no data, then drop the packet. Also if
* the buffer is wrong type, then also drop the packet.
* The first buffer needs to have user data part that
* contains user data. The rest of the fragments should
* be data fragments without user data.
*/
if (!buf->frags || !buf->pool->user_data_size) {
NET_DBG("Corrupted buffer (frags %p, data size %u)",
buf->frags, buf->pool->user_data_size);
/* If there is no data, then drop the packet. */
if (!pkt->frags) {
NET_DBG("Corrupted packet (frags %p)", pkt->frags);
net_stats_update_processing_error();
return NET_DROP;
}
if (!is_loopback && !locally_routed) {
ret = net_if_recv_data(net_pkt_iface(buf), buf);
ret = net_if_recv_data(net_pkt_iface(pkt), pkt);
if (ret != NET_CONTINUE) {
if (ret == NET_DROP) {
NET_DBG("Buffer %p discarded by L2", buf);
NET_DBG("Packet %p discarded by L2", pkt);
net_stats_update_processing_error();
}
@ -107,46 +101,46 @@ static inline enum net_verdict process_data(struct net_buf *buf,
}
/* IP version and header length. */
switch (NET_IPV6_BUF(buf)->vtc & 0xf0) {
switch (NET_IPV6_BUF(pkt)->vtc & 0xf0) {
#if defined(CONFIG_NET_IPV6)
case 0x60:
net_stats_update_ipv6_recv();
net_pkt_set_family(buf, PF_INET6);
return net_ipv6_process_pkt(buf);
net_pkt_set_family(pkt, PF_INET6);
return net_ipv6_process_pkt(pkt);
#endif
#if defined(CONFIG_NET_IPV4)
case 0x40:
net_stats_update_ipv4_recv();
net_pkt_set_family(buf, PF_INET);
return net_ipv4_process_pkt(buf);
net_pkt_set_family(pkt, PF_INET);
return net_ipv4_process_pkt(pkt);
#endif
}
NET_DBG("Unknown IP family packet (0x%x)",
NET_IPV6_BUF(buf)->vtc & 0xf0);
NET_IPV6_BUF(pkt)->vtc & 0xf0);
net_stats_update_ip_errors_protoerr();
net_stats_update_ip_errors_vhlerr();
return NET_DROP;
}
static void processing_data(struct net_buf *buf, bool is_loopback)
static void processing_data(struct net_pkt *pkt, bool is_loopback)
{
switch (process_data(buf, is_loopback)) {
switch (process_data(pkt, is_loopback)) {
case NET_OK:
NET_DBG("Consumed buf %p", buf);
NET_DBG("Consumed pkt %p", pkt);
break;
case NET_DROP:
default:
NET_DBG("Dropping buf %p", buf);
net_pkt_unref(buf);
NET_DBG("Dropping pkt %p", pkt);
net_pkt_unref(pkt);
break;
}
}
static void net_rx_thread(void)
{
struct net_buf *buf;
struct net_pkt *pkt;
NET_DBG("Starting RX thread (stack %zu bytes)", sizeof(rx_stack));
@ -168,18 +162,18 @@ static void net_rx_thread(void)
size_t pkt_len;
#endif
buf = net_buf_get(&rx_queue, K_FOREVER);
pkt = k_fifo_get(&rx_queue, K_FOREVER);
net_analyze_stack("RX thread", rx_stack, sizeof(rx_stack));
#if defined(CONFIG_NET_STATISTICS) || defined(CONFIG_NET_DEBUG_CORE)
pkt_len = net_buf_frags_len(buf);
pkt_len = net_pkt_get_len(pkt);
#endif
NET_DBG("Received buf %p len %zu", buf, pkt_len);
NET_DBG("Received pkt %p len %zu", pkt, pkt_len);
net_stats_update_bytes_recv(pkt_len);
processing_data(buf, false);
processing_data(pkt, false);
net_print_statistics();
net_pkt_print();
@ -202,11 +196,11 @@ static void init_rx_queue(void)
/* Check if the IPv{4|6} addresses are proper. As this can be expensive,
* make this optional.
*/
static inline int check_ip_addr(struct net_buf *buf)
static inline int check_ip_addr(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
if (net_ipv6_addr_cmp(&NET_IPV6_BUF(buf)->dst,
if (net_pkt_family(pkt) == AF_INET6) {
if (net_ipv6_addr_cmp(&NET_IPV6_BUF(pkt)->dst,
net_ipv6_unspecified_address())) {
NET_DBG("IPv6 dst address missing");
return -EADDRNOTAVAIL;
@ -215,17 +209,17 @@ static inline int check_ip_addr(struct net_buf *buf)
/* If the destination address is our own, then route it
* back to us.
*/
if (net_is_ipv6_addr_loopback(&NET_IPV6_BUF(buf)->dst) ||
net_is_my_ipv6_addr(&NET_IPV6_BUF(buf)->dst)) {
if (net_is_ipv6_addr_loopback(&NET_IPV6_BUF(pkt)->dst) ||
net_is_my_ipv6_addr(&NET_IPV6_BUF(pkt)->dst)) {
struct in6_addr addr;
/* Swap the addresses so that in receiving side
* the packet is accepted.
*/
net_ipaddr_copy(&addr, &NET_IPV6_BUF(buf)->src);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->src,
&NET_IPV6_BUF(buf)->dst);
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, &addr);
net_ipaddr_copy(&addr, &NET_IPV6_BUF(pkt)->src);
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->src,
&NET_IPV6_BUF(pkt)->dst);
net_ipaddr_copy(&NET_IPV6_BUF(pkt)->dst, &addr);
return 1;
}
@ -233,7 +227,7 @@ static inline int check_ip_addr(struct net_buf *buf)
/* The source check must be done after the destination check
* as having src ::1 is perfectly ok if dst is ::1 too.
*/
if (net_is_ipv6_addr_loopback(&NET_IPV6_BUF(buf)->src)) {
if (net_is_ipv6_addr_loopback(&NET_IPV6_BUF(pkt)->src)) {
NET_DBG("IPv6 loopback src address");
return -EADDRNOTAVAIL;
}
@ -241,8 +235,8 @@ static inline int check_ip_addr(struct net_buf *buf)
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
if (net_ipv4_addr_cmp(&NET_IPV4_BUF(buf)->dst,
if (net_pkt_family(pkt) == AF_INET) {
if (net_ipv4_addr_cmp(&NET_IPV4_BUF(pkt)->dst,
net_ipv4_unspecified_address())) {
return -EADDRNOTAVAIL;
}
@ -250,17 +244,17 @@ static inline int check_ip_addr(struct net_buf *buf)
/* If the destination address is our own, then route it
* back to us.
*/
if (net_is_ipv4_addr_loopback(&NET_IPV4_BUF(buf)->dst) ||
net_is_my_ipv4_addr(&NET_IPV4_BUF(buf)->dst)) {
if (net_is_ipv4_addr_loopback(&NET_IPV4_BUF(pkt)->dst) ||
net_is_my_ipv4_addr(&NET_IPV4_BUF(pkt)->dst)) {
struct in_addr addr;
/* Swap the addresses so that in receiving side
* the packet is accepted.
*/
net_ipaddr_copy(&addr, &NET_IPV4_BUF(buf)->src);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->src,
&NET_IPV4_BUF(buf)->dst);
net_ipaddr_copy(&NET_IPV4_BUF(buf)->dst, &addr);
net_ipaddr_copy(&addr, &NET_IPV4_BUF(pkt)->src);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->src,
&NET_IPV4_BUF(pkt)->dst);
net_ipaddr_copy(&NET_IPV4_BUF(pkt)->dst, &addr);
return 1;
}
@ -269,7 +263,7 @@ static inline int check_ip_addr(struct net_buf *buf)
* as having src 127.0.0.0/8 is perfectly ok if dst is in
* localhost subnet too.
*/
if (net_is_ipv4_addr_loopback(&NET_IPV4_BUF(buf)->src)) {
if (net_is_ipv4_addr_loopback(&NET_IPV4_BUF(pkt)->src)) {
NET_DBG("IPv4 loopback src address");
return -EADDRNOTAVAIL;
}
@ -283,24 +277,24 @@ static inline int check_ip_addr(struct net_buf *buf)
return 0;
}
#else
#define check_ip_addr(buf) 0
#define check_ip_addr(pkt) 0
#endif
/* Called when data needs to be sent to network */
int net_send_data(struct net_buf *buf)
int net_send_data(struct net_pkt *pkt)
{
int status;
if (!buf || !buf->frags) {
if (!pkt || !pkt->frags) {
return -ENODATA;
}
if (!net_pkt_iface(buf)) {
if (!net_pkt_iface(pkt)) {
return -EINVAL;
}
#if defined(CONFIG_NET_STATISTICS)
switch (net_pkt_family(buf)) {
switch (net_pkt_family(pkt)) {
case AF_INET:
net_stats_update_ipv4_sent();
break;
@ -310,18 +304,18 @@ int net_send_data(struct net_buf *buf)
}
#endif
status = check_ip_addr(buf);
status = check_ip_addr(pkt);
if (status < 0) {
return status;
} else if (status > 0) {
/* Packet is destined back to us so send it directly
* to RX processing.
*/
processing_data(buf, true);
processing_data(pkt, true);
return 0;
}
if (net_if_send_data(net_pkt_iface(buf), buf) == NET_DROP) {
if (net_if_send_data(net_pkt_iface(pkt), pkt) == NET_DROP) {
return -EIO;
}
@ -329,12 +323,12 @@ int net_send_data(struct net_buf *buf)
}
/* Called by driver when an IP packet has been received */
int net_recv_data(struct net_if *iface, struct net_buf *buf)
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
{
NET_ASSERT(buf && buf->frags);
NET_ASSERT(pkt && pkt->frags);
NET_ASSERT(iface);
if (!buf->frags) {
if (!pkt->frags) {
return -ENODATA;
}
@ -342,12 +336,12 @@ int net_recv_data(struct net_if *iface, struct net_buf *buf)
return -ENETDOWN;
}
NET_DBG("fifo %p iface %p buf %p len %zu", &rx_queue, iface, buf,
net_buf_frags_len(buf));
NET_DBG("fifo %p iface %p pkt %p len %zu", &rx_queue, iface, pkt,
net_pkt_get_len(pkt));
net_pkt_set_iface(buf, iface);
net_pkt_set_iface(pkt, iface);
net_buf_put(&rx_queue, buf);
k_fifo_put(&rx_queue, pkt);
return 0;
}

View file

@ -46,14 +46,14 @@ NET_STACK_DEFINE(TX, tx_stack, CONFIG_NET_TX_STACK_SIZE,
CONFIG_NET_TX_STACK_SIZE);
#if defined(CONFIG_NET_DEBUG_IF)
#define debug_check_packet(buf) \
#define debug_check_packet(pkt) \
{ \
size_t len = net_buf_frags_len(buf->frags); \
size_t len = net_pkt_get_len(pkt); \
\
NET_DBG("Processing (buf %p, data len %zu) network packet", \
buf, len); \
NET_DBG("Processing (pkt %p, data len %zu) network packet", \
pkt, len); \
\
NET_ASSERT(buf->frags && len); \
NET_ASSERT(pkt->frags && len); \
} while (0)
#else
#define debug_check_packet(...)
@ -78,29 +78,29 @@ static bool net_if_tx(struct net_if *iface)
const struct net_if_api *api = iface->dev->driver_api;
struct net_linkaddr *dst;
struct net_context *context;
struct net_buf *buf;
struct net_pkt *pkt;
void *context_token;
int status;
#if defined(CONFIG_NET_STATISTICS)
size_t pkt_len;
#endif
buf = net_buf_get(&iface->tx_queue, K_NO_WAIT);
if (!buf) {
pkt = k_fifo_get(&iface->tx_queue, K_NO_WAIT);
if (!pkt) {
return false;
}
debug_check_packet(buf);
debug_check_packet(pkt);
dst = net_pkt_ll_dst(buf);
context = net_pkt_context(buf);
context_token = net_pkt_token(buf);
dst = net_pkt_ll_dst(pkt);
context = net_pkt_context(pkt);
context_token = net_pkt_token(pkt);
if (atomic_test_bit(iface->flags, NET_IF_UP)) {
#if defined(CONFIG_NET_STATISTICS)
pkt_len = net_buf_frags_len(buf);
pkt_len = net_pkt_get_len(pkt);
#endif
status = api->send(iface, buf);
status = api->send(iface, pkt);
} else {
/* Drop packet if interface is not up */
NET_WARN("iface %p is down", iface);
@ -108,7 +108,7 @@ static bool net_if_tx(struct net_if *iface)
}
if (status < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
} else {
net_stats_update_bytes_sent(pkt_len);
}
@ -133,8 +133,8 @@ static void net_if_flush_tx(struct net_if *iface)
return;
}
/* Without this, the net_buf_get() can return a buf which
* has buf->frags set to NULL. This is not allowed as we
/* Without this, the k_fifo_get() can return a pkt which
* has pkt->frags set to NULL. This is not allowed as we
* cannot send a packet that has no data in it.
* The k_yield() fixes the issue and packets are flushed
* correctly.
@ -222,11 +222,11 @@ static inline void init_iface(struct net_if *iface)
api->init(iface);
}
enum net_verdict net_if_send_data(struct net_if *iface, struct net_buf *buf)
enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
{
struct net_context *context = net_pkt_context(buf);
struct net_linkaddr *dst = net_pkt_ll_dst(buf);
void *token = net_pkt_token(buf);
struct net_context *context = net_pkt_context(pkt);
struct net_linkaddr *dst = net_pkt_ll_dst(pkt);
void *token = net_pkt_token(pkt);
enum net_verdict verdict;
int status = -EIO;
@ -244,25 +244,25 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_buf *buf)
* https://jira.zephyrproject.org/browse/ZEP-1656
*/
if (!atomic_test_bit(iface->flags, NET_IF_POINTOPOINT) &&
!net_pkt_ll_src(buf)->addr) {
net_pkt_ll_src(buf)->addr = net_pkt_ll_if(buf)->addr;
net_pkt_ll_src(buf)->len = net_pkt_ll_if(buf)->len;
!net_pkt_ll_src(pkt)->addr) {
net_pkt_ll_src(pkt)->addr = net_pkt_ll_if(pkt)->addr;
net_pkt_ll_src(pkt)->len = net_pkt_ll_if(pkt)->len;
}
#if defined(CONFIG_NET_IPV6)
/* If the ll dst address is not set check if it is present in the nbr
* cache.
*/
if (net_pkt_family(buf) == AF_INET6) {
buf = net_ipv6_prepare_for_send(buf);
if (!buf) {
if (net_pkt_family(pkt) == AF_INET6) {
pkt = net_ipv6_prepare_for_send(pkt);
if (!pkt) {
verdict = NET_CONTINUE;
goto done;
}
}
#endif
verdict = iface->l2->send(iface, buf);
verdict = iface->l2->send(iface, pkt);
done:
/* The L2 send() function can return

File diff suppressed because it is too large Load diff

View file

@ -19,12 +19,12 @@ extern void net_pkt_init(void);
extern void net_if_init(struct k_sem *startup_sync);
extern void net_if_post_init(void);
extern void net_context_init(void);
enum net_verdict net_ipv4_process_pkt(struct net_buf *buf);
enum net_verdict net_ipv6_process_pkt(struct net_buf *buf);
enum net_verdict net_ipv4_process_pkt(struct net_pkt *pkt);
enum net_verdict net_ipv6_process_pkt(struct net_pkt *pkt);
extern void net_ipv6_init(void);
#if defined(CONFIG_NET_IPV6_FRAGMENT)
int net_ipv6_send_fragmented_pkt(struct net_if *iface, struct net_buf *buf,
int net_ipv6_send_fragmented_pkt(struct net_if *iface, struct net_pkt *pkt,
uint16_t pkt_len);
#endif
@ -32,30 +32,30 @@ extern const char *net_proto2str(enum net_ip_protocol proto);
extern char *net_byte_to_hex(char *ptr, uint8_t byte, char base, bool pad);
extern char *net_sprint_ll_addr_buf(const uint8_t *ll, uint8_t ll_len,
char *buf, int buflen);
extern uint16_t net_calc_chksum(struct net_buf *buf, uint8_t proto);
extern uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto);
#if defined(CONFIG_NET_IPV4)
extern uint16_t net_calc_chksum_ipv4(struct net_buf *buf);
extern uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt);
#endif /* CONFIG_NET_IPV4 */
static inline uint16_t net_calc_chksum_icmpv6(struct net_buf *buf)
static inline uint16_t net_calc_chksum_icmpv6(struct net_pkt *pkt)
{
return net_calc_chksum(buf, IPPROTO_ICMPV6);
return net_calc_chksum(pkt, IPPROTO_ICMPV6);
}
static inline uint16_t net_calc_chksum_icmpv4(struct net_buf *buf)
static inline uint16_t net_calc_chksum_icmpv4(struct net_pkt *pkt)
{
return net_calc_chksum(buf, IPPROTO_ICMP);
return net_calc_chksum(pkt, IPPROTO_ICMP);
}
static inline uint16_t net_calc_chksum_udp(struct net_buf *buf)
static inline uint16_t net_calc_chksum_udp(struct net_pkt *pkt)
{
return net_calc_chksum(buf, IPPROTO_UDP);
return net_calc_chksum(pkt, IPPROTO_UDP);
}
static inline uint16_t net_calc_chksum_tcp(struct net_buf *buf)
static inline uint16_t net_calc_chksum_tcp(struct net_pkt *pkt)
{
return net_calc_chksum(buf, IPPROTO_TCP);
return net_calc_chksum(pkt, IPPROTO_TCP);
}
#if NET_LOG_ENABLED > 0
@ -143,26 +143,26 @@ static inline void net_hexdump(const char *str, const uint8_t *packet,
}
/* Hexdump from all fragments */
static inline void net_hexdump_frags(const char *str, struct net_buf *buf)
static inline void net_hexdump_frags(const char *str, struct net_pkt *pkt)
{
struct net_buf *frag = buf->frags;
struct net_buf *frag = pkt->frags;
while (frag) {
net_hexdump(str, frag->data, net_pkt_get_len(frag));
net_hexdump(str, frag->data, frag->len);
frag = frag->frags;
}
}
/* Print fragment chain */
static inline void net_print_frags(const char *str, struct net_buf *buf)
static inline void net_print_frags(const char *str, struct net_pkt *pkt)
{
struct net_buf *frag = buf->frags;
struct net_buf *frag = pkt->frags;
if (str) {
printk("%s", str);
}
printk("%p[%d]", buf, buf->ref);
printk("%p[%d]", pkt, pkt->ref);
if (frag) {
printk("->");

View file

@ -509,7 +509,8 @@ static void ipv6_frag_cb(struct net_ipv6_reassembly *reass,
#endif /* CONFIG_NET_IPV6_FRAGMENT */
#if defined(CONFIG_NET_DEBUG_NET_PKT)
static void allocs_cb(struct net_buf *buf,
static void allocs_cb(struct net_pkt *pkt,
struct net_buf *buf,
const char *func_alloc,
int line_alloc,
const char *func_free,
@ -529,6 +530,24 @@ static void allocs_cb(struct net_buf *buf,
}
}
if (buf) {
goto buf;
}
if (func_alloc) {
if (in_use) {
printk("%p/%d\t%5s\t%5s\t%s():%d\n", pkt, pkt->ref,
str, net_pkt_slab2str(pkt->slab), func_alloc,
line_alloc);
} else {
printk("%p\t%5s\t%5s\t%s():%d -> %s():%d\n", pkt,
str, net_pkt_slab2str(pkt->slab), func_alloc,
line_alloc, func_free, line_free);
}
}
return;
buf:
if (func_alloc) {
if (in_use) {
printk("%p/%d\t%5s\t%5s\t%s():%d\n", buf, buf->ref,
@ -551,8 +570,8 @@ static int shell_cmd_allocs(int argc, char *argv[])
ARG_UNUSED(argv);
#if defined(CONFIG_NET_DEBUG_NET_PKT)
printk("Network buffer allocations\n\n");
printk("net_buf\t\tStatus\tPool\tFunction alloc -> freed\n");
printk("Network memory allocations\n\n");
printk("memory\t\tStatus\tPool\tFunction alloc -> freed\n");
net_pkt_allocs_foreach(allocs_cb, NULL);
#else
printk("Enable CONFIG_NET_DEBUG_NET_PKT to see allocations.\n");
@ -806,21 +825,27 @@ static int shell_cmd_iface(int argc, char *argv[])
struct ctx_info {
int pos;
bool are_external_pools;
struct net_buf_pool *tx_pools[CONFIG_NET_MAX_CONTEXTS];
struct k_mem_slab *tx_slabs[CONFIG_NET_MAX_CONTEXTS];
struct net_buf_pool *data_pools[CONFIG_NET_MAX_CONTEXTS];
};
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
static bool pool_found_already(struct ctx_info *info,
static bool slab_pool_found_already(struct ctx_info *info,
struct k_mem_slab *slab,
struct net_buf_pool *pool)
{
int i;
for (i = 0; i < CONFIG_NET_MAX_CONTEXTS; i++) {
if (info->tx_pools[i] == pool ||
info->data_pools[i] == pool) {
if (slab) {
if (info->tx_slabs[i] == slab) {
return true;
}
} else {
if (info->data_pools[i] == pool) {
return true;
}
}
}
return false;
@ -831,34 +856,35 @@ static void context_info(struct net_context *context, void *user_data)
{
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
struct ctx_info *info = user_data;
struct k_mem_slab *slab;
struct net_buf_pool *pool;
if (!net_context_is_used(context)) {
return;
}
if (context->tx_pool) {
pool = context->tx_pool();
if (context->tx_slab) {
slab = context->tx_slab();
if (pool_found_already(info, pool)) {
if (slab_pool_found_already(info, slab, NULL)) {
return;
}
#if defined(CONFIG_NET_DEBUG_NET_PKT)
printk("ETX (%s)\t%d\t%d\t%d\t%p\n",
pool->name, pool->pool_size, pool->buf_count,
pool->avail_count, pool);
printk("ETX\t%zu\t%u\t%u\t%p\n",
slab->num_blocks * slab->block_size,
slab->num_blocks, k_mem_slab_num_free_get(slab), slab);
#else
printk("ETX \t%d\t%p\n", pool->buf_count, pool);
printk("ETX \t%d\t%p\n", slab->num_blocks, slab);
#endif
info->are_external_pools = true;
info->tx_pools[info->pos] = pool;
info->tx_slabs[info->pos] = slab;
}
if (context->data_pool) {
pool = context->data_pool();
if (pool_found_already(info, pool)) {
if (slab_pool_found_already(info, NULL, pool)) {
return;
}
@ -879,7 +905,8 @@ static void context_info(struct net_context *context, void *user_data)
static int shell_cmd_mem(int argc, char *argv[])
{
struct net_buf_pool *tx, *rx, *rx_data, *tx_data;
struct k_mem_slab *rx, *tx;
struct net_buf_pool *rx_data, *tx_data;
ARG_UNUSED(argc);
ARG_UNUSED(argv);
@ -893,11 +920,13 @@ static int shell_cmd_mem(int argc, char *argv[])
#if defined(CONFIG_NET_DEBUG_NET_PKT)
printk("Name\t\t\tSize\tCount\tAvail\tAddress\n");
printk("RX (%s)\t\t%d\t%d\t%d\t%p\n",
rx->name, rx->pool_size, rx->buf_count, rx->avail_count, rx);
printk("RX\t\t%zu\t%d\t%u\t%p\n",
rx->num_blocks * rx->block_size,
rx->num_blocks, k_mem_slab_num_free_get(rx), rx);
printk("TX (%s)\t\t%d\t%d\t%d\t%p\n",
tx->name, tx->pool_size, tx->buf_count, tx->avail_count, tx);
printk("TX\t\t%zu\t%d\t%u\t%p\n",
tx->num_blocks * tx->block_size,
tx->num_blocks, k_mem_slab_num_free_get(tx), tx);
printk("RX DATA (%s)\t%d\t%d\t%d\t%p\n",
rx_data->name, rx_data->pool_size, rx_data->buf_count,
@ -909,8 +938,8 @@ static int shell_cmd_mem(int argc, char *argv[])
#else
printk("Name \tCount\tAddress\n");
printk("RX \t%d\t%p\n", rx->buf_count, rx);
printk("TX \t%d\t%p\n", tx->buf_count, tx);
printk("RX \t%d\t%p\n", rx->num_blocks, rx);
printk("TX \t%d\t%p\n", tx->num_blocks, tx);
printk("RX DATA \t%d\t%p\n", rx_data->buf_count, rx_data);
printk("TX DATA \t%d\t%p\n", tx_data->buf_count, tx_data);
#endif /* CONFIG_NET_DEBUG_NET_PKT */
@ -1018,7 +1047,7 @@ K_SEM_DEFINE(ping_timeout, 0, 1);
#if defined(CONFIG_NET_IPV6)
static enum net_verdict _handle_ipv6_echo_reply(struct net_buf *buf);
static enum net_verdict _handle_ipv6_echo_reply(struct net_pkt *pkt);
static struct net_icmpv6_handler ping6_handler = {
.type = NET_ICMPV6_ECHO_REPLY,
@ -1031,15 +1060,15 @@ static inline void _remove_ipv6_ping_handler(void)
net_icmpv6_unregister_handler(&ping6_handler);
}
static enum net_verdict _handle_ipv6_echo_reply(struct net_buf *buf)
static enum net_verdict _handle_ipv6_echo_reply(struct net_pkt *pkt)
{
char addr[NET_IPV6_ADDR_LEN];
snprintk(addr, sizeof(addr), "%s",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->dst));
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->dst));
printk("Received echo reply from %s to %s\n",
net_sprint_ipv6_addr(&NET_IPV6_BUF(buf)->src), addr);
net_sprint_ipv6_addr(&NET_IPV6_BUF(pkt)->src), addr);
k_sem_give(&ping_timeout);
_remove_ipv6_ping_handler();
@ -1077,7 +1106,7 @@ static int _ping_ipv6(char *host)
#if defined(CONFIG_NET_IPV4)
static enum net_verdict _handle_ipv4_echo_reply(struct net_buf *buf);
static enum net_verdict _handle_ipv4_echo_reply(struct net_pkt *pkt);
static struct net_icmpv4_handler ping4_handler = {
.type = NET_ICMPV4_ECHO_REPLY,
@ -1090,15 +1119,15 @@ static inline void _remove_ipv4_ping_handler(void)
net_icmpv4_unregister_handler(&ping4_handler);
}
static enum net_verdict _handle_ipv4_echo_reply(struct net_buf *buf)
static enum net_verdict _handle_ipv4_echo_reply(struct net_pkt *pkt)
{
char addr[NET_IPV4_ADDR_LEN];
snprintk(addr, sizeof(addr), "%s",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->dst));
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->dst));
printk("Received echo reply from %s to %s\n",
net_sprint_ipv4_addr(&NET_IPV4_BUF(buf)->src), addr);
net_sprint_ipv4_addr(&NET_IPV4_BUF(pkt)->src), addr);
k_sem_give(&ping_timeout);
_remove_ipv4_ping_handler();
@ -1470,7 +1499,7 @@ static int shell_cmd_tcp(int argc, char *argv[])
if (!strcmp(argv[arg], "send")) {
/* tcp send <data> */
struct net_buf *buf;
struct net_pkt *pkt;
if (!tcp_ctx || !net_context_is_used(tcp_ctx)) {
printk("Not connected\n");
@ -1482,25 +1511,25 @@ static int shell_cmd_tcp(int argc, char *argv[])
return 0;
}
buf = net_pkt_get_tx(tcp_ctx, TCP_TIMEOUT);
if (!buf) {
printk("Out of bufs, msg cannot be sent.\n");
pkt = net_pkt_get_tx(tcp_ctx, TCP_TIMEOUT);
if (!pkt) {
printk("Out of pkts, msg cannot be sent.\n");
return 0;
}
ret = net_pkt_append(buf, strlen(argv[arg]),
ret = net_pkt_append(pkt, strlen(argv[arg]),
argv[arg], TCP_TIMEOUT);
if (!ret) {
printk("Cannot build msg (out of bufs)\n");
net_pkt_unref(buf);
printk("Cannot build msg (out of pkts)\n");
net_pkt_unref(pkt);
return 0;
}
ret = net_context_send(buf, tcp_sent_cb, TCP_TIMEOUT,
ret = net_context_send(pkt, tcp_sent_cb, TCP_TIMEOUT,
NULL, NULL);
if (ret < 0) {
printk("Cannot send msg (%d)\n", ret);
net_pkt_unref(buf);
net_pkt_unref(pkt);
return 0;
}
@ -1550,14 +1579,14 @@ static int shell_cmd_help(int argc, char *argv[])
ARG_UNUSED(argv);
/* Keep the commands in alphabetical order */
printk("net allocs\n\tPrint network buffer allocations\n");
printk("net allocs\n\tPrint network memory allocations\n");
printk("net conn\n\tPrint information about network connections\n");
printk("net dns\n\tShow how DNS is configured\n");
printk("net dns cancel\n\tCancel all pending requests\n");
printk("net dns <hostname> [A or AAAA]\n\tQuery IPv4 address (default)"
" or IPv6 address for a host name\n");
printk("net iface\n\tPrint information about network interfaces\n");
printk("net mem\n\tPrint network buffer information\n");
printk("net mem\n\tPrint network memory information\n");
printk("net nbr\n\tPrint neighbor information\n");
printk("net nbr rm <IPv6 address>\n\tRemove neighbor from cache\n");
printk("net ping <host>\n\tPing a network host\n");

View file

@ -716,12 +716,12 @@ bool net_route_get_info(struct net_if *iface,
return false;
}
int net_route_packet(struct net_buf *buf, struct in6_addr *nexthop)
int net_route_packet(struct net_pkt *pkt, struct in6_addr *nexthop)
{
struct net_linkaddr_storage *lladdr;
struct net_nbr *nbr;
nbr = net_ipv6_nbr_lookup(net_pkt_iface(buf), nexthop);
nbr = net_ipv6_nbr_lookup(net_pkt_iface(pkt), nexthop);
if (!nbr) {
NET_DBG("Cannot find %s neighbor.",
net_sprint_ipv6_addr(nexthop));
@ -738,25 +738,25 @@ int net_route_packet(struct net_buf *buf, struct in6_addr *nexthop)
/* Sanitycheck: If src and dst ll addresses are going to be same,
* then something went wrong in route lookup.
*/
if (!memcmp(net_pkt_ll_src(buf)->addr, lladdr->addr, lladdr->len)) {
if (!memcmp(net_pkt_ll_src(pkt)->addr, lladdr->addr, lladdr->len)) {
NET_ERR("Src ll and Dst ll are same");
return -EINVAL;
}
net_pkt_set_forwarding(buf, true);
net_pkt_set_forwarding(pkt, true);
/* Set the destination and source ll address in the packet.
* We set the destination address to be the nexthop recipient.
*/
net_pkt_ll_src(buf)->addr = net_pkt_ll_if(buf)->addr;
net_pkt_ll_src(buf)->type = net_pkt_ll_if(buf)->type;
net_pkt_ll_src(buf)->len = net_pkt_ll_if(buf)->len;
net_pkt_ll_src(pkt)->addr = net_pkt_ll_if(pkt)->addr;
net_pkt_ll_src(pkt)->type = net_pkt_ll_if(pkt)->type;
net_pkt_ll_src(pkt)->len = net_pkt_ll_if(pkt)->len;
net_pkt_ll_dst(buf)->addr = lladdr->addr;
net_pkt_ll_dst(buf)->type = lladdr->type;
net_pkt_ll_dst(buf)->len = lladdr->len;
net_pkt_ll_dst(pkt)->addr = lladdr->addr;
net_pkt_ll_dst(pkt)->type = lladdr->type;
net_pkt_ll_dst(pkt)->len = lladdr->len;
return net_send_data(buf);
return net_send_data(pkt);
}
void net_route_init(void)

View file

@ -251,12 +251,12 @@ bool net_route_get_info(struct net_if *iface,
/**
* @brief Send the network packet to network via some intermediate host.
*
* @param buf Network buffer to send.
* @param pkt Network packet to send.
* @param nexthop Next hop neighbor IPv6 address.
*
* @return 0 if there was no error, <0 if the packet could not be sent.
*/
int net_route_packet(struct net_buf *buf, struct in6_addr *nexthop);
int net_route_packet(struct net_pkt *pkt, struct in6_addr *nexthop);
#else /* CONFIG_NET_ROUTE */
#define net_route_init(...)

File diff suppressed because it is too large Load diff

View file

@ -909,17 +909,17 @@ void net_rpl_global_repair(struct net_route_entry *route);
/**
* @brief Update RPL headers in IPv6 packet.
*
* @param buf Network buffer.
* @param pkt Network packet.
* @param addr IPv6 address of next hop host.
*
* @return 0 if ok, < 0 if error
*/
int net_rpl_update_header(struct net_buf *buf, struct in6_addr *addr);
int net_rpl_update_header(struct net_pkt *pkt, struct in6_addr *addr);
/**
* @brief Verify RPL header in IPv6 packet.
*
* @param buf Network buffer fragment list.
* @param pkt Network packet fragment list.
* @param frag Current network buffer fragment.
* @param offset Where the RPL header starts in the packet
* @param pos How long the RPL header was, this is returned to the caller.
@ -927,30 +927,30 @@ int net_rpl_update_header(struct net_buf *buf, struct in6_addr *addr);
*
* @return frag Returns the fragment where this call finished reading.
*/
struct net_buf *net_rpl_verify_header(struct net_buf *buf, struct net_buf *frag,
struct net_buf *net_rpl_verify_header(struct net_pkt *pkt, struct net_buf *frag,
uint16_t offset, uint16_t *pos,
bool *result);
/**
* @brief Insert RPL extension header to IPv6 packet.
*
* @param buf Network buffer.
* @param pkt Network packet.
*
* @return 0 if ok, <0 if error.
*/
int net_rpl_insert_header(struct net_buf *buf);
int net_rpl_insert_header(struct net_pkt *pkt);
/**
* @brief Revert RPL extension header to IPv6 packet.
* Revert flags, instance ID and sender rank in the packet.
*
* @param buf Network buffer.
* @param pkt Network packet.
* @param offset Where the HBH header starts in the packet
* @param pos How long the RPL header was, this is returned to the caller.
*
* @return 0 if ok, <0 if error.
*/
int net_rpl_revert_header(struct net_buf *buf, uint16_t offset, uint16_t *pos);
int net_rpl_revert_header(struct net_pkt *pkt, uint16_t offset, uint16_t *pos);
/**
* @brief Get parent IPv6 address.

View file

@ -72,12 +72,12 @@ static char upper_if_set(char chr, bool set)
return chr | 0x20;
}
static void net_tcp_trace(struct net_buf *buf, struct net_tcp *tcp)
static void net_tcp_trace(struct net_pkt *pkt, struct net_tcp *tcp)
{
uint8_t flags = NET_TCP_FLAGS(buf);
uint8_t flags = NET_TCP_FLAGS(pkt);
uint32_t rel_ack, ack;
ack = sys_get_be32(NET_TCP_BUF(buf)->ack);
ack = sys_get_be32(NET_TCP_BUF(pkt)->ack);
if (!tcp->sent_ack) {
rel_ack = 0;
@ -85,12 +85,12 @@ static void net_tcp_trace(struct net_buf *buf, struct net_tcp *tcp)
rel_ack = ack ? ack - tcp->sent_ack : 0;
}
NET_DBG("buf %p src %u dst %u seq 0x%04x ack 0x%04x (%u) "
NET_DBG("pkt %p src %u dst %u seq 0x%04x ack 0x%04x (%u) "
"flags %c%c%c%c%c%c win %u chk 0x%04x",
buf,
ntohs(NET_TCP_BUF(buf)->src_port),
ntohs(NET_TCP_BUF(buf)->dst_port),
sys_get_be32(NET_TCP_BUF(buf)->seq),
pkt,
ntohs(NET_TCP_BUF(pkt)->src_port),
ntohs(NET_TCP_BUF(pkt)->dst_port),
sys_get_be32(NET_TCP_BUF(pkt)->seq),
ack,
/* This tells how many bytes we are acking now */
rel_ack,
@ -100,8 +100,8 @@ static void net_tcp_trace(struct net_buf *buf, struct net_tcp *tcp)
upper_if_set('r', flags & NET_TCP_RST),
upper_if_set('s', flags & NET_TCP_SYN),
upper_if_set('f', flags & NET_TCP_FIN),
sys_get_be16(NET_TCP_BUF(buf)->wnd),
ntohs(NET_TCP_BUF(buf)->chksum));
sys_get_be16(NET_TCP_BUF(pkt)->wnd),
ntohs(NET_TCP_BUF(pkt)->chksum));
}
#else
#define net_tcp_trace(...)
@ -118,30 +118,30 @@ static inline uint32_t retry_timeout(const struct net_tcp *tcp)
return ((uint32_t)1 << tcp->retry_timeout_shift) * INIT_RETRY_MS;
}
#define is_6lo_technology(buf) \
(IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(buf) == AF_INET6 && \
#define is_6lo_technology(pkt) \
(IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6 && \
((IS_ENABLED(CONFIG_NET_L2_BLUETOOTH) && \
net_pkt_ll_dst(buf)->type == NET_LINK_BLUETOOTH) || \
net_pkt_ll_dst(pkt)->type == NET_LINK_BLUETOOTH) || \
(IS_ENABLED(CONFIG_NET_L2_IEEE802154) && \
net_pkt_ll_dst(buf)->type == NET_LINK_IEEE802154)))
net_pkt_ll_dst(pkt)->type == NET_LINK_IEEE802154)))
static inline void do_ref_if_needed(struct net_buf *buf)
static inline void do_ref_if_needed(struct net_pkt *pkt)
{
/* The ref should not be done for Bluetooth and IEEE 802.15.4 which use
* IPv6 header compression (6lo). For BT and 802.15.4 we copy the buf
* IPv6 header compression (6lo). For BT and 802.15.4 we copy the pkt
* chain we are about to send so it is fine if the network driver
* releases it. As we have our own copy of the sent data, we do not
* need to take a reference of it. See also net_tcp_send_buf().
* need to take a reference of it. See also net_tcp_send_pkt().
*/
if (!is_6lo_technology(buf)) {
buf = net_pkt_ref(buf);
if (!is_6lo_technology(pkt)) {
pkt = net_pkt_ref(pkt);
}
}
static void tcp_retry_expired(struct k_timer *timer)
{
struct net_tcp *tcp = CONTAINER_OF(timer, struct net_tcp, retry_timer);
struct net_buf *buf;
struct net_pkt *pkt;
/* Double the retry period for exponential backoff and resent
* the first (only the first!) unack'd packet.
@ -150,12 +150,12 @@ static void tcp_retry_expired(struct k_timer *timer)
tcp->retry_timeout_shift++;
k_timer_start(&tcp->retry_timer, retry_timeout(tcp), 0);
buf = CONTAINER_OF(sys_slist_peek_head(&tcp->sent_list),
struct net_buf, sent_list);
pkt = CONTAINER_OF(sys_slist_peek_head(&tcp->sent_list),
struct net_pkt, sent_list);
do_ref_if_needed(buf);
if (net_tcp_send_buf(buf) < 0 && !is_6lo_technology(buf)) {
net_pkt_unref(buf);
do_ref_if_needed(pkt);
if (net_tcp_send_pkt(pkt) < 0 && !is_6lo_technology(pkt)) {
net_pkt_unref(pkt);
}
} else if (IS_ENABLED(CONFIG_NET_TCP_TIME_WAIT)) {
if (tcp->fin_sent && tcp->fin_rcvd) {
@ -200,18 +200,18 @@ struct net_tcp *net_tcp_alloc(struct net_context *context)
int net_tcp_release(struct net_tcp *tcp)
{
struct net_buf *buf;
struct net_buf *tmp;
struct net_pkt *pkt;
struct net_pkt *tmp;
int key;
if (!PART_OF_ARRAY(tcp_context, tcp)) {
return -EINVAL;
}
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&tcp->sent_list, buf, tmp,
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&tcp->sent_list, pkt, tmp,
sent_list) {
sys_slist_remove(&tcp->sent_list, NULL, &buf->sent_list);
net_pkt_unref(buf);
sys_slist_remove(&tcp->sent_list, NULL, &pkt->sent_list);
net_pkt_unref(pkt);
}
k_delayed_work_cancel(&tcp->ack_timer);
@ -247,16 +247,16 @@ static inline uint8_t net_tcp_add_options(struct net_buf *header, size_t len,
return optlen;
}
static int finalize_segment(struct net_context *context, struct net_buf *buf)
static int finalize_segment(struct net_context *context, struct net_pkt *pkt)
{
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
return net_ipv4_finalize(context, buf);
if (net_pkt_family(pkt) == AF_INET) {
return net_ipv4_finalize(context, pkt);
} else
#endif
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
return net_ipv6_finalize(context, buf);
if (net_pkt_family(pkt) == AF_INET6) {
return net_ipv6_finalize(context, pkt);
}
#endif
{
@ -265,9 +265,9 @@ static int finalize_segment(struct net_context *context, struct net_buf *buf)
return 0;
}
static struct net_buf *prepare_segment(struct net_tcp *tcp,
static struct net_pkt *prepare_segment(struct net_tcp *tcp,
struct tcp_segment *segment,
struct net_buf *buf)
struct net_pkt *pkt)
{
struct net_buf *header, *tail = NULL;
struct net_tcp_hdr *tcphdr;
@ -277,49 +277,49 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp,
NET_ASSERT(context);
if (buf) {
if (pkt) {
/* TCP transmit data comes in with a pre-allocated
* net_pkt at the head (so that net_context_send can find
* the context), and the data after. Rejigger so we
* can insert a TCP header cleanly
*/
tail = buf->frags;
buf->frags = NULL;
tail = pkt->frags;
pkt->frags = NULL;
} else {
buf = net_pkt_get_tx(context, K_FOREVER);
pkt = net_pkt_get_tx(context, K_FOREVER);
}
#if defined(CONFIG_NET_IPV4)
if (net_pkt_family(buf) == AF_INET) {
net_ipv4_create(context, buf,
if (net_pkt_family(pkt) == AF_INET) {
net_ipv4_create(context, pkt,
net_sin_ptr(segment->src_addr)->sin_addr,
&(net_sin(segment->dst_addr)->sin_addr));
dst_port = net_sin(segment->dst_addr)->sin_port;
src_port = ((struct sockaddr_in_ptr *)&context->local)->
sin_port;
NET_IPV4_BUF(buf)->proto = IPPROTO_TCP;
NET_IPV4_BUF(pkt)->proto = IPPROTO_TCP;
} else
#endif
#if defined(CONFIG_NET_IPV6)
if (net_pkt_family(buf) == AF_INET6) {
net_ipv6_create(tcp->context, buf,
if (net_pkt_family(pkt) == AF_INET6) {
net_ipv6_create(tcp->context, pkt,
net_sin6_ptr(segment->src_addr)->sin6_addr,
&(net_sin6(segment->dst_addr)->sin6_addr));
dst_port = net_sin6(segment->dst_addr)->sin6_port;
src_port = ((struct sockaddr_in6_ptr *)&context->local)->
sin6_port;
NET_IPV6_BUF(buf)->nexthdr = IPPROTO_TCP;
NET_IPV6_BUF(pkt)->nexthdr = IPPROTO_TCP;
} else
#endif
{
NET_DBG("Protocol family %d not supported",
net_pkt_family(buf));
net_pkt_unref(buf);
net_pkt_family(pkt));
net_pkt_unref(pkt);
return NULL;
}
header = net_pkt_get_data(context, K_FOREVER);
net_buf_frag_add(buf, header);
net_pkt_frag_add(pkt, header);
tcphdr = (struct net_tcp_hdr *)net_buf_add(header, NET_TCPH_LEN);
@ -340,17 +340,17 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp,
tcphdr->urg[1] = 0;
if (tail) {
net_buf_frag_add(buf, tail);
net_pkt_frag_add(pkt, tail);
}
if (finalize_segment(context, buf) < 0) {
net_pkt_unref(buf);
if (finalize_segment(context, pkt) < 0) {
net_pkt_unref(pkt);
return NULL;
}
net_tcp_trace(buf, tcp);
net_tcp_trace(pkt, tcp);
return buf;
return pkt;
}
static inline uint32_t get_recv_wnd(struct net_tcp *tcp)
@ -379,7 +379,7 @@ int net_tcp_prepare_segment(struct net_tcp *tcp, uint8_t flags,
void *options, size_t optlen,
const struct sockaddr_ptr *local,
const struct sockaddr *remote,
struct net_buf **send_buf)
struct net_pkt **send_pkt)
{
uint32_t seq;
uint16_t wnd;
@ -437,8 +437,8 @@ int net_tcp_prepare_segment(struct net_tcp *tcp, uint8_t flags,
segment.options = options;
segment.optlen = optlen;
*send_buf = prepare_segment(tcp, &segment, *send_buf);
if (!*send_buf) {
*send_pkt = prepare_segment(tcp, &segment, *send_pkt);
if (!*send_pkt) {
return -EINVAL;
}
@ -530,7 +530,7 @@ static void net_tcp_set_syn_opt(struct net_tcp *tcp, uint8_t *options,
}
int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
struct net_buf **buf)
struct net_pkt **pkt)
{
uint8_t options[NET_TCP_MAX_OPT_SIZE];
uint8_t optionlen;
@ -546,7 +546,7 @@ int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
return net_tcp_prepare_segment(tcp, NET_TCP_SYN | NET_TCP_ACK,
options, optionlen, NULL, remote,
buf);
pkt);
case NET_TCP_FIN_WAIT_1:
case NET_TCP_LAST_ACK:
/* In the FIN_WAIT_1 and LAST_ACK states acknowledgment must
@ -555,10 +555,10 @@ int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
tcp->send_seq--;
return net_tcp_prepare_segment(tcp, NET_TCP_FIN | NET_TCP_ACK,
0, 0, NULL, remote, buf);
0, 0, NULL, remote, pkt);
default:
return net_tcp_prepare_segment(tcp, NET_TCP_ACK, 0, 0, NULL,
remote, buf);
remote, pkt);
}
return -EINVAL;
@ -566,7 +566,7 @@ int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
int net_tcp_prepare_reset(struct net_tcp *tcp,
const struct sockaddr *remote,
struct net_buf **buf)
struct net_pkt **pkt)
{
struct tcp_segment segment = { 0 };
@ -590,7 +590,7 @@ int net_tcp_prepare_reset(struct net_tcp *tcp,
segment.options = NULL;
segment.optlen = 0;
*buf = prepare_segment(tcp, &segment, NULL);
*pkt = prepare_segment(tcp, &segment, NULL);
}
return 0;
@ -630,10 +630,10 @@ const char * const net_tcp_state_str(enum net_tcp_state state)
return "";
}
int net_tcp_queue_data(struct net_context *context, struct net_buf *buf)
int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt)
{
struct net_conn *conn = (struct net_conn *)context->conn_handler;
size_t data_len = net_buf_frags_len(buf);
size_t data_len = net_pkt_get_len(pkt);
int ret;
/* Set PSH on all packets, our window is so small that there's
@ -641,14 +641,14 @@ int net_tcp_queue_data(struct net_context *context, struct net_buf *buf)
* coalesce packets.
*/
ret = net_tcp_prepare_segment(context->tcp, NET_TCP_PSH | NET_TCP_ACK,
NULL, 0, NULL, &conn->remote_addr, &buf);
NULL, 0, NULL, &conn->remote_addr, &pkt);
if (ret) {
return ret;
}
context->tcp->send_seq += data_len;
sys_slist_append(&context->tcp->sent_list, &buf->sent_list);
sys_slist_append(&context->tcp->sent_list, &pkt->sent_list);
/* We need to restart retry_timer if it is stopped. */
if (k_timer_remaining_get(&context->tcp->retry_timer) == 0) {
@ -656,15 +656,15 @@ int net_tcp_queue_data(struct net_context *context, struct net_buf *buf)
retry_timeout(context->tcp), 0);
}
do_ref_if_needed(buf);
do_ref_if_needed(pkt);
return 0;
}
int net_tcp_send_buf(struct net_buf *buf)
int net_tcp_send_pkt(struct net_pkt *pkt)
{
struct net_context *ctx = net_pkt_context(buf);
struct net_tcp_hdr *tcphdr = NET_TCP_BUF(buf);
struct net_context *ctx = net_pkt_context(pkt);
struct net_tcp_hdr *tcphdr = NET_TCP_BUF(pkt);
sys_put_be32(ctx->tcp->send_ack, tcphdr->ack);
@ -683,58 +683,58 @@ int net_tcp_send_buf(struct net_buf *buf)
ctx->tcp->sent_ack = ctx->tcp->send_ack;
net_pkt_set_buf_sent(buf, true);
net_pkt_set_sent(pkt, true);
/* We must have special handling for some network technologies that
* tweak the IP protocol headers during packet sending. This happens
* with Bluetooth and IEEE 802.15.4 which use IPv6 header compression
* (6lo) and alter the sent network buffer. So in order to avoid any
* (6lo) and alter the sent network packet. So in order to avoid any
* corruption of the original data buffer, we must copy the sent data.
* For Bluetooth, its fragmentation code will even mangle the data
* part of the message so we need to copy those too.
*/
if (is_6lo_technology(buf)) {
struct net_buf *new_buf, *check_buf;
if (is_6lo_technology(pkt)) {
struct net_pkt *new_pkt, *check_pkt;
int ret;
bool buf_in_slist = false;
bool pkt_in_slist = false;
/*
* There are users of this function that don't add buf to TCP
* There are users of this function that don't add pkt to TCP
* sent_list. (See send_ack() in net_context.c) In these cases,
* we should avoid the extra 6lowpan specific buffer copy
* below.
*/
SYS_SLIST_FOR_EACH_CONTAINER(&ctx->tcp->sent_list,
check_buf, sent_list) {
if (check_buf == buf) {
buf_in_slist = true;
check_pkt, sent_list) {
if (check_pkt == pkt) {
pkt_in_slist = true;
break;
}
}
if (buf_in_slist) {
new_buf = net_pkt_get_tx(ctx, K_FOREVER);
if (pkt_in_slist) {
new_pkt = net_pkt_get_tx(ctx, K_FOREVER);
new_buf->frags = net_pkt_copy_all(buf, 0, K_FOREVER);
net_pkt_copy_user_data(new_buf, buf);
memcpy(new_pkt, pkt, sizeof(struct net_pkt));
new_pkt->frags = net_pkt_copy_all(pkt, 0, K_FOREVER);
NET_DBG("Copied %zu bytes from %p to %p",
net_buf_frags_len(new_buf), buf, new_buf);
net_pkt_get_len(new_pkt), pkt, new_pkt);
/* This function is called from net_context.c and if we
* return < 0, the caller will unref the original buf.
* This would leak the new_buf so remove it here.
* return < 0, the caller will unref the original pkt.
* This would leak the new_pkt so remove it here.
*/
ret = net_send_data(new_buf);
ret = net_send_data(new_pkt);
if (ret < 0) {
net_pkt_unref(new_buf);
net_pkt_unref(new_pkt);
}
return ret;
}
}
return net_send_data(buf);
return net_send_data(pkt);
}
static void restart_timer(struct net_tcp *tcp)
@ -759,16 +759,16 @@ static void restart_timer(struct net_tcp *tcp)
int net_tcp_send_data(struct net_context *context)
{
struct net_buf *buf;
struct net_pkt *pkt;
/* For now, just send all queued data synchronously. Need to
* add window handling and retry/ACK logic.
*/
SYS_SLIST_FOR_EACH_CONTAINER(&context->tcp->sent_list, buf, sent_list) {
if (!net_pkt_buf_sent(buf)) {
if (net_tcp_send_buf(buf) < 0 &&
!is_6lo_technology(buf)) {
net_pkt_unref(buf);
SYS_SLIST_FOR_EACH_CONTAINER(&context->tcp->sent_list, pkt, sent_list) {
if (!net_pkt_sent(pkt)) {
if (net_tcp_send_pkt(pkt) < 0 &&
!is_6lo_technology(pkt)) {
net_pkt_unref(pkt);
}
}
}
@ -781,17 +781,17 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack)
struct net_tcp *tcp = ctx->tcp;
sys_slist_t *list = &ctx->tcp->sent_list;
sys_snode_t *head;
struct net_buf *buf;
struct net_pkt *pkt;
struct net_tcp_hdr *tcphdr;
uint32_t seq;
bool valid_ack = false;
while (!sys_slist_is_empty(list)) {
head = sys_slist_peek_head(list);
buf = CONTAINER_OF(head, struct net_buf, sent_list);
tcphdr = NET_TCP_BUF(buf);
pkt = CONTAINER_OF(head, struct net_pkt, sent_list);
tcphdr = NET_TCP_BUF(pkt);
seq = sys_get_be32(tcphdr->seq) + net_pkt_appdatalen(buf) - 1;
seq = sys_get_be32(tcphdr->seq) + net_pkt_appdatalen(pkt) - 1;
if (!seq_greater(ack, seq)) {
break;
@ -808,7 +808,7 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack)
}
sys_slist_remove(list, NULL, head);
net_pkt_unref(buf);
net_pkt_unref(pkt);
valid_ack = true;
}
@ -827,13 +827,13 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack)
* pipe is uncorked again.
*/
if (ctx->tcp->flags & NET_TCP_RETRYING) {
struct net_buf *buf;
struct net_pkt *pkt;
SYS_SLIST_FOR_EACH_CONTAINER(&ctx->tcp->sent_list, buf,
SYS_SLIST_FOR_EACH_CONTAINER(&ctx->tcp->sent_list, pkt,
sent_list) {
if (net_pkt_buf_sent(buf)) {
do_ref_if_needed(buf);
net_pkt_set_buf_sent(buf, false);
if (net_pkt_sent(pkt)) {
do_ref_if_needed(pkt);
net_pkt_set_sent(pkt, false);
}
}

View file

@ -234,7 +234,7 @@ int net_tcp_release(struct net_tcp *tcp);
* @param local Source address, or NULL to use the local address of
* the TCP context
* @param remote Peer address
* @param send_buf Full IP + TCP header that is to be sent.
* @param send_pkt Full IP + TCP header that is to be sent.
*
* @return 0 if ok, < 0 if error
*/
@ -242,31 +242,31 @@ int net_tcp_prepare_segment(struct net_tcp *tcp, uint8_t flags,
void *options, size_t optlen,
const struct sockaddr_ptr *local,
const struct sockaddr *remote,
struct net_buf **send_buf);
struct net_pkt **send_pkt);
/**
* @brief Prepare a TCP ACK message that can be send to peer.
*
* @param tcp TCP context
* @param remote Peer address
* @param buf Network buffer
* @param pkt Network buffer
*
* @return 0 if ok, < 0 if error
*/
int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
struct net_buf **buf);
struct net_pkt **pkt);
/**
* @brief Prepare a TCP RST message that can be send to peer.
*
* @param tcp TCP context
* @param remote Peer address
* @param buf Network buffer
* @param pkt Network buffer
*
* @return 0 if ok, < 0 if error
*/
int net_tcp_prepare_reset(struct net_tcp *tcp, const struct sockaddr *remote,
struct net_buf **buf);
struct net_pkt **pkt);
typedef void (*net_tcp_cb_t)(struct net_tcp *tcp, void *user_data);
@ -292,19 +292,19 @@ int net_tcp_send_data(struct net_context *context);
* @brief Enqueue a single packet for transmission
*
* @param context TCP context
* @param buf Packet
* @param pkt Packet
*
* @return 0 if ok, < 0 if error
*/
int net_tcp_queue_data(struct net_context *context, struct net_buf *buf);
int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt);
/**
* @brief Sends one TCP packet initialized with the _prepare_*()
* family of functions.
*
* @param buf Packet
* @param pkt Packet
*/
int net_tcp_send_buf(struct net_buf *buf);
int net_tcp_send_pkt(struct net_pkt *pkt);
/**
* @brief Handle a received TCP ACK

View file

@ -28,53 +28,53 @@ extern "C" {
#if defined(CONFIG_NET_UDP)
/**
* @brief Append UDP packet into net_buf
* @brief Append UDP packet into net_pkt
*
* @param buf Network buffer
* @param pkt Network packet
* @param src_port Source port in host byte order.
* @param dst_port Destination port in host byte order.
*
* @return Return network buffer that contains the UDP packet.
* @return Return network packet that contains the UDP packet.
*/
static inline struct net_buf *net_udp_append_raw(struct net_buf *buf,
static inline struct net_pkt *net_udp_append_raw(struct net_pkt *pkt,
uint16_t src_port,
uint16_t dst_port)
{
NET_UDP_BUF(buf)->src_port = htons(src_port);
NET_UDP_BUF(buf)->dst_port = htons(dst_port);
NET_UDP_BUF(pkt)->src_port = htons(src_port);
NET_UDP_BUF(pkt)->dst_port = htons(dst_port);
net_buf_add(buf->frags, sizeof(struct net_udp_hdr));
net_buf_add(pkt->frags, sizeof(struct net_udp_hdr));
NET_UDP_BUF(buf)->len = htons(net_buf_frags_len(buf) -
net_pkt_ip_hdr_len(buf));
NET_UDP_BUF(pkt)->len = htons(net_pkt_get_len(pkt) -
net_pkt_ip_hdr_len(pkt));
net_pkt_set_appdata(buf, net_pkt_udp_data(buf) +
net_pkt_set_appdata(pkt, net_pkt_udp_data(pkt) +
sizeof(struct net_udp_hdr));
return buf;
return pkt;
}
/**
* @brief Append UDP packet into net_buf
* @brief Append UDP packet into net_pkt
*
* @param context Network context for a connection
* @param buf Network buffer
* @param pkt Network packet
* @param port Destination port in host byte order.
*
* @return Return network buffer that contains the UDP packet.
* @return Return network packet that contains the UDP packet.
*/
static inline struct net_buf *net_udp_append(struct net_context *context,
struct net_buf *buf,
static inline struct net_pkt *net_udp_append(struct net_context *context,
struct net_pkt *pkt,
uint16_t port)
{
return net_udp_append_raw(buf,
return net_udp_append_raw(pkt,
ntohs(net_sin((struct sockaddr *)
&context->local)->sin_port),
port);
}
#else
#define net_udp_append_raw(buf, src_port, dst_port) (buf)
#define net_udp_append(context, buf, port) (buf)
#define net_udp_append_raw(pkt, src_port, dst_port) (pkt)
#define net_udp_append(context, pkt, port) (pkt)
#endif /* CONFIG_NET_UDP */
/**

View file

@ -400,12 +400,12 @@ static uint16_t calc_chksum(uint16_t sum, const uint8_t *ptr, uint16_t len)
return sum;
}
static inline uint16_t calc_chksum_buf(uint16_t sum, struct net_buf *buf,
static inline uint16_t calc_chksum_pkt(uint16_t sum, struct net_pkt *pkt,
uint16_t upper_layer_len)
{
struct net_buf *frag = buf->frags;
uint16_t proto_len = net_pkt_ip_hdr_len(buf) +
net_pkt_ext_len(buf);
struct net_buf *frag = pkt->frags;
uint16_t proto_len = net_pkt_ip_hdr_len(pkt) +
net_pkt_ext_len(pkt);
int16_t len = frag->len - proto_len;
uint8_t *ptr = frag->data + proto_len;
@ -443,45 +443,45 @@ static inline uint16_t calc_chksum_buf(uint16_t sum, struct net_buf *buf,
return sum;
}
uint16_t net_calc_chksum(struct net_buf *buf, uint8_t proto)
uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto)
{
uint16_t upper_layer_len;
uint16_t sum;
switch (net_pkt_family(buf)) {
switch (net_pkt_family(pkt)) {
#if defined(CONFIG_NET_IPV4)
case AF_INET:
upper_layer_len = (NET_IPV4_BUF(buf)->len[0] << 8) +
NET_IPV4_BUF(buf)->len[1] -
net_pkt_ext_len(buf) -
net_pkt_ip_hdr_len(buf);
upper_layer_len = (NET_IPV4_BUF(pkt)->len[0] << 8) +
NET_IPV4_BUF(pkt)->len[1] -
net_pkt_ext_len(pkt) -
net_pkt_ip_hdr_len(pkt);
if (proto == IPPROTO_ICMP) {
return htons(calc_chksum(0, net_pkt_ip_data(buf) +
net_pkt_ip_hdr_len(buf),
return htons(calc_chksum(0, net_pkt_ip_data(pkt) +
net_pkt_ip_hdr_len(pkt),
upper_layer_len));
} else {
sum = calc_chksum(upper_layer_len + proto,
(uint8_t *)&NET_IPV4_BUF(buf)->src,
(uint8_t *)&NET_IPV4_BUF(pkt)->src,
2 * sizeof(struct in_addr));
}
break;
#endif
#if defined(CONFIG_NET_IPV6)
case AF_INET6:
upper_layer_len = (NET_IPV6_BUF(buf)->len[0] << 8) +
NET_IPV6_BUF(buf)->len[1] - net_pkt_ext_len(buf);
upper_layer_len = (NET_IPV6_BUF(pkt)->len[0] << 8) +
NET_IPV6_BUF(pkt)->len[1] - net_pkt_ext_len(pkt);
sum = calc_chksum(upper_layer_len + proto,
(uint8_t *)&NET_IPV6_BUF(buf)->src,
(uint8_t *)&NET_IPV6_BUF(pkt)->src,
2 * sizeof(struct in6_addr));
break;
#endif
default:
NET_DBG("Unknown protocol family %d", net_pkt_family(buf));
NET_DBG("Unknown protocol family %d", net_pkt_family(pkt));
return 0;
}
sum = calc_chksum_buf(sum, buf, upper_layer_len);
sum = calc_chksum_pkt(sum, pkt, upper_layer_len);
sum = (sum == 0) ? 0xffff : htons(sum);
@ -489,11 +489,11 @@ uint16_t net_calc_chksum(struct net_buf *buf, uint8_t proto)
}
#if defined(CONFIG_NET_IPV4)
uint16_t net_calc_chksum_ipv4(struct net_buf *buf)
uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt)
{
uint16_t sum;
sum = calc_chksum(0, (uint8_t *)NET_IPV4_BUF(buf), NET_IPV4H_LEN);
sum = calc_chksum(0, (uint8_t *)NET_IPV4_BUF(pkt), NET_IPV4H_LEN);
sum = (sum == 0) ? 0xffff : htons(sum);

View file

@ -358,7 +358,7 @@ static inline int get_slot_by_id(struct dns_resolve_context *ctx,
}
static int dns_read(struct dns_resolve_context *ctx,
struct net_buf *buf,
struct net_pkt *pkt,
struct net_buf *dns_data,
uint16_t *dns_id,
struct net_buf *dns_cname,
@ -377,12 +377,12 @@ static int dns_read(struct dns_resolve_context *ctx,
int ret;
int server_idx, query_idx;
data_len = min(net_pkt_appdatalen(buf), DNS_RESOLVER_MAX_BUF_SIZE);
offset = net_buf_frags_len(buf) - data_len;
data_len = min(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE);
offset = net_pkt_get_len(pkt) - data_len;
/* TODO: Instead of this temporary copy, just use the net_buf directly.
/* TODO: Instead of this temporary copy, just use the net_pkt directly.
*/
ret = net_pkt_linear_copy(dns_data, buf, offset, data_len);
ret = net_frag_linear_copy(dns_data, pkt->frags, offset, data_len);
if (ret < 0) {
ret = DNS_EAI_MEMORY;
goto quit;
@ -526,7 +526,7 @@ static int dns_read(struct dns_resolve_context *ctx,
ctx->queries[query_idx].cb = NULL;
net_pkt_unref(buf);
net_pkt_unref(pkt);
return 0;
@ -534,13 +534,13 @@ finished:
dns_resolve_cancel(ctx, *dns_id);
quit:
net_pkt_unref(buf);
net_pkt_unref(pkt);
return ret;
}
static void cb_recv(struct net_context *net_ctx,
struct net_buf *buf,
struct net_pkt *pkt,
int status,
void *user_data)
{
@ -570,7 +570,7 @@ static void cb_recv(struct net_context *net_ctx,
goto quit;
}
ret = dns_read(ctx, buf, dns_data, &dns_id, dns_cname, &info);
ret = dns_read(ctx, pkt, dns_data, &dns_id, dns_cname, &info);
if (!ret) {
/* We called the callback already in dns_read() if there
* was no errors.
@ -643,7 +643,7 @@ static int dns_write(struct dns_resolve_context *ctx,
enum dns_query_type query_type;
struct net_context *net_ctx;
struct sockaddr *server;
struct net_buf *buf;
struct net_pkt *pkt;
int server_addr_len;
uint16_t dns_id;
int ret;
@ -661,13 +661,13 @@ static int dns_write(struct dns_resolve_context *ctx,
goto quit;
}
buf = net_pkt_get_tx(net_ctx, ctx->buf_timeout);
if (!buf) {
pkt = net_pkt_get_tx(net_ctx, ctx->buf_timeout);
if (!pkt) {
ret = -ENOMEM;
goto quit;
}
ret = net_pkt_append(buf, dns_data->len, dns_data->data,
ret = net_pkt_append(pkt, dns_data->len, dns_data->data,
ctx->buf_timeout);
if (ret < 0) {
ret = -ENOMEM;
@ -682,11 +682,11 @@ static int dns_write(struct dns_resolve_context *ctx,
net_context_recv(net_ctx, cb_recv, K_NO_WAIT, ctx);
ret = net_context_sendto(buf, server, server_addr_len, NULL,
ret = net_context_sendto(pkt, server, server_addr_len, NULL,
K_NO_WAIT, NULL, NULL);
if (ret < 0) {
NET_DBG("Cannot send query (%d)", ret);
net_pkt_unref(buf);
net_pkt_unref(pkt);
goto quit;
}

View file

@ -19,7 +19,7 @@
int http_request(struct net_context *net_ctx, int32_t timeout,
struct http_client_request *req)
{
struct net_buf *tx;
struct net_pkt *tx;
int rc = -ENOMEM;
tx = net_pkt_get_tx(net_ctx, timeout);
@ -97,7 +97,7 @@ int http_request(struct net_context *net_ctx, int32_t timeout,
return net_context_send(tx, NULL, timeout, NULL, NULL);
lb_exit:
net_buf_unref(tx);
net_pkt_unref(tx);
return rc;
}

View file

@ -32,7 +32,7 @@ static inline uint16_t http_strlen(const char *str)
return 0;
}
static int http_add_header(struct net_buf *tx, int32_t timeout, const char *str)
static int http_add_header(struct net_pkt *tx, int32_t timeout, const char *str)
{
if (net_pkt_append(tx, strlen(str), (uint8_t *)str, timeout)) {
return 0;
@ -41,7 +41,7 @@ static int http_add_header(struct net_buf *tx, int32_t timeout, const char *str)
return -ENOMEM;
}
static int http_add_chunk(struct net_buf *tx, int32_t timeout, const char *str)
static int http_add_chunk(struct net_pkt *tx, int32_t timeout, const char *str)
{
char chunk_header[16];
char *rn = "\r\n";
@ -71,12 +71,12 @@ static int http_add_chunk(struct net_buf *tx, int32_t timeout, const char *str)
int http_response(struct http_server_ctx *ctx, const char *http_header,
const char *html_payload)
{
struct net_buf *tx;
struct net_pkt *tx;
int rc = -EINVAL;
tx = net_pkt_get_tx(ctx->net_ctx, ctx->timeout);
if (!tx) {
goto exit_routine;
return rc;
}
rc = http_add_header(tx, ctx->timeout, http_header);
@ -105,7 +105,6 @@ int http_response(struct http_server_ctx *ctx, const char *http_header,
tx = NULL;
exit_routine:
/* unref can handle NULL buffers, so we are covered */
net_pkt_unref(tx);
return rc;

View file

@ -26,7 +26,7 @@ NET_BUF_POOL_DEFINE(mqtt_msg_pool, MQTT_BUF_CTR, MSG_SIZE, 0, NULL);
int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg)
{
struct net_buf *data = NULL;
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
int rc;
data = net_buf_alloc(&mqtt_msg_pool, ctx->net_timeout);
@ -49,7 +49,7 @@ int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg)
goto exit_connect;
}
net_buf_frag_add(tx, data);
net_pkt_frag_add(tx, data);
data = NULL;
rc = net_context_send(tx, NULL, ctx->net_timeout, NULL, NULL);
@ -61,7 +61,7 @@ int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg)
tx = NULL;
exit_connect:
net_pkt_unref(data);
net_pkt_frag_unref(data);
net_pkt_unref(tx);
return rc;
@ -69,7 +69,7 @@ exit_connect:
int mqtt_tx_disconnect(struct mqtt_ctx *ctx)
{
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
/* DISCONNECT is a zero length message: 2 bytes required, no payload */
uint8_t msg[2];
uint16_t len;
@ -121,14 +121,14 @@ exit_disconnect:
*
* @retval 0 on success
* @retval -EINVAL
* @retval -ENOMEM if a tx buffer is not available
* @retval -ENOMEM if a tx pktfer is not available
* @retval -EIO on network error
*/
static
int mqtt_tx_pub_msgs(struct mqtt_ctx *ctx, uint16_t id,
enum mqtt_packet pkt_type)
{
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
uint8_t msg[4];
uint16_t len;
int rc;
@ -203,7 +203,7 @@ int mqtt_tx_pubrel(struct mqtt_ctx *ctx, uint16_t id)
int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg)
{
struct net_buf *data = NULL;
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
int rc;
data = net_buf_alloc(&mqtt_msg_pool, ctx->net_timeout);
@ -224,7 +224,7 @@ int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg)
goto exit_publish;
}
net_buf_frag_add(tx, data);
net_pkt_frag_add(tx, data);
data = NULL;
rc = net_context_send(tx, NULL, ctx->net_timeout, NULL, NULL);
@ -236,7 +236,7 @@ int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg)
tx = NULL;
exit_publish:
net_pkt_unref(data);
net_pkt_frag_unref(data);
net_pkt_unref(tx);
return rc;
@ -244,7 +244,7 @@ exit_publish:
int mqtt_tx_pingreq(struct mqtt_ctx *ctx)
{
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
uint8_t msg[2];
uint16_t len;
int rc;
@ -285,7 +285,7 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
const char *topics[], const enum mqtt_qos qos[])
{
struct net_buf *data = NULL;
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
int rc;
data = net_buf_alloc(&mqtt_msg_pool, ctx->net_timeout);
@ -297,7 +297,7 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
rc = mqtt_pack_subscribe(data->data, &data->len, data->size,
pkt_id, items, topics, qos);
if (rc != 0) {
net_pkt_unref(data);
net_pkt_frag_unref(data);
rc = -EINVAL;
goto exit_subs;
}
@ -308,7 +308,7 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
goto exit_subs;
}
net_buf_frag_add(tx, data);
net_pkt_frag_add(tx, data);
data = NULL;
rc = net_context_send(tx, NULL, ctx->net_timeout, NULL, NULL);
@ -320,7 +320,7 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
tx = NULL;
exit_subs:
net_pkt_unref(data);
net_pkt_frag_unref(data);
net_pkt_unref(tx);
return rc;
@ -330,7 +330,7 @@ int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
const char *topics[])
{
struct net_buf *data = NULL;
struct net_buf *tx = NULL;
struct net_pkt *tx = NULL;
int rc;
data = net_buf_alloc(&mqtt_msg_pool, ctx->net_timeout);
@ -352,7 +352,7 @@ int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
goto exit_unsub;
}
net_buf_frag_add(tx, data);
net_pkt_frag_add(tx, data);
data = NULL;
rc = net_context_send(tx, NULL, ctx->net_timeout, NULL, NULL);
@ -364,8 +364,8 @@ int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
tx = NULL;
exit_unsub:
net_buf_unref(data);
net_buf_unref(tx);
net_pkt_frag_unref(data);
net_pkt_unref(tx);
return rc;
}
@ -421,7 +421,7 @@ exit_connect:
}
/**
* Parses and validates the MQTT PUBxxxx message contained in the rx buffer.
* Parses and validates the MQTT PUBxxxx message contained in the rx packet.
*
*
* @details It validates against message structure and Packet Identifier.
@ -429,7 +429,7 @@ exit_connect:
* corresponding MQTT PUB msg.
*
* @param ctx MQTT context
* @param rx RX buffer
* @param rx RX packet
* @param type MQTT Packet type
*
* @retval 0 on success
@ -629,18 +629,18 @@ int mqtt_rx_publish(struct mqtt_ctx *ctx, struct net_buf *rx)
}
/**
* Linearizes an IP fragmented buffer
* Linearizes an IP fragmented packet
*
* @param [in] ctx MQTT context structure
* @param [in] rx RX IP stack buffer
* @param [in] rx RX IP stack packet
* @param [in] min_size Min message size allowed. This allows us to exit if the
* rx buffer is shorter than the expected msg size
* rx packet is shorter than the expected msg size
*
* @retval Data buffer
* @retval NULL on error
*/
static
struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx,
struct net_buf *mqtt_linearize_packet(struct mqtt_ctx *ctx, struct net_pkt *rx,
uint16_t min_size)
{
struct net_buf *data = NULL;
@ -649,7 +649,7 @@ struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx,
int rc;
/* CONFIG_MQTT_MSG_MAX_SIZE is defined via Kconfig. So here it's
* determined if the input buffer could fit our data buffer or if
* determined if the input packet could fit our data buffer or if
* it has the expected size.
*/
data_len = net_pkt_appdatalen(rx);
@ -662,8 +662,8 @@ struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx,
return NULL;
}
offset = net_buf_frags_len(rx) - data_len;
rc = net_pkt_linear_copy(data, rx, offset, data_len);
offset = net_pkt_get_len(rx) - data_len;
rc = net_frag_linear_copy(data, rx->frags, offset, data_len);
if (rc != 0) {
goto exit_error;
}
@ -671,7 +671,7 @@ struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx,
return data;
exit_error:
net_pkt_unref(data);
net_pkt_frag_unref(data);
return NULL;
}
@ -683,7 +683,7 @@ exit_error:
* (if defined)
*
* @param ctx MQTT context
* @param rx RX buffer
* @param rx RX packet
*
* @retval 0 on success
* @retval -EINVAL if an unknown message is received
@ -692,13 +692,13 @@ exit_error:
* and mqtt_rx_pingresp return codes
*/
static
int mqtt_publisher_parser(struct mqtt_ctx *ctx, struct net_buf *rx)
int mqtt_publisher_parser(struct mqtt_ctx *ctx, struct net_pkt *rx)
{
uint16_t pkt_type = MQTT_INVALID;
struct net_buf *data = NULL;
int rc = -EINVAL;
data = mqtt_linearize_buffer(ctx, rx, MQTT_PUBLISHER_MIN_MSG_SIZE);
data = mqtt_linearize_packet(ctx, rx, MQTT_PUBLISHER_MIN_MSG_SIZE);
if (!data) {
rc = -ENOMEM;
goto exit_parser;
@ -736,7 +736,7 @@ exit_parser:
ctx->malformed(ctx, pkt_type);
}
net_pkt_unref(data);
net_pkt_frag_unref(data);
return rc;
}
@ -749,7 +749,7 @@ exit_parser:
* (if defined)
*
* @param ctx MQTT context
* @param rx RX buffer
* @param rx RX packet
*
* @retval 0 on success
* @retval -EINVAL if an unknown message is received
@ -758,13 +758,13 @@ exit_parser:
* return codes
*/
static
int mqtt_subscriber_parser(struct mqtt_ctx *ctx, struct net_buf *rx)
int mqtt_subscriber_parser(struct mqtt_ctx *ctx, struct net_pkt *rx)
{
uint16_t pkt_type = MQTT_INVALID;
struct net_buf *data = NULL;
int rc = 0;
data = mqtt_linearize_buffer(ctx, rx, MQTT_PUBLISHER_MIN_MSG_SIZE);
data = mqtt_linearize_packet(ctx, rx, MQTT_PUBLISHER_MIN_MSG_SIZE);
if (!data) {
rc = -EINVAL;
goto exit_parser;
@ -803,13 +803,13 @@ exit_parser:
ctx->malformed(ctx, pkt_type);
}
net_pkt_unref(data);
net_pkt_frag_unref(data);
return rc;
}
static
void mqtt_recv(struct net_context *net_ctx, struct net_buf *buf, int status,
void mqtt_recv(struct net_context *net_ctx, struct net_pkt *pkt, int status,
void *data)
{
struct mqtt_ctx *mqtt = (struct mqtt_ctx *)data;
@ -817,18 +817,18 @@ void mqtt_recv(struct net_context *net_ctx, struct net_buf *buf, int status,
/* net_ctx is already referenced to by the mqtt_ctx struct */
ARG_UNUSED(net_ctx);
if (status || !buf) {
if (status || !pkt) {
return;
}
if (net_pkt_appdatalen(buf) == 0) {
if (net_pkt_appdatalen(pkt) == 0) {
goto lb_exit;
}
mqtt->rcv(mqtt, buf);
mqtt->rcv(mqtt, pkt);
lb_exit:
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
int mqtt_init(struct mqtt_ctx *ctx, enum mqtt_app app_type)

View file

@ -82,7 +82,7 @@ static int decode_delta(int num, const uint8_t *buf, int16_t buflen,
return hdrlen;
}
static int coap_parse_option(const struct zoap_packet *pkt,
static int coap_parse_option(const struct zoap_packet *zpkt,
struct option_context *context,
uint8_t **value, uint16_t *vlen)
{
@ -141,16 +141,16 @@ static int coap_parse_option(const struct zoap_packet *pkt,
return context->used;
}
static int coap_parse_options(struct zoap_packet *pkt, unsigned int offset)
static int coap_parse_options(struct zoap_packet *zpkt, unsigned int offset)
{
struct option_context context = {
.delta = 0,
.used = 0,
.buflen = pkt->buf->frags->len - offset,
.buf = &pkt->buf->frags->data[offset] };
.buflen = zpkt->pkt->frags->len - offset,
.buf = &zpkt->pkt->frags->data[offset] };
while (true) {
int r = coap_parse_option(pkt, &context, NULL, NULL);
int r = coap_parse_option(zpkt, &context, NULL, NULL);
if (r < 0) {
return -EINVAL;
@ -163,68 +163,68 @@ static int coap_parse_options(struct zoap_packet *pkt, unsigned int offset)
return context.used;
}
static uint8_t coap_header_get_tkl(const struct zoap_packet *pkt)
static uint8_t coap_header_get_tkl(const struct zoap_packet *zpkt)
{
return pkt->buf->frags->data[0] & 0xF;
return zpkt->pkt->frags->data[0] & 0xF;
}
static int coap_get_header_len(const struct zoap_packet *pkt)
static int coap_get_header_len(const struct zoap_packet *zpkt)
{
unsigned int hdrlen;
uint8_t tkl;
hdrlen = BASIC_HEADER_SIZE;
if (pkt->buf->frags->len < hdrlen) {
if (zpkt->pkt->frags->len < hdrlen) {
return -EINVAL;
}
tkl = coap_header_get_tkl(pkt);
tkl = coap_header_get_tkl(zpkt);
/* Token lenghts 9-15 are reserved. */
if (tkl > 8) {
return -EINVAL;
}
if (pkt->buf->frags->len < hdrlen + tkl) {
if (zpkt->pkt->frags->len < hdrlen + tkl) {
return -EINVAL;
}
return hdrlen + tkl;
}
int zoap_packet_parse(struct zoap_packet *pkt, struct net_buf *buf)
int zoap_packet_parse(struct zoap_packet *zpkt, struct net_pkt *pkt)
{
int optlen, hdrlen;
if (!buf || !buf->frags) {
if (!pkt || !pkt->frags) {
return -EINVAL;
}
memset(pkt, 0, sizeof(*pkt));
pkt->buf = buf;
memset(zpkt, 0, sizeof(*zpkt));
zpkt->pkt = pkt;
hdrlen = coap_get_header_len(pkt);
hdrlen = coap_get_header_len(zpkt);
if (hdrlen < 0) {
return -EINVAL;
}
optlen = coap_parse_options(pkt, hdrlen);
optlen = coap_parse_options(zpkt, hdrlen);
if (optlen < 0) {
return -EINVAL;
}
if (buf->frags->len < hdrlen + optlen) {
if (pkt->frags->len < hdrlen + optlen) {
return -EINVAL;
}
if (buf->frags->len <= hdrlen + optlen + 1) {
pkt->start = NULL;
if (pkt->frags->len <= hdrlen + optlen + 1) {
zpkt->start = NULL;
return 0;
}
pkt->start = buf->frags->data + hdrlen + optlen + 1;
pkt->total_size = buf->frags->len;
zpkt->start = pkt->frags->data + hdrlen + optlen + 1;
zpkt->total_size = pkt->frags->len;
return 0;
}
@ -298,30 +298,30 @@ static int coap_option_encode(struct option_context *context, uint16_t code,
return offset + len;
}
int zoap_packet_init(struct zoap_packet *pkt,
struct net_buf *buf)
int zoap_packet_init(struct zoap_packet *zpkt,
struct net_pkt *pkt)
{
void *data;
if (!buf || !buf->frags) {
if (!pkt || !pkt->frags) {
return -EINVAL;
}
if (net_buf_tailroom(buf->frags) < BASIC_HEADER_SIZE) {
if (net_buf_tailroom(pkt->frags) < BASIC_HEADER_SIZE) {
return -ENOMEM;
}
memset(pkt, 0, sizeof(*pkt));
pkt->total_size = net_buf_tailroom(buf->frags);
memset(zpkt, 0, sizeof(*zpkt));
zpkt->total_size = net_buf_tailroom(pkt->frags);
data = net_buf_add(buf->frags, BASIC_HEADER_SIZE);
data = net_buf_add(pkt->frags, BASIC_HEADER_SIZE);
/*
* As some header data is built by OR operations, we zero
* the header to be sure.
*/
memset(data, 0, BASIC_HEADER_SIZE);
pkt->buf = buf;
zpkt->pkt = pkt;
return 0;
}
@ -335,7 +335,7 @@ int zoap_pending_init(struct zoap_pending *pending,
memcpy(&pending->addr, addr, sizeof(*addr));
/* Will increase the reference count when the pending is cycled */
pending->buf = request->buf;
pending->pkt = request->pkt;
return 0;
}
@ -347,7 +347,7 @@ struct zoap_pending *zoap_pending_next_unused(
size_t i;
for (i = 0, p = pendings; i < len; i++, p++) {
if (p->timeout == 0 && !p->buf) {
if (p->timeout == 0 && !p->pkt) {
return p;
}
}
@ -472,7 +472,7 @@ bool zoap_pending_cycle(struct zoap_pending *pending)
* When it it is the last retransmission, the buffer
* will be destroyed when it is transmitted.
*/
net_pkt_ref(pending->buf);
net_pkt_ref(pending->pkt);
}
return cont;
@ -481,18 +481,18 @@ bool zoap_pending_cycle(struct zoap_pending *pending)
void zoap_pending_clear(struct zoap_pending *pending)
{
pending->timeout = 0;
net_pkt_unref(pending->buf);
pending->buf = NULL;
net_pkt_unref(pending->pkt);
pending->pkt = NULL;
}
static bool uri_path_eq(const struct zoap_packet *pkt,
static bool uri_path_eq(const struct zoap_packet *zpkt,
const char * const *path)
{
struct zoap_option options[16];
uint16_t count = 16;
int i, r;
r = zoap_find_options(pkt, ZOAP_OPTION_URI_PATH, options, count);
r = zoap_find_options(zpkt, ZOAP_OPTION_URI_PATH, options, count);
if (r < 0) {
return false;
}
@ -533,20 +533,20 @@ static zoap_method_t method_from_code(const struct zoap_resource *resource,
}
}
static bool is_request(const struct zoap_packet *pkt)
static bool is_request(const struct zoap_packet *zpkt)
{
uint8_t code = zoap_header_get_code(pkt);
uint8_t code = zoap_header_get_code(zpkt);
return !(code & ~ZOAP_REQUEST_MASK);
}
int zoap_handle_request(struct zoap_packet *pkt,
int zoap_handle_request(struct zoap_packet *zpkt,
struct zoap_resource *resources,
const struct sockaddr *from)
{
struct zoap_resource *resource;
if (!is_request(pkt)) {
if (!is_request(zpkt)) {
return 0;
}
@ -555,18 +555,18 @@ int zoap_handle_request(struct zoap_packet *pkt,
uint8_t code;
/* FIXME: deal with hierarchical resources */
if (!uri_path_eq(pkt, resource->path)) {
if (!uri_path_eq(zpkt, resource->path)) {
continue;
}
code = zoap_header_get_code(pkt);
code = zoap_header_get_code(zpkt);
method = method_from_code(resource, code);
if (!method) {
return 0;
}
return method(resource, pkt, from);
return method(resource, zpkt, from);
}
return -ENOENT;
@ -594,13 +594,13 @@ unsigned int zoap_option_value_to_int(const struct zoap_option *option)
return 0;
}
static int get_observe_option(const struct zoap_packet *pkt)
static int get_observe_option(const struct zoap_packet *zpkt)
{
struct zoap_option option = {};
uint16_t count = 1;
int r;
r = zoap_find_options(pkt, ZOAP_OPTION_OBSERVE, &option, count);
r = zoap_find_options(zpkt, ZOAP_OPTION_OBSERVE, &option, count);
if (r <= 0) {
return -ENOENT;
}
@ -797,56 +797,56 @@ struct zoap_observer *zoap_find_observer_by_addr(
return NULL;
}
uint8_t *zoap_packet_get_payload(struct zoap_packet *pkt, uint16_t *len)
uint8_t *zoap_packet_get_payload(struct zoap_packet *zpkt, uint16_t *len)
{
uint8_t *appdata = pkt->buf->frags->data;
uint16_t appdatalen = pkt->buf->frags->len;
uint8_t *appdata = zpkt->pkt->frags->data;
uint16_t appdatalen = zpkt->pkt->frags->len;
if (!pkt || !len) {
if (!zpkt || !len) {
return NULL;
}
if (!pkt->start) {
if (appdatalen + 1 >= pkt->total_size) {
if (!zpkt->start) {
if (appdatalen + 1 >= zpkt->total_size) {
return NULL;
}
appdata[appdatalen] = COAP_MARKER;
pkt->buf->frags->len += 1;
zpkt->pkt->frags->len += 1;
pkt->start = appdata + pkt->buf->frags->len;
zpkt->start = appdata + zpkt->pkt->frags->len;
}
*len = appdata + pkt->total_size - pkt->start;
*len = appdata + zpkt->total_size - zpkt->start;
return pkt->start;
return zpkt->start;
}
int zoap_packet_set_used(struct zoap_packet *pkt, uint16_t len)
int zoap_packet_set_used(struct zoap_packet *zpkt, uint16_t len)
{
if ((pkt->buf->frags->len + len) >
net_buf_tailroom(pkt->buf->frags)) {
if ((zpkt->pkt->frags->len + len) >
net_buf_tailroom(zpkt->pkt->frags)) {
return -ENOMEM;
}
pkt->buf->frags->len += len;
zpkt->pkt->frags->len += len;
return 0;
}
int zoap_add_option(struct zoap_packet *pkt, uint16_t code,
int zoap_add_option(struct zoap_packet *zpkt, uint16_t code,
const void *value, uint16_t len)
{
struct net_buf *frag = pkt->buf->frags;
struct net_buf *frag = zpkt->pkt->frags;
struct option_context context = { .delta = 0,
.used = 0 };
int r, offset;
if (pkt->start) {
if (zpkt->start) {
return -EINVAL;
}
offset = coap_get_header_len(pkt);
offset = coap_get_header_len(zpkt);
if (offset < 0) {
return -EINVAL;
}
@ -856,7 +856,7 @@ int zoap_add_option(struct zoap_packet *pkt, uint16_t code,
context.buf = frag->data + offset;
while (context.delta <= code) {
r = coap_parse_option(pkt, &context, NULL, NULL);
r = coap_parse_option(zpkt, &context, NULL, NULL);
if (r < 0) {
return -ENOENT;
}
@ -883,7 +883,7 @@ int zoap_add_option(struct zoap_packet *pkt, uint16_t code,
return 0;
}
int zoap_add_option_int(struct zoap_packet *pkt, uint16_t code,
int zoap_add_option_int(struct zoap_packet *zpkt, uint16_t code,
unsigned int val)
{
uint8_t data[4], len;
@ -906,19 +906,19 @@ int zoap_add_option_int(struct zoap_packet *pkt, uint16_t code,
len = 4;
}
return zoap_add_option(pkt, code, data, len);
return zoap_add_option(zpkt, code, data, len);
}
int zoap_find_options(const struct zoap_packet *pkt, uint16_t code,
int zoap_find_options(const struct zoap_packet *zpkt, uint16_t code,
struct zoap_option *options, uint16_t veclen)
{
struct net_buf *frag = pkt->buf->frags;
struct net_buf *frag = zpkt->pkt->frags;
struct option_context context = { .delta = 0,
.used = 0 };
int hdrlen, count = 0;
uint16_t len;
hdrlen = coap_get_header_len(pkt);
hdrlen = coap_get_header_len(zpkt);
if (hdrlen < 0) {
return -EINVAL;
}
@ -927,7 +927,7 @@ int zoap_find_options(const struct zoap_packet *pkt, uint16_t code,
context.buf = (uint8_t *)frag->data + hdrlen;
while (context.delta <= code && count < veclen) {
int used = coap_parse_option(pkt, &context,
int used = coap_parse_option(zpkt, &context,
(uint8_t **)&options[count].value,
&len);
options[count].len = len;
@ -949,26 +949,26 @@ int zoap_find_options(const struct zoap_packet *pkt, uint16_t code,
return count;
}
uint8_t zoap_header_get_version(const struct zoap_packet *pkt)
uint8_t zoap_header_get_version(const struct zoap_packet *zpkt)
{
return (pkt->buf->frags->data[0] & 0xC0) >> 6;
return (zpkt->pkt->frags->data[0] & 0xC0) >> 6;
}
uint8_t zoap_header_get_type(const struct zoap_packet *pkt)
uint8_t zoap_header_get_type(const struct zoap_packet *zpkt)
{
return (pkt->buf->frags->data[0] & 0x30) >> 4;
return (zpkt->pkt->frags->data[0] & 0x30) >> 4;
}
uint8_t coap_header_get_code(const struct zoap_packet *pkt)
uint8_t coap_header_get_code(const struct zoap_packet *zpkt)
{
return pkt->buf->frags->data[1];
return zpkt->pkt->frags->data[1];
}
const uint8_t *zoap_header_get_token(const struct zoap_packet *pkt,
const uint8_t *zoap_header_get_token(const struct zoap_packet *zpkt,
uint8_t *len)
{
struct net_buf *frag = pkt->buf->frags;
uint8_t tkl = coap_header_get_tkl(pkt);
struct net_buf *frag = zpkt->pkt->frags;
uint8_t tkl = coap_header_get_tkl(zpkt);
if (len) {
*len = 0;
@ -985,9 +985,9 @@ const uint8_t *zoap_header_get_token(const struct zoap_packet *pkt,
return (uint8_t *)frag->data + BASIC_HEADER_SIZE;
}
uint8_t zoap_header_get_code(const struct zoap_packet *pkt)
uint8_t zoap_header_get_code(const struct zoap_packet *zpkt)
{
uint8_t code = coap_header_get_code(pkt);
uint8_t code = coap_header_get_code(zpkt);
switch (code) {
/* Methods are encoded in the code field too */
@ -1025,25 +1025,25 @@ uint8_t zoap_header_get_code(const struct zoap_packet *pkt)
}
}
uint16_t zoap_header_get_id(const struct zoap_packet *pkt)
uint16_t zoap_header_get_id(const struct zoap_packet *zpkt)
{
return sys_get_be16(&pkt->buf->frags->data[2]);
return sys_get_be16(&zpkt->pkt->frags->data[2]);
}
void zoap_header_set_version(struct zoap_packet *pkt, uint8_t ver)
void zoap_header_set_version(struct zoap_packet *zpkt, uint8_t ver)
{
pkt->buf->frags->data[0] |= (ver & 0x3) << 6;
zpkt->pkt->frags->data[0] |= (ver & 0x3) << 6;
}
void zoap_header_set_type(struct zoap_packet *pkt, uint8_t type)
void zoap_header_set_type(struct zoap_packet *zpkt, uint8_t type)
{
pkt->buf->frags->data[0] |= (type & 0x3) << 4;
zpkt->pkt->frags->data[0] |= (type & 0x3) << 4;
}
int zoap_header_set_token(struct zoap_packet *pkt, const uint8_t *token,
int zoap_header_set_token(struct zoap_packet *zpkt, const uint8_t *token,
uint8_t tokenlen)
{
struct net_buf *frag = pkt->buf->frags;
struct net_buf *frag = zpkt->pkt->frags;
uint8_t *appdata = frag->data;
if (net_buf_tailroom(frag) < BASIC_HEADER_SIZE + tokenlen) {
@ -1063,14 +1063,14 @@ int zoap_header_set_token(struct zoap_packet *pkt, const uint8_t *token,
return 0;
}
void zoap_header_set_code(struct zoap_packet *pkt, uint8_t code)
void zoap_header_set_code(struct zoap_packet *zpkt, uint8_t code)
{
pkt->buf->frags->data[1] = code;
zpkt->pkt->frags->data[1] = code;
}
void zoap_header_set_id(struct zoap_packet *pkt, uint16_t id)
void zoap_header_set_id(struct zoap_packet *zpkt, uint16_t id)
{
sys_put_be16(id, &pkt->buf->frags->data[2]);
sys_put_be16(id, &zpkt->pkt->frags->data[2]);
}
int zoap_block_transfer_init(struct zoap_block_context *ctx,
@ -1092,14 +1092,14 @@ int zoap_block_transfer_init(struct zoap_block_context *ctx,
#define SET_MORE(v, m) ((v) |= (m) ? 0x08 : 0x00)
#define SET_NUM(v, n) ((v) |= ((n) << 4))
int zoap_add_block1_option(struct zoap_packet *pkt,
int zoap_add_block1_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx)
{
uint16_t bytes = zoap_block_size_to_bytes(ctx->block_size);
unsigned int val = 0;
int r;
if (is_request(pkt)) {
if (is_request(zpkt)) {
SET_BLOCK_SIZE(val, ctx->block_size);
SET_MORE(val, ctx->current + bytes < ctx->total_size);
SET_NUM(val, ctx->current / bytes);
@ -1108,18 +1108,18 @@ int zoap_add_block1_option(struct zoap_packet *pkt,
SET_NUM(val, ctx->current / bytes);
}
r = zoap_add_option_int(pkt, ZOAP_OPTION_BLOCK1, val);
r = zoap_add_option_int(zpkt, ZOAP_OPTION_BLOCK1, val);
return r;
}
int zoap_add_block2_option(struct zoap_packet *pkt,
int zoap_add_block2_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx)
{
int r, val = 0;
uint16_t bytes = zoap_block_size_to_bytes(ctx->block_size);
if (is_request(pkt)) {
if (is_request(zpkt)) {
SET_BLOCK_SIZE(val, ctx->block_size);
SET_NUM(val, ctx->current / bytes);
} else {
@ -1128,21 +1128,21 @@ int zoap_add_block2_option(struct zoap_packet *pkt,
SET_NUM(val, ctx->current / bytes);
}
r = zoap_add_option_int(pkt, ZOAP_OPTION_BLOCK2, val);
r = zoap_add_option_int(zpkt, ZOAP_OPTION_BLOCK2, val);
return r;
}
int zoap_add_size1_option(struct zoap_packet *pkt,
int zoap_add_size1_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx)
{
return zoap_add_option_int(pkt, ZOAP_OPTION_SIZE1, ctx->total_size);
return zoap_add_option_int(zpkt, ZOAP_OPTION_SIZE1, ctx->total_size);
}
int zoap_add_size2_option(struct zoap_packet *pkt,
int zoap_add_size2_option(struct zoap_packet *zpkt,
struct zoap_block_context *ctx)
{
return zoap_add_option_int(pkt, ZOAP_OPTION_SIZE2, ctx->total_size);
return zoap_add_option_int(zpkt, ZOAP_OPTION_SIZE2, ctx->total_size);
}
struct block_transfer {
@ -1151,13 +1151,13 @@ struct block_transfer {
bool more;
};
static int get_block_option(const struct zoap_packet *pkt, uint16_t code)
static int get_block_option(const struct zoap_packet *zpkt, uint16_t code)
{
struct zoap_option option;
unsigned int val;
int count = 1;
count = zoap_find_options(pkt, code, &option, count);
count = zoap_find_options(zpkt, code, &option, count);
if (count <= 0) {
return -ENOENT;
}
@ -1243,20 +1243,20 @@ static int update_control_block2(struct zoap_block_context *ctx,
return 0;
}
int zoap_update_from_block(const struct zoap_packet *pkt,
int zoap_update_from_block(const struct zoap_packet *zpkt,
struct zoap_block_context *ctx)
{
int r, block1, block2, size1, size2;
block1 = get_block_option(pkt, ZOAP_OPTION_BLOCK1);
block2 = get_block_option(pkt, ZOAP_OPTION_BLOCK2);
size1 = get_block_option(pkt, ZOAP_OPTION_SIZE1);
size2 = get_block_option(pkt, ZOAP_OPTION_SIZE2);
block1 = get_block_option(zpkt, ZOAP_OPTION_BLOCK1);
block2 = get_block_option(zpkt, ZOAP_OPTION_BLOCK2);
size1 = get_block_option(zpkt, ZOAP_OPTION_SIZE1);
size2 = get_block_option(zpkt, ZOAP_OPTION_SIZE2);
size1 = size1 == -ENOENT ? 0 : size1;
size2 = size2 == -ENOENT ? 0 : size2;
if (is_request(pkt)) {
if (is_request(zpkt)) {
r = update_control_block2(ctx, block2, size2);
if (r) {
return r;

View file

@ -223,30 +223,31 @@ static int send_error_response(struct zoap_resource *resource,
{
struct net_context *context;
struct zoap_packet response;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint16_t id;
int r;
id = zoap_header_get_id(request);
context = net_pkt_context(request->buf);
context = net_pkt_context(request->pkt);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
frag = net_pkt_get_data(context, K_FOREVER);
if (!frag) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return r;
}
@ -256,10 +257,10 @@ static int send_error_response(struct zoap_resource *resource,
zoap_header_set_code(&response, ZOAP_RESPONSE_CODE_BAD_REQUEST);
zoap_header_set_id(&response, id);
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return r;
@ -272,7 +273,8 @@ int _zoap_well_known_core_get(struct zoap_resource *resource,
struct net_context *context;
struct zoap_packet response;
struct zoap_option query;
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
const uint8_t *token;
unsigned int num_queries;
uint16_t id;
@ -293,22 +295,22 @@ int _zoap_well_known_core_get(struct zoap_resource *resource,
num_queries = r;
context = net_pkt_context(request->buf);
context = net_pkt_context(request->pkt);
buf = net_pkt_get_tx(context, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_tx(context, K_FOREVER);
if (!pkt) {
return -ENOMEM;
}
frag = net_pkt_get_data(context, K_FOREVER);
if (!frag) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return -ENOMEM;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
r = zoap_packet_init(&response, buf);
r = zoap_packet_init(&response, pkt);
if (r < 0) {
goto done;
}
@ -323,7 +325,7 @@ int _zoap_well_known_core_get(struct zoap_resource *resource,
r = zoap_add_option(&response, ZOAP_OPTION_CONTENT_FORMAT,
&format, sizeof(format));
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return -EINVAL;
}
@ -342,18 +344,18 @@ int _zoap_well_known_core_get(struct zoap_resource *resource,
}
if (!response.start) {
temp = response.buf->frags;
temp = response.pkt->frags;
str = net_buf_add(temp, 1);
*str = 0xFF;
response.start = str + 1;
} else {
temp = net_pkt_get_data(context, K_FOREVER);
if (!temp) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return -ENOMEM;
}
net_buf_frag_add(buf, temp);
net_pkt_frag_add(pkt, temp);
}
r = format_resource(resource, temp);
@ -362,18 +364,18 @@ int _zoap_well_known_core_get(struct zoap_resource *resource,
}
}
net_pkt_compact(buf);
net_pkt_compact(pkt);
done:
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return send_error_response(resource, request, from);
}
r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6),
r = net_context_sendto(pkt, from, sizeof(struct sockaddr_in6),
NULL, 0, NULL, NULL);
if (r < 0) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
}
return r;

View file

@ -14,11 +14,12 @@ CONFIG_NET_PKT_TX_COUNT=1
CONFIG_NET_BUF_RX_COUNT=3
CONFIG_NET_BUF_TX_COUNT=3
CONFIG_NET_LOG=y
CONFIG_SYS_LOG_NET_LEVEL=2
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_NET_DEBUG_IF=y
CONFIG_NET_DEBUG_CORE=y
CONFIG_NET_DEBUG_6LO=n
CONFIG_NET_DEBUG_NET_PKT=n
CONFIG_NET_DEBUG_6LO=y
CONFIG_NET_DEBUG_NET_PKT=y
CONFIG_NET_6LO_CONTEXT=y
#Before modifying this value, add respective code in src/main.c

View file

@ -198,9 +198,9 @@ 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_buf *buf)
static int tester_send(struct net_if *iface, struct net_pkt *pkt)
{
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NET_OK;
}
@ -214,7 +214,7 @@ NET_DEVICE_INIT(net_6lo_test, "net_6lo_test",
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&net_6lo_if_api, DUMMY_L2, NET_L2_GET_CTX_TYPE(DUMMY_L2), 127);
static bool compare_data(struct net_buf *buf, struct net_6lo_data *data)
static bool compare_data(struct net_pkt *pkt, struct net_6lo_data *data)
{
struct net_buf *frag;
uint8_t bytes;
@ -224,38 +224,38 @@ static bool compare_data(struct net_buf *buf, struct net_6lo_data *data)
int remaining = data->small ? SIZE_OF_SMALL_DATA : SIZE_OF_LARGE_DATA;
if (data->nh_udp) {
if (net_buf_frags_len(buf->frags) !=
if (net_pkt_get_len(pkt) !=
(NET_IPV6UDPH_LEN + remaining)) {
TC_PRINT("mismatch lengths, expected %d received %zu\n",
NET_IPV6UDPH_LEN + remaining,
net_buf_frags_len(buf->frags));
net_pkt_get_len(pkt));
return false;
}
} else if (data->nh_icmp) {
if (net_buf_frags_len(buf->frags) !=
if (net_pkt_get_len(pkt) !=
(NET_IPV6ICMPH_LEN + remaining)) {
TC_PRINT("mismatch lengths, expected %d received %zu\n",
NET_IPV6ICMPH_LEN + remaining,
net_buf_frags_len(buf->frags));
net_pkt_get_len(pkt));
return false;
}
} else {
if (net_buf_frags_len(buf->frags) !=
if (net_pkt_get_len(pkt) !=
(NET_IPV6H_LEN + remaining)) {
TC_PRINT("mismatch lengths, expected %d received %zu\n",
NET_IPV6H_LEN + remaining,
net_buf_frags_len(buf->frags));
net_pkt_get_len(pkt));
return false;
}
}
frag = buf->frags;
frag = pkt->frags;
if (data->nh_udp) {
if (memcmp(frag->data, (uint8_t *)data, NET_IPV6UDPH_LEN)) {
@ -301,30 +301,31 @@ static bool compare_data(struct net_buf *buf, struct net_6lo_data *data)
return true;
}
static struct net_buf *create_buf(struct net_6lo_data *data)
static struct net_pkt *create_pkt(struct net_6lo_data *data)
{
struct net_buf *buf, *frag;
struct net_pkt *pkt;
struct net_buf *frag;
uint8_t bytes, pos;
uint16_t len;
int remaining;
buf = net_pkt_get_reserve_tx(0, K_FOREVER);
if (!buf) {
pkt = net_pkt_get_reserve_tx(0, K_FOREVER);
if (!pkt) {
return NULL;
}
net_pkt_set_iface(buf, net_if_get_default());
net_pkt_set_ip_hdr_len(buf, NET_IPV6H_LEN);
net_pkt_set_iface(pkt, net_if_get_default());
net_pkt_set_ip_hdr_len(pkt, NET_IPV6H_LEN);
net_pkt_ll_src(buf)->addr = src_mac;
net_pkt_ll_src(buf)->len = 8;
net_pkt_ll_src(pkt)->addr = src_mac;
net_pkt_ll_src(pkt)->len = 8;
net_pkt_ll_dst(buf)->addr = dst_mac;
net_pkt_ll_dst(buf)->len = 8;
net_pkt_ll_dst(pkt)->addr = dst_mac;
net_pkt_ll_dst(pkt)->len = 8;
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
if (!frag) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NULL;
}
@ -377,18 +378,18 @@ static struct net_buf *create_buf(struct net_6lo_data *data)
remaining -= bytes;
if (net_buf_tailroom(frag) - (bytes - copy)) {
net_pkt_unref(buf);
net_pkt_unref(pkt);
return NULL;
}
net_buf_frag_add(buf, frag);
net_pkt_frag_add(pkt, frag);
if (remaining > 0) {
frag = net_pkt_get_frag(buf, K_FOREVER);
frag = net_pkt_get_frag(pkt, K_FOREVER);
}
}
return buf;
return pkt;
}
static struct net_6lo_data test_data_1 = {
@ -798,49 +799,49 @@ static struct net_6lo_data test_data_22 = {
static int test_6lo(struct net_6lo_data *data)
{
struct net_buf *buf;
struct net_pkt *pkt;
int result = TC_FAIL;
buf = create_buf(data);
if (!buf) {
pkt = create_pkt(data);
if (!pkt) {
TC_PRINT("%s: failed to create buffer\n", __func__);
goto end;
}
#if DEBUG > 0
TC_PRINT("length before compression %zu\n",
net_buf_frags_len(buf->frags));
net_hexdump_frags("before-compression", buf);
net_pkt_get_len(pkt));
net_hexdump_frags("before-compression", pkt);
#endif
if (!net_6lo_compress(buf, data->iphc, NULL)) {
if (!net_6lo_compress(pkt, data->iphc, NULL)) {
TC_PRINT("compression failed\n");
goto end;
}
#if DEBUG > 0
TC_PRINT("length after compression %zu\n",
net_buf_frags_len(buf->frags));
net_hexdump_frags("after-compression", buf);
net_pkt_get_len(pkt));
net_hexdump_frags("after-compression", pkt);
#endif
if (!net_6lo_uncompress(buf)) {
if (!net_6lo_uncompress(pkt)) {
TC_PRINT("uncompression failed\n");
goto end;
}
#if DEBUG > 0
TC_PRINT("length after uncompression %zu\n",
net_buf_frags_len(buf->frags));
net_hexdump_frags("after-uncompression", buf);
net_pkt_get_len(pkt));
net_hexdump_frags("after-uncompression", pkt);
#endif
if (compare_data(buf, data)) {
if (compare_data(pkt, data)) {
result = TC_PASS;
}
end:
net_pkt_unref(buf);
net_pkt_unref(pkt);
return result;
}

Some files were not shown because too many files have changed in this diff Show more