Receiving PTP packets via the HSR interface does not make sense. The HSR stack will forward one copy to the user and ignore the duplicate from the other port. The PTP stack is however interested in both copies since they will have different content (due to different processing times within the HSR ring) and different timestamp information which is not forwarded at all. Forwarding a PTP packet by the HSR stack is undesired because the forwarding takes time, it is not accounted in the packet and this makes the outgoing PTP packet inaccurate and therefore useless. Drop all received PTP packets. For the PRP configuration it is the ether type, for HSR configuration it is the encapsulated protocol, that is checked. A PTP stack that is doing PTP over a HSR network needs to retrieve the PTP packet on the original slave interface where it was received. Signed-off-by: Sebastian Andrzej Siewior --- net/hsr/hsr_slave.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c index 0f2cedaffa347..7cc0641dbd137 100644 --- a/net/hsr/hsr_slave.c +++ b/net/hsr/hsr_slave.c @@ -44,8 +44,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) { /* Directly kill frames sent by ourselves */ - kfree_skb(skb); - goto finish_consume; + goto finish_free_consume; } /* For HSR, only tagged frames are expected (unless the device offloads @@ -64,10 +63,8 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) skb_reset_mac_header(skb); if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) || protocol == htons(ETH_P_HSR)) { - if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)) { - kfree_skb(skb); - goto finish_consume; - } + if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)) + goto finish_free_consume; skb_set_network_header(skb, ETH_HLEN + HSR_HLEN); } @@ -81,10 +78,32 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) hsr_forward_skb(skb, port, HSR_PT_NONE, false); spin_unlock_bh(&hsr->seqnr_lock); } else { + struct hsr_ethhdr *hsr_ethhdr; + + /* PTP packets are not supposed to be forwarded via HSR as-is. + * The latency introduced by forwarding renders the time + * information useless. Userland needs to capture the packet on + * the original interface instead of hsr. + */ + if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) || + protocol == htons(ETH_P_HSR)) { + /* HSR */ + hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb); + if (hsr_ethhdr->hsr_tag.encap_proto == htons(ETH_P_1588)) + goto finish_free_consume; + } else { + /* PRP */ + if (protocol == htons(ETH_P_1588)) + goto finish_free_consume; + } + hsr_forward_skb(skb, port, HSR_PT_NONE, false); } -finish_consume: + return RX_HANDLER_CONSUMED; + +finish_free_consume: + kfree_skb(skb); return RX_HANDLER_CONSUMED; finish_pass: -- 2.53.0