ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
Revision: 1.3
Committed: Sun Mar 9 12:40:18 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*
2     protocol.h -- header for protocol.C
3    
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8    
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17     */
18    
19     #ifndef VPE_PROTOCOL_H__
20     #define VPE_PROTOCOL_H__
21    
22     #include <netinet/in.h>
23 pcg 1.3 #include <netinet/ip.h> // for tos etc.
24 pcg 1.1
25     #include <openssl/evp.h>
26     #include <openssl/rsa.h>
27    
28     #include "conf.h"
29     #include "util.h"
30     #include "device.h"
31    
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    
39     struct vpn;
40     struct vpn_packet;
41    
42     typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
43     typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
44    
45     struct crypto_ctx;
46    
47     enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
48    
49     struct 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 pcg 1.2 enum conf_node::connectmode connectmode;
70    
71 pcg 1.1 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 pcg 1.2 connectmode = conf_node::C_ALWAYS; // initial setting
95 pcg 1.1 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    
108     struct vpn
109     {
110     int socket_fd;
111     int events;
112    
113     tap_device *tap;
114    
115     enum {
116     EVENT_RECONNECT = 1,
117     EVENT_SHUTDOWN = 2,
118     };
119    
120     typedef vector<connection *> conns_vector;
121     conns_vector conns;
122    
123     connection *find_router ();
124    
125 pcg 1.3 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
126 pcg 1.1 void reconnect_all ();
127     void shutdown_all ();
128     void connect_request (int id);
129    
130     vpn ();
131     ~vpn ();
132    
133     int setup ();
134     void main_loop ();
135    
136     const char *script_if_up ();
137     };
138    
139     #endif
140