hard-interface.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_HARD_INTERFACE_H_
  7. #define _NET_BATMAN_ADV_HARD_INTERFACE_H_
  8. #include "main.h"
  9. #include <linux/compiler.h>
  10. #include <linux/kref.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/rcupdate.h>
  13. #include <linux/stddef.h>
  14. #include <linux/types.h>
  15. /**
  16. * enum batadv_hard_if_state - State of a hard interface
  17. */
  18. enum batadv_hard_if_state {
  19. /**
  20. * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
  21. * batman-adv mesh interface
  22. */
  23. BATADV_IF_NOT_IN_USE,
  24. /**
  25. * @BATADV_IF_TO_BE_REMOVED: interface will be removed from mesh
  26. * interface
  27. */
  28. BATADV_IF_TO_BE_REMOVED,
  29. /** @BATADV_IF_INACTIVE: interface is deactivated */
  30. BATADV_IF_INACTIVE,
  31. /** @BATADV_IF_ACTIVE: interface is used */
  32. BATADV_IF_ACTIVE,
  33. /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */
  34. BATADV_IF_TO_BE_ACTIVATED,
  35. };
  36. /**
  37. * enum batadv_hard_if_bcast - broadcast avoidance options
  38. */
  39. enum batadv_hard_if_bcast {
  40. /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */
  41. BATADV_HARDIF_BCAST_OK = 0,
  42. /**
  43. * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no
  44. * recipient
  45. */
  46. BATADV_HARDIF_BCAST_NORECIPIENT,
  47. /**
  48. * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it
  49. * from
  50. */
  51. BATADV_HARDIF_BCAST_DUPFWD,
  52. /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */
  53. BATADV_HARDIF_BCAST_DUPORIG,
  54. };
  55. extern struct notifier_block batadv_hard_if_notifier;
  56. struct net_device *__batadv_get_real_netdev(struct net_device *net_device);
  57. struct net_device *batadv_get_real_netdev(struct net_device *net_device);
  58. bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
  59. bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
  60. struct batadv_hard_iface*
  61. batadv_hardif_get_by_netdev(const struct net_device *net_dev);
  62. int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
  63. struct net_device *mesh_iface);
  64. void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
  65. int batadv_hardif_min_mtu(struct net_device *mesh_iface);
  66. void batadv_update_min_mtu(struct net_device *mesh_iface);
  67. void batadv_hardif_release(struct kref *ref);
  68. int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
  69. u8 *orig_addr, u8 *orig_neigh);
  70. /**
  71. * batadv_hardif_put() - decrement the hard interface refcounter and possibly
  72. * release it
  73. * @hard_iface: the hard interface to free
  74. */
  75. static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface)
  76. {
  77. if (!hard_iface)
  78. return;
  79. kref_put(&hard_iface->refcount, batadv_hardif_release);
  80. }
  81. /**
  82. * batadv_primary_if_get_selected() - Get reference to primary interface
  83. * @bat_priv: the bat priv with all the mesh interface information
  84. *
  85. * Return: primary interface (with increased refcnt), otherwise NULL
  86. */
  87. static inline struct batadv_hard_iface *
  88. batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
  89. {
  90. struct batadv_hard_iface *hard_iface;
  91. rcu_read_lock();
  92. hard_iface = rcu_dereference(bat_priv->primary_if);
  93. if (!hard_iface)
  94. goto out;
  95. if (!kref_get_unless_zero(&hard_iface->refcount))
  96. hard_iface = NULL;
  97. out:
  98. rcu_read_unlock();
  99. return hard_iface;
  100. }
  101. #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */