controller link as operation
[oweals/gnunet.git] / src / include / gnunet_vpn_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2012 Christian Grothoff (and other contributing authors)
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 2, 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 include/gnunet_vpn_service.h
23  * @brief API to access the VPN service. 
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_VPN_SERVICE_H
27 #define GNUNET_VPN_SERVICE_H
28
29 #include "gnunet_util_lib.h"
30
31
32 /**
33  * Opaque VPN handle
34  */
35 struct GNUNET_VPN_Handle;
36
37 /**
38  * Opaque redirection request handle.
39  */
40 struct GNUNET_VPN_RedirectionRequest;
41
42
43 /**
44  * Callback invoked from the VPN service once a redirection is
45  * available.  Provides the IP address that can now be used to
46  * reach the requested destination.
47  *
48  * @param cls closure
49  * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
50  *                will match 'result_af' from the request
51  * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
52  *                that the VPN allocated for the redirection;
53  *                traffic to this IP will now be redirected to the 
54  *                specified target peer; NULL on error
55  */
56 typedef void (*GNUNET_VPN_AllocationCallback)(void *cls,
57                                               int af,
58                                               const void *address);
59
60
61 /**
62  * Cancel redirection request with the service.
63  *
64  * @param rr request to cancel
65  */
66 void
67 GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr);
68
69
70 /**
71  * Tell the VPN that a forwarding to a particular peer offering a
72  * particular service is requested.  The VPN is to reserve a
73  * particular IP for the redirection and return it.  The VPN will
74  * begin the redirection as soon as possible and maintain it as long
75  * as it is actively used and keeping it is feasible.  Given resource
76  * limitations, the longest inactive mappings will be destroyed.
77  *
78  * @param vh VPN handle
79  * @param result_af desired address family for the returned allocation
80  *                  can also be AF_UNSPEC
81  * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP
82  * @param peer target peer for the redirection
83  * @param serv service descriptor to give to the peer
84  * @param nac GNUNET_YES to notify via callback only after completion of
85  *            the MESH-level connection,
86  *            GNUNET_NO to notify as soon as the IP has been reserved
87  * @param expiration_time at what time should the redirection expire?
88  *        (this should not impact connections that are active at that time)
89  * @param cb function to call with the IP
90  * @param cb_cls closure for cb
91  * @return handle to cancel the request (means the callback won't be
92  *         invoked anymore; the mapping may or may not be established
93  *         anyway)
94  */
95 struct GNUNET_VPN_RedirectionRequest *
96 GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *vh,
97                              int result_af,
98                              uint8_t protocol,
99                              const struct GNUNET_PeerIdentity *peer,
100                              const struct GNUNET_HashCode *serv,
101                              int nac,
102                              struct GNUNET_TIME_Absolute expiration_time,
103                              GNUNET_VPN_AllocationCallback cb,
104                              void *cb_cls);
105
106                 
107 /**
108  * Tell the VPN that forwarding to the Internet via some exit node is
109  * requested.  Note that both UDP and TCP traffic will be forwarded,
110  * but possibly to different exit nodes.  The VPN is to reserve a
111  * particular IP for the redirection and return it.  The VPN will
112  * begin the redirection as soon as possible and maintain it as long
113  * as it is actively used and keeping it is feasible.  Given resource
114  * limitations, the longest inactive mappings will be destroyed.
115  *
116  * @param vh VPN handle
117  * @param result_af desired address family for the returned allocation,
118  *                  can also be AF_UNSPEC
119  * @param addr_af address family for 'addr', AF_INET or AF_INET6
120  * @param addr destination IP address on the Internet; destination
121  *             port is to be taken from the VPN packet itself
122  * @param nac GNUNET_YES to notify via callback only after completion of
123  *            the MESH-level connection,
124  *            GNUNET_NO to notify as soon as the IP has been reserved
125  * @param expiration_time at what time should the redirection expire?
126  *        (this should not impact connections that are active at that time)
127  * @param cb function to call with the IP
128  * @param cb_cls closure for cb
129  * @return handle to cancel the request (means the callback won't be
130  *         invoked anymore; the mapping may or may not be established
131  *         anyway)
132  */
133 struct GNUNET_VPN_RedirectionRequest *
134 GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh, 
135                            int result_af,
136                            int addr_af,
137                            const void *addr,
138                            int nac,
139                            struct GNUNET_TIME_Absolute expiration_time,
140                            GNUNET_VPN_AllocationCallback cb,
141                            void *cb_cls);
142
143
144 /**
145  * Connect to the VPN service
146  *
147  * @param cfg configuration to use
148  * @return VPN handle 
149  */
150 struct GNUNET_VPN_Handle *
151 GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
152
153
154 /**
155  * Disconnect from the VPN service.
156  *
157  * @param vh VPN handle
158  */
159 void
160 GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh);
161
162 #endif