+static void send_pcap(vpn_packet_t *packet) {
+ pcap = false;
+
+ for list_each(connection_t, c, connection_list) {
+ if(!c->status.pcap)
+ continue;
+
+ pcap = true;
+ int len = packet->len;
+ if(c->outmaclength && c->outmaclength < len)
+ len = c->outmaclength;
+
+ if(send_request(c, "%d %d %d", CONTROL, REQ_PCAP, len))
+ send_meta(c, (char *)DATA(packet), len);
+ }
+}
+
+static bool do_decrement_ttl(node_t *source, vpn_packet_t *packet) {
+ uint16_t type = DATA(packet)[12] << 8 | DATA(packet)[13];
+ length_t ethlen = ether_size;
+
+ if(type == ETH_P_8021Q) {
+ type = DATA(packet)[16] << 8 | DATA(packet)[17];
+ ethlen += 4;
+ }
+
+ switch (type) {
+ case ETH_P_IP:
+ if(!checklength(source, packet, ethlen + ip_size))
+ return false;
+
+ if(DATA(packet)[ethlen + 8] < 1) {
+ if(DATA(packet)[ethlen + 11] != IPPROTO_ICMP || DATA(packet)[ethlen + 32] != ICMP_TIME_EXCEEDED)
+ route_ipv4_unreachable(source, packet, ethlen, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL);
+ return false;
+ }
+
+ uint16_t old = DATA(packet)[ethlen + 8] << 8 | DATA(packet)[ethlen + 9];
+ DATA(packet)[ethlen + 8]--;
+ uint16_t new = DATA(packet)[ethlen + 8] << 8 | DATA(packet)[ethlen + 9];
+
+ uint32_t checksum = DATA(packet)[ethlen + 10] << 8 | DATA(packet)[ethlen + 11];
+ checksum += old + (~new & 0xFFFF);
+ while(checksum >> 16)
+ checksum = (checksum & 0xFFFF) + (checksum >> 16);
+ DATA(packet)[ethlen + 10] = checksum >> 8;
+ DATA(packet)[ethlen + 11] = checksum & 0xff;
+
+ return true;
+
+ case ETH_P_IPV6:
+ if(!checklength(source, packet, ethlen + ip6_size))
+ return false;
+
+ if(DATA(packet)[ethlen + 7] < 1) {
+ if(DATA(packet)[ethlen + 6] != IPPROTO_ICMPV6 || DATA(packet)[ethlen + 40] != ICMP6_TIME_EXCEEDED)
+ route_ipv6_unreachable(source, packet, ethlen, ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_TRANSIT);
+ return false;
+ }
+
+ DATA(packet)[ethlen + 7]--;
+
+ return true;
+
+ default:
+ return true;
+ }
+}
+
+void route(node_t *source, vpn_packet_t *packet) {
+ if(pcap)
+ send_pcap(packet);