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.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 u32 iseqno; 80 sliding_window iseqno;
63 u32 ismask; // bitmask with set bits for each received seqno (input seen mask) 81
82 u8 prot_send, prot_recv;
64 83
65 pkt_queue queue; 84 pkt_queue queue;
66 85
67 crypto_ctx *octx, *ictx; 86 crypto_ctx *octx, *ictx;
68 87
69 enum conf_node::connectmode connectmode; 88 enum conf_node::connectmode connectmode;
89 u8 prot_minor; // minor number of other side
70 90
71 void reset_dstaddr (); 91 void reset_dstaddr ();
72 92
73 void shutdown (); 93 void shutdown ();
74 void reset_connection (); 94 void reset_connection ();
75 void establish_connection (); 95 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
76 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
77 98
78 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); 99 void send_auth_request (const sockinfo &si, bool initiate);
79 void send_reset (SOCKADDR *dsa); 100 void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg);
80 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);
81 void send_data_packet (tap_packet *pkt, bool broadcast = false); 103 void send_data_packet (tap_packet *pkt, bool broadcast = false);
82 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 104 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
83 void connect_request (int id); 105 void connect_request (int id);
84 106
107 void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
85 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 108 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
86
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 109
103 void script_node (); 110 void script_node ();
104 const char *script_node_up (); 111 const char *script_node_up (int);
105 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 ();
106 }; 118 };
107 119
108struct vpn 120struct vpn
109 { 121 {
110 int socket_fd; 122 int udpv4_fd;
123 int ipv4_fd;
124
111 int events; 125 int events;
112
113 tap_device *tap;
114 126
115 enum { 127 enum {
116 EVENT_RECONNECT = 1, 128 EVENT_RECONNECT = 1,
117 EVENT_SHUTDOWN = 2, 129 EVENT_SHUTDOWN = 2,
118 }; 130 };
119 131
132 void event_cb (tstamp &ts); time_watcher event;
133
134 tap_device *tap;
135
120 typedef vector<connection *> conns_vector; 136 typedef vector<connection *> conns_vector;
121 conns_vector conns; 137 conns_vector conns;
122 138
123 connection *find_router (); 139 connection *find_router ();
124 140
125 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
126 void reconnect_all (); 141 void reconnect_all ();
127 void shutdown_all (); 142 void shutdown_all ();
128 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);
129 153
130 vpn (); 154 vpn ();
131 ~vpn (); 155 ~vpn ();
132 156
133 int setup (); 157 int setup ();
134 void main_loop ();
135 158
159 void dump_status ();
160
136 const char *script_if_up (); 161 const char *script_if_up (int);
137 }; 162 };
138 163
139#endif 164#endif
140 165

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines