2012-08-27 00:34:59 +00:00
|
|
|
/*
|
2013-12-04 06:26:55 +00:00
|
|
|
Serval DNA MDP addressing
|
|
|
|
Copyright (C) 2012-2013 Serval Project Inc.
|
2018-03-21 23:43:08 +00:00
|
|
|
Copyright (C) 2018 Flinders University
|
2013-12-04 06:26:55 +00:00
|
|
|
|
|
|
|
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-08-27 00:34:59 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-04 06:44:14 +00:00
|
|
|
#ifndef __SERVAL_DNA__OVERLAY_ADDRESS_H
|
|
|
|
#define __SERVAL_DNA__OVERLAY_ADDRESS_H
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
#include "constants.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 "serval_types.h" // for sid_t
|
2014-05-23 08:19:00 +00:00
|
|
|
#include "os.h" // for time_ms_t
|
2013-12-09 07:15:47 +00:00
|
|
|
#include "socket.h"
|
2016-09-13 04:44:21 +00:00
|
|
|
#include "nibble_tree.h"
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
// not reachable
|
|
|
|
#define REACHABLE_NONE 0
|
|
|
|
|
2012-11-30 03:15:08 +00:00
|
|
|
// this subscriber is in our keystore
|
|
|
|
#define REACHABLE_SELF (1<<0)
|
2012-09-10 01:25:12 +00:00
|
|
|
|
2012-11-30 03:15:08 +00:00
|
|
|
// immediate neighbour broadcast packet
|
|
|
|
#define REACHABLE_BROADCAST (1<<1)
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-11-30 03:15:08 +00:00
|
|
|
// reachable directly via unicast packet
|
|
|
|
#define REACHABLE_UNICAST (1<<2)
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-11-30 03:15:08 +00:00
|
|
|
// packets must be routed via next_hop
|
|
|
|
#define REACHABLE_INDIRECT (1<<3)
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-11-30 03:15:08 +00:00
|
|
|
#define REACHABLE_ASSUMED (1<<4)
|
2012-09-19 00:20:29 +00:00
|
|
|
|
2012-11-30 03:15:08 +00:00
|
|
|
#define REACHABLE_DIRECT (REACHABLE_BROADCAST|REACHABLE_UNICAST)
|
|
|
|
#define REACHABLE (REACHABLE_DIRECT|REACHABLE_INDIRECT)
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
#define BROADCAST_LEN 8
|
|
|
|
|
2014-02-07 05:25:40 +00:00
|
|
|
struct packet_rule;
|
2014-12-01 02:18:46 +00:00
|
|
|
struct overlay_buffer;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
|
|
|
// This structure supports both our own routing protocol which can store calculation details in *node
|
|
|
|
// or IP4 addresses reachable via any other kind of normal layer3 routing protocol, eg olsr
|
|
|
|
struct subscriber{
|
2016-09-13 04:44:21 +00:00
|
|
|
// minimum abbreviation length, in bits.
|
|
|
|
// Note this must be here to match the memory layout of struct tree_record
|
2016-10-12 03:04:03 +00:00
|
|
|
size_t tree_depth;
|
2013-10-09 08:24:21 +00:00
|
|
|
sid_t sid;
|
2016-09-13 04:44:21 +00:00
|
|
|
|
2013-08-08 05:50:31 +00:00
|
|
|
int max_packet_version;
|
|
|
|
|
2013-04-26 07:23:04 +00:00
|
|
|
// link state routing information
|
|
|
|
struct link_state *link_state;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2013-06-18 03:57:26 +00:00
|
|
|
// rhizome sync state
|
|
|
|
struct rhizome_sync *sync_state;
|
2016-03-22 05:58:44 +00:00
|
|
|
struct rhizome_sync_keys *sync_keys_state;
|
2016-03-09 02:02:23 +00:00
|
|
|
uint8_t sync_version;
|
2013-06-18 03:57:26 +00:00
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
// result of routing calculations;
|
|
|
|
int reachable;
|
2013-05-24 04:22:31 +00:00
|
|
|
|
2012-10-17 01:08:31 +00:00
|
|
|
// if indirect, who is the next hop?
|
|
|
|
struct subscriber *next_hop;
|
2016-03-02 00:03:19 +00:00
|
|
|
int hop_count;
|
|
|
|
struct subscriber *prior_hop;
|
2012-10-17 01:08:31 +00:00
|
|
|
|
|
|
|
// if direct, or unicast, where do we send packets?
|
2013-08-08 05:50:31 +00:00
|
|
|
struct network_destination *destination;
|
2012-10-17 01:08:31 +00:00
|
|
|
|
2012-12-11 06:17:36 +00:00
|
|
|
time_ms_t last_stun_request;
|
2013-01-29 00:57:13 +00:00
|
|
|
time_ms_t last_probe_response;
|
2013-06-19 05:57:17 +00:00
|
|
|
time_ms_t last_explained;
|
2012-10-17 01:08:31 +00:00
|
|
|
|
|
|
|
// public signing key details for remote peers
|
2016-08-15 03:43:26 +00:00
|
|
|
identity_t id_public;
|
|
|
|
time_ms_t id_last_request;
|
|
|
|
uint8_t id_valid:1;
|
|
|
|
uint8_t id_combined:1;
|
2016-07-25 06:20:43 +00:00
|
|
|
|
|
|
|
// should we send the full address once?
|
|
|
|
uint8_t send_full:1;
|
|
|
|
|
2012-10-10 00:02:25 +00:00
|
|
|
// private keys for local identities
|
2013-10-16 03:00:00 +00:00
|
|
|
struct keyring_identity *identity;
|
2012-08-27 00:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct broadcast{
|
|
|
|
unsigned char id[BROADCAST_LEN];
|
|
|
|
};
|
|
|
|
|
2015-11-16 03:17:28 +00:00
|
|
|
#define DECODE_FLAG_ENCODING_HEADER (1<<0)
|
|
|
|
#define DECODE_FLAG_INVALID_ADDRESS (1<<1)
|
|
|
|
#define DECODE_FLAG_DONT_EXPLAIN (1<<2)
|
2017-05-01 00:36:24 +00:00
|
|
|
#define DECODE_FLAG_EXTRA_BITS (1<<3)
|
2015-11-16 03:17:28 +00:00
|
|
|
|
2012-09-19 04:46:40 +00:00
|
|
|
struct decode_context{
|
2012-12-04 04:17:57 +00:00
|
|
|
struct overlay_interface *interface;
|
2013-05-15 06:26:43 +00:00
|
|
|
int sender_interface;
|
2013-05-24 04:22:31 +00:00
|
|
|
int packet_version;
|
|
|
|
int encapsulation;
|
2013-12-09 07:15:47 +00:00
|
|
|
struct socket_address addr;
|
2015-11-16 03:17:28 +00:00
|
|
|
uint8_t flags;
|
2012-09-19 04:46:40 +00:00
|
|
|
struct overlay_frame *please_explain;
|
2012-11-22 22:34:42 +00:00
|
|
|
struct subscriber *sender;
|
|
|
|
struct subscriber *previous;
|
2013-08-08 05:50:31 +00:00
|
|
|
struct subscriber *point_to_point_device;
|
2012-09-19 04:46:40 +00:00
|
|
|
};
|
|
|
|
|
2016-10-19 09:26:11 +00:00
|
|
|
struct subscriber *get_my_subscriber(bool_t create);
|
2016-06-15 07:38:25 +00:00
|
|
|
void release_my_subscriber();
|
2015-05-25 02:16:37 +00:00
|
|
|
extern __thread struct subscriber *directory_service;
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2016-09-13 04:44:21 +00:00
|
|
|
struct subscriber *find_subscriber(const uint8_t *sid, int len, int create);
|
2013-11-25 12:10:14 +00:00
|
|
|
|
2018-03-21 23:43:08 +00:00
|
|
|
typedef struct subscriber_iterator {
|
|
|
|
tree_iterator tree_iterator;
|
|
|
|
} subscriber_iterator;
|
|
|
|
|
|
|
|
void subscriber_iterator_start(subscriber_iterator *it);
|
|
|
|
void subscriber_iterator_advance_to(subscriber_iterator *it, const sid_t *sid);
|
|
|
|
struct subscriber **subscriber_iterator_get_current(subscriber_iterator *it);
|
|
|
|
void subscriber_iterator_advance(subscriber_iterator *it);
|
|
|
|
void subscriber_iterator_free(subscriber_iterator *it);
|
|
|
|
|
2016-09-13 04:44:21 +00:00
|
|
|
void enum_subscribers(struct subscriber *start, walk_callback callback, void *context);
|
2016-03-02 00:03:19 +00:00
|
|
|
int set_reachable(struct subscriber *subscriber, struct network_destination *destination, struct subscriber *next_hop, int hop_count, struct subscriber *prior_hop);
|
2016-01-20 06:30:08 +00:00
|
|
|
struct network_destination *load_subscriber_address(struct subscriber *subscriber);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-09-19 04:46:40 +00:00
|
|
|
int process_explain(struct overlay_frame *frame);
|
2012-08-27 00:34:59 +00:00
|
|
|
int overlay_broadcast_drop_check(struct broadcast *addr);
|
|
|
|
int overlay_broadcast_generate_address(struct broadcast *addr);
|
|
|
|
|
2013-11-25 06:13:32 +00:00
|
|
|
void overlay_broadcast_append(struct overlay_buffer *b, struct broadcast *broadcast);
|
|
|
|
void overlay_address_append(struct decode_context *context, struct overlay_buffer *b, struct subscriber *subscriber);
|
2012-09-19 04:46:40 +00:00
|
|
|
|
2012-11-26 04:58:13 +00:00
|
|
|
int overlay_broadcast_parse(struct overlay_buffer *b, struct broadcast *broadcast);
|
|
|
|
int overlay_address_parse(struct decode_context *context, struct overlay_buffer *b, struct subscriber **subscriber);
|
2012-09-19 04:46:40 +00:00
|
|
|
int send_please_explain(struct decode_context *context, struct subscriber *source, struct subscriber *destination);
|
|
|
|
|
2013-11-06 05:06:21 +00:00
|
|
|
void free_subscribers();
|
|
|
|
|
2013-12-04 06:44:14 +00:00
|
|
|
#endif //__SERVAL_DNA__OVERLAY_ADDRESS_H
|