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.4 by pcg, Mon Mar 17 15:20:18 2003 UTC vs.
Revision 1.10 by pcg, Fri Mar 28 04:05:10 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"
31#include "sockinfo.h"
30#include "device.h" 32#include "device.h"
31 33
32/* Protocol version. Different versions are incompatible, 34/* Protocol version. Different major versions are incompatible,
33 incompatible version have different protocols. 35 * different minor versions probably are compatible ;)
34 */ 36 */
35 37
36#define PROTOCOL_MAJOR 2 38#define PROTOCOL_MAJOR 0
37#define PROTOCOL_MINOR 0 39#define PROTOCOL_MINOR 0
38 40
39struct vpn; 41struct vpn;
40struct vpn_packet; 42struct vpn_packet;
41 43
44struct rsaid {
45 u8 id[RSA_IDLEN]; // the challenge id
46};
47
42typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data 48typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data;
43typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge 49typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
50typedef u8 rsaresponse[RSA_RESLEN]; // the encrypted ripemd160 hash
44 51
45struct crypto_ctx; 52struct crypto_ctx;
46 53
47enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY }; 54// a very simple fifo pkt-queue
55class pkt_queue
56 {
57 tap_packet *queue[QUEUEDEPTH];
58 int i, j;
59
60 public:
61
62 void put (tap_packet *p);
63 tap_packet *get ();
64
65 pkt_queue ();
66 ~pkt_queue ();
67 };
48 68
49struct connection 69struct connection
50 { 70 {
51 conf_node *conf; 71 conf_node *conf;
52 struct vpn *vpn; 72 struct vpn *vpn;
53 73
54 SOCKADDR sa; 74 sockinfo si; // the current(!) destination ip to send packets to
55 int retry_cnt; 75 int retry_cnt;
56 76
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 77 tstamp last_activity; // time of last packet received
60 78
61 u32 oseqno; 79 u32 oseqno;
62 sliding_window iseqno; 80 sliding_window iseqno;
81
82 u8 prot_send, prot_recv;
63 83
64 pkt_queue queue; 84 pkt_queue queue;
65 85
66 crypto_ctx *octx, *ictx; 86 crypto_ctx *octx, *ictx;
67 87
68 enum conf_node::connectmode connectmode; 88 enum conf_node::connectmode connectmode;
89 u8 prot_minor; // minor number of other side
69 90
70 void reset_dstaddr (); 91 void reset_dstaddr ();
71 92
72 void shutdown (); 93 void shutdown ();
73 void reset_connection (); 94 void reset_connection ();
74 void establish_connection (); 95 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
75 void rekey (); 96 void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing)
97 void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
76 98
77 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); 99 void send_auth_request (const sockinfo &si, bool initiate);
78 void send_reset (SOCKADDR *dsa); 100 void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg);
79 void send_ping (SOCKADDR *dss, u8 pong = 0); 101 void send_reset (const sockinfo &dsi);
102 void send_ping (const sockinfo &dsi, u8 pong = 0);
80 void send_data_packet (tap_packet *pkt, bool broadcast = false); 103 void send_data_packet (tap_packet *pkt, bool broadcast = false);
81 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 104 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
82 void connect_request (int id); 105 void connect_request (int id);
83 106
107 void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
84 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 108 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
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 109
102 void script_node (); 110 void script_node ();
103 const char *script_node_up (); 111 const char *script_node_up (int);
104 const char *script_node_down (); 112 const char *script_node_down (int);
113
114 void dump_status ();
115
116 connection(struct vpn *vpn_);
117 ~connection ();
105 }; 118 };
106 119
107struct vpn 120struct vpn
108 { 121 {
109 int socket_fd; 122 int udpv4_fd;
123 int ipv4_fd;
124
110 int events; 125 int events;
111
112 tap_device *tap;
113 126
114 enum { 127 enum {
115 EVENT_RECONNECT = 1, 128 EVENT_RECONNECT = 1,
116 EVENT_SHUTDOWN = 2, 129 EVENT_SHUTDOWN = 2,
117 }; 130 };
118 131
132 void event_cb (tstamp &ts); time_watcher event;
133
134 tap_device *tap;
135
119 typedef vector<connection *> conns_vector; 136 typedef vector<connection *> conns_vector;
120 conns_vector conns; 137 conns_vector conns;
121 138
122 connection *find_router (); 139 connection *find_router ();
123 140
124 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
125 void reconnect_all (); 141 void reconnect_all ();
126 void shutdown_all (); 142 void shutdown_all ();
127 void connect_request (int id); 143 void connect_request (int id);
144
145 void tap_ev (short revents); io_watcher tap_ev_watcher;
146 void ipv4_ev (short revents); io_watcher ipv4_ev_watcher;
147 void udpv4_ev (short revents); io_watcher udpv4_ev_watcher;
148
149 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
150
151 void send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
152 void send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
128 153
129 vpn (); 154 vpn ();
130 ~vpn (); 155 ~vpn ();
131 156
132 int setup (); 157 int setup ();
133 void main_loop ();
134 158
159 void dump_status ();
160
135 const char *script_if_up (); 161 const char *script_if_up (int);
136 }; 162 };
137 163
138#endif 164#endif
139 165

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines