Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) B.A.T.M.A.N. contributors:
0003  *
0004  * Marek Lindner, Simon Wunderlich
0005  */
0006 
0007 #ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_
0008 #define _NET_BATMAN_ADV_HARD_INTERFACE_H_
0009 
0010 #include "main.h"
0011 
0012 #include <linux/compiler.h>
0013 #include <linux/kref.h>
0014 #include <linux/netdevice.h>
0015 #include <linux/notifier.h>
0016 #include <linux/rcupdate.h>
0017 #include <linux/stddef.h>
0018 #include <linux/types.h>
0019 
0020 /**
0021  * enum batadv_hard_if_state - State of a hard interface
0022  */
0023 enum batadv_hard_if_state {
0024     /**
0025      * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
0026      * batman-adv soft interface
0027      */
0028     BATADV_IF_NOT_IN_USE,
0029 
0030     /**
0031      * @BATADV_IF_TO_BE_REMOVED: interface will be removed from soft
0032      * interface
0033      */
0034     BATADV_IF_TO_BE_REMOVED,
0035 
0036     /** @BATADV_IF_INACTIVE: interface is deactivated */
0037     BATADV_IF_INACTIVE,
0038 
0039     /** @BATADV_IF_ACTIVE: interface is used */
0040     BATADV_IF_ACTIVE,
0041 
0042     /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */
0043     BATADV_IF_TO_BE_ACTIVATED,
0044 };
0045 
0046 /**
0047  * enum batadv_hard_if_bcast - broadcast avoidance options
0048  */
0049 enum batadv_hard_if_bcast {
0050     /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */
0051     BATADV_HARDIF_BCAST_OK = 0,
0052 
0053     /**
0054      * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no
0055      *  recipient
0056      */
0057     BATADV_HARDIF_BCAST_NORECIPIENT,
0058 
0059     /**
0060      * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it
0061      *  from
0062      */
0063     BATADV_HARDIF_BCAST_DUPFWD,
0064 
0065     /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */
0066     BATADV_HARDIF_BCAST_DUPORIG,
0067 };
0068 
0069 extern struct notifier_block batadv_hard_if_notifier;
0070 
0071 struct net_device *batadv_get_real_netdev(struct net_device *net_device);
0072 bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
0073 bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
0074 struct batadv_hard_iface*
0075 batadv_hardif_get_by_netdev(const struct net_device *net_dev);
0076 int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
0077                    struct net_device *soft_iface);
0078 void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
0079 int batadv_hardif_min_mtu(struct net_device *soft_iface);
0080 void batadv_update_min_mtu(struct net_device *soft_iface);
0081 void batadv_hardif_release(struct kref *ref);
0082 int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
0083                    u8 *orig_addr, u8 *orig_neigh);
0084 
0085 /**
0086  * batadv_hardif_put() - decrement the hard interface refcounter and possibly
0087  *  release it
0088  * @hard_iface: the hard interface to free
0089  */
0090 static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface)
0091 {
0092     if (!hard_iface)
0093         return;
0094 
0095     kref_put(&hard_iface->refcount, batadv_hardif_release);
0096 }
0097 
0098 /**
0099  * batadv_primary_if_get_selected() - Get reference to primary interface
0100  * @bat_priv: the bat priv with all the soft interface information
0101  *
0102  * Return: primary interface (with increased refcnt), otherwise NULL
0103  */
0104 static inline struct batadv_hard_iface *
0105 batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
0106 {
0107     struct batadv_hard_iface *hard_iface;
0108 
0109     rcu_read_lock();
0110     hard_iface = rcu_dereference(bat_priv->primary_if);
0111     if (!hard_iface)
0112         goto out;
0113 
0114     if (!kref_get_unless_zero(&hard_iface->refcount))
0115         hard_iface = NULL;
0116 
0117 out:
0118     rcu_read_unlock();
0119     return hard_iface;
0120 }
0121 
0122 #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */