BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * Copyright (C) Ambroz Bizjak <ambrop7@gmail.com>
3 * Contributions:
4 * Transparent DNS: Copyright (C) Kerem Hadimli <kerem.hadimli@gmail.com>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28  
29 #ifndef BADVPN_UDPGW_CLIENT_UDPGWCLIENT_H
30 #define BADVPN_UDPGW_CLIENT_UDPGWCLIENT_H
31  
32 #include <stdint.h>
33  
34 #include <protocol/udpgw_proto.h>
35 #include <misc/debug.h>
36 #include <misc/packed.h>
37 #include <structure/BAVL.h>
38 #include <structure/LinkedList1.h>
39 #include <base/DebugObject.h>
40 #include <system/BAddr.h>
41 #include <base/BPending.h>
42 #include <flow/PacketPassFairQueue.h>
43 #include <flow/PacketStreamSender.h>
44 #include <flow/PacketProtoFlow.h>
45 #include <flow/PacketProtoDecoder.h>
46 #include <flow/PacketPassConnector.h>
47 #include <flowextra/PacketPassInactivityMonitor.h>
48  
49 typedef void (*UdpGwClient_handler_servererror) (void *user);
50 typedef void (*UdpGwClient_handler_received) (void *user, BAddr local_addr, BAddr remote_addr, const uint8_t *data, int data_len);
51  
52 B_START_PACKED
53 struct UdpGwClient__keepalive_packet {
54 struct packetproto_header pp;
55 struct udpgw_header udpgw;
56 } B_PACKED;
57 B_END_PACKED
58  
59 typedef struct {
60 int udp_mtu;
61 int max_connections;
62 int send_buffer_size;
63 btime_t keepalive_time;
64 BReactor *reactor;
65 void *user;
66 UdpGwClient_handler_servererror handler_servererror;
67 UdpGwClient_handler_received handler_received;
68 int udpgw_mtu;
69 int pp_mtu;
70 BAVL connections_tree_by_conaddr;
71 BAVL connections_tree_by_conid;
72 LinkedList1 connections_list;
73 int num_connections;
74 int next_conid;
75 PacketPassFairQueue send_queue;
76 PacketPassInactivityMonitor send_monitor;
77 PacketPassConnector send_connector;
78 struct UdpGwClient__keepalive_packet keepalive_packet;
79 PacketPassInterface *keepalive_if;
80 PacketPassFairQueueFlow keepalive_qflow;
81 int keepalive_sending;
82 int have_server;
83 PacketStreamSender send_sender;
84 PacketProtoDecoder recv_decoder;
85 PacketPassInterface recv_if;
86 DebugObject d_obj;
87 } UdpGwClient;
88  
89 struct UdpGwClient_conaddr {
90 BAddr local_addr;
91 BAddr remote_addr;
92 };
93  
94 struct UdpGwClient_connection {
95 UdpGwClient *client;
96 struct UdpGwClient_conaddr conaddr;
97 uint8_t first_flags;
98 const uint8_t *first_data;
99 int first_data_len;
100 uint16_t conid;
101 BPending first_job;
102 BufferWriter *send_if;
103 PacketProtoFlow send_ppflow;
104 PacketPassFairQueueFlow send_qflow;
105 BAVLNode connections_tree_by_conaddr_node;
106 BAVLNode connections_tree_by_conid_node;
107 LinkedList1Node connections_list_node;
108 };
109  
110 int UdpGwClient_Init (UdpGwClient *o, int udp_mtu, int max_connections, int send_buffer_size, btime_t keepalive_time, BReactor *reactor, void *user,
111 UdpGwClient_handler_servererror handler_servererror,
112 UdpGwClient_handler_received handler_received) WARN_UNUSED;
113 void UdpGwClient_Free (UdpGwClient *o);
114 void UdpGwClient_SubmitPacket (UdpGwClient *o, BAddr local_addr, BAddr remote_addr, int is_dns, const uint8_t *data, int data_len);
115 int UdpGwClient_ConnectServer (UdpGwClient *o, StreamPassInterface *send_if, StreamRecvInterface *recv_if) WARN_UNUSED;
116 void UdpGwClient_DisconnectServer (UdpGwClient *o);
117  
118 #endif