Generalized request broadcasting/forwarding.
[tinc] / src / protocol.h
1 /*
2     protocol.h -- header for protocol.c
3     Copyright (C) 1999-2001 Ivo Timmermans <ivo@o2w.nl>,
4                   2000,2001 Guus Sliepen <guus@sliepen.eu.org>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: protocol.h,v 1.5.4.34 2002/09/04 16:26:45 guus Exp $
21 */
22
23 #ifndef __TINC_PROTOCOL_H__
24 #define __TINC_PROTOCOL_H__
25
26 #include "net.h"
27 #include "node.h"
28 #include "edge.h"
29 #include "subnet.h"
30
31 /* Protocol version. Different versions are incompatible,
32    incompatible version have different protocols.
33  */
34
35 #define PROT_CURRENT 17
36
37 /* Request numbers */
38
39 enum {
40   ALL = -1,                          /* Guardian for allow_request */
41   ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
42   STATUS, ERROR, TERMREQ,
43   PING, PONG,
44 //  ADD_NODE, DEL_NODE,
45   ADD_SUBNET, DEL_SUBNET,
46   ADD_EDGE, DEL_EDGE,
47   KEY_CHANGED, REQ_KEY, ANS_KEY,
48   PACKET,
49   LAST                               /* Guardian for the highest request number */
50 };
51
52 typedef struct past_request_t {
53   char *request;
54   time_t firstseen;
55 } past_request_t;
56
57 /* Maximum size of strings in a request */
58
59 #define MAX_STRING_SIZE 2048
60 #define MAX_STRING "%2048s"
61
62 /* Basic functions */
63
64 extern int send_request(connection_t*, const char*, ...);
65 extern int forward_request(connection_t *);
66 extern int receive_request(connection_t *);
67 extern int check_id(char *);
68
69 extern void init_requests(void);
70 extern void exit_requests(void);
71 extern int seen_request(char *);
72 extern void age_past_requests(void);
73
74 /* Requests */
75
76 extern int send_id(connection_t *);
77 extern int send_metakey(connection_t *);
78 extern int send_challenge(connection_t *);
79 extern int send_chal_reply(connection_t *);
80 extern int send_ack(connection_t *);
81 extern int send_status(connection_t *, int, char *);
82 extern int send_error(connection_t *, int, char *);
83 extern int send_termreq(connection_t *);
84 extern int send_ping(connection_t *);
85 extern int send_pong(connection_t *);
86 // extern int send_add_node(connection_t *, node_t *);
87 // extern int send_del_node(connection_t *, node_t *);
88 extern int send_add_subnet(connection_t *, subnet_t *);
89 extern int send_del_subnet(connection_t *, subnet_t *);
90 extern int send_add_edge(connection_t *, edge_t *);
91 extern int send_del_edge(connection_t *, edge_t *);
92 extern int send_key_changed(connection_t *, node_t *);
93 extern int send_req_key(connection_t *, node_t *, node_t *);
94 extern int send_ans_key(connection_t *, node_t *, node_t *);
95 extern int send_tcppacket(connection_t *, vpn_packet_t *);
96
97 /* Request handlers  */
98
99 extern int (*request_handlers[])(connection_t *);
100
101 extern int id_h(connection_t *);
102 extern int metakey_h(connection_t *);
103 extern int challenge_h(connection_t *);
104 extern int chal_reply_h(connection_t *);
105 extern int ack_h(connection_t *);
106 extern int status_h(connection_t *);
107 extern int error_h(connection_t *);
108 extern int termreq_h(connection_t *);
109 extern int ping_h(connection_t *);
110 extern int pong_h(connection_t *);
111 // extern int add_node_h(connection_t *);
112 // extern int del_node_h(connection_t *);
113 extern int add_subnet_h(connection_t *);
114 extern int del_subnet_h(connection_t *);
115 extern int add_edge_h(connection_t *);
116 extern int del_edge_h(connection_t *);
117 extern int key_changed_h(connection_t *);
118 extern int req_key_h(connection_t *);
119 extern int ans_key_h(connection_t *);
120 extern int tcppacket_h(connection_t *);
121
122 #endif /* __TINC_PROTOCOL_H__ */