3 Copyright (C) 2000-2005 Ivo Timmermans,
4 2000-2010 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 || !(via->options & OPTION_CLAMP_MSS))
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 if(packet->len < start + 20 + len)
118 /* Search for MSS option header */
119 for(int i = 0; i < len;) {
120 if(packet->data[start + 20 + i] == 0)
123 if(packet->data[start + 20 + i] == 1) {
128 if(i > len - 2 || i > len - packet->data[start + 21 + i])
131 if(packet->data[start + 20 + i] != 2) {
132 if(packet->data[start + 21 + i] < 2)
134 i += packet->data[start + 21 + i];
138 if(packet->data[start + 21] != 4)
142 uint16_t oldmss = packet->data[start + 22 + i] << 8 | packet->data[start + 23 + i];
143 uint16_t newmss = via->mtu - start - 20;
144 uint16_t csum = packet->data[start + 16] << 8 | packet->data[start + 17];
149 ifdebug(TRAFFIC) logger(LOG_INFO, "Clamping MSS of packet from %s to %s to %d", source->name, via->name, newmss);
151 /* Update the MSS value and the checksum */
152 packet->data[start + 22 + i] = newmss >> 8;
153 packet->data[start + 23 + i] = newmss & 0xff;
158 packet->data[start + 16] = csum >> 8;
159 packet->data[start + 17] = csum & 0xff;
164 static void swap_mac_addresses(vpn_packet_t *packet) {
166 memcpy(&tmp, &packet->data[0], sizeof tmp);
167 memcpy(&packet->data[0], &packet->data[6], sizeof tmp);
168 memcpy(&packet->data[6], &tmp, sizeof tmp);
171 static void learn_mac(mac_t *address) {
176 subnet = lookup_subnet_mac(myself, address);
178 /* If we don't know this MAC address yet, store it */
181 ifdebug(TRAFFIC) logger(LOG_INFO, "Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx",
182 address->x[0], address->x[1], address->x[2], address->x[3],
183 address->x[4], address->x[5]);
185 subnet = new_subnet();
186 subnet->type = SUBNET_MAC;
187 subnet->expires = now + macexpire;
188 subnet->net.mac.address = *address;
190 subnet_add(myself, subnet);
191 subnet_update(myself, subnet, true);
193 /* And tell all other tinc daemons it's our MAC */
195 for(node = connection_tree->head; node; node = node->next) {
198 send_add_subnet(c, subnet);
203 subnet->expires = now + macexpire;
206 void age_subnets(void) {
209 avl_node_t *node, *next, *node2;
211 for(node = myself->subnet_tree->head; node; node = next) {
214 if(s->expires && s->expires < now) {
216 char netstr[MAXNETSTR];
217 if(net2str(netstr, sizeof netstr, s))
218 logger(LOG_INFO, "Subnet %s expired", netstr);
221 for(node2 = connection_tree->head; node2; node2 = node2->next) {
224 send_del_subnet(c, s);
227 subnet_update(myself, s, false);
228 subnet_del(myself, s);
235 static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
237 struct icmp icmp = {0};
239 struct in_addr ip_src;
240 struct in_addr ip_dst;
246 /* Swap Ethernet source and destination addresses */
248 swap_mac_addresses(packet);
250 /* Copy headers from packet into properly aligned structs on the stack */
252 memcpy(&ip, packet->data + ether_size, ip_size);
254 /* Remember original source and destination */
259 oldlen = packet->len - ether_size;
261 if(type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
262 icmp.icmp_nextmtu = htons(packet->len - ether_size);
264 if(oldlen >= IP_MSS - ip_size - icmp_size)
265 oldlen = IP_MSS - ip_size - icmp_size;
267 /* Copy first part of original contents to ICMP message */
269 memmove(packet->data + ether_size + ip_size + icmp_size, packet->data + ether_size, oldlen);
271 /* Fill in IPv4 header */
274 ip.ip_hl = ip_size / 4;
276 ip.ip_len = htons(ip_size + icmp_size + oldlen);
280 ip.ip_p = IPPROTO_ICMP;
285 ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
287 /* Fill in ICMP header */
289 icmp.icmp_type = type;
290 icmp.icmp_code = code;
293 icmp.icmp_cksum = inet_checksum(&icmp, icmp_size, ~0);
294 icmp.icmp_cksum = inet_checksum(packet->data + ether_size + ip_size + icmp_size, oldlen, icmp.icmp_cksum);
296 /* Copy structs on stack back to packet */
298 memcpy(packet->data + ether_size, &ip, ip_size);
299 memcpy(packet->data + ether_size + ip_size, &icmp, icmp_size);
301 packet->len = ether_size + ip_size + icmp_size + oldlen;
303 send_packet(source, packet);
308 static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
310 vpn_packet_t fragment;
311 int len, maxlen, todo;
313 uint16_t ip_off, origf;
315 memcpy(&ip, packet->data + ether_size, ip_size);
316 fragment.priority = packet->priority;
318 if(ip.ip_hl != ip_size / 4)
321 todo = ntohs(ip.ip_len) - ip_size;
323 if(ether_size + ip_size + todo != packet->len) {
324 ifdebug(TRAFFIC) logger(LOG_WARNING, "Length of packet (%d) doesn't match length in IPv4 header (%zd)", packet->len, ether_size + ip_size + todo);
328 ifdebug(TRAFFIC) logger(LOG_INFO, "Fragmenting packet of %d bytes to %s (%s)", packet->len, dest->name, dest->hostname);
330 offset = packet->data + ether_size + ip_size;
331 maxlen = (dest->mtu - ether_size - ip_size) & ~0x7;
332 ip_off = ntohs(ip.ip_off);
333 origf = ip_off & ~IP_OFFMASK;
334 ip_off &= IP_OFFMASK;
337 len = todo > maxlen ? maxlen : todo;
338 memcpy(fragment.data + ether_size + ip_size, offset, len);
342 ip.ip_len = htons(ip_size + len);
343 ip.ip_off = htons(ip_off | origf | (todo ? IP_MF : 0));
345 ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
346 memcpy(fragment.data, packet->data, ether_size);
347 memcpy(fragment.data + ether_size, &ip, ip_size);
348 fragment.len = ether_size + ip_size + len;
350 send_packet(dest, &fragment);
356 static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
361 memcpy(&dest, &packet->data[30], sizeof dest);
362 subnet = lookup_subnet_ipv4(&dest);
365 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv4 destination address %d.%d.%d.%d",
366 source->name, source->hostname,
372 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNKNOWN);
376 if(subnet->owner == source) {
377 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
381 if(!subnet->owner->status.reachable)
382 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNREACH);
384 if(priorityinheritance)
385 packet->priority = packet->data[15];
387 via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
389 if(via && packet->len > max(via->mtu, 590) && via != myself) {
390 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);
391 if(packet->data[20] & 0x40) {
392 packet->len = max(via->mtu, 590);
393 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
395 fragment_ipv4_packet(via, packet);
401 clamp_mss(source, via, packet);
403 send_packet(subnet->owner, packet);
406 static void route_ipv4(node_t *source, vpn_packet_t *packet) {
407 if(!checklength(source, packet, ether_size + ip_size))
410 if(((packet->data[30] & 0xf0) == 0xe0) || (
411 packet->data[30] == 255 &&
412 packet->data[31] == 255 &&
413 packet->data[32] == 255 &&
414 packet->data[33] == 255))
415 broadcast_packet(source, packet);
417 route_ipv4_unicast(source, packet);
422 static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
424 struct icmp6_hdr icmp6 = {0};
428 struct in6_addr ip6_src; /* source address */
429 struct in6_addr ip6_dst; /* destination address */
437 /* Swap Ethernet source and destination addresses */
439 swap_mac_addresses(packet);
441 /* Copy headers from packet to structs on the stack */
443 memcpy(&ip6, packet->data + ether_size, ip6_size);
445 /* Remember original source and destination */
447 pseudo.ip6_src = ip6.ip6_dst;
448 pseudo.ip6_dst = ip6.ip6_src;
450 pseudo.length = packet->len - ether_size;
452 if(type == ICMP6_PACKET_TOO_BIG)
453 icmp6.icmp6_mtu = htonl(pseudo.length);
455 if(pseudo.length >= IP_MSS - ip6_size - icmp6_size)
456 pseudo.length = IP_MSS - ip6_size - icmp6_size;
458 /* Copy first part of original contents to ICMP message */
460 memmove(packet->data + ether_size + ip6_size + icmp6_size, packet->data + ether_size, pseudo.length);
462 /* Fill in IPv6 header */
464 ip6.ip6_flow = htonl(0x60000000UL);
465 ip6.ip6_plen = htons(icmp6_size + pseudo.length);
466 ip6.ip6_nxt = IPPROTO_ICMPV6;
468 ip6.ip6_src = pseudo.ip6_src;
469 ip6.ip6_dst = pseudo.ip6_dst;
471 /* Fill in ICMP header */
473 icmp6.icmp6_type = type;
474 icmp6.icmp6_code = code;
475 icmp6.icmp6_cksum = 0;
477 /* Create pseudo header */
479 pseudo.length = htonl(icmp6_size + pseudo.length);
480 pseudo.next = htonl(IPPROTO_ICMPV6);
482 /* Generate checksum */
484 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
485 checksum = inet_checksum(&icmp6, icmp6_size, checksum);
486 checksum = inet_checksum(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
488 icmp6.icmp6_cksum = checksum;
490 /* Copy structs on stack back to packet */
492 memcpy(packet->data + ether_size, &ip6, ip6_size);
493 memcpy(packet->data + ether_size + ip6_size, &icmp6, icmp6_size);
495 packet->len = ether_size + ip6_size + ntohl(pseudo.length);
497 send_packet(source, packet);
500 static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
505 memcpy(&dest, &packet->data[38], sizeof dest);
506 subnet = lookup_subnet_ipv6(&dest);
509 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
510 source->name, source->hostname,
520 route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR);
524 if(subnet->owner == source) {
525 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
529 if(!subnet->owner->status.reachable)
530 route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE);
532 via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
534 if(via && packet->len > max(via->mtu, 1294) && via != myself) {
535 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);
536 packet->len = max(via->mtu, 1294);
537 route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
541 clamp_mss(source, via, packet);
543 send_packet(subnet->owner, packet);
548 static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
550 struct nd_neighbor_solicit ns;
551 struct nd_opt_hdr opt;
557 struct in6_addr ip6_src; /* source address */
558 struct in6_addr ip6_dst; /* destination address */
563 if(!checklength(source, packet, ether_size + ip6_size + ns_size))
566 has_opt = packet->len >= ether_size + ip6_size + ns_size + opt_size + ETH_ALEN;
568 if(source != myself) {
569 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got neighbor solicitation request from %s (%s) while in router mode!", source->name, source->hostname);
573 /* Copy headers from packet to structs on the stack */
575 memcpy(&ip6, packet->data + ether_size, ip6_size);
576 memcpy(&ns, packet->data + ether_size + ip6_size, ns_size);
578 memcpy(&opt, packet->data + ether_size + ip6_size + ns_size, opt_size);
580 /* First, snatch the source address from the neighbor solicitation packet */
583 memcpy(mymac.x, packet->data + ETH_ALEN, ETH_ALEN);
585 /* Check if this is a valid neighbor solicitation request */
587 if(ns.nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
588 (has_opt && opt.nd_opt_type != ND_OPT_SOURCE_LINKADDR)) {
589 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type neighbor solicitation request");
593 /* Create pseudo header */
595 pseudo.ip6_src = ip6.ip6_src;
596 pseudo.ip6_dst = ip6.ip6_dst;
598 pseudo.length = htonl(ns_size + opt_size + ETH_ALEN);
600 pseudo.length = htonl(ns_size);
601 pseudo.next = htonl(IPPROTO_ICMPV6);
603 /* Generate checksum */
605 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
606 checksum = inet_checksum(&ns, ns_size, checksum);
608 checksum = inet_checksum(&opt, opt_size, checksum);
609 checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
613 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: checksum error for neighbor solicitation request");
617 /* Check if the IPv6 address exists on the VPN */
619 subnet = lookup_subnet_ipv6((ipv6_t *) &ns.nd_ns_target);
622 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
623 ntohs(((uint16_t *) &ns.nd_ns_target)[0]),
624 ntohs(((uint16_t *) &ns.nd_ns_target)[1]),
625 ntohs(((uint16_t *) &ns.nd_ns_target)[2]),
626 ntohs(((uint16_t *) &ns.nd_ns_target)[3]),
627 ntohs(((uint16_t *) &ns.nd_ns_target)[4]),
628 ntohs(((uint16_t *) &ns.nd_ns_target)[5]),
629 ntohs(((uint16_t *) &ns.nd_ns_target)[6]),
630 ntohs(((uint16_t *) &ns.nd_ns_target)[7]));
635 /* Check if it is for our own subnet */
637 if(subnet->owner == myself)
638 return; /* silently ignore */
640 /* Create neighbor advertation reply */
642 memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
643 packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
645 ip6.ip6_dst = ip6.ip6_src; /* swap destination and source protocoll address */
646 ip6.ip6_src = ns.nd_ns_target;
649 memcpy(packet->data + ether_size + ip6_size + ns_size + opt_size, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
652 ns.nd_ns_type = ND_NEIGHBOR_ADVERT;
653 ns.nd_ns_reserved = htonl(0x40000000UL); /* Set solicited flag */
654 opt.nd_opt_type = ND_OPT_TARGET_LINKADDR;
656 /* Create pseudo header */
658 pseudo.ip6_src = ip6.ip6_src;
659 pseudo.ip6_dst = ip6.ip6_dst;
661 pseudo.length = htonl(ns_size + opt_size + ETH_ALEN);
663 pseudo.length = htonl(ns_size);
664 pseudo.next = htonl(IPPROTO_ICMPV6);
666 /* Generate checksum */
668 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
669 checksum = inet_checksum(&ns, ns_size, checksum);
671 checksum = inet_checksum(&opt, opt_size, checksum);
672 checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
675 ns.nd_ns_hdr.icmp6_cksum = checksum;
677 /* Copy structs on stack back to packet */
679 memcpy(packet->data + ether_size, &ip6, ip6_size);
680 memcpy(packet->data + ether_size + ip6_size, &ns, ns_size);
682 memcpy(packet->data + ether_size + ip6_size + ns_size, &opt, opt_size);
684 send_packet(source, packet);
687 static void route_ipv6(node_t *source, vpn_packet_t *packet) {
688 if(!checklength(source, packet, ether_size + ip6_size))
691 if(packet->data[20] == IPPROTO_ICMPV6 && checklength(source, packet, ether_size + ip6_size + icmp6_size) && packet->data[54] == ND_NEIGHBOR_SOLICIT) {
692 route_neighborsol(source, packet);
696 if(packet->data[38] == 255)
697 broadcast_packet(source, packet);
699 route_ipv6_unicast(source, packet);
704 static void route_arp(node_t *source, vpn_packet_t *packet) {
705 struct ether_arp arp;
709 if(!checklength(source, packet, ether_size + arp_size))
712 if(source != myself) {
713 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got ARP request from %s (%s) while in router mode!", source->name, source->hostname);
717 /* First, snatch the source address from the ARP packet */
720 memcpy(mymac.x, packet->data + ETH_ALEN, ETH_ALEN);
722 /* Copy headers from packet to structs on the stack */
724 memcpy(&arp, packet->data + ether_size, arp_size);
726 /* Check if this is a valid ARP request */
728 if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP ||
729 arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) {
730 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type ARP request");
734 /* Check if the IPv4 address exists on the VPN */
736 subnet = lookup_subnet_ipv4((ipv4_t *) &arp.arp_tpa);
739 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: ARP request for unknown address %d.%d.%d.%d",
740 arp.arp_tpa[0], arp.arp_tpa[1], arp.arp_tpa[2],
745 /* Check if it is for our own subnet */
747 if(subnet->owner == myself)
748 return; /* silently ignore */
750 memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
751 packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
753 memcpy(&addr, arp.arp_tpa, sizeof(addr)); /* save protocol addr */
754 memcpy(arp.arp_tpa, arp.arp_spa, sizeof(addr)); /* swap destination and source protocol address */
755 memcpy(arp.arp_spa, &addr, sizeof(addr)); /* ... */
757 memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */
758 memcpy(arp.arp_sha, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
759 arp.arp_op = htons(ARPOP_REPLY);
761 /* Copy structs on stack back to packet */
763 memcpy(packet->data + ether_size, &arp, arp_size);
765 send_packet(source, packet);
768 static void route_mac(node_t *source, vpn_packet_t *packet) {
772 /* Learn source address */
774 if(source == myself) {
776 memcpy(&src, &packet->data[6], sizeof src);
780 /* Lookup destination address */
782 memcpy(&dest, &packet->data[0], sizeof dest);
783 subnet = lookup_subnet_mac(NULL, &dest);
786 broadcast_packet(source, packet);
790 if(subnet->owner == source) {
791 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
795 // Handle packets larger than PMTU
797 node_t *via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
799 if(via && packet->len > via->mtu && via != myself) {
800 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);
801 uint16_t type = packet->data[12] << 8 | packet->data[13];
802 if(type == ETH_P_IP && packet->len > 590) {
803 if(packet->data[20] & 0x40) {
804 packet->len = via->mtu;
805 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
807 fragment_ipv4_packet(via, packet);
810 } else if(type == ETH_P_IPV6 && packet->len > 1294) {
811 packet->len = via->mtu;
812 route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
817 clamp_mss(source, via, packet);
819 send_packet(subnet->owner, packet);
822 void route(node_t *source, vpn_packet_t *packet) {
823 if(!checklength(source, packet, ether_size))
826 switch (routing_mode) {
829 uint16_t type = packet->data[12] << 8 | packet->data[13];
833 route_arp(source, packet);
837 route_ipv4(source, packet);
841 route_ipv6(source, packet);
845 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown type %hx", source->name, source->hostname, type);
852 route_mac(source, packet);
856 broadcast_packet(source, packet);