-
- cp();
-
- /* Copy headers from packet to structs on the stack */
-
- memcpy(&ip6, packet->data + ether_size, ip6_size);
- memcpy(&icmp6, packet->data + ether_size + ip6_size, icmp6_size);
-
- /* Remember original source and destination */
-
- memcpy(&pseudo.ip6_src, &ip6.ip6_dst, sizeof(ip6.ip6_src));
- memcpy(&pseudo.ip6_dst, &ip6.ip6_src, sizeof(ip6.ip6_dst));
-
- pseudo.length = ntohs(ip6.ip6_plen) + ip6_size;
-
- if(pseudo.length >= IP_MSS - ip6_size - icmp6_size)
- pseudo.length = IP_MSS - ip6_size - icmp6_size;
-
- /* Copy first part of original contents to ICMP message */
-
- memmove(packet->data + ether_size + ip6_size + icmp6_size, packet->data + ether_size, pseudo.length);
-
- /* Fill in IPv6 header */
-
- ip6.ip6_flow = htonl(0x60000000UL);
- ip6.ip6_plen = htons(icmp6_size + pseudo.length);
- ip6.ip6_nxt = IPPROTO_ICMPV6;
- ip6.ip6_hlim = 255;
- memcpy(&ip6.ip6_src, &pseudo.ip6_src, sizeof(ip6.ip6_src));
- memcpy(&ip6.ip6_dst, &pseudo.ip6_dst, sizeof(ip6.ip6_dst));
-
- /* Fill in ICMP header */
-
- icmp6.icmp6_type = ICMP6_DST_UNREACH;
- icmp6.icmp6_code = code;
- icmp6.icmp6_cksum = 0;
-
- /* Create pseudo header */
-
- pseudo.length = htonl(icmp6_size + pseudo.length);
- pseudo.next = htonl(IPPROTO_ICMPV6);
-
- /* Generate checksum */
-
- checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
- checksum = inet_checksum(&icmp6, icmp6_size, checksum);
- checksum = inet_checksum(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
-
- icmp6.icmp6_cksum = checksum;
-
- /* Copy structs on stack back to packet */
-
- memcpy(packet->data + ether_size, &ip6, ip6_size);
- memcpy(packet->data + ether_size + ip6_size, &icmp6, icmp6_size);
-
- packet->len = ether_size + ip6_size + ntohl(pseudo.length);
-
- write_packet(packet);
-}
-
-static node_t *route_ipv6(vpn_packet_t *packet)
-{
- subnet_t *subnet;
-
- cp();
-
- subnet = lookup_subnet_ipv6((ipv6_t *) &packet->data[38]);
-
- if(!subnet) {
- ifdebug(TRAFFIC) logger(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
- ntohs(*(uint16_t *) &packet->data[38]),
- ntohs(*(uint16_t *) &packet->data[40]),
- ntohs(*(uint16_t *) &packet->data[42]),
- ntohs(*(uint16_t *) &packet->data[44]),
- ntohs(*(uint16_t *) &packet->data[46]),
- ntohs(*(uint16_t *) &packet->data[48]),
- ntohs(*(uint16_t *) &packet->data[50]),
- ntohs(*(uint16_t *) &packet->data[52]));
- route_ipv6_unreachable(packet, ICMP6_DST_UNREACH_ADDR);
-
- return NULL;