hard-interface.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_
  19. #define _NET_BATMAN_ADV_HARD_INTERFACE_H_
  20. #include "main.h"
  21. #include <linux/compiler.h>
  22. #include <linux/kref.h>
  23. #include <linux/notifier.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/stddef.h>
  26. #include <linux/types.h>
  27. struct net_device;
  28. struct net;
  29. /**
  30. * enum batadv_hard_if_state - State of a hard interface
  31. */
  32. enum batadv_hard_if_state {
  33. /**
  34. * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
  35. * batman-adv soft interface
  36. */
  37. BATADV_IF_NOT_IN_USE,
  38. /**
  39. * @BATADV_IF_TO_BE_REMOVED: interface will be removed from soft
  40. * interface
  41. */
  42. BATADV_IF_TO_BE_REMOVED,
  43. /** @BATADV_IF_INACTIVE: interface is deactivated */
  44. BATADV_IF_INACTIVE,
  45. /** @BATADV_IF_ACTIVE: interface is used */
  46. BATADV_IF_ACTIVE,
  47. /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */
  48. BATADV_IF_TO_BE_ACTIVATED,
  49. /**
  50. * @BATADV_IF_I_WANT_YOU: interface is queued up (using sysfs) for being
  51. * added as slave interface of a batman-adv soft interface
  52. */
  53. BATADV_IF_I_WANT_YOU,
  54. };
  55. /**
  56. * enum batadv_hard_if_bcast - broadcast avoidance options
  57. */
  58. enum batadv_hard_if_bcast {
  59. /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */
  60. BATADV_HARDIF_BCAST_OK = 0,
  61. /**
  62. * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no
  63. * recipient
  64. */
  65. BATADV_HARDIF_BCAST_NORECIPIENT,
  66. /**
  67. * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it
  68. * from
  69. */
  70. BATADV_HARDIF_BCAST_DUPFWD,
  71. /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */
  72. BATADV_HARDIF_BCAST_DUPORIG,
  73. };
  74. /**
  75. * enum batadv_hard_if_cleanup - Cleanup modi for soft_iface after slave removal
  76. */
  77. enum batadv_hard_if_cleanup {
  78. /**
  79. * @BATADV_IF_CLEANUP_KEEP: Don't automatically delete soft-interface
  80. */
  81. BATADV_IF_CLEANUP_KEEP,
  82. /**
  83. * @BATADV_IF_CLEANUP_AUTO: Delete soft-interface after last slave was
  84. * removed
  85. */
  86. BATADV_IF_CLEANUP_AUTO,
  87. };
  88. extern struct notifier_block batadv_hard_if_notifier;
  89. struct net_device *batadv_get_real_netdev(struct net_device *net_device);
  90. bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
  91. bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
  92. struct batadv_hard_iface*
  93. batadv_hardif_get_by_netdev(const struct net_device *net_dev);
  94. int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
  95. struct net *net, const char *iface_name);
  96. void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
  97. enum batadv_hard_if_cleanup autodel);
  98. void batadv_hardif_remove_interfaces(void);
  99. int batadv_hardif_min_mtu(struct net_device *soft_iface);
  100. void batadv_update_min_mtu(struct net_device *soft_iface);
  101. void batadv_hardif_release(struct kref *ref);
  102. int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
  103. u8 *orig_addr, u8 *orig_neigh);
  104. /**
  105. * batadv_hardif_put() - decrement the hard interface refcounter and possibly
  106. * release it
  107. * @hard_iface: the hard interface to free
  108. */
  109. static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface)
  110. {
  111. kref_put(&hard_iface->refcount, batadv_hardif_release);
  112. }
  113. /**
  114. * batadv_primary_if_get_selected() - Get reference to primary interface
  115. * @bat_priv: the bat priv with all the soft interface information
  116. *
  117. * Return: primary interface (with increased refcnt), otherwise NULL
  118. */
  119. static inline struct batadv_hard_iface *
  120. batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
  121. {
  122. struct batadv_hard_iface *hard_iface;
  123. rcu_read_lock();
  124. hard_iface = rcu_dereference(bat_priv->primary_if);
  125. if (!hard_iface)
  126. goto out;
  127. if (!kref_get_unless_zero(&hard_iface->refcount))
  128. hard_iface = NULL;
  129. out:
  130. rcu_read_unlock();
  131. return hard_iface;
  132. }
  133. #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */