aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/gateway_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/gateway_common.c')
-rw-r--r--net/batman-adv/gateway_common.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index ca57ac7d73b..9001208d175 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -1,5 +1,4 @@
1/* 1/* Copyright (C) 2009-2012 B.A.T.M.A.N. contributors:
2 * Copyright (C) 2009-2012 B.A.T.M.A.N. contributors:
3 * 2 *
4 * Marek Lindner 3 * Marek Lindner
5 * 4 *
@@ -16,7 +15,6 @@
16 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA 17 * 02110-1301, USA
19 *
20 */ 18 */
21 19
22#include "main.h" 20#include "main.h"
@@ -24,7 +22,7 @@
24#include "gateway_client.h" 22#include "gateway_client.h"
25 23
26/* calculates the gateway class from kbit */ 24/* calculates the gateway class from kbit */
27static void kbit_to_gw_bandwidth(int down, int up, long *gw_srv_class) 25static void batadv_kbit_to_gw_bandwidth(int down, int up, long *gw_srv_class)
28{ 26{
29 int mdown = 0, tdown, tup, difference; 27 int mdown = 0, tdown, tup, difference;
30 uint8_t sbit, part; 28 uint8_t sbit, part;
@@ -59,7 +57,7 @@ static void kbit_to_gw_bandwidth(int down, int up, long *gw_srv_class)
59} 57}
60 58
61/* returns the up and downspeeds in kbit, calculated from the class */ 59/* returns the up and downspeeds in kbit, calculated from the class */
62void gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *up) 60void batadv_gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *up)
63{ 61{
64 int sbit = (gw_srv_class & 0x80) >> 7; 62 int sbit = (gw_srv_class & 0x80) >> 7;
65 int dpart = (gw_srv_class & 0x78) >> 3; 63 int dpart = (gw_srv_class & 0x78) >> 3;
@@ -75,8 +73,8 @@ void gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *up)
75 *up = ((upart + 1) * (*down)) / 8; 73 *up = ((upart + 1) * (*down)) / 8;
76} 74}
77 75
78static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, 76static bool batadv_parse_gw_bandwidth(struct net_device *net_dev, char *buff,
79 int *up, int *down) 77 int *up, int *down)
80{ 78{
81 int ret, multi = 1; 79 int ret, multi = 1;
82 char *slash_ptr, *tmp_ptr; 80 char *slash_ptr, *tmp_ptr;
@@ -99,9 +97,9 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
99 97
100 ret = kstrtol(buff, 10, &ldown); 98 ret = kstrtol(buff, 10, &ldown);
101 if (ret) { 99 if (ret) {
102 bat_err(net_dev, 100 batadv_err(net_dev,
103 "Download speed of gateway mode invalid: %s\n", 101 "Download speed of gateway mode invalid: %s\n",
104 buff); 102 buff);
105 return false; 103 return false;
106 } 104 }
107 105
@@ -124,9 +122,9 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
124 122
125 ret = kstrtol(slash_ptr + 1, 10, &lup); 123 ret = kstrtol(slash_ptr + 1, 10, &lup);
126 if (ret) { 124 if (ret) {
127 bat_err(net_dev, 125 batadv_err(net_dev,
128 "Upload speed of gateway mode invalid: %s\n", 126 "Upload speed of gateway mode invalid: %s\n",
129 slash_ptr + 1); 127 slash_ptr + 1);
130 return false; 128 return false;
131 } 129 }
132 130
@@ -136,14 +134,15 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
136 return true; 134 return true;
137} 135}
138 136
139ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count) 137ssize_t batadv_gw_bandwidth_set(struct net_device *net_dev, char *buff,
138 size_t count)
140{ 139{
141 struct bat_priv *bat_priv = netdev_priv(net_dev); 140 struct batadv_priv *bat_priv = netdev_priv(net_dev);
142 long gw_bandwidth_tmp = 0; 141 long gw_bandwidth_tmp = 0;
143 int up = 0, down = 0; 142 int up = 0, down = 0;
144 bool ret; 143 bool ret;
145 144
146 ret = parse_gw_bandwidth(net_dev, buff, &up, &down); 145 ret = batadv_parse_gw_bandwidth(net_dev, buff, &up, &down);
147 if (!ret) 146 if (!ret)
148 goto end; 147 goto end;
149 148
@@ -153,23 +152,25 @@ ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count)
153 if (!up) 152 if (!up)
154 up = down / 5; 153 up = down / 5;
155 154
156 kbit_to_gw_bandwidth(down, up, &gw_bandwidth_tmp); 155 batadv_kbit_to_gw_bandwidth(down, up, &gw_bandwidth_tmp);
157 156
158 /** 157 /* the gw bandwidth we guessed above might not match the given
159 * the gw bandwidth we guessed above might not match the given
160 * speeds, hence we need to calculate it back to show the number 158 * speeds, hence we need to calculate it back to show the number
161 * that is going to be propagated 159 * that is going to be propagated
162 **/ 160 */
163 gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, &down, &up); 161 batadv_gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, &down, &up);
164 162
165 gw_deselect(bat_priv); 163 if (atomic_read(&bat_priv->gw_bandwidth) == gw_bandwidth_tmp)
166 bat_info(net_dev, 164 return count;
167 "Changing gateway bandwidth from: '%i' to: '%ld' (propagating: %d%s/%d%s)\n", 165
168 atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp, 166 batadv_gw_deselect(bat_priv);
169 (down > 2048 ? down / 1024 : down), 167 batadv_info(net_dev,
170 (down > 2048 ? "MBit" : "KBit"), 168 "Changing gateway bandwidth from: '%i' to: '%ld' (propagating: %d%s/%d%s)\n",
171 (up > 2048 ? up / 1024 : up), 169 atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp,
172 (up > 2048 ? "MBit" : "KBit")); 170 (down > 2048 ? down / 1024 : down),
171 (down > 2048 ? "MBit" : "KBit"),
172 (up > 2048 ? up / 1024 : up),
173 (up > 2048 ? "MBit" : "KBit"));
173 174
174 atomic_set(&bat_priv->gw_bandwidth, gw_bandwidth_tmp); 175 atomic_set(&bat_priv->gw_bandwidth, gw_bandwidth_tmp);
175 176