mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Finally looks like selfacknowledgement acks get sent and can be
decoded. Now to actually use them ...
This commit is contained in:
parent
b6ce25ab24
commit
78e3bfc4a3
@ -91,7 +91,7 @@ int findHlr(unsigned char *hlr,int *ofs,char *sid,char *did)
|
||||
|
||||
if ((*ofs)>=hlr_size) return 0;
|
||||
|
||||
if (debug>1) fprintf(stderr,"Searching for HLR record sid=[%s]/did=[%s]\n",sid?sid:"NULL",did?did:"NULL");
|
||||
if (debug>4) fprintf(stderr,"Searching for HLR record sid=[%s]/did=[%s]\n",sid?sid:"NULL",did?did:"NULL");
|
||||
|
||||
if (did&&did[0]) {
|
||||
/* Make packed version of DID so that we can compare faster with the DIDs in the HLR */
|
||||
@ -117,7 +117,7 @@ int findHlr(unsigned char *hlr,int *ofs,char *sid,char *did)
|
||||
|
||||
if (!record_length) return 0;
|
||||
|
||||
if (debug>1) fprintf(stderr,"Considering HLR entry @ 0x%x\n",*ofs);
|
||||
if (debug>4) fprintf(stderr,"Considering HLR entry @ 0x%x\n",*ofs);
|
||||
|
||||
records_searched++;
|
||||
|
||||
@ -160,7 +160,7 @@ int findHlr(unsigned char *hlr,int *ofs,char *sid,char *did)
|
||||
/* For each match ... */
|
||||
if (match)
|
||||
{
|
||||
if (debug>1) fprintf(stderr,"Returning HLR entry @ 0x%x\n",*ofs);
|
||||
if (debug>4) fprintf(stderr,"Returning HLR entry @ 0x%x\n",*ofs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
1
mphlr.h
1
mphlr.h
@ -787,3 +787,4 @@ int overlayServerMode();
|
||||
int overlay_payload_enqueue(int q,overlay_frame *p);
|
||||
long long overlay_time_in_ms();
|
||||
int overlay_abbreviate_lookup_sender_id();
|
||||
int ob_dump(overlay_buffer *b,char *desc);
|
||||
|
@ -240,6 +240,7 @@ int overlay_frame_process(int interface,overlay_frame *f)
|
||||
overlay_route_saw_selfannounce_ack(interface,f,now);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"Unsupported f->type=0x%x\n",f->type);
|
||||
return WHY("Support for that f->type not yet implemented");
|
||||
break;
|
||||
}
|
||||
|
@ -248,6 +248,11 @@ int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs)
|
||||
if (!in) return WHY("in==NULL");
|
||||
if (in[0]<0x10) return WHY("Invalid address - 0x00-0x0f are reserved prefixes.");
|
||||
|
||||
/* Try repeating previous address */
|
||||
for(i=0;i<SID_SIZE;i++) if (in[i]!=overlay_abbreviate_previous_address.b[i]) break;
|
||||
if (i==SID_SIZE) { out[(*ofs)++]=OA_CODE_PREVIOUS; return 0; } else
|
||||
WHY("this address does not match previous sender");
|
||||
|
||||
if (!abbrs) {
|
||||
// Abbreviation table not setup, so allocate it.
|
||||
// Epoch starts at zero.
|
||||
@ -269,9 +274,12 @@ int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs)
|
||||
XXX If we do, we need a way to indicate a reference to an old epoch */
|
||||
for(i=0;i<2;i++)
|
||||
if (abbrs->byfirstbyte[in[0]][i])
|
||||
{ if (!overlay_abbreviate_try_byindex(in,out,ofs,abbrs->byfirstbyte[in[0]][i]))
|
||||
return 0; }
|
||||
{
|
||||
if (0) { if (!overlay_abbreviate_try_byindex(in,out,ofs,abbrs->byfirstbyte[in[0]][i]))
|
||||
return 0; } else WHY("Abbreviation by index temporarily disabled to simplify development");
|
||||
}
|
||||
else break;
|
||||
|
||||
if (i<2&&abbrs->next_free) {
|
||||
// There is a spare slot to abbreviate this address by storing it in an index if we
|
||||
// wish. So let's store it, then send the full address along with the newly allocated
|
||||
@ -282,7 +290,7 @@ int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs)
|
||||
abbrs->byfirstbyte[in[0]][i]=abbrs->next_free;
|
||||
|
||||
/* Write address out with index code */
|
||||
out[(*ofs)++]=0x08;
|
||||
out[(*ofs)++]=OA_CODE_FULL_INDEX1;
|
||||
bcopy(in,&out[(*ofs)],SID_SIZE);
|
||||
(*ofs)+=SID_SIZE;
|
||||
out[(*ofs)++]=abbrs->next_free;
|
||||
@ -298,7 +306,7 @@ int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs)
|
||||
right as an simple initial policy. */
|
||||
if (wasInCachedP) {
|
||||
/* Prefix addresses that have been seen recently */
|
||||
out[(*ofs)++]=0x06;
|
||||
out[(*ofs)++]=OA_CODE_PREFIX7;
|
||||
bcopy(in,&out[(*ofs)],7);
|
||||
(*ofs)+=7;
|
||||
return 0;
|
||||
@ -330,6 +338,7 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
|
||||
out,ofs,OVERLAY_SENDER_PREFIX_LENGTH,0);
|
||||
(*inofs)++;
|
||||
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
|
||||
(*inofs)++;
|
||||
return r;
|
||||
case OA_CODE_PREVIOUS: /* Same as last address */
|
||||
(*inofs)++;
|
||||
@ -438,7 +447,6 @@ int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *of
|
||||
for(i=0;i<SID_SIZE;i++) fprintf(stderr,"%02x",cache->sids[index].b[i]);
|
||||
fprintf(stderr,"\n");
|
||||
|
||||
fprintf(stderr,"Copying cache entry to %p[%d]\n",out,*ofs);
|
||||
bcopy(&cache->sids[index].b[0],&out[(*ofs)],SID_SIZE);
|
||||
(*ofs)+=SID_SIZE;
|
||||
if (index_bytes) {
|
||||
|
@ -203,9 +203,9 @@ int asprintable(int c)
|
||||
return c;
|
||||
}
|
||||
|
||||
int ob_dump(overlay_buffer *b)
|
||||
int ob_dump(overlay_buffer *b,char *desc)
|
||||
{
|
||||
fprintf(stderr,"Dumping overlay_buffer at %p : length=%d\n",b,b->length);
|
||||
fprintf(stderr,"Dumping overlay_buffer '%s' at %p : length=%d\n",desc,b,b->length);
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<b->length;i+=16)
|
||||
|
@ -89,6 +89,9 @@ int packetOkOverlay(int interface,unsigned char *packet,int len,unsigned char *t
|
||||
f.type=packet[ofs]&OF_TYPE_BITS;
|
||||
f.modifiers=packet[ofs]&OF_MODIFIER_BITS;
|
||||
|
||||
fprintf(stderr,"f.type=0x%02x, f.modifiers=0x%02x, ofs=%d\n",
|
||||
f.type,f.modifiers,ofs);
|
||||
|
||||
switch(packet[ofs]&OF_TYPE_BITS)
|
||||
{
|
||||
case OF_TYPE_EXTENDED20:
|
||||
@ -125,6 +128,7 @@ int packetOkOverlay(int interface,unsigned char *packet,int len,unsigned char *t
|
||||
|
||||
/* Decode length of remainder of frame */
|
||||
f.rfs=rfs_decode(packet,&ofs);
|
||||
fprintf(stderr,"f.rfs=%d, ofs=%d\n",f.rfs,ofs);
|
||||
|
||||
if (!f.rfs) {
|
||||
/* Zero length -- assume we fell off the end of the packet */
|
||||
@ -145,6 +149,9 @@ int packetOkOverlay(int interface,unsigned char *packet,int len,unsigned char *t
|
||||
if (f.bytecount<0) {
|
||||
f.bytecount=0;
|
||||
WHY("negative residual byte count after extracting addresses from frame header");
|
||||
fprintf(stderr,"f.rfs=%d, offset=%d, ofs=%d\n",
|
||||
f.rfs,offset,ofs);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Finally process the frame */
|
||||
@ -223,7 +230,7 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
|
||||
/* Add space for Remaining Frame Size field. This will always be a single byte
|
||||
for self-announcments as they are always <256 bytes. */
|
||||
c=1+1+(send_prefix?(1+7):SID_SIZE)+4+4;
|
||||
c=1+1+(send_prefix?(1+7):SID_SIZE)+4+4+1;
|
||||
if (ob_append_bytes(b,&c,1))
|
||||
return WHY("ob_append_bytes() could not add RFS for self-announcement frame");
|
||||
|
||||
@ -270,6 +277,8 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
if (ob_append_byte(b,interface))
|
||||
return WHY("ob_append_int() could not add interface number to self-announcement");
|
||||
|
||||
ob_dump(b,"self announcement");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -15,17 +15,20 @@ int op_append_type(overlay_buffer *headers,overlay_frame *p)
|
||||
{
|
||||
case OF_TYPE_FLAG_NORMAL:
|
||||
c[0]=p->type|p->modifiers;
|
||||
fprintf(stderr,"type resolves to %02x\n",c[0]);
|
||||
if (ob_append_bytes(headers,c,1)) return -1;
|
||||
break;
|
||||
case OF_TYPE_FLAG_E12:
|
||||
c[0]=(p->type&OF_MODIFIER_BITS)|OF_TYPE_EXTENDED12;
|
||||
c[1]=(p->type>>4)&0xff;
|
||||
fprintf(stderr,"type resolves to %02x%02x\n",c[0],c[1]);
|
||||
if (ob_append_bytes(headers,c,2)) return -1;
|
||||
break;
|
||||
case OF_TYPE_FLAG_E20:
|
||||
c[0]=(p->type&OF_MODIFIER_BITS)|OF_TYPE_EXTENDED20;
|
||||
c[1]=(p->type>>4)&0xff;
|
||||
c[2]=(p->type>>12)&0xff;
|
||||
fprintf(stderr,"type resolves to %02x%02x%02x\n",c[0],c[1],c[2]);
|
||||
if (ob_append_bytes(headers,c,3)) return -1;
|
||||
break;
|
||||
default:
|
||||
@ -44,7 +47,6 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
Will pick a next hop if one has not been chosen.
|
||||
*/
|
||||
|
||||
unsigned char c[64];
|
||||
int nexthoplen=0;
|
||||
|
||||
overlay_buffer *headers=ob_new(256);
|
||||
@ -70,10 +72,12 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
/* XXX Write fields in correct order */
|
||||
|
||||
/* Write out type field byte(s) */
|
||||
if (op_append_type(headers,p)) fail++;
|
||||
fprintf(stderr,">>>>> packet length before appending frame type = %d\n",b->length);
|
||||
if (!fail) if (op_append_type(headers,p)) fail++;
|
||||
|
||||
/* Write out TTL */
|
||||
c[0]=p->ttl; if (ob_append_bytes(headers,c,1)) fail++;
|
||||
fprintf(stderr,">>>>> packet length before appending TTL = %d\n",b->length);
|
||||
if (!fail) if (ob_append_byte(headers,p->ttl)) fail++;
|
||||
|
||||
/* Length. This is the fun part, because we cannot calculate how many bytes we need until
|
||||
we have abbreviated the addresses, and the length encoding we use varies according to the
|
||||
@ -81,22 +85,32 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
we rely on context for abbreviating the addresses. So we write it initially and then patch it
|
||||
after.
|
||||
*/
|
||||
int max_len=((SID_SIZE+3)*3+headers->length+p->payload->length);
|
||||
ob_append_rfs(b,max_len);
|
||||
|
||||
int addrs_len=b->length;
|
||||
|
||||
/* Write out addresses as abbreviated as possible */
|
||||
overlay_abbreviate_append_address(b,p->nexthop);
|
||||
overlay_abbreviate_set_most_recent_address(p->nexthop);
|
||||
overlay_abbreviate_append_address(b,p->destination);
|
||||
overlay_abbreviate_set_most_recent_address(p->destination);
|
||||
overlay_abbreviate_append_address(b,p->source);
|
||||
overlay_abbreviate_set_most_recent_address(p->source);
|
||||
|
||||
addrs_len=b->length-addrs_len;
|
||||
int actual_len=addrs_len+p->payload->length;
|
||||
ob_patch_rfs(b,actual_len);
|
||||
if (!fail) {
|
||||
int max_len=((SID_SIZE+3)*3+headers->length+p->payload->length);
|
||||
ob_dump(headers,"before append rfs");
|
||||
ob_append_rfs(headers,max_len);
|
||||
|
||||
int addrs_start=headers->length;
|
||||
|
||||
/* Write out addresses as abbreviated as possible */
|
||||
fprintf(stderr,">>>>> packet length before appending nexthop = %d\n",b->length);
|
||||
overlay_abbreviate_append_address(headers,p->nexthop);
|
||||
overlay_abbreviate_set_most_recent_address(p->nexthop);
|
||||
fprintf(stderr,">>>>> packet length before appending destination = %d\n",b->length);
|
||||
overlay_abbreviate_append_address(headers,p->destination);
|
||||
overlay_abbreviate_set_most_recent_address(p->destination);
|
||||
fprintf(stderr,">>>>> packet length before appending source = %d\n",b->length);
|
||||
overlay_abbreviate_append_address(headers,p->source);
|
||||
overlay_abbreviate_set_most_recent_address(p->source);
|
||||
|
||||
int addrs_len=headers->length-addrs_start;
|
||||
int actual_len=addrs_len+p->payload->length;
|
||||
fprintf(stderr,"Actual RFS=%d\n",actual_len);
|
||||
ob_patch_rfs(headers,actual_len);
|
||||
ob_dump(headers,"after patch rfs");
|
||||
}
|
||||
ob_dump(b,"Existing packet");
|
||||
ob_dump(headers,"Payload headers");
|
||||
|
||||
if (fail) {
|
||||
ob_free(headers);
|
||||
@ -112,12 +126,14 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
|
||||
/* Package up headers and payload */
|
||||
ob_checkpoint(b);
|
||||
if (ob_append_short(b,0x1000|(p->payload->length+headers->length)))
|
||||
{ fail++; WHY("could not append version and length bytes"); }
|
||||
if (ob_append_bytes(b,headers->bytes,headers->length))
|
||||
{ fail++; WHY("could not append header"); }
|
||||
fprintf(stderr,">>>>> packet length AFTER appending headers = %d\n",b->length);
|
||||
if (ob_append_bytes(b,p->payload->bytes,p->payload->length))
|
||||
{ fail++; WHY("could not append payload"); }
|
||||
fprintf(stderr,">>>>> packet length after appending PAYLOAD = %d\n",b->length);
|
||||
|
||||
ob_dump(b,"Appended packet");
|
||||
|
||||
/* XXX SIGN &/or ENCRYPT */
|
||||
|
||||
|
@ -524,7 +524,8 @@ int overlay_route_ack_selfannounce(overlay_frame *f,overlay_neighbour *n)
|
||||
|
||||
/* XXX Temporary to stop memory leaks while writing the rest of this function */
|
||||
|
||||
return WHY("Not implemented");
|
||||
WHY("incomplete");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_route_make_neighbour(overlay_node *n)
|
||||
|
Loading…
Reference in New Issue
Block a user