diff --git a/mphlr.h b/mphlr.h index e3073413..2810a92d 100644 --- a/mphlr.h +++ b/mphlr.h @@ -611,7 +611,8 @@ int overlay_check_ticks(); int overlay_add_selfannouncement(); int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b); int overlay_interface_args(char *arg); -int overlay_get_nexthop(unsigned char *final_destination,unsigned char *nexthop,int *nexthoplen); +int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen, + int *interface); extern int overlay_interface_count; diff --git a/overlay.c b/overlay.c index d0e9f314..de0968f8 100644 --- a/overlay.c +++ b/overlay.c @@ -209,13 +209,13 @@ int overlay_frame_process(int interface,overlay_frame *f) if (((!ultimatelyForMe)||broadcast)&&(f->ttl>1)) { /* Yes, it is. */ - int len=0; + int len=0; if (broadcast&&(f->type==OF_TYPE_SELFANNOUNCE)) { // Don't forward broadcast self-announcement packets as that is O(n^2) with // traffic. We have other means to propagating the mesh topology information. } else { - if (overlay_get_nexthop(f->destination,f->nexthop,&len)) + if (overlay_get_nexthop(f->destination,f->nexthop,&len,&f->nexthop_interface)) return WHY("Could not find next hop for host - dropping frame"); f->ttl--; diff --git a/overlay_route.c b/overlay_route.c index d4d713da..7839928d 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -333,11 +333,30 @@ int overlay_route_init(int mb_ram) nodes that are only indirectly connected. Indeed, the two are somewhat interconnected as an indirect route may be required to get a self-announce ack back to the sender. */ -int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen) +int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen, + int *interface) { if (!overlay_neighbours) return 0; - + overlay_neighbour *neh=overlay_route_get_neighbour_structure(d,0 /* don't create if + missing */); + + if (neh) { + /* 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 + via that interface and directly addressed to the recipient. */ + bcopy(d,nexthop,SID_SIZE); + (*nexthoplen)=SID_SIZE; + + *interface=0; + for(i=1;iscores[i]>neh->scores[*interface]) *interface=i; + if (neg->scores[*interface]<1) return WHY("No open path to node"); + return 0; + } else { + /* Is not a direct neighbour */ + } return WHY("Not implemented"); } @@ -530,9 +549,10 @@ int overlay_route_make_neighbour(overlay_node *n) return 0; } -overlay_neighbour *overlay_route_get_neighbour_structure(unsigned char *packed_sid) +overlay_neighbour *overlay_route_get_neighbour_structure(unsigned char *packed_sid, + int createP) { - overlay_node *n=overlay_route_find_node(packed_sid,1 /* create if necessary */); + overlay_node *n=overlay_route_find_node(packed_sid,createP); if (!n) { WHY("Could not find node record for observed node"); return NULL; } /* Check if node is already a neighbour, or if not, make it one */