diff --git a/mphlr.h b/mphlr.h index 56135f14..52588902 100644 --- a/mphlr.h +++ b/mphlr.h @@ -512,8 +512,8 @@ typedef struct overlay_payload { struct overlay_payload *next; /* We allows 256 bit addresses and 32bit port numbers */ - char src[SIDDIDFIELD_LEN]; - char dst[SIDDIDFIELD_LEN]; + unsigned char src[SIDDIDFIELD_LEN]; + unsigned char dst[SIDDIDFIELD_LEN]; int srcPort; int dstPort; @@ -595,7 +595,7 @@ int overlay_check_ticks(); int overlay_add_selfannouncement(); int overlay_payload_package_fmt1(overlay_payload *p,overlay_buffer *b); int overlay_interface_args(char *arg); -int overlay_get_nexthop(overlay_payload *p,unsigned char *nexthop,int *nexthoplen); +int overlay_get_nexthop(unsigned char *final_destination,unsigned char *nexthop,int *nexthoplen); extern int overlay_interface_count; @@ -649,7 +649,7 @@ extern int overlay_interface_count; #define OVERLAY_ADDRESS_CACHE_SIZE 1024 int overlay_abbreviate_address(unsigned char *in,char *out,int *ofs); int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs,unsigned char *out,int *ofs); -int overlay_address_cache_address(unsigned char *sid); +int overlay_abbreviate_cache_address(unsigned char *sid); int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *ofs, int prefix_bytes,int index_bytes); int overlay_abbreviate_remember_index(int index_byte_count,unsigned char *in,unsigned char *index_bytes); diff --git a/overlay.c b/overlay.c index 07f9cad9..7f773ae0 100644 --- a/overlay.c +++ b/overlay.c @@ -64,6 +64,14 @@ int overlayServerMode() int i; fd_set read_fds; int maxfd=-1; + + /* Add all local SIDs to our cache */ + int ofs=0; + while(findHlr(hlr,&ofs,NULL,NULL)) { + overlay_abbreviate_cache_address(&hlr[ofs+4]); + if (nextHlr(hlr,&ofs)) break; + } + while(1) { /* Work out how long we can wait before we need to tick */ long long ms=overlay_time_until_next_tick(); @@ -145,6 +153,8 @@ int overlay_frame_process(int interface,overlay_frame *f) /* Okay, nexthop is valid, so let's see if it is us */ int forMe=0,i; + int ultimatelyForMe=0; + int broadcast=0; fprintf(stderr,"Nexthop for this frame is: "); for(i=0;inexthop[i]); fprintf(stderr,"\n"); @@ -154,22 +164,51 @@ int overlay_frame_process(int interface,overlay_frame *f) for(i=0;inexthop[i]!=hlr[4+i]) break; if (i==SID_SIZE) forMe=1; - fprintf(stderr,"This frame is%s for me.\n",forMe?"":" not"); - - /* Not for us? Then just ignore it */ - if (!forMe) return 0; - - switch(f->type) - { - case OF_TYPE_SELFANNOUNCE: - if (overlay_frame_resolve_addresses(interface,f)) - return WHY("Failed to resolve destination and sender addresses in frame"); + if (forMe) { + /* It's for us, so resolve the addresses */ + if (overlay_frame_resolve_addresses(interface,f)) + return WHY("Failed to resolve destination and sender addresses in frame"); + if (debug&4) { fprintf(stderr,"Destination for this frame is (resolve code=%d): ",f->destination_address_status); if (f->destination_address_status==OA_RESOLVED) for(i=0;idestination[i]); else fprintf(stderr,"???"); fprintf(stderr,"\n"); fprintf(stderr,"Source for this frame is (resolve code=%d): ",f->source_address_status); if (f->source_address_status==OA_RESOLVED) for(i=0;isource[i]); else fprintf(stderr,"???"); fprintf(stderr,"\n"); + } + + if (f->destination_address_status==OA_RESOLVED) { + for(i=0;idestination[i]!=0xff) break; + if (i==SID_SIZE) { ultimatelyForMe=1; broadcast=1; } + for(i=0;idestination[i]!=hlr[4+i]) break; + if (i==SID_SIZE) ultimatelyForMe=1; + } + } + + fprintf(stderr,"This frame does%s have me listed as next hop.\n",forMe?"":" not"); + fprintf(stderr,"This frame is%s for me.\n",ultimatelyForMe?"":" not"); + + /* Not for us? Then just ignore it */ + if (!forMe) return 0; + + /* Is this a frame we have to forward on? */ + if (((!ultimatelyForMe)||broadcast)&&(f->ttl>1)) + { + /* Yes, it is. */ + int len=0; + if (overlay_get_nexthop(f->destination,f->nexthop,&len)) + return WHY("Could not find next hop for host - dropping frame"); + f->ttl--; + /* Queue frame for dispatch */ + + return WHY("forwarding of frame not implemented"); + } + + switch(f->type) + { + case OF_TYPE_SELFANNOUNCE: + + break; default: diff --git a/overlay_abbreviations.c b/overlay_abbreviations.c index fb90225a..b475ffc3 100644 --- a/overlay_abbreviations.c +++ b/overlay_abbreviations.c @@ -179,6 +179,12 @@ int overlay_abbreviate_cache_address(unsigned char *sid) /* Not yet in cache, so store it */ bcopy(sid,&cache->sids[index].b[0],SID_SIZE); + if (debug&4) { + fprintf(stderr,"Cached address "); + int i; + for(i=0;isids[index].b[i]); + fprintf(stderr,"\n"); + } return 0; } diff --git a/overlay_packetformats.c b/overlay_packetformats.c index 2f585b7b..fb24a998 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -164,7 +164,7 @@ int overlay_frame_resolve_addresses(int interface,overlay_frame *f) alen=0; f->source_address_status=overlay_abbreviate_expand_address(interface,f->bytes,&offset,f->source,&alen); f->payload=&f->bytes[offset]; - f->payloadlength=f->bytes-offset; + f->payloadlength=f->bytecount-offset; if (f->payloadlength<0) return WHY("Abbreviated ddresses run past end of packet"); return 0; diff --git a/overlay_payload.c b/overlay_payload.c index 6393f006..cbb6ec7a 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -25,7 +25,7 @@ int overlay_payload_package_fmt1(overlay_payload *p,overlay_buffer *b) /* Build header */ int fail=0; - if (overlay_get_nexthop(p,nexthop,&nexthoplen)) fail++; + if (overlay_get_nexthop((unsigned char *)p->dst,nexthop,&nexthoplen)) fail++; if (ob_append_bytes(headers,nexthop,nexthoplen)) fail++; /* XXX Can use shorter fields for different address types, and if we know that the next hop diff --git a/overlay_route.c b/overlay_route.c index 13525e28..12032420 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -1,7 +1,6 @@ #include "mphlr.h" - -int overlay_get_nexthop(overlay_payload *p,unsigned char *nexthop,int *nexthoplen) +int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen) { return WHY("Not implemented"); }