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()
41 if (!hsr->redbox || !is_valid_ether_addr(hsr->macaddress_redbox)) in hsr_addr_is_redbox()
44 return ether_addr_equal(addr, hsr->macaddress_redbox); in hsr_addr_is_redbox()
53 sn = rcu_dereference(hsr->self_node); in hsr_addr_is_self()
55 WARN_ONCE(1, "HSR: No self node\n"); in hsr_addr_is_self()
59 if (ether_addr_equal(addr, sn->macaddress_A) || in hsr_addr_is_self()
60 ether_addr_equal(addr, sn->macaddress_B)) in hsr_addr_is_self()
72 struct hsr_node *node; in find_node_by_addr_A() local
74 list_for_each_entry_rcu(node, node_db, mac_list) { in find_node_by_addr_A()
75 if (ether_addr_equal(node->macaddress_A, addr)) in find_node_by_addr_A()
76 return node; in find_node_by_addr_A()
82 /* Check if node for a given MAC address is already present in data base
101 return -ENOMEM; in hsr_create_self_node()
103 ether_addr_copy(sn->macaddress_A, addr_a); in hsr_create_self_node()
104 ether_addr_copy(sn->macaddress_B, addr_b); in hsr_create_self_node()
106 spin_lock_bh(&hsr->list_lock); in hsr_create_self_node()
107 old = rcu_replace_pointer(hsr->self_node, sn, in hsr_create_self_node()
108 lockdep_is_held(&hsr->list_lock)); in hsr_create_self_node()
109 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
120 spin_lock_bh(&hsr->list_lock); in hsr_del_self_node()
121 old = rcu_replace_pointer(hsr->self_node, NULL, in hsr_del_self_node()
122 lockdep_is_held(&hsr->list_lock)); in hsr_del_self_node()
123 spin_unlock_bh(&hsr->list_lock); in hsr_del_self_node()
130 struct hsr_node *node; in hsr_del_nodes() local
133 list_for_each_entry_safe(node, tmp, node_db, mac_list) in hsr_del_nodes()
134 kfree(node); in hsr_del_nodes()
138 struct hsr_node *node) in prp_handle_san_frame() argument
140 /* Mark if the SAN node is over LAN_A or LAN_B */ in prp_handle_san_frame()
142 node->san_a = true; in prp_handle_san_frame()
147 node->san_b = true; in prp_handle_san_frame()
150 /* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A;
152 * originating from the newly added node.
160 struct hsr_node *new_node, *node; in hsr_add_node() local
168 ether_addr_copy(new_node->macaddress_A, addr); in hsr_add_node()
169 spin_lock_init(&new_node->seq_out_lock); in hsr_add_node()
176 new_node->time_in[i] = now; in hsr_add_node()
177 new_node->time_out[i] = now; in hsr_add_node()
180 new_node->seq_out[i] = seq_out; in hsr_add_node()
182 if (san && hsr->proto_ops->handle_san_frame) in hsr_add_node()
183 hsr->proto_ops->handle_san_frame(san, rx_port, new_node); in hsr_add_node()
185 spin_lock_bh(&hsr->list_lock); in hsr_add_node()
186 list_for_each_entry_rcu(node, node_db, mac_list, in hsr_add_node()
187 lockdep_is_held(&hsr->list_lock)) { in hsr_add_node()
188 if (ether_addr_equal(node->macaddress_A, addr)) in hsr_add_node()
190 if (ether_addr_equal(node->macaddress_B, addr)) in hsr_add_node()
193 list_add_tail_rcu(&new_node->mac_list, node_db); in hsr_add_node()
194 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
197 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
199 return node; in hsr_add_node()
202 void prp_update_san_info(struct hsr_node *node, bool is_sup) in prp_update_san_info() argument
207 node->san_a = false; in prp_update_san_info()
208 node->san_b = false; in prp_update_san_info()
217 struct hsr_priv *hsr = port->hsr; in hsr_get_node()
218 struct hsr_node *node; in hsr_get_node() local
229 list_for_each_entry_rcu(node, node_db, mac_list) { in hsr_get_node()
230 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
231 if (hsr->proto_ops->update_san_info) in hsr_get_node()
232 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
233 return node; in hsr_get_node()
235 if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { in hsr_get_node()
236 if (hsr->proto_ops->update_san_info) in hsr_get_node()
237 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
238 return node; in hsr_get_node()
242 /* Check if required node is not in proxy nodes table */ in hsr_get_node()
243 list_for_each_entry_rcu(node, &hsr->proxy_node_db, mac_list) { in hsr_get_node()
244 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
245 if (hsr->proto_ops->update_san_info) in hsr_get_node()
246 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
247 return node; in hsr_get_node()
251 /* Everyone may create a node entry, connected node to a HSR/PRP in hsr_get_node()
254 if (ethhdr->h_proto == htons(ETH_P_PRP) || in hsr_get_node()
255 ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_get_node()
257 if (skb->mac_len < sizeof(struct hsr_ethhdr)) in hsr_get_node()
263 seq_out = hsr_get_skb_sequence_nr(skb) - 1; in hsr_get_node()
275 return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out, in hsr_get_node()
281 * node.
285 struct hsr_node *node_curr = frame->node_src; in hsr_handle_sup_frame()
286 struct hsr_port *port_rcv = frame->port_rcv; in hsr_handle_sup_frame()
287 struct hsr_priv *hsr = port_rcv->hsr; in hsr_handle_sup_frame()
298 /* Here either frame->skb_hsr or frame->skb_prp should be in hsr_handle_sup_frame()
302 if (frame->skb_hsr) in hsr_handle_sup_frame()
303 skb = frame->skb_hsr; in hsr_handle_sup_frame()
304 else if (frame->skb_prp) in hsr_handle_sup_frame()
305 skb = frame->skb_prp; in hsr_handle_sup_frame()
306 else if (frame->skb_std) in hsr_handle_sup_frame()
307 skb = frame->skb_std; in hsr_handle_sup_frame()
319 if (ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_handle_sup_frame()
331 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
334 node_db = &port_rcv->hsr->node_db; in hsr_handle_sup_frame()
335 node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); in hsr_handle_sup_frame()
337 /* No frame received from AddrA of this node yet */ in hsr_handle_sup_frame()
338 node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, in hsr_handle_sup_frame()
339 HSR_SEQNR_START - 1, true, in hsr_handle_sup_frame()
340 port_rcv->type); in hsr_handle_sup_frame()
344 /* Node has already been merged */ in hsr_handle_sup_frame()
353 hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data; in hsr_handle_sup_frame()
355 if (hsr_sup_tlv->HSR_TLV_type == PRP_TLV_REDBOX_MAC) { in hsr_handle_sup_frame()
360 if (hsr_sup_tlv->HSR_TLV_length != 6) in hsr_handle_sup_frame()
369 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
371 /* Check if redbox mac and node mac are equal. */ in hsr_handle_sup_frame()
372 if (!ether_addr_equal(node_real->macaddress_A, hsr_sp->macaddress_A)) { in hsr_handle_sup_frame()
378 ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); in hsr_handle_sup_frame()
379 spin_lock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
381 if (!node_curr->time_in_stale[i] && in hsr_handle_sup_frame()
382 time_after(node_curr->time_in[i], node_real->time_in[i])) { in hsr_handle_sup_frame()
383 node_real->time_in[i] = node_curr->time_in[i]; in hsr_handle_sup_frame()
384 node_real->time_in_stale[i] = in hsr_handle_sup_frame()
385 node_curr->time_in_stale[i]; in hsr_handle_sup_frame()
387 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) in hsr_handle_sup_frame()
388 node_real->seq_out[i] = node_curr->seq_out[i]; in hsr_handle_sup_frame()
390 spin_unlock_bh(&node_real->seq_out_lock); in hsr_handle_sup_frame()
391 node_real->addr_B_port = port_rcv->type; in hsr_handle_sup_frame()
393 spin_lock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
394 if (!node_curr->removed) { in hsr_handle_sup_frame()
395 list_del_rcu(&node_curr->mac_list); in hsr_handle_sup_frame()
396 node_curr->removed = true; in hsr_handle_sup_frame()
399 spin_unlock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
408 * If the frame was sent by a node's B interface, replace the source
409 * address with that node's "official" address (macaddress_A) so that upper
412 void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) in hsr_addr_subst_source() argument
419 memcpy(&eth_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); in hsr_addr_subst_source()
423 * 'port' is the outgoing interface
426 * recipient interface MAC address, regardless of whether that is the
427 * recipient's A or B interface.
441 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) in hsr_addr_subst_dest()
444 node_dst = find_node_by_addr_A(&port->hsr->node_db, in hsr_addr_subst_dest()
445 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
446 if (!node_dst && port->hsr->redbox) in hsr_addr_subst_dest()
447 node_dst = find_node_by_addr_A(&port->hsr->proxy_node_db, in hsr_addr_subst_dest()
448 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
451 if (port->hsr->prot_version != PRP_V1 && net_ratelimit()) in hsr_addr_subst_dest()
452 netdev_err(skb->dev, "%s: Unknown node\n", __func__); in hsr_addr_subst_dest()
455 if (port->type != node_dst->addr_B_port) in hsr_addr_subst_dest()
458 if (is_valid_ether_addr(node_dst->macaddress_B)) in hsr_addr_subst_dest()
459 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); in hsr_addr_subst_dest()
462 void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, in hsr_register_frame_in() argument
467 * re-register and resume communications. in hsr_register_frame_in()
469 if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) && in hsr_register_frame_in()
470 seq_nr_before(sequence_nr, node->seq_out[port->type])) in hsr_register_frame_in()
473 node->time_in[port->type] = jiffies; in hsr_register_frame_in()
474 node->time_in_stale[port->type] = false; in hsr_register_frame_in()
478 * ethhdr->h_source address and skb->mac_header set.
481 * 1 if frame can be shown to have been sent recently on this interface,
485 int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, in hsr_register_frame_out() argument
488 spin_lock_bh(&node->seq_out_lock); in hsr_register_frame_out()
489 if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) && in hsr_register_frame_out()
490 time_is_after_jiffies(node->time_out[port->type] + in hsr_register_frame_out()
492 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
496 node->time_out[port->type] = jiffies; in hsr_register_frame_out()
497 node->seq_out[port->type] = sequence_nr; in hsr_register_frame_out()
498 spin_unlock_bh(&node->seq_out_lock); in hsr_register_frame_out()
503 struct hsr_node *node) in get_late_port() argument
505 if (node->time_in_stale[HSR_PT_SLAVE_A]) in get_late_port()
507 if (node->time_in_stale[HSR_PT_SLAVE_B]) in get_late_port()
510 if (time_after(node->time_in[HSR_PT_SLAVE_B], in get_late_port()
511 node->time_in[HSR_PT_SLAVE_A] + in get_late_port()
514 if (time_after(node->time_in[HSR_PT_SLAVE_A], in get_late_port()
515 node->time_in[HSR_PT_SLAVE_B] + in get_late_port()
528 struct hsr_node *node; in hsr_prune_nodes() local
534 spin_lock_bh(&hsr->list_lock); in hsr_prune_nodes()
535 list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { in hsr_prune_nodes()
536 /* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A] in hsr_prune_nodes()
538 * the master port. Thus the master node will be repeatedly in hsr_prune_nodes()
541 if (hsr_addr_is_self(hsr, node->macaddress_A)) in hsr_prune_nodes()
545 time_a = node->time_in[HSR_PT_SLAVE_A]; in hsr_prune_nodes()
546 time_b = node->time_in[HSR_PT_SLAVE_B]; in hsr_prune_nodes()
548 /* Check for timestamps old enough to risk wrap-around */ in hsr_prune_nodes()
550 node->time_in_stale[HSR_PT_SLAVE_A] = true; in hsr_prune_nodes()
552 node->time_in_stale[HSR_PT_SLAVE_B] = true; in hsr_prune_nodes()
554 /* Get age of newest frame from node. in hsr_prune_nodes()
559 if (node->time_in_stale[HSR_PT_SLAVE_A] || in hsr_prune_nodes()
560 (!node->time_in_stale[HSR_PT_SLAVE_B] && in hsr_prune_nodes()
568 port = get_late_port(hsr, node); in hsr_prune_nodes()
570 hsr_nl_ringerror(hsr, node->macaddress_A, port); in hsr_prune_nodes()
577 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_nodes()
578 if (!node->removed) { in hsr_prune_nodes()
579 list_del_rcu(&node->mac_list); in hsr_prune_nodes()
580 node->removed = true; in hsr_prune_nodes()
582 kfree_rcu(node, rcu_head); in hsr_prune_nodes()
586 spin_unlock_bh(&hsr->list_lock); in hsr_prune_nodes()
589 mod_timer(&hsr->prune_timer, in hsr_prune_nodes()
597 struct hsr_node *node; in hsr_prune_proxy_nodes() local
600 spin_lock_bh(&hsr->list_lock); in hsr_prune_proxy_nodes()
601 list_for_each_entry_safe(node, tmp, &hsr->proxy_node_db, mac_list) { in hsr_prune_proxy_nodes()
602 /* Don't prune RedBox node. */ in hsr_prune_proxy_nodes()
603 if (hsr_addr_is_redbox(hsr, node->macaddress_A)) in hsr_prune_proxy_nodes()
606 timestamp = node->time_in[HSR_PT_INTERLINK]; in hsr_prune_proxy_nodes()
611 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_proxy_nodes()
612 if (!node->removed) { in hsr_prune_proxy_nodes()
613 list_del_rcu(&node->mac_list); in hsr_prune_proxy_nodes()
614 node->removed = true; in hsr_prune_proxy_nodes()
616 kfree_rcu(node, rcu_head); in hsr_prune_proxy_nodes()
621 spin_unlock_bh(&hsr->list_lock); in hsr_prune_proxy_nodes()
624 mod_timer(&hsr->prune_proxy_timer, in hsr_prune_proxy_nodes()
631 struct hsr_node *node; in hsr_get_next_node() local
634 node = list_first_or_null_rcu(&hsr->node_db, in hsr_get_next_node()
636 if (node) in hsr_get_next_node()
637 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
638 return node; in hsr_get_next_node()
641 node = _pos; in hsr_get_next_node()
642 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { in hsr_get_next_node()
643 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
644 return node; in hsr_get_next_node()
659 struct hsr_node *node; in hsr_get_node_data() local
663 node = find_node_by_addr_A(&hsr->node_db, addr); in hsr_get_node_data()
664 if (!node) in hsr_get_node_data()
665 return -ENOENT; in hsr_get_node_data()
667 ether_addr_copy(addr_b, node->macaddress_B); in hsr_get_node_data()
669 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; in hsr_get_node_data()
670 if (node->time_in_stale[HSR_PT_SLAVE_A]) in hsr_get_node_data()
679 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; in hsr_get_node_data()
680 if (node->time_in_stale[HSR_PT_SLAVE_B]) in hsr_get_node_data()
689 /* Present sequence numbers as if they were incoming on interface */ in hsr_get_node_data()
690 *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; in hsr_get_node_data()
691 *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; in hsr_get_node_data()
693 if (node->addr_B_port != HSR_PT_NONE) { in hsr_get_node_data()
694 port = hsr_port_get_hsr(hsr, node->addr_B_port); in hsr_get_node_data()
695 *addr_b_ifindex = port->dev->ifindex; in hsr_get_node_data()
697 *addr_b_ifindex = -1; in hsr_get_node_data()