/net/batman-adv/hard-interface.h

http://github.com/mirrors/linux · C Header · 144 lines · 64 code · 23 blank · 57 comment · 2 complexity · d7f433ed98771b1376c0a7f9a0c69cb8 MD5 · raw file

  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. void batadv_hardif_remove_interfaces(void);
  87. int batadv_hardif_min_mtu(struct net_device *soft_iface);
  88. void batadv_update_min_mtu(struct net_device *soft_iface);
  89. void batadv_hardif_release(struct kref *ref);
  90. int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
  91. u8 *orig_addr, u8 *orig_neigh);
  92. /**
  93. * batadv_hardif_put() - decrement the hard interface refcounter and possibly
  94. * release it
  95. * @hard_iface: the hard interface to free
  96. */
  97. static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface)
  98. {
  99. kref_put(&hard_iface->refcount, batadv_hardif_release);
  100. }
  101. /**
  102. * batadv_primary_if_get_selected() - Get reference to primary interface
  103. * @bat_priv: the bat priv with all the soft interface information
  104. *
  105. * Return: primary interface (with increased refcnt), otherwise NULL
  106. */
  107. static inline struct batadv_hard_iface *
  108. batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
  109. {
  110. struct batadv_hard_iface *hard_iface;
  111. rcu_read_lock();
  112. hard_iface = rcu_dereference(bat_priv->primary_if);
  113. if (!hard_iface)
  114. goto out;
  115. if (!kref_get_unless_zero(&hard_iface->refcount))
  116. hard_iface = NULL;
  117. out:
  118. rcu_read_unlock();
  119. return hard_iface;
  120. }
  121. #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */