mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
273 lines
9.0 KiB
C
273 lines
9.0 KiB
C
/*
|
|
Serval DNA header file
|
|
Copyright (C) 2010-2012 Paul Gardner-Stephen
|
|
Copyright (C) 2012-2013 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.
|
|
*/
|
|
|
|
/*
|
|
Portions Copyright (C) 2013 Petter Reinholdtsen
|
|
Some rights reserved
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in
|
|
the documentation and/or other materials provided with the
|
|
distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef __SERVAL_DNA__SERVAL_H
|
|
#define __SERVAL_DNA__SERVAL_H
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <sys/types.h>
|
|
|
|
#ifdef WIN32
|
|
# include "win32/win32.h"
|
|
#else
|
|
# include <unistd.h>
|
|
# ifdef HAVE_SYS_SOCKET_H
|
|
# include <sys/socket.h>
|
|
# endif
|
|
# ifdef HAVE_NET_ROUTE_H
|
|
# include <net/route.h>
|
|
# endif
|
|
# ifdef HAVE_LINUX_IF_H
|
|
# include <linux/if.h>
|
|
# else
|
|
# ifdef HAVE_NET_IF_H
|
|
# include <net/if.h>
|
|
# endif
|
|
# endif
|
|
# 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
|
|
# ifdef HAVE_SYS_SOCKIO_H
|
|
# include <sys/sockio.h>
|
|
# endif
|
|
# ifdef HAVE_SYS_UCRED_H
|
|
# include <sys/ucred.h>
|
|
# endif
|
|
#endif //!WIN32
|
|
|
|
#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_NETDB_H
|
|
#include <netdb.h>
|
|
#endif
|
|
#ifdef HAVE_CTYPE_H
|
|
#include <ctype.h>
|
|
#endif
|
|
|
|
#ifndef WIN32
|
|
#include <sys/ioctl.h>
|
|
#include <sys/un.h>
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include "constants.h"
|
|
#include "cli.h"
|
|
#include "serval_types.h"
|
|
#include "sighandlers.h"
|
|
#include "instance.h"
|
|
#include "fdqueue.h"
|
|
#include "mem.h"
|
|
#include "xprintf.h"
|
|
#include "log.h"
|
|
#include "net.h"
|
|
#include "os.h"
|
|
|
|
#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
|
|
|
|
int rhizome_enabled();
|
|
int rhizome_http_server_running();
|
|
|
|
#define MAX_PEERS 1024
|
|
extern int peer_count;
|
|
extern struct in_addr peers[MAX_PEERS];
|
|
|
|
struct subscriber;
|
|
struct decode_context;
|
|
struct socket_address;
|
|
struct overlay_interface;
|
|
struct network_destination;
|
|
struct internal_mdp_header;
|
|
|
|
struct overlay_buffer;
|
|
struct overlay_frame;
|
|
struct broadcast;
|
|
|
|
void overlay_mdp_clean_socket_files();
|
|
int mdp_send_external_packet(struct overlay_interface *interface, struct socket_address *address, const uint8_t *payload, size_t len);
|
|
|
|
int overlay_forward_payload(struct overlay_frame *f);
|
|
int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, size_t len,
|
|
struct socket_address *recvaddr);
|
|
int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *frame,
|
|
struct overlay_buffer *buffer, struct subscriber **nexthop);
|
|
int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface *interface,
|
|
struct socket_address *addr, struct overlay_buffer *buffer);
|
|
int process_incoming_frame(time_ms_t now, struct overlay_interface *interface,
|
|
struct overlay_frame *f, struct decode_context *context);
|
|
|
|
int overlay_frame_process(struct overlay_interface *interface, struct overlay_frame *f);
|
|
|
|
int overlay_frame_append_payload(struct decode_context *context, int encapsulation,
|
|
struct overlay_frame *p, struct subscriber *next_hop,
|
|
struct overlay_buffer *b, char will_retransmit);
|
|
int overlay_packet_init_header(int packet_version, int encapsulation,
|
|
struct decode_context *context, struct overlay_buffer *buff,
|
|
char unicast, char interface, int seq);
|
|
void rhizome_sync_status_html(struct strbuf *b, struct subscriber *subscriber);
|
|
int rhizome_cache_count();
|
|
|
|
int overlayServerMode(void);
|
|
int _overlay_payload_enqueue(struct __sourceloc whence, struct overlay_frame *p);
|
|
#define overlay_payload_enqueue(P) _overlay_payload_enqueue(__WHENCE__,P)
|
|
int overlay_queue_remaining(int queue);
|
|
int overlay_queue_schedule_next(time_ms_t next_allowed_packet);
|
|
int overlay_send_tick_packet(struct network_destination *destination);
|
|
int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *destination, uint32_t ack_mask, int ack_seq);
|
|
|
|
int overlay_rhizome_saw_advertisements(struct decode_context *context, struct overlay_frame *f);
|
|
int rhizome_saw_voice_traffic();
|
|
int overlay_saw_mdp_containing_frame(struct overlay_frame *f);
|
|
|
|
int serval_packetvisualise(const char *message, const unsigned char *packet, size_t len);
|
|
int serval_packetvisualise_xpf(XPRINTF xpf, const char *message, const unsigned char *packet, size_t len);
|
|
void logServalPacket(int level, struct __sourceloc __whence, const char *message, const unsigned char *packet, size_t len);
|
|
#define DEBUG_packet_visualise(M,P,N) logServalPacket(LOG_LEVEL_DEBUG, __WHENCE__, (M), (P), (N))
|
|
|
|
int rhizome_opendb();
|
|
|
|
int allow_inbound_packet(const struct internal_mdp_header *header);
|
|
int allow_outbound_packet(const struct internal_mdp_header *header);
|
|
void load_mdp_packet_rules(const char *filename);
|
|
|
|
struct vomp_call_state;
|
|
|
|
void set_codec_flag(int codec, unsigned char *flags);
|
|
|
|
struct vomp_call_state *vomp_find_call_by_session(uint16_t session_token);
|
|
int vomp_parse_dtmf_digit(char c);
|
|
int vomp_dial(struct subscriber *local, struct subscriber *remote, const char *local_did, const char *remote_did);
|
|
int vomp_pickup(struct vomp_call_state *call);
|
|
int vomp_hangup(struct vomp_call_state *call);
|
|
int vomp_ringing(struct vomp_call_state *call);
|
|
int vomp_received_audio(struct vomp_call_state *call, int audio_codec, int time, int sequence,
|
|
const unsigned char *audio, int audio_length);
|
|
void monitor_get_all_supported_codecs(unsigned char *codecs);
|
|
|
|
int directory_registration();
|
|
|
|
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
|
|
|
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
|
int monitor_tell_clients(char *msg, int msglen, int mask);
|
|
int monitor_tell_formatted(int mask, char *fmt, ...);
|
|
int monitor_client_interested(int mask);
|
|
|
|
int scrapeProcNetRoute();
|
|
int lsif();
|
|
int doifaddrs();
|
|
|
|
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
|
|
|
extern uint16_t mdp_loopback_port;
|
|
|
|
int overlay_packetradio_setup_port(struct overlay_interface *interface);
|
|
int overlay_send_probe(struct subscriber *peer, struct network_destination *destination, int queue);
|
|
int overlay_send_stun_request(struct subscriber *server, struct subscriber *request);
|
|
void rhizome_check_connections(struct sched_ent *alarm);
|
|
|
|
int overlay_queue_init();
|
|
|
|
void monitor_client_poll(struct sched_ent *alarm);
|
|
void monitor_poll(struct sched_ent *alarm);
|
|
void rhizome_fetch_poll(struct sched_ent *alarm);
|
|
void rhizome_server_poll(struct sched_ent *alarm);
|
|
|
|
int olsr_send(struct overlay_frame *frame);
|
|
|
|
int pack_uint(unsigned char *buffer, uint64_t v);
|
|
int measure_packed_uint(uint64_t v);
|
|
int unpack_uint(unsigned char *buffer, int buff_size, uint64_t *v);
|
|
|
|
void rhizome_fetch_log_short_status();
|
|
|
|
#endif // __SERVAL_DNA__SERVAL_H
|