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
24 /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
32 if ((int)b - a == 32768) in seq_nr_after()
35 return (((s16)(b - a)) < 0); in seq_nr_after()
43 struct hsr_node *node; in hsr_addr_is_self() local
45 node = list_first_or_null_rcu(&hsr->self_node_db, struct hsr_node, in hsr_addr_is_self()
47 if (!node) { in hsr_addr_is_self()
48 WARN_ONCE(1, "HSR: No self node\n"); in hsr_addr_is_self()
52 if (ether_addr_equal(addr, node->macaddress_A)) in hsr_addr_is_self()
54 if (ether_addr_equal(addr, node->macaddress_B)) in hsr_addr_is_self()
65 struct hsr_node *node; in find_node_by_addr_A() local
67 list_for_each_entry_rcu(node, node_db, mac_list) { in find_node_by_addr_A()
68 if (ether_addr_equal(node->macaddress_A, addr)) in find_node_by_addr_A()
69 return node; in find_node_by_addr_A()
82 struct list_head *self_node_db = &hsr->self_node_db; in hsr_create_self_node()
83 struct hsr_node *node, *oldnode; in hsr_create_self_node() local
85 node = kmalloc(sizeof(*node), GFP_KERNEL); in hsr_create_self_node()
86 if (!node) in hsr_create_self_node()
87 return -ENOMEM; in hsr_create_self_node()
89 ether_addr_copy(node->macaddress_A, addr_a); in hsr_create_self_node()
90 ether_addr_copy(node->macaddress_B, addr_b); in hsr_create_self_node()
92 spin_lock_bh(&hsr->list_lock); in hsr_create_self_node()
96 list_replace_rcu(&oldnode->mac_list, &node->mac_list); in hsr_create_self_node()
97 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
100 list_add_tail_rcu(&node->mac_list, self_node_db); in hsr_create_self_node()
101 spin_unlock_bh(&hsr->list_lock); in hsr_create_self_node()
109 struct list_head *self_node_db = &hsr->self_node_db; in hsr_del_self_node()
110 struct hsr_node *node; in hsr_del_self_node() local
112 spin_lock_bh(&hsr->list_lock); in hsr_del_self_node()
113 node = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list); in hsr_del_self_node()
114 if (node) { in hsr_del_self_node()
115 list_del_rcu(&node->mac_list); in hsr_del_self_node()
116 kfree_rcu(node, rcu_head); in hsr_del_self_node()
118 spin_unlock_bh(&hsr->list_lock); in hsr_del_self_node()
123 struct hsr_node *node; in hsr_del_nodes() local
126 list_for_each_entry_safe(node, tmp, node_db, mac_list) in hsr_del_nodes()
127 kfree(node); in hsr_del_nodes()
131 struct hsr_node *node) in prp_handle_san_frame() argument
133 /* Mark if the SAN node is over LAN_A or LAN_B */ in prp_handle_san_frame()
135 node->san_a = true; in prp_handle_san_frame()
140 node->san_b = true; in prp_handle_san_frame()
143 /* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A;
145 * originating from the newly added node.
153 struct hsr_node *new_node, *node; in hsr_add_node() local
161 ether_addr_copy(new_node->macaddress_A, addr); in hsr_add_node()
168 new_node->time_in[i] = now; in hsr_add_node()
169 new_node->time_out[i] = now; in hsr_add_node()
172 new_node->seq_out[i] = seq_out; in hsr_add_node()
174 if (san && hsr->proto_ops->handle_san_frame) in hsr_add_node()
175 hsr->proto_ops->handle_san_frame(san, rx_port, new_node); in hsr_add_node()
177 spin_lock_bh(&hsr->list_lock); in hsr_add_node()
178 list_for_each_entry_rcu(node, node_db, mac_list, in hsr_add_node()
179 lockdep_is_held(&hsr->list_lock)) { in hsr_add_node()
180 if (ether_addr_equal(node->macaddress_A, addr)) in hsr_add_node()
182 if (ether_addr_equal(node->macaddress_B, addr)) in hsr_add_node()
185 list_add_tail_rcu(&new_node->mac_list, node_db); in hsr_add_node()
186 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
189 spin_unlock_bh(&hsr->list_lock); in hsr_add_node()
191 return node; in hsr_add_node()
194 void prp_update_san_info(struct hsr_node *node, bool is_sup) in prp_update_san_info() argument
199 node->san_a = false; in prp_update_san_info()
200 node->san_b = false; in prp_update_san_info()
209 struct hsr_priv *hsr = port->hsr; in hsr_get_node()
210 struct hsr_node *node; in hsr_get_node() local
221 list_for_each_entry_rcu(node, node_db, mac_list) { in hsr_get_node()
222 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { in hsr_get_node()
223 if (hsr->proto_ops->update_san_info) in hsr_get_node()
224 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
225 return node; in hsr_get_node()
227 if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { in hsr_get_node()
228 if (hsr->proto_ops->update_san_info) in hsr_get_node()
229 hsr->proto_ops->update_san_info(node, is_sup); in hsr_get_node()
230 return node; in hsr_get_node()
234 /* Everyone may create a node entry, connected node to a HSR/PRP in hsr_get_node()
237 if (ethhdr->h_proto == htons(ETH_P_PRP) || in hsr_get_node()
238 ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_get_node()
242 seq_out = hsr_get_skb_sequence_nr(skb) - 1; in hsr_get_node()
254 return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out, in hsr_get_node()
260 * node.
264 struct hsr_node *node_curr = frame->node_src; in hsr_handle_sup_frame()
265 struct hsr_port *port_rcv = frame->port_rcv; in hsr_handle_sup_frame()
266 struct hsr_priv *hsr = port_rcv->hsr; in hsr_handle_sup_frame()
274 /* Here either frame->skb_hsr or frame->skb_prp should be in hsr_handle_sup_frame()
278 if (frame->skb_hsr) in hsr_handle_sup_frame()
279 skb = frame->skb_hsr; in hsr_handle_sup_frame()
280 else if (frame->skb_prp) in hsr_handle_sup_frame()
281 skb = frame->skb_prp; in hsr_handle_sup_frame()
282 else if (frame->skb_std) in hsr_handle_sup_frame()
283 skb = frame->skb_std; in hsr_handle_sup_frame()
293 if (ethhdr->h_proto == htons(ETH_P_HSR)) in hsr_handle_sup_frame()
299 hsr_sp = (struct hsr_sup_payload *)skb->data; in hsr_handle_sup_frame()
302 node_db = &port_rcv->hsr->node_db; in hsr_handle_sup_frame()
303 node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); in hsr_handle_sup_frame()
305 /* No frame received from AddrA of this node yet */ in hsr_handle_sup_frame()
306 node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, in hsr_handle_sup_frame()
307 HSR_SEQNR_START - 1, true, in hsr_handle_sup_frame()
308 port_rcv->type); in hsr_handle_sup_frame()
312 /* Node has already been merged */ in hsr_handle_sup_frame()
315 ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); in hsr_handle_sup_frame()
317 if (!node_curr->time_in_stale[i] && in hsr_handle_sup_frame()
318 time_after(node_curr->time_in[i], node_real->time_in[i])) { in hsr_handle_sup_frame()
319 node_real->time_in[i] = node_curr->time_in[i]; in hsr_handle_sup_frame()
320 node_real->time_in_stale[i] = in hsr_handle_sup_frame()
321 node_curr->time_in_stale[i]; in hsr_handle_sup_frame()
323 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) in hsr_handle_sup_frame()
324 node_real->seq_out[i] = node_curr->seq_out[i]; in hsr_handle_sup_frame()
326 node_real->addr_B_port = port_rcv->type; in hsr_handle_sup_frame()
328 spin_lock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
329 list_del_rcu(&node_curr->mac_list); in hsr_handle_sup_frame()
330 spin_unlock_bh(&hsr->list_lock); in hsr_handle_sup_frame()
335 if (ethhdr->h_proto == htons(ETH_P_HSR)) in hsr_handle_sup_frame()
343 * If the frame was sent by a node's B interface, replace the source
344 * address with that node's "official" address (macaddress_A) so that upper
347 void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) in hsr_addr_subst_source() argument
354 memcpy(ð_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); in hsr_addr_subst_source()
358 * 'port' is the outgoing interface
361 * recipient interface MAC address, regardless of whether that is the
362 * recipient's A or B interface.
376 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) in hsr_addr_subst_dest()
379 node_dst = find_node_by_addr_A(&port->hsr->node_db, in hsr_addr_subst_dest()
380 eth_hdr(skb)->h_dest); in hsr_addr_subst_dest()
383 netdev_err(skb->dev, "%s: Unknown node\n", __func__); in hsr_addr_subst_dest()
386 if (port->type != node_dst->addr_B_port) in hsr_addr_subst_dest()
389 if (is_valid_ether_addr(node_dst->macaddress_B)) in hsr_addr_subst_dest()
390 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); in hsr_addr_subst_dest()
393 void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, in hsr_register_frame_in() argument
398 * re-register and resume communications. in hsr_register_frame_in()
400 if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) && in hsr_register_frame_in()
401 seq_nr_before(sequence_nr, node->seq_out[port->type])) in hsr_register_frame_in()
404 node->time_in[port->type] = jiffies; in hsr_register_frame_in()
405 node->time_in_stale[port->type] = false; in hsr_register_frame_in()
409 * ethhdr->h_source address and skb->mac_header set.
412 * 1 if frame can be shown to have been sent recently on this interface,
416 int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, in hsr_register_frame_out() argument
419 if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) && in hsr_register_frame_out()
420 time_is_after_jiffies(node->time_out[port->type] + in hsr_register_frame_out()
424 node->time_out[port->type] = jiffies; in hsr_register_frame_out()
425 node->seq_out[port->type] = sequence_nr; in hsr_register_frame_out()
430 struct hsr_node *node) in get_late_port() argument
432 if (node->time_in_stale[HSR_PT_SLAVE_A]) in get_late_port()
434 if (node->time_in_stale[HSR_PT_SLAVE_B]) in get_late_port()
437 if (time_after(node->time_in[HSR_PT_SLAVE_B], in get_late_port()
438 node->time_in[HSR_PT_SLAVE_A] + in get_late_port()
441 if (time_after(node->time_in[HSR_PT_SLAVE_A], in get_late_port()
442 node->time_in[HSR_PT_SLAVE_B] + in get_late_port()
455 struct hsr_node *node; in hsr_prune_nodes() local
461 spin_lock_bh(&hsr->list_lock); in hsr_prune_nodes()
462 list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { in hsr_prune_nodes()
463 /* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A] in hsr_prune_nodes()
465 * the master port. Thus the master node will be repeatedly in hsr_prune_nodes()
468 if (hsr_addr_is_self(hsr, node->macaddress_A)) in hsr_prune_nodes()
472 time_a = node->time_in[HSR_PT_SLAVE_A]; in hsr_prune_nodes()
473 time_b = node->time_in[HSR_PT_SLAVE_B]; in hsr_prune_nodes()
475 /* Check for timestamps old enough to risk wrap-around */ in hsr_prune_nodes()
477 node->time_in_stale[HSR_PT_SLAVE_A] = true; in hsr_prune_nodes()
479 node->time_in_stale[HSR_PT_SLAVE_B] = true; in hsr_prune_nodes()
481 /* Get age of newest frame from node. in hsr_prune_nodes()
486 if (node->time_in_stale[HSR_PT_SLAVE_A] || in hsr_prune_nodes()
487 (!node->time_in_stale[HSR_PT_SLAVE_B] && in hsr_prune_nodes()
495 port = get_late_port(hsr, node); in hsr_prune_nodes()
497 hsr_nl_ringerror(hsr, node->macaddress_A, port); in hsr_prune_nodes()
504 hsr_nl_nodedown(hsr, node->macaddress_A); in hsr_prune_nodes()
505 list_del_rcu(&node->mac_list); in hsr_prune_nodes()
507 kfree_rcu(node, rcu_head); in hsr_prune_nodes()
510 spin_unlock_bh(&hsr->list_lock); in hsr_prune_nodes()
513 mod_timer(&hsr->prune_timer, in hsr_prune_nodes()
520 struct hsr_node *node; in hsr_get_next_node() local
523 node = list_first_or_null_rcu(&hsr->node_db, in hsr_get_next_node()
525 if (node) in hsr_get_next_node()
526 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
527 return node; in hsr_get_next_node()
530 node = _pos; in hsr_get_next_node()
531 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { in hsr_get_next_node()
532 ether_addr_copy(addr, node->macaddress_A); in hsr_get_next_node()
533 return node; in hsr_get_next_node()
548 struct hsr_node *node; in hsr_get_node_data() local
552 node = find_node_by_addr_A(&hsr->node_db, addr); in hsr_get_node_data()
553 if (!node) in hsr_get_node_data()
554 return -ENOENT; in hsr_get_node_data()
556 ether_addr_copy(addr_b, node->macaddress_B); in hsr_get_node_data()
558 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; in hsr_get_node_data()
559 if (node->time_in_stale[HSR_PT_SLAVE_A]) in hsr_get_node_data()
568 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; in hsr_get_node_data()
569 if (node->time_in_stale[HSR_PT_SLAVE_B]) in hsr_get_node_data()
578 /* Present sequence numbers as if they were incoming on interface */ in hsr_get_node_data()
579 *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; in hsr_get_node_data()
580 *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; in hsr_get_node_data()
582 if (node->addr_B_port != HSR_PT_NONE) { in hsr_get_node_data()
583 port = hsr_port_get_hsr(hsr, node->addr_B_port); in hsr_get_node_data()
584 *addr_b_ifindex = port->dev->ifindex; in hsr_get_node_data()
586 *addr_b_ifindex = -1; in hsr_get_node_data()