18 changed files with 1125 additions and 781 deletions
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere |
||||
* Copyright (C) 2011-2019 ZeroTier, Inc. https://www.zerotier.com/
|
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* |
||||
* -- |
||||
* |
||||
* You can be released from the requirements of the license by purchasing |
||||
* a commercial license. Buying such a license is mandatory as soon as you |
||||
* develop commercial closed-source software that incorporates or links |
||||
* directly against ZeroTier software without disclosing the source code |
||||
* of your own application. |
||||
*/ |
||||
|
||||
/**
|
||||
* @file |
||||
* |
||||
* Common constants used throughout the SDK |
||||
*/ |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control API error codes //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Everything is ok
|
||||
#define ZTS_ERR_OK 0 |
||||
// A argument provided by the user application is invalid (e.g. out of range, NULL, etc)
|
||||
#define ZTS_ERR_INVALID_ARG -1 |
||||
// The service isn't initialized or is for some reason currently unavailable. Try again.
|
||||
#define ZTS_ERR_SERVICE -2 |
||||
// For some reason this API operation is not permitted or doesn't make sense at this time.
|
||||
#define ZTS_ERR_INVALID_OP -3 |
||||
// The call succeeded, but no object or relevant result was available
|
||||
#define ZTS_ERR_NO_RESULT -4 |
||||
|
||||
/**
|
||||
* The system port upon which ZT traffic is sent and received |
||||
*/ |
||||
#define ZTS_DEFAULT_PORT 9994 |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Control API event codes //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ZTS_EVENT_NONE -1 |
||||
#define ZTS_EVENT_NODE_UP 0 |
||||
// Standard node events
|
||||
#define ZTS_EVENT_NODE_OFFLINE 1 |
||||
#define ZTS_EVENT_NODE_ONLINE 2 |
||||
#define ZTS_EVENT_NODE_DOWN 3 |
||||
#define ZTS_EVENT_NODE_IDENTITY_COLLISION 4 |
||||
#define ZTS_EVENT_NODE_UNRECOVERABLE_ERROR 16 |
||||
#define ZTS_EVENT_NODE_NORMAL_TERMINATION 17 |
||||
// Network events
|
||||
#define ZTS_EVENT_NETWORK_NOT_FOUND 32 |
||||
#define ZTS_EVENT_NETWORK_CLIENT_TOO_OLD 33 |
||||
#define ZTS_EVENT_NETWORK_REQUESTING_CONFIG 34 |
||||
#define ZTS_EVENT_NETWORK_OK 35 |
||||
#define ZTS_EVENT_NETWORK_ACCESS_DENIED 36 |
||||
#define ZTS_EVENT_NETWORK_READY_IP4 37 |
||||
#define ZTS_EVENT_NETWORK_READY_IP6 38 |
||||
#define ZTS_EVENT_NETWORK_READY_IP4_IP6 39 |
||||
#define ZTS_EVENT_NETWORK_DOWN 40 |
||||
// Network Stack events
|
||||
#define ZTS_EVENT_STACK_UP 48 |
||||
#define ZTS_EVENT_STACK_DOWN 49 |
||||
// lwIP netif events
|
||||
#define ZTS_EVENT_NETIF_UP 64 |
||||
#define ZTS_EVENT_NETIF_DOWN 65 |
||||
#define ZTS_EVENT_NETIF_REMOVED 66 |
||||
#define ZTS_EVENT_NETIF_LINK_UP 67 |
||||
#define ZTS_EVENT_NETIF_LINK_DOWN 68 |
||||
// Peer events
|
||||
#define ZTS_EVENT_PEER_P2P 96 |
||||
#define ZTS_EVENT_PEER_RELAY 97 |
||||
#define ZTS_EVENT_PEER_UNREACHABLE 98 |
||||
// Path events
|
||||
#define ZTS_EVENT_PATH_DISCOVERED 112 |
||||
#define ZTS_EVENT_PATH_ALIVE 113 |
||||
#define ZTS_EVENT_PATH_DEAD 114 |
||||
// Route events
|
||||
#define ZTS_EVENT_ROUTE_ADDED 128 |
||||
#define ZTS_EVENT_ROUTE_REMOVED 129 |
||||
// Address events
|
||||
#define ZTS_EVENT_ADDR_ADDED_IP4 144 |
||||
#define ZTS_EVENT_ADDR_REMOVED_IP4 145 |
||||
#define ZTS_EVENT_ADDR_ADDED_IP6 146 |
||||
#define ZTS_EVENT_ADDR_REMOVED_IP6 147 |
||||
|
||||
// Macros for legacy behaviour
|
||||
#define NODE_EVENT_TYPE(code) code >= ZTS_EVENT_NODE_UP && code <= ZTS_EVENT_NODE_NORMAL_TERMINATION |
||||
#define NETWORK_EVENT_TYPE(code) code >= ZTS_EVENT_NETWORK_NOT_FOUND && code <= ZTS_EVENT_NETWORK_DOWN |
||||
#define STACK_EVENT_TYPE(code) code >= ZTS_EVENT_STACK_UP && code <= ZTS_EVENT_STACK_DOWN |
||||
#define NETIF_EVENT_TYPE(code) code >= ZTS_EVENT_NETIF_UP && code <= ZTS_EVENT_NETIF_LINK_DOWN |
||||
#define PEER_EVENT_TYPE(code) code >= ZTS_EVENT_PEER_P2P && code <= ZTS_EVENT_PEER_UNREACHABLE |
||||
#define PATH_EVENT_TYPE(code) code >= ZTS_EVENT_PATH_DISCOVERED && code <= ZTS_EVENT_PATH_DEAD |
||||
#define ROUTE_EVENT_TYPE(code) code >= ZTS_EVENT_ROUTE_ADDED && code <= ZTS_EVENT_ROUTE_REMOVED |
||||
#define ADDR_EVENT_TYPE(code) code >= ZTS_EVENT_ADDR_ADDED_IP4 && code <= ZTS_EVENT_ADDR_REMOVED_IP6 |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Common definitions and structures for interacting with the ZT socket API //
|
||||
// This is a subset of lwip/sockets.h, lwip/arch.h, and lwip/inet.h //
|
||||
// //
|
||||
// These re-definitions exist here so that the user application's usage //
|
||||
// of the API is internally consistent with the underlying network stack. //
|
||||
// They have an attached prefix so that they can co-exist with the native //
|
||||
// platform's own definitions and structures. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Socket protocol types
|
||||
#define ZTS_SOCK_STREAM 0x0001 |
||||
#define ZTS_SOCK_DGRAM 0x0002 |
||||
#define ZTS_SOCK_RAW 0x0003 |
||||
// Socket family types
|
||||
#define ZTS_AF_UNSPEC 0x0000 |
||||
#define ZTS_AF_INET 0x0002 |
||||
#define ZTS_AF_INET6 0x000a |
||||
#define ZTS_PF_INET ZTS_AF_INET |
||||
#define ZTS_PF_INET6 ZTS_AF_INET6 |
||||
#define ZTS_PF_UNSPEC ZTS_AF_UNSPEC |
||||
// Protocol command types
|
||||
#define ZTS_IPPROTO_IP 0x0000 |
||||
#define ZTS_IPPROTO_ICMP 0x0001 |
||||
#define ZTS_IPPROTO_TCP 0x0006 |
||||
#define ZTS_IPPROTO_UDP 0x0011 |
||||
#define ZTS_IPPROTO_IPV6 0x0029 |
||||
#define ZTS_IPPROTO_ICMPV6 0x003a |
||||
#define ZTS_IPPROTO_UDPLITE 0x0088 |
||||
#define ZTS_IPPROTO_RAW 0x00ff |
||||
// send() and recv() flags
|
||||
#define ZTS_MSG_PEEK 0x0001 |
||||
#define ZTS_MSG_WAITALL 0x0002 // NOT YET SUPPORTED
|
||||
#define ZTS_MSG_OOB 0x0004 // NOT YET SUPPORTED
|
||||
#define ZTS_MSG_DONTWAIT 0x0008 |
||||
#define ZTS_MSG_MORE 0x0010 |
||||
// fnctl() commands
|
||||
#define ZTS_F_GETFL 0x0003 |
||||
#define ZTS_F_SETFL 0x0004 |
||||
// fnctl() flags
|
||||
#define ZTS_O_NONBLOCK 0x0001 |
||||
#define ZTS_O_NDELAY 0x0001 |
||||
// Shutdown commands
|
||||
#define ZTS_SHUT_RD 0x0000 |
||||
#define ZTS_SHUT_WR 0x0001 |
||||
#define ZTS_SHUT_RDWR 0x0002 |
||||
// Socket level option number
|
||||
#define ZTS_SOL_SOCKET 0x0fff |
||||
// Socket options
|
||||
#define ZTS_SO_DEBUG 0x0001 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_ACCEPTCONN 0x0002 |
||||
#define ZTS_SO_REUSEADDR 0x0004 |
||||
#define ZTS_SO_KEEPALIVE 0x0008 |
||||
#define ZTS_SO_DONTROUTE 0x0010 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_BROADCAST 0x0020 |
||||
#define ZTS_SO_USELOOPBACK 0x0040 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_LINGER 0x0080 |
||||
#define ZTS_SO_DONTLINGER ((int)(~ZTS_SO_LINGER)) |
||||
#define ZTS_SO_OOBINLINE 0x0100 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_REUSEPORT 0x0200 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_SNDBUF 0x1001 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_RCVBUF 0x1002 |
||||
#define ZTS_SO_SNDLOWAT 0x1003 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_RCVLOWAT 0x1004 // NOT YET SUPPORTED
|
||||
#define ZTS_SO_SNDTIMEO 0x1005 |
||||
#define ZTS_SO_RCVTIMEO 0x1006 |
||||
#define ZTS_SO_ERROR 0x1007 |
||||
#define ZTS_SO_TYPE 0x1008 |
||||
#define ZTS_SO_CONTIMEO 0x1009 |
||||
#define ZTS_SO_NO_CHECK 0x100a |
||||
// IPPROTO_IP options
|
||||
#define ZTS_IP_TOS 0x0001 |
||||
#define ZTS_IP_TTL 0x0002 |
||||
// IPPROTO_TCP options
|
||||
#define ZTS_TCP_NODELAY 0x0001 |
||||
#define ZTS_TCP_KEEPALIVE 0x0002 |
||||
#define ZTS_TCP_KEEPIDLE 0x0003 |
||||
#define ZTS_TCP_KEEPINTVL 0x0004 |
||||
#define ZTS_TCP_KEEPCNT 0x0005 |
||||
// IPPROTO_IPV6 options
|
||||
#define ZTS_IPV6_CHECKSUM 0x0007 // RFC3542
|
||||
#define ZTS_IPV6_V6ONLY 0x001b // RFC3493
|
||||
// Macro's for defining ioctl() command values
|
||||
#define ZTS_IOCPARM_MASK 0x7fU |
||||
#define ZTS_IOC_VOID 0x20000000UL |
||||
#define ZTS_IOC_OUT 0x40000000UL |
||||
#define ZTS_IOC_IN 0x80000000UL |
||||
#define ZTS_IOC_INOUT (ZTS_IOC_IN | ZTS_IOC_OUT) |
||||
#define ZTS_IO(x,y) (ZTS_IOC_VOID | ((x)<<8)|(y)) |
||||
#define ZTS_IOR(x,y,t) (ZTS_IOC_OUT | (((long)sizeof(t) & ZTS_IOCPARM_MASK)<<16) | ((x)<<8) | (y)) |
||||
#define ZTS_IOW(x,y,t) (ZTS_IOC_IN | (((long)sizeof(t) & ZTS_IOCPARM_MASK)<<16) | ((x)<<8) | (y)) |
||||
// ioctl() commands
|
||||
#define ZTS_FIONREAD ZTS_IOR('f', 127, unsigned long) |
||||
#define ZTS_FIONBIO ZTS_IOW('f', 126, unsigned long) |
||||
|
||||
/* FD_SET used for lwip_select */ |
||||
|
||||
#ifndef ZTS_FD_SET |
||||
#undef ZTS_FD_SETSIZE |
||||
// Make FD_SETSIZE match NUM_SOCKETS in socket.c
|
||||
#define ZTS_FD_SETSIZE MEMP_NUM_NETCONN |
||||
#define ZTS_FDSETSAFESET(n, code) do { \ |
||||
if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
|
||||
code; }} while(0) |
||||
#define ZTS_FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ |
||||
(code) : 0) |
||||
#define ZTS_FD_SET(n, p) ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) |
||||
#define ZTS_FD_CLR(n, p) ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) |
||||
#define ZTS_FD_ISSET(n,p) ZTS_FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) |
||||
#define ZTS_FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) |
||||
|
||||
#elif LWIP_SOCKET_OFFSET |
||||
#error LWIP_SOCKET_OFFSET does not work with external FD_SET! |
||||
#elif ZTS_FD_SETSIZE < MEMP_NUM_NETCONN |
||||
#error "external ZTS_FD_SETSIZE too small for number of sockets" |
||||
#endif // FD_SET
|
||||
|
||||
//#if defined(_USING_LWIP_DEFINITIONS_)
|
||||
@ -0,0 +1,37 @@
|
||||
License for: include/net/route.h |
||||
|
||||
/* |
||||
* Copyright (c) 1980, 1986, 1993 |
||||
* The Regents of the University of California. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* This product includes software developed by the University of |
||||
* California, Berkeley and its contributors. |
||||
* 4. Neither the name of the University nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* @(#)route.h 8.3 (Berkeley) 4/19/94 |
||||
* $FreeBSD: src/sys/net/route.h,v 1.36.2.1 2000/08/16 06:14:23 jayanth Exp $ |
||||
*/ |
||||
@ -0,0 +1,29 @@
|
||||
License for: include/net/route.h |
||||
|
||||
/* |
||||
* Copyright (c) 2000-2017 Apple Inc. All rights reserved. |
||||
* |
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
||||
* |
||||
* This file contains Original Code and/or Modifications of Original Code |
||||
* as defined in and that are subject to the Apple Public Source License |
||||
* Version 2.0 (the 'License'). You may not use this file except in |
||||
* compliance with the License. The rights granted to you under the License |
||||
* may not be used to create, or enable the creation or redistribution of, |
||||
* unlawful or unlicensed copies of an Apple operating system, or to |
||||
* circumvent, violate, or enable the circumvention or violation of, any |
||||
* terms of an Apple operating system software license agreement. |
||||
* |
||||
* Please obtain a copy of the License at |
||||
* http://www.opensource.apple.com/apsl/ and read it before using this file. |
||||
* |
||||
* The Original Code and all software distributed under the License are |
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
||||
* Please see the License for the specific language governing rights and |
||||
* limitations under the License. |
||||
* |
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
||||
*/ |
||||
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2017 Apple Inc. All rights reserved. |
||||
* |
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
||||
* |
||||
* This file contains Original Code and/or Modifications of Original Code |
||||
* as defined in and that are subject to the Apple Public Source License |
||||
* Version 2.0 (the 'License'). You may not use this file except in |
||||
* compliance with the License. The rights granted to you under the License |
||||
* may not be used to create, or enable the creation or redistribution of, |
||||
* unlawful or unlicensed copies of an Apple operating system, or to |
||||
* circumvent, violate, or enable the circumvention or violation of, any |
||||
* terms of an Apple operating system software license agreement. |
||||
* |
||||
* Please obtain a copy of the License at |
||||
* http://www.opensource.apple.com/apsl/ and read it before using this file.
|
||||
* |
||||
* The Original Code and all software distributed under the License are |
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
||||
* Please see the License for the specific language governing rights and |
||||
* limitations under the License. |
||||
* |
||||
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
||||
*/ |
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993 |
||||
* The Regents of the University of California. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* 3. All advertising materials mentioning features or use of this software |
||||
* must display the following acknowledgement: |
||||
* This product includes software developed by the University of |
||||
* California, Berkeley and its contributors. |
||||
* 4. Neither the name of the University nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
* |
||||
* @(#)route.h 8.3 (Berkeley) 4/19/94 |
||||
* $FreeBSD: src/sys/net/route.h,v 1.36.2.1 2000/08/16 06:14:23 jayanth Exp $ |
||||
*/ |
||||
|
||||
#ifndef _NET_ROUTE_H_ |
||||
#define _NET_ROUTE_H_ |
||||
#include <sys/appleapiopts.h> |
||||
#include <stdint.h> |
||||
#include <sys/types.h> |
||||
#include <sys/socket.h> |
||||
|
||||
/*
|
||||
* These numbers are used by reliable protocols for determining |
||||
* retransmission behavior and are included in the routing structure. |
||||
*/ |
||||
struct rt_metrics { |
||||
u_int32_t rmx_locks; /* Kernel leaves these values alone */ |
||||
u_int32_t rmx_mtu; /* MTU for this path */ |
||||
u_int32_t rmx_hopcount; /* max hops expected */ |
||||
int32_t rmx_expire; /* lifetime for route, e.g. redirect */ |
||||
u_int32_t rmx_recvpipe; /* inbound delay-bandwidth product */ |
||||
u_int32_t rmx_sendpipe; /* outbound delay-bandwidth product */ |
||||
u_int32_t rmx_ssthresh; /* outbound gateway buffer limit */ |
||||
u_int32_t rmx_rtt; /* estimated round trip time */ |
||||
u_int32_t rmx_rttvar; /* estimated rtt variance */ |
||||
u_int32_t rmx_pksent; /* packets sent using this route */ |
||||
u_int32_t rmx_state; /* route state */ |
||||
u_int32_t rmx_filler[3]; /* will be used for T/TCP later */ |
||||
}; |
||||
|
||||
/*
|
||||
* rmx_rtt and rmx_rttvar are stored as microseconds; |
||||
*/ |
||||
#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ |
||||
|
||||
|
||||
|
||||
#define RTF_UP 0x1 /* route usable */ |
||||
#define RTF_GATEWAY 0x2 /* destination is a gateway */ |
||||
#define RTF_HOST 0x4 /* host entry (net otherwise) */ |
||||
#define RTF_REJECT 0x8 /* host or net unreachable */ |
||||
#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ |
||||
#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ |
||||
#define RTF_DONE 0x40 /* message confirmed */ |
||||
#define RTF_DELCLONE 0x80 /* delete cloned route */ |
||||
#define RTF_CLONING 0x100 /* generate new routes on use */ |
||||
#define RTF_XRESOLVE 0x200 /* external daemon resolves name */ |
||||
#define RTF_LLINFO 0x400 /* DEPRECATED - exists ONLY for backward |
||||
compatibility */ |
||||
#define RTF_LLDATA 0x400 /* used by apps to add/del L2 entries */ |
||||
#define RTF_STATIC 0x800 /* manually added */ |
||||
#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */ |
||||
#define RTF_NOIFREF 0x2000 /* not eligible for RTF_IFREF */ |
||||
#define RTF_PROTO2 0x4000 /* protocol specific routing flag */ |
||||
#define RTF_PROTO1 0x8000 /* protocol specific routing flag */ |
||||
|
||||
#define RTF_PRCLONING 0x10000 /* protocol requires cloning */ |
||||
#define RTF_WASCLONED 0x20000 /* route generated through cloning */ |
||||
#define RTF_PROTO3 0x40000 /* protocol specific routing flag */ |
||||
/* 0x80000 unused */ |
||||
#define RTF_PINNED 0x100000 /* future use */ |
||||
#define RTF_LOCAL 0x200000 /* route represents a local address */ |
||||
#define RTF_BROADCAST 0x400000 /* route represents a bcast address */ |
||||
#define RTF_MULTICAST 0x800000 /* route represents a mcast address */ |
||||
#define RTF_IFSCOPE 0x1000000 /* has valid interface scope */ |
||||
#define RTF_CONDEMNED 0x2000000 /* defunct; no longer modifiable */ |
||||
#define RTF_IFREF 0x4000000 /* route holds a ref to interface */ |
||||
#define RTF_PROXY 0x8000000 /* proxying, no interface scope */ |
||||
#define RTF_ROUTER 0x10000000 /* host is a router */ |
||||
#define RTF_DEAD 0x20000000 /* Route entry is being freed */ |
||||
/* 0x40000000 and up unassigned */ |
||||
|
||||
#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */ |
||||
#define RTF_BITS \ |
||||
"\020\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE" \
|
||||
"\10DELCLONE\11CLONING\12XRESOLVE\13LLINFO\14STATIC\15BLACKHOLE" \
|
||||
"\16NOIFREF\17PROTO2\20PROTO1\21PRCLONING\22WASCLONED\23PROTO3" \
|
||||
"\25PINNED\26LOCAL\27BROADCAST\30MULTICAST\31IFSCOPE\32CONDEMNED" \
|
||||
"\33IFREF\34PROXY\35ROUTER" |
||||
|
||||
#define IS_DIRECT_HOSTROUTE(rt) \ |
||||
(((rt)->rt_flags & (RTF_HOST | RTF_GATEWAY)) == RTF_HOST) |
||||
/*
|
||||
* Routing statistics. |
||||
*/ |
||||
struct rtstat { |
||||
short rts_badredirect; /* bogus redirect calls */ |
||||
short rts_dynamic; /* routes created by redirects */ |
||||
short rts_newgateway; /* routes modified by redirects */ |
||||
short rts_unreach; /* lookups which failed */ |
||||
short rts_wildcard; /* lookups satisfied by a wildcard */ |
||||
short rts_badrtgwroute; /* route to gateway is not direct */ |
||||
}; |
||||
|
||||
/*
|
||||
* Structures for routing messages. |
||||
*/ |
||||
struct rt_msghdr { |
||||
u_short rtm_msglen; /* to skip over non-understood messages */ |
||||
u_char rtm_version; /* future binary compatibility */ |
||||
u_char rtm_type; /* message type */ |
||||
u_short rtm_index; /* index for associated ifp */ |
||||
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ |
||||
int rtm_addrs; /* bitmask identifying sockaddrs in msg */ |
||||
pid_t rtm_pid; /* identify sender */ |
||||
int rtm_seq; /* for sender to identify action */ |
||||
int rtm_errno; /* why failed */ |
||||
int rtm_use; /* from rtentry */ |
||||
u_int32_t rtm_inits; /* which metrics we are initializing */ |
||||
struct rt_metrics rtm_rmx; /* metrics themselves */ |
||||
}; |
||||
|
||||
struct rt_msghdr2 { |
||||
u_short rtm_msglen; /* to skip over non-understood messages */ |
||||
u_char rtm_version; /* future binary compatibility */ |
||||
u_char rtm_type; /* message type */ |
||||
u_short rtm_index; /* index for associated ifp */ |
||||
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ |
||||
int rtm_addrs; /* bitmask identifying sockaddrs in msg */ |
||||
int32_t rtm_refcnt; /* reference count */ |
||||
int rtm_parentflags; /* flags of the parent route */ |
||||
int rtm_reserved; /* reserved field set to 0 */ |
||||
int rtm_use; /* from rtentry */ |
||||
u_int32_t rtm_inits; /* which metrics we are initializing */ |
||||
struct rt_metrics rtm_rmx; /* metrics themselves */ |
||||
}; |
||||
|
||||
|
||||
#define RTM_VERSION 5 /* Up the ante and ignore older versions */ |
||||
|
||||
/*
|
||||
* Message types. |
||||
*/ |
||||
#define RTM_ADD 0x1 /* Add Route */ |
||||
#define RTM_DELETE 0x2 /* Delete Route */ |
||||
#define RTM_CHANGE 0x3 /* Change Metrics or flags */ |
||||
#define RTM_GET 0x4 /* Report Metrics */ |
||||
#define RTM_LOSING 0x5 /* RTM_LOSING is no longer generated by xnu |
||||
and is deprecated */ |
||||
#define RTM_REDIRECT 0x6 /* Told to use different route */ |
||||
#define RTM_MISS 0x7 /* Lookup failed on this address */ |
||||
#define RTM_LOCK 0x8 /* fix specified metrics */ |
||||
#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ |
||||
#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ |
||||
#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ |
||||
#define RTM_NEWADDR 0xc /* address being added to iface */ |
||||
#define RTM_DELADDR 0xd /* address being removed from iface */ |
||||
#define RTM_IFINFO 0xe /* iface going up/down etc. */ |
||||
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */ |
||||
#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */ |
||||
#define RTM_IFINFO2 0x12 /* */ |
||||
#define RTM_NEWMADDR2 0x13 /* */ |
||||
#define RTM_GET2 0x14 /* */ |
||||
|
||||
/*
|
||||
* Bitmask values for rtm_inits and rmx_locks. |
||||
*/ |
||||
#define RTV_MTU 0x1 /* init or lock _mtu */ |
||||
#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ |
||||
#define RTV_EXPIRE 0x4 /* init or lock _expire */ |
||||
#define RTV_RPIPE 0x8 /* init or lock _recvpipe */ |
||||
#define RTV_SPIPE 0x10 /* init or lock _sendpipe */ |
||||
#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ |
||||
#define RTV_RTT 0x40 /* init or lock _rtt */ |
||||
#define RTV_RTTVAR 0x80 /* init or lock _rttvar */ |
||||
|
||||
/*
|
||||
* Bitmask values for rtm_addrs. |
||||
*/ |
||||
#define RTA_DST 0x1 /* destination sockaddr present */ |
||||
#define RTA_GATEWAY 0x2 /* gateway sockaddr present */ |
||||
#define RTA_NETMASK 0x4 /* netmask sockaddr present */ |
||||
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ |
||||
#define RTA_IFP 0x10 /* interface name sockaddr present */ |
||||
#define RTA_IFA 0x20 /* interface addr sockaddr present */ |
||||
#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ |
||||
#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */ |
||||
|
||||
/*
|
||||
* Index offsets for sockaddr array for alternate internal encoding. |
||||
*/ |
||||
#define RTAX_DST 0 /* destination sockaddr present */ |
||||
#define RTAX_GATEWAY 1 /* gateway sockaddr present */ |
||||
#define RTAX_NETMASK 2 /* netmask sockaddr present */ |
||||
#define RTAX_GENMASK 3 /* cloning mask sockaddr present */ |
||||
#define RTAX_IFP 4 /* interface name sockaddr present */ |
||||
#define RTAX_IFA 5 /* interface addr sockaddr present */ |
||||
#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */ |
||||
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */ |
||||
#define RTAX_MAX 8 /* size of array to allocate */ |
||||
|
||||
struct rt_addrinfo { |
||||
int rti_addrs; |
||||
struct sockaddr *rti_info[RTAX_MAX]; |
||||
}; |
||||
|
||||
|
||||
#endif /* _NET_ROUTE_H_ */ |
||||
@ -1,7 +0,0 @@
|
||||
#!/bin/bash |
||||
|
||||
rm -rf bin build products tmp |
||||
rm -f *.o *.s *.exp *.lib .depend* *.core core |
||||
rm -rf .depend |
||||
find . -type f \( -name '*.o' -o -name '*.o.d' -o -name \ |
||||
'*.out' -o -name '*.log' -o -name '*.dSYM' -o -name '*.class' \) -delete |
||||
@ -1,184 +1,258 @@
|
||||
#!/bin/bash |
||||
|
||||
# Call this script from the root project directory via `make dist` |
||||
# - submodules will be recursively initialized and updated |
||||
# - patches will be applied to submodules if needed |
||||
# - this script will call CMake to generate library-building packages if necessary |
||||
# - once projects have been generated, this script will use their tooling to build the libraries/packages |
||||
# - when all products have been built and moved to `tmp`, they will be compressed and moved to `products` |
||||
# This script works in conjunction with the Makefile and CMakeLists.txt. It is |
||||
# intented to be called from the Makefile, it generates projects and builds |
||||
# targets as specified in CMakeLists.txt. This script is also responsible for |
||||
# packaging all of the resultant builds, licenses, and documentation. |
||||
|
||||
BUILD_CONCURRENCY= |
||||
#"-j 2" |
||||
OSNAME=$(uname | tr '[A-Z]' '[a-z]') |
||||
BUILD_CONCURRENCY=4 |
||||
PROJROOT=$(pwd) |
||||
BUILD_PRODUCTS_DIR=$(pwd)/bin |
||||
LIB_PRODUCTS_DIR=$BUILD_PRODUCTS_DIR/lib |
||||
FINISHED_PRODUCTS_DIR=$(pwd)/products |
||||
STAGING_DIR=$(pwd)/staging |
||||
# Windows (previously built) |
||||
WIN_PREBUILT_DIR=$PROJROOT/staging/win |
||||
WIN_RELEASE_PRODUCTS_DIR=$WIN_PREBUILT_DIR/release |
||||
WIN_DEBUG_PRODUCTS_DIR=$WIN_PREBUILT_DIR/debug |
||||
WIN32_RELEASE_PRODUCTS_DIR=$WIN_RELEASE_PRODUCTS_DIR/win32 |
||||
WIN64_RELEASE_PRODUCTS_DIR=$WIN_RELEASE_PRODUCTS_DIR/win64 |
||||
WIN32_DEBUG_PRODUCTS_DIR=$WIN_DEBUG_PRODUCTS_DIR/win32 |
||||
WIN64_DEBUG_PRODUCTS_DIR=$WIN_DEBUG_PRODUCTS_DIR/win64 |
||||
# Linux |
||||
LINUX_PROD_DIR=$PROJROOT/staging/linux |
||||
# macOS |
||||
MACOS_PROD_DIR=$PROJROOT/staging/macos |
||||
MACOS_RELEASE_PROD_DIR=$MACOS_PROD_DIR/release |
||||
MACOS_DEBUG_PROD_DIR=$MACOS_PROD_DIR/debug |
||||
# iOS |
||||
IOS_PROD_DIR=$PROJROOT/staging/ios |
||||
# Android |
||||
ANDROID_PROJ_DIR=$(pwd)/"ports/android" |
||||
ANDROID_ARCHIVE_FILENAME="zt.aar" |
||||
# Xcode |
||||
XCODE_IOS_PROJ_DIR=$(pwd)/"ports/xcode_ios" |
||||
XCODE_MACOS_PROJ_DIR=$(pwd)/"ports/xcode_macos" |
||||
BUILD_TMP=$(pwd)/tmp |
||||
ANDROID_PROJ_DIR=$(pwd)/ports/android |
||||
XCODE_IOS_ARM64_PROJ_DIR=$(pwd)/ports/xcode_ios-arm64 |
||||
#XCODE_IOS_ARMV7_PROJ_DIR=$(pwd)/ports/xcode_ios-armv7 |
||||
XCODE_MACOS_PROJ_DIR=$(pwd)/ports/xcode_macos |
||||
|
||||
mkdir $FINISHED_PRODUCTS_DIR |
||||
mkdir $STAGING_DIR |
||||
|
||||
# Check that projects exist, generate them and exit if they don't exist |
||||
generate_projects_if_necessary() |
||||
# Generates projects if needed |
||||
generate_projects() |
||||
{ |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
# iOS |
||||
if [ ! -d "$XCODE_IOS_PROJ_DIR" ]; then |
||||
echo "BUILDING: iOS project" |
||||
should_exit=1 |
||||
mkdir -p $XCODE_IOS_PROJ_DIR |
||||
cd $XCODE_IOS_PROJ_DIR |
||||
cmake -G Xcode ../../ |
||||
# Bug in CMake requires us to manually replace architecture strings in project file |
||||
sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' $PROJNAME.xcodeproj/project.pbxproj |
||||
# iOS (SDK 11+, 64-bit only, arm64) |
||||
if [ ! -d "$XCODE_IOS_ARM64_PROJ_DIR" ]; then |
||||
mkdir -p $XCODE_IOS_ARM64_PROJ_DIR |
||||
cd $XCODE_IOS_ARM64_PROJ_DIR |
||||
cmake -G Xcode ../../ -DIOS_FRAMEWORK=1 -DIOS_ARM64=1 |
||||
# Manually replace arch strings in project file |
||||
sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj |
||||
cd - |
||||
fi |
||||
# iOS (SDK <11, 32-bit only, armv7, armv7s) |
||||
#if [ ! -d "$XCODE_IOS_ARMV7_PROJ_DIR" ]; then |
||||
# mkdir -p $XCODE_IOS_ARMV7_PROJ_DIR |
||||
# cd $XCODE_IOS_ARMV7_PROJ_DIR |
||||
# cmake -G Xcode ../../ -DIOS_FRAMEWORK=1 -DIOS_ARMV7=1 |
||||
# Manually replace arch strings in project file |
||||
# sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj |
||||
# cd - |
||||
#fi |
||||
# macOS |
||||
if [ ! -d "$XCODE_MACOS_PROJ_DIR" ]; then |
||||
echo "BUILDING: macOS project" |
||||
should_exit=1 |
||||
mkdir -p $XCODE_MACOS_PROJ_DIR |
||||
cd $XCODE_MACOS_PROJ_DIR |
||||
cmake -G Xcode ../../ |
||||
cmake -G Xcode ../../ -DMACOS_FRAMEWORK=1 |
||||
cd - |
||||
fi |
||||
# android? |
||||
if [[ $should_exit = 1 ]]; then |
||||
echo "Generated projects. Perform necessary modifications and then re-run this script" |
||||
echo "Please place previously built windows binaries in $WIN_PREBUILT_DIR before running again." |
||||
exit 0 |
||||
else |
||||
echo "Projects detected, going to build stage next" |
||||
fi |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
build_all_products() |
||||
ios() |
||||
{ |
||||
CONFIG=$1 |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
generate_projects # if needed |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
|
||||
# Targets to build on and for darwin |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
# Xcode Frameworks --- Builds targets from a CMake-generated Xcode project |
||||
if false; then |
||||
if [[ $2 != *"JNI"* ]]; then |
||||
CURR_BUILD_PRODUCTS_DIR=$LIB_PRODUCTS_DIR/$UPPERCASE_CONFIG |
||||
# (iOS) |
||||
echo "BUILDING: iOS" |
||||
cd $XCODE_IOS_PROJ_DIR |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos" |
||||
xcodebuild -target zt-static -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos" |
||||
cd - |
||||
CURR_ARCH="arm64" # spoof this architecture since HOSTTYPE is likely x86_64 |
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/ios-$CURR_ARCH |
||||
mkdir -p $CURR_TMP_PRODUCT_DIR |
||||
mv $CURR_BUILD_PRODUCTS_DIR/*.framework $CURR_TMP_PRODUCT_DIR |
||||
mv $CURR_BUILD_PRODUCTS_DIR/libzt.* $CURR_TMP_PRODUCT_DIR |
||||
# 64-bit |
||||
cd $XCODE_IOS_ARM64_PROJ_DIR |
||||
# Framework |
||||
xcodebuild -arch arm64 -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos" |
||||
cd - |
||||
OUTPUT_DIR=$(pwd)/lib/$1/ios-arm64 |
||||
mkdir -p $OUTPUT_DIR |
||||
rm -rf $OUTPUT_DIR/zt.framework # Remove prior to move to prevent error |
||||
mv $XCODE_IOS_ARM64_PROJ_DIR/$UPPERCASE_CONFIG-iphoneos/* $OUTPUT_DIR |
||||
|
||||
# (macOS) |
||||
echo "BUILDING: macOS" |
||||
cd $XCODE_MACOS_PROJ_DIR |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
xcodebuild -target zt-static -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
xcodebuild -target zt-shared -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
cd - |
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/macos-$(uname -m) |
||||
mkdir -p $CURR_TMP_PRODUCT_DIR |
||||
mv $CURR_BUILD_PRODUCTS_DIR/*.framework $CURR_TMP_PRODUCT_DIR |
||||
mv $CURR_BUILD_PRODUCTS_DIR/libzt.* $CURR_TMP_PRODUCT_DIR |
||||
fi |
||||
fi |
||||
# Android Archive (AAR) --- Executes a Gradle task |
||||
if true; then |
||||
CMAKE_FLAGS=$CMAKE_FLAGS" -DSDK_JNI=1" |
||||
CURR_ARCH="armeabi-v7a" # spoof this architecture since HOSTTYPE is likely x86_64 |
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/android-$CURR_ARCH |
||||
mkdir -p $CURR_TMP_PRODUCT_DIR |
||||
echo "BUILDING: AAR" |
||||
cd $ANDROID_PROJ_DIR |
||||
./gradlew assemble$UPPERCASE_CONFIG # e.g. assembleRelease |
||||
mv $ANDROID_PROJ_DIR/app/build/outputs/aar/app-$CONFIG.aar $CURR_TMP_PRODUCT_DIR/$ANDROID_ARCHIVE_FILENAME |
||||
cd - |
||||
fi |
||||
# Java Archive (JAR) |
||||
if false; then |
||||
CURR_BUILD_PRODUCTS_DIR=$LIB_PRODUCTS_DIR |
||||
CMAKE_FLAGS=$CMAKE_FLAGS" -DJNI=1" |
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/macos-$(uname -m) |
||||
mkdir -p $CURR_TMP_PRODUCT_DIR |
||||
echo "BUILDING: JAR" |
||||
rm -rf $LIB_PRODUCTS_DIR # clean-lite |
||||
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG "-DJNI=1 -DBUILD_TESTS=0" |
||||
cmake --build build |
||||
cd $PROJROOT/ports/java |
||||
cp $CURR_BUILD_PRODUCTS_DIR/libzt.dylib . |
||||
javac com/zerotier/libzt/*.java |
||||
jar cf zt.jar libzt.dylib com/zerotier/libzt/*.class |
||||
rm libzt.dylib |
||||
mv zt.jar $CURR_TMP_PRODUCT_DIR |
||||
cd - |
||||
fi |
||||
fi |
||||
# Linux targets |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
CURR_BUILD_PRODUCTS_DIR=$LIB_PRODUCTS_DIR |
||||
# Ordinary libraries |
||||
if true; then |
||||
rm -rf $LIB_PRODUCTS_DIR |
||||
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG "-DBUILD_TESTS=0" |
||||
cmake --build build |
||||
# -j $BUILD_CONCURRENCY |
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/linux-$(uname -m) |
||||
mkdir -p $CURR_TMP_PRODUCT_DIR |
||||
mv $CURR_BUILD_PRODUCTS_DIR/libzt.* $CURR_TMP_PRODUCT_DIR |
||||
fi |
||||
# Java JAR file |
||||
if true; then |
||||
rm -rf $LIB_PRODUCTS_DIR |
||||
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=$CONFIG "-DJNI=1 -DBUILD_TESTS=0" |
||||
cmake --build build |
||||
# -j $BUILD_CONCURRENCY |
||||
CURR_TMP_PRODUCT_DIR=$STAGING_DIR/$CONFIG/linux-$(uname -m) |
||||
mkdir -p $CURR_TMP_PRODUCT_DIR |
||||
cd $PROJROOT/ports/java |
||||
cp $CURR_BUILD_PRODUCTS_DIR/libzt.so . |
||||
javac com/zerotier/libzt/*.java |
||||
jar cf zt.jar libzt.dylib com/zerotier/libzt/*.class |
||||
rm libzt.dylib |
||||
mv zt.jar $CURR_TMP_PRODUCT_DIR |
||||
cd - |
||||
fi |
||||
fi |
||||
# 32-bit |
||||
#cd $XCODE_IOS_ARMV7_PROJ_DIR |
||||
# Framework |
||||
#xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "iphoneos10.0" |
||||
# Manually replace arch strings in project file |
||||
#sed -i '' 's/x86_64/$(CURRENT_ARCH)/g' zt.xcodeproj/project.pbxproj |
||||
#cd - |
||||
#OUTPUT_DIR=$(pwd)/lib/$1/ios-armv7 |
||||
#mkdir -p $OUTPUT_DIR |
||||
#rm -rf $OUTPUT_DIR/* |
||||
#mv $XCODE_IOS_ARMV7_PROJ_DIR/$UPPERCASE_CONFIG-iphoneos/* $OUTPUT_DIR |
||||
} |
||||
|
||||
macos() |
||||
{ |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
generate_projects # if needed |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
cd $XCODE_MACOS_PROJ_DIR |
||||
# Framework |
||||
xcodebuild -target zt -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
# NOTE: We build the static and dynamic editions in host() |
||||
# Static library (libzt.a) |
||||
#xcodebuild -target zt-static -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
# Dynamic library (libzt.dylib) |
||||
#xcodebuild -target zt-shared -configuration "$UPPERCASE_CONFIG" -sdk "macosx" |
||||
cd - |
||||
OUTPUT_DIR=$(pwd)/lib/$1/macos-$(uname -m) |
||||
mkdir -p $OUTPUT_DIR |
||||
rm -rf $OUTPUT_DIR/zt.framework # Remove prior to move to prevent error |
||||
mv $XCODE_MACOS_PROJ_DIR/$UPPERCASE_CONFIG/* $OUTPUT_DIR |
||||
} |
||||
|
||||
host_jar() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
NORMALIZED_OSNAME=$OSNAME |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.dylib" |
||||
NORMALIZED_OSNAME="macos" |
||||
fi |
||||
if [[ $OSNAME = *"linux"* ]]; then |
||||
DYNAMIC_LIB_NAME="libzt.so" |
||||
fi |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
# Build dynamic library |
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-jni-$1 |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
cmake -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$UPPERCASE_CONFIG "-DJNI=1" |
||||
cmake --build $BUILD_DIR $BUILD_CONCURRENCY |
||||
# Copy dynamic library from previous build step |
||||
# And, remove any lib that may exist prior. We don't want accidental successes |
||||
cd $(pwd)/ports/java |
||||
rm $DYNAMIC_LIB_NAME |
||||
mv $BUILD_DIR/lib/$DYNAMIC_LIB_NAME . |
||||
# Begin constructing JAR |
||||
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 |
||||
javac com/zerotier/libzt/*.java |
||||
jar cf zt.jar $DYNAMIC_LIB_NAME com/zerotier/libzt/*.class |
||||
rm $DYNAMIC_LIB_NAME |
||||
cd - |
||||
# Move completed JAR |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
mv $(pwd)/ports/java/zt.jar $LIB_OUTPUT_DIR |
||||
} |
||||
|
||||
host() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
NORMALIZED_OSNAME=$OSNAME |
||||
if [[ $OSNAME = *"darwin"* ]]; then |
||||
NORMALIZED_OSNAME="macos" |
||||
fi |
||||
# CMake build files |
||||
BUILD_DIR=$(pwd)/tmp/${NORMALIZED_OSNAME}-$(uname -m)-$1 |
||||
mkdir -p $BUILD_DIR |
||||
# Where to place results |
||||
BIN_OUTPUT_DIR=$(pwd)/bin/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $BIN_OUTPUT_DIR |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/${NORMALIZED_OSNAME}-$(uname -m) |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
# Build |
||||
cmake -H. -B$BUILD_DIR -DCMAKE_BUILD_TYPE=$1 |
||||
cmake --build $BUILD_DIR $BUILD_CONCURRENCY |
||||
# Move and clean up |
||||
mv $BUILD_DIR/bin/* $BIN_OUTPUT_DIR |
||||
mv $BUILD_DIR/lib/* $LIB_OUTPUT_DIR |
||||
cleanup |
||||
} |
||||
|
||||
android() |
||||
{ |
||||
# NOTE: There's no reason this won't build on linux, it's just that |
||||
# for our purposes we limit this to execution on macOS |
||||
if [[ ! $OSNAME = *"darwin"* ]]; then |
||||
exit 0 |
||||
fi |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
ARCH="armeabi-v7a" |
||||
# CMake build files |
||||
BUILD_DIR=$(pwd)/tmp/android-$ARCH-$1 |
||||
mkdir -p $BUILD_DIR |
||||
# If clean requested, remove temp build dir |
||||
if [[ $1 = *"clean"* ]]; then |
||||
rm -rf $BUILD_DIR |
||||
exit 0 |
||||
fi |
||||
# Where to place results |
||||
LIB_OUTPUT_DIR=$(pwd)/lib/$1/android-$ARCH |
||||
mkdir -p $LIB_OUTPUT_DIR |
||||
# Build |
||||
UPPERCASE_CONFIG="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" |
||||
CMAKE_FLAGS=$CMAKE_FLAGS" -DSDK_JNI=1" |
||||
cd $ANDROID_PROJ_DIR |
||||
./gradlew assemble$UPPERCASE_CONFIG # assembleRelease / assembleDebug |
||||
mv $ANDROID_PROJ_DIR/app/build/outputs/aar/app-$1.aar \ |
||||
$LIB_OUTPUT_DIR/libzt-$1.aar |
||||
cd - |
||||
} |
||||
|
||||
cleanup() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
find $(pwd)/lib -type f -name 'liblwip_pic.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'liblwip.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libminiupnpc.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libnatpmp.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libzto_pic.a' -exec rm {} + |
||||
find $(pwd)/lib -type f -name 'libzerotiercore.a' -exec rm {} + |
||||
} |
||||
|
||||
package_everything() |
||||
{ |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
LIBZT_VERSION=$(git describe) |
||||
ZT_CORE_VERSION="1.2.12" |
||||
PROD_NAME=$LIBZT_VERSION-$1 |
||||
PROD_DIR=$(pwd)/products/$PROD_NAME/ |
||||
# Make products directory |
||||
LICENSE_DIR=$PROD_DIR/licenses |
||||
mkdir -p $LICENSE_DIR |
||||
# Licenses |
||||
cp $(pwd)/ext/lwip/COPYING $LICENSE_DIR/LWIP-LICENSE.BSD |
||||
cp $(pwd)/ext/concurrentqueue/LICENSE.md $LICENSE_DIR/CONCURRENTQUEUE-LICENSE.BSD |
||||
cp $(pwd)/LICENSE.GPL-3 $LICENSE_DIR/ZEROTIER-LICENSE.GPL-3 |
||||
cp $(pwd)/include/net/ROUTE_H-LICENSE.APSL $LICENSE_DIR/ROUTE_H-LICENSE.APSL |
||||
cp $(pwd)/include/net/ROUTE_H-LICENSE $LICENSE_DIR/ROUTE_H-LICENSE |
||||
|
||||
# Documentation |
||||
#mkdir -p $PROD_DIR/doc |
||||
#cp $(pwd)/README.md $PROD_DIR/doc |
||||
# Header(s) |
||||
mkdir -p $PROD_DIR/include |
||||
cp $(pwd)/include/*.h $PROD_DIR/include |
||||
# Libraries |
||||
mkdir -p $PROD_DIR/lib |
||||
cp -r $(pwd)/lib/$1/* $PROD_DIR/lib |
||||
# Clean |
||||
find $PROD_DIR -type f \( -name '*.DS_Store' -o -name 'thumbs.db' \) -delete |
||||
# Emit a README file |
||||
# echo $'* libzt version: '${LIBZT_VERSION}$'\n* Core ZeroTier version: |
||||
#'${ZT_CORE_VERSION}$'\n* Date: '$(date)$'\n |
||||
#- ZeroTier Manual: https://www.zerotier.com/manual.shtml |
||||
#- libzt Manual: https://www.zerotier.com/manual.shtml#5 |
||||
#- libzt Repo: https://github.com/zerotier/libzt |
||||
#- Other Downloads: https://www.zerotier.com/download.shtml |
||||
#- For more assistance, visit https://my.zerotier.com and ask your |
||||
#question in our Community section' > $PROD_DIR/README.FIRST |
||||
# Tar everything |
||||
PROD_FILENAME=$(pwd)/products/$PROD_NAME.tar.gz |
||||
tar --exclude=$PROD_FILENAME -zcvf $PROD_FILENAME $PROD_DIR |
||||
md5 $PROD_FILENAME |
||||
} |
||||
|
||||
main() |
||||
dist() |
||||
{ |
||||
#generate_projects_if_necessary |
||||
build_all_products "release" |
||||
build_all_products "debug" |
||||
echo "Executing task: " ${FUNCNAME[ 0 ]} "(" $1 ")" |
||||
package_everything "debug" |
||||
package_everything "release" |
||||
} |
||||
|
||||
main "$@" |
||||
"$@" |
||||
@ -1,43 +0,0 @@
|
||||
#!/bin/bash |
||||
|
||||
PROJNAME="zt" |
||||
LIBNAME="lib"$PROJNAME |
||||
LIBZT_VERSION="1.2.0" |
||||
LIBZT_REVISION="1" |
||||
ZT_CORE_VERSION="1.2.12" |
||||
FILENAME_PREFIX=${LIBNAME} |
||||
|
||||
STAGING_DIR=$(pwd)/staging |
||||
STAGING_DEBUG_DIR=$(pwd)/staging/debug |
||||
STAGING_RELEASE_DIR=$(pwd)/staging/release |
||||
FINISHED_PRODUCTS_DIR=$(pwd)/products |
||||
|
||||
# Clean before zipping |
||||
find . -type f \( -name '*.DS_Store' -o -name 'thumbs.db' \) -delete |
||||
|
||||
# Emit a README file |
||||
echo $'* libzt version: '${LIBZT_VERSION}$'r'${LIBZT_REVISION}$'\n* Core ZeroTier version: '${ZT_CORE_VERSION}$'\n* Date: '$(date)$'\n\nZeroTier Manual: https://www.zerotier.com/manual.shtml\n |
||||
Other Downloads: https://www.zerotier.com/download.shtml |
||||
\nlibzt Repo: https://github.com/zerotier/libzt\n\nFor more assistance, visit https://my.zerotier.com and ask your question in our Community section' > ${STAGING_DIR}/README.md |
||||
|
||||
cp ${STAGING_DIR}/README.md ${STAGING_DIR}/debug/README.md |
||||
cp ${STAGING_DIR}/README.md ${STAGING_DIR}/release/README.md |
||||
|
||||
# Package everything together |
||||
# (debug) |
||||
PRODUCT_FILENAME=${FILENAME_PREFIX}-debug.tar.gz |
||||
echo "Making: " ${FINISHED_PRODUCTS_DIR}/${PRODUCT_FILENAME} |
||||
cd ${STAGING_DEBUG_DIR} |
||||
tar --exclude=${PRODUCT_FILENAME} -zcvf ${PRODUCT_FILENAME} . |
||||
md5 $PRODUCT_FILENAME |
||||
mv *.tar.gz ${FINISHED_PRODUCTS_DIR} |
||||
cd - |
||||
|
||||
# (release) |
||||
PRODUCT_FILENAME=${FILENAME_PREFIX}-release.tar.gz |
||||
echo "Making: " ${FINISHED_PRODUCTS_DIR}/${PRODUCT_FILENAME} |
||||
cd ${STAGING_RELEASE_DIR} |
||||
tar --exclude=${PRODUCT_FILENAME} -zcvf ${PRODUCT_FILENAME} . |
||||
md5 $PRODUCT_FILENAME |
||||
mv *.tar.gz ${FINISHED_PRODUCTS_DIR} |
||||
cd - |
||||
Loading…
Reference in new issue