src: for every AGPL3.0 file, add SPDX identifier.
[oweals/gnunet.git] / src / include / gnunet_vpn_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012 GNUnet e.V.
4
5       GNUnet is free software: you can redistribute it and/or modify it
6       under the terms of the GNU Affero General Public License as published
7       by the Free Software Foundation, either version 3 of the License,
8       or (at your 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       Affero General Public License for more details.
14      
15       You should have received a copy of the GNU Affero General Public License
16       along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * API to access the VPN service.
26  *
27  * @defgroup vpn  VPN service
28  *
29  * @{
30  */
31 #ifndef GNUNET_VPN_SERVICE_H
32 #define GNUNET_VPN_SERVICE_H
33
34 #include "gnunet_util_lib.h"
35
36
37 /**
38  * Opaque VPN handle
39  */
40 struct GNUNET_VPN_Handle;
41
42 /**
43  * Opaque redirection request handle.
44  */
45 struct GNUNET_VPN_RedirectionRequest;
46
47
48 /**
49  * Callback invoked from the VPN service once a redirection is
50  * available.  Provides the IP address that can now be used to
51  * reach the requested destination.
52  *
53  * @param cls closure
54  * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
55  *                will match 'result_af' from the request
56  * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
57  *                that the VPN allocated for the redirection;
58  *                traffic to this IP will now be redirected to the
59  *                specified target peer; NULL on error
60  */
61 typedef void (*GNUNET_VPN_AllocationCallback)(void *cls,
62                                               int af,
63                                               const void *address);
64
65
66 /**
67  * Cancel redirection request with the service.
68  *
69  * @param rr request to cancel
70  */
71 void
72 GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr);
73
74
75 /**
76  * Tell the VPN that a forwarding to a particular peer offering a
77  * particular service is requested.  The VPN is to reserve a
78  * particular IP for the redirection and return it.  The VPN will
79  * begin the redirection as soon as possible and maintain it as long
80  * as it is actively used and keeping it is feasible.  Given resource
81  * limitations, the longest inactive mappings will be destroyed.
82  *
83  * @param vh VPN handle
84  * @param result_af desired address family for the returned allocation
85  *                  can also be AF_UNSPEC
86  * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP
87  * @param peer target peer for the redirection
88  * @param serv service descriptor to give to the peer
89  * @param expiration_time at what time should the redirection expire?
90  *        (this should not impact connections that are active at that time)
91  * @param cb function to call with the IP
92  * @param cb_cls closure for cb
93  * @return handle to cancel the request (means the callback won't be
94  *         invoked anymore; the mapping may or may not be established
95  *         anyway)
96  */
97 struct GNUNET_VPN_RedirectionRequest *
98 GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *vh,
99                              int result_af,
100                              uint8_t protocol,
101                              const struct GNUNET_PeerIdentity *peer,
102                              const struct GNUNET_HashCode *serv,
103                              struct GNUNET_TIME_Absolute expiration_time,
104                              GNUNET_VPN_AllocationCallback cb,
105                              void *cb_cls);
106
107
108 /**
109  * Tell the VPN that forwarding to the Internet via some exit node is
110  * requested.  Note that both UDP and TCP traffic will be forwarded,
111  * but possibly to different exit nodes.  The VPN is to reserve a
112  * particular IP for the redirection and return it.  The VPN will
113  * begin the redirection as soon as possible and maintain it as long
114  * as it is actively used and keeping it is feasible.  Given resource
115  * limitations, the longest inactive mappings will be destroyed.
116  *
117  * @param vh VPN handle
118  * @param result_af desired address family for the returned allocation,
119  *                  can also be AF_UNSPEC
120  * @param addr_af address family for 'addr', AF_INET or AF_INET6
121  * @param addr destination IP address on the Internet; destination
122  *             port is to be taken from the VPN packet itself
123  * @param expiration_time at what time should the redirection expire?
124  *        (this should not impact connections that are active at that time)
125  * @param cb function to call with the IP
126  * @param cb_cls closure for cb
127  * @return handle to cancel the request (means the callback won't be
128  *         invoked anymore; the mapping may or may not be established
129  *         anyway)
130  */
131 struct GNUNET_VPN_RedirectionRequest *
132 GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh,
133                            int result_af,
134                            int addr_af,
135                            const void *addr,
136                            struct GNUNET_TIME_Absolute expiration_time,
137                            GNUNET_VPN_AllocationCallback cb,
138                            void *cb_cls);
139
140
141 /**
142  * Connect to the VPN service
143  *
144  * @param cfg configuration to use
145  * @return VPN handle
146  */
147 struct GNUNET_VPN_Handle *
148 GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
149
150
151 /**
152  * Disconnect from the VPN service.
153  *
154  * @param vh VPN handle
155  */
156 void
157 GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh);
158
159 #endif
160
161 /** @} */  /* end of group */