3 Copyright (C) 2000-2005 Ivo Timmermans,
4 2000-2009 Guus Sliepen <guus@tinc-vpn.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "connection.h"
35 rmode_t routing_mode = RMODE_ROUTER;
36 bool priorityinheritance = false;
38 bool overwrite_mac = false;
39 mac_t mymac = {{0xFE, 0xFD, 0, 0, 0, 0}};
41 /* Sizes of various headers */
43 static const size_t ether_size = sizeof(struct ether_header);
44 static const size_t arp_size = sizeof(struct ether_arp);
45 static const size_t ip_size = sizeof(struct ip);
46 static const size_t icmp_size = sizeof(struct icmp) - sizeof(struct ip);
47 static const size_t ip6_size = sizeof(struct ip6_hdr);
48 static const size_t icmp6_size = sizeof(struct icmp6_hdr);
49 static const size_t ns_size = sizeof(struct nd_neighbor_solicit);
50 static const size_t opt_size = sizeof(struct nd_opt_hdr);
51 #define max(a, b) ((a) > (b) ? (a) : (b))
55 static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) {
57 uint32_t checksum = prevsum ^ 0xFFFF;
65 checksum += *(uint8_t *)p;
68 checksum = (checksum & 0xFFFF) + (checksum >> 16);
73 static bool ratelimit(int frequency) {
74 static time_t lasttime = 0;
78 if(++count > frequency)
88 static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) {
89 if(packet->len < length) {
90 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got too short packet from %s (%s)", source->name, source->hostname);
96 static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *packet) {
97 if(!via || via == myself)
100 /* Find TCP header */
102 uint16_t type = packet->data[12] << 8 | packet->data[13];
104 if(type == ETH_P_IP && packet->data[23] == 6)
105 start = 14 + (packet->data[14] & 0xf) * 4;
106 else if(type == ETH_P_IPV6 && packet->data[20] == 6)
109 if(!start || packet->len <= start + 20)
112 /* Use data offset field to calculate length of options field */
113 int len = ((packet->data[start + 12] >> 4) - 5) * 4;
115 /* Search for MSS option header */
116 for(int i = 0; i < len;) {
117 if(packet->data[start + 20 + i] == 0)
120 if(packet->data[start + 20 + i] == 1) {
125 if(i > len - 2 || i > len - packet->data[start + 21 + i])
128 if(packet->data[start + 20 + i] != 2) {
129 if(packet->data[start + 21 + i] < 2)
131 i += packet->data[start + 21 + i];
135 if(packet->data[start + 21] != 4)
139 uint16_t oldmss = packet->data[start + 22 + i] << 8 | packet->data[start + 23 + i];
140 uint16_t newmss = via->mtu - start - 20;
141 uint16_t csum = packet->data[start + 16] << 8 | packet->data[start + 17];
146 ifdebug(TRAFFIC) logger(LOG_INFO, "Clamping MSS of packet from %s to %s to %d", source->name, via->name, newmss);
148 /* Update the MSS value and the checksum */
149 packet->data[start + 22 + i] = newmss >> 8;
150 packet->data[start + 23 + i] = newmss & 0xff;
155 packet->data[start + 16] = csum >> 8;
156 packet->data[start + 17] = csum & 0xff;
161 static void swap_mac_addresses(vpn_packet_t *packet) {
163 memcpy(&tmp, &packet->data[0], sizeof tmp);
164 memcpy(&packet->data[0], &packet->data[6], sizeof tmp);
165 memcpy(&packet->data[6], &tmp, sizeof tmp);
168 static void learn_mac(mac_t *address) {
173 subnet = lookup_subnet_mac(myself, address);
175 /* If we don't know this MAC address yet, store it */
178 ifdebug(TRAFFIC) logger(LOG_INFO, "Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx",
179 address->x[0], address->x[1], address->x[2], address->x[3],
180 address->x[4], address->x[5]);
182 subnet = new_subnet();
183 subnet->type = SUBNET_MAC;
184 subnet->expires = now + macexpire;
185 subnet->net.mac.address = *address;
187 subnet_add(myself, subnet);
189 /* And tell all other tinc daemons it's our MAC */
191 for(node = connection_tree->head; node; node = node->next) {
194 send_add_subnet(c, subnet);
199 subnet->expires = now + macexpire;
202 void age_subnets(void) {
205 avl_node_t *node, *next, *node2;
207 for(node = myself->subnet_tree->head; node; node = next) {
210 if(s->expires && s->expires < now) {
212 char netstr[MAXNETSTR];
213 if(net2str(netstr, sizeof netstr, s))
214 logger(LOG_INFO, "Subnet %s expired", netstr);
217 for(node2 = connection_tree->head; node2; node2 = node2->next) {
220 send_del_subnet(c, s);
223 subnet_del(myself, s);
230 static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
232 struct icmp icmp = {0};
234 struct in_addr ip_src;
235 struct in_addr ip_dst;
241 /* Swap Ethernet source and destination addresses */
243 swap_mac_addresses(packet);
245 /* Copy headers from packet into properly aligned structs on the stack */
247 memcpy(&ip, packet->data + ether_size, ip_size);
249 /* Remember original source and destination */
254 oldlen = packet->len - ether_size;
256 if(type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
257 icmp.icmp_nextmtu = htons(packet->len - ether_size);
259 if(oldlen >= IP_MSS - ip_size - icmp_size)
260 oldlen = IP_MSS - ip_size - icmp_size;
262 /* Copy first part of original contents to ICMP message */
264 memmove(packet->data + ether_size + ip_size + icmp_size, packet->data + ether_size, oldlen);
266 /* Fill in IPv4 header */
269 ip.ip_hl = ip_size / 4;
271 ip.ip_len = htons(ip_size + icmp_size + oldlen);
275 ip.ip_p = IPPROTO_ICMP;
280 ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
282 /* Fill in ICMP header */
284 icmp.icmp_type = type;
285 icmp.icmp_code = code;
288 icmp.icmp_cksum = inet_checksum(&icmp, icmp_size, ~0);
289 icmp.icmp_cksum = inet_checksum(packet->data + ether_size + ip_size + icmp_size, oldlen, icmp.icmp_cksum);
291 /* Copy structs on stack back to packet */
293 memcpy(packet->data + ether_size, &ip, ip_size);
294 memcpy(packet->data + ether_size + ip_size, &icmp, icmp_size);
296 packet->len = ether_size + ip_size + icmp_size + oldlen;
298 send_packet(source, packet);
303 static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
305 vpn_packet_t fragment;
306 int len, maxlen, todo;
308 uint16_t ip_off, origf;
310 memcpy(&ip, packet->data + ether_size, ip_size);
311 fragment.priority = packet->priority;
313 if(ip.ip_hl != ip_size / 4)
316 todo = ntohs(ip.ip_len) - ip_size;
318 if(ether_size + ip_size + todo != packet->len) {
319 ifdebug(TRAFFIC) logger(LOG_WARNING, "Length of packet (%d) doesn't match length in IPv4 header (%zd)", packet->len, ether_size + ip_size + todo);
323 ifdebug(TRAFFIC) logger(LOG_INFO, "Fragmenting packet of %d bytes to %s (%s)", packet->len, dest->name, dest->hostname);
325 offset = packet->data + ether_size + ip_size;
326 maxlen = (dest->mtu - ether_size - ip_size) & ~0x7;
327 ip_off = ntohs(ip.ip_off);
328 origf = ip_off & ~IP_OFFMASK;
329 ip_off &= IP_OFFMASK;
332 len = todo > maxlen ? maxlen : todo;
333 memcpy(fragment.data + ether_size + ip_size, offset, len);
337 ip.ip_len = htons(ip_size + len);
338 ip.ip_off = htons(ip_off | origf | (todo ? IP_MF : 0));
340 ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
341 memcpy(fragment.data, packet->data, ether_size);
342 memcpy(fragment.data + ether_size, &ip, ip_size);
343 fragment.len = ether_size + ip_size + len;
345 send_packet(dest, &fragment);
351 static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
356 memcpy(&dest, &packet->data[30], sizeof dest);
357 subnet = lookup_subnet_ipv4(&dest);
360 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv4 destination address %d.%d.%d.%d",
361 source->name, source->hostname,
367 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNKNOWN);
371 if(subnet->owner == source) {
372 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
376 if(!subnet->owner->status.reachable)
377 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNREACH);
379 if(priorityinheritance)
380 packet->priority = packet->data[15];
382 via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
384 if(via && packet->len > max(via->mtu, 590) && via != myself) {
385 ifdebug(TRAFFIC) logger(LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
386 if(packet->data[20] & 0x40) {
387 packet->len = max(via->mtu, 590);
388 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
390 fragment_ipv4_packet(via, packet);
396 clamp_mss(source, via, packet);
398 send_packet(subnet->owner, packet);
401 static void route_ipv4(node_t *source, vpn_packet_t *packet) {
402 if(!checklength(source, packet, ether_size + ip_size))
405 if(((packet->data[30] & 0xf0) == 0xe0) || (
406 packet->data[30] == 255 &&
407 packet->data[31] == 255 &&
408 packet->data[32] == 255 &&
409 packet->data[33] == 255))
410 broadcast_packet(source, packet);
412 route_ipv4_unicast(source, packet);
417 static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
419 struct icmp6_hdr icmp6 = {0};
423 struct in6_addr ip6_src; /* source address */
424 struct in6_addr ip6_dst; /* destination address */
432 /* Swap Ethernet source and destination addresses */
434 swap_mac_addresses(packet);
436 /* Copy headers from packet to structs on the stack */
438 memcpy(&ip6, packet->data + ether_size, ip6_size);
440 /* Remember original source and destination */
442 pseudo.ip6_src = ip6.ip6_dst;
443 pseudo.ip6_dst = ip6.ip6_src;
445 pseudo.length = packet->len - ether_size;
447 if(type == ICMP6_PACKET_TOO_BIG)
448 icmp6.icmp6_mtu = htonl(pseudo.length);
450 if(pseudo.length >= IP_MSS - ip6_size - icmp6_size)
451 pseudo.length = IP_MSS - ip6_size - icmp6_size;
453 /* Copy first part of original contents to ICMP message */
455 memmove(packet->data + ether_size + ip6_size + icmp6_size, packet->data + ether_size, pseudo.length);
457 /* Fill in IPv6 header */
459 ip6.ip6_flow = htonl(0x60000000UL);
460 ip6.ip6_plen = htons(icmp6_size + pseudo.length);
461 ip6.ip6_nxt = IPPROTO_ICMPV6;
463 ip6.ip6_src = pseudo.ip6_src;
464 ip6.ip6_dst = pseudo.ip6_dst;
466 /* Fill in ICMP header */
468 icmp6.icmp6_type = type;
469 icmp6.icmp6_code = code;
470 icmp6.icmp6_cksum = 0;
472 /* Create pseudo header */
474 pseudo.length = htonl(icmp6_size + pseudo.length);
475 pseudo.next = htonl(IPPROTO_ICMPV6);
477 /* Generate checksum */
479 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
480 checksum = inet_checksum(&icmp6, icmp6_size, checksum);
481 checksum = inet_checksum(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
483 icmp6.icmp6_cksum = checksum;
485 /* Copy structs on stack back to packet */
487 memcpy(packet->data + ether_size, &ip6, ip6_size);
488 memcpy(packet->data + ether_size + ip6_size, &icmp6, icmp6_size);
490 packet->len = ether_size + ip6_size + ntohl(pseudo.length);
492 send_packet(source, packet);
495 static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
500 memcpy(&dest, &packet->data[38], sizeof dest);
501 subnet = lookup_subnet_ipv6(&dest);
504 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
505 source->name, source->hostname,
515 route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR);
519 if(subnet->owner == source) {
520 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
524 if(!subnet->owner->status.reachable)
525 route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE);
527 via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
529 if(via && packet->len > max(via->mtu, 1294) && via != myself) {
530 ifdebug(TRAFFIC) logger(LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
531 packet->len = max(via->mtu, 1294);
532 route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
536 clamp_mss(source, via, packet);
538 send_packet(subnet->owner, packet);
543 static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
545 struct nd_neighbor_solicit ns;
546 struct nd_opt_hdr opt;
552 struct in6_addr ip6_src; /* source address */
553 struct in6_addr ip6_dst; /* destination address */
558 if(!checklength(source, packet, ether_size + ip6_size + ns_size))
561 has_opt = packet->len >= ether_size + ip6_size + ns_size + opt_size + ETH_ALEN;
563 if(source != myself) {
564 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got neighbor solicitation request from %s (%s) while in router mode!", source->name, source->hostname);
568 /* Copy headers from packet to structs on the stack */
570 memcpy(&ip6, packet->data + ether_size, ip6_size);
571 memcpy(&ns, packet->data + ether_size + ip6_size, ns_size);
573 memcpy(&opt, packet->data + ether_size + ip6_size + ns_size, opt_size);
575 /* First, snatch the source address from the neighbor solicitation packet */
578 memcpy(mymac.x, packet->data + ETH_ALEN, ETH_ALEN);
580 /* Check if this is a valid neighbor solicitation request */
582 if(ns.nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
583 (has_opt && opt.nd_opt_type != ND_OPT_SOURCE_LINKADDR)) {
584 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type neighbor solicitation request");
588 /* Create pseudo header */
590 pseudo.ip6_src = ip6.ip6_src;
591 pseudo.ip6_dst = ip6.ip6_dst;
593 pseudo.length = htonl(ns_size + opt_size + ETH_ALEN);
595 pseudo.length = htonl(ns_size);
596 pseudo.next = htonl(IPPROTO_ICMPV6);
598 /* Generate checksum */
600 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
601 checksum = inet_checksum(&ns, ns_size, checksum);
603 checksum = inet_checksum(&opt, opt_size, checksum);
604 checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
608 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: checksum error for neighbor solicitation request");
612 /* Check if the IPv6 address exists on the VPN */
614 subnet = lookup_subnet_ipv6((ipv6_t *) &ns.nd_ns_target);
617 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
618 ntohs(((uint16_t *) &ns.nd_ns_target)[0]),
619 ntohs(((uint16_t *) &ns.nd_ns_target)[1]),
620 ntohs(((uint16_t *) &ns.nd_ns_target)[2]),
621 ntohs(((uint16_t *) &ns.nd_ns_target)[3]),
622 ntohs(((uint16_t *) &ns.nd_ns_target)[4]),
623 ntohs(((uint16_t *) &ns.nd_ns_target)[5]),
624 ntohs(((uint16_t *) &ns.nd_ns_target)[6]),
625 ntohs(((uint16_t *) &ns.nd_ns_target)[7]));
630 /* Check if it is for our own subnet */
632 if(subnet->owner == myself)
633 return; /* silently ignore */
635 /* Create neighbor advertation reply */
637 memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
638 packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
640 ip6.ip6_dst = ip6.ip6_src; /* swap destination and source protocoll address */
641 ip6.ip6_src = ns.nd_ns_target;
644 memcpy(packet->data + ether_size + ip6_size + ns_size + opt_size, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
647 ns.nd_ns_type = ND_NEIGHBOR_ADVERT;
648 ns.nd_ns_reserved = htonl(0x40000000UL); /* Set solicited flag */
649 opt.nd_opt_type = ND_OPT_TARGET_LINKADDR;
651 /* Create pseudo header */
653 pseudo.ip6_src = ip6.ip6_src;
654 pseudo.ip6_dst = ip6.ip6_dst;
656 pseudo.length = htonl(ns_size + opt_size + ETH_ALEN);
658 pseudo.length = htonl(ns_size);
659 pseudo.next = htonl(IPPROTO_ICMPV6);
661 /* Generate checksum */
663 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
664 checksum = inet_checksum(&ns, ns_size, checksum);
666 checksum = inet_checksum(&opt, opt_size, checksum);
667 checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
670 ns.nd_ns_hdr.icmp6_cksum = checksum;
672 /* Copy structs on stack back to packet */
674 memcpy(packet->data + ether_size, &ip6, ip6_size);
675 memcpy(packet->data + ether_size + ip6_size, &ns, ns_size);
677 memcpy(packet->data + ether_size + ip6_size + ns_size, &opt, opt_size);
679 send_packet(source, packet);
682 static void route_ipv6(node_t *source, vpn_packet_t *packet) {
683 if(!checklength(source, packet, ether_size + ip6_size))
686 if(packet->data[20] == IPPROTO_ICMPV6 && checklength(source, packet, ether_size + ip6_size + icmp6_size) && packet->data[54] == ND_NEIGHBOR_SOLICIT) {
687 route_neighborsol(source, packet);
691 if(packet->data[38] == 255)
692 broadcast_packet(source, packet);
694 route_ipv6_unicast(source, packet);
699 static void route_arp(node_t *source, vpn_packet_t *packet) {
700 struct ether_arp arp;
704 if(!checklength(source, packet, ether_size + arp_size))
707 if(source != myself) {
708 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got ARP request from %s (%s) while in router mode!", source->name, source->hostname);
712 /* First, snatch the source address from the ARP packet */
715 memcpy(mymac.x, packet->data + ETH_ALEN, ETH_ALEN);
717 /* Copy headers from packet to structs on the stack */
719 memcpy(&arp, packet->data + ether_size, arp_size);
721 /* Check if this is a valid ARP request */
723 if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP ||
724 arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) {
725 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type ARP request");
729 /* Check if the IPv4 address exists on the VPN */
731 subnet = lookup_subnet_ipv4((ipv4_t *) &arp.arp_tpa);
734 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: ARP request for unknown address %d.%d.%d.%d",
735 arp.arp_tpa[0], arp.arp_tpa[1], arp.arp_tpa[2],
740 /* Check if it is for our own subnet */
742 if(subnet->owner == myself)
743 return; /* silently ignore */
745 memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
746 packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
748 memcpy(&addr, arp.arp_tpa, sizeof(addr)); /* save protocol addr */
749 memcpy(arp.arp_tpa, arp.arp_spa, sizeof(addr)); /* swap destination and source protocol address */
750 memcpy(arp.arp_spa, &addr, sizeof(addr)); /* ... */
752 memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */
753 memcpy(arp.arp_sha, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
754 arp.arp_op = htons(ARPOP_REPLY);
756 /* Copy structs on stack back to packet */
758 memcpy(packet->data + ether_size, &arp, arp_size);
760 send_packet(source, packet);
763 static void route_mac(node_t *source, vpn_packet_t *packet) {
767 /* Learn source address */
769 if(source == myself) {
771 memcpy(&src, &packet->data[6], sizeof src);
775 /* Lookup destination address */
777 memcpy(&dest, &packet->data[0], sizeof dest);
778 subnet = lookup_subnet_mac(NULL, &dest);
781 broadcast_packet(source, packet);
785 if(subnet->owner == source) {
786 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
790 // Handle packets larger than PMTU
792 node_t *via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
794 if(via && packet->len > via->mtu && via != myself) {
795 ifdebug(TRAFFIC) logger(LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
796 uint16_t type = packet->data[12] << 8 | packet->data[13];
797 if(type == ETH_P_IP && packet->len > 590) {
798 if(packet->data[20] & 0x40) {
799 packet->len = via->mtu;
800 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
802 fragment_ipv4_packet(via, packet);
805 } else if(type == ETH_P_IPV6 && packet->len > 1294) {
806 packet->len = via->mtu;
807 route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
812 clamp_mss(source, via, packet);
814 send_packet(subnet->owner, packet);
817 void route(node_t *source, vpn_packet_t *packet) {
818 if(!checklength(source, packet, ether_size))
821 switch (routing_mode) {
824 uint16_t type = packet->data[12] << 8 | packet->data[13];
828 route_arp(source, packet);
832 route_ipv4(source, packet);
836 route_ipv6(source, packet);
840 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown type %hx", source->name, source->hostname, type);
847 route_mac(source, packet);
851 broadcast_packet(source, packet);