xref: /linux/net/hsr/hsr_framereg.c (revision bfb921b2a9d5d1123d1d10b196a39db629ddef87)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2011-2014 Autronica Fire and Security AS
3  *
4  * Author(s):
5  *	2011-2014 Arvid Brodin, arvid.brodin@alten.se
6  *
7  * The HSR spec says never to forward the same frame twice on the same
8  * interface. A frame is identified by its source MAC address and its HSR
9  * sequence number. This code keeps track of senders and their sequence numbers
10  * to allow filtering of duplicate frames, and to detect HSR ring errors.
11  * Same code handles filtering of duplicates for PRP as well.
12  */
13 
14 #include <linux/if_ether.h>
15 #include <linux/etherdevice.h>
16 #include <linux/slab.h>
17 #include <linux/rculist.h>
18 #include "hsr_main.h"
19 #include "hsr_framereg.h"
20 #include "hsr_netlink.h"
21 
22 /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
23  * false otherwise.
24  */
25 static bool seq_nr_after(u16 a, u16 b)
26 {
27 	/* Remove inconsistency where
28 	 * seq_nr_after(a, b) == seq_nr_before(a, b)
29 	 */
30 	if ((int)b - a == 32768)
31 		return false;
32 
33 	return (((s16)(b - a)) < 0);
34 }
35 
36 #define seq_nr_before(a, b)		seq_nr_after((b), (a))
37 #define seq_nr_before_or_eq(a, b)	(!seq_nr_after((a), (b)))
38 
39 bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr)
40 {
41 	struct hsr_self_node *sn;
42 	bool ret = false;
43 
44 	rcu_read_lock();
45 	sn = rcu_dereference(hsr->self_node);
46 	if (!sn) {
47 		WARN_ONCE(1, "HSR: No self node\n");
48 		goto out;
49 	}
50 
51 	if (ether_addr_equal(addr, sn->macaddress_A) ||
52 	    ether_addr_equal(addr, sn->macaddress_B))
53 		ret = true;
54 out:
55 	rcu_read_unlock();
56 	return ret;
57 }
58 
59 /* Search for mac entry. Caller must hold rcu read lock.
60  */
61 static struct hsr_node *find_node_by_addr_A(struct list_head *node_db,
62 					    const unsigned char addr[ETH_ALEN])
63 {
64 	struct hsr_node *node;
65 
66 	list_for_each_entry_rcu(node, node_db, mac_list) {
67 		if (ether_addr_equal(node->macaddress_A, addr))
68 			return node;
69 	}
70 
71 	return NULL;
72 }
73 
74 /* Check if node for a given MAC address is already present in data base
75  */
76 bool hsr_is_node_in_db(struct list_head *node_db,
77 		       const unsigned char addr[ETH_ALEN])
78 {
79 	return !!find_node_by_addr_A(node_db, addr);
80 }
81 
82 /* Helper for device init; the self_node is used in hsr_rcv() to recognize
83  * frames from self that's been looped over the HSR ring.
84  */
85 int hsr_create_self_node(struct hsr_priv *hsr,
86 			 const unsigned char addr_a[ETH_ALEN],
87 			 const unsigned char addr_b[ETH_ALEN])
88 {
89 	struct hsr_self_node *sn, *old;
90 
91 	sn = kmalloc(sizeof(*sn), GFP_KERNEL);
92 	if (!sn)
93 		return -ENOMEM;
94 
95 	ether_addr_copy(sn->macaddress_A, addr_a);
96 	ether_addr_copy(sn->macaddress_B, addr_b);
97 
98 	spin_lock_bh(&hsr->list_lock);
99 	old = rcu_replace_pointer(hsr->self_node, sn,
100 				  lockdep_is_held(&hsr->list_lock));
101 	spin_unlock_bh(&hsr->list_lock);
102 
103 	if (old)
104 		kfree_rcu(old, rcu_head);
105 	return 0;
106 }
107 
108 void hsr_del_self_node(struct hsr_priv *hsr)
109 {
110 	struct hsr_self_node *old;
111 
112 	spin_lock_bh(&hsr->list_lock);
113 	old = rcu_replace_pointer(hsr->self_node, NULL,
114 				  lockdep_is_held(&hsr->list_lock));
115 	spin_unlock_bh(&hsr->list_lock);
116 	if (old)
117 		kfree_rcu(old, rcu_head);
118 }
119 
120 void hsr_del_nodes(struct list_head *node_db)
121 {
122 	struct hsr_node *node;
123 	struct hsr_node *tmp;
124 
125 	list_for_each_entry_safe(node, tmp, node_db, mac_list)
126 		kfree(node);
127 }
128 
129 void prp_handle_san_frame(bool san, enum hsr_port_type port,
130 			  struct hsr_node *node)
131 {
132 	/* Mark if the SAN node is over LAN_A or LAN_B */
133 	if (port == HSR_PT_SLAVE_A) {
134 		node->san_a = true;
135 		return;
136 	}
137 
138 	if (port == HSR_PT_SLAVE_B)
139 		node->san_b = true;
140 }
141 
142 /* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A;
143  * seq_out is used to initialize filtering of outgoing duplicate frames
144  * originating from the newly added node.
145  */
146 static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
147 				     struct list_head *node_db,
148 				     unsigned char addr[],
149 				     u16 seq_out, bool san,
150 				     enum hsr_port_type rx_port)
151 {
152 	struct hsr_node *new_node, *node;
153 	unsigned long now;
154 	int i;
155 
156 	new_node = kzalloc(sizeof(*new_node), GFP_ATOMIC);
157 	if (!new_node)
158 		return NULL;
159 
160 	ether_addr_copy(new_node->macaddress_A, addr);
161 	spin_lock_init(&new_node->seq_out_lock);
162 
163 	/* We are only interested in time diffs here, so use current jiffies
164 	 * as initialization. (0 could trigger an spurious ring error warning).
165 	 */
166 	now = jiffies;
167 	for (i = 0; i < HSR_PT_PORTS; i++) {
168 		new_node->time_in[i] = now;
169 		new_node->time_out[i] = now;
170 	}
171 	for (i = 0; i < HSR_PT_PORTS; i++)
172 		new_node->seq_out[i] = seq_out;
173 
174 	if (san && hsr->proto_ops->handle_san_frame)
175 		hsr->proto_ops->handle_san_frame(san, rx_port, new_node);
176 
177 	spin_lock_bh(&hsr->list_lock);
178 	list_for_each_entry_rcu(node, node_db, mac_list,
179 				lockdep_is_held(&hsr->list_lock)) {
180 		if (ether_addr_equal(node->macaddress_A, addr))
181 			goto out;
182 		if (ether_addr_equal(node->macaddress_B, addr))
183 			goto out;
184 	}
185 	list_add_tail_rcu(&new_node->mac_list, node_db);
186 	spin_unlock_bh(&hsr->list_lock);
187 	return new_node;
188 out:
189 	spin_unlock_bh(&hsr->list_lock);
190 	kfree(new_node);
191 	return node;
192 }
193 
194 void prp_update_san_info(struct hsr_node *node, bool is_sup)
195 {
196 	if (!is_sup)
197 		return;
198 
199 	node->san_a = false;
200 	node->san_b = false;
201 }
202 
203 /* Get the hsr_node from which 'skb' was sent.
204  */
205 struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
206 			      struct sk_buff *skb, bool is_sup,
207 			      enum hsr_port_type rx_port)
208 {
209 	struct hsr_priv *hsr = port->hsr;
210 	struct hsr_node *node;
211 	struct ethhdr *ethhdr;
212 	struct prp_rct *rct;
213 	bool san = false;
214 	u16 seq_out;
215 
216 	if (!skb_mac_header_was_set(skb))
217 		return NULL;
218 
219 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
220 
221 	list_for_each_entry_rcu(node, node_db, mac_list) {
222 		if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) {
223 			if (hsr->proto_ops->update_san_info)
224 				hsr->proto_ops->update_san_info(node, is_sup);
225 			return node;
226 		}
227 		if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) {
228 			if (hsr->proto_ops->update_san_info)
229 				hsr->proto_ops->update_san_info(node, is_sup);
230 			return node;
231 		}
232 	}
233 
234 	/* Check if required node is not in proxy nodes table */
235 	list_for_each_entry_rcu(node, &hsr->proxy_node_db, mac_list) {
236 		if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) {
237 			if (hsr->proto_ops->update_san_info)
238 				hsr->proto_ops->update_san_info(node, is_sup);
239 			return node;
240 		}
241 	}
242 
243 	/* Everyone may create a node entry, connected node to a HSR/PRP
244 	 * device.
245 	 */
246 	if (ethhdr->h_proto == htons(ETH_P_PRP) ||
247 	    ethhdr->h_proto == htons(ETH_P_HSR)) {
248 		/* Check if skb contains hsr_ethhdr */
249 		if (skb->mac_len < sizeof(struct hsr_ethhdr))
250 			return NULL;
251 
252 		/* Use the existing sequence_nr from the tag as starting point
253 		 * for filtering duplicate frames.
254 		 */
255 		seq_out = hsr_get_skb_sequence_nr(skb) - 1;
256 	} else {
257 		rct = skb_get_PRP_rct(skb);
258 		if (rct && prp_check_lsdu_size(skb, rct, is_sup)) {
259 			seq_out = prp_get_skb_sequence_nr(rct);
260 		} else {
261 			if (rx_port != HSR_PT_MASTER)
262 				san = true;
263 			seq_out = HSR_SEQNR_START;
264 		}
265 	}
266 
267 	return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out,
268 			    san, rx_port);
269 }
270 
271 /* Use the Supervision frame's info about an eventual macaddress_B for merging
272  * nodes that has previously had their macaddress_B registered as a separate
273  * node.
274  */
275 void hsr_handle_sup_frame(struct hsr_frame_info *frame)
276 {
277 	struct hsr_node *node_curr = frame->node_src;
278 	struct hsr_port *port_rcv = frame->port_rcv;
279 	struct hsr_priv *hsr = port_rcv->hsr;
280 	struct hsr_sup_payload *hsr_sp;
281 	struct hsr_sup_tlv *hsr_sup_tlv;
282 	struct hsr_node *node_real;
283 	struct sk_buff *skb = NULL;
284 	struct list_head *node_db;
285 	struct ethhdr *ethhdr;
286 	int i;
287 	unsigned int pull_size = 0;
288 	unsigned int total_pull_size = 0;
289 
290 	/* Here either frame->skb_hsr or frame->skb_prp should be
291 	 * valid as supervision frame always will have protocol
292 	 * header info.
293 	 */
294 	if (frame->skb_hsr)
295 		skb = frame->skb_hsr;
296 	else if (frame->skb_prp)
297 		skb = frame->skb_prp;
298 	else if (frame->skb_std)
299 		skb = frame->skb_std;
300 	if (!skb)
301 		return;
302 
303 	/* Leave the ethernet header. */
304 	pull_size = sizeof(struct ethhdr);
305 	skb_pull(skb, pull_size);
306 	total_pull_size += pull_size;
307 
308 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
309 
310 	/* And leave the HSR tag. */
311 	if (ethhdr->h_proto == htons(ETH_P_HSR)) {
312 		pull_size = sizeof(struct hsr_tag);
313 		skb_pull(skb, pull_size);
314 		total_pull_size += pull_size;
315 	}
316 
317 	/* And leave the HSR sup tag. */
318 	pull_size = sizeof(struct hsr_sup_tag);
319 	skb_pull(skb, pull_size);
320 	total_pull_size += pull_size;
321 
322 	/* get HSR sup payload */
323 	hsr_sp = (struct hsr_sup_payload *)skb->data;
324 
325 	/* Merge node_curr (registered on macaddress_B) into node_real */
326 	node_db = &port_rcv->hsr->node_db;
327 	node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A);
328 	if (!node_real)
329 		/* No frame received from AddrA of this node yet */
330 		node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A,
331 					 HSR_SEQNR_START - 1, true,
332 					 port_rcv->type);
333 	if (!node_real)
334 		goto done; /* No mem */
335 	if (node_real == node_curr)
336 		/* Node has already been merged */
337 		goto done;
338 
339 	/* Leave the first HSR sup payload. */
340 	pull_size = sizeof(struct hsr_sup_payload);
341 	skb_pull(skb, pull_size);
342 	total_pull_size += pull_size;
343 
344 	/* Get second supervision tlv */
345 	hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data;
346 	/* And check if it is a redbox mac TLV */
347 	if (hsr_sup_tlv->HSR_TLV_type == PRP_TLV_REDBOX_MAC) {
348 		/* We could stop here after pushing hsr_sup_payload,
349 		 * or proceed and allow macaddress_B and for redboxes.
350 		 */
351 		/* Sanity check length */
352 		if (hsr_sup_tlv->HSR_TLV_length != 6)
353 			goto done;
354 
355 		/* Leave the second HSR sup tlv. */
356 		pull_size = sizeof(struct hsr_sup_tlv);
357 		skb_pull(skb, pull_size);
358 		total_pull_size += pull_size;
359 
360 		/* Get redbox mac address. */
361 		hsr_sp = (struct hsr_sup_payload *)skb->data;
362 
363 		/* Check if redbox mac and node mac are equal. */
364 		if (!ether_addr_equal(node_real->macaddress_A, hsr_sp->macaddress_A)) {
365 			/* This is a redbox supervision frame for a VDAN! */
366 			goto done;
367 		}
368 	}
369 
370 	ether_addr_copy(node_real->macaddress_B, ethhdr->h_source);
371 	spin_lock_bh(&node_real->seq_out_lock);
372 	for (i = 0; i < HSR_PT_PORTS; i++) {
373 		if (!node_curr->time_in_stale[i] &&
374 		    time_after(node_curr->time_in[i], node_real->time_in[i])) {
375 			node_real->time_in[i] = node_curr->time_in[i];
376 			node_real->time_in_stale[i] =
377 						node_curr->time_in_stale[i];
378 		}
379 		if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i]))
380 			node_real->seq_out[i] = node_curr->seq_out[i];
381 	}
382 	spin_unlock_bh(&node_real->seq_out_lock);
383 	node_real->addr_B_port = port_rcv->type;
384 
385 	spin_lock_bh(&hsr->list_lock);
386 	if (!node_curr->removed) {
387 		list_del_rcu(&node_curr->mac_list);
388 		node_curr->removed = true;
389 		kfree_rcu(node_curr, rcu_head);
390 	}
391 	spin_unlock_bh(&hsr->list_lock);
392 
393 done:
394 	/* Push back here */
395 	skb_push(skb, total_pull_size);
396 }
397 
398 /* 'skb' is a frame meant for this host, that is to be passed to upper layers.
399  *
400  * If the frame was sent by a node's B interface, replace the source
401  * address with that node's "official" address (macaddress_A) so that upper
402  * layers recognize where it came from.
403  */
404 void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb)
405 {
406 	if (!skb_mac_header_was_set(skb)) {
407 		WARN_ONCE(1, "%s: Mac header not set\n", __func__);
408 		return;
409 	}
410 
411 	memcpy(&eth_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN);
412 }
413 
414 /* 'skb' is a frame meant for another host.
415  * 'port' is the outgoing interface
416  *
417  * Substitute the target (dest) MAC address if necessary, so the it matches the
418  * recipient interface MAC address, regardless of whether that is the
419  * recipient's A or B interface.
420  * This is needed to keep the packets flowing through switches that learn on
421  * which "side" the different interfaces are.
422  */
423 void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
424 			 struct hsr_port *port)
425 {
426 	struct hsr_node *node_dst;
427 
428 	if (!skb_mac_header_was_set(skb)) {
429 		WARN_ONCE(1, "%s: Mac header not set\n", __func__);
430 		return;
431 	}
432 
433 	if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest))
434 		return;
435 
436 	node_dst = find_node_by_addr_A(&port->hsr->node_db,
437 				       eth_hdr(skb)->h_dest);
438 	if (!node_dst && port->hsr->redbox)
439 		node_dst = find_node_by_addr_A(&port->hsr->proxy_node_db,
440 					       eth_hdr(skb)->h_dest);
441 
442 	if (!node_dst) {
443 		if (port->hsr->prot_version != PRP_V1 && net_ratelimit())
444 			netdev_err(skb->dev, "%s: Unknown node\n", __func__);
445 		return;
446 	}
447 	if (port->type != node_dst->addr_B_port)
448 		return;
449 
450 	if (is_valid_ether_addr(node_dst->macaddress_B))
451 		ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B);
452 }
453 
454 void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
455 			   u16 sequence_nr)
456 {
457 	/* Don't register incoming frames without a valid sequence number. This
458 	 * ensures entries of restarted nodes gets pruned so that they can
459 	 * re-register and resume communications.
460 	 */
461 	if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) &&
462 	    seq_nr_before(sequence_nr, node->seq_out[port->type]))
463 		return;
464 
465 	node->time_in[port->type] = jiffies;
466 	node->time_in_stale[port->type] = false;
467 }
468 
469 /* 'skb' is a HSR Ethernet frame (with a HSR tag inserted), with a valid
470  * ethhdr->h_source address and skb->mac_header set.
471  *
472  * Return:
473  *	 1 if frame can be shown to have been sent recently on this interface,
474  *	 0 otherwise, or
475  *	 negative error code on error
476  */
477 int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node,
478 			   u16 sequence_nr)
479 {
480 	spin_lock_bh(&node->seq_out_lock);
481 	if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) &&
482 	    time_is_after_jiffies(node->time_out[port->type] +
483 	    msecs_to_jiffies(HSR_ENTRY_FORGET_TIME))) {
484 		spin_unlock_bh(&node->seq_out_lock);
485 		return 1;
486 	}
487 
488 	node->time_out[port->type] = jiffies;
489 	node->seq_out[port->type] = sequence_nr;
490 	spin_unlock_bh(&node->seq_out_lock);
491 	return 0;
492 }
493 
494 static struct hsr_port *get_late_port(struct hsr_priv *hsr,
495 				      struct hsr_node *node)
496 {
497 	if (node->time_in_stale[HSR_PT_SLAVE_A])
498 		return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
499 	if (node->time_in_stale[HSR_PT_SLAVE_B])
500 		return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
501 
502 	if (time_after(node->time_in[HSR_PT_SLAVE_B],
503 		       node->time_in[HSR_PT_SLAVE_A] +
504 					msecs_to_jiffies(MAX_SLAVE_DIFF)))
505 		return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
506 	if (time_after(node->time_in[HSR_PT_SLAVE_A],
507 		       node->time_in[HSR_PT_SLAVE_B] +
508 					msecs_to_jiffies(MAX_SLAVE_DIFF)))
509 		return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
510 
511 	return NULL;
512 }
513 
514 /* Remove stale sequence_nr records. Called by timer every
515  * HSR_LIFE_CHECK_INTERVAL (two seconds or so).
516  */
517 void hsr_prune_nodes(struct timer_list *t)
518 {
519 	struct hsr_priv *hsr = from_timer(hsr, t, prune_timer);
520 	struct hsr_node *node;
521 	struct hsr_node *tmp;
522 	struct hsr_port *port;
523 	unsigned long timestamp;
524 	unsigned long time_a, time_b;
525 
526 	spin_lock_bh(&hsr->list_lock);
527 	list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) {
528 		/* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A]
529 		 * nor time_in[HSR_PT_SLAVE_B], will ever be updated for
530 		 * the master port. Thus the master node will be repeatedly
531 		 * pruned leading to packet loss.
532 		 */
533 		if (hsr_addr_is_self(hsr, node->macaddress_A))
534 			continue;
535 
536 		/* Shorthand */
537 		time_a = node->time_in[HSR_PT_SLAVE_A];
538 		time_b = node->time_in[HSR_PT_SLAVE_B];
539 
540 		/* Check for timestamps old enough to risk wrap-around */
541 		if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2))
542 			node->time_in_stale[HSR_PT_SLAVE_A] = true;
543 		if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2))
544 			node->time_in_stale[HSR_PT_SLAVE_B] = true;
545 
546 		/* Get age of newest frame from node.
547 		 * At least one time_in is OK here; nodes get pruned long
548 		 * before both time_ins can get stale
549 		 */
550 		timestamp = time_a;
551 		if (node->time_in_stale[HSR_PT_SLAVE_A] ||
552 		    (!node->time_in_stale[HSR_PT_SLAVE_B] &&
553 		    time_after(time_b, time_a)))
554 			timestamp = time_b;
555 
556 		/* Warn of ring error only as long as we get frames at all */
557 		if (time_is_after_jiffies(timestamp +
558 				msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) {
559 			rcu_read_lock();
560 			port = get_late_port(hsr, node);
561 			if (port)
562 				hsr_nl_ringerror(hsr, node->macaddress_A, port);
563 			rcu_read_unlock();
564 		}
565 
566 		/* Prune old entries */
567 		if (time_is_before_jiffies(timestamp +
568 				msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
569 			hsr_nl_nodedown(hsr, node->macaddress_A);
570 			if (!node->removed) {
571 				list_del_rcu(&node->mac_list);
572 				node->removed = true;
573 				/* Note that we need to free this entry later: */
574 				kfree_rcu(node, rcu_head);
575 			}
576 		}
577 	}
578 	spin_unlock_bh(&hsr->list_lock);
579 
580 	/* Restart timer */
581 	mod_timer(&hsr->prune_timer,
582 		  jiffies + msecs_to_jiffies(PRUNE_PERIOD));
583 }
584 
585 void hsr_prune_proxy_nodes(struct timer_list *t)
586 {
587 	struct hsr_priv *hsr = from_timer(hsr, t, prune_proxy_timer);
588 	unsigned long timestamp;
589 	struct hsr_node *node;
590 	struct hsr_node *tmp;
591 
592 	spin_lock_bh(&hsr->list_lock);
593 	list_for_each_entry_safe(node, tmp, &hsr->proxy_node_db, mac_list) {
594 		timestamp = node->time_in[HSR_PT_INTERLINK];
595 
596 		/* Prune old entries */
597 		if (time_is_before_jiffies(timestamp +
598 				msecs_to_jiffies(HSR_PROXY_NODE_FORGET_TIME))) {
599 			hsr_nl_nodedown(hsr, node->macaddress_A);
600 			if (!node->removed) {
601 				list_del_rcu(&node->mac_list);
602 				node->removed = true;
603 				/* Note that we need to free this entry later: */
604 				kfree_rcu(node, rcu_head);
605 			}
606 		}
607 	}
608 
609 	spin_unlock_bh(&hsr->list_lock);
610 
611 	/* Restart timer */
612 	mod_timer(&hsr->prune_proxy_timer,
613 		  jiffies + msecs_to_jiffies(PRUNE_PROXY_PERIOD));
614 }
615 
616 void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
617 			unsigned char addr[ETH_ALEN])
618 {
619 	struct hsr_node *node;
620 
621 	if (!_pos) {
622 		node = list_first_or_null_rcu(&hsr->node_db,
623 					      struct hsr_node, mac_list);
624 		if (node)
625 			ether_addr_copy(addr, node->macaddress_A);
626 		return node;
627 	}
628 
629 	node = _pos;
630 	list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) {
631 		ether_addr_copy(addr, node->macaddress_A);
632 		return node;
633 	}
634 
635 	return NULL;
636 }
637 
638 int hsr_get_node_data(struct hsr_priv *hsr,
639 		      const unsigned char *addr,
640 		      unsigned char addr_b[ETH_ALEN],
641 		      unsigned int *addr_b_ifindex,
642 		      int *if1_age,
643 		      u16 *if1_seq,
644 		      int *if2_age,
645 		      u16 *if2_seq)
646 {
647 	struct hsr_node *node;
648 	struct hsr_port *port;
649 	unsigned long tdiff;
650 
651 	node = find_node_by_addr_A(&hsr->node_db, addr);
652 	if (!node)
653 		return -ENOENT;
654 
655 	ether_addr_copy(addr_b, node->macaddress_B);
656 
657 	tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A];
658 	if (node->time_in_stale[HSR_PT_SLAVE_A])
659 		*if1_age = INT_MAX;
660 #if HZ <= MSEC_PER_SEC
661 	else if (tdiff > msecs_to_jiffies(INT_MAX))
662 		*if1_age = INT_MAX;
663 #endif
664 	else
665 		*if1_age = jiffies_to_msecs(tdiff);
666 
667 	tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B];
668 	if (node->time_in_stale[HSR_PT_SLAVE_B])
669 		*if2_age = INT_MAX;
670 #if HZ <= MSEC_PER_SEC
671 	else if (tdiff > msecs_to_jiffies(INT_MAX))
672 		*if2_age = INT_MAX;
673 #endif
674 	else
675 		*if2_age = jiffies_to_msecs(tdiff);
676 
677 	/* Present sequence numbers as if they were incoming on interface */
678 	*if1_seq = node->seq_out[HSR_PT_SLAVE_B];
679 	*if2_seq = node->seq_out[HSR_PT_SLAVE_A];
680 
681 	if (node->addr_B_port != HSR_PT_NONE) {
682 		port = hsr_port_get_hsr(hsr, node->addr_B_port);
683 		*addr_b_ifindex = port->dev->ifindex;
684 	} else {
685 		*addr_b_ifindex = -1;
686 	}
687 
688 	return 0;
689 }
690