The upper layer can submit a port on which the skb should be sent and whether or not a HSR header should be added. Use this information while forwarding the packet: - If the port set, deliver it only on the requested port. - If a header is already present then skip parts of the stack: - The packet originates from the master port and we don't want to assign a sequence number to it, it needs to preserve the original one. - The existing h_source must be used (and not replaced). - The node should already exist in the node_db if "other" packets are exchaned. If the node information is not yet existing then creating it makes no sense because it is used for deduplication of incoming packets and this is not used in the PTP case. If no other packets are exchanged then the node_db will age and then removed. Signed-off-by: Sebastian Andrzej Siewior --- net/hsr/hsr_forward.c | 45 ++++++++++++++++++++++++++++++++++++--------- net/hsr/hsr_framereg.h | 2 ++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c index 699b0619cf469..95ae1d9dad26b 100644 --- a/net/hsr/hsr_forward.c +++ b/net/hsr/hsr_forward.c @@ -431,7 +431,7 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port, struct hsr_frame_info *frame) { - if (frame->port_rcv->type == HSR_PT_MASTER) { + if (frame->port_rcv->type == HSR_PT_MASTER && !frame->has_foreign_header) { hsr_addr_subst_dest(frame->node_src, skb, port); /* Address substitution (IEC62439-3 pp 26, 50): replace mac @@ -530,11 +530,12 @@ bool hsr_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port) static void hsr_forward_do(struct hsr_frame_info *frame) { struct hsr_port *port; - struct sk_buff *skb; bool sent = false; hsr_for_each_port(frame->port_rcv->hsr, port) { struct hsr_priv *hsr = port->hsr; + struct sk_buff *skb = NULL; + /* Don't send frame back the way it came */ if (port == frame->port_rcv) continue; @@ -553,6 +554,17 @@ static void hsr_forward_do(struct hsr_frame_info *frame) if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent) continue; + /* PTP TX packets have an outgoing port specified */ + if (frame->req_tx_port != HSR_PT_NONE && frame->req_tx_port != port->type) + continue; + /* PTP TX packets may already have a HSR header which needs to + * be preserved + */ + if (frame->has_foreign_header && frame->skb_std) { + skb = skb_clone(frame->skb_std, GFP_ATOMIC); + goto inject_into_stack; + } + /* Don't send frame over port where it has been sent before. * Also for SAN, this shouldn't be done. */ @@ -580,6 +592,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame) else skb = hsr->proto_ops->get_untagged_frame(frame, port); +inject_into_stack: if (!skb) { frame->port_rcv->dev->stats.rx_dropped++; continue; @@ -644,6 +657,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb, struct hsr_port *port = frame->port_rcv; struct hsr_priv *hsr = port->hsr; + if (frame->has_foreign_header) { + frame->skb_std = skb; + + WARN_ON_ONCE(port->type != HSR_PT_MASTER); + WARN_ON_ONCE(skb->mac_len < sizeof(struct hsr_ethhdr)); + return 0; + } /* HSRv0 supervisory frames double as a tag so treat them as tagged. */ if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) || proto == htons(ETH_P_HSR)) { @@ -685,7 +705,8 @@ int prp_fill_frame_info(__be16 proto, struct sk_buff *skb, } static int fill_frame_info(struct hsr_frame_info *frame, - struct sk_buff *skb, struct hsr_port *port) + struct sk_buff *skb, struct hsr_port *port, + enum hsr_port_type tx_port, bool has_hsr_header) { struct hsr_priv *hsr = port->hsr; struct hsr_vlan_ethhdr *vlan_hdr; @@ -708,10 +729,15 @@ static int fill_frame_info(struct hsr_frame_info *frame, if (port->type == HSR_PT_INTERLINK) n_db = &hsr->proxy_node_db; - frame->node_src = hsr_get_node(port, n_db, skb, - frame->is_supervision, port->type); - if (!frame->node_src) - return -1; /* Unknown node and !is_supervision, or no mem */ + frame->req_tx_port = tx_port; + frame->has_foreign_header = has_hsr_header; + + if (!frame->has_foreign_header) { + frame->node_src = hsr_get_node(port, n_db, skb, + frame->is_supervision, port->type); + if (!frame->node_src) + return -1; /* Unknown node and !is_supervision, or no mem */ + } ethhdr = (struct ethhdr *)skb_mac_header(skb); frame->is_vlan = false; @@ -748,10 +774,11 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port, struct hsr_frame_info frame; rcu_read_lock(); - if (fill_frame_info(&frame, skb, port) < 0) + if (fill_frame_info(&frame, skb, port, tx_port, has_hsr_header) < 0) goto out_drop; - hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); + if (!frame.has_foreign_header) + hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); hsr_forward_do(&frame); rcu_read_unlock(); /* Gets called for ingress frames as well as egress from master port. diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h index c65ecb9257348..7aeb59beb7fd8 100644 --- a/net/hsr/hsr_framereg.h +++ b/net/hsr/hsr_framereg.h @@ -27,6 +27,8 @@ struct hsr_frame_info { bool is_local_dest; bool is_local_exclusive; bool is_from_san; + bool has_foreign_header; + enum hsr_port_type req_tx_port; }; void hsr_del_self_node(struct hsr_priv *hsr); -- 2.53.0