Update lwIP to forked and patched version supporting 6PLANE addressing

This commit is contained in:
Joseph Henry
2020-04-17 21:41:24 -07:00
parent 3b0d8e81a0
commit 18fd449c84
3 changed files with 1 additions and 120 deletions

View File

@@ -1,32 +0,0 @@
diff --git a/ports/unix/port/include/arch/cc.h b/ports/unix/port/include/arch/cc.h
index 80b37d8..ed219f3 100644
--- a/ports/unix/port/include/arch/cc.h
+++ b/ports/unix/port/include/arch/cc.h
@@ -32,6 +32,8 @@
#ifndef LWIP_ARCH_CC_H
#define LWIP_ARCH_CC_H
+#include "Debug.hpp" // libzt
+
/* see https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
#if defined __ANDROID__
#define LWIP_UNIX_ANDROID
@@ -65,7 +67,7 @@
#endif
#if defined(LWIP_UNIX_ANDROID) && defined(FD_SET)
-typedef __kernel_fd_set fd_set;
+//typedef __kernel_fd_set fd_set;
#endif
#if defined(LWIP_UNIX_MACH)
@@ -76,6 +78,9 @@ typedef __kernel_fd_set fd_set;
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#endif
+// Comment out the following line to use lwIP's default diagnostic printing routine
+#define LWIP_PLATFORM_DIAG(x) do {DEBUG_INFO x;} while(0)
+
struct sio_status_s;
typedef struct sio_status_s sio_status_t;
#define sio_fd_t sio_status_t*

View File

@@ -1,87 +0,0 @@
diff --git a/src/api/sockets.c b/src/api/sockets.c
index 2d231739..a0c24829 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -38,6 +38,7 @@
*/
#include "lwip/opt.h"
+#include "ZeroTierConstants.h"
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
@@ -281,6 +282,7 @@ static struct lwip_select_cb *select_cb_list;
#define sock_set_errno(sk, e) do { \
const int sockerr = (e); \
set_errno(sockerr); \
+ zts_errno = sockerr; \
} while (0)
/* Forward declaration of some functions */
diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c
index 039b7963..6647c90c 100644
--- a/src/core/ipv6/nd6.c
+++ b/src/core/ipv6/nd6.c
@@ -1644,9 +1644,27 @@ nd6_is_prefix_in_netif(const ip6_addr_t *ip6addr, struct netif *netif)
* addresses (from autoconfiguration) have no implied subnet assignment, and
* are thus effectively /128 assignments. See RFC 5942 for more on this. */
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
- if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
+ /*if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
netif_ip6_addr_isstatic(netif, i) &&
- ip6_addr_netcmp(ip6addr, netif_ip6_addr(netif, i))) {
+ ip6_addr_netcmp(ip6addr, netif_ip6_addr(netif, i))) {*/
+ int prefix_match = 0;
+ if (ip6_addr_is_zt_6plane(ip6addr)) {
+ prefix_match = ip6_addr_6plane_cmp(ip6addr, netif_ip6_addr(netif, i));
+ DEBUG_INFO("6plane, prefix_match=%d", prefix_match);
+ }
+ if (ip6_addr_is_zt_adhoc(ip6addr)) {
+ prefix_match = ip6_addr_adhoc_cmp(ip6addr, netif_ip6_addr(netif, i));
+ DEBUG_INFO("adhoc, prefix_match=%d", prefix_match);
+ }
+ if (ip6_addr_is_zt_rfc4193(ip6addr)) {
+ prefix_match = ip6_addr_rfc4193_cmp(ip6addr, netif_ip6_addr(netif, i));
+ DEBUG_INFO("rfc4193, prefix_match=%d", prefix_match);
+ }
+ if (!prefix_match) {
+ prefix_match = ip6_addr_netcmp(ip6addr, netif_ip6_addr(netif, i));
+ DEBUG_INFO("traditional match, prefix_match=%d", prefix_match);
+ }
+ if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && prefix_match) {
return 1;
}
}
diff --git a/src/include/lwip/ip6_addr.h b/src/include/lwip/ip6_addr.h
index 29c2a34d..205b0e1f 100644
--- a/src/include/lwip/ip6_addr.h
+++ b/src/include/lwip/ip6_addr.h
@@ -160,6 +160,28 @@ typedef struct ip6_addr ip6_addr_t;
#define ip6_addr_netcmp(addr1, addr2) (ip6_addr_netcmp_zoneless((addr1), (addr2)) && \
ip6_addr_cmp_zone((addr1), (addr2)))
+/* Determine if an address *could* be a ZeroTier 6PLANE address */
+#define ip6_addr_is_zt_6plane(addr1) (((addr1)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xfc000000UL))
+
+/* Compare first 40 bits of address (ff + first 32 bits of nwid XOR'd with second 32 bits of nwid) */
+#define ip6_addr_6plane_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
+ ((addr1)->addr[1] & PP_HTONL(0xff000000UL)) == ((addr2)->addr[1] & PP_HTONL(0xff000000UL)))
+
+/* Determine if an address *could* be a ZeroTier Ad-hoc address */
+#define ip6_addr_is_zt_adhoc(addr1) (((addr1)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
+
+/* Compare first 40 bits of address (ff + first 32 bits of nwid XOR'd with second 32 bits of nwid) */
+#define ip6_addr_adhoc_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
+ ((addr1)->addr[1] & PP_HTONL(0xff000000UL)) == ((addr2)->addr[1] & PP_HTONL(0xff000000UL)))
+
+/* Determine if an address *could* be an RFC4193 address */
+#define ip6_addr_is_zt_rfc4193(addr1) (((addr1)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xfd000000UL))
+
+/* Compare first 72 bits of address (fd + 64 bits of nwid) */
+#define ip6_addr_rfc4193_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
+ ((addr1)->addr[1] == (addr2)->addr[1]) && \
+ ((addr1)->addr[2] & PP_HTONL(0xff000000UL)) == ((addr2)->addr[2] & PP_HTONL(0xff000000UL)))
+
/* Exact-host comparison *after* ip6_addr_netcmp() succeeded, for efficiency. */
#define ip6_addr_nethostcmp(addr1, addr2) (((addr1)->addr[2] == (addr2)->addr[2]) && \
((addr1)->addr[3] == (addr2)->addr[3]))