};
+/**
+ * Return value from 'main'.
+ */
+static int global_ret;
+
/**
* The handle to the configuration used throughout the process
*/
/**
* Arguments to the exit helper.
*/
-static char *exit_argv[7];
+static char *exit_argv[8];
/**
* IPv6 address of our TUN interface.
/**
* If there are at least this many connections, old ones will be removed
*/
-static long long unsigned int max_connections;
+static unsigned long long max_connections;
/**
* This hashmaps saves interesting things about the configured UDP services
GNUNET_HashCode key;
struct TunnelState *state;
+ if ( ( (af == AF_INET) && (protocol == IPPROTO_ICMP) ) ||
+ ( (af == AF_INET6) && (protocol == IPPROTO_ICMPV6) ) )
+ {
+ /* ignore ports */
+ destination_port = 0;
+ local_port = 0;
+ }
ri.remote_address.af = af;
if (af == AF_INET)
ri.remote_address.address.ipv4 = *((struct in_addr*) destination_ip);
*
* @param service_map map of services (TCP or UDP)
* @param desc service descriptor
- * @param dpt destination port
+ * @param destination_port destination port
* @return NULL if we are not aware of such a service
*/
static struct LocalService *
find_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
const GNUNET_HashCode *desc,
- uint16_t dpt)
+ uint16_t destination_port)
{
char key[sizeof (GNUNET_HashCode) + sizeof (uint16_t)];
- memcpy (&key[0], &dpt, sizeof (uint16_t));
+ memcpy (&key[0], &destination_port, sizeof (uint16_t));
memcpy (&key[sizeof(uint16_t)], desc, sizeof (GNUNET_HashCode));
return GNUNET_CONTAINER_multihashmap_get (service_map,
(GNUNET_HashCode *) key);
*
* @param service_map map of services (TCP or UDP)
* @param name name of the service
- * @param dpt destination port
+ * @param destination_port destination port
* @param service service information record to store (service->name will be set).
*/
static void
store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
const char *name,
- uint16_t dpt,
+ uint16_t destination_port,
struct LocalService *service)
{
char key[sizeof (GNUNET_HashCode) + sizeof (uint16_t)];
GNUNET_CRYPTO_hash (name, strlen (name) + 1, &desc);
service->name = GNUNET_strdup (name);
- memcpy (&key[0], &dpt, sizeof (uint16_t));
+ memcpy (&key[0], &destination_port, sizeof (uint16_t));
memcpy (&key[sizeof(uint16_t)], &desc, sizeof (GNUNET_HashCode));
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (service_map,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Got duplicate service records for `%s:%u'\n"),
name,
- (unsigned int) dpt);
+ (unsigned int) destination_port);
}
}
s->th = NULL;
tnq = s->head;
+ if (NULL == tnq)
+ return 0;
+ if (0 == size)
+ {
+ s->th = GNUNET_MESH_notify_transmit_ready (tunnel,
+ GNUNET_NO /* corking */,
+ 0 /* priority */,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ NULL,
+ tnq->len,
+ &send_to_peer_notify_callback,
+ s);
+ return 0;
+ }
GNUNET_assert (size >= tnq->len);
memcpy (buf, tnq->payload, tnq->len);
size = tnq->len;
}
+/**
+ * @brief Handles an ICMP packet received from the helper.
+ *
+ * @param icmp A pointer to the Packet
+ * @param pktlen number of bytes in 'icmp'
+ * @param af address family (AFINET or AF_INET6)
+ * @param destination_ip destination IP-address of the IP packet (should
+ * be our local address)
+ * @param source_ip original source IP-address of the IP packet (should
+ * be the original destination address)
+ */
+static void
+icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp,
+ size_t pktlen,
+ int af,
+ const void *destination_ip,
+ const void *source_ip)
+{
+ struct TunnelState *state;
+ struct TunnelMessageQueue *tnq;
+ struct GNUNET_EXIT_IcmpToVPNMessage *i2v;
+ const struct GNUNET_TUN_IPv4Header *ipv4;
+ const struct GNUNET_TUN_IPv6Header *ipv6;
+ const struct GNUNET_TUN_UdpHeader *udp;
+ size_t mlen;
+ uint16_t source_port;
+ uint16_t destination_port;
+ uint8_t protocol;
+
+ {
+ char sbuf[INET6_ADDRSTRLEN];
+ char dbuf[INET6_ADDRSTRLEN];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received ICMP packet going from %s to %s\n",
+ inet_ntop (af,
+ source_ip,
+ sbuf, sizeof (sbuf)),
+ inet_ntop (af,
+ destination_ip,
+ dbuf, sizeof (dbuf)));
+ }
+ if (pktlen < sizeof (struct GNUNET_TUN_IcmpHeader))
+ {
+ /* blame kernel */
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Find out if this is an ICMP packet in response to an existing
+ TCP/UDP packet and if so, figure out ports / protocol of the
+ existing session from the IP data in the ICMP payload */
+ source_port = 0;
+ destination_port = 0;
+ switch (af)
+ {
+ case AF_INET:
+ protocol = IPPROTO_ICMP;
+ switch (icmp->type)
+ {
+ case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
+ case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
+ break;
+ case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
+ case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
+ case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
+ if (pktlen <
+ sizeof (struct GNUNET_TUN_IcmpHeader) +
+ sizeof (struct GNUNET_TUN_IPv4Header) + 8)
+ {
+ /* blame kernel */
+ GNUNET_break (0);
+ return;
+ }
+ ipv4 = (const struct GNUNET_TUN_IPv4Header *) &icmp[1];
+ protocol = ipv4->protocol;
+ /* could be TCP or UDP, but both have the ports in the right
+ place, so that doesn't matter here */
+ udp = (const struct GNUNET_TUN_UdpHeader *) &ipv4[1];
+ /* swap ports, as they are from the original message */
+ destination_port = ntohs (udp->source_port);
+ source_port = ntohs (udp->destination_port);
+ /* throw away ICMP payload, won't be useful for the other side anyway */
+ pktlen = sizeof (struct GNUNET_TUN_IcmpHeader);
+ break;
+ default:
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
+ 1, GNUNET_NO);
+ return;
+ }
+ break;
+ case AF_INET6:
+ protocol = IPPROTO_ICMPV6;
+ switch (icmp->type)
+ {
+ case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
+ case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
+ case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
+ case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
+ if (pktlen <
+ sizeof (struct GNUNET_TUN_IcmpHeader) +
+ sizeof (struct GNUNET_TUN_IPv6Header) + 8)
+ {
+ /* blame kernel */
+ GNUNET_break (0);
+ return;
+ }
+ ipv6 = (const struct GNUNET_TUN_IPv6Header *) &icmp[1];
+ protocol = ipv6->next_header;
+ /* could be TCP or UDP, but both have the ports in the right
+ place, so that doesn't matter here */
+ udp = (const struct GNUNET_TUN_UdpHeader *) &ipv6[1];
+ /* swap ports, as they are from the original message */
+ destination_port = ntohs (udp->source_port);
+ source_port = ntohs (udp->destination_port);
+ /* throw away ICMP payload, won't be useful for the other side anyway */
+ pktlen = sizeof (struct GNUNET_TUN_IcmpHeader);
+ break;
+ case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
+ case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
+ break;
+ default:
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
+ 1, GNUNET_NO);
+ return;
+ }
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ switch (protocol)
+ {
+ case IPPROTO_ICMP:
+ state = get_redirect_state (af, IPPROTO_ICMP,
+ source_ip, 0,
+ destination_ip, 0,
+ NULL);
+ break;
+ case IPPROTO_ICMPV6:
+ state = get_redirect_state (af, IPPROTO_ICMPV6,
+ source_ip, 0,
+ destination_ip, 0,
+ NULL);
+ break;
+ case IPPROTO_UDP:
+ state = get_redirect_state (af, IPPROTO_UDP,
+ source_ip,
+ source_port,
+ destination_ip,
+ destination_port,
+ NULL);
+ break;
+ case IPPROTO_TCP:
+ state = get_redirect_state (af, IPPROTO_TCP,
+ source_ip,
+ source_port,
+ destination_ip,
+ destination_port,
+ NULL);
+ break;
+ default:
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMP packets dropped (not allowed)"),
+ 1, GNUNET_NO);
+ return;
+ }
+ if (NULL == state)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("ICMP Packet dropped, have no matching connection information\n"));
+ return;
+ }
+ mlen = sizeof (struct GNUNET_EXIT_IcmpToVPNMessage) + pktlen - sizeof (struct GNUNET_TUN_IcmpHeader);
+ tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueue) + mlen);
+ tnq->payload = &tnq[1];
+ tnq->len = mlen;
+ i2v = (struct GNUNET_EXIT_IcmpToVPNMessage *) &tnq[1];
+ i2v->header.size = htons ((uint16_t) mlen);
+ i2v->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN);
+ i2v->af = htonl (af);
+ memcpy (&i2v->icmp_header,
+ icmp,
+ pktlen);
+ send_packet_to_mesh_tunnel (state->tunnel,
+ tnq);
+}
+
+
/**
* @brief Handles an UDP packet received from the helper.
*
inet_ntop (af,
source_ip,
sbuf, sizeof (sbuf)),
- (unsigned int) ntohs (udp->spt),
+ (unsigned int) ntohs (udp->source_port),
inet_ntop (af,
- source_ip,
+ destination_ip,
dbuf, sizeof (dbuf)),
- (unsigned int) ntohs (udp->dpt));
+ (unsigned int) ntohs (udp->destination_port));
}
if (pktlen < sizeof (struct GNUNET_TUN_UdpHeader))
{
}
state = get_redirect_state (af, IPPROTO_UDP,
source_ip,
- ntohs (udp->spt),
+ ntohs (udp->source_port),
destination_ip,
- ntohs (udp->dpt),
+ ntohs (udp->destination_port),
NULL);
if (NULL == state)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Packet dropped, have no matching connection information\n"));
+ _("UDP Packet dropped, have no matching connection information\n"));
return;
}
mlen = sizeof (struct GNUNET_EXIT_UdpReplyMessage) + pktlen - sizeof (struct GNUNET_TUN_UdpHeader);
const void *source_ip)
{
struct TunnelState *state;
- char buf[pktlen];
+ char buf[pktlen] GNUNET_ALIGN;
struct GNUNET_TUN_TcpHeader *mtcp;
struct GNUNET_EXIT_TcpDataMessage *tdm;
struct TunnelMessageQueue *tnq;
inet_ntop (af,
source_ip,
sbuf, sizeof (sbuf)),
- (unsigned int) ntohs (tcp->spt),
+ (unsigned int) ntohs (tcp->source_port),
inet_ntop (af,
- source_ip,
+ destination_ip,
dbuf, sizeof (dbuf)),
- (unsigned int) ntohs (tcp->dpt));
+ (unsigned int) ntohs (tcp->destination_port));
}
if (pktlen < sizeof (struct GNUNET_TUN_TcpHeader))
{
}
state = get_redirect_state (af, IPPROTO_TCP,
source_ip,
- ntohs (tcp->spt),
+ ntohs (tcp->source_port),
destination_ip,
- ntohs (tcp->dpt),
+ ntohs (tcp->destination_port),
NULL);
if (NULL == state)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Packet dropped, have no matching connection information\n"));
+ _("TCP Packet dropped, have no matching connection information\n"));
return;
}
sender will need to lookup the correct values anyway */
memcpy (buf, tcp, pktlen);
mtcp = (struct GNUNET_TUN_TcpHeader *) buf;
- mtcp->spt = 0;
- mtcp->dpt = 0;
+ mtcp->source_port = 0;
+ mtcp->destination_port = 0;
mtcp->crc = 0;
mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + (pktlen - sizeof (struct GNUNET_TUN_TcpHeader));
const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun;
size_t size;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got %u-byte message of type %u from gnunet-helper-exit\n",
+ ntohs (message->size),
+ ntohs (message->type));
GNUNET_STATISTICS_update (stats,
gettext_noop ("# Packets received from TUN"),
1, GNUNET_NO);
AF_INET,
&pkt4->destination_address,
&pkt4->source_address);
+ break;
case IPPROTO_TCP:
tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt4[1], size,
AF_INET,
&pkt4->destination_address,
&pkt4->source_address);
break;
+ case IPPROTO_ICMP:
+ icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt4[1], size,
+ AF_INET,
+ &pkt4->destination_address,
+ &pkt4->source_address);
+ break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv4 packet with unsupported next header received. Ignored.\n"));
+ _("IPv4 packet with unsupported next header %u received. Ignored.\n"),
+ (int) pkt4->protocol);
return;
}
}
return;
}
pkt6 = (struct GNUNET_TUN_IPv6Header *) &pkt_tun[1];
- if (size != ntohs (pkt6->payload_length))
+ if (size != ntohs (pkt6->payload_length) + sizeof (struct GNUNET_TUN_IPv6Header))
{
/* Kernel to blame? */
GNUNET_break (0);
&pkt6->destination_address,
&pkt6->source_address);
break;
+ case IPPROTO_ICMPV6:
+ icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt6[1], size,
+ AF_INET6,
+ &pkt6->destination_address,
+ &pkt6->source_address);
+ break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 packet with unsupported next header received. Ignored.\n"));
+ _("IPv6 packet with unsupported next header %d received. Ignored.\n"),
+ pkt6->next_header);
return;
}
}
local_address->proto = (uint8_t) proto;
/* default "local" port range is often 32768--61000,
so we pick a random value in that range */
- local_address->port
- = (uint16_t) 32768 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 28232);
+ if ( ( (af == AF_INET) && (proto == IPPROTO_ICMP) ) ||
+ ( (af == AF_INET6) && (proto == IPPROTO_ICMPV6) ) )
+ local_address->port = 0;
+ else
+ local_address->port
+ = (uint16_t) 32768 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ 28232);
switch (af)
{
case AF_INET:
/* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF,
thus: */
mask = addr;
- for (i=127;i>=128-ipv6prefix;i--)
+ for (i=127;i>=ipv6prefix;i--)
mask.s6_addr[i / 8] |= (1 << (i % 8));
/* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */
inet_ntop (state->ri.local_address.af,
&state->ri.local_address.address,
buf, sizeof (buf)),
- (unsigned int) state->ri.local_address.port);
+ (unsigned int) state->ri.local_address.port);
}
state->state_key = key;
GNUNET_assert (GNUNET_OK ==
* TCP header, depending on protocol)
* @param payload_length number of bytes in 'payload'
* @param protocol IPPROTO_UDP or IPPROTO_TCP
+ * @param tcp_header skeleton of the TCP header, NULL for UDP
* @param src_address source address to use (IP and port)
* @param dst_address destination address to use (IP and port)
- * @param pkt6 where to write the assembled packet; must
+ * @param pkt4 where to write the assembled packet; must
* contain enough space for the IP header, UDP/TCP header
* AND the payload
*/
{
struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct GNUNET_TUN_UdpHeader *) &pkt4[1];
- pkt4_udp->spt = htons (src_address->port);
- pkt4_udp->dpt = htons (dst_address->port);
+ pkt4_udp->source_port = htons (src_address->port);
+ pkt4_udp->destination_port = htons (dst_address->port);
pkt4_udp->len = htons ((uint16_t) payload_length);
GNUNET_TUN_calculate_udp4_checksum (pkt4,
pkt4_udp,
{
struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt4[1];
- memcpy (pkt4_tcp, tcp_header, sizeof (struct GNUNET_TUN_TcpHeader));
- pkt4_tcp->spt = htons (src_address->port);
- pkt4_tcp->dpt = htons (dst_address->port);
+ *pkt4_tcp = *tcp_header;
+ pkt4_tcp->source_port = htons (src_address->port);
+ pkt4_tcp->destination_port = htons (dst_address->port);
GNUNET_TUN_calculate_tcp4_checksum (pkt4,
pkt4_tcp,
payload,
* TCP header, depending on protocol)
* @param payload_length number of bytes in 'payload'
* @param protocol IPPROTO_UDP or IPPROTO_TCP
+ * @param tcp_header skeleton TCP header data to send, NULL for UDP
* @param src_address source address to use (IP and port)
* @param dst_address destination address to use (IP and port)
* @param pkt6 where to write the assembled packet; must
len += sizeof (struct GNUNET_TUN_UdpHeader);
break;
case IPPROTO_TCP:
- /* tcp_header (with port/crc not set) must be part of payload! */
- if (len < sizeof (struct GNUNET_TUN_TcpHeader))
- {
- GNUNET_break (0);
- return;
- }
+ len += sizeof (struct GNUNET_TUN_TcpHeader);
break;
default:
GNUNET_break (0);
GNUNET_TUN_initialize_ipv6_header (pkt6,
protocol,
- len,
- &dst_address->address.ipv6,
- &src_address->address.ipv6);
+ len,
+ &src_address->address.ipv6,
+ &dst_address->address.ipv6);
switch (protocol)
{
{
struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct GNUNET_TUN_UdpHeader *) &pkt6[1];
- pkt6_udp->spt = htons (src_address->port);
- pkt6_udp->dpt = htons (dst_address->port);
+ pkt6_udp->source_port = htons (src_address->port);
+ pkt6_udp->destination_port = htons (dst_address->port);
pkt6_udp->len = htons ((uint16_t) payload_length);
- pkt6_udp->crc = 0;
GNUNET_TUN_calculate_udp6_checksum (pkt6,
pkt6_udp,
payload,
payload_length);
- memcpy (&pkt6[1], payload, payload_length);
+ memcpy (&pkt6_udp[1], payload, payload_length);
}
break;
case IPPROTO_TCP:
{
- struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *) pkt6;
+ struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt6[1];
/* memcpy first here as some TCP header fields are initialized this way! */
- memcpy (pkt6_tcp, payload, payload_length);
- pkt6_tcp->spt = htons (src_address->port);
- pkt6_tcp->dpt = htons (dst_address->port);
+ *pkt6_tcp = *tcp_header;
+ pkt6_tcp->source_port = htons (src_address->port);
+ pkt6_tcp->destination_port = htons (dst_address->port);
GNUNET_TUN_calculate_tcp6_checksum (pkt6,
pkt6_tcp,
payload,
payload_length);
+ memcpy (&pkt6_tcp[1], payload, payload_length);
}
break;
default:
*
* @param destination_address IP and port to use for the TCP packet's destination
* @param source_address IP and port to use for the TCP packet's source
- * @param tcp header template to use
+ * @param tcp_header header template to use
* @param payload payload of the TCP packet
* @param payload_length number of bytes in 'payload'
*/
return;
}
{
- char buf[len];
+ char buf[len] GNUNET_ALIGN;
struct GNUNET_MessageHeader *hdr;
struct GNUNET_TUN_Layer2PacketHeader *tun;
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
-receive_tcp_service (void *unused GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
+receive_tcp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
void **tunnel_ctx GNUNET_UNUSED,
const struct GNUNET_PeerIdentity *sender GNUNET_UNUSED,
const struct GNUNET_MessageHeader *message,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ if (start->tcp_header.off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_break_op (ntohl (start->reserved) == 0);
/* setup fresh connection */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received data from %s for forwarding to TCP service %s on port %u\n",
GNUNET_i2s (sender),
GNUNET_h2s (&start->service_descriptor),
- (unsigned int) ntohs (start->tcp_header.dpt));
+ (unsigned int) ntohs (start->tcp_header.destination_port));
if (NULL == (state->serv = find_service (tcp_services, &start->service_descriptor,
- ntohs (start->tcp_header.dpt))))
+ ntohs (start->tcp_header.destination_port))))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("No service found for %s on port %d!\n"),
"TCP",
- ntohs (start->tcp_header.dpt));
+ ntohs (start->tcp_header.destination_port));
GNUNET_STATISTICS_update (stats,
gettext_noop ("# TCP requests dropped (no such service)"),
1, GNUNET_NO);
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ if (start->tcp_header.off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
af = (int) ntohl (start->af);
state->ri.remote_address.af = af;
switch (af)
}
v6 = (const struct in6_addr*) &start[1];
payload = &v6[1];
- pkt_len -= sizeof (struct in_addr);
+ pkt_len -= sizeof (struct in6_addr);
state->ri.remote_address.address.ipv6 = *v6;
break;
default:
inet_ntop (af,
&state->ri.remote_address.address,
buf, sizeof (buf)),
- (unsigned int) ntohs (start->tcp_header.dpt));
+ (unsigned int) ntohs (start->tcp_header.destination_port));
}
-
state->ri.remote_address.proto = IPPROTO_TCP;
- state->ri.remote_address.port = ntohs (start->tcp_header.dpt);
+ state->ri.remote_address.port = ntohs (start->tcp_header.destination_port);
setup_state_record (state);
send_tcp_packet_via_tun (&state->ri.remote_address,
&state->ri.local_address,
1, GNUNET_NO);
return GNUNET_SYSERR;
}
+ if (data->tcp_header.off * 4 < sizeof (struct GNUNET_TUN_TcpHeader))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
GNUNET_break_op (ntohl (data->reserved) == 0);
{
char buf[INET6_ADDRSTRLEN];
}
+/**
+ * Send an ICMP packet via the TUN interface.
+ *
+ * @param destination_address IP to use for the ICMP packet's destination
+ * @param source_address IP to use for the ICMP packet's source
+ * @param icmp_header ICMP header to send
+ * @param payload payload of the ICMP packet (does NOT include ICMP header)
+ * @param payload_length number of bytes of data in payload
+ */
+static void
+send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
+ const struct SocketAddress *source_address,
+ const struct GNUNET_TUN_IcmpHeader *icmp_header,
+ const void *payload, size_t payload_length)
+{
+ size_t len;
+ struct GNUNET_TUN_IcmpHeader *icmp;
+
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMP packets sent via TUN"),
+ 1, GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending packet with %u bytes ICMP payload via TUN\n",
+ (unsigned int) payload_length);
+ len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader);
+ switch (destination_address->af)
+ {
+ case AF_INET:
+ len += sizeof (struct GNUNET_TUN_IPv4Header);
+ break;
+ case AF_INET6:
+ len += sizeof (struct GNUNET_TUN_IPv6Header);
+ break;
+ default:
+ GNUNET_break (0);
+ return;
+ }
+ len += sizeof (struct GNUNET_TUN_IcmpHeader);
+ len += payload_length;
+ if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ {
+ char buf[len] GNUNET_ALIGN;
+ struct GNUNET_MessageHeader *hdr;
+ struct GNUNET_TUN_Layer2PacketHeader *tun;
+
+ hdr= (struct GNUNET_MessageHeader *) buf;
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
+ hdr->size = htons (len);
+ tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1];
+ tun->flags = htons (0);
+ switch (source_address->af)
+ {
+ case AF_INET:
+ {
+ struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
+
+ tun->proto = htons (ETH_P_IPV4);
+ GNUNET_TUN_initialize_ipv4_header (ipv4,
+ IPPROTO_ICMP,
+ sizeof (struct GNUNET_TUN_IcmpHeader) + payload_length,
+ &source_address->address.ipv4,
+ &destination_address->address.ipv4);
+ icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv4[1];
+ }
+ break;
+ case AF_INET6:
+ {
+ struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
+
+ tun->proto = htons (ETH_P_IPV6);
+ GNUNET_TUN_initialize_ipv6_header (ipv6,
+ IPPROTO_ICMPV6,
+ sizeof (struct GNUNET_TUN_IcmpHeader) + payload_length,
+ &source_address->address.ipv6,
+ &destination_address->address.ipv6);
+ icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv6[1];
+ }
+ break;
+ default:
+ GNUNET_assert (0);
+ break;
+ }
+ *icmp = *icmp_header;
+ memcpy (&icmp[1],
+ payload,
+ payload_length);
+ GNUNET_TUN_calculate_icmp_checksum (icmp,
+ payload,
+ payload_length);
+ (void) GNUNET_HELPER_send (helper_handle,
+ (const struct GNUNET_MessageHeader*) buf,
+ GNUNET_YES,
+ NULL, NULL);
+ }
+}
+
+
+/**
+ * Synthesize a plausible ICMP payload for an ICMPv4 error
+ * response on the given tunnel.
+ *
+ * @param state tunnel information
+ * @param ipp IPv6 header to fill in (ICMP payload)
+ * @param udp "UDP" header to fill in (ICMP payload); might actually
+ * also be the first 8 bytes of the TCP header
+ */
+static void
+make_up_icmpv4_payload (struct TunnelState *state,
+ struct GNUNET_TUN_IPv4Header *ipp,
+ struct GNUNET_TUN_UdpHeader *udp)
+{
+ GNUNET_TUN_initialize_ipv4_header (ipp,
+ state->ri.remote_address.proto,
+ sizeof (struct GNUNET_TUN_TcpHeader),
+ &state->ri.remote_address.address.ipv4,
+ &state->ri.local_address.address.ipv4);
+ udp->source_port = htons (state->ri.remote_address.port);
+ udp->destination_port = htons (state->ri.local_address.port);
+ udp->len = htons (0);
+ udp->crc = htons (0);
+}
+
+
+/**
+ * Synthesize a plausible ICMP payload for an ICMPv6 error
+ * response on the given tunnel.
+ *
+ * @param state tunnel information
+ * @param ipp IPv6 header to fill in (ICMP payload)
+ * @param udp "UDP" header to fill in (ICMP payload); might actually
+ * also be the first 8 bytes of the TCP header
+ */
+static void
+make_up_icmpv6_payload (struct TunnelState *state,
+ struct GNUNET_TUN_IPv6Header *ipp,
+ struct GNUNET_TUN_UdpHeader *udp)
+{
+ GNUNET_TUN_initialize_ipv6_header (ipp,
+ state->ri.remote_address.proto,
+ sizeof (struct GNUNET_TUN_TcpHeader),
+ &state->ri.remote_address.address.ipv6,
+ &state->ri.local_address.address.ipv6);
+ udp->source_port = htons (state->ri.remote_address.port);
+ udp->destination_port = htons (state->ri.local_address.port);
+ udp->len = htons (0);
+ udp->crc = htons (0);
+}
+
+
+/**
+ * Process a request to forward ICMP data to the Internet via this peer.
+ *
+ * @param cls closure, NULL
+ * @param tunnel connection to the other end
+ * @param tunnel_ctx pointer to our 'struct TunnelState *'
+ * @param sender who sent the message
+ * @param message the actual message
+ * @param atsi performance data for the connection
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+static int
+receive_icmp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx GNUNET_UNUSED,
+ const struct GNUNET_PeerIdentity *sender GNUNET_UNUSED,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
+{
+ struct TunnelState *state = *tunnel_ctx;
+ const struct GNUNET_EXIT_IcmpInternetMessage *msg;
+ uint16_t pkt_len = ntohs (message->size);
+ const struct in_addr *v4;
+ const struct in6_addr *v6;
+ const void *payload;
+ char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
+ int af;
+
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# Bytes received from MESH"),
+ pkt_len, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMP IP-exit requests received via mesh"),
+ 1, GNUNET_NO);
+ if (pkt_len < sizeof (struct GNUNET_EXIT_IcmpInternetMessage))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ msg = (const struct GNUNET_EXIT_IcmpInternetMessage*) message;
+ pkt_len -= sizeof (struct GNUNET_EXIT_IcmpInternetMessage);
+
+ af = (int) ntohl (msg->af);
+ if ( (NULL != state->heap_node) &&
+ (af != state->ri.remote_address.af) )
+ {
+ /* other peer switched AF on this tunnel; not allowed */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ switch (af)
+ {
+ case AF_INET:
+ if (pkt_len < sizeof (struct in_addr))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (! ipv4_exit)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ v4 = (const struct in_addr*) &msg[1];
+ payload = &v4[1];
+ pkt_len -= sizeof (struct in_addr);
+ state->ri.remote_address.address.ipv4 = *v4;
+ if (NULL == state->heap_node)
+ {
+ state->ri.remote_address.af = af;
+ state->ri.remote_address.proto = IPPROTO_ICMP;
+ setup_state_record (state);
+ }
+ /* check that ICMP type is something we want to support
+ and possibly make up payload! */
+ switch (msg->icmp_header.type)
+ {
+ case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
+ case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
+ break;
+ case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
+ case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
+ case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ /* make up payload */
+ {
+ struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) buf;
+ struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1];
+
+ GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
+ pkt_len = sizeof (struct GNUNET_TUN_IPv4Header) + 8;
+ make_up_icmpv4_payload (state,
+ ipp,
+ udp);
+ payload = ipp;
+ }
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
+ 1, GNUNET_NO);
+ return GNUNET_SYSERR;
+ }
+ /* end AF_INET */
+ break;
+ case AF_INET6:
+ if (pkt_len < sizeof (struct in6_addr))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (! ipv6_exit)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ v6 = (const struct in6_addr*) &msg[1];
+ payload = &v6[1];
+ pkt_len -= sizeof (struct in6_addr);
+ state->ri.remote_address.address.ipv6 = *v6;
+ if (NULL == state->heap_node)
+ {
+ state->ri.remote_address.af = af;
+ state->ri.remote_address.proto = IPPROTO_ICMPV6;
+ setup_state_record (state);
+ }
+ /* check that ICMP type is something we want to support
+ and possibly make up payload! */
+ switch (msg->icmp_header.type)
+ {
+ case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
+ case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
+ break;
+ case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
+ case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
+ case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
+ case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ /* make up payload */
+ {
+ struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) buf;
+ struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1];
+
+ GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
+ pkt_len = sizeof (struct GNUNET_TUN_IPv6Header) + 8;
+ make_up_icmpv6_payload (state,
+ ipp,
+ udp);
+ payload = ipp;
+ }
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
+ 1, GNUNET_NO);
+ return GNUNET_SYSERR;
+ }
+ /* end AF_INET6 */
+ break;
+ default:
+ /* bad AF */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ {
+ char buf[INET6_ADDRSTRLEN];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received ICMP data from %s for forwarding to %s\n",
+ GNUNET_i2s (sender),
+ inet_ntop (af,
+ &state->ri.remote_address.address,
+ buf, sizeof (buf)));
+ }
+ send_icmp_packet_via_tun (&state->ri.remote_address,
+ &state->ri.local_address,
+ &msg->icmp_header,
+ payload, pkt_len);
+ return GNUNET_YES;
+}
+
+
+/**
+ * Setup ICMP payload for ICMP error messages. Called
+ * for both IPv4 and IPv6 addresses.
+ *
+ * @param state context for creating the IP Packet
+ * @param buf where to create the payload, has at least
+ * sizeof (struct GNUNET_TUN_IPv6Header) + 8 bytes
+ * @return number of bytes of payload we created in buf
+ */
+static uint16_t
+make_up_icmp_service_payload (struct TunnelState *state,
+ char *buf)
+{
+ switch (state->serv->address.af)
+ {
+ case AF_INET:
+ {
+ struct GNUNET_TUN_IPv4Header *ipv4;
+ struct GNUNET_TUN_UdpHeader *udp;
+
+ ipv4 = (struct GNUNET_TUN_IPv4Header *)buf;
+ udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1];
+ make_up_icmpv4_payload (state,
+ ipv4,
+ udp);
+ GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
+ return sizeof (struct GNUNET_TUN_IPv4Header) + 8;
+ }
+ break;
+ case AF_INET6:
+ {
+ struct GNUNET_TUN_IPv6Header *ipv6;
+ struct GNUNET_TUN_UdpHeader *udp;
+
+ ipv6 = (struct GNUNET_TUN_IPv6Header *)buf;
+ udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1];
+ make_up_icmpv6_payload (state,
+ ipv6,
+ udp);
+ GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
+ return sizeof (struct GNUNET_TUN_IPv6Header) + 8;
+ }
+ break;
+ default:
+ GNUNET_break (0);
+ }
+ return 0;
+}
+
+
+/**
+ * Process a request via mesh to send ICMP data to a service
+ * offered by this system.
+ *
+ * @param cls closure, NULL
+ * @param tunnel connection to the other end
+ * @param tunnel_ctx pointer to our 'struct TunnelState *'
+ * @param sender who sent the message
+ * @param message the actual message
+ * @param atsi performance data for the connection
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+static int
+receive_icmp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
+ void **tunnel_ctx,
+ const struct GNUNET_PeerIdentity *sender GNUNET_UNUSED,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
+{
+ struct TunnelState *state = *tunnel_ctx;
+ const struct GNUNET_EXIT_IcmpServiceMessage *msg;
+ uint16_t pkt_len = ntohs (message->size);
+ struct GNUNET_TUN_IcmpHeader icmp;
+ char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
+ const void *payload;
+
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# Bytes received from MESH"),
+ pkt_len, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMP service requests received via mesh"),
+ 1, GNUNET_NO);
+ /* check that we got at least a valid header */
+ if (pkt_len < sizeof (struct GNUNET_EXIT_IcmpServiceMessage))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ msg = (const struct GNUNET_EXIT_IcmpServiceMessage*) message;
+ pkt_len -= sizeof (struct GNUNET_EXIT_IcmpServiceMessage);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received data from %s for forwarding to ICMP service %s\n",
+ GNUNET_i2s (sender),
+ GNUNET_h2s (&msg->service_descriptor));
+ if (NULL == state->serv)
+ {
+ /* first packet to service must not be ICMP (cannot determine service!) */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ icmp = msg->icmp_header;
+ payload = &msg[1];
+ state->ri.remote_address = state->serv->address;
+ setup_state_record (state);
+
+ /* check that ICMP type is something we want to support,
+ perform ICMP PT if needed ans possibly make up payload */
+ switch (msg->af)
+ {
+ case AF_INET:
+ switch (msg->icmp_header.type)
+ {
+ case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
+ if (state->serv->address.af == AF_INET6)
+ icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY;
+ break;
+ case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST:
+ if (state->serv->address.af == AF_INET6)
+ icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST;
+ break;
+ case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE:
+ if (state->serv->address.af == AF_INET6)
+ icmp.type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE;
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ payload = buf;
+ pkt_len = make_up_icmp_service_payload (state, buf);
+ break;
+ case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED:
+ if (state->serv->address.af == AF_INET6)
+ icmp.type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED;
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ payload = buf;
+ pkt_len = make_up_icmp_service_payload (state, buf);
+ break;
+ case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH:
+ if (state->serv->address.af == AF_INET6)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"),
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ payload = buf;
+ pkt_len = make_up_icmp_service_payload (state, buf);
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv4 packets dropped (type not allowed)"),
+ 1, GNUNET_NO);
+ return GNUNET_SYSERR;
+ }
+ /* end of AF_INET */
+ break;
+ case AF_INET6:
+ switch (msg->icmp_header.type)
+ {
+ case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY:
+ if (state->serv->address.af == AF_INET)
+ icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY;
+ break;
+ case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST:
+ if (state->serv->address.af == AF_INET)
+ icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST;
+ break;
+ case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
+ if (state->serv->address.af == AF_INET)
+ icmp.type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE;
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ payload = buf;
+ pkt_len = make_up_icmp_service_payload (state, buf);
+ break;
+ case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED:
+ if (state->serv->address.af == AF_INET)
+ icmp.type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED;
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ payload = buf;
+ pkt_len = make_up_icmp_service_payload (state, buf);
+ break;
+ case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG:
+ case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM:
+ if (state->serv->address.af == AF_INET)
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"),
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
+ if (0 != pkt_len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ payload = buf;
+ pkt_len = make_up_icmp_service_payload (state, buf);
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# ICMPv6 packets dropped (type not allowed)"),
+ 1, GNUNET_NO);
+ return GNUNET_SYSERR;
+ }
+ /* end of AF_INET6 */
+ break;
+ default:
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ send_icmp_packet_via_tun (&state->ri.remote_address,
+ &state->ri.local_address,
+ &icmp,
+ payload, pkt_len);
+ return GNUNET_YES;
+}
+
+
/**
* Send a UDP packet via the TUN interface.
*
return;
}
{
- char buf[len];
+ char buf[len] GNUNET_ALIGN;
struct GNUNET_MessageHeader *hdr;
struct GNUNET_TUN_Layer2PacketHeader *tun;
}
v6 = (const struct in6_addr*) &msg[1];
payload = &v6[1];
- pkt_len -= sizeof (struct in_addr);
+ pkt_len -= sizeof (struct in6_addr);
state->ri.remote_address.address.ipv6 = *v6;
break;
default:
static void *
new_tunnel (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
const struct GNUNET_PeerIdentity *initiator GNUNET_UNUSED,
- const struct GNUNET_ATS_Information *ats GNUNET_UNUSED)
+ const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
{
struct TunnelState *s = GNUNET_malloc (sizeof (struct TunnelState));
}
if (stats != NULL)
{
- GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
stats = NULL;
}
- for (i=0;i<5;i++)
+ for (i=0;i<8;i++)
GNUNET_free_non_null (exit_argv[i]);
}
}
+/**
+ * Test if the given AF is supported by this system.
+ *
+ * @param af to test
+ * @return GNUNET_OK if the AF is supported
+ */
+static int
+test_af (int af)
+{
+ int s;
+
+ s = socket (af, SOCK_STREAM, 0);
+ if (-1 == s)
+ {
+ if (EAFNOSUPPORT == errno)
+ return GNUNET_NO;
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "socket");
+ return GNUNET_SYSERR;
+ }
+ close (s);
+ return GNUNET_OK;
+}
+
+
/**
* @brief Main function that will be run by the scheduler.
*
const struct GNUNET_CONFIGURATION_Handle *cfg_)
{
static struct GNUNET_MESH_MessageHandler handlers[] = {
+ {&receive_icmp_service, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, 0},
+ {&receive_icmp_remote, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, 0},
{&receive_udp_service, GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, 0},
{&receive_udp_remote, GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET, 0},
{&receive_tcp_service, GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START, 0},
char *ipv4addr;
char *ipv4mask;
+ if (GNUNET_YES !=
+ GNUNET_OS_check_helper_binary ("gnunet-helper-exit"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("`%s' must be installed SUID, refusing to run\n"),
+ "gnunet-helper-exit");
+ global_ret = 1;
+ return;
+ }
cfg = cfg_;
stats = GNUNET_STATISTICS_create ("exit", cfg);
ipv4_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "EXIT_IPV4");
ipv6_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "EXIT_IPV6");
ipv4_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV4");
ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV6");
+
+ if ( (ipv4_exit || ipv4_enabled) &&
+ GNUNET_OK != test_af (AF_INET))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n"));
+ ipv4_exit = GNUNET_NO;
+ ipv4_enabled = GNUNET_NO;
+ }
+ if ( (ipv6_exit || ipv6_enabled) &&
+ GNUNET_OK != test_af (AF_INET6))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n"));
+ ipv6_exit = GNUNET_NO;
+ ipv6_enabled = GNUNET_NO;
+ }
if (ipv4_exit && (! ipv4_enabled))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
{
exit_argv[2] = GNUNET_strdup ("%");
}
+
+
if (GNUNET_YES == ipv6_enabled)
{
if ( (GNUNET_SYSERR ==
GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit",
gettext_noop
("Daemon to run to provide an IP exit node for the VPN"),
- options, &run, NULL)) ? 0 : 1;
+ options, &run, NULL)) ? global_ret : 1;
}