[PATCH net-next v6 2/8] hsr: Use skb_clone() while adding the HSR header
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: 2026-09-23 12:14:19
Subsystem:
hsr network protocol, networking [general], the rest · Maintainers:
"David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
hsr_create_tagged_frame() creates a new skb where the HSR header can be prepended via __pskb_copy(). This does not copy the skb_shared_info part of the original skb so any timestamp request is lost. An alternative is to use skb_clone() where the skb_shared_info part is shared and then skb_cow_head() to make the header part writeable. This avoids touching manually the tx_flags and tskey members. Using skb_clone() allows also return early (after the clone) in the offloaded case so this can be unified a bit. This is a prepartion for PTP handling where timestatmps are requested. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- net/hsr/hsr_forward.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index 7734a521a96c2..0c16fbf8fd14f 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c@@ -342,16 +342,18 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame, /* set the lane id properly */ hsr_set_path_id(frame, hsr_ethhdr, port); return skb_clone(frame->skb_hsr, GFP_ATOMIC); - } else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) { - return skb_clone(frame->skb_std, GFP_ATOMIC); } - /* Create the new skb with enough headroom to fit the HSR tag */ - skb = __pskb_copy(frame->skb_std, - skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC); + skb = skb_clone(frame->skb_std, GFP_ATOMIC); if (!skb) return NULL; - skb_reset_mac_header(skb); + + if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) + return skb; + + /* Ensure the cloned skb has enough headroom to fit the HSR tag */ + if (skb_cow_head(skb, HSR_HLEN)) + goto err; if (skb->ip_summed == CHECKSUM_PARTIAL) skb->csum_start += HSR_HLEN;
@@ -360,15 +362,24 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame, if (frame->is_vlan) movelen += VLAN_HLEN; + /* The entire header area needs to be linear */ + if (!pskb_may_pull(skb, HSR_HLEN + movelen)) + goto err; + src = skb_mac_header(skb); dst = skb_push(skb, HSR_HLEN); memmove(dst, src, movelen); + skb_set_network_header(skb, ETH_HLEN + HSR_HLEN); skb_reset_mac_header(skb); + skb_reset_mac_len(skb); /* skb_put_padto free skb on error and hsr_fill_tag returns NULL in * that case */ return hsr_fill_tag(skb, frame, port, port->hsr->prot_version); +err: + kfree_skb(skb); + return NULL; } struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
--
2.55.0