Thinned out debug messages and fixed SID generation bug to make sure

that it always generates a valid SID, i.e., not beginning with 0.
This commit is contained in:
gardners 2011-09-07 21:50:20 +09:30
parent 78e3bfc4a3
commit 144f3ee4b1
5 changed files with 36 additions and 37 deletions

@ -179,6 +179,8 @@ int createHlr(char *did,char *sid) {
/* Generate random SID */
for(i=0;i<64;i++) sid[i]=hexdigit[random()&0xf]; sid[64]=0;
/* But make sure first digit is non-zero as required by the overlay mesh */
while(sid[0]=='0') sid[i]=hexdigit[random()&0xf];
if (debug>1) fprintf(stderr,"Creating new HLR entry with sid %s\n",sid);
/* Find first free byte of HLR */

@ -250,8 +250,7 @@ int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs)
/* 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 (i==SID_SIZE) { out[(*ofs)++]=OA_CODE_PREVIOUS; return 0; }
if (!abbrs) {
// Abbreviation table not setup, so allocate it.
@ -322,7 +321,7 @@ int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs)
int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs,unsigned char *out,int *ofs)
{
int bytes=0,r;
fprintf(stderr,"Address first byte/abbreviation code=%02x (input offset=%d)\n",in[*inofs],*inofs);
if (debug>3) fprintf(stderr,"Address first byte/abbreviation code=%02x (input offset=%d)\n",in[*inofs],*inofs);
switch(in[*inofs])
{
case OA_CODE_00: case OA_CODE_02: case OA_CODE_04: case OA_CODE_0C:
@ -426,9 +425,11 @@ int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *of
int index=((in[0]<<16)|(in[0]<<8)|in[2])>>cache->shift;
int i;
fprintf(stderr,"Looking in cache slot #%d for: ",index);
for(i=0;i<prefix_bytes;i++) fprintf(stderr,"%02x",in[i]);
fprintf(stderr,"*\n");
if (debug>3) {
fprintf(stderr,"Looking in cache slot #%d for: ",index);
for(i=0;i<prefix_bytes;i++) fprintf(stderr,"%02x",in[i]);
fprintf(stderr,"*\n");
}
/* So is it there? */
if (memcmp(in,&cache->sids[index].b[0],prefix_bytes))
@ -442,10 +443,12 @@ int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *of
colliding prefixes and ask the sender to resolve them for us, or better yet dynamically
size the prefix length based on whether any given short prefix has collided */
/* It is here, so let's return it */
fprintf(stderr,"I think I looked up the following: ");
for(i=0;i<SID_SIZE;i++) fprintf(stderr,"%02x",cache->sids[index].b[i]);
fprintf(stderr,"\n");
if (debug>3) {
/* It is here, so let's return it */
fprintf(stderr,"I think I looked up the following: ");
for(i=0;i<SID_SIZE;i++) fprintf(stderr,"%02x",cache->sids[index].b[i]);
fprintf(stderr,"\n");
}
bcopy(&cache->sids[index].b[0],&out[(*ofs)],SID_SIZE);
(*ofs)+=SID_SIZE;

@ -89,8 +89,8 @@ 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);
if (debug>3) fprintf(stderr,"f.type=0x%02x, f.modifiers=0x%02x, ofs=%d\n",
f.type,f.modifiers,ofs);
switch(packet[ofs]&OF_TYPE_BITS)
{
@ -128,7 +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 (debug>3) 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 */
@ -149,8 +149,8 @@ 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);
if (debug>3) fprintf(stderr,"f.rfs=%d, offset=%d, ofs=%d\n",
f.rfs,offset,ofs);
exit(1);
}
@ -277,8 +277,6 @@ 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,20 +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 (debug>3) 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 (debug>3) 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 (debug>3) 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:
@ -63,20 +63,28 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
else p->nexthop_address_status=OA_RESOLVED;
}
if (p->source[0]<0x10||p->destination[0]<0x10||p->nexthop[0]<0x10) {
if (p->source[0]<0x10) {
// Make sure that addresses do not overload the special address spaces of 0x00*-0x0f*
fail++;
return WHY("one or more packet addresses begins with reserved value 0x00-0x0f");
return WHY("packet source address begins with reserved value 0x00-0x0f");
}
if (p->destination[0]<0x10) {
// Make sure that addresses do not overload the special address spaces of 0x00*-0x0f*
fail++;
return WHY("packet destination address begins with reserved value 0x00-0x0f");
}
if (p->nexthop[0]<0x10) {
// Make sure that addresses do not overload the special address spaces of 0x00*-0x0f*
fail++;
return WHY("packet nexthop address begins with reserved value 0x00-0x0f");
}
/* XXX Write fields in correct order */
/* Write out type field byte(s) */
fprintf(stderr,">>>>> packet length before appending frame type = %d\n",b->length);
if (!fail) if (op_append_type(headers,p)) fail++;
/* Write out TTL */
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
@ -87,30 +95,22 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
*/
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);
@ -128,12 +128,8 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
ob_checkpoint(b);
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 */

@ -378,7 +378,7 @@ unsigned int overlay_route_hash_sid(unsigned char *sid)
/* Mask out extranous bits to return only a valid bin number */
bin&=(overlay_bin_count-1);
if (debug>2) {
if (debug>3) {
fprintf(stderr,"The following address resolves to bin #%d\n",bin);
for(i=0;i<SID_SIZE;i++) fprintf(stderr,"%02x",sid[i]);
fprintf(stderr,"\n");