diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-14 14:15:06 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-14 14:15:06 +0000 |
commit | 3d20da8230a5383c2389cb274856560412598119 (patch) | |
tree | 32d4695186403a3705622b9a352526e307343218 /src/transport/plugin_transport_udp.c | |
parent | 46c20b1b6925ce1879794a1f369809132629068b (diff) | |
download | gnunet-3d20da8230a5383c2389cb274856560412598119.tar.gz gnunet-3d20da8230a5383c2389cb274856560412598119.zip |
fixing issues with udp due to internal address length
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index d5aef62ce..219535bf8 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1086,12 +1086,14 @@ dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1086 | } | 1086 | } |
1087 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", | 1087 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", |
1088 | -1, GNUNET_NO); | 1088 | -1, GNUNET_NO); |
1089 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) | 1089 | if (udpw->session->address->address_length == sizeof(struct IPv4UdpAddress)) |
1090 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, | 1090 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, |
1091 | plugin->ipv4_queue_tail, udpw); | 1091 | plugin->ipv4_queue_tail, udpw); |
1092 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) | 1092 | else if (udpw->session->address->address_length == sizeof(struct IPv6UdpAddress)) |
1093 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, | 1093 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, |
1094 | plugin->ipv6_queue_tail, udpw); | 1094 | plugin->ipv6_queue_tail, udpw); |
1095 | else | ||
1096 | GNUNET_break (0); | ||
1095 | } | 1097 | } |
1096 | 1098 | ||
1097 | static void | 1099 | static void |
@@ -1489,7 +1491,7 @@ udp_plugin_create_session (void *cls, | |||
1489 | "Creating new %s session %p for peer `%s' address `%s'\n", | 1491 | "Creating new %s session %p for peer `%s' address `%s'\n", |
1490 | GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", | 1492 | GNUNET_HELLO_address_check_option (address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", |
1491 | s, GNUNET_i2s (&address->peer), | 1493 | s, GNUNET_i2s (&address->peer), |
1492 | udp_address_to_string(NULL,address->address,address->address_length)); | 1494 | udp_address_to_string( NULL,address->address,address->address_length)); |
1493 | GNUNET_assert( | 1495 | GNUNET_assert( |
1494 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 1496 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
1495 | GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", | 1497 | GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", |
@@ -1554,12 +1556,14 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1554 | } | 1556 | } |
1555 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", | 1557 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", |
1556 | 1, GNUNET_NO); | 1558 | 1, GNUNET_NO); |
1557 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) | 1559 | if (udpw->session->address->address_length == sizeof (struct IPv4UdpAddress)) |
1558 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, | 1560 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, |
1559 | plugin->ipv4_queue_tail, udpw); | 1561 | plugin->ipv4_queue_tail, udpw); |
1560 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) | 1562 | else if (udpw->session->address->address_length == sizeof (struct IPv6UdpAddress)) |
1561 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, | 1563 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, |
1562 | plugin->ipv6_queue_tail, udpw); | 1564 | plugin->ipv6_queue_tail, udpw); |
1565 | else | ||
1566 | GNUNET_break (0); | ||
1563 | } | 1567 | } |
1564 | 1568 | ||
1565 | /** | 1569 | /** |
@@ -1656,10 +1660,14 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1656 | GNUNET_assert(plugin != NULL); | 1660 | GNUNET_assert(plugin != NULL); |
1657 | GNUNET_assert(s != NULL); | 1661 | GNUNET_assert(s != NULL); |
1658 | 1662 | ||
1659 | if ((s->address->address_length == sizeof(struct sockaddr_in6)) && (plugin->sockv6 == NULL )) | 1663 | if ((s->address->address_length == sizeof(struct IPv6UdpAddress)) && (plugin->sockv6 == NULL )) |
1664 | { | ||
1660 | return GNUNET_SYSERR; | 1665 | return GNUNET_SYSERR; |
1661 | if ((s->address->address_length == sizeof(struct sockaddr_in)) && (plugin->sockv4 == NULL )) | 1666 | } |
1667 | if ((s->address->address_length == sizeof(struct IPv4UdpAddress)) && (plugin->sockv4 == NULL )) | ||
1668 | { | ||
1662 | return GNUNET_SYSERR; | 1669 | return GNUNET_SYSERR; |
1670 | } | ||
1663 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1671 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1664 | { | 1672 | { |
1665 | GNUNET_break(0); | 1673 | GNUNET_break(0); |
@@ -1672,7 +1680,7 @@ udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, | |||
1672 | GNUNET_break(0); | 1680 | GNUNET_break(0); |
1673 | return GNUNET_SYSERR; | 1681 | return GNUNET_SYSERR; |
1674 | } | 1682 | } |
1675 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1683 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1676 | "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, | 1684 | "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, |
1677 | GNUNET_i2s (&s->target), udp_address_to_string (NULL, s->address->address, s->address->address_length)); | 1685 | GNUNET_i2s (&s->target), udp_address_to_string (NULL, s->address->address, s->address->address_length)); |
1678 | 1686 | ||
@@ -2240,7 +2248,7 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
2240 | } | 2248 | } |
2241 | msg = (const struct GNUNET_MessageHeader *) buf; | 2249 | msg = (const struct GNUNET_MessageHeader *) buf; |
2242 | 2250 | ||
2243 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2251 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2244 | "UDP received %u-byte message from `%s' type %u\n", (unsigned int ) size, | 2252 | "UDP received %u-byte message from `%s' type %u\n", (unsigned int ) size, |
2245 | GNUNET_a2s ((const struct sockaddr * ) &addr, fromlen), | 2253 | GNUNET_a2s ((const struct sockaddr * ) &addr, fromlen), |
2246 | ntohs (msg->type)); | 2254 | ntohs (msg->type)); |
@@ -2436,9 +2444,14 @@ analyze_send_error (struct Plugin *plugin, const struct sockaddr * sa, | |||
2436 | static size_t | 2444 | static size_t |
2437 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | 2445 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) |
2438 | { | 2446 | { |
2439 | const struct sockaddr * sa; | ||
2440 | ssize_t sent; | 2447 | ssize_t sent; |
2441 | socklen_t slen; | 2448 | socklen_t slen; |
2449 | struct sockaddr *a; | ||
2450 | const struct IPv4UdpAddress *u4; | ||
2451 | struct sockaddr_in a4; | ||
2452 | const struct IPv6UdpAddress *u6; | ||
2453 | struct sockaddr_in6 a6; | ||
2454 | |||
2442 | 2455 | ||
2443 | struct UDP_MessageWrapper *udpw = NULL; | 2456 | struct UDP_MessageWrapper *udpw = NULL; |
2444 | 2457 | ||
@@ -2449,16 +2462,43 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2449 | if (NULL == udpw) | 2462 | if (NULL == udpw) |
2450 | return 0; /* No message to send */ | 2463 | return 0; /* No message to send */ |
2451 | 2464 | ||
2452 | sa = udpw->session->address->address; | 2465 | if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) |
2453 | slen = udpw->session->address->address_length; | 2466 | { |
2454 | 2467 | u4 = udpw->session->address->address; | |
2455 | sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, | 2468 | memset (&a4, 0, sizeof(a4)); |
2469 | a4.sin_family = AF_INET; | ||
2470 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
2471 | a4.sin_len = sizeof (a4); | ||
2472 | #endif | ||
2473 | a4.sin_port = u4->u4_port; | ||
2474 | memcpy (&a4.sin_addr, &u4->ipv4_addr, sizeof(struct in_addr)); | ||
2475 | a = (struct sockaddr *) &a4; | ||
2476 | slen = sizeof (a4); | ||
2477 | } | ||
2478 | else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length) | ||
2479 | { | ||
2480 | u6 = udpw->session->address->address; | ||
2481 | memset (&a6, 0, sizeof(a6)); | ||
2482 | a6.sin6_family = AF_INET6; | ||
2483 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
2484 | a6.sin6_len = sizeof (a6); | ||
2485 | #endif | ||
2486 | a6.sin6_port = u6->u6_port; | ||
2487 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); | ||
2488 | a = (struct sockaddr *) &a6; | ||
2489 | slen = sizeof (a6); | ||
2490 | } | ||
2491 | else | ||
2492 | { | ||
2493 | GNUNET_break (0); | ||
2494 | } | ||
2495 | sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, a, | ||
2456 | slen); | 2496 | slen); |
2457 | 2497 | ||
2458 | if (GNUNET_SYSERR == sent) | 2498 | if (GNUNET_SYSERR == sent) |
2459 | { | 2499 | { |
2460 | /* Failure */ | 2500 | /* Failure */ |
2461 | analyze_send_error (plugin, sa, slen, errno); | 2501 | analyze_send_error (plugin, a, slen, errno); |
2462 | call_continuation (udpw, GNUNET_SYSERR); | 2502 | call_continuation (udpw, GNUNET_SYSERR); |
2463 | GNUNET_STATISTICS_update (plugin->env->stats, | 2503 | GNUNET_STATISTICS_update (plugin->env->stats, |
2464 | "# UDP, total, bytes, sent, failure", sent, GNUNET_NO); | 2504 | "# UDP, total, bytes, sent, failure", sent, GNUNET_NO); |
@@ -2468,10 +2508,10 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2468 | else | 2508 | else |
2469 | { | 2509 | { |
2470 | /* Success */ | 2510 | /* Success */ |
2471 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2511 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2472 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", | 2512 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", |
2473 | (unsigned int ) (udpw->msg_size), GNUNET_i2s (&udpw->session->target), | 2513 | (unsigned int ) (udpw->msg_size), GNUNET_i2s (&udpw->session->target), |
2474 | GNUNET_a2s (sa, slen), (int ) sent, | 2514 | GNUNET_a2s (a, slen), (int ) sent, |
2475 | (sent < 0) ? STRERROR (errno) : "ok"); | 2515 | (sent < 0) ? STRERROR (errno) : "ok"); |
2476 | GNUNET_STATISTICS_update (plugin->env->stats, | 2516 | GNUNET_STATISTICS_update (plugin->env->stats, |
2477 | "# UDP, total, bytes, sent, success", sent, GNUNET_NO); | 2517 | "# UDP, total, bytes, sent, success", sent, GNUNET_NO); |