#include "system.h"
#ifdef HAVE_ZLIB
+#define ZLIB_CONST
#include <zlib.h>
#endif
#include LZO1X_H
#endif
+#include "address_cache.h"
#include "cipher.h"
#include "conf.h"
#include "connection.h"
static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
if(!DATA(packet)[0]) {
logger(DEBUG_TRAFFIC, LOG_INFO, "Got UDP probe request %d from %s (%s)", packet->len, n->name, n->hostname);
- return send_udp_probe_reply(n, packet, len);
+ send_udp_probe_reply(n, packet, len);
+ return;
}
if(DATA(packet)[0] == 2) {
/* It's a valid reply: now we know bidirectional communication
is possible using the address and socket that the reply
packet used. */
- n->status.udp_confirmed = true;
+ if(!n->status.udp_confirmed) {
+ n->status.udp_confirmed = true;
+ fprintf(stderr, "Updating address cache...\n");
+
+ if(!n->address_cache) {
+ n->address_cache = open_address_cache(n);
+ }
+
+ reset_address_cache(n->address_cache, &n->address);
+ }
// Reset the UDP ping timer.
n->udp_ping_sent = now;
#ifdef HAVE_ZLIB
else {
unsigned long destlen = MAXSIZE;
+ static z_stream stream;
- if(uncompress(dest, &destlen, source, len) == Z_OK) {
- return destlen;
+ if(stream.next_in) {
+ inflateReset(&stream);
+ } else {
+ inflateInit(&stream);
+ }
+
+ stream.next_in = source;
+ stream.avail_in = len;
+ stream.next_out = dest;
+ stream.avail_out = destlen;
+ stream.total_out = 0;
+
+ if(inflate(&stream, Z_FINISH) == Z_STREAM_END) {
+ return stream.total_out;
} else {
return -1;
}
}
if(n->status.sptps) {
- return send_sptps_packet(n, origpkt);
+ send_sptps_packet(n, origpkt);
+ return;
}
#ifdef DISABLE_LEGACY
if(relay_supported) {
if(direct) {
/* Inform the recipient that this packet was sent directly. */
- node_id_t nullid = {};
+ node_id_t nullid = {{0}};
memcpy(buf_ptr, &nullid, sizeof(nullid));
buf_ptr += sizeof(nullid);
} else {
if(!from->status.validkey) {
from->status.validkey = true;
from->status.waitingforkey = false;
- logger(DEBUG_META, LOG_INFO, "SPTPS key exchange with %s (%s) succesful", from->name, from->hostname);
+ logger(DEBUG_META, LOG_INFO, "SPTPS key exchange with %s (%s) successful", from->name, from->hostname);
}
return true;
return;
}
- return try_tx(via, mtu);
+ try_tx(via, mtu);
+ return;
}
/* Otherwise, try to establish UDP connectivity. */
static void handle_incoming_vpn_packet(listen_socket_t *ls, vpn_packet_t *pkt, sockaddr_t *addr) {
char *hostname;
- node_id_t nullid = {};
+ node_id_t nullid = {{0}};
node_t *from, *to;
bool direct = false;