hard-interface.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2007-2020 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/notifier.h>
  13. #include <linux/rcupdate.h>
  14. #include <linux/stddef.h>
  15. #include <linux/types.h>
  16. #include <net/net_namespace.h>
  17. /**
  18. * enum batadv_hard_if_state - State of a hard interface
  19. */
  20. enum batadv_hard_if_state {
  21. /**
  22. * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
  23. * batman-adv soft interface
  24. */
  25. BATADV_IF_NOT_IN_USE,
  26. /**
  27. * @BATADV_IF_TO_BE_REMOVED: interface will be removed from soft
  28. * interface
  29. */
  30. BATADV_IF_TO_BE_REMOVED,
  31. /** @BATADV_IF_INACTIVE: interface is deactivated */
  32. BATADV_IF_INACTIVE,
  33. /** @BATADV_IF_ACTIVE: interface is used */
  34. BATADV_IF_ACTIVE,
  35. /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */
  36. BATADV_IF_TO_BE_ACTIVATED,
  37. /**
  38. * @BATADV_IF_I_WANT_YOU: interface is queued up (using sysfs) for being
  39. * added as slave interface of a batman-adv soft interface
  40. */
  41. BATADV_IF_I_WANT_YOU,
  42. };
  43. /**
  44. * enum batadv_hard_if_bcast - broadcast avoidance options
  45. */
  46. enum batadv_hard_if_bcast {
  47. /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */
  48. BATADV_HARDIF_BCAST_OK = 0,
  49. /**
  50. * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no
  51. * recipient
  52. */
  53. BATADV_HARDIF_BCAST_NORECIPIENT,
  54. /**
  55. * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it
  56. * from
  57. */
  58. BATADV_HARDIF_BCAST_DUPFWD,
  59. /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */
  60. BATADV_HARDIF_BCAST_DUPORIG,
  61. };
  62. /**
  63. * enum batadv_hard_if_cleanup - Cleanup modi for soft_iface after slave removal
  64. */
  65. enum batadv_hard_if_cleanup {
  66. /**
  67. * @BATADV_IF_CLEANUP_KEEP: Don't automatically delete soft-interface
  68. */
  69. BATADV_IF_CLEANUP_KEEP,
  70. /**
  71. * @BATADV_IF_CLEANUP_AUTO: Delete soft-interface after last slave was
  72. * removed
  73. */
  74. BATADV_IF_CLEANUP_AUTO,
  75. };
  76. extern struct notifier_block batadv_hard_if_notifier;
  77. struct net_device *batadv_get_real_netdev(struct net_device *net_device);
  78. bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
  79. bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
  80. struct batadv_hard_iface*
  81. batadv_hardif_get_by_netdev(const struct net_device *net_dev);
  82. int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
  83. struct net *net, const char *iface_name);
  84. void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
  85. enum batadv_hard_if_cleanup autodel);
  86. int batadv_hardif_min_mtu(struct net_device *soft_iface);
  87. void batadv_update_min_mtu(struct net_device *soft_iface);
  88. void batadv_hardif_release(struct kref *ref);
  89. int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
  90. u8 *orig_addr, u8 *orig_neigh);
  91. /**
  92. * batadv_hardif_put() - decrement the hard interface refcounter and possibly
  93. * release it
  94. * @hard_iface: the hard interface to free
  95. */
  96. static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface)
  97. {
  98. if (!hard_iface)
  99. return;
  100. kref_put(&hard_iface->refcount, batadv_hardif_release);
  101. }
  102. /**
  103. * batadv_primary_if_get_selected() - Get reference to primary interface
  104. * @bat_priv: the bat priv with all the soft interface information
  105. *
  106. * Return: primary interface (with increased refcnt), otherwise NULL
  107. */
  108. static inline struct batadv_hard_iface *
  109. batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
  110. {
  111. struct batadv_hard_iface *hard_iface;
  112. rcu_read_lock();
  113. hard_iface = rcu_dereference(bat_priv->primary_if);
  114. if (!hard_iface)
  115. goto out;
  116. if (!kref_get_unless_zero(&hard_iface->refcount))
  117. hard_iface = NULL;
  118. out:
  119. rcu_read_unlock();
  120. return hard_iface;
  121. }
  122. #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */