2010-07-13 12:15:46 +00:00
|
|
|
/*
|
2012-07-30 03:28:21 +00:00
|
|
|
Serval Daemon
|
|
|
|
Copyright (C) 2010-2012 Paul Gardner-Stephen
|
|
|
|
Copyright (C) 2012 Serval Project Inc.
|
2010-07-13 12:15:46 +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-07-30 03:28:21 +00:00
|
|
|
#ifndef __SERVALD_SERVALD_H
|
|
|
|
#define __SERVALD_SERVALD_H
|
2012-07-23 04:17:59 +00:00
|
|
|
|
2012-04-20 09:56:08 +00:00
|
|
|
// #define MALLOC_PARANOIA
|
2012-04-20 06:11:13 +00:00
|
|
|
|
2010-07-13 12:15:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2012-05-10 03:23:57 +00:00
|
|
|
#include <stdarg.h>
|
2010-07-13 12:15:46 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
2011-12-01 19:14:32 +00:00
|
|
|
#include <signal.h>
|
2012-05-14 09:02:10 +00:00
|
|
|
#include <sys/types.h>
|
2011-03-30 05:04:23 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include "win32/win32.h"
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2011-10-16 21:41:05 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NET_ROUTE_H
|
|
|
|
#include <net/route.h>
|
|
|
|
#endif
|
2012-04-28 11:14:20 +00:00
|
|
|
#ifdef HAVE_LINUX_IF_H
|
|
|
|
#include <linux/if.h>
|
|
|
|
#else
|
2011-07-08 05:06:54 +00:00
|
|
|
#ifdef HAVE_NET_IF_H
|
|
|
|
#include <net/if.h>
|
|
|
|
#endif
|
2012-04-28 11:14:20 +00:00
|
|
|
#endif
|
2011-07-08 05:06:54 +00:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LINUX_NETLINK_H
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LINUX_RTNETLINK_H
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_IFADDRS_H
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#endif
|
2012-10-15 05:28:42 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKIO_H
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#endif
|
2012-05-21 02:52:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_UCRED_H
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#endif
|
2011-03-30 05:04:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(FORASTERISK) && !defined(s_addr)
|
2010-07-13 12:15:46 +00:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#else
|
|
|
|
typedef unsigned int in_addr_t;
|
|
|
|
struct in_addr {
|
|
|
|
in_addr_t s_addr;
|
|
|
|
};
|
|
|
|
#endif
|
2011-03-21 02:38:35 +00:00
|
|
|
#endif
|
2011-03-30 05:04:23 +00:00
|
|
|
|
2010-07-13 12:15:46 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_POLL_H
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CTYPE_H
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
2011-03-30 05:04:23 +00:00
|
|
|
|
|
|
|
#ifndef WIN32
|
2010-07-13 12:15:46 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/un.h>
|
2011-03-30 05:04:23 +00:00
|
|
|
#endif
|
|
|
|
|
2010-07-13 12:15:46 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ctype.h>
|
2012-05-10 07:28:25 +00:00
|
|
|
#include <sys/stat.h>
|
2010-07-13 12:15:46 +00:00
|
|
|
|
2012-07-29 03:05:53 +00:00
|
|
|
#include "constants.h"
|
2012-08-03 07:14:05 +00:00
|
|
|
#include "xprintf.h"
|
2012-07-29 03:05:53 +00:00
|
|
|
#include "log.h"
|
2012-08-23 03:01:07 +00:00
|
|
|
#include "net.h"
|
2012-07-29 03:05:53 +00:00
|
|
|
#include "conf.h"
|
|
|
|
|
2012-08-09 02:44:32 +00:00
|
|
|
/* All wall clock times in the Serval daemon are represented in milliseconds
|
|
|
|
* since the Unix epoch. The gettime_ms() function uses gettimeofday(2) to
|
|
|
|
* return this value when called. The time_ms_t typedef should be used
|
|
|
|
* wherever this time value is handled or stored.
|
|
|
|
*
|
|
|
|
* This type could perfectly well be unsigned, but is defined as signed to
|
|
|
|
* avoid the need to cast or define a special signed timedelta_ms_t type at **
|
|
|
|
* (1):
|
|
|
|
*
|
|
|
|
* static time_ms_t then = 0;
|
|
|
|
* time_ms_t now = gettime_ms();
|
|
|
|
* time_ms_t ago = now - then; // ** (1)
|
|
|
|
* if (then && ago < 0) {
|
|
|
|
* ... time going backwards ...
|
|
|
|
* } else {
|
|
|
|
* ... time has advanced ...
|
|
|
|
* then = now;
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
typedef long long time_ms_t;
|
|
|
|
|
2012-05-14 09:02:10 +00:00
|
|
|
/* bzero(3) is deprecated in favour of memset(3). */
|
|
|
|
#define bzero(addr,len) memset((addr), 0, (len))
|
|
|
|
|
2011-08-08 14:41:46 +00:00
|
|
|
/* UDP Port numbers for various Serval services.
|
|
|
|
The overlay mesh works over DNA */
|
2011-04-27 11:48:09 +00:00
|
|
|
#define PORT_DNA 4110
|
2010-07-13 12:15:46 +00:00
|
|
|
|
|
|
|
/* OpenWRT libc doesn't have bcopy, but has memmove */
|
|
|
|
#define bcopy(A,B,C) memmove(B,A,C)
|
|
|
|
|
|
|
|
#define BATCH 1
|
|
|
|
#define NONBATCH 0
|
|
|
|
|
|
|
|
#define REQ_SERIAL 0
|
|
|
|
#define REQ_PARALLEL -1
|
|
|
|
#define REQ_FIRSTREPLY -2
|
|
|
|
#define REQ_REPLY -101
|
|
|
|
|
|
|
|
|
|
|
|
#define SET_NOREPLACE 1
|
|
|
|
#define SET_REPLACE 2
|
|
|
|
#define SET_NOCREATE 3
|
|
|
|
#define SET_FRAGMENT 0x80
|
|
|
|
|
|
|
|
#define WITHDATA 1
|
|
|
|
#define WITHOUTDATA 0
|
|
|
|
|
|
|
|
/* Limit packet payloads to minimise packet loss of big packets in mesh networks */
|
|
|
|
#define MAX_DATA_BYTES 256
|
|
|
|
|
|
|
|
double simulatedBER;
|
|
|
|
|
|
|
|
extern int serverMode;
|
2012-03-04 22:57:31 +00:00
|
|
|
extern int servalShutdown;
|
2010-07-13 12:15:46 +00:00
|
|
|
|
2011-08-10 13:38:59 +00:00
|
|
|
extern char *gatewayspec;
|
2011-05-06 02:27:33 +00:00
|
|
|
|
2012-05-15 03:26:10 +00:00
|
|
|
int rhizome_enabled();
|
2012-07-12 02:40:59 +00:00
|
|
|
int rhizome_http_server_running();
|
2012-05-15 03:26:10 +00:00
|
|
|
const char *rhizome_datastore_path();
|
2011-12-17 01:41:32 +00:00
|
|
|
|
2010-07-13 12:15:46 +00:00
|
|
|
extern struct in_addr client_addr;
|
|
|
|
extern int client_port;
|
|
|
|
|
|
|
|
#define MAX_PEERS 1024
|
|
|
|
extern int peer_count;
|
2011-04-27 11:48:09 +00:00
|
|
|
extern struct in_addr peers[MAX_PEERS];
|
2010-07-13 12:15:46 +00:00
|
|
|
|
|
|
|
extern char *outputtemplate;
|
2011-05-05 09:10:38 +00:00
|
|
|
extern char *instrumentation_file;
|
2010-07-13 12:15:46 +00:00
|
|
|
extern char *batman_socket;
|
2011-03-21 02:38:35 +00:00
|
|
|
extern char *batman_peerfile;
|
2010-07-13 12:15:46 +00:00
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
|
2012-10-03 04:29:46 +00:00
|
|
|
struct subscriber;
|
2012-10-09 01:34:02 +00:00
|
|
|
struct decode_context;
|
2012-10-03 04:29:46 +00:00
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
typedef struct keypair {
|
|
|
|
int type;
|
|
|
|
unsigned char *private_key;
|
|
|
|
int private_key_len;
|
|
|
|
unsigned char *public_key;
|
|
|
|
int public_key_len;
|
|
|
|
} keypair;
|
|
|
|
|
|
|
|
/* Contains just the list of private:public key pairs and types,
|
|
|
|
the pin used to extract them, and the slot in the keyring file
|
|
|
|
(so that it can be replaced/rewritten as required). */
|
|
|
|
#define PKR_MAX_KEYPAIRS 64
|
|
|
|
#define PKR_SALT_BYTES 32
|
|
|
|
#define PKR_MAC_BYTES 64
|
2012-07-30 05:49:24 +00:00
|
|
|
typedef struct keyring_identity {
|
2012-04-12 23:55:03 +00:00
|
|
|
char *PKRPin;
|
2012-10-10 00:02:25 +00:00
|
|
|
struct subscriber *subscriber;
|
2012-04-12 23:55:03 +00:00
|
|
|
unsigned int slot;
|
|
|
|
int keypair_count;
|
|
|
|
keypair *keypairs[PKR_MAX_KEYPAIRS];
|
|
|
|
} keyring_identity;
|
|
|
|
|
|
|
|
/* 64K identities, can easily be increased should the need arise,
|
|
|
|
but keep it low-ish for now so that the 64K pointers don't eat too
|
|
|
|
much ram on a small device. Should probably think about having
|
|
|
|
small and large device settings for some of these things */
|
|
|
|
#define KEYRING_MAX_IDENTITIES 65536
|
|
|
|
typedef struct keyring_context {
|
|
|
|
char *KeyRingPin;
|
|
|
|
unsigned char *KeyRingSalt;
|
|
|
|
int KeyRingSaltLen;
|
|
|
|
|
|
|
|
int identity_count;
|
|
|
|
keyring_identity *identities[KEYRING_MAX_IDENTITIES];
|
|
|
|
} keyring_context;
|
|
|
|
|
|
|
|
#define KEYRING_PAGE_SIZE 4096LL
|
|
|
|
#define KEYRING_BAM_BYTES 2048LL
|
|
|
|
#define KEYRING_BAM_BITS (KEYRING_BAM_BYTES<<3)
|
|
|
|
#define KEYRING_SLAB_SIZE (KEYRING_PAGE_SIZE*KEYRING_BAM_BITS)
|
|
|
|
typedef struct keyring_bam {
|
|
|
|
off_t file_offset;
|
|
|
|
unsigned char bitmap[KEYRING_BAM_BYTES];
|
|
|
|
struct keyring_bam *next;
|
|
|
|
} keyring_bam;
|
|
|
|
|
|
|
|
#define KEYRING_MAX_CONTEXTS 256
|
|
|
|
typedef struct keyring_file {
|
|
|
|
int context_count;
|
|
|
|
keyring_bam *bam;
|
|
|
|
keyring_context *contexts[KEYRING_MAX_CONTEXTS];
|
|
|
|
FILE *file;
|
|
|
|
off_t file_size;
|
|
|
|
} keyring_file;
|
|
|
|
|
|
|
|
void keyring_free(keyring_file *k);
|
|
|
|
void keyring_free_context(keyring_context *c);
|
|
|
|
void keyring_free_identity(keyring_identity *id);
|
|
|
|
void keyring_free_keypair(keypair *kp);
|
|
|
|
int keyring_identity_mac(keyring_context *c,keyring_identity *id,
|
|
|
|
unsigned char *pkrsalt,unsigned char *mac);
|
|
|
|
#define KEYTYPE_CRYPTOBOX 0x01
|
|
|
|
#define KEYTYPE_CRYPTOSIGN 0x02
|
|
|
|
#define KEYTYPE_RHIZOME 0x03
|
|
|
|
/* DIDs aren't really keys, but the keyring is a real handy place to keep them,
|
|
|
|
and keep them private if people so desire */
|
|
|
|
#define KEYTYPE_DID 0x04
|
|
|
|
|
|
|
|
/* handle to keyring file for use in running instance */
|
|
|
|
extern keyring_file *keyring;
|
|
|
|
|
|
|
|
/* Public calls to keyring management */
|
|
|
|
keyring_file *keyring_open(char *file);
|
2012-04-23 07:42:10 +00:00
|
|
|
keyring_file *keyring_open_with_pins(const char *pinlist);
|
|
|
|
int keyring_enter_pin(keyring_file *k, const char *pin);
|
|
|
|
int keyring_enter_pins(keyring_file *k, const char *pinlist);
|
2012-05-01 05:08:09 +00:00
|
|
|
int keyring_set_did(keyring_identity *id,char *did,char *name);
|
2012-06-08 08:55:43 +00:00
|
|
|
int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp);
|
|
|
|
int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int keytype);
|
|
|
|
int keyring_next_identity(const keyring_file *k,int *cn,int *in,int *kp);
|
|
|
|
int keyring_identity_find_keytype(const keyring_file *k, int cn, int in, int keytype);
|
|
|
|
int keyring_find_did(const keyring_file *k,int *cn,int *in,int *kp,char *did);
|
|
|
|
int keyring_find_sid(const keyring_file *k,int *cn,int *in,int *kp, const unsigned char *sid);
|
2012-04-15 20:36:43 +00:00
|
|
|
unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
|
|
|
unsigned char **sas_public);
|
2012-10-03 04:29:46 +00:00
|
|
|
int keyring_send_sas_request(struct subscriber *subscriber);
|
2012-04-14 17:47:36 +00:00
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
int keyring_commit(keyring_file *k);
|
2012-07-06 03:47:53 +00:00
|
|
|
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c, const char *pin);
|
2012-04-12 23:55:03 +00:00
|
|
|
int keyring_seed(keyring_file *k);
|
2012-07-06 03:47:53 +00:00
|
|
|
void keyring_identity_extract(const keyring_identity *id, const unsigned char **sidp, const char **didp, const char **namep);
|
2010-07-13 12:15:46 +00:00
|
|
|
|
|
|
|
/* Make sure we have space to put bytes of the packet as we go along */
|
2012-05-24 07:41:55 +00:00
|
|
|
#define CHECK_PACKET_LEN(B) {if (((*packet_len)+(B))>=packet_maxlen) { return WHY("Packet composition ran out of space."); } }
|
2010-07-13 12:15:46 +00:00
|
|
|
|
|
|
|
extern int sock;
|
|
|
|
|
2012-07-02 06:34:00 +00:00
|
|
|
struct profile_total {
|
|
|
|
struct profile_total *_next;
|
2012-07-02 03:49:54 +00:00
|
|
|
int _initialised;
|
|
|
|
const char *name;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t max_time;
|
|
|
|
time_ms_t total_time;
|
|
|
|
time_ms_t child_time;
|
2012-07-02 03:49:54 +00:00
|
|
|
int calls;
|
|
|
|
};
|
|
|
|
|
2012-07-12 00:45:16 +00:00
|
|
|
struct call_stats{
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t enter_time;
|
|
|
|
time_ms_t child_time;
|
2012-07-12 00:45:16 +00:00
|
|
|
struct profile_total *totals;
|
|
|
|
struct call_stats *prev;
|
|
|
|
};
|
|
|
|
|
2012-07-02 03:49:54 +00:00
|
|
|
struct sched_ent;
|
|
|
|
|
|
|
|
typedef void (*ALARM_FUNCP) (struct sched_ent *alarm);
|
|
|
|
|
|
|
|
struct sched_ent{
|
|
|
|
struct sched_ent *_next;
|
|
|
|
struct sched_ent *_prev;
|
|
|
|
|
|
|
|
ALARM_FUNCP function;
|
|
|
|
void *context;
|
|
|
|
struct pollfd poll;
|
2012-07-12 00:45:16 +00:00
|
|
|
// when we should first consider the alarm
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t alarm;
|
2012-07-12 00:45:16 +00:00
|
|
|
// the order we will prioritise the alarm
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t deadline;
|
2012-07-02 06:34:00 +00:00
|
|
|
struct profile_total *stats;
|
2012-07-02 03:49:54 +00:00
|
|
|
int _poll_index;
|
|
|
|
};
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
struct overlay_buffer;
|
2012-11-20 06:11:06 +00:00
|
|
|
struct overlay_frame;
|
2012-11-23 05:55:32 +00:00
|
|
|
struct broadcast;
|
|
|
|
|
2012-07-25 08:34:16 +00:00
|
|
|
#define STRUCT_SCHED_ENT_UNUSED ((struct sched_ent){NULL, NULL, NULL, NULL, {-1, 0, 0}, 0LL, 0LL, NULL, -1})
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2011-08-08 14:41:46 +00:00
|
|
|
extern int overlayMode;
|
2012-04-13 18:36:08 +00:00
|
|
|
|
2012-07-25 07:23:44 +00:00
|
|
|
#define INTERFACE_STATE_FREE 0
|
|
|
|
#define INTERFACE_STATE_UP 1
|
|
|
|
#define INTERFACE_STATE_DOWN 2
|
|
|
|
#define INTERFACE_STATE_DETECTING 3
|
|
|
|
|
2011-08-08 06:41:05 +00:00
|
|
|
typedef struct overlay_interface {
|
2012-07-02 03:49:54 +00:00
|
|
|
struct sched_ent alarm;
|
2012-11-09 03:10:55 +00:00
|
|
|
char name[256];
|
2012-07-31 08:19:24 +00:00
|
|
|
int recv_offset;
|
2011-08-14 08:36:39 +00:00
|
|
|
int fileP;
|
2011-08-08 06:41:05 +00:00
|
|
|
int bits_per_second;
|
|
|
|
int port;
|
|
|
|
int type;
|
|
|
|
/* Number of milli-seconds per tick for this interface, which is basically related to the
|
2012-07-02 03:49:54 +00:00
|
|
|
the typical TX range divided by the maximum expected speed of nodes in the network.
|
|
|
|
This means that short-range communications has a higher bandwidth requirement than
|
|
|
|
long-range communications because the tick interval has to be shorter to still allow
|
|
|
|
fast-convergence time to allow for mobility.
|
|
|
|
|
|
|
|
For wifi (nominal range 100m) it is usually 500ms.
|
|
|
|
For ~100K ISM915MHz (nominal range 1000m) it will probably be about 5000ms.
|
|
|
|
For ~10K ISM915MHz (nominal range ~3000m) it will probably be about 15000ms.
|
|
|
|
These figures will be refined over time, and we will allow people to set them per-interface.
|
|
|
|
*/
|
2011-08-20 09:36:15 +00:00
|
|
|
int tick_ms; /* milliseconds per tick */
|
2012-08-30 00:04:52 +00:00
|
|
|
int send_broadcasts;
|
2011-08-08 14:41:46 +00:00
|
|
|
/* The time of the last tick on this interface in milli seconds */
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t last_tick_ms;
|
2011-08-15 07:27:29 +00:00
|
|
|
/* How many times have we abbreviated our address since we last announced it in full? */
|
|
|
|
int ticks_since_sent_full_address;
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-05-14 06:14:36 +00:00
|
|
|
/* sequence number of last packet sent on this interface.
|
2012-07-02 03:49:54 +00:00
|
|
|
Used to allow NACKs that can request retransmission of recent packets.
|
|
|
|
*/
|
2011-08-12 06:34:56 +00:00
|
|
|
int sequence_number;
|
2012-05-14 06:14:36 +00:00
|
|
|
/* XXX need recent packet buffers to support the above */
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-07-25 07:23:44 +00:00
|
|
|
/* We need to make sure that interface name and broadcast address is unique for all interfaces that are UP.
|
|
|
|
We bind a separate socket per interface / broadcast address Broadcast address and netmask, if known
|
2012-07-02 03:49:54 +00:00
|
|
|
We really only case about distinct broadcast addresses on interfaces.
|
|
|
|
Also simplifies aliases on interfaces. */
|
2012-07-25 07:23:44 +00:00
|
|
|
struct sockaddr_in address;
|
2011-08-08 14:41:46 +00:00
|
|
|
struct sockaddr_in broadcast_address;
|
2012-08-08 05:27:27 +00:00
|
|
|
struct in_addr netmask;
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2011-08-08 14:41:46 +00:00
|
|
|
/* Not necessarily the real MTU, but the largest frame size we are willing to TX on this interface.
|
2012-07-02 03:49:54 +00:00
|
|
|
For radio links the actual maximum and the maximum that is likely to be delivered reliably are
|
|
|
|
potentially two quite different values. */
|
2011-08-08 14:41:46 +00:00
|
|
|
int mtu;
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-07-25 07:23:44 +00:00
|
|
|
/* Use one of the INTERFACE_STATE_* constants to indicate the state of this interface.
|
|
|
|
If the interface stops working or disappears, it will be marked as DOWN and the socket closed.
|
|
|
|
But if it comes back up again, we should try to reuse this structure, even if the broadcast address has changed.
|
|
|
|
*/
|
|
|
|
int state;
|
2011-08-08 06:41:05 +00:00
|
|
|
} overlay_interface;
|
|
|
|
|
|
|
|
/* Maximum interface count is rather arbitrary.
|
2012-07-02 03:49:54 +00:00
|
|
|
Memory consumption is O(n) with respect to this parameter, so let's not make it too big for now.
|
|
|
|
*/
|
2011-08-08 06:41:05 +00:00
|
|
|
extern overlay_interface overlay_interfaces[OVERLAY_MAX_INTERFACES];
|
2012-01-08 17:49:52 +00:00
|
|
|
extern int overlay_last_interface_number; // used to remember where a packet came from
|
2011-08-20 09:36:15 +00:00
|
|
|
extern unsigned int overlay_sequence_number;
|
2011-08-08 06:41:05 +00:00
|
|
|
|
2012-07-03 06:06:51 +00:00
|
|
|
ssize_t recvwithttl(int sock, unsigned char *buffer, size_t bufferlen, int *ttl, struct sockaddr *recvaddr, socklen_t *recvaddrlen);
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-10-09 03:19:23 +00:00
|
|
|
// is the SID entirely 0xFF?
|
|
|
|
#define is_sid_broadcast(SID) is_all_matching(SID, SID_SIZE, 0xFF)
|
|
|
|
|
|
|
|
// is the SID entirely 0x00?
|
|
|
|
#define is_sid_any(SID) is_all_matching(SID, SID_SIZE, 0)
|
2012-09-19 06:25:29 +00:00
|
|
|
|
2012-07-12 06:44:25 +00:00
|
|
|
int str_is_subscriber_id(const char *sid);
|
|
|
|
int strn_is_subscriber_id(const char *sid, size_t *lenp);
|
2012-07-23 02:53:17 +00:00
|
|
|
int str_is_did(const char *did);
|
|
|
|
int strn_is_did(const char *did, size_t *lenp);
|
2012-07-23 08:59:57 +00:00
|
|
|
int str_is_uri(const char *uri);
|
2012-07-12 06:44:25 +00:00
|
|
|
|
2012-07-02 03:49:54 +00:00
|
|
|
int stowSid(unsigned char *packet, int ofs, const char *sid);
|
|
|
|
void srandomdev();
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t gettime_ms();
|
2012-08-21 04:04:29 +00:00
|
|
|
time_ms_t sleep_ms(time_ms_t milliseconds);
|
2012-07-02 03:49:54 +00:00
|
|
|
int server_pid();
|
|
|
|
void server_save_argv(int argc, const char *const *argv);
|
|
|
|
int server(char *backing_file);
|
|
|
|
int server_create_stopfile();
|
|
|
|
int server_remove_stopfile();
|
|
|
|
int server_check_stopfile();
|
|
|
|
void serverCleanUp();
|
|
|
|
int isTransactionInCache(unsigned char *transaction_id);
|
|
|
|
void insertTransactionInCache(unsigned char *transaction_id);
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
int overlay_forward_payload(struct overlay_frame *f);
|
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);
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
int overlay_frame_process(struct overlay_interface *interface, struct overlay_frame *f);
|
|
|
|
int overlay_frame_resolve_addresses(struct overlay_frame *f);
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-07-11 04:47:53 +00:00
|
|
|
#define alloca_tohex(buf,len) tohex((char *)alloca((len)*2+1), (buf), (len))
|
|
|
|
#define alloca_tohex_sid(sid) alloca_tohex((sid), SID_SIZE)
|
2012-08-14 04:36:59 +00:00
|
|
|
#define alloca_tohex_sas(sas) alloca_tohex((sas), SAS_SIZE)
|
2012-06-08 05:57:15 +00:00
|
|
|
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t overlay_time_until_next_tick();
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-11-22 22:34:42 +00:00
|
|
|
int overlay_add_selfannouncement(struct decode_context *context, int interface,struct overlay_buffer *b);
|
|
|
|
int overlay_frame_append_payload(struct decode_context *context, overlay_interface *interface,
|
|
|
|
struct overlay_frame *p, struct subscriber *next_hop, struct overlay_buffer *b);
|
2012-11-26 04:51:01 +00:00
|
|
|
int overlay_packet_init_header(struct decode_context *context, struct overlay_buffer *buff);
|
2012-11-23 05:55:32 +00:00
|
|
|
int overlay_frame_build_header(struct decode_context *context, struct overlay_buffer *buff,
|
|
|
|
int queue, int type, int modifiers, int ttl,
|
|
|
|
struct broadcast *broadcast, struct subscriber *next_hop,
|
|
|
|
struct subscriber *destination, struct subscriber *source);
|
2012-05-07 04:19:38 +00:00
|
|
|
int overlay_interface_args(const char *arg);
|
2012-11-22 22:34:42 +00:00
|
|
|
int overlay_rhizome_add_advertisements(struct decode_context *context, int interface_number, struct overlay_buffer *e);
|
2012-01-08 23:25:21 +00:00
|
|
|
int overlay_add_local_identity(unsigned char *s);
|
2011-08-08 14:41:46 +00:00
|
|
|
|
|
|
|
extern int overlay_interface_count;
|
2011-08-12 06:15:26 +00:00
|
|
|
|
2012-01-08 23:25:21 +00:00
|
|
|
extern int overlay_local_identity_count;
|
|
|
|
extern unsigned char *overlay_local_identities[OVERLAY_MAX_LOCAL_IDENTITIES];
|
|
|
|
|
2011-08-17 01:22:17 +00:00
|
|
|
int rfs_length(int l);
|
|
|
|
int rfs_encode(int l,unsigned char *b);
|
|
|
|
int rfs_decode(unsigned char *b,int *offset);
|
2011-08-15 07:27:29 +00:00
|
|
|
|
2011-09-01 13:14:30 +00:00
|
|
|
typedef struct overlay_node_observation {
|
2011-09-12 17:15:12 +00:00
|
|
|
unsigned char observed_score; /* serves as validty check also */
|
|
|
|
unsigned char corrected_score;
|
2011-09-11 10:39:47 +00:00
|
|
|
unsigned char gateways_en_route;
|
2011-09-12 17:24:03 +00:00
|
|
|
unsigned char RESERVED; /* for alignment */
|
2012-04-29 02:26:47 +00:00
|
|
|
unsigned char interface;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t rx_time;
|
2012-08-15 04:06:10 +00:00
|
|
|
struct subscriber *sender;
|
2011-08-29 06:50:27 +00:00
|
|
|
} overlay_node_observation;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct overlay_node {
|
2012-08-15 04:06:10 +00:00
|
|
|
struct subscriber *subscriber;
|
2011-08-29 06:50:27 +00:00
|
|
|
int neighbour_id; /* 0=not a neighbour */
|
|
|
|
int most_recent_observation_id;
|
2011-09-12 17:49:54 +00:00
|
|
|
int best_link_score;
|
|
|
|
int best_observation;
|
2012-04-29 02:26:47 +00:00
|
|
|
unsigned int last_first_hand_observation_time_millisec;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t last_observation_time_ms;
|
2011-09-12 17:49:54 +00:00
|
|
|
/* When did we last advertise this node on each interface, and what score
|
|
|
|
did we advertise? */
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t most_recent_advertisment_ms[OVERLAY_MAX_INTERFACES];
|
2011-09-12 17:49:54 +00:00
|
|
|
unsigned char most_recent_advertised_score[OVERLAY_MAX_INTERFACES];
|
2011-08-29 06:50:27 +00:00
|
|
|
overlay_node_observation observations[OVERLAY_MAX_OBSERVATIONS];
|
|
|
|
} overlay_node;
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
int overlay_route_saw_selfannounce_ack(struct overlay_frame *f, time_ms_t now);
|
|
|
|
int overlay_route_saw_selfannounce(struct overlay_frame *f, time_ms_t now);
|
2012-07-03 08:07:03 +00:00
|
|
|
overlay_node *overlay_route_find_node(const unsigned char *sid,int prefixLen,int createP);
|
2012-08-15 04:06:10 +00:00
|
|
|
|
2011-09-05 03:04:54 +00:00
|
|
|
int overlayServerMode();
|
2012-10-09 05:14:37 +00:00
|
|
|
int overlay_payload_enqueue(struct overlay_frame *p);
|
2012-11-26 04:12:26 +00:00
|
|
|
int overlay_route_record_link( time_ms_t now, struct subscriber *to,
|
|
|
|
struct subscriber *via,int sender_interface,
|
2012-04-29 02:26:47 +00:00
|
|
|
unsigned int s1,unsigned int s2,int score,int gateways_en_route);
|
2011-09-12 14:19:55 +00:00
|
|
|
int overlay_route_dump();
|
2012-11-22 22:34:42 +00:00
|
|
|
int overlay_route_add_advertisements(struct decode_context *context, overlay_interface *interface, struct overlay_buffer *e);
|
2011-09-12 19:22:52 +00:00
|
|
|
int ovleray_route_please_advertise(overlay_node *n);
|
|
|
|
|
2012-10-09 01:34:02 +00:00
|
|
|
int overlay_route_saw_advertisements(int i, struct overlay_frame *f, struct decode_context *context, time_ms_t now);
|
2012-08-27 00:34:59 +00:00
|
|
|
int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, time_ms_t now);
|
2011-09-12 20:10:23 +00:00
|
|
|
int overlay_route_please_advertise(overlay_node *n);
|
2011-12-22 11:28:18 +00:00
|
|
|
int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
2012-05-22 03:35:29 +00:00
|
|
|
int rhizome_saw_voice_traffic();
|
2012-08-27 00:34:59 +00:00
|
|
|
int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now);
|
2011-10-16 21:41:05 +00:00
|
|
|
|
2012-08-03 07:14:05 +00:00
|
|
|
int serval_packetvisualise(XPRINTF xpf, const char *message, const unsigned char *packet, size_t len);
|
2012-01-10 11:26:07 +00:00
|
|
|
|
2012-02-15 13:08:23 +00:00
|
|
|
int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
2012-03-04 22:57:31 +00:00
|
|
|
int rhizome_opendb();
|
2012-01-10 11:26:07 +00:00
|
|
|
|
2012-07-24 06:09:36 +00:00
|
|
|
int parseCommandLine(const char *argv0, int argc, const char *const *argv);
|
2012-02-23 02:09:31 +00:00
|
|
|
|
2012-03-29 03:37:07 +00:00
|
|
|
int form_serval_instance_path(char * buf, size_t bufsiz, const char *path);
|
2012-03-29 04:33:17 +00:00
|
|
|
int create_serval_instance_dir();
|
2012-03-29 03:37:07 +00:00
|
|
|
|
2012-03-17 02:32:09 +00:00
|
|
|
int overlay_mdp_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
2012-04-19 12:23:40 +00:00
|
|
|
int overlay_mdp_reply_error(int sock,
|
|
|
|
struct sockaddr_un *recvaddr,int recvaddrlen,
|
|
|
|
int error_number,char *message);
|
2012-07-02 03:49:54 +00:00
|
|
|
extern struct sched_ent mdp_abstract;
|
|
|
|
extern struct sched_ent mdp_named;
|
2012-04-19 12:23:40 +00:00
|
|
|
|
2012-03-19 05:36:34 +00:00
|
|
|
|
|
|
|
typedef struct sockaddr_mdp {
|
|
|
|
unsigned char sid[SID_SIZE];
|
|
|
|
unsigned int port;
|
|
|
|
} sockaddr_mdp;
|
2012-10-04 23:44:24 +00:00
|
|
|
unsigned char *keyring_get_nm_bytes(unsigned char *known_sid, unsigned char *unknown_sid);
|
2012-03-19 05:36:34 +00:00
|
|
|
|
2012-04-10 03:25:46 +00:00
|
|
|
typedef struct overlay_mdp_data_frame {
|
2012-03-27 08:55:38 +00:00
|
|
|
sockaddr_mdp src;
|
2012-03-19 05:36:34 +00:00
|
|
|
sockaddr_mdp dst;
|
2012-09-28 01:58:01 +00:00
|
|
|
uint16_t payload_length;
|
|
|
|
// temporary hack to improve reliability before implementing per-packet nack's
|
|
|
|
int send_copies;
|
2012-10-09 05:39:33 +00:00
|
|
|
int queue;
|
2012-10-10 05:52:31 +00:00
|
|
|
int ttl;
|
2012-04-10 03:25:46 +00:00
|
|
|
unsigned char payload[MDP_MTU-100];
|
2012-03-28 00:58:04 +00:00
|
|
|
} overlay_mdp_data_frame;
|
2012-03-19 05:36:34 +00:00
|
|
|
|
|
|
|
typedef struct overlay_mdp_error {
|
|
|
|
unsigned int error;
|
2012-03-20 06:41:58 +00:00
|
|
|
char message[128];
|
2012-03-19 05:36:34 +00:00
|
|
|
} overlay_mdp_error;
|
|
|
|
|
2012-03-27 08:55:38 +00:00
|
|
|
typedef struct overlay_mdp_addrlist {
|
2012-07-04 02:36:15 +00:00
|
|
|
int mode;
|
2012-03-27 08:55:38 +00:00
|
|
|
unsigned int server_sid_count;
|
|
|
|
unsigned int first_sid;
|
|
|
|
unsigned int last_sid;
|
2012-07-04 02:36:15 +00:00
|
|
|
unsigned int frame_sid_count; /* how many of the following 59 slots are populated */
|
2012-03-27 08:55:38 +00:00
|
|
|
unsigned char sids[MDP_MAX_SID_REQUEST][SID_SIZE];
|
|
|
|
} overlay_mdp_addrlist;
|
|
|
|
|
2012-11-26 04:10:22 +00:00
|
|
|
struct overlay_route_record{
|
|
|
|
unsigned char sid[SID_SIZE];
|
|
|
|
int reachable;
|
|
|
|
unsigned char neighbour[SID_SIZE];
|
|
|
|
};
|
|
|
|
|
2012-04-25 21:44:01 +00:00
|
|
|
typedef struct overlay_mdp_nodeinfo {
|
|
|
|
unsigned char sid[SID_SIZE];
|
2012-08-15 04:06:10 +00:00
|
|
|
int sid_prefix_length; /* must be long enough to be unique */
|
2012-04-25 21:44:01 +00:00
|
|
|
int foundP;
|
|
|
|
int localP;
|
|
|
|
int neighbourP;
|
|
|
|
int score;
|
|
|
|
int interface_number;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t time_since_last_observation;
|
2012-04-25 21:44:01 +00:00
|
|
|
} overlay_mdp_nodeinfo;
|
|
|
|
|
2012-03-19 05:36:34 +00:00
|
|
|
typedef struct overlay_mdp_frame {
|
2012-09-28 01:58:01 +00:00
|
|
|
uint16_t packetTypeAndFlags;
|
2012-03-19 05:36:34 +00:00
|
|
|
union {
|
2012-03-28 00:58:04 +00:00
|
|
|
overlay_mdp_data_frame out;
|
|
|
|
overlay_mdp_data_frame in;
|
2012-09-28 01:58:01 +00:00
|
|
|
sockaddr_mdp bind;
|
2012-03-27 08:55:38 +00:00
|
|
|
overlay_mdp_addrlist addrlist;
|
2012-04-25 21:44:01 +00:00
|
|
|
overlay_mdp_nodeinfo nodeinfo;
|
2012-03-19 05:36:34 +00:00
|
|
|
overlay_mdp_error error;
|
|
|
|
/* 2048 is too large (causes EMSGSIZE errors on OSX, but probably fine on
|
|
|
|
Linux) */
|
2012-04-10 03:25:46 +00:00
|
|
|
char raw[MDP_MTU];
|
2012-03-19 05:36:34 +00:00
|
|
|
};
|
|
|
|
} overlay_mdp_frame;
|
|
|
|
|
2012-04-14 17:47:36 +00:00
|
|
|
int keyring_mapping_request(keyring_file *k,overlay_mdp_frame *req);
|
|
|
|
|
2012-03-28 00:58:04 +00:00
|
|
|
/* Server-side MDP functions */
|
2012-04-15 20:36:43 +00:00
|
|
|
int overlay_mdp_swap_src_dst(overlay_mdp_frame *mdp);
|
2012-03-27 08:55:38 +00:00
|
|
|
int overlay_mdp_reply(int sock,struct sockaddr_un *recvaddr,int recvaddrlen,
|
|
|
|
overlay_mdp_frame *mdpreply);
|
2012-04-14 00:08:55 +00:00
|
|
|
int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
2012-03-28 00:58:04 +00:00
|
|
|
struct sockaddr_un *recvaddr,int recvaddlen);
|
2012-08-06 07:14:36 +00:00
|
|
|
int overlay_mdp_dnalookup_reply(const sockaddr_mdp *dstaddr, const unsigned char *resolved_sid, const char *uri, const char *did, const char *name);
|
2012-03-20 17:25:13 +00:00
|
|
|
|
2012-04-13 16:44:41 +00:00
|
|
|
int urandombytes(unsigned char *x,unsigned long long xlen);
|
|
|
|
|
2012-03-22 06:45:51 +00:00
|
|
|
#ifdef MALLOC_PARANOIA
|
2012-10-16 06:16:52 +00:00
|
|
|
#define malloc(X) _serval_debug_malloc(X,__WHENCE__)
|
|
|
|
#define calloc(X,Y) _serval_debug_calloc(X,Y,__WHENCE__)
|
|
|
|
#define free(X) _serval_debug_free(X,__WHENCE__)
|
2012-03-22 06:40:27 +00:00
|
|
|
|
2012-10-16 06:16:52 +00:00
|
|
|
void *_serval_debug_malloc(unsigned int bytes, struct __sourceloc whence);
|
|
|
|
void *_serval_debug_calloc(unsigned int bytes, unsigned int count, struct __sourceloc whence);
|
|
|
|
void _serval_debug_free(void *p, struct __sourceloc whence);
|
2012-03-22 06:45:51 +00:00
|
|
|
#endif
|
2012-04-18 22:04:12 +00:00
|
|
|
|
|
|
|
|
2012-08-06 05:16:46 +00:00
|
|
|
struct vomp_call_state;
|
2012-09-27 06:57:37 +00:00
|
|
|
|
|
|
|
void set_codec_flag(int codec, unsigned char *flags);
|
|
|
|
int is_codec_set(int codec, unsigned char *flags);
|
|
|
|
|
2012-08-06 05:16:46 +00:00
|
|
|
struct vomp_call_state *vomp_find_call_by_session(int session_token);
|
2012-04-18 23:17:59 +00:00
|
|
|
int vomp_mdp_received(overlay_mdp_frame *mdp);
|
2012-04-21 11:51:26 +00:00
|
|
|
int vomp_tick_interval();
|
2012-04-24 05:57:20 +00:00
|
|
|
int vomp_sample_size(int c);
|
2012-04-24 11:19:59 +00:00
|
|
|
int vomp_codec_timespan(int c);
|
2012-05-03 18:14:41 +00:00
|
|
|
int vomp_parse_dtmf_digit(char c);
|
2012-09-25 04:01:34 +00:00
|
|
|
int vomp_dial(unsigned char *local_sid, unsigned char *remote_sid, const char *local_did, const char *remote_did);
|
2012-08-06 05:16:46 +00:00
|
|
|
int vomp_pickup(struct vomp_call_state *call);
|
|
|
|
int vomp_hangup(struct vomp_call_state *call);
|
|
|
|
int vomp_ringing(struct vomp_call_state *call);
|
2012-08-13 06:45:10 +00:00
|
|
|
int vomp_received_audio(struct vomp_call_state *call, int audio_codec, const unsigned char *audio, int audio_length);
|
2012-09-27 06:57:37 +00:00
|
|
|
void monitor_get_all_supported_codecs(unsigned char *codecs);
|
2012-07-05 06:22:21 +00:00
|
|
|
|
2012-04-24 08:20:27 +00:00
|
|
|
int cli_putchar(char c);
|
|
|
|
int cli_puts(const char *str);
|
|
|
|
int cli_printf(const char *fmt, ...);
|
|
|
|
int cli_delim(const char *opt);
|
2012-04-20 06:11:13 +00:00
|
|
|
|
2012-07-04 09:27:02 +00:00
|
|
|
int is_configvarname(const char *arg);
|
|
|
|
|
2012-04-20 06:11:13 +00:00
|
|
|
int overlay_mdp_getmyaddr(int index,unsigned char *sid);
|
2012-04-25 10:54:08 +00:00
|
|
|
int overlay_mdp_bind(unsigned char *localaddr,int port);
|
2012-10-03 06:51:06 +00:00
|
|
|
int overlay_route_node_info(overlay_mdp_nodeinfo *node_info);
|
2012-06-08 07:31:50 +00:00
|
|
|
int overlay_interface_register(char *name,
|
2012-08-08 05:27:27 +00:00
|
|
|
struct in_addr addr,
|
|
|
|
struct in_addr mask);
|
2012-08-30 00:04:52 +00:00
|
|
|
overlay_interface * overlay_interface_find(struct in_addr addr);
|
2012-09-14 02:20:45 +00:00
|
|
|
overlay_interface * overlay_interface_find_name(const char *name);
|
2012-11-20 06:11:06 +00:00
|
|
|
int overlay_broadcast_ensemble(int interface_number,
|
|
|
|
struct sockaddr_in *recipientaddr,
|
|
|
|
unsigned char *bytes,int len);
|
2012-09-14 02:20:45 +00:00
|
|
|
|
2012-09-18 02:56:30 +00:00
|
|
|
int directory_registration();
|
|
|
|
int directory_service_init();
|
2012-04-20 06:11:13 +00:00
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
struct command_line_option;
|
2012-10-05 08:15:30 +00:00
|
|
|
int app_rhizome_direct_sync(int argc, const char *const *argv, struct command_line_option *o, void *context);
|
2012-04-23 11:28:28 +00:00
|
|
|
#ifdef HAVE_VOIPTEST
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_pa_phone(int argc, const char *const *argv, struct command_line_option *o, void *context);
|
2012-04-23 11:28:28 +00:00
|
|
|
#endif
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_monitor_cli(int argc, const char *const *argv, struct command_line_option *o, void *context);
|
2012-09-27 06:57:37 +00:00
|
|
|
int app_vomp_console(int argc, const char *const *argv, struct command_line_option *o, void *context);
|
2012-05-02 16:58:39 +00:00
|
|
|
|
|
|
|
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
|
|
|
|
|
|
|
int monitor_setup_sockets();
|
|
|
|
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
2012-07-03 08:07:03 +00:00
|
|
|
int monitor_announce_peer(const unsigned char *sid);
|
2012-07-17 08:52:39 +00:00
|
|
|
int monitor_announce_unreachable_peer(const unsigned char *sid);
|
2012-06-25 05:30:07 +00:00
|
|
|
int monitor_tell_clients(char *msg, int msglen, int mask);
|
2012-08-08 01:26:05 +00:00
|
|
|
int monitor_tell_formatted(int mask, char *fmt, ...);
|
2012-08-06 05:16:46 +00:00
|
|
|
int monitor_client_interested(int mask);
|
2012-05-02 17:30:34 +00:00
|
|
|
extern int monitor_socket_count;
|
2012-05-09 18:16:27 +00:00
|
|
|
|
2012-05-10 07:28:25 +00:00
|
|
|
|
|
|
|
typedef struct monitor_audio {
|
|
|
|
char name[128];
|
|
|
|
int (*start)();
|
|
|
|
int (*stop)();
|
|
|
|
int (*poll_fds)(struct pollfd *,int);
|
|
|
|
int (*read)(unsigned char *,int);
|
|
|
|
int (*write)(unsigned char *,int);
|
|
|
|
} monitor_audio;
|
|
|
|
extern monitor_audio *audev;
|
|
|
|
|
|
|
|
monitor_audio *audio_msm_g1_detect();
|
|
|
|
monitor_audio *audio_alsa_detect();
|
2012-05-10 22:30:09 +00:00
|
|
|
monitor_audio *audio_reflector_detect();
|
2012-05-09 18:16:27 +00:00
|
|
|
int detectAudioDevice();
|
2012-05-10 08:59:00 +00:00
|
|
|
int getAudioPlayFd();
|
|
|
|
int getAudioRecordFd();
|
2012-05-09 18:16:27 +00:00
|
|
|
int getAudioBytes(unsigned char *buffer,
|
|
|
|
int offset,
|
|
|
|
int bufferSize);
|
|
|
|
int encodeAndDispatchRecordedAudio(int fd,int callSessionToken,
|
|
|
|
int recordCodec,
|
|
|
|
unsigned char *sampleData,
|
|
|
|
int sampleBytes);
|
2012-05-10 04:37:11 +00:00
|
|
|
int scrapeProcNetRoute();
|
2012-05-28 05:24:33 +00:00
|
|
|
int lsif();
|
2012-06-08 07:01:59 +00:00
|
|
|
int doifaddrs();
|
2012-08-09 02:44:32 +00:00
|
|
|
int bufferAudioForPlayback(int codec, time_ms_t start_time, time_ms_t end_time,
|
2012-05-10 22:30:09 +00:00
|
|
|
unsigned char *data,int dataLen);
|
|
|
|
int startAudio();
|
|
|
|
int stopAudio();
|
2012-05-21 11:15:07 +00:00
|
|
|
|
|
|
|
#define SERVER_UNKNOWN 1
|
|
|
|
#define SERVER_NOTRESPONDING 2
|
|
|
|
#define SERVER_NOTRUNNING 3
|
|
|
|
#define SERVER_RUNNING 4
|
|
|
|
int server_probe(int *pid);
|
2012-06-20 22:37:03 +00:00
|
|
|
|
2012-09-18 02:54:33 +00:00
|
|
|
int dna_helper_start();
|
2012-07-20 08:47:43 +00:00
|
|
|
int dna_helper_shutdown();
|
|
|
|
int dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char *requestorSid);
|
2012-06-20 22:37:03 +00:00
|
|
|
int dna_return_resolution(overlay_mdp_frame *mdp, unsigned char *fromSid,
|
|
|
|
const char *did,const char *name,const char *uri);
|
2012-07-23 08:59:57 +00:00
|
|
|
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
2012-06-21 01:00:08 +00:00
|
|
|
extern int sigPipeFlag;
|
|
|
|
extern int sigIoFlag;
|
|
|
|
void sigPipeHandler(int signal);
|
|
|
|
void sigIoHandler(int signal);
|
2012-06-21 05:05:05 +00:00
|
|
|
|
2012-06-25 23:52:51 +00:00
|
|
|
int overlay_mdp_setup_sockets();
|
|
|
|
|
2012-10-24 04:43:50 +00:00
|
|
|
int is_scheduled(const struct sched_ent *alarm);
|
2012-10-16 06:28:24 +00:00
|
|
|
int _schedule(struct __sourceloc whence, struct sched_ent *alarm);
|
|
|
|
int _unschedule(struct __sourceloc whence, struct sched_ent *alarm);
|
|
|
|
int _watch(struct __sourceloc whence, struct sched_ent *alarm);
|
|
|
|
int _unwatch(struct __sourceloc whence, struct sched_ent *alarm);
|
|
|
|
#define schedule(alarm) _schedule(__WHENCE__, alarm)
|
|
|
|
#define unschedule(alarm) _unschedule(__WHENCE__, alarm)
|
|
|
|
#define watch(alarm) _watch(__WHENCE__, alarm)
|
|
|
|
#define unwatch(alarm) _unwatch(__WHENCE__, alarm)
|
2012-06-22 03:55:41 +00:00
|
|
|
int fd_poll();
|
2012-07-02 03:49:54 +00:00
|
|
|
|
|
|
|
void overlay_interface_discover(struct sched_ent *alarm);
|
|
|
|
void overlay_dummy_poll(struct sched_ent *alarm);
|
|
|
|
void overlay_route_tick(struct sched_ent *alarm);
|
|
|
|
void server_shutdown_check(struct sched_ent *alarm);
|
|
|
|
void overlay_mdp_poll(struct sched_ent *alarm);
|
|
|
|
void fd_periodicstats(struct sched_ent *alarm);
|
|
|
|
void rhizome_check_connections(struct sched_ent *alarm);
|
|
|
|
|
2012-11-20 06:11:06 +00:00
|
|
|
int overlay_tick_interface(int i, time_ms_t now);
|
|
|
|
int overlay_queue_init();
|
|
|
|
|
2012-07-02 03:49:54 +00:00
|
|
|
void monitor_client_poll(struct sched_ent *alarm);
|
|
|
|
void monitor_poll(struct sched_ent *alarm);
|
|
|
|
void rhizome_client_poll(struct sched_ent *alarm);
|
|
|
|
void rhizome_fetch_poll(struct sched_ent *alarm);
|
|
|
|
void rhizome_server_poll(struct sched_ent *alarm);
|
|
|
|
|
|
|
|
/* function timing routines */
|
2012-07-03 08:30:52 +00:00
|
|
|
int fd_clearstats();
|
|
|
|
int fd_showstats();
|
2012-06-22 03:55:41 +00:00
|
|
|
int fd_checkalarms();
|
2012-11-12 04:04:30 +00:00
|
|
|
int fd_func_enter(struct __sourceloc __whence, struct call_stats *this_call);
|
|
|
|
int fd_func_exit(struct __sourceloc __whence, struct call_stats *this_call);
|
2012-07-12 00:45:16 +00:00
|
|
|
void dump_stack();
|
|
|
|
|
|
|
|
#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \
|
|
|
|
struct call_stats _this_call; \
|
|
|
|
_this_call.totals=&_aggregate_stats; \
|
2012-11-12 04:04:30 +00:00
|
|
|
fd_func_enter(__HERE__, &_this_call);
|
2012-07-02 03:49:54 +00:00
|
|
|
|
2012-11-12 04:04:30 +00:00
|
|
|
#define OUT() fd_func_exit(__HERE__, &_this_call)
|
2012-10-11 07:28:24 +00:00
|
|
|
#define RETURN(X) do { OUT(); return (X); } while (0);
|
|
|
|
#define RETURNNULL do { OUT(); return (NULL); } while (0);
|
2012-07-30 03:28:21 +00:00
|
|
|
|
2012-08-31 05:28:40 +00:00
|
|
|
int olsr_init_socket(void);
|
|
|
|
int olsr_send(struct overlay_frame *frame);
|
|
|
|
|
2012-07-30 03:28:21 +00:00
|
|
|
#endif // __SERVALD_SERVALD_H
|