Author: marek Date: 2009-11-04 23:12:34 +0000 (Wed, 04 Nov 2009) New Revision: 1460
Modified: trunk/batman-adv-kernelland/routing.c Log: [batman-adv] avoid temporary routing loops
Modified: trunk/batman-adv-kernelland/routing.c =================================================================== --- trunk/batman-adv-kernelland/routing.c 2009-10-26 20:48:30 UTC (rev 1459) +++ trunk/batman-adv-kernelland/routing.c 2009-11-04 23:12:34 UTC (rev 1460) @@ -344,18 +344,28 @@
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 @@
/* 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 @@ 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)