Commit e2d0d35b5b0ce420505e88255fd5922ed035bb8d

Authored by Sven Eckelmann
Committed by Simon Wunderlich
1 parent 3e15b06eb7

batman-adv: Add gateway mesh genl configuration

The mesh/soft-interface can optimize the handling of DHCP packets. Instead
of flooding them through the whole mesh, it can be forwarded as unicast to
a specific gateway server. The originator which injects the packets in the
mesh has to select (based on sel_class thresholds) a responsible gateway
server. This is done by switching this originator to the gw_mode client.
The servers announce their forwarding bandwidth (download/upload) when the
gw_mode server was selected.

The BATADV_CMD_SET_MESH/BATADV_CMD_GET_MESH commands allow to set/get the
configuration of this feature using the attributes:

* u8 BATADV_ATTR_GW_MODE (0 == off, 1 == client, 2 == server)
* u32 BATADV_ATTR_GW_BANDWIDTH_DOWN (in 100 kbit/s steps)
* u32 BATADV_ATTR_GW_BANDWIDTH_UP (in 100 kbit/s steps)
* u32 BATADV_ATTR_GW_SEL_CLASS

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>

Showing 7 changed files with 135 additions and 8 deletions Side-by-side Diff

include/uapi/linux/batman_adv.h
... ... @@ -140,6 +140,20 @@
140 140 };
141 141  
142 142 /**
  143 + * enum batadv_gw_modes - gateway mode of node
  144 + */
  145 +enum batadv_gw_modes {
  146 + /** @BATADV_GW_MODE_OFF: gw mode disabled */
  147 + BATADV_GW_MODE_OFF,
  148 +
  149 + /** @BATADV_GW_MODE_CLIENT: send DHCP requests to gw servers */
  150 + BATADV_GW_MODE_CLIENT,
  151 +
  152 + /** @BATADV_GW_MODE_SERVER: announce itself as gatway server */
  153 + BATADV_GW_MODE_SERVER,
  154 +};
  155 +
  156 +/**
143 157 * enum batadv_nl_attrs - batman-adv netlink attributes
144 158 */
145 159 enum batadv_nl_attrs {
... ... @@ -402,6 +416,32 @@
402 416 * packet size exceeds the outgoing interface MTU.
403 417 */
404 418 BATADV_ATTR_FRAGMENTATION_ENABLED,
  419 +
  420 + /**
  421 + * @BATADV_ATTR_GW_BANDWIDTH_DOWN: defines the download bandwidth which
  422 + * is propagated by this node if %BATADV_ATTR_GW_BANDWIDTH_MODE was set
  423 + * to 'server'.
  424 + */
  425 + BATADV_ATTR_GW_BANDWIDTH_DOWN,
  426 +
  427 + /**
  428 + * @BATADV_ATTR_GW_BANDWIDTH_UP: defines the upload bandwidth which
  429 + * is propagated by this node if %BATADV_ATTR_GW_BANDWIDTH_MODE was set
  430 + * to 'server'.
  431 + */
  432 + BATADV_ATTR_GW_BANDWIDTH_UP,
  433 +
  434 + /**
  435 + * @BATADV_ATTR_GW_MODE: defines the state of the gateway features.
  436 + * Possible values are specified in enum batadv_gw_modes
  437 + */
  438 + BATADV_ATTR_GW_MODE,
  439 +
  440 + /**
  441 + * @BATADV_ATTR_GW_SEL_CLASS: defines the selection criteria this node
  442 + * will use to choose a gateway if gw_mode was set to 'client'.
  443 + */
  444 + BATADV_ATTR_GW_SEL_CLASS,
405 445  
406 446 /* add attributes above here, update the policy in netlink.c */
407 447  
net/batman-adv/gateway_client.c
... ... @@ -47,7 +47,6 @@
47 47 #include <uapi/linux/batadv_packet.h>
48 48 #include <uapi/linux/batman_adv.h>
49 49  
50   -#include "gateway_common.h"
51 50 #include "hard-interface.h"
52 51 #include "log.h"
53 52 #include "netlink.h"
net/batman-adv/gateway_common.c
... ... @@ -28,6 +28,7 @@
28 28 #include <linux/stddef.h>
29 29 #include <linux/string.h>
30 30 #include <uapi/linux/batadv_packet.h>
  31 +#include <uapi/linux/batman_adv.h>
31 32  
32 33 #include "gateway_client.h"
33 34 #include "log.h"
net/batman-adv/gateway_common.h
... ... @@ -25,12 +25,6 @@
25 25  
26 26 struct net_device;
27 27  
28   -enum batadv_gw_modes {
29   - BATADV_GW_MODE_OFF,
30   - BATADV_GW_MODE_CLIENT,
31   - BATADV_GW_MODE_SERVER,
32   -};
33   -
34 28 /**
35 29 * enum batadv_bandwidth_units - bandwidth unit types
36 30 */
net/batman-adv/netlink.c
... ... @@ -51,6 +51,7 @@
51 51 #include "bridge_loop_avoidance.h"
52 52 #include "distributed-arp-table.h"
53 53 #include "gateway_client.h"
  54 +#include "gateway_common.h"
54 55 #include "hard-interface.h"
55 56 #include "multicast.h"
56 57 #include "originator.h"
... ... @@ -147,6 +148,10 @@
147 148 [BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED] = { .type = NLA_U8 },
148 149 [BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED] = { .type = NLA_U8 },
149 150 [BATADV_ATTR_FRAGMENTATION_ENABLED] = { .type = NLA_U8 },
  151 + [BATADV_ATTR_GW_BANDWIDTH_DOWN] = { .type = NLA_U32 },
  152 + [BATADV_ATTR_GW_BANDWIDTH_UP] = { .type = NLA_U32 },
  153 + [BATADV_ATTR_GW_MODE] = { .type = NLA_U8 },
  154 + [BATADV_ATTR_GW_SEL_CLASS] = { .type = NLA_U32 },
150 155 };
151 156  
152 157 /**
... ... @@ -303,6 +308,28 @@
303 308 !!atomic_read(&bat_priv->fragmentation)))
304 309 goto nla_put_failure;
305 310  
  311 + if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_DOWN,
  312 + atomic_read(&bat_priv->gw.bandwidth_down)))
  313 + goto nla_put_failure;
  314 +
  315 + if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_UP,
  316 + atomic_read(&bat_priv->gw.bandwidth_up)))
  317 + goto nla_put_failure;
  318 +
  319 + if (nla_put_u8(msg, BATADV_ATTR_GW_MODE,
  320 + atomic_read(&bat_priv->gw.mode)))
  321 + goto nla_put_failure;
  322 +
  323 + if (bat_priv->algo_ops->gw.get_best_gw_node &&
  324 + bat_priv->algo_ops->gw.is_eligible) {
  325 + /* GW selection class is not available if the routing algorithm
  326 + * in use does not implement the GW API
  327 + */
  328 + if (nla_put_u32(msg, BATADV_ATTR_GW_SEL_CLASS,
  329 + atomic_read(&bat_priv->gw.sel_class)))
  330 + goto nla_put_failure;
  331 + }
  332 +
306 333 if (primary_if)
307 334 batadv_hardif_put(primary_if);
308 335  
... ... @@ -442,6 +469,71 @@
442 469  
443 470 atomic_set(&bat_priv->fragmentation, !!nla_get_u8(attr));
444 471 batadv_update_min_mtu(bat_priv->soft_iface);
  472 + }
  473 +
  474 + if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]) {
  475 + attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN];
  476 +
  477 + atomic_set(&bat_priv->gw.bandwidth_down, nla_get_u32(attr));
  478 + batadv_gw_tvlv_container_update(bat_priv);
  479 + }
  480 +
  481 + if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP]) {
  482 + attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP];
  483 +
  484 + atomic_set(&bat_priv->gw.bandwidth_up, nla_get_u32(attr));
  485 + batadv_gw_tvlv_container_update(bat_priv);
  486 + }
  487 +
  488 + if (info->attrs[BATADV_ATTR_GW_MODE]) {
  489 + u8 gw_mode;
  490 +
  491 + attr = info->attrs[BATADV_ATTR_GW_MODE];
  492 + gw_mode = nla_get_u8(attr);
  493 +
  494 + if (gw_mode <= BATADV_GW_MODE_SERVER) {
  495 + /* Invoking batadv_gw_reselect() is not enough to really
  496 + * de-select the current GW. It will only instruct the
  497 + * gateway client code to perform a re-election the next
  498 + * time that this is needed.
  499 + *
  500 + * When gw client mode is being switched off the current
  501 + * GW must be de-selected explicitly otherwise no GW_ADD
  502 + * uevent is thrown on client mode re-activation. This
  503 + * is operation is performed in
  504 + * batadv_gw_check_client_stop().
  505 + */
  506 + batadv_gw_reselect(bat_priv);
  507 +
  508 + /* always call batadv_gw_check_client_stop() before
  509 + * changing the gateway state
  510 + */
  511 + batadv_gw_check_client_stop(bat_priv);
  512 + atomic_set(&bat_priv->gw.mode, gw_mode);
  513 + batadv_gw_tvlv_container_update(bat_priv);
  514 + }
  515 + }
  516 +
  517 + if (info->attrs[BATADV_ATTR_GW_SEL_CLASS] &&
  518 + bat_priv->algo_ops->gw.get_best_gw_node &&
  519 + bat_priv->algo_ops->gw.is_eligible) {
  520 + /* setting the GW selection class is allowed only if the routing
  521 + * algorithm in use implements the GW API
  522 + */
  523 +
  524 + u32 sel_class_max = 0xffffffffu;
  525 + u32 sel_class;
  526 +
  527 + attr = info->attrs[BATADV_ATTR_GW_SEL_CLASS];
  528 + sel_class = nla_get_u32(attr);
  529 +
  530 + if (!bat_priv->algo_ops->gw.store_sel_class)
  531 + sel_class_max = BATADV_TQ_MAX_VALUE;
  532 +
  533 + if (sel_class >= 1 && sel_class <= sel_class_max) {
  534 + atomic_set(&bat_priv->gw.sel_class, sel_class);
  535 + batadv_gw_reselect(bat_priv);
  536 + }
445 537 }
446 538  
447 539 batadv_netlink_notify_mesh(bat_priv);
net/batman-adv/soft-interface.c
... ... @@ -50,13 +50,13 @@
50 50 #include <linux/string.h>
51 51 #include <linux/types.h>
52 52 #include <uapi/linux/batadv_packet.h>
  53 +#include <uapi/linux/batman_adv.h>
53 54  
54 55 #include "bat_algo.h"
55 56 #include "bridge_loop_avoidance.h"
56 57 #include "debugfs.h"
57 58 #include "distributed-arp-table.h"
58 59 #include "gateway_client.h"
59   -#include "gateway_common.h"
60 60 #include "hard-interface.h"
61 61 #include "multicast.h"
62 62 #include "network-coding.h"
net/batman-adv/sysfs.c
... ... @@ -40,6 +40,7 @@
40 40 #include <linux/stringify.h>
41 41 #include <linux/workqueue.h>
42 42 #include <uapi/linux/batadv_packet.h>
  43 +#include <uapi/linux/batman_adv.h>
43 44  
44 45 #include "bridge_loop_avoidance.h"
45 46 #include "distributed-arp-table.h"