Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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) 2009-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
^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) #include "gateway_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/netdevice.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/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <uapi/linux/batadv_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <uapi/linux/batman_adv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "gateway_client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "tvlv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * batadv_parse_throughput() - parse supplied string buffer to extract
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *  throughput information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * @net_dev: the soft interface net device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * @buff: string buffer to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @description: text shown when throughput string cannot be parsed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @throughput: pointer holding the returned throughput information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Return: false on parse error and true otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) bool batadv_parse_throughput(struct net_device *net_dev, char *buff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			     const char *description, u32 *throughput)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	enum batadv_bandwidth_units bw_unit_type = BATADV_BW_UNIT_KBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u64 lthroughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	char *tmp_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (strlen(buff) > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		tmp_ptr = buff + strlen(buff) - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (strncasecmp(tmp_ptr, "mbit", 4) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			bw_unit_type = BATADV_BW_UNIT_MBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		if (strncasecmp(tmp_ptr, "kbit", 4) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		    bw_unit_type == BATADV_BW_UNIT_MBIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			*tmp_ptr = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	ret = kstrtou64(buff, 10, &lthroughput);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		batadv_err(net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			   "Invalid throughput speed for %s: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			   description, buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	switch (bw_unit_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case BATADV_BW_UNIT_MBIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		/* prevent overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		if (U64_MAX / 10 < lthroughput) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			batadv_err(net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				   "Throughput speed for %s too large: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				   description, buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		lthroughput *= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	case BATADV_BW_UNIT_KBIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		lthroughput = div_u64(lthroughput, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (lthroughput > U32_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		batadv_err(net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			   "Throughput speed for %s too large: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			   description, buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	*throughput = lthroughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * batadv_parse_gw_bandwidth() - parse supplied string buffer to extract
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *  download and upload bandwidth information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @net_dev: the soft interface net device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * @buff: string buffer to parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @down: pointer holding the returned download bandwidth information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * @up: pointer holding the returned upload bandwidth information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * Return: false on parse error and true otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static bool batadv_parse_gw_bandwidth(struct net_device *net_dev, char *buff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				      u32 *down, u32 *up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	char *slash_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	slash_ptr = strchr(buff, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (slash_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		*slash_ptr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ret = batadv_parse_throughput(net_dev, buff, "download gateway speed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				      down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* we also got some upload info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (slash_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		ret = batadv_parse_throughput(net_dev, slash_ptr + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					      "upload gateway speed", up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * batadv_gw_tvlv_container_update() - update the gw tvlv container after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *  gateway setting change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct batadv_tvlv_gateway_data gw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	u32 down, up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	char gw_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	gw_mode = atomic_read(&bat_priv->gw.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	switch (gw_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	case BATADV_GW_MODE_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	case BATADV_GW_MODE_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_GW, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	case BATADV_GW_MODE_SERVER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		down = atomic_read(&bat_priv->gw.bandwidth_down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		up = atomic_read(&bat_priv->gw.bandwidth_up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		gw.bandwidth_down = htonl(down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		gw.bandwidth_up = htonl(up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		batadv_tvlv_container_register(bat_priv, BATADV_TVLV_GW, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 					       &gw, sizeof(gw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * batadv_gw_bandwidth_set() - Parse and set download/upload gateway bandwidth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  *  from supplied string buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * @net_dev: netdev struct of the soft interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * @buff: the buffer containing the user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * @count: number of bytes in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * Return: 'count' on success or a negative error code in case of failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ssize_t batadv_gw_bandwidth_set(struct net_device *net_dev, char *buff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct batadv_priv *bat_priv = netdev_priv(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	u32 down_curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	u32 up_curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	u32 down_new = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	u32 up_new = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	down_curr = (unsigned int)atomic_read(&bat_priv->gw.bandwidth_down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	up_curr = (unsigned int)atomic_read(&bat_priv->gw.bandwidth_up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	ret = batadv_parse_gw_bandwidth(net_dev, buff, &down_new, &up_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!down_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		down_new = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!up_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		up_new = down_new / 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!up_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		up_new = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (down_curr == down_new && up_curr == up_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	batadv_gw_reselect(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	batadv_info(net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		    "Changing gateway bandwidth from: '%u.%u/%u.%u MBit' to: '%u.%u/%u.%u MBit'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		    down_curr / 10, down_curr % 10, up_curr / 10, up_curr % 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		    down_new / 10, down_new % 10, up_new / 10, up_new % 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	atomic_set(&bat_priv->gw.bandwidth_down, down_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	atomic_set(&bat_priv->gw.bandwidth_up, up_new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	batadv_gw_tvlv_container_update(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * batadv_gw_tvlv_ogm_handler_v1() - process incoming gateway tvlv container
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * @orig: the orig_node of the ogm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * @tvlv_value: tvlv buffer containing the gateway data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * @tvlv_value_len: tvlv buffer length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static void batadv_gw_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 					  struct batadv_orig_node *orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 					  u8 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 					  void *tvlv_value, u16 tvlv_value_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct batadv_tvlv_gateway_data gateway, *gateway_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* only fetch the tvlv value if the handler wasn't called via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * CIFNOTFND flag and if there is data to fetch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	    tvlv_value_len < sizeof(gateway)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		gateway.bandwidth_down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		gateway.bandwidth_up = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		gateway_ptr = tvlv_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		gateway.bandwidth_down = gateway_ptr->bandwidth_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		gateway.bandwidth_up = gateway_ptr->bandwidth_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (gateway.bandwidth_down == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		    gateway.bandwidth_up == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			gateway.bandwidth_down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			gateway.bandwidth_up = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	batadv_gw_node_update(bat_priv, orig, &gateway);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* restart gateway selection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (gateway.bandwidth_down != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	    atomic_read(&bat_priv->gw.mode) == BATADV_GW_MODE_CLIENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		batadv_gw_check_election(bat_priv, orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * batadv_gw_init() - initialise the gateway handling internals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void batadv_gw_init(struct batadv_priv *bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (bat_priv->algo_ops->gw.init_sel_class)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		bat_priv->algo_ops->gw.init_sel_class(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		atomic_set(&bat_priv->gw.sel_class, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	batadv_tvlv_handler_register(bat_priv, batadv_gw_tvlv_ogm_handler_v1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				     NULL, BATADV_TVLV_GW, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				     BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * batadv_gw_free() - free the gateway handling internals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void batadv_gw_free(struct batadv_priv *bat_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_GW, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_GW, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }