hard-interface.h 3.2 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/notifier.h>
  13. #include <linux/rcupdate.h>
  14. #include <linux/stddef.h>
  15. #include <linux/types.h>
  16. /**
  17. * enum batadv_hard_if_state - State of a hard interface
  18. */
  19. enum batadv_hard_if_state {
  20. /**
  21. * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
  22. * batman-adv soft interface
  23. */
  24. BATADV_IF_NOT_IN_USE,
  25. /**
  26. * @BATADV_IF_TO_BE_REMOVED: interface will be removed from soft
  27. * interface
  28. */
  29. BATADV_IF_TO_BE_REMOVED,
  30. /** @BATADV_IF_INACTIVE: interface is deactivated */
  31. BATADV_IF_INACTIVE,
  32. /** @BATADV_IF_ACTIVE: interface is used */
  33. BATADV_IF_ACTIVE,
  34. /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */
  35. BATADV_IF_TO_BE_ACTIVATED,
  36. };
  37. /**
  38. * enum batadv_hard_if_bcast - broadcast avoidance options
  39. */
  40. enum batadv_hard_if_bcast {
  41. /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */
  42. BATADV_HARDIF_BCAST_OK = 0,
  43. /**
  44. * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no
  45. * recipient
  46. */
  47. BATADV_HARDIF_BCAST_NORECIPIENT,
  48. /**
  49. * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it
  50. * from
  51. */
  52. BATADV_HARDIF_BCAST_DUPFWD,
  53. /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */
  54. BATADV_HARDIF_BCAST_DUPORIG,
  55. };
  56. extern struct notifier_block batadv_hard_if_notifier;
  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 *soft_iface);
  64. void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
  65. int batadv_hardif_min_mtu(struct net_device *soft_iface);
  66. void batadv_update_min_mtu(struct net_device *soft_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 soft 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_ */