Changed broadcast address to include a 64bit BPI to allow filtering

of duplicate broadcast announcements.
This commit is contained in:
gardners 2012-01-10 21:56:07 +10:30
parent 2a3721506b
commit f8eea651b5
8 changed files with 54 additions and 18 deletions

View File

@ -3,14 +3,14 @@ SRCS= dna.c server.c client.c peers.c ciphers.c responses.c packetformats.c data
overlay.c overlay_buffer.c overlay_interface.c overlay_payload.c overlay_route.c \
overlay_packetformats.c overlay_abbreviations.c overlay_advertise.c \
rhizome.c rhizome_http.c sqlite3.c encode.c sha2.c randombytes.c \
serval_packetvisualise.c
overlay_broadcast.c serval_packetvisualise.c
OBJS= dna.o server.o client.o peers.o ciphers.o responses.o packetformats.o dataformats.o \
hlrdata.o srandomdev.o simulate.o batman.o export.o gateway.o \
overlay.o overlay_buffer.o overlay_interface.o overlay_payload.o overlay_route.o \
overlay_packetformats.o overlay_abbreviations.o overlay_advertise.o \
rhizome.o rhizome_http.o sqlite3.o encode.o sha2.o randombytes.o \
serval_packetvisualise.o
overlay_broadcast.o serval_packetvisualise.o
HDRS= Makefile mphlr.h sqlite-amalgamation-3070900/sqlite3.h sha2.h rhizome.h

View File

@ -894,5 +894,11 @@ int rhizome_server_poll();
#define DEBUG_RHIZOME 131072
#define DEBUG_OVERLAYROUTEMONITOR 262144
#define DEBUG_QUEUES 524288
#define DEBUG_BROADCASTS 1048576
int serval_packetvisualise(FILE *f,char *message,unsigned char *packet,int plen);
int overlay_broadcast_drop_check(unsigned char *a);
int overlay_address_is_broadcast(unsigned char *a);
int overlay_broadcast_generate_address(unsigned char *a);

View File

@ -57,6 +57,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
start to hit the limit of traffic, we start to throw away some of the redundancy. This of course relies on us knowing when the
network channel is getting too full.
Smart-flooding of broadcast information is also a requirement. The long addresses help here, as we can make any address that begins
with the first 192 bits all ones be broadcast, and use the remaining 64 bits as a "broadcast packet identifier" (BPI).
Nodes can remember recently seen BPIs and not forward broadcast frames that have been seen recently. This should get us smart flooding
of the majority of a mesh (with some node mobility issues being a factor). We could refine this later, but it will do for now, especially
since for things like number resolution we are happy to send repeat requests.
This file currently seems to exist solely to contain this introduction, which is fine with me. Functions land in here until their
proper place becomes apparent.
@ -208,10 +214,12 @@ 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;
int broadcast=overlay_address_is_broadcast(f->nexthop);
int duplicateBroadcast=0;
for(i=0;i<SID_SIZE;i++) if (f->nexthop[i]!=0xff) break;
if (i==SID_SIZE) forMe=1;
if (broadcast) {
if (overlay_broadcast_drop_check(f->destination)) duplicateBroadcast=1;
forMe=1; }
if (overlay_address_is_local(f->nexthop)) forMe=1;
if (forMe) {
@ -239,8 +247,9 @@ int overlay_frame_process(int interface,overlay_frame *f)
}
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; }
if (overlay_address_is_broadcast(f->destination))
{ ultimatelyForMe=1; broadcast=1;
if (overlay_broadcast_drop_check(f->destination)) duplicateBroadcast=1; }
if (overlay_address_is_local(f->destination)) ultimatelyForMe=1;
} else {
if (debug&DEBUG_OVERLAYFRAMES) WHY("Destination address could not be resolved, so dropping frame.");
@ -263,7 +272,7 @@ int overlay_frame_process(int interface,overlay_frame *f)
/* Yes, it is. */
int len=0;
if (broadcast&&
if (broadcast&&(!duplicateBroadcast)&&
((f->type==OF_TYPE_SELFANNOUNCE)
||(f->type==OF_TYPE_RHIZOME_ADVERT)
))
@ -272,6 +281,9 @@ int overlay_frame_process(int interface,overlay_frame *f)
// traffic. We have other means to propagating the mesh topology information.
// Similarly, rhizome advertisement traffic is always link local, so don't
// forward that either.
if (debug&DEBUG_BROADCASTS)
if (duplicateBroadcast)
fprintf(stderr,"Dropping broadcast frame (BPI seen before)\n");
} else {
if (debug&DEBUG_OVERLAYFRAMES) fprintf(stderr,"\nForwarding frame.\n");
if (overlay_get_nexthop(f->destination,f->nexthop,&len,&f->nexthop_interface))

View File

@ -375,8 +375,16 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
overlay_abbreviate_set_most_recent_address(&out[(*ofs)-SID_SIZE]);
return r;
case OA_CODE_BROADCAST: /* broadcast */
memset(&out[*ofs],0xff,SID_SIZE);
memset(&out[*ofs],0xff,SID_SIZE-8);
(*inofs)++;
/* Copy Broadcast Packet Identifier */
{ int i; for(i=0;i<8;i++) out[(*ofs)+24+i]=in[(*inofs)+i]; }
if (debug&DEBUG_BROADCASTS)
fprintf(stderr,"Expanded broadcast address with "
"BPI=%02X%02X%02X%02X%02X%02X%02X%02X\n",
in[(*inofs)+0],in[(*inofs)+1],in[(*inofs)+2],in[(*inofs)+3],
in[(*inofs)+4],in[(*inofs)+5],in[(*inofs)+6],in[(*inofs)+7]);
(*inofs)+=8;
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
return OA_RESOLVED;
case OA_CODE_FULL_INDEX1: case OA_CODE_FULL_INDEX2:

View File

@ -84,7 +84,7 @@ int overlay_route_add_advertisements(int interface,overlay_buffer *e)
*/
int i;
int bytes=e->sizeLimit-e->length;
int overhead=1+1+3+32+1+1; /* maximum overhead */
int overhead=1+8+1+3+32+1+1; /* maximum overhead */
int slots=(bytes-overhead)/8;
if (slots>30) slots=30;
int slots_used=0;
@ -96,11 +96,12 @@ int overlay_route_add_advertisements(int interface,overlay_buffer *e)
ob_append_byte(e,1); /* TTL */
int rfs_offset=e->length; /* remember where the RFS byte gets stored
so that we can patch it later */
ob_append_byte(e,1+1+1+8*slots_used/* RFS */);
ob_append_byte(e,1+8+1+1+8*slots_used/* RFS */);
/* Stuff in dummy address fields */
ob_append_byte(e,OA_CODE_BROADCAST);
ob_append_byte(e,OA_CODE_BROADCAST);
for(i=0;i<8;i++) ob_append_byte(e,random()&0xff); /* random BPI */
ob_append_byte(e,OA_CODE_PREVIOUS);
ob_append_byte(e,OA_CODE_SELF);
int count;
@ -159,7 +160,7 @@ int overlay_route_add_advertisements(int interface,overlay_buffer *e)
if (oad_bin==bin&&oad_slot==slot) break;
}
e->bytes[rfs_offset]=1+1+1+8*slots_used;
e->bytes[rfs_offset]=1+8+1+1+8*slots_used;
return 0;
}

View File

@ -257,7 +257,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+1;
c=1+8+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");
@ -265,6 +265,7 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
c=OA_CODE_BROADCAST;
if (ob_append_bytes(b,&c,1))
return WHY("ob_append_bytes() could not add self-announcement header");
{ int i; for(i=0;i<8;i++) ob_append_byte(b,random()&0xff); } /* BPI for broadcast */
/* Add final destination. Always broadcast for self-announcments.
As we have just referenced the broadcast address, we can encode it in a single byte */

View File

@ -1408,11 +1408,12 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
ob_append_byte(e,1); /* TTL */
int rfs_offset=e->length; /* remember where the RFS byte gets stored
so that we can patch it later */
ob_append_byte(e,1+1+1+1+RHIZOME_BAR_BYTES*slots_used/* RFS */);
ob_append_byte(e,1+8+1+1+1+RHIZOME_BAR_BYTES*slots_used/* RFS */);
/* Stuff in dummy address fields */
ob_append_byte(e,OA_CODE_BROADCAST);
ob_append_byte(e,OA_CODE_BROADCAST);
{ int i; for(i=0;i<8;i++) ob_append_byte(e,random()&0xff); } /* BPI for broadcast */
ob_append_byte(e,OA_CODE_PREVIOUS);
ob_append_byte(e,OA_CODE_SELF);
/* Version of rhizome advert block */
@ -1481,7 +1482,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
}
if (debug&DEBUG_RHIZOME) printf("Appended %d rhizome advertisements to packet.\n",slots_used);
e->bytes[rfs_offset]=1+1+1+1+RHIZOME_BAR_BYTES*slots_used;
e->bytes[rfs_offset]=1+8+1+1+1+RHIZOME_BAR_BYTES*slots_used;
sqlite3_finalize(statement);
return 0;

View File

@ -75,7 +75,14 @@ int serval_packetvisualise_renderaddress(FILE *f,unsigned char *packet,int *ofs,
(*ofs)+=11;
break;
case 0x0f: /* broadcast */
fprintf(f,"<broadcast>"); (*ofs)++; break;
{
int i;
(*ofs)++;
fprintf(f,"<broadcast BPI=");
for(i=0;i<8;i++) fprintf(f,"%02X",packet[(*ofs)+i]);
(*ofs)+=8;
fprintf(f,">"); break;
}
case 0x0b: /* prefix 11 bytes and assign index */
case 0x0d: /* prefix 11 bytes and assign 2-byte index */