]> git.meshlink.io Git - meshlink-tiny/blob - src/net.h
ec37eaad6d9eb480bc002fdb7694ac88b74845fd
[meshlink-tiny] / 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 len;           /* the actual number of bytes in the `data' field */
43         uint8_t data[MAXSIZE];
44 } vpn_packet_t;
45
46 #include "conf.h"
47 #include "list.h"
48
49 typedef struct outgoing_t {
50         struct node_t *node;
51         enum {
52                 OUTGOING_START,
53                 OUTGOING_CANONICAL_RESOLVE,
54                 OUTGOING_CANONICAL,
55                 OUTGOING_RECENT,
56                 OUTGOING_KNOWN,
57                 OUTGOING_END,
58                 OUTGOING_NO_KNOWN_ADDRESSES,
59         } state;
60         int timeout;
61         timeout_t ev;
62         struct addrinfo *ai;
63         struct addrinfo *aip;
64 } outgoing_t;
65
66 /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
67 #include "connection.h"
68 #include "node.h"
69
70 void init_outgoings(struct meshlink_handle *mesh);
71 void exit_outgoings(struct meshlink_handle *mesh);
72
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 *);
94
95 #ifndef HAVE_MINGW
96 #define closesocket(s) close(s)
97 #endif
98
99 #endif