Skip to content

Commit

Permalink
net: pkt: Add flags to indicate the pkt should be timestamped
Browse files Browse the repository at this point in the history
This is the first commit from the set of patches that brings to the
Zephyr, SO_TIMESTAMPING socket level option. This enables to pass to
the network driver information whether given network packet should
be timestamped or not.

Signed-off-by: Adam Wojasinski <[email protected]>
  • Loading branch information
awojasinski authored and nashif committed Jun 13, 2024
1 parent c87c36d commit 56338de
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/zephyr/net/net_pkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ struct net_pkt {
*/
#if defined(CONFIG_NET_IP_FRAGMENT)
uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
#endif
#if defined(CONFIG_NET_PKT_TIMESTAMP)
uint8_t tx_timestamping : 1; /** Timestamp transmitted packet */
uint8_t rx_timestamping : 1; /** Timestamp received packet */
#endif
/* bitfield byte alignment boundary */

Expand Down Expand Up @@ -389,6 +393,38 @@ static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
pkt->ptp_pkt = is_ptp;
}

static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_PKT_TIMESTAMP)
return !!(pkt->tx_timestamping);
#else
return false;
#endif
}

static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
{
#if defined(CONFIG_NET_PKT_TIMESTAMP)
pkt->tx_timestamping = is_timestamping;
#endif
}

static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_PKT_TIMESTAMP)
return !!(pkt->rx_timestamping);
#else
return false;
#endif
}

static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
{
#if defined(CONFIG_NET_PKT_TIMESTAMP)
pkt->rx_timestamping = is_timestamping;
#endif
}

static inline bool net_pkt_is_captured(struct net_pkt *pkt)
{
return !!(pkt->captured);
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/ip/net_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,8 @@ static void clone_pkt_attributes(struct net_pkt *pkt, struct net_pkt *clone_pkt)
net_pkt_set_captured(clone_pkt, net_pkt_is_captured(pkt));
net_pkt_set_eof(clone_pkt, net_pkt_eof(pkt));
net_pkt_set_ptp(clone_pkt, net_pkt_is_ptp(pkt));
net_pkt_set_tx_timestamping(clone_pkt, net_pkt_is_tx_timestamping(pkt));
net_pkt_set_rx_timestamping(clone_pkt, net_pkt_is_rx_timestamping(pkt));
net_pkt_set_forwarding(clone_pkt, net_pkt_forwarding(pkt));
net_pkt_set_chksum_done(clone_pkt, net_pkt_is_chksum_done(pkt));
net_pkt_set_ip_reassembled(pkt, net_pkt_is_ip_reassembled(pkt));
Expand Down
10 changes: 10 additions & 0 deletions tests/net/net_pkt/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ ZTEST(net_pkt_test_suite, test_net_pkt_clone)
net_pkt_set_captured(pkt, true);
net_pkt_set_eof(pkt, true);
net_pkt_set_ptp(pkt, true);
net_pkt_set_tx_timestamping(pkt, true);
net_pkt_set_rx_timestamping(pkt, true);
net_pkt_set_forwarding(pkt, true);

net_pkt_set_l2_bridged(pkt, true);
Expand Down Expand Up @@ -855,6 +857,14 @@ ZTEST(net_pkt_test_suite, test_net_pkt_clone)
zassert_true(net_pkt_is_ptp(cloned_pkt),
"Cloned pkt ptp_pkt flag mismatch");

#if CONFIG_NET_PKT_TIMESTAMP
zassert_true(net_pkt_is_tx_timestamping(cloned_pkt),
"Cloned pkt tx_timestamping flag mismatch");

zassert_true(net_pkt_is_rx_timestamping(cloned_pkt),
"Cloned pkt rx_timestamping flag mismatch");
#endif

zassert_true(net_pkt_forwarding(cloned_pkt),
"Cloned pkt forwarding flag mismatch");

Expand Down

0 comments on commit 56338de

Please sign in to comment.