aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Quartulli <a@unstable.cc>2016-07-03 06:46:32 -0400
committerSimon Wunderlich <sw@simonwunderlich.de>2016-08-09 01:54:29 -0400
commit086869438a73d8213a3f945da6679a548badbabc (patch)
tree3e22abd6c0b709c86edee8c4e356954ad0f292bf
parentf55a2e844701673dcdb939ea94a289294d1741e2 (diff)
batman-adv: make the GW selection class algorithm specific
The B.A.T.M.A.N. V algorithm uses a different metric compared to its predecessor and for this reason the logic used to compute the best Gateway is also changed. This means that the GW selection class fed to this logic has a semantics that depends on the algorithm being used. Make the parsing and printing routine of the GW selection class routing algorithm specific. Each algorithm can now parse (and print) this value independently. If no API is provided by any algorithm, the default is to use the current mechanism of considering such value like an integer between 1 and 255. Signed-off-by: Antonio Quartulli <a@unstable.cc> Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
-rw-r--r--net/batman-adv/bat_v.c34
-rw-r--r--net/batman-adv/sysfs.c34
-rw-r--r--net/batman-adv/types.h13
3 files changed, 79 insertions, 2 deletions
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index 0366cbf5e444..90fd5ee877d1 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -21,8 +21,10 @@
21#include <linux/atomic.h> 21#include <linux/atomic.h>
22#include <linux/bug.h> 22#include <linux/bug.h>
23#include <linux/cache.h> 23#include <linux/cache.h>
24#include <linux/errno.h>
24#include <linux/init.h> 25#include <linux/init.h>
25#include <linux/jiffies.h> 26#include <linux/jiffies.h>
27#include <linux/kernel.h>
26#include <linux/netdevice.h> 28#include <linux/netdevice.h>
27#include <linux/rculist.h> 29#include <linux/rculist.h>
28#include <linux/rcupdate.h> 30#include <linux/rcupdate.h>
@@ -34,6 +36,8 @@
34#include "bat_algo.h" 36#include "bat_algo.h"
35#include "bat_v_elp.h" 37#include "bat_v_elp.h"
36#include "bat_v_ogm.h" 38#include "bat_v_ogm.h"
39#include "gateway_client.h"
40#include "gateway_common.h"
37#include "hard-interface.h" 41#include "hard-interface.h"
38#include "hash.h" 42#include "hash.h"
39#include "originator.h" 43#include "originator.h"
@@ -320,6 +324,32 @@ err_ifinfo1:
320 return ret; 324 return ret;
321} 325}
322 326
327static ssize_t batadv_v_store_sel_class(struct batadv_priv *bat_priv,
328 char *buff, size_t count)
329{
330 u32 old_class, class;
331
332 if (!batadv_parse_throughput(bat_priv->soft_iface, buff,
333 "B.A.T.M.A.N. V GW selection class",
334 &class))
335 return -EINVAL;
336
337 old_class = atomic_read(&bat_priv->gw.sel_class);
338 atomic_set(&bat_priv->gw.sel_class, class);
339
340 if (old_class != class)
341 batadv_gw_reselect(bat_priv);
342
343 return count;
344}
345
346static ssize_t batadv_v_show_sel_class(struct batadv_priv *bat_priv, char *buff)
347{
348 u32 class = atomic_read(&bat_priv->gw.sel_class);
349
350 return sprintf(buff, "%u.%u MBit\n", class / 10, class % 10);
351}
352
323static struct batadv_algo_ops batadv_batman_v __read_mostly = { 353static struct batadv_algo_ops batadv_batman_v __read_mostly = {
324 .name = "BATMAN_V", 354 .name = "BATMAN_V",
325 .iface = { 355 .iface = {
@@ -338,6 +368,10 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
338 .orig = { 368 .orig = {
339 .print = batadv_v_orig_print, 369 .print = batadv_v_orig_print,
340 }, 370 },
371 .gw = {
372 .store_sel_class = batadv_v_store_sel_class,
373 .show_sel_class = batadv_v_show_sel_class,
374 },
341}; 375};
342 376
343/** 377/**
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index 4e06cb792e5d..e78bd7f2f276 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -515,6 +515,36 @@ static ssize_t batadv_store_gw_mode(struct kobject *kobj,
515 return count; 515 return count;
516} 516}
517 517
518static ssize_t batadv_show_gw_sel_class(struct kobject *kobj,
519 struct attribute *attr, char *buff)
520{
521 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
522
523 if (bat_priv->algo_ops->gw.show_sel_class)
524 return bat_priv->algo_ops->gw.show_sel_class(bat_priv, buff);
525
526 return sprintf(buff, "%i\n", atomic_read(&bat_priv->gw.sel_class));
527}
528
529static ssize_t batadv_store_gw_sel_class(struct kobject *kobj,
530 struct attribute *attr, char *buff,
531 size_t count)
532{
533 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
534
535 if (buff[count - 1] == '\n')
536 buff[count - 1] = '\0';
537
538 if (bat_priv->algo_ops->gw.store_sel_class)
539 return bat_priv->algo_ops->gw.store_sel_class(bat_priv, buff,
540 count);
541
542 return __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE,
543 batadv_post_gw_reselect, attr,
544 &bat_priv->gw.sel_class,
545 bat_priv->soft_iface);
546}
547
518static ssize_t batadv_show_gw_bwidth(struct kobject *kobj, 548static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,
519 struct attribute *attr, char *buff) 549 struct attribute *attr, char *buff)
520{ 550{
@@ -626,8 +656,8 @@ BATADV_ATTR_SIF_UINT(orig_interval, orig_interval, S_IRUGO | S_IWUSR,
626 2 * BATADV_JITTER, INT_MAX, NULL); 656 2 * BATADV_JITTER, INT_MAX, NULL);
627BATADV_ATTR_SIF_UINT(hop_penalty, hop_penalty, S_IRUGO | S_IWUSR, 0, 657BATADV_ATTR_SIF_UINT(hop_penalty, hop_penalty, S_IRUGO | S_IWUSR, 0,
628 BATADV_TQ_MAX_VALUE, NULL); 658 BATADV_TQ_MAX_VALUE, NULL);
629BATADV_ATTR_SIF_UINT(gw_sel_class, gw.sel_class, S_IRUGO | S_IWUSR, 1, 659static BATADV_ATTR(gw_sel_class, S_IRUGO | S_IWUSR, batadv_show_gw_sel_class,
630 BATADV_TQ_MAX_VALUE, batadv_post_gw_reselect); 660 batadv_store_gw_sel_class);
631static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth, 661static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth,
632 batadv_store_gw_bwidth); 662 batadv_store_gw_bwidth);
633#ifdef CONFIG_BATMAN_ADV_MCAST 663#ifdef CONFIG_BATMAN_ADV_MCAST
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 96af6daa4fc9..deaadba61a2c 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1450,12 +1450,24 @@ struct batadv_algo_orig_ops {
1450}; 1450};
1451 1451
1452/** 1452/**
1453 * struct batadv_algo_gw_ops - mesh algorithm callbacks (GW specific)
1454 * @store_sel_class: parse and stores a new GW selection class (optional)
1455 * @show_sel_class: prints the current GW selection class (optional)
1456 */
1457struct batadv_algo_gw_ops {
1458 ssize_t (*store_sel_class)(struct batadv_priv *bat_priv, char *buff,
1459 size_t count);
1460 ssize_t (*show_sel_class)(struct batadv_priv *bat_priv, char *buff);
1461};
1462
1463/**
1453 * struct batadv_algo_ops - mesh algorithm callbacks 1464 * struct batadv_algo_ops - mesh algorithm callbacks
1454 * @list: list node for the batadv_algo_list 1465 * @list: list node for the batadv_algo_list
1455 * @name: name of the algorithm 1466 * @name: name of the algorithm
1456 * @iface: callbacks related to interface handling 1467 * @iface: callbacks related to interface handling
1457 * @neigh: callbacks related to neighbors handling 1468 * @neigh: callbacks related to neighbors handling
1458 * @orig: callbacks related to originators handling 1469 * @orig: callbacks related to originators handling
1470 * @gw: callbacks related to GW mode
1459 */ 1471 */
1460struct batadv_algo_ops { 1472struct batadv_algo_ops {
1461 struct hlist_node list; 1473 struct hlist_node list;
@@ -1463,6 +1475,7 @@ struct batadv_algo_ops {
1463 struct batadv_algo_iface_ops iface; 1475 struct batadv_algo_iface_ops iface;
1464 struct batadv_algo_neigh_ops neigh; 1476 struct batadv_algo_neigh_ops neigh;
1465 struct batadv_algo_orig_ops orig; 1477 struct batadv_algo_orig_ops orig;
1478 struct batadv_algo_gw_ops gw;
1466}; 1479};
1467 1480
1468/** 1481/**