diff options
Diffstat (limited to 'src/vpn/gnunet-service-vpn.c')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 58 |
1 files changed, 16 insertions, 42 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 0d236975e..153327b9b 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -32,10 +32,6 @@ | |||
32 | * | 32 | * |
33 | * Features: | 33 | * Features: |
34 | * - add back ICMP support (especially needed for IPv6) | 34 | * - add back ICMP support (especially needed for IPv6) |
35 | * | ||
36 | * Code cleanup: | ||
37 | * - consider moving IP-header building / checksumming code into shared library | ||
38 | * with dns/exit/vpn (libgnunettun_tcpip?) | ||
39 | */ | 35 | */ |
40 | #include "platform.h" | 36 | #include "platform.h" |
41 | #include "gnunet_util_lib.h" | 37 | #include "gnunet_util_lib.h" |
@@ -1436,7 +1432,10 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1436 | else | 1432 | else |
1437 | udp->dpt = reply->destination_port; | 1433 | udp->dpt = reply->destination_port; |
1438 | udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); | 1434 | udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); |
1439 | udp->crc = 0; // FIXME: optional, but we might want to calculate this one anyway | 1435 | GNUNET_TUN_calculate_udp4_checksum (ipv4, |
1436 | udp, | ||
1437 | &reply[1], | ||
1438 | mlen); | ||
1440 | memcpy (&udp[1], | 1439 | memcpy (&udp[1], |
1441 | &reply[1], | 1440 | &reply[1], |
1442 | mlen); | 1441 | mlen); |
@@ -1464,15 +1463,11 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1464 | msg->size = htons (size); | 1463 | msg->size = htons (size); |
1465 | tun->flags = htons (0); | 1464 | tun->flags = htons (0); |
1466 | tun->proto = htons (ETH_P_IPV6); | 1465 | tun->proto = htons (ETH_P_IPV6); |
1467 | ipv6->traffic_class_h = 0; | 1466 | GNUNET_TUN_initialize_ipv6_header (ipv6, |
1468 | ipv6->version = 6; | 1467 | IPPROTO_UDP, |
1469 | ipv6->traffic_class_l = 0; | 1468 | sizeof (struct GNUNET_TUN_UdpHeader) + mlen, |
1470 | ipv6->flow_label = 0; | 1469 | &ts->destination_ip.v6, |
1471 | ipv6->payload_length = htons (sizeof (struct GNUNET_TUN_UdpHeader) + sizeof (struct GNUNET_TUN_IPv6Header) + mlen); | 1470 | &ts->source_ip.v6); |
1472 | ipv6->next_header = IPPROTO_UDP; | ||
1473 | ipv6->hop_limit = 255; | ||
1474 | ipv6->source_address = ts->destination_ip.v6; | ||
1475 | ipv6->destination_address = ts->source_ip.v6; | ||
1476 | if (0 == ntohs (reply->source_port)) | 1471 | if (0 == ntohs (reply->source_port)) |
1477 | udp->spt = htons (ts->destination_port); | 1472 | udp->spt = htons (ts->destination_port); |
1478 | else | 1473 | else |
@@ -1482,24 +1477,12 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1482 | else | 1477 | else |
1483 | udp->dpt = reply->destination_port; | 1478 | udp->dpt = reply->destination_port; |
1484 | udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); | 1479 | udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); |
1485 | udp->crc = 0; | 1480 | GNUNET_TUN_calculate_udp6_checksum (ipv6, |
1481 | udp, | ||
1482 | &reply[1], mlen); | ||
1486 | memcpy (&udp[1], | 1483 | memcpy (&udp[1], |
1487 | &reply[1], | 1484 | &reply[1], |
1488 | mlen); | 1485 | mlen); |
1489 | { | ||
1490 | uint32_t sum = 0; | ||
1491 | sum = | ||
1492 | GNUNET_CRYPTO_crc16_step (sum, &ipv6->source_address, | ||
1493 | sizeof (struct in6_addr) * 2); | ||
1494 | uint32_t tmp = udp->len; | ||
1495 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1496 | tmp = htons (IPPROTO_UDP); | ||
1497 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1498 | sum = GNUNET_CRYPTO_crc16_step (sum, | ||
1499 | udp, | ||
1500 | ntohs (udp->len)); | ||
1501 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); | ||
1502 | } | ||
1503 | (void) GNUNET_HELPER_send (helper_handle, | 1486 | (void) GNUNET_HELPER_send (helper_handle, |
1504 | msg, | 1487 | msg, |
1505 | GNUNET_YES, | 1488 | GNUNET_YES, |
@@ -1596,22 +1579,13 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1596 | *tcp = data->tcp_header; | 1579 | *tcp = data->tcp_header; |
1597 | tcp->spt = htons (ts->destination_port); | 1580 | tcp->spt = htons (ts->destination_port); |
1598 | tcp->dpt = htons (ts->source_port); | 1581 | tcp->dpt = htons (ts->source_port); |
1599 | tcp->crc = 0; | 1582 | GNUNET_TUN_calculate_tcp4_checksum (ipv4, |
1583 | tcp, | ||
1584 | &data[1], | ||
1585 | mlen); | ||
1600 | memcpy (&tcp[1], | 1586 | memcpy (&tcp[1], |
1601 | &data[1], | 1587 | &data[1], |
1602 | mlen); | 1588 | mlen); |
1603 | { | ||
1604 | uint32_t sum = 0; | ||
1605 | uint32_t tmp; | ||
1606 | |||
1607 | sum = GNUNET_CRYPTO_crc16_step (sum, | ||
1608 | &ipv4->source_address, | ||
1609 | 2 * sizeof (struct in_addr)); | ||
1610 | tmp = htonl ((IPPROTO_TCP << 16) | (mlen + sizeof (struct GNUNET_TUN_TcpHeader))); | ||
1611 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | ||
1612 | sum = GNUNET_CRYPTO_crc16_step (sum, tcp, mlen + sizeof (struct GNUNET_TUN_TcpHeader)); | ||
1613 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | ||
1614 | } | ||
1615 | (void) GNUNET_HELPER_send (helper_handle, | 1589 | (void) GNUNET_HELPER_send (helper_handle, |
1616 | msg, | 1590 | msg, |
1617 | GNUNET_YES, | 1591 | GNUNET_YES, |