include $(INTLEMU_SUBDIRS) \
util \
hello \
+ tun \
block \
statistics \
arm \
gnunet_service_dns_SOURCES = \
gnunet-service-dns.c
gnunet_service_dns_LDADD = \
+ $(top_builddir)/src/tun/libgnunettun.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
#include "gnunet_statistics_service.h"
#include "gnunet_tun_lib.h"
-#ifndef IPVERSION
-#define IPVERSION 4
-#endif
/**
* Phases each request goes through.
spt = dst->sin_port;
dpt = src->sin_port;
- ip.header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
- ip.version = IPVERSION; /* aka 4 */
- ip.diff_serv = 0;
- ip.total_length = htons ((uint16_t) reply_len - off);
- ip.identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 65536);
- ip.flags = 0;
- ip.fragmentation_offset = 0;
- ip.ttl = 255; /* or lower? */
- ip.protocol = IPPROTO_UDP;
- ip.checksum = 0; /* checksum is optional */
- ip.source_address = dst->sin_addr;
- ip.destination_address = src->sin_addr;
- ip.checksum = GNUNET_CRYPTO_crc16_n (&ip, sizeof (ip));
+ GNUNET_TUN_initialize_ipv4_header (&ip,
+ IPPROTO_UDP,
+ reply_len - off - sizeof (struct GNUNET_TUN_IPv4Header),
+ &dst->sin_addr,
+ &src->sin_addr);
+
+
udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
&ip.source_address,
case ETH_P_IPV4:
ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1];
if ( (msize < sizeof (struct GNUNET_TUN_IPv4Header)) ||
- (ip4->version != IPVERSION) ||
+ (ip4->version != 4) ||
(ip4->header_length != sizeof (struct GNUNET_TUN_IPv4Header) / 4) ||
(ntohs(ip4->total_length) != msize) ||
(ip4->protocol != IPPROTO_UDP) )
/* setup new request */
rr->phase = RP_INIT;
- if (ip4->version == IPVERSION)
+ if (ip4->version == 4)
{
srca4 = (struct sockaddr_in*) &rr->src_addr;
dsta4 = (struct sockaddr_in*) &rr->dst_addr;
gnunet_daemon_exit_LDADD = \
$(top_builddir)/src/core/libgnunetcore.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/tun/libgnunettun.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/mesh/libgnunetmesh.la \
$(GN_LIBINTL)
return;
}
- pkt4->version = 4;
- pkt4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
- pkt4->diff_serv = 0;
- pkt4->total_length = htons ((uint16_t) (sizeof (struct GNUNET_TUN_IPv4Header) + len));
- pkt4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT16_MAX + 1);
- pkt4->flags = 0;
- pkt4->fragmentation_offset = 0;
- pkt4->ttl = 255;
- pkt4->protocol = protocol;
- pkt4->checksum = 0;
- pkt4->destination_address = dst_address->address.ipv4;
- pkt4->source_address = src_address->address.ipv4;
- pkt4->checksum = GNUNET_CRYPTO_crc16_n (pkt4, sizeof (struct GNUNET_TUN_IPv4Header));
-
+ GNUNET_TUN_initialize_ipv4_header (pkt4,
+ protocol,
+ len,
+ &src_address->address.ipv4,
+ &dst_address->address.ipv4);
switch (protocol)
{
case IPPROTO_UDP:
GNUNET_NETWORK_STRUCT_END
+/**
+ * Initialize an IPv4 header.
+ *
+ * @param ip header to initialize
+ * @param protocol protocol to use (i.e. IPPROTO_UDP)
+ * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
+ * @param src source IP address to use
+ * @param dst destination IP address to use
+ */
+void
+GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in_addr *src,
+ const struct in_addr *dst);
+
+
#endif
gnunet-service-vpn.c
gnunet_service_vpn_LDADD = \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/tun/libgnunettun.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/mesh/libgnunetmesh.la \
$(GN_LIBINTL)
msg->size = htons (size);
tun->flags = htons (0);
tun->proto = htons (ETH_P_IPV4);
- ipv4->version = 4;
- ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
- ipv4->diff_serv = 0;
- ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) +
- sizeof (struct GNUNET_TUN_UdpHeader) +
- mlen);
- ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT16_MAX + 1);
- ipv4->flags = 0;
- ipv4->fragmentation_offset = 0;
- ipv4->ttl = 255;
- ipv4->protocol = IPPROTO_UDP;
- ipv4->checksum = 0;
- ipv4->source_address = ts->destination_ip.v4;
- ipv4->destination_address = ts->source_ip.v4;
- ipv4->checksum =
- GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header));
+ GNUNET_TUN_initialize_ipv4_header (ipv4,
+ IPPROTO_UDP,
+ sizeof (struct GNUNET_TUN_UdpHeader) + mlen,
+ &ts->destination_ip.v4,
+ &ts->source_ip.v4);
if (0 == ntohs (reply->source_port))
udp->spt = htons (ts->destination_port);
else
msg->size = htons (size);
tun->flags = htons (0);
tun->proto = htons (ETH_P_IPV4);
- ipv4->version = 4;
- ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
- ipv4->diff_serv = 0;
- ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) +
- sizeof (struct GNUNET_TUN_TcpHeader) +
- mlen);
- ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT16_MAX + 1);
- ipv4->flags = 0;
- ipv4->fragmentation_offset = 0;
- ipv4->ttl = 255;
- ipv4->protocol = IPPROTO_TCP;
- ipv4->checksum = 0;
- ipv4->source_address = ts->destination_ip.v4;
- ipv4->destination_address = ts->source_ip.v4;
- ipv4->checksum =
- GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header));
+ GNUNET_TUN_initialize_ipv4_header (ipv4,
+ IPPROTO_TCP,
+ sizeof (struct GNUNET_TUN_TcpHeader) + mlen,
+ &ts->destination_ip.v4,
+ &ts->source_ip.v4);
*tcp = data->tcp_header;
tcp->spt = htons (ts->destination_port);
tcp->dpt = htons (ts->source_port);