LAN loop avoidance
Hi folks,
recently, I came across a nasty issue which hasn't been solved yet. The problem begins to show up when you try to connect multiple batman-adv mesh node to the same LAN network. If batman-adv is bridged into the LAN and the nodes have a decent connection to each other you are about to create an ethernet loop which will take out your entire network.
A simple visualization of the loop:
node1 <-- LAN --> node2
| | wifi <-- mesh --> wifi
Let's assume a packet from the LAN arrives at node1 which then floods the mesh with that new packet. Node2 receives the packet via the mesh and forwards it to the LAN where node1 receives it ...
If there wasn't the LAN connection this would not happen because batman-adv provides a flood/loop protection inside the batman header but as soon as the packet gets bridged this information is stripped from the packet. Every batman node connected to the LAN will think: Hey, it is a new packet!
A common solution to avoid bridge loops is to deploy protocols like STP or one of its derivates. STP would detect the loop and close ports to avoid it. Running STP over the mesh is not really what we want as STP has no clue about the link qualities and who wants to run a spanning tree over lossy links ?
So, batman-adv needs it own mechanism to detect other batman nodes connected to the same LAN and then close the appropriate ports. As a followup to this mail I propose a patch which does exactly that. It will detect OGMs that come in via the batX interface and interprets them as "port announcements". Internally, it keeps a list of all LAN neighbors and selects the one with the smallest mac address as gateway to the LAN. All traffic that should go to the LAN is forwarded to this node. Traffic from the LAN is simply dropped - only the smallest mac node will forward it to the mesh.
Simple steps to see it in action:
* add your wifi interface
-> batctl if add wlan0
* create a bridge for bat0 and your lan
-> brctl addbr br-lan
-> brctl addif br-lan eth0
-> brctl addif br-lan bat0
* activate batman on the lan
-> batctl if add br-lan
The patch can also deal with vlans on top of batX and offers a list of LAN neighbors via debugfs (batctl support is yet to come).
Feedback is welcome! :-)
Regards,
Marek
PATCH 1/1 batman-adv: softif lan loop avoidance
--- batman-adv/bat_debugfs.c | 9 ++ batman-adv/main.c | 1 + batman-adv/main.h | 2 + batman-adv/originator.c | 3 + batman-adv/routing.c | 12 +- batman-adv/routing.h | 2 + batman-adv/soft-interface.c | 273 +++++++++++++++++++++++++++++++++++++++++-- batman-adv/soft-interface.h | 5 +- batman-adv/types.h | 10 ++ 9 files changed, 300 insertions(+), 17 deletions(-)
batman-adv/bat_debugfs.c +9 -0
@@ -29,6 +29,7 @@#include "hard-interface.h" #include "gateway_common.h" #include "gateway_client.h" +#include "soft-interface.h" #include "vis.h" #include "icmp_socket.h" #include "compat.h"
@@ -234,6 +235,12 @@ static int gateways_open(struct inode *inode, struct file *file)return single_open (file, gw_client_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;
@@ -271,6 +278,7 @@ struct bat_debuginfo bat_debuginfo_##_name = { \ static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_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);
@@ -278,6 +286,7 @@ static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);static struct bat_debuginfo *mesh_debuginfos[] = { &bat_debuginfo_originators, &bat_debuginfo_gateways, + &bat_debuginfo_softif_neigh, &bat_debuginfo_transtable_global, &bat_debuginfo_transtable_local, &bat_debuginfo_vis_data,
batman-adv/main.c +1 -0
@@ -93,6 +93,7 @@ int mesh_init(struct net_device *soft_iface)INIT_HLIST_HEAD (&bat_priv->forw_bat_list);INIT_HLIST_HEAD (&bat_priv->forw_bcast_list);INIT_HLIST_HEAD (&bat_priv->gw_list); +INIT_HLIST_HEAD (&bat_priv->softif_neigh_list);if (originator_init (bat_priv) <1 ) goto err;
batman-adv/main.h +2 -0
@@ -72,6 +72,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 */
batman-adv/originator.c +3 -0
@@ -30,6 +30,7 @@#include "gateway_client.h" #include "hard-interface.h" #include "unicast.h" +#include "soft-interface.h" static void purge_orig (struct work_struct *work);
@@ -292,6 +293,8 @@ static void _purge_orig(struct bat_priv *bat_priv)gw_node_purge_deleted (bat_priv);gw_election (bat_priv); + +softif_neigh_purge (bat_priv); }static void purge_orig (struct work_struct *work)
batman-adv/routing.c +6 -6
@@ -1131,8 +1131,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;
@@ -1147,7 +1147,7 @@ static int route_unicast_packet(struct sk_buff *skb,/* 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 ; }
@@ -1207,7 +1207,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 ; }
@@ -1268,7 +1268,7 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if)if (!skb)return NET_RX_DROP ; -interface_rx (recv_if->soft_iface, skb, hdr_size); +interface_rx (recv_if->soft_iface, skb, recv_if, hdr_size);return NET_RX_SUCCESS ; }
@@ -1349,7 +1349,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 ; }
batman-adv/routing.h +2 -0
@@ -32,6 +32,8 @@ void receive_bat_packet(struct ethhdr *ethhdr,void update_routes (struct bat_priv *bat_priv,struct orig_node *orig_node,struct neigh_node *neigh_node,unsigned char *hna_buff,int hna_buff_len); +int route_unicast_packet (struct sk_buff *skb,struct batman_if *recv_if, +int hdr_size);int recv_icmp_packet (struct sk_buff *skb,struct batman_if *recv_if);int recv_unicast_packet (struct sk_buff *skb,struct batman_if *recv_if);int recv_ucast_frag_packet (struct sk_buff *skb,struct batman_if *recv_if);
batman-adv/soft-interface.c +263 -10
332 lines not on this page · raw message
batman-adv/soft-interface.h +4 -1
@@ -23,9 +23,12 @@#define _NET_BATMAN_ADV_SOFT_INTERFACE_H_int my_skb_head_push (struct sk_buff *skb,unsigned int len); +int softif_neigh_seq_print_text (struct seq_file *seq,void *offset); +void softif_neigh_purge (struct bat_priv *bat_priv);int interface_tx (struct sk_buff *skb,struct net_device *soft_iface);void interface_rx (struct net_device *soft_iface, -struct sk_buff *skb,int hdr_size); +struct sk_buff *skb,struct batman_if *recv_if, +int hdr_size);struct net_device *softif_create (char *name);void softif_destroy (struct net_device *soft_iface);
batman-adv/types.h +10 -0
@@ -134,6 +134,8 @@ struct bat_priv {atomic_t bcast_queue_left;atomic_t batman_queue_left;char num_ifaces; +struct hlist_head softif_neigh_list; +struct softif_neigh *softif_neigh;struct debug_log *debug_log;struct batman_if *primary_if;struct kobject *mesh_obj;
@@ -253,4 +255,12 @@ struct recvlist_node { uint8_t mac[ETH_ALEN]; }; +struct softif_neigh { +struct hlist_node list; +uint8_t addr[ETH_ALEN ]; +unsigned long last_seen; +short vid; +struct rcu_head rcu; +}; +#endif /* _NET_BATMAN_ADV_TYPES_H_ */
Signature · 1 line
1.7.1
Re: [B.A.T.M.A.N.] [PATCH] batman-adv: softif lan loop avoidance
To make it short: please check your code againstDocumentation/RCU/checklist.txt
The new patch adds different problems I tried to address in other patches posted by me today. There are also new parts which leaks information outside rcu_read_lock... so parts which aren't yet addressed by patches for other subsystems of batman-adv.
Best regards,
Sven