aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-28 11:37:52 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-28 11:37:52 +0000
commit59ca0059f61b1e2538f2890625601a88b2119f66 (patch)
treeecc298a424c8e28d3048bc74dd47bc8d3deff538 /src/transport/plugin_transport_tcp.c
parent62f22f399bd326fc6521204aff3b02bb32e8a401 (diff)
downloadgnunet-59ca0059f61b1e2538f2890625601a88b2119f66.tar.gz
gnunet-59ca0059f61b1e2538f2890625601a88b2119f66.zip
implementing local address check for tcp/udp
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c106
1 files changed, 104 insertions, 2 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index edf403ac6..2737003ab 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -150,6 +150,31 @@ struct Plugin;
150 150
151 151
152/** 152/**
153 * Local network addresses (actual IP address follows this struct).
154 * PORT is NOT included!
155 */
156struct LocalAddrList
157{
158
159 /**
160 * This is a doubly linked list.
161 */
162 struct LocalAddrList *next;
163
164 /**
165 * This is a doubly linked list.
166 */
167 struct LocalAddrList *prev;
168
169 /**
170 * Number of bytes of the address that follow
171 */
172 size_t size;
173
174};
175
176
177/**
153 * Information kept for each message that is yet to 178 * Information kept for each message that is yet to
154 * be transmitted. 179 * be transmitted.
155 */ 180 */
@@ -360,6 +385,16 @@ struct Plugin
360 char *internal_address; 385 char *internal_address;
361 386
362 /** 387 /**
388 * List of our IP addresses.
389 */
390 struct LocalAddrList *lal_head;
391
392 /**
393 * Tail of our IP address list.
394 */
395 struct LocalAddrList *lal_tail;
396
397 /**
363 * ID of task used to update our addresses when one expires. 398 * ID of task used to update our addresses when one expires.
364 */ 399 */
365 GNUNET_SCHEDULER_TaskIdentifier address_update_task; 400 GNUNET_SCHEDULER_TaskIdentifier address_update_task;
@@ -395,6 +430,47 @@ struct Plugin
395}; 430};
396 431
397 432
433static void
434add_to_address_list (struct Plugin *plugin,
435 const void *arg,
436 size_t arg_size)
437{
438 struct LocalAddrList *lal;
439
440 lal = plugin->lal_head;
441 while (NULL != lal)
442 {
443 if ( (lal->size == arg_size) &&
444 (0 == memcmp (&lal[1], arg, arg_size)) )
445 return;
446 lal = lal->next;
447 }
448 lal = GNUNET_malloc (sizeof (struct LocalAddrList) + arg_size);
449 lal->size = arg_size;
450 memcpy (&lal[1], arg, arg_size);
451 GNUNET_CONTAINER_DLL_insert (plugin->lal_head,
452 plugin->lal_tail,
453 lal);
454}
455
456
457static int
458check_local_addr (struct Plugin *plugin,
459 const void *arg,
460 size_t arg_size)
461{
462 struct LocalAddrList *lal;
463
464 lal = plugin->lal_head;
465 while (NULL != lal)
466 {
467 if ( (lal->size == arg_size) &&
468 (0 == memcmp (&lal[1], arg, arg_size)) )
469 return GNUNET_OK;
470 lal = lal->next;
471 }
472 return GNUNET_SYSERR;
473}
398 474
399 475
400/** 476/**
@@ -1375,6 +1451,14 @@ tcp_plugin_address_pretty_printer (void *cls,
1375static int 1451static int
1376check_port (struct Plugin *plugin, uint16_t in_port) 1452check_port (struct Plugin *plugin, uint16_t in_port)
1377{ 1453{
1454 if ( (plugin->behind_nat == GNUNET_YES) && (in_port == 0) )
1455 return GNUNET_OK;
1456 if ( (plugin->only_nat_addresses == GNUNET_YES) &&
1457 (plugin->behind_nat == GNUNET_YES) &&
1458 (in_port != 0) )
1459 {
1460 return GNUNET_SYSERR; /* odd case... */
1461 }
1378 if ((in_port == plugin->adv_port) || (in_port == plugin->open_port)) 1462 if ((in_port == plugin->adv_port) || (in_port == plugin->open_port))
1379 return GNUNET_OK; 1463 return GNUNET_OK;
1380 return GNUNET_SYSERR; 1464 return GNUNET_SYSERR;
@@ -1417,7 +1501,11 @@ tcp_plugin_check_address (void *cls,
1417 if (GNUNET_OK != 1501 if (GNUNET_OK !=
1418 check_port (plugin, ntohs (v4->t_port))) 1502 check_port (plugin, ntohs (v4->t_port)))
1419 return GNUNET_SYSERR; 1503 return GNUNET_SYSERR;
1420 /* FIXME: check IP! */ 1504 if (GNUNET_OK !=
1505 check_local_addr (plugin, &v4->ipv4_addr, sizeof (uint32_t)))
1506 {
1507 return GNUNET_SYSERR;
1508 }
1421 } 1509 }
1422 else 1510 else
1423 { 1511 {
@@ -1430,7 +1518,11 @@ tcp_plugin_check_address (void *cls,
1430 if (GNUNET_OK != 1518 if (GNUNET_OK !=
1431 check_port (plugin, ntohs (v6->t6_port))) 1519 check_port (plugin, ntohs (v6->t6_port)))
1432 return GNUNET_SYSERR; 1520 return GNUNET_SYSERR;
1433 /* FIXME: check IP! */ 1521 if (GNUNET_OK !=
1522 check_local_addr (plugin, &v6->ipv6_addr, sizeof (struct in6_addr)))
1523 {
1524 return GNUNET_SYSERR;
1525 }
1434 } 1526 }
1435 return GNUNET_OK; 1527 return GNUNET_OK;
1436} 1528}
@@ -1796,6 +1888,7 @@ process_interfaces (void *cls,
1796 if (af == AF_INET) 1888 if (af == AF_INET)
1797 { 1889 {
1798 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 1890 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1891 add_to_address_list (plugin, &t4.ipv4_addr, sizeof (uint32_t));
1799 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES)) 1892 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES))
1800 t4.t_port = htons(0); 1893 t4.t_port = htons(0);
1801 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */ 1894 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */
@@ -1819,6 +1912,7 @@ process_interfaces (void *cls,
1819 memcpy (&t6.ipv6_addr, 1912 memcpy (&t6.ipv6_addr,
1820 &((struct sockaddr_in6 *) addr)->sin6_addr, 1913 &((struct sockaddr_in6 *) addr)->sin6_addr,
1821 sizeof (struct in6_addr)); 1914 sizeof (struct in6_addr));
1915 add_to_address_list (plugin, &t6.ipv6_addr, sizeof (struct in6_addr));
1822 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES)) 1916 if ((plugin->behind_nat == GNUNET_YES) && (plugin->only_nat_addresses == GNUNET_YES))
1823 t6.t6_port = htons(0); 1917 t6.t6_port = htons(0);
1824 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */ 1918 else if (plugin->behind_nat == GNUNET_YES) /* We are behind NAT, but will advertise NAT and normal addresses */
@@ -2401,6 +2495,7 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2401 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2495 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2402 struct Plugin *plugin = api->cls; 2496 struct Plugin *plugin = api->cls;
2403 struct Session *session; 2497 struct Session *session;
2498 struct LocalAddrList *lal;
2404 2499
2405 while (NULL != (session = plugin->sessions)) 2500 while (NULL != (session = plugin->sessions))
2406 disconnect_session (session); 2501 disconnect_session (session);
@@ -2411,6 +2506,13 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2411 } 2506 }
2412 GNUNET_SERVICE_stop (plugin->service); 2507 GNUNET_SERVICE_stop (plugin->service);
2413 GNUNET_free (plugin->handlers); 2508 GNUNET_free (plugin->handlers);
2509 while (NULL != (lal = plugin->lal_head))
2510 {
2511 GNUNET_CONTAINER_DLL_remove (plugin->lal_head,
2512 plugin->lal_tail,
2513 lal);
2514 GNUNET_free (lal);
2515 }
2414 GNUNET_free (plugin); 2516 GNUNET_free (plugin);
2415 GNUNET_free (api); 2517 GNUNET_free (api);
2416 return NULL; 2518 return NULL;