diff --git a/configure.ac b/configure.ac
index 120a8db5..4c5c0560 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,7 @@ AC_PREREQ(2.61)
 AC_INIT([tinc], m4_esyscmd_s((git describe || echo UNKNOWN) | sed 's/release-//'))
 AC_CONFIG_SRCDIR([src/tincd.c])
 AC_GNU_SOURCE
-AM_INIT_AUTOMAKE([info-in-builddir std-options subdir-objects -Wall])
+AM_INIT_AUTOMAKE([std-options subdir-objects -Wall])
 AC_CONFIG_HEADERS([config.h])
 
 # Enable GNU extensions.
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ae43b03..63af709c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,11 +3,11 @@
 sbin_PROGRAMS = tincd tinc sptps_test sptps_keypair
 
 ## Make sure version.c is always rebuilt with the latest git information
-.PHONY: $(srcdir)/version.c version_git.h
+.PHONY: ${srcdir}/version.c version_git.h
 version_git.h:
 	echo >$@
 	-(cd $(srcdir) && git describe) && echo '#define GIT_DESCRIPTION "'`(cd $(srcdir) && git describe) | sed 's/release-//'`'"' >$@
-$(srcdir)/version.c: version_git.h
+${srcdir}/version.c: version_git.h
 
 if LINUX
 sbin_PROGRAMS += sptps_speed
@@ -260,4 +260,4 @@ if TUNEMU
 LIBS += -lpcap
 endif
 
-AM_CFLAGS = -DCONFDIR=\"$(sysconfdir)\" -DLOCALSTATEDIR=\"$(localstatedir)\" -DSBINDIR=\"$(sbindir)\" -I.
+AM_CFLAGS = -DCONFDIR=\"$(sysconfdir)\" -DLOCALSTATEDIR=\"$(localstatedir)\" -DSBINDIR=\"$(sbindir)\" -iquote.
diff --git a/src/ed25519/precomp_data.h b/src/ed25519/precomp_data.h
index 776b84f4..ce59788c 100644
--- a/src/ed25519/precomp_data.h
+++ b/src/ed25519/precomp_data.h
@@ -1388,4 +1388,4 @@ static ge_precomp base[32][8] = {
             { -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 },
         },
     },
-};
\ No newline at end of file
+};
diff --git a/src/ed25519/sc.h b/src/ed25519/sc.h
index 8fa727ef..e29e7fa5 100644
--- a/src/ed25519/sc.h
+++ b/src/ed25519/sc.h
@@ -9,4 +9,4 @@ where l = 2^252 + 27742317777372353535851937790883648493.
 void sc_reduce(unsigned char *s);
 void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c);
 
-#endif
\ No newline at end of file
+#endif
diff --git a/src/meta.c b/src/meta.c
index a05c7bd2..260cb005 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -30,6 +30,10 @@
 #include "utils.h"
 #include "xalloc.h"
 
+#ifndef MIN
+#define MIN(x, y) (((x)<(y))?(x):(y))
+#endif
+
 bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) {
 	connection_t *c = handle;
 
diff --git a/src/net_packet.c b/src/net_packet.c
index f9cec704..e3b9d398 100644
--- a/src/net_packet.c
+++ b/src/net_packet.c
@@ -283,9 +283,8 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
 			}
 			return false;
 		}
-		inpkt->offset += 2 * sizeof(node_id_t);
 		n->status.udppacket = true;
-		bool result = sptps_receive_data(&n->sptps, DATA(inpkt), inpkt->len - 2 * sizeof(node_id_t));
+		bool result = sptps_receive_data(&n->sptps, DATA(inpkt), inpkt->len);
 		n->status.udppacket = false;
 
 		if(!result) {
@@ -1192,15 +1191,13 @@ static void try_tx_sptps(node_t *n, bool mtu) {
 
 	node_t *via = (n->via == myself) ? n->nexthop : n->via;
 
-	/* If the static relay doesn't support SPTPS, everything goes via TCP anyway. */
+	/* If we do have a static relay, try everything with that one instead, if it supports relaying. */
 
-	if((via->options >> 24) < 4)
-		return;
-
-	/* If we do have a static relay, try everything with that one instead. */
-
-	if(via != n)
+	if(via != n) {
+		if((via->options >> 24) < 4)
+			return;
 		return try_tx_sptps(via, mtu);
+	}
 
 	/* Otherwise, try to establish UDP connectivity. */
 
@@ -1351,7 +1348,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) {
 		if(!n->status.reachable || n == myself)
 			continue;
 
-		if((n->status.sptps && !n->sptps.instate) || !n->status.validkey_in)
+		if(!n->status.validkey_in && !(n->status.sptps && n->sptps.instate))
 			continue;
 
 		bool soft = false;
@@ -1441,10 +1438,16 @@ skip_harder:
 		return;
 	}
 
-	if(n->status.sptps) {
-		pkt.offset = 2 * sizeof(node_id_t);
+	pkt.offset = 0;
 
-		if(!memcmp(DSTID(&pkt), &nullid, sizeof nullid)) {
+	if(n->status.sptps) {
+		bool relay_enabled = (n->options >> 24) >= 4;
+		if (relay_enabled) {
+			pkt.offset = 2 * sizeof(node_id_t);
+			pkt.len -= pkt.offset;
+		}
+
+		if(!memcmp(DSTID(&pkt), &nullid, sizeof nullid) || !relay_enabled) {
 			direct = true;
 			from = n;
 			to = myself;
@@ -1469,7 +1472,7 @@ skip_harder:
 		/* If we're not the final recipient, relay the packet. */
 
 		if(to != myself) {
-			send_sptps_data(to, from, 0, DATA(&pkt), pkt.len - 2 * sizeof(node_id_t));
+			send_sptps_data(to, from, 0, DATA(&pkt), pkt.len);
 			try_tx_sptps(to, true);
 			return;
 		}
@@ -1478,7 +1481,6 @@ skip_harder:
 		from = n;
 	}
 
-	pkt.offset = 0;
 	if(!receive_udppacket(from, &pkt))
 		return;
 
diff --git a/src/protocol_misc.c b/src/protocol_misc.c
index 25433985..47f4aef0 100644
--- a/src/protocol_misc.c
+++ b/src/protocol_misc.c
@@ -30,6 +30,10 @@
 #include "utils.h"
 #include "xalloc.h"
 
+#ifndef MIN
+#define MIN(x, y) (((x)<(y))?(x):(y))
+#endif
+
 int maxoutbufsize = 0;
 int mtu_info_interval = 5;
 int udp_info_interval = 5;
diff --git a/test/invite-join.test b/test/invite-join.test
index dbe6f8ae..c1bd1b8e 100755
--- a/test/invite-join.test
+++ b/test/invite-join.test
@@ -24,7 +24,7 @@ $tinc $c1 invite bar | $tinc $c2 join
 # Test equivalence of host config files
 
 cmp $d1/hosts/foo $d2/hosts/foo
-test "`grep ^ECDSAPublicKey $d1/hosts/bar`" = "`grep ^ECDSAPublicKey $d2/hosts/bar`"
+test "`grep ^Ed25519PublicKey $d1/hosts/bar`" = "`grep ^Ed25519PublicKey $d2/hosts/bar`"
 
 # Test Mode, Broadcast and ConnectTo statements