aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-10 21:52:42 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-10 21:52:42 +0000
commit894248a687a4c5e63de96a58026bf275a10339a0 (patch)
tree0c9d612c27d69617891fd2e5dc62f83ef780c1ed
parent909622d667a3ee923ff0ea03f5184a4eaa20880f (diff)
downloadgnunet-894248a687a4c5e63de96a58026bf275a10339a0.tar.gz
gnunet-894248a687a4c5e63de96a58026bf275a10339a0.zip
-dealing with new UDP message formats
-rw-r--r--src/exit/exit.h18
-rw-r--r--src/exit/gnunet-daemon-exit.c104
2 files changed, 78 insertions, 44 deletions
diff --git a/src/exit/exit.h b/src/exit/exit.h
index 37ae7e8a4..2047ca113 100644
--- a/src/exit/exit.h
+++ b/src/exit/exit.h
@@ -128,9 +128,14 @@ struct GNUNET_EXIT_UdpServiceMessage
128 struct GNUNET_MessageHeader header; 128 struct GNUNET_MessageHeader header;
129 129
130 /** 130 /**
131 * Always 0. 131 * Source port to use for the UDP request (0 to use a random port). In NBO.
132 */ 132 */
133 uint32_t reserved; 133 uint16_t source_port;
134
135 /**
136 * Destination port to use for the UDP request. In NBO.
137 */
138 uint16_t destination_port;
134 139
135 /** 140 /**
136 * Identification for the desired service. 141 * Identification for the desired service.
@@ -157,6 +162,15 @@ struct GNUNET_EXIT_UdpInternetMessage
157 */ 162 */
158 int32_t af; 163 int32_t af;
159 164
165 /**
166 * Source port to use for the UDP request (0 to use a random port). In NBO.
167 */
168 uint16_t source_port;
169
170 /**
171 * Destination port to use for the UDP request. In NBO.
172 */
173 uint16_t destination_port;
160 174
161 /* followed by IP address of the destination; either 175 /* followed by IP address of the destination; either
162 'struct in_addr' or 'struct in6_addr', depending on af */ 176 'struct in_addr' or 'struct in6_addr', depending on af */
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index e5d471b2f..2f1865714 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -25,7 +25,6 @@
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 * 26 *
27 * TODO: 27 * TODO:
28 * - use new proper message headers for mesh P2P messages
29 * - factor out crc computations from DNS/EXIT/VPN into shared library? 28 * - factor out crc computations from DNS/EXIT/VPN into shared library?
30 * - which code should advertise services? the service model is right 29 * - which code should advertise services? the service model is right
31 * now a bit odd, especially as this code DOES the exit and knows 30 * now a bit odd, especially as this code DOES the exit and knows
@@ -1202,7 +1201,7 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1202 struct tun_header *tun; 1201 struct tun_header *tun;
1203 1202
1204 hdr= (struct GNUNET_MessageHeader *) buf; 1203 hdr= (struct GNUNET_MessageHeader *) buf;
1205 hdr->type = htons (42); 1204 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1206 hdr->size = htons (len); 1205 hdr->size = htons (len);
1207 tun = (struct tun_header*) &hdr[1]; 1206 tun = (struct tun_header*) &hdr[1];
1208 tun->flags = htons (0); 1207 tun->flags = htons (0);
@@ -1477,7 +1476,7 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
1477 struct tun_header *tun; 1476 struct tun_header *tun;
1478 1477
1479 hdr= (struct GNUNET_MessageHeader *) buf; 1478 hdr= (struct GNUNET_MessageHeader *) buf;
1480 hdr->type = htons (42); 1479 hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
1481 hdr->size = htons (len); 1480 hdr->size = htons (len);
1482 tun = (struct tun_header*) &hdr[1]; 1481 tun = (struct tun_header*) &hdr[1];
1483 tun->flags = htons (0); 1482 tun->flags = htons (0);
@@ -1541,29 +1540,59 @@ receive_udp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1541 const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED) 1540 const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
1542{ 1541{
1543 struct TunnelState *state = *tunnel_ctx; 1542 struct TunnelState *state = *tunnel_ctx;
1544 // FIXME: write proper request struct (!) 1543 const struct GNUNET_EXIT_UdpInternetMessage *msg;
1545 const GNUNET_HashCode *desc = (const GNUNET_HashCode *) &message[1];
1546 const struct udp_packet *pkt = (const struct udp_packet *) &desc[1];
1547 const struct SocketAddress *s = (const struct SocketAddress *) desc;
1548 uint16_t pkt_len = ntohs (message->size); 1544 uint16_t pkt_len = ntohs (message->size);
1545 const struct in_addr *v4;
1546 const struct in6_addr *v6;
1547 const void *payload;
1548 int af;
1549 1549
1550 if (pkt_len < sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + sizeof (struct udp_packet)) 1550 if (pkt_len < sizeof (struct GNUNET_EXIT_UdpInternetMessage))
1551 { 1551 {
1552 GNUNET_break_op (0); 1552 GNUNET_break_op (0);
1553 return GNUNET_SYSERR; 1553 return GNUNET_SYSERR;
1554 } 1554 }
1555 pkt_len -= (sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode)); 1555 msg = (const struct GNUNET_EXIT_UdpInternetMessage*) message;
1556 1556 pkt_len -= sizeof (struct GNUNET_EXIT_UdpInternetMessage);
1557 if (NULL == state->heap_node) 1557 af = (int) ntohl (msg->af);
1558 state->ri.remote_address.af = af;
1559 switch (af)
1558 { 1560 {
1559 /* first packet, setup record */ 1561 case AF_INET:
1560 state->ri.remote_address = *s; 1562 if (pkt_len < sizeof (struct in_addr))
1561 setup_state_record (state); 1563 {
1564 GNUNET_break_op (0);
1565 return GNUNET_SYSERR;
1566 }
1567 v4 = (const struct in_addr*) &msg[1];
1568 payload = &v4[1];
1569 pkt_len -= sizeof (struct in_addr);
1570 state->ri.remote_address.address.ipv4 = *v4;
1571 break;
1572 case AF_INET6:
1573 if (pkt_len < sizeof (struct in6_addr))
1574 {
1575 GNUNET_break_op (0);
1576 return GNUNET_SYSERR;
1577 }
1578 v6 = (const struct in6_addr*) &msg[1];
1579 payload = &v6[1];
1580 pkt_len -= sizeof (struct in_addr);
1581 state->ri.remote_address.address.ipv6 = *v6;
1582 break;
1583 default:
1584 GNUNET_break_op (0);
1585 return GNUNET_SYSERR;
1562 } 1586 }
1563 1587 state->ri.remote_address.proto = IPPROTO_UDP;
1588 state->ri.remote_address.port = msg->destination_port;
1589 if (NULL == state->heap_node)
1590 setup_state_record (state);
1591 if (0 != ntohs (msg->source_port))
1592 state->ri.local_address.port = msg->source_port;
1564 send_udp_packet_via_tun (&state->ri.remote_address, 1593 send_udp_packet_via_tun (&state->ri.remote_address,
1565 &state->ri.local_address, 1594 &state->ri.local_address,
1566 &pkt[1], pkt_len - sizeof (struct udp_packet)); 1595 payload, pkt_len);
1567 return GNUNET_YES; 1596 return GNUNET_YES;
1568} 1597}
1569 1598
@@ -1589,43 +1618,34 @@ receive_udp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1589 const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED) 1618 const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
1590{ 1619{
1591 struct TunnelState *state = *tunnel_ctx; 1620 struct TunnelState *state = *tunnel_ctx;
1592 // FIXME: write proper request struct (we don't need UDP except dpt either!) 1621 const struct GNUNET_EXIT_UdpServiceMessage *msg;
1593 const GNUNET_HashCode *desc = (const GNUNET_HashCode *) &message[1];
1594 const struct udp_packet *pkt = (const struct udp_packet *) &desc[1];
1595 uint16_t pkt_len = ntohs (message->size); 1622 uint16_t pkt_len = ntohs (message->size);
1596 1623
1597
1598 /* check that we got at least a valid header */ 1624 /* check that we got at least a valid header */
1599 if (pkt_len < sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + sizeof (struct udp_packet)) 1625 if (pkt_len < sizeof (struct GNUNET_EXIT_UdpServiceMessage))
1600 { 1626 {
1601 GNUNET_break_op (0); 1627 GNUNET_break_op (0);
1602 return GNUNET_SYSERR; 1628 return GNUNET_SYSERR;
1603 } 1629 }
1604 pkt_len -= (sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode)); 1630 msg = (const struct GNUNET_EXIT_UdpServiceMessage*) message;
1605 1631 pkt_len -= sizeof (struct GNUNET_EXIT_UdpServiceMessage);
1606 GNUNET_assert (ntohs (pkt->len) == 1632
1607 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1633 if (NULL == (state->serv = find_service (udp_services, &msg->service_descriptor,
1608 sizeof (GNUNET_HashCode)); 1634 ntohs (msg->destination_port))))
1609
1610 if (NULL == state->serv)
1611 { 1635 {
1612 /* setup fresh connection */ 1636 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1613 GNUNET_assert (NULL == state->heap_node); 1637 _("No service found for %s on port %d!\n"),
1614 if (NULL == (state->serv = find_service (udp_services, desc, ntohs (pkt->dpt)))) 1638 "UDP",
1615 { 1639 ntohs (msg->destination_port));
1616 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1640 return GNUNET_SYSERR;
1617 _("No service found for %s on port %d!\n"),
1618 "UDP",
1619 ntohs (pkt->dpt));
1620 GNUNET_MESH_tunnel_destroy (state->tunnel);
1621 return GNUNET_SYSERR;
1622 }
1623 state->ri.remote_address = state->serv->address;
1624 setup_state_record (state);
1625 } 1641 }
1642 state->ri.remote_address = state->serv->address;
1643 setup_state_record (state);
1644 if (0 != ntohs (msg->source_port))
1645 state->ri.local_address.port = msg->source_port;
1626 send_udp_packet_via_tun (&state->ri.remote_address, 1646 send_udp_packet_via_tun (&state->ri.remote_address,
1627 &state->ri.local_address, 1647 &state->ri.local_address,
1628 &pkt[1], pkt_len - sizeof (struct udp_packet)); 1648 &msg[1], pkt_len);
1629 return GNUNET_YES; 1649 return GNUNET_YES;
1630} 1650}
1631 1651