spt = dst->sin6_port;
dpt = src->sin6_port;
- ip.traffic_class_h = 0;
- ip.version = 6; /* is there a named constant? I couldn't find one */
- ip.traffic_class_l = 0;
- ip.flow_label = 0;
- ip.payload_length = htons ((uint16_t) reply_len);
- ip.next_header = IPPROTO_UDP;
- ip.hop_limit = 255; /* or lower? */
- ip.source_address = dst->sin6_addr;
- ip.destination_address = src->sin6_addr;
- udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum,
- &ip.source_address,
- sizeof (struct in6_addr) * 2);
+ GNUNET_TUN_initialize_ipv6_header (&ip,
+ IPPROTO_UDP,
+ reply_len - sizeof (struct GNUNET_TUN_IPv6Header),
+ &dst->sin6_addr,
+ &src->sin6_addr);
{
uint32_t tmp;
return;
}
- pkt6->version = 6;
- pkt6->next_header = protocol;
- pkt6->payload_length = htons ((uint16_t) (len + sizeof (struct GNUNET_TUN_IPv6Header)));
- pkt6->hop_limit = 255;
- pkt6->destination_address = dst_address->address.ipv6;
- pkt6->source_address = src_address->address.ipv6;
+ GNUNET_TUN_initialize_ipv6_header (pkt6,
+ protocol,
+ len,
+ &dst_address->address.ipv6,
+ &src_address->address.ipv6);
switch (protocol)
{
const struct in_addr *dst);
+/**
+ * Initialize an IPv6 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_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in6_addr *src,
+ const struct in6_addr *dst);
+
+
#endif
const struct in_addr *src,
const struct in_addr *dst)
{
+ GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
ip->version = 4;
ip->diff_serv = 0;
}
+/**
+ * Initialize an IPv6 header.
+ *
+ * @param ip header to initialize
+ * @param protocol protocol to use (i.e. IPPROTO_UDP), technically "next_header" for IPv6
+ * @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_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in6_addr *src,
+ const struct in6_addr *dst)
+{
+ GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
+ ip->traffic_class_h = 0;
+ ip->version = 6;
+ ip->traffic_class_l = 0;
+ ip->flow_label = 0;
+ ip->next_header = protocol;
+ ip->payload_length = htons ((uint16_t) (payload_length + sizeof (struct GNUNET_TUN_IPv6Header)));
+ ip->hop_limit = FRESH_TTL;
+ ip->destination_address = *dst;
+ ip->source_address = *src;
+}
+
+
/* end of tun.c */
msg->size = htons (size);
tun->flags = htons (0);
tun->proto = htons (ETH_P_IPV6);
- ipv6->traffic_class_h = 0;
- ipv6->version = 6;
- ipv6->traffic_class_l = 0;
- ipv6->flow_label = 0;
- ipv6->payload_length = htons (sizeof (struct GNUNET_TUN_TcpHeader) + sizeof (struct GNUNET_TUN_IPv6Header) + mlen);
- ipv6->next_header = IPPROTO_TCP;
- ipv6->hop_limit = 255;
- ipv6->source_address = ts->destination_ip.v6;
- ipv6->destination_address = ts->source_ip.v6;
+ GNUNET_TUN_initialize_ipv6_header (ipv6,
+ IPPROTO_TCP,
+ sizeof (struct GNUNET_TUN_TcpHeader) + mlen,
+ &ts->destination_ip.v6,
+ &ts->source_ip.v6);
tcp->spt = htons (ts->destination_port);
tcp->dpt = htons (ts->source_port);
tcp->crc = 0;