1 #ifndef MESHLINK_PROTOCOL_H
2 #define MESHLINK_PROTOCOL_H
5 protocol.h -- header for protocol.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.
25 /* Protocol version. Different major versions are incompatible. */
28 #define PROT_MINOR 3 /* Should not exceed 255! */
38 typedef enum request_t {
39 ALL = -1, /* Guardian for allow_request */
40 ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
41 STATUS, ERROR, TERMREQ,
43 ADD_SUBNET, DEL_SUBNET,
45 KEY_CHANGED, REQ_KEY, ANS_KEY,
47 /* Tinc 1.1 requests */
49 REQ_PUBKEY, ANS_PUBKEY,
51 LAST /* Guardian for the highest request number */
54 typedef struct past_request_t {
59 /* Maximum size of strings in a request.
60 * scanf terminates %2048s with a NUL character,
61 * but the NUL character can be written after the 2048th non-NUL character.
64 #define MAX_STRING_SIZE 2049
65 #define MAX_STRING "%2048s"
73 extern bool send_request(struct meshlink_handle *mesh, struct connection_t *, const char *, ...) __attribute__((__format__(printf, 3, 4)));
74 extern void forward_request(struct meshlink_handle *mesh, struct connection_t *, const char *);
75 extern bool receive_request(struct meshlink_handle *mesh, struct connection_t *, const char *);
76 extern bool check_id(const char *);
78 extern void init_requests(struct meshlink_handle *mesh);
79 extern void exit_requests(struct meshlink_handle *mesh);
80 extern bool seen_request(struct meshlink_handle *mesh, const char *);
84 extern bool send_id(struct meshlink_handle *mesh, struct connection_t *);
85 extern bool send_ack(struct meshlink_handle *mesh, struct connection_t *);
86 extern bool send_status(struct meshlink_handle *mesh, struct connection_t *, int, const char *);
87 extern bool send_error(struct meshlink_handle *mesh, struct connection_t *, int, const char *);
88 extern bool send_termreq(struct meshlink_handle *mesh, struct connection_t *);
89 extern bool send_ping(struct meshlink_handle *mesh, struct connection_t *);
90 extern bool send_pong(struct meshlink_handle *mesh, struct connection_t *);
91 extern bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *);
92 extern bool send_del_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *);
93 extern void send_key_changed(struct meshlink_handle *mesh);
94 extern bool send_req_key(struct meshlink_handle *mesh, struct node_t *);
95 extern bool send_ans_key(struct meshlink_handle *mesh, struct node_t *);
96 extern bool send_tcppacket(struct meshlink_handle *mesh, struct connection_t *, const struct vpn_packet_t *);
98 /* Request handlers */
100 extern bool id_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
101 extern bool ack_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
102 extern bool status_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
103 extern bool error_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
104 extern bool termreq_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
105 extern bool ping_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
106 extern bool pong_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
107 extern bool add_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
108 extern bool del_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
109 extern bool key_changed_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
110 extern bool req_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
111 extern bool ans_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
112 extern bool tcppacket_h(struct meshlink_handle *mesh, struct connection_t *, const char *);