diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-04 00:46:41 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-04 00:46:41 +0000 |
commit | 8dac0fff1f5e4a5df3b6f7afaaf6ab334d79436b (patch) | |
tree | 9c682c61c8705ac941a5a750abaa6145b58c747c /src | |
parent | e8ee3b10972c452c29acf1bc00d9b39765205aa3 (diff) | |
download | gnunet-8dac0fff1f5e4a5df3b6f7afaaf6ab334d79436b.tar.gz gnunet-8dac0fff1f5e4a5df3b6f7afaaf6ab334d79436b.zip |
remember which port we picked at random on port-autoconfig
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index dba8de2cb..3572a4ac6 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1122,8 +1122,8 @@ udp_plugin_check_address (void *cls, | |||
1122 | struct IPv4UdpAddress *v4; | 1122 | struct IPv4UdpAddress *v4; |
1123 | struct IPv6UdpAddress *v6; | 1123 | struct IPv6UdpAddress *v6; |
1124 | 1124 | ||
1125 | if ((addrlen != sizeof(struct IPv4UdpAddress)) | 1125 | if ( (addrlen != sizeof(struct IPv4UdpAddress)) && |
1126 | && (addrlen != sizeof(struct IPv6UdpAddress))) | 1126 | (addrlen != sizeof(struct IPv6UdpAddress)) ) |
1127 | { | 1127 | { |
1128 | GNUNET_break_op(0); | 1128 | GNUNET_break_op(0); |
1129 | return GNUNET_SYSERR; | 1129 | return GNUNET_SYSERR; |
@@ -1133,9 +1133,10 @@ udp_plugin_check_address (void *cls, | |||
1133 | v4 = (struct IPv4UdpAddress *) addr; | 1133 | v4 = (struct IPv4UdpAddress *) addr; |
1134 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) | 1134 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) |
1135 | return GNUNET_SYSERR; | 1135 | return GNUNET_SYSERR; |
1136 | if (GNUNET_OK | 1136 | if (GNUNET_OK != |
1137 | != GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, | 1137 | GNUNET_NAT_test_address (plugin->nat, |
1138 | sizeof(struct in_addr))) | 1138 | &v4->ipv4_addr, |
1139 | sizeof (struct in_addr))) | ||
1139 | return GNUNET_SYSERR; | 1140 | return GNUNET_SYSERR; |
1140 | } | 1141 | } |
1141 | else | 1142 | else |
@@ -3140,9 +3141,9 @@ setup_sockets (struct Plugin *plugin, | |||
3140 | server_addrv6.sin6_addr = in6addr_any; | 3141 | server_addrv6.sin6_addr = in6addr_any; |
3141 | 3142 | ||
3142 | if (0 == plugin->port) /* autodetect */ | 3143 | if (0 == plugin->port) /* autodetect */ |
3143 | server_addrv6.sin6_port = htons ( | 3144 | server_addrv6.sin6_port |
3144 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | 3145 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) |
3145 | + 32000); | 3146 | + 32000); |
3146 | else | 3147 | else |
3147 | server_addrv6.sin6_port = htons (plugin->port); | 3148 | server_addrv6.sin6_port = htons (plugin->port); |
3148 | addrlen = sizeof(struct sockaddr_in6); | 3149 | addrlen = sizeof(struct sockaddr_in6); |
@@ -3155,20 +3156,21 @@ setup_sockets (struct Plugin *plugin, | |||
3155 | "Binding to IPv6 `%s'\n", | 3156 | "Binding to IPv6 `%s'\n", |
3156 | GNUNET_a2s (server_addr, addrlen)); | 3157 | GNUNET_a2s (server_addr, addrlen)); |
3157 | /* binding */ | 3158 | /* binding */ |
3158 | if (GNUNET_OK | 3159 | if (GNUNET_OK == |
3159 | == GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, | 3160 | GNUNET_NETWORK_socket_bind (plugin->sockv6, |
3160 | addrlen)) | 3161 | server_addr, |
3162 | addrlen)) | ||
3161 | break; | 3163 | break; |
3162 | eno = errno; | 3164 | eno = errno; |
3163 | if (0 != plugin->port) | 3165 | if (0 != plugin->port) |
3164 | { | 3166 | { |
3165 | tries = 10; /* fail */ | 3167 | tries = 10; /* fail immediately */ |
3166 | break; /* bind failed on specific port */ | 3168 | break; /* bind failed on specific port */ |
3167 | } | 3169 | } |
3168 | /* autodetect */ | 3170 | /* autodetect */ |
3169 | server_addrv6.sin6_port = htons ( | 3171 | server_addrv6.sin6_port |
3170 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | 3172 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) |
3171 | + 32000); | 3173 | + 32000); |
3172 | tries++; | 3174 | tries++; |
3173 | } | 3175 | } |
3174 | if (tries >= 10) | 3176 | if (tries >= 10) |
@@ -3177,8 +3179,11 @@ setup_sockets (struct Plugin *plugin, | |||
3177 | plugin->enable_ipv6 = GNUNET_NO; | 3179 | plugin->enable_ipv6 = GNUNET_NO; |
3178 | plugin->sockv6 = NULL; | 3180 | plugin->sockv6 = NULL; |
3179 | } | 3181 | } |
3180 | 3182 | else | |
3181 | if (plugin->sockv6 != NULL ) | 3183 | { |
3184 | plugin->port = ntohs (server_addrv6.sin6_port); | ||
3185 | } | ||
3186 | if (NULL != plugin->sockv6) | ||
3182 | { | 3187 | { |
3183 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3188 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3184 | "IPv6 socket created on port %s\n", | 3189 | "IPv6 socket created on port %s\n", |
@@ -3222,9 +3227,10 @@ setup_sockets (struct Plugin *plugin, | |||
3222 | 3227 | ||
3223 | if (0 == plugin->port) | 3228 | if (0 == plugin->port) |
3224 | /* autodetect */ | 3229 | /* autodetect */ |
3225 | server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, | 3230 | server_addrv4.sin_port |
3226 | 33537) | 3231 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, |
3227 | + 32000); | 3232 | 33537) |
3233 | + 32000); | ||
3228 | else | 3234 | else |
3229 | server_addrv4.sin_port = htons (plugin->port); | 3235 | server_addrv4.sin_port = htons (plugin->port); |
3230 | 3236 | ||
@@ -3252,18 +3258,21 @@ setup_sockets (struct Plugin *plugin, | |||
3252 | } | 3258 | } |
3253 | 3259 | ||
3254 | /* autodetect */ | 3260 | /* autodetect */ |
3255 | server_addrv4.sin_port = htons ( | 3261 | server_addrv4.sin_port |
3256 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | 3262 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) |
3257 | + 32000); | 3263 | + 32000); |
3258 | tries++; | 3264 | tries++; |
3259 | } | 3265 | } |
3260 | |||
3261 | if (tries >= 10) | 3266 | if (tries >= 10) |
3262 | { | 3267 | { |
3263 | GNUNET_NETWORK_socket_close (plugin->sockv4); | 3268 | GNUNET_NETWORK_socket_close (plugin->sockv4); |
3264 | plugin->enable_ipv4 = GNUNET_NO; | 3269 | plugin->enable_ipv4 = GNUNET_NO; |
3265 | plugin->sockv4 = NULL; | 3270 | plugin->sockv4 = NULL; |
3266 | } | 3271 | } |
3272 | else | ||
3273 | { | ||
3274 | plugin->port = ntohs (server_addrv4.sin_port); | ||
3275 | } | ||
3267 | 3276 | ||
3268 | if (NULL != plugin->sockv4) | 3277 | if (NULL != plugin->sockv4) |
3269 | { | 3278 | { |