Lines Matching +full:interface +full:- +full:node

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2011-2014 Autronica Fire and Security AS
5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
8 * interface. A frame is identified by its source MAC address and its HSR
22 /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
30 if ((int)b - a == 32768) in seq_nr_after()
33 return (((s16)(b - a)) < 0); in seq_nr_after()
42 if (!hsr->redbox || !is_valid_ether_addr(hsr->macaddress_redbox)) in hsr_addr_is_redbox()
45 return ether_addr_equal(addr, hsr->macaddress_redbox); in hsr_addr_is_redbox()
54 sn = rcu_dereference(hsr->self_node); in hsr_addr_is_self()
56 WARN_ONCE(1, "HSR: No self node\n"); in hsr_addr_is_self()
60 if (ether_addr_equal(addr, sn->macaddress_A) || in hsr_addr_is_self()
61 ether_addr_equal(addr, sn->macaddress_B)) in hsr_addr_is_self()
73 struct hsr_node *node; in find_node_by_addr_A() local
75 list_for_each_entry_rcu(node, node_db, mac_list) { in find_node_by_addr_A()
76 if (ether_addr_equal(node->macaddress_A, addr)) in find_node_by_addr_A()
77 return node; in find_node_by_addr_A()
83 /* Check if node for a given MAC address is already present in data base
102 return -ENOMEM; in hsr_create_self_node()
104 ether_addr_copy(sn->macaddress_A, addr_a); in hsr_create_self_node()
105 ether_addr_copy(sn->macaddress_B, addr_b); in hsr_create_self_node()
107 spin_lock_bh(&hsr->list_lock); in hsr_create_self_node()
108 old = rcu_replace_pointer(hsr->self_node, sn, in hsr_create_self_node()
109 lockdep_is_held(&hsr->list_lock)); in hsr_create_self_node()
110 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
121 spin_lock_bh(&hsr->list_lock); in hsr_del_self_node()
122 old = rcu_replace_pointer(hsr->self_node, NULL, in hsr_del_self_node()
123 lockdep_is_held(&hsr->list_lock)); in hsr_del_self_node()
124 spin_unlock_bh(&hsr->list_lock); in hsr_del_self_node()
131 struct hsr_node *node; in hsr_del_nodes() local
134 list_for_each_entry_safe(node, tmp, node_db, mac_list) in hsr_del_nodes()
135 kfree(node); in hsr_del_nodes()
139 struct hsr_node *node) in prp_handle_san_frame() argument
141 /* Mark if the SAN node is over LAN_A or LAN_B */ in prp_handle_san_frame()
143 node->san_a = true; in prp_handle_san_frame()
148 node->san_b = true; in prp_handle_san_frame()
151 /* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A;
153 * originating from the newly added node.
161 struct hsr_node *new_node, *node; in hsr_add_node() local
169 ether_addr_copy(new_node->macaddress_A, addr); in hsr_add_node()
170 spin_lock_init(&new_node->seq_out_lock); in hsr_add_node()
177 new_node->time_in[i] = now; in hsr_add_node()
178 new_node->time_out[i] = now; in hsr_add_node()
181 new_node->seq_out[i] = seq_out; in hsr_add_node()
182 new_node->seq_expected[i] = seq_out + 1; in hsr_add_node()
183 new_node->seq_start[i] = seq_out + 1; in hsr_add_node()
186 if (san && hsr->proto_ops->handle_san_frame) in hsr_add_node()
187 hsr->proto_ops->handle_san_frame(san, rx_port, new_node); in hsr_add_node()
189 spin_lock_bh(&hsr->list_lock); in hsr_add_node()
190 list_for_each_entry_rcu(node, node_db, mac_list, in hsr_add_node()
191 lockdep_is_held(&hsr->list_lock)) { in hsr_add_node()
192 if (ether_addr_equal(node->macaddress_A, addr)) in hsr_add_node()
194 if (ether_addr_equal(node->macaddress_B, addr)) in hsr_add_node()
197 list_add_tail_rcu(&new_node->mac_list, node_db); in hsr_add_node()
198 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
201 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
203 return node; in hsr_add_node()
206 void prp_update_san_info(struct hsr_node *node, bool is_sup) in prp_update_san_info() argument
211 node->san_a = false; in prp_update_san_info()
212 node->san_b = false; in prp_update_san_info()
221 struct hsr_priv *hsr = port->hsr; in hsr_get_node()
222 struct hsr_node *node; in hsr_get_node() local
233 list_for_each_entry_rcu(node, node_db, mac_list) { in hsr_get_node()
234 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
235 if (hsr->proto_ops->update_san_info) in hsr_get_node()
236 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
237 return node; in hsr_get_node()
239 if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { in hsr_get_node()
240 if (hsr->proto_ops->update_san_info) in hsr_get_node()
241 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
242 return node; in hsr_get_node()
246 /* Check if required node is not in proxy nodes table */ in hsr_get_node()
247 list_for_each_entry_rcu(node, &hsr->proxy_node_db, mac_list) { in hsr_get_node()
248 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
249 if (hsr->proto_ops->update_san_info) in hsr_get_node()
250 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
251 return node; in hsr_get_node()
255 /* Everyone may create a node entry, connected node to a HSR/PRP in hsr_get_node()
258 if (ethhdr->h_proto == htons(ETH_P_PRP) || in hsr_get_node()
259 ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_get_node()
261 if (skb->mac_len < sizeof(struct hsr_ethhdr)) in hsr_get_node()
267 seq_out = hsr_get_skb_sequence_nr(skb) - 1; in hsr_get_node()
279 return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out, in hsr_get_node()
285 * node.
289 struct hsr_node *node_curr = frame->node_src; in hsr_handle_sup_frame()
290 struct hsr_port *port_rcv = frame->port_rcv; in hsr_handle_sup_frame()
291 struct hsr_priv *hsr = port_rcv->hsr; in hsr_handle_sup_frame()
302 /* Here either frame->skb_hsr or frame->skb_prp should be in hsr_handle_sup_frame()
306 if (frame->skb_hsr) in hsr_handle_sup_frame()
307 skb = frame->skb_hsr; in hsr_handle_sup_frame()
308 else if (frame->skb_prp) in hsr_handle_sup_frame()
309 skb = frame->skb_prp; in hsr_handle_sup_frame()
310 else if (frame->skb_std) in hsr_handle_sup_frame()
311 skb = frame->skb_std; in hsr_handle_sup_frame()
323 if (ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_handle_sup_frame()
335 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
338 node_db = &port_rcv->hsr->node_db; in hsr_handle_sup_frame()
339 node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); in hsr_handle_sup_frame()
341 /* No frame received from AddrA of this node yet */ in hsr_handle_sup_frame()
342 node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, in hsr_handle_sup_frame()
343 HSR_SEQNR_START - 1, true, in hsr_handle_sup_frame()
344 port_rcv->type); in hsr_handle_sup_frame()
348 /* Node has already been merged */ in hsr_handle_sup_frame()
357 hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data; in hsr_handle_sup_frame()
359 if (hsr_sup_tlv->HSR_TLV_type == PRP_TLV_REDBOX_MAC) { in hsr_handle_sup_frame()
364 if (hsr_sup_tlv->HSR_TLV_length != 6) in hsr_handle_sup_frame()
373 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
375 /* Check if redbox mac and node mac are equal. */ in hsr_handle_sup_frame()
376 if (!ether_addr_equal(node_real->macaddress_A, hsr_sp->macaddress_A)) { in hsr_handle_sup_frame()
382 ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); in hsr_handle_sup_frame()
383 spin_lock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
385 if (!node_curr->time_in_stale[i] && in hsr_handle_sup_frame()
386 time_after(node_curr->time_in[i], node_real->time_in[i])) { in hsr_handle_sup_frame()
387 node_real->time_in[i] = node_curr->time_in[i]; in hsr_handle_sup_frame()
388 node_real->time_in_stale[i] = in hsr_handle_sup_frame()
389 node_curr->time_in_stale[i]; in hsr_handle_sup_frame()
391 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) in hsr_handle_sup_frame()
392 node_real->seq_out[i] = node_curr->seq_out[i]; in hsr_handle_sup_frame()
394 spin_unlock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
395 node_real->addr_B_port = port_rcv->type; in hsr_handle_sup_frame()
397 spin_lock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
398 if (!node_curr->removed) { in hsr_handle_sup_frame()
399 list_del_rcu(&node_curr->mac_list); in hsr_handle_sup_frame()
400 node_curr->removed = true; in hsr_handle_sup_frame()
403 spin_unlock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
412 * If the frame was sent by a node's B interface, replace the source
413 * address with that node's "official" address (macaddress_A) so that upper
416 void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) in hsr_addr_subst_source() argument
423 memcpy(&eth_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); in hsr_addr_subst_source()
427 * 'port' is the outgoing interface
430 * recipient interface MAC address, regardless of whether that is the
431 * recipient's A or B interface.
445 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) in hsr_addr_subst_dest()
448 node_dst = find_node_by_addr_A(&port->hsr->node_db, in hsr_addr_subst_dest()
449 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
450 if (!node_dst && port->hsr->redbox) in hsr_addr_subst_dest()
451 node_dst = find_node_by_addr_A(&port->hsr->proxy_node_db, in hsr_addr_subst_dest()
452 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
455 if (port->hsr->prot_version != PRP_V1 && net_ratelimit()) in hsr_addr_subst_dest()
456 netdev_err(skb->dev, "%s: Unknown node\n", __func__); in hsr_addr_subst_dest()
459 if (port->type != node_dst->addr_B_port) in hsr_addr_subst_dest()
462 if (is_valid_ether_addr(node_dst->macaddress_B)) in hsr_addr_subst_dest()
463 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); in hsr_addr_subst_dest()
466 void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, in hsr_register_frame_in() argument
471 * re-register and resume communications. in hsr_register_frame_in()
473 if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) && in hsr_register_frame_in()
474 seq_nr_before(sequence_nr, node->seq_out[port->type])) in hsr_register_frame_in()
477 node->time_in[port->type] = jiffies; in hsr_register_frame_in()
478 node->time_in_stale[port->type] = false; in hsr_register_frame_in()
482 * ethhdr->h_source address and skb->mac_header set.
485 * 1 if frame can be shown to have been sent recently on this interface,
491 struct hsr_node *node = frame->node_src; in hsr_register_frame_out() local
492 u16 sequence_nr = frame->sequence_nr; in hsr_register_frame_out()
494 spin_lock_bh(&node->seq_out_lock); in hsr_register_frame_out()
495 if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) && in hsr_register_frame_out()
496 time_is_after_jiffies(node->time_out[port->type] + in hsr_register_frame_out()
498 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
502 node->time_out[port->type] = jiffies; in hsr_register_frame_out()
503 node->seq_out[port->type] = sequence_nr; in hsr_register_frame_out()
504 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
520 * 'port' is the outgoing interface
524 * 1 if frame can be shown to have been sent recently on this interface,
531 struct hsr_node *node; in prp_register_frame_out() local
536 /* out-going frames are always in order in prp_register_frame_out()
539 if (frame->port_rcv->type == HSR_PT_MASTER) in prp_register_frame_out()
545 if (port->type != HSR_PT_MASTER) in prp_register_frame_out()
548 node = frame->node_src; in prp_register_frame_out()
549 sequence_nr = frame->sequence_nr; in prp_register_frame_out()
551 rcv_port = frame->port_rcv->type; in prp_register_frame_out()
555 spin_lock_bh(&node->seq_out_lock); in prp_register_frame_out()
556 if (time_is_before_jiffies(node->time_out[port->type] + in prp_register_frame_out()
558 (node->seq_start[rcv_port] == node->seq_expected[rcv_port] && in prp_register_frame_out()
559 node->seq_start[other_port] == node->seq_expected[other_port])) { in prp_register_frame_out()
560 /* the node hasn't been sending for a while in prp_register_frame_out()
563 node->seq_start[rcv_port] = sequence_nr; in prp_register_frame_out()
564 } else if (seq_nr_before(sequence_nr, node->seq_expected[other_port]) && in prp_register_frame_out()
565 seq_nr_before_or_eq(node->seq_start[other_port], sequence_nr)) { in prp_register_frame_out()
569 node->seq_start[other_port] = sequence_exp; in prp_register_frame_out()
570 node->seq_expected[rcv_port] = sequence_exp; in prp_register_frame_out()
571 node->seq_start[rcv_port] = node->seq_expected[rcv_port]; in prp_register_frame_out()
572 spin_unlock_bh(&node->seq_out_lock); in prp_register_frame_out()
579 node->seq_start[other_port] = node->seq_expected[other_port]; in prp_register_frame_out()
580 node->seq_expected[rcv_port] = sequence_exp; in prp_register_frame_out()
581 sequence_diff = sequence_exp - node->seq_start[rcv_port]; in prp_register_frame_out()
583 node->seq_start[rcv_port] = sequence_exp - PRP_DROP_WINDOW_LEN; in prp_register_frame_out()
585 node->time_out[port->type] = jiffies; in prp_register_frame_out()
586 node->seq_out[port->type] = sequence_nr; in prp_register_frame_out()
587 spin_unlock_bh(&node->seq_out_lock); in prp_register_frame_out()
596 struct hsr_node *node) in get_late_port() argument
598 if (node->time_in_stale[HSR_PT_SLAVE_A]) in get_late_port()
600 if (node->time_in_stale[HSR_PT_SLAVE_B]) in get_late_port()
603 if (time_after(node->time_in[HSR_PT_SLAVE_B], in get_late_port()
604 node->time_in[HSR_PT_SLAVE_A] + in get_late_port()
607 if (time_after(node->time_in[HSR_PT_SLAVE_A], in get_late_port()
608 node->time_in[HSR_PT_SLAVE_B] + in get_late_port()
621 struct hsr_node *node; in hsr_prune_nodes() local
627 spin_lock_bh(&hsr->list_lock); in hsr_prune_nodes()
628 list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { in hsr_prune_nodes()
629 /* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A] in hsr_prune_nodes()
631 * the master port. Thus the master node will be repeatedly in hsr_prune_nodes()
634 if (hsr_addr_is_self(hsr, node->macaddress_A)) in hsr_prune_nodes()
638 time_a = node->time_in[HSR_PT_SLAVE_A]; in hsr_prune_nodes()
639 time_b = node->time_in[HSR_PT_SLAVE_B]; in hsr_prune_nodes()
641 /* Check for timestamps old enough to risk wrap-around */ in hsr_prune_nodes()
643 node->time_in_stale[HSR_PT_SLAVE_A] = true; in hsr_prune_nodes()
645 node->time_in_stale[HSR_PT_SLAVE_B] = true; in hsr_prune_nodes()
647 /* Get age of newest frame from node. in hsr_prune_nodes()
652 if (node->time_in_stale[HSR_PT_SLAVE_A] || in hsr_prune_nodes()
653 (!node->time_in_stale[HSR_PT_SLAVE_B] && in hsr_prune_nodes()
661 port = get_late_port(hsr, node); in hsr_prune_nodes()
663 hsr_nl_ringerror(hsr, node->macaddress_A, port); in hsr_prune_nodes()
670 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_nodes()
671 if (!node->removed) { in hsr_prune_nodes()
672 list_del_rcu(&node->mac_list); in hsr_prune_nodes()
673 node->removed = true; in hsr_prune_nodes()
675 kfree_rcu(node, rcu_head); in hsr_prune_nodes()
679 spin_unlock_bh(&hsr->list_lock); in hsr_prune_nodes()
682 mod_timer(&hsr->prune_timer, in hsr_prune_nodes()
690 struct hsr_node *node; in hsr_prune_proxy_nodes() local
693 spin_lock_bh(&hsr->list_lock); in hsr_prune_proxy_nodes()
694 list_for_each_entry_safe(node, tmp, &hsr->proxy_node_db, mac_list) { in hsr_prune_proxy_nodes()
695 /* Don't prune RedBox node. */ in hsr_prune_proxy_nodes()
696 if (hsr_addr_is_redbox(hsr, node->macaddress_A)) in hsr_prune_proxy_nodes()
699 timestamp = node->time_in[HSR_PT_INTERLINK]; in hsr_prune_proxy_nodes()
704 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_proxy_nodes()
705 if (!node->removed) { in hsr_prune_proxy_nodes()
706 list_del_rcu(&node->mac_list); in hsr_prune_proxy_nodes()
707 node->removed = true; in hsr_prune_proxy_nodes()
709 kfree_rcu(node, rcu_head); in hsr_prune_proxy_nodes()
714 spin_unlock_bh(&hsr->list_lock); in hsr_prune_proxy_nodes()
717 mod_timer(&hsr->prune_proxy_timer, in hsr_prune_proxy_nodes()
724 struct hsr_node *node; in hsr_get_next_node() local
727 node = list_first_or_null_rcu(&hsr->node_db, in hsr_get_next_node()
729 if (node) in hsr_get_next_node()
730 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
731 return node; in hsr_get_next_node()
734 node = _pos; in hsr_get_next_node()
735 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { in hsr_get_next_node()
736 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
737 return node; in hsr_get_next_node()
752 struct hsr_node *node; in hsr_get_node_data() local
756 node = find_node_by_addr_A(&hsr->node_db, addr); in hsr_get_node_data()
757 if (!node) in hsr_get_node_data()
758 return -ENOENT; in hsr_get_node_data()
760 ether_addr_copy(addr_b, node->macaddress_B); in hsr_get_node_data()
762 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; in hsr_get_node_data()
763 if (node->time_in_stale[HSR_PT_SLAVE_A]) in hsr_get_node_data()
772 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; in hsr_get_node_data()
773 if (node->time_in_stale[HSR_PT_SLAVE_B]) in hsr_get_node_data()
782 /* Present sequence numbers as if they were incoming on interface */ in hsr_get_node_data()
783 *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; in hsr_get_node_data()
784 *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; in hsr_get_node_data()
786 if (node->addr_B_port != HSR_PT_NONE) { in hsr_get_node_data()
787 port = hsr_port_get_hsr(hsr, node->addr_B_port); in hsr_get_node_data()
788 *addr_b_ifindex = port->dev->ifindex; in hsr_get_node_data()
790 *addr_b_ifindex = -1; in hsr_get_node_data()