2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff
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.
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.
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.
23 * @brief library to access the VPN service and tell it how to redirect traffic
24 * @author Christian Grothoff
27 #include "gnunet_vpn_service.h"
34 struct GNUNET_VPN_Handle
37 * Configuration we use.
39 const struct GNUNET_CONFIGURATION_Handle *cfg;
42 * Connection to VPN service.
44 struct GNUNET_CLIENT_Connection *client;
47 * Head of list of active redirection requests.
49 struct GNUNET_VPN_RedirectionRequest *rr_head;
52 * Tail of list of active redirection requests.
54 struct GNUNET_VPN_RedirectionRequest *rr_tail;
59 * Opaque redirection request handle.
61 struct GNUNET_VPN_RedirectionRequest
66 struct GNUNET_VPN_RedirectionRequest *next;
71 struct GNUNET_VPN_RedirectionRequest *prev;
74 * Pointer to the VPN struct.
76 struct GNUNET_VPN_Handle *vh;
79 * Target IP address for the redirection, or NULL for
80 * redirection to service. Allocated after this struct.
85 * Function to call with the designated IP address.
87 GNUNET_VPN_AllocationCallback cb;
95 * For service redirection, identity of the peer offering the service.
97 struct GNUNET_PeerIdentity peer;
100 * For service redirection, service descriptor.
102 GNUNET_HashCode serv;
105 * At what time should the created service mapping expire?
107 struct GNUNET_TIME_Absolute expiration_time;
110 * AF_INET or AF_INET6.
115 * GNUNET_YES if we are to call the callback only after successful
116 * mesh tunnel creation.
121 * For service redirection, IPPROT_UDP or IPPROTO_TCP.
129 * Cancel redirection request with the service.
131 * @param rr request to cancel
134 GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr)
136 struct GNUNET_VPN_Handle *vh;
139 GNUNET_CONTAINER_DLL_remove (vh->rr_head,
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.
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
170 struct GNUNET_VPN_RedirectionRequest *
171 GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *rh,
174 const struct GNUNET_PeerIdentity *peer,
175 const GNUNET_HashCode *serv,
177 struct GNUNET_TIME_Absolute expiration_time,
178 GNUNET_VPN_AllocationCallback cb,
181 return NULL; // FIXME
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.
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
209 struct GNUNET_VPN_RedirectionRequest *
210 GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *rh,
214 struct GNUNET_TIME_Absolute expiration_time,
215 GNUNET_VPN_AllocationCallback cb,
218 return NULL; // FIXME
223 * Connect to the VPN service
225 * @param cfg configuration to use
228 struct GNUNET_VPN_Handle *
229 GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
231 struct GNUNET_VPN_Handle *vh;
233 vh = GNUNET_malloc (sizeof (struct GNUNET_VPN_Handle));
235 vh->client = GNUNET_CLIENT_connect ("vpn", cfg);
241 * Disconnect from the VPN service.
243 * @param vh VPN handle
246 GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh)
248 GNUNET_assert (NULL == vh->rr_head);
249 GNUNET_CLIENT_disconnect (vh->client, GNUNET_NO);
253 /* end of vpn_api.c */