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