blob: 64f660dbbe542cd63ab640d0cbf485d50b3db9e6 [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sven Eckelmanncfa55c62021-01-01 00:00:01 +01002/* Copyright (C) B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, Simon Wunderlich
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00005 */
6
7#ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_
8#define _NET_BATMAN_ADV_HARD_INTERFACE_H_
9
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020010#include "main.h"
11
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020012#include <linux/compiler.h>
Sven Eckelmann7a659d52016-01-16 10:29:54 +010013#include <linux/kref.h>
Sven Eckelmann68a600d2019-05-24 20:11:17 +020014#include <linux/netdevice.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020015#include <linux/notifier.h>
16#include <linux/rcupdate.h>
17#include <linux/stddef.h>
18#include <linux/types.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020019
Sven Eckelmann73844a82017-12-02 19:51:51 +010020/**
21 * enum batadv_hard_if_state - State of a hard interface
22 */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020023enum batadv_hard_if_state {
Sven Eckelmann73844a82017-12-02 19:51:51 +010024 /**
25 * @BATADV_IF_NOT_IN_USE: interface is not used as slave interface of a
26 * batman-adv soft interface
27 */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020028 BATADV_IF_NOT_IN_USE,
Sven Eckelmann73844a82017-12-02 19:51:51 +010029
30 /**
31 * @BATADV_IF_TO_BE_REMOVED: interface will be removed from soft
32 * interface
33 */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020034 BATADV_IF_TO_BE_REMOVED,
Sven Eckelmann73844a82017-12-02 19:51:51 +010035
36 /** @BATADV_IF_INACTIVE: interface is deactivated */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020037 BATADV_IF_INACTIVE,
Sven Eckelmann73844a82017-12-02 19:51:51 +010038
39 /** @BATADV_IF_ACTIVE: interface is used */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020040 BATADV_IF_ACTIVE,
Sven Eckelmann73844a82017-12-02 19:51:51 +010041
42 /** @BATADV_IF_TO_BE_ACTIVATED: interface is getting activated */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +020043 BATADV_IF_TO_BE_ACTIVATED,
Sven Eckelmanne8958db2011-06-04 11:26:00 +020044};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000045
Sven Eckelmanna15fd362013-02-11 17:10:24 +080046/**
Linus Lüssing3111bee2016-08-07 12:34:19 +020047 * enum batadv_hard_if_bcast - broadcast avoidance options
Linus Lüssing3111bee2016-08-07 12:34:19 +020048 */
49enum batadv_hard_if_bcast {
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010050 /** @BATADV_HARDIF_BCAST_OK: Do broadcast on according hard interface */
Linus Lüssing3111bee2016-08-07 12:34:19 +020051 BATADV_HARDIF_BCAST_OK = 0,
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010052
53 /**
54 * @BATADV_HARDIF_BCAST_NORECIPIENT: Broadcast not needed, there is no
55 * recipient
56 */
Linus Lüssing3111bee2016-08-07 12:34:19 +020057 BATADV_HARDIF_BCAST_NORECIPIENT,
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010058
59 /**
60 * @BATADV_HARDIF_BCAST_DUPFWD: There is just the neighbor we got it
61 * from
62 */
Linus Lüssing3111bee2016-08-07 12:34:19 +020063 BATADV_HARDIF_BCAST_DUPFWD,
Sven Eckelmann8b84cc42017-12-02 19:51:48 +010064
65 /** @BATADV_HARDIF_BCAST_DUPORIG: There is just the originator */
Linus Lüssing3111bee2016-08-07 12:34:19 +020066 BATADV_HARDIF_BCAST_DUPORIG,
67};
68
Sven Eckelmann95638772012-05-12 02:09:31 +020069extern struct notifier_block batadv_hard_if_notifier;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000070
Marek Lindner1942de12016-09-30 15:21:05 +020071struct net_device *batadv_get_real_netdev(struct net_device *net_device);
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +020072bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface);
73bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
Sven Eckelmann56303d32012-06-05 22:31:31 +020074struct batadv_hard_iface*
Sven Eckelmann95638772012-05-12 02:09:31 +020075batadv_hardif_get_by_netdev(const struct net_device *net_dev);
Sven Eckelmann56303d32012-06-05 22:31:31 +020076int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
Sven Eckelmannfa205602021-06-01 23:50:35 +020077 struct net_device *soft_iface);
Sven Eckelmanna962cb22020-08-17 14:37:13 +020078void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
Sven Eckelmann95638772012-05-12 02:09:31 +020079int batadv_hardif_min_mtu(struct net_device *soft_iface);
80void batadv_update_min_mtu(struct net_device *soft_iface);
Sven Eckelmann7a659d52016-01-16 10:29:54 +010081void batadv_hardif_release(struct kref *ref);
Linus Lüssing3111bee2016-08-07 12:34:19 +020082int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
83 u8 *orig_addr, u8 *orig_neigh);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000084
Simon Wunderlich89652332013-11-13 19:14:46 +010085/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010086 * batadv_hardif_put() - decrement the hard interface refcounter and possibly
Sven Eckelmann7a659d52016-01-16 10:29:54 +010087 * release it
Simon Wunderlich89652332013-11-13 19:14:46 +010088 * @hard_iface: the hard interface to free
89 */
Sven Eckelmann82047ad2016-01-17 11:01:10 +010090static inline void batadv_hardif_put(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000091{
Sven Eckelmann6340dcb2021-08-08 19:56:17 +020092 if (!hard_iface)
93 return;
94
Sven Eckelmann7a659d52016-01-16 10:29:54 +010095 kref_put(&hard_iface->refcount, batadv_hardif_release);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000096}
97
Sven Eckelmanne57acf82017-12-02 19:51:52 +010098/**
99 * batadv_primary_if_get_selected() - Get reference to primary interface
100 * @bat_priv: the bat priv with all the soft interface information
101 *
102 * Return: primary interface (with increased refcnt), otherwise NULL
103 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200104static inline struct batadv_hard_iface *
105batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200106{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200107 struct batadv_hard_iface *hard_iface;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200108
109 rcu_read_lock();
110 hard_iface = rcu_dereference(bat_priv->primary_if);
111 if (!hard_iface)
112 goto out;
113
Sven Eckelmann7a659d52016-01-16 10:29:54 +0100114 if (!kref_get_unless_zero(&hard_iface->refcount))
Marek Lindner32ae9b22011-04-20 15:40:58 +0200115 hard_iface = NULL;
116
117out:
118 rcu_read_unlock();
119 return hard_iface;
120}
121
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000122#endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */