Skip to content

Commit 15dc8d7

Browse files
yangbolu1991nashif
authored andcommitted
net: pkt: support common usage of control block
Supported common usage of control block for any layer. Signed-off-by: Yangbo Lu <[email protected]>
1 parent 997edb4 commit 15dc8d7

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

drivers/ieee802154/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
menuconfig IEEE802154
1010
bool "IEEE 802.15.4 drivers"
1111
depends on NETWORKING
12+
select NET_PKT_CONTROL_BLOCK
1213
default y if NET_L2_PHY_IEEE802154
1314

1415
if IEEE802154

include/zephyr/net/ieee802154_pkt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ extern "C" {
2525

2626
/** @cond ignore */
2727

28-
#ifndef NET_PKT_HAS_CONTROL_BLOCK
29-
#define NET_PKT_HAS_CONTROL_BLOCK
30-
#endif
31-
3228
/* See section 6.16.2.8 - Received Signal Strength Indicator (RSSI) */
3329
#define IEEE802154_MAC_RSSI_MIN 0U /* corresponds to -174 dBm */
3430
#define IEEE802154_MAC_RSSI_MAX 254U /* corresponds to 80 dBm */

include/zephyr/net/net_pkt.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,18 +317,18 @@ struct net_pkt {
317317
uint16_t vlan_tci;
318318
#endif /* CONFIG_NET_VLAN */
319319

320-
#if defined(NET_PKT_HAS_CONTROL_BLOCK)
321-
/* TODO: Evolve this into a union of orthogonal
322-
* control block declarations if further L2
323-
* stacks require L2-specific attributes.
324-
*/
320+
#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
321+
/* Control block which could be used by any layer */
322+
union {
323+
uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
325324
#if defined(CONFIG_IEEE802154)
326-
/* The following structure requires a 4-byte alignment
327-
* boundary to avoid padding.
328-
*/
329-
struct net_pkt_cb_ieee802154 cb;
325+
/* The following structure requires a 4-byte alignment
326+
* boundary to avoid padding.
327+
*/
328+
struct net_pkt_cb_ieee802154 cb_ieee802154;
330329
#endif /* CONFIG_IEEE802154 */
331-
#endif /* NET_PKT_HAS_CONTROL_BLOCK */
330+
} cb;
331+
#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
332332

333333
/** Network packet priority, can be left out in which case packet
334334
* is not prioritised.
@@ -1463,7 +1463,7 @@ static inline void net_pkt_set_ppp(struct net_pkt *pkt,
14631463
}
14641464
#endif /* CONFIG_NET_L2_PPP */
14651465

1466-
#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1466+
#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
14671467
static inline void *net_pkt_cb(struct net_pkt *pkt)
14681468
{
14691469
return &pkt->cb;

subsys/net/ip/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,21 @@ config NET_PKT_BUF_TX_DATA_ALLOC_ALIGN_LEN
755755
that expects 4 byte alignment for the length of the data and the start
756756
of the data that is being sent.
757757

758+
config NET_PKT_CONTROL_BLOCK
759+
bool "pkt control block"
760+
help
761+
This is to enable control block which can be used by any layer.
762+
763+
config NET_PKT_CONTROL_BLOCK_SIZE
764+
int "Size of pkt control block in bytes"
765+
depends on NET_PKT_CONTROL_BLOCK
766+
default 1
767+
help
768+
Size of pkt control block in bytes if there are no other specific control blocks
769+
enabled. If there are already specific control blocks enabled, like
770+
net_pkt_cb_ieee802154, the actual pkt control block size will be the
771+
maximum of them.
772+
758773
config NET_HEADERS_ALWAYS_CONTIGUOUS
759774
bool
760775
help

subsys/net/ip/net_pkt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ int net_pkt_copy(struct net_pkt *pkt_dst,
20162016
return 0;
20172017
}
20182018

2019-
#if defined(NET_PKT_HAS_CONTROL_BLOCK)
2019+
#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
20202020
static inline void clone_pkt_cb(struct net_pkt *pkt, struct net_pkt *clone_pkt)
20212021
{
20222022
memcpy(net_pkt_cb(clone_pkt), net_pkt_cb(pkt), sizeof(clone_pkt->cb));

0 commit comments

Comments
 (0)