diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-06-11 11:39:20 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-06-11 11:39:20 +0000 |
commit | 8ab1946b4136cb0b20a47661bb54dbe0820ba04f (patch) | |
tree | 396600b983a32f29054d90ba86f52f30d7cae20e /src/transport/plugin_transport_udp.c | |
parent | 069ba0d81d3e74204b20bf6505d93d4e5200eef2 (diff) | |
download | gnunet-8ab1946b4136cb0b20a47661bb54dbe0820ba04f.tar.gz gnunet-8ab1946b4136cb0b20a47661bb54dbe0820ba04f.zip |
explicitly add user provided external address to known addresses when used with NAT
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 14b80d9e9..8caabd0d5 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1671,6 +1671,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1671 | int only_nat_addresses; | 1671 | int only_nat_addresses; |
1672 | char *internal_address; | 1672 | char *internal_address; |
1673 | char *external_address; | 1673 | char *external_address; |
1674 | struct sockaddr_in in_addr; | ||
1674 | 1675 | ||
1675 | service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg); | 1676 | service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg); |
1676 | if (service == NULL) | 1677 | if (service == NULL) |
@@ -1736,6 +1737,11 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1736 | return NULL; | 1737 | return NULL; |
1737 | } | 1738 | } |
1738 | 1739 | ||
1740 | if ((external_address != NULL) && (inet_pton(AF_INET, external_address, &in_addr.sin_addr) != 1)) | ||
1741 | { | ||
1742 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed EXTERNAL_ADDRESS %s given in configuration!\n", external_address); | ||
1743 | } | ||
1744 | |||
1739 | internal_address = NULL; | 1745 | internal_address = NULL; |
1740 | if ((GNUNET_YES == behind_nat) && (GNUNET_OK != | 1746 | if ((GNUNET_YES == behind_nat) && (GNUNET_OK != |
1741 | GNUNET_CONFIGURATION_get_value_string (env->cfg, | 1747 | GNUNET_CONFIGURATION_get_value_string (env->cfg, |
@@ -1753,6 +1759,11 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1753 | return NULL; | 1759 | return NULL; |
1754 | } | 1760 | } |
1755 | 1761 | ||
1762 | if ((internal_address != NULL) && (inet_pton(AF_INET, internal_address, &in_addr.sin_addr) != 1)) | ||
1763 | { | ||
1764 | GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed INTERNAL_ADDRESS %s given in configuration!\n", internal_address); | ||
1765 | } | ||
1766 | |||
1756 | if (GNUNET_OK != | 1767 | if (GNUNET_OK != |
1757 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1768 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
1758 | "transport-udp", | 1769 | "transport-udp", |
@@ -1799,7 +1810,11 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1799 | 1810 | ||
1800 | plugin->service = service; | 1811 | plugin->service = service; |
1801 | 1812 | ||
1802 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | 1813 | if (plugin->behind_nat == GNUNET_NO) |
1814 | { | ||
1815 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | ||
1816 | } | ||
1817 | |||
1803 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, | 1818 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, |
1804 | env->cfg, | 1819 | env->cfg, |
1805 | AF_UNSPEC, | 1820 | AF_UNSPEC, |
@@ -1807,6 +1822,15 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1807 | &process_hostname_ips, | 1822 | &process_hostname_ips, |
1808 | plugin); | 1823 | plugin); |
1809 | 1824 | ||
1825 | if ((plugin->behind_nat == GNUNET_YES) && (inet_pton(AF_INET, plugin->external_address, &in_addr.sin_addr) == 1)) | ||
1826 | { | ||
1827 | in_addr.sin_port = htons(0); | ||
1828 | in_addr.sin_family = AF_INET; | ||
1829 | plugin->env->notify_address (plugin->env->cls, | ||
1830 | "udp", | ||
1831 | &in_addr, sizeof(in_addr), GNUNET_TIME_UNIT_FOREVER_REL); | ||
1832 | } | ||
1833 | |||
1810 | sockets_created = udp_transport_server_start (plugin); | 1834 | sockets_created = udp_transport_server_start (plugin); |
1811 | 1835 | ||
1812 | GNUNET_assert (sockets_created == 1); | 1836 | GNUNET_assert (sockets_created == 1); |
@@ -1814,7 +1838,6 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1814 | return api; | 1838 | return api; |
1815 | } | 1839 | } |
1816 | 1840 | ||
1817 | |||
1818 | void * | 1841 | void * |
1819 | libgnunet_plugin_transport_udp_done (void *cls) | 1842 | libgnunet_plugin_transport_udp_done (void *cls) |
1820 | { | 1843 | { |