From f972c988b969c7d208dd1a558a575a04cfff3a72 Mon Sep 17 00:00:00 2001 From: gardners Date: Sat, 14 Apr 2012 04:06:08 +0930 Subject: [PATCH] Adding support for marking payloads as broadcast so that they can be directed to all interfaces if they are broadcast (previously overlay mesh would "broadcast" to one semi-random interface only). --- overlay_payload.c | 10 ++++++++++ serval.h | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/overlay_payload.c b/overlay_payload.c index 05702c37..77fed61c 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -220,6 +220,16 @@ int overlay_payload_enqueue(int q,overlay_frame *p) if (0) dump_queue("before",q); + /* If the frame is broadcast, then mark it correctly so that it can be sent + via all interfaces. */ + if (overlay_address_is_broadcast(p->destination)) + { + p->isBroadcast=1; + int i; + for(i=0;ibroadcast_sent_via[i]=0; + } + else p->isBroadcast=0; + overlay_frame *l=overlay_tx[q].last; if (l) l->next=p; p->prev=l; diff --git a/serval.h b/serval.h index 2ba23119..54d726c6 100644 --- a/serval.h +++ b/serval.h @@ -474,6 +474,7 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP struct response_set *responses); int readArpTable(struct in_addr peers[],int *peer_count,int peer_max); +#define OVERLAY_MAX_INTERFACES 16 typedef struct overlay_address_table { unsigned char epoch; @@ -515,6 +516,12 @@ typedef struct overlay_frame { unsigned char ttl; + /* Mark which interfaces the frame has been sent on, + so that we can ensure that broadcast frames get sent + exactly once on each interface */ + int isBroadcast; + unsigned char broadcast_sent_via[OVERLAY_MAX_INTERFACES]; + unsigned char nexthop[32]; int nexthop_address_status; int nexthop_interface; /* which interface the next hop should be attempted on */ @@ -554,6 +561,7 @@ extern int overlayMode; #define OVERLAY_INTERFACE_ETHERNET 1 #define OVERLAY_INTERFACE_WIFI 2 #define OVERLAY_INTERFACE_PACKETRADIO 3 + typedef struct overlay_interface { char name[80]; int fd; @@ -603,7 +611,6 @@ typedef struct overlay_interface { /* Maximum interface count is rather arbitrary. Memory consumption is O(n) with respect to this parameter, so let's not make it too big for now. */ -#define OVERLAY_MAX_INTERFACES 16 extern overlay_interface overlay_interfaces[OVERLAY_MAX_INTERFACES]; extern int overlay_last_interface_number; // used to remember where a packet came from extern unsigned int overlay_sequence_number;