diff --git a/Makefile b/Makefile index e01b3d7..7e9239f 100644 --- a/Makefile +++ b/Makefile @@ -133,7 +133,7 @@ endif # Build with address sanitization library for advanced debugging (clang) # TODO: Add GCC version as well ifeq ($(LIBZT_SANITIZE),1) - SANFLAGS+=-x c++ -O -g -fsanitize=address -DASAN_OPTIONS=symbolize=1 \ + SANFLAGS+=-x c++ -g -fsanitize=address -DASAN_OPTIONS=symbolize=1 \ -DASAN_SYMBOLIZER_PATH=$(shell which llvm-symbolizer) endif @@ -254,6 +254,7 @@ static_lib: picotcp $(ZTO_OBJS) mv ext/picotcp/build/lib/*.o obj mv ext/picotcp/build/modules/*.o obj $(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o + @date +"Build script finished on %F %T" endif ifeq ($(STACK_LWIP),1) static_lib: lwip $(ZTO_OBJS) @@ -263,6 +264,7 @@ static_lib: lwip $(ZTO_OBJS) $(STACK_DRIVER_FILES) -c mv *.o obj $(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) $(STACK_LIB) obj/*.o + @date +"Build script finished on %F %T" endif # for layer-2 only (this will omit all userspace network stack code) ifeq ($(NO_STACK),1) @@ -271,6 +273,7 @@ static_lib: $(ZTO_OBJS) $(CXX) $(CXXFLAGS) $(ZT_FLAGS) $(ZT_INCLUDES) $(LIBZT_FLAGS) $(LIBZT_INCLUDES) $(LIBZT_FILES) -c mv *.o obj $(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o + @date +"Build script finished on %F %T" endif ############################################################################## @@ -319,19 +322,23 @@ selftest: $(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) $(ZT_UTILS) test/selftest.cpp -o \ $(BUILD)/selftest -L$(BUILD) -lzt -lpthread @./check.sh $(BUILD)/selftest + @date +"Build script finished on %F %T" nativetest: $(CXX) $(CXXFLAGS) -D__NATIVETEST__ $(STACK_DRIVER_FLAGS) $(SANFLAGS) \ $(LIBZT_INCLUDES) $(ZT_INCLUDES) test/selftest.cpp -o $(BUILD)/nativetest @./check.sh $(BUILD)/nativetest + @date +"Build script finished on %F %T" ztproxy: $(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) \ examples/ztproxy/ztproxy.cpp -o $(BUILD)/ztproxy $< -L$(BUILD) -lzt @./check.sh $(BUILD)/ztproxy + @date +"Build script finished on %F %T" intercept: $(CXX) $(CXXFLAGS) $(SANFLAGS) $(STACK_DRIVER_FLAGS) $(LIBZT_INCLUDES) \ $(ZT_INCLUDES) examples/intercept/intercept.cpp -D_GNU_SOURCE \ -shared -o $(BUILD)/intercept.so $< -ldl @./check.sh $(BUILD)/intercept.so + @date +"Build script finished on %F %T" ############################################################################## ## Misc ## @@ -348,5 +355,7 @@ clean: -rm -f *.o *.s .depend* *.core core -rm -rf $(BUILD)/* -find . -type f \( -name '*.a' -o -name '*.o' -o -name '*.so' -o -name \ - '*.o.d' -o -name '*.out' -o -name '*.log' -o -name '*.dSYM' \) -delete + '*.o.d' -o -name '*.out' -o -name '*.log' -o -name '*.dSYM' \) -delete +time: + @date +"Build script finished on %F %T" \ No newline at end of file diff --git a/include/libzt.h b/include/libzt.h index 90e74cb..7aee5a6 100644 --- a/include/libzt.h +++ b/include/libzt.h @@ -542,36 +542,34 @@ ssize_t zts_recvmsg(ZT_RECVMSG_SIG); /** * Read bytes from socket onto buffer - * - Note, this function isn't strictly necessary, you can - * use a regular read() call as long as the socket fd was - * created via a zts_socket() call. + * - Note, this function isn't strictly necessary, you can use a regular read() + * call as long as the socket file descriptor was created via a zts_socket() call. */ int zts_read(ZT_READ_SIG); /** * Write bytes from buffer to socket - * - Note, this function isn't strictly necessary, you can - * use a regular write() call as long as the socket fd was - * created via a zts_socket() call. + * - Note, this function isn't strictly necessary, you can use a regular write() + * call as long as the socket file descriptor was created via a zts_socket() call. */ int zts_write(ZT_WRITE_SIG); -/* +/** * Sends a FIN segment */ int zts_shutdown(ZT_SHUTDOWN_SIG); -/* +/** * Returns a vector of network routes { target, via, metric, etc... } */ std::vector *zts_get_network_routes(char *nwid); -/* +/** * Adds a DNS nameserver for the network stack to use */ int zts_add_dns_nameserver(struct sockaddr *addr); -/* +/** * Removes a DNS nameserver */ int zts_del_dns_nameserver(struct sockaddr *addr); @@ -593,7 +591,7 @@ namespace ZeroTier struct InetAddress; } -/* +/** * Whether we can add a new socket or not. Depends on stack in use */ bool can_provision_new_socket(int socket_type); @@ -607,7 +605,7 @@ bool can_provision_new_socket(int socket_type); */ int zts_num_active_virt_sockets(); -/* +/** * Returns maximum number of sockets allowed by network stack */ int zts_maxsockets(int socket_type); @@ -624,46 +622,47 @@ ZeroTier::VirtualTap *getTapByName(char *ifname); ZeroTier::VirtualTap *getTapByIndex(int index); ZeroTier::VirtualTap *getAnyTap(); -/* - * Returns a pointer to a VirtualSocket for a given fd +/** + * Returns a pointer to a VirtualSocket for a given file descriptor */ ZeroTier::VirtualSocket *get_virt_socket(int fd); -/* +/** * Removes a VirtualSocket */ int del_virt_socket(int fd); -/* +/** * Adds a virtualSocket */ int add_unassigned_virt_socket(int fd, ZeroTier::VirtualSocket *vs); -/* + +/** * Removes unassigned VirtualSocket */ int del_unassigned_virt_socket(int fd); -/* +/** * Adds an assigned VirtualSocket */ int add_assigned_virt_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd); -/* +/** * Removes an assigned VirtualSocket */ int del_assigned_virt_socket(ZeroTier::VirtualTap *tap, ZeroTier::VirtualSocket *vs, int fd); -/* +/** * Gets a pair of associated virtual objects (VirtualSocket bound to a VirtualTap) */ std::pair *get_assigned_virtual_pair(int fd); -/* +/** * Disable all virtual tap devices */ void disableTaps(); -/* +/** * Get device ID (from file) */ int zts_get_device_id_from_file(const char *filepath, char *devID); @@ -673,8 +672,8 @@ int zts_get_device_id_from_file(const char *filepath, char *devID); */ void *zts_start_service(void *thread_id); -/* - * +/** + * Should be called wherever libzt enters a condition where undefined behaviour might occur */ void handle_general_failure(); diff --git a/src/Utilities.hpp b/src/Utilities.hpp index db8df58..bf54c6c 100644 --- a/src/Utilities.hpp +++ b/src/Utilities.hpp @@ -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) diff --git a/src/VirtualSocket.hpp b/src/VirtualSocket.hpp index 7e28295..294e2cf 100644 --- a/src/VirtualSocket.hpp +++ b/src/VirtualSocket.hpp @@ -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 diff --git a/src/VirtualTap.hpp b/src/VirtualTap.hpp index 3304098..000caac 100644 --- a/src/VirtualTap.hpp +++ b/src/VirtualTap.hpp @@ -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 &added,std::vector &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 */ /****************************************************************************/