aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-07 17:58:36 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-07 17:58:36 +0100
commitc3b77fea0f652b7d8f0641696f3a3418864ab135 (patch)
tree57a0320fe248583863e98938d2e5bea4e7b6f68f /src
parentddadc570d8fd3ce7a4f658adf9a2c9b9d9c0dcba (diff)
downloadgnunet-c3b77fea0f652b7d8f0641696f3a3418864ab135.tar.gz
gnunet-c3b77fea0f652b7d8f0641696f3a3418864ab135.zip
fix calls to test_address, expects a struct sockaddr, not an in_addr
Diffstat (limited to 'src')
-rw-r--r--src/nat/nat_api.c2
-rw-r--r--src/transport/plugin_transport_tcp.c55
-rw-r--r--src/transport/plugin_transport_udp.c35
3 files changed, 51 insertions, 41 deletions
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 261b901a9..826dbd57a 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2007-2016 GNUnet e.V. 3 Copyright (C) 2007-2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 605579c18..eca62a8ca 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -2413,27 +2413,6 @@ tcp_plugin_address_pretty_printer (void *cls,
2413 2413
2414 2414
2415/** 2415/**
2416 * Check if the given port is plausible (must be either our listen
2417 * port or our advertised port), or any port if we are behind NAT
2418 * and do not have a port open. If it is neither, we return
2419 * #GNUNET_SYSERR.
2420 *
2421 * @param plugin global variables
2422 * @param in_port port number to check
2423 * @return #GNUNET_OK if port is either open_port or adv_port
2424 */
2425static int
2426check_port (struct Plugin *plugin,
2427 uint16_t in_port)
2428{
2429 if ( (in_port == plugin->adv_port) ||
2430 (in_port == plugin->open_port) )
2431 return GNUNET_OK;
2432 return GNUNET_SYSERR;
2433}
2434
2435
2436/**
2437 * Function that will be called to check if a binary address for this 2416 * Function that will be called to check if a binary address for this
2438 * plugin is well-formed and corresponds to an address for THIS peer 2417 * plugin is well-formed and corresponds to an address for THIS peer
2439 * (as per our configuration). Naturally, if absolutely necessary, 2418 * (as per our configuration). Naturally, if absolutely necessary,
@@ -2466,6 +2445,8 @@ tcp_plugin_check_address (void *cls,
2466 2445
2467 if (addrlen == sizeof(struct IPv4TcpAddress)) 2446 if (addrlen == sizeof(struct IPv4TcpAddress))
2468 { 2447 {
2448 struct sockaddr_in s4;
2449
2469 v4 = (const struct IPv4TcpAddress *) addr; 2450 v4 = (const struct IPv4TcpAddress *) addr;
2470 if (0 != memcmp (&v4->options, 2451 if (0 != memcmp (&v4->options,
2471 &plugin->myoptions, 2452 &plugin->myoptions,
@@ -2474,17 +2455,24 @@ tcp_plugin_check_address (void *cls,
2474 GNUNET_break (0); 2455 GNUNET_break (0);
2475 return GNUNET_SYSERR; 2456 return GNUNET_SYSERR;
2476 } 2457 }
2477 if (GNUNET_OK != check_port (plugin, 2458 memset (&s4, 0, sizeof (s4));
2478 ntohs (v4->t4_port))) 2459 s4.sin_family = AF_INET;
2479 return GNUNET_SYSERR; 2460#if HAVE_SOCKADDR_IN_SIN_LEN
2461 s4.sin_len = sizeof (s4);
2462#endif
2463 s4.sin_port = v4->t4_port;
2464 s4.sin_addr.s_addr = v4->ipv4_addr;
2465
2480 if (GNUNET_OK != 2466 if (GNUNET_OK !=
2481 GNUNET_NAT_test_address (plugin->nat, 2467 GNUNET_NAT_test_address (plugin->nat,
2482 &v4->ipv4_addr, 2468 &s4,
2483 sizeof (struct in_addr))) 2469 sizeof (struct sockaddr_in)))
2484 return GNUNET_SYSERR; 2470 return GNUNET_SYSERR;
2485 } 2471 }
2486 else 2472 else
2487 { 2473 {
2474 struct sockaddr_in6 s6;
2475
2488 v6 = (const struct IPv6TcpAddress *) addr; 2476 v6 = (const struct IPv6TcpAddress *) addr;
2489 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 2477 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
2490 { 2478 {
@@ -2498,13 +2486,18 @@ tcp_plugin_check_address (void *cls,
2498 GNUNET_break (0); 2486 GNUNET_break (0);
2499 return GNUNET_SYSERR; 2487 return GNUNET_SYSERR;
2500 } 2488 }
2501 if (GNUNET_OK != check_port (plugin, 2489 memset (&s6, 0, sizeof (s6));
2502 ntohs (v6->t6_port))) 2490 s6.sin6_family = AF_INET6;
2503 return GNUNET_SYSERR; 2491#if HAVE_SOCKADDR_IN_SIN_LEN
2492 s6.sin6_len = sizeof (s6);
2493#endif
2494 s6.sin6_port = v6->t6_port;
2495 s6.sin6_addr = v6->ipv6_addr;
2496
2504 if (GNUNET_OK != 2497 if (GNUNET_OK !=
2505 GNUNET_NAT_test_address (plugin->nat, 2498 GNUNET_NAT_test_address (plugin->nat,
2506 &v6->ipv6_addr, 2499 &s6,
2507 sizeof(struct in6_addr))) 2500 sizeof(struct sockaddr_in6)))
2508 return GNUNET_SYSERR; 2501 return GNUNET_SYSERR;
2509 } 2502 }
2510 return GNUNET_OK; 2503 return GNUNET_OK;
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index c9fb754c1..8281e48c5 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1245,31 +1245,48 @@ udp_plugin_check_address (void *cls,
1245 1245
1246 if (sizeof(struct IPv4UdpAddress) == addrlen) 1246 if (sizeof(struct IPv4UdpAddress) == addrlen)
1247 { 1247 {
1248 struct sockaddr_in s4;
1249
1248 v4 = (const struct IPv4UdpAddress *) addr; 1250 v4 = (const struct IPv4UdpAddress *) addr;
1249 if (GNUNET_OK != check_port (plugin, 1251 if (GNUNET_OK != check_port (plugin,
1250 ntohs (v4->u4_port))) 1252 ntohs (v4->u4_port)))
1251 return GNUNET_SYSERR; 1253 return GNUNET_SYSERR;
1254 memset (&s4, 0, sizeof (s4));
1255 s4.sin_family = AF_INET;
1256#if HAVE_SOCKADDR_IN_SIN_LEN
1257 s4.sin_len = sizeof (s4);
1258#endif
1259 s4.sin_port = v4->u4_port;
1260 s4.sin_addr.s_addr = v4->ipv4_addr;
1261
1252 if (GNUNET_OK != 1262 if (GNUNET_OK !=
1253 GNUNET_NAT_test_address (plugin->nat, 1263 GNUNET_NAT_test_address (plugin->nat,
1254 &v4->ipv4_addr, 1264 &s4,
1255 sizeof (struct in_addr))) 1265 sizeof (struct sockaddr_in)))
1256 return GNUNET_SYSERR; 1266 return GNUNET_SYSERR;
1257 } 1267 }
1258 else if (sizeof(struct IPv6UdpAddress) == addrlen) 1268 else if (sizeof(struct IPv6UdpAddress) == addrlen)
1259 { 1269 {
1270 struct sockaddr_in6 s6;
1271
1260 v6 = (const struct IPv6UdpAddress *) addr; 1272 v6 = (const struct IPv6UdpAddress *) addr;
1261 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 1273 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1262 { 1274 {
1263 GNUNET_break_op (0); 1275 GNUNET_break_op (0);
1264 return GNUNET_SYSERR; 1276 return GNUNET_SYSERR;
1265 } 1277 }
1266 if (GNUNET_OK != check_port (plugin, 1278 memset (&s6, 0, sizeof (s6));
1267 ntohs (v6->u6_port))) 1279 s6.sin6_family = AF_INET6;
1268 return GNUNET_SYSERR; 1280#if HAVE_SOCKADDR_IN_SIN_LEN
1281 s6.sin6_len = sizeof (s6);
1282#endif
1283 s6.sin6_port = v6->u6_port;
1284 s6.sin6_addr = v6->ipv6_addr;
1285
1269 if (GNUNET_OK != 1286 if (GNUNET_OK !=
1270 GNUNET_NAT_test_address (plugin->nat, 1287 GNUNET_NAT_test_address (plugin->nat,
1271 &v6->ipv6_addr, 1288 &s6,
1272 sizeof (struct in6_addr))) 1289 sizeof(struct sockaddr_in6)))
1273 return GNUNET_SYSERR; 1290 return GNUNET_SYSERR;
1274 } 1291 }
1275 else 1292 else