+#ifdef HAVE_NETINET_IP6_H
+
+/* RFC 2463 */
+
+void route_ipv6_unreachable(vpn_packet_t *packet, uint8_t code)
+{
+ struct ip6_hdr *hdr;
+ struct icmp6_hdr *icmp;
+ uint16_t checksum;
+
+ struct {
+ struct in6_addr ip6_src; /* source address */
+ struct in6_addr ip6_dst; /* destination address */
+ uint32_t length;
+ uint32_t next;
+ } pseudo;
+
+ if(ratelimit())
+ return;
+
+ cp();
+
+ hdr = (struct ip6_hdr *)(packet->data + 14);
+ icmp = (struct icmp6_hdr *)(packet->data + 14 + sizeof(*hdr));
+
+ /* Remember original source and destination */
+
+ memcpy(&pseudo.ip6_src, &hdr->ip6_dst, 16);
+ memcpy(&pseudo.ip6_dst, &hdr->ip6_src, 16);
+ pseudo.length = ntohs(hdr->ip6_plen) + sizeof(*hdr);
+
+ if(pseudo.length >= IP_MSS - sizeof(*hdr) - sizeof(*icmp))
+ pseudo.length = IP_MSS - sizeof(*hdr) - sizeof(*icmp);
+
+ /* Copy first part of original contents to ICMP message */
+
+ memmove(((char *)icmp) + sizeof(*icmp), hdr, pseudo.length);
+
+ /* Fill in IPv6 header */
+
+ hdr->ip6_flow = htonl(0x60000000UL);
+ hdr->ip6_plen = htons(sizeof(*icmp) + pseudo.length);
+ hdr->ip6_nxt = IPPROTO_ICMPV6;
+ hdr->ip6_hlim = 255;
+ memcpy(&hdr->ip6_dst, &pseudo.ip6_dst, 16);
+ memcpy(&hdr->ip6_src, &pseudo.ip6_src, 16);
+
+ /* Fill in ICMP header */
+
+ icmp->icmp6_type = ICMP6_DST_UNREACH;
+ icmp->icmp6_code = code;
+ icmp->icmp6_cksum = 0;
+
+ /* Create pseudo header */
+
+ pseudo.length = htonl(sizeof(*icmp) + pseudo.length);
+ pseudo.next = htonl(IPPROTO_ICMPV6);
+
+ /* Generate checksum */
+
+ checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
+ checksum = inet_checksum(icmp, ntohl(pseudo.length), checksum);
+
+ icmp->icmp6_cksum = checksum;
+
+ packet->len = 14 + sizeof(*hdr) + ntohl(pseudo.length);
+
+ write_packet(packet);
+}
+
+#endif
+
+node_t *route_ipv6(vpn_packet_t *packet)