merging recent upgrades into master
This commit is contained in:
41
src/debug.h
41
src/debug.h
@@ -26,16 +26,20 @@
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef _SDK_DEBUG_H_
|
||||
#define _SDK_DEBUG_H_
|
||||
|
||||
#define DEBUG_LEVEL 4 // Set this to adjust what you'd like to see in the debug traces
|
||||
#define DEBUG_LEVEL 1 // Set this to adjust what you'd like to see in the debug traces
|
||||
|
||||
#define MSG_ERROR 1 // Errors
|
||||
#define MSG_TRANSFER 2 // RX/TX specific statements
|
||||
#define MSG_INFO 3 // Information which is generally useful to any developer
|
||||
#define MSG_EXTRA 4 // If nothing in your world makes sense
|
||||
#define MSG_FLOW 5 // High-level flow messages
|
||||
|
||||
#define __SHOW_FILENAMES__ true
|
||||
#define __SHOW_COLOR__ true
|
||||
@@ -79,6 +83,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#define THREAD_ID (long)getpid()
|
||||
#elif __APPLE__
|
||||
#define THREAD_ID (long)syscall(SYS_thread_selfid)
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
@@ -87,10 +97,11 @@ extern "C" {
|
||||
|
||||
//#if defined(SDK_DEBUG)
|
||||
#if DEBUG_LEVEL >= MSG_ERROR
|
||||
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, RED "ZT_ERROR: %14s:%4d:%25s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, RED "ZT_ERROR[%ld] : %14s:%4d:%25s: " fmt "\n" RESET, THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#else
|
||||
#define DEBUG_ERROR(fmt, args...)
|
||||
#endif
|
||||
|
||||
#if DEBUG_LEVEL >= MSG_INFO
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_INFO : %14s:%4d:%20s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
@@ -98,33 +109,47 @@ extern "C" {
|
||||
#define DEBUG_ATTN(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_INFO : %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_STACK: %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define DEBUG_INFO(fmt, args...) fprintf(stderr, "ZT_INFO : %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, CYN "ZT_INFO : %14s:%4d:%25s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_STACK(fmt, args...) fprintf(stderr, YEL "ZT_STACK: %14s:%4d:%25s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, "ZT_INFO : %14s:%4d:" fmt "\n", __FILENAME__, __LINE__, ##args)
|
||||
#define DEBUG_INFO(fmt, args...) fprintf(stderr, "ZT_INFO [%ld] : %14s:%4d:%25s: " fmt "\n", THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, CYN "ZT_ATTN [%ld] : %14s:%4d:%25s: " fmt "\n" RESET, THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_STACK(fmt, args...) fprintf(stderr, YEL "ZT_STACK[%ld] : %14s:%4d:%25s: " fmt "\n" RESET, THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, "ZT_INFO [%ld] : %14s:%4d:" fmt "\n", THREAD_ID, __FILENAME__, __LINE__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_INFO(fmt, args...)
|
||||
#define DEBUG_BLANK(fmt, args...)
|
||||
#define DEBUG_ATTN(fmt, args...)
|
||||
#define DEBUG_STACK(fmt, args...)
|
||||
#endif
|
||||
|
||||
#if DEBUG_LEVEL >= MSG_TRANSFER
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_TRANS : %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, GRN "ZT_TRANS: %14s:%4d:%25s: " fmt "\n" RESET, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, GRN "ZT_TRANS[%ld] : %14s:%4d:%25s: " fmt "\n" RESET, THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_TRANS(fmt, args...)
|
||||
#endif
|
||||
|
||||
#if DEBUG_LEVEL >= MSG_EXTRA
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_EXTRA : %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, "ZT_EXTRA: %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, "ZT_EXTRA[%ld] : %14s:%4d:%25s: " fmt "\n", THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_EXTRA(fmt, args...)
|
||||
#endif
|
||||
|
||||
#if DEBUG_LEVEL >= MSG_FLOW
|
||||
#if defined(__ANDROID__)
|
||||
#define DEBUG_FLOW(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "ZT_FLOW : %14s:%4d:%25s: " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
|
||||
#else
|
||||
#define DEBUG_FLOW(fmt, args...) fprintf(stderr, "ZT_FLOW [%ld] : %14s:%4d:%25s: " fmt "\n", THREAD_ID, __FILENAME__, __LINE__, __FUNCTION__, ##args)
|
||||
#endif
|
||||
#else
|
||||
#define DEBUG_FLOW(fmt, args...)
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
22
src/defs.h
22
src/defs.h
@@ -25,18 +25,15 @@
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
// --- lwIP
|
||||
#define APPLICATION_POLL_FREQ 2
|
||||
#define ZT_LWIP_TCP_TIMER_INTERVAL 50
|
||||
#define STATUS_TMR_INTERVAL 500 // How often we check connection statuses (in ms)
|
||||
#define SDK_MTU 1200//ZT_MAX_MTU // 2800, usually
|
||||
|
||||
// --- picoTCP
|
||||
#define UNIX_SOCK_BUF_SIZE 1024*1024
|
||||
#define ZT_PHY_POLL_INTERVAL 50 // in ms
|
||||
|
||||
// picoTCP
|
||||
#define MAX_PICO_FRAME_RX_BUF_SZ ZT_MAX_MTU * 128
|
||||
|
||||
// --- jip
|
||||
|
||||
// --- General
|
||||
|
||||
// General
|
||||
// TCP Buffer sizes
|
||||
#define DEFAULT_TCP_TX_BUF_SZ 1024 * 1024
|
||||
#define DEFAULT_TCP_RX_BUF_SZ 1024 * 1024
|
||||
@@ -49,4 +46,9 @@
|
||||
|
||||
// UDP Buffer sizes (should be about the size of your MTU)
|
||||
#define DEFAULT_UDP_TX_BUF_SZ ZT_MAX_MTU
|
||||
#define DEFAULT_UDP_RX_BUF_SZ ZT_MAX_MTU * 128
|
||||
#define DEFAULT_UDP_RX_BUF_SZ ZT_MAX_MTU * 10
|
||||
|
||||
// lwIP
|
||||
#define APPLICATION_POLL_FREQ 2
|
||||
#define ZT_LWIP_TCP_TIMER_INTERVAL 50
|
||||
#define STATUS_TMR_INTERVAL 500 // How often we check connection statuses (in ms)
|
||||
74
src/sdk.h
74
src/sdk.h
@@ -28,6 +28,17 @@
|
||||
#ifndef _ZT_SDK_H
|
||||
#define _ZT_SDK_H 1
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// ---------------------------- Compilation flag checks -------------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
#define INTERCEPT_ENABLED 111
|
||||
#define INTERCEPT_DISABLED 222
|
||||
#define MAX_DIR_SZ 256 // Max path length used for home dir
|
||||
|
||||
#if defined(SDK_SERVICE)
|
||||
// Sanity checks for compilation
|
||||
#if !defined(SDK_LWIP) && !defined(SDK_PICOTCP)
|
||||
@@ -44,22 +55,37 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
<<<<<<< HEAD
|
||||
#include <sys/socket.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SETSOCKOPT_SIG int fd, int level, int optname, const void *optval, socklen_t optlen
|
||||
#define GETSOCKOPT_SIG int fd, int level, int optname, void *optval, socklen_t *optlen
|
||||
|
||||
=======
|
||||
// ------------------------------------------------------------------------------
|
||||
// -------------- Socket API function signatures for convenience ----------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
#define SETSOCKOPT_SIG int fd, int level, int optname, const void *optval, socklen_t optlen
|
||||
#define GETSOCKOPT_SIG int fd, int level, int optname, void *optval, socklen_t *optlen
|
||||
>>>>>>> dev
|
||||
#define SENDMSG_SIG int fd, const struct msghdr *msg, int flags
|
||||
#define SENDTO_SIG int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen
|
||||
#define RECV_SIG int fd, void *buf, size_t len, int flags
|
||||
#define RECVFROM_SIG int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen
|
||||
#define RECVMSG_SIG int fd, struct msghdr *msg,int flags
|
||||
<<<<<<< HEAD
|
||||
|
||||
#define SEND_SIG int fd, const void *buf, size_t len, int flags
|
||||
#define WRITE_SIG int fd, const void *buf, size_t len
|
||||
#define READ_SIG int fd, void *buf, size_t len
|
||||
|
||||
=======
|
||||
#define SEND_SIG int fd, const void *buf, size_t len, int flags
|
||||
#define WRITE_SIG int fd, const void *buf, size_t len
|
||||
#define READ_SIG int fd, void *buf, size_t len
|
||||
>>>>>>> dev
|
||||
#define SOCKET_SIG int socket_family, int socket_type, int protocol
|
||||
#define CONNECT_SIG int fd, const struct sockaddr *addr, socklen_t addrlen
|
||||
#define BIND_SIG int fd, const struct sockaddr *addr, socklen_t addrlen
|
||||
@@ -80,15 +106,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INTERCEPT_ENABLED 111
|
||||
#define INTERCEPT_DISABLED 222
|
||||
#define MAX_DIR_SZ 256 // Max path length used for home dir
|
||||
|
||||
extern void load_symbols();
|
||||
extern void zts_init_rpc(const char *path, const char *nwid);
|
||||
extern char *api_netpath;
|
||||
extern char *debug_logfile;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// ------------------------- Ancient INTERCEPT-related cruft --------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
// Function pointers to original system calls
|
||||
// - These are used when we detect that either the intercept is not
|
||||
// available or that ZeroTier hasn't administered the given socket
|
||||
@@ -115,42 +141,35 @@ extern char *debug_logfile;
|
||||
extern int (*realgetsockopt)(GETSOCKOPT_SIG);
|
||||
extern int (*realclose)(CLOSE_SIG);
|
||||
extern int (*realgetsockname)(GETSOCKNAME_SIG);
|
||||
|
||||
// Direct call
|
||||
// - Skips intercept
|
||||
// - Uses RPC
|
||||
// - Depending on the target, the API will be exposed as zt_* in
|
||||
// the specific way needed for that platform, but will be implemented
|
||||
// in terms of zts_*
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// ---------------------------- Direct API call section -------------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
// SOCKS5 Proxy Controls
|
||||
int zts_start_proxy_server(const char *homepath, const char * nwid, struct sockaddr_storage * addr);
|
||||
int zts_stop_proxy_server(const char *nwid);
|
||||
int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage *addr);
|
||||
bool zts_proxy_is_running(const char *nwid);
|
||||
|
||||
// ZT Service Controls
|
||||
void zts_start_service(const char *path);
|
||||
void *zts_start_core_service(void *thread_id);
|
||||
void zts_stop_service();
|
||||
void zts_stop();
|
||||
bool zts_service_is_running();
|
||||
void zts_join_network(const char * nwid);
|
||||
void zts_join_network_soft(const char * filepath, const char * nwid);
|
||||
void zts_leave_network_soft(const char * filepath, const char * nwid);
|
||||
void zts_leave_network(const char * nwid);
|
||||
// void zts_get_addresses(const char * nwid, char * addrstr);
|
||||
void zts_get_ipv4_address(const char *nwid, char *addrstr);
|
||||
void zts_get_ipv6_address(const char *nwid, char *addrstr);
|
||||
bool zts_has_address(const char *nwid);
|
||||
int zts_get_device_id();
|
||||
bool zts_is_relayed();
|
||||
int zts_get_device_id(char *devID);
|
||||
int zts_get_device_id_from_file(const char *filepath, char *devID);
|
||||
char *zts_get_homepath();
|
||||
|
||||
// ZT Intercept/RPC Controls
|
||||
// TODO: Remove any?
|
||||
//void set_intercept_status(int mode); // TODO: Rethink this
|
||||
//void init_service(int key, const char * path);
|
||||
//void init_service_and_rpc(int key, const char * path, const char * nwid);
|
||||
//void init_intercept(int key);
|
||||
|
||||
void zts_get_6plane_addr(char *addr, const char *nwid, const char *devID);
|
||||
void zts_get_rfc4193_addr(char *addr, const char *nwid, const char *devID);
|
||||
// BSD-like socket API
|
||||
int zts_socket(SOCKET_SIG);
|
||||
int zts_connect(CONNECT_SIG);
|
||||
int zts_bind(BIND_SIG);
|
||||
@@ -165,12 +184,10 @@ int zts_getsockname(GETSOCKNAME_SIG);
|
||||
int zts_getpeername(GETPEERNAME_SIG);
|
||||
int zts_close(CLOSE_SIG);
|
||||
int zts_fcntl(FCNTL_SIG);
|
||||
|
||||
ssize_t zts_sendto(SENDTO_SIG);
|
||||
ssize_t zts_sendmsg(SENDMSG_SIG);
|
||||
ssize_t zts_recvfrom(RECVFROM_SIG);
|
||||
ssize_t zts_recvmsg(RECVMSG_SIG);
|
||||
|
||||
#if defined(__UNITY_3D__)
|
||||
ssize_t zts_recv(int fd, void *buf, int len);
|
||||
ssize_t zts_send(int fd, void *buf, int len);
|
||||
@@ -183,7 +200,10 @@ ssize_t zts_recvmsg(RECVMSG_SIG);
|
||||
void zt_leave_network(const char * nwid);
|
||||
#endif
|
||||
|
||||
// Android JNI Direct-call API
|
||||
// ------------------------------------------------------------------------------
|
||||
// --------------------- Direct API call section (for Android) ------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
|
||||
#if defined(__ANDROID__)
|
||||
// ZT SERVICE CONTROLS
|
||||
@@ -226,7 +246,7 @@ ssize_t zts_recvmsg(RECVMSG_SIG);
|
||||
|
||||
|
||||
// Prototypes for redefinition of syscalls
|
||||
// - Implemented in SDK_Intercept.c
|
||||
// - Implemented in intercept.c
|
||||
#if defined(SDK_INTERCEPT)
|
||||
int socket(SOCKET_SIG);
|
||||
int connect(CONNECT_SIG);
|
||||
|
||||
128
src/service.cpp
128
src/service.cpp
@@ -45,29 +45,29 @@
|
||||
#include "OneService.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "OSUtils.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
|
||||
#include "tap.hpp"
|
||||
#include "sdk.h"
|
||||
#include "debug.h"
|
||||
|
||||
std::string service_path;
|
||||
pthread_t intercept_thread;
|
||||
int * intercept_thread_id;
|
||||
pthread_key_t thr_id_key;
|
||||
static ZeroTier::OneService *volatile zt1Service;
|
||||
|
||||
std::string localHomeDir; // Local shortened path
|
||||
std::string givenHomeDir; // What the user/application provides as a suggestion
|
||||
std::string homeDir; // The resultant platform-specific dir we *must* use internally
|
||||
std::string netDir;
|
||||
std::string rpcNWID;
|
||||
|
||||
bool rpcEnabled;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static ZeroTier::OneService *zt1Service;
|
||||
|
||||
std::string service_path;
|
||||
std::string localHomeDir; // Local shortened path
|
||||
std::string givenHomeDir; // What the user/application provides as a suggestion
|
||||
std::string homeDir; // The resultant platform-specific dir we *must* use internally
|
||||
std::string netDir; // Where network .conf files are to be written
|
||||
|
||||
pthread_t intercept_thread;
|
||||
pthread_key_t thr_id_key;
|
||||
|
||||
int * intercept_thread_id;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// --------------------------------- Base zts_* API -----------------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
@@ -122,8 +122,8 @@ int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage * ad
|
||||
|
||||
// Basic ZT service controls
|
||||
// Will also spin up a SOCKS5 proxy server if USE_SOCKS_PROXY is set
|
||||
void zts_join_network(const char * nwid) {
|
||||
DEBUG_INFO();
|
||||
void zts_join_network(const char * nwid) {
|
||||
DEBUG_ERROR();
|
||||
std::string confFile = zt1Service->givenHomePath() + "/networks.d/" + nwid + ".conf";
|
||||
if(!ZeroTier::OSUtils::mkdir(netDir)) {
|
||||
DEBUG_ERROR("unable to create: %s", netDir.c_str());
|
||||
@@ -140,26 +140,50 @@ void zts_join_network(const char * nwid) {
|
||||
zts_start_proxy_server(homeDir.c_str(), nwid, NULL); // NULL addr for default
|
||||
#endif
|
||||
}
|
||||
//
|
||||
// Just create the dir and conf file required, don't instruct the core to do anything
|
||||
void zts_join_network_soft(const char * filepath, const char * nwid) {
|
||||
std::string net_dir = std::string(filepath) + "/networks.d/";
|
||||
std::string confFile = net_dir + std::string(nwid) + ".conf";
|
||||
if(!ZeroTier::OSUtils::mkdir(net_dir)) {
|
||||
DEBUG_ERROR("unable to create: %s", net_dir.c_str());
|
||||
}
|
||||
if(!ZeroTier::OSUtils::fileExists(confFile.c_str(),false)) {
|
||||
if(!ZeroTier::OSUtils::writeFile(confFile.c_str(), "")) {
|
||||
DEBUG_ERROR("unable to write network conf file: %s", confFile.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Prevent service from joining network upon startup
|
||||
void zts_leave_network_soft(const char * filepath, const char * nwid) {
|
||||
std::string net_dir = std::string(filepath) + "/networks.d/";
|
||||
ZeroTier::OSUtils::rm((net_dir + nwid + ".conf").c_str());
|
||||
}
|
||||
// Instruct the service to leave the network
|
||||
void zts_leave_network(const char * nwid) {
|
||||
if(zt1Service)
|
||||
zt1Service->leave(nwid);
|
||||
zt1Service->leave(nwid);
|
||||
}
|
||||
//
|
||||
// Check whether the service is running
|
||||
bool zts_service_is_running() {
|
||||
return !zt1Service ? false : zt1Service->isRunning();
|
||||
}
|
||||
//
|
||||
// Stop the service
|
||||
void zts_stop_service() {
|
||||
if(zt1Service)
|
||||
zt1Service->terminate();
|
||||
}
|
||||
// Stop the service, proxy server, stack, etc
|
||||
void zts_stop() {
|
||||
DEBUG_INFO("Stopping STSDK");
|
||||
zts_stop_service();
|
||||
/* TODO: kill each proxy server as well
|
||||
zts_stop_proxy_server(...); */
|
||||
}
|
||||
|
||||
// FIXME: Re-implemented to make it play nicer with the C-linkage required for Xcode integrations
|
||||
// Now only returns first assigned address per network. Shouldn't normally be a problem.
|
||||
|
||||
// Get IPV4 Address for this device on given network
|
||||
|
||||
bool zts_has_address(const char *nwid)
|
||||
{
|
||||
char ipv4_addr[64], ipv6_addr[64];
|
||||
@@ -172,8 +196,6 @@ bool zts_has_address(const char *nwid)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void zts_get_ipv4_address(const char *nwid, char *addrstr)
|
||||
{
|
||||
uint64_t nwid_int = strtoull(nwid, NULL, 16);
|
||||
@@ -211,23 +233,46 @@ void zts_get_ipv6_address(const char *nwid, char *addrstr)
|
||||
memcpy(addrstr, "-1.-1.-1.-1/-1", 14);
|
||||
}
|
||||
}
|
||||
// Get device ID
|
||||
int zts_get_device_id()
|
||||
{
|
||||
// zt->node->status
|
||||
/* TODO */ return 0;
|
||||
// Get device ID (from running service)
|
||||
int zts_get_device_id(char *devID) {
|
||||
if(zt1Service) {
|
||||
char id[10];
|
||||
sprintf(id, "%lx",zt1Service->getNode()->address());
|
||||
memcpy(devID, id, 10);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
//
|
||||
bool zts_is_relayed() {
|
||||
// TODO
|
||||
// zt1Service->getNode()->peers()
|
||||
return false;
|
||||
// Get device ID (from file)
|
||||
int zts_get_device_id_from_file(const char *filepath, char *devID) {
|
||||
std::string fname("identity.public");
|
||||
std::string fpath(filepath);
|
||||
|
||||
if(ZeroTier::OSUtils::fileExists((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),false)) {
|
||||
std::string oldid;
|
||||
ZeroTier::OSUtils::readFile((fpath + ZT_PATH_SEPARATOR_S + fname).c_str(),oldid);
|
||||
memcpy(devID, oldid.c_str(), 10); // first 10 bytes of file
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
// Return the home path for this instance of ZeroTier
|
||||
char *zts_get_homepath() {
|
||||
return (char*)givenHomeDir.c_str();
|
||||
}
|
||||
|
||||
// Returns a 6PLANE IPv6 address given a network ID and zerotier ID
|
||||
void zts_get_6plane_addr(char *addr, const char *nwid, const char *devID)
|
||||
{
|
||||
ZeroTier::InetAddress _6planeAddr = ZeroTier::InetAddress::makeIpv66plane(ZeroTier::Utils::hexStrToU64(nwid),ZeroTier::Utils::hexStrToU64(devID));
|
||||
memcpy(addr, _6planeAddr.toIpString().c_str(), 40);
|
||||
}
|
||||
// Returns a RFC 4193 IPv6 address given a network ID and zerotier ID
|
||||
void zts_get_rfc4193_addr(char *addr, const char *nwid, const char *devID)
|
||||
{
|
||||
ZeroTier::InetAddress _6planeAddr = ZeroTier::InetAddress::makeIpv6rfc4193(ZeroTier::Utils::hexStrToU64(nwid),ZeroTier::Utils::hexStrToU64(devID));
|
||||
memcpy(addr, _6planeAddr.toIpString().c_str(), 40);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// ----------------------------- .NET Interop functions -------------------------
|
||||
@@ -288,7 +333,6 @@ void zts_start_service(const char *path)
|
||||
}
|
||||
|
||||
//void init_service_and_rpc(int key, const char * path, const char * nwid) {
|
||||
// rpcEnabled = true;
|
||||
// rpcNWID = nwid;
|
||||
// init_service(key, path);
|
||||
//}
|
||||
@@ -483,7 +527,7 @@ void *zts_start_core_service(void *thread_id) {
|
||||
|
||||
// Construct path for network config and supporting service files
|
||||
if (homeDir.length()) {
|
||||
std::vector<std::string> hpsp(ZeroTier::Utils::split(homeDir.c_str(),ZT_PATH_SEPARATOR_S,"",""));
|
||||
std::vector<std::string> hpsp(ZeroTier::OSUtils::split(homeDir.c_str(),ZT_PATH_SEPARATOR_S,"",""));
|
||||
std::string ptmp;
|
||||
if (homeDir[0] == ZT_PATH_SEPARATOR)
|
||||
ptmp.push_back(ZT_PATH_SEPARATOR);
|
||||
@@ -504,17 +548,7 @@ void *zts_start_core_service(void *thread_id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
||||
#if defined(__UNITY_3D__)
|
||||
DEBUG_INFO("starting service...");
|
||||
#endif
|
||||
DEBUG_INFO("starting service...");
|
||||
|
||||
// Initialize RPC
|
||||
// TODO: remove?
|
||||
if(rpcEnabled) {
|
||||
zts_init_rpc(localHomeDir.c_str(), rpcNWID.c_str());
|
||||
}
|
||||
DEBUG_INFO("starting service...");
|
||||
|
||||
// Generate random port for new service instance
|
||||
unsigned int randp = 0;
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
#include "sdk.h"
|
||||
#include "debug.h"
|
||||
#include "rpc.h"
|
||||
#include "defs.h"
|
||||
|
||||
#include "Constants.hpp" // For Tap's MTU
|
||||
|
||||
@@ -100,16 +101,19 @@ int (*realclose)(CLOSE_SIG);
|
||||
// If no path, construct one or get it fron system env vars
|
||||
if(!api_netpath) {
|
||||
rpc_mutex_init();
|
||||
// Provided by user
|
||||
#if defined(SDK_BUNDLED)
|
||||
// Get the path/nwid from the user application
|
||||
// netpath = [path + "/nc_" + nwid]
|
||||
char *fullpath = (char *)malloc(strlen(path)+strlen(nwid)+1+4);
|
||||
if(fullpath) {
|
||||
zts_join_network_soft(path, nwid);
|
||||
strcpy(fullpath, path);
|
||||
strcat(fullpath, "/nc_");
|
||||
strcat(fullpath, nwid);
|
||||
api_netpath = fullpath;
|
||||
}
|
||||
// Provided by Env
|
||||
#else
|
||||
// Get path/nwid from environment variables
|
||||
if (!api_netpath) {
|
||||
@@ -191,7 +195,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
ssize_t zts_sendto(SENDTO_SIG) // Used as internal implementation
|
||||
#endif
|
||||
{
|
||||
DEBUG_EXTRA("fd=%d", fd);
|
||||
//DEBUG_EXTRA("fd=%d", fd);
|
||||
if(len > ZT_UDP_DEFAULT_PAYLOAD_MTU) {
|
||||
errno = EMSGSIZE; // Msg is too large
|
||||
return -1;
|
||||
@@ -232,7 +236,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
ssize_t zts_sendmsg(SENDMSG_SIG)
|
||||
#endif
|
||||
{
|
||||
DEBUG_EXTRA("fd=%d",fd);
|
||||
//DEBUG_EXTRA("fd=%d",fd);
|
||||
char * p, * buf;
|
||||
size_t tot_len = 0;
|
||||
size_t err;
|
||||
@@ -280,7 +284,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
jbyte *body = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
unsigned char buffer[ZT_MAX_MTU];
|
||||
unsigned char buffer[SDK_MTU];
|
||||
int payload_offset = sizeof(int) + sizeof(struct sockaddr_storage);
|
||||
int rxbytes = zts_recvfrom(fd, &buffer, len, flags, &addr, sizeof(struct sockaddr_storage));
|
||||
if(rxbytes > 0)
|
||||
@@ -304,19 +308,42 @@ int (*realclose)(CLOSE_SIG);
|
||||
ssize_t zts_recvfrom(RECVFROM_SIG)
|
||||
#endif
|
||||
{
|
||||
int payload_offset, tmpsz = 0; // payload size
|
||||
char tmpbuf[ZT_MAX_MTU];
|
||||
if(read(fd, tmpbuf, ZT_MAX_MTU) > 0) {
|
||||
int read_chunk_sz = 0, payload_offset, tmpsz=0, pnum=0; // payload size
|
||||
char tmpbuf[SDK_MTU];
|
||||
memset(tmpbuf, 0, SDK_MTU);
|
||||
|
||||
// Attempt to read SDK_MTU sized chunk
|
||||
int total_read = 0, n=0;
|
||||
|
||||
// Read the entire SDK_MTU-sized chunk from the service socket
|
||||
while(total_read < SDK_MTU) {
|
||||
n = read(fd, tmpbuf+total_read, SDK_MTU);
|
||||
if(n>0)
|
||||
total_read += n;
|
||||
else
|
||||
return n;
|
||||
}
|
||||
|
||||
if(n > 0) {
|
||||
// No matter how much we read from the service, only copy 'read_chunk_sz'
|
||||
// into the app's buffer
|
||||
read_chunk_sz = len < SDK_MTU ? len : SDK_MTU;
|
||||
|
||||
// TODO: case for address size mismatch?
|
||||
memcpy(addr, tmpbuf, *addrlen);
|
||||
memcpy(&tmpsz, tmpbuf + sizeof(struct sockaddr_storage), sizeof(tmpsz));
|
||||
memcpy(&pnum, tmpbuf + sizeof(struct sockaddr_storage) + sizeof(int), sizeof(int));
|
||||
if(tmpsz > SDK_MTU || tmpsz < 0) {
|
||||
DEBUG_ERROR("An error occured somewhere in the SDK, read=%d", n);
|
||||
return -1;
|
||||
}
|
||||
payload_offset = sizeof(int) + sizeof(struct sockaddr_storage);
|
||||
memcpy(buf, tmpbuf + payload_offset, ZT_MAX_MTU-payload_offset);
|
||||
memcpy(buf, tmpbuf + payload_offset, read_chunk_sz);
|
||||
}
|
||||
else {
|
||||
perror("read:\n");
|
||||
return -1;
|
||||
}
|
||||
return tmpsz;
|
||||
return read_chunk_sz;
|
||||
}
|
||||
//#endif
|
||||
|
||||
@@ -332,7 +359,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
ssize_t zts_recvmsg(RECVMSG_SIG)
|
||||
#endif
|
||||
{
|
||||
DEBUG_EXTRA("fd=%d", fd);
|
||||
//DEBUG_EXTRA("fd=%d", fd);
|
||||
ssize_t err, n, tot_len = 0;
|
||||
char *buf, *p;
|
||||
struct iovec *iov = msg->msg_iov;
|
||||
@@ -541,7 +568,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
#endif
|
||||
{
|
||||
get_api_netpath();
|
||||
DEBUG_INFO("fd=%d", fd);
|
||||
//DEBUG_INFO("fd=%d", fd);
|
||||
struct connect_st rpc_st;
|
||||
rpc_st.fd = fd;
|
||||
memcpy(&rpc_st.addr, addr, sizeof(struct sockaddr_storage));
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "src/debug.h"
|
||||
#endif
|
||||
|
||||
#include "tap.hpp"
|
||||
#include "sdkutils.hpp"
|
||||
|
||||
@@ -676,10 +680,10 @@ namespace ZeroTier
|
||||
{
|
||||
DEBUG_EXTRA("conn=%p", (void*)&conn);
|
||||
lwIP_stack *stack = tap->lwipstack;
|
||||
if(!conn || (!conn->TCP_pcb && !conn->UDP_pcb)) {
|
||||
DEBUG_ERROR(" invalid connection");
|
||||
return;
|
||||
}
|
||||
if(!conn || (!conn->TCP_pcb && !conn->UDP_pcb)) {
|
||||
DEBUG_ERROR(" invalid connection");
|
||||
return;
|
||||
}
|
||||
if(conn->type == SOCK_DGRAM) {
|
||||
if(!conn->UDP_pcb) {
|
||||
DEBUG_ERROR(" invalid UDP_pcb, type=SOCK_DGRAM");
|
||||
@@ -704,24 +708,24 @@ namespace ZeroTier
|
||||
} else if(err != ERR_OK) {
|
||||
DEBUG_ERROR(" error sending packet - %d", err);
|
||||
} else {
|
||||
// Success
|
||||
// Success
|
||||
int buf_remaining = (conn->txsz)-udp_trans_len;
|
||||
if(buf_remaining)
|
||||
memmove(&conn->txbuf, (conn->txbuf+udp_trans_len), buf_remaining);
|
||||
conn->txsz -= udp_trans_len;
|
||||
|
||||
#if DEBUG_LEVEL >= MSG_TRANSFER
|
||||
struct sockaddr_in * addr_in2 = (struct sockaddr_in *)conn->peer_addr;
|
||||
int port = stack->__lwip_ntohs(addr_in2->sin_port);
|
||||
int ip = addr_in2->sin_addr.s_addr;
|
||||
unsigned char d[4];
|
||||
d[0] = ip & 0xFF;
|
||||
d[1] = (ip >> 8) & 0xFF;
|
||||
d[2] = (ip >> 16) & 0xFF;
|
||||
d[3] = (ip >> 24) & 0xFF;
|
||||
DEBUG_TRANS("[UDP TX] ---> :: {TX: ------, RX: ------, sock=%p} :: %d bytes (dest_addr=%d.%d.%d.%d:%d)",
|
||||
(void*)conn->sock, udp_trans_len, d[0], d[1], d[2], d[3], port);
|
||||
#endif
|
||||
#if DEBUG_LEVEL >= MSG_TRANSFER
|
||||
struct sockaddr_in * addr_in2 = (struct sockaddr_in *)conn->peer_addr;
|
||||
int port = stack->__lwip_ntohs(addr_in2->sin_port);
|
||||
int ip = addr_in2->sin_addr.s_addr;
|
||||
unsigned char d[4];
|
||||
d[0] = ip & 0xFF;
|
||||
d[1] = (ip >> 8) & 0xFF;
|
||||
d[2] = (ip >> 16) & 0xFF;
|
||||
d[3] = (ip >> 24) & 0xFF;
|
||||
DEBUG_TRANS("[UDP TX] ---> :: {TX: ------, RX: ------, sock=%p} :: %d bytes (dest_addr=%d.%d.%d.%d:%d)",
|
||||
(void*)conn->sock, udp_trans_len, d[0], d[1], d[2], d[3], port);
|
||||
#endif
|
||||
}
|
||||
stack->__pbuf_free(pb);
|
||||
return;
|
||||
@@ -764,7 +768,7 @@ namespace ZeroTier
|
||||
DEBUG_ERROR("out of memory");
|
||||
return;
|
||||
} else {
|
||||
// adjust buffer
|
||||
// adjust buffer
|
||||
sz = (conn->txsz)-r;
|
||||
if(sz)
|
||||
memmove(&conn->txbuf, (conn->txbuf+r), sz);
|
||||
|
||||
@@ -479,52 +479,52 @@ namespace ZeroTier {
|
||||
#endif
|
||||
|
||||
#if defined(SDK_IPV6)
|
||||
inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_add(netif,state,init,input); }
|
||||
inline void __nd6_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); _nd6_tmr(); }
|
||||
inline void __netif_ip6_addr_set_state(NETIF_IP6_ADDR_SET_STATE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_ip6_addr_set_state(netif, addr_idx, state); }
|
||||
inline void __netif_create_ip6_linklocal_address(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _netif_create_ip6_linklocal_address(netif, from_mac_48bit); }
|
||||
inline err_t __ethip6_output(ETHIP6_OUTPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethip6_output(netif,q,ip6addr); }
|
||||
inline struct netif * __netif_add(NETIF_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _netif_add(netif,state,init,input); }
|
||||
inline void __nd6_tmr(void) throw() { /**/ Mutex::Lock _l(_lock); _nd6_tmr(); }
|
||||
inline void __netif_ip6_addr_set_state(NETIF_IP6_ADDR_SET_STATE_SIG) throw() { Mutex::Lock _l(_lock); _netif_ip6_addr_set_state(netif, addr_idx, state); }
|
||||
inline void __netif_create_ip6_linklocal_address(NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG) throw() { Mutex::Lock _l(_lock); _netif_create_ip6_linklocal_address(netif, from_mac_48bit); }
|
||||
inline err_t __ethip6_output(ETHIP6_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _ethip6_output(netif,q,ip6addr); }
|
||||
#endif
|
||||
|
||||
inline void __netif_init(void) throw() { Mutex::Lock _l(_lock); _netif_init(); }
|
||||
// inline void __netif_set_addr(NETIF_SET_ADDR_SIG) throw() { Mutex::Lock _l(_lock); _netif_set_addr(netif, ipaddr, netmask, gw); }
|
||||
inline void __lwip_init() throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _lwip_init(); }
|
||||
inline err_t __tcp_write(TCP_WRITE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_write(pcb,arg,len,apiflags); }
|
||||
inline void __tcp_sent(TCP_SENT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_sent(pcb,sent); }
|
||||
inline struct tcp_pcb * __tcp_new(TCP_NEW_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_new(); }
|
||||
inline struct udp_pcb * __udp_new(UDP_NEW_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_new(); }
|
||||
inline err_t __udp_connect(UDP_CONNECT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_connect(pcb,ipaddr,port); }
|
||||
inline err_t __udp_send(UDP_SEND_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_send(pcb,p); }
|
||||
inline err_t __udp_sendto(UDP_SENDTO_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_sendto(pcb,p,dst_ip,dst_port); }
|
||||
inline void __udp_recv(UDP_RECV_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_recv(pcb,recv,recv_arg); }
|
||||
inline err_t __udp_bind(UDP_BIND_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_bind(pcb,ipaddr,port); }
|
||||
inline void __udp_remove(UDP_REMOVE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _udp_remove(pcb); }
|
||||
inline u16_t __tcp_sndbuf(TCP_SNDBUF_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_sndbuf(pcb); }
|
||||
inline err_t __tcp_connect(TCP_CONNECT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_connect(pcb,ipaddr,port,connected); }
|
||||
inline void __tcp_recv(TCP_RECV_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_recv(pcb,recv); }
|
||||
inline void __tcp_recved(TCP_RECVED_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_recved(pcb,len); }
|
||||
inline void __tcp_err(TCP_ERR_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_err(pcb,err); }
|
||||
inline void __tcp_poll(TCP_POLL_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_poll(pcb,poll,interval); }
|
||||
inline void __tcp_arg(TCP_ARG_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _tcp_arg(pcb,arg); }
|
||||
inline err_t __tcp_close(TCP_CLOSE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_close(pcb); }
|
||||
inline void __tcp_abort(TCP_ABORT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_abort(pcb); }
|
||||
inline err_t __tcp_output(TCP_OUTPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_output(pcb); }
|
||||
inline void __tcp_accept(TCP_ACCEPT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_accept(pcb,accept); }
|
||||
inline struct tcp_pcb * __tcp_listen(TCP_LISTEN_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_listen(pcb); }
|
||||
inline struct tcp_pcb * __tcp_listen_with_backlog(TCP_LISTEN_WITH_BACKLOG_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_listen_with_backlog(pcb,backlog); }
|
||||
inline err_t __tcp_bind(TCP_BIND_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_bind(pcb,ipaddr,port); }
|
||||
inline void __etharp_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _etharp_tmr(); }
|
||||
inline void __tcp_tmr(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _tcp_tmr(); }
|
||||
inline u8_t __pbuf_free(PBUF_FREE_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pbuf_free(p); }
|
||||
inline struct pbuf * __pbuf_alloc(PBUF_ALLOC_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock_mem); return _pbuf_alloc(layer,length,type); }
|
||||
inline u16_t __lwip_htons(LWIP_HTONS_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _lwip_htons(x); }
|
||||
inline u16_t __lwip_ntohs(LWIP_NTOHS_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _lwip_ntohs(x); }
|
||||
inline void __lwip_init() throw() { Mutex::Lock _l(_lock); return _lwip_init(); }
|
||||
inline err_t __tcp_write(TCP_WRITE_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_write(pcb,arg,len,apiflags); }
|
||||
inline void __tcp_sent(TCP_SENT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_sent(pcb,sent); }
|
||||
inline struct tcp_pcb * __tcp_new(TCP_NEW_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_new(); }
|
||||
inline struct udp_pcb * __udp_new(UDP_NEW_SIG) throw() { Mutex::Lock _l(_lock); return _udp_new(); }
|
||||
inline err_t __udp_connect(UDP_CONNECT_SIG) throw() { Mutex::Lock _l(_lock); return _udp_connect(pcb,ipaddr,port); }
|
||||
inline err_t __udp_send(UDP_SEND_SIG) throw() { Mutex::Lock _l(_lock); return _udp_send(pcb,p); }
|
||||
inline err_t __udp_sendto(UDP_SENDTO_SIG) throw() { Mutex::Lock _l(_lock); return _udp_sendto(pcb,p,dst_ip,dst_port); }
|
||||
inline void __udp_recv(UDP_RECV_SIG) throw() { Mutex::Lock _l(_lock); return _udp_recv(pcb,recv,recv_arg); }
|
||||
inline err_t __udp_bind(UDP_BIND_SIG) throw() { Mutex::Lock _l(_lock); return _udp_bind(pcb,ipaddr,port); }
|
||||
inline void __udp_remove(UDP_REMOVE_SIG) throw() { Mutex::Lock _l(_lock); return _udp_remove(pcb); }
|
||||
inline u16_t __tcp_sndbuf(TCP_SNDBUF_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_sndbuf(pcb); }
|
||||
inline err_t __tcp_connect(TCP_CONNECT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_connect(pcb,ipaddr,port,connected); }
|
||||
inline void __tcp_recv(TCP_RECV_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_recv(pcb,recv); }
|
||||
inline void __tcp_recved(TCP_RECVED_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_recved(pcb,len); }
|
||||
inline void __tcp_err(TCP_ERR_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_err(pcb,err); }
|
||||
inline void __tcp_poll(TCP_POLL_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_poll(pcb,poll,interval); }
|
||||
inline void __tcp_arg(TCP_ARG_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_arg(pcb,arg); }
|
||||
inline err_t __tcp_close(TCP_CLOSE_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_close(pcb); }
|
||||
inline void __tcp_abort(TCP_ABORT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_abort(pcb); }
|
||||
inline err_t __tcp_output(TCP_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_output(pcb); }
|
||||
inline void __tcp_accept(TCP_ACCEPT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_accept(pcb,accept); }
|
||||
inline struct tcp_pcb * __tcp_listen(TCP_LISTEN_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_listen(pcb); }
|
||||
inline struct tcp_pcb * __tcp_listen_with_backlog(TCP_LISTEN_WITH_BACKLOG_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_listen_with_backlog(pcb,backlog); }
|
||||
inline err_t __tcp_bind(TCP_BIND_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_bind(pcb,ipaddr,port); }
|
||||
inline void __etharp_tmr(void) throw() { Mutex::Lock _l(_lock); return _etharp_tmr(); }
|
||||
inline void __tcp_tmr(void) throw() { Mutex::Lock _l(_lock); return _tcp_tmr(); }
|
||||
inline u8_t __pbuf_free(PBUF_FREE_SIG) throw() { Mutex::Lock _l(_lock); return _pbuf_free(p); }
|
||||
inline struct pbuf * __pbuf_alloc(PBUF_ALLOC_SIG) throw() { Mutex::Lock _l(_lock_mem); return _pbuf_alloc(layer,length,type); }
|
||||
inline u16_t __lwip_htons(LWIP_HTONS_SIG) throw() { Mutex::Lock _l(_lock); return _lwip_htons(x); }
|
||||
inline u16_t __lwip_ntohs(LWIP_NTOHS_SIG) throw() { Mutex::Lock _l(_lock); return _lwip_ntohs(x); }
|
||||
//inline err_t __etharp_output(ETHARP_OUTPUT_SIG) throw() { Mutex::Lock _l(_lock); return _etharp_output(netif,q,ipaddr); }
|
||||
inline err_t __ethernet_input(ETHERNET_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ethernet_input(p,netif); }
|
||||
inline void __tcp_input(TCP_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _tcp_input(p,inp); }
|
||||
inline err_t __ip_input(IP_INPUT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _ip_input(p,inp); }
|
||||
inline void __netif_set_default(NETIF_SET_DEFAULT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_set_default(netif); }
|
||||
inline void __netif_set_up(NETIF_SET_UP_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _netif_set_up(netif); }
|
||||
inline err_t __ethernet_input(ETHERNET_INPUT_SIG) throw() { Mutex::Lock _l(_lock); return _ethernet_input(p,netif); }
|
||||
inline void __tcp_input(TCP_INPUT_SIG) throw() { Mutex::Lock _l(_lock); return _tcp_input(p,inp); }
|
||||
inline err_t __ip_input(IP_INPUT_SIG) throw() { Mutex::Lock _l(_lock); return _ip_input(p,inp); }
|
||||
inline void __netif_set_default(NETIF_SET_DEFAULT_SIG) throw() { Mutex::Lock _l(_lock); return _netif_set_default(netif); }
|
||||
inline void __netif_set_up(NETIF_SET_UP_SIG) throw() { Mutex::Lock _l(_lock); return _netif_set_up(netif); }
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
@@ -40,21 +40,6 @@
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
// This may be removed in production
|
||||
void check_buffer_states(Connection *conn)
|
||||
{
|
||||
#if defined(SDK_DEBUG)
|
||||
if(conn->rxsz < 0) {
|
||||
DEBUG_ERROR("conn->rxsz < 0");
|
||||
exit(0);
|
||||
}
|
||||
if(conn->txsz < 0) {
|
||||
DEBUG_ERROR("conn->txsz < 0");
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Reference to the tap interface
|
||||
// This is needed due to the fact that there's a lot going on in the tap interface
|
||||
// that needs to be updated on each of the network stack's callbacks and not every
|
||||
@@ -121,20 +106,19 @@ namespace ZeroTier {
|
||||
}
|
||||
}
|
||||
|
||||
// I/O thread loop
|
||||
// Main stack loop
|
||||
void pico_loop(NetconEthernetTap *tap)
|
||||
{
|
||||
DEBUG_INFO();
|
||||
while(tap->_run)
|
||||
{
|
||||
tap->_phy.poll(50); // in ms
|
||||
//usleep(50);
|
||||
tap->_phy.poll(ZT_PHY_POLL_INTERVAL); // in ms
|
||||
tap->picostack->__pico_stack_tick();
|
||||
}
|
||||
}
|
||||
|
||||
// RX packets from network onto internal buffer
|
||||
// Also notifies the tap service that data can be read
|
||||
// RX packets from [ZT->STACK] onto RXBUF
|
||||
// Also notify the tap service that data can be read:
|
||||
// [RXBUF -> (ZTSOCK->APP)]
|
||||
// -----------------------------------------
|
||||
// | TAP <-> MEM BUFFER <-> STACK <-> APP |
|
||||
// | |
|
||||
@@ -144,8 +128,7 @@ namespace ZeroTier {
|
||||
// After this step, buffer will be emptied periodically by pico_handleRead()
|
||||
void pico_cb_tcp_read(NetconEthernetTap *tap, struct pico_socket *s)
|
||||
{
|
||||
// TODO: Verify
|
||||
// DEBUG_INFO("picosock=%p", s);
|
||||
DEBUG_INFO();
|
||||
Connection *conn = tap->getConnection(s);
|
||||
if(conn) {
|
||||
int r;
|
||||
@@ -158,11 +141,9 @@ namespace ZeroTier {
|
||||
do {
|
||||
int avail = DEFAULT_TCP_RX_BUF_SZ - conn->rxsz;
|
||||
if(avail) {
|
||||
// r = tap->picostack->__pico_socket_read(s, conn->rxbuf + (conn->rxsz), ZT_MAX_MTU);
|
||||
r = tap->picostack->__pico_socket_recvfrom(s, conn->rxbuf + (conn->rxsz), ZT_MAX_MTU, (void *)&peer.ip4.addr, &port);
|
||||
r = tap->picostack->__pico_socket_recvfrom(s, conn->rxbuf + (conn->rxsz), SDK_MTU, (void *)&peer.ip4.addr, &port);
|
||||
// DEBUG_ATTN("received packet (%d byte) from %08X:%u", r, long_be2(peer.ip4.addr), short_be(port));
|
||||
tap->_phy.setNotifyWritable(conn->sock, true);
|
||||
//DEBUG_EXTRA("read=%d", r);
|
||||
if (r > 0)
|
||||
conn->rxsz += r;
|
||||
}
|
||||
@@ -175,7 +156,7 @@ namespace ZeroTier {
|
||||
DEBUG_ERROR("invalid connection");
|
||||
}
|
||||
|
||||
// RX packets from network onto internal buffer
|
||||
// RX packets from the stack onto internal buffer
|
||||
// Also notifies the tap service that data can be read
|
||||
// -----------------------------------------
|
||||
// | TAP <-> MEM BUFFER <-> STACK <-> APP |
|
||||
@@ -190,49 +171,52 @@ namespace ZeroTier {
|
||||
//
|
||||
void pico_cb_udp_read(NetconEthernetTap *tap, struct pico_socket *s)
|
||||
{
|
||||
DEBUG_INFO();
|
||||
|
||||
Connection *conn = tap->getConnection(s);
|
||||
if(conn) {
|
||||
|
||||
|
||||
uint16_t port = 0;
|
||||
union {
|
||||
struct pico_ip4 ip4;
|
||||
struct pico_ip6 ip6;
|
||||
} peer;
|
||||
|
||||
char tmpbuf[ZT_MAX_MTU];
|
||||
int tot = 0;
|
||||
char tmpbuf[SDK_MTU];
|
||||
unsigned char *addr_pos, *sz_pos, *payload_pos;
|
||||
struct sockaddr_in addr_in;
|
||||
addr_in.sin_addr.s_addr = peer.ip4.addr;
|
||||
addr_in.sin_port = port;
|
||||
|
||||
// RX
|
||||
int r = tap->picostack->__pico_socket_recvfrom(s, tmpbuf, ZT_MAX_MTU, (void *)&peer.ip4.addr, &port);
|
||||
DEBUG_EXTRA("read=%d", r);
|
||||
int r = tap->picostack->__pico_socket_recvfrom(s, tmpbuf, SDK_MTU, (void *)&peer.ip4.addr, &port);
|
||||
DEBUG_FLOW(" [ RXBUF <- STACK] Receiving (%d) from stack, copying to receving buffer", r);
|
||||
|
||||
// Mutex::Lock _l2(tap->_rx_buf_m);
|
||||
// struct sockaddr_in6 addr_in6;
|
||||
// addr_in6.sin6_addr.s6_addr;
|
||||
// addr_in6.sin6_port = Utils::ntoh(s->remote_port);
|
||||
// DEBUG_ATTN("remote_port=%d, local_port=%d", s->remote_port, Utils::ntoh(s->local_port));
|
||||
|
||||
|
||||
picotap->_rx_buf_m.lock();
|
||||
|
||||
if(conn->rxsz == DEFAULT_UDP_RX_BUF_SZ) { // if UDP buffer full
|
||||
DEBUG_INFO("UDP RX buffer full. Discarding oldest payload segment");
|
||||
memmove(conn->rxbuf, conn->rxbuf + ZT_MAX_MTU, DEFAULT_UDP_RX_BUF_SZ - ZT_MAX_MTU);
|
||||
addr_pos = conn->rxbuf + (DEFAULT_UDP_RX_BUF_SZ - ZT_MAX_MTU); // TODO:
|
||||
//DEBUG_FLOW(" [ RXBUF <- STACK] UDP RX buffer full. Discarding oldest payload segment");
|
||||
memmove(conn->rxbuf, conn->rxbuf + SDK_MTU, DEFAULT_UDP_RX_BUF_SZ - SDK_MTU);
|
||||
addr_pos = conn->rxbuf + (DEFAULT_UDP_RX_BUF_SZ - SDK_MTU); // TODO:
|
||||
sz_pos = addr_pos + sizeof(struct sockaddr_storage);
|
||||
conn->rxsz -= ZT_MAX_MTU;
|
||||
conn->rxsz -= SDK_MTU;
|
||||
}
|
||||
else {
|
||||
addr_pos = conn->rxbuf + conn->rxsz; // where we'll prepend the size of the address
|
||||
sz_pos = addr_pos + sizeof(struct sockaddr_storage);
|
||||
}
|
||||
payload_pos = addr_pos + sizeof(struct sockaddr_storage) + sizeof(tot);
|
||||
payload_pos = addr_pos + sizeof(struct sockaddr_storage) + sizeof(r);
|
||||
memcpy(addr_pos, &addr_in, sizeof(struct sockaddr_storage));
|
||||
|
||||
// Adjust buffer size
|
||||
if(r) {
|
||||
conn->rxsz += ZT_MAX_MTU;
|
||||
conn->rxsz += SDK_MTU;
|
||||
memcpy(sz_pos, &r, sizeof(r));
|
||||
tap->phyOnUnixWritable(conn->sock, NULL, true);
|
||||
//tap->_phy.setNotifyWritable(conn->sock, false);
|
||||
@@ -241,6 +225,8 @@ namespace ZeroTier {
|
||||
DEBUG_ERROR("unable to read from picosock=%p", s);
|
||||
}
|
||||
memcpy(payload_pos, tmpbuf, r); // write payload to app's socket
|
||||
//DEBUG_EXTRA(" Copied onto rxbuf (%d) from stack socket", r);
|
||||
picotap->_rx_buf_m.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -257,7 +243,7 @@ namespace ZeroTier {
|
||||
|
||||
// Only called from a locked context, no need to lock anything
|
||||
if(conn->txsz > 0) {
|
||||
int r, max_write_len = conn->txsz < ZT_MAX_MTU ? conn->txsz : ZT_MAX_MTU;
|
||||
int r, max_write_len = conn->txsz < SDK_MTU ? conn->txsz : SDK_MTU;
|
||||
if((r = tap->picostack->__pico_socket_write(s, &conn->txbuf, max_write_len)) < 0) {
|
||||
DEBUG_ERROR("unable to write to picosock=%p", s);
|
||||
return;
|
||||
@@ -276,6 +262,7 @@ namespace ZeroTier {
|
||||
// Main callback for TCP connections
|
||||
void pico_cb_socket_activity(uint16_t ev, struct pico_socket *s)
|
||||
{
|
||||
DEBUG_INFO();
|
||||
int err;
|
||||
Mutex::Lock _l(picotap->_tcpconns_m);
|
||||
Connection *conn = picotap->getConnection(s);
|
||||
@@ -365,7 +352,7 @@ namespace ZeroTier {
|
||||
// -----------------------------------------
|
||||
int pico_eth_send(struct pico_device *dev, void *buf, int len)
|
||||
{
|
||||
DEBUG_INFO("len=%d", len);
|
||||
//DEBUG_INFO("len=%d", len);
|
||||
struct pico_eth_hdr *ethhdr;
|
||||
ethhdr = (struct pico_eth_hdr *)buf;
|
||||
|
||||
@@ -389,35 +376,61 @@ namespace ZeroTier {
|
||||
// It will then periodically be transfered into the network stack via pico_eth_poll()
|
||||
void pico_rx(NetconEthernetTap *tap, const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||
{
|
||||
// DEBUG_INFO();
|
||||
DEBUG_INFO();
|
||||
// Since picoTCP only allows the reception of frames from within the polling function, we
|
||||
// must enqueue each frame into a memory structure shared by both threads. This structure will
|
||||
Mutex::Lock _l(tap->_pico_frame_rxbuf_m);
|
||||
if(len > ((1024 * 1024) - tap->pico_frame_rxbuf_tot)) {
|
||||
DEBUG_ERROR("dropping packet (len = %d) - not enough space left on RX frame buffer", len);
|
||||
return;
|
||||
}
|
||||
//if(len != memcpy(pico_frame_rxbuf, data, len)) {
|
||||
// DEBUG_ERROR("dropping packet (len = %d) - unable to copy contents of frame to RX frame buffer", len);
|
||||
// return;
|
||||
//}
|
||||
|
||||
// assemble new eth header
|
||||
struct pico_eth_hdr ethhdr;
|
||||
from.copyTo(ethhdr.saddr, 6);
|
||||
to.copyTo(ethhdr.daddr, 6);
|
||||
ethhdr.proto = Utils::hton((uint16_t)etherType);
|
||||
int newlen = len+sizeof(struct pico_eth_hdr);
|
||||
//
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot, &newlen, sizeof(newlen)); // size of frame
|
||||
int newlen = len + sizeof(int) + sizeof(struct pico_eth_hdr);
|
||||
|
||||
int mylen;
|
||||
while(newlen > (MAX_PICO_FRAME_RX_BUF_SZ-tap->pico_frame_rxbuf_tot) && ethhdr.proto == 56710)
|
||||
{
|
||||
mylen = 0;
|
||||
DEBUG_ERROR(" [ ZTWIRE -> FBUF ] not enough space left on RX frame buffer, dropping oldest packet in buffer");
|
||||
/*
|
||||
memcpy(&mylen, picotap->pico_frame_rxbuf, sizeof(len));
|
||||
memmove(tap->pico_frame_rxbuf, tap->pico_frame_rxbuf + mylen, MAX_PICO_FRAME_RX_BUF_SZ-mylen); // shift buffer
|
||||
picotap->pico_frame_rxbuf_tot-=mylen;
|
||||
*/
|
||||
memset(tap->pico_frame_rxbuf,0,MAX_PICO_FRAME_RX_BUF_SZ);
|
||||
picotap->pico_frame_rxbuf_tot=0;
|
||||
}
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot, &newlen, sizeof(newlen)); // size of frame + meta
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot + sizeof(newlen), ðhdr, sizeof(ethhdr)); // new eth header
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot + sizeof(newlen) + sizeof(ethhdr), data, len); // frame data
|
||||
tap->pico_frame_rxbuf_tot += len + sizeof(len) + sizeof(ethhdr);
|
||||
// DEBUG_INFO("RX frame buffer %3f full", (float)pico_frame_rxbuf_tot / (float)(1024 * 1024));
|
||||
// DEBUG_INFO("len=%d", len);
|
||||
tap->pico_frame_rxbuf_tot += newlen;
|
||||
DEBUG_FLOW(" [ ZTWIRE -> FBUF ] Move FRAME(sz=%d) into FBUF(sz=%d), data_len=%d", newlen, picotap->pico_frame_rxbuf_tot, len);
|
||||
|
||||
/*
|
||||
char graph[GRAPH_BUF_SZ];
|
||||
gengraph(&graph, GRAPH_BUF_SZ, '|', 0.6);
|
||||
DEBUG_FLOW(graph);
|
||||
*/
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
/*
|
||||
if(newlen > (MAX_PICO_FRAME_RX_BUF_SZ-tap->pico_frame_rxbuf_tot)) {
|
||||
DEBUG_ERROR("dropping packet (len = %d) - not enough space left on RX frame buffer", len);
|
||||
return;
|
||||
}
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot, &newlen, sizeof(newlen)); // size of frame + meta
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot + sizeof(newlen), ðhdr, sizeof(ethhdr)); // new eth header
|
||||
memcpy(tap->pico_frame_rxbuf + tap->pico_frame_rxbuf_tot + sizeof(newlen) + sizeof(ethhdr), data, len); // frame data
|
||||
|
||||
tap->pico_frame_rxbuf_tot += newlen;
|
||||
DEBUG_FLOW(" [ ZTWIRE -> FBUF ] Moved FRAME(sz=%d) into FBUF(sz=%d), data_len=%d, ethhdr.proto=%d", newlen, picotap->pico_frame_rxbuf_tot, len, ethhdr.proto);
|
||||
*/
|
||||
//}
|
||||
}
|
||||
|
||||
// Called periodically by the stack, this removes data from the locked memory buffer and feeds it into the stack.
|
||||
// Called periodically by the stack, this removes data from the locked memory buffer (FBUF) and feeds it into the stack.
|
||||
// A maximum of 'loop_score' frames can be processed in each call
|
||||
// -----------------------------------------
|
||||
// | TAP <-> MEM BUFFER <-> STACK <-> APP |
|
||||
@@ -427,22 +440,28 @@ namespace ZeroTier {
|
||||
// -----------------------------------------
|
||||
int pico_eth_poll(struct pico_device *dev, int loop_score)
|
||||
{
|
||||
// DEBUG_EXTRA();
|
||||
//DEBUG_ERROR();
|
||||
// OPTIMIZATION: The copy logic and/or buffer structure should be reworked for better performance after the BETA
|
||||
// NetconEthernetTap *tap = (NetconEthernetTap*)netif->state;
|
||||
Mutex::Lock _l(picotap->_pico_frame_rxbuf_m);
|
||||
unsigned char frame[ZT_MAX_MTU];
|
||||
uint32_t len;
|
||||
|
||||
while (picotap->pico_frame_rxbuf_tot > 0) {
|
||||
unsigned char frame[SDK_MTU];
|
||||
int len;
|
||||
while (picotap->pico_frame_rxbuf_tot > 0 && loop_score > 0) {
|
||||
DEBUG_INFO(" [ FBUF -> STACK] Frame buffer SZ=%d", picotap->pico_frame_rxbuf_tot);
|
||||
memset(frame, 0, sizeof(frame));
|
||||
len = 0;
|
||||
memcpy(&len, picotap->pico_frame_rxbuf, sizeof(len)); // get frame len
|
||||
memcpy(frame, picotap->pico_frame_rxbuf + sizeof(len), len); // get frame data
|
||||
memmove(picotap->pico_frame_rxbuf, picotap->pico_frame_rxbuf + sizeof(len) + len, ZT_MAX_MTU-(sizeof(len) + len));
|
||||
picotap->picostack->__pico_stack_recv(dev, (uint8_t*)frame, len);
|
||||
picotap->pico_frame_rxbuf_tot-=(sizeof(len) + len);
|
||||
// DEBUG_EXTRA("RX frame buffer %3f full", (float)(picotap->pico_frame_rxbuf_tot) / (float)(MAX_PICO_FRAME_RX_BUF_SZ));
|
||||
if(len >= 0) {
|
||||
DEBUG_FLOW(" [ FBUF -> STACK] Moving FRAME of size (%d) from FBUF(sz=%d) into stack",len, picotap->pico_frame_rxbuf_tot-len);
|
||||
memcpy(frame, picotap->pico_frame_rxbuf + sizeof(len), len-(sizeof(len)) ); // get frame data
|
||||
memmove(picotap->pico_frame_rxbuf, picotap->pico_frame_rxbuf + len, MAX_PICO_FRAME_RX_BUF_SZ-len); // shift buffer
|
||||
picotap->picostack->__pico_stack_recv(dev, (uint8_t*)frame, (len-sizeof(len)));
|
||||
picotap->pico_frame_rxbuf_tot-=len;
|
||||
}
|
||||
else {
|
||||
DEBUG_ERROR("Skipping frame of size (%d)",len);
|
||||
exit(0);
|
||||
}
|
||||
loop_score--;
|
||||
}
|
||||
return loop_score;
|
||||
@@ -475,10 +494,28 @@ namespace ZeroTier {
|
||||
*uptr = newConn;
|
||||
newConn->type = socket_rpc->socket_type;
|
||||
newConn->sock = sock;
|
||||
/*
|
||||
int res = 0;
|
||||
int sendbuff = UNIX_SOCK_BUF_SIZE;
|
||||
socklen_t optlen = sizeof(sendbuff);
|
||||
|
||||
res = setsockopt(picotap->_phy.getDescriptor(sock), SOL_SOCKET, SO_RCVBUF, &sendbuff, sizeof(sendbuff));
|
||||
if(res == -1)
|
||||
DEBUG_ERROR("Error while setting RX buffer limits");
|
||||
res = setsockopt(picotap->_phy.getDescriptor(sock), SOL_SOCKET, SO_SNDBUF, &sendbuff, sizeof(sendbuff));
|
||||
if(res == -1)
|
||||
DEBUG_ERROR("Error while setting TX buffer limits");
|
||||
|
||||
// Get buffer size
|
||||
// optlen = sizeof(sendbuff);
|
||||
// res = getsockopt(picotap->_phy.getDescriptor(sock), SOL_SOCKET, SO_SNDBUF, &sendbuff, &optlen);
|
||||
// DEBUG_INFO("buflen=%d", sendbuff);
|
||||
*/
|
||||
newConn->local_addr = NULL;
|
||||
// newConn->peer_addr = NULL;
|
||||
newConn->picosock = psock;
|
||||
picotap->_Connections.push_back(newConn);
|
||||
memset(newConn->rxbuf, 0, DEFAULT_UDP_RX_BUF_SZ);
|
||||
return newConn;
|
||||
}
|
||||
else {
|
||||
@@ -496,13 +533,13 @@ namespace ZeroTier {
|
||||
// -----------------------------------------
|
||||
void pico_handleWrite(Connection *conn)
|
||||
{
|
||||
DEBUG_INFO();
|
||||
//DEBUG_INFO();
|
||||
if(!conn || !conn->picosock) {
|
||||
DEBUG_ERROR(" invalid connection");
|
||||
return;
|
||||
}
|
||||
|
||||
int max, r, max_write_len = conn->txsz < ZT_MAX_MTU ? conn->txsz : ZT_MAX_MTU;
|
||||
int max, r, max_write_len = conn->txsz < SDK_MTU ? conn->txsz : SDK_MTU;
|
||||
if((r = picotap->picostack->__pico_socket_write(conn->picosock, &conn->txbuf, max_write_len)) < 0) {
|
||||
DEBUG_ERROR("unable to write to picosock=%p, r=%d", (conn->picosock), r);
|
||||
return;
|
||||
@@ -542,16 +579,15 @@ namespace ZeroTier {
|
||||
}
|
||||
if(conn->type == SOCK_DGRAM) {
|
||||
max = DEFAULT_UDP_TX_BUF_SZ;
|
||||
DEBUG_TRANS("[UDP TX] ---> :: {TX: %.3f%%, RX: %.3f%%, physock=%p} :: %d bytes",
|
||||
(float)conn->txsz / (float)max, (float)conn->rxsz / max, conn->sock, r);
|
||||
//DEBUG_TRANS("[UDP TX] ---> :: {TX: %.3f%%, RX: %.3f%%, physock=%p} :: %d bytes",
|
||||
// (float)conn->txsz / (float)max, (float)conn->rxsz / max, conn->sock, r);
|
||||
}
|
||||
check_buffer_states(conn);
|
||||
}
|
||||
|
||||
// Instructs the stack to connect to a remote host
|
||||
void pico_handleConnect(PhySocket *sock, PhySocket *rpcSock, Connection *conn, struct connect_st* connect_rpc)
|
||||
{
|
||||
DEBUG_INFO();
|
||||
//DEBUG_INFO();
|
||||
if(conn->picosock) {
|
||||
struct sockaddr_in *addr = (struct sockaddr_in *) &connect_rpc->addr;
|
||||
int ret;
|
||||
@@ -562,7 +598,7 @@ namespace ZeroTier {
|
||||
char ipv4_str[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &(in4->sin_addr), ipv4_str, INET_ADDRSTRLEN);
|
||||
picotap->picostack->__pico_string_to_ipv4(ipv4_str, &(zaddr.addr));
|
||||
DEBUG_ATTN("addr=%s:%d", ipv4_str, Utils::ntoh(addr->sin_port));
|
||||
//DEBUG_ATTN("addr=%s:%d", ipv4_str, Utils::ntoh(addr->sin_port));
|
||||
ret = picotap->picostack->__pico_socket_connect(conn->picosock, &zaddr, addr->sin_port);
|
||||
#elif defined(SDK_IPV6) // "fd56:5799:d8f6:1238:8c99:9322:30ce:418a"
|
||||
struct pico_ip6 zaddr;
|
||||
@@ -570,7 +606,7 @@ namespace ZeroTier {
|
||||
char ipv6_str[INET6_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET6, &(in6->sin6_addr), ipv6_str, INET6_ADDRSTRLEN);
|
||||
picotap->picostack->__pico_string_to_ipv6(ipv6_str, zaddr.addr);
|
||||
DEBUG_ATTN("addr=%s:%d", ipv6_str, Utils::ntoh(addr->sin_port));
|
||||
//DEBUG_ATTN("addr=%s:%d", ipv6_str, Utils::ntoh(addr->sin_port));
|
||||
ret = picotap->picostack->__pico_socket_connect(conn->picosock, &zaddr, addr->sin_port);
|
||||
#endif
|
||||
|
||||
@@ -661,6 +697,7 @@ namespace ZeroTier {
|
||||
}
|
||||
|
||||
// Feeds data into the local app socket from the I/O buffer associated with the "connection"
|
||||
// [ (APP<-ZTSOCK) <- RXBUF ]
|
||||
// -----------------------------------------
|
||||
// | TAP <-> MEM BUFFER <-> STACK <-> APP |
|
||||
// | |
|
||||
@@ -669,42 +706,53 @@ namespace ZeroTier {
|
||||
// -----------------------------------------
|
||||
void pico_handleRead(PhySocket *sock,void **uptr,bool lwip_invoked)
|
||||
{
|
||||
DEBUG_INFO();
|
||||
if(!lwip_invoked) {
|
||||
// The stack thread writes to RXBUF as well
|
||||
picotap->_tcpconns_m.lock();
|
||||
picotap->_rx_buf_m.lock();
|
||||
}
|
||||
|
||||
int tot = 0, n = -1;
|
||||
|
||||
DEBUG_ATTN();
|
||||
Connection *conn = picotap->getConnection(sock);
|
||||
if(conn && conn->rxsz) {
|
||||
float max = conn->type == SOCK_STREAM ? (float)DEFAULT_TCP_RX_BUF_SZ : (float)DEFAULT_UDP_RX_BUF_SZ;
|
||||
int n = -1;
|
||||
// extract address and payload size info
|
||||
|
||||
if(conn->type==SOCK_DGRAM) {
|
||||
n = picotap->_phy.streamSend(conn->sock, conn->rxbuf, ZT_MAX_MTU);
|
||||
DEBUG_EXTRA("SOCK_DGRAM, conn=%p, physock=%p", conn, sock);
|
||||
//DEBUG_FLOW(" [ ZTSOCK <- RXBUF] attempting write, RXBUF(%d)", conn->rxsz);
|
||||
// Try to write SDK_MTU-sized chunk to app socket
|
||||
while(tot < SDK_MTU) {
|
||||
n = picotap->_phy.streamSend(conn->sock, (conn->rxbuf)+tot, SDK_MTU);
|
||||
tot += n;
|
||||
DEBUG_FLOW(" [ ZTSOCK <- RXBUF] wrote = %d, total = %d", n, tot);
|
||||
}
|
||||
// DEBUG_EXTRA("SOCK_DGRAM, conn=%p, physock=%p", conn, sock);
|
||||
int payload_sz, addr_sz_offset = sizeof(struct sockaddr_storage);
|
||||
memcpy(&payload_sz, conn->rxbuf + addr_sz_offset, sizeof(int));
|
||||
struct sockaddr_storage addr;
|
||||
memcpy(&addr, conn->rxbuf, addr_sz_offset);
|
||||
// adjust buffer
|
||||
if(conn->rxsz-n > 0) // If more remains on buffer
|
||||
memcpy(conn->rxbuf, conn->rxbuf+ZT_MAX_MTU, conn->rxsz - ZT_MAX_MTU);
|
||||
conn->rxsz -= ZT_MAX_MTU;
|
||||
//DEBUG_FLOW(" [ ZTSOCK <- RXBUF] Copying data from receiving buffer to ZT-controlled app socket (n=%d, payload_sz=%d)", n, payload_sz);
|
||||
if(conn->rxsz-n > 0) { // If more remains on buffer
|
||||
memcpy(conn->rxbuf, conn->rxbuf+SDK_MTU, conn->rxsz - SDK_MTU);
|
||||
//DEBUG_FLOW(" [ ZTSOCK <- RXBUF] Data(%d) still on buffer, moving it up by one MTU", conn->rxsz-n);
|
||||
////memset(conn->rxbuf, 0, DEFAULT_UDP_RX_BUF_SZ);
|
||||
////conn->rxsz=SDK_MTU;
|
||||
}
|
||||
conn->rxsz -= SDK_MTU;
|
||||
}
|
||||
|
||||
if(conn->type==SOCK_STREAM) {
|
||||
n = picotap->_phy.streamSend(conn->sock, conn->rxbuf, conn->rxsz);
|
||||
DEBUG_EXTRA("SOCK_STREAM, conn=%p, physock=%p, n=%d", conn, sock, n);
|
||||
if(conn->rxsz-n > 0) // If more remains on buffer
|
||||
memcpy(conn->rxbuf, conn->rxbuf+n, conn->rxsz - n);
|
||||
conn->rxsz -= n;
|
||||
}
|
||||
if(n) {
|
||||
if(conn->type==SOCK_STREAM) {
|
||||
DEBUG_TRANS("[TCP RX] <--- :: {TX: %.3f%%, RX: %.3f%%, physock=%p} :: %d bytes",
|
||||
(float)conn->txsz / max, (float)conn->rxsz / max, conn->sock, n);
|
||||
//DEBUG_TRANS("[TCP RX] <--- :: {TX: %.3f%%, RX: %.3f%%, physock=%p} :: %d bytes",
|
||||
// (float)conn->txsz / max, (float)conn->rxsz / max, conn->sock, n);
|
||||
}
|
||||
if(conn->rxsz == 0) {
|
||||
picotap->_phy.setNotifyWritable(sock, false);
|
||||
@@ -717,13 +765,12 @@ namespace ZeroTier {
|
||||
picotap->_phy.setNotifyWritable(sock, false);
|
||||
}
|
||||
}
|
||||
picotap->_phy.whack();
|
||||
check_buffer_states(conn);
|
||||
|
||||
//picotap->_phy.whack();
|
||||
if(!lwip_invoked) {
|
||||
picotap->_tcpconns_m.unlock();
|
||||
picotap->_rx_buf_m.unlock();
|
||||
}
|
||||
DEBUG_FLOW(" [ ZTSOCK <- RXBUF] Emitted (%d) from RXBUF(%d) to socket", tot, conn->rxsz);
|
||||
}
|
||||
|
||||
// Closes a pico_socket
|
||||
|
||||
@@ -265,31 +265,31 @@ namespace ZeroTier {
|
||||
dlclose(_libref);
|
||||
}
|
||||
|
||||
inline void __pico_stack_init(void) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); _pico_stack_init(); }
|
||||
inline void __pico_stack_init(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); _pico_stack_init(); }
|
||||
inline void __pico_stack_tick(void) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); _pico_stack_tick(); }
|
||||
inline int __pico_ipv4_to_string(PICO_IPV4_TO_STRING_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_ipv4_to_string(ipbuf, ip); }
|
||||
inline int __pico_ipv4_link_add(PICO_IPV4_LINK_ADD_SIG) throw() { DEBUG_STACK(); /*Mutex::Lock _l(_lock);*/ return _pico_ipv4_link_add(dev, address, netmask); }
|
||||
inline int __pico_device_init(PICO_DEVICE_INIT_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_device_init(dev, name, mac); }
|
||||
inline int __pico_stack_recv(PICO_STACK_RECV_SIG) throw() { DEBUG_STACK(); /*Mutex::Lock _l(_lock);*/ return _pico_stack_recv(dev, buffer, len); }
|
||||
inline int __pico_icmp4_ping(PICO_ICMP4_PING_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_icmp4_ping(dst, count, interval, timeout, size, cb); }
|
||||
inline int __pico_string_to_ipv4(PICO_STRING_TO_IPV4_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_string_to_ipv4(ipstr, ip); }
|
||||
inline int __pico_string_to_ipv6(PICO_STRING_TO_IPV6_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_string_to_ipv6(ipstr, ip); }
|
||||
inline int __pico_socket_setoption(PICO_SOCKET_SETOPTION_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_socket_setoption(s, option, value); }
|
||||
inline uint32_t __pico_timer_add(PICO_TIMER_ADD_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_timer_add(expire, timer, arg); }
|
||||
inline int __pico_ipv4_to_string(PICO_IPV4_TO_STRING_SIG) throw() {/* DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_ipv4_to_string(ipbuf, ip); }
|
||||
inline int __pico_ipv4_link_add(PICO_IPV4_LINK_ADD_SIG) throw() { /*DEBUG_STACK();*/ /*Mutex::Lock _l(_lock);*/ return _pico_ipv4_link_add(dev, address, netmask); }
|
||||
inline int __pico_device_init(PICO_DEVICE_INIT_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_device_init(dev, name, mac); }
|
||||
inline int __pico_stack_recv(PICO_STACK_RECV_SIG) throw() { /*DEBUG_STACK();*/ /*Mutex::Lock _l(_lock);*/ return _pico_stack_recv(dev, buffer, len); }
|
||||
inline int __pico_icmp4_ping(PICO_ICMP4_PING_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_icmp4_ping(dst, count, interval, timeout, size, cb); }
|
||||
inline int __pico_string_to_ipv4(PICO_STRING_TO_IPV4_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_string_to_ipv4(ipstr, ip); }
|
||||
inline int __pico_string_to_ipv6(PICO_STRING_TO_IPV6_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_string_to_ipv6(ipstr, ip); }
|
||||
inline int __pico_socket_setoption(PICO_SOCKET_SETOPTION_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_socket_setoption(s, option, value); }
|
||||
inline uint32_t __pico_timer_add(PICO_TIMER_ADD_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_timer_add(expire, timer, arg); }
|
||||
inline int __pico_socket_send(PICO_SOCKET_SEND_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_socket_send(s, buf, len); }
|
||||
inline int __pico_socket_sendto(PICO_SOCKET_SENDTO_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_socket_sendto(s, buf, len, dst, remote_port); }
|
||||
inline int __pico_socket_recv(PICO_SOCKET_RECV_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_socket_recv(s, buf, len); }
|
||||
inline int __pico_socket_recvfrom(PICO_SOCKET_RECVFROM_SIG) throw() { /*DEBUG_STACK();*/ /*Mutex::Lock _l(_lock);*/ return _pico_socket_recvfrom(s, buf, len, orig, remote_port); }
|
||||
inline struct pico_socket * __pico_socket_open(PICO_SOCKET_OPEN_SIG) throw() { DEBUG_ATTN(); return _pico_socket_open(net, proto, wakeup); }
|
||||
inline int __pico_socket_bind(PICO_SOCKET_BIND_SIG) throw() { DEBUG_ATTN(); Mutex::Lock _l(_lock); return _pico_socket_bind(s, local_addr, port); }
|
||||
inline int __pico_socket_connect(PICO_SOCKET_CONNECT_SIG) throw() { DEBUG_ATTN(); Mutex::Lock _l(_lock); return _pico_socket_connect(s, srv_addr, remote_port); }
|
||||
inline int __pico_socket_listen(PICO_SOCKET_LISTEN_SIG) throw() { DEBUG_ATTN(); Mutex::Lock _l(_lock); return _pico_socket_listen(s, backlog); }
|
||||
inline struct pico_socket * __pico_socket_open(PICO_SOCKET_OPEN_SIG) throw() { /*DEBUG_ATTN();*/ return _pico_socket_open(net, proto, wakeup); }
|
||||
inline int __pico_socket_bind(PICO_SOCKET_BIND_SIG) throw() { /*DEBUG_ATTN();*/ Mutex::Lock _l(_lock); return _pico_socket_bind(s, local_addr, port); }
|
||||
inline int __pico_socket_connect(PICO_SOCKET_CONNECT_SIG) throw() { /*DEBUG_ATTN();*/ Mutex::Lock _l(_lock); return _pico_socket_connect(s, srv_addr, remote_port); }
|
||||
inline int __pico_socket_listen(PICO_SOCKET_LISTEN_SIG) throw() { /*DEBUG_ATTN();*/ Mutex::Lock _l(_lock); return _pico_socket_listen(s, backlog); }
|
||||
inline int __pico_socket_read(PICO_SOCKET_READ_SIG) throw() { /*DEBUG_STACK();*/ /*Mutex::Lock _l(_lock); */ return _pico_socket_read(s, buf, len); }
|
||||
inline int __pico_socket_write(PICO_SOCKET_WRITE_SIG) throw() { /*DEBUG_STACK();*/ /*Mutex::Lock _l(_lock);*/ return _pico_socket_write(s, buf, len); }
|
||||
inline int __pico_socket_close(PICO_SOCKET_CLOSE_SIG) throw() { DEBUG_STACK(); /*Mutex::Lock _l(_lock);*/ return _pico_socket_close(s); }
|
||||
inline int __pico_socket_shutdown(PICO_SOCKET_SHUTDOWN_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_socket_shutdown(s, mode); }
|
||||
inline struct pico_socket * __pico_socket_accept(PICO_SOCKET_ACCEPT_SIG) throw() { DEBUG_ATTN(); /*Mutex::Lock _l(_lock);*/ return _pico_socket_accept(s, orig, port); }
|
||||
inline int __pico_ipv6_link_add(PICO_IPV6_LINK_ADD_SIG) throw() { DEBUG_STACK(); Mutex::Lock _l(_lock); return _pico_ipv6_link_add(dev, address, netmask); }
|
||||
inline int __pico_socket_close(PICO_SOCKET_CLOSE_SIG) throw() { /*DEBUG_STACK();*/ /*Mutex::Lock _l(_lock);*/ return _pico_socket_close(s); }
|
||||
inline int __pico_socket_shutdown(PICO_SOCKET_SHUTDOWN_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_socket_shutdown(s, mode); }
|
||||
inline struct pico_socket * __pico_socket_accept(PICO_SOCKET_ACCEPT_SIG) throw() { /*DEBUG_ATTN();*/ /*Mutex::Lock _l(_lock);*/ return _pico_socket_accept(s, orig, port); }
|
||||
inline int __pico_ipv6_link_add(PICO_IPV6_LINK_ADD_SIG) throw() { /*DEBUG_STACK();*/ Mutex::Lock _l(_lock); return _pico_ipv6_link_add(dev, address, netmask); }
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
20
src/tap.cpp
20
src/tap.cpp
@@ -63,7 +63,7 @@ namespace ZeroTier {
|
||||
int NetconEthernetTap::sendReturnValue(int fd, int retval, int _errno)
|
||||
{
|
||||
//#if !defined(USE_SOCKS_PROXY)
|
||||
DEBUG_EXTRA("fd=%d, retval=%d, errno=%d", fd, retval, _errno);
|
||||
//DEBUG_EXTRA("fd=%d, retval=%d, errno=%d", fd, retval, _errno);
|
||||
int sz = sizeof(char) + sizeof(retval) + sizeof(errno);
|
||||
char retmsg[sz];
|
||||
memset(&retmsg, 0, sizeof(retmsg));
|
||||
@@ -328,7 +328,7 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
|
||||
}
|
||||
|
||||
void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) {
|
||||
DEBUG_EXTRA("physock=%p", sock);
|
||||
//DEBUG_EXTRA("physock=%p", sock);
|
||||
Mutex::Lock _l(_tcpconns_m);
|
||||
//closeConnection(sock);
|
||||
}
|
||||
@@ -359,7 +359,7 @@ void NetconEthernetTap::phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_
|
||||
|
||||
void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data, ssize_t len)
|
||||
{
|
||||
DEBUG_EXTRA("physock=%p, len=%d", sock, (int)len);
|
||||
//DEBUG_EXTRA("physock=%p, len=%d", sock, (int)len);
|
||||
uint64_t CANARY_num;
|
||||
pid_t pid, tid;
|
||||
ssize_t wlen = len;
|
||||
@@ -384,7 +384,7 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data,
|
||||
// DEBUG_EXTRA(" RPC: physock=%p, (pid=%d, tid=%d, timestamp=%s, cmd=%d)", sock, pid, tid, timestamp, cmd);
|
||||
|
||||
if(cmd == RPC_SOCKET) {
|
||||
DEBUG_INFO("RPC_SOCKET, physock=%p", sock);
|
||||
//DEBUG_INFO("RPC_SOCKET, physock=%p", sock);
|
||||
// Create new lwip socket and associate it with this sock
|
||||
struct socket_st socket_rpc;
|
||||
memcpy(&socket_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct socket_st));
|
||||
@@ -478,31 +478,31 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data,
|
||||
// DEBUG_EXTRA(" RPC: physock=%p, (pid=%d, tid=%d, timestamp=%s, cmd=%d)", sock, pid, tid, timestamp, cmd);
|
||||
switch(cmd) {
|
||||
case RPC_BIND:
|
||||
DEBUG_INFO("RPC_BIND, physock=%p", sock);
|
||||
//DEBUG_INFO("RPC_BIND, physock=%p", sock);
|
||||
struct bind_st bind_rpc;
|
||||
memcpy(&bind_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct bind_st));
|
||||
handleBind(sock, rpcSock, uptr, &bind_rpc);
|
||||
break;
|
||||
case RPC_LISTEN:
|
||||
DEBUG_INFO("RPC_LISTEN, physock=%p", sock);
|
||||
//DEBUG_INFO("RPC_LISTEN, physock=%p", sock);
|
||||
struct listen_st listen_rpc;
|
||||
memcpy(&listen_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct listen_st));
|
||||
handleListen(sock, rpcSock, uptr, &listen_rpc);
|
||||
break;
|
||||
case RPC_GETSOCKNAME:
|
||||
DEBUG_INFO("RPC_GETSOCKNAME, physock=%p", sock);
|
||||
//DEBUG_INFO("RPC_GETSOCKNAME, physock=%p", sock);
|
||||
struct getsockname_st getsockname_rpc;
|
||||
memcpy(&getsockname_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct getsockname_st));
|
||||
handleGetsockname(sock, rpcSock, uptr, &getsockname_rpc);
|
||||
break;
|
||||
case RPC_GETPEERNAME:
|
||||
DEBUG_INFO("RPC_GETPEERNAME, physock=%p", sock);
|
||||
//DEBUG_INFO("RPC_GETPEERNAME, physock=%p", sock);
|
||||
struct getsockname_st getpeername_rpc;
|
||||
memcpy(&getpeername_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct getsockname_st));
|
||||
handleGetpeername(sock, rpcSock, uptr, &getpeername_rpc);
|
||||
break;
|
||||
case RPC_CONNECT:
|
||||
DEBUG_INFO("RPC_CONNECT, physock=%p", sock);
|
||||
//DEBUG_INFO("RPC_CONNECT, physock=%p", sock);
|
||||
struct connect_st connect_rpc;
|
||||
memcpy(&connect_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct connect_st));
|
||||
handleConnect(sock, rpcSock, conn, &connect_rpc);
|
||||
@@ -574,7 +574,7 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
|
||||
// Connect a stack's PCB/socket/Connection object to a remote host
|
||||
void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Connection *conn, struct connect_st* connect_rpc)
|
||||
{
|
||||
DEBUG_ATTN("physock=%p", sock);
|
||||
//DEBUG_ATTN("physock=%p", sock);
|
||||
Mutex::Lock _l(_tcpconns_m);
|
||||
#if defined(SDK_PICOTCP)
|
||||
pico_handleConnect(sock, rpcSock, conn, connect_rpc);
|
||||
|
||||
Reference in New Issue
Block a user