2011-12-21 09:55:05 +00:00
|
|
|
/*
|
|
|
|
Serval Distributed Numbering Architecture (DNA)
|
|
|
|
Copyright (C) 2010 Paul Gardner-Stephen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-04-27 11:49:38 +00:00
|
|
|
/*
|
|
|
|
Serval Overlay Mesh Network.
|
|
|
|
|
|
|
|
Basically we use UDP broadcast to send link-local, and then implement a BATMAN-like protocol over the top of that.
|
|
|
|
|
|
|
|
Each overlay packet can contain one or more encapsulated packets each addressed using Serval DNA SIDs, with source,
|
|
|
|
destination and next-hop addresses.
|
|
|
|
|
2011-08-08 06:41:05 +00:00
|
|
|
The use of an overlay also lets us be a bit clever about using irregular transports, such as an ISM915 modem attached via ethernet
|
|
|
|
(which we are planning to build in coming months), by paring off the IP and UDP headers that would otherwise dominate. Even on
|
|
|
|
regular WiFi and ethernet we can aggregate packets in a way similar to IAX, but not just for voice frames.
|
|
|
|
|
|
|
|
The use of long (relative to IPv4 or even IPv6) 256 bit Curve25519 addresses means that it is a really good idea to
|
|
|
|
have neighbouring nodes exchange lists of peer aliases so that addresses can be summarised, possibly using less space than IPv4
|
|
|
|
would have.
|
|
|
|
|
|
|
|
One approach to handle address shortening is to have the periodic TTL=255 BATMAN-style hello packets include an epoch number.
|
|
|
|
This epoch number can be used by immediate neighbours of the originator to reference the neighbours listed in that packet by
|
|
|
|
their ordinal position in the packet instead of by their full address. This gets us address shortening to 1 byte in most cases
|
|
|
|
in return for no new packets, but the periodic hello packets will now be larger. We might deal with this issue by having these
|
|
|
|
hello packets reference the previous epoch for common neighbours. Unresolved neighbour addresses could be resolved by a simple
|
|
|
|
DNA request, which should only need to occur ocassionally, and other link-local neighbours could sniff and cache the responses
|
|
|
|
to avoid duplicated traffic. Indeed, during quiet times nodes could preemptively advertise address resolutions if they wished,
|
|
|
|
or similarly advertise the full address of a few (possibly randomly selected) neighbours in each epoch.
|
2011-04-27 11:49:38 +00:00
|
|
|
|
|
|
|
Byzantine Robustness is a goal, so we have to think about all sorts of malicious failure modes.
|
|
|
|
|
|
|
|
One approach to help byzantine robustness is to have multiple signature shells for each hop for mesh topology packets.
|
|
|
|
Thus forging a report of closeness requires forging a signature. As such frames are forwarded, the outermost signature
|
2011-08-08 06:41:05 +00:00
|
|
|
shell is removed. This is really only needed for more paranoid uses.
|
|
|
|
|
|
|
|
We want to have different traffic classes for voice/video calls versus regular traffic, e.g., MeshMS frames. Thus we need to have
|
|
|
|
separate traffic queues for these items. Aside from allowing us to prioritise isochronous data, it also allows us to expire old
|
|
|
|
isochronous frames that are in-queue once there is no longer any point delivering them (e.g after holding them more than 200ms).
|
|
|
|
We can also be clever about round-robin fair-sharing or even prioritising among isochronous streams. Since we also know about the
|
|
|
|
DNA isochronous protocols and the forward error correction and other redundancy measures we also get smart about dropping, say, 1 in 3
|
|
|
|
frames from every call if we know that this can be safely done. That is, when traffic is low, we maximise redundancy, and when we
|
|
|
|
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.
|
2011-08-08 14:41:46 +00:00
|
|
|
|
2012-01-10 11:26:07 +00:00
|
|
|
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.
|
|
|
|
|
2011-08-08 14:41:46 +00:00
|
|
|
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.
|
2011-04-27 11:49:38 +00:00
|
|
|
|
2011-08-08 06:41:05 +00:00
|
|
|
*/
|
2011-04-27 11:49:38 +00:00
|
|
|
|
2012-02-23 02:15:42 +00:00
|
|
|
#include "serval.h"
|
2011-04-27 11:49:38 +00:00
|
|
|
|
2011-08-08 14:41:46 +00:00
|
|
|
int overlayMode=0;
|
2011-04-27 11:49:38 +00:00
|
|
|
|
2011-09-05 03:04:54 +00:00
|
|
|
overlay_txqueue overlay_tx[OQ_MAX];
|
2011-08-14 08:36:39 +00:00
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
keyring_file *keyring=NULL;
|
|
|
|
|
2011-08-14 08:36:39 +00:00
|
|
|
int overlayServerMode()
|
|
|
|
{
|
|
|
|
/* In overlay mode we need to listen to all of our sockets, and also to
|
|
|
|
send periodic traffic. This means we need to */
|
|
|
|
fprintf(stderr,"Running in overlay mode.\n");
|
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
/* Get keyring available for use.
|
|
|
|
Required for MDP, and very soon as a complete replacement for the
|
|
|
|
HLR for DNA lookups, even in non-overlay mode. */
|
|
|
|
keyring=keyring_open_with_pins("");
|
|
|
|
if (!keyring) {
|
|
|
|
return WHY("Could not open serval keyring file.");
|
|
|
|
}
|
|
|
|
/* put initial identity in if we don't have any visible */
|
|
|
|
keyring_seed(keyring);
|
|
|
|
|
2011-09-05 03:49:00 +00:00
|
|
|
/* Set default congestion levels for queues */
|
|
|
|
int i;
|
|
|
|
for(i=0;i<OQ_MAX;i++) {
|
|
|
|
overlay_tx[i].maxLength=100;
|
|
|
|
overlay_tx[i].latencyTarget=5000; /* Keep packets in queue for 5 seconds by default */
|
|
|
|
}
|
|
|
|
/* But expire voice/video call packets much sooner, as they just aren't any use if late */
|
|
|
|
overlay_tx[OQ_ISOCHRONOUS_VOICE].latencyTarget=500;
|
|
|
|
overlay_tx[OQ_ISOCHRONOUS_VIDEO].latencyTarget=500;
|
|
|
|
|
2011-08-14 08:36:39 +00:00
|
|
|
/* Get the set of socket file descriptors we need to monitor.
|
|
|
|
Note that end-of-file will trigger select(), so we cannot run select() if we
|
|
|
|
have any dummy interfaces running. So we do an ugly hack of just waiting no more than
|
|
|
|
5ms between checks if we have a dummy interface running. This is a reasonable simulation
|
|
|
|
of wifi latency anyway, so we'll live with it. Larger values will affect voice transport,
|
|
|
|
and smaller values would affect CPU and energy use, and make the simulation less realistic. */
|
2012-01-12 06:17:24 +00:00
|
|
|
|
|
|
|
struct pollfd fds[128];
|
|
|
|
int fdcount;
|
2011-08-15 14:22:29 +00:00
|
|
|
|
2011-08-17 19:00:13 +00:00
|
|
|
/* Create structures to use 1MB of RAM for testing */
|
|
|
|
overlay_route_init(1);
|
|
|
|
|
2012-01-12 06:17:24 +00:00
|
|
|
/* Get rhizome server started BEFORE populating fd list so that
|
|
|
|
the server's listen socket is in the list for poll() */
|
|
|
|
if (rhizome_datastore_path) rhizome_server_poll();
|
2012-02-15 13:21:12 +00:00
|
|
|
|
2011-08-14 08:36:39 +00:00
|
|
|
while(1) {
|
2012-03-04 22:57:31 +00:00
|
|
|
|
|
|
|
if (servalShutdown) servalShutdownCleanly();
|
|
|
|
|
2011-08-14 08:36:39 +00:00
|
|
|
/* Work out how long we can wait before we need to tick */
|
|
|
|
long long ms=overlay_time_until_next_tick();
|
2012-02-15 13:21:12 +00:00
|
|
|
memabuseCheck();
|
2011-08-14 08:36:39 +00:00
|
|
|
int filesPresent=0;
|
2012-01-12 06:17:24 +00:00
|
|
|
fds[0].fd=sock; fds[0].events=POLLIN;
|
|
|
|
fdcount=1;
|
|
|
|
rhizome_server_get_fds(fds,&fdcount,128);
|
2012-01-13 06:51:06 +00:00
|
|
|
rhizome_fetching_get_fds(fds,&fdcount,128);
|
2012-03-17 02:32:09 +00:00
|
|
|
overlay_mdp_get_fds(fds,&fdcount,128);
|
2012-01-13 06:51:06 +00:00
|
|
|
|
2011-08-14 08:36:39 +00:00
|
|
|
for(i=0;i<overlay_interface_count;i++)
|
|
|
|
{
|
2012-01-12 06:17:24 +00:00
|
|
|
/* Make socket non-blocking so that poll() behaves correctly.
|
|
|
|
We then set non-blocking before actually reading from it */
|
|
|
|
fcntl(overlay_interfaces[i].fd, F_SETFL,
|
|
|
|
fcntl(overlay_interfaces[i].fd, F_GETFL, NULL)&(~O_NONBLOCK));
|
|
|
|
|
|
|
|
if ((!overlay_interfaces[i].fileP)&&(fdcount<128))
|
2011-08-14 08:36:39 +00:00
|
|
|
{
|
2012-01-12 06:17:24 +00:00
|
|
|
if (debug&DEBUG_IO) {
|
|
|
|
fprintf(stderr,"Interface %s is poll() slot #%d (fd %d)\n",
|
|
|
|
overlay_interfaces[i].name,
|
|
|
|
fdcount,
|
|
|
|
overlay_interfaces[i].fd);
|
|
|
|
}
|
|
|
|
fds[fdcount].fd=overlay_interfaces[i].fd;
|
|
|
|
fds[fdcount].events=POLLRDNORM;
|
|
|
|
fds[fdcount].revents=0;
|
|
|
|
fdcount++;
|
2011-08-14 08:36:39 +00:00
|
|
|
}
|
2012-01-12 06:17:24 +00:00
|
|
|
if (overlay_interfaces[i].fileP)
|
|
|
|
{ filesPresent=1; if (ms>5) ms=5; }
|
2011-08-14 08:36:39 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 15:32:58 +00:00
|
|
|
/* Progressively update link scores to neighbours etc, and find out how long before
|
|
|
|
we should next tick the route table.
|
|
|
|
Basically the faster the CPU and the sparser the route table, the less often we
|
|
|
|
will need to tick in order to keep each tick nice and fast. */
|
|
|
|
int route_tick_interval=overlay_route_tick();
|
|
|
|
if (ms>route_tick_interval) ms=route_tick_interval;
|
|
|
|
|
2012-01-12 06:17:24 +00:00
|
|
|
if (debug&DEBUG_VERBOSE_IO)
|
|
|
|
fprintf(stderr,"Waiting via poll() for up to %lldms\n",ms);
|
|
|
|
int r=poll(fds,fdcount,ms);
|
|
|
|
|
2011-08-14 08:36:39 +00:00
|
|
|
if (r<0) {
|
|
|
|
/* select had a problem */
|
2012-01-12 06:17:24 +00:00
|
|
|
if (debug&DEBUG_IO) perror("poll()");
|
2011-08-14 08:36:39 +00:00
|
|
|
WHY("select() complained.");
|
|
|
|
} else if (r>0) {
|
|
|
|
/* We have data, so try to receive it */
|
2012-01-12 06:17:24 +00:00
|
|
|
if (debug&DEBUG_IO) {
|
|
|
|
fprintf(stderr,"poll() reports %d fds ready\n",r);
|
|
|
|
int i;
|
|
|
|
for(i=0;i<fdcount;i++) {
|
|
|
|
if (fds[i].revents)
|
|
|
|
{
|
|
|
|
fprintf(stderr," #%d (fd %d): %d (",i,fds[i].fd,fds[i].revents);
|
|
|
|
if ((fds[i].revents&POLL_IN)==POLL_IN) fprintf(stderr,"POLL_IN,");
|
|
|
|
if ((fds[i].revents&POLLRDNORM)==POLLRDNORM) fprintf(stderr,"POLLRDNORM,");
|
|
|
|
if ((fds[i].revents&POLL_OUT)==POLL_OUT) fprintf(stderr,"POLL_OUT,");
|
|
|
|
if ((fds[i].revents&POLL_ERR)==POLL_ERR) fprintf(stderr,"POLL_ERR,");
|
|
|
|
if ((fds[i].revents&POLL_HUP)==POLL_HUP) fprintf(stderr,"POLL_HUP,");
|
|
|
|
if ((fds[i].revents&POLLNVAL)==POLLNVAL) fprintf(stderr,"POLL_NVAL,");
|
|
|
|
fprintf(stderr,")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-08-14 08:36:39 +00:00
|
|
|
overlay_rx_messages();
|
2012-01-13 06:51:06 +00:00
|
|
|
if (rhizome_datastore_path) {
|
|
|
|
rhizome_server_poll();
|
|
|
|
rhizome_fetch_poll();
|
2012-03-17 02:32:09 +00:00
|
|
|
overlay_mdp_poll();
|
2012-01-13 06:51:06 +00:00
|
|
|
}
|
2011-08-14 08:36:39 +00:00
|
|
|
} else {
|
|
|
|
/* No data before tick occurred, so do nothing.
|
|
|
|
Well, for now let's just check anyway. */
|
2012-01-12 06:17:24 +00:00
|
|
|
if (debug&DEBUG_IO) fprintf(stderr,"poll() timeout.\n");
|
2011-08-14 08:36:39 +00:00
|
|
|
overlay_rx_messages();
|
2012-01-13 06:51:06 +00:00
|
|
|
if (rhizome_datastore_path) {
|
|
|
|
rhizome_server_poll();
|
|
|
|
rhizome_fetch_poll();
|
2012-03-19 05:36:34 +00:00
|
|
|
overlay_mdp_poll();
|
2012-01-13 06:51:06 +00:00
|
|
|
}
|
2011-08-14 08:36:39 +00:00
|
|
|
}
|
|
|
|
/* Check if we need to trigger any ticks on any interfaces */
|
|
|
|
overlay_check_ticks();
|
|
|
|
}
|
2011-08-15 07:27:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-15 10:51:00 +00:00
|
|
|
int overlay_frame_process(int interface,overlay_frame *f)
|
2011-08-15 07:27:29 +00:00
|
|
|
{
|
2011-08-15 10:51:00 +00:00
|
|
|
if (!f) return WHY("f==NULL");
|
|
|
|
|
2011-08-29 06:50:27 +00:00
|
|
|
long long now=overlay_gettime_ms();
|
|
|
|
|
2012-01-10 06:51:26 +00:00
|
|
|
if (f->source_address_status==OA_RESOLVED&&overlay_address_is_local(f->source))
|
|
|
|
return WHY("Dropping frame claiming to come from myself.");
|
2012-01-08 23:27:57 +00:00
|
|
|
|
2012-01-10 05:26:40 +00:00
|
|
|
if (debug&DEBUG_OVERLAYFRAMES) fprintf(stderr,">>> Received frame (type=%02x)\n",f->type);
|
2011-09-12 14:19:55 +00:00
|
|
|
|
2011-08-15 10:51:00 +00:00
|
|
|
/* First order of business is whether the nexthop address has been resolved.
|
|
|
|
If not, we need to think about asking for it to be resolved.
|
|
|
|
The trouble is that we do not want to trigger a Hanson Event (a storm of
|
|
|
|
please explains/resolution requests). Yet, we do not want to delay
|
|
|
|
communications unnecessarily.
|
|
|
|
|
|
|
|
The simple solution for now is to queue the address for resolution request
|
|
|
|
in our next tick. If we see another resolution request for the same
|
|
|
|
address in the mean time, then we can cancel our request */
|
|
|
|
switch (f->nexthop_address_status)
|
|
|
|
{
|
|
|
|
case OA_UNINITIALISED:
|
|
|
|
/* Um? Right. */
|
|
|
|
return WHY("frame passed with ununitialised nexthop address");
|
|
|
|
break;
|
|
|
|
case OA_RESOLVED:
|
|
|
|
/* Great, we have the address, so we can get on with things */
|
|
|
|
break;
|
|
|
|
case OA_PLEASEEXPLAIN:
|
2012-01-11 03:57:40 +00:00
|
|
|
return WHY("Address cannot be resolved -- aborting packet processing.");
|
2012-01-09 05:58:44 +00:00
|
|
|
/* XXX Should send a please explain to get this address resolved. */
|
2011-08-15 10:51:00 +00:00
|
|
|
break;
|
|
|
|
case OA_UNSUPPORTED:
|
|
|
|
default:
|
|
|
|
/* If we don't support the address format, we should probably tell
|
|
|
|
the sender. Again, we queue this up, and cancel it if someone else
|
|
|
|
tells them in the meantime to avoid an Opposition Event (like a Hanson
|
|
|
|
Event, but repeatedly berating any node that holds a different policy
|
|
|
|
to itself. */
|
2012-04-13 22:09:02 +00:00
|
|
|
WHY("Packet with unsupported address format");
|
2011-08-15 10:51:00 +00:00
|
|
|
overlay_interface_repeat_abbreviation_policy[interface]=1;
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Okay, nexthop is valid, so let's see if it is us */
|
|
|
|
int forMe=0,i;
|
2011-08-15 14:22:29 +00:00
|
|
|
int ultimatelyForMe=0;
|
2012-04-14 01:24:48 +00:00
|
|
|
int broadcast=0;
|
|
|
|
int nhbroadcast=overlay_address_is_broadcast(f->nexthop);
|
2012-01-10 11:26:07 +00:00
|
|
|
int duplicateBroadcast=0;
|
2011-08-15 11:10:37 +00:00
|
|
|
|
2012-04-14 01:24:48 +00:00
|
|
|
if (nhbroadcast) {
|
|
|
|
if (overlay_broadcast_drop_check(f->nexthop)) duplicateBroadcast=1;
|
2012-01-10 11:26:07 +00:00
|
|
|
forMe=1; }
|
2012-01-08 23:25:21 +00:00
|
|
|
if (overlay_address_is_local(f->nexthop)) forMe=1;
|
2011-08-15 10:51:00 +00:00
|
|
|
|
2011-08-15 14:22:29 +00:00
|
|
|
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");
|
2012-04-14 01:24:48 +00:00
|
|
|
broadcast=overlay_address_is_broadcast(f->destination);
|
2012-01-10 05:26:40 +00:00
|
|
|
if (debug&DEBUG_OVERLAYFRAMES) {
|
2011-08-15 14:22:29 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2012-01-09 05:58:44 +00:00
|
|
|
if (f->source_address_status!=OA_RESOLVED) {
|
2012-01-10 05:26:40 +00:00
|
|
|
if (debug&DEBUG_OVERLAYFRAMES) WHY("Source address could not be resolved, so dropping frame.");
|
2012-01-09 05:58:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-01-10 09:57:36 +00:00
|
|
|
if (overlay_address_is_local(f->source))
|
|
|
|
{
|
|
|
|
if (debug&DEBUG_OVERLAYROUTING)
|
|
|
|
WHY("Dropping frame claiming to come from myself.");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-01-09 05:58:44 +00:00
|
|
|
|
2011-08-15 14:22:29 +00:00
|
|
|
if (f->destination_address_status==OA_RESOLVED) {
|
2012-01-10 11:26:07 +00:00
|
|
|
if (overlay_address_is_broadcast(f->destination))
|
2012-04-13 22:09:02 +00:00
|
|
|
{ ultimatelyForMe=1; broadcast=1; }
|
2012-01-08 23:25:21 +00:00
|
|
|
if (overlay_address_is_local(f->destination)) ultimatelyForMe=1;
|
2012-01-09 05:58:44 +00:00
|
|
|
} else {
|
2012-01-10 05:26:40 +00:00
|
|
|
if (debug&DEBUG_OVERLAYFRAMES) WHY("Destination address could not be resolved, so dropping frame.");
|
2012-01-09 05:58:44 +00:00
|
|
|
return -1;
|
2011-08-15 14:22:29 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-12 14:19:55 +00:00
|
|
|
|
2012-01-10 05:26:40 +00:00
|
|
|
if (debug&DEBUG_OVERLAYFRAMES) {
|
2011-09-12 14:19:55 +00:00
|
|
|
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");
|
2012-04-13 19:03:01 +00:00
|
|
|
fprintf(stderr,"This frame is%s%s broadcast.\n",
|
|
|
|
broadcast?"":" not",duplicateBroadcast?" a duplicate":"");
|
2011-09-12 14:19:55 +00:00
|
|
|
}
|
2011-08-15 11:50:30 +00:00
|
|
|
|
2012-04-13 22:09:02 +00:00
|
|
|
if (duplicateBroadcast) {
|
|
|
|
WHY("Packet is duplicate broadcast");
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-13 19:03:01 +00:00
|
|
|
|
2011-08-15 11:50:30 +00:00
|
|
|
/* Not for us? Then just ignore it */
|
2012-04-13 22:09:02 +00:00
|
|
|
if (!forMe) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-15 11:50:30 +00:00
|
|
|
|
2011-08-15 14:22:29 +00:00
|
|
|
/* Is this a frame we have to forward on? */
|
|
|
|
if (((!ultimatelyForMe)||broadcast)&&(f->ttl>1))
|
|
|
|
{
|
|
|
|
/* Yes, it is. */
|
2011-09-05 05:25:44 +00:00
|
|
|
int len=0;
|
2011-08-15 14:22:29 +00:00
|
|
|
|
2012-01-10 11:26:07 +00:00
|
|
|
if (broadcast&&(!duplicateBroadcast)&&
|
2012-01-08 23:25:21 +00:00
|
|
|
((f->type==OF_TYPE_SELFANNOUNCE)
|
|
|
|
||(f->type==OF_TYPE_RHIZOME_ADVERT)
|
|
|
|
))
|
|
|
|
{
|
|
|
|
// Don't forward broadcast self-announcement packets as that is O(n^2) with
|
|
|
|
// 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.
|
2012-01-10 11:26:07 +00:00
|
|
|
if (debug&DEBUG_BROADCASTS)
|
|
|
|
if (duplicateBroadcast)
|
|
|
|
fprintf(stderr,"Dropping broadcast frame (BPI seen before)\n");
|
2012-01-08 23:25:21 +00:00
|
|
|
} else {
|
2012-01-10 05:26:40 +00:00
|
|
|
if (debug&DEBUG_OVERLAYFRAMES) fprintf(stderr,"\nForwarding frame.\n");
|
2012-04-13 22:09:02 +00:00
|
|
|
int dontForward=0;
|
|
|
|
if (!broadcast) {
|
|
|
|
if (overlay_get_nexthop(f->destination,f->nexthop,&len,
|
|
|
|
&f->nexthop_interface))
|
|
|
|
WHY("Could not find next hop for host - dropping frame");
|
|
|
|
dontForward=1;
|
|
|
|
}
|
2011-08-17 16:45:13 +00:00
|
|
|
f->ttl--;
|
2012-04-13 22:09:02 +00:00
|
|
|
|
2012-04-14 01:24:48 +00:00
|
|
|
printf("considering forwarding frame to %s (forme=%d, broadcast=%d)\n",
|
|
|
|
overlay_render_sid(f->destination),ultimatelyForMe,broadcast);
|
|
|
|
if (overlay_address_is_broadcast(f->destination))
|
|
|
|
if (overlay_broadcast_drop_check(f->destination))
|
|
|
|
{
|
|
|
|
dontForward=1;
|
|
|
|
return WHY("Not forwarding or reading duplicate broadcast");
|
|
|
|
}
|
|
|
|
|
2012-04-13 22:09:02 +00:00
|
|
|
if (!dontForward) {
|
|
|
|
/* Queue frame for dispatch.
|
|
|
|
Don't forget to put packet in the correct queue based on type.
|
2012-04-14 01:24:48 +00:00
|
|
|
(e.g., mesh management, voice, video, ordinary or opportunistic).
|
|
|
|
|
|
|
|
But the really important bit is to clone the frame, since the
|
|
|
|
structure we are looking at here must be left as is and returned
|
|
|
|
to the caller to do as they please */
|
|
|
|
overlay_frame *qf=op_dup(f);
|
|
|
|
if (!qf) WHY("Could not clone frame for queuing");
|
|
|
|
else {
|
|
|
|
/* XXX we should preserve the queue priority of the frame */
|
|
|
|
int qn=OQ_ORDINARY;
|
|
|
|
WHY("queuing frame for forwarding");
|
|
|
|
if (overlay_payload_enqueue(qn,qf)) {
|
|
|
|
WHY("failed to enqueue forwarded payload");
|
|
|
|
op_free(qf);
|
|
|
|
}
|
|
|
|
}
|
2012-04-13 22:09:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 16:45:13 +00:00
|
|
|
/* If the frame was a broadcast frame, then we need to hang around
|
|
|
|
so that we can process it, since we are one of the recipients.
|
|
|
|
Otherwise, return triumphant. */
|
|
|
|
if (!broadcast) return 0;
|
|
|
|
}
|
2011-08-15 14:22:29 +00:00
|
|
|
}
|
|
|
|
|
2011-08-15 10:51:00 +00:00
|
|
|
switch(f->type)
|
|
|
|
{
|
|
|
|
case OF_TYPE_SELFANNOUNCE:
|
2011-09-03 21:18:41 +00:00
|
|
|
overlay_route_saw_selfannounce(interface,f,now);
|
2011-08-17 01:22:17 +00:00
|
|
|
break;
|
|
|
|
case OF_TYPE_SELFANNOUNCE_ACK:
|
2011-09-03 21:18:41 +00:00
|
|
|
overlay_route_saw_selfannounce_ack(interface,f,now);
|
2011-08-15 10:51:00 +00:00
|
|
|
break;
|
2011-09-12 20:07:24 +00:00
|
|
|
case OF_TYPE_NODEANNOUNCE:
|
|
|
|
overlay_route_saw_advertisements(interface,f,now);
|
|
|
|
break;
|
2012-01-08 22:47:54 +00:00
|
|
|
case OF_TYPE_RHIZOME_ADVERT:
|
|
|
|
overlay_rhizome_saw_advertisements(interface,f,now);
|
2012-01-08 22:51:23 +00:00
|
|
|
break;
|
2012-03-16 22:33:41 +00:00
|
|
|
case OF_TYPE_DATA:
|
2012-04-13 22:09:02 +00:00
|
|
|
WHY("saw mdp containing frame");
|
2012-03-27 08:55:38 +00:00
|
|
|
overlay_saw_mdp_containing_frame(interface,f,now);
|
2012-03-16 22:33:41 +00:00
|
|
|
break;
|
2011-08-15 10:51:00 +00:00
|
|
|
default:
|
2011-09-07 03:39:54 +00:00
|
|
|
fprintf(stderr,"Unsupported f->type=0x%x\n",f->type);
|
2011-08-15 11:50:30 +00:00
|
|
|
return WHY("Support for that f->type not yet implemented");
|
2011-08-15 10:51:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-05 03:07:46 +00:00
|
|
|
return 0;
|
2011-08-14 08:36:39 +00:00
|
|
|
}
|
2011-09-12 20:07:24 +00:00
|
|
|
|