aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-05 21:23:02 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-05 21:23:02 +0100
commit1b7f6eea0a06abab9b75b30f021aa6313fccfcd4 (patch)
tree0d726dbd6650997c22a7c17ce833ce53c23bde9e /src
parent07d7291d64688ecf9ef0bf2b663b10a168d5fff2 (diff)
downloadgnunet-1b7f6eea0a06abab9b75b30f021aa6313fccfcd4.tar.gz
gnunet-1b7f6eea0a06abab9b75b30f021aa6313fccfcd4.zip
pass section name instead of specific option via IPC
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_nat_service.h4
-rw-r--r--src/nat/gnunet-nat.c14
-rw-r--r--src/nat/gnunet-service-nat.c20
-rw-r--r--src/nat/nat.h9
-rw-r--r--src/nat/nat_api.c19
-rw-r--r--src/transport/transport.conf.in13
6 files changed, 48 insertions, 31 deletions
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index 0dbc23e74..6b9650306 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -185,8 +185,8 @@ struct GNUNET_NAT_Handle;
185 * address_callback for any 'plausible' external address. 185 * address_callback for any 'plausible' external address.
186 * 186 *
187 * @param cfg configuration to use 187 * @param cfg configuration to use
188 * @param config_section name of the configuration section for optionsx
188 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP 189 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
189 * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
190 * @param num_addrs number of addresses in @a addrs 190 * @param num_addrs number of addresses in @a addrs
191 * @param addrs list of local addresses packets should be redirected to 191 * @param addrs list of local addresses packets should be redirected to
192 * @param addrlens actual lengths of the addresses in @a addrs 192 * @param addrlens actual lengths of the addresses in @a addrs
@@ -198,8 +198,8 @@ struct GNUNET_NAT_Handle;
198 */ 198 */
199struct GNUNET_NAT_Handle * 199struct GNUNET_NAT_Handle *
200GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, 200GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
201 const char *config_section,
201 uint8_t proto, 202 uint8_t proto,
202 const char *hole_external,
203 unsigned int num_addrs, 203 unsigned int num_addrs,
204 const struct sockaddr **addrs, 204 const struct sockaddr **addrs,
205 const socklen_t *addrlens, 205 const socklen_t *addrlens,
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index 81e4549b5..4171babf9 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -39,10 +39,10 @@ static int global_ret;
39static struct GNUNET_NAT_AutoHandle *ah; 39static struct GNUNET_NAT_AutoHandle *ah;
40 40
41/** 41/**
42 * External hostname and port, if user manually punched 42 * Name of section in configuration file to use for
43 * the NAT. 43 * additional options.
44 */ 44 */
45static char *hole_external; 45static char *section_name;
46 46
47/** 47/**
48 * Flag set to 1 if we use IPPROTO_UDP. 48 * Flag set to 1 if we use IPPROTO_UDP.
@@ -568,8 +568,8 @@ run (void *cls,
568 if (NULL != local_addr) 568 if (NULL != local_addr)
569 { 569 {
570 nh = GNUNET_NAT_register (c, 570 nh = GNUNET_NAT_register (c,
571 section_name,
571 proto, 572 proto,
572 hole_external,
573 1, 573 1,
574 (const struct sockaddr **) &local_sa, 574 (const struct sockaddr **) &local_sa,
575 &local_len, 575 &local_len,
@@ -698,9 +698,9 @@ main (int argc,
698 {'r', "remote", "ADDRESS", 698 {'r', "remote", "ADDRESS",
699 gettext_noop ("which remote IP and port should be asked for connection reversal"), 699 gettext_noop ("which remote IP and port should be asked for connection reversal"),
700 GNUNET_YES, &GNUNET_GETOPT_set_string, &remote_addr }, 700 GNUNET_YES, &GNUNET_GETOPT_set_string, &remote_addr },
701 {'p', "punched", NULL, 701 {'S', "section", NULL,
702 gettext_noop ("external hostname and port of NAT, if punched manually; use AUTO for hostname for automatic determination of the external IP"), 702 gettext_noop ("name of configuration section to find additional options, such as manual host punching data"),
703 GNUNET_YES, &GNUNET_GETOPT_set_string, &hole_external }, 703 GNUNET_YES, &GNUNET_GETOPT_set_string, &section_name },
704 {'s', "stun", NULL, 704 {'s', "stun", NULL,
705 gettext_noop ("enable STUN processing"), 705 gettext_noop ("enable STUN processing"),
706 GNUNET_NO, &GNUNET_GETOPT_set_one, &do_stun }, 706 GNUNET_NO, &GNUNET_GETOPT_set_one, &do_stun },
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index 8af27af9e..79f806f27 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -30,8 +30,6 @@
30 * TODO: 30 * TODO:
31 * - test and document (!) ICMP based NAT traversal 31 * - test and document (!) ICMP based NAT traversal
32 * - test manual hole punching support 32 * - test manual hole punching support
33 * - consider passing transport plugin name instead of
34 * external IP address string (more flexible!)
35 * - adapt existing transports to use new NAT logic 33 * - adapt existing transports to use new NAT logic
36 * - abandon legacy NAT code 34 * - abandon legacy NAT code
37 * 35 *
@@ -186,6 +184,11 @@ struct ClientHandle
186 char *hole_external; 184 char *hole_external;
187 185
188 /** 186 /**
187 * Name of the configuration section this client cares about.
188 */
189 char *section_name;
190
191 /**
189 * Task for periodically re-running the @e ext_dns DNS lookup. 192 * Task for periodically re-running the @e ext_dns DNS lookup.
190 */ 193 */
191 struct GNUNET_SCHEDULER_Task *ext_dns_task; 194 struct GNUNET_SCHEDULER_Task *ext_dns_task;
@@ -505,7 +508,7 @@ check_register (void *cls,
505 off += alen; 508 off += alen;
506 left -= alen; 509 left -= alen;
507 } 510 }
508 if (left != ntohs (message->hole_external_len)) 511 if (left != ntohs (message->str_len))
509 { 512 {
510 GNUNET_break (0); 513 GNUNET_break (0);
511 return GNUNET_SYSERR; 514 return GNUNET_SYSERR;
@@ -1575,10 +1578,14 @@ handle_register (void *cls,
1575 off += alen; 1578 off += alen;
1576 } 1579 }
1577 1580
1578 ch->hole_external 1581 ch->section_name
1579 = GNUNET_strndup (off, 1582 = GNUNET_strndup (off,
1580 ntohs (message->hole_external_len)); 1583 ntohs (message->str_len));
1581 if (0 != ntohs (message->hole_external_len)) 1584 if (GNUNET_OK ==
1585 GNUNET_CONFIGURATION_get_value_string (cfg,
1586 ch->section_name,
1587 "HOLE_EXTERNAL",
1588 &ch->hole_external))
1582 lookup_hole_external (ch); 1589 lookup_hole_external (ch);
1583 1590
1584 /* Actually send IP address list to client */ 1591 /* Actually send IP address list to client */
@@ -2352,6 +2359,7 @@ client_disconnect_cb (void *cls,
2352 ch->ext_dns = NULL; 2359 ch->ext_dns = NULL;
2353 } 2360 }
2354 GNUNET_free (ch->hole_external); 2361 GNUNET_free (ch->hole_external);
2362 GNUNET_free (ch->section_name);
2355 GNUNET_free (ch); 2363 GNUNET_free (ch);
2356} 2364}
2357 2365
diff --git a/src/nat/nat.h b/src/nat/nat.h
index af418c7c2..02bae71e9 100644
--- a/src/nat/nat.h
+++ b/src/nat/nat.h
@@ -29,6 +29,7 @@
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30
31 31
32
32GNUNET_NETWORK_STRUCT_BEGIN 33GNUNET_NETWORK_STRUCT_BEGIN
33 34
34/** 35/**
@@ -111,10 +112,9 @@ struct GNUNET_NAT_RegisterMessage
111 112
112 /** 113 /**
113 * Number of bytes in the string that follow which 114 * Number of bytes in the string that follow which
114 * specify the hostname and port of a manually punched 115 * specifies a section name in the configuration.
115 * hole for this client.
116 */ 116 */
117 uint16_t hole_external_len GNUNET_PACKED; 117 uint16_t str_len GNUNET_PACKED;
118 118
119 /** 119 /**
120 * Number of addresses that this service is bound to that follow. 120 * Number of addresses that this service is bound to that follow.
@@ -126,8 +126,7 @@ struct GNUNET_NAT_RegisterMessage
126 /* Followed by @e num_addrs addresses of type 'struct 126 /* Followed by @e num_addrs addresses of type 'struct
127 sockaddr' */ 127 sockaddr' */
128 128
129 /* Followed by @e hole_external_len bytes giving a hostname 129 /* Followed by @e str_len section name to use for options */
130 and port */
131 130
132}; 131};
133 132
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 008ad19e4..06b4b99fa 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -368,8 +368,8 @@ do_connect (void *cls)
368 * address_callback for any 'plausible' external address. 368 * address_callback for any 'plausible' external address.
369 * 369 *
370 * @param cfg configuration to use 370 * @param cfg configuration to use
371 * @param config_section name of the configuration section for optionsx
371 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP 372 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
372 * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
373 * @param num_addrs number of addresses in @a addrs 373 * @param num_addrs number of addresses in @a addrs
374 * @param addrs list of local addresses packets should be redirected to 374 * @param addrs list of local addresses packets should be redirected to
375 * @param addrlens actual lengths of the addresses in @a addrs 375 * @param addrlens actual lengths of the addresses in @a addrs
@@ -381,8 +381,8 @@ do_connect (void *cls)
381 */ 381 */
382struct GNUNET_NAT_Handle * 382struct GNUNET_NAT_Handle *
383GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, 383GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
384 const char *config_section,
384 uint8_t proto, 385 uint8_t proto,
385 const char *hole_external,
386 unsigned int num_addrs, 386 unsigned int num_addrs,
387 const struct sockaddr **addrs, 387 const struct sockaddr **addrs,
388 const socklen_t *addrlens, 388 const socklen_t *addrlens,
@@ -393,17 +393,14 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
393 struct GNUNET_NAT_Handle *nh; 393 struct GNUNET_NAT_Handle *nh;
394 struct GNUNET_NAT_RegisterMessage *rm; 394 struct GNUNET_NAT_RegisterMessage *rm;
395 size_t len; 395 size_t len;
396 size_t hole_external_len; 396 size_t str_len;
397 char *off; 397 char *off;
398 398
399 len = 0; 399 len = 0;
400 for (unsigned int i=0;i<num_addrs;i++) 400 for (unsigned int i=0;i<num_addrs;i++)
401 len += addrlens[i]; 401 len += addrlens[i];
402 hole_external_len 402 str_len = strlen (config_section) + 1;
403 = (NULL == hole_external) 403 len += str_len;
404 ? 0
405 : strlen (hole_external);
406 len += hole_external_len;
407 if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) || 404 if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
408 (num_addrs > UINT16_MAX) ) 405 (num_addrs > UINT16_MAX) )
409 { 406 {
@@ -419,7 +416,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
419 if (NULL != reversal_callback) 416 if (NULL != reversal_callback)
420 rm->flags |= GNUNET_NAT_RF_REVERSAL; 417 rm->flags |= GNUNET_NAT_RF_REVERSAL;
421 rm->proto = proto; 418 rm->proto = proto;
422 rm->hole_external_len = htons (hole_external_len); 419 rm->str_len = htons (str_len);
423 rm->num_addrs = htons ((uint16_t) num_addrs); 420 rm->num_addrs = htons ((uint16_t) num_addrs);
424 off = (char *) &rm[1]; 421 off = (char *) &rm[1];
425 for (unsigned int i=0;i<num_addrs;i++) 422 for (unsigned int i=0;i<num_addrs;i++)
@@ -459,8 +456,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
459 off += addrlens[i]; 456 off += addrlens[i];
460 } 457 }
461 GNUNET_memcpy (off, 458 GNUNET_memcpy (off,
462 hole_external, 459 config_section,
463 hole_external_len); 460 str_len);
464 461
465 nh = GNUNET_new (struct GNUNET_NAT_Handle); 462 nh = GNUNET_new (struct GNUNET_NAT_Handle);
466 nh->reg = &rm->header; 463 nh->reg = &rm->header;
diff --git a/src/transport/transport.conf.in b/src/transport/transport.conf.in
index 95e3f9944..4e9f17f77 100644
--- a/src/transport/transport.conf.in
+++ b/src/transport/transport.conf.in
@@ -55,6 +55,9 @@ MAX_CONNECTIONS = 128
55# Enable TCP stealth? 55# Enable TCP stealth?
56TCP_STEALTH = NO 56TCP_STEALTH = NO
57 57
58# Configuration for manually punched holes in NAT.
59# HOLE_EXTERNAL = auto:2086
60
58[transport-udp] 61[transport-udp]
59# Use PORT = 0 to autodetect a port available 62# Use PORT = 0 to autodetect a port available
60PORT = 2086 63PORT = 2086
@@ -69,6 +72,9 @@ BROADCAST_INTERVAL = 30 s
69MAX_BPS = 1000000 72MAX_BPS = 1000000
70TESTING_IGNORE_KEYS = ACCEPT_FROM; 73TESTING_IGNORE_KEYS = ACCEPT_FROM;
71 74
75# Configuration for manually punched holes in NAT.
76# HOLE_EXTERNAL = auto:2086
77
72[transport-http_client] 78[transport-http_client]
73MAX_CONNECTIONS = 128 79MAX_CONNECTIONS = 128
74TESTING_IGNORE_KEYS = ACCEPT_FROM; 80TESTING_IGNORE_KEYS = ACCEPT_FROM;
@@ -99,6 +105,9 @@ TESTING_IGNORE_KEYS = ACCEPT_FROM;
99# Enable TCP stealth? 105# Enable TCP stealth?
100TCP_STEALTH = NO 106TCP_STEALTH = NO
101 107
108# Configuration for manually punched holes in NAT.
109# HOLE_EXTERNAL = auto:2086
110
102[transport-https_client] 111[transport-https_client]
103MAX_CONNECTIONS = 128 112MAX_CONNECTIONS = 128
104TESTING_IGNORE_KEYS = ACCEPT_FROM; 113TESTING_IGNORE_KEYS = ACCEPT_FROM;
@@ -140,6 +149,10 @@ TESTING_IGNORE_KEYS = ACCEPT_FROM;
140# Enable TCP stealth? 149# Enable TCP stealth?
141TCP_STEALTH = NO 150TCP_STEALTH = NO
142 151
152# Configuration for manually punched holes in NAT.
153# HOLE_EXTERNAL = auto:2086
154
155
143[transport-wlan] 156[transport-wlan]
144# Name of the interface in monitor mode (typically monX) 157# Name of the interface in monitor mode (typically monX)
145INTERFACE = mon0 158INTERFACE = mon0