ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
Revision: 1.5
Committed: Fri Mar 21 23:17:01 2003 UTC (21 years, 3 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +30 -24 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 "iom.h"
30 #include "util.h"
31 #include "device.h"
32
33 /* Protocol version. Different versions are incompatible,
34 incompatible version have different protocols.
35 */
36
37 #define PROTOCOL_MAJOR 2
38 #define PROTOCOL_MINOR 0
39
40 struct vpn;
41 struct vpn_packet;
42
43 typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
44 typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
45
46 struct crypto_ctx;
47
48 // a very simple fifo pkt-queue
49 class pkt_queue
50 {
51 tap_packet *queue[QUEUEDEPTH];
52 int i, j;
53
54 public:
55
56 void put (tap_packet *p);
57 tap_packet *get ();
58
59 pkt_queue ();
60 ~pkt_queue ();
61 };
62
63 enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
64
65 struct connection
66 {
67 conf_node *conf;
68 struct vpn *vpn;
69
70 SOCKADDR sa;
71 int retry_cnt;
72
73 tstamp last_activity; // time of last packet received
74
75 u32 oseqno;
76 sliding_window iseqno;
77
78 pkt_queue queue;
79
80 crypto_ctx *octx, *ictx;
81
82 enum conf_node::connectmode connectmode;
83
84 void reset_dstaddr ();
85
86 void shutdown ();
87 void reset_connection ();
88 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
89 void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing)
90 void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
91
92 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0);
93 void send_reset (SOCKADDR *dsa);
94 void send_ping (SOCKADDR *dss, u8 pong = 0);
95 void send_data_packet (tap_packet *pkt, bool broadcast = false);
96 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
97 void connect_request (int id);
98
99 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
100
101 void script_node ();
102 const char *script_node_up ();
103 const char *script_node_down ();
104
105 connection(struct vpn *vpn_);
106 ~connection ();
107 };
108
109 struct vpn
110 {
111 int socket_fd;
112 int events;
113
114 enum {
115 EVENT_RECONNECT = 1,
116 EVENT_SHUTDOWN = 2,
117 };
118
119 void event_cb (tstamp &ts); time_watcher event;
120
121 tap_device *tap;
122
123 typedef vector<connection *> conns_vector;
124 conns_vector conns;
125
126 connection *find_router ();
127
128 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
129 void reconnect_all ();
130 void shutdown_all ();
131 void connect_request (int id);
132
133 void vpn_ev (short revents); io_watcher vpn_ev_watcher;
134 void udp_ev (short revents); io_watcher udp_ev_watcher;
135
136 vpn ();
137 ~vpn ();
138
139 int setup ();
140
141 const char *script_if_up ();
142 };
143
144 #endif
145