Replaced check for status.active by status.dataopen in check_network_activity.
[tinc] / src / protocol.h
1 /*
2     protocol.h -- header for protocol.c
3     Copyright (C) 1999 Ivo Timmermans <zarq@iname.com>
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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __TINC_PROTOCOL_H__
21 #define __TINC_PROTOCOL_H__
22
23 #include "net.h"
24
25 enum {
26   PROT_RESERVED = 0,                 /* reserved: do not use. */
27   PROT_NOT_IN_USE,
28   PROT_TOO_OLD = 2,
29   PROT_3,
30   PROT_CURRENT,                      /* protocol currently in use */
31 };
32
33 enum {
34   ACK = 1,              /* acknowledged */
35   AUTH_S_INIT = 10,     /* initiate authentication */
36   AUTH_C_INIT,
37   AUTH_S_SPP,           /* send passphrase */
38   AUTH_C_SPP,
39   AUTH_S_SKEY,          /* send g^k */
40   AUTH_C_SKEY,
41   AUTH_S_SACK,          /* send ack */
42   AUTH_C_RACK,          /* waiting for ack */
43   TERMREQ = 30,         /* terminate connection */
44   PINGTIMEOUT,          /* terminate due to ping t.o. */
45   DEL_HOST,             /* forward a termreq to others */
46   PING = 40,            /* ping */
47   PONG,
48   ADD_HOST = 60,        /* Add new given host to connection list */
49   BASIC_INFO,           /* some basic info follows */
50   PASSPHRASE,           /* encrypted passphrase */
51   PUBLIC_KEY,           /* public key in base-36 */
52   HOLD = 80,            /* don't send any data */
53   RESUME,               /* resume dataflow with new encryption key */
54   CALCULATE = 100,      /* calculate the following numer^privkey and send me the result */  
55   CALC_RES,             /* result of the above */
56   ALMOST_KEY,           /* this number^privkey is the shared key */
57   REQ_KEY = 160,        /* request public key */
58   ANS_KEY,              /* answer to such request */
59   KEY_CHANGED,          /* public key has changed */
60 };
61
62 typedef struct add_host_t {
63   unsigned char type;
64   char unused1;
65   ip_t real_ip;
66   ip_t vpn_ip;
67   ip_t vpn_mask;
68   unsigned short portnr;
69 } add_host_t;
70
71 typedef struct termreq_t {
72   unsigned char type;
73   char unused1;
74   ip_t vpn_ip;
75 } termreq_t;
76
77 typedef struct basic_info_t {
78   unsigned char type;
79   unsigned char protocol;
80   unsigned short portnr;
81   ip_t vpn_ip;
82   ip_t vpn_mask;
83 } basic_info_t;
84
85 typedef struct calculate_t {
86   unsigned char type;
87   char unused1;
88   unsigned short len;
89   char key;
90 } calculate_t;
91
92 typedef struct public_key_t {
93   unsigned char type;
94   char unused1;
95   unsigned short len;
96   char key;
97 } public_key_t;
98
99 typedef struct key_req_t {
100   unsigned char type;
101   char unused1;
102   ip_t from;
103   ip_t to;
104   time_t expiry;
105   short int len; /* 0 if requesting */
106   char key;
107 } key_req_t;
108
109 typedef struct key_changed_t {
110   unsigned char type;
111   char unused1;
112   ip_t from;
113 } key_changed_t;
114
115 typedef struct del_host_t {
116   unsigned char type;
117   char unused1;
118   ip_t vpn_ip;
119 } del_host_t;
120
121 extern int (*request_handlers[256])(conn_list_t*, unsigned char*, int);
122
123 extern int send_ping(conn_list_t*);
124 extern int send_basic_info(conn_list_t *);
125 extern int send_termreq(conn_list_t *);
126 extern int send_timeout(conn_list_t *);
127 extern int send_key_request(ip_t);
128 extern void send_key_changed2(void);
129
130 #endif /* __TINC_PROTOCOL_H__ */
131