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.2 by pcg, Sat Mar 8 10:48:41 2003 UTC vs.
Revision 1.5 by pcg, Fri Mar 21 23:17:01 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines