-#ifdef HAVE_LZO
- lzo_uint lzolen = MAXSIZE;
- lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem);
- return lzolen;
-#else
- return -1;
-#endif
- }
-
- return -1;
-}
-
-static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
- if(level == 0) {
- memcpy(dest, source, len);
- return len;
- } else if(level > 9) {
-#ifdef HAVE_LZO
- lzo_uint lzolen = MAXSIZE;
- if(lzo1x_decompress_safe(source, len, dest, &lzolen, NULL) == LZO_E_OK)
- return lzolen;
- else
-#endif
- return -1;
- }
-#ifdef HAVE_ZLIB
- else {
- unsigned long destlen = MAXSIZE;
- if(uncompress(dest, &destlen, source, len) == Z_OK)
- return destlen;
- else
- return -1;
- }
-#endif
-
- return -1;
-}
-
-/* VPN packet I/O */
-
-static void receive_packet(node_t *n, vpn_packet_t *packet) {
- logger(DEBUG_TRAFFIC, LOG_DEBUG, "Received packet of %d bytes from %s (%s)",
- packet->len, n->name, n->hostname);
-
- n->in_packets++;
- n->in_bytes += packet->len;
-
- route(n, packet);
-}
-
-static bool try_mac(node_t *n, const vpn_packet_t *inpkt) {
- if(n->status.sptps)
- return sptps_verify_datagram(&n->sptps, (char *)&inpkt->seqno, inpkt->len);
-
- if(!digest_active(&n->indigest) || inpkt->len < sizeof inpkt->seqno + digest_length(&n->indigest))
- return false;
-
- return digest_verify(&n->indigest, &inpkt->seqno, inpkt->len - n->indigest.maclength, (const char *)&inpkt->seqno + inpkt->len - n->indigest.maclength);
-}
-
-static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
- vpn_packet_t pkt1, pkt2;
- vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
- int nextpkt = 0;
- vpn_packet_t *outpkt = pkt[0];
- size_t outlen;
-
- if(n->status.sptps) {
- sptps_receive_data(&n->sptps, (char *)&inpkt->seqno, inpkt->len);
- return;
- }
-
- if(!cipher_active(&n->incipher)) {
- logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got packet from %s (%s) but he hasn't got our key yet",
- n->name, n->hostname);
- return;
- }
-
- /* Check packet length */