Blame view
net/hsr/hsr_framereg.c
14.4 KB
0e7623bdf
|
1 |
// SPDX-License-Identifier: GPL-2.0 |
70ebe4a47
|
2 |
/* Copyright 2011-2014 Autronica Fire and Security AS |
f421436a5
|
3 |
* |
f421436a5
|
4 |
* Author(s): |
70ebe4a47
|
5 |
* 2011-2014 Arvid Brodin, arvid.brodin@alten.se |
f421436a5
|
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
* * The HSR spec says never to forward the same frame twice on the same * interface. A frame is identified by its source MAC address and its HSR * sequence number. This code keeps track of senders and their sequence numbers * to allow filtering of duplicate frames, and to detect HSR ring errors. */ #include <linux/if_ether.h> #include <linux/etherdevice.h> #include <linux/slab.h> #include <linux/rculist.h> #include "hsr_main.h" #include "hsr_framereg.h" #include "hsr_netlink.h" |
f266a683a
|
20 |
/* TODO: use hash lists for mac addresses (linux/jhash.h)? */ |
f421436a5
|
21 |
|
f266a683a
|
22 23 |
/* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b, * false otherwise. |
f421436a5
|
24 |
*/ |
f266a683a
|
25 |
static bool seq_nr_after(u16 a, u16 b) |
f421436a5
|
26 |
{ |
f266a683a
|
27 28 29 |
/* Remove inconsistency where * seq_nr_after(a, b) == seq_nr_before(a, b) */ |
5fa967780
|
30 |
if ((int)b - a == 32768) |
f266a683a
|
31 |
return false; |
f421436a5
|
32 |
|
5fa967780
|
33 |
return (((s16)(b - a)) < 0); |
f421436a5
|
34 |
} |
9f73c2bb4
|
35 |
|
f266a683a
|
36 37 38 |
#define seq_nr_before(a, b) seq_nr_after((b), (a)) #define seq_nr_after_or_eq(a, b) (!seq_nr_before((a), (b))) #define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) |
f421436a5
|
39 |
|
f266a683a
|
40 |
bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr) |
f421436a5
|
41 |
{ |
70ebe4a47
|
42 |
struct hsr_node *node; |
f421436a5
|
43 |
|
f266a683a
|
44 45 46 47 48 49 |
node = list_first_or_null_rcu(&hsr->self_node_db, struct hsr_node, mac_list); if (!node) { WARN_ONCE(1, "HSR: No self node "); return false; |
f421436a5
|
50 |
} |
b1b4aa914
|
51 |
if (ether_addr_equal(addr, node->macaddress_A)) |
f266a683a
|
52 |
return true; |
b1b4aa914
|
53 |
if (ether_addr_equal(addr, node->macaddress_B)) |
f266a683a
|
54 |
return true; |
f421436a5
|
55 |
|
f266a683a
|
56 57 |
return false; } |
f421436a5
|
58 59 60 |
/* Search for mac entry. Caller must hold rcu read lock. */ |
b1b4aa914
|
61 62 |
static struct hsr_node *find_node_by_addr_A(struct list_head *node_db, const unsigned char addr[ETH_ALEN]) |
f421436a5
|
63 |
{ |
70ebe4a47
|
64 |
struct hsr_node *node; |
f421436a5
|
65 66 |
list_for_each_entry_rcu(node, node_db, mac_list) { |
b1b4aa914
|
67 |
if (ether_addr_equal(node->macaddress_A, addr)) |
f421436a5
|
68 69 70 71 72 |
return node; } return NULL; } |
f421436a5
|
73 74 75 |
/* Helper for device init; the self_node_db is used in hsr_rcv() to recognize * frames from self that's been looped over the HSR ring. */ |
0fc906e60
|
76 |
int hsr_create_self_node(struct hsr_priv *hsr, |
f421436a5
|
77 78 79 |
unsigned char addr_a[ETH_ALEN], unsigned char addr_b[ETH_ALEN]) { |
0fc906e60
|
80 |
struct list_head *self_node_db = &hsr->self_node_db; |
70ebe4a47
|
81 |
struct hsr_node *node, *oldnode; |
f421436a5
|
82 83 84 85 |
node = kmalloc(sizeof(*node), GFP_KERNEL); if (!node) return -ENOMEM; |
b1b4aa914
|
86 87 |
ether_addr_copy(node->macaddress_A, addr_a); ether_addr_copy(node->macaddress_B, addr_b); |
f421436a5
|
88 |
|
0fc906e60
|
89 |
spin_lock_bh(&hsr->list_lock); |
f421436a5
|
90 |
oldnode = list_first_or_null_rcu(self_node_db, |
4fe25bd8c
|
91 |
struct hsr_node, mac_list); |
f421436a5
|
92 93 |
if (oldnode) { list_replace_rcu(&oldnode->mac_list, &node->mac_list); |
0fc906e60
|
94 95 |
spin_unlock_bh(&hsr->list_lock); kfree_rcu(oldnode, rcu_head); |
f421436a5
|
96 |
} else { |
f421436a5
|
97 |
list_add_tail_rcu(&node->mac_list, self_node_db); |
0fc906e60
|
98 |
spin_unlock_bh(&hsr->list_lock); |
f421436a5
|
99 100 101 102 |
} return 0; } |
0fc906e60
|
103 |
void hsr_del_self_node(struct hsr_priv *hsr) |
6caabe7f1
|
104 |
{ |
0fc906e60
|
105 |
struct list_head *self_node_db = &hsr->self_node_db; |
6caabe7f1
|
106 |
struct hsr_node *node; |
0fc906e60
|
107 |
spin_lock_bh(&hsr->list_lock); |
6caabe7f1
|
108 |
node = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list); |
6caabe7f1
|
109 110 |
if (node) { list_del_rcu(&node->mac_list); |
0fc906e60
|
111 |
kfree_rcu(node, rcu_head); |
6caabe7f1
|
112 |
} |
0fc906e60
|
113 |
spin_unlock_bh(&hsr->list_lock); |
6caabe7f1
|
114 |
} |
f421436a5
|
115 |
|
b9a1e6274
|
116 117 118 119 120 121 122 123 |
void hsr_del_nodes(struct list_head *node_db) { struct hsr_node *node; struct hsr_node *tmp; list_for_each_entry_safe(node, tmp, node_db, mac_list) kfree(node); } |
b1b4aa914
|
124 |
/* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A; |
f266a683a
|
125 126 |
* seq_out is used to initialize filtering of outgoing duplicate frames * originating from the newly added node. |
f421436a5
|
127 |
*/ |
0fc906e60
|
128 129 130 131 |
static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, struct list_head *node_db, unsigned char addr[], u16 seq_out) |
f421436a5
|
132 |
{ |
0fc906e60
|
133 |
struct hsr_node *new_node, *node; |
f421436a5
|
134 |
unsigned long now; |
f266a683a
|
135 |
int i; |
f421436a5
|
136 |
|
0fc906e60
|
137 138 |
new_node = kzalloc(sizeof(*new_node), GFP_ATOMIC); if (!new_node) |
f421436a5
|
139 |
return NULL; |
0fc906e60
|
140 |
ether_addr_copy(new_node->macaddress_A, addr); |
f421436a5
|
141 142 143 144 145 |
/* We are only interested in time diffs here, so use current jiffies * as initialization. (0 could trigger an spurious ring error warning). */ now = jiffies; |
c5a759117
|
146 |
for (i = 0; i < HSR_PT_PORTS; i++) |
0fc906e60
|
147 |
new_node->time_in[i] = now; |
c5a759117
|
148 |
for (i = 0; i < HSR_PT_PORTS; i++) |
0fc906e60
|
149 |
new_node->seq_out[i] = seq_out; |
f421436a5
|
150 |
|
0fc906e60
|
151 152 153 154 155 156 157 158 159 160 161 162 163 |
spin_lock_bh(&hsr->list_lock); list_for_each_entry_rcu(node, node_db, mac_list) { if (ether_addr_equal(node->macaddress_A, addr)) goto out; if (ether_addr_equal(node->macaddress_B, addr)) goto out; } list_add_tail_rcu(&new_node->mac_list, node_db); spin_unlock_bh(&hsr->list_lock); return new_node; out: spin_unlock_bh(&hsr->list_lock); kfree(new_node); |
f421436a5
|
164 165 |
return node; } |
f266a683a
|
166 167 |
/* Get the hsr_node from which 'skb' was sent. */ |
675c8da04
|
168 |
struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, |
f266a683a
|
169 170 |
bool is_sup) { |
675c8da04
|
171 |
struct list_head *node_db = &port->hsr->node_db; |
0fc906e60
|
172 |
struct hsr_priv *hsr = port->hsr; |
f266a683a
|
173 174 175 176 177 178 |
struct hsr_node *node; struct ethhdr *ethhdr; u16 seq_out; if (!skb_mac_header_was_set(skb)) return NULL; |
5fa967780
|
179 |
ethhdr = (struct ethhdr *)skb_mac_header(skb); |
f266a683a
|
180 181 |
list_for_each_entry_rcu(node, node_db, mac_list) { |
b1b4aa914
|
182 |
if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) |
f266a683a
|
183 |
return node; |
b1b4aa914
|
184 |
if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) |
f266a683a
|
185 186 |
return node; } |
ee1c27977
|
187 |
/* Everyone may create a node entry, connected node to a HSR device. */ |
f266a683a
|
188 |
|
059477830
|
189 190 |
if (ethhdr->h_proto == htons(ETH_P_PRP) || ethhdr->h_proto == htons(ETH_P_HSR)) { |
f266a683a
|
191 192 193 194 195 |
/* Use the existing sequence_nr from the tag as starting point * for filtering duplicate frames. */ seq_out = hsr_get_skb_sequence_nr(skb) - 1; } else { |
675c8da04
|
196 197 198 199 200 201 |
/* this is called also for frames from master port and * so warn only for non master ports */ if (port->type != HSR_PT_MASTER) WARN_ONCE(1, "%s: Non-HSR frame ", __func__); |
ee1c27977
|
202 |
seq_out = HSR_SEQNR_START; |
f266a683a
|
203 |
} |
0fc906e60
|
204 |
return hsr_add_node(hsr, node_db, ethhdr->h_source, seq_out); |
f266a683a
|
205 |
} |
b1b4aa914
|
206 207 |
/* Use the Supervision frame's info about an eventual macaddress_B for merging * nodes that has previously had their macaddress_B registered as a separate |
f266a683a
|
208 209 210 211 212 |
* node. */ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, struct hsr_port *port_rcv) { |
0fc906e60
|
213 |
struct hsr_priv *hsr = port_rcv->hsr; |
f266a683a
|
214 |
struct hsr_sup_payload *hsr_sp; |
0fc906e60
|
215 |
struct hsr_node *node_real; |
f266a683a
|
216 |
struct list_head *node_db; |
0fc906e60
|
217 |
struct ethhdr *ethhdr; |
f266a683a
|
218 |
int i; |
5fa967780
|
219 |
ethhdr = (struct ethhdr *)skb_mac_header(skb); |
f266a683a
|
220 |
|
ee1c27977
|
221 222 223 224 225 226 227 228 229 |
/* Leave the ethernet header. */ skb_pull(skb, sizeof(struct ethhdr)); /* And leave the HSR tag. */ if (ethhdr->h_proto == htons(ETH_P_HSR)) skb_pull(skb, sizeof(struct hsr_tag)); /* And leave the HSR sup tag. */ skb_pull(skb, sizeof(struct hsr_sup_tag)); |
5fa967780
|
230 |
hsr_sp = (struct hsr_sup_payload *)skb->data; |
f266a683a
|
231 |
|
b1b4aa914
|
232 |
/* Merge node_curr (registered on macaddress_B) into node_real */ |
f266a683a
|
233 |
node_db = &port_rcv->hsr->node_db; |
b1b4aa914
|
234 |
node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); |
f266a683a
|
235 236 |
if (!node_real) /* No frame received from AddrA of this node yet */ |
0fc906e60
|
237 |
node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A, |
f266a683a
|
238 239 240 241 242 243 |
HSR_SEQNR_START - 1); if (!node_real) goto done; /* No mem */ if (node_real == node_curr) /* Node has already been merged */ goto done; |
b1b4aa914
|
244 |
ether_addr_copy(node_real->macaddress_B, ethhdr->h_source); |
f266a683a
|
245 246 247 248 |
for (i = 0; i < HSR_PT_PORTS; i++) { if (!node_curr->time_in_stale[i] && time_after(node_curr->time_in[i], node_real->time_in[i])) { node_real->time_in[i] = node_curr->time_in[i]; |
d595b85a6
|
249 250 |
node_real->time_in_stale[i] = node_curr->time_in_stale[i]; |
f266a683a
|
251 252 253 254 |
} if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) node_real->seq_out[i] = node_curr->seq_out[i]; } |
b1b4aa914
|
255 |
node_real->addr_B_port = port_rcv->type; |
f266a683a
|
256 |
|
0fc906e60
|
257 |
spin_lock_bh(&hsr->list_lock); |
f266a683a
|
258 |
list_del_rcu(&node_curr->mac_list); |
0fc906e60
|
259 |
spin_unlock_bh(&hsr->list_lock); |
f266a683a
|
260 261 262 |
kfree_rcu(node_curr, rcu_head); done: |
ee1c27977
|
263 |
skb_push(skb, sizeof(struct hsrv1_ethhdr_sp)); |
f266a683a
|
264 |
} |
f421436a5
|
265 266 |
/* 'skb' is a frame meant for this host, that is to be passed to upper layers. * |
f266a683a
|
267 |
* If the frame was sent by a node's B interface, replace the source |
b1b4aa914
|
268 |
* address with that node's "official" address (macaddress_A) so that upper |
f421436a5
|
269 270 |
* layers recognize where it came from. */ |
f266a683a
|
271 |
void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) |
f421436a5
|
272 |
{ |
f421436a5
|
273 274 275 276 277 |
if (!skb_mac_header_was_set(skb)) { WARN_ONCE(1, "%s: Mac header not set ", __func__); return; } |
f421436a5
|
278 |
|
b1b4aa914
|
279 |
memcpy(ð_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN); |
f421436a5
|
280 |
} |
f421436a5
|
281 |
/* 'skb' is a frame meant for another host. |
f266a683a
|
282 |
* 'port' is the outgoing interface |
f421436a5
|
283 284 285 286 287 288 289 |
* * Substitute the target (dest) MAC address if necessary, so the it matches the * recipient interface MAC address, regardless of whether that is the * recipient's A or B interface. * This is needed to keep the packets flowing through switches that learn on * which "side" the different interfaces are. */ |
f266a683a
|
290 |
void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb, |
c5a759117
|
291 |
struct hsr_port *port) |
f421436a5
|
292 |
{ |
f266a683a
|
293 |
struct hsr_node *node_dst; |
f421436a5
|
294 |
|
f266a683a
|
295 296 297 298 299 |
if (!skb_mac_header_was_set(skb)) { WARN_ONCE(1, "%s: Mac header not set ", __func__); return; } |
f421436a5
|
300 |
|
f266a683a
|
301 302 |
if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) return; |
f421436a5
|
303 |
|
b1b4aa914
|
304 305 |
node_dst = find_node_by_addr_A(&port->hsr->node_db, eth_hdr(skb)->h_dest); |
f266a683a
|
306 307 308 309 310 |
if (!node_dst) { WARN_ONCE(1, "%s: Unknown node ", __func__); return; } |
b1b4aa914
|
311 |
if (port->type != node_dst->addr_B_port) |
f266a683a
|
312 |
return; |
f421436a5
|
313 |
|
b1b4aa914
|
314 |
ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B); |
f421436a5
|
315 |
} |
f421436a5
|
316 |
|
f266a683a
|
317 318 |
void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, u16 sequence_nr) |
f421436a5
|
319 |
{ |
f266a683a
|
320 321 322 323 324 325 |
/* Don't register incoming frames without a valid sequence number. This * ensures entries of restarted nodes gets pruned so that they can * re-register and resume communications. */ if (seq_nr_before(sequence_nr, node->seq_out[port->type])) return; |
c5a759117
|
326 327 |
node->time_in[port->type] = jiffies; node->time_in_stale[port->type] = false; |
f421436a5
|
328 |
} |
f421436a5
|
329 330 331 332 333 334 335 336 |
/* 'skb' is a HSR Ethernet frame (with a HSR tag inserted), with a valid * ethhdr->h_source address and skb->mac_header set. * * Return: * 1 if frame can be shown to have been sent recently on this interface, * 0 otherwise, or * negative error code on error */ |
f266a683a
|
337 338 |
int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node, u16 sequence_nr) |
f421436a5
|
339 |
{ |
c5a759117
|
340 |
if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type])) |
f421436a5
|
341 |
return 1; |
c5a759117
|
342 |
node->seq_out[port->type] = sequence_nr; |
f421436a5
|
343 344 |
return 0; } |
c5a759117
|
345 346 |
static struct hsr_port *get_late_port(struct hsr_priv *hsr, struct hsr_node *node) |
f421436a5
|
347 |
{ |
c5a759117
|
348 349 350 351 352 353 354 355 356 357 358 359 360 |
if (node->time_in_stale[HSR_PT_SLAVE_A]) return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); if (node->time_in_stale[HSR_PT_SLAVE_B]) return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); if (time_after(node->time_in[HSR_PT_SLAVE_B], node->time_in[HSR_PT_SLAVE_A] + msecs_to_jiffies(MAX_SLAVE_DIFF))) return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A); if (time_after(node->time_in[HSR_PT_SLAVE_A], node->time_in[HSR_PT_SLAVE_B] + msecs_to_jiffies(MAX_SLAVE_DIFF))) return hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B); |
f421436a5
|
361 |
|
c5a759117
|
362 |
return NULL; |
f421436a5
|
363 |
} |
f421436a5
|
364 365 366 |
/* Remove stale sequence_nr records. Called by timer every * HSR_LIFE_CHECK_INTERVAL (two seconds or so). */ |
dda436b7a
|
367 |
void hsr_prune_nodes(struct timer_list *t) |
f421436a5
|
368 |
{ |
dda436b7a
|
369 |
struct hsr_priv *hsr = from_timer(hsr, t, prune_timer); |
70ebe4a47
|
370 |
struct hsr_node *node; |
0fc906e60
|
371 |
struct hsr_node *tmp; |
c5a759117
|
372 |
struct hsr_port *port; |
f421436a5
|
373 374 |
unsigned long timestamp; unsigned long time_a, time_b; |
0fc906e60
|
375 376 |
spin_lock_bh(&hsr->list_lock); list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) { |
d2daa127e
|
377 378 379 380 381 382 383 |
/* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A] * nor time_in[HSR_PT_SLAVE_B], will ever be updated for * the master port. Thus the master node will be repeatedly * pruned leading to packet loss. */ if (hsr_addr_is_self(hsr, node->macaddress_A)) continue; |
f421436a5
|
384 |
/* Shorthand */ |
c5a759117
|
385 386 |
time_a = node->time_in[HSR_PT_SLAVE_A]; time_b = node->time_in[HSR_PT_SLAVE_B]; |
f421436a5
|
387 388 |
/* Check for timestamps old enough to risk wrap-around */ |
d131fcc69
|
389 |
if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2)) |
c5a759117
|
390 |
node->time_in_stale[HSR_PT_SLAVE_A] = true; |
d131fcc69
|
391 |
if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2)) |
c5a759117
|
392 |
node->time_in_stale[HSR_PT_SLAVE_B] = true; |
f421436a5
|
393 394 395 396 397 398 |
/* Get age of newest frame from node. * At least one time_in is OK here; nodes get pruned long * before both time_ins can get stale */ timestamp = time_a; |
c5a759117
|
399 400 |
if (node->time_in_stale[HSR_PT_SLAVE_A] || (!node->time_in_stale[HSR_PT_SLAVE_B] && |
f421436a5
|
401 402 403 404 405 |
time_after(time_b, time_a))) timestamp = time_b; /* Warn of ring error only as long as we get frames at all */ if (time_is_after_jiffies(timestamp + |
d131fcc69
|
406 |
msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) { |
c5a759117
|
407 408 |
rcu_read_lock(); port = get_late_port(hsr, node); |
05ca6e644
|
409 |
if (port) |
b1b4aa914
|
410 |
hsr_nl_ringerror(hsr, node->macaddress_A, port); |
c5a759117
|
411 |
rcu_read_unlock(); |
f421436a5
|
412 413 414 415 |
} /* Prune old entries */ if (time_is_before_jiffies(timestamp + |
d595b85a6
|
416 |
msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { |
b1b4aa914
|
417 |
hsr_nl_nodedown(hsr, node->macaddress_A); |
f421436a5
|
418 419 |
list_del_rcu(&node->mac_list); /* Note that we need to free this entry later: */ |
1aee6cc2a
|
420 |
kfree_rcu(node, rcu_head); |
f421436a5
|
421 422 |
} } |
0fc906e60
|
423 |
spin_unlock_bh(&hsr->list_lock); |
5150b45fd
|
424 425 426 427 |
/* Restart timer */ mod_timer(&hsr->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD)); |
f421436a5
|
428 |
} |
70ebe4a47
|
429 |
void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, |
f421436a5
|
430 431 |
unsigned char addr[ETH_ALEN]) { |
70ebe4a47
|
432 |
struct hsr_node *node; |
f421436a5
|
433 434 |
if (!_pos) { |
70ebe4a47
|
435 436 |
node = list_first_or_null_rcu(&hsr->node_db, struct hsr_node, mac_list); |
f421436a5
|
437 |
if (node) |
b1b4aa914
|
438 |
ether_addr_copy(addr, node->macaddress_A); |
f421436a5
|
439 440 441 442 |
return node; } node = _pos; |
70ebe4a47
|
443 |
list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { |
b1b4aa914
|
444 |
ether_addr_copy(addr, node->macaddress_A); |
f421436a5
|
445 446 447 448 449 |
return node; } return NULL; } |
70ebe4a47
|
450 |
int hsr_get_node_data(struct hsr_priv *hsr, |
f421436a5
|
451 452 453 454 455 456 457 458 |
const unsigned char *addr, unsigned char addr_b[ETH_ALEN], unsigned int *addr_b_ifindex, int *if1_age, u16 *if1_seq, int *if2_age, u16 *if2_seq) { |
70ebe4a47
|
459 |
struct hsr_node *node; |
c5a759117
|
460 |
struct hsr_port *port; |
f421436a5
|
461 |
unsigned long tdiff; |
b1b4aa914
|
462 |
node = find_node_by_addr_A(&hsr->node_db, addr); |
80aa1e38e
|
463 464 |
if (!node) return -ENOENT; |
f421436a5
|
465 |
|
b1b4aa914
|
466 |
ether_addr_copy(addr_b, node->macaddress_B); |
f421436a5
|
467 |
|
c5a759117
|
468 469 |
tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; if (node->time_in_stale[HSR_PT_SLAVE_A]) |
f421436a5
|
470 471 472 473 474 475 476 |
*if1_age = INT_MAX; #if HZ <= MSEC_PER_SEC else if (tdiff > msecs_to_jiffies(INT_MAX)) *if1_age = INT_MAX; #endif else *if1_age = jiffies_to_msecs(tdiff); |
c5a759117
|
477 478 |
tdiff = jiffies - node->time_in[HSR_PT_SLAVE_B]; if (node->time_in_stale[HSR_PT_SLAVE_B]) |
f421436a5
|
479 480 481 482 483 484 485 486 487 |
*if2_age = INT_MAX; #if HZ <= MSEC_PER_SEC else if (tdiff > msecs_to_jiffies(INT_MAX)) *if2_age = INT_MAX; #endif else *if2_age = jiffies_to_msecs(tdiff); /* Present sequence numbers as if they were incoming on interface */ |
c5a759117
|
488 489 |
*if1_seq = node->seq_out[HSR_PT_SLAVE_B]; *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; |
f421436a5
|
490 |
|
b1b4aa914
|
491 492 |
if (node->addr_B_port != HSR_PT_NONE) { port = hsr_port_get_hsr(hsr, node->addr_B_port); |
c5a759117
|
493 494 |
*addr_b_ifindex = port->dev->ifindex; } else { |
f421436a5
|
495 |
*addr_b_ifindex = -1; |
c5a759117
|
496 |
} |
f421436a5
|
497 |
|
f421436a5
|
498 499 |
return 0; } |