originator.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. */
  6. #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
  7. #define _NET_BATMAN_ADV_ORIGINATOR_H_
  8. #include "main.h"
  9. #include <linux/compiler.h>
  10. #include <linux/if_ether.h>
  11. #include <linux/jhash.h>
  12. #include <linux/kref.h>
  13. #include <linux/netlink.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/types.h>
  16. bool batadv_compare_orig(const struct hlist_node *node, const void *data2);
  17. int batadv_originator_init(struct batadv_priv *bat_priv);
  18. void batadv_originator_free(struct batadv_priv *bat_priv);
  19. void batadv_purge_orig_ref(struct batadv_priv *bat_priv);
  20. void batadv_orig_node_release(struct kref *ref);
  21. struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
  22. const u8 *addr);
  23. struct batadv_hardif_neigh_node *
  24. batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
  25. const u8 *neigh_addr);
  26. void batadv_hardif_neigh_release(struct kref *ref);
  27. struct batadv_neigh_node *
  28. batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
  29. struct batadv_hard_iface *hard_iface,
  30. const u8 *neigh_addr);
  31. void batadv_neigh_node_release(struct kref *ref);
  32. struct batadv_neigh_node *
  33. batadv_orig_router_get(struct batadv_orig_node *orig_node,
  34. const struct batadv_hard_iface *if_outgoing);
  35. struct batadv_neigh_node *
  36. batadv_orig_to_router(struct batadv_priv *bat_priv, u8 *orig_addr,
  37. struct batadv_hard_iface *if_outgoing);
  38. struct batadv_neigh_ifinfo *
  39. batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh,
  40. struct batadv_hard_iface *if_outgoing);
  41. struct batadv_neigh_ifinfo *
  42. batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh,
  43. struct batadv_hard_iface *if_outgoing);
  44. void batadv_neigh_ifinfo_release(struct kref *ref);
  45. int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb);
  46. struct batadv_orig_ifinfo *
  47. batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node,
  48. struct batadv_hard_iface *if_outgoing);
  49. struct batadv_orig_ifinfo *
  50. batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node,
  51. struct batadv_hard_iface *if_outgoing);
  52. void batadv_orig_ifinfo_release(struct kref *ref);
  53. int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb);
  54. struct batadv_orig_node_vlan *
  55. batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
  56. unsigned short vid);
  57. struct batadv_orig_node_vlan *
  58. batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
  59. unsigned short vid);
  60. void batadv_orig_node_vlan_release(struct kref *ref);
  61. /**
  62. * batadv_choose_orig() - Return the index of the orig entry in the hash table
  63. * @data: mac address of the originator node
  64. * @size: the size of the hash table
  65. *
  66. * Return: the hash index where the object represented by @data should be
  67. * stored at.
  68. */
  69. static inline u32 batadv_choose_orig(const void *data, u32 size)
  70. {
  71. u32 hash = 0;
  72. hash = jhash(data, ETH_ALEN, hash);
  73. return hash % size;
  74. }
  75. struct batadv_orig_node *
  76. batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data);
  77. /**
  78. * batadv_orig_node_vlan_put() - decrement the refcounter and possibly release
  79. * the originator-vlan object
  80. * @orig_vlan: the originator-vlan object to release
  81. */
  82. static inline void
  83. batadv_orig_node_vlan_put(struct batadv_orig_node_vlan *orig_vlan)
  84. {
  85. if (!orig_vlan)
  86. return;
  87. kref_put(&orig_vlan->refcount, batadv_orig_node_vlan_release);
  88. }
  89. /**
  90. * batadv_neigh_ifinfo_put() - decrement the refcounter and possibly release
  91. * the neigh_ifinfo
  92. * @neigh_ifinfo: the neigh_ifinfo object to release
  93. */
  94. static inline void
  95. batadv_neigh_ifinfo_put(struct batadv_neigh_ifinfo *neigh_ifinfo)
  96. {
  97. if (!neigh_ifinfo)
  98. return;
  99. kref_put(&neigh_ifinfo->refcount, batadv_neigh_ifinfo_release);
  100. }
  101. /**
  102. * batadv_hardif_neigh_put() - decrement the hardif neighbors refcounter
  103. * and possibly release it
  104. * @hardif_neigh: hardif neigh neighbor to free
  105. */
  106. static inline void
  107. batadv_hardif_neigh_put(struct batadv_hardif_neigh_node *hardif_neigh)
  108. {
  109. if (!hardif_neigh)
  110. return;
  111. kref_put(&hardif_neigh->refcount, batadv_hardif_neigh_release);
  112. }
  113. /**
  114. * batadv_neigh_node_put() - decrement the neighbors refcounter and possibly
  115. * release it
  116. * @neigh_node: neigh neighbor to free
  117. */
  118. static inline void batadv_neigh_node_put(struct batadv_neigh_node *neigh_node)
  119. {
  120. if (!neigh_node)
  121. return;
  122. kref_put(&neigh_node->refcount, batadv_neigh_node_release);
  123. }
  124. /**
  125. * batadv_orig_ifinfo_put() - decrement the refcounter and possibly release
  126. * the orig_ifinfo
  127. * @orig_ifinfo: the orig_ifinfo object to release
  128. */
  129. static inline void
  130. batadv_orig_ifinfo_put(struct batadv_orig_ifinfo *orig_ifinfo)
  131. {
  132. if (!orig_ifinfo)
  133. return;
  134. kref_put(&orig_ifinfo->refcount, batadv_orig_ifinfo_release);
  135. }
  136. /**
  137. * batadv_orig_node_put() - decrement the orig node refcounter and possibly
  138. * release it
  139. * @orig_node: the orig node to free
  140. */
  141. static inline void batadv_orig_node_put(struct batadv_orig_node *orig_node)
  142. {
  143. if (!orig_node)
  144. return;
  145. kref_put(&orig_node->refcount, batadv_orig_node_release);
  146. }
  147. #endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */