Skip to content

Commit 9800d46

Browse files
rlubosdkalowsk
authored andcommitted
net: pkt: Add helper function to initialize TX packet
Add helper function to initialize externally allocated TX packet. It's especially important to configure net_buf slab for the packet so that net buffers are allocated from a correct pool for the packet. Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit b8c7984)
1 parent ac91402 commit 9800d46

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

subsys/net/ip/net_pkt.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,19 @@ int net_pkt_set_data(struct net_pkt *pkt,
23542354
return net_pkt_write(pkt, access->data, access->size);
23552355
}
23562356

2357+
void net_pkt_tx_init(struct net_pkt *pkt)
2358+
{
2359+
memset(pkt, 0, sizeof(struct net_pkt));
2360+
2361+
pkt->atomic_ref = ATOMIC_INIT(1);
2362+
pkt->slab = &tx_pkts;
2363+
2364+
net_pkt_set_ipv6_next_hdr(pkt, 255);
2365+
net_pkt_set_priority(pkt, TX_DEFAULT_PRIORITY);
2366+
net_pkt_set_vlan_tag(pkt, NET_VLAN_TAG_UNSPEC);
2367+
net_pkt_cursor_init(pkt);
2368+
}
2369+
23572370
void net_pkt_init(void)
23582371
{
23592372
#if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG

subsys/net/ip/net_private.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,10 @@ static inline void net_pkt_print_buffer_info(struct net_pkt *pkt, const char *st
414414

415415
printk("\n");
416416
}
417+
418+
/**
419+
* Initialize externally allocated TX packet.
420+
*
421+
* @param pkt The network packet to initialize.
422+
*/
423+
void net_pkt_tx_init(struct net_pkt *pkt);

0 commit comments

Comments
 (0)