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