Added build timestamps for logging
This commit is contained in:
@@ -27,23 +27,23 @@
|
||||
#ifndef UTILITIES_HPP
|
||||
#define UTILITIES_HPP
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns masked address for subnet comparisons
|
||||
*/
|
||||
//ZeroTier::InetAddress *ztipv6_mask(ZeroTier::InetAddress *addr, unsigned int bits);
|
||||
bool ipv6_in_subnet(ZeroTier::InetAddress *subnet, ZeroTier::InetAddress *addr);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Convert protocol numbers to human-readable strings
|
||||
*/
|
||||
char *beautify_eth_proto_nums(int proto);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Convert a struct sockaddr to a ZeroTier::InetAddress
|
||||
*/
|
||||
void sockaddr2inet(int socket_family, const struct sockaddr *addr, ZeroTier::InetAddress *inet);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Convert a raw MAC address byte array into a human-readable string
|
||||
*/
|
||||
void mac2str(char *macbuf, int len, unsigned char* addr);
|
||||
@@ -54,7 +54,7 @@ void mac2str(char *macbuf, int len, unsigned char* addr);
|
||||
(ipaddr)->addr[2] = ZeroTier::Utils::hton(((e & 0xffff) << 16) | (f & 0xffff)); \
|
||||
(ipaddr)->addr[3] = ZeroTier::Utils::hton(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
|
||||
|
||||
/*
|
||||
/**
|
||||
* Convert from standard IPV6 address structure to an lwIP native structure
|
||||
*/
|
||||
inline void in6_to_ip6(ip6_addr_t *ba, struct sockaddr_in6 *in6)
|
||||
|
||||
@@ -56,12 +56,10 @@ namespace ZeroTier {
|
||||
|
||||
class VirtualTap;
|
||||
|
||||
/*
|
||||
* Something analogous to a socket. This is a common object used by the
|
||||
* libzt API, VirtualTap, and the userspace network stack driver implementations.
|
||||
* In some situations the word 'Connection' would capture the meaning and
|
||||
* function of this object, however I'd like to discourage this since this
|
||||
* object also handles non-connection-based traffic as well.
|
||||
/**
|
||||
* An abstraction of a socket that operates between the application-exposed platform-sockets
|
||||
* and the network stack's representation of a protocol control block. This object is used by
|
||||
* the POSIX socket emulation layer and stack drivers.
|
||||
*/
|
||||
class VirtualSocket
|
||||
{
|
||||
@@ -74,6 +72,9 @@ namespace ZeroTier {
|
||||
PhySocket *sock = NULL;
|
||||
|
||||
// State control
|
||||
/**
|
||||
* Sets the VirtualSocket's state value
|
||||
*/
|
||||
void set_state(int state) {
|
||||
// states may be set by application or by stack callbacks, thus this must be guarded
|
||||
_op_m.lock();
|
||||
@@ -81,11 +82,13 @@ namespace ZeroTier {
|
||||
//DEBUG_EXTRA("SET STATE = %d (vs=%p)", _state, this);
|
||||
_op_m.unlock();
|
||||
}
|
||||
/**
|
||||
* Gets the VirtualSocket's state value
|
||||
*/
|
||||
int get_state() {
|
||||
//DEBUG_EXTRA("GET STATE = %d (vs=%p)", _state, this);
|
||||
return _state;
|
||||
}
|
||||
|
||||
#if defined(STACK_PICO)
|
||||
struct pico_socket *picosock = NULL;
|
||||
#endif
|
||||
@@ -93,13 +96,13 @@ namespace ZeroTier {
|
||||
void *pcb = NULL; // Protocol Control Block
|
||||
/*
|
||||
- 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
|
||||
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.
|
||||
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 = TCP_WRITE_FLAG_COPY;
|
||||
@@ -154,7 +157,7 @@ namespace ZeroTier {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* A helper object for passing VirtualTap(s) and VirtualSocket(s) through the stack
|
||||
*/
|
||||
struct VirtualBindingPair
|
||||
|
||||
@@ -65,8 +65,8 @@ struct netif;
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/*
|
||||
* Socket Tap -- emulates an Ethernet tap device
|
||||
/**
|
||||
* emulates an Ethernet tap device
|
||||
*/
|
||||
class VirtualTap
|
||||
{
|
||||
@@ -88,96 +88,96 @@ namespace ZeroTier {
|
||||
void setEnabled(bool en);
|
||||
bool enabled() const;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Registers a device with the given address
|
||||
*/
|
||||
bool registerIpWithStack(const InetAddress &ip);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Adds an address to the userspace stack interface associated with this VirtualTap
|
||||
* - Starts VirtualTap main thread ONLY if successful
|
||||
*/
|
||||
bool addIp(const InetAddress &ip);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Removes an address from the userspace stack interface associated with this VirtualTap
|
||||
*/
|
||||
bool removeIp(const InetAddress &ip);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Presents data to the userspace stack
|
||||
*/
|
||||
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,
|
||||
unsigned int len);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get VirtualTap device name (e.g. 'libzt4-17d72843bc2c5760')
|
||||
*/
|
||||
std::string deviceName() const;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get Node ID (ZT address)
|
||||
*/
|
||||
std::string nodeId() const;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Set friendly name
|
||||
*/
|
||||
void setFriendlyName(const char *friendlyName);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Scan multicast groups
|
||||
*/
|
||||
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Set MTU
|
||||
*/
|
||||
void setMtu(unsigned int mtu);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Calls main network stack loops
|
||||
*/
|
||||
void threadMain()
|
||||
throw();
|
||||
|
||||
/*
|
||||
/**
|
||||
* For moving data onto the ZeroTier virtual wire
|
||||
*/
|
||||
void (*_handler)(void *, void *, uint64_t, const MAC &, const MAC &, unsigned int, unsigned int,
|
||||
const void *, unsigned int);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Signals us to close the TcpVirtualSocket associated with this PhySocket
|
||||
*/
|
||||
void phyOnUnixClose(PhySocket *sock, void **uptr);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Notifies us that there is data to be read from an application's socket
|
||||
*/
|
||||
void phyOnUnixData(PhySocket *sock, void **uptr, void *data, ssize_t len);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Notifies us that we can write to an application's socket
|
||||
*/
|
||||
void phyOnUnixWritable(PhySocket *sock, void **uptr, bool stack_invoked);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Adds a route to the virtual tap
|
||||
*/
|
||||
bool routeAdd(const InetAddress &addr, const InetAddress &nm, const InetAddress &gw);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Deletes a route from the virtual tap
|
||||
*/
|
||||
bool routeDelete(const InetAddress &addr, const InetAddress &nm);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Assign a VirtualSocket to the VirtualTap
|
||||
*/
|
||||
void addVirtualSocket(VirtualSocket *vs);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Remove a VirtualSocket from the VirtualTap
|
||||
*/
|
||||
void removeVirtualSocket(VirtualSocket *vs);
|
||||
@@ -186,12 +186,12 @@ namespace ZeroTier {
|
||||
/* 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);
|
||||
@@ -258,66 +258,56 @@ namespace ZeroTier {
|
||||
/* 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(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
|
||||
*/
|
||||
void Housekeeping();
|
||||
|
||||
/*
|
||||
* Return the address that the socket is bound to
|
||||
*/
|
||||
void handleGetsockname(PhySocket *sock, PhySocket *rpcsock, void **uptr, struct getsockname_st *getsockname_rpc);
|
||||
|
||||
/*
|
||||
* Return the address of the peer connected to this socket
|
||||
*/
|
||||
void handleGetpeername(PhySocket *sock, PhySocket *rpcsock, void **uptr, struct getsockname_st *getsockname_rpc);
|
||||
|
||||
/****************************************************************************/
|
||||
/* Not used in this implementation */
|
||||
/****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user