Removed cruft from project

This commit is contained in:
Joseph Henry
2018-07-19 17:19:06 -07:00
parent 50396baaf1
commit 07be7a25a3
38 changed files with 289 additions and 4308 deletions

View File

@@ -41,14 +41,6 @@
#include <sys/time.h>
#endif
/**
* @brief Returns the thread-id. Used in debug traces.
*
* @usage For internal use only.
* @return
*/
inline unsigned int gettid();
/**
* @brief Current time in milliseconds since epoch, platform-aware convenience function.
*

View File

@@ -1,54 +0,0 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2018 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
*
*
*/
#ifndef LIBZT_VIRTUALBINDINGPAIR_H
#define LIBZT_VIRTUALBINDINGPAIR_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* A helper object for passing VirtualTap(s) and VirtualSocket(s) through the stack
*/
struct VirtualBindingPair
{
VirtualTap *tap;
VirtualSocket *vs;
VirtualBindingPair(VirtualTap *_tap, VirtualSocket *_vs) : tap(_tap), vs(_vs) {}
};
#ifdef __cplusplus
}
#endif
#endif // _H

View File

@@ -1,159 +0,0 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2018 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
*
* Platform- and stack-agnostic implementation of a socket-like object
*/
#ifndef LIBZT_VIRTUALSOCKET_H
#define LIBZT_VIRTUALSOCKET_H
#include <queue>
#include "RingBuffer.h"
#include "libztDefs.h"
#include "VirtualTap.h"
#include "Mutex.hpp"
#define VS_STATE_INACTIVE 0x000000u // Default value for newly created VirtualSocket
#define VS_STATE_ACTIVE 0x000001u // VirtualSocket is RX'ing or TX'ing without issue
#define VS_STATE_SHOULD_SHUTDOWN 0x000002u // Application, stack driver, or stack marked this VirtualSocket for death
#define VS_STATE_SHUTDOWN 0x000004u // VirtualSocket and underlying protocol control structures will not RX/TX
#define VS_STATE_CLOSED 0x000008u // VirtualSocket and underlying protocol control structures are closed
#define VS_STATE_UNHANDLED_CONNECTED 0x000010u // stack callback has received a connection but we haven't dealt with it
#define VS_STATE_CONNECTED 0x000020u // stack driver has akwnowledged new connection
#define VS_STATE_LISTENING 0x000040u // virtual socket is listening for incoming connections
#define VS_OPT_TCP_NODELAY 0x000000u // Nagle's algorithm
#define VS_OPT_SO_LINGER 0x000001u // VirtualSocket waits for data transmission before closure
/*
#define VS_RESERVED 0x000002u //
#define VS_RESERVED 0x000004u //
#define VS_RESERVED 0x000008u //
#define VS_RESERVED 0x000010u //
#define VS_RESERVED 0x000020u //
#define VS_RESERVED 0x000040u //
*/
#define VS_OPT_FD_NONBLOCKING 0x000080u // Whether the VirtualSocket exhibits non-blocking behaviour
/*
#define VS_RESERVED 0x000100u //
#define VS_RESERVED 0x000200u //
#define VS_RESERVED 0x000400u //
#define VS_RESERVED 0x000800u //
#define VS_RESERVED 0x001000u //
#define VS_RESERVED 0x002000u //
#define VS_RESERVED 0x004000u //
#define VS_RESERVED 0x008000u //
#define VS_RESERVED 0x010000u //
#define VS_RESERVED 0x020000u //
#define VS_RESERVED 0x040000u //
#define VS_RESERVED 0x080000u //
#define VS_RESERVED 0x100000u //
#define VS_RESERVED 0x200000u //
#define VS_RESERVED 0x400000u //
#define VS_RESERVED 0x800000u //
*/
#define vs_is_nonblocking(vs) (((vs)->optflags & VS_OPT_FD_NONBLOCKING) != 0)
#ifdef __cplusplus
extern "C" {
#endif
/**
* An abstraction of a socket that operates between the application-exposed platform-sockets
* and the network stack's representation of a protocol control structure. This object is used by
* the POSIX socket emulation layer and stack drivers.
*/
class VirtualSocket
{
private:
int _state = VS_STATE_INACTIVE;
public:
RingBuffer *TXbuf, *RXbuf;
ZeroTier::Mutex _tx_m, _rx_m, _op_m;
ZeroTier::PhySocket *sock = NULL;
void *pcb = NULL; // Protocol Control Block
#if defined(STACK_LWIP)
int32_t optflags = 0;
int linger;
/*
- TCP_WRITE_FLAG_COPY: indicates whether the new memory should be allocated
for the data to be copied into. If this flag is not given, no new memory
should be allocated and the data should only be referenced by pointer. This
also means that the memory behind dataptr must not change until the data is
ACKed by the remote host
- TCP_WRITE_FLAG_MORE: indicates that more data follows. If this is omitted,
the PSH flag is set in the last segment created by this call to tcp_write.
If this flag is given, the PSH flag is not set.
*/
// copy as default, processed via pointer reference if set to 0. See notes in lwip_cb_sent() and lwip_Write()
int8_t copymode = 1; // TCP_WRITE_FLAG_COPY;
#endif
struct sockaddr_storage local_addr; // address we've bound to locally
struct sockaddr_storage peer_addr; // address of connection call to remote host
int socket_family = 0;
int socket_type = 0;
int protocol = 0;
int app_fd = 0; // used by app for I/O
int sdk_fd = 0; // used by lib for I/O
std::queue<VirtualSocket*> _AcceptedConnections;
VirtualTap *tap = NULL;
/**
* Sets the VirtualSocket's state value
*/
void apply_state(int state);
/**
* Sets the VirtualSocket's state value
*/
void set_state(int state);
/**
* Gets the VirtualSocket's state value
*/
int get_state();
/**
* default ctor
*/
VirtualSocket();
/**
* dtor
*/
~VirtualSocket();
};
#ifdef __cplusplus
}
#endif
#endif // _H

View File

@@ -1,443 +0,0 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2018 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
*
* VirtualSocket management layer
*/
#include "libztDefs.h"
namespace ZeroTier {
class Mutex;
struct InetAddress;
}
class VirtualSocket;
class VirtualTap;
extern ZeroTier::Mutex _multiplexer_lock;
VirtualSocket *get_virt_socket(int fd);
int del_virt_socket(int fd);
int add_unassigned_virt_socket(int fd, VirtualSocket *vs);
int del_unassigned_virt_socket(int fd);
int add_assigned_virt_socket(void *tap, VirtualSocket *vs, int fd);
int del_assigned_virt_socket(void *tap, VirtualSocket *vs, int fd);
//void *get_assigned_virtual_pair(int fd);
/**
* @brief Stops all VirtualTap interfaces and associated I/O loops
*
* @usage For internal use only.
* @param
* @return
*/
void disableTaps();
/**
* @brief Create a socket
*
* This function will return an integer which can be used in much the same way as a
* typical file descriptor, however it is only valid for use with libzt library calls
* as this is merely a facade which is associated with the internal socket representation
* of both the network stacks and drivers.
*
* @usage Call this after virt_start() has succeeded
* @param socket_family Address family (AF_INET, AF_INET6)
* @param socket_type Type of socket (SOCK_STREAM, SOCK_DGRAM, SOCK_RAW)
* @param protocol Protocols supported on this socket
* @return
*/
int virt_socket(int socket_family, int socket_type, int protocol);
/**
* @brief Connect a socket to a remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param addr Remote host address to connect to
* @param addrlen Length of address
* @return
*/
int virt_connect(int fd, const struct sockaddr *addr, socklen_t addrlen);
/**
* @brief Bind a socket to a virtual interface
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param addr Local interface address to bind to
* @param addrlen Length of address
* @return
*/
int virt_bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
/**
* @brief Listen for incoming connections
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param backlog Number of backlogged connection allowed
* @return
*/
int virt_listen(int fd, int backlog);
/**
* @brief Accept an incoming connection
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param addr Address of remote host for accepted connection
* @param addrlen Length of address
* @return
*/
int virt_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
/**
* @brief Accept an incoming connection
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param addr Address of remote host for accepted connection
* @param addrlen Length of address
* @param flags
* @return
*/
#if defined(__linux__)
int virt_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags);
#endif
/**
* @brief Set socket options
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param level Protocol level to which option name should apply
* @param optname Option name to set
* @param optval Source of option value to set
* @param optlen Length of option value
* @return
*/
int virt_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen);
/**
* @brief Get socket options
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param level Protocol level to which option name should apply
* @param optname Option name to get
* @param optval Where option value will be stored
* @param optlen Length of value
* @return
*/
int virt_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen);
/**
* @brief Get socket name
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param addr Name associated with this socket
* @param addrlen Length of name
* @return
*/
int virt_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen);
/**
* @brief Get the peer name for the remote end of a connected socket
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param addr Name associated with remote end of this socket
* @param addrlen Length of name
* @return
*/
int virt_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen);
/**
* @brief Gets current hostname
*
* @usage Call this after virt_start() has succeeded
* @param name
* @param len
* @return
*/
int virt_gethostname(char *name, size_t len);
/**
* @brief Sets current hostname
*
* @usage Call this after virt_start() has succeeded
* @param name
* @param len
* @return
*/
int virt_sethostname(const char *name, size_t len);
/**
* @brief Return a pointer to an object with the following structure describing an internet host referenced by name
*
* @usage Call this after virt_start() has succeeded
* @param name
* @return Returns pointer to hostent structure otherwise NULL if failure
*/
struct hostent *virt_gethostbyname(const char *name);
/**
* @brief Close a socket
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @return
*/
int virt_close(int fd);
/**
* @brief Waits for one of a set of file descriptors to become ready to perform I/O.
*
* @usage Call this after virt_start() has succeeded
* @param fds
* @param nfds
* @param timeout
* @return
*/
/*
#ifdef __linux__
int virt_poll(struct pollfd *fds, nfds_t nfds, int timeout);
#endif
*/
/**
* @brief Monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready"
*
* @usage Call this after virt_start() has succeeded
* @param nfds
* @param readfds
* @param writefds
* @param exceptfds
* @param timeout
* @return
*/
int virt_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
/**
* @brief Issue file control commands on a socket
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param cmd
* @param flags
* @return
*/
int virt_fcntl(int fd, int cmd, int flags);
/**
* @brief Control a device
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param request
* @param argp
* @return
*/
int virt_ioctl(int fd, unsigned long request, void *argp);
/**
* @brief Send data to remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param buf Pointer to data buffer
* @param len Length of data to write
* @param flags
* @return
*/
ssize_t virt_send(int fd, const void *buf, size_t len, int flags);
/**
* @brief Send data to remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param buf Pointer to data buffer
* @param len Length of data to write
* @param flags
* @param addr Destination address
* @param addrlen Length of destination address
* @return
*/
ssize_t virt_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen);
/**
* @brief Send message to remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param msg
* @param flags
* @return
*/
ssize_t virt_sendmsg(int fd, const struct msghdr *msg, int flags);
/**
* @brief Receive data from remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param buf Pointer to data buffer
* @param len Length of data buffer
* @param flags
* @return
*/
ssize_t virt_recv(int fd, void *buf, size_t len, int flags);
/**
* @brief Receive data from remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param buf Pointer to data buffer
* @param len Length of data buffer
* @param flags
* @param addr
* @param addrlen
* @return
*/
ssize_t virt_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen);
/**
* @brief Receive a message from remote host
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param msg
* @param flags
* @return
*/
ssize_t virt_recvmsg(int fd, struct msghdr *msg,int flags);
/**
* @brief Read bytes from socket onto buffer
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param buf Pointer to data buffer
* @param len Length of data buffer to receive data
* @return
*/
int virt_read(int fd, void *buf, size_t len);
/**
* @brief Write bytes from buffer to socket
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param buf Pointer to data buffer
* @param len Length of buffer to write
* @return
*/
int virt_write(int fd, const void *buf, size_t len);
/**
* @brief Shut down some aspect of a socket (read, write, or both)
*
* @usage Call this after virt_start() has succeeded
* @param fd File descriptor (only valid for use with libzt calls)
* @param how Which aspects of the socket should be shut down
* @return
*/
int virt_shutdown(int fd, int how);
/**
* @brief Adds a DNS nameserver for the network stack to use
*
* @usage Call this after virt_start() has succeeded
* @param addr Address for DNS nameserver
* @return
*/
int virt_add_dns_nameserver(struct sockaddr *addr);
/**
* @brief Removes a DNS nameserver
*
* @usage Call this after virt_start() has succeeded
* @param addr Address for DNS nameserver
* @return
*/
int virt_del_dns_nameserver(struct sockaddr *addr);
/**
* @brief Returns whether one can add a new socket or not. This depends on network stack in use.
*
* @usage Call this after zts_start() has succeeded
* @param socket_type
* @return
*/
bool virt_can_provision_new_socket(int socket_type);
/**
* @brief Returns the number of VirtualSockets either already provisioned or waiting to be
* Some network stacks may have a limit on the number of sockets that they can
* safely handle due to timer construction, this is a way to check that we
* haven't passed that limit. Someday if multiple stacks are used simultaneously
* the logic for this function should change accordingly.
*
* @usage Call this after zts_start() has succeeded
* @return
*/
int virt_num_active_sockets();
/**
* @brief Return the maximum number of sockets allowable by platform/stack configuration
*
* @usage Call this after zts_start() has succeeded
* @param socket_type
* @return
*/
int virt_maxsockets(int socket_type);
/**
* @brief Return the number of currently active picoTCP timers
*
* @usage Call this after zts_start() has succeeded
* @return
*/
//int pico_ntimers();
/**
* @brief Convert a struct sockaddr to a ZeroTier::InetAddress
*
* @usage For internal use only.
* @param socket_family
* @param addr
* @param inet
* @return
*/
void sockaddr2inet(int socket_family, const struct sockaddr *addr, ZeroTier::InetAddress *inet);

View File

@@ -86,7 +86,7 @@ public:
/**
* Registers a device with the given address
*/
bool registerIpWithStack(const ZeroTier::InetAddress &ip);
void registerIpWithStack(const ZeroTier::InetAddress &ip);
/**
* Adds an address to the userspace stack interface associated with this VirtualTap
@@ -157,72 +157,14 @@ public:
void (*_handler)(void *, void *, uint64_t, const ZeroTier::MAC &, const ZeroTier::MAC &, unsigned int, unsigned int,
const void *, unsigned int);
/**
* Signals us to close the TcpVirtualSocket associated with this PhySocket
*/
void phyOnUnixClose(ZeroTier::PhySocket *sock, void **uptr);
/**
* Notifies us that there is data to be read from an application's socket
*/
void phyOnUnixData(ZeroTier::PhySocket *sock, void **uptr, void *data, ssize_t len);
/**
* Notifies us that we can write to an application's socket
*/
void phyOnUnixWritable(ZeroTier::PhySocket *sock, void **uptr, bool stack_invoked);
/**
* Adds a route to the virtual tap
*/
bool routeAdd(const ZeroTier::InetAddress &ip, const ZeroTier::InetAddress &nm, const ZeroTier::InetAddress &gw);
/**
* Deletes a route from the virtual tap
*/
bool routeDelete(const ZeroTier::InetAddress &ip, const ZeroTier::InetAddress &nm);
/**
* Assign a VirtualSocket to the VirtualTap
*/
void addVirtualSocket(VirtualSocket *vs);
/**
* Remove a VirtualSocket from the VirtualTap
*/
void removeVirtualSocket();
/****************************************************************************/
/* DNS */
/****************************************************************************/
/**
* Registers a DNS nameserver with the network stack
*/
int add_DNS_Nameserver(struct sockaddr *addr);
/**
* Un-registers a DNS nameserver from the network stack
*/
int del_DNS_Nameserver(struct sockaddr *addr);
/****************************************************************************/
/* Vars */
/****************************************************************************/
#if defined(STACK_PICO)
bool should_start_stack = false;
struct pico_device *picodev = NULL;
/****************************************************************************/
/* Guarded RX Frame Buffer for picoTCP */
/****************************************************************************/
unsigned char pico_frame_rxbuf[MAX_PICO_FRAME_RX_BUF_SZ];
int pico_frame_rxbuf_tot = 0;
Mutex _pico_frame_rxbuf_m;
#endif
std::vector<std::pair<ZeroTier::InetAddress, ZeroTier::InetAddress> > routes;
void *zt1ServiceRef = NULL;
@@ -261,56 +203,6 @@ public:
*/
uint64_t last_housekeeping_ts = 0;
/****************************************************************************/
/* In these, we will call the stack's corresponding functions, this is */
/* where one would put logic to select between different stacks */
/****************************************************************************/
/**
* Connect to a remote host via the userspace stack interface associated with this VirtualTap
*/
int Connect(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
/**
* Bind to the userspace stack interface associated with this VirtualTap
*/
int Bind(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
/**
* Listen for a VirtualSocket
*/
int Listen(VirtualSocket *vs, int backlog);
/**
* Accepts an incoming VirtualSocket
*/
VirtualSocket* Accept(VirtualSocket *vs);
/**
* Move data from RX buffer to application's "socket"
*/
int Read(VirtualSocket *vs, PhySocket *sock, void **uptr, bool stack_invoked);
/**
* Move data from application's "socket" into network stack
*/
int Write(VirtualSocket *vs, void *data, ssize_t len);
/**
* Send data to specified host
*/
int SendTo(VirtualSocket *vs, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen);
/**
* Closes a VirtualSocket
*/
int Close(VirtualSocket *vs);
/**
* Shuts down some aspect of a VirtualSocket
*/
int Shutdown(VirtualSocket *vs, int how);
/**
* Disposes of previously-closed VirtualSockets
*/

View File

@@ -223,7 +223,7 @@ ZT_SOCKET_API int ZTCALL zts_get_num_assigned_addresses(const uint64_t nwid);
* @return The number of addresses assigned
*/
ZT_SOCKET_API int ZTCALL zts_get_address_at_index(
const uint64_t nwid, const int index, struct sockaddr_storage *addr);
const uint64_t nwid, const int index, struct sockaddr *addr, socklen_t *addrlen);
/**
* @brief Get IP address for this device on a given network
@@ -231,7 +231,7 @@ ZT_SOCKET_API int ZTCALL zts_get_address_at_index(
* @usage FIXME: Only returns first address found, good enough for most cases
* @param nwid Network ID
* @param addr Destination structure for address
* @param address_family To designate what family of addresses we want to return. AF_INET or AF_INET6
* @param addrlen size of destination address buffer, will be changed to size of returned address
* @return 0 if an address was successfully found, -1 if failure
*/
ZT_SOCKET_API int ZTCALL zts_get_address(
@@ -269,16 +269,6 @@ ZT_SOCKET_API void ZTCALL zts_get_rfc4193_addr(
*/
ZT_SOCKET_API unsigned long zts_get_peer_count();
/**
* @brief Get the virtual address of a peer given its Node ID
*
* @usage Call this after zts_start() has succeeded
* @param peer Returned peer address
* @param nodeId Provided Node ID
* @return
*/
ZT_SOCKET_API int ZTCALL zts_get_peer_address(char *peer, const uint64_t nodeId);
/****************************************************************************/
/* POSIX-like socket API */
/****************************************************************************/

View File

@@ -75,13 +75,11 @@
#define ZT_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // short
extern unsigned int gettid();
#ifdef __linux__
#define ZT_THREAD_ID syscall(SYS_gettid)
#endif
#ifdef __APPLE__
#define ZT_THREAD_ID (long)0 //(long)gettid()
#define ZT_THREAD_ID (long)0
#endif
#ifdef _WIN32
#define ZT_THREAD_ID (long)0
@@ -99,8 +97,7 @@ extern unsigned int gettid();
#if defined(__ANDROID__)
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"STACK[%ld]: %17s:%5d:%20s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32)
#elif defined(_WIN32)
#define DEBUG_STACK(fmt, ...) fprintf(stderr, ZT_YEL "STACK[%ld]: %17s:%5d:%25s: " fmt \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
@@ -115,8 +112,7 @@ extern unsigned int gettid();
#if defined(__ANDROID__)
#define DEBUG_TEST(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"TEST : %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32)
#elif defined(_WIN32)
#define DEBUG_TEST(fmt, ...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
@@ -132,8 +128,7 @@ extern unsigned int gettid();
#if defined(__ANDROID__)
#define DEBUG_ERROR(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ERROR: %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32)
#elif defined(_WIN32)
#define DEBUG_ERROR(fmt, ...) fprintf(stderr, ZT_RED "ERROR[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
@@ -149,8 +144,7 @@ extern unsigned int gettid();
#if defined(__ANDROID__)
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"INFO : %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32)
#elif defined(_WIN32)
#define DEBUG_INFO(fmt, ...) fprintf(stderr, ZT_WHT "INFO [%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
@@ -166,8 +160,7 @@ extern unsigned int gettid();
#if defined(__ANDROID__)
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"TRANS: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32)
#elif defined(_WIN32)
#define DEBUG_TRANS(fmt, ...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__)
#else
@@ -183,8 +176,7 @@ extern unsigned int gettid();
#if defined(__ANDROID__)
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"EXTRA: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32)
#elif defined(_WIN32)
#define DEBUG_EXTRA(fmt, ...) fprintf(stderr, ZT_WHT "EXTRA[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, __VA_ARGS__, (long)0)
#else

View File

@@ -33,87 +33,15 @@
#ifndef LIBZT_DEFINES_H
#define LIBZT_DEFINES_H
#define LIBZT_IPV4 1
#define LIBZT_IPV6 1
/**
* Default port that libzt will use to support all virtual communication
*/
#define LIBZT_DEFAULT_PORT 9994
/**
* Use ZeroTier Virtual Socket layer to abstract network stack raw API
*/
#define ZT_VIRTUAL_SOCKET 0
/**
* Use lwIP sockets API
*/
#define ZT_LWIP_SEQ_SOCKET 1
/**
* Use pico BSD socket API
*/
#define ZT_PICO_BSD_SOCKET 0
#define STACK_LWIP 1
#define STACK_PICO 0
#define NO_STACK 0 // for layer-2 only (this will omit all userspace network stack code)
/* sanity checks for userspace network stack and socket API layer choices
EX.
zts_socket()
1. ) ZT_VIRTUAL_SOCKET? -> virt_socket() --- Choose this if the default socket layer isn't doing what you need
STACK_LWIP? -> raw lwip_ API
STACK_PICO? -> raw pico_ API
otherStack? -> raw API
2.) ZT_LWIP_SEQ_SOCKET? (default) -> lwip_socket() --- currently provides greatest safety and performance
3.) ZT_PICO_BSD_SOCKET? -> pico_ socket API
otherStack? -> other_stack_socket()
Default is: STACK_LWIP=1 ZT_LWIP_SEQ_SOCKET=1
*/
#if (STACK_LWIP+STACK_PICO) > 1
#error "Multiple network stacks specified. Pick only one."
#endif
#if STACK_LWIP==0 && STACK_PICO==0 && NO_STACK==0
#error "No network stacks specified and NO_STACK wasn't set. Pick one."
#endif
#if ZT_VIRTUAL_SOCKET==0 && ZT_LWIP_SEQ_SOCKET==0 && ZT_PICO_BSD_SOCKET==0
#error "No socket handling layer specified. Pick one."
#endif
#if (ZT_VIRTUAL_SOCKET + ZT_LWIP_SEQ_SOCKET + ZT_PICO_BSD_SOCKET) > 1
#error "Multiple socket handling layers specified. Pick only one."
#endif
#if ZT_LWIP_SEQ_SOCKET==1 && STACK_LWIP==0
#error "ZT_LWIP_SEQ_SOCKET is selected as socket handling layer, but STACK_LWIP isn't set"
#endif
#if ZT_PICO_BSD_SOCKET==1 && STACK_PICO==0
#error "ZT_PICO_BSD_SOCKET is selected as socket handling layer, but STACK_PICO isn't set"
#endif
#if STACK_LWIP==1
#undef STACK_PICO
#undef NO_STACK
#endif
#if STACK_PICO==1
#undef STACK_LWIP
#undef NO_STACK
#endif
#if NO_STACK==1
#undef STACK_LWIP
#undef STACK_PICO
#endif
#if ZT_VIRTUAL_SOCKET==1
#undef ZT_LWIP_SEQ_SOCKET
#undef ZT_PICO_BSD_SOCKET
#endif
#if ZT_LWIP_SEQ_SOCKET==1
#undef ZT_VIRTUAL_SOCKET
#undef ZT_PICO_BSD_SOCKET
#endif
#if ZT_PICO_BSD_SOCKET==1
#undef ZT_VIRTUAL_SOCKET
#undef ZT_LWIP_SEQ_SOCKET
#endif
#define NO_STACK 0 // for layer-2 only (this will omit all userspace network stack code)
/**
* Maximum MTU size for ZeroTier
@@ -166,8 +94,6 @@ struct sockaddr_ll {
// For LWIP configuration see: include/lwipopts.h
#if defined(STACK_LWIP)
/* The following three quantities are related and govern how incoming frames are fed into the
network stack's core:
@@ -208,7 +134,6 @@ typedef signed char err_t;
#define LWIP_STATUS_TMR_INTERVAL 500
// #define LWIP_CHKSUM <your_checksum_routine>, See: RFC1071 for inspiration
#endif
/****************************************************************************/
/* Defines */
@@ -259,11 +184,6 @@ typedef signed char err_t;
*/
#define ZT_API_CHECK_INTERVAL 50
/**
* Maximum size of guarded RX buffer (for picoTCP raw driver only)
*/
#define MAX_PICO_FRAME_RX_BUF_SZ ZT_MAX_MTU * 128
/**
* Size of TCP TX buffer for VirtualSockets used in raw network stack drivers
*/
@@ -384,4 +304,6 @@ typedef signed char err_t;
#define ZT_IOCTL_SIG int fd, unsigned long request, void *argp
#define ZT_SYSCALL_SIG long number, ...
#define LIBZT_SERVICE_NOT_STARTED_STR "service not started yet, call zts_startjoin()"
#endif // _H

View File

@@ -34,8 +34,7 @@
#define ZT_LWIP_HPP
#include "libztDefs.h"
#ifdef STACK_LWIP
#include "lwip/err.h"
namespace ZeroTier {
class MAC;
@@ -43,8 +42,6 @@ namespace ZeroTier {
struct InetAddress;
}
//#include "lwip/err.h"
/**
* @brief Initialize network stack semaphores, threads, and timers.
*
@@ -105,146 +102,4 @@ err_t lwip_eth_tx(struct netif *netif, struct pbuf *p);
void lwip_eth_rx(VirtualTap *tap, const ZeroTier::MAC &from, const ZeroTier::MAC &to, unsigned int etherType,
const void *data, unsigned int len);
/****************************************************************************/
/* Raw API driver */
/****************************************************************************/
#ifdef ZT_VIRTUAL_SOCKET
class VirtualSocket;
/**
* Returns the number of TCP PCBs currently allocated
*/
int rd_lwip_num_current_tcp_pcbs();
/**
* Returns the number of UDP PCBs currently allocated
*/
int rd_lwip_num_current_udp_pcbs();
/**
* Returns the number of RAW PCBs currently allocated
*/
int rd_lwip_num_current_raw_pcbs();
/**
* Returns the total number of PCBs of any time or state
*/
int rd_lwip_num_total_pcbs();
/**
* Registers a DNS nameserver with the network stack
*/
int rd_lwip_add_dns_nameserver(struct sockaddr *addr);
/**
* Un-registers a DNS nameserver from the network stack
*/
int rd_lwip_del_dns_nameserver(struct sockaddr *addr);
/**
* Main stack loop
*/
void rd_lwip_loop(VirtualTap *tap);
/**
* Creates a stack-specific "socket" or "VirtualSocket object"
*/
int rd_lwip_socket(void **pcb, int socket_family, int socket_type, int protocol);
/**
* Connect to remote host via userspace network stack interface - Called from VirtualTap
*/
int rd_lwip_connect(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
/**
* Bind to a userspace network stack interface - Called from VirtualTap
*/
int rd_lwip_bind(VirtualTap *tap, VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
/**
* Listen for incoming VirtualSockets - Called from VirtualTap
*/
int rd_lwip_listen(VirtualSocket *vs, int backlog);
/**
* Accept an incoming VirtualSocket - Called from VirtualTap
*/
VirtualSocket* rd_lwip_accept(VirtualSocket *vs);
/**
* Read from RX buffer to application - Called from VirtualTap
*/
int rd_lwip_read(VirtualSocket *vs, bool lwip_invoked);
/**
* Write to userspace network stack - Called from VirtualTap
*/
int rd_lwip_write(VirtualSocket *vs, void *data, ssize_t len);
/**
* Close a VirtualSocket - Called from VirtualTap
*/
int rd_lwip_close(VirtualSocket *vs);
/**
* Shuts down some aspect of a VirtualSocket - Called from VirtualTap
*/
int rd_lwip_shutdown(VirtualSocket *vs, int how);
/**
* Sets a property of a socket
*/
int rd_lwip_setsockopt(VirtualSocket *vs, int level, int optname, const void *optval, socklen_t optlen);
/**
* Gets a property of a socket
*/
int rd_lwip_getsockopt(VirtualSocket *vs, int level, int optname, void *optval, socklen_t *optlen);
// --- Callbacks from network stack ---
#ifdef ZT_DRIVER_MODULE // only include these symbols if we're building the full driver
/**
* Callback for handling received UDP packets (already processed by network stack)
*/
static err_t rd_lwip_cb_tcp_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err);
/**
* Callback for handling accepted connection
*/
static err_t rd_lwip_cb_accept(void *arg, struct tcp_pcb *newPCB, err_t err);
/**
* Callback for handling received TCP packets (already processed by stack)
*/
static void rd_lwip_cb_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, const ip_addr_t * addr, u16_t port);
/**
* Callback for handling errors from within the network stack
*/
static void rd_lwip_cb_err(void *arg, err_t err);
/**
* Callback for handling periodic background tasks
*/
static err_t rd_lwip_cb_poll(void* arg, struct tcp_pcb *PCB);
/**
* Callback for handling confirmation of sent packets
*/
static err_t rd_lwip_cb_sent(void *arg, struct tcp_pcb *PCB, u16_t len);
/**
* Callback for handling successful connections
*/
static err_t rd_lwip_cb_connected(void *arg, struct tcp_pcb *PCB, err_t err);
#endif // ZT_DRIVER_MODULE
#endif
#endif // ZT_VIRTUAL_SOCKET
#endif // STACK_LWIP
#endif // _H

View File

@@ -44,7 +44,12 @@
/*
* Provides its own errno
*/
#if __ANDROID__
#define LWIP_PROVIDE_ERRNO 0
#else
#define LWIP_PROVIDE_ERRNO 0
#endif
/*
* Provides core locking machinery
@@ -56,6 +61,7 @@
*/
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
#define LWIP_NOASSERT 1
/*
*
*/
@@ -70,8 +76,10 @@
/*
* Provides network/host byte transformation macros
*/
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 1
#if __ANDROID__
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS 1
#endif
/*
* Include user defined options first. Anything not defined in these files
@@ -80,8 +88,8 @@
#include "lwip/debug.h"
// IP Protocol version
#define LWIP_IPV6 1
#define LWIP_IPV4 1
#define LWIP_IPV6 1
// --- DEBUG ---
@@ -115,7 +123,7 @@
// interfaces
#define SLIP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
// API (not used in libzt)
// API
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
@@ -474,7 +482,7 @@ happening sooner than they should.
/**
* LWIP_DHCP==1: Enable DHCP module.
*/
#define LWIP_DHCP 1
#define LWIP_DHCP 0
/*------------------------------------------------------------------------------

View File

@@ -1,222 +0,0 @@
/*
* ZeroTier SDK - Network Virtualization Everywhere
* Copyright (C) 2011-2018 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.
*/
#ifndef ZT_PICOTCP_HPP
#define ZT_PICOTCP_HPP
/*
#include "pico_eth.h"
#include "pico_stack.h"
#include "pico_ipv4.h"
#include "pico_icmp4.h"
#include "pico_dev_tap.h"
#include "pico_protocol.h"
#include "pico_socket.h"
#include "pico_device.h"
#include "pico_ipv6.h"
*/
struct pico_socket;
class VirtualSocket;
class VirtualTap;
#include "VirtualTap.h"
/****************************************************************************/
/* PicoTCP API Signatures (See libzt.h for the application-facing API) */
/****************************************************************************/
#define PICO_IPV4_TO_STRING_SIG char *ipbuf, const uint32_t ip
#define PICO_TAP_CREATE_SIG char *name
#define PICO_IPV4_LINK_ADD_SIG struct pico_device *dev, struct pico_ip4 address, struct pico_ip4 netmask
#define PICO_DEVICE_INIT_SIG struct pico_device *dev, const char *name, uint8_t *mac
#define PICO_STACK_RECV_SIG struct pico_device *dev, uint8_t *buffer, uint32_t len
#define PICO_ICMP4_PING_SIG char *dst, int count, int interval, int timeout, int size, void (*cb)(struct pico_icmp4_stats *)
#define PICO_TIMER_ADD_SIG pico_time expire, void (*timer)(pico_time, void *), void *arg
#define PICO_STRING_TO_IPV4_SIG const char *ipstr, uint32_t *ip
#define PICO_STRING_TO_IPV6_SIG const char *ipstr, uint8_t *ip
#define PICO_SOCKET_SETOPTION_SIG struct pico_socket *s, int option, void *value
#define PICO_SOCKET_SEND_SIG struct pico_socket *s, const void *buf, int len
#define PICO_SOCKET_SENDTO_SIG struct pico_socket *s, const void *buf, int len, void *dst, uint16_t remote_port
#define PICO_SOCKET_RECV_SIG struct pico_socket *s, void *buf, int len
#define PICO_SOCKET_RECVFROM_SIG struct pico_socket *s, void *buf, int len, void *orig, uint16_t *remote_port
#define PICO_SOCKET_OPEN_SIG uint16_t net, uint16_t proto, void (*wakeup)(uint16_t ev, struct pico_socket *s)
#define PICO_SOCKET_BIND_SIG struct pico_socket *s, void *local_addr, uint16_t *port
#define PICO_SOCKET_CONNECT_SIG struct pico_socket *s, const void *srv_addr, uint16_t remote_port
#define PICO_SOCKET_LISTEN_SIG struct pico_socket *s, const int backlog
#define PICO_SOCKET_READ_SIG struct pico_socket *s, void *buf, int len
#define PICO_SOCKET_WRITE_SIG struct pico_socket *s, const void *buf, int len
#define PICO_SOCKET_CLOSE_SIG struct pico_socket *s
#define PICO_SOCKET_SHUTDOWN_SIG struct pico_socket *s, int mode
#define PICO_SOCKET_ACCEPT_SIG struct pico_socket *s, void *orig, uint16_t *port
#define PICO_IPV6_LINK_ADD_SIG struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask
#define PICO_IPV4_ROUTE_ADD_SIG struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link
#define PICO_IPV4_ROUTE_DEL_SIG struct pico_ip4 address, struct pico_ip4 netmask, int metric
#define PICO_IPV6_ROUTE_ADD_SIG struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link
#define PICO_IPV6_ROUTE_DEL_SIG struct pico_ip6 address, struct pico_ip6 netmask, struct pico_ip6 gateway, int metric, struct pico_ipv6_link *link
#define PICO_DNS_CLIENT_NAMESERVER_SIG pico_ip4*, unsigned char
/**
* Send raw frames from the stack to the ZeroTier virtual wire
*/
int rd_pico_eth_tx(struct pico_device *dev, void *buf, int len);
/**
* Read raw frames from RX frame buffer into the stack
*/
int rd_pico_eth_poll(struct pico_device *dev, int loop_score);
/**
* Set up an interface in the network stack for the VirtualTap
*/
bool pico_init_interface(VirtualTap *tap);
/**
* Register an address with the stack
*/
bool pico_register_address(VirtualTap *tap, const InetAddress &ip);
/**
* Adds a route to the picoTCP device
*/
bool rd_pico_route_add(VirtualTap *tap, const InetAddress &addr, const InetAddress &nm, const InetAddress &gw, int metric);
/**
* Deletes a route from the picoTCP device
*/
bool rd_pico_route_del(VirtualTap *tap, const InetAddress &addr, const InetAddress &nm, int metric);
/**
* Registers a DNS nameserver with the network stack
*/
int rd_pico_add_dns_nameserver(struct sockaddr *addr);
/**
* Un-registers a DNS nameserver from the network stack
*/
int rd_pico_del_dns_nameserver(struct sockaddr *addr);
/**
* Main stack loop
*/
void rd_pico_loop(VirtualTap *tap);
/**
* Read bytes from the stack to the RX buffer (prepare to be read by app)
*/
void rd_pico_cb_tcp_read(VirtualTap *tap, struct pico_socket *s);
/**
* Read bytes from the stack to the RX buffer (prepare to be read by app)
*/
void rd_pico_cb_udp_read(VirtualTap *tap, struct pico_socket *s);
/**
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
*/
void rd_pico_cb_tcp_write(VirtualTap *tap, struct pico_socket *s);
/**
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
*/
void rd_pico_cb_socket_ev(uint16_t ev, struct pico_socket *s);
/**
* Packets from the ZeroTier virtual wire enter the stack here
*/
void rd_pico_eth_rx(VirtualTap *tap, const ZeroTier::MAC &from, const ZeroTier::MAC &to,
unsigned int etherType, const void *data, unsigned int len);
/**
* Creates a stack-specific "socket" or "VirtualSocket object"
*/
int rd_pico_socket(struct pico_socket **p, int socket_family, int socket_type, int protocol);
/**
* Connect to remote host via userspace network stack interface - Called from VirtualTap
*/
int rd_pico_connect(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
/**
* Bind to a userspace network stack interface - Called from VirtualTap
*/
int rd_pico_bind(VirtualSocket *vs, const struct sockaddr *addr, socklen_t addrlen);
/**
* Listen for incoming VirtualSockets - Called from VirtualTap
*/
int rd_pico_listen(VirtualSocket *vs, int backlog);
/**
* Accept an incoming VirtualSocket - Called from VirtualTap
*/
VirtualSocket* rd_pico_accept(VirtualSocket *vs);
/**
* Read from RX buffer to application - Called from VirtualTap
*/
int rd_pico_read(VirtualTap *tap, ZeroTier::PhySocket *sock, VirtualSocket *vs, bool stack_invoked);
/**
* Write to userspace network stack - Called from VirtualTap
*/
int rd_pico_write(VirtualSocket *vs, void *data, ssize_t len);
/**
* Close a VirtualSocket - Called from VirtualTap
*/
int rd_pico_close(VirtualSocket *vs);
/**
* Shuts down some aspect of a VirtualSocket - Called from VirtualTap
*/
int rd_pico_shutdown(VirtualSocket *vs, int how);
/**
* Sets a property of a socket
*/
int rd_pico_setsockopt(VirtualSocket *vs, int level, int optname, const void *optval, socklen_t optlen);
/**
* Gets a property of a socket
*/
int rd_pico_getsockopt(VirtualSocket *vs, int level, int optname, void *optval, socklen_t *optlen);
/**
* Converts a pico_err to its most closely-related errno, and sets errno
*/
int map_pico_err_to_errno(int err);
/**
* Converts picoTCP error codes to pretty string
*/
char *beautify_pico_error(int err);
/**
* Converts picoTCP socket states into pretty string
*/
char *beautify_pico_state(int state);
#endif // _H