batman-adv: Add bridge_loop_avoidance mesh genl configuration
authorSven Eckelmann <sven@narfation.org>
Fri, 23 Nov 2018 12:03:39 +0000 (13:03 +0100)
committerSimon Wunderlich <sw@simonwunderlich.de>
Sat, 9 Feb 2019 13:28:14 +0000 (14:28 +0100)
The mesh interface can try to detect loops in the same mesh caused by
(indirectly) bridged mesh/soft-interfaces of different nodes. Some of the
loops can also be resolved without breaking the mesh.

The BATADV_CMD_SET_MESH/BATADV_CMD_GET_MESH commands allow to set/get the
configuration of this feature using the
BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED attribute. Setting the u8 to zero
will disable this feature and setting it to something else is enabling this
feature.

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/netlink.c

index f74ff26..3cb35c6 100644 (file)
@@ -381,6 +381,13 @@ enum batadv_nl_attrs {
         */
        BATADV_ATTR_BONDING_ENABLED,
 
+       /**
+        * @BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED: whether the bridge loop
+        *  avoidance feature is enabled. This feature detects and avoids loops
+        *  between the mesh and devices bridged with the soft interface
+        */
+       BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED,
+
        /* add attributes above here, update the policy in netlink.c */
 
        /**
index 310a2c3..40c940d 100644 (file)
@@ -144,6 +144,7 @@ static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
        [BATADV_ATTR_ISOLATION_MARK]            = { .type = NLA_U32 },
        [BATADV_ATTR_ISOLATION_MASK]            = { .type = NLA_U32 },
        [BATADV_ATTR_BONDING_ENABLED]           = { .type = NLA_U8 },
+       [BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]     = { .type = NLA_U8 },
 };
 
 /**
@@ -284,6 +285,12 @@ static int batadv_netlink_mesh_fill(struct sk_buff *msg,
                       !!atomic_read(&bat_priv->bonding)))
                goto nla_put_failure;
 
+#ifdef CONFIG_BATMAN_ADV_BLA
+       if (nla_put_u8(msg, BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED,
+                      !!atomic_read(&bat_priv->bridge_loop_avoidance)))
+               goto nla_put_failure;
+#endif /* CONFIG_BATMAN_ADV_BLA */
+
        if (primary_if)
                batadv_hardif_put(primary_if);
 
@@ -398,6 +405,16 @@ static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info)
                atomic_set(&bat_priv->bonding, !!nla_get_u8(attr));
        }
 
+#ifdef CONFIG_BATMAN_ADV_BLA
+       if (info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]) {
+               attr = info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED];
+
+               atomic_set(&bat_priv->bridge_loop_avoidance,
+                          !!nla_get_u8(attr));
+               batadv_bla_status_update(bat_priv->soft_iface);
+       }
+#endif /* CONFIG_BATMAN_ADV_BLA */
+
        batadv_netlink_notify_mesh(bat_priv);
 
        return 0;