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 {
44 uint16_t len; /* the actual number of bytes in the `data' field */
45 uint8_t data[MAXSIZE];
48 /* Packet types when using SPTPS */
50 #define PKT_COMPRESSED 1
53 typedef enum packet_type_t {
62 typedef struct outgoing_t {
66 OUTGOING_CANONICAL_RESOLVE,
71 OUTGOING_NO_KNOWN_ADDRESSES,
79 /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
80 #include "connection.h"
83 void init_outgoings(struct meshlink_handle *mesh);
84 void exit_outgoings(struct meshlink_handle *mesh);
86 void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *);
87 void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int);
88 void finish_connecting(struct meshlink_handle *mesh, struct connection_t *);
89 void do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
90 void handle_new_meta_connection(struct event_loop_t *loop, void *, int);
91 bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
92 bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len) __attribute__((__warn_unused_result__));
93 void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
94 char *get_name(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
95 void load_all_nodes(struct meshlink_handle *mesh);
96 bool setup_myself_reloadable(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
97 bool setup_network(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
98 void reset_outgoing(struct outgoing_t *);
99 void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
100 void close_network_connections(struct meshlink_handle *mesh);
101 void main_loop(struct meshlink_handle *mesh);
102 void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool);
103 bool node_read_public_key(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
104 bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config) __attribute__((__warn_unused_result__));
105 bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
106 bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
107 bool node_write_config(struct meshlink_handle *mesh, struct node_t *, bool new_key) __attribute__((__warn_unused_result__));
108 void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *);
109 void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *);
110 void retry(struct meshlink_handle *mesh);
111 void flush_meta(struct meshlink_handle *mesh, struct connection_t *);
114 #define closesocket(s) close(s)