diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-05 21:23:02 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-05 21:23:02 +0100 |
commit | 1b7f6eea0a06abab9b75b30f021aa6313fccfcd4 (patch) | |
tree | 0d726dbd6650997c22a7c17ce833ce53c23bde9e /src/nat | |
parent | 07d7291d64688ecf9ef0bf2b663b10a168d5fff2 (diff) |
pass section name instead of specific option via IPC
Diffstat (limited to 'src/nat')
-rw-r--r-- | src/nat/gnunet-nat.c | 14 | ||||
-rw-r--r-- | src/nat/gnunet-service-nat.c | 20 | ||||
-rw-r--r-- | src/nat/nat.h | 9 | ||||
-rw-r--r-- | src/nat/nat_api.c | 19 |
4 files changed, 33 insertions, 29 deletions
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c index 81e4549b5d..4171babf94 100644 --- a/src/nat/gnunet-nat.c +++ b/src/nat/gnunet-nat.c @@ -39,10 +39,10 @@ static int global_ret; static struct GNUNET_NAT_AutoHandle *ah; /** - * External hostname and port, if user manually punched - * the NAT. + * Name of section in configuration file to use for + * additional options. */ -static char *hole_external; +static char *section_name; /** * Flag set to 1 if we use IPPROTO_UDP. @@ -568,8 +568,8 @@ run (void *cls, if (NULL != local_addr) { nh = GNUNET_NAT_register (c, + section_name, proto, - hole_external, 1, (const struct sockaddr **) &local_sa, &local_len, @@ -698,9 +698,9 @@ main (int argc, {'r', "remote", "ADDRESS", gettext_noop ("which remote IP and port should be asked for connection reversal"), GNUNET_YES, &GNUNET_GETOPT_set_string, &remote_addr }, - {'p', "punched", NULL, - gettext_noop ("external hostname and port of NAT, if punched manually; use AUTO for hostname for automatic determination of the external IP"), - GNUNET_YES, &GNUNET_GETOPT_set_string, &hole_external }, + {'S', "section", NULL, + gettext_noop ("name of configuration section to find additional options, such as manual host punching data"), + GNUNET_YES, &GNUNET_GETOPT_set_string, §ion_name }, {'s', "stun", NULL, gettext_noop ("enable STUN processing"), 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 8af27af9ee..79f806f271 100644 --- a/src/nat/gnunet-service-nat.c +++ b/src/nat/gnunet-service-nat.c @@ -30,8 +30,6 @@ * TODO: * - test and document (!) ICMP based NAT traversal * - test manual hole punching support - * - consider passing transport plugin name instead of - * external IP address string (more flexible!) * - adapt existing transports to use new NAT logic * - abandon legacy NAT code * @@ -186,6 +184,11 @@ struct ClientHandle char *hole_external; /** + * Name of the configuration section this client cares about. + */ + char *section_name; + + /** * Task for periodically re-running the @e ext_dns DNS lookup. */ struct GNUNET_SCHEDULER_Task *ext_dns_task; @@ -505,7 +508,7 @@ check_register (void *cls, off += alen; left -= alen; } - if (left != ntohs (message->hole_external_len)) + if (left != ntohs (message->str_len)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -1575,10 +1578,14 @@ handle_register (void *cls, off += alen; } - ch->hole_external + ch->section_name = GNUNET_strndup (off, - ntohs (message->hole_external_len)); - if (0 != ntohs (message->hole_external_len)) + ntohs (message->str_len)); + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, + ch->section_name, + "HOLE_EXTERNAL", + &ch->hole_external)) lookup_hole_external (ch); /* Actually send IP address list to client */ @@ -2352,6 +2359,7 @@ client_disconnect_cb (void *cls, ch->ext_dns = NULL; } GNUNET_free (ch->hole_external); + GNUNET_free (ch->section_name); GNUNET_free (ch); } diff --git a/src/nat/nat.h b/src/nat/nat.h index af418c7c24..02bae71e90 100644 --- a/src/nat/nat.h +++ b/src/nat/nat.h @@ -29,6 +29,7 @@ #include "gnunet_util_lib.h" + GNUNET_NETWORK_STRUCT_BEGIN /** @@ -111,10 +112,9 @@ struct GNUNET_NAT_RegisterMessage /** * Number of bytes in the string that follow which - * specify the hostname and port of a manually punched - * hole for this client. + * specifies a section name in the configuration. */ - uint16_t hole_external_len GNUNET_PACKED; + uint16_t str_len GNUNET_PACKED; /** * Number of addresses that this service is bound to that follow. @@ -126,8 +126,7 @@ struct GNUNET_NAT_RegisterMessage /* Followed by @e num_addrs addresses of type 'struct sockaddr' */ - /* Followed by @e hole_external_len bytes giving a hostname - and port */ + /* Followed by @e str_len section name to use for options */ }; diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c index 008ad19e4a..06b4b99fa4 100644 --- a/src/nat/nat_api.c +++ b/src/nat/nat_api.c @@ -368,8 +368,8 @@ do_connect (void *cls) * address_callback for any 'plausible' external address. * * @param cfg configuration to use + * @param config_section name of the configuration section for optionsx * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP - * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string) * @param num_addrs number of addresses in @a addrs * @param addrs list of local addresses packets should be redirected to * @param addrlens actual lengths of the addresses in @a addrs @@ -381,8 +381,8 @@ do_connect (void *cls) */ struct GNUNET_NAT_Handle * GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *config_section, uint8_t proto, - const char *hole_external, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, @@ -393,17 +393,14 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_NAT_Handle *nh; struct GNUNET_NAT_RegisterMessage *rm; size_t len; - size_t hole_external_len; + size_t str_len; char *off; len = 0; for (unsigned int i=0;i<num_addrs;i++) len += addrlens[i]; - hole_external_len - = (NULL == hole_external) - ? 0 - : strlen (hole_external); - len += hole_external_len; + str_len = strlen (config_section) + 1; + len += str_len; if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) || (num_addrs > UINT16_MAX) ) { @@ -419,7 +416,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, if (NULL != reversal_callback) rm->flags |= GNUNET_NAT_RF_REVERSAL; rm->proto = proto; - rm->hole_external_len = htons (hole_external_len); + rm->str_len = htons (str_len); rm->num_addrs = htons ((uint16_t) num_addrs); off = (char *) &rm[1]; for (unsigned int i=0;i<num_addrs;i++) @@ -459,8 +456,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, off += addrlens[i]; } GNUNET_memcpy (off, - hole_external, - hole_external_len); + config_section, + str_len); nh = GNUNET_new (struct GNUNET_NAT_Handle); nh->reg = &rm->header; |