hsr_framereg.c 17 KB

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