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 7 #ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_ 8 #define _NET_BATMAN_ADV_HARD_INTERFACE_H_ 9 10 #include "main.h" 11 12 #include <linux/compiler.h> 13 #include <linux/init.h> 14 #include <linux/kref.h> 15 #include <linux/netdevice.h> 16 #include <linux/rcupdate.h> 17 #include <linux/stddef.h> 18 #include <linux/types.h> 19 20 /** 21 * enum batadv_hard_if_state - State of a hard interface 22 */ 23 enum batadv_hard_if_state { 24 /** 25 * @BATADV_IF_TO_BE_REMOVED: interface will be removed from mesh 26 * interface 27 */ 28 BATADV_IF_TO_BE_REMOVED, 29 30 /** @BATADV_IF_INACTIVE: interface is deactivated */ 31 BATADV_IF_INACTIVE, 32 33 /** @BATADV_IF_ACTIVE: interface is used */ 34 BATADV_IF_ACTIVE, 35 36 /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */ 37 BATADV_IF_TO_BE_ACTIVATED, 38 }; 39 40 /** 41 * enum batadv_hard_if_bcast - broadcast avoidance options 42 */ 43 enum batadv_hard_if_bcast { 44 /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */ 45 BATADV_HARDIF_BCAST_OK = 0, 46 47 /** 48 * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no 49 * recipient 50 */ 51 BATADV_HARDIF_BCAST_NORECIPIENT, 52 53 /** 54 * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it 55 * from 56 */ 57 BATADV_HARDIF_BCAST_DUPFWD, 58 59 /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */ 60 BATADV_HARDIF_BCAST_DUPORIG, 61 }; 62 63 extern struct notifier_block batadv_hard_if_notifier; 64 65 struct net_device *__batadv_get_real_netdev(struct net_device *net_device); 66 struct net_device *batadv_get_real_netdev(struct net_device *net_device); 67 u32 batadv_netdev_get_wifi_flags(struct net_device *net_dev); 68 u32 batadv_hardif_get_wifi_flags(struct batadv_hard_iface *hard_iface); 69 bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface); 70 struct batadv_hard_iface* 71 batadv_hardif_get_by_netdev(struct net_device *net_dev); 72 int batadv_hardif_enable_interface(struct net_device *net_dev, 73 struct net_device *mesh_iface); 74 void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface); 75 int batadv_hardif_min_mtu(struct net_device *mesh_iface); 76 void batadv_update_min_mtu(struct net_device *mesh_iface); 77 void batadv_hardif_release(struct kref *ref); 78 int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing, 79 u8 *orig_addr, u8 *orig_neigh); 80 int __init batadv_wifi_net_devices_init(void); 81 void batadv_wifi_net_devices_deinit(void); 82 83 /** 84 * batadv_hardif_put() - decrement the hard interface refcounter and possibly 85 * release it 86 * @hard_iface: the hard interface to free 87 */ 88 static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface) 89 { 90 if (!hard_iface) 91 return; 92 93 kref_put(&hard_iface->refcount, batadv_hardif_release); 94 } 95 96 /** 97 * batadv_primary_if_get_selected() - Get reference to primary interface 98 * @bat_priv: the bat priv with all the mesh interface information 99 * 100 * Return: primary interface (with increased refcnt), otherwise NULL 101 */ 102 static inline struct batadv_hard_iface * 103 batadv_primary_if_get_selected(struct batadv_priv *bat_priv) 104 { 105 struct batadv_hard_iface *hard_iface; 106 107 rcu_read_lock(); 108 hard_iface = rcu_dereference(bat_priv->primary_if); 109 if (!hard_iface) 110 goto out; 111 112 if (!kref_get_unless_zero(&hard_iface->refcount)) 113 hard_iface = NULL; 114 115 out: 116 rcu_read_unlock(); 117 return hard_iface; 118 } 119 120 /** 121 * batadv_is_cfg80211() - check if the given hardif is a cfg80211 122 * wifi interface 123 * @wifi_flags: extracted batadv_hard_iface_wifi_flags of a net_device 124 * 125 * Return: true if the net device is a cfg80211 wireless device, false 126 * otherwise. 127 */ 128 static inline bool batadv_is_cfg80211(u32 wifi_flags) 129 { 130 u32 allowed_flags = 0; 131 132 allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT; 133 allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT; 134 135 return !!(wifi_flags & allowed_flags); 136 } 137 138 /** 139 * batadv_is_wifi() - check if flags belong to wifi interface 140 * @wifi_flags: extracted batadv_hard_iface_wifi_flags of a net_device 141 * 142 * Return: true if the net device is a 802.11 wireless device, false otherwise. 143 */ 144 static inline bool batadv_is_wifi(u32 wifi_flags) 145 { 146 return wifi_flags != 0; 147 } 148 149 #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */ 150