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 /* Maximum size of SPTPS payload */
27 #ifdef ENABLE_JUMBOGRAMS
28 #define MTU 8951 /* 9000 bytes payload - 28 bytes IP+UDP header - 21 bytes SPTPS header+MAC */
30 #define MTU 1451 /* 1500 bytes payload - 28 bytes IP+UDP - 21 bytes SPTPS header+MAC */
33 #define MINMTU 527 /* 576 minimum recommended Internet MTU - 28 bytes IP+UDP - 21 bytes SPTPS header+MAC */
35 /* MAXSIZE is the maximum size of an encapsulated packet */
36 #define MAXSIZE (MTU + 64)
38 /* MAXBUFSIZE is the maximum size of a request: enough for a base64 encoded MAXSIZEd packet plus request header */
39 #define MAXBUFSIZE ((MAXSIZE * 8) / 6 + 128)
41 typedef struct vpn_packet_t {
42 uint16_t len; /* the actual number of bytes in the `data' field */
43 uint8_t data[MAXSIZE];
49 typedef struct outgoing_t {
53 OUTGOING_CANONICAL_RESOLVE,
58 OUTGOING_NO_KNOWN_ADDRESSES,
66 /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
67 #include "connection.h"
70 void init_outgoings(struct meshlink_handle *mesh);
71 void exit_outgoings(struct meshlink_handle *mesh);
73 void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *);
74 void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int);
75 void finish_connecting(struct meshlink_handle *mesh, struct connection_t *);
76 void do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
77 void handle_new_meta_connection(struct event_loop_t *loop, void *, int);
78 void load_all_nodes(struct meshlink_handle *mesh);
79 bool setup_myself_reloadable(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
80 bool setup_network(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
81 void reset_outgoing(struct outgoing_t *);
82 void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
83 void close_network_connections(struct meshlink_handle *mesh);
84 void main_loop(struct meshlink_handle *mesh);
85 void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool);
86 bool node_read_public_key(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
87 bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config) __attribute__((__warn_unused_result__));
88 bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
89 bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
90 bool node_write_config(struct meshlink_handle *mesh, struct node_t *, bool new_key) __attribute__((__warn_unused_result__));
91 void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *);
92 void retry(struct meshlink_handle *mesh);
93 void flush_meta(struct meshlink_handle *mesh, struct connection_t *);
96 #define closesocket(s) close(s)