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