X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fnet.h;h=cae63bf12a33795bf763d72fbf3a33e32df676ea;hp=432825fe099e58bcc10586170a04ef263dab3a06;hb=b70b090a28ff4cbdce29a3ad030f7d51ce9079b2;hpb=f7bacce5e9fb1363a503970b00d601c3d1d7bd12 diff --git a/src/net.h b/src/net.h index 432825fe..cae63bf1 100644 --- a/src/net.h +++ b/src/net.h @@ -1,6 +1,9 @@ +#ifndef MESHLINK_NET_H +#define MESHLINK_NET_H + /* net.h -- header for net.c - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014, 2017 Guus Sliepen 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 @@ -17,11 +20,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __TINC_NET_H__ -#define __TINC_NET_H__ - -#include "cipher.h" -#include "digest.h" #include "event.h" #include "sockaddr.h" @@ -31,19 +29,15 @@ #define MTU 1518 /* 1500 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */ #endif -/* MAXSIZE is the maximum size of an encapsulated packet: MTU + seqno + padding + HMAC + compressor overhead */ -#define MAXSIZE (MTU + 4 + CIPHER_MAX_BLOCK_SIZE + DIGEST_MAX_SIZE + MTU/64 + 20) +/* MAXSIZE is the maximum size of an encapsulated packet: MTU + seqno + HMAC + compressor overhead */ +#define MAXSIZE (MTU + 4 + 32 + MTU/64 + 20) /* MAXBUFSIZE is the maximum size of a request: enough for a MAXSIZEd packet or a 8192 bits RSA key */ #define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128) -#define MAXSOCKETS 8 /* Probably overkill... */ - typedef struct vpn_packet_t { - struct { - unsigned int probe:1; - unsigned int tcp:1; - }; + uint16_t probe: 1; + int16_t tcp: 1; uint16_t len; /* the actual number of bytes in the `data' field */ uint8_t data[MAXSIZE]; } vpn_packet_t; @@ -59,77 +53,63 @@ typedef enum packet_type_t { PACKET_PROBE } packet_type_t; -typedef struct listen_socket_t { - struct io_t tcp; - struct io_t udp; - sockaddr_t sa; - bool bindto; -} listen_socket_t; - #include "conf.h" #include "list.h" typedef struct outgoing_t { - char *name; + struct node_t *node; + enum { + OUTGOING_START, + OUTGOING_CANONICAL, + OUTGOING_RECENT, + OUTGOING_KNOWN, + OUTGOING_END, + OUTGOING_NO_KNOWN_ADDRESSES, + } state; int timeout; - struct splay_tree_t *config_tree; - struct config_t *cfg; + timeout_t ev; struct addrinfo *ai; struct addrinfo *aip; - timeout_t ev; } outgoing_t; -extern int maxoutbufsize; -extern int addressfamily; -extern unsigned replaywin; - -extern listen_socket_t listen_socket[MAXSOCKETS]; -extern int listen_sockets; -extern int keylifetime; -extern int max_connection_burst; -extern bool do_prune; -extern int autoconnect; - /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */ #include "connection.h" #include "node.h" -extern void retry_outgoing(outgoing_t *); -extern void handle_incoming_vpn_data(void *, int); -extern void finish_connecting(struct connection_t *); -extern bool do_outgoing_connection(struct outgoing_t *); -extern void handle_new_meta_connection(void *, int); -extern int setup_listen_socket(const sockaddr_t *); -extern int setup_vpn_in_socket(const sockaddr_t *); -extern bool send_sptps_data(void *handle, uint8_t type, const char *data, size_t len); -extern bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t len); -extern void send_packet(struct node_t *, struct vpn_packet_t *); -extern void receive_tcppacket(struct connection_t *, const char *, int); -extern void broadcast_packet(const struct node_t *, struct vpn_packet_t *); -extern char *get_name(void); -extern bool setup_myself_reloadable(void); -extern bool setup_network(void); -extern void setup_outgoing_connection(struct outgoing_t *); -extern void try_outgoing_connections(void); -extern void close_network_connections(void); -extern int main_loop(void); -extern void terminate_connection(struct connection_t *, bool); -extern bool node_read_ecdsa_public_key(struct node_t *); -extern bool read_ecdsa_public_key(struct connection_t *); -extern void send_mtu_probe(struct node_t *); -extern void handle_device_data(void *, int); -extern void handle_meta_connection_data(struct connection_t *); -extern void regenerate_key(void); -extern void purge(void); -extern void retry(void); -extern int reload_configuration(void); -extern void load_all_subnets(void); -extern void load_all_nodes(void); +extern void init_outgoings(struct meshlink_handle *mesh); +extern void exit_outgoings(struct meshlink_handle *mesh); + +extern void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *); +extern void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int); +extern void finish_connecting(struct meshlink_handle *mesh, struct connection_t *); +extern void do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *); +extern void handle_new_meta_connection(struct event_loop_t *loop, void *, int); +extern int setup_tcp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__)); +extern int setup_udp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__)); +extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len); +extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len) __attribute__((__warn_unused_result__)); +extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *); +extern char *get_name(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern void load_all_nodes(struct meshlink_handle *mesh); +extern bool setup_myself_reloadable(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern bool setup_network(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern void reset_outgoing(struct outgoing_t *); +extern void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *); +extern void close_network_connections(struct meshlink_handle *mesh); +extern void main_loop(struct meshlink_handle *mesh); +extern void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool); +extern bool node_read_public_key(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__)); +extern bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config) __attribute__((__warn_unused_result__)); +extern bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__)); +extern bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); +extern bool node_write_config(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__)); +extern void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *); +extern void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *); +extern void retry(struct meshlink_handle *mesh); +extern int check_port(struct meshlink_handle *mesh); #ifndef HAVE_MINGW #define closesocket(s) close(s) -#else -extern CRITICAL_SECTION mutex; #endif -#endif /* __TINC_NET_H__ */ +#endif