Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42019357 authored by Marek Lindner's avatar Marek Lindner Committed by Greg Kroah-Hartman
Browse files

Staging: batman-adv: softif bridge loop avoidance



By connecting multiple batman-adv mesh nodes to the same ethernet
segment a loop can be created when the soft-interface is bridged
into that ethernet segment. A simple visualization of the loop
involving the most common case - a LAN as ethernet segment:

node1  <-- LAN  -->  node2
   |                   |
 wifi  <-- mesh -->  wifi

Packets from the LAN (e.g. ARP broadcasts) will circle forever from
node1 or node2 over the mesh back into the LAN.

This patch adds the functionality to detect other batman-adv nodes
connected to the LAN and select a 'gateway' to talk to the
non-batman-adv devices on this LAN. All traffic from and to the mesh
will be handled by this gateway to avoid the loop. OGMs received via
the soft-interface are interpreted as 'port announcements' to locate
potential batman-adv nodes. The patch can also deal with vlans on
top of batX and offers a list of LAN neighbors via debugfs.

Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
[sven.eckelmann@gmx.de: Rework on top of current version]
Signed-off-by: default avatarSven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 225f7b0b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "translation-table.h"
#include "originator.h"
#include "hard-interface.h"
#include "soft-interface.h"
#include "vis.h"
#include "icmp_socket.h"

@@ -227,6 +228,12 @@ static int originators_open(struct inode *inode, struct file *file)
	return single_open(file, orig_seq_print_text, net_dev);
}

static int softif_neigh_open(struct inode *inode, struct file *file)
{
	struct net_device *net_dev = (struct net_device *)inode->i_private;
	return single_open(file, softif_neigh_seq_print_text, net_dev);
}

static int transtable_global_open(struct inode *inode, struct file *file)
{
	struct net_device *net_dev = (struct net_device *)inode->i_private;
@@ -263,12 +270,14 @@ struct bat_debuginfo bat_debuginfo_##_name = { \
};

static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open);
static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open);
static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open);
static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);

static struct bat_debuginfo *mesh_debuginfos[] = {
	&bat_debuginfo_originators,
	&bat_debuginfo_softif_neigh,
	&bat_debuginfo_transtable_global,
	&bat_debuginfo_transtable_local,
	&bat_debuginfo_vis_data,
+4 −0
Original line number Diff line number Diff line
@@ -86,9 +86,11 @@ int mesh_init(struct net_device *soft_iface)
	spin_lock_init(&bat_priv->hna_ghash_lock);
	spin_lock_init(&bat_priv->vis_hash_lock);
	spin_lock_init(&bat_priv->vis_list_lock);
	spin_lock_init(&bat_priv->softif_neigh_lock);

	INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
	INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
	INIT_HLIST_HEAD(&bat_priv->softif_neigh_list);

	if (originator_init(bat_priv) < 1)
		goto err;
@@ -132,6 +134,8 @@ void mesh_free(struct net_device *soft_iface)
	hna_local_free(bat_priv);
	hna_global_free(bat_priv);

	softif_neigh_purge(bat_priv);

	atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
}

+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@
				   * forw_packet->direct_link_flags */
#define MAX_AGGREGATION_MS 100

#define SOFTIF_NEIGH_TIMEOUT 180000 /* 3 minutes */

#define RESET_PROTECTION_MS 30000
#define EXPECTED_SEQNO_RANGE	65536
/* don't reset again within 30 seconds */
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "routing.h"
#include "hard-interface.h"
#include "unicast.h"
#include "soft-interface.h"

static void purge_orig(struct work_struct *work);

@@ -286,6 +287,7 @@ static void _purge_orig(struct bat_priv *bat_priv)

	spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);

	softif_neigh_purge(bat_priv);
}

static void purge_orig(struct work_struct *work)
+6 −6
Original line number Diff line number Diff line
@@ -1117,8 +1117,8 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size)
	return 0;
}

static int route_unicast_packet(struct sk_buff *skb,
				struct batman_if *recv_if, int hdr_size)
int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if,
			 int hdr_size)
{
	struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
	struct orig_node *orig_node;
@@ -1210,7 +1210,7 @@ int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if)

	/* packet for me */
	if (is_my_mac(unicast_packet->dest)) {
		interface_rx(recv_if->soft_iface, skb, hdr_size);
		interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size);
		return NET_RX_SUCCESS;
	}

@@ -1242,7 +1242,7 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if)
		if (!new_skb)
			return NET_RX_SUCCESS;

		interface_rx(recv_if->soft_iface, new_skb,
		interface_rx(recv_if->soft_iface, new_skb, recv_if,
			     sizeof(struct unicast_packet));
		return NET_RX_SUCCESS;
	}
@@ -1324,7 +1324,7 @@ int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if)
	add_bcast_packet_to_list(bat_priv, skb);

	/* broadcast for me */
	interface_rx(recv_if->soft_iface, skb, hdr_size);
	interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size);

	return NET_RX_SUCCESS;
}
Loading