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.
|
|
|
|
*/
|
|
|
|
|
2012-02-23 02:15:42 +00:00
|
|
|
#include "serval.h"
|
2012-12-11 05:29:46 +00:00
|
|
|
#include "conf.h"
|
2012-11-07 06:12:45 +00:00
|
|
|
#include "str.h"
|
2012-07-17 06:00:50 +00:00
|
|
|
#include "strbuf.h"
|
2012-08-22 00:51:38 +00:00
|
|
|
#include "overlay_buffer.h"
|
2012-08-27 00:34:59 +00:00
|
|
|
#include "overlay_packet.h"
|
2011-08-15 07:27:29 +00:00
|
|
|
|
2012-09-27 05:44:43 +00:00
|
|
|
struct sockaddr_in loopback;
|
2012-01-12 06:17:24 +00:00
|
|
|
|
2012-11-22 22:35:57 +00:00
|
|
|
unsigned char magic_header[]={0x00, 0x01};
|
2012-11-21 05:00:20 +00:00
|
|
|
|
2012-12-14 06:30:54 +00:00
|
|
|
#define PACKET_UNICAST (1<<0)
|
|
|
|
#define PACKET_INTERFACE (1<<1)
|
|
|
|
#define PACKET_SEQ (1<<2)
|
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
int overlay_packet_init_header(struct decode_context *context, struct overlay_buffer *buff,
|
2012-12-14 06:30:54 +00:00
|
|
|
struct subscriber *destination,
|
|
|
|
char unicast, char interface, char seq){
|
|
|
|
|
2012-11-22 22:35:57 +00:00
|
|
|
if (ob_append_bytes(buff,magic_header,sizeof magic_header))
|
|
|
|
return -1;
|
2012-11-26 04:51:01 +00:00
|
|
|
if (overlay_address_append(context, buff, my_subscriber))
|
|
|
|
return -1;
|
|
|
|
context->sender = my_subscriber;
|
2012-12-14 06:30:54 +00:00
|
|
|
|
|
|
|
int flags=0;
|
|
|
|
|
|
|
|
if (unicast)
|
|
|
|
flags |= PACKET_UNICAST;
|
|
|
|
if (interface)
|
|
|
|
flags |= PACKET_INTERFACE;
|
|
|
|
if (seq)
|
|
|
|
flags |= PACKET_SEQ;
|
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
ob_append_byte(buff,flags);
|
2012-12-14 06:30:54 +00:00
|
|
|
|
|
|
|
if (flags & PACKET_INTERFACE)
|
|
|
|
ob_append_byte(buff,interface);
|
|
|
|
|
|
|
|
if (flags & PACKET_SEQ)
|
|
|
|
ob_append_byte(buff,seq);
|
|
|
|
|
2012-11-26 04:51:01 +00:00
|
|
|
return 0;
|
2012-11-21 05:00:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
// a frame destined for one of our local addresses, or broadcast, has arrived. Process it.
|
2012-10-09 01:34:02 +00:00
|
|
|
int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, struct overlay_frame *f, struct decode_context *context){
|
2012-11-23 05:55:32 +00:00
|
|
|
IN();
|
2012-08-27 00:34:59 +00:00
|
|
|
int id = (interface - overlay_interfaces);
|
|
|
|
switch(f->type)
|
|
|
|
{
|
|
|
|
case OF_TYPE_SELFANNOUNCE_ACK:
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUG("Processing OF_TYPE_SELFANNOUNCE_ACK");
|
2012-08-27 00:34:59 +00:00
|
|
|
overlay_route_saw_selfannounce_ack(f,now);
|
|
|
|
break;
|
|
|
|
case OF_TYPE_NODEANNOUNCE:
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUG("Processing OF_TYPE_NODEANNOUNCE");
|
2012-10-09 01:34:02 +00:00
|
|
|
overlay_route_saw_advertisements(id,f,context,now);
|
2012-08-27 00:34:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// data frames
|
|
|
|
case OF_TYPE_RHIZOME_ADVERT:
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUG("Processing OF_TYPE_RHIZOME_ADVERT");
|
2012-08-27 00:34:59 +00:00
|
|
|
overlay_rhizome_saw_advertisements(id,f,now);
|
|
|
|
break;
|
|
|
|
case OF_TYPE_DATA:
|
|
|
|
case OF_TYPE_DATA_VOICE:
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUG("Processing OF_TYPE_DATA");
|
2012-08-27 00:34:59 +00:00
|
|
|
overlay_saw_mdp_containing_frame(f,now);
|
|
|
|
break;
|
2012-09-19 04:46:40 +00:00
|
|
|
case OF_TYPE_PLEASEEXPLAIN:
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUG("Processing OF_TYPE_PLEASEEXPLAIN");
|
2012-09-19 04:46:40 +00:00
|
|
|
process_explain(f);
|
|
|
|
break;
|
2012-08-27 00:34:59 +00:00
|
|
|
default:
|
2012-12-15 23:35:32 +00:00
|
|
|
RETURN(WHYF("Support for f->type=0x%x not implemented",f->type));
|
2012-08-27 00:34:59 +00:00
|
|
|
}
|
2012-11-23 05:55:32 +00:00
|
|
|
RETURN(0);
|
2012-08-27 00:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// duplicate the frame and queue it
|
|
|
|
int overlay_forward_payload(struct overlay_frame *f){
|
2012-11-23 05:55:32 +00:00
|
|
|
IN();
|
2012-08-27 00:34:59 +00:00
|
|
|
if (f->ttl<=0)
|
2012-11-23 05:55:32 +00:00
|
|
|
RETURN(0);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUGF("Forwarding payload for %s, ttl=%d",
|
|
|
|
(f->destination?alloca_tohex_sid(f->destination->sid):"broadcast"),
|
|
|
|
f->ttl);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
/* Queue frame for dispatch.
|
|
|
|
Don't forget to put packet in the correct queue based on type.
|
|
|
|
(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 */
|
|
|
|
struct overlay_frame *qf=op_dup(f);
|
|
|
|
if (!qf)
|
2012-11-23 05:55:32 +00:00
|
|
|
RETURN(WHY("Could not clone frame for queuing"));
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-10-09 05:14:37 +00:00
|
|
|
if (overlay_payload_enqueue(qf)) {
|
2012-08-27 00:34:59 +00:00
|
|
|
op_free(qf);
|
2012-11-23 05:55:32 +00:00
|
|
|
RETURN(WHY("failed to enqueue forwarded payload"));
|
2012-08-27 00:34:59 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 05:55:32 +00:00
|
|
|
RETURN(0);
|
2012-08-27 00:34:59 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 06:06:51 +00:00
|
|
|
int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, size_t len,
|
2012-11-21 05:00:20 +00:00
|
|
|
int recvttl, struct sockaddr *recvaddr, size_t recvaddrlen)
|
2011-08-15 07:27:29 +00:00
|
|
|
{
|
2012-11-23 05:55:32 +00:00
|
|
|
IN();
|
2011-08-15 07:27:29 +00:00
|
|
|
/*
|
2012-07-18 05:24:23 +00:00
|
|
|
This function decodes overlay packets which have been assembled for delivery overy IP networks.
|
|
|
|
IP based wireless networks have a high, but limited rate of packets that can be sent. In order
|
|
|
|
to increase throughput of small payloads, we ammend many payloads together and have used a scheme
|
|
|
|
to compress common network identifiers.
|
|
|
|
|
|
|
|
A different network type may have very different constraints on the number and size of packets,
|
|
|
|
and may need a different encoding scheme to use the bandwidth efficiently.
|
|
|
|
|
|
|
|
The current structure of an overlay packet is as follows;
|
|
|
|
Fixed header [0x4F, 0x10]
|
|
|
|
Version [0x00, 0x01]
|
|
|
|
|
|
|
|
Each frame within the packet has the following fields:
|
2011-08-17 01:22:17 +00:00
|
|
|
Frame type (8-24bits)
|
2011-08-15 11:50:30 +00:00
|
|
|
TTL (8bits)
|
2011-08-17 01:22:17 +00:00
|
|
|
Remaining frame size (RFS) (see overlay_payload.c or overlay_buffer.c for explanation of format)
|
2011-08-15 07:27:29 +00:00
|
|
|
Next hop (variable length due to address abbreviation)
|
2012-07-18 05:24:23 +00:00
|
|
|
Destination (variable length due to address abbreviation)
|
|
|
|
Source (variable length due to address abbreviation)
|
|
|
|
Payload (length = RFS- len(frame type) - len(next hop)
|
2011-08-15 07:27:29 +00:00
|
|
|
|
|
|
|
This structure is intended to allow relaying nodes to quickly ignore frames that are
|
|
|
|
not addressed to them as either the next hop or final destination.
|
|
|
|
|
|
|
|
The RFS field uses additional bytes to encode the length of longer frames.
|
|
|
|
This provides us with a slight space saving for the common case of short frames.
|
|
|
|
|
2012-07-18 05:24:23 +00:00
|
|
|
The frame payload itself can be enciphered with the final destination's public key, so
|
|
|
|
that it is not possible for the relaying 3rd parties to observe the content.
|
2011-08-15 07:27:29 +00:00
|
|
|
|
|
|
|
Naturally some information will leak simply based on the size, periodicity and other
|
|
|
|
characteristics of the traffic, and some 3rd parties may be malevolent, so noone should
|
|
|
|
assume that this provides complete security.
|
|
|
|
|
2012-07-18 05:24:23 +00:00
|
|
|
It would be possible to design a super-paranoid mode where onion routing is used with
|
|
|
|
concentric shells of encryption so that each hop can only work out the next node to send it
|
|
|
|
to. However, that would result in rather large frames, which may well betray more information
|
|
|
|
than the super-paranoid mode would hide.
|
2011-08-15 07:27:29 +00:00
|
|
|
|
|
|
|
Note also that it is possible to dispatch frames on a local link which are addressed to
|
|
|
|
broadcast, but are enciphered. In that situation only the intended recipient can
|
|
|
|
decode the frame, but at the cost of having all nodes on the local link having to decrypt
|
|
|
|
frame. Of course the nodes may elect to not decrypt such anonymous frames.
|
|
|
|
|
|
|
|
Such frames could even be flooded throughout part of the mesh by having the TTL>1, and
|
|
|
|
optionally with an anonymous source address to provide some plausible deniability for both
|
|
|
|
sending and reception if combined with a randomly selected TTL to give the impression of
|
|
|
|
the source having received the frame from elsewhere.
|
|
|
|
*/
|
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
if (recvaddr->sa_family!=AF_INET)
|
|
|
|
RETURN(WHYF("Unexpected protocol family %d",recvaddr->sa_family));
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
struct overlay_frame f;
|
2012-11-23 05:55:32 +00:00
|
|
|
struct decode_context context;
|
|
|
|
bzero(&context, sizeof context);
|
2012-12-04 04:17:57 +00:00
|
|
|
bzero(&f,sizeof f);
|
2012-09-19 04:46:40 +00:00
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
time_ms_t now = gettime_ms();
|
|
|
|
struct overlay_buffer *b = ob_static(packet, len);
|
|
|
|
ob_limitsize(b, len);
|
2012-11-21 05:00:20 +00:00
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
if (ob_get(b)!=magic_header[0] || ob_get(b)!=magic_header[1]){
|
|
|
|
ob_free(b);
|
|
|
|
RETURN(WHY("Packet type not recognised."));
|
|
|
|
}
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
context.interface = f.interface = interface;
|
2012-07-12 01:06:41 +00:00
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
f.recvaddr = *((struct sockaddr_in *)recvaddr);
|
2012-01-10 20:46:22 +00:00
|
|
|
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-12-04 04:17:57 +00:00
|
|
|
DEBUG("Received overlay packet");
|
|
|
|
|
2012-12-06 01:34:13 +00:00
|
|
|
if (overlay_address_parse(&context, b, &context.sender)){
|
|
|
|
WHY("Unable to parse sender");
|
|
|
|
}
|
2012-11-22 22:35:57 +00:00
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
int packet_flags = ob_get(b);
|
|
|
|
|
2012-12-14 06:30:54 +00:00
|
|
|
int sender_interface = 0;
|
|
|
|
if (packet_flags & PACKET_INTERFACE)
|
|
|
|
sender_interface = ob_get(b);
|
|
|
|
|
|
|
|
if (packet_flags & PACKET_SEQ)
|
|
|
|
ob_get(b); // sequence number, not implemented yet
|
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
if (context.sender){
|
|
|
|
|
|
|
|
if (context.sender->reachable==REACHABLE_SELF){
|
|
|
|
ob_free(b);
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
2012-12-06 03:33:55 +00:00
|
|
|
context.sender->last_rx = now;
|
|
|
|
|
|
|
|
// TODO probe unicast links when we detect an address change.
|
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
// if this is a dummy announcement for a node that isn't in our routing table
|
2012-12-15 23:35:32 +00:00
|
|
|
if (context.sender->reachable == REACHABLE_NONE) {
|
2012-12-05 05:06:46 +00:00
|
|
|
context.sender->interface = interface;
|
2013-01-29 00:57:13 +00:00
|
|
|
context.sender->address = f.recvaddr;
|
|
|
|
context.sender->last_probe = 0;
|
2012-12-15 23:35:32 +00:00
|
|
|
|
|
|
|
// assume for the moment, that we can reply with the same packet type
|
|
|
|
if (packet_flags&PACKET_UNICAST){
|
|
|
|
set_reachable(context.sender, REACHABLE_UNICAST|REACHABLE_ASSUMED);
|
|
|
|
}else{
|
|
|
|
set_reachable(context.sender, REACHABLE_BROADCAST|REACHABLE_ASSUMED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 00:57:13 +00:00
|
|
|
/* Note the probe payload must be queued before any SID/SAS request so we can force the packet to have a full sid */
|
|
|
|
if (context.sender->last_probe==0 || now - context.sender->last_probe > 5000)
|
|
|
|
overlay_send_probe(context.sender, f.recvaddr, interface, OQ_MESH_MANAGEMENT);
|
|
|
|
|
2012-12-15 23:35:32 +00:00
|
|
|
if ((!(packet_flags&PACKET_UNICAST)) && context.sender->last_acked + interface->tick_ms <= now){
|
|
|
|
overlay_route_ack_selfannounce(interface,
|
|
|
|
context.sender->last_acked>now - 3*interface->tick_ms?context.sender->last_acked:now,
|
|
|
|
now,sender_interface,context.sender);
|
|
|
|
|
|
|
|
context.sender->last_acked = now;
|
2012-12-04 04:17:57 +00:00
|
|
|
}
|
2013-01-29 00:57:13 +00:00
|
|
|
|
2012-12-04 04:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (packet_flags & PACKET_UNICAST)
|
|
|
|
context.addr=f.recvaddr;
|
|
|
|
else
|
|
|
|
context.addr=interface->broadcast_address;
|
2012-07-17 06:00:50 +00:00
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
while(b->position < b->sizeLimit){
|
2012-09-19 04:46:40 +00:00
|
|
|
context.invalid_addresses=0;
|
2012-11-26 04:22:49 +00:00
|
|
|
struct subscriber *nexthop=NULL;
|
|
|
|
bzero(f.broadcast_id.id, BROADCAST_LEN);
|
|
|
|
int process=1;
|
|
|
|
int forward=1;
|
2012-08-27 00:34:59 +00:00
|
|
|
int flags = ob_get(b);
|
2012-12-06 01:34:13 +00:00
|
|
|
if (flags<0){
|
|
|
|
WHY("Unable to parse payload flags");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-26 04:22:49 +00:00
|
|
|
if (flags & PAYLOAD_FLAG_SENDER_SAME){
|
2012-11-30 03:15:08 +00:00
|
|
|
if (!context.sender)
|
|
|
|
context.invalid_addresses=1;
|
2012-11-26 04:22:49 +00:00
|
|
|
f.source = context.sender;
|
|
|
|
}else{
|
2012-12-06 01:34:13 +00:00
|
|
|
if (overlay_address_parse(&context, b, &f.source)){
|
|
|
|
WHY("Unable to parse payload source");
|
2012-11-26 04:22:49 +00:00
|
|
|
break;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-11-26 04:22:49 +00:00
|
|
|
if (!f.source || f.source->reachable==REACHABLE_SELF)
|
|
|
|
process=forward=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & PAYLOAD_FLAG_TO_BROADCAST){
|
|
|
|
if (!(flags & PAYLOAD_FLAG_ONE_HOP)){
|
2012-12-06 01:34:13 +00:00
|
|
|
if (overlay_broadcast_parse(b, &f.broadcast_id)){
|
|
|
|
WHY("Unable to parse payload broadcast id");
|
2012-11-26 04:22:49 +00:00
|
|
|
break;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-11-26 04:22:49 +00:00
|
|
|
if (overlay_broadcast_drop_check(&f.broadcast_id)){
|
|
|
|
process=forward=0;
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-11-26 04:22:49 +00:00
|
|
|
DEBUGF("Ignoring duplicate broadcast (%s)", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.destination=NULL;
|
|
|
|
}else{
|
2012-12-06 01:34:13 +00:00
|
|
|
if (overlay_address_parse(&context, b, &f.destination)){
|
|
|
|
WHY("Unable to parse payload destination");
|
2012-11-26 04:22:49 +00:00
|
|
|
break;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-11-26 04:22:49 +00:00
|
|
|
|
|
|
|
if (!f.destination || f.destination->reachable!=REACHABLE_SELF){
|
|
|
|
process=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & PAYLOAD_FLAG_ONE_HOP)){
|
2012-12-06 01:34:13 +00:00
|
|
|
if (overlay_address_parse(&context, b, &nexthop)){
|
|
|
|
WHY("Unable to parse payload nexthop");
|
2012-11-26 04:22:49 +00:00
|
|
|
break;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-11-26 04:22:49 +00:00
|
|
|
|
|
|
|
if (!nexthop || nexthop->reachable!=REACHABLE_SELF){
|
|
|
|
forward=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-09 05:39:33 +00:00
|
|
|
|
2012-11-26 04:22:49 +00:00
|
|
|
if (flags & PAYLOAD_FLAG_ONE_HOP){
|
|
|
|
f.ttl=1;
|
|
|
|
}else{
|
|
|
|
int ttl_qos = ob_get(b);
|
2012-12-06 01:34:13 +00:00
|
|
|
if (ttl_qos<0){
|
|
|
|
WHY("Unable to parse ttl/qos");
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 04:22:49 +00:00
|
|
|
f.ttl = ttl_qos & 0x1F;
|
|
|
|
f.queue = (ttl_qos >> 5) & 3;
|
|
|
|
}
|
2012-10-10 05:52:31 +00:00
|
|
|
f.ttl--;
|
2012-11-26 04:22:49 +00:00
|
|
|
if (f.ttl<=0)
|
|
|
|
forward=0;
|
2012-11-27 00:54:03 +00:00
|
|
|
|
|
|
|
if (flags & PAYLOAD_FLAG_LEGACY_TYPE){
|
|
|
|
f.type=ob_get(b);
|
2012-12-06 01:34:13 +00:00
|
|
|
if (f.type<0){
|
|
|
|
WHY("Unable to parse payload type");
|
2012-11-27 00:54:03 +00:00
|
|
|
break;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-11-27 00:54:03 +00:00
|
|
|
}else
|
|
|
|
f.type=OF_TYPE_DATA;
|
2012-11-26 04:22:49 +00:00
|
|
|
|
|
|
|
f.modifiers=flags;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-11-26 04:22:49 +00:00
|
|
|
// TODO allow for one byte length
|
2012-12-15 23:35:32 +00:00
|
|
|
unsigned int payload_len = ob_get_ui16(b);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-12-15 23:35:32 +00:00
|
|
|
if (payload_len > ob_remaining(b)){
|
|
|
|
WHYF("Unable to parse payload length (%d)", payload_len);
|
2012-08-27 00:34:59 +00:00
|
|
|
break;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-11-23 05:55:32 +00:00
|
|
|
|
2012-12-15 23:35:32 +00:00
|
|
|
int next_payload = ob_position(b) + payload_len;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-12-05 05:06:46 +00:00
|
|
|
if (f.source)
|
|
|
|
f.source->last_rx = now;
|
|
|
|
|
2012-09-19 04:46:40 +00:00
|
|
|
// if we can't understand one of the addresses, skip processing the payload
|
2012-12-06 01:34:13 +00:00
|
|
|
if (context.invalid_addresses){
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes)
|
2012-12-06 01:34:13 +00:00
|
|
|
DEBUG("Skipping payload due to unknown addresses");
|
2012-09-19 04:46:40 +00:00
|
|
|
goto next;
|
2012-12-06 01:34:13 +00:00
|
|
|
}
|
2012-09-19 04:46:40 +00:00
|
|
|
|
2012-12-11 05:29:46 +00:00
|
|
|
if (config.debug.overlayframes){
|
2012-08-27 00:34:59 +00:00
|
|
|
DEBUGF("Received payload type %x, len %d", f.type, next_payload - b->position);
|
|
|
|
DEBUGF("Payload from %s", alloca_tohex_sid(f.source->sid));
|
2012-09-19 23:48:41 +00:00
|
|
|
DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid(f.destination->sid):"broadcast"));
|
|
|
|
if (!is_all_matching(f.broadcast_id.id, BROADCAST_LEN, 0))
|
|
|
|
DEBUGF("Broadcast id %s", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN));
|
2012-08-27 00:34:59 +00:00
|
|
|
if (nexthop)
|
|
|
|
DEBUGF("Next hop %s", alloca_tohex_sid(nexthop->sid));
|
|
|
|
}
|
|
|
|
|
2012-11-26 04:22:49 +00:00
|
|
|
if (!process && !forward)
|
2012-08-27 00:34:59 +00:00
|
|
|
goto next;
|
|
|
|
|
2012-12-15 23:35:32 +00:00
|
|
|
f.payload = ob_slice(b, b->position, payload_len);
|
2012-08-27 00:34:59 +00:00
|
|
|
if (!f.payload){
|
|
|
|
WHY("Payload length is longer than remaining packet size");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// mark the entire payload as having valid data
|
2012-12-15 23:35:32 +00:00
|
|
|
ob_limitsize(f.payload, payload_len);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
// forward payloads that are for someone else or everyone
|
2012-11-26 04:22:49 +00:00
|
|
|
if (forward){
|
2012-08-27 00:34:59 +00:00
|
|
|
overlay_forward_payload(&f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// process payloads that are for me or everyone
|
2012-11-26 04:22:49 +00:00
|
|
|
if (process){
|
2012-10-09 01:34:02 +00:00
|
|
|
process_incoming_frame(now, interface, &f, &context);
|
2012-08-27 00:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
if (f.payload){
|
|
|
|
ob_free(f.payload);
|
|
|
|
f.payload=NULL;
|
|
|
|
}
|
|
|
|
b->position=next_payload;
|
|
|
|
}
|
2012-07-17 06:00:50 +00:00
|
|
|
|
2012-11-23 05:55:32 +00:00
|
|
|
send_please_explain(&context, my_subscriber, context.sender);
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
ob_free(b);
|
2012-09-19 04:46:40 +00:00
|
|
|
|
2012-11-23 05:55:32 +00:00
|
|
|
RETURN(0);
|
2011-08-15 11:50:30 +00:00
|
|
|
}
|