GNUnet 0.22.2
gnunet-vpn.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_vpn_service.h"
Include dependency graph for gnunet-vpn.c:

Go to the source code of this file.

Functions

static void do_disconnect (void *cls)
 Shutdown. More...
 
static void allocation_cb (void *cls, int af, const void *address)
 Callback invoked from the VPN service once a redirection is available. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 

Variables

static struct GNUNET_VPN_Handlehandle
 Handle to vpn service. More...
 
static struct GNUNET_VPN_RedirectionRequestrequest
 Opaque redirection request handle. More...
 
static char * peer_id
 Option -p: destination peer identity for service. More...
 
static char * service_name
 Option -s: service name (hash to get service descriptor) More...
 
static char * target_ip
 Option -i: target IP. More...
 
static int ipv4
 Option -4: IPv4 requested. More...
 
static int ipv6
 Option -6: IPv6 requested. More...
 
static int tcp
 Option -t: TCP requested. More...
 
static int udp
 Option -u: UDP requested. More...
 
static unsigned int verbosity
 Selected level of verbosity. More...
 
static int ret
 Global return value. More...
 
static struct GNUNET_TIME_Relative duration = { 5 * 60 * 1000 }
 Option '-d': duration of the mapping. More...
 

Function Documentation

◆ do_disconnect()

static void do_disconnect ( void *  cls)
static

Shutdown.

Definition at line 97 of file gnunet-vpn.c.

98{
99 if (NULL != request)
100 {
102 request = NULL;
103 }
104 if (NULL != handle)
105 {
107 handle = NULL;
108 }
112}
static char * target_ip
Option -i: target IP.
Definition: gnunet-vpn.c:55
static char * peer_id
Option -p: destination peer identity for service.
Definition: gnunet-vpn.c:45
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_VPN_cancel_request(struct GNUNET_VPN_RedirectionRequest *rr)
Cancel redirection request with the service.
Definition: vpn_api.c:375
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
Definition: vpn_api.c:512

References GNUNET_free, GNUNET_VPN_cancel_request(), GNUNET_VPN_disconnect(), handle, peer_id, request, service_name, and target_ip.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allocation_cb()

static void allocation_cb ( void *  cls,
int  af,
const void *  address 
)
static

Callback invoked from the VPN service once a redirection is available.

Provides the IP address that can now be used to reach the requested destination.

Parameters
clsclosure
afaddress family, AF_INET or AF_INET6; AF_UNSPEC on error; will match 'result_af' from the request
addressIP address (struct in_addr or struct in_addr6, depending on 'af') that the VPN allocated for the redirection; traffic to this IP will now be redirected to the specified target peer; NULL on error

Definition at line 129 of file gnunet-vpn.c.

130{
131 char buf[INET6_ADDRSTRLEN];
132
133 request = NULL;
134 switch (af)
135 {
136 case AF_INET6:
137 case AF_INET:
138 fprintf (stdout, "%s\n", inet_ntop (af, address, buf, sizeof(buf)));
139 break;
140
141 case AF_UNSPEC:
142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Error creating tunnel\n"));
143 ret = 1;
144 break;
145
146 default:
147 break;
148 }
150}
static char * address
GNS address for this phone.
static int ret
Global return value.
Definition: gnunet-vpn.c:85
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

References _, address, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_shutdown(), request, and ret.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 162 of file gnunet-vpn.c.

166{
167 int dst_af;
168 int req_af;
169 struct GNUNET_PeerIdentity peer;
170 struct GNUNET_HashCode sd;
171 const void *addr;
172 struct in_addr v4;
173 struct in6_addr v6;
174 uint8_t protocol;
176
180 if (NULL == handle)
181 goto error;
182 req_af = AF_UNSPEC;
183 if (ipv4)
184 {
185 if (ipv6)
186 {
187 fprintf (stderr,
188 _ ("Option `%s' makes no sense with option `%s'.\n"),
189 "-4",
190 "-6");
191 goto error;
192 }
193 req_af = AF_INET;
194 }
195 if (ipv6)
196 req_af = AF_INET6;
197
198 if (NULL == target_ip)
199 {
200 if (NULL == service_name)
201 {
202 fprintf (stderr, _ ("Option `%s' or `%s' is required.\n"), "-i", "-s");
203 goto error;
204 }
205 if (NULL == peer_id)
206 {
207 fprintf (stderr,
208 _ ("Option `%s' is required when using option `%s'.\n"),
209 "-p",
210 "-s");
211 goto error;
212 }
213 if (! (tcp | udp))
214 {
215 fprintf (stderr,
216 _ ("Option `%s' or `%s' is required when using option `%s'.\n"),
217 "-t",
218 "-u",
219 "-s");
220 goto error;
221 }
222 if (tcp & udp)
223 {
224 fprintf (stderr,
225 _ ("Option `%s' makes no sense with option `%s'.\n"),
226 "-t",
227 "-u");
228 goto error;
229 }
230 if (tcp)
231 protocol = IPPROTO_TCP;
232 if (udp)
233 protocol = IPPROTO_UDP;
234 if (GNUNET_OK !=
236 strlen (peer_id),
237 &peer.public_key))
238 {
239 fprintf (stderr, _ ("`%s' is not a valid peer identifier.\n"), peer_id);
240 goto error;
241 }
244 req_af,
245 protocol,
246 &peer,
247 &sd,
248 etime,
250 NULL);
251 }
252 else
253 {
254 if (1 != inet_pton (AF_INET6, target_ip, &v6))
255 {
256 if (1 != inet_pton (AF_INET, target_ip, &v4))
257 {
258 fprintf (stderr, _ ("`%s' is not a valid IP address.\n"), target_ip);
259 goto error;
260 }
261 else
262 {
263 dst_af = AF_INET;
264 addr = &v4;
265 }
266 }
267 else
268 {
269 dst_af = AF_INET6;
270 addr = &v6;
271 }
273 req_af,
274 dst_af,
275 addr,
276 etime,
278 NULL);
279 }
280 return;
281
282error:
284 ret = 1;
285}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static uint64_t etime
Expiration string converted to numeric value.
static void do_disconnect(void *cls)
Shutdown.
Definition: gnunet-vpn.c:97
static void allocation_cb(void *cls, int af, const void *address)
Callback invoked from the VPN service once a redirection is available.
Definition: gnunet-vpn.c:129
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:90
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:60
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:75
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:65
static int tcp
Option -t: TCP requested.
Definition: gnunet-vpn.c:70
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:361
@ GNUNET_OK
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
void GNUNET_TUN_service_name_to_hash(const char *service_name, struct GNUNET_HashCode *hc)
Hash the service name of a hosted service to the hash code that is used to identify the service on th...
Definition: tun.c:38
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
Definition: vpn_api.c:490
struct GNUNET_VPN_RedirectionRequest * GNUNET_VPN_redirect_to_peer(struct GNUNET_VPN_Handle *vh, int result_af, uint8_t protocol, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *serv, struct GNUNET_TIME_Absolute expiration_time, GNUNET_VPN_AllocationCallback cb, void *cb_cls)
Tell the VPN that a forwarding to a particular peer offering a particular service is requested.
Definition: vpn_api.c:388
struct GNUNET_VPN_RedirectionRequest * GNUNET_VPN_redirect_to_ip(struct GNUNET_VPN_Handle *vh, int result_af, int addr_af, const void *addr, struct GNUNET_TIME_Absolute expiration_time, GNUNET_VPN_AllocationCallback cb, void *cb_cls)
Tell the VPN that forwarding to the Internet via some exit node is requested.
Definition: vpn_api.c:439
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.

References _, allocation_cb(), cfg, do_disconnect(), duration, etime, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_relative_to_absolute(), GNUNET_TUN_service_name_to_hash(), GNUNET_VPN_connect(), GNUNET_VPN_redirect_to_ip(), GNUNET_VPN_redirect_to_peer(), handle, ipv4, ipv6, peer_id, GNUNET_PeerIdentity::public_key, request, ret, service_name, target_ip, tcp, and udp.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

Definition at line 289 of file gnunet-vpn.c.

290{
293 "ipv4",
295 "request that result should be an IPv4 address"),
296 &ipv4),
297
299 "ipv6",
301 "request that result should be an IPv6 address"),
302 &ipv6),
303
305 'd',
306 "duration",
307 "TIME",
308 gettext_noop ("how long should the mapping be valid for new tunnels?"),
309 &duration),
310
312 "ip",
313 "IP",
315 "destination IP for the tunnel"),
316 &target_ip),
317
319 'p',
320 "peer",
321 "PEERID",
322 gettext_noop ("peer offering the service we would like to access"),
323 &peer_id),
324
326 "service",
327 "NAME",
329 "name of the service we would like to access"),
330 &service_name),
331
333 "tcp",
334 gettext_noop ("service is offered via TCP"),
335 &tcp),
336
338 "udp",
339 gettext_noop ("service is offered via UDP"),
340 &udp),
341
343
345
346 ret =
347 (GNUNET_OK ==
349 argc,
350 argv,
351 "gnunet-vpn",
352 gettext_noop ("Setup tunnels via VPN."),
353 options,
354 &run,
355 NULL))
356 ? ret
357 : 1;
358 return ret;
359}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static unsigned int verbosity
Selected level of verbosity.
Definition: gnunet-vpn.c:80
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
Definition: gnunet-vpn.c:162
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:407
Definition of a command line option.

References duration, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_verbose(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), ipv4, ipv6, options, peer_id, ret, run(), service_name, target_ip, tcp, udp, and verbosity.

Here is the call graph for this function:

Variable Documentation

◆ handle

struct GNUNET_VPN_Handle* handle
static

Handle to vpn service.

Definition at line 35 of file gnunet-vpn.c.

Referenced by add_attribute_cont(), add_credential_cont(), add_get_request_to_pending(), add_list_handle(), add_service_handle(), attr_collect(), attr_in_claims_request(), attr_in_idtoken_request(), attr_in_userinfo_request(), authorize_endpoint(), build_authz_response(), build_redirect(), bulk_tx_start(), callback_mq_error(), callback_reconnect(), callback_room_message(), change_srv_handle_member_id(), check_authorization(), cleanup_handle(), cleanup_issue_handle(), client_redirect(), close_handle_room(), close_service_room(), close_srv_handle_room(), code_redirect(), collect_finished_cb(), consume_cont(), consume_fail(), consume_ticket(), consume_ticket_cont(), cookie_identity_interpretation(), cr_cont(), create_finished(), create_handle(), create_handle_member_id(), create_room(), create_srv_handle(), create_srv_room(), cred_collect(), del_finished(), delete_attribute_cont(), delete_credential_cont(), delete_finished_cb(), destroy_handle(), destroy_srv_handle(), do_disconnect(), do_error(), do_finished(), do_finished_create(), do_redirect_error(), do_timeout(), do_userinfo_error(), ecdsa_symmetric_decrypt(), ecdsa_symmetric_encrypt(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), ego_edit_name(), ego_edit_pubkey(), ego_get_all(), ego_get_name(), ego_get_pubkey(), ego_get_response(), ego_sign_data(), ego_sign_data_cb(), enter_srv_room_at(), entry_handle_room_at(), entry_service_room(), entry_srv_handle_room(), find_list_handle_by_member(), finished_cont(), force_reconnect(), get_cont(), get_gns_cont(), get_handle_contact(), get_handle_contact_store(), get_handle_key(), get_handle_member_session(), get_handle_name(), get_handle_pubkey(), get_handle_room(), get_oidc_dir_path(), get_srv_handle_data_subdir(), get_srv_handle_key(), get_srv_handle_member_id(), get_url_parameter_copy(), GNUNET_ABD_collect(), GNUNET_ABD_connect(), GNUNET_ABD_disconnect(), GNUNET_ABD_request_cancel(), GNUNET_ABD_verify(), GNUNET_CADET_disconnect(), GNUNET_CORE_disconnect(), GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_DHT_connect(), GNUNET_DHT_disconnect(), GNUNET_DHT_get_start(), GNUNET_DHT_get_stop(), GNUNET_DHT_monitor_start(), GNUNET_DHT_monitor_stop(), GNUNET_DHT_put(), GNUNET_DHT_put_cancel(), GNUNET_GNS_connect(), GNUNET_GNS_disconnect(), GNUNET_GNS_lookup(), GNUNET_GNS_lookup_cancel(), GNUNET_GNS_lookup_limited(), GNUNET_GNS_lookup_with_tld(), GNUNET_MESSENGER_connect(), GNUNET_MESSENGER_disconnect(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_find_rooms(), GNUNET_MESSENGER_get_key(), GNUNET_MESSENGER_get_name(), GNUNET_MESSENGER_open_room(), GNUNET_MESSENGER_set_key(), GNUNET_MESSENGER_set_name(), GNUNET_STATISTICS_get(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), GNUNET_STATISTICS_watch(), GNUNET_STATISTICS_watch_cancel(), GNUNET_TRANSPORT_core_get_mq(), handle_client_hello(), handle_client_result(), handle_gns_response(), handle_intermediate(), handle_member_id(), handle_miss_message(), handle_monitor_get(), handle_monitor_get_resp(), handle_monitor_put(), handle_recv_message(), handle_result(), handle_room_close(), handle_room_entry(), handle_room_open(), handle_room_sync(), handle_ticket_result(), header_iterator(), import_next_cb(), initialize_handle_via_key(), initialize_service_handle(), is_srv_handle_routing(), iterate_close_room(), iterate_close_rooms(), iterate_next_member_ids(), iterate_reset_room(), iterate_save_member_session_history_hentries(), iterate_save_peers(), iterate_send_name_to_room(), join_room(), join_room_locally(), jwks_endpoint(), list_attribute_cont(), list_credential_cont(), list_tickets_cont(), load_list_messages(), load_list_tunnels(), load_member_session_history(), load_peer_store(), login_cont(), login_redirect(), lookup_redirect_uri_result(), main_task(), merge_srv_room_last_messages(), mq_error_handler(), namestore_add(), namestore_add_or_update(), namestore_delete(), namestore_get(), namestore_import(), namestore_iteration_error(), namestore_list_finished(), namestore_list_iteration(), namestore_update(), neighbour_delete(), notify_srv_handle_member_id(), notify_srv_handle_message(), ns_get_lookup_cb(), ns_lookup_cb(), ns_lookup_error_cb(), oidc_attr_collect(), oidc_attr_collect_finished_cb(), oidc_config_cors(), oidc_config_endpoint(), oidc_cred_collect(), oidc_cred_collect_finished_cb(), oidc_iteration_error(), oidc_ticket_issue_cb(), on_identity(), open_handle_room(), open_service_room(), open_srv_handle_room(), open_srv_room(), options_cont(), pack_srv_room_message(), parse_credentials_basic_auth(), parse_credentials_post_body(), plugin_callback(), post_data_iter(), process_message_control(), reconnect(), reconnect_task(), remove_list_handle(), remove_service_handle(), REST_config_process_request(), REST_copying_process_request(), REST_gns_process_request(), rest_identity_process_request(), REST_identity_process_request(), REST_namestore_process_request(), REST_openid_process_request(), REST_reclaim_process_request(), return_response(), revoke_ticket_cont(), run(), save_list_messages(), save_list_tunnels(), save_member_session_history(), save_peer_store(), send_close_room(), send_enter_room(), send_message_id(), send_message_join(), send_message_key(), send_open_room(), send_room_info(), send_srv_handle_message(), send_srv_room_message(), send_sync_room(), send_tunnel_message(), set_cont(), set_handle_key(), set_handle_name(), set_srv_handle_key(), setup_cipher_aes(), setup_cipher_twofish(), sign_srv_room_message_by_peer(), store_ticket_issue_cont(), sync_srv_handle_messages(), task_message_control(), task_notify_srv_handle_member_id(), ticket_collect(), tld_iter(), token_endpoint(), transmit_get(), transmit_set(), transmit_watch(), url_iterator(), and userinfo_endpoint().

◆ request

◆ peer_id

char* peer_id
static

Option -p: destination peer identity for service.

Definition at line 45 of file gnunet-vpn.c.

Referenced by do_disconnect(), main(), and run().

◆ service_name

◆ target_ip

char* target_ip
static

Option -i: target IP.

Definition at line 55 of file gnunet-vpn.c.

Referenced by do_disconnect(), main(), and run().

◆ ipv4

◆ ipv6

◆ tcp

int tcp
static

◆ udp

◆ verbosity

unsigned int verbosity
static

Selected level of verbosity.

Definition at line 80 of file gnunet-vpn.c.

Referenced by main().

◆ ret

int ret
static

Global return value.

Definition at line 85 of file gnunet-vpn.c.

Referenced by allocation_cb(), main(), and run().

◆ duration