1 #ifndef TINC_PROTOCOL_H
2 #define TINC_PROTOCOL_H
5 protocol.h -- header for protocol.c
6 Copyright (C) 1999-2005 Ivo Timmermans,
7 2000-2017 Guus Sliepen <guus@tinc-vpn.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "connection.h"
27 /* Protocol version. Different major versions are incompatible. */
32 STATIC_ASSERT(PROT_MINOR <= 255, "PROT_MINOR must not exceed 255");
42 typedef enum request_t {
43 ALL = -1, /* Guardian for allow_request */
44 ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
45 STATUS, ERROR, TERMREQ,
47 ADD_SUBNET, DEL_SUBNET,
49 KEY_CHANGED, REQ_KEY, ANS_KEY,
51 /* Tinc 1.1 requests */
53 REQ_PUBKEY, ANS_PUBKEY,
56 LAST /* Guardian for the highest request number */
59 typedef bool (request_handler_t)(connection_t *c, const char *request);
61 typedef struct past_request_t {
67 request_handler_t *const handler;
71 extern bool tunnelserver;
72 extern bool strictsubnets;
73 extern bool experimental;
75 extern int invitation_lifetime;
76 extern ecdsa_t *invitation_key;
78 /* Maximum size of strings in a request.
79 * scanf terminates %2048s with a NUL character,
80 * but the NUL character can be written after the 2048th non-NUL character.
83 #define MAX_STRING_SIZE 2049
84 #define MAX_STRING "%2048s"
93 extern bool send_request(struct connection_t *c, const char *format, ...) ATTR_FORMAT(printf, 2, 3);
94 extern void forward_request(struct connection_t *c, const char *request);
95 extern bool receive_request(struct connection_t *c, const char *request);
97 extern void exit_requests(void);
98 extern bool seen_request(const char *request);
100 extern const request_entry_t *get_request_entry(request_t req);
104 extern bool send_id(struct connection_t *c);
105 extern bool send_metakey(struct connection_t *c);
106 extern bool send_challenge(struct connection_t *c);
107 extern bool send_chal_reply(struct connection_t *c);
108 extern bool send_ack(struct connection_t *c);
109 extern bool send_termreq(struct connection_t *c);
110 extern bool send_ping(struct connection_t *c);
111 extern bool send_pong(struct connection_t *c);
112 extern bool send_add_subnet(struct connection_t *c, const struct subnet_t *subnet);
113 extern bool send_del_subnet(struct connection_t *c, const struct subnet_t *subnet);
114 extern bool send_add_edge(struct connection_t *c, const struct edge_t *e);
115 extern bool send_del_edge(struct connection_t *c, const struct edge_t *e);
116 extern void send_key_changed(void);
117 extern bool send_req_key(struct node_t *to);
118 extern bool send_ans_key(struct node_t *to);
119 extern bool send_tcppacket(struct connection_t *c, const struct vpn_packet_t *packet);
120 extern bool send_sptps_tcppacket(struct connection_t *c, const void *packet, size_t len);
121 extern bool send_udp_info(struct node_t *from, struct node_t *to);
122 extern bool send_mtu_info(struct node_t *from, struct node_t *to, int mtu);
124 /* Request handlers */
126 extern request_handler_t id_h;
127 extern request_handler_t metakey_h;
128 extern request_handler_t challenge_h;
129 extern request_handler_t chal_reply_h;
130 extern request_handler_t ack_h;
131 extern request_handler_t termreq_h;
132 extern request_handler_t ping_h;
133 extern request_handler_t pong_h;
134 extern request_handler_t add_subnet_h;
135 extern request_handler_t del_subnet_h;
136 extern request_handler_t add_edge_h;
137 extern request_handler_t del_edge_h;
138 extern request_handler_t key_changed_h;
139 extern request_handler_t req_key_h;
140 extern request_handler_t ans_key_h;
141 extern request_handler_t tcppacket_h;
142 extern request_handler_t sptps_tcppacket_h;
143 extern request_handler_t control_h;
144 extern request_handler_t udp_info_h;
145 extern request_handler_t mtu_info_h;