]> git.meshlink.io Git - meshlink/blob - src/protocol.h
Remove everything GPL that is not copyright Guus Sliepen, update copyright statements.
[meshlink] / src / protocol.h
1 /*
2     protocol.h -- header for protocol.c
3     Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef __TINC_PROTOCOL_H__
21 #define __TINC_PROTOCOL_H__
22
23 #include "ecdsa.h"
24
25 /* Protocol version. Different major versions are incompatible. */
26
27 #define PROT_MAJOR 17
28 #define PROT_MINOR 3 /* Should not exceed 255! */
29
30 /* Silly Windows */
31
32 #ifdef ERROR
33 #undef ERROR
34 #endif
35
36 /* Request numbers */
37
38 typedef enum request_t {
39         ALL = -1,                                       /* Guardian for allow_request */
40         ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
41         STATUS, ERROR, TERMREQ,
42         PING, PONG,
43         ADD_SUBNET, DEL_SUBNET,
44         ADD_EDGE, DEL_EDGE,
45         KEY_CHANGED, REQ_KEY, ANS_KEY,
46         PACKET,
47         /* Tinc 1.1 requests */
48         CONTROL,
49         REQ_PUBKEY, ANS_PUBKEY,
50         REQ_SPTPS,
51         LAST                                            /* Guardian for the highest request number */
52 } request_t;
53
54 typedef struct past_request_t {
55         const char *request;
56         time_t firstseen;
57 } past_request_t;
58
59 extern bool experimental;
60
61 extern ecdsa_t *invitation_key;
62
63 /* Maximum size of strings in a request.
64  * scanf terminates %2048s with a NUL character,
65  * but the NUL character can be written after the 2048th non-NUL character.
66  */
67
68 #define MAX_STRING_SIZE 2049
69 #define MAX_STRING "%2048s"
70
71 #include "edge.h"
72 #include "net.h"
73 #include "node.h"
74
75 /* Basic functions */
76
77 extern bool send_request(struct connection_t *, const char *, ...) __attribute__ ((__format__(printf, 2, 3)));
78 extern void forward_request(struct connection_t *, const char *);
79 extern bool receive_request(struct connection_t *, const char *);
80 extern bool check_id(const char *);
81
82 extern void init_requests(void);
83 extern void exit_requests(void);
84 extern bool seen_request(const char *);
85
86 /* Requests */
87
88 extern bool send_id(struct connection_t *);
89 extern bool send_metakey(struct connection_t *);
90 extern bool send_metakey_ec(struct connection_t *);
91 extern bool send_challenge(struct connection_t *);
92 extern bool send_chal_reply(struct connection_t *);
93 extern bool send_ack(struct connection_t *);
94 extern bool send_status(struct connection_t *, int, const char *);
95 extern bool send_error(struct connection_t *, int, const  char *);
96 extern bool send_termreq(struct connection_t *);
97 extern bool send_ping(struct connection_t *);
98 extern bool send_pong(struct connection_t *);
99 extern bool send_add_edge(struct connection_t *, const struct edge_t *);
100 extern bool send_del_edge(struct connection_t *, const struct edge_t *);
101 extern void send_key_changed(void);
102 extern bool send_req_key(struct node_t *);
103 extern bool send_ans_key(struct node_t *);
104 extern bool send_tcppacket(struct connection_t *, const struct vpn_packet_t *);
105
106 /* Request handlers  */
107
108 extern bool id_h(struct connection_t *, const char *);
109 extern bool metakey_h(struct connection_t *, const char *);
110 extern bool challenge_h(struct connection_t *, const char *);
111 extern bool chal_reply_h(struct connection_t *, const char *);
112 extern bool ack_h(struct connection_t *, const char *);
113 extern bool status_h(struct connection_t *, const char *);
114 extern bool error_h(struct connection_t *, const char *);
115 extern bool termreq_h(struct connection_t *, const char *);
116 extern bool ping_h(struct connection_t *, const char *);
117 extern bool pong_h(struct connection_t *, const char *);
118 extern bool add_edge_h(struct connection_t *, const char *);
119 extern bool del_edge_h(struct connection_t *, const char *);
120 extern bool key_changed_h(struct connection_t *, const char *);
121 extern bool req_key_h(struct connection_t *, const char *);
122 extern bool ans_key_h(struct connection_t *, const char *);
123 extern bool tcppacket_h(struct connection_t *, const char *);
124
125 #endif /* __TINC_PROTOCOL_H__ */