batman-adv: Add gateway mesh genl configuration
authorSven Eckelmann <sven@narfation.org>
Fri, 23 Nov 2018 12:15:00 +0000 (13:15 +0100)
committerSimon Wunderlich <sw@simonwunderlich.de>
Sat, 9 Feb 2019 13:28:14 +0000 (14:28 +0100)
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>
include/uapi/linux/batman_adv.h
net/batman-adv/gateway_client.c
net/batman-adv/gateway_common.c
net/batman-adv/gateway_common.h
net/batman-adv/netlink.c
net/batman-adv/soft-interface.c
net/batman-adv/sysfs.c

index 847841b8de5ddb471177d056b3a2eed8f1c94baa..165272be687878cfd0c42a580310ca69bbd22f92 100644 (file)
@@ -139,6 +139,20 @@ enum batadv_mcast_flags_priv {
        BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING       = (1 << 4),
 };
 
+/**
+ * enum batadv_gw_modes - gateway mode of node
+ */
+enum batadv_gw_modes {
+       /** @BATADV_GW_MODE_OFF: gw mode disabled */
+       BATADV_GW_MODE_OFF,
+
+       /** @BATADV_GW_MODE_CLIENT: send DHCP requests to gw servers */
+       BATADV_GW_MODE_CLIENT,
+
+       /** @BATADV_GW_MODE_SERVER: announce itself as gatway server */
+       BATADV_GW_MODE_SERVER,
+};
+
 /**
  * enum batadv_nl_attrs - batman-adv netlink attributes
  */
@@ -403,6 +417,32 @@ enum batadv_nl_attrs {
         */
        BATADV_ATTR_FRAGMENTATION_ENABLED,
 
+       /**
+        * @BATADV_ATTR_GW_BANDWIDTH_DOWN: defines the download bandwidth which
+        *  is propagated by this node if %BATADV_ATTR_GW_BANDWIDTH_MODE was set
+        *  to 'server'.
+        */
+       BATADV_ATTR_GW_BANDWIDTH_DOWN,
+
+       /**
+        * @BATADV_ATTR_GW_BANDWIDTH_UP: defines the upload bandwidth which
+        *  is propagated by this node if %BATADV_ATTR_GW_BANDWIDTH_MODE was set
+        *  to 'server'.
+        */
+       BATADV_ATTR_GW_BANDWIDTH_UP,
+
+       /**
+        * @BATADV_ATTR_GW_MODE: defines the state of the gateway features.
+        * Possible values are specified in enum batadv_gw_modes
+        */
+       BATADV_ATTR_GW_MODE,
+
+       /**
+        * @BATADV_ATTR_GW_SEL_CLASS: defines the selection criteria this node
+        *  will use to choose a gateway if gw_mode was set to 'client'.
+        */
+       BATADV_ATTR_GW_SEL_CLASS,
+
        /* add attributes above here, update the policy in netlink.c */
 
        /**
index 0a6b9b30eabd19d320feee8fe1bd2223aa71a06a..f5811f61aa927e80ca5cbecd04b19b8c6d93e3d0 100644 (file)
@@ -47,7 +47,6 @@
 #include <uapi/linux/batadv_packet.h>
 #include <uapi/linux/batman_adv.h>
 
-#include "gateway_common.h"
 #include "hard-interface.h"
 #include "log.h"
 #include "netlink.h"
index 53d03adc9bfc2b13543d9ca6028c5846fb4e07ba..e064de45e22cdbb575c093b3ae5ec33926e7f6a8 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/stddef.h>
 #include <linux/string.h>
 #include <uapi/linux/batadv_packet.h>
+#include <uapi/linux/batman_adv.h>
 
 #include "gateway_client.h"
 #include "log.h"
index 89bae100a0b0d9d0ad075cedb135bcb70ebf5c20..128467a0fb895484c810502c5f86e4094de81748 100644 (file)
 
 struct net_device;
 
-enum batadv_gw_modes {
-       BATADV_GW_MODE_OFF,
-       BATADV_GW_MODE_CLIENT,
-       BATADV_GW_MODE_SERVER,
-};
-
 /**
  * enum batadv_bandwidth_units - bandwidth unit types
  */
index 5b2160d2f4824ff08237ebed7bb0b3e0eb5e61f6..473467afea914c0b6bff068ea7091e442352e417 100644 (file)
@@ -51,6 +51,7 @@
 #include "bridge_loop_avoidance.h"
 #include "distributed-arp-table.h"
 #include "gateway_client.h"
+#include "gateway_common.h"
 #include "hard-interface.h"
 #include "multicast.h"
 #include "originator.h"
@@ -147,6 +148,10 @@ static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
        [BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]     = { .type = NLA_U8 },
        [BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED]     = { .type = NLA_U8 },
        [BATADV_ATTR_FRAGMENTATION_ENABLED]     = { .type = NLA_U8 },
+       [BATADV_ATTR_GW_BANDWIDTH_DOWN]         = { .type = NLA_U32 },
+       [BATADV_ATTR_GW_BANDWIDTH_UP]           = { .type = NLA_U32 },
+       [BATADV_ATTR_GW_MODE]                   = { .type = NLA_U8 },
+       [BATADV_ATTR_GW_SEL_CLASS]              = { .type = NLA_U32 },
 };
 
 /**
@@ -303,6 +308,28 @@ static int batadv_netlink_mesh_fill(struct sk_buff *msg,
                       !!atomic_read(&bat_priv->fragmentation)))
                goto nla_put_failure;
 
+       if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_DOWN,
+                       atomic_read(&bat_priv->gw.bandwidth_down)))
+               goto nla_put_failure;
+
+       if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_UP,
+                       atomic_read(&bat_priv->gw.bandwidth_up)))
+               goto nla_put_failure;
+
+       if (nla_put_u8(msg, BATADV_ATTR_GW_MODE,
+                      atomic_read(&bat_priv->gw.mode)))
+               goto nla_put_failure;
+
+       if (bat_priv->algo_ops->gw.get_best_gw_node &&
+           bat_priv->algo_ops->gw.is_eligible) {
+               /* GW selection class is not available if the routing algorithm
+                * in use does not implement the GW API
+                */
+               if (nla_put_u32(msg, BATADV_ATTR_GW_SEL_CLASS,
+                               atomic_read(&bat_priv->gw.sel_class)))
+                       goto nla_put_failure;
+       }
+
        if (primary_if)
                batadv_hardif_put(primary_if);
 
@@ -444,6 +471,71 @@ static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info)
                batadv_update_min_mtu(bat_priv->soft_iface);
        }
 
+       if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]) {
+               attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN];
+
+               atomic_set(&bat_priv->gw.bandwidth_down, nla_get_u32(attr));
+               batadv_gw_tvlv_container_update(bat_priv);
+       }
+
+       if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP]) {
+               attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP];
+
+               atomic_set(&bat_priv->gw.bandwidth_up, nla_get_u32(attr));
+               batadv_gw_tvlv_container_update(bat_priv);
+       }
+
+       if (info->attrs[BATADV_ATTR_GW_MODE]) {
+               u8 gw_mode;
+
+               attr = info->attrs[BATADV_ATTR_GW_MODE];
+               gw_mode = nla_get_u8(attr);
+
+               if (gw_mode <= BATADV_GW_MODE_SERVER) {
+                       /* Invoking batadv_gw_reselect() is not enough to really
+                        * de-select the current GW. It will only instruct the
+                        * gateway client code to perform a re-election the next
+                        * time that this is needed.
+                        *
+                        * When gw client mode is being switched off the current
+                        * GW must be de-selected explicitly otherwise no GW_ADD
+                        * uevent is thrown on client mode re-activation. This
+                        * is operation is performed in
+                        * batadv_gw_check_client_stop().
+                        */
+                       batadv_gw_reselect(bat_priv);
+
+                       /* always call batadv_gw_check_client_stop() before
+                        * changing the gateway state
+                        */
+                       batadv_gw_check_client_stop(bat_priv);
+                       atomic_set(&bat_priv->gw.mode, gw_mode);
+                       batadv_gw_tvlv_container_update(bat_priv);
+               }
+       }
+
+       if (info->attrs[BATADV_ATTR_GW_SEL_CLASS] &&
+           bat_priv->algo_ops->gw.get_best_gw_node &&
+           bat_priv->algo_ops->gw.is_eligible) {
+               /* setting the GW selection class is allowed only if the routing
+                * algorithm in use implements the GW API
+                */
+
+               u32 sel_class_max = 0xffffffffu;
+               u32 sel_class;
+
+               attr = info->attrs[BATADV_ATTR_GW_SEL_CLASS];
+               sel_class = nla_get_u32(attr);
+
+               if (!bat_priv->algo_ops->gw.store_sel_class)
+                       sel_class_max = BATADV_TQ_MAX_VALUE;
+
+               if (sel_class >= 1 && sel_class <= sel_class_max) {
+                       atomic_set(&bat_priv->gw.sel_class, sel_class);
+                       batadv_gw_reselect(bat_priv);
+               }
+       }
+
        batadv_netlink_notify_mesh(bat_priv);
 
        return 0;
index b14fb3462af73cf2118430cffe8998df5cbf46e4..12028c287de5752c54484b9801d568b30b488b96 100644 (file)
 #include <linux/string.h>
 #include <linux/types.h>
 #include <uapi/linux/batadv_packet.h>
+#include <uapi/linux/batman_adv.h>
 
 #include "bat_algo.h"
 #include "bridge_loop_avoidance.h"
 #include "debugfs.h"
 #include "distributed-arp-table.h"
 #include "gateway_client.h"
-#include "gateway_common.h"
 #include "hard-interface.h"
 #include "multicast.h"
 #include "network-coding.h"
index e1b816262c53b615ed56c4277027bf4ffdd11bc1..64fd5932a5553e92173ce0d7c74f15d5862ba954 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/stringify.h>
 #include <linux/workqueue.h>
 #include <uapi/linux/batadv_packet.h>
+#include <uapi/linux/batman_adv.h>
 
 #include "bridge_loop_avoidance.h"
 #include "distributed-arp-table.h"