GNUnet  0.10.x
Functions | Variables
gnunet-vpn.c File Reference

Tool to manually request VPN tunnels to be created. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_tun_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...
 

Detailed Description

Tool to manually request VPN tunnels to be created.

Author
Christian Grothoff

Definition in file gnunet-vpn.c.

Function Documentation

◆ do_disconnect()

static void do_disconnect ( void *  cls)
static

Shutdown.

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

References GNUNET_free_non_null, GNUNET_VPN_cancel_request(), GNUNET_VPN_disconnect(), peer_id, service_name, and target_ip.

Referenced by run().

99 {
100  if (NULL != request)
101  {
103  request = NULL;
104  }
105  if (NULL != handle)
106  {
108  handle = NULL;
109  }
113 }
static char * target_ip
Option -i: target IP.
Definition: gnunet-vpn.c:56
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
Definition: vpn_api.c:526
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
void GNUNET_VPN_cancel_request(struct GNUNET_VPN_RedirectionRequest *rr)
Cancel redirection request with the service.
Definition: vpn_api.c:369
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:36
static char * peer_id
Option -p: destination peer identity for service.
Definition: gnunet-vpn.c:46
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 130 of file gnunet-vpn.c.

References _, buf, FPRINTF, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_shutdown(), and ret.

Referenced by run().

133 {
134  char buf[INET6_ADDRSTRLEN];
135 
136  request = NULL;
137  switch (af)
138  {
139  case AF_INET6:
140  case AF_INET:
141  FPRINTF (stdout,
142  "%s\n",
143  inet_ntop (af, address, buf, sizeof (buf)));
144  break;
145  case AF_UNSPEC:
147  _("Error creating tunnel\n"));
148  ret = 1;
149  break;
150  default:
151  break;
152  }
154 }
#define FPRINTF
Definition: plibc.h:683
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static char buf[2048]
static int ret
Global return value.
Definition: gnunet-vpn.c:86
#define GNUNET_log(kind,...)
static char * address
GNS address for this phone.
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 166 of file gnunet-vpn.c.

References _, allocation_cb(), do_disconnect(), FPRINTF, 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(), inet_pton(), ipv4, ipv6, peer_id, GNUNET_PeerIdentity::public_key, ret, service_name, target_ip, tcp, and udp.

Referenced by main().

170 {
171  int dst_af;
172  int req_af;
173  struct GNUNET_PeerIdentity peer;
174  struct GNUNET_HashCode sd;
175  const void *addr;
176  struct in_addr v4;
177  struct in6_addr v6;
178  uint8_t protocol;
180 
183  handle = GNUNET_VPN_connect (cfg);
184  if (NULL == handle)
185  goto error;
186  req_af = AF_UNSPEC;
187  if (ipv4)
188  {
189  if (ipv6)
190  {
191  FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"),
192  "-4", "-6");
193  goto error;
194  }
195  req_af = AF_INET;
196  }
197  if (ipv6)
198  req_af = AF_INET6;
199 
200  if (NULL == target_ip)
201  {
202  if (NULL == service_name)
203  {
204  FPRINTF (stderr, _("Option `%s' or `%s' is required.\n"),
205  "-i", "-s");
206  goto error;
207  }
208  if (NULL == peer_id)
209  {
210  FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"),
211  "-p", "-s");
212  goto error;
213  }
214  if (! (tcp | udp) )
215  {
216  FPRINTF (stderr, _("Option `%s' or `%s' is required when using option `%s'.\n"),
217  "-t", "-u", "-s");
218  goto error;
219  }
220  if (tcp & udp)
221  {
222  FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"),
223  "-t", "-u");
224  goto error;
225  }
226  if (tcp)
227  protocol = IPPROTO_TCP;
228  if (udp)
229  protocol = IPPROTO_UDP;
230  if (GNUNET_OK !=
232  strlen (peer_id),
233  &peer.public_key))
234  {
235  FPRINTF (stderr,
236  _("`%s' is not a valid peer identifier.\n"),
237  peer_id);
238  goto error;
239  }
241  &sd);
243  req_af,
244  protocol,
245  &peer,
246  &sd,
247  etime,
248  &allocation_cb, NULL);
249  }
250  else
251  {
252  if (1 != inet_pton (AF_INET6, target_ip, &v6))
253  {
254  if (1 != inet_pton (AF_INET, target_ip, &v4))
255  {
256  FPRINTF (stderr, _("`%s' is not a valid IP address.\n"),
257  target_ip);
258  goto error;
259  }
260  else
261  {
262  dst_af = AF_INET;
263  addr = &v4;
264  }
265  }
266  else
267  {
268  dst_af = AF_INET6;
269  addr = &v6;
270  }
272  req_af,
273  dst_af,
274  addr,
275  etime,
276  &allocation_cb, NULL);
277  }
278  return;
279 
280  error:
282  ret = 1;
283 }
static char * target_ip
Option -i: target IP.
Definition: gnunet-vpn.c:56
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:76
#define FPRINTF
Definition: plibc.h:683
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:61
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:245
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:130
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:91
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
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: regex.c:804
static int ret
Global return value.
Definition: gnunet-vpn.c:86
A 512-bit hashcode.
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:404
static uint64_t etime
Expiration string converted to numeric value.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static int tcp
Option -t: TCP requested.
Definition: gnunet-vpn.c:71
int 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:501
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
Definition: vpn_api.c:504
The identity of the host (wraps the signing key of the peer).
static void do_disconnect(void *cls)
Shutdown.
Definition: gnunet-vpn.c:98
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:36
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
static char * peer_id
Option -p: destination peer identity for service.
Definition: gnunet-vpn.c:46
Time for absolute times used by GNUnet, in microseconds.
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66
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:455
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 287 of file gnunet-vpn.c.

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

288 {
291  "ipv4",
292  gettext_noop ("request that result should be an IPv4 address"),
293  &ipv4),
294 
296  "ipv6",
297  gettext_noop ("request that result should be an IPv6 address"),
298  &ipv6),
299 
301  "duration",
302  "TIME",
303  gettext_noop ("how long should the mapping be valid for new tunnels?"),
304  &duration),
305 
307  "ip",
308  "IP",
309  gettext_noop ("destination IP for the tunnel"),
310  &target_ip),
311 
313  "peer",
314  "PEERID",
315  gettext_noop ("peer offering the service we would like to access"),
316  &peer_id),
317 
319  "service",
320  "NAME",
321  gettext_noop ("name of the service we would like to access"),
322  &service_name),
323 
325  "tcp",
326  gettext_noop ("service is offered via TCP"),
327  &tcp),
328 
330  "udp",
331  gettext_noop ("service is offered via UDP"),
332  &udp),
333 
335 
337  };
338  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
339  return 2;
340 
341  ret = (GNUNET_OK ==
342  GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn",
344  ("Setup tunnels via VPN."), options,
345  &run, NULL)) ? ret : 1;
346  GNUNET_free ((void *) argv);
347  return ret;
348 }
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)...
static char * target_ip
Option -i: target IP.
Definition: gnunet-vpn.c:56
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:76
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
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:166
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static int ipv4
Option -4: IPv4 requested.
Definition: gnunet-vpn.c:61
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
static unsigned int verbosity
Selected level of verbosity.
Definition: gnunet-vpn.c:81
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:91
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
static int ret
Global return value.
Definition: gnunet-vpn.c:86
static int tcp
Option -t: TCP requested.
Definition: gnunet-vpn.c:71
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.
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:361
static char * peer_id
Option -p: destination peer identity for service.
Definition: gnunet-vpn.c:46
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66
Here is the call graph for this function:

Variable Documentation

◆ handle

struct GNUNET_VPN_Handle* handle
static

Handle to vpn service.

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

◆ request

Opaque redirection request handle.

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

Referenced by create_response(), generate_gns_certificate(), handle_request(), and open_device().

◆ peer_id

char* peer_id
static

Option -p: destination peer identity for service.

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

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

◆ service_name

char* service_name
static

Option -s: service name (hash to get service descriptor)

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

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

◆ target_ip

char* target_ip
static

Option -i: target IP.

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

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

◆ ipv4

int ipv4
static

Option -4: IPv4 requested.

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

Referenced by GNUNET_HOSTLIST_server_start(), handle_icmp_back(), handle_tcp_back(), handle_udp_back(), main(), and run().

◆ ipv6

int ipv6
static

Option -6: IPv6 requested.

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

Referenced by GNUNET_HOSTLIST_server_start(), handle_icmp_back(), handle_tcp_back(), handle_udp_back(), main(), and run().

◆ tcp

int tcp
static

Option -t: TCP requested.

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

Referenced by handle_tcp_back(), main(), route_packet(), and run().

◆ udp

int udp
static

◆ verbosity

unsigned int verbosity
static

Selected level of verbosity.

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

Referenced by main().

◆ ret

int ret
static

Global return value.

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

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

◆ duration

struct GNUNET_TIME_Relative duration = { 5 * 60 * 1000}
static

Option '-d': duration of the mapping.

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