2012-08-27 00:34:59 +00:00
|
|
|
/*
|
2013-12-04 06:26:55 +00:00
|
|
|
Serval DNA MDP overlay frame
|
2012-08-27 00:34:59 +00:00
|
|
|
Copyright (C) 2012 Serval Project Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2013-12-04 06:44:14 +00:00
|
|
|
#ifndef __SERVAL_DNA__OVERLAY_PACKET_H
|
|
|
|
#define __SERVAL_DNA__OVERLAY_PACKET_H
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2014-05-23 08:19:00 +00:00
|
|
|
#include "serval_types.h"
|
Switch to feature-driven linking
This introduces a new way of linking Serval executables and dynamic
libraries from static libraries like libservald.a -- called
"feature-driven" linking.
The Makefile now links servald and serval-tests from libservald.a,
rather than from an explicit list of object (.o) files. Thanks to the
section-based method for registering functions such as HTTP handlers,
CLI commands and MDP handlers, these object files had become
"stand-alone" and hence were no longer included in the link because
there was no unresolved reference that required them to be linked in.
The new "feature.h" provides the DECLARE_FEATURE(name) macro that each
stand-alone source file uses to declare the named feature(s) it
provides. Each executable can call the USE_FEATURE(name) macro in any
of its explicitly-linked source files to cause the corresponding
object(s) to be included in the link, eg, servald_features.c.
The DEFINE_BINDING() macro has been extended so that every individual
MDP binding is given a feature name based on its port number macro, eg,
"mdp_binding_MDP_PORT_ECHO".
Some features have been factored into their own separate source files so
they can be omitted or included in a build independently of each other:
- the MDP bindings for MDP_PORT_DNALOOKUP, MDP_PORT_ECHO,
MDP_PORT_TRACE, MDP_PORT_KEYMAPREQUEST, MDP_PORT_RHIZOME_xxx,
MDP_PORT_PROBE, MDP_PORT_STUN, MDP_PORT_STUNREQ
- the CLI "log" and "echo" commands
- the CLI "rhizome direct" command
The JNI source files are only compiled if the <jni.h> header is present,
otherwise they are omitted from libservald.so.
2016-10-13 02:58:23 +00:00
|
|
|
#include "feature.h"
|
2016-03-16 00:01:09 +00:00
|
|
|
#include "overlay_address.h"
|
2016-03-07 05:18:23 +00:00
|
|
|
#include "section.h"
|
2017-02-28 04:02:08 +00:00
|
|
|
#include "fdqueue.h"
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-05-20 03:53:35 +00:00
|
|
|
#define FRAME_NOT_SENT -1
|
|
|
|
#define FRAME_DONT_SEND -2
|
|
|
|
|
2013-08-08 05:50:31 +00:00
|
|
|
#define MAX_PACKET_DESTINATIONS OVERLAY_MAX_INTERFACES
|
|
|
|
|
|
|
|
struct packet_destination{
|
|
|
|
// if we've sent this packet once, what was the envelope sequence number?
|
|
|
|
int sent_sequence;
|
2013-08-29 05:35:32 +00:00
|
|
|
// track when we last sent this packet. if we don't get an ack, send it again.
|
|
|
|
time_ms_t transmit_time;
|
2013-08-15 00:45:08 +00:00
|
|
|
// the actual out going stream for this packet
|
2013-08-08 05:50:31 +00:00
|
|
|
struct network_destination *destination;
|
2014-09-23 04:17:48 +00:00
|
|
|
// next hop in the route
|
|
|
|
struct subscriber *next_hop;
|
2013-08-08 05:50:31 +00:00
|
|
|
};
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
struct overlay_frame {
|
2013-08-15 00:45:08 +00:00
|
|
|
// packet queue pointers
|
2012-08-27 00:34:59 +00:00
|
|
|
struct overlay_frame *prev;
|
|
|
|
struct overlay_frame *next;
|
2014-06-26 07:17:23 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// when did we insert into the queue?
|
|
|
|
time_ms_t enqueued_at;
|
2014-06-26 07:17:23 +00:00
|
|
|
struct __sourceloc whence;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// deprecated, all future "types" should just be assigned port numbers
|
2012-08-27 00:34:59 +00:00
|
|
|
unsigned int type;
|
2013-08-15 00:45:08 +00:00
|
|
|
// encrypted? signed?
|
2012-08-27 00:34:59 +00:00
|
|
|
unsigned int modifiers;
|
|
|
|
|
2015-06-15 05:40:08 +00:00
|
|
|
uint8_t ttl;
|
2013-08-15 00:45:08 +00:00
|
|
|
// Which QOS queue?
|
2015-06-15 05:40:08 +00:00
|
|
|
uint8_t queue;
|
|
|
|
// How many times should we retransmit?
|
|
|
|
int8_t resend;
|
2013-08-15 00:45:08 +00:00
|
|
|
|
|
|
|
// callback and context just before packet sending
|
2013-05-15 04:57:38 +00:00
|
|
|
void *send_context;
|
2015-06-22 03:00:18 +00:00
|
|
|
int (*send_hook)(struct overlay_frame *, struct network_destination *, int, void *);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// when should we send it?
|
2013-08-08 05:50:31 +00:00
|
|
|
time_ms_t delay_until;
|
2013-08-15 00:45:08 +00:00
|
|
|
// where should we send it?
|
2013-08-08 05:50:31 +00:00
|
|
|
struct packet_destination destinations[MAX_PACKET_DESTINATIONS];
|
|
|
|
int destination_count;
|
2015-06-22 03:00:18 +00:00
|
|
|
uint8_t manual_destinations;
|
2013-08-15 00:45:08 +00:00
|
|
|
// how often have we sent it?
|
2013-08-09 06:49:45 +00:00
|
|
|
int transmit_count;
|
|
|
|
|
2013-08-08 05:50:31 +00:00
|
|
|
// each payload gets a sequence number that is reused on retransmission
|
2013-05-24 04:22:31 +00:00
|
|
|
int32_t mdp_sequence;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// packet addressing;
|
|
|
|
// where did this packet originate?
|
|
|
|
struct subscriber *source;
|
|
|
|
// where is this packet destined for
|
|
|
|
// for broadcast packets, the destination will be null and the broadcast_id will be set if ttl>1
|
2012-08-27 00:34:59 +00:00
|
|
|
struct subscriber *destination;
|
2013-08-08 05:50:31 +00:00
|
|
|
struct broadcast broadcast_id;
|
2013-08-15 00:45:08 +00:00
|
|
|
// where is this packet going next?
|
2012-12-03 03:14:31 +00:00
|
|
|
struct subscriber *next_hop;
|
2013-08-15 00:45:08 +00:00
|
|
|
|
|
|
|
// should we force the next packet header to include our full public key?
|
2012-12-11 03:02:02 +00:00
|
|
|
int source_full;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// how did we receive this packet?
|
2013-12-09 07:15:47 +00:00
|
|
|
struct overlay_interface *interface;
|
2013-12-11 06:11:57 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// packet envelope header;
|
|
|
|
// Was it a unicast frame
|
2012-12-14 06:30:54 +00:00
|
|
|
char unicast;
|
2013-08-15 00:45:08 +00:00
|
|
|
// what encoding version was used / should be used?
|
2013-05-24 04:22:31 +00:00
|
|
|
int packet_version;
|
2013-08-15 00:45:08 +00:00
|
|
|
// which interface did the previous hop sent it from?
|
2013-08-08 05:50:31 +00:00
|
|
|
int sender_interface;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-08-15 00:45:08 +00:00
|
|
|
// Raw wire format of the payload, probably encrypted or signed.
|
2012-08-27 00:34:59 +00:00
|
|
|
struct overlay_buffer *payload;
|
|
|
|
};
|
|
|
|
|
2014-01-23 06:01:56 +00:00
|
|
|
// simple representation for passing mdp packet header details
|
|
|
|
struct internal_mdp_header{
|
|
|
|
struct subscriber *source;
|
|
|
|
mdp_port_t source_port;
|
|
|
|
struct subscriber *destination;
|
|
|
|
mdp_port_t destination_port;
|
2015-06-15 05:40:08 +00:00
|
|
|
int8_t resend;
|
2014-01-23 06:01:56 +00:00
|
|
|
uint8_t ttl;
|
|
|
|
uint8_t qos;
|
2014-01-31 01:45:56 +00:00
|
|
|
uint8_t crypt_flags; // combination of MDP_FLAG_NO_CRYPT & MDP_FLAG_NO_SIGN flags
|
2014-01-23 06:01:56 +00:00
|
|
|
struct overlay_interface *receive_interface;
|
2015-06-22 03:00:18 +00:00
|
|
|
void *send_context;
|
|
|
|
int (*send_hook)(struct overlay_frame *, struct network_destination *, int, void *);
|
2014-01-23 06:01:56 +00:00
|
|
|
};
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
int op_free(struct overlay_frame *p);
|
|
|
|
struct overlay_frame *op_dup(struct overlay_frame *f);
|
|
|
|
|
2014-04-29 06:01:50 +00:00
|
|
|
int reload_mdp_packet_rules(void);
|
2015-03-30 00:57:37 +00:00
|
|
|
void frame_remove_destination(struct overlay_frame *frame, int i);
|
|
|
|
void frame_add_destination(struct overlay_frame *frame, struct subscriber *next_hop, struct network_destination *dest);
|
2014-04-29 06:01:50 +00:00
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
void mdp_init_response(const struct internal_mdp_header *in, struct internal_mdp_header *out);
|
|
|
|
void overlay_mdp_encode_ports(struct overlay_buffer *plaintext, mdp_port_t dst_port, mdp_port_t src_port);
|
|
|
|
int overlay_mdp_dnalookup_reply(struct subscriber *dest, mdp_port_t dest_port,
|
|
|
|
struct subscriber *resolved_sid, const char *uri, const char *did, const char *name);
|
|
|
|
|
|
|
|
int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *header, struct overlay_buffer *payload);
|
|
|
|
#define overlay_send_frame(H, P) _overlay_send_frame(__WHENCE__, H, P)
|
|
|
|
|
|
|
|
struct internal_binding{
|
|
|
|
mdp_port_t port;
|
|
|
|
int (*function)(struct internal_mdp_header *header, struct overlay_buffer *payload);
|
2017-02-28 04:02:08 +00:00
|
|
|
struct profile_total stats;
|
2016-03-07 05:18:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_SECTION(struct internal_binding, bindings);
|
|
|
|
|
|
|
|
#define DEFINE_BINDING(PORT, FUNC) \
|
Switch to feature-driven linking
This introduces a new way of linking Serval executables and dynamic
libraries from static libraries like libservald.a -- called
"feature-driven" linking.
The Makefile now links servald and serval-tests from libservald.a,
rather than from an explicit list of object (.o) files. Thanks to the
section-based method for registering functions such as HTTP handlers,
CLI commands and MDP handlers, these object files had become
"stand-alone" and hence were no longer included in the link because
there was no unresolved reference that required them to be linked in.
The new "feature.h" provides the DECLARE_FEATURE(name) macro that each
stand-alone source file uses to declare the named feature(s) it
provides. Each executable can call the USE_FEATURE(name) macro in any
of its explicitly-linked source files to cause the corresponding
object(s) to be included in the link, eg, servald_features.c.
The DEFINE_BINDING() macro has been extended so that every individual
MDP binding is given a feature name based on its port number macro, eg,
"mdp_binding_MDP_PORT_ECHO".
Some features have been factored into their own separate source files so
they can be omitted or included in a build independently of each other:
- the MDP bindings for MDP_PORT_DNALOOKUP, MDP_PORT_ECHO,
MDP_PORT_TRACE, MDP_PORT_KEYMAPREQUEST, MDP_PORT_RHIZOME_xxx,
MDP_PORT_PROBE, MDP_PORT_STUN, MDP_PORT_STUNREQ
- the CLI "log" and "echo" commands
- the CLI "rhizome direct" command
The JNI source files are only compiled if the <jni.h> header is present,
otherwise they are omitted from libservald.so.
2016-10-13 02:58:23 +00:00
|
|
|
DEFINE_FEATURE(mdp_binding_ ## PORT); \
|
2016-03-07 05:18:23 +00:00
|
|
|
static int FUNC(struct internal_mdp_header *, struct overlay_buffer *);\
|
|
|
|
static struct internal_binding BIND ## FUNC IN_SECTION(bindings) = { \
|
|
|
|
.port = PORT, \
|
|
|
|
.function = FUNC, \
|
2017-06-28 04:04:38 +00:00
|
|
|
.stats = {.name = #FUNC, }, \
|
2016-03-07 05:18:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 06:44:14 +00:00
|
|
|
#endif //__SERVAL_DNA__OVERLAY_PACKET_H
|