The following commit has been merged in the master branch: commit 1e94b41f4bc9d224d89a4bff2705e8f92db8ddb6 Author: marek marek@45894c77-fb22-0410-b583-ff6e7d5dbf6c Date: Wed Nov 4 23:12:34 2009 +0000
[batman-adv] avoid temporary routing loops
git-svn-id: http://downloads.open-mesh.net/svn/batman/trunk/batman-adv-kernelland@1460 45894c77-fb22-0410-b583-ff6e7d5dbf6c
diff --git a/routing.c b/routing.c index c317998..a5a7c61 100644 --- a/routing.c +++ b/routing.c @@ -344,18 +344,28 @@ static void update_orig(struct orig_node *orig_node, struct ethhdr *ethhdr, stru
tmp_hna_buff_len = (hna_buff_len > batman_packet->num_hna * ETH_ALEN ? batman_packet->num_hna * ETH_ALEN : hna_buff_len);
- /** - * if we got have a better tq value via this neighbour or - * same tq value but the link is more symetric change the next hop - * router - */ - if ((orig_node->router != neigh_node) && ((!orig_node->router) || - (neigh_node->tq_avg > orig_node->router->tq_avg) || - ((neigh_node->tq_avg == orig_node->router->tq_avg) && - (neigh_node->orig_node->bcast_own_sum[if_incoming->if_num] > orig_node->router->orig_node->bcast_own_sum[if_incoming->if_num])))) - update_routes(orig_node, neigh_node, hna_buff, tmp_hna_buff_len); - else - update_routes(orig_node, orig_node->router, hna_buff, tmp_hna_buff_len); + /* if this neighbor already is our next hop there is nothing to change */ + if (orig_node->router == neigh_node) + goto update_hna; + + /* if this neighbor does not offer a better TQ we won't consider it */ + if ((orig_node->router) && + (orig_node->router->tq_avg > neigh_node->tq_avg)) + goto update_hna; + + /* if the TQ is the same and the link not more symetric we won't consider it either */ + if ((orig_node->router) && + ((neigh_node->tq_avg == orig_node->router->tq_avg) && + (orig_node->router->orig_node->bcast_own_sum[if_incoming->if_num] > + neigh_node->orig_node->bcast_own_sum[if_incoming->if_num]))) + goto update_hna; + + update_routes(orig_node, neigh_node, hna_buff, tmp_hna_buff_len); + return; + +update_hna: + update_routes(orig_node, orig_node->router, hna_buff, tmp_hna_buff_len); + return; }
static char count_real_packets(struct ethhdr *ethhdr, struct batman_packet *batman_packet, struct batman_if *if_incoming) @@ -402,7 +412,7 @@ void receive_bat_packet(struct ethhdr *ethhdr, struct batman_packet *batman_pack
/* Silently drop when the batman packet is actually not a correct packet. * - * This might happen if a packet is padded (e.g. Ethernet has a + * This might happen if a packet is padded (e.g. Ethernet has a * minimum frame length of 64 byte) and the aggregation interprets * it as an additional length. * @@ -491,6 +501,15 @@ void receive_bat_packet(struct ethhdr *ethhdr, struct batman_packet *batman_pack if (orig_node == NULL) return;
+ /* avoid temporary routing loops */ + if ((orig_node->router) && (orig_node->router->orig_node->router) && + (compare_orig(orig_node->router->addr, batman_packet->prev_sender)) && + !(compare_orig(batman_packet->orig, batman_packet->prev_sender)) && + (compare_orig(orig_node->router->addr, orig_node->router->orig_node->router->addr))) { + debug_log(LOG_TYPE_BATMAN, "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %s) \n", neigh_str); + return; + } + /* if sender is a direct neighbor the sender mac equals originator mac */ orig_neigh_node = (is_single_hop_neigh ? orig_node : get_orig_node(ethhdr->h_source)); if (orig_neigh_node == NULL)