ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
Revision: 1.4
Committed: Mon Mar 17 15:20:18 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 protocol.h -- header for protocol.C
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifndef VPE_PROTOCOL_H__
20 #define VPE_PROTOCOL_H__
21
22 #include <netinet/in.h>
23 #include <netinet/ip.h> // for tos etc.
24
25 #include <openssl/evp.h>
26 #include <openssl/rsa.h>
27
28 #include "conf.h"
29 #include "util.h"
30 #include "device.h"
31
32 /* Protocol version. Different versions are incompatible,
33 incompatible version have different protocols.
34 */
35
36 #define PROTOCOL_MAJOR 2
37 #define PROTOCOL_MINOR 0
38
39 struct vpn;
40 struct vpn_packet;
41
42 typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
43 typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
44
45 struct crypto_ctx;
46
47 enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
48
49 struct connection
50 {
51 conf_node *conf;
52 struct vpn *vpn;
53
54 SOCKADDR sa;
55 int retry_cnt;
56
57 time_t next_retry; // next connection retry
58 time_t next_rekey; // next rekying (actually current reset + reestablishing)
59 time_t last_activity; // time of last packet received
60
61 u32 oseqno;
62 sliding_window iseqno;
63
64 pkt_queue queue;
65
66 crypto_ctx *octx, *ictx;
67
68 enum conf_node::connectmode connectmode;
69
70 void reset_dstaddr ();
71
72 void shutdown ();
73 void reset_connection ();
74 void establish_connection ();
75 void rekey ();
76
77 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0);
78 void send_reset (SOCKADDR *dsa);
79 void send_ping (SOCKADDR *dss, u8 pong = 0);
80 void send_data_packet (tap_packet *pkt, bool broadcast = false);
81 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
82 void connect_request (int id);
83
84 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
85
86 void timer ();
87
88 connection(struct vpn *vpn_)
89 : vpn(vpn_)
90 {
91 octx = ictx = 0;
92 retry_cnt = 0;
93 connectmode = conf_node::C_ALWAYS; // initial setting
94 reset_connection ();
95 }
96
97 ~connection ()
98 {
99 shutdown ();
100 }
101
102 void script_node ();
103 const char *script_node_up ();
104 const char *script_node_down ();
105 };
106
107 struct vpn
108 {
109 int socket_fd;
110 int events;
111
112 tap_device *tap;
113
114 enum {
115 EVENT_RECONNECT = 1,
116 EVENT_SHUTDOWN = 2,
117 };
118
119 typedef vector<connection *> conns_vector;
120 conns_vector conns;
121
122 connection *find_router ();
123
124 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
125 void reconnect_all ();
126 void shutdown_all ();
127 void connect_request (int id);
128
129 vpn ();
130 ~vpn ();
131
132 int setup ();
133 void main_loop ();
134
135 const char *script_if_up ();
136 };
137
138 #endif
139