ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
Revision: 1.2
Committed: Sat Mar 8 10:48:41 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +3 -0 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    
24     #include <openssl/evp.h>
25     #include <openssl/rsa.h>
26    
27     #include "conf.h"
28     #include "util.h"
29     #include "device.h"
30    
31     /* Protocol version. Different versions are incompatible,
32     incompatible version have different protocols.
33     */
34    
35     #define PROTOCOL_MAJOR 2
36     #define PROTOCOL_MINOR 0
37    
38     struct vpn;
39     struct vpn_packet;
40    
41     typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
42     typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
43    
44     struct crypto_ctx;
45    
46     enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
47    
48     struct connection
49     {
50     conf_node *conf;
51     struct vpn *vpn;
52    
53     SOCKADDR sa;
54     int retry_cnt;
55    
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
59    
60     u32 oseqno;
61     u32 iseqno;
62     u32 ismask; // bitmask with set bits for each received seqno (input seen mask)
63    
64     pkt_queue queue;
65    
66     crypto_ctx *octx, *ictx;
67    
68 pcg 1.2 enum conf_node::connectmode connectmode;
69    
70 pcg 1.1 void reset_dstaddr ();
71    
72     void shutdown ();
73     void reset_connection ();
74     void establish_connection ();
75     void rekey ();
76    
77     void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0);
78     void send_reset (SOCKADDR *dsa);
79     void send_ping (SOCKADDR *dss, u8 pong = 0);
80     void send_data_packet (tap_packet *pkt, bool broadcast = false);
81     void inject_data_packet (tap_packet *pkt, bool broadcast = false);
82     void connect_request (int id);
83    
84     void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
85    
86     void timer ();
87    
88     connection(struct vpn *vpn_)
89     : vpn(vpn_)
90     {
91     octx = ictx = 0;
92     retry_cnt = 0;
93 pcg 1.2 connectmode = conf_node::C_ALWAYS; // initial setting
94 pcg 1.1 reset_connection ();
95     }
96    
97     ~connection ()
98     {
99     shutdown ();
100     }
101    
102     void script_node ();
103     const char *script_node_up ();
104     const char *script_node_down ();
105     };
106    
107     struct vpn
108     {
109     int socket_fd;
110     int events;
111    
112     tap_device *tap;
113    
114     enum {
115     EVENT_RECONNECT = 1,
116     EVENT_SHUTDOWN = 2,
117     };
118    
119     typedef vector<connection *> conns_vector;
120     conns_vector conns;
121    
122     connection *find_router ();
123    
124     void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa);
125     void reconnect_all ();
126     void shutdown_all ();
127     void connect_request (int id);
128    
129     vpn ();
130     ~vpn ();
131    
132     int setup ();
133     void main_loop ();
134    
135     const char *script_if_up ();
136     };
137    
138     #endif
139