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 void clamp_mss(node_t *source, node_t *via, vpn_packet_t *packet) {
98 int len = ((packet->data[46] >> 4) - 5) * 4;
100 for(int i = 0; i < len;) {
101 if(packet->data[54 + i] == 0)
104 if(packet->data[54 + i] == 1) {
109 if(i > len - 2 || i > len - packet->data[55 + i])
112 if(packet->data[54 + i] != 2) {
113 if(packet->data[55 + i] < 2)
115 i += packet->data[55 + i];
119 if(packet->data[55] != 4)
122 uint16_t oldmss = packet->data[56 + i] << 8 | packet->data[57 + i];
123 uint16_t newmss = via->mtu - 54;
124 uint16_t csum = packet->data[50] << 8 | packet->data[51];
129 ifdebug(TRAFFIC) logger(LOG_INFO, "Clamping MSS of packet from %s to %s to %d", source->name, via->name, newmss);
131 packet->data[56 + i] = newmss >> 8;
132 packet->data[57 + i] = newmss & 0xff;
137 packet->data[50] = csum >> 8;
138 packet->data[51] = csum & 0xff;
143 static void swap_mac_addresses(vpn_packet_t *packet) {
145 memcpy(&tmp, &packet->data[0], sizeof tmp);
146 memcpy(&packet->data[0], &packet->data[6], sizeof tmp);
147 memcpy(&packet->data[6], &tmp, sizeof tmp);
150 static void learn_mac(mac_t *address) {
155 subnet = lookup_subnet_mac(myself, address);
157 /* If we don't know this MAC address yet, store it */
160 ifdebug(TRAFFIC) logger(LOG_INFO, "Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx",
161 address->x[0], address->x[1], address->x[2], address->x[3],
162 address->x[4], address->x[5]);
164 subnet = new_subnet();
165 subnet->type = SUBNET_MAC;
166 subnet->expires = now + macexpire;
167 subnet->net.mac.address = *address;
169 subnet_add(myself, subnet);
171 /* And tell all other tinc daemons it's our MAC */
173 for(node = connection_tree->head; node; node = node->next) {
176 send_add_subnet(c, subnet);
181 subnet->expires = now + macexpire;
184 void age_subnets(void) {
187 avl_node_t *node, *next, *node2;
189 for(node = myself->subnet_tree->head; node; node = next) {
192 if(s->expires && s->expires < now) {
194 char netstr[MAXNETSTR];
195 if(net2str(netstr, sizeof netstr, s))
196 logger(LOG_INFO, "Subnet %s expired", netstr);
199 for(node2 = connection_tree->head; node2; node2 = node2->next) {
202 send_del_subnet(c, s);
205 subnet_del(myself, s);
212 static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
214 struct icmp icmp = {0};
216 struct in_addr ip_src;
217 struct in_addr ip_dst;
223 /* Swap Ethernet source and destination addresses */
225 swap_mac_addresses(packet);
227 /* Copy headers from packet into properly aligned structs on the stack */
229 memcpy(&ip, packet->data + ether_size, ip_size);
231 /* Remember original source and destination */
236 oldlen = packet->len - ether_size;
238 if(type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
239 icmp.icmp_nextmtu = htons(packet->len - ether_size);
241 if(oldlen >= IP_MSS - ip_size - icmp_size)
242 oldlen = IP_MSS - ip_size - icmp_size;
244 /* Copy first part of original contents to ICMP message */
246 memmove(packet->data + ether_size + ip_size + icmp_size, packet->data + ether_size, oldlen);
248 /* Fill in IPv4 header */
251 ip.ip_hl = ip_size / 4;
253 ip.ip_len = htons(ip_size + icmp_size + oldlen);
257 ip.ip_p = IPPROTO_ICMP;
262 ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
264 /* Fill in ICMP header */
266 icmp.icmp_type = type;
267 icmp.icmp_code = code;
270 icmp.icmp_cksum = inet_checksum(&icmp, icmp_size, ~0);
271 icmp.icmp_cksum = inet_checksum(packet->data + ether_size + ip_size + icmp_size, oldlen, icmp.icmp_cksum);
273 /* Copy structs on stack back to packet */
275 memcpy(packet->data + ether_size, &ip, ip_size);
276 memcpy(packet->data + ether_size + ip_size, &icmp, icmp_size);
278 packet->len = ether_size + ip_size + icmp_size + oldlen;
280 send_packet(source, packet);
285 static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
287 vpn_packet_t fragment;
288 int len, maxlen, todo;
290 uint16_t ip_off, origf;
292 memcpy(&ip, packet->data + ether_size, ip_size);
293 fragment.priority = packet->priority;
295 if(ip.ip_hl != ip_size / 4)
298 todo = ntohs(ip.ip_len) - ip_size;
300 if(ether_size + ip_size + todo != packet->len) {
301 ifdebug(TRAFFIC) logger(LOG_WARNING, "Length of packet (%d) doesn't match length in IPv4 header (%zd)", packet->len, ether_size + ip_size + todo);
305 ifdebug(TRAFFIC) logger(LOG_INFO, "Fragmenting packet of %d bytes to %s (%s)", packet->len, dest->name, dest->hostname);
307 offset = packet->data + ether_size + ip_size;
308 maxlen = (dest->mtu - ether_size - ip_size) & ~0x7;
309 ip_off = ntohs(ip.ip_off);
310 origf = ip_off & ~IP_OFFMASK;
311 ip_off &= IP_OFFMASK;
314 len = todo > maxlen ? maxlen : todo;
315 memcpy(fragment.data + ether_size + ip_size, offset, len);
319 ip.ip_len = htons(ip_size + len);
320 ip.ip_off = htons(ip_off | origf | (todo ? IP_MF : 0));
322 ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
323 memcpy(fragment.data, packet->data, ether_size);
324 memcpy(fragment.data + ether_size, &ip, ip_size);
325 fragment.len = ether_size + ip_size + len;
327 send_packet(dest, &fragment);
333 static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
338 memcpy(&dest, &packet->data[30], sizeof dest);
339 subnet = lookup_subnet_ipv4(&dest);
342 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv4 destination address %d.%d.%d.%d",
343 source->name, source->hostname,
349 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNKNOWN);
353 if(subnet->owner == source) {
354 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
358 if(!subnet->owner->status.reachable)
359 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNREACH);
361 if(priorityinheritance)
362 packet->priority = packet->data[15];
364 via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
366 if(via && packet->len > max(via->mtu, 590) && via != myself) {
367 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);
368 if(packet->data[20] & 0x40) {
369 packet->len = max(via->mtu, 590);
370 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
372 fragment_ipv4_packet(via, packet);
378 if(via && via != myself && packet->data[23] == 6 && packet->len >= 58 && (packet->data[46] >> 4) > 5)
379 clamp_mss(source, via, packet);
381 send_packet(subnet->owner, packet);
384 static void route_ipv4(node_t *source, vpn_packet_t *packet) {
385 if(!checklength(source, packet, ether_size + ip_size))
388 if(((packet->data[30] & 0xf0) == 0xe0) || (
389 packet->data[30] == 255 &&
390 packet->data[31] == 255 &&
391 packet->data[32] == 255 &&
392 packet->data[33] == 255))
393 broadcast_packet(source, packet);
395 route_ipv4_unicast(source, packet);
400 static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
402 struct icmp6_hdr icmp6 = {0};
406 struct in6_addr ip6_src; /* source address */
407 struct in6_addr ip6_dst; /* destination address */
415 /* Swap Ethernet source and destination addresses */
417 swap_mac_addresses(packet);
419 /* Copy headers from packet to structs on the stack */
421 memcpy(&ip6, packet->data + ether_size, ip6_size);
423 /* Remember original source and destination */
425 pseudo.ip6_src = ip6.ip6_dst;
426 pseudo.ip6_dst = ip6.ip6_src;
428 pseudo.length = packet->len - ether_size;
430 if(type == ICMP6_PACKET_TOO_BIG)
431 icmp6.icmp6_mtu = htonl(pseudo.length);
433 if(pseudo.length >= IP_MSS - ip6_size - icmp6_size)
434 pseudo.length = IP_MSS - ip6_size - icmp6_size;
436 /* Copy first part of original contents to ICMP message */
438 memmove(packet->data + ether_size + ip6_size + icmp6_size, packet->data + ether_size, pseudo.length);
440 /* Fill in IPv6 header */
442 ip6.ip6_flow = htonl(0x60000000UL);
443 ip6.ip6_plen = htons(icmp6_size + pseudo.length);
444 ip6.ip6_nxt = IPPROTO_ICMPV6;
446 ip6.ip6_src = pseudo.ip6_src;
447 ip6.ip6_dst = pseudo.ip6_dst;
449 /* Fill in ICMP header */
451 icmp6.icmp6_type = type;
452 icmp6.icmp6_code = code;
453 icmp6.icmp6_cksum = 0;
455 /* Create pseudo header */
457 pseudo.length = htonl(icmp6_size + pseudo.length);
458 pseudo.next = htonl(IPPROTO_ICMPV6);
460 /* Generate checksum */
462 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
463 checksum = inet_checksum(&icmp6, icmp6_size, checksum);
464 checksum = inet_checksum(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
466 icmp6.icmp6_cksum = checksum;
468 /* Copy structs on stack back to packet */
470 memcpy(packet->data + ether_size, &ip6, ip6_size);
471 memcpy(packet->data + ether_size + ip6_size, &icmp6, icmp6_size);
473 packet->len = ether_size + ip6_size + ntohl(pseudo.length);
475 send_packet(source, packet);
478 static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
483 memcpy(&dest, &packet->data[38], sizeof dest);
484 subnet = lookup_subnet_ipv6(&dest);
487 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
488 source->name, source->hostname,
498 route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR);
502 if(subnet->owner == source) {
503 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
507 if(!subnet->owner->status.reachable)
508 route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE);
510 via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
512 if(via && packet->len > max(via->mtu, 1294) && via != myself) {
513 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);
514 packet->len = max(via->mtu, 1294);
515 route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
519 send_packet(subnet->owner, packet);
524 static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
526 struct nd_neighbor_solicit ns;
527 struct nd_opt_hdr opt;
533 struct in6_addr ip6_src; /* source address */
534 struct in6_addr ip6_dst; /* destination address */
539 if(!checklength(source, packet, ether_size + ip6_size + ns_size))
542 has_opt = packet->len >= ether_size + ip6_size + ns_size + opt_size + ETH_ALEN;
544 if(source != myself) {
545 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got neighbor solicitation request from %s (%s) while in router mode!", source->name, source->hostname);
549 /* Copy headers from packet to structs on the stack */
551 memcpy(&ip6, packet->data + ether_size, ip6_size);
552 memcpy(&ns, packet->data + ether_size + ip6_size, ns_size);
554 memcpy(&opt, packet->data + ether_size + ip6_size + ns_size, opt_size);
556 /* First, snatch the source address from the neighbor solicitation packet */
559 memcpy(mymac.x, packet->data + ETH_ALEN, ETH_ALEN);
561 /* Check if this is a valid neighbor solicitation request */
563 if(ns.nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
564 (has_opt && opt.nd_opt_type != ND_OPT_SOURCE_LINKADDR)) {
565 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type neighbor solicitation request");
569 /* Create pseudo header */
571 pseudo.ip6_src = ip6.ip6_src;
572 pseudo.ip6_dst = ip6.ip6_dst;
574 pseudo.length = htonl(ns_size + opt_size + ETH_ALEN);
576 pseudo.length = htonl(ns_size);
577 pseudo.next = htonl(IPPROTO_ICMPV6);
579 /* Generate checksum */
581 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
582 checksum = inet_checksum(&ns, ns_size, checksum);
584 checksum = inet_checksum(&opt, opt_size, checksum);
585 checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
589 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: checksum error for neighbor solicitation request");
593 /* Check if the IPv6 address exists on the VPN */
595 subnet = lookup_subnet_ipv6((ipv6_t *) &ns.nd_ns_target);
598 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
599 ntohs(((uint16_t *) &ns.nd_ns_target)[0]),
600 ntohs(((uint16_t *) &ns.nd_ns_target)[1]),
601 ntohs(((uint16_t *) &ns.nd_ns_target)[2]),
602 ntohs(((uint16_t *) &ns.nd_ns_target)[3]),
603 ntohs(((uint16_t *) &ns.nd_ns_target)[4]),
604 ntohs(((uint16_t *) &ns.nd_ns_target)[5]),
605 ntohs(((uint16_t *) &ns.nd_ns_target)[6]),
606 ntohs(((uint16_t *) &ns.nd_ns_target)[7]));
611 /* Check if it is for our own subnet */
613 if(subnet->owner == myself)
614 return; /* silently ignore */
616 /* Create neighbor advertation reply */
618 memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
619 packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
621 ip6.ip6_dst = ip6.ip6_src; /* swap destination and source protocoll address */
622 ip6.ip6_src = ns.nd_ns_target;
625 memcpy(packet->data + ether_size + ip6_size + ns_size + opt_size, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
628 ns.nd_ns_type = ND_NEIGHBOR_ADVERT;
629 ns.nd_ns_reserved = htonl(0x40000000UL); /* Set solicited flag */
630 opt.nd_opt_type = ND_OPT_TARGET_LINKADDR;
632 /* Create pseudo header */
634 pseudo.ip6_src = ip6.ip6_src;
635 pseudo.ip6_dst = ip6.ip6_dst;
637 pseudo.length = htonl(ns_size + opt_size + ETH_ALEN);
639 pseudo.length = htonl(ns_size);
640 pseudo.next = htonl(IPPROTO_ICMPV6);
642 /* Generate checksum */
644 checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0);
645 checksum = inet_checksum(&ns, ns_size, checksum);
647 checksum = inet_checksum(&opt, opt_size, checksum);
648 checksum = inet_checksum(packet->data + ether_size + ip6_size + ns_size + opt_size, ETH_ALEN, checksum);
651 ns.nd_ns_hdr.icmp6_cksum = checksum;
653 /* Copy structs on stack back to packet */
655 memcpy(packet->data + ether_size, &ip6, ip6_size);
656 memcpy(packet->data + ether_size + ip6_size, &ns, ns_size);
658 memcpy(packet->data + ether_size + ip6_size + ns_size, &opt, opt_size);
660 send_packet(source, packet);
663 static void route_ipv6(node_t *source, vpn_packet_t *packet) {
664 if(!checklength(source, packet, ether_size + ip6_size))
667 if(packet->data[20] == IPPROTO_ICMPV6 && checklength(source, packet, ether_size + ip6_size + icmp6_size) && packet->data[54] == ND_NEIGHBOR_SOLICIT) {
668 route_neighborsol(source, packet);
672 if(packet->data[38] == 255)
673 broadcast_packet(source, packet);
675 route_ipv6_unicast(source, packet);
680 static void route_arp(node_t *source, vpn_packet_t *packet) {
681 struct ether_arp arp;
685 if(!checklength(source, packet, ether_size + arp_size))
688 if(source != myself) {
689 ifdebug(TRAFFIC) logger(LOG_WARNING, "Got ARP request from %s (%s) while in router mode!", source->name, source->hostname);
693 /* First, snatch the source address from the ARP packet */
696 memcpy(mymac.x, packet->data + ETH_ALEN, ETH_ALEN);
698 /* Copy headers from packet to structs on the stack */
700 memcpy(&arp, packet->data + ether_size, arp_size);
702 /* Check if this is a valid ARP request */
704 if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP ||
705 arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) {
706 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: received unknown type ARP request");
710 /* Check if the IPv4 address exists on the VPN */
712 subnet = lookup_subnet_ipv4((ipv4_t *) &arp.arp_tpa);
715 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet: ARP request for unknown address %d.%d.%d.%d",
716 arp.arp_tpa[0], arp.arp_tpa[1], arp.arp_tpa[2],
721 /* Check if it is for our own subnet */
723 if(subnet->owner == myself)
724 return; /* silently ignore */
726 memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
727 packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
729 memcpy(&addr, arp.arp_tpa, sizeof(addr)); /* save protocol addr */
730 memcpy(arp.arp_tpa, arp.arp_spa, sizeof(addr)); /* swap destination and source protocol address */
731 memcpy(arp.arp_spa, &addr, sizeof(addr)); /* ... */
733 memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */
734 memcpy(arp.arp_sha, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
735 arp.arp_op = htons(ARPOP_REPLY);
737 /* Copy structs on stack back to packet */
739 memcpy(packet->data + ether_size, &arp, arp_size);
741 send_packet(source, packet);
744 static void route_mac(node_t *source, vpn_packet_t *packet) {
748 /* Learn source address */
750 if(source == myself) {
752 memcpy(&src, &packet->data[6], sizeof src);
756 /* Lookup destination address */
758 memcpy(&dest, &packet->data[0], sizeof dest);
759 subnet = lookup_subnet_mac(NULL, &dest);
762 broadcast_packet(source, packet);
766 if(subnet->owner == source) {
767 ifdebug(TRAFFIC) logger(LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
771 // Handle packets larger than PMTU
773 node_t *via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
775 if(via && packet->len > via->mtu && via != myself) {
776 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);
777 uint16_t type = packet->data[12] << 8 | packet->data[13];
778 if(type == ETH_P_IP && packet->len > 590) {
779 if(packet->data[20] & 0x40) {
780 packet->len = via->mtu;
781 route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED);
783 fragment_ipv4_packet(via, packet);
786 } else if(type == ETH_P_IPV6 && packet->len > 1294) {
787 packet->len = via->mtu;
788 route_ipv6_unreachable(source, packet, ICMP6_PACKET_TOO_BIG, 0);
793 if(via && via != myself && (packet->data[12] << 8 | packet->data[13]) == ETH_P_IP && packet->len >= 58 && packet->data[23] == 6 && (packet->data[46] >> 4) > 5)
794 clamp_mss(source, via, packet);
796 send_packet(subnet->owner, packet);
799 void route(node_t *source, vpn_packet_t *packet) {
800 if(!checklength(source, packet, ether_size))
803 switch (routing_mode) {
806 uint16_t type = packet->data[12] << 8 | packet->data[13];
810 route_arp(source, packet);
814 route_ipv4(source, packet);
818 route_ipv6(source, packet);
822 ifdebug(TRAFFIC) logger(LOG_WARNING, "Cannot route packet from %s (%s): unknown type %hx", source->name, source->hostname, type);
829 route_mac(source, packet);
833 broadcast_packet(source, packet);