improved debugging usability for all platforms

This commit is contained in:
Joseph Henry
2016-09-06 15:07:06 -07:00
parent 9943db56d2
commit 1af75c386e
15 changed files with 458 additions and 485 deletions

View File

@@ -102,9 +102,9 @@ public class ZTSDK {
return zt_get_proxy_port(nwid); return zt_get_proxy_port(nwid);
} }
public native boolean zt_running(); public native boolean zt_service_is_running();
public boolean running() { public boolean service_is_running() {
return zt_running(); return zt_service_is_running();
} }
@@ -272,4 +272,11 @@ public class ZTSDK {
//public static native int zt_getsockopt(int fd, int type, int protocol); //public static native int zt_getsockopt(int fd, int type, int protocol);
//public static native int zt_setsockopt(int fd, int type, int protocol); //public static native int zt_setsockopt(int fd, int type, int protocol);
//public static native int zt_getsockname(int fd, int type, int protocol); //public static native int zt_getsockname(int fd, int type, int protocol);
// PROXY SERVER CONTROLS
public native boolean zt_proxy_is_running();
public boolean proxy_is_running() {
return zt_proxy_is_running();
}
} }

View File

@@ -34,7 +34,14 @@ public class MainActivity extends AppCompatActivity {
zt.start_service(homeDir); zt.start_service(homeDir);
} }
}).start(); }).start();
while(!zt.running()) { } while(!zt.service_is_running()) { }
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// client/server mode toggle // client/server mode toggle
int mode = 4, err; int mode = 4, err;

View File

@@ -12,7 +12,6 @@
7C9587951D6FB4C80014AF6B /* SDK_Service.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA03DE1D628E88003F9B1A /* SDK_Service.cpp */; }; 7C9587951D6FB4C80014AF6B /* SDK_Service.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA03DE1D628E88003F9B1A /* SDK_Service.cpp */; };
7CAA03DF1D628E88003F9B1A /* SDK_Service.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA03DE1D628E88003F9B1A /* SDK_Service.cpp */; }; 7CAA03DF1D628E88003F9B1A /* SDK_Service.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CAA03DE1D628E88003F9B1A /* SDK_Service.cpp */; };
7CC003261D1216E3003E68DC /* ZeroTierSDK_iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC003251D1216E3003E68DC /* ZeroTierSDK_iOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7CC003261D1216E3003E68DC /* ZeroTierSDK_iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC003251D1216E3003E68DC /* ZeroTierSDK_iOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
7CC003501D12178D003E68DC /* SDK_Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003421D12178D003E68DC /* SDK_Debug.c */; };
7CC003511D12178D003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; }; 7CC003511D12178D003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; };
7CC003521D12178D003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; }; 7CC003521D12178D003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; };
7CC003531D12178D003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; }; 7CC003531D12178D003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; };
@@ -84,7 +83,6 @@
7CC004351D121840003E68DC /* Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC0041C1D121840003E68DC /* Utils.cpp */; }; 7CC004351D121840003E68DC /* Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC0041C1D121840003E68DC /* Utils.cpp */; };
7CC0043A1D12184F003E68DC /* ControlPlane.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC004361D12184F003E68DC /* ControlPlane.cpp */; }; 7CC0043A1D12184F003E68DC /* ControlPlane.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC004361D12184F003E68DC /* ControlPlane.cpp */; };
7CC0043B1D12184F003E68DC /* OneService.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC004381D12184F003E68DC /* OneService.cpp */; }; 7CC0043B1D12184F003E68DC /* OneService.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC004381D12184F003E68DC /* OneService.cpp */; };
7CC0043C1D1316BF003E68DC /* SDK_Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003421D12178D003E68DC /* SDK_Debug.c */; };
7CC0043D1D1316BF003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; }; 7CC0043D1D1316BF003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; };
7CC0043E1D1316BF003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; }; 7CC0043E1D1316BF003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; };
7CC0043F1D1316BF003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; }; 7CC0043F1D1316BF003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; };
@@ -156,7 +154,6 @@
7CC004841D131704003E68DC /* tcpip.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003641D1217C3003E68DC /* tcpip.c */; }; 7CC004841D131704003E68DC /* tcpip.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003641D1217C3003E68DC /* tcpip.c */; };
7CC004851D1318DA003E68DC /* lz4.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC0035A1D1217B2003E68DC /* lz4.c */; }; 7CC004851D1318DA003E68DC /* lz4.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC0035A1D1217B2003E68DC /* lz4.c */; };
7CC004861D1318DA003E68DC /* http_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003571D1217A1003E68DC /* http_parser.c */; }; 7CC004861D1318DA003E68DC /* http_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003571D1217A1003E68DC /* http_parser.c */; };
7CC004871D131E21003E68DC /* SDK_Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003421D12178D003E68DC /* SDK_Debug.c */; };
7CC004881D131E21003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; }; 7CC004881D131E21003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; };
7CC004891D131E21003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; }; 7CC004891D131E21003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; };
7CC0048A1D131E21003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; }; 7CC0048A1D131E21003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; };
@@ -228,7 +225,6 @@
7CC004D01D131E37003E68DC /* lz4.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC0035A1D1217B2003E68DC /* lz4.c */; }; 7CC004D01D131E37003E68DC /* lz4.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC0035A1D1217B2003E68DC /* lz4.c */; };
7CC004D11D131E37003E68DC /* http_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003571D1217A1003E68DC /* http_parser.c */; }; 7CC004D11D131E37003E68DC /* http_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003571D1217A1003E68DC /* http_parser.c */; };
7CC004D21D131F76003E68DC /* ip_addr.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003921D1217DD003E68DC /* ip_addr.c */; }; 7CC004D21D131F76003E68DC /* ip_addr.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003921D1217DD003E68DC /* ip_addr.c */; };
7CC004D71D13247A003E68DC /* SDK_Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003421D12178D003E68DC /* SDK_Debug.c */; };
7CC004D81D13247A003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; }; 7CC004D81D13247A003E68DC /* SDK_EthernetTap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */; };
7CC004D91D13247A003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; }; 7CC004D91D13247A003E68DC /* SDK_Intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003461D12178D003E68DC /* SDK_Intercept.c */; };
7CC004DA1D13247A003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; }; 7CC004DA1D13247A003E68DC /* SDK_Proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC003481D12178D003E68DC /* SDK_Proxy.cpp */; };
@@ -314,7 +310,6 @@
7CC003341D1216F8003E68DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 7CC003341D1216F8003E68DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7CC0033C1D121741003E68DC /* ZeroTierSDK_Unity3D_OSX.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZeroTierSDK_Unity3D_OSX.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 7CC0033C1D121741003E68DC /* ZeroTierSDK_Unity3D_OSX.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZeroTierSDK_Unity3D_OSX.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
7CC0033E1D121742003E68DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 7CC0033E1D121742003E68DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7CC003421D12178D003E68DC /* SDK_Debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDK_Debug.c; path = ../../../src/SDK_Debug.c; sourceTree = "<group>"; };
7CC003431D12178D003E68DC /* SDK_Debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDK_Debug.h; path = ../../../src/SDK_Debug.h; sourceTree = "<group>"; }; 7CC003431D12178D003E68DC /* SDK_Debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDK_Debug.h; path = ../../../src/SDK_Debug.h; sourceTree = "<group>"; };
7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SDK_EthernetTap.cpp; path = ../../../src/SDK_EthernetTap.cpp; sourceTree = "<group>"; }; 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SDK_EthernetTap.cpp; path = ../../../src/SDK_EthernetTap.cpp; sourceTree = "<group>"; };
7CC003451D12178D003E68DC /* SDK_EthernetTap.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = SDK_EthernetTap.hpp; path = ../../../src/SDK_EthernetTap.hpp; sourceTree = "<group>"; }; 7CC003451D12178D003E68DC /* SDK_EthernetTap.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = SDK_EthernetTap.hpp; path = ../../../src/SDK_EthernetTap.hpp; sourceTree = "<group>"; };
@@ -733,7 +728,6 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
7CAA03DE1D628E88003F9B1A /* SDK_Service.cpp */, 7CAA03DE1D628E88003F9B1A /* SDK_Service.cpp */,
7CC003421D12178D003E68DC /* SDK_Debug.c */,
7CC003431D12178D003E68DC /* SDK_Debug.h */, 7CC003431D12178D003E68DC /* SDK_Debug.h */,
7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */, 7CC003441D12178D003E68DC /* SDK_EthernetTap.cpp */,
7CC003451D12178D003E68DC /* SDK_EthernetTap.hpp */, 7CC003451D12178D003E68DC /* SDK_EthernetTap.hpp */,
@@ -958,7 +952,6 @@
7CC003821D1217D1003E68DC /* memp.c in Sources */, 7CC003821D1217D1003E68DC /* memp.c in Sources */,
7CC003661D1217C3003E68DC /* api_msg.c in Sources */, 7CC003661D1217C3003E68DC /* api_msg.c in Sources */,
7CC004291D121840003E68DC /* NetworkConfig.cpp in Sources */, 7CC004291D121840003E68DC /* NetworkConfig.cpp in Sources */,
7CC003501D12178D003E68DC /* SDK_Debug.c in Sources */,
7CC004321D121840003E68DC /* SHA512.cpp in Sources */, 7CC004321D121840003E68DC /* SHA512.cpp in Sources */,
7CC003531D12178D003E68DC /* SDK_Proxy.cpp in Sources */, 7CC003531D12178D003E68DC /* SDK_Proxy.cpp in Sources */,
7CC003961D1217DD003E68DC /* icmp.c in Sources */, 7CC003961D1217DD003E68DC /* icmp.c in Sources */,
@@ -1101,7 +1094,6 @@
7CC0045D1D1316F5003E68DC /* BackgroundResolver.cpp in Sources */, 7CC0045D1D1316F5003E68DC /* BackgroundResolver.cpp in Sources */,
7CC0045E1D1316F5003E68DC /* Http.cpp in Sources */, 7CC0045E1D1316F5003E68DC /* Http.cpp in Sources */,
7CC0045F1D1316F5003E68DC /* OSUtils.cpp in Sources */, 7CC0045F1D1316F5003E68DC /* OSUtils.cpp in Sources */,
7CC0043C1D1316BF003E68DC /* SDK_Debug.c in Sources */,
7CC0043D1D1316BF003E68DC /* SDK_EthernetTap.cpp in Sources */, 7CC0043D1D1316BF003E68DC /* SDK_EthernetTap.cpp in Sources */,
7CC0043E1D1316BF003E68DC /* SDK_Intercept.c in Sources */, 7CC0043E1D1316BF003E68DC /* SDK_Intercept.c in Sources */,
7CC0043F1D1316BF003E68DC /* SDK_Proxy.cpp in Sources */, 7CC0043F1D1316BF003E68DC /* SDK_Proxy.cpp in Sources */,
@@ -1152,7 +1144,6 @@
7CC004CD1D131E2D003E68DC /* netifapi.c in Sources */, 7CC004CD1D131E2D003E68DC /* netifapi.c in Sources */,
7CC004CE1D131E2D003E68DC /* sockets.c in Sources */, 7CC004CE1D131E2D003E68DC /* sockets.c in Sources */,
7CC004CF1D131E2D003E68DC /* tcpip.c in Sources */, 7CC004CF1D131E2D003E68DC /* tcpip.c in Sources */,
7CC004871D131E21003E68DC /* SDK_Debug.c in Sources */,
7CC004881D131E21003E68DC /* SDK_EthernetTap.cpp in Sources */, 7CC004881D131E21003E68DC /* SDK_EthernetTap.cpp in Sources */,
7CC004891D131E21003E68DC /* SDK_Intercept.c in Sources */, 7CC004891D131E21003E68DC /* SDK_Intercept.c in Sources */,
7CC0048A1D131E21003E68DC /* SDK_Proxy.cpp in Sources */, 7CC0048A1D131E21003E68DC /* SDK_Proxy.cpp in Sources */,
@@ -1261,7 +1252,6 @@
7CC004F81D1324A2003E68DC /* BackgroundResolver.cpp in Sources */, 7CC004F81D1324A2003E68DC /* BackgroundResolver.cpp in Sources */,
7CC004F91D1324A2003E68DC /* Http.cpp in Sources */, 7CC004F91D1324A2003E68DC /* Http.cpp in Sources */,
7CC004FA1D1324A2003E68DC /* OSUtils.cpp in Sources */, 7CC004FA1D1324A2003E68DC /* OSUtils.cpp in Sources */,
7CC004D71D13247A003E68DC /* SDK_Debug.c in Sources */,
7CC004D81D13247A003E68DC /* SDK_EthernetTap.cpp in Sources */, 7CC004D81D13247A003E68DC /* SDK_EthernetTap.cpp in Sources */,
7CC004D91D13247A003E68DC /* SDK_Intercept.c in Sources */, 7CC004D91D13247A003E68DC /* SDK_Intercept.c in Sources */,
7CC004DA1D13247A003E68DC /* SDK_Proxy.cpp in Sources */, 7CC004DA1D13247A003E68DC /* SDK_Proxy.cpp in Sources */,

View File

@@ -86,15 +86,16 @@ extern char *debug_logfile;
// the specific way needed for that platform, but will be implemented // the specific way needed for that platform, but will be implemented
// in terms of zts_* // in terms of zts_*
// NOTE: Each platform specific exposed API will be implemented in terms of zts_*
// SOCKS5 Proxy Controls // SOCKS5 Proxy Controls
int zts_start_proxy_server(const char *homepath, const char * nwid, struct sockaddr_storage * addr); 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_stop_proxy_server(const char *nwid);
int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage *addr); int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage *addr);
bool zts_proxy_is_running();
// ZT Service Controls // ZT Service Controls
void *zts_start_service(void *thread_id); void *zts_start_service(void *thread_id);
void zts_stop_service(); void zts_stop_service();
bool zts_is_running(); bool zts_service_is_running();
void zts_join_network(const char * nwid); void zts_join_network(const char * nwid);
void zts_leave_network(const char * nwid); void zts_leave_network(const char * nwid);
void zts_get_addresses(const char * nwid, char * addrstr); void zts_get_addresses(const char * nwid, char * addrstr);
@@ -144,44 +145,43 @@ ssize_t zts_recvmsg(RECVMSG_SIG);
// Android JNI Direct-call API // Android JNI Direct-call API
// JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME // JNI naming convention: Java_PACKAGENAME_CLASSNAME_METHODNAME
#if defined(__ANDROID__) #if defined(__ANDROID__)
// Exported JNI : ZT SERVICE CONTROLS // ZT SERVICE CONTROLS
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1start_1service(JNIEnv *env, jobject thisObj, jstring path); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1start_1service(JNIEnv *env, jobject thisObj, jstring path);
JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_zt_1stop_service(); JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1stop_service();
JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1join_1network(JNIEnv *env, jobject thisObj, jstring nwid); JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1service_1is_1running(JNIEnv *env, jobject thisObj);
JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1leave_1network(JNIEnv *env, jobject thisObj, jstring nwid); JNIEXPORT jstring JNICALL Java_ZeroTier_ZTSDK_zt_1get_1homepath(JNIEnv *env, jobject thisObj);
JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_zt_1running(JNIEnv *env, jobject thisObj); JNIEXPORT void JNICALL Java_ZeroTier_ZTSDK_zt_1join_1network(JNIEnv *env, jobject thisObj, jstring nwid);
JNIEXPORT jobject JNICALL Java_ZeroTier_SDK_zt_1get_1addresses(JNIEnv *env, jobject thisObj, jstring nwid); JNIEXPORT void JNICALL Java_ZeroTier_ZTSDK_zt_1leave_1network(JNIEnv *env, jobject thisObj, jstring nwid);
JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_zt_1is_1relayed(); JNIEXPORT jobject JNICALL Java_ZeroTier_ZTSDK_zt_1get_1addresses(JNIEnv *env, jobject thisObj, jstring nwid);
// Returns the homepath JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1is_1relayed();
JNIEXPORT jstring JNICALL Java_ZeroTier_SDK_zt_1get_1homepath(JNIEnv *env, jobject thisObj);
// Exported JNI : SOCKS5 PROXY SERVER CONTROLS // SOCKS5 PROXY SERVER CONTROLS
// Stops the SOCKS5 proxy server for a given ZeroTier network JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1start_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid, jobject zaddr);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1start_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid, jobject zaddr); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1stop_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1stop_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1get_1proxy_1server_1address(JNIEnv *env, jobject thisObj, jstring nwid, jobject zaddr);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1get_1proxy_1server_1address(JNIEnv *env, jobject thisObj, jstring nwid, jobject zaddr); JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1proxy_1is_1running(JNIEnv *env, jobject thisObj, jstring nwid);
// Exported JNI : SOCKET API // SOCKET API
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1socket(JNIEnv *env, jobject thisObj, jint family, jint type, jint protocol); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1socket(JNIEnv *env, jobject thisObj, jint family, jint type, jint protocol);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1connect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1connect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1bind(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1bind(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1accept4(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port, jint flags); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1accept4(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port, jint flags);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1accept(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1accept(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1listen(JNIEnv *env, jobject thisObj, jint fd, int backlog); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1listen(JNIEnv *env, jobject thisObj, jint fd, int backlog);
// TCP // TCP
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1write(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1write(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1read(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1read(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags);
// UDP // UDP
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1sendto(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1sendto(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1recvfrom(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1recvfrom(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr);
// GENERAL UTILITY // GENERAL UTILITY
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1close(JNIEnv *env, jobject thisObj, jint fd); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1close(JNIEnv *env, jobject thisObj, jint fd);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1fcntl(JNIEnv *env, jobject thisObj, jint socket, jint cmd, jint flags); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1fcntl(JNIEnv *env, jobject thisObj, jint socket, jint cmd, jint flags);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1setsockopt(JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1setsockopt(JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1getsockopt(JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1getsockopt(JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1getsockname(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1getsockname(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr);
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1getpeername(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr); JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1getpeername(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr);
#endif #endif

View File

@@ -1,131 +0,0 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* ZeroTier may be used and distributed under the terms of the GPLv3, which
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
*
* If you would like to embed ZeroTier into a commercial application or
* redistribute it in a modified binary form, please contact ZeroTier Networks
* LLC. Start here: http://www.zerotier.com/
*/
#ifndef _COMMON_DEBUG_
#define _COMMON_DEBUG_
#include <stdio.h>
#include <netdb.h>
#include <stdarg.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/syscall.h>
#ifndef SDK_DEBUG_H
#define SDK_DEBUG_H
// Set during make (e.g. make SDK_DEBUG=2)
#define DEBUG_LEVEL 4
#define MSG_ERROR 1 // Errors
#define MSG_TRANSFER 2 // RX/TX specific statements
#define MSG_INFO 3 // Information which is generally useful to any user
#define MSG_DEBUG 4 // Information which is only useful to someone debugging
#define MSG_DEBUG_EXTRA 5 // If nothing in your world makes sense
#ifdef __cplusplus
extern "C" {
#endif
#if __ANDROID__
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "ZTSDK"
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
#else
#define LOGV(...) fprintf(stdout, __VA_ARGS__)
#define LOGI(...) fprintf(stdout, __VA_ARGS__)
#define LOGD(...) fprintf(stdout, __VA_ARGS__)
#define LOGE(...) fprintf(stdout, __VA_ARGS__)
#endif
#ifdef __cplusplus
} // extern "C"
#endif
//char *debug_logfile = (char*)0;
void dwr(int level, const char *fmt, ... );
//#if !defined(__ANDROID__)
void dwr(int level, const char *fmt, ... )
{
#if defined(SDK_DEBUG)
if(level > DEBUG_LEVEL)
return;
int saveerr;
saveerr = errno;
va_list ap;
va_start(ap, fmt);
char timestring[20];
time_t timestamp;
timestamp = time(NULL);
strftime(timestring, sizeof(timestring), "%H:%M:%S", localtime(&timestamp));
#if defined(__ANDROID__)
pid_t tid = gettid();
#elif defined(__linux__)
pid_t tid = 5;//syscall(SYS_gettid);
#elif defined(__APPLE__)
pid_t tid = pthread_mach_thread_np(pthread_self());
#endif
#if defined(SDK_DEBUG_LOG_TO_FILE)
if(!debug_logfile) { // Try to get logfile from env
debug_logfile = getenv("ZT_SDK_LOGFILE");
}
if(debug_logfile) {
FILE *file = fopen(debug_logfile,"a");
fprintf(file, "%s [tid=%7d] ", timestring, tid);
vfprintf(file, fmt, ap);
fclose(file);
va_end(ap);
}
#endif
va_start(ap, fmt);
fprintf(stderr, "%s [tid=%7d] ", timestring, tid);
vfprintf(stderr, fmt, ap);
// Outputs to Android debug console
#if defined(__ANDROID__)
__android_log_vprint(ANDROID_LOG_VERBOSE, "ZT-JNI", fmt, ap);
#endif
fflush(stderr);
errno = saveerr;
va_end(ap);
#endif // _SDK_DEBUG
}
//#endif
#endif //
#endif //

View File

@@ -26,33 +26,129 @@
* LLC. Start here: http://www.zerotier.com/ * LLC. Start here: http://www.zerotier.com/
*/ */
#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 4 // Set this to adjust what you'd like to see in the debug traces
#define MSG_ERROR 1 // Errors #define MSG_ERROR 1 // Errors
#define MSG_TRANSFER 2 // RX/TX specific statements #define MSG_TRANSFER 2 // RX/TX specific statements
#define MSG_INFO 3 // Information which is generally useful to any user #define MSG_INFO 3 // Information which is generally useful to any developer
#define MSG_DEBUG 4 // Information which is only useful to someone debugging #define MSG_EXTRA 4 // If nothing in your world makes sense
#define MSG_DEBUG_EXTRA 5 // If nothing in your world makes sense
extern char *debug_logfile; #define __SHOW_FILENAMES__ true
// filenames
#if __SHOW_FILENAMES__
#if __SHOW_FULL_FILENAME_PATH__
#define __FILENAME__ __FILE__ // show the entire mess
#else
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // shorten
#endif
#else
#define __FILENAME__ // omit filename
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if __ANDROID__
#if defined(__ANDROID__)
#include <jni.h> #include <jni.h>
#include <android/log.h> #include <android/log.h>
#define LOG_TAG "ZTSDK" #define LOG_TAG "ZTSDK"
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) #endif
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) //#if defined(SDK_DEBUG)
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) #if DEBUG_LEVEL >= MSG_ERROR
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, "\nZT_ERROR: %s:%d:%s(): " fmt "\n", __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, "\nZT_INFO : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
#else #else
#define LOGV(...) fprintf(stdout, __VA_ARGS__) #define DEBUG_INFO(fmt, args...) fprintf(stderr, "\nZT_INFO : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
#define LOGI(...) fprintf(stdout, __VA_ARGS__) #define DEBUG_BLANK(fmt, args...) fprintf(stderr, "\nZT_INFO : %s:%d:" fmt "\n", __FILENAME__, __LINE__, ##args)
#define LOGD(...) fprintf(stdout, __VA_ARGS__)
#define LOGE(...) fprintf(stdout, __VA_ARGS__)
#endif #endif
#else
#define DEBUG_INFO(fmt, args...)
#define DEBUG_BLANK(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, "\nZT_TRANS : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, "\nZT_TRANS: %s:%d:%s(): " fmt "\n", __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, "\nZT_EXTRA : %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args))
#else
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, "\nZT_EXTRA: %s:%d:%s(): " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##args)
#endif
#else
#define DEBUG_EXTRA(fmt, args...)
#endif
//#endif
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
#endif // _SDK_DEBUG_H_
/*
void dwr(int level, const char *fmt, ... )
{
#if defined(SDK_DEBUG)
if(level > DEBUG_LEVEL)
return;
int saveerr;
saveerr = errno;
va_list ap;
va_start(ap, fmt);
char timestring[20];
time_t timestamp;
timestamp = time(NULL);
strftime(timestring, sizeof(timestring), "%H:%M:%S", localtime(&timestamp));
#if defined(__ANDROID__)
pid_t tid = gettid();
#elif defined(__linux__)
pid_t tid = 5;//syscall(SYS_gettid);
#elif defined(__APPLE__)
pid_t tid = pthread_mach_thread_np(pthread_self());
#endif
#if defined(SDK_DEBUG_LOG_TO_FILE)
if(!debug_logfile) { // Try to get logfile from env
debug_logfile = getenv("ZT_SDK_LOGFILE");
}
if(debug_logfile) {
FILE *file = fopen(debug_logfile,"a");
fprintf(file, "%s [tid=%7d] ", timestring, tid);
vfprintf(file, fmt, ap);
fclose(file);
va_end(ap);
}
#endif
va_start(ap, fmt);
fprintf(stderr, "%s [tid=%7d] ", timestring, tid);
vfprintf(stderr, fmt, ap);
// Outputs to Android debug console
#if defined(__ANDROID__)
__android_log_vprint(ANDROID_LOG_VERBOSE, "ZT-JNI", fmt, ap);
#endif
fflush(stderr);
errno = saveerr;
va_end(ap);
#endif // _SDK_DEBUG
}
*/

View File

@@ -58,8 +58,8 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "SDK_Debug.c"
#include "SDK.h" #include "SDK.h"
#include "SDK_Debug.h"
#if !defined(__IOS__) && !defined(__ANDROID__) && !defined(__UNITY_3D__) && !defined(__XCODE__) #if !defined(__IOS__) && !defined(__ANDROID__) && !defined(__UNITY_3D__) && !defined(__XCODE__)
const ip_addr_t ip_addr_any = { IPADDR_ANY }; const ip_addr_t ip_addr_any = { IPADDR_ANY };
@@ -142,9 +142,9 @@ NetconEthernetTap::NetconEthernetTap(
lwipstack->__lwip_init(); lwipstack->__lwip_init();
_unixListenSocket = _phy.unixListen(sockPath,(void *)this); _unixListenSocket = _phy.unixListen(sockPath,(void *)this);
dwr(MSG_DEBUG, " NetconEthernetTap initialized on: %s\n", sockPath); DEBUG_INFO(" NetconEthernetTap initialized on: %s\n", sockPath);
if (!_unixListenSocket) if (!_unixListenSocket)
dwr(MSG_ERROR, "unable to bind to: %s\n", sockPath); DEBUG_ERROR("unable to bind to: %s\n", sockPath);
_thread = Thread::start(this); _thread = Thread::start(this);
} }
@@ -170,7 +170,7 @@ bool NetconEthernetTap::enabled() const
bool NetconEthernetTap::addIp(const InetAddress &ip) bool NetconEthernetTap::addIp(const InetAddress &ip)
{ {
dwr(MSG_DEBUG, "addIp(): ZT address = %s", ip.toString().c_str()); DEBUG_INFO("addIp(): ZT address = %s", ip.toString().c_str());
Mutex::Lock _l(_ips_m); Mutex::Lock _l(_ips_m);
if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) { if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
_ips.push_back(ip); _ips.push_back(ip);
@@ -222,7 +222,7 @@ std::vector<InetAddress> NetconEthernetTap::ips() const
void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len) void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
{ {
dwr(MSG_DEBUG_EXTRA, "RX packet: len = %d\n", len); DEBUG_EXTRA("RX packet: len = %d\n", len);
struct pbuf *p,*q; struct pbuf *p,*q;
if (!_enabled) if (!_enabled)
return; return;
@@ -240,7 +240,7 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
// First pbuf gets ethernet header at start // First pbuf gets ethernet header at start
q = p; q = p;
if (q->len < sizeof(ethhdr)) { if (q->len < sizeof(ethhdr)) {
dwr(MSG_ERROR,"_put(): Dropped packet: first pbuf smaller than ethernet header\n"); DEBUG_ERROR("_put(): Dropped packet: first pbuf smaller than ethernet header\n");
return; return;
} }
memcpy(q->payload,&ethhdr,sizeof(ethhdr)); memcpy(q->payload,&ethhdr,sizeof(ethhdr));
@@ -253,13 +253,13 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
dataptr += q->len; dataptr += q->len;
} }
} else { } else {
dwr(MSG_ERROR,"put(): Dropped packet: no pbufs available\n"); DEBUG_ERROR("put(): Dropped packet: no pbufs available\n");
return; return;
} }
{ {
if(interface.input(p, &interface) != ERR_OK) { if(interface.input(p, &interface) != ERR_OK) {
dwr(MSG_ERROR,"put(): Error while RXing packet (netif->input)\n"); DEBUG_ERROR("put(): Error while RXing packet (netif->input)\n");
} }
} }
} }
@@ -276,7 +276,6 @@ void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,s
{ {
std::vector<MulticastGroup> newGroups; std::vector<MulticastGroup> newGroups;
Mutex::Lock _l(_multicastGroups_m); Mutex::Lock _l(_multicastGroups_m);
// TODO: get multicast subscriptions from LWIP // TODO: get multicast subscriptions from LWIP
std::vector<InetAddress> allIps(ips()); std::vector<InetAddress> allIps(ips());
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip) for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
@@ -294,7 +293,6 @@ void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,s
removed.push_back(*m); removed.push_back(*m);
} }
_multicastGroups.swap(newGroups); _multicastGroups.swap(newGroups);
} }
void NetconEthernetTap::threadMain() void NetconEthernetTap::threadMain()
@@ -318,7 +316,7 @@ void NetconEthernetTap::threadMain()
if(!_Connections[i]->sock || _Connections[i]->type != SOCK_STREAM) if(!_Connections[i]->sock || _Connections[i]->type != SOCK_STREAM)
continue; continue;
int fd = _phy.getDescriptor(_Connections[i]->sock); int fd = _phy.getDescriptor(_Connections[i]->sock);
// dwr(MSG_DEBUG," tap_thread(): tcp\\jobs = {%d, %d}\n", _Connection.size(), jobmap.size()); // DEBUG_INFO(" tap_thread(): tcp\\jobs = {%d, %d}\n", _Connection.size(), jobmap.size());
// If there's anything on the RX buf, set to notify in case we stalled // If there's anything on the RX buf, set to notify in case we stalled
if(_Connections[i]->rxsz > 0) if(_Connections[i]->rxsz > 0)
_phy.setNotifyWritable(_Connections[i]->sock, true); _phy.setNotifyWritable(_Connections[i]->sock, true);
@@ -327,14 +325,14 @@ void NetconEthernetTap::threadMain()
ssize_t n = read(fd,&tmpbuf,BUF_SZ); ssize_t n = read(fd,&tmpbuf,BUF_SZ);
if(_Connections[i]->TCP_pcb->state == SYN_SENT) { if(_Connections[i]->TCP_pcb->state == SYN_SENT) {
dwr(MSG_DEBUG_EXTRA," tap_thread(): (sock=%p) state = SYN_SENT, should finish or be removed soon\n", DEBUG_EXTRA(" tap_thread(): (sock=%p) state = SYN_SENT, should finish or be removed soon\n",
(void*)&(_Connections[i]->sock)); (void*)&(_Connections[i]->sock));
} }
if((n < 0 && errno != EAGAIN) || (n == 0 && errno == EAGAIN)) { if((n < 0 && errno != EAGAIN) || (n == 0 && errno == EAGAIN)) {
dwr(MSG_DEBUG," tap_thread(): closing sock (%x)\n", _Connections[i]->sock); DEBUG_INFO(" tap_thread(): closing sock (%x)\n", (void*)_Connections[i]->sock);
closeConnection(_Connections[i]->sock); closeConnection(_Connections[i]->sock);
} else if (n > 0) { } else if (n > 0) {
dwr(MSG_DEBUG," tap_thread(): data read during connection check (%d bytes)\n", n); DEBUG_INFO(" tap_thread(): data read during connection check (%ld bytes)\n", n);
phyOnUnixData(_Connections[i]->sock,_phy.getuptr(_Connections[i]->sock),&tmpbuf,n); phyOnUnixData(_Connections[i]->sock,_phy.getuptr(_Connections[i]->sock),&tmpbuf,n);
} }
} }
@@ -376,11 +374,11 @@ Connection *NetconEthernetTap::getConnection(PhySocket *sock)
void NetconEthernetTap::closeConnection(PhySocket *sock) void NetconEthernetTap::closeConnection(PhySocket *sock)
{ {
dwr(MSG_DEBUG_EXTRA, "closeConnection(sock=%x):\n", sock); DEBUG_EXTRA("closeConnection(sock=%x):\n", sock);
Mutex::Lock _l(_close_m); Mutex::Lock _l(_close_m);
// Here we assume _tcpconns_m is already locked by caller // Here we assume _tcpconns_m is already locked by caller
if(!sock) { if(!sock) {
dwr(MSG_DEBUG_EXTRA,"closeConnection(): invalid PhySocket\n"); DEBUG_EXTRA("closeConnection(): invalid PhySocket\n");
return; return;
} }
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
@@ -390,14 +388,14 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
lwipstack->__udp_remove(conn->UDP_pcb); lwipstack->__udp_remove(conn->UDP_pcb);
} }
if(conn->TCP_pcb && conn->TCP_pcb->state != CLOSED) { if(conn->TCP_pcb && conn->TCP_pcb->state != CLOSED) {
dwr(MSG_DEBUG_EXTRA,"closeConnection(conn=%p,sock=%p): PCB->state = %d\n", DEBUG_EXTRA("closeConnection(conn=%p,sock=%p): PCB->state = %d\n",
(void*)&conn, (void*)&sock, conn->TCP_pcb->state); (void*)&conn, (void*)&sock, conn->TCP_pcb->state);
if(conn->TCP_pcb->state == SYN_SENT /*|| conn->TCP_pcb->state == CLOSE_WAIT*/) { if(conn->TCP_pcb->state == SYN_SENT /*|| conn->TCP_pcb->state == CLOSE_WAIT*/) {
dwr(MSG_DEBUG_EXTRA,"closeConnection(sock=%p): invalid PCB state for this operation. ignoring.\n", DEBUG_EXTRA("closeConnection(sock=%p): invalid PCB state for this operation. ignoring.\n",
(void*)&sock); (void*)&sock);
return; return;
} }
dwr(MSG_DEBUG_EXTRA, "__tcp_close(...)\n"); DEBUG_EXTRA("__tcp_close(...)\n");
if(lwipstack->__tcp_close(conn->TCP_pcb) == ERR_OK) { if(lwipstack->__tcp_close(conn->TCP_pcb) == ERR_OK) {
// Unregister callbacks for this PCB // Unregister callbacks for this PCB
lwipstack->__tcp_arg(conn->TCP_pcb, NULL); lwipstack->__tcp_arg(conn->TCP_pcb, NULL);
@@ -407,7 +405,7 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
lwipstack->__tcp_poll(conn->TCP_pcb, NULL, 1); lwipstack->__tcp_poll(conn->TCP_pcb, NULL, 1);
} }
else { else {
dwr(MSG_DEBUG_EXTRA,"closeConnection(sock=%p): error while calling tcp_close()\n", (void*)&sock); DEBUG_EXTRA("closeConnection(sock=%p): error while calling tcp_close()\n", (void*)&sock);
} }
} }
for(size_t i=0;i<_Connections.size();++i) { for(size_t i=0;i<_Connections.size();++i) {
@@ -424,7 +422,7 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
} }
void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) { void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) {
dwr(MSG_DEBUG_EXTRA, "phyOnUnixClose(sock=%p):\n", (void*)&sock); DEBUG_EXTRA("phyOnUnixClose(sock=%p):\n", (void*)&sock);
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
closeConnection(sock); closeConnection(sock);
} }
@@ -432,7 +430,7 @@ void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) {
void NetconEthernetTap::processReceivedData(PhySocket *sock,void **uptr,bool lwip_invoked) void NetconEthernetTap::processReceivedData(PhySocket *sock,void **uptr,bool lwip_invoked)
{ {
//dwr(MSG_DEBUG_EXTRA,"processReceivedData(sock=%p): lwip_invoked = %d\n", (void*)&sock, lwip_invoked); //DEBUG_EXTRA("processReceivedData(sock=%p): lwip_invoked = %d\n", (void*)&sock, lwip_invoked);
if(!lwip_invoked) { if(!lwip_invoked) {
_tcpconns_m.lock(); _tcpconns_m.lock();
_rx_buf_m.lock(); _rx_buf_m.lock();
@@ -464,19 +462,19 @@ void NetconEthernetTap::processReceivedData(PhySocket *sock,void **uptr,bool lwi
d[1] = (ip >> 8) & 0xFF; d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_TRANSFER,"UDP RX <--- :: {TX: %.3f%%, RX: %d, sock=%x} :: payload = %d bytes (%d.%d.%d.%d:%d)\n", DEBUG_TRANS("UDP RX <--- :: {TX: %.3f%%, RX: %d, sock=%x} :: payload = %d bytes (%d.%d.%d.%d:%d)\n",
(float)conn->txsz / max, conn->rxsz/* / max*/, conn->sock, payload_sz, d[0],d[1],d[2],d[3], port); (float)conn->txsz / max, conn->rxsz/* / max*/, conn->sock, payload_sz, d[0],d[1],d[2],d[3], port);
#endif #endif
} }
// STREAM // STREAM
//dwr(MSG_DEBUG, "phyOnUnixWritable(): tid = %d\n", pthread_mach_thread_np(pthread_self())); //DEBUG_INFO("phyOnUnixWritable(): tid = %d\n", pthread_mach_thread_np(pthread_self()));
if(conn->type==SOCK_STREAM) { // Only acknolwedge receipt of TCP packets if(conn->type==SOCK_STREAM) { // Only acknolwedge receipt of TCP packets
lwipstack->__tcp_recved(conn->TCP_pcb, n); lwipstack->__tcp_recved(conn->TCP_pcb, n);
dwr(MSG_TRANSFER,"TCP RX <--- :: {TX: %.3f%%, RX: %.3f%%, sock=%x} :: %d bytes\n", DEBUG_TRANS("TCP RX <--- :: {TX: %.3f%%, RX: %.3f%%, sock=%x} :: %ld bytes\n",
(float)conn->txsz / max, (float)conn->rxsz / max, conn->sock, n); (float)conn->txsz / max, (float)conn->rxsz / max, conn->sock, n);
} }
} else { } else {
dwr(MSG_DEBUG_EXTRA," processReceivedData(): errno = %d, rxsz = %d\n", errno, conn->rxsz); DEBUG_EXTRA(" processReceivedData(): errno = %d, rxsz = %d\n", errno, conn->rxsz);
_phy.setNotifyWritable(conn->sock, false); _phy.setNotifyWritable(conn->sock, false);
} }
} }
@@ -490,16 +488,15 @@ void NetconEthernetTap::processReceivedData(PhySocket *sock,void **uptr,bool lwi
} }
} }
void NetconEthernetTap::phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked) void NetconEthernetTap::phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked)
{ {
//dwr(MSG_DEBUG_EXTRA," phyOnUnixWritable(sock=%p): lwip_invoked = %d\n", (void*)&sock, lwip_invoked); //DEBUG_EXTRA(" phyOnUnixWritable(sock=%p): lwip_invoked = %d\n", (void*)&sock, lwip_invoked);
processReceivedData(sock,uptr,lwip_invoked); processReceivedData(sock,uptr,lwip_invoked);
} }
void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data, ssize_t len) void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data, ssize_t len)
{ {
dwr(MSG_DEBUG_EXTRA, "phyOnUnixData(%p), len = %d\n", (void*)&sock, len); DEBUG_EXTRA("phyOnUnixData(%p), len = %d\n", (void*)&sock, (int)len);
uint64_t CANARY_num; uint64_t CANARY_num;
pid_t pid, tid; pid_t pid, tid;
ssize_t wlen = len; ssize_t wlen = len;
@@ -521,11 +518,11 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data,
if(detected_rpc) { if(detected_rpc) {
unloadRPC(data, pid, tid, timestamp, CANARY, cmd, payload); unloadRPC(data, pid, tid, timestamp, CANARY, cmd, payload);
memcpy(&CANARY_num, CANARY, CANARY_SZ); memcpy(&CANARY_num, CANARY, CANARY_SZ);
dwr(MSG_DEBUG_EXTRA," <sock=%p> RPC: (pid=%d, tid=%d, timestamp=%s, cmd=%d)\n", DEBUG_EXTRA(" <sock=%p> RPC: (pid=%d, tid=%d, timestamp=%s, cmd=%d)\n",
(void*)&sock, pid, tid, timestamp, cmd); (void*)&sock, pid, tid, timestamp, cmd);
if(cmd == RPC_SOCKET) { if(cmd == RPC_SOCKET) {
dwr(MSG_DEBUG," <sock=%p> RPC_SOCKET\n", (void*)&sock); DEBUG_INFO(" <sock=%p> RPC_SOCKET\n", (void*)&sock);
// Create new lwip socket and associate it with this sock // Create new lwip socket and associate it with this sock
struct socket_st socket_rpc; struct socket_st socket_rpc;
memcpy(&socket_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct socket_st)); memcpy(&socket_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct socket_st));
@@ -553,7 +550,7 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data,
// Find job // Find job
sockdata = jobmap[CANARY_num]; sockdata = jobmap[CANARY_num];
if(!sockdata.first) { if(!sockdata.first) {
dwr(MSG_DEBUG," <sock=%p> unable to locate job entry for %llu\n", (void*)&sock, CANARY_num); DEBUG_INFO(" <sock=%p> unable to locate job entry for %llu\n", (void*)&sock, CANARY_num);
return; return;
} else } else
foundJob = true; foundJob = true;
@@ -615,36 +612,36 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data,
rpcSock = sockdata.first; rpcSock = sockdata.first;
buf = (unsigned char*)sockdata.second; buf = (unsigned char*)sockdata.second;
unloadRPC(buf, pid, tid, timestamp, CANARY, cmd, payload); unloadRPC(buf, pid, tid, timestamp, CANARY, cmd, payload);
dwr(MSG_DEBUG_EXTRA," <sock=%p> RPC: (pid=%d, tid=%d, timestamp=%s, cmd=%d)\n", DEBUG_EXTRA(" <sock=%p> RPC: (pid=%d, tid=%d, timestamp=%s, cmd=%d)\n",
(void*)&sock, pid, tid, timestamp, cmd); (void*)&sock, pid, tid, timestamp, cmd);
switch(cmd) { switch(cmd) {
case RPC_BIND: case RPC_BIND:
dwr(MSG_DEBUG," <sock=%p> RPC_BIND\n", (void*)&sock); DEBUG_INFO(" <sock=%p> RPC_BIND\n", (void*)&sock);
struct bind_st bind_rpc; struct bind_st bind_rpc;
memcpy(&bind_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct bind_st)); memcpy(&bind_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct bind_st));
handleBind(sock, rpcSock, uptr, &bind_rpc); handleBind(sock, rpcSock, uptr, &bind_rpc);
break; break;
case RPC_LISTEN: case RPC_LISTEN:
dwr(MSG_DEBUG," <sock=%p> RPC_LISTEN\n", (void*)&sock); DEBUG_INFO(" <sock=%p> RPC_LISTEN\n", (void*)&sock);
struct listen_st listen_rpc; struct listen_st listen_rpc;
memcpy(&listen_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct listen_st)); memcpy(&listen_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct listen_st));
handleListen(sock, rpcSock, uptr, &listen_rpc); handleListen(sock, rpcSock, uptr, &listen_rpc);
break; break;
case RPC_GETSOCKNAME: case RPC_GETSOCKNAME:
dwr(MSG_DEBUG," <sock=%p> RPC_GETSOCKNAME\n", (void*)&sock); DEBUG_INFO(" <sock=%p> RPC_GETSOCKNAME\n", (void*)&sock);
struct getsockname_st getsockname_rpc; struct getsockname_st getsockname_rpc;
memcpy(&getsockname_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct getsockname_st)); memcpy(&getsockname_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct getsockname_st));
handleGetsockname(sock, rpcSock, uptr, &getsockname_rpc); handleGetsockname(sock, rpcSock, uptr, &getsockname_rpc);
break; break;
case RPC_GETPEERNAME: case RPC_GETPEERNAME:
dwr(MSG_DEBUG," <sock=%p> RPC_GETPEERNAME\n", (void*)&sock); DEBUG_INFO(" <sock=%p> RPC_GETPEERNAME\n", (void*)&sock);
struct getsockname_st getpeername_rpc; struct getsockname_st getpeername_rpc;
memcpy(&getpeername_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct getsockname_st)); memcpy(&getpeername_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct getsockname_st));
handleGetpeername(sock, rpcSock, uptr, &getpeername_rpc); handleGetpeername(sock, rpcSock, uptr, &getpeername_rpc);
break; break;
case RPC_CONNECT: case RPC_CONNECT:
dwr(MSG_DEBUG," <sock=%p> RPC_CONNECT\n", (void*)&sock); DEBUG_INFO(" <sock=%p> RPC_CONNECT\n", (void*)&sock);
struct connect_st connect_rpc; struct connect_st connect_rpc;
memcpy(&connect_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct connect_st)); memcpy(&connect_rpc, &buf[IDX_PAYLOAD+STRUCT_IDX], sizeof(struct connect_st));
handleConnect(sock, rpcSock, conn, &connect_rpc); handleConnect(sock, rpcSock, conn, &connect_rpc);
@@ -661,13 +658,13 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock, void **uptr, void *data,
} }
int NetconEthernetTap::sendReturnValue(PhySocket *sock, int retval, int _errno = 0){ int NetconEthernetTap::sendReturnValue(PhySocket *sock, int retval, int _errno = 0){
dwr(MSG_DEBUG_EXTRA," sendReturnValue(sock=%p)\n", (void*)&sock); DEBUG_EXTRA(" sendReturnValue(sock=%p)\n", (void*)&sock);
return sendReturnValue(_phy.getDescriptor(sock), retval, _errno); return sendReturnValue(_phy.getDescriptor(sock), retval, _errno);
} }
int NetconEthernetTap::sendReturnValue(int fd, int retval, int _errno = 0) int NetconEthernetTap::sendReturnValue(int fd, int retval, int _errno = 0)
{ {
//#if !defined(USE_SOCKS_PROXY) //#if !defined(USE_SOCKS_PROXY)
dwr(MSG_DEBUG_EXTRA," sendReturnValue(): fd = %d, retval = %d, errno = %d\n", fd, retval, _errno); DEBUG_EXTRA(" sendReturnValue(): fd = %d, retval = %d, errno = %d\n", fd, retval, _errno);
int sz = sizeof(char) + sizeof(retval) + sizeof(errno); int sz = sizeof(char) + sizeof(retval) + sizeof(errno);
char retmsg[sz]; char retmsg[sz];
memset(&retmsg, 0, sizeof(retmsg)); memset(&retmsg, 0, sizeof(retmsg));
@@ -697,7 +694,7 @@ void NetconEthernetTap::unloadRPC(void *data, pid_t &pid, pid_t &tid,
err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err) err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
{ {
dwr(MSG_DEBUG, "nc_accept(pcb=%p)\n", (void*)&newPCB); DEBUG_INFO("nc_accept(pcb=%p)\n", (void*)&newPCB);
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
Mutex::Lock _l(l->tap->_tcpconns_m); Mutex::Lock _l(l->tap->_tcpconns_m);
Connection *conn = l->conn; Connection *conn = l->conn;
@@ -717,7 +714,7 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
if(socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0) { if(socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0) {
if(errno < 0) { if(errno < 0) {
l->tap->sendReturnValue(conn, -1, errno); l->tap->sendReturnValue(conn, -1, errno);
dwr(MSG_ERROR," nc_accept(): unable to create socketpair\n"); DEBUG_ERROR(" nc_accept(): unable to create socketpair\n");
return ERR_MEM; return ERR_MEM;
} }
} }
@@ -740,14 +737,14 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
tcp_accepted(conn->TCP_pcb); // Let lwIP know that it can queue additional incoming connections tcp_accepted(conn->TCP_pcb); // Let lwIP know that it can queue additional incoming connections
return ERR_OK; return ERR_OK;
} else } else
dwr(MSG_ERROR," nc_accept(): can't locate Connection object for PCB.\n"); DEBUG_ERROR(" nc_accept(): can't locate Connection object for PCB.\n");
return -1; return -1;
} }
void NetconEthernetTap::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, struct ip_addr * addr, u16_t port) void NetconEthernetTap::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, struct ip_addr * addr, u16_t port)
{ {
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
//dwr(MSG_DEBUG_EXTRA, "nc_udp_recved(conn=%p,pcb=%p,port=%d)\n", (void*)&(l->conn), (void*)&upcb, port); //DEBUG_EXTRA("nc_udp_recved(conn=%p,pcb=%p,port=%d)\n", (void*)&(l->conn), (void*)&upcb, port);
int tot = 0; int tot = 0;
unsigned char *addr_pos, *sz_pos, *payload_pos; unsigned char *addr_pos, *sz_pos, *payload_pos;
struct pbuf* q = p; struct pbuf* q = p;
@@ -762,7 +759,7 @@ void NetconEthernetTap::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct
if(p) { if(p) {
// Intra-API "packetization" scheme: [addr_len|addr|payload_len|payload] // Intra-API "packetization" scheme: [addr_len|addr|payload_len|payload]
if(l->conn->rxsz == DEFAULT_UDP_RX_BUF_SZ) { // if UDP buffer full if(l->conn->rxsz == DEFAULT_UDP_RX_BUF_SZ) { // if UDP buffer full
dwr(MSG_DEBUG, "nc_udp_recved(): UDP RX buffer full. Discarding oldest payload segment\n"); DEBUG_INFO("nc_udp_recved(): UDP RX buffer full. Discarding oldest payload segment\n");
memmove(l->conn->rxbuf, l->conn->rxbuf + ZT_MAX_MTU, DEFAULT_UDP_RX_BUF_SZ - ZT_MAX_MTU); memmove(l->conn->rxbuf, l->conn->rxbuf + ZT_MAX_MTU, DEFAULT_UDP_RX_BUF_SZ - ZT_MAX_MTU);
addr_pos = l->conn->rxbuf + (DEFAULT_UDP_RX_BUF_SZ - ZT_MAX_MTU); // TODO: addr_pos = l->conn->rxbuf + (DEFAULT_UDP_RX_BUF_SZ - ZT_MAX_MTU); // TODO:
sz_pos = addr_pos + sizeof(struct sockaddr_storage); sz_pos = addr_pos + sizeof(struct sockaddr_storage);
@@ -788,7 +785,7 @@ void NetconEthernetTap::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct
if(tot) { if(tot) {
l->conn->rxsz += ZT_MAX_MTU; l->conn->rxsz += ZT_MAX_MTU;
memcpy(sz_pos, &tot, sizeof(tot)); memcpy(sz_pos, &tot, sizeof(tot));
//dwr(MSG_DEBUG_EXTRA, " nc_udp_recved(): data_len = %d, rxsz = %d, addr_info_len = %d\n", //DEBUG_EXTRA(" nc_udp_recved(): data_len = %d, rxsz = %d, addr_info_len = %d\n",
// tot, l->conn->rxsz, sizeof(u32_t) + sizeof(u16_t)); // tot, l->conn->rxsz, sizeof(u32_t) + sizeof(u16_t));
l->tap->phyOnUnixWritable(l->conn->sock, NULL, true); l->tap->phyOnUnixWritable(l->conn->sock, NULL, true);
l->tap->_phy.setNotifyWritable(l->conn->sock, true); l->tap->_phy.setNotifyWritable(l->conn->sock, true);
@@ -800,13 +797,13 @@ void NetconEthernetTap::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct
err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err) err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err)
{ {
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
dwr(MSG_DEBUG_EXTRA, "nc_recved(conn=%p,pcb=%p)\n", (void*)&(l->conn), (void*)&PCB); DEBUG_EXTRA("nc_recved(conn=%p,pcb=%p)\n", (void*)&(l->conn), (void*)&PCB);
int tot = 0; int tot = 0;
struct pbuf* q = p; struct pbuf* q = p;
Mutex::Lock _l(l->tap->_tcpconns_m); Mutex::Lock _l(l->tap->_tcpconns_m);
if(!l->conn) { if(!l->conn) {
dwr(MSG_ERROR," nc_recved(): no connection\n"); DEBUG_ERROR(" nc_recved(): no connection\n");
return ERR_OK; return ERR_OK;
} }
if(p == NULL) { if(p == NULL) {
@@ -825,7 +822,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *
int avail = DEFAULT_TCP_RX_BUF_SZ - l->conn->rxsz; int avail = DEFAULT_TCP_RX_BUF_SZ - l->conn->rxsz;
int len = p->len; int len = p->len;
if(avail < len) if(avail < len)
dwr(MSG_ERROR," nc_recved(): not enough room (%d bytes) on RX buffer\n", avail); DEBUG_ERROR(" nc_recved(): not enough room (%d bytes) on RX buffer\n", avail);
memcpy(l->conn->rxbuf + (l->conn->rxsz), p->payload, len); memcpy(l->conn->rxbuf + (l->conn->rxsz), p->payload, len);
l->conn->rxsz += len; l->conn->rxsz += len;
p = p->next; p = p->next;
@@ -844,7 +841,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *
err_t NetconEthernetTap::nc_sent(void* arg, struct tcp_pcb *PCB, u16_t len) err_t NetconEthernetTap::nc_sent(void* arg, struct tcp_pcb *PCB, u16_t len)
{ {
dwr(MSG_DEBUG_EXTRA, "nc_sent(pcb=%p)\n", (void*)&PCB); DEBUG_EXTRA("nc_sent(pcb=%p)\n", (void*)&PCB);
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
Mutex::Lock _l(l->tap->_tcpconns_m); Mutex::Lock _l(l->tap->_tcpconns_m);
if(l->conn->probation && l->conn->txsz == 0){ if(l->conn->probation && l->conn->txsz == 0){
@@ -862,13 +859,13 @@ err_t NetconEthernetTap::nc_sent(void* arg, struct tcp_pcb *PCB, u16_t len)
err_t NetconEthernetTap::nc_connected_proxy(void *arg, struct tcp_pcb *PCB, err_t err) err_t NetconEthernetTap::nc_connected_proxy(void *arg, struct tcp_pcb *PCB, err_t err)
{ {
dwr(MSG_DEBUG, "nc_connected_proxy(pcb=%p)\n", (void*)&PCB); DEBUG_INFO("nc_connected_proxy(pcb=%p)\n", (void*)&PCB);
return ERR_OK; return ERR_OK;
} }
err_t NetconEthernetTap::nc_connected(void *arg, struct tcp_pcb *PCB, err_t err) err_t NetconEthernetTap::nc_connected(void *arg, struct tcp_pcb *PCB, err_t err)
{ {
dwr(MSG_DEBUG, "nc_connected(pcb=%p)\n", (void*)&PCB); DEBUG_INFO("nc_connected(pcb=%p)\n", (void*)&PCB);
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
if(l && l->conn) if(l && l->conn)
l->tap->sendReturnValue(l->tap->_phy.getDescriptor(l->conn->rpcSock), ERR_OK); l->tap->sendReturnValue(l->tap->_phy.getDescriptor(l->conn->rpcSock), ERR_OK);
@@ -882,54 +879,54 @@ err_t NetconEthernetTap::nc_poll(void* arg, struct tcp_pcb *PCB)
void NetconEthernetTap::nc_err(void *arg, err_t err) void NetconEthernetTap::nc_err(void *arg, err_t err)
{ {
dwr(MSG_DEBUG,"nc_err() = %d\n", err); DEBUG_INFO("nc_err() = %d\n", err);
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
Mutex::Lock _l(l->tap->_tcpconns_m); Mutex::Lock _l(l->tap->_tcpconns_m);
if(!l->conn) if(!l->conn)
dwr(MSG_ERROR," nc_err(): connection is NULL!\n"); DEBUG_ERROR(" nc_err(): connection is NULL!\n");
int fd = l->tap->_phy.getDescriptor(l->conn->sock); int fd = l->tap->_phy.getDescriptor(l->conn->sock);
switch(err) switch(err)
{ {
case ERR_MEM: case ERR_MEM:
dwr(MSG_ERROR," nc_err(): ERR_MEM->ENOMEM\n"); DEBUG_ERROR(" nc_err(): ERR_MEM->ENOMEM\n");
l->tap->sendReturnValue(fd, -1, ENOMEM); l->tap->sendReturnValue(fd, -1, ENOMEM);
break; break;
case ERR_BUF: case ERR_BUF:
dwr(MSG_ERROR," nc_err(): ERR_BUF->ENOBUFS\n"); DEBUG_ERROR(" nc_err(): ERR_BUF->ENOBUFS\n");
l->tap->sendReturnValue(fd, -1, ENOBUFS); l->tap->sendReturnValue(fd, -1, ENOBUFS);
break; break;
case ERR_TIMEOUT: case ERR_TIMEOUT:
dwr(MSG_ERROR," nc_err(): ERR_TIMEOUT->ETIMEDOUT\n"); DEBUG_ERROR(" nc_err(): ERR_TIMEOUT->ETIMEDOUT\n");
l->tap->sendReturnValue(fd, -1, ETIMEDOUT); l->tap->sendReturnValue(fd, -1, ETIMEDOUT);
break; break;
case ERR_RTE: case ERR_RTE:
dwr(MSG_ERROR," nc_err(): ERR_RTE->ENETUNREACH\n"); DEBUG_ERROR(" nc_err(): ERR_RTE->ENETUNREACH\n");
l->tap->sendReturnValue(fd, -1, ENETUNREACH); l->tap->sendReturnValue(fd, -1, ENETUNREACH);
break; break;
case ERR_INPROGRESS: case ERR_INPROGRESS:
dwr(MSG_ERROR," nc_err(): ERR_INPROGRESS->EINPROGRESS\n"); DEBUG_ERROR(" nc_err(): ERR_INPROGRESS->EINPROGRESS\n");
l->tap->sendReturnValue(fd, -1, EINPROGRESS); l->tap->sendReturnValue(fd, -1, EINPROGRESS);
break; break;
case ERR_VAL: case ERR_VAL:
dwr(MSG_ERROR," nc_err(): ERR_VAL->EINVAL\n"); DEBUG_ERROR(" nc_err(): ERR_VAL->EINVAL\n");
l->tap->sendReturnValue(fd, -1, EINVAL); l->tap->sendReturnValue(fd, -1, EINVAL);
break; break;
case ERR_WOULDBLOCK: case ERR_WOULDBLOCK:
dwr(MSG_ERROR," nc_err(): ERR_WOULDBLOCK->EWOULDBLOCK\n"); DEBUG_ERROR(" nc_err(): ERR_WOULDBLOCK->EWOULDBLOCK\n");
l->tap->sendReturnValue(fd, -1, EWOULDBLOCK); l->tap->sendReturnValue(fd, -1, EWOULDBLOCK);
break; break;
case ERR_USE: case ERR_USE:
dwr(MSG_ERROR," nc_err(): ERR_USE->EADDRINUSE\n"); DEBUG_ERROR(" nc_err(): ERR_USE->EADDRINUSE\n");
l->tap->sendReturnValue(fd, -1, EADDRINUSE); l->tap->sendReturnValue(fd, -1, EADDRINUSE);
break; break;
case ERR_ISCONN: case ERR_ISCONN:
dwr(MSG_ERROR," nc_err(): ERR_ISCONN->EISCONN\n"); DEBUG_ERROR(" nc_err(): ERR_ISCONN->EISCONN\n");
l->tap->sendReturnValue(fd, -1, EISCONN); l->tap->sendReturnValue(fd, -1, EISCONN);
break; break;
case ERR_ABRT: case ERR_ABRT:
dwr(MSG_ERROR," nc_err(): ERR_ABRT->ECONNREFUSED\n"); DEBUG_ERROR(" nc_err(): ERR_ABRT->ECONNREFUSED\n");
l->tap->sendReturnValue(fd, -1, ECONNREFUSED); l->tap->sendReturnValue(fd, -1, ECONNREFUSED);
break; break;
@@ -953,7 +950,7 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
default: default:
break; break;
} }
dwr(MSG_ERROR," nc_err(): closing connection\n"); DEBUG_ERROR(" nc_err(): closing connection\n");
l->tap->closeConnection(l->conn); l->tap->closeConnection(l->conn);
} }
@@ -966,7 +963,7 @@ void NetconEthernetTap::handleGetsockname(PhySocket *sock, PhySocket *rpcSock, v
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
if(conn->local_addr == NULL){ if(conn->local_addr == NULL){
dwr(MSG_DEBUG_EXTRA," handleGetsockname(): No address info available. Is it bound?"); DEBUG_EXTRA(" handleGetsockname(): No address info available. Is it bound?");
struct sockaddr_storage storage; struct sockaddr_storage storage;
memset(&storage, 0, sizeof(struct sockaddr_storage)); memset(&storage, 0, sizeof(struct sockaddr_storage));
write(_phy.getDescriptor(rpcSock), NULL, sizeof(struct sockaddr_storage)); write(_phy.getDescriptor(rpcSock), NULL, sizeof(struct sockaddr_storage));
@@ -980,7 +977,7 @@ void NetconEthernetTap::handleGetpeername(PhySocket *sock, PhySocket *rpcSock, v
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
if(conn->peer_addr == NULL){ if(conn->peer_addr == NULL){
dwr(MSG_DEBUG_EXTRA," handleGetpeername(): No peer address info available. Is it connected?"); DEBUG_EXTRA(" handleGetpeername(): No peer address info available. Is it connected?");
struct sockaddr_storage storage; struct sockaddr_storage storage;
memset(&storage, 0, sizeof(struct sockaddr_storage)); memset(&storage, 0, sizeof(struct sockaddr_storage));
write(_phy.getDescriptor(rpcSock), NULL, sizeof(struct sockaddr_storage)); write(_phy.getDescriptor(rpcSock), NULL, sizeof(struct sockaddr_storage));
@@ -997,7 +994,7 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
ip_addr_t connAddr; ip_addr_t connAddr;
if(!_ips.size()) { if(!_ips.size()) {
// We haven't been given an address yet. Binding at this stage is premature // We haven't been given an address yet. Binding at this stage is premature
dwr(MSG_ERROR, " handleBind(): ZT address hasn't been provided. Cannot bind yet."); DEBUG_ERROR(" handleBind(): ZT address hasn't been provided. Cannot bind yet.");
sendReturnValue(rpcSock, -1, ENOMEM); sendReturnValue(rpcSock, -1, ENOMEM);
return; return;
} }
@@ -1008,11 +1005,11 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
d[1] = (ip >> 8) & 0xFF; d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_DEBUG," handleBind(): %d.%d.%d.%d : %d\n", d[0],d[1],d[2],d[3], port); DEBUG_INFO(" handleBind(): %d.%d.%d.%d : %d\n", d[0],d[1],d[2],d[3], port);
connAddr.addr = *((u32_t *)_ips[0].rawIpData()); connAddr.addr = *((u32_t *)_ips[0].rawIpData());
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
dwr(MSG_DEBUG," handleBind(sock=%p,fd=%d,port=%d)\n", (void*)&sock, bind_rpc->fd, port); DEBUG_INFO(" handleBind(sock=%p,fd=%d,port=%d)\n", (void*)&sock, bind_rpc->fd, port);
if(conn) { if(conn) {
if(conn->type == SOCK_DGRAM) { if(conn->type == SOCK_DGRAM) {
#if defined(__ANDROID__) #if defined(__ANDROID__)
@@ -1036,7 +1033,7 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
if(conn->TCP_pcb->state == CLOSED){ if(conn->TCP_pcb->state == CLOSED){
err = lwipstack->__tcp_bind(conn->TCP_pcb, &connAddr, port); err = lwipstack->__tcp_bind(conn->TCP_pcb, &connAddr, port);
if(err != ERR_OK) { if(err != ERR_OK) {
dwr(MSG_ERROR," handleBind(): err = %d\n", err); DEBUG_ERROR(" handleBind(): err = %d\n", err);
if(err == ERR_USE) if(err == ERR_USE)
sendReturnValue(rpcSock, -1, EADDRINUSE); sendReturnValue(rpcSock, -1, EADDRINUSE);
if(err == ERR_MEM) if(err == ERR_MEM)
@@ -1048,20 +1045,20 @@ void NetconEthernetTap::handleBind(PhySocket *sock, PhySocket *rpcSock, void **u
sendReturnValue(rpcSock, ERR_OK, ERR_OK); // Success sendReturnValue(rpcSock, ERR_OK, ERR_OK); // Success
} }
} else { } else {
dwr(MSG_ERROR," handleBind(): PCB (conn=%p,pcb=%p) not in CLOSED state. Ignoring BIND request.\n", DEBUG_ERROR(" handleBind(): PCB (conn=%p,pcb=%p) not in CLOSED state. Ignoring BIND request.\n",
(void*)&conn, (void*)&conn->TCP_pcb); (void*)&conn, (void*)&conn->TCP_pcb);
sendReturnValue(rpcSock, -1, EINVAL); sendReturnValue(rpcSock, -1, EINVAL);
} }
} }
} else { } else {
dwr(MSG_ERROR," handleBind(): unable to locate Connection.\n"); DEBUG_ERROR(" handleBind(): unable to locate Connection.\n");
sendReturnValue(rpcSock, -1, EBADF); sendReturnValue(rpcSock, -1, EBADF);
} }
} }
void NetconEthernetTap::handleListen(PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc) void NetconEthernetTap::handleListen(PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc)
{ {
dwr(MSG_DEBUG, "handleListen(sock=%p)\n", (void*)&sock); DEBUG_INFO("handleListen(sock=%p)\n", (void*)&sock);
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
@@ -1071,12 +1068,12 @@ void NetconEthernetTap::handleListen(PhySocket *sock, PhySocket *rpcSock, void *
return; return;
} }
if(!conn) { if(!conn) {
dwr(MSG_ERROR," handleListen(): unable to locate Connection.\n"); DEBUG_ERROR(" handleListen(): unable to locate Connection.\n");
sendReturnValue(rpcSock, -1, EBADF); sendReturnValue(rpcSock, -1, EBADF);
return; return;
} }
if(conn->TCP_pcb->state == LISTEN) { if(conn->TCP_pcb->state == LISTEN) {
dwr(MSG_ERROR," handleListen(): PCB is already in listening state.\n"); DEBUG_ERROR(" handleListen(): PCB is already in listening state.\n");
sendReturnValue(rpcSock, ERR_OK, ERR_OK); sendReturnValue(rpcSock, ERR_OK, ERR_OK);
return; return;
} }
@@ -1103,19 +1100,19 @@ Connection * NetconEthernetTap::handleSocketProxy(PhySocket *sock, int socket_ty
{ {
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
if(!conn){ if(!conn){
dwr(MSG_DEBUG, "handleSocketProxy(sock=%p): Unable to locate Connection object for this PhySocket\n", (void*)&sock); DEBUG_INFO("handleSocketProxy(sock=%p): Unable to locate Connection object for this PhySocket\n", (void*)&sock);
return NULL; return NULL;
} }
dwr(MSG_DEBUG, "handleSocketProxy(sock=%p)\n", (void*)&sock); DEBUG_INFO("handleSocketProxy(sock=%p)\n", (void*)&sock);
struct udp_pcb *new_udp_PCB = NULL; struct udp_pcb *new_udp_PCB = NULL;
struct tcp_pcb *new_tcp_PCB = NULL; struct tcp_pcb *new_tcp_PCB = NULL;
if(socket_type == SOCK_DGRAM) { if(socket_type == SOCK_DGRAM) {
dwr(MSG_DEBUG, " handleSocketProxy(): SOCK_DGRAM\n"); DEBUG_INFO(" handleSocketProxy(): SOCK_DGRAM\n");
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
new_udp_PCB = lwipstack->__udp_new(); new_udp_PCB = lwipstack->__udp_new();
} }
else if(socket_type == SOCK_STREAM) { else if(socket_type == SOCK_STREAM) {
dwr(MSG_DEBUG, " handleSocketProxy(): SOCK_STREAM\n"); DEBUG_INFO(" handleSocketProxy(): SOCK_STREAM\n");
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
new_tcp_PCB = lwipstack->__tcp_new(); new_tcp_PCB = lwipstack->__tcp_new();
} }
@@ -1126,25 +1123,25 @@ Connection * NetconEthernetTap::handleSocketProxy(PhySocket *sock, int socket_ty
conn->peer_addr = NULL; conn->peer_addr = NULL;
if(conn->type == SOCK_DGRAM) conn->UDP_pcb = new_udp_PCB; if(conn->type == SOCK_DGRAM) conn->UDP_pcb = new_udp_PCB;
if(conn->type == SOCK_STREAM) conn->TCP_pcb = new_tcp_PCB; if(conn->type == SOCK_STREAM) conn->TCP_pcb = new_tcp_PCB;
dwr(MSG_DEBUG, " handleSocketProxy(): Updated sock=%p\n", (void*)&sock); DEBUG_INFO(" handleSocketProxy(): Updated sock=%p\n", (void*)&sock);
return conn; return conn;
} }
dwr(MSG_ERROR," handleSocketProxy(): Memory not available for new PCB\n"); DEBUG_ERROR(" handleSocketProxy(): Memory not available for new PCB\n");
return NULL; return NULL;
} }
Connection * NetconEthernetTap::handleSocket(PhySocket *sock, void **uptr, struct socket_st* socket_rpc) Connection * NetconEthernetTap::handleSocket(PhySocket *sock, void **uptr, struct socket_st* socket_rpc)
{ {
dwr(MSG_DEBUG, "handleSocket(sock=%p)\n", (void*)&sock); DEBUG_INFO("handleSocket(sock=%p)\n", (void*)&sock);
struct udp_pcb *new_udp_PCB = NULL; struct udp_pcb *new_udp_PCB = NULL;
struct tcp_pcb *new_tcp_PCB = NULL; struct tcp_pcb *new_tcp_PCB = NULL;
if(socket_rpc->socket_type == SOCK_DGRAM) { if(socket_rpc->socket_type == SOCK_DGRAM) {
dwr(MSG_DEBUG, "handleSocket(): SOCK_DGRAM\n"); DEBUG_INFO("handleSocket(): SOCK_DGRAM\n");
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
new_udp_PCB = lwipstack->__udp_new(); new_udp_PCB = lwipstack->__udp_new();
} }
else if(socket_rpc->socket_type == SOCK_STREAM) { else if(socket_rpc->socket_type == SOCK_STREAM) {
dwr(MSG_DEBUG, "handleSocket(): SOCK_STREAM\n"); DEBUG_INFO("handleSocket(): SOCK_STREAM\n");
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
new_tcp_PCB = lwipstack->__tcp_new(); new_tcp_PCB = lwipstack->__tcp_new();
} }
@@ -1160,14 +1157,14 @@ Connection * NetconEthernetTap::handleSocket(PhySocket *sock, void **uptr, struc
_Connections.push_back(newConn); _Connections.push_back(newConn);
return newConn; return newConn;
} }
dwr(MSG_ERROR," handleSocket(): Memory not available for new PCB\n"); DEBUG_ERROR(" handleSocket(): Memory not available for new PCB\n");
sendReturnValue(_phy.getDescriptor(sock), -1, ENOMEM); sendReturnValue(_phy.getDescriptor(sock), -1, ENOMEM);
return NULL; return NULL;
} }
int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *rawAddr) int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *rawAddr)
{ {
dwr(MSG_DEBUG, "handleConnectProxy(%p)\n", (void*)&sock); DEBUG_INFO("handleConnectProxy(%p)\n", (void*)&sock);
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
int port = rawAddr->sin_port; int port = rawAddr->sin_port;
ip_addr_t connAddr = convert_ip(rawAddr); ip_addr_t connAddr = convert_ip(rawAddr);
@@ -1175,13 +1172,13 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
if(!conn) { if(!conn) {
dwr(MSG_DEBUG, " handleConnectProxy(): Unable to locate Connection object for (sock=%p)\n", (void*)&sock); DEBUG_INFO(" handleConnectProxy(): Unable to locate Connection object for (sock=%p)\n", (void*)&sock);
return -1; return -1;
} }
if(conn->type == SOCK_DGRAM) { if(conn->type == SOCK_DGRAM) {
// Generates no network traffic // Generates no network traffic
if((err = lwipstack->__udp_connect(conn->UDP_pcb,&connAddr,port)) < 0) if((err = lwipstack->__udp_connect(conn->UDP_pcb,&connAddr,port)) < 0)
dwr(MSG_DEBUG, "handleConnectProxy(): Error while connecting to with UDP\n"); DEBUG_INFO("handleConnectProxy(): Error while connecting to with UDP\n");
lwipstack->__udp_recv(conn->UDP_pcb, nc_udp_recved, new Larg(this, conn)); lwipstack->__udp_recv(conn->UDP_pcb, nc_udp_recved, new Larg(this, conn));
errno = ERR_OK; errno = ERR_OK;
return 0; return 0;
@@ -1199,10 +1196,10 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
d[1] = (ip >> 8) & 0xFF; d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_DEBUG," handleConnectProxy(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], port); DEBUG_INFO(" handleConnectProxy(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], port);
dwr(MSG_DEBUG," handleConnectProxy(): pcb->state = %x\n", conn->TCP_pcb->state); DEBUG_INFO(" handleConnectProxy(): pcb->state = %x\n", conn->TCP_pcb->state);
if(conn->TCP_pcb->state != CLOSED) { if(conn->TCP_pcb->state != CLOSED) {
dwr(MSG_DEBUG," handleConnectProxy(): PCB != CLOSED, cannot connect using this PCB\n"); DEBUG_INFO(" handleConnectProxy(): PCB != CLOSED, cannot connect using this PCB\n");
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
@@ -1246,7 +1243,7 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
// that's it! // that's it!
// - Most instances of a retval for a connect() should happen // - Most instances of a retval for a connect() should happen
// in the nc_connect() and nc_err() callbacks! // in the nc_connect() and nc_err() callbacks!
dwr(MSG_ERROR," handleConnectProxy(): unable to connect\n"); DEBUG_ERROR(" handleConnectProxy(): unable to connect\n");
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
@@ -1254,7 +1251,7 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
conn->listening=true; conn->listening=true;
return 0; return 0;
} else { } else {
dwr(MSG_ERROR," handleConnectProxy(): could not locate PCB based on their fd\n"); DEBUG_ERROR(" handleConnectProxy(): could not locate PCB based on their fd\n");
errno = EBADF; errno = EBADF;
return -1; return -1;
} }
@@ -1263,7 +1260,7 @@ int NetconEthernetTap::handleConnectProxy(PhySocket *sock, struct sockaddr_in *r
void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Connection *conn, struct connect_st* connect_rpc) void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Connection *conn, struct connect_st* connect_rpc)
{ {
dwr(MSG_DEBUG_EXTRA, "handleConnect(%p)\n", (void*)&sock); DEBUG_EXTRA("handleConnect(%p)\n", (void*)&sock);
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
struct sockaddr_in *rawAddr = (struct sockaddr_in *) &connect_rpc->addr; struct sockaddr_in *rawAddr = (struct sockaddr_in *) &connect_rpc->addr;
int port = lwipstack->__lwip_ntohs(rawAddr->sin_port); int port = lwipstack->__lwip_ntohs(rawAddr->sin_port);
@@ -1275,12 +1272,12 @@ void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Conne
d[1] = (ip >> 8) & 0xFF; d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_DEBUG," handleConnect(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], port); DEBUG_INFO(" handleConnect(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], port);
if(conn->type == SOCK_DGRAM) { if(conn->type == SOCK_DGRAM) {
// Generates no network traffic // Generates no network traffic
if((err = lwipstack->__udp_connect(conn->UDP_pcb,&connAddr,port)) < 0) if((err = lwipstack->__udp_connect(conn->UDP_pcb,&connAddr,port)) < 0)
dwr(MSG_ERROR, "handleConnect(): Error while connecting to with UDP\n"); DEBUG_ERROR("handleConnect(): Error while connecting to with UDP\n");
lwipstack->__udp_recv(conn->UDP_pcb, nc_udp_recved, new Larg(this, conn)); lwipstack->__udp_recv(conn->UDP_pcb, nc_udp_recved, new Larg(this, conn));
sendReturnValue(rpcSock, 0, ERR_OK); sendReturnValue(rpcSock, 0, ERR_OK);
return; return;
@@ -1292,9 +1289,9 @@ void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Conne
lwipstack->__tcp_poll(conn->TCP_pcb, nc_poll, APPLICATION_POLL_FREQ); lwipstack->__tcp_poll(conn->TCP_pcb, nc_poll, APPLICATION_POLL_FREQ);
lwipstack->__tcp_arg(conn->TCP_pcb, new Larg(this, conn)); lwipstack->__tcp_arg(conn->TCP_pcb, new Larg(this, conn));
dwr(MSG_DEBUG_EXTRA," handleConnect(): pcb->state = %x\n", conn->TCP_pcb->state); DEBUG_EXTRA(" handleConnect(): pcb->state = %x\n", conn->TCP_pcb->state);
if(conn->TCP_pcb->state != CLOSED) { if(conn->TCP_pcb->state != CLOSED) {
dwr(MSG_DEBUG," handleConnect(): PCB != CLOSED, cannot connect using this PCB\n"); DEBUG_INFO(" handleConnect(): PCB != CLOSED, cannot connect using this PCB\n");
sendReturnValue(rpcSock, -1, EAGAIN); sendReturnValue(rpcSock, -1, EAGAIN);
return; return;
} }
@@ -1339,48 +1336,48 @@ void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Conne
// that's it! // that's it!
// - Most instances of a retval for a connect() should happen // - Most instances of a retval for a connect() should happen
// in the nc_connect() and nc_err() callbacks! // in the nc_connect() and nc_err() callbacks!
dwr(MSG_ERROR," handleConnect(): unable to connect\n"); DEBUG_ERROR(" handleConnect(): unable to connect\n");
sendReturnValue(rpcSock, -1, EAGAIN); sendReturnValue(rpcSock, -1, EAGAIN);
} }
// Everything seems to be ok, but we don't have enough info to retval // Everything seems to be ok, but we don't have enough info to retval
conn->listening=true; conn->listening=true;
conn->rpcSock=rpcSock; // used for return value from lwip CB conn->rpcSock=rpcSock; // used for return value from lwip CB
} else { } else {
dwr(MSG_ERROR," handleConnect(): could not locate PCB based on their fd\n"); DEBUG_ERROR(" handleConnect(): could not locate PCB based on their fd\n");
sendReturnValue(rpcSock, -1, EBADF); sendReturnValue(rpcSock, -1, EBADF);
} }
} }
void NetconEthernetTap::handleWrite(Connection *conn) void NetconEthernetTap::handleWrite(Connection *conn)
{ {
dwr(MSG_DEBUG_EXTRA, "handleWrite(conn=%p)\n", (void*)&conn); DEBUG_EXTRA("handleWrite(conn=%p)\n", (void*)&conn);
if(!conn || (!conn->TCP_pcb && !conn->UDP_pcb)) { if(!conn || (!conn->TCP_pcb && !conn->UDP_pcb)) {
dwr(MSG_ERROR," handleWrite(): invalid connection\n"); DEBUG_ERROR(" handleWrite(): invalid connection\n");
return; return;
} }
if(conn->type == SOCK_DGRAM) { if(conn->type == SOCK_DGRAM) {
if(!conn->UDP_pcb) { if(!conn->UDP_pcb) {
dwr(MSG_ERROR, " handleWrite(): type = SOCK_DGRAM, invalid UDP_pcb\n"); DEBUG_ERROR(" handleWrite(): type = SOCK_DGRAM, invalid UDP_pcb\n");
return; return;
} }
// TODO: Packet re-assembly hasn't yet been tested with lwIP so UDP packets are limited to MTU-sized chunks // TODO: Packet re-assembly hasn't yet been tested with lwIP so UDP packets are limited to MTU-sized chunks
int udp_trans_len = conn->txsz < ZT_UDP_DEFAULT_PAYLOAD_MTU ? conn->txsz : ZT_UDP_DEFAULT_PAYLOAD_MTU; int udp_trans_len = conn->txsz < ZT_UDP_DEFAULT_PAYLOAD_MTU ? conn->txsz : ZT_UDP_DEFAULT_PAYLOAD_MTU;
dwr(MSG_DEBUG_EXTRA, " handleWrite(): Allocating pbuf chain of size (%d) for UDP packet, TXSZ = %d\n", udp_trans_len, conn->txsz); DEBUG_EXTRA(" handleWrite(): Allocating pbuf chain of size (%d) for UDP packet, TXSZ = %d\n", udp_trans_len, conn->txsz);
struct pbuf * pb = lwipstack->__pbuf_alloc(PBUF_TRANSPORT, udp_trans_len, PBUF_POOL); struct pbuf * pb = lwipstack->__pbuf_alloc(PBUF_TRANSPORT, udp_trans_len, PBUF_POOL);
if(!pb){ if(!pb){
dwr(MSG_ERROR, " handleWrite(): unable to allocate new pbuf of size (%d)\n", conn->txsz); DEBUG_ERROR(" handleWrite(): unable to allocate new pbuf of size (%d)\n", conn->txsz);
return; return;
} }
memcpy(pb->payload, conn->txbuf, udp_trans_len); memcpy(pb->payload, conn->txbuf, udp_trans_len);
int err = lwipstack->__udp_send(conn->UDP_pcb, pb); int err = lwipstack->__udp_send(conn->UDP_pcb, pb);
if(err == ERR_MEM) { if(err == ERR_MEM) {
dwr(MSG_ERROR, " handleWrite(): Error sending packet. Out of memory\n"); DEBUG_ERROR(" handleWrite(): Error sending packet. Out of memory\n");
} else if(err == ERR_RTE) { } else if(err == ERR_RTE) {
dwr(MSG_ERROR, " handleWrite(): Could not find route to destinations address\n"); DEBUG_ERROR(" handleWrite(): Could not find route to destinations address\n");
} else if(err != ERR_OK) { } else if(err != ERR_OK) {
dwr(MSG_ERROR, " handleWrite(): Error sending packet - %d\n", err); DEBUG_ERROR(" handleWrite(): Error sending packet - %d\n", err);
} else { } else {
// Success // Success
int buf_remaining = (conn->txsz)-udp_trans_len; int buf_remaining = (conn->txsz)-udp_trans_len;
@@ -1398,7 +1395,7 @@ void NetconEthernetTap::handleWrite(Connection *conn)
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_TRANSFER,"UDP TX ---> :: {TX: ------, RX: ------, sock=%x} :: %d bytes (%d.%d.%d.%d:%d)\n", DEBUG_TRANS("UDP TX ---> :: {TX: ------, RX: ------, sock=%x} :: %d bytes (%d.%d.%d.%d:%d)\n",
conn->sock, udp_trans_len, d[0], d[1], d[2], d[3], port); conn->sock, udp_trans_len, d[0], d[1], d[2], d[3], port);
#endif #endif
} }
@@ -1407,7 +1404,7 @@ void NetconEthernetTap::handleWrite(Connection *conn)
} }
else if(conn->type == SOCK_STREAM) { else if(conn->type == SOCK_STREAM) {
if(!conn->TCP_pcb) { if(!conn->TCP_pcb) {
dwr(MSG_ERROR, " handleWrite(): type = SOCK_STREAM, invalid TCP_pcb\n"); DEBUG_ERROR(" handleWrite(): type = SOCK_STREAM, invalid TCP_pcb\n");
return; return;
} }
// How much we are currently allowed to write to the connection // How much we are currently allowed to write to the connection
@@ -1419,7 +1416,7 @@ void NetconEthernetTap::handleWrite(Connection *conn)
// corresponding PhySocket until nc_sent() is called and confirms that there is // corresponding PhySocket until nc_sent() is called and confirms that there is
// now space on the buffer // now space on the buffer
if(!conn->probation) { if(!conn->probation) {
dwr(MSG_ERROR," handleWrite(): sndbuf == 0, LWIP stack is full\n"); DEBUG_ERROR(" handleWrite(): sndbuf == 0, LWIP stack is full\n");
_phy.setNotifyReadable(conn->sock, false); _phy.setNotifyReadable(conn->sock, false);
conn->probation = true; conn->probation = true;
} }
@@ -1438,9 +1435,9 @@ void NetconEthernetTap::handleWrite(Connection *conn)
err = lwipstack->__tcp_write(conn->TCP_pcb, &conn->txbuf, r, TCP_WRITE_FLAG_COPY); err = lwipstack->__tcp_write(conn->TCP_pcb, &conn->txbuf, r, TCP_WRITE_FLAG_COPY);
lwipstack->__tcp_output(conn->TCP_pcb); lwipstack->__tcp_output(conn->TCP_pcb);
if(err != ERR_OK) { if(err != ERR_OK) {
dwr(MSG_ERROR," handleWrite(): error while writing to PCB, (err = %d)\n", err); DEBUG_ERROR(" handleWrite(): error while writing to PCB, (err = %d)\n", err);
if(err == -1) if(err == -1)
dwr(MSG_ERROR," handleWrite(): out of memory\n"); DEBUG_ERROR(" handleWrite(): out of memory\n");
return; return;
} else { } else {
sz = (conn->txsz)-r; sz = (conn->txsz)-r;
@@ -1448,7 +1445,7 @@ void NetconEthernetTap::handleWrite(Connection *conn)
memmove(&conn->txbuf, (conn->txbuf+r), sz); memmove(&conn->txbuf, (conn->txbuf+r), sz);
conn->txsz -= r; conn->txsz -= r;
int max = conn->type == SOCK_STREAM ? DEFAULT_TCP_TX_BUF_SZ : DEFAULT_UDP_TX_BUF_SZ; int max = conn->type == SOCK_STREAM ? DEFAULT_TCP_TX_BUF_SZ : DEFAULT_UDP_TX_BUF_SZ;
dwr(MSG_TRANSFER,"TCP TX ---> :: {TX: %.3f%%, RX: %.3f%%, sock=%p} :: %d bytes\n", DEBUG_TRANS("TCP TX ---> :: {TX: %.3f%%, RX: %.3f%%, sock=%p} :: %d bytes\n",
(float)conn->txsz / (float)max, (float)conn->rxsz / max, (void*)&conn->sock, r); (float)conn->txsz / (float)max, (float)conn->rxsz / max, (void*)&conn->sock, r);
return; return;
} }

View File

@@ -25,7 +25,7 @@
* LLC. Start here: http://www.zerotier.com/ * LLC. Start here: http://www.zerotier.com/
*/ */
#if defined(SDK_INTERCEPT) #if defined(_SDK_INTERCEPT_)
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
@@ -42,7 +42,7 @@
#include <pthread.h> #include <pthread.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> //#include <sys/socket.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/resource.h> #include <sys/resource.h>
@@ -59,9 +59,8 @@
#include "SDK_Debug.h" #include "SDK_Debug.h"
#include "SDK_RPC.h" #include "SDK_RPC.h"
void dwr(int level, const char *fmt, ... );
pthread_key_t thr_id_key; pthread_key_t thr_id_key;
char *api_netpath; //char *api_netpath;
// externs common between SDK_Intercept and SDK_Socket from SDK.h // externs common between SDK_Intercept and SDK_Socket from SDK.h
#if defined(__linux__) #if defined(__linux__)
@@ -93,7 +92,7 @@ char *api_netpath;
extern void load_symbols() extern void load_symbols()
{ {
dwr(MSG_DEBUG_EXTRA,"load_symbols\n"); DEBUG_EXTRA("");
#if defined(__linux__) #if defined(__linux__)
realaccept4 = dlsym(RTLD_NEXT, "accept4"); realaccept4 = dlsym(RTLD_NEXT, "accept4");
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
@@ -122,7 +121,7 @@ char *api_netpath;
// Return whether 'intercept' API is enabled for this thread // Return whether 'intercept' API is enabled for this thread
bool check_intercept_enabled() { bool check_intercept_enabled() {
dwr(MSG_DEBUG_EXTRA, "check_intercept_enabled()\n"); DEBUG_EXTRA("");
if(!realconnect){ if(!realconnect){
load_symbols(); load_symbols();
} }
@@ -157,7 +156,7 @@ char *api_netpath;
addr_un = (struct sockaddr_un*)&addr; addr_un = (struct sockaddr_un*)&addr;
return strcmp(addr_un->sun_path, api_netpath) == 0; return strcmp(addr_un->sun_path, api_netpath) == 0;
} }
dwr(MSG_DEBUG,"connected_to_service(): Not connected to service\n"); DEBUG_INFO("connected_to_service(): Not connected to service\n");
return 0; return 0;
} }
@@ -170,7 +169,7 @@ char *api_netpath;
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
ssize_t sendto(SENDTO_SIG) ssize_t sendto(SENDTO_SIG)
{ {
dwr(MSG_DEBUG, "sendto(%d, ..., %d)\n", fd, len); DEBUG_INFO("fd=%d, len=%d\n", fd, (int)len);
//if (!check_intercept_enabled()) //if (!check_intercept_enabled())
return realsendto(fd, buf, len, flags, addr, addrlen); return realsendto(fd, buf, len, flags, addr, addrlen);
return zts_sendto(fd, buf, len, flags, addr, addrlen); return zts_sendto(fd, buf, len, flags, addr, addrlen);
@@ -185,7 +184,7 @@ char *api_netpath;
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
ssize_t sendmsg(SENDMSG_SIG) ssize_t sendmsg(SENDMSG_SIG)
{ {
dwr(MSG_DEBUG, "sendmsg()\n"); DEBUG_INFO("");
//if(!check_intercept_enabled()) //if(!check_intercept_enabled())
return realsendmsg(fd, msg, flags); return realsendmsg(fd, msg, flags);
zts_sendmsg(fd, msg, flags); zts_sendmsg(fd, msg, flags);
@@ -201,7 +200,7 @@ char *api_netpath;
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
ssize_t recvfrom(RECVFROM_SIG) ssize_t recvfrom(RECVFROM_SIG)
{ {
dwr(MSG_DEBUG, "recvfrom(%d)\n", socket); DEBUG_INFO("fd=%d", fd);
if(!check_intercept_enabled()) if(!check_intercept_enabled())
return realrecvfrom(fd, buf, len, flags, addr, addrlen); return realrecvfrom(fd, buf, len, flags, addr, addrlen);
return zts_recvfrom(fd, buf, len, flags, addr, addrlen); return zts_recvfrom(fd, buf, len, flags, addr, addrlen);
@@ -216,7 +215,7 @@ char *api_netpath;
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
ssize_t recvmsg(RECVMSG_SIG) ssize_t recvmsg(RECVMSG_SIG)
{ {
dwr(MSG_DEBUG, "recvmsg(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
//if(!check_intercept_enabled()) //if(!check_intercept_enabled())
return realrecvmsg(fd, msg, flags); return realrecvmsg(fd, msg, flags);
return zts_recvmsg(fd, msg, flags); return zts_recvmsg(fd, msg, flags);
@@ -230,7 +229,7 @@ char *api_netpath;
int setsockopt(SETSOCKOPT_SIG) int setsockopt(SETSOCKOPT_SIG)
{ {
dwr(MSG_DEBUG, "setsockopt(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
if (!check_intercept_enabled()) if (!check_intercept_enabled())
return realsetsockopt(fd, level, optname, optval, optlen); return realsetsockopt(fd, level, optname, optval, optlen);
#if defined(__linux__) #if defined(__linux__)
@@ -253,7 +252,7 @@ char *api_netpath;
int getsockopt(GETSOCKOPT_SIG) int getsockopt(GETSOCKOPT_SIG)
{ {
dwr(MSG_DEBUG, "getsockopt(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
if (!check_intercept_enabled() || !connected_to_service(fd)) if (!check_intercept_enabled() || !connected_to_service(fd))
return realgetsockopt(fd, level, optname, optval, optlen); return realgetsockopt(fd, level, optname, optval, optlen);
return zts_getsockopt(fd, level, optname, optval, optlen); return zts_getsockopt(fd, level, optname, optval, optlen);
@@ -265,15 +264,15 @@ char *api_netpath;
// int socket_family, int socket_type, int protocol // int socket_family, int socket_type, int protocol
int socket(SOCKET_SIG) int socket(SOCKET_SIG)
{ {
dwr(MSG_DEBUG, "socket()\n"); DEBUG_INFO();
if (!check_intercept_enabled() && socket_type) { if (!check_intercept_enabled() && socket_type) {
int err = realsocket(socket_family, socket_type, protocol); int err = realsocket(socket_family, socket_type, protocol);
if(err < 0) { if(err < 0) {
perror("socket:\n"); perror("socket:\n");
} }
else { else {
dwr(MSG_DEBUG, " socket() = %d\n", err); DEBUG_INFO("err=%d", err);
return err; return err;
} }
} }
@@ -284,7 +283,7 @@ char *api_netpath;
#endif #endif
|| socket_family == AF_UNIX) { || socket_family == AF_UNIX) {
int err = realsocket(socket_family, socket_type, protocol); int err = realsocket(socket_family, socket_type, protocol);
dwr(MSG_DEBUG,"realsocket() = %d\n", err); DEBUG_BLANK("realsocket(): err=%d\n", err);
return err; return err;
} }
return zts_socket(socket_family, socket_type, protocol); return zts_socket(socket_family, socket_type, protocol);
@@ -297,14 +296,14 @@ char *api_netpath;
int connect(CONNECT_SIG) int connect(CONNECT_SIG)
{ {
dwr(MSG_DEBUG, "connect(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
struct sockaddr_in *connaddr; struct sockaddr_in *connaddr;
connaddr = (struct sockaddr_in *)addr; connaddr = (struct sockaddr_in *)addr;
if(addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX) { if(addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX) {
struct sockaddr_storage storage; struct sockaddr_storage storage;
memcpy(&storage, addr, addrlen); memcpy(&storage, addr, addrlen);
struct sockaddr_un *s_un = (struct sockaddr_un*)&storage; struct sockaddr_un *s_un = (struct sockaddr_un*)&storage;
dwr(MSG_DEBUG, "connect(): address = %s\n", s_un->sun_path); DEBUG_INFO("addr=%s\n", s_un->sun_path);
} }
int port = connaddr->sin_port; int port = connaddr->sin_port;
@@ -314,7 +313,7 @@ char *api_netpath;
d[1] = (ip >> 8) & 0xFF; d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_DEBUG,"connect(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], ntohs(port)); DEBUG_INFO("addr=%d.%d.%d.%d:%d\n", d[0],d[1],d[2],d[3], ntohs(port));
if(!check_intercept_enabled()) if(!check_intercept_enabled())
return realconnect(fd, addr, addrlen); return realconnect(fd, addr, addrlen);
@@ -360,7 +359,7 @@ char *api_netpath;
int bind(BIND_SIG) int bind(BIND_SIG)
{ {
dwr(MSG_DEBUG,"bind(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
// make sure we don't touch any standard outputs // make sure we don't touch any standard outputs
if(fd == 0 || fd == 1 || fd == 2) if(fd == 0 || fd == 1 || fd == 2)
return(realbind(fd, addr, addrlen)); return(realbind(fd, addr, addrlen));
@@ -373,7 +372,7 @@ char *api_netpath;
#endif #endif
|| connaddr->sin_family == AF_UNIX) { || connaddr->sin_family == AF_UNIX) {
int err = realbind(fd, addr, addrlen); int err = realbind(fd, addr, addrlen);
dwr(MSG_DEBUG,"realbind, err = %d\n", err); DEBUG_BLANK("realbind(): err=%d", err);
return err; return err;
} }
int port = connaddr->sin_port; int port = connaddr->sin_port;
@@ -383,7 +382,7 @@ char *api_netpath;
d[1] = (ip >> 8) & 0xFF; d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF; d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF; d[3] = (ip >> 24) & 0xFF;
dwr(MSG_DEBUG,"bind(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], ntohs(port)); DEBUG_INFO("addr=%d.%d.%d.%d:%d\n", d[0],d[1],d[2],d[3], ntohs(port));
int sock_type; int sock_type;
socklen_t sock_type_len = sizeof(sock_type); socklen_t sock_type_len = sizeof(sock_type);
@@ -418,7 +417,7 @@ char *api_netpath;
#if defined(__linux__) #if defined(__linux__)
int accept4(ACCEPT4_SIG) { int accept4(ACCEPT4_SIG) {
dwr(MSG_DEBUG,"accept4(%d):\n", fd); DEBUG_INFO("fd=%d", fd);
return zts_accept4(fd, addr, addrlen, flags); return zts_accept4(fd, addr, addrlen, flags);
} }
#endif #endif
@@ -429,7 +428,7 @@ char *api_netpath;
// int fd struct sockaddr *addr, socklen_t *addrlen // int fd struct sockaddr *addr, socklen_t *addrlen
int accept(ACCEPT_SIG) { int accept(ACCEPT_SIG) {
dwr(MSG_DEBUG,"accept(%d):\n", fd); DEBUG_INFO("fd=%d", fd);
if (!check_intercept_enabled()) if (!check_intercept_enabled())
return realaccept(fd, addr, addrlen); return realaccept(fd, addr, addrlen);
@@ -437,7 +436,7 @@ char *api_netpath;
if(fcntl(fd, F_GETFD) < 0) { if(fcntl(fd, F_GETFD) < 0) {
return -1; return -1;
errno = EBADF; errno = EBADF;
dwr(MSG_DEBUG,"EBADF\n"); DEBUG_INFO("EBADF\n");
return -1; return -1;
} }
// Check that it is a socket // Check that it is a socket
@@ -445,13 +444,13 @@ char *api_netpath;
socklen_t opt_len; socklen_t opt_len;
if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *) &opt, &opt_len) < 0) { if(getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *) &opt, &opt_len) < 0) {
errno = ENOTSOCK; errno = ENOTSOCK;
dwr(MSG_DEBUG,"ENOTSOCK\n"); DEBUG_INFO("ENOTSOCK\n");
return -1; return -1;
} }
// Check that this socket supports accept() // Check that this socket supports accept()
if(!(opt && (SOCK_STREAM | SOCK_SEQPACKET))) { if(!(opt && (SOCK_STREAM | SOCK_SEQPACKET))) {
errno = EOPNOTSUPP; errno = EOPNOTSUPP;
dwr(MSG_DEBUG,"EOPNOTSUPP\n"); DEBUG_INFO("EOPNOTSUPP\n");
return -1; return -1;
} }
// Check that we haven't hit the soft-limit file descriptors allowed // Check that we haven't hit the soft-limit file descriptors allowed
@@ -459,18 +458,18 @@ char *api_netpath;
getrlimit(RLIMIT_NOFILE, &rl); getrlimit(RLIMIT_NOFILE, &rl);
if(fd >= rl.rlim_cur){ if(fd >= rl.rlim_cur){
errno = EMFILE; errno = EMFILE;
dwr(MSG_DEBUG,"EMFILE\n"); DEBUG_INFO("EMFILE\n");
return -1; return -1;
} }
// Check address length // Check address length
if(addrlen < 0) { if(addrlen < 0) {
errno = EINVAL; errno = EINVAL;
dwr(MSG_DEBUG,"EINVAL\n"); DEBUG_INFO("EINVAL\n");
return -1; return -1;
} }
// redirect calls for standard I/O descriptors to kernel // redirect calls for standard I/O descriptors to kernel
if(fd == 0 || fd == 1 || fd == 2){ if(fd == 0 || fd == 1 || fd == 2){
dwr(MSG_DEBUG,"realaccept():\n"); DEBUG_BLANK("realaccept(): ");
return(realaccept(fd, addr, addrlen)); return(realaccept(fd, addr, addrlen));
} }
@@ -484,7 +483,7 @@ char *api_netpath;
int listen(LISTEN_SIG) int listen(LISTEN_SIG)
{ {
dwr(MSG_DEBUG,"listen(%d):\n", fd); DEBUG_INFO("listen(%d):\n", fd);
if (!check_intercept_enabled()) if (!check_intercept_enabled())
return reallisten(fd, backlog); return reallisten(fd, backlog);
@@ -521,7 +520,7 @@ char *api_netpath;
// int fd // int fd
int close(CLOSE_SIG) { int close(CLOSE_SIG) {
dwr(MSG_DEBUG, " close(%d)\n", fd); DEBUG_INFO(" close(%d)\n", fd);
if(!check_intercept_enabled()) { if(!check_intercept_enabled()) {
return realclose(fd); return realclose(fd);
} }
@@ -535,14 +534,14 @@ char *api_netpath;
int getsockname(GETSOCKNAME_SIG) int getsockname(GETSOCKNAME_SIG)
{ {
dwr(MSG_DEBUG,"getsockname(%d):\n", fd); DEBUG_INFO("getsockname(%d):\n", fd);
#if !defined(__IOS__) #if !defined(__IOS__)
if (!check_intercept_enabled()) if (!check_intercept_enabled())
return realgetsockname(fd, addr, addrlen); return realgetsockname(fd, addr, addrlen);
#endif #endif
dwr(MSG_DEBUG,"getsockname(%d)\n", fd); DEBUG_INFO("getsockname(%d)\n", fd);
if(!connected_to_service(fd)) { if(!connected_to_service(fd)) {
dwr(MSG_DEBUG,"getsockname(): not used by service\n"); DEBUG_INFO("getsockname(): not used by service\n");
return realgetsockname(fd, addr, addrlen); return realgetsockname(fd, addr, addrlen);
} }
return zts_getsockname(fd, addr, addrlen); return zts_getsockname(fd, addr, addrlen);
@@ -570,7 +569,7 @@ char *api_netpath;
if (!check_intercept_enabled()) if (!check_intercept_enabled())
return realsyscall(number,a,b,c,d,e,f); return realsyscall(number,a,b,c,d,e,f);
dwr(MSG_DEBUG,"syscall(%u, ...)\n", number); DEBUG_INFO("syscall(%u, ...)\n", number);
#if defined(__i386__) #if defined(__i386__)
// TODO: Implement for 32-bit systems: syscall(__NR_socketcall, 18, args); // TODO: Implement for 32-bit systems: syscall(__NR_socketcall, 18, args);
@@ -597,5 +596,5 @@ char *api_netpath;
#endif #endif
#endif #endif
#endif // zts_SDK_INTERCEPT #endif // _SDK_INTERCEPT_

View File

@@ -102,9 +102,9 @@ public class ZTSDK {
return zt_get_proxy_port(nwid); return zt_get_proxy_port(nwid);
} }
public native boolean zt_running(); public native boolean zt_service_is_running();
public boolean running() { public boolean service_is_running() {
return zt_running(); return zt_service_is_running();
} }
@@ -272,4 +272,11 @@ public class ZTSDK {
//public static native int zt_getsockopt(int fd, int type, int protocol); //public static native int zt_getsockopt(int fd, int type, int protocol);
//public static native int zt_setsockopt(int fd, int type, int protocol); //public static native int zt_setsockopt(int fd, int type, int protocol);
//public static native int zt_getsockname(int fd, int type, int protocol); //public static native int zt_getsockname(int fd, int type, int protocol);
// PROXY SERVER CONTROLS
public native boolean zt_proxy_is_running();
public boolean proxy_is_running() {
return zt_proxy_is_running();
}
} }

View File

@@ -1 +1 @@
#define ZTSDK_BUILD_VERSION 34 #define ZTSDK_BUILD_VERSION 44

View File

@@ -80,12 +80,12 @@ namespace ZeroTier
int NetconEthernetTap::stopProxyServer() int NetconEthernetTap::stopProxyServer()
{ {
dwr(MSG_DEBUG, "stopProxyServer()"); DEBUG_INFO("stopProxyServer()");
if(proxyListenPhySocket) { if(proxyListenPhySocket) {
_phy.close(proxyListenPhySocket); _phy.close(proxyListenPhySocket);
return 0; return 0;
} }
dwr(MSG_ERROR, "stopProxyServer(): Invalid proxyListenPhySocket"); DEBUG_ERROR("stopProxyServer(): Invalid proxyListenPhySocket");
return -1; return -1;
} }
@@ -96,25 +96,25 @@ namespace ZeroTier
// - If no address, assume 127.0.0.1:<networks.d/nwid.port> // - If no address, assume 127.0.0.1:<networks.d/nwid.port>
// - If no port assignment file, 127.0.0.1:RANDOM_PORT // - If no port assignment file, 127.0.0.1:RANDOM_PORT
dwr(MSG_DEBUG, "startProxyServer()\n"); DEBUG_INFO("startProxyServer()\n");
int portno = -1; int portno = -1;
if(addr) { if(addr) {
dwr(MSG_DEBUG, "startProxyServer(): Using provided address"); DEBUG_INFO("startProxyServer(): Using provided address");
// This address pointer may come from a different memory space and might be de-allocated, so we keep a copy // This address pointer may come from a different memory space and might be de-allocated, so we keep a copy
memcpy(&proxyServerAddress, addr, sizeof(struct sockaddr_storage)); memcpy(&proxyServerAddress, addr, sizeof(struct sockaddr_storage));
struct sockaddr_in *in4 = (struct sockaddr_in *)&addr; struct sockaddr_in *in4 = (struct sockaddr_in *)&addr;
proxyListenPhySocket = _phy.tcpListen((const struct sockaddr*)&in4,(void *)this); proxyListenPhySocket = _phy.tcpListen((const struct sockaddr*)&in4,(void *)this);
sockstate = SOCKS_OPEN; sockstate = SOCKS_OPEN;
dwr(MSG_DEBUG, "SOCKS5 proxy server address for <%.16llx> is: <%s> (sock=%p)\n", nwid, inet_ntoa(in4->sin_addr), /*ntohs(in4->sin_port), */(void*)&proxyListenPhySocket); DEBUG_INFO("SOCKS5 proxy server address for <%.16llx> is: <%s> (sock=%p)\n", nwid, inet_ntoa(in4->sin_addr), /*ntohs(in4->sin_port), */(void*)&proxyListenPhySocket);
return 0; return 0;
} }
else { else {
dwr(MSG_DEBUG, "startProxyServer(): No address provided. Checking port file."); DEBUG_INFO("startProxyServer(): No address provided. Checking port file.");
// Look for a port file for this network's proxy server instance // Look for a port file for this network's proxy server instance
char portFile[4096]; char portFile[4096];
Utils::snprintf(portFile,sizeof(portFile),"%s/networks.d/%.16llx.port",homepath,nwid); Utils::snprintf(portFile,sizeof(portFile),"%s/networks.d/%.16llx.port",homepath,nwid);
std::string portStr; std::string portStr;
printf("Proxy(): Reading port from: %s\n", portFile); DEBUG_INFO("Proxy(): Reading port from: %s\n", portFile);
if(ZeroTier::OSUtils::fileExists(portFile,true)) if(ZeroTier::OSUtils::fileExists(portFile,true))
{ {
if(ZeroTier::OSUtils::readFile(portFile, portStr)) { if(ZeroTier::OSUtils::readFile(portFile, portStr)) {
@@ -125,12 +125,12 @@ namespace ZeroTier
unsigned int randp = 0; unsigned int randp = 0;
Utils::getSecureRandom(&randp,sizeof(randp)); Utils::getSecureRandom(&randp,sizeof(randp));
portno = 1000 + (randp % 1000); portno = 1000 + (randp % 1000);
dwr(MSG_DEBUG, "Proxy(): No port specified in networks.d/%.16llx.port, randomly picking port\n", nwid); DEBUG_INFO("Proxy(): No port specified in networks.d/%.16llx.port, randomly picking port\n", nwid);
std::stringstream ss; std::stringstream ss;
ss << portno; ss << portno;
portStr = ss.str(); portStr = ss.str();
if(!ZeroTier::OSUtils::writeFile(portFile, portStr)) { if(!ZeroTier::OSUtils::writeFile(portFile, portStr)) {
dwr(MSG_ERROR, "unable to write proxy port file: %s\n", portFile); DEBUG_ERROR("unable to write proxy port file: %s\n", portFile);
} }
} }
struct sockaddr_in in4; struct sockaddr_in in4;
@@ -140,7 +140,7 @@ namespace ZeroTier
in4.sin_port = Utils::hton((uint16_t)portno); in4.sin_port = Utils::hton((uint16_t)portno);
proxyListenPhySocket = _phy.tcpListen((const struct sockaddr*)&in4,(void *)this); proxyListenPhySocket = _phy.tcpListen((const struct sockaddr*)&in4,(void *)this);
sockstate = SOCKS_OPEN; sockstate = SOCKS_OPEN;
//dwr(MSG_DEBUG, "SOCKS5 proxy server address for <%.16llx> is: <%s:%d> (sock=%p)\n", nwid, , portno, (void*)&proxyListenPhySocket); //DEBUG_INFO("SOCKS5 proxy server address for <%.16llx> is: <%s:%d> (sock=%p)\n", nwid, , portno, (void*)&proxyListenPhySocket);
} }
return 0; return 0;
} }
@@ -168,14 +168,14 @@ namespace ZeroTier
void NetconEthernetTap::phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsigned long len) void NetconEthernetTap::phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsigned long len)
{ {
dwr(MSG_DEBUG, "phyOnTcpData(): sock=%p, len=%lu\n", (void*)&sock, len); DEBUG_INFO("phyOnTcpData(): sock=%p, len=%lu\n", (void*)&sock, len);
unsigned char *buf; unsigned char *buf;
buf = (unsigned char *)data; buf = (unsigned char *)data;
// Get connection for this PhySocket // Get connection for this PhySocket
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
if(!conn) { if(!conn) {
dwr(MSG_DEBUG, "phyOnTcpData(): Unable to locate Connection for sock=%p\n", (void*)&sock); DEBUG_INFO("phyOnTcpData(): Unable to locate Connection for sock=%p\n", (void*)&sock);
return; return;
} }
@@ -183,7 +183,7 @@ namespace ZeroTier
if(conn->proxy_conn_state == SOCKS_COMPLETE) if(conn->proxy_conn_state == SOCKS_COMPLETE)
{ {
if(len) { if(len) {
dwr(MSG_DEBUG, "len=%lu\n", len); DEBUG_INFO("len=%lu\n", len);
memcpy((&conn->txbuf)+(conn->txsz), buf, len); memcpy((&conn->txbuf)+(conn->txsz), buf, len);
conn->txsz += len; conn->txsz += len;
handleWrite(conn); handleWrite(conn);
@@ -192,7 +192,7 @@ namespace ZeroTier
if(conn->proxy_conn_state==SOCKS_UDP) if(conn->proxy_conn_state==SOCKS_UDP)
{ {
dwr(MSG_DEBUG, "SOCKS_UDP from client\n"); DEBUG_INFO("SOCKS_UDP from client\n");
// +----+------+------+----------+----------+----------+ // +----+------+------+----------+----------+----------+
// |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA | // |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
// +----+------+------+----------+----------+----------+ // +----+------+------+----------+----------+----------+
@@ -222,7 +222,7 @@ namespace ZeroTier
if(firstSupportedMethod == 2) { if(firstSupportedMethod == 2) {
supportedMethod = firstSupportedMethod; supportedMethod = firstSupportedMethod;
} }
dwr(MSG_DEBUG, " INFO <ver=%d, meth_len=%d, supp_meth=%d>\n", version, methodsLength, supportedMethod); DEBUG_INFO(" INFO <ver=%d, meth_len=%d, supp_meth=%d>\n", version, methodsLength, supportedMethod);
// Send METHOD selection msg // Send METHOD selection msg
// +----+--------+ // +----+--------+
@@ -255,11 +255,11 @@ namespace ZeroTier
int cmd = buf[IDX_COMMAND]; int cmd = buf[IDX_COMMAND];
int addr_type = buf[IDX_ATYP]; int addr_type = buf[IDX_ATYP];
dwr(MSG_DEBUG, "SOCKS REQUEST = <ver=%d, cmd=%d, typ=%d>\n", version, cmd, addr_type); DEBUG_INFO("SOCKS REQUEST = <ver=%d, cmd=%d, typ=%d>\n", version, cmd, addr_type);
// CONNECT request // CONNECT request
if(cmd == 1) { if(cmd == 1) {
dwr(MSG_DEBUG, "CONNECT request\n"); DEBUG_INFO("CONNECT request\n");
// Ipv4 // Ipv4
/* /*
if(addr_type == 144) if(addr_type == 144)
@@ -269,12 +269,12 @@ namespace ZeroTier
memcpy(&raw_addr, &buf[4], 4); memcpy(&raw_addr, &buf[4], 4);
char newaddr[16]; char newaddr[16];
inet_ntop(AF_INET, &raw_addr, (char*)newaddr, INET_ADDRSTRLEN); inet_ntop(AF_INET, &raw_addr, (char*)newaddr, INET_ADDRSTRLEN);
dwr(MSG_DEBUG, "new addr = %s\n", newaddr); DEBUG_INFO("new addr = %s\n", newaddr);
int rawport, port; int rawport, port;
memcpy(&rawport, &buf[5], 2); memcpy(&rawport, &buf[5], 2);
port = Utils::ntoh(rawport); port = Utils::ntoh(rawport);
dwr(MSG_DEBUG, "new port = %d\n", port); DEBUG_INFO("new port = %d\n", port);
// Assemble new address // Assemble new address
struct sockaddr_in addr; struct sockaddr_in addr;
@@ -283,13 +283,13 @@ namespace ZeroTier
addr.sin_port = Utils::hton(8080); addr.sin_port = Utils::hton(8080);
int fd = socket(AF_INET, SOCK_STREAM, 0); int fd = socket(AF_INET, SOCK_STREAM, 0);
dwr(MSG_DEBUG, "fd = %d\n", fd); DEBUG_INFO("fd = %d\n", fd);
if(fd < 0) if(fd < 0)
perror("socket"); perror("socket");
int err = connect(fd, (struct sockaddr*)&addr, sizeof(addr)); int err = connect(fd, (struct sockaddr*)&addr, sizeof(addr));
dwr(MSG_DEBUG, "connect_err = %d\n", err); DEBUG_INFO("connect_err = %d\n", err);
if(err < 0) if(err < 0)
perror("connect"); perror("connect");
} }
@@ -302,7 +302,7 @@ namespace ZeroTier
ExtractAddress(addr_type,buf,&addr); ExtractAddress(addr_type,buf,&addr);
PhySocket * new_sock = handleSocketProxy(sock, SOCK_STREAM); PhySocket * new_sock = handleSocketProxy(sock, SOCK_STREAM);
if(!new_sock) if(!new_sock)
dwr(MSG_ERROR, "Error while creating proxied-socket\n"); DEBUG_ERROR("Error while creating proxied-socket\n");
handleConnectProxy(sock, &addr); handleConnectProxy(sock, &addr);
// Convert connection err code into SOCKS-err-code // Convert connection err code into SOCKS-err-code
@@ -324,7 +324,7 @@ namespace ZeroTier
// | 1 | 1 | X'00' | 1 | Variable | 2 | // | 1 | 1 | X'00' | 1 | Variable | 2 |
// +----+-----+-------+------+----------+----------+ // +----+-----+-------+------+----------+----------+
dwr(MSG_DEBUG, "REPLY = %d\n", addr.sin_port); DEBUG_INFO("REPLY = %d\n", addr.sin_port);
char reply[len]; // TODO: determine proper length char reply[len]; // TODO: determine proper length
int addr_len = domain_len; int addr_len = domain_len;
memset(reply, 0, len); // Create reply buffer at least as big as incoming SOCKS request data memset(reply, 0, len); // Create reply buffer at least as big as incoming SOCKS request data
@@ -346,7 +346,7 @@ namespace ZeroTier
// BIND Request // BIND Request
if(cmd == 2) if(cmd == 2)
{ {
dwr(MSG_DEBUG, "BIND request\n"); DEBUG_INFO("BIND request\n");
//char raw_addr[15]; //char raw_addr[15];
//int bind_port; //int bind_port;
} }
@@ -355,7 +355,7 @@ namespace ZeroTier
if(cmd == 3) if(cmd == 3)
{ {
// PORT supplied should be port assigned by server in previous msg // PORT supplied should be port assigned by server in previous msg
dwr(MSG_DEBUG, "UDP association request\n"); DEBUG_INFO("UDP association request\n");
// SOCKS_CONNECT (Cont.) // SOCKS_CONNECT (Cont.)
// +----+-----+-------+------+----------+----------+ // +----+-----+-------+------+----------+----------+
@@ -381,10 +381,10 @@ namespace ZeroTier
// Create new lwIP PCB // Create new lwIP PCB
PhySocket * new_sock = handleSocketProxy(sock, SOCK_DGRAM); PhySocket * new_sock = handleSocketProxy(sock, SOCK_DGRAM);
dwr(MSG_DEBUG, "new_sock = %p\n", (void*)&sock); DEBUG_INFO("new_sock = %p\n", (void*)&sock);
dwr(MSG_DEBUG, "new_sock = %p\n", (void*)&new_sock); DEBUG_INFO("new_sock = %p\n", (void*)&new_sock);
if(!new_sock) if(!new_sock)
dwr(MSG_ERROR, "Error while creating proxied-socket\n"); DEBUG_ERROR("Error while creating proxied-socket\n");
// Form address // Form address
struct sockaddr_in addr; struct sockaddr_in addr;
@@ -407,7 +407,7 @@ namespace ZeroTier
void NetconEthernetTap::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from) void NetconEthernetTap::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from)
{ {
dwr(MSG_DEBUG, "phyOnTcpAccept(): sock=%p\n", (void*)&sockN); DEBUG_INFO("phyOnTcpAccept(): sock=%p\n", (void*)&sockN);
Connection *newConn = new Connection(); Connection *newConn = new Connection();
newConn->sock = sockN; newConn->sock = sockN;
_phy.setNotifyWritable(sockN, false); _phy.setNotifyWritable(sockN, false);
@@ -416,17 +416,17 @@ namespace ZeroTier
void NetconEthernetTap::phyOnTcpConnect(PhySocket *sock,void **uptr,bool success) void NetconEthernetTap::phyOnTcpConnect(PhySocket *sock,void **uptr,bool success)
{ {
dwr(MSG_DEBUG, "phyOnTcpConnect(): sock=%p\n", (void*)&sock); DEBUG_INFO("phyOnTcpConnect(): sock=%p\n", (void*)&sock);
} }
// Unused -- no UDP or TCP from this thread/Phy<> // Unused -- no UDP or TCP from this thread/Phy<>
void NetconEthernetTap::phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *local_address, const struct sockaddr *from,void *data,unsigned long len) void NetconEthernetTap::phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *local_address, const struct sockaddr *from,void *data,unsigned long len)
{ {
dwr(MSG_DEBUG, "phyOnDatagram(): len = %lu\n", len); DEBUG_INFO("phyOnDatagram(): len = %lu\n", len);
if(len) { if(len) {
Connection *conn = getConnection(sock); Connection *conn = getConnection(sock);
if(!conn){ if(!conn){
dwr(MSG_ERROR, "unable to locate Connection: sock=%p\n", (void*)sock); DEBUG_ERROR("unable to locate Connection: sock=%p\n", (void*)sock);
return; return;
} }
unsigned char *buf = (unsigned char*)data; unsigned char *buf = (unsigned char*)data;
@@ -438,20 +438,20 @@ namespace ZeroTier
void NetconEthernetTap::phyOnTcpClose(PhySocket *sock,void **uptr) void NetconEthernetTap::phyOnTcpClose(PhySocket *sock,void **uptr)
{ {
dwr(MSG_DEBUG, "phyOnTcpClose(): sock=%p\n", (void*)&sock); DEBUG_INFO("phyOnTcpClose(): sock=%p\n", (void*)&sock);
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
closeConnection(sock); closeConnection(sock);
} }
void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr, bool lwip_invoked) void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr, bool lwip_invoked)
{ {
dwr(MSG_DEBUG, " phyOnTcpWritable(): sock=%p\n", (void*)&sock); DEBUG_INFO(" phyOnTcpWritable(): sock=%p\n", (void*)&sock);
processReceivedData(sock,uptr,lwip_invoked); processReceivedData(sock,uptr,lwip_invoked);
} }
// RX data on stream socks and send back over client sock's underlying fd // RX data on stream socks and send back over client sock's underlying fd
void NetconEthernetTap::phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable) void NetconEthernetTap::phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable)
{ {
dwr(MSG_DEBUG, "phyOnFileDescriptorActivity(): sock=%p\n", (void*&)sock); DEBUG_INFO("phyOnFileDescriptorActivity(): sock=%p\n", (void*&)sock);
} }
} }

View File

@@ -30,12 +30,7 @@
#endif #endif
#if defined(__linux__) #if defined(__linux__)
#include <sys/syscall.h> #include <sys/syscall.h>
#endif
// For defining the Android direct-call API
#if defined(__ANDROID__)
#include <jni.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
@@ -55,8 +50,8 @@
// externs common between SDK_Intercept and SDK_Socket from SDK.h // externs common between SDK_Intercept and SDK_Socket from SDK.h
int (*realsocket)(SOCKET_SIG); //int (*realsocket)(SOCKET_SIG);
int (*realconnect)(CONNECT_SIG); //int (*realconnect)(CONNECT_SIG);
void dwr(int level, const char *fmt, ... ); void dwr(int level, const char *fmt, ... );

View File

@@ -54,7 +54,7 @@
std::string service_path; std::string service_path;
pthread_t intercept_thread; pthread_t intercept_thread;
int * intercept_thread_id; int * intercept_thread_id;
pthread_key_t thr_id_key; extern pthread_key_t thr_id_key;
static ZeroTier::OneService *volatile zt1Service; static ZeroTier::OneService *volatile zt1Service;
std::string localHomeDir; // Local shortened path std::string localHomeDir; // Local shortened path
@@ -75,30 +75,29 @@ void zts_init_rpc(const char * path, const char * nwid);
void dwr(int level, const char *fmt, ... ); void dwr(int level, const char *fmt, ... );
int zts_start_proxy_server(const char *homepath, const char * nwid, struct sockaddr_storage * addr) { int zts_start_proxy_server(const char *homepath, const char * nwid, struct sockaddr_storage * addr) {
LOGV("zts_start_proxy_server\n"); DEBUG_INFO();
dwr(MSG_DEBUG, "zts_start_proxy_server()\n");
uint64_t nwid_int = strtoull(nwid, NULL, 16); uint64_t nwid_int = strtoull(nwid, NULL, 16);
ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int]; ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int];
if(tap) { if(tap) {
if(tap->startProxyServer(homepath, nwid_int, addr) < 0) { if(tap->startProxyServer(homepath, nwid_int, addr) < 0) {
dwr(MSG_ERROR, "zts_start_proxy_server(%s): Problem while starting server.", nwid); DEBUG_ERROR("zts_start_proxy_server(%s): Problem while starting server.", nwid);
return -1; return -1;
} }
} }
dwr(MSG_ERROR, "zts_start_proxy_server(%s): Invalid tap. Possibly incorrect NWID", nwid); DEBUG_ERROR("zts_start_proxy_server(%s): Invalid tap. Possibly incorrect NWID", nwid);
return 0; return 0;
} }
int zts_stop_proxy_server(const char *nwid) { int zts_stop_proxy_server(const char *nwid) {
dwr(MSG_DEBUG, "zts_stop_proxy_server()"); DEBUG_INFO("zts_stop_proxy_server()");
uint64_t nwid_int = strtoull(nwid, NULL, 16); uint64_t nwid_int = strtoull(nwid, NULL, 16);
ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int]; ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int];
if(tap) { if(tap) {
if(tap->stopProxyServer() < 0) { if(tap->stopProxyServer() < 0) {
dwr(MSG_ERROR, "zts_stop_proxy_server(%s): Problem while stopping server.", nwid); DEBUG_ERROR("zts_stop_proxy_server(%s): Problem while stopping server.", nwid);
return -1; return -1;
} }
} }
dwr(MSG_ERROR, "zts_stop_proxy_server(%s): Invalid tap. Possibly incorrect NWID", nwid); DEBUG_ERROR("zts_stop_proxy_server(%s): Invalid tap. Possibly incorrect NWID", nwid);
return 0; return 0;
} }
int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage * addr) { int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage * addr) {
@@ -114,13 +113,13 @@ int zts_get_proxy_server_address(const char * nwid, struct sockaddr_storage * ad
// Basic ZT service controls // Basic ZT service controls
// Will also spin up a SOCKS5 proxy server if USE_SOCKS_PROXY is set // Will also spin up a SOCKS5 proxy server if USE_SOCKS_PROXY is set
void zts_join_network(const char * nwid) { void zts_join_network(const char * nwid) {
LOGV("zts_join_network\n"); DEBUG_INFO();
std::string confFile = zt1Service->givenHomePath() + "/networks.d/" + nwid + ".conf"; std::string confFile = zt1Service->givenHomePath() + "/networks.d/" + nwid + ".conf";
if(!ZeroTier::OSUtils::mkdir(netDir)) { if(!ZeroTier::OSUtils::mkdir(netDir)) {
dwr(MSG_ERROR, "unable to create %s\n", netDir.c_str()); DEBUG_INFO("unable to create %s\n", netDir.c_str());
} }
if(!ZeroTier::OSUtils::writeFile(confFile.c_str(), "")) { if(!ZeroTier::OSUtils::writeFile(confFile.c_str(), "")) {
dwr(MSG_ERROR, "unable to write network conf file: %s\n", confFile.c_str()); DEBUG_INFO("unable to write network conf file: %s\n", confFile.c_str());
} }
zt1Service->join(nwid); zt1Service->join(nwid);
// Provide the API with the RPC information // Provide the API with the RPC information
@@ -132,7 +131,7 @@ void zts_join_network(const char * nwid) {
#endif #endif
} }
void zts_leave_network(const char * nwid) { zt1Service->leave(nwid); } void zts_leave_network(const char * nwid) { zt1Service->leave(nwid); }
bool zts_is_running() { return zt1Service->isRunning(); } bool zts_service_is_running() { return zt1Service->isRunning(); }
void zts_stop_service() { zt1Service->terminate(); } void zts_stop_service() { zt1Service->terminate(); }
// FIXME: Re-implemented to make it play nicer with the C-linkage required for Xcode integrations // FIXME: Re-implemented to make it play nicer with the C-linkage required for Xcode integrations
@@ -143,7 +142,7 @@ void zts_get_addresses(const char * nwid, char *addrstr)
ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int]; ZeroTier::NetconEthernetTap * tap = zt1Service->getTaps()[nwid_int];
if(tap && tap->_ips.size()){ if(tap && tap->_ips.size()){
std::string addr = tap->_ips[0].toString(); std::string addr = tap->_ips[0].toString();
dwr(MSG_DEBUG, "addr.length() = %d, addr = %s\n", addr.length(), addr.c_str()); DEBUG_INFO("addr.length() = %d, addr = %s\n", addr.length(), addr.c_str());
memcpy(addrstr, addr.c_str(), addr.length()); memcpy(addrstr, addr.c_str(), addr.length());
} }
else { else {
@@ -222,26 +221,30 @@ char *zts_get_homepath() {
/* NOTE: Since on Android devices the sdcard is formatted as fat32, we can't use just any /* NOTE: Since on Android devices the sdcard is formatted as fat32, we can't use just any
location to set up the RPC unix domain socket. Rather we must use the application's specific location to set up the RPC unix domain socket. Rather we must use the application's specific
data directory given by getApplicationContext().getFilesDir() */ data directory given by getApplicationContext().getFilesDir() */
JNIEXPORT int JNICALL Java_ZeroTier_SDK_zt_1start_1service(JNIEnv *env, jobject thisObj, jstring path) { JNIEXPORT int JNICALL Java_ZeroTier_ZTSDK_zt_1start_1service(JNIEnv *env, jobject thisObj, jstring path) {
if(path) if(path)
homeDir = env->GetStringUTFChars(path, NULL); homeDir = env->GetStringUTFChars(path, NULL);
zts_start_service(NULL); zts_start_service(NULL);
} }
// Shuts down ZeroTier service and SOCKS5 Proxy server // Shuts down ZeroTier service and SOCKS5 Proxy server
JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1stop_1service(JNIEnv *env, jobject thisObj) { JNIEXPORT void JNICALL Java_ZeroTier_ZTSDK_zt_1stop_1service(JNIEnv *env, jobject thisObj) {
if(zt1Service) if(zt1Service)
zts_stop_service(); zts_stop_service();
// TODO: Also terminate SOCKS5 Proxy // TODO: Also terminate SOCKS5 Proxy
// zts_stop_proxy_server(); // zts_stop_proxy_server();
} }
// Returns whether the ZeroTier service is running // Returns whether the ZeroTier service is running
JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_zt_1running(JNIEnv *env, jobject thisObj) { JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1service_1is_1running(JNIEnv *env, jobject thisObj) {
if(zt1Service) if(zt1Service)
return zts_is_running(); return zts_service_is_running();
return false; return false;
} }
// Returns path for ZT config/data files
JNIEXPORT jstring JNICALL Java_ZeroTier_ZTSDK_zt_1get_1homepath(JNIEnv *env, jobject thisObj) {
return (*env).NewStringUTF(zts_get_homepath());
}
// Join a network // Join a network
JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1join_1network(JNIEnv *env, jobject thisObj, jstring nwid) { JNIEXPORT void JNICALL Java_ZeroTier_ZTSDK_zt_1join_1network(JNIEnv *env, jobject thisObj, jstring nwid) {
const char *nwidstr; const char *nwidstr;
if(nwid) { if(nwid) {
nwidstr = env->GetStringUTFChars(nwid, NULL); nwidstr = env->GetStringUTFChars(nwid, NULL);
@@ -249,7 +252,7 @@ char *zts_get_homepath() {
} }
} }
// Leave a network // Leave a network
JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1leave_1network(JNIEnv *env, jobject thisObj, jstring nwid) { JNIEXPORT void JNICALL Java_ZeroTier_ZTSDK_zt_1leave_1network(JNIEnv *env, jobject thisObj, jstring nwid) {
const char *nwidstr; const char *nwidstr;
if(nwid) { if(nwid) {
nwidstr = env->GetStringUTFChars(nwid, NULL); nwidstr = env->GetStringUTFChars(nwid, NULL);
@@ -258,7 +261,7 @@ char *zts_get_homepath() {
} }
// FIXME: Re-implemented to make it play nicer with the C-linkage required for Xcode integrations // 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 // Now only returns first assigned address per network. Shouldn't normally be a problem
JNIEXPORT jobject JNICALL Java_ZeroTier_SDK_zt_1get_1addresses(JNIEnv *env, jobject thisObj, jstring nwid) { JNIEXPORT jobject JNICALL Java_ZeroTier_ZTSDK_zt_1get_1addresses(JNIEnv *env, jobject thisObj, jstring nwid) {
const char *nwid_str = env->GetStringUTFChars(nwid, NULL); const char *nwid_str = env->GetStringUTFChars(nwid, NULL);
char address_string[32]; char address_string[32];
memset(address_string, 0, 32); memset(address_string, 0, 32);
@@ -287,15 +290,15 @@ char *zts_get_homepath() {
*/ */
} }
// Returns the device is in integer form // Returns the device is in integer form
JNIEXPORT jint Java_ZeroTier_SDK_zt_1get_1device_1id() { JNIEXPORT jint Java_ZeroTier_ZTSDK_zt_1get_1device_1id() {
return zts_get_device_id(); return zts_get_device_id();
} }
// Returns whether the path to an endpoint is currently relayed by a root server // Returns whether the path to an endpoint is currently relayed by a root server
JNIEXPORT jboolean JNICALL Java_ZeroTier_SDK_zt_1is_1relayed() { JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1is_1relayed() {
return zts_is_relayed(); return zts_is_relayed();
} }
// Returns the local address of the SOCKS5 Proxy server // Returns the local address of the SOCKS5 Proxy server
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1get_1proxy_1server_1address(JNIEnv *env, jobject thisObj, jstring nwid, jobject ztaddr) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1get_1proxy_1server_1address(JNIEnv *env, jobject thisObj, jstring nwid, jobject ztaddr) {
struct sockaddr_in addr; struct sockaddr_in addr;
int err = zts_get_proxy_server_address(env->GetStringUTFChars(nwid, NULL), (struct sockaddr_storage*)&addr); int err = zts_get_proxy_server_address(env->GetStringUTFChars(nwid, NULL), (struct sockaddr_storage*)&addr);
// SET ZTAddress fields // SET ZTAddress fields
@@ -308,7 +311,7 @@ char *zts_get_homepath() {
return err; return err;
} }
// Starts a SOCKS5 proxy server for a given ZeroTier network // Starts a SOCKS5 proxy server for a given ZeroTier network
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1start_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid, jobject ztaddr) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1start_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid, jobject ztaddr) {
const char *nwidstr = env->GetStringUTFChars(nwid, NULL); const char *nwidstr = env->GetStringUTFChars(nwid, NULL);
struct sockaddr_in addr; struct sockaddr_in addr;
// GET ZTAddress fields // GET ZTAddress fields
@@ -320,11 +323,12 @@ char *zts_get_homepath() {
return zts_start_proxy_server((char *)zts_get_homepath, nwidstr, (struct sockaddr_storage *)&addr); return zts_start_proxy_server((char *)zts_get_homepath, nwidstr, (struct sockaddr_storage *)&addr);
} }
// //
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1stop_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1stop_1proxy_1server(JNIEnv *env, jobject thisObj, jstring nwid) {
return zts_stop_proxy_server((char*)env->GetStringUTFChars(nwid, NULL)); return zts_stop_proxy_server((char*)env->GetStringUTFChars(nwid, NULL));
} }
JNIEXPORT jstring JNICALL Java_ZeroTier_SDK_zt_1get_1homepath(JNIEnv *env, jobject thisObj) { //
return (*env).NewStringUTF(zts_get_homepath()); JNIEXPORT jboolean JNICALL Java_ZeroTier_ZTSDK_zt_1proxy_1is_1running(JNIEnv *env, jobject thisObj, jstring nwid) {
// TODO: implement
} }
#endif #endif
@@ -362,8 +366,7 @@ char *zts_get_homepath() {
// Starts a ZeroTier service in the background // Starts a ZeroTier service in the background
void *zts_start_service(void *thread_id) { void *zts_start_service(void *thread_id) {
#if defined(__ANDROID__) #if defined(__ANDROID__)
dwr(MSG_DEBUG, "ZTSDK_BUILD_VERSION = %d\n", ZTSDK_BUILD_VERSION); DEBUG_INFO("ZTSDK_BUILD_VERSION = %d\n", ZTSDK_BUILD_VERSION);
LOGV("ZTSDK_BUILD_VERSION = %d\n", ZTSDK_BUILD_VERSION);
#endif #endif
#if defined(SDK_BUNDLED) && !defined(__ANDROID__) #if defined(SDK_BUNDLED) && !defined(__ANDROID__)
@@ -392,7 +395,7 @@ void *zts_start_service(void *thread_id) {
localHomeDir = homeDir; // Used for RPC and *can* differ from homeDir on some platforms localHomeDir = homeDir; // Used for RPC and *can* differ from homeDir on some platforms
#endif #endif
dwr(MSG_DEBUG, "homeDir = %s\n", homeDir.c_str()); DEBUG_INFO("homeDir = %s\n", homeDir.c_str());
// Where network .conf files will be stored // Where network .conf files will be stored
netDir = homeDir + "/networks.d"; netDir = homeDir + "/networks.d";
zt1Service = (ZeroTier::OneService *)0; zt1Service = (ZeroTier::OneService *)0;
@@ -409,7 +412,7 @@ void *zts_start_service(void *thread_id) {
ptmp.append(*pi); ptmp.append(*pi);
if ((*pi != ".")&&(*pi != "..")) { if ((*pi != ".")&&(*pi != "..")) {
if (!ZeroTier::OSUtils::mkdir(ptmp)) { if (!ZeroTier::OSUtils::mkdir(ptmp)) {
dwr(MSG_ERROR, "startOneService(): home path does not exist, and could not create\n"); DEBUG_ERROR("startOneService(): home path does not exist, and could not create\n");
} }
} }
} }

View File

@@ -75,11 +75,10 @@
#include "Constants.hpp" // For Tap's MTU #include "Constants.hpp" // For Tap's MTU
// Prototypes // Prototypes
void dwr(int level, const char *fmt, ... );
char *api_netpath = (char *)0; char *api_netpath = (char *)0;
void load_symbols(); void load_symbols();
void load_symbols_rpc(); void load_symbols_rpc();
int (*realclose)(CLOSE_SIG); //int (*realclose)(CLOSE_SIG);
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// ---------------------------------- zt_init_rpc ------------------------------- // ---------------------------------- zt_init_rpc -------------------------------
@@ -88,7 +87,7 @@ int (*realclose)(CLOSE_SIG);
// Assembles (and/or) sets the RPC path for communication with the ZeroTier service // Assembles (and/or) sets the RPC path for communication with the ZeroTier service
void zts_init_rpc(const char *path, const char *nwid) void zts_init_rpc(const char *path, const char *nwid)
{ {
// dwr(MSG_DEBUG_EXTRA, "zt_init_rpc\n"); DEBUG_EXTRA("zt_init_rpc\n");
#if !defined(__IOS__) #if !defined(__IOS__)
// Since we don't use function interposition in iOS // Since we don't use function interposition in iOS
if(!realconnect) { if(!realconnect) {
@@ -113,10 +112,10 @@ int (*realclose)(CLOSE_SIG);
// This is used when you're dynamically-linking our library into your application at runtime // This is used when you're dynamically-linking our library into your application at runtime
if (!api_netpath) { if (!api_netpath) {
api_netpath = getenv("ZT_NC_NETWORK"); api_netpath = getenv("ZT_NC_NETWORK");
dwr(MSG_DEBUG, "$ZT_NC_NETWORK(len=%d) = %s\n", strlen(api_netpath), api_netpath); DEBUG_INFO("$ZT_NC_NETWORK(len=%d) = %s\n", strlen(api_netpath), api_netpath);
} }
#endif #endif
dwr(MSG_DEBUG_EXTRA, "zt_init_rpc(): api_netpath = %s\n", api_netpath); DEBUG_EXTRA("zt_init_rpc(): api_netpath = %s\n", api_netpath);
} }
} }
@@ -128,7 +127,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, const void *buf, size_t len // int fd, const void *buf, size_t len
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags) JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags)
{ {
jbyte *body = (*env)->GetByteArrayElements(env, buf, 0); jbyte *body = (*env)->GetByteArrayElements(env, buf, 0);
char * bufp = (char *)malloc(sizeof(char)*len); char * bufp = (char *)malloc(sizeof(char)*len);
@@ -148,7 +147,7 @@ int (*realclose)(CLOSE_SIG);
#if defined(__ANDROID__) #if defined(__ANDROID__)
// TODO: Check result of each JNI call // TODO: Check result of each JNI call
// UDP TX // UDP TX
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1sendto( JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1sendto(
JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr) JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
@@ -177,7 +176,7 @@ int (*realclose)(CLOSE_SIG);
ssize_t zts_sendto(SENDTO_SIG) // Used as internal implementation ssize_t zts_sendto(SENDTO_SIG) // Used as internal implementation
#endif #endif
{ {
dwr(MSG_DEBUG_EXTRA, "zt_sendto(%d, ...)\n", fd); DEBUG_EXTRA("zt_sendto(%d, ...)\n", fd);
if(len > ZT_UDP_DEFAULT_PAYLOAD_MTU) { if(len > ZT_UDP_DEFAULT_PAYLOAD_MTU) {
errno = EMSGSIZE; // Msg is too large errno = EMSGSIZE; // Msg is too large
return -1; return -1;
@@ -198,7 +197,7 @@ int (*realclose)(CLOSE_SIG);
// This connect call is used to get the address info to the stack for sending the packet // This connect call is used to get the address info to the stack for sending the packet
int err; int err;
if((err = zts_connect(fd, addr, addrlen)) < 0) { if((err = zts_connect(fd, addr, addrlen)) < 0) {
LOGV("sendto(): unknown problem passing address info to stack\n"); DEBUG_ERROR("unknown problem passing address info to stack");
errno = EISCONN; // double-check this is correct errno = EISCONN; // double-check this is correct
return -1; return -1;
} }
@@ -218,7 +217,7 @@ int (*realclose)(CLOSE_SIG);
ssize_t zts_sendmsg(SENDMSG_SIG) ssize_t zts_sendmsg(SENDMSG_SIG)
#endif #endif
{ {
dwr(MSG_DEBUG_EXTRA, "zt_sendmsg(%d)\n", fd); DEBUG_EXTRA("fd=%d",fd);
char * p, * buf; char * p, * buf;
size_t tot_len = 0; size_t tot_len = 0;
size_t err; size_t err;
@@ -253,7 +252,7 @@ int (*realclose)(CLOSE_SIG);
#if defined(__ANDROID__) #if defined(__ANDROID__)
// UDP RX // UDP RX
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1recvfrom( JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1recvfrom(
JNIEnv *env, jobject thisObj, jint fd, jbyteArray buf, jint len, jint flags, jobject ztaddr) JNIEnv *env, jobject thisObj, jint fd, jbyteArray buf, jint len, jint flags, jobject ztaddr)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
@@ -283,7 +282,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
int tmpsz = 0; // payload size int tmpsz = 0; // payload size
// dwr(MSG_DEBUG_EXTRA,"zt_recvfrom(%d, ...)\n", fd); // DEBUG_EXTRA("zt_recvfrom(%d, ...)\n", fd);
if(read(fd, buf, ZT_MAX_MTU) > 0) { if(read(fd, buf, ZT_MAX_MTU) > 0) {
// TODO: case for address size mismatch? // TODO: case for address size mismatch?
memcpy(addr, buf, addrlen); memcpy(addr, buf, addrlen);
@@ -308,7 +307,7 @@ int (*realclose)(CLOSE_SIG);
ssize_t zts_recvmsg(RECVMSG_SIG) ssize_t zts_recvmsg(RECVMSG_SIG)
#endif #endif
{ {
dwr(MSG_DEBUG_EXTRA, "zt_recvmsg(%d)\n", fd); DEBUG_EXTRA("zt_recvmsg(%d)\n", fd);
ssize_t err, n, tot_len = 0; ssize_t err, n, tot_len = 0;
char *buf, *p; char *buf, *p;
struct iovec *iov = msg->msg_iov; struct iovec *iov = msg->msg_iov;
@@ -366,7 +365,7 @@ int (*realclose)(CLOSE_SIG);
#if defined(__ANDROID__) #if defined(__ANDROID__)
// TCP TX // TCP TX
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1write(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len) JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1write(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len)
{ {
jbyte *body = (*env)->GetByteArrayElements(env, buf, 0); jbyte *body = (*env)->GetByteArrayElements(env, buf, 0);
char * bufp = (char *)malloc(sizeof(char)*len); char * bufp = (char *)malloc(sizeof(char)*len);
@@ -376,7 +375,7 @@ int (*realclose)(CLOSE_SIG);
return written_bytes; return written_bytes;
} }
// TCP RX // TCP RX
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1read(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len) JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1read(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len)
{ {
jbyte *body = (*env)->GetByteArrayElements(env, buf, 0); jbyte *body = (*env)->GetByteArrayElements(env, buf, 0);
int read_bytes = read(fd, body, len); int read_bytes = read(fd, body, len);
@@ -391,7 +390,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, int level, int optname, const void *optval, socklen_t optlen // int fd, int level, int optname, const void *optval, socklen_t optlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1setsockopt( JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1setsockopt(
JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen) { JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen) {
return zts_setsockopt(fd, level, optname, optval, optlen); return zts_setsockopt(fd, level, optname, optval, optlen);
} }
@@ -403,7 +402,7 @@ int (*realclose)(CLOSE_SIG);
int zts_setsockopt(SETSOCKOPT_SIG) int zts_setsockopt(SETSOCKOPT_SIG)
#endif #endif
{ {
dwr(MSG_DEBUG, "zt_setsockopt(%d)\n", fd); DEBUG_INFO("zt_setsockopt(%d)\n", fd);
return 0; return 0;
} }
@@ -413,7 +412,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, int level, int optname, void *optval, socklen_t *optlen // int fd, int level, int optname, void *optval, socklen_t *optlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1getsockopt( JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1getsockopt(
JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen) { JNIEnv *env, jobject thisObj, jint fd, jint level, jint optname, jint optval, jint optlen) {
return zts_getsockopt(fd, level, optname, optval, optlen); return zts_getsockopt(fd, level, optname, optval, optlen);
} }
@@ -425,7 +424,7 @@ int (*realclose)(CLOSE_SIG);
int zts_getsockopt(GETSOCKOPT_SIG) int zts_getsockopt(GETSOCKOPT_SIG)
#endif #endif
{ {
dwr(MSG_DEBUG,"zt_getsockopt(%d)\n", fd); DEBUG_INFO("zt_getsockopt(%d)\n", fd);
if(optname == SO_TYPE) { if(optname == SO_TYPE) {
int* val = (int*)optval; int* val = (int*)optval;
*val = 2; *val = 2;
@@ -440,7 +439,7 @@ int (*realclose)(CLOSE_SIG);
// int socket_family, int socket_type, int protocol // int socket_family, int socket_type, int protocol
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1socket(JNIEnv *env, jobject thisObj, jint family, jint type, jint protocol) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1socket(JNIEnv *env, jobject thisObj, jint family, jint type, jint protocol) {
return zts_socket(family, type, protocol); return zts_socket(family, type, protocol);
} }
#endif #endif
@@ -452,7 +451,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG, "zt_socket()\n"); DEBUG_INFO("");
// Check that type makes sense // Check that type makes sense
#if defined(__linux__) #if defined(__linux__)
int flags = socket_type & ~SOCK_TYPE_MASK; int flags = socket_type & ~SOCK_TYPE_MASK;
@@ -488,9 +487,9 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
#endif #endif
// -1 is passed since we we're generating the new socket in this call // -1 is passed since we we're generating the new socket in this call
printf("api_netpath = %s\n", api_netpath); DEBUG_INFO("api_netpath=%s\n", api_netpath);
int err = rpc_send_command(api_netpath, RPC_SOCKET, -1, &rpc_st, sizeof(struct socket_st)); int err = rpc_send_command(api_netpath, RPC_SOCKET, -1, &rpc_st, sizeof(struct socket_st));
dwr(MSG_DEBUG," socket() = %d\n", err); DEBUG_INFO("err=%d\n", err);
return err; return err;
} }
@@ -500,10 +499,10 @@ int (*realclose)(CLOSE_SIG);
// int fd, const struct sockaddr *addr, socklen_t addrlen // int fd, const struct sockaddr *addr, socklen_t addrlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1connect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1connect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) {
struct sockaddr_in addr; struct sockaddr_in addr;
const char *str = (*env)->GetStringUTFChars(env, addrstr, 0); const char *str = (*env)->GetStringUTFChars(env, addrstr, 0);
dwr(MSG_DEBUG, "zt_connect(): fd = %d\naddr = %s\nport=%d", fd, str, port); DEBUG_INFO("zt_connect(): fd = %d\naddr = %s\nport=%d", fd, str, port);
addr.sin_addr.s_addr = inet_addr(str); addr.sin_addr.s_addr = inet_addr(str);
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons( port ); addr.sin_port = htons( port );
@@ -519,7 +518,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG,"zt_connect(%d)\n", fd); DEBUG_INFO("zt_connect(%d)\n", fd);
struct connect_st rpc_st; struct connect_st rpc_st;
#if defined(__linux__) #if defined(__linux__)
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
@@ -540,10 +539,10 @@ int (*realclose)(CLOSE_SIG);
// int fd, const struct sockaddr *addr, socklen_t addrlen // int fd, const struct sockaddr *addr, socklen_t addrlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1bind(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1bind(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) {
struct sockaddr_in addr; struct sockaddr_in addr;
const char *str = (*env)->GetStringUTFChars(env, addrstr, 0); const char *str = (*env)->GetStringUTFChars(env, addrstr, 0);
dwr(MSG_DEBUG, "zt_bind(): fd = %d\naddr = %s\nport=%d", fd, str, port); DEBUG_INFO("zt_bind(): fd = %d\naddr = %s\nport=%d", fd, str, port);
addr.sin_addr.s_addr = inet_addr(str); addr.sin_addr.s_addr = inet_addr(str);
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons( port ); addr.sin_port = htons( port );
@@ -559,7 +558,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG,"zt_bind(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
struct bind_st rpc_st; struct bind_st rpc_st;
rpc_st.fd = fd; rpc_st.fd = fd;
#if defined(__linux__) #if defined(__linux__)
@@ -581,7 +580,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, struct sockaddr *addr, socklen_t *addrlen, int flags // int fd, struct sockaddr *addr, socklen_t *addrlen, int flags
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1accept4(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port, jint flags) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1accept4(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port, jint flags) {
struct sockaddr_in addr; struct sockaddr_in addr;
char *str; char *str;
// = env->GetStringUTFChars(addrstr, NULL); // = env->GetStringUTFChars(addrstr, NULL);
@@ -601,7 +600,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG,"zt_accept4(%d):\n", fd); DEBUG_INFO("zt_accept4(%d):\n", fd);
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
if ((flags & SOCK_CLOEXEC)) if ((flags & SOCK_CLOEXEC))
fcntl(fd, F_SETFL, FD_CLOEXEC); fcntl(fd, F_SETFL, FD_CLOEXEC);
@@ -619,7 +618,7 @@ int (*realclose)(CLOSE_SIG);
// int fd struct sockaddr *addr, socklen_t *addrlen // int fd struct sockaddr *addr, socklen_t *addrlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1accept(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1accept(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) {
struct sockaddr_in addr; struct sockaddr_in addr;
// TODO: Send addr info back to Javaland // TODO: Send addr info back to Javaland
addr.sin_addr.s_addr = inet_addr(""); addr.sin_addr.s_addr = inet_addr("");
@@ -636,14 +635,14 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG,"zt_accept(%d):\n", fd); DEBUG_INFO("fd=%d", fd);
// FIXME: Find a better solution for this before production // FIXME: Find a better solution for this before production
#if !defined(__UNITY_3D__) #if !defined(__UNITY_3D__)
if(addr) if(addr)
addr->sa_family = AF_INET; addr->sa_family = AF_INET;
#endif #endif
int new_fd = get_new_fd(fd); int new_fd = get_new_fd(fd);
dwr(MSG_DEBUG,"newfd = %d\n", new_fd); DEBUG_INFO("newfd=%d", new_fd);
if(new_fd > 0) { if(new_fd > 0) {
errno = ERR_OK; errno = ERR_OK;
@@ -659,7 +658,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, int backlog // int fd, int backlog
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1listen(JNIEnv *env, jobject thisObj, jint fd, int backlog) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1listen(JNIEnv *env, jobject thisObj, jint fd, int backlog) {
return zts_listen(fd, backlog); return zts_listen(fd, backlog);
} }
#endif #endif
@@ -671,7 +670,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG,"zt_listen(%d):\n", fd); DEBUG_INFO("fd=%d", fd);
struct listen_st rpc_st; struct listen_st rpc_st;
rpc_st.fd = fd; rpc_st.fd = fd;
rpc_st.backlog = backlog; rpc_st.backlog = backlog;
@@ -691,7 +690,7 @@ int (*realclose)(CLOSE_SIG);
// int fd // int fd
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1close(JNIEnv *env, jobject thisObj, jint fd) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1close(JNIEnv *env, jobject thisObj, jint fd) {
return zts_close(fd); return zts_close(fd);
} }
#endif #endif
@@ -703,7 +702,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG, "zt_close(%d)\n", fd); DEBUG_INFO("fd=%d", fd);
return realclose(fd); return realclose(fd);
} }
@@ -713,7 +712,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, struct sockaddr *addr, socklen_t *addrlen // int fd, struct sockaddr *addr, socklen_t *addrlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1getsockname(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1getsockname(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr) {
struct sockaddr_in addr; struct sockaddr_in addr;
int err = zts_getsockname(fd, &addr, sizeof(struct sockaddr)); int err = zts_getsockname(fd, &addr, sizeof(struct sockaddr));
jfieldID fid; jfieldID fid;
@@ -733,7 +732,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG_EXTRA,"zt_getsockname(%d):\n", fd); DEBUG_EXTRA("fd=%d", fd);
struct getsockname_st rpc_st; struct getsockname_st rpc_st;
rpc_st.fd = fd; rpc_st.fd = fd;
memcpy(&rpc_st.addrlen, &addrlen, sizeof(socklen_t)); memcpy(&rpc_st.addrlen, &addrlen, sizeof(socklen_t));
@@ -751,13 +750,13 @@ int (*realclose)(CLOSE_SIG);
} }
if(!sum) { // RXed a zero-ed address buffer, currently the only way to signal a problem if(!sum) { // RXed a zero-ed address buffer, currently the only way to signal a problem
errno = ENOTSOCK; // TODO: general error, needs to be more specific errno = ENOTSOCK; // TODO: general error, needs to be more specific
dwr(MSG_ERROR, "zt_getpeername(): no address info given by service.\n"); DEBUG_ERROR("no address info given by service.");
return -1; return -1;
} }
} }
else { else {
errno = ENOTSOCK; // TODO: general error, needs to be more specific errno = ENOTSOCK; // TODO: general error, needs to be more specific
dwr(MSG_ERROR, "zt_getpeername(): unable to read address info from service.\n", err); DEBUG_ERROR("unable to read address info from service. err=%d", err);
return -1; return -1;
} }
} }
@@ -775,7 +774,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, struct sockaddr *addr, socklen_t *addrlen // int fd, struct sockaddr *addr, socklen_t *addrlen
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1getpeername(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1getpeername(JNIEnv *env, jobject thisObj, jint fd, jobject ztaddr) {
struct sockaddr_in addr; struct sockaddr_in addr;
int err = zts_getpeername(fd, &addr, sizeof(struct sockaddr)); int err = zts_getpeername(fd, &addr, sizeof(struct sockaddr));
jfieldID fid; jfieldID fid;
@@ -795,7 +794,7 @@ int (*realclose)(CLOSE_SIG);
#endif #endif
{ {
get_api_netpath(); get_api_netpath();
dwr(MSG_DEBUG_EXTRA,"zt_getpeername(%d):\n", fd); DEBUG_EXTRA("fd=%d", fd);
struct getsockname_st rpc_st; struct getsockname_st rpc_st;
rpc_st.fd = fd; rpc_st.fd = fd;
memcpy(&rpc_st.addrlen, &addrlen, sizeof(socklen_t)); memcpy(&rpc_st.addrlen, &addrlen, sizeof(socklen_t));
@@ -814,13 +813,13 @@ int (*realclose)(CLOSE_SIG);
} }
if(!sum) { // RXed a zero-ed address buffer, currently the only way to signal a problem if(!sum) { // RXed a zero-ed address buffer, currently the only way to signal a problem
errno = ENOTSOCK; // TODO: general error, needs to be more specific errno = ENOTSOCK; // TODO: general error, needs to be more specific
dwr(MSG_ERROR, "zt_getpeername(): no address info given by service.\n"); DEBUG_ERROR("no address info given by service.");
return -1; return -1;
} }
} }
else { else {
errno = ENOTSOCK; // TODO: general error, needs to be more specific errno = ENOTSOCK; // TODO: general error, needs to be more specific
dwr(MSG_ERROR, "zt_getpeername(): unable to read address info from service.\n", err); DEBUG_ERROR("unable to read address info from service. err=%d", err);
return -1; return -1;
} }
} }
@@ -838,7 +837,7 @@ int (*realclose)(CLOSE_SIG);
// int fd, int cmd, int flags // int fd, int cmd, int flags
#if defined(__ANDROID__) #if defined(__ANDROID__)
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1fcntl(JNIEnv *env, jobject thisObj, jint fd, jint cmd, jint flags) { JNIEXPORT jint JNICALL Java_ZeroTier_ZTSDK_zt_1fcntl(JNIEnv *env, jobject thisObj, jint fd, jint cmd, jint flags) {
return zts_fcntl(fd,cmd,flags); return zts_fcntl(fd,cmd,flags);
} }
#endif #endif
@@ -849,7 +848,7 @@ int (*realclose)(CLOSE_SIG);
int zts_fcntl(FCNTL_SIG) int zts_fcntl(FCNTL_SIG)
#endif #endif
{ {
dwr(MSG_DEBUG_EXTRA,"zt_fcntl(%d, %d, %d)\n", fd, cmd, flags); DEBUG_EXTRA("fd=%d, cmd=%d, flags=%d", fd, cmd, flags);
return fcntl(fd,cmd,flags); return fcntl(fd,cmd,flags);
} }

View File

@@ -67,6 +67,10 @@ extern "C" void zt_stop_proxy_server(const char *nwid) {
zts_stop_proxy_server(nwid); zts_stop_proxy_server(nwid);
} }
// //
extern "C" void zt_proxy_running(const char *homepath, const char *nwid, struct sockaddr_storage *addr) {
zts_start_proxy_server(homepath, nwid, addr);
}
//
extern "C" void zt_get_proxy_server_address(const char *nwid, struct sockaddr_storage *addr) { extern "C" void zt_get_proxy_server_address(const char *nwid, struct sockaddr_storage *addr) {
zts_get_proxy_server_address(nwid, addr); zts_get_proxy_server_address(nwid, addr);
} }
@@ -84,38 +88,38 @@ extern "C" int zt_socket(SOCKET_SIG) {
return zts_socket(socket_family, socket_type, protocol); return zts_socket(socket_family, socket_type, protocol);
} }
extern "C" int zt_connect(CONNECT_SIG) { extern "C" int zt_connect(CONNECT_SIG) {
return zts_connect(__fd, __addr, __len); return zts_connect(fd, addr, addrlen);
} }
extern "C" int zt_bind(BIND_SIG){ extern "C" int zt_bind(BIND_SIG){
return zts_bind(sockfd, addr, addrlen); return zts_bind(fd, addr, addrlen);
} }
extern "C" int zt_accept(ACCEPT_SIG) { extern "C" int zt_accept(ACCEPT_SIG) {
return zts_accept(sockfd, addr, addrlen); return zts_accept(fd, addr, addrlen);
} }
extern "C" int zt_listen(LISTEN_SIG) { extern "C" int zt_listen(LISTEN_SIG) {
return zts_listen(sockfd, backlog); return zts_listen(fd, backlog);
} }
extern "C" int zt_setsockopt(SETSOCKOPT_SIG) { extern "C" int zt_setsockopt(SETSOCKOPT_SIG) {
return zts_setsockopt(socket, level, optname, optval, optlen); return zts_setsockopt(fd, level, optname, optval, optlen);
} }
extern "C" int zt_getsockopt(GETSOCKOPT_SIG) { extern "C" int zt_getsockopt(GETSOCKOPT_SIG) {
return zts_getsockopt(sockfd, level, optname, optval, optlen); return zts_getsockopt(fd, level, optname, optval, optlen);
} }
extern "C" int zt_close(CLOSE_SIG) { extern "C" int zt_close(CLOSE_SIG) {
return zts_close(fd); return zts_close(fd);
} }
extern "C" int zt_getsockname(GETSOCKNAME_SIG) { extern "C" int zt_getsockname(GETSOCKNAME_SIG) {
return zts_getsockname(sockfd, addr, addrlen); return zts_getsockname(fd, addr, addrlen);
} }
extern "C" int zt_getpeername(GETPEERNAME_SIG) { extern "C" int zt_getpeername(GETPEERNAME_SIG) {
return zts_getpeername(sockfd, addr, addrlen); return zts_getpeername(fd, addr, addrlen);
} }
extern "C" int zt_fcntl(FCNTL_SIG) { extern "C" int zt_fcntl(FCNTL_SIG) {
return zts_fcntl(fd, cmd, flags); return zts_fcntl(fd, cmd, flags);
} }
extern "C" ssize_t zt_recvfrom(RECVFROM_SIG) { extern "C" ssize_t zt_recvfrom(RECVFROM_SIG) {
return zts_recvfrom(socket, buffer, length, flags, address, address_len); return zts_recvfrom(fd, buf, len, flags, addr, addrlen);
} }
extern "C" ssize_t zt_sendto(SENDTO_SIG) { extern "C" ssize_t zt_sendto(SENDTO_SIG) {
return zts_sendto(sockfd, buf, len, flags, addr, addr_len); return zts_sendto(fd, buf, len, flags, addr, addrlen);
} }