ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
(Generate patch)

Comparing gvpe/src/protocol.h (file contents):
Revision 1.3 by pcg, Sun Mar 9 12:40:18 2003 UTC vs.
Revision 1.7 by pcg, Sat Mar 22 22:36:25 2003 UTC

24 24
25#include <openssl/evp.h> 25#include <openssl/evp.h>
26#include <openssl/rsa.h> 26#include <openssl/rsa.h>
27 27
28#include "conf.h" 28#include "conf.h"
29#include "iom.h"
29#include "util.h" 30#include "util.h"
30#include "device.h" 31#include "device.h"
31 32
32/* Protocol version. Different versions are incompatible, 33/* Protocol version. Different versions are incompatible,
33 incompatible version have different protocols. 34 incompatible version have different protocols.
34 */ 35 */
35 36
36#define PROTOCOL_MAJOR 2 37#define PROTOCOL_MAJOR 3
37#define PROTOCOL_MINOR 0 38#define PROTOCOL_MINOR 0
38 39
39struct vpn; 40struct vpn;
40struct vpn_packet; 41struct vpn_packet;
41 42
42typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data 43typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
43typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge 44typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
44 45
45struct crypto_ctx; 46struct crypto_ctx;
46 47
48// a very simple fifo pkt-queue
49class 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
47enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY }; 63enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
64
65struct auth_packet;
48 66
49struct connection 67struct connection
50 { 68 {
51 conf_node *conf; 69 conf_node *conf;
52 struct vpn *vpn; 70 struct vpn *vpn;
71 u32 seqrand;
53 72
54 SOCKADDR sa; 73 SOCKADDR sa;
55 int retry_cnt; 74 int retry_cnt;
56 75
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 76 tstamp last_activity; // time of last packet received
60 77
61 u32 oseqno; 78 u32 oseqno;
62 u32 iseqno; 79 sliding_window iseqno;
63 u32 ismask; // bitmask with set bits for each received seqno (input seen mask)
64 80
65 pkt_queue queue; 81 pkt_queue queue;
66 82
67 crypto_ctx *octx, *ictx; 83 crypto_ctx *octx, *ictx;
68 84
70 86
71 void reset_dstaddr (); 87 void reset_dstaddr ();
72 88
73 void shutdown (); 89 void shutdown ();
74 void reset_connection (); 90 void reset_connection ();
75 void establish_connection (); 91 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
76 void rekey (); 92 void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing)
93 void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
77 94
78 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); 95 void send_auth (auth_subtype subtype, SOCKADDR *sa, const rsachallenge *k = 0);
79 void send_reset (SOCKADDR *dsa); 96 void send_reset (SOCKADDR *dsa);
80 void send_ping (SOCKADDR *dss, u8 pong = 0); 97 void send_ping (SOCKADDR *dss, u8 pong = 0);
81 void send_data_packet (tap_packet *pkt, bool broadcast = false); 98 void send_data_packet (tap_packet *pkt, bool broadcast = false);
82 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 99 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
83 void connect_request (int id); 100 void connect_request (int id);
84 101
85 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 102 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
86 103
87 void timer ();
88
89 connection(struct vpn *vpn_)
90 : vpn(vpn_)
91 {
92 octx = ictx = 0;
93 retry_cnt = 0;
94 connectmode = conf_node::C_ALWAYS; // initial setting
95 reset_connection ();
96 }
97
98 ~connection ()
99 {
100 shutdown ();
101 }
102
103 void script_node (); 104 void script_node ();
104 const char *script_node_up (); 105 const char *script_node_up ();
105 const char *script_node_down (); 106 const char *script_node_down ();
107
108 connection(struct vpn *vpn_);
109 ~connection ();
106 }; 110 };
107 111
108struct vpn 112struct vpn
109 { 113 {
110 int socket_fd; 114 int socket_fd;
111 int events; 115 int events;
112 116
113 tap_device *tap;
114
115 enum { 117 enum {
116 EVENT_RECONNECT = 1, 118 EVENT_RECONNECT = 1,
117 EVENT_SHUTDOWN = 2, 119 EVENT_SHUTDOWN = 2,
118 }; 120 };
121
122 void event_cb (tstamp &ts); time_watcher event;
123
124 tap_device *tap;
119 125
120 typedef vector<connection *> conns_vector; 126 typedef vector<connection *> conns_vector;
121 conns_vector conns; 127 conns_vector conns;
122 128
123 connection *find_router (); 129 connection *find_router ();
125 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY); 131 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
126 void reconnect_all (); 132 void reconnect_all ();
127 void shutdown_all (); 133 void shutdown_all ();
128 void connect_request (int id); 134 void connect_request (int id);
129 135
136 void vpn_ev (short revents); io_watcher vpn_ev_watcher;
137 void udp_ev (short revents); io_watcher udp_ev_watcher;
138
130 vpn (); 139 vpn ();
131 ~vpn (); 140 ~vpn ();
132 141
133 int setup (); 142 int setup ();
134 void main_loop ();
135 143
136 const char *script_if_up (); 144 const char *script_if_up ();
137 }; 145 };
138 146
139#endif 147#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines