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 * Desired address family for the result.
115 * Address family of 'addr'. AF_INET or AF_INET6.
120 * GNUNET_YES if we are to call the callback only after successful
121 * mesh tunnel creation.
126 * For service redirection, IPPROT_UDP or IPPROTO_TCP.
134 * Cancel redirection request with the service.
136 * @param rr request to cancel
139 GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr)
141 struct GNUNET_VPN_Handle *vh;
144 GNUNET_CONTAINER_DLL_remove (vh->rr_head,
152 * Tell the VPN that a forwarding to a particular peer offering a
153 * particular service is requested. The VPN is to reserve a
154 * particular IP for the redirection and return it. The VPN will
155 * begin the redirection as soon as possible and maintain it as long
156 * as it is actively used and keeping it is feasible. Given resource
157 * limitations, the longest inactive mappings will be destroyed.
159 * @param vh VPN handle
160 * @param af address family, AF_INET or AF_INET6
161 * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP
162 * @param peer target peer for the redirection
163 * @param serv service descriptor to give to the peer
164 * @param nac GNUNET_YES to notify via callback only after completion of
165 * the MESH-level connection,
166 * GNUNET_NO to notify as soon as the IP has been reserved
167 * @param expiration_time at what time should the redirection expire?
168 * (this should not impact connections that are active at that time)
169 * @param cb function to call with the IP
170 * @param cb_cls closure for cb
171 * @return handle to cancel the request (means the callback won't be
172 * invoked anymore; the mapping may or may not be established
175 struct GNUNET_VPN_RedirectionRequest *
176 GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *rh,
179 const struct GNUNET_PeerIdentity *peer,
180 const GNUNET_HashCode *serv,
182 struct GNUNET_TIME_Absolute expiration_time,
183 GNUNET_VPN_AllocationCallback cb,
186 return NULL; // FIXME
191 * Tell the VPN that forwarding to the Internet via some exit node is
192 * requested. Note that both UDP and TCP traffic will be forwarded,
193 * but possibly to different exit nodes. The VPN is to reserve a
194 * particular IP for the redirection and return it. The VPN will
195 * begin the redirection as soon as possible and maintain it as long
196 * as it is actively used and keeping it is feasible. Given resource
197 * limitations, the longest inactive mappings will be destroyed.
199 * @param vh VPN handle
200 * @param result_af desired address family for the returned allocation
201 * @param addr_af address family for 'addr', AF_INET or AF_INET6
202 * @param addr destination IP address on the Internet; destination
203 * port is to be taken from the VPN packet itself
204 * @param nac GNUNET_YES to notify via callback only after completion of
205 * the MESH-level connection,
206 * GNUNET_NO to notify as soon as the IP has been reserved
207 * @param expiration_time at what time should the redirection expire?
208 * (this should not impact connections that are active at that time)
209 * @param cb function to call with the IP
210 * @param cb_cls closure for cb
211 * @return handle to cancel the request (means the callback won't be
212 * invoked anymore; the mapping may or may not be established
215 struct GNUNET_VPN_RedirectionRequest *
216 GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *rh,
221 struct GNUNET_TIME_Absolute expiration_time,
222 GNUNET_VPN_AllocationCallback cb,
225 return NULL; // FIXME
230 * Connect to the VPN service
232 * @param cfg configuration to use
235 struct GNUNET_VPN_Handle *
236 GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
238 struct GNUNET_VPN_Handle *vh;
240 vh = GNUNET_malloc (sizeof (struct GNUNET_VPN_Handle));
242 vh->client = GNUNET_CLIENT_connect ("vpn", cfg);
248 * Disconnect from the VPN service.
250 * @param vh VPN handle
253 GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh)
255 GNUNET_assert (NULL == vh->rr_head);
256 GNUNET_CLIENT_disconnect (vh->client, GNUNET_NO);
260 /* end of vpn_api.c */