5 net.h -- header for net.c
6 Copyright (C) 2014, 2017 Guus Sliepen <guus@meshlink.io>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifdef ENABLE_JUMBOGRAMS
27 #define MTU 9018 /* 9000 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
29 #define MTU 1518 /* 1500 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
32 /* MAXSIZE is the maximum size of an encapsulated packet: MTU + seqno + HMAC + compressor overhead */
33 #define MAXSIZE (MTU + 4 + 32 + MTU/64 + 20)
35 /* MAXBUFSIZE is the maximum size of a request: enough for a MAXSIZEd packet or a 8192 bits RSA key */
36 #define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128)
38 typedef struct vpn_packet_t {
40 unsigned int probe: 1;
43 uint16_t len; /* the actual number of bytes in the `data' field */
44 uint8_t data[MAXSIZE];
47 /* Packet types when using SPTPS */
49 #define PKT_COMPRESSED 1
52 typedef enum packet_type_t {
61 typedef struct outgoing_t {
63 struct splay_tree_t *config_tree;
71 OUTGOING_NO_KNOWN_ADDRESSES,
77 struct meshlink_handle *mesh;
80 extern int maxoutbufsize;
81 extern int addressfamily;
83 extern int keylifetime;
84 extern int max_connection_burst;
87 /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
88 #include "connection.h"
91 extern void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *);
92 extern void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int);
93 extern void finish_connecting(struct meshlink_handle *mesh, struct connection_t *);
94 extern bool do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
95 extern void handle_new_meta_connection(struct event_loop_t *loop, void *, int);
96 extern int setup_listen_socket(const sockaddr_t *);
97 extern int setup_vpn_in_socket(struct meshlink_handle *mesh, const sockaddr_t *);
98 extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
99 extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len);
100 extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
101 extern void broadcast_packet(struct meshlink_handle *mesh, const struct node_t *, struct vpn_packet_t *);
102 extern char *get_name(struct meshlink_handle *mesh);
103 extern void load_all_nodes(struct meshlink_handle *mesh);
104 extern bool setup_myself_reloadable(struct meshlink_handle *mesh);
105 extern bool setup_network(struct meshlink_handle *mesh);
106 extern void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
107 extern void try_outgoing_connections(struct meshlink_handle *mesh);
108 extern void close_network_connections(struct meshlink_handle *mesh);
109 extern int main_loop(struct meshlink_handle *mesh);
110 extern void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool);
111 extern bool node_read_ecdsa_public_key(struct meshlink_handle *mesh, struct node_t *);
112 extern bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *);
113 extern bool read_ecdsa_private_key(struct meshlink_handle *mesh);
114 extern void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *);
115 extern void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *);
116 extern void retry(struct meshlink_handle *mesh);
119 #define closesocket(s) close(s)