Skip to content

Commit b8c7984

Browse files
rluboshenrikbrixandersen
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]>
1 parent aca511c commit b8c7984

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
@@ -2358,6 +2358,19 @@ int net_pkt_set_data(struct net_pkt *pkt,
23582358
return net_pkt_write(pkt, access->data, access->size);
23592359
}
23602360

2361+
void net_pkt_tx_init(struct net_pkt *pkt)
2362+
{
2363+
memset(pkt, 0, sizeof(struct net_pkt));
2364+
2365+
pkt->atomic_ref = ATOMIC_INIT(1);
2366+
pkt->slab = &tx_pkts;
2367+
2368+
net_pkt_set_ipv6_next_hdr(pkt, 255);
2369+
net_pkt_set_priority(pkt, TX_DEFAULT_PRIORITY);
2370+
net_pkt_set_vlan_tag(pkt, NET_VLAN_TAG_UNSPEC);
2371+
net_pkt_cursor_init(pkt);
2372+
}
2373+
23612374
void net_pkt_init(void)
23622375
{
23632376
#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
@@ -416,3 +416,10 @@ static inline void net_pkt_print_buffer_info(struct net_pkt *pkt, const char *st
416416

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

0 commit comments

Comments
 (0)