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.13 by pcg, Wed Apr 2 03:06:22 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.
24 23
25#include <openssl/evp.h> 24#include <openssl/evp.h>
26#include <openssl/rsa.h> 25#include <openssl/rsa.h>
27 26
28#include "conf.h" 27#include "conf.h"
28#include "iom.h"
29#include "util.h" 29#include "util.h"
30#include "sockinfo.h"
30#include "device.h" 31#include "device.h"
31 32#include "connection.h"
32/* Protocol version. Different versions are incompatible,
33 incompatible version have different protocols.
34 */
35
36#define PROTOCOL_MAJOR 2
37#define PROTOCOL_MINOR 0
38
39struct vpn;
40struct vpn_packet;
41
42typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
43typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
44
45struct crypto_ctx;
46
47enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
48
49struct connection
50 {
51 conf_node *conf;
52 struct vpn *vpn;
53
54 SOCKADDR sa;
55 int retry_cnt;
56
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
60
61 u32 oseqno;
62 u32 iseqno;
63 u32 ismask; // bitmask with set bits for each received seqno (input seen mask)
64
65 pkt_queue queue;
66
67 crypto_ctx *octx, *ictx;
68
69 enum conf_node::connectmode connectmode;
70
71 void reset_dstaddr ();
72
73 void shutdown ();
74 void reset_connection ();
75 void establish_connection ();
76 void rekey ();
77
78 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0);
79 void send_reset (SOCKADDR *dsa);
80 void send_ping (SOCKADDR *dss, u8 pong = 0);
81 void send_data_packet (tap_packet *pkt, bool broadcast = false);
82 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
83 void connect_request (int id);
84
85 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
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
103 void script_node ();
104 const char *script_node_up ();
105 const char *script_node_down ();
106 };
107 33
108struct vpn 34struct vpn
109 { 35 {
110 int socket_fd; 36 int udpv4_fd;
37 int ipv4_fd;
38
111 int events; 39 int events;
112
113 tap_device *tap;
114 40
115 enum { 41 enum {
116 EVENT_RECONNECT = 1, 42 EVENT_RECONNECT = 1,
117 EVENT_SHUTDOWN = 2, 43 EVENT_SHUTDOWN = 2,
118 }; 44 };
119 45
46 void event_cb (tstamp &ts); time_watcher event;
47
48 tap_device *tap;
49
120 typedef vector<connection *> conns_vector; 50 typedef vector<connection *> conns_vector;
121 conns_vector conns; 51 conns_vector conns;
122 52
123 connection *find_router (); 53 connection *find_router ();
124 54
125 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
126 void reconnect_all (); 55 void reconnect_all ();
127 void shutdown_all (); 56 void shutdown_all ();
128 void connect_request (int id); 57 void connect_request (int id);
58
59 void tap_ev (short revents); io_watcher tap_ev_watcher;
60 void ipv4_ev (short revents); io_watcher ipv4_ev_watcher;
61 void udpv4_ev (short revents); io_watcher udpv4_ev_watcher;
62
63 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
64
65 void send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
66 void send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
129 67
130 vpn (); 68 vpn ();
131 ~vpn (); 69 ~vpn ();
132 70
133 int setup (); 71 int setup ();
134 void main_loop ();
135 72
73 void dump_status ();
74
136 const char *script_if_up (); 75 const char *script_if_up (int);
137 }; 76 };
138 77
139#endif 78#endif
140 79

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines