aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-08-17 11:09:18 +0000
committerNathan S. Evans <evans@in.tum.de>2010-08-17 11:09:18 +0000
commit88ea7736981fd28afc53d16901a957f9b5708fb1 (patch)
treea45bff4663ac4d990d59b213454984cf75d29916 /src/transport/plugin_transport_udp.c
parent94da310728280f2869f106931ce693a442639495 (diff)
downloadgnunet-88ea7736981fd28afc53d16901a957f9b5708fb1.tar.gz
gnunet-88ea7736981fd28afc53d16901a957f9b5708fb1.zip
some nat fixes
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c224
1 files changed, 129 insertions, 95 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 5be9bfb80..d37106778 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -53,7 +53,7 @@
53#include "plugin_transport.h" 53#include "plugin_transport.h"
54#include "transport.h" 54#include "transport.h"
55 55
56#define DEBUG_UDP GNUNET_NO 56#define DEBUG_UDP GNUNET_YES
57 57
58#define MAX_PROBES 20 58#define MAX_PROBES 20
59 59
@@ -397,6 +397,16 @@ struct Plugin
397 char *internal_address; 397 char *internal_address;
398 398
399 /** 399 /**
400 * Address we were told to bind to exclusively (IPv4).
401 */
402 char *bind_address;
403
404 /**
405 * Address we were told to bind to exclusively (IPv6).
406 */
407 char *bind6_address;
408
409 /**
400 * List of our IP addresses. 410 * List of our IP addresses.
401 */ 411 */
402 struct LocalAddrList *lal_head; 412 struct LocalAddrList *lal_head;
@@ -598,8 +608,7 @@ udp_real_send (void *cls,
598 if ((addr == NULL) || (addrlen == 0)) 608 if ((addr == NULL) || (addrlen == 0))
599 { 609 {
600#if DEBUG_UDP 610#if DEBUG_UDP
601 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
602 "udp",
603 "udp_real_send called without address, returning!\n"); 612 "udp_real_send called without address, returning!\n");
604#endif 613#endif
605 if (cont != NULL) 614 if (cont != NULL)
@@ -698,7 +707,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
698 t4 = (struct IPv4UdpAddress *)addr; 707 t4 = (struct IPv4UdpAddress *)addr;
699 708
700 if (NULL == inet_ntop (AF_INET, 709 if (NULL == inet_ntop (AF_INET,
701 &t4->u_port, 710 &t4->ipv4_addr,
702 addr_buf, INET_ADDRSTRLEN)) 711 addr_buf, INET_ADDRSTRLEN))
703 { 712 {
704 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 713 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
@@ -707,7 +716,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
707 address_as_string = GNUNET_strdup (addr_buf); 716 address_as_string = GNUNET_strdup (addr_buf);
708 GNUNET_asprintf(&port_as_string, "%d", plugin->port); 717 GNUNET_asprintf(&port_as_string, "%d", plugin->port);
709#if DEBUG_UDP 718#if DEBUG_UDP
710 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 _("Running gnunet-nat-client with arguments: %s %s %d\n"), plugin->external_address, address_as_string, plugin->port); 720 _("Running gnunet-nat-client with arguments: %s %s %d\n"), plugin->external_address, address_as_string, plugin->port);
712#endif 721#endif
713 722
@@ -810,7 +819,7 @@ udp_plugin_send (void *cls,
810 peer_session->messages->cont = cont; 819 peer_session->messages->cont = cont;
811 peer_session->messages->cont_cls = cont_cls; 820 peer_session->messages->cont_cls = cont_cls;
812#if DEBUG_UDP 821#if DEBUG_UDP
813 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
814 _("Other peer is NAT'd, set up peer session for peer %s\n"), GNUNET_i2s(target)); 823 _("Other peer is NAT'd, set up peer session for peer %s\n"), GNUNET_i2s(target));
815#endif 824#endif
816 run_gnunet_nat_client(plugin, addr, addrlen); 825 run_gnunet_nat_client(plugin, addr, addrlen);
@@ -924,12 +933,21 @@ process_interfaces (void *cls,
924 void *arg; 933 void *arg;
925 uint16_t args; 934 uint16_t args;
926 void *addr_nat; 935 void *addr_nat;
936 char buf[INET6_ADDRSTRLEN];
927 937
928 addr_nat = NULL; 938 addr_nat = NULL;
929 af = addr->sa_family; 939 af = addr->sa_family;
940
941 memset(buf, 0, INET6_ADDRSTRLEN);
930 if (af == AF_INET) 942 if (af == AF_INET)
931 { 943 {
932 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 944 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
945 GNUNET_assert(NULL != inet_ntop(AF_INET, &t4.ipv4_addr, &buf[0], INET_ADDRSTRLEN));
946 if ((plugin->bind6_address != NULL) || ((plugin->bind_address != NULL) && (0 != strcmp(buf, plugin->bind_address))))
947 {
948 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Not notifying transport of address %s\n", "UDP", GNUNET_a2s (addr, addrlen));
949 return GNUNET_OK;
950 }
933 add_to_address_list (plugin, &t4.ipv4_addr, sizeof (uint32_t)); 951 add_to_address_list (plugin, &t4.ipv4_addr, sizeof (uint32_t));
934 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES)) 952 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES))
935 { 953 {
@@ -959,6 +977,12 @@ process_interfaces (void *cls,
959 memcpy (&t6.ipv6_addr, 977 memcpy (&t6.ipv6_addr,
960 &((struct sockaddr_in6 *) addr)->sin6_addr, 978 &((struct sockaddr_in6 *) addr)->sin6_addr,
961 sizeof (struct in6_addr)); 979 sizeof (struct in6_addr));
980 GNUNET_assert(NULL != inet_ntop(AF_INET6, &t6.ipv6_addr, &buf[0], INET6_ADDRSTRLEN));
981 if ((plugin->bind_address != NULL) || ((plugin->bind6_address != NULL) && (0 != strcmp(buf, plugin->bind_address))))
982 {
983 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Not notifying transport of address %s\n", "UDP", GNUNET_a2s (addr, addrlen));
984 return GNUNET_OK;
985 }
962 add_to_address_list (plugin, &t6.ipv6_addr, sizeof (struct in6_addr)); 986 add_to_address_list (plugin, &t6.ipv6_addr, sizeof (struct in6_addr));
963 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES)) 987 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES))
964 { 988 {
@@ -1001,7 +1025,7 @@ process_interfaces (void *cls,
1001 GNUNET_a2s (addr_nat, args), name); 1025 GNUNET_a2s (addr_nat, args), name);
1002 GNUNET_free(addr_nat); 1026 GNUNET_free(addr_nat);
1003 } 1027 }
1004 1028
1005 plugin->env->notify_address (plugin->env->cls, 1029 plugin->env->notify_address (plugin->env->cls,
1006 "udp", 1030 "udp",
1007 arg, args, GNUNET_TIME_UNIT_FOREVER_REL); 1031 arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -1055,7 +1079,7 @@ send_udp_probe_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
1055 probe->addr.u_port = htons(plugin->port); 1079 probe->addr.u_port = htons(plugin->port);
1056 1080
1057#if DEBUG_UDP 1081#if DEBUG_UDP
1058 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1059 _("Sending a probe to port %d\n"), ntohs(probe->addr.u_port)); 1083 _("Sending a probe to port %d\n"), ntohs(probe->addr.u_port));
1060#endif 1084#endif
1061 probe->count++; 1085 probe->count++;
@@ -1083,7 +1107,7 @@ udp_probe_continuation (void *cls, const struct GNUNET_PeerIdentity *target, int
1083 if ((result == GNUNET_OK) && (probe->count < MAX_PROBES)) 1107 if ((result == GNUNET_OK) && (probe->count < MAX_PROBES))
1084 { 1108 {
1085#if DEBUG_UDP 1109#if DEBUG_UDP
1086 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 _("Scheduling next probe for 10000 milliseconds\n")); 1111 _("Scheduling next probe for 10000 milliseconds\n"));
1088#endif 1112#endif
1089 probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10000), &send_udp_probe_message, probe); 1113 probe->task = GNUNET_SCHEDULER_add_delayed(plugin->env->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10000), &send_udp_probe_message, probe);
@@ -1091,7 +1115,7 @@ udp_probe_continuation (void *cls, const struct GNUNET_PeerIdentity *target, int
1091 else /* Destroy the probe context. */ 1115 else /* Destroy the probe context. */
1092 { 1116 {
1093#if DEBUG_UDP 1117#if DEBUG_UDP
1094 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1095 _("Sending probe didn't go well...\n")); 1119 _("Sending probe didn't go well...\n"));
1096#endif 1120#endif
1097 } 1121 }
@@ -1147,7 +1171,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
1147 if (bytes < 1) 1171 if (bytes < 1)
1148 { 1172 {
1149#if DEBUG_UDP 1173#if DEBUG_UDP
1150 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1151 _("Finished reading from server stdout with code: %d\n"), bytes); 1175 _("Finished reading from server stdout with code: %d\n"), bytes);
1152#endif 1176#endif
1153 return; 1177 return;
@@ -1179,7 +1203,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
1179 } 1203 }
1180 1204
1181#if DEBUG_UDP 1205#if DEBUG_UDP
1182 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1183 _("nat-server-read read: %s port %d\n"), &mybuf, port); 1207 _("nat-server-read read: %s port %d\n"), &mybuf, port);
1184#endif 1208#endif
1185 1209
@@ -1190,7 +1214,7 @@ udp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
1190 if (inet_pton(AF_INET, &mybuf[0], &a4.ipv4_addr) != 1) 1214 if (inet_pton(AF_INET, &mybuf[0], &a4.ipv4_addr) != 1)
1191 { 1215 {
1192 1216
1193 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", 1217 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1194 _("nat-server-read malformed address\n"), &mybuf, port); 1218 _("nat-server-read malformed address\n"), &mybuf, port);
1195 1219
1196 plugin->server_read_task = 1220 plugin->server_read_task =
@@ -1277,9 +1301,9 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1277 outgoing_probe_reply->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY); 1301 outgoing_probe_reply->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY);
1278 1302
1279#if DEBUG_UDP 1303#if DEBUG_UDP
1280 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1281 _("Received a probe on listen port %d, sent_from port %d\n"), 1305 _("Received a probe on listen port %d, sent_from port %d\n"),
1282 sockinfo->port, incoming_port); 1306 sockinfo->port, incoming_port);
1283#endif 1307#endif
1284 1308
1285 udp_real_send(plugin, sockinfo->desc, NULL, 1309 udp_real_send(plugin, sockinfo->desc, NULL,
@@ -1290,19 +1314,19 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1290 NULL, NULL); 1314 NULL, NULL);
1291 1315
1292#if DEBUG_UDP 1316#if DEBUG_UDP
1293 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1294 _("Sent PROBE REPLY to port %d on outgoing port %d\n"), 1318 _("Sent PROBE REPLY to port %d on outgoing port %d\n"),
1295 incoming_port, sockinfo->port); 1319 incoming_port, sockinfo->port);
1296#endif 1320#endif
1297 GNUNET_free(outgoing_probe_reply); 1321 GNUNET_free(outgoing_probe_reply);
1298 break; 1322 break;
1299 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY: 1323 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_REPLY:
1300 /* Check for existing probe, check ports returned, send confirmation if all is well */ 1324 /* Check for existing probe, check ports returned, send confirmation if all is well */
1301#if DEBUG_UDP 1325#if DEBUG_UDP
1302 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1303 _("Received PROBE REPLY from port %d on incoming port %d\n"), incoming_port, sockinfo->port); 1327 _("Received PROBE REPLY from port %d on incoming port %d\n"), incoming_port, sockinfo->port);
1304#endif 1328#endif
1305 if (sizeof(sender_addr) == sizeof(struct IPv4UdpAddress)) 1329 if (fromlen == sizeof(struct IPv4UdpAddress))
1306 { 1330 {
1307 memset(&addr_buf, 0, sizeof(addr_buf)); 1331 memset(&addr_buf, 0, sizeof(addr_buf));
1308 if (NULL == inet_ntop (AF_INET, 1332 if (NULL == inet_ntop (AF_INET,
@@ -1316,8 +1340,8 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1316 if (outgoing_probe != NULL) 1340 if (outgoing_probe != NULL)
1317 { 1341 {
1318#if DEBUG_UDP 1342#if DEBUG_UDP
1319 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1320 _("Sending confirmation that we were reached!\n")); 1344 _("Sending confirmation that we were reached!\n"));
1321#endif 1345#endif
1322 outgoing_probe_confirmation = GNUNET_malloc(sizeof(struct UDP_NAT_ProbeMessageConfirmation)); 1346 outgoing_probe_confirmation = GNUNET_malloc(sizeof(struct UDP_NAT_ProbeMessageConfirmation));
1323 outgoing_probe_confirmation->header.size = htons(sizeof(struct UDP_NAT_ProbeMessageConfirmation)); 1347 outgoing_probe_confirmation->header.size = htons(sizeof(struct UDP_NAT_ProbeMessageConfirmation));
@@ -1339,23 +1363,30 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1339 else 1363 else
1340 { 1364 {
1341#if DEBUG_UDP 1365#if DEBUG_UDP
1342 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", 1366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1343 _("Received a probe reply, but have no record of a sent probe!\n")); 1367 _("Received a probe reply, but have no record of a sent probe!\n"));
1344#endif 1368#endif
1345 } 1369 }
1346 } 1370 }
1371 else
1372 {
1373#if DEBUG_UDP
1374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1375 _("Received a probe reply, but sender address size is WRONG (should be %d, is %d)!\n"), sizeof(struct IPv4UdpAddress), fromlen);
1376#endif
1377 }
1347 break; 1378 break;
1348 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_CONFIRM: 1379 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_CONFIRM:
1349 peer_session = find_session(plugin, sender); 1380 peer_session = find_session(plugin, sender);
1350#if DEBUG_UDP 1381#if DEBUG_UDP
1351 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1352 _("Looking up peer session for peer %s\n"), GNUNET_i2s(sender)); 1383 _("Looking up peer session for peer %s\n"), GNUNET_i2s(sender));
1353#endif 1384#endif
1354 if (peer_session == NULL) /* Shouldn't this NOT happen? */ 1385 if (peer_session == NULL) /* Shouldn't this NOT happen? */
1355 { 1386 {
1356#if DEBUG_UDP 1387#if DEBUG_UDP
1357 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", 1388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1358 _("Peer not in list, adding (THIS MAY BE A MISTAKE) %s\n"), GNUNET_i2s(sender)); 1389 _("Peer not in list, adding (THIS MAY BE A MISTAKE) %s\n"), GNUNET_i2s(sender));
1359#endif 1390#endif
1360 peer_session = GNUNET_malloc(sizeof(struct PeerSession)); 1391 peer_session = GNUNET_malloc(sizeof(struct PeerSession));
1361 peer_session->connect_addr = GNUNET_malloc(fromlen); 1392 peer_session->connect_addr = GNUNET_malloc(fromlen);
@@ -1385,22 +1416,22 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1385 } 1416 }
1386 1417
1387#if DEBUG_UDP 1418#if DEBUG_UDP
1388 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", 1419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1389 _("Received a probe confirmation, will send to peer on port %d\n"), incoming_port); 1420 _("Received a probe confirmation, will send to peer on port %d\n"), incoming_port);
1390#endif 1421#endif
1391 if (peer_session->messages != NULL) 1422 if (peer_session->messages != NULL)
1392 { 1423 {
1393#if DEBUG_UDP 1424#if DEBUG_UDP
1394 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", 1425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1395 _("Received a probe confirmation, sending queued messages.\n")); 1426 _("Received a probe confirmation, sending queued messages.\n"));
1396#endif 1427#endif
1397 pending_message = peer_session->messages; 1428 pending_message = peer_session->messages;
1398 int count = 0; 1429 int count = 0;
1399 while (pending_message != NULL) 1430 while (pending_message != NULL)
1400 { 1431 {
1401#if DEBUG_UDP 1432#if DEBUG_UDP
1402 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", 1433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1403 _("sending queued message %d\n"), count); 1434 _("sending queued message %d\n"), count);
1404#endif 1435#endif
1405 udp_real_send(plugin, 1436 udp_real_send(plugin,
1406 peer_session->sock, 1437 peer_session->sock,
@@ -1418,8 +1449,8 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1418 GNUNET_free(pending_message_temp->msgbuf); 1449 GNUNET_free(pending_message_temp->msgbuf);
1419 GNUNET_free(pending_message_temp); 1450 GNUNET_free(pending_message_temp);
1420#if DEBUG_UDP 1451#if DEBUG_UDP
1421 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", 1452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1422 _("finished sending queued message %d\n"), count); 1453 _("finished sending queued message %d\n"), count);
1423#endif 1454#endif
1424 count++; 1455 count++;
1425 } 1456 }
@@ -1429,8 +1460,8 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1429 else 1460 else
1430 { 1461 {
1431#if DEBUG_UDP 1462#if DEBUG_UDP
1432 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", 1463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1433 _("Received probe confirmation for already confirmed peer!\n")); 1464 _("Received probe confirmation for already confirmed peer!\n"));
1434#endif 1465#endif
1435 } 1466 }
1436 /* Received confirmation, add peer with address/port specified */ 1467 /* Received confirmation, add peer with address/port specified */
@@ -1441,10 +1472,9 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1441 break; 1472 break;
1442 default: 1473 default:
1443#if DEBUG_UDP 1474#if DEBUG_UDP
1444 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1445 "udp", 1476 "Sending message type %d to transport!\n",
1446 "Sending message type %d to transport!\n", 1477 ntohs(currhdr->type));
1447 ntohs(currhdr->type));
1448#endif 1478#endif
1449 plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, 1479 plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE,
1450 NULL, sender_addr, fromlen); 1480 NULL, sender_addr, fromlen);
@@ -1592,6 +1622,7 @@ udp_transport_server_start (void *cls)
1592 int sockets_created; 1622 int sockets_created;
1593 int tries; 1623 int tries;
1594 1624
1625
1595 sockets_created = 0; 1626 sockets_created = 0;
1596 if (plugin->behind_nat == GNUNET_YES) 1627 if (plugin->behind_nat == GNUNET_YES)
1597 { 1628 {
@@ -1600,11 +1631,10 @@ udp_transport_server_start (void *cls)
1600 if (plugin->server_stdout == NULL) 1631 if (plugin->server_stdout == NULL)
1601 return sockets_created; 1632 return sockets_created;
1602#if DEBUG_UDP 1633#if DEBUG_UDP
1603 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1604 "udp", 1635 "Starting gnunet-nat-server process cmd: %s %s\n",
1605 "Starting gnunet-nat-server process cmd: %s %s\n", 1636 "gnunet-nat-server",
1606 "gnunet-nat-server", 1637 plugin->internal_address);
1607 plugin->internal_address);
1608#endif 1638#endif
1609 /* Start the server process */ 1639 /* Start the server process */
1610 plugin->server_pid = GNUNET_OS_start_process(NULL, 1640 plugin->server_pid = GNUNET_OS_start_process(NULL,
@@ -1615,9 +1645,8 @@ udp_transport_server_start (void *cls)
1615 if (plugin->server_pid == GNUNET_SYSERR) 1645 if (plugin->server_pid == GNUNET_SYSERR)
1616 { 1646 {
1617#if DEBUG_UDP 1647#if DEBUG_UDP
1618 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1619 "udp", 1649 "Failed to start gnunet-nat-server process\n");
1620 "Failed to start gnunet-nat-server process\n");
1621#endif 1650#endif
1622 return GNUNET_SYSERR; 1651 return GNUNET_SYSERR;
1623 } 1652 }
@@ -1632,10 +1661,10 @@ udp_transport_server_start (void *cls)
1632 } 1661 }
1633 1662
1634 if ( (GNUNET_YES != 1663 if ( (GNUNET_YES !=
1635 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "GNUNETD", 1664 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "transport-udp",
1636 "DISABLE-IPV6"))) 1665 "DISABLEV6")))
1637 { 1666 {
1638 plugin->udp_sockv6.desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 17); 1667 plugin->udp_sockv6.desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
1639 if (NULL == plugin->udp_sockv6.desc) 1668 if (NULL == plugin->udp_sockv6.desc)
1640 { 1669 {
1641 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "socket"); 1670 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "socket");
@@ -1646,14 +1675,20 @@ udp_transport_server_start (void *cls)
1646#if HAVE_SOCKADDR_IN_SIN_LEN 1675#if HAVE_SOCKADDR_IN_SIN_LEN
1647 serverAddrv6.sin6_len = sizeof (serverAddrv6); 1676 serverAddrv6.sin6_len = sizeof (serverAddrv6);
1648#endif 1677#endif
1678
1649 serverAddrv6.sin6_family = AF_INET6; 1679 serverAddrv6.sin6_family = AF_INET6;
1650 serverAddrv6.sin6_addr = in6addr_any; 1680 serverAddrv6.sin6_addr = in6addr_any;
1681 if (plugin->bind6_address != NULL)
1682 {
1683 if (1 != inet_pton(AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr))
1684 return 0;
1685 }
1686
1651 serverAddrv6.sin6_port = htons (plugin->port); 1687 serverAddrv6.sin6_port = htons (plugin->port);
1652 addrlen = sizeof (serverAddrv6); 1688 addrlen = sizeof (serverAddrv6);
1653 serverAddr = (struct sockaddr *) &serverAddrv6; 1689 serverAddr = (struct sockaddr *) &serverAddrv6;
1654#if DEBUG_UDP 1690#if DEBUG_UDP
1655 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "udp",
1657 "Binding to IPv6 port %d\n", 1692 "Binding to IPv6 port %d\n",
1658 ntohs(serverAddrv6.sin6_port)); 1693 ntohs(serverAddrv6.sin6_port));
1659#endif 1694#endif
@@ -1663,8 +1698,7 @@ udp_transport_server_start (void *cls)
1663 { 1698 {
1664 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1699 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1665#if DEBUG_UDP 1700#if DEBUG_UDP
1666 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1667 "udp",
1668 "IPv6 Binding failed, trying new port %d\n", 1702 "IPv6 Binding failed, trying new port %d\n",
1669 ntohs(serverAddrv6.sin6_port)); 1703 ntohs(serverAddrv6.sin6_port));
1670#endif 1704#endif
@@ -1683,11 +1717,11 @@ udp_transport_server_start (void *cls)
1683 } 1717 }
1684 } 1718 }
1685 } 1719 }
1686 1720
1687 plugin->udp_sockv4.desc = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 17); 1721 plugin->udp_sockv4.desc = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
1688 if (NULL == plugin->udp_sockv4.desc) 1722 if (NULL == plugin->udp_sockv4.desc)
1689 { 1723 {
1690 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "socket"); 1724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "socket");
1691 } 1725 }
1692 else 1726 else
1693 { 1727 {
@@ -1697,12 +1731,16 @@ udp_transport_server_start (void *cls)
1697#endif 1731#endif
1698 serverAddrv4.sin_family = AF_INET; 1732 serverAddrv4.sin_family = AF_INET;
1699 serverAddrv4.sin_addr.s_addr = INADDR_ANY; 1733 serverAddrv4.sin_addr.s_addr = INADDR_ANY;
1734 if (plugin->bind_address != NULL)
1735 {
1736 if (1 != inet_pton(AF_INET, plugin->bind_address, &serverAddrv4.sin_addr))
1737 return 0;
1738 }
1700 serverAddrv4.sin_port = htons (plugin->port); 1739 serverAddrv4.sin_port = htons (plugin->port);
1701 addrlen = sizeof (serverAddrv4); 1740 addrlen = sizeof (serverAddrv4);
1702 serverAddr = (struct sockaddr *) &serverAddrv4; 1741 serverAddr = (struct sockaddr *) &serverAddrv4;
1703#if DEBUG_UDP 1742#if DEBUG_UDP
1704 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1705 "udp",
1706 "Binding to IPv4 port %d\n", 1744 "Binding to IPv4 port %d\n",
1707 ntohs(serverAddrv4.sin_port)); 1745 ntohs(serverAddrv4.sin_port));
1708#endif 1746#endif
@@ -1712,8 +1750,7 @@ udp_transport_server_start (void *cls)
1712 { 1750 {
1713 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1751 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1714#if DEBUG_UDP 1752#if DEBUG_UDP
1715 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1716 "udp",
1717 "IPv4 Binding failed, trying new port %d\n", 1754 "IPv4 Binding failed, trying new port %d\n",
1718 ntohs(serverAddrv4.sin_port)); 1755 ntohs(serverAddrv4.sin_port));
1719#endif 1756#endif
@@ -1740,6 +1777,7 @@ udp_transport_server_start (void *cls)
1740 if (NULL != plugin->udp_sockv6.desc) 1777 if (NULL != plugin->udp_sockv6.desc)
1741 GNUNET_NETWORK_fdset_set (plugin->rs, 1778 GNUNET_NETWORK_fdset_set (plugin->rs,
1742 plugin->udp_sockv6.desc); 1779 plugin->udp_sockv6.desc);
1780
1743 plugin->select_task = 1781 plugin->select_task =
1744 GNUNET_SCHEDULER_add_select (plugin->env->sched, 1782 GNUNET_SCHEDULER_add_select (plugin->env->sched,
1745 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1783 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1851,8 +1889,7 @@ udp_check_address (void *cls,
1851 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 1889 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
1852 1890
1853#if DEBUG_UDP 1891#if DEBUG_UDP
1854 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1855 "udp",
1856 "Informing transport service about my address `%s:%u'\n", 1893 "Informing transport service about my address `%s:%u'\n",
1857 buf, 1894 buf,
1858 port); 1895 port);
@@ -2089,7 +2126,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2089 service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg); 2126 service = GNUNET_SERVICE_start ("transport-udp", env->sched, env->cfg);
2090 if (service == NULL) 2127 if (service == NULL)
2091 { 2128 {
2092 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", _ 2129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _
2093 ("Failed to start service for `%s' transport plugin.\n"), 2130 ("Failed to start service for `%s' transport plugin.\n"),
2094 "udp"); 2131 "udp");
2095 return NULL; 2132 return NULL;
@@ -2105,7 +2142,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2105 else 2142 else
2106 { 2143 {
2107 behind_nat = GNUNET_NO; 2144 behind_nat = GNUNET_NO;
2108 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", "Configuration specified you are behind a NAT, but gnunet-nat-server is not installed properly (suid bit not set)!\n"); 2145 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Configuration specified you are behind a NAT, but gnunet-nat-server is not installed properly (suid bit not set)!\n");
2109 } 2146 }
2110 } 2147 }
2111 else 2148 else
@@ -2120,7 +2157,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2120 else 2157 else
2121 { 2158 {
2122 allow_nat = GNUNET_NO; 2159 allow_nat = GNUNET_NO;
2123 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "udp", "Configuration specified you want to connect to NAT'd peers, but gnunet-nat-client is not installed properly (suid bit not set)!\n"); 2160 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Configuration specified you want to connect to NAT'd peers, but gnunet-nat-client is not installed properly (suid bit not set)!\n");
2124 } 2161 }
2125 2162
2126 } 2163 }
@@ -2141,18 +2178,16 @@ libgnunet_plugin_transport_udp_init (void *cls)
2141 "EXTERNAL_ADDRESS", 2178 "EXTERNAL_ADDRESS",
2142 &external_address))) 2179 &external_address)))
2143 { 2180 {
2144 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2145 "udp", 2182 _("Require EXTERNAL_ADDRESS for service `%s' in configuration (either BEHIND_NAT or ALLOW_NAT set to YES)!\n"),
2146 _ 2183 "transport-udp");
2147 ("Require EXTERNAL_ADDRESS for service `%s' in configuration (either BEHIND_NAT or ALLOW_NAT set to YES)!\n"),
2148 "transport-udp");
2149 GNUNET_SERVICE_stop (service); 2184 GNUNET_SERVICE_stop (service);
2150 return NULL; 2185 return NULL;
2151 } 2186 }
2152 2187
2153 if ((external_address != NULL) && (inet_pton(AF_INET, external_address, &v4_address.ipv4_addr) != 1)) 2188 if ((external_address != NULL) && (inet_pton(AF_INET, external_address, &v4_address.ipv4_addr) != 1))
2154 { 2189 {
2155 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed EXTERNAL_ADDRESS %s given in configuration!\n", external_address); 2190 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Malformed EXTERNAL_ADDRESS %s given in configuration!\n", external_address);
2156 } 2191 }
2157 2192
2158 internal_address = NULL; 2193 internal_address = NULL;
@@ -2162,10 +2197,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
2162 "INTERNAL_ADDRESS", 2197 "INTERNAL_ADDRESS",
2163 &internal_address))) 2198 &internal_address)))
2164 { 2199 {
2165 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2166 "udp", 2201 _("Require INTERNAL_ADDRESS for service `%s' in configuration!\n"),
2167 _
2168 ("Require INTERNAL_ADDRESS for service `%s' in configuration!\n"),
2169 "transport-udp"); 2202 "transport-udp");
2170 GNUNET_SERVICE_stop (service); 2203 GNUNET_SERVICE_stop (service);
2171 GNUNET_free_non_null(external_address); 2204 GNUNET_free_non_null(external_address);
@@ -2174,7 +2207,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
2174 2207
2175 if ((internal_address != NULL) && (inet_pton(AF_INET, internal_address, &v4_address.ipv4_addr) != 1)) 2208 if ((internal_address != NULL) && (inet_pton(AF_INET, internal_address, &v4_address.ipv4_addr) != 1))
2176 { 2209 {
2177 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, "udp", "Malformed INTERNAL_ADDRESS %s given in configuration!\n", internal_address); 2210 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Malformed INTERNAL_ADDRESS %s given in configuration!\n", internal_address);
2178 } 2211 }
2179 2212
2180 if (GNUNET_OK != 2213 if (GNUNET_OK !=
@@ -2185,12 +2218,11 @@ libgnunet_plugin_transport_udp_init (void *cls)
2185 port = UDP_NAT_DEFAULT_PORT; 2218 port = UDP_NAT_DEFAULT_PORT;
2186 else if (port > 65535) 2219 else if (port > 65535)
2187 { 2220 {
2188 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 2221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2189 "udp", 2222 _("Given `%s' option is out of range: %llu > %u\n"),
2190 _("Given `%s' option is out of range: %llu > %u\n"), 2223 "PORT",
2191 "PORT", 2224 port,
2192 port, 2225 65535);
2193 65535);
2194 GNUNET_SERVICE_stop (service); 2226 GNUNET_SERVICE_stop (service);
2195 GNUNET_free_non_null(external_address); 2227 GNUNET_free_non_null(external_address);
2196 GNUNET_free_non_null(internal_address); 2228 GNUNET_free_non_null(internal_address);
@@ -2199,10 +2231,9 @@ libgnunet_plugin_transport_udp_init (void *cls)
2199 2231
2200 mtu = 1240; 2232 mtu = 1240;
2201 if (mtu < 1200) 2233 if (mtu < 1200)
2202 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2234 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2203 "udp", 2235 _("MTU %llu for `%s' is probably too low!\n"), mtu,
2204 _("MTU %llu for `%s' is probably too low!\n"), mtu, 2236 "UDP");
2205 "UDP");
2206 2237
2207 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2238 plugin = GNUNET_malloc (sizeof (struct Plugin));
2208 plugin->external_address = external_address; 2239 plugin->external_address = external_address;
@@ -2224,6 +2255,10 @@ libgnunet_plugin_transport_udp_init (void *cls)
2224 2255
2225 plugin->service = service; 2256 plugin->service = service;
2226 2257
2258 GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-udp", "BINDTO", &plugin->bind_address);
2259
2260 GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-udp", "BINDTO6", &plugin->bind6_address);
2261
2227 if (plugin->behind_nat == GNUNET_NO) 2262 if (plugin->behind_nat == GNUNET_NO)
2228 { 2263 {
2229 GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); 2264 GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
@@ -2253,9 +2288,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
2253 2288
2254 sockets_created = udp_transport_server_start (plugin); 2289 sockets_created = udp_transport_server_start (plugin);
2255 if (sockets_created == 0) 2290 if (sockets_created == 0)
2256 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 2291 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2257 "udp", 2292 _("Failed to open UDP sockets\n"));
2258 _("Failed to open UDP sockets\n"));
2259 return api; 2293 return api;
2260} 2294}
2261 2295