From ddc17434c4f1b48471171ca69de8acc0d6a4db2b Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 30 Jul 2012 18:35:28 +0930 Subject: [PATCH] Fix next-hop logic for case of no interfaces up --- overlay_interface.c | 4 ++-- overlay_route.c | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/overlay_interface.c b/overlay_interface.c index cc2b4dd3..33eef34b 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -654,7 +654,7 @@ void overlay_interface_discover(struct sched_ent *alarm){ int detect_real_interfaces = 0; /* Mark all UP interfaces as DETECTING, so we can tell which interfaces are new, and which are dead */ - for(i = 0; i < overlay_interface_count; i++) + for (i = 0; i < overlay_interface_count; i++) if (overlay_interfaces[i].state==INTERFACE_STATE_UP) overlay_interfaces[i].state=INTERFACE_STATE_DETECTING; @@ -665,7 +665,7 @@ void overlay_interface_discover(struct sched_ent *alarm){ continue; } - for(i = 0; i < overlay_interface_count; i++) + for (i = 0; i < overlay_interface_count; i++) if (!strcasecmp(overlay_interfaces[i].name,r->namespec)){ if (overlay_interfaces[i].state==INTERFACE_STATE_DETECTING) overlay_interfaces[i].state=INTERFACE_STATE_UP; diff --git a/overlay_route.c b/overlay_route.c index 51fe28d4..a07fbc85 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -398,28 +398,29 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *interface) long long now = gettime_ms(); overlay_neighbour *direct_neighbour=NULL; - - if (n->neighbour_id){ + + if (n->neighbour_id) { direct_neighbour = &overlay_neighbours[n->neighbour_id]; overlay_route_recalc_neighbour_metrics(direct_neighbour, now); /* Is a direct neighbour. So in the absence of any better indirect route, we pick the interface that - we can hear this neighbour on the most reliably, and then send the frame + we can hear this neighbour on the most reliably, and then send the frame via that interface and directly addressed to the recipient. */ - - *interface=0; - for(i=1;iscores[i]>direct_neighbour->scores[*interface]) *interface=i; + int ifn = -1; + for (i = 0; i < overlay_interface_count; ++i) { + if ( overlay_interfaces[i].state == INTERFACE_STATE_UP + && (ifn == -1 || direct_neighbour->scores[i] > direct_neighbour->scores[ifn])) + ifn = i; } - if (direct_neighbour->scores[*interface]>0) { - bcopy(d,nexthop,SID_SIZE); - if (0) DEBUGF("nexthop is %s",alloca_tohex_sid(nexthop)); + if (ifn != -1 && direct_neighbour->scores[ifn] > 0) { + *interface = ifn; + bcopy(d, nexthop, SID_SIZE); + if (debug&DEBUG_OVERLAYROUTING) + DEBUGF("nexthop is %s", alloca_tohex_sid(nexthop)); return 0; } - // otherwise fall through } - + /* Is not a direct neighbour. XXX - Very simplistic for now. */ int o;