mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-07 11:08:36 +00:00
More work on parsing overlay frames. Now has bare bones to think about
forwarding frames. routing is still not implemented, so it doesn't do anything yet, but it does try.
This commit is contained in:
parent
4396570745
commit
62a7a65fd6
8
mphlr.h
8
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);
|
||||
|
59
overlay.c
59
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;i<SID_SIZE;i++) fprintf(stderr,"%02x",f->nexthop[i]);
|
||||
fprintf(stderr,"\n");
|
||||
@ -154,22 +164,51 @@ int overlay_frame_process(int interface,overlay_frame *f)
|
||||
for(i=0;i<SID_SIZE;i++) if (f->nexthop[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;i<SID_SIZE;i++) fprintf(stderr,"%02x",f->destination[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;i<SID_SIZE;i++) fprintf(stderr,"%02x",f->source[i]); else fprintf(stderr,"???");
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
|
||||
if (f->destination_address_status==OA_RESOLVED) {
|
||||
for(i=0;i<SID_SIZE;i++) if (f->destination[i]!=0xff) break;
|
||||
if (i==SID_SIZE) { ultimatelyForMe=1; broadcast=1; }
|
||||
for(i=0;i<SID_SIZE;i++) if (f->destination[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:
|
||||
|
@ -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;i<SID_SIZE;i++) fprintf(stderr,"%02x",cache->sids[index].b[i]);
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user