]> git.meshlink.io Git - meshlink/blob - src/net.h
Propagate the discovered PMTU between nodes to UTCP.
[meshlink] / src / net.h
1 #ifndef MESHLINK_NET_H
2 #define MESHLINK_NET_H
3
4 /*
5     net.h -- header for net.c
6     Copyright (C) 2014, 2017 Guus Sliepen <guus@meshlink.io>
7
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.
12
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.
17
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.
21 */
22
23 #include "event.h"
24 #include "sockaddr.h"
25
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 */
29 #else
30 #define MTU 1451        /* 1500 bytes payload - 28 bytes IP+UDP - 21 bytes SPTPS header+MAC */
31 #endif
32
33 #define MINMTU 527      /* 576 minimum recommended Internet MTU - 28 bytes IP+UDP - 21 bytes SPTPS header+MAC */
34
35 /* MAXSIZE is the maximum size of an encapsulated packet */
36 #define MAXSIZE (MTU + 64)
37
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)
40
41 typedef struct vpn_packet_t {
42         uint16_t probe: 1;
43         int16_t tcp: 1;
44         uint16_t len;           /* the actual number of bytes in the `data' field */
45         uint8_t data[MAXSIZE];
46 } vpn_packet_t;
47
48 /* Packet types when using SPTPS */
49
50 #define PKT_COMPRESSED 1
51 #define PKT_PROBE 4
52
53 typedef enum packet_type_t {
54         PACKET_NORMAL,
55         PACKET_COMPRESSED,
56         PACKET_PROBE
57 } packet_type_t;
58
59 #include "conf.h"
60 #include "list.h"
61
62 typedef struct outgoing_t {
63         struct node_t *node;
64         enum {
65                 OUTGOING_START,
66                 OUTGOING_CANONICAL,
67                 OUTGOING_RECENT,
68                 OUTGOING_KNOWN,
69                 OUTGOING_END,
70                 OUTGOING_NO_KNOWN_ADDRESSES,
71         } state;
72         int timeout;
73         timeout_t ev;
74         struct addrinfo *ai;
75         struct addrinfo *aip;
76 } outgoing_t;
77
78 /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
79 #include "connection.h"
80 #include "node.h"
81
82 extern void init_outgoings(struct meshlink_handle *mesh);
83 extern void exit_outgoings(struct meshlink_handle *mesh);
84
85 extern void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *);
86 extern void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int);
87 extern void finish_connecting(struct meshlink_handle *mesh, struct connection_t *);
88 extern void do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
89 extern void handle_new_meta_connection(struct event_loop_t *loop, void *, int);
90 extern int setup_tcp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__));
91 extern int setup_udp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__));
92 extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
93 extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len) __attribute__((__warn_unused_result__));
94 extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
95 extern char *get_name(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
96 extern void load_all_nodes(struct meshlink_handle *mesh);
97 extern bool setup_myself_reloadable(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
98 extern bool setup_network(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
99 extern void reset_outgoing(struct outgoing_t *);
100 extern void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
101 extern void close_network_connections(struct meshlink_handle *mesh);
102 extern void main_loop(struct meshlink_handle *mesh);
103 extern void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool);
104 extern bool node_read_public_key(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
105 extern bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config) __attribute__((__warn_unused_result__));
106 extern bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
107 extern bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
108 extern bool node_write_config(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
109 extern void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *);
110 extern void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *);
111 extern void retry(struct meshlink_handle *mesh);
112 extern int check_port(struct meshlink_handle *mesh);
113
114 #ifndef HAVE_MINGW
115 #define closesocket(s) close(s)
116 #endif
117
118 #endif