aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/vpn_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-07 19:00:55 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-07 19:00:55 +0000
commit4c6f5a7ae36bbed02ecd1ae78ecff44e93c0970b (patch)
treef715e8ea14fdc5b98033db81e91c2b0d03e1c03b /src/vpn/vpn_api.c
parentffc10c1b249e2cc774ec7bcbf9d5366a36179a22 (diff)
downloadgnunet-4c6f5a7ae36bbed02ecd1ae78ecff44e93c0970b.tar.gz
gnunet-4c6f5a7ae36bbed02ecd1ae78ecff44e93c0970b.zip
-vpn api skeleton
Diffstat (limited to 'src/vpn/vpn_api.c')
-rw-r--r--src/vpn/vpn_api.c253
1 files changed, 253 insertions, 0 deletions
diff --git a/src/vpn/vpn_api.c b/src/vpn/vpn_api.c
new file mode 100644
index 000000000..5c351a190
--- /dev/null
+++ b/src/vpn/vpn_api.c
@@ -0,0 +1,253 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file vpn/vpn_api.c
23 * @brief library to access the VPN service and tell it how to redirect traffic
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_vpn_service.h"
28#include "vpn.h"
29
30
31/**
32 * Opaque VPN handle
33 */
34struct GNUNET_VPN_Handle
35{
36 /**
37 * Configuration we use.
38 */
39 const struct GNUNET_CONFIGURATION_Handle *cfg;
40
41 /**
42 * Connection to VPN service.
43 */
44 struct GNUNET_CLIENT_Connection *client;
45
46 /**
47 * Head of list of active redirection requests.
48 */
49 struct GNUNET_VPN_RedirectionRequest *rr_head;
50
51 /**
52 * Tail of list of active redirection requests.
53 */
54 struct GNUNET_VPN_RedirectionRequest *rr_tail;
55};
56
57
58/**
59 * Opaque redirection request handle.
60 */
61struct GNUNET_VPN_RedirectionRequest
62{
63 /**
64 * Element in DLL.
65 */
66 struct GNUNET_VPN_RedirectionRequest *next;
67
68 /**
69 * Element in DLL.
70 */
71 struct GNUNET_VPN_RedirectionRequest *prev;
72
73 /**
74 * Pointer to the VPN struct.
75 */
76 struct GNUNET_VPN_Handle *vh;
77
78 /**
79 * Target IP address for the redirection, or NULL for
80 * redirection to service. Allocated after this struct.
81 */
82 const void *addr;
83
84 /**
85 * Function to call with the designated IP address.
86 */
87 GNUNET_VPN_AllocationCallback cb;
88
89 /**
90 * Closure for 'cb'.
91 */
92 void *cb_cls;
93
94 /**
95 * For service redirection, identity of the peer offering the service.
96 */
97 struct GNUNET_PeerIdentity peer;
98
99 /**
100 * For service redirection, service descriptor.
101 */
102 GNUNET_HashCode serv;
103
104 /**
105 * At what time should the created service mapping expire?
106 */
107 struct GNUNET_TIME_Absolute expiration_time;
108
109 /**
110 * AF_INET or AF_INET6.
111 */
112 int af;
113
114 /**
115 * GNUNET_YES if we are to call the callback only after successful
116 * mesh tunnel creation.
117 */
118 int nac;
119
120 /**
121 * For service redirection, IPPROT_UDP or IPPROTO_TCP.
122 */
123 uint8_t protocol;
124
125};
126
127
128/**
129 * Cancel redirection request with the service.
130 *
131 * @param rr request to cancel
132 */
133void
134GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr)
135{
136 struct GNUNET_VPN_Handle *vh;
137
138 vh = rr->vh;
139 GNUNET_CONTAINER_DLL_remove (vh->rr_head,
140 vh->rr_tail,
141 rr);
142 GNUNET_free (rr);
143}
144
145
146/**
147 * Tell the VPN that a forwarding to a particular peer offering a
148 * particular service is requested. The VPN is to reserve a
149 * particular IP for the redirection and return it. The VPN will
150 * begin the redirection as soon as possible and maintain it as long
151 * as it is actively used and keeping it is feasible. Given resource
152 * limitations, the longest inactive mappings will be destroyed.
153 *
154 * @param vh VPN handle
155 * @param af address family, AF_INET or AF_INET6
156 * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP
157 * @param peer target peer for the redirection
158 * @param serv service descriptor to give to the peer
159 * @param nac GNUNET_YES to notify via callback only after completion of
160 * the MESH-level connection,
161 * GNUNET_NO to notify as soon as the IP has been reserved
162 * @param expiration_time at what time should the redirection expire?
163 * (this should not impact connections that are active at that time)
164 * @param cb function to call with the IP
165 * @param cb_cls closure for cb
166 * @return handle to cancel the request (means the callback won't be
167 * invoked anymore; the mapping may or may not be established
168 * anyway)
169 */
170struct GNUNET_VPN_RedirectionRequest *
171GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *rh,
172 int af,
173 uint8_t protocol,
174 const struct GNUNET_PeerIdentity *peer,
175 const GNUNET_HashCode *serv,
176 int nac,
177 struct GNUNET_TIME_Absolute expiration_time,
178 GNUNET_VPN_AllocationCallback cb,
179 void *cb_cls)
180{
181 return NULL; // FIXME
182}
183
184
185/**
186 * Tell the VPN that forwarding to the Internet via some exit node is
187 * requested. Note that both UDP and TCP traffic will be forwarded,
188 * but possibly to different exit nodes. The VPN is to reserve a
189 * particular IP for the redirection and return it. The VPN will
190 * begin the redirection as soon as possible and maintain it as long
191 * as it is actively used and keeping it is feasible. Given resource
192 * limitations, the longest inactive mappings will be destroyed.
193 *
194 * @param vh VPN handle
195 * @param af address family, AF_INET or AF_INET6
196 * @param addr destination IP address on the Internet; destination
197 * port is to be taken from the VPN packet itself
198 * @param nac GNUNET_YES to notify via callback only after completion of
199 * the MESH-level connection,
200 * GNUNET_NO to notify as soon as the IP has been reserved
201 * @param expiration_time at what time should the redirection expire?
202 * (this should not impact connections that are active at that time)
203 * @param cb function to call with the IP
204 * @param cb_cls closure for cb
205 * @return handle to cancel the request (means the callback won't be
206 * invoked anymore; the mapping may or may not be established
207 * anyway)
208 */
209struct GNUNET_VPN_RedirectionRequest *
210GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *rh,
211 int af,
212 const void *addr,
213 int nac,
214 struct GNUNET_TIME_Absolute expiration_time,
215 GNUNET_VPN_AllocationCallback cb,
216 void *cb_cls)
217{
218 return NULL; // FIXME
219}
220
221
222/**
223 * Connect to the VPN service
224 *
225 * @param cfg configuration to use
226 * @return VPN handle
227 */
228struct GNUNET_VPN_Handle *
229GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
230{
231 struct GNUNET_VPN_Handle *vh;
232
233 vh = GNUNET_malloc (sizeof (struct GNUNET_VPN_Handle));
234 vh->cfg = cfg;
235 vh->client = GNUNET_CLIENT_connect ("vpn", cfg);
236 return vh;
237}
238
239
240/**
241 * Disconnect from the VPN service.
242 *
243 * @param vh VPN handle
244 */
245void
246GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh)
247{
248 GNUNET_assert (NULL == vh->rr_head);
249 GNUNET_CLIENT_disconnect (vh->client, GNUNET_NO);
250 GNUNET_free (vh);
251}
252
253/* end of vpn_api.c */