Normalized indentation for entire project to TABS
This commit is contained in:
@@ -41,123 +41,123 @@
|
|||||||
|
|
||||||
// Debug output colors
|
// Debug output colors
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include "TargetConditionals.h"
|
#include "TargetConditionals.h"
|
||||||
#endif
|
#endif
|
||||||
#if defined(ZT_COLOR) && !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(__APP_FRAMEWORK__)
|
#if defined(ZT_COLOR) && !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(__APP_FRAMEWORK__)
|
||||||
#define ZT_RED "\x1B[31m"
|
#define ZT_RED "\x1B[31m"
|
||||||
#define ZT_GRN "\x1B[32m"
|
#define ZT_GRN "\x1B[32m"
|
||||||
#define ZT_YEL "\x1B[33m"
|
#define ZT_YEL "\x1B[33m"
|
||||||
#define ZT_BLU "\x1B[34m"
|
#define ZT_BLU "\x1B[34m"
|
||||||
#define ZT_MAG "\x1B[35m"
|
#define ZT_MAG "\x1B[35m"
|
||||||
#define ZT_CYN "\x1B[36m"
|
#define ZT_CYN "\x1B[36m"
|
||||||
#define ZT_WHT "\x1B[37m"
|
#define ZT_WHT "\x1B[37m"
|
||||||
#define ZT_RESET "\x1B[0m"
|
#define ZT_RESET "\x1B[0m"
|
||||||
#else
|
#else
|
||||||
#define ZT_RED
|
#define ZT_RED
|
||||||
#define ZT_GRN
|
#define ZT_GRN
|
||||||
#define ZT_YEL
|
#define ZT_YEL
|
||||||
#define ZT_BLU
|
#define ZT_BLU
|
||||||
#define ZT_MAG
|
#define ZT_MAG
|
||||||
#define ZT_CYN
|
#define ZT_CYN
|
||||||
#define ZT_WHT
|
#define ZT_WHT
|
||||||
#define ZT_RESET
|
#define ZT_RESET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ZT_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // short
|
#define ZT_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // short
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define ZT_THREAD_ID 0 // (long)getpid()
|
#define ZT_THREAD_ID 0 // (long)getpid()
|
||||||
#elif __FreeBSD__
|
#elif __FreeBSD__
|
||||||
#define ZT_THREAD_ID 0 // (long)getpid()
|
#define ZT_THREAD_ID 0 // (long)getpid()
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
#define ZT_THREAD_ID 0 // (long)syscall(SYS_thread_selfid)
|
#define ZT_THREAD_ID 0 // (long)syscall(SYS_thread_selfid)
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define ZT_THREAD_ID 0
|
#define ZT_THREAD_ID 0
|
||||||
|
|
||||||
#if defined(__JNI_LIB__)
|
#if defined(__JNI_LIB__)
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#define ZT_LOG_TAG "ZTSDK"
|
#define ZT_LOG_TAG "ZTSDK"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZT_DEBUG_LEVEL >= ZT_MSG_TEST
|
#if ZT_DEBUG_LEVEL >= ZT_MSG_TEST
|
||||||
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "TEST [%d] : %16s:%5d:%25s: " fmt \
|
#define DEBUG_TEST(fmt, args...) fprintf(stderr, ZT_CYN "TEST [%d] : %16s:%5d:%25s: " fmt \
|
||||||
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#else
|
#else
|
||||||
#define DEBUG_ERROR(fmt, args...)
|
#define DEBUG_ERROR(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZT_DEBUG_LEVEL >= ZT_MSG_ERROR
|
#if ZT_DEBUG_LEVEL >= ZT_MSG_ERROR
|
||||||
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED "ERROR[%d] : %16s:%5d:%25s: " fmt \
|
#define DEBUG_ERROR(fmt, args...) fprintf(stderr, ZT_RED "ERROR[%d] : %16s:%5d:%25s: " fmt \
|
||||||
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#else
|
#else
|
||||||
#define DEBUG_ERROR(fmt, args...)
|
#define DEBUG_ERROR(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZT_DEBUG_LEVEL >= ZT_MSG_INFO
|
#if ZT_DEBUG_LEVEL >= ZT_MSG_INFO
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"INFO : %16s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"INFO : %16s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#define DEBUG_BLANK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_BLANK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"INFO : %16s:%5d:" fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"INFO : %16s:%5d:" fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#define DEBUG_ATTN(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_ATTN(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"INFO : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"INFO : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"STACK: %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"STACK: %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#else
|
#else
|
||||||
#define DEBUG_INFO(fmt, args...) fprintf(stderr, \
|
#define DEBUG_INFO(fmt, args...) fprintf(stderr, \
|
||||||
"INFO [%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"INFO [%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, ZT_CYN \
|
#define DEBUG_ATTN(fmt, args...) fprintf(stderr, ZT_CYN \
|
||||||
"ATTN [%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"ATTN [%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#define DEBUG_STACK(fmt, args...) fprintf(stderr, ZT_YEL \
|
#define DEBUG_STACK(fmt, args...) fprintf(stderr, ZT_YEL \
|
||||||
"STACK[%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"STACK[%d] : %16s:%5d:%25s: " fmt "\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, \
|
#define DEBUG_BLANK(fmt, args...) fprintf(stderr, \
|
||||||
"INFO [%d] : %16s:%5d:" fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, ##args)
|
"INFO [%d] : %16s:%5d:" fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, ##args)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define DEBUG_INFO(fmt, args...)
|
#define DEBUG_INFO(fmt, args...)
|
||||||
#define DEBUG_BLANK(fmt, args...)
|
#define DEBUG_BLANK(fmt, args...)
|
||||||
#define DEBUG_ATTN(fmt, args...)
|
#define DEBUG_ATTN(fmt, args...)
|
||||||
#define DEBUG_STACK(fmt, args...)
|
#define DEBUG_STACK(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZT_DEBUG_LEVEL >= ZT_MSG_TRANSFER
|
#if ZT_DEBUG_LEVEL >= ZT_MSG_TRANSFER
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"TRANS : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"TRANS : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#else
|
#else
|
||||||
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "TRANS[%ld] : %16s:%5d:%25s: " fmt \
|
#define DEBUG_TRANS(fmt, args...) fprintf(stderr, ZT_GRN "TRANS[%ld] : %16s:%5d:%25s: " fmt \
|
||||||
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"\n" ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define DEBUG_TRANS(fmt, args...)
|
#define DEBUG_TRANS(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZT_DEBUG_LEVEL >= ZT_MSG_EXTRA
|
#if ZT_DEBUG_LEVEL >= ZT_MSG_EXTRA
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"EXTRA : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"EXTRA : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#else
|
#else
|
||||||
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, \
|
#define DEBUG_EXTRA(fmt, args...) fprintf(stderr, \
|
||||||
"EXTRA[%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
"EXTRA[%d] : %16s:%5d:%25s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define DEBUG_EXTRA(fmt, args...)
|
#define DEBUG_EXTRA(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ZT_DEBUG_LEVEL >= ZT_MSG_FLOW
|
#if ZT_DEBUG_LEVEL >= ZT_MSG_FLOW
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#define DEBUG_FLOW(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
#define DEBUG_FLOW(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
|
||||||
"FLOW : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
"FLOW : %16s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
|
||||||
#else
|
#else
|
||||||
#define DEBUG_FLOW(fmt, args...) fprintf(stderr, "FLOW [%ld] : %16s:%5d:%25s: " fmt "\n", \
|
#define DEBUG_FLOW(fmt, args...) fprintf(stderr, "FLOW [%ld] : %16s:%5d:%25s: " fmt "\n", \
|
||||||
ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define DEBUG_FLOW(fmt, args...)
|
#define DEBUG_FLOW(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
@@ -45,33 +45,33 @@
|
|||||||
// Normally defined in linux/if_packet.h, defined here so we can offer a linux-like
|
// Normally defined in linux/if_packet.h, defined here so we can offer a linux-like
|
||||||
// raw socket API on non-linux platforms
|
// raw socket API on non-linux platforms
|
||||||
struct sockaddr_ll {
|
struct sockaddr_ll {
|
||||||
unsigned short sll_family; /* Always AF_PACKET */
|
unsigned short sll_family; /* Always AF_PACKET */
|
||||||
unsigned short sll_protocol; /* Physical layer protocol */
|
unsigned short sll_protocol; /* Physical layer protocol */
|
||||||
int sll_ifindex; /* Interface number */
|
int sll_ifindex; /* Interface number */
|
||||||
unsigned short sll_hatype; /* ARP hardware type */
|
unsigned short sll_hatype; /* ARP hardware type */
|
||||||
unsigned char sll_pkttype; /* Packet type */
|
unsigned char sll_pkttype; /* Packet type */
|
||||||
unsigned char sll_halen; /* Length of address */
|
unsigned char sll_halen; /* Length of address */
|
||||||
unsigned char sll_addr[8]; /* Physical layer address */
|
unsigned char sll_addr[8]; /* Physical layer address */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct zts_ifreq {
|
struct zts_ifreq {
|
||||||
char ifr_name[IFNAMSIZ]; // Interface name
|
char ifr_name[IFNAMSIZ]; // Interface name
|
||||||
union {
|
union {
|
||||||
struct sockaddr ifr_addr;
|
struct sockaddr ifr_addr;
|
||||||
struct sockaddr ifr_dstaddr;
|
struct sockaddr ifr_dstaddr;
|
||||||
struct sockaddr ifr_broadaddr;
|
struct sockaddr ifr_broadaddr;
|
||||||
struct sockaddr ifr_netmask;
|
struct sockaddr ifr_netmask;
|
||||||
struct sockaddr ifr_hwaddr;
|
struct sockaddr ifr_hwaddr;
|
||||||
short ifr_flags;
|
short ifr_flags;
|
||||||
int ifr_ifindex;
|
int ifr_ifindex;
|
||||||
int ifr_metric;
|
int ifr_metric;
|
||||||
int ifr_mtu;
|
int ifr_mtu;
|
||||||
struct ifmap ifr_map;
|
struct ifmap ifr_map;
|
||||||
char ifr_slave[IFNAMSIZ];
|
char ifr_slave[IFNAMSIZ];
|
||||||
char ifr_newname[IFNAMSIZ];
|
char ifr_newname[IFNAMSIZ];
|
||||||
char *ifr_data;
|
char *ifr_data;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -467,14 +467,14 @@ int zts_shutdown(ZT_SHUTDOWN_SIG);
|
|||||||
|
|
||||||
namespace ZeroTier
|
namespace ZeroTier
|
||||||
{
|
{
|
||||||
class picoTCP;
|
class picoTCP;
|
||||||
extern ZeroTier::picoTCP *picostack;
|
extern ZeroTier::picoTCP *picostack;
|
||||||
|
|
||||||
class lwIP;
|
class lwIP;
|
||||||
extern ZeroTier::lwIP *lwipstack;
|
extern ZeroTier::lwIP *lwipstack;
|
||||||
|
|
||||||
class SocketTap;
|
class SocketTap;
|
||||||
struct InetAddress;
|
struct InetAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -32,158 +32,158 @@
|
|||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
template<typename T> class RingBuffer {
|
template<typename T> class RingBuffer {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T * buf;
|
T * buf;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t begin;
|
size_t begin;
|
||||||
size_t end;
|
size_t end;
|
||||||
bool wrap;
|
bool wrap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* create a RingBuffer with space for up to size elements.
|
* create a RingBuffer with space for up to size elements.
|
||||||
*/
|
*/
|
||||||
explicit RingBuffer(size_t size)
|
explicit RingBuffer(size_t size)
|
||||||
: size(size),
|
: size(size),
|
||||||
begin(0),
|
begin(0),
|
||||||
end(0),
|
end(0),
|
||||||
wrap(false)
|
wrap(false)
|
||||||
{
|
{
|
||||||
buf = new T[size];
|
buf = new T[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
RingBuffer(const RingBuffer<T> & ring)
|
RingBuffer(const RingBuffer<T> & ring)
|
||||||
{
|
{
|
||||||
this(ring.size);
|
this(ring.size);
|
||||||
begin = ring.begin;
|
begin = ring.begin;
|
||||||
end = ring.end;
|
end = ring.end;
|
||||||
memcpy(buf, ring.buf, sizeof(T) * size);
|
memcpy(buf, ring.buf, sizeof(T) * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RingBuffer()
|
~RingBuffer()
|
||||||
{
|
{
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a reference to the underlying buffer
|
// get a reference to the underlying buffer
|
||||||
T* get_buf()
|
T* get_buf()
|
||||||
{
|
{
|
||||||
return buf + begin;
|
return buf + begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust buffer index pointer as if we copied data in
|
// adjust buffer index pointer as if we copied data in
|
||||||
size_t produce(size_t n)
|
size_t produce(size_t n)
|
||||||
{
|
{
|
||||||
n = std::min(n, getFree());
|
n = std::min(n, getFree());
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t first_chunk = std::min(n, size - end);
|
const size_t first_chunk = std::min(n, size - end);
|
||||||
end = (end + first_chunk) % size;
|
end = (end + first_chunk) % size;
|
||||||
|
|
||||||
if (first_chunk < n) {
|
if (first_chunk < n) {
|
||||||
const size_t second_chunk = n - first_chunk;
|
const size_t second_chunk = n - first_chunk;
|
||||||
end = (end + second_chunk) % size;
|
end = (end + second_chunk) % size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin == end) {
|
if (begin == end) {
|
||||||
wrap = true;
|
wrap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust buffer index pointer as if we copied data out
|
// adjust buffer index pointer as if we copied data out
|
||||||
size_t consume(size_t n)
|
size_t consume(size_t n)
|
||||||
{
|
{
|
||||||
n = std::min(n, count());
|
n = std::min(n, count());
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wrap) {
|
if (wrap) {
|
||||||
wrap = false;
|
wrap = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t first_chunk = std::min(n, size - begin);
|
const size_t first_chunk = std::min(n, size - begin);
|
||||||
begin = (begin + first_chunk) % size;
|
begin = (begin + first_chunk) % size;
|
||||||
|
|
||||||
if (first_chunk < n) {
|
if (first_chunk < n) {
|
||||||
const size_t second_chunk = n - first_chunk;
|
const size_t second_chunk = n - first_chunk;
|
||||||
begin = (begin + second_chunk) % size;
|
begin = (begin + second_chunk) % size;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t write(const T * data, size_t n)
|
size_t write(const T * data, size_t n)
|
||||||
{
|
{
|
||||||
n = std::min(n, getFree());
|
n = std::min(n, getFree());
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t first_chunk = std::min(n, size - end);
|
const size_t first_chunk = std::min(n, size - end);
|
||||||
memcpy(buf + end, data, first_chunk * sizeof(T));
|
memcpy(buf + end, data, first_chunk * sizeof(T));
|
||||||
end = (end + first_chunk) % size;
|
end = (end + first_chunk) % size;
|
||||||
|
|
||||||
if (first_chunk < n) {
|
if (first_chunk < n) {
|
||||||
const size_t second_chunk = n - first_chunk;
|
const size_t second_chunk = n - first_chunk;
|
||||||
memcpy(buf + end, data + first_chunk, second_chunk * sizeof(T));
|
memcpy(buf + end, data + first_chunk, second_chunk * sizeof(T));
|
||||||
end = (end + second_chunk) % size;
|
end = (end + second_chunk) % size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin == end) {
|
if (begin == end) {
|
||||||
wrap = true;
|
wrap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t read(T * dest, size_t n)
|
size_t read(T * dest, size_t n)
|
||||||
{
|
{
|
||||||
n = std::min(n, count());
|
n = std::min(n, count());
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wrap) {
|
if (wrap) {
|
||||||
wrap = false;
|
wrap = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t first_chunk = std::min(n, size - begin);
|
const size_t first_chunk = std::min(n, size - begin);
|
||||||
memcpy(dest, buf + begin, first_chunk * sizeof(T));
|
memcpy(dest, buf + begin, first_chunk * sizeof(T));
|
||||||
begin = (begin + first_chunk) % size;
|
begin = (begin + first_chunk) % size;
|
||||||
|
|
||||||
if (first_chunk < n) {
|
if (first_chunk < n) {
|
||||||
const size_t second_chunk = n - first_chunk;
|
const size_t second_chunk = n - first_chunk;
|
||||||
memcpy(dest + first_chunk, buf + begin, second_chunk * sizeof(T));
|
memcpy(dest + first_chunk, buf + begin, second_chunk * sizeof(T));
|
||||||
begin = (begin + second_chunk) % size;
|
begin = (begin + second_chunk) % size;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t count() {
|
size_t count() {
|
||||||
if (end == begin) {
|
if (end == begin) {
|
||||||
return wrap ? size : 0;
|
return wrap ? size : 0;
|
||||||
}
|
}
|
||||||
else if (end > begin) {
|
else if (end > begin) {
|
||||||
return end - begin;
|
return end - begin;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return size + end - begin;
|
return size + end - begin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getFree() {
|
size_t getFree() {
|
||||||
return size - count();
|
return size - count();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // ZT_RINGBUFFER_HPP
|
#endif // ZT_RINGBUFFER_HPP
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace ZeroTier {
|
|||||||
void (*handler)(void *,void*,uint64_t,const MAC &,const MAC &,
|
void (*handler)(void *,void*,uint64_t,const MAC &,const MAC &,
|
||||||
unsigned int,unsigned int,const void *,unsigned int),
|
unsigned int,unsigned int,const void *,unsigned int),
|
||||||
void *arg) :
|
void *arg) :
|
||||||
_handler(handler),
|
_handler(handler),
|
||||||
_homePath(homePath),
|
_homePath(homePath),
|
||||||
_arg(arg),
|
_arg(arg),
|
||||||
_enabled(true),
|
_enabled(true),
|
||||||
@@ -185,12 +185,12 @@ namespace ZeroTier {
|
|||||||
const void *data,unsigned int len)
|
const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
#if defined(STACK_PICO)
|
#if defined(STACK_PICO)
|
||||||
if(picostack)
|
if(picostack)
|
||||||
picostack->pico_rx(this,from,to,etherType,data,len);
|
picostack->pico_rx(this,from,to,etherType,data,len);
|
||||||
#endif
|
#endif
|
||||||
#if defined(STACK_LWIP)
|
#if defined(STACK_LWIP)
|
||||||
if(lwipstack)
|
if(lwipstack)
|
||||||
lwipstack->lwip_rx(this,from,to,etherType,data,len);
|
lwipstack->lwip_rx(this,from,to,etherType,data,len);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,11 +264,11 @@ namespace ZeroTier {
|
|||||||
Connection *conn = (Connection*)*uptr;
|
Connection *conn = (Connection*)*uptr;
|
||||||
if(!conn)
|
if(!conn)
|
||||||
return;
|
return;
|
||||||
if(len){
|
if(len){
|
||||||
|
|
||||||
Write(conn, data, len);
|
Write(conn, data, len);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketTap::phyOnUnixWritable(PhySocket *sock,void **uptr,bool stack_invoked)
|
void SocketTap::phyOnUnixWritable(PhySocket *sock,void **uptr,bool stack_invoked)
|
||||||
@@ -337,13 +337,13 @@ namespace ZeroTier {
|
|||||||
|
|
||||||
int SocketTap::Write(Connection *conn, void *data, ssize_t len) {
|
int SocketTap::Write(Connection *conn, void *data, ssize_t len) {
|
||||||
if(conn->socket_type == SOCK_RAW) { // we don't want to use a stack, just VL2
|
if(conn->socket_type == SOCK_RAW) { // we don't want to use a stack, just VL2
|
||||||
struct ether_header *eh = (struct ether_header *) data;
|
struct ether_header *eh = (struct ether_header *) data;
|
||||||
MAC src_mac;
|
MAC src_mac;
|
||||||
MAC dest_mac;
|
MAC dest_mac;
|
||||||
src_mac.setTo(eh->ether_shost, 6);
|
src_mac.setTo(eh->ether_shost, 6);
|
||||||
dest_mac.setTo(eh->ether_dhost, 6);
|
dest_mac.setTo(eh->ether_dhost, 6);
|
||||||
_handler(_arg,NULL,_nwid,src_mac,dest_mac, Utils::ntoh((uint16_t)eh->ether_type),0, ((char*)data) + sizeof(struct ether_header),len - sizeof(struct ether_header));
|
_handler(_arg,NULL,_nwid,src_mac,dest_mac, Utils::ntoh((uint16_t)eh->ether_type),0, ((char*)data) + sizeof(struct ether_header),len - sizeof(struct ether_header));
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(STACK_PICO)
|
#if defined(STACK_PICO)
|
||||||
|
|||||||
@@ -137,22 +137,22 @@ namespace ZeroTier {
|
|||||||
/*
|
/*
|
||||||
* For moving data onto the ZeroTier virtual wire
|
* For moving data onto the ZeroTier virtual wire
|
||||||
*/
|
*/
|
||||||
void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,
|
void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,
|
||||||
const void *,unsigned int);
|
const void *,unsigned int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Signals us to close the TcpConnection associated with this PhySocket
|
* Signals us to close the TcpConnection associated with this PhySocket
|
||||||
*/
|
*/
|
||||||
void phyOnUnixClose(PhySocket *sock,void **uptr);
|
void phyOnUnixClose(PhySocket *sock,void **uptr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notifies us that there is data to be read from an application's socket
|
* Notifies us that there is data to be read from an application's socket
|
||||||
*/
|
*/
|
||||||
void phyOnUnixData(PhySocket *sock,void **uptr,void *data,ssize_t len);
|
void phyOnUnixData(PhySocket *sock,void **uptr,void *data,ssize_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notifies us that we can write to an application's socket
|
* Notifies us that we can write to an application's socket
|
||||||
*/
|
*/
|
||||||
void phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked);
|
void phyOnUnixWritable(PhySocket *sock,void **uptr,bool lwip_invoked);
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
@@ -173,14 +173,14 @@ namespace ZeroTier {
|
|||||||
/* Guarded RX Frame Buffer for picoTCP */
|
/* Guarded RX Frame Buffer for picoTCP */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
unsigned char pico_frame_rxbuf[MAX_PICO_FRAME_RX_BUF_SZ];
|
unsigned char pico_frame_rxbuf[MAX_PICO_FRAME_RX_BUF_SZ];
|
||||||
int pico_frame_rxbuf_tot;
|
int pico_frame_rxbuf_tot;
|
||||||
Mutex _pico_frame_rxbuf_m;
|
Mutex _pico_frame_rxbuf_m;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STACK_LWIP)
|
#if defined(STACK_LWIP)
|
||||||
netif lwipdev;
|
netif lwipdev;
|
||||||
netif lwipdev6;
|
netif lwipdev6;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int devno;
|
static int devno;
|
||||||
@@ -190,13 +190,13 @@ namespace ZeroTier {
|
|||||||
std::vector<InetAddress> _ips;
|
std::vector<InetAddress> _ips;
|
||||||
|
|
||||||
std::string _homePath;
|
std::string _homePath;
|
||||||
void *_arg;
|
void *_arg;
|
||||||
volatile bool _enabled;
|
volatile bool _enabled;
|
||||||
volatile bool _run;
|
volatile bool _run;
|
||||||
MAC _mac;
|
MAC _mac;
|
||||||
unsigned int _mtu;
|
unsigned int _mtu;
|
||||||
uint64_t _nwid;
|
uint64_t _nwid;
|
||||||
PhySocket *_unixListenSocket;
|
PhySocket *_unixListenSocket;
|
||||||
Phy<SocketTap *> _phy;
|
Phy<SocketTap *> _phy;
|
||||||
|
|
||||||
std::vector<Connection*> _Connections;
|
std::vector<Connection*> _Connections;
|
||||||
@@ -245,14 +245,14 @@ namespace ZeroTier {
|
|||||||
int Read(PhySocket *sock,void **uptr,bool stack_invoked);
|
int Read(PhySocket *sock,void **uptr,bool stack_invoked);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Move data from application's "socket" into network stack
|
* Move data from application's "socket" into network stack
|
||||||
*/
|
*/
|
||||||
int Write(Connection *conn, void *data, ssize_t len);
|
int Write(Connection *conn, void *data, ssize_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Closes a Connection
|
* Closes a Connection
|
||||||
*/
|
*/
|
||||||
int Close(Connection *conn);
|
int Close(Connection *conn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disposes of previously-closed Connections
|
* Disposes of previously-closed Connections
|
||||||
|
|||||||
@@ -38,14 +38,14 @@
|
|||||||
#define ip4_addr4b(ipaddr) (((u8_t*)(ipaddr))[3])
|
#define ip4_addr4b(ipaddr) (((u8_t*)(ipaddr))[3])
|
||||||
inline ip_addr_t convert_ip(struct sockaddr_in * addr)
|
inline ip_addr_t convert_ip(struct sockaddr_in * addr)
|
||||||
{
|
{
|
||||||
ip_addr_t conn_addr;
|
ip_addr_t conn_addr;
|
||||||
struct sockaddr_in *ipv4 = addr;
|
struct sockaddr_in *ipv4 = addr;
|
||||||
short a = ip4_addr1b(&(ipv4->sin_addr));
|
short a = ip4_addr1b(&(ipv4->sin_addr));
|
||||||
short b = ip4_addr2b(&(ipv4->sin_addr));
|
short b = ip4_addr2b(&(ipv4->sin_addr));
|
||||||
short c = ip4_addr3b(&(ipv4->sin_addr));
|
short c = ip4_addr3b(&(ipv4->sin_addr));
|
||||||
short d = ip4_addr4b(&(ipv4->sin_addr));
|
short d = ip4_addr4b(&(ipv4->sin_addr));
|
||||||
IP4_ADDR(&conn_addr, a,b,c,d);
|
IP4_ADDR(&conn_addr, a,b,c,d);
|
||||||
return conn_addr;
|
return conn_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // STACK_LWIP && LIBZT_IPV4
|
#endif // STACK_LWIP && LIBZT_IPV4
|
||||||
|
|||||||
2762
src/libzt.cpp
2762
src/libzt.cpp
File diff suppressed because it is too large
Load Diff
606
src/lwIP.cpp
606
src/lwIP.cpp
@@ -42,352 +42,352 @@ err_t tapif_init(struct netif *netif)
|
|||||||
|
|
||||||
err_t low_level_output(struct netif *netif, struct pbuf *p)
|
err_t low_level_output(struct netif *netif, struct pbuf *p)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
struct pbuf *q;
|
struct pbuf *q;
|
||||||
char buf[ZT_MAX_MTU+32];
|
char buf[ZT_MAX_MTU+32];
|
||||||
char *bufptr;
|
char *bufptr;
|
||||||
int totalLength = 0;
|
int totalLength = 0;
|
||||||
|
|
||||||
ZeroTier::SocketTap *tap = (ZeroTier::SocketTap*)netif->state;
|
ZeroTier::SocketTap *tap = (ZeroTier::SocketTap*)netif->state;
|
||||||
bufptr = buf;
|
bufptr = buf;
|
||||||
// Copy data from each pbuf, one at a time
|
// Copy data from each pbuf, one at a time
|
||||||
for(q = p; q != NULL; q = q->next) {
|
for(q = p; q != NULL; q = q->next) {
|
||||||
memcpy(bufptr, q->payload, q->len);
|
memcpy(bufptr, q->payload, q->len);
|
||||||
bufptr += q->len;
|
bufptr += q->len;
|
||||||
totalLength += q->len;
|
totalLength += q->len;
|
||||||
}
|
}
|
||||||
// Split ethernet header and feed into handler
|
// Split ethernet header and feed into handler
|
||||||
struct eth_hdr *ethhdr;
|
struct eth_hdr *ethhdr;
|
||||||
ethhdr = (struct eth_hdr *)buf;
|
ethhdr = (struct eth_hdr *)buf;
|
||||||
|
|
||||||
ZeroTier::MAC src_mac;
|
ZeroTier::MAC src_mac;
|
||||||
ZeroTier::MAC dest_mac;
|
ZeroTier::MAC dest_mac;
|
||||||
src_mac.setTo(ethhdr->src.addr, 6);
|
src_mac.setTo(ethhdr->src.addr, 6);
|
||||||
dest_mac.setTo(ethhdr->dest.addr, 6);
|
dest_mac.setTo(ethhdr->dest.addr, 6);
|
||||||
|
|
||||||
tap->_handler(tap->_arg,NULL,tap->_nwid,src_mac,dest_mac,
|
tap->_handler(tap->_arg,NULL,tap->_nwid,src_mac,dest_mac,
|
||||||
ZeroTier::Utils::ntoh((uint16_t)ethhdr->type),0,buf + sizeof(struct eth_hdr),totalLength - sizeof(struct eth_hdr));
|
ZeroTier::Utils::ntoh((uint16_t)ethhdr->type),0,buf + sizeof(struct eth_hdr),totalLength - sizeof(struct eth_hdr));
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ZeroTier
|
namespace ZeroTier
|
||||||
{
|
{
|
||||||
void lwIP::lwip_init_interface(SocketTap *tap, const InetAddress &ip)
|
void lwIP::lwip_init_interface(SocketTap *tap, const InetAddress &ip)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
Mutex::Lock _l(tap->_ips_m);
|
Mutex::Lock _l(tap->_ips_m);
|
||||||
|
|
||||||
if (std::find(tap->_ips.begin(),tap->_ips.end(),ip) == tap->_ips.end()) {
|
if (std::find(tap->_ips.begin(),tap->_ips.end(),ip) == tap->_ips.end()) {
|
||||||
tap->_ips.push_back(ip);
|
tap->_ips.push_back(ip);
|
||||||
std::sort(tap->_ips.begin(),tap->_ips.end());
|
std::sort(tap->_ips.begin(),tap->_ips.end());
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
if (ip.isV4()) {
|
if (ip.isV4()) {
|
||||||
// Set IP
|
// Set IP
|
||||||
static ip_addr_t ipaddr, netmask, gw;
|
static ip_addr_t ipaddr, netmask, gw;
|
||||||
IP4_ADDR(&gw,127,0,0,1);
|
IP4_ADDR(&gw,127,0,0,1);
|
||||||
ipaddr.addr = *((u32_t *)ip.rawIpData());
|
ipaddr.addr = *((u32_t *)ip.rawIpData());
|
||||||
netmask.addr = *((u32_t *)ip.netmask().rawIpData());
|
netmask.addr = *((u32_t *)ip.netmask().rawIpData());
|
||||||
netif_add(&(tap->lwipdev),&ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
|
netif_add(&(tap->lwipdev),&ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
|
||||||
tap->lwipdev.state = tap;
|
tap->lwipdev.state = tap;
|
||||||
tap->lwipdev.output = etharp_output;
|
tap->lwipdev.output = etharp_output;
|
||||||
tap->_mac.copyTo(tap->lwipdev.hwaddr, 6);
|
tap->_mac.copyTo(tap->lwipdev.hwaddr, 6);
|
||||||
tap->lwipdev.mtu = tap->_mtu;
|
tap->lwipdev.mtu = tap->_mtu;
|
||||||
tap->lwipdev.name[0] = 'l';
|
tap->lwipdev.name[0] = 'l';
|
||||||
tap->lwipdev.name[1] = '4';
|
tap->lwipdev.name[1] = '4';
|
||||||
tap->lwipdev.linkoutput = low_level_output;
|
tap->lwipdev.linkoutput = low_level_output;
|
||||||
tap->lwipdev.hwaddr_len = 6;
|
tap->lwipdev.hwaddr_len = 6;
|
||||||
tap->lwipdev.flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP | NETIF_FLAG_LINK_UP | NETIF_FLAG_UP;
|
tap->lwipdev.flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP | NETIF_FLAG_LINK_UP | NETIF_FLAG_UP;
|
||||||
netif_set_default(&(tap->lwipdev));
|
netif_set_default(&(tap->lwipdev));
|
||||||
netif_set_up(&(tap->lwipdev));
|
netif_set_up(&(tap->lwipdev));
|
||||||
DEBUG_INFO("addr=%s, netmask=%s", ip.toString().c_str(), ip.netmask().toString().c_str());
|
DEBUG_INFO("addr=%s, netmask=%s", ip.toString().c_str(), ip.netmask().toString().c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
if(ip.isV6()) {
|
if(ip.isV6()) {
|
||||||
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
DEBUG_INFO("local_addr=%s", ip.toString().c_str());
|
||||||
static ip6_addr_t addr6;
|
static ip6_addr_t addr6;
|
||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
memcpy(in6.sin6_addr.s6_addr,ip.rawIpData(),16);
|
memcpy(in6.sin6_addr.s6_addr,ip.rawIpData(),16);
|
||||||
in6_to_ip6((ip6_addr *)&addr6, &in6);
|
in6_to_ip6((ip6_addr *)&addr6, &in6);
|
||||||
tap->lwipdev6.mtu = tap->_mtu;
|
tap->lwipdev6.mtu = tap->_mtu;
|
||||||
tap->lwipdev6.name[0] = 'l';
|
tap->lwipdev6.name[0] = 'l';
|
||||||
tap->lwipdev6.name[1] = '6';
|
tap->lwipdev6.name[1] = '6';
|
||||||
tap->lwipdev6.hwaddr_len = 6;
|
tap->lwipdev6.hwaddr_len = 6;
|
||||||
tap->lwipdev6.linkoutput = low_level_output;
|
tap->lwipdev6.linkoutput = low_level_output;
|
||||||
tap->lwipdev6.ip6_autoconfig_enabled = 1;
|
tap->lwipdev6.ip6_autoconfig_enabled = 1;
|
||||||
tap->_mac.copyTo(tap->lwipdev6.hwaddr, tap->lwipdev6.hwaddr_len);
|
tap->_mac.copyTo(tap->lwipdev6.hwaddr, tap->lwipdev6.hwaddr_len);
|
||||||
netif_create_ip6_linklocal_address(&(tap->lwipdev6), 1);
|
netif_create_ip6_linklocal_address(&(tap->lwipdev6), 1);
|
||||||
netif_add(&(tap->lwipdev6), NULL, tapif_init, ethernet_input);
|
netif_add(&(tap->lwipdev6), NULL, tapif_init, ethernet_input);
|
||||||
netif_set_default(&(tap->lwipdev6));
|
netif_set_default(&(tap->lwipdev6));
|
||||||
netif_set_up(&(tap->lwipdev6));
|
netif_set_up(&(tap->lwipdev6));
|
||||||
netif_ip6_addr_set_state(&(tap->lwipdev6), 1, IP6_ADDR_TENTATIVE);
|
netif_ip6_addr_set_state(&(tap->lwipdev6), 1, IP6_ADDR_TENTATIVE);
|
||||||
ip6_addr_copy(ip_2_ip6(tap->lwipdev6.ip6_addr[1]), addr6);
|
ip6_addr_copy(ip_2_ip6(tap->lwipdev6.ip6_addr[1]), addr6);
|
||||||
tap->lwipdev6.output_ip6 = ethip6_output;
|
tap->lwipdev6.output_ip6 = ethip6_output;
|
||||||
tap->lwipdev6.state = tap;
|
tap->lwipdev6.state = tap;
|
||||||
tap->lwipdev6.flags = NETIF_FLAG_LINK_UP | NETIF_FLAG_UP;
|
tap->lwipdev6.flags = NETIF_FLAG_LINK_UP | NETIF_FLAG_UP;
|
||||||
DEBUG_INFO("addr=%s, netmask=%s", ip.toString().c_str(), ip.netmask().toString().c_str());
|
DEBUG_INFO("addr=%s, netmask=%s", ip.toString().c_str(), ip.netmask().toString().c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lwIP::lwip_loop(SocketTap *tap)
|
void lwIP::lwip_loop(SocketTap *tap)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
uint64_t prev_tcp_time = 0, prev_status_time = 0, prev_discovery_time = 0;
|
uint64_t prev_tcp_time = 0, prev_status_time = 0, prev_discovery_time = 0;
|
||||||
while(tap->_run)
|
while(tap->_run)
|
||||||
{
|
{
|
||||||
uint64_t now = OSUtils::now();
|
uint64_t now = OSUtils::now();
|
||||||
uint64_t since_tcp = now - prev_tcp_time;
|
uint64_t since_tcp = now - prev_tcp_time;
|
||||||
uint64_t since_discovery = now - prev_discovery_time;
|
uint64_t since_discovery = now - prev_discovery_time;
|
||||||
uint64_t since_status = now - prev_status_time;
|
uint64_t since_status = now - prev_status_time;
|
||||||
uint64_t tcp_remaining = LWIP_TCP_TIMER_INTERVAL;
|
uint64_t tcp_remaining = LWIP_TCP_TIMER_INTERVAL;
|
||||||
uint64_t discovery_remaining = 5000;
|
uint64_t discovery_remaining = 5000;
|
||||||
|
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
#define DISCOVERY_INTERVAL 1000
|
#define DISCOVERY_INTERVAL 1000
|
||||||
#elif defined(LIBZT_IPV4)
|
#elif defined(LIBZT_IPV4)
|
||||||
#define DISCOVERY_INTERVAL ARP_TMR_INTERVAL
|
#define DISCOVERY_INTERVAL ARP_TMR_INTERVAL
|
||||||
#endif
|
#endif
|
||||||
// Main TCP/ETHARP timer section
|
// Main TCP/ETHARP timer section
|
||||||
if (since_tcp >= LWIP_TCP_TIMER_INTERVAL) {
|
if (since_tcp >= LWIP_TCP_TIMER_INTERVAL) {
|
||||||
prev_tcp_time = now;
|
prev_tcp_time = now;
|
||||||
tcp_tmr();
|
tcp_tmr();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tcp_remaining = LWIP_TCP_TIMER_INTERVAL - since_tcp;
|
tcp_remaining = LWIP_TCP_TIMER_INTERVAL - since_tcp;
|
||||||
}
|
}
|
||||||
if (since_discovery >= DISCOVERY_INTERVAL) {
|
if (since_discovery >= DISCOVERY_INTERVAL) {
|
||||||
prev_discovery_time = now;
|
prev_discovery_time = now;
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
etharp_tmr();
|
etharp_tmr();
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
nd6_tmr();
|
nd6_tmr();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
discovery_remaining = DISCOVERY_INTERVAL - since_discovery;
|
discovery_remaining = DISCOVERY_INTERVAL - since_discovery;
|
||||||
}
|
}
|
||||||
tap->_phy.poll((unsigned long)std::min(tcp_remaining,discovery_remaining));
|
tap->_phy.poll((unsigned long)std::min(tcp_remaining,discovery_remaining));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lwIP::lwip_rx(SocketTap *tap, const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
void lwIP::lwip_rx(SocketTap *tap, const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
struct pbuf *p,*q;
|
struct pbuf *p,*q;
|
||||||
if (!tap->_enabled)
|
if (!tap->_enabled)
|
||||||
return;
|
return;
|
||||||
struct eth_hdr ethhdr;
|
struct eth_hdr ethhdr;
|
||||||
from.copyTo(ethhdr.src.addr, 6);
|
from.copyTo(ethhdr.src.addr, 6);
|
||||||
to.copyTo(ethhdr.dest.addr, 6);
|
to.copyTo(ethhdr.dest.addr, 6);
|
||||||
ethhdr.type = ZeroTier::Utils::hton((uint16_t)etherType);
|
ethhdr.type = ZeroTier::Utils::hton((uint16_t)etherType);
|
||||||
|
|
||||||
p = pbuf_alloc(PBUF_RAW, len+sizeof(struct eth_hdr), PBUF_POOL);
|
p = pbuf_alloc(PBUF_RAW, len+sizeof(struct eth_hdr), PBUF_POOL);
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
const char *dataptr = reinterpret_cast<const char *>(data);
|
const char *dataptr = reinterpret_cast<const char *>(data);
|
||||||
// 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)) {
|
||||||
DEBUG_ERROR("dropped packet: first pbuf smaller than ethernet header");
|
DEBUG_ERROR("dropped packet: first pbuf smaller than ethernet header");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(q->payload,ðhdr,sizeof(ethhdr));
|
memcpy(q->payload,ðhdr,sizeof(ethhdr));
|
||||||
memcpy((char*)q->payload + sizeof(ethhdr),dataptr,q->len - sizeof(ethhdr));
|
memcpy((char*)q->payload + sizeof(ethhdr),dataptr,q->len - sizeof(ethhdr));
|
||||||
dataptr += q->len - sizeof(ethhdr);
|
dataptr += q->len - sizeof(ethhdr);
|
||||||
|
|
||||||
// Remaining pbufs (if any) get rest of data
|
// Remaining pbufs (if any) get rest of data
|
||||||
while ((q = q->next)) {
|
while ((q = q->next)) {
|
||||||
memcpy(q->payload,dataptr,q->len);
|
memcpy(q->payload,dataptr,q->len);
|
||||||
dataptr += q->len;
|
dataptr += q->len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG_ERROR("dropped packet: no pbufs available");
|
DEBUG_ERROR("dropped packet: no pbufs available");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
if(tap->lwipdev6.input(p, &(tap->lwipdev6)) != ERR_OK) {
|
if(tap->lwipdev6.input(p, &(tap->lwipdev6)) != ERR_OK) {
|
||||||
DEBUG_ERROR("error while feeding frame into stack lwipdev6");
|
DEBUG_ERROR("error while feeding frame into stack lwipdev6");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
if(tap->lwipdev.input(p, &(tap->lwipdev)) != ERR_OK) {
|
if(tap->lwipdev.input(p, &(tap->lwipdev)) != ERR_OK) {
|
||||||
DEBUG_ERROR("error while feeding frame into stack lwipdev");
|
DEBUG_ERROR("error while feeding frame into stack lwipdev");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Socket(void **pcb, int socket_family, int socket_type, int protocol)
|
int lwIP::lwip_Socket(void **pcb, int socket_family, int socket_type, int protocol)
|
||||||
{
|
{
|
||||||
// TODO: check lwIP timers, and max sockets
|
// TODO: check lwIP timers, and max sockets
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
if(socket_type == SOCK_STREAM) {
|
if(socket_type == SOCK_STREAM) {
|
||||||
struct tcp_pcb *new_tcp_PCB = tcp_new();
|
struct tcp_pcb *new_tcp_PCB = tcp_new();
|
||||||
*pcb = new_tcp_PCB;
|
*pcb = new_tcp_PCB;
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
if(socket_type == SOCK_DGRAM) {
|
if(socket_type == SOCK_DGRAM) {
|
||||||
struct udp_pcb *new_udp_PCB = udp_new();
|
struct udp_pcb *new_udp_PCB = udp_new();
|
||||||
*pcb = new_udp_PCB;
|
*pcb = new_udp_PCB;
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
if(socket_type == SOCK_RAW) {
|
if(socket_type == SOCK_RAW) {
|
||||||
DEBUG_ERROR("SOCK_RAW, not currently supported.");
|
DEBUG_ERROR("SOCK_RAW, not currently supported.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen)
|
int lwIP::lwip_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Bind(SocketTap *tap, Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen)
|
int lwIP::lwip_Bind(SocketTap *tap, Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
ip_addr_t ba;
|
ip_addr_t ba;
|
||||||
char addrstr[INET6_ADDRSTRLEN];
|
char addrstr[INET6_ADDRSTRLEN];
|
||||||
int port = 0, err = 0;
|
int port = 0, err = 0;
|
||||||
|
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
DEBUG_ERROR("A");
|
DEBUG_ERROR("A");
|
||||||
struct sockaddr_in *in4;
|
struct sockaddr_in *in4;
|
||||||
if(addr->sa_family == AF_INET) {
|
if(addr->sa_family == AF_INET) {
|
||||||
DEBUG_ERROR("A");
|
DEBUG_ERROR("A");
|
||||||
in4 = (struct sockaddr_in *)addr;
|
in4 = (struct sockaddr_in *)addr;
|
||||||
DEBUG_ERROR("A");
|
DEBUG_ERROR("A");
|
||||||
inet_ntop(AF_INET, &(in4->sin_addr), addrstr, INET_ADDRSTRLEN);
|
inet_ntop(AF_INET, &(in4->sin_addr), addrstr, INET_ADDRSTRLEN);
|
||||||
DEBUG_ERROR("A");
|
DEBUG_ERROR("A");
|
||||||
DEBUG_INFO("%s:%d", addrstr, lwip_ntohs(in4->sin_port));
|
DEBUG_INFO("%s:%d", addrstr, lwip_ntohs(in4->sin_port));
|
||||||
}
|
}
|
||||||
ba = convert_ip(in4);
|
ba = convert_ip(in4);
|
||||||
port = lwip_ntohs(in4->sin_port);
|
port = lwip_ntohs(in4->sin_port);
|
||||||
DEBUG_INFO("port=%d", port);
|
DEBUG_INFO("port=%d", port);
|
||||||
DEBUG_INFO("port=%d", lwip_ntohs(port));
|
DEBUG_INFO("port=%d", lwip_ntohs(port));
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&addr;
|
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&addr;
|
||||||
in6_to_ip6((ip6_addr *)&ba, in6);
|
in6_to_ip6((ip6_addr *)&ba, in6);
|
||||||
if(addr->sa_family == AF_INET6) {
|
if(addr->sa_family == AF_INET6) {
|
||||||
struct sockaddr_in6 *connaddr6 = (struct sockaddr_in6 *)addr;
|
struct sockaddr_in6 *connaddr6 = (struct sockaddr_in6 *)addr;
|
||||||
inet_ntop(AF_INET6, &(connaddr6->sin6_addr), addrstr, INET6_ADDRSTRLEN);
|
inet_ntop(AF_INET6, &(connaddr6->sin6_addr), addrstr, INET6_ADDRSTRLEN);
|
||||||
DEBUG_INFO("%s:%d", addrstr, lwip_ntohs(connaddr6->sin6_port));
|
DEBUG_INFO("%s:%d", addrstr, lwip_ntohs(connaddr6->sin6_port));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(conn->socket_type == SOCK_DGRAM) {
|
if(conn->socket_type == SOCK_DGRAM) {
|
||||||
err = udp_bind((struct udp_pcb*)conn->pcb, (const ip_addr_t *)&ba, port);
|
err = udp_bind((struct udp_pcb*)conn->pcb, (const ip_addr_t *)&ba, port);
|
||||||
if(err == ERR_USE) {
|
if(err == ERR_USE) {
|
||||||
err = -1;
|
err = -1;
|
||||||
errno = EADDRINUSE; // port in use
|
errno = EADDRINUSE; // port in use
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// set the recv callback
|
// set the recv callback
|
||||||
udp_recv((struct udp_pcb*)conn->pcb, nc_udp_recved, new ConnectionPair(tap, conn));
|
udp_recv((struct udp_pcb*)conn->pcb, nc_udp_recved, new ConnectionPair(tap, conn));
|
||||||
err = ERR_OK;
|
err = ERR_OK;
|
||||||
errno = ERR_OK; // success
|
errno = ERR_OK; // success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (conn->socket_type == SOCK_STREAM) {
|
else if (conn->socket_type == SOCK_STREAM) {
|
||||||
err = tcp_bind((struct tcp_pcb*)conn->pcb, (const ip_addr_t *)&ba, port);
|
err = tcp_bind((struct tcp_pcb*)conn->pcb, (const ip_addr_t *)&ba, port);
|
||||||
if(err != ERR_OK) {
|
if(err != ERR_OK) {
|
||||||
DEBUG_ERROR("err=%d", err);
|
DEBUG_ERROR("err=%d", err);
|
||||||
if(err == ERR_USE){
|
if(err == ERR_USE){
|
||||||
err = -1;
|
err = -1;
|
||||||
errno = EADDRINUSE;
|
errno = EADDRINUSE;
|
||||||
}
|
}
|
||||||
if(err == ERR_MEM){
|
if(err == ERR_MEM){
|
||||||
err = -1;
|
err = -1;
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
}
|
}
|
||||||
if(err == ERR_BUF){
|
if(err == ERR_BUF){
|
||||||
err = -1;
|
err = -1;
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
err = ERR_OK;
|
err = ERR_OK;
|
||||||
errno = ERR_OK; // success
|
errno = ERR_OK; // success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Listen(SocketTap *tap, PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc)
|
int lwIP::lwip_Listen(SocketTap *tap, PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Read(SocketTap *tap, PhySocket *sock, void **uptr, bool lwip_invoked)
|
int lwIP::lwip_Read(SocketTap *tap, PhySocket *sock, void **uptr, bool lwip_invoked)
|
||||||
{
|
{
|
||||||
DEBUG_EXTRA();
|
DEBUG_EXTRA();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Write(SocketTap *tap, Connection *conn)
|
int lwIP::lwip_Write(SocketTap *tap, Connection *conn)
|
||||||
{
|
{
|
||||||
DEBUG_EXTRA("conn=%p", (void*)&conn);
|
DEBUG_EXTRA("conn=%p", (void*)&conn);
|
||||||
// to be implemented
|
// to be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwIP::lwip_Close(SocketTap *tap, PhySocket *sock, Connection *conn)
|
int lwIP::lwip_Close(SocketTap *tap, PhySocket *sock, Connection *conn)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* Callbacks from lwIP stack */
|
/* Callbacks from lwIP stack */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
err_t lwIP::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err)
|
err_t lwIP::nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t lwIP::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
|
err_t lwIP::nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lwIP::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, const ip_addr_t * addr, u16_t port)
|
void lwIP::nc_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, const ip_addr_t * addr, u16_t port)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t lwIP::nc_sent(void* arg, struct tcp_pcb *PCB, u16_t len)
|
err_t lwIP::nc_sent(void* arg, struct tcp_pcb *PCB, u16_t len)
|
||||||
{
|
{
|
||||||
DEBUG_EXTRA("pcb=%p", (void*)&PCB);
|
DEBUG_EXTRA("pcb=%p", (void*)&PCB);
|
||||||
// to be implemented
|
// to be implemented
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t lwIP::nc_connected(void *arg, struct tcp_pcb *PCB, err_t err)
|
err_t lwIP::nc_connected(void *arg, struct tcp_pcb *PCB, err_t err)
|
||||||
{
|
{
|
||||||
DEBUG_ATTN("pcb=%p", (void*)&PCB);
|
DEBUG_ATTN("pcb=%p", (void*)&PCB);
|
||||||
// to be implemented
|
// to be implemented
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t lwIP::nc_poll(void* arg, struct tcp_pcb *PCB)
|
err_t lwIP::nc_poll(void* arg, struct tcp_pcb *PCB)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lwIP::nc_err(void *arg, err_t err)
|
void lwIP::nc_err(void *arg, err_t err)
|
||||||
{
|
{
|
||||||
DEBUG_INFO();
|
DEBUG_INFO();
|
||||||
// to be implemented
|
// to be implemented
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
92
src/lwIP.hpp
92
src/lwIP.hpp
@@ -51,16 +51,16 @@ struct tcp_pcb;
|
|||||||
struct netif;
|
struct netif;
|
||||||
|
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
#define LWIP_NETIF_ADD_SIG struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input
|
#define LWIP_NETIF_ADD_SIG struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input
|
||||||
#define LWIP_ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr
|
#define LWIP_ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
#include "lwip/ip6_addr.h"
|
#include "lwip/ip6_addr.h"
|
||||||
#define LWIP_NETIF_ADD_SIG struct netif *netif, void *state, netif_init_fn init, netif_input_fn input
|
#define LWIP_NETIF_ADD_SIG struct netif *netif, void *state, netif_init_fn init, netif_input_fn input
|
||||||
#define LWIP_ETHIP6_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr
|
#define LWIP_ETHIP6_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr
|
||||||
#define LWIP_ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr
|
#define LWIP_ETHARP_OUTPUT_SIG struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr
|
||||||
#define LWIP_NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state
|
#define LWIP_NETIF_IP6_ADDR_SET_STATE_SIG struct netif* netif, s8_t addr_idx, u8_t state
|
||||||
#define LWIP_NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG struct netif *netif, u8_t from_mac_48bit
|
#define LWIP_NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG struct netif *netif, u8_t from_mac_48bit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LWIP_PBUF_FREE_SIG struct pbuf *p
|
#define LWIP_PBUF_FREE_SIG struct pbuf *p
|
||||||
@@ -105,13 +105,13 @@ struct netif;
|
|||||||
|
|
||||||
|
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
extern "C" err_t etharp_output(LWIP_ETHARP_OUTPUT_SIG);
|
extern "C" err_t etharp_output(LWIP_ETHARP_OUTPUT_SIG);
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
extern "C" void nd6_tmr(void);
|
extern "C" void nd6_tmr(void);
|
||||||
extern "C" void netif_ip6_addr_set_state(LWIP_NETIF_IP6_ADDR_SET_STATE_SIG);
|
extern "C" void netif_ip6_addr_set_state(LWIP_NETIF_IP6_ADDR_SET_STATE_SIG);
|
||||||
extern "C" void netif_create_ip6_linklocal_address(LWIP_NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG);
|
extern "C" void netif_create_ip6_linklocal_address(LWIP_NETIF_CREATE_IP6_LINKLOCAL_ADDRESS_SIG);
|
||||||
extern "C" err_t _ethip6_output(LWIP_ETHIP6_OUTPUT_SIG);
|
extern "C" err_t _ethip6_output(LWIP_ETHIP6_OUTPUT_SIG);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern "C" void lwip_init();
|
extern "C" void lwip_init();
|
||||||
@@ -161,45 +161,45 @@ extern "C" err_t ip_input(LWIP_IP_INPUT_SIG);
|
|||||||
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
class SocketTap;
|
class SocketTap;
|
||||||
struct Connection;
|
struct Connection;
|
||||||
|
|
||||||
class lwIP
|
class lwIP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up an interface in the network stack for the SocketTap
|
* Set up an interface in the network stack for the SocketTap
|
||||||
*/
|
*/
|
||||||
void lwip_init_interface(SocketTap *tap, const InetAddress &ip);
|
void lwip_init_interface(SocketTap *tap, const InetAddress &ip);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main stack loop
|
* Main stack loop
|
||||||
*/
|
*/
|
||||||
void lwip_loop(SocketTap *tap);
|
void lwip_loop(SocketTap *tap);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Packets from the ZeroTier virtual wire enter the stack here
|
* Packets from the ZeroTier virtual wire enter the stack here
|
||||||
*/
|
*/
|
||||||
void lwip_rx(SocketTap *tap, const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
void lwip_rx(SocketTap *tap, const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
int lwip_Socket(void **pcb, int socket_family, int socket_type, int protocol);
|
int lwip_Socket(void **pcb, int socket_family, int socket_type, int protocol);
|
||||||
int lwip_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
int lwip_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
int lwip_Bind(SocketTap *tap, Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
int lwip_Bind(SocketTap *tap, Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
int lwip_Listen(SocketTap *tap, PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc);
|
int lwip_Listen(SocketTap *tap, PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc);
|
||||||
int lwip_Read(SocketTap *tap, PhySocket *sock, void **uptr, bool lwip_invoked);
|
int lwip_Read(SocketTap *tap, PhySocket *sock, void **uptr, bool lwip_invoked);
|
||||||
int lwip_Write(SocketTap *tap, Connection *conn);
|
int lwip_Write(SocketTap *tap, Connection *conn);
|
||||||
int lwip_Close(SocketTap *tap, PhySocket *sock, Connection *conn);
|
int lwip_Close(SocketTap *tap, PhySocket *sock, Connection *conn);
|
||||||
|
|
||||||
static err_t nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err);
|
static err_t nc_recved(void *arg, struct tcp_pcb *PCB, struct pbuf *p, err_t err);
|
||||||
static err_t nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err);
|
static err_t nc_accept(void *arg, struct tcp_pcb *newPCB, err_t err);
|
||||||
static void nc_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, const ip_addr_t * addr, u16_t port);
|
static void nc_udp_recved(void * arg, struct udp_pcb * upcb, struct pbuf * p, const ip_addr_t * addr, u16_t port);
|
||||||
static void nc_err(void *arg, err_t err);
|
static void nc_err(void *arg, err_t err);
|
||||||
static err_t nc_poll(void* arg, struct tcp_pcb *PCB);
|
static err_t nc_poll(void* arg, struct tcp_pcb *PCB);
|
||||||
static err_t nc_sent(void *arg, struct tcp_pcb *PCB, u16_t len);
|
static err_t nc_sent(void *arg, struct tcp_pcb *PCB, u16_t len);
|
||||||
static err_t nc_connected(void *arg, struct tcp_pcb *PCB, err_t err);
|
static err_t nc_connected(void *arg, struct tcp_pcb *PCB, err_t err);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
888
src/picoTCP.cpp
888
src/picoTCP.cpp
File diff suppressed because it is too large
Load Diff
@@ -73,12 +73,12 @@ namespace ZeroTier
|
|||||||
/*
|
/*
|
||||||
* Send raw frames from the stack to the ZeroTier virtual wire
|
* Send raw frames from the stack to the ZeroTier virtual wire
|
||||||
*/
|
*/
|
||||||
int pico_eth_send(struct pico_device *dev, void *buf, int len);
|
int pico_eth_send(struct pico_device *dev, void *buf, int len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read raw frames from RX frame buffer into the stack
|
* Read raw frames from RX frame buffer into the stack
|
||||||
*/
|
*/
|
||||||
int pico_eth_poll(struct pico_device *dev, int loop_score);
|
int pico_eth_poll(struct pico_device *dev, int loop_score);
|
||||||
|
|
||||||
class SocketTap;
|
class SocketTap;
|
||||||
struct Connection;
|
struct Connection;
|
||||||
@@ -88,38 +88,38 @@ namespace ZeroTier
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up an interface in the network stack for the SocketTap
|
* Set up an interface in the network stack for the SocketTap
|
||||||
*/
|
*/
|
||||||
bool pico_init_interface(ZeroTier::SocketTap *tap, const ZeroTier::InetAddress &ip);
|
bool pico_init_interface(ZeroTier::SocketTap *tap, const ZeroTier::InetAddress &ip);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main stack loop
|
* Main stack loop
|
||||||
*/
|
*/
|
||||||
void pico_loop(SocketTap *tap);
|
void pico_loop(SocketTap *tap);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read bytes from the stack to the RX buffer (prepare to be read by app)
|
* Read bytes from the stack to the RX buffer (prepare to be read by app)
|
||||||
*/
|
*/
|
||||||
static void pico_cb_tcp_read(SocketTap *tap, struct pico_socket *s);
|
static void pico_cb_tcp_read(SocketTap *tap, struct pico_socket *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read bytes from the stack to the RX buffer (prepare to be read by app)
|
* Read bytes from the stack to the RX buffer (prepare to be read by app)
|
||||||
*/
|
*/
|
||||||
static void pico_cb_udp_read(SocketTap *tap, struct pico_socket *s);
|
static void pico_cb_udp_read(SocketTap *tap, struct pico_socket *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
|
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
|
||||||
*/
|
*/
|
||||||
static void pico_cb_tcp_write(SocketTap *tap, struct pico_socket *s);
|
static void pico_cb_tcp_write(SocketTap *tap, struct pico_socket *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
|
* Write bytes from TX buffer to stack (prepare to be sent to ZT virtual wire)
|
||||||
*/
|
*/
|
||||||
static void pico_cb_socket_activity(uint16_t ev, struct pico_socket *s);
|
static void pico_cb_socket_activity(uint16_t ev, struct pico_socket *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Packets from the ZeroTier virtual wire enter the stack here
|
* Packets from the ZeroTier virtual wire enter the stack here
|
||||||
*/
|
*/
|
||||||
void pico_rx(SocketTap *tap, const ZeroTier::MAC &from,const ZeroTier::MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
void pico_rx(SocketTap *tap, const ZeroTier::MAC &from,const ZeroTier::MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -130,39 +130,39 @@ namespace ZeroTier
|
|||||||
/*
|
/*
|
||||||
* Connect to remote host via userspace network stack interface - Called from SocketTap
|
* Connect to remote host via userspace network stack interface - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
int pico_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
int pico_Connect(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind to a userspace network stack interface - Called from SocketTap
|
* Bind to a userspace network stack interface - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
int pico_Bind(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
int pico_Bind(Connection *conn, int fd, const struct sockaddr *addr, socklen_t addrlen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Listen for incoming connections - Called from SocketTap
|
* Listen for incoming connections - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
int pico_Listen(Connection *conn, int fd, int backlog);
|
int pico_Listen(Connection *conn, int fd, int backlog);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Accept an incoming connection - Called from SocketTap
|
* Accept an incoming connection - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
Connection* pico_Accept(Connection *conn);
|
Connection* pico_Accept(Connection *conn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read from RX buffer to application - Called from SocketTap
|
* Read from RX buffer to application - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
int pico_Read(SocketTap *tap, ZeroTier::PhySocket *sock,Connection *conn,bool stack_invoked);
|
int pico_Read(SocketTap *tap, ZeroTier::PhySocket *sock,Connection *conn,bool stack_invoked);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write to userspace network stack - Called from SocketTap
|
* Write to userspace network stack - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
int pico_Write(Connection *conn, void *data, ssize_t len);
|
int pico_Write(Connection *conn, void *data, ssize_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close a Connection - Called from SocketTap
|
* Close a Connection - Called from SocketTap
|
||||||
*/
|
*/
|
||||||
int pico_Close(Connection *conn);
|
int pico_Close(Connection *conn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converts picoTCP error codes to pretty string
|
* Converts picoTCP error codes to pretty string
|
||||||
*/
|
*/
|
||||||
static char *beautify_pico_error(int err);
|
static char *beautify_pico_error(int err);
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ void loadTestConfigFile(std::string filepath)
|
|||||||
prefix = value;
|
prefix = value;
|
||||||
}
|
}
|
||||||
if(key[0] != '#' && key[0] != ';') {
|
if(key[0] != '#' && key[0] != ';') {
|
||||||
testConf[prefix + "." + key] = value; // format: alice.ipv4 172.30.30.1
|
testConf[prefix + "." + key] = value; // format: alice.ipv4 172.30.30.1
|
||||||
//fprintf(stderr, "%s.%s = %s\n", prefix.c_str(), key.c_str(), testConf[prefix + "." + key].c_str());
|
//fprintf(stderr, "%s.%s = %s\n", prefix.c_str(), key.c_str(), testConf[prefix + "." + key].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
testFile.close();
|
testFile.close();
|
||||||
@@ -225,18 +225,18 @@ void start_echo_mode(std::string ipstr, int listen_port)
|
|||||||
|
|
||||||
int main(int argc , char *argv[])
|
int main(int argc , char *argv[])
|
||||||
{
|
{
|
||||||
if(argc < 5) {
|
if(argc < 5) {
|
||||||
fprintf(stderr, "usage: echotest <selftest.conf> <alice|bob|ted|carol> to <bob|alice|ted|carol>\n");
|
fprintf(stderr, "usage: echotest <selftest.conf> <alice|bob|ted|carol> to <bob|alice|ted|carol>\n");
|
||||||
fprintf(stderr, "e.g. : echotest test/selftest.conf bob to alice\n");
|
fprintf(stderr, "e.g. : echotest test/selftest.conf bob to alice\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string from = argv[2];
|
std::string from = argv[2];
|
||||||
std::string to = argv[4];
|
std::string to = argv[4];
|
||||||
std::string me = from;
|
std::string me = from;
|
||||||
|
|
||||||
int start_port = 0;
|
int start_port = 0;
|
||||||
int port_offset = 0;
|
int port_offset = 0;
|
||||||
int echo_listen_port = 0;
|
int echo_listen_port = 0;
|
||||||
|
|
||||||
std::string local_echo_ipv4;
|
std::string local_echo_ipv4;
|
||||||
|
|||||||
@@ -27,22 +27,22 @@
|
|||||||
|
|
||||||
unsigned short csum(unsigned short *buf, int nwords)
|
unsigned short csum(unsigned short *buf, int nwords)
|
||||||
{
|
{
|
||||||
unsigned long sum;
|
unsigned long sum;
|
||||||
for(sum=0; nwords>0; nwords--)
|
for(sum=0; nwords>0; nwords--)
|
||||||
sum += *buf++;
|
sum += *buf++;
|
||||||
sum = (sum >> 16) + (sum &0xffff);
|
sum = (sum >> 16) + (sum &0xffff);
|
||||||
sum += (sum >> 16);
|
sum += (sum >> 16);
|
||||||
return (unsigned short)(~sum);
|
return (unsigned short)(~sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc , char *argv[])
|
int main(int argc , char *argv[])
|
||||||
{
|
{
|
||||||
if(argc < 3) {
|
if(argc < 3) {
|
||||||
fprintf(stderr, "usage: layer2 <zt_home_dir> <nwid>\n");
|
fprintf(stderr, "usage: layer2 <zt_home_dir> <nwid>\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize library
|
// initialize library
|
||||||
printf("Starting libzt...\n");
|
printf("Starting libzt...\n");
|
||||||
zts_simple_start(argv[1], argv[2]);
|
zts_simple_start(argv[1], argv[2]);
|
||||||
char device_id[11];
|
char device_id[11];
|
||||||
@@ -181,7 +181,7 @@ int main(int argc , char *argv[])
|
|||||||
usleep(10000);
|
usleep(10000);
|
||||||
// Send packet
|
// Send packet
|
||||||
if (zts_sendto(fd, sendbuf, tx_len, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)) < 0)
|
if (zts_sendto(fd, sendbuf, tx_len, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)) < 0)
|
||||||
fprintf(stderr, "Send failed\n");
|
fprintf(stderr, "Send failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// dismantle all zt virtual taps (SocketTaps)
|
// dismantle all zt virtual taps (SocketTaps)
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ std::map<std::string, std::string> testConf;
|
|||||||
[OK] comprehensive server ipv6 - test all ipv4/6 server simple/sustained modes
|
[OK] comprehensive server ipv6 - test all ipv4/6 server simple/sustained modes
|
||||||
|
|
||||||
Performance:
|
Performance:
|
||||||
(See libzt.h, compile libzt with appropriate ZT_TCP_TX_BUF_SZ, ZT_TCP_RX_BUF_SZ, ZT_UDP_TX_BUF_SZ, and ZT_UDO_RX_BUF_SZ for your test)
|
(See libzt.h, compile libzt with appropriate ZT_TCP_TX_BUF_SZ, ZT_TCP_RX_BUF_SZ, ZT_UDP_TX_BUF_SZ, and ZT_UDO_RX_BUF_SZ for your test)
|
||||||
|
|
||||||
[OK] Throughput - Test maximum RX/TX speeds
|
[OK] Throughput - Test maximum RX/TX speeds
|
||||||
[ ] Memory Usage - Test memory consumption profile
|
[ ] Memory Usage - Test memory consumption profile
|
||||||
@@ -164,9 +164,9 @@ void loadTestConfigFile(std::string filepath)
|
|||||||
prefix = value;
|
prefix = value;
|
||||||
}
|
}
|
||||||
if(key[0] != '#' && key[0] != ';') {
|
if(key[0] != '#' && key[0] != ';') {
|
||||||
testConf[prefix + "." + key] = value;
|
testConf[prefix + "." + key] = value;
|
||||||
fprintf(stderr, "%s.%s = %s\n", prefix.c_str(), key.c_str(), testConf[prefix + "." + key].c_str());
|
fprintf(stderr, "%s.%s = %s\n", prefix.c_str(), key.c_str(), testConf[prefix + "." + key].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
testFile.close();
|
testFile.close();
|
||||||
@@ -870,7 +870,7 @@ int slam_api_test()
|
|||||||
int results[SLAM_NUMBER*SLAM_REPEAT];
|
int results[SLAM_NUMBER*SLAM_REPEAT];
|
||||||
|
|
||||||
struct hostent *server;
|
struct hostent *server;
|
||||||
struct sockaddr_in6 addr6;
|
struct sockaddr_in6 addr6;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
// int start_stack_timer_count = pico_ntimers(); // number of picoTCP timers allocated
|
// int start_stack_timer_count = pico_ntimers(); // number of picoTCP timers allocated
|
||||||
@@ -946,17 +946,17 @@ int slam_api_test()
|
|||||||
|
|
||||||
int port;
|
int port;
|
||||||
while(!(std::find(used_ports.begin(),used_ports.end(),port) == used_ports.end())) {
|
while(!(std::find(used_ports.begin(),used_ports.end(),port) == used_ports.end())) {
|
||||||
port = MIN_PORT + (rand() % (int)(MAX_PORT - MIN_PORT + 1));
|
port = MIN_PORT + (rand() % (int)(MAX_PORT - MIN_PORT + 1));
|
||||||
}
|
}
|
||||||
used_ports.push_back(port);
|
used_ports.push_back(port);
|
||||||
std::cout << "port = " << port << std::endl;
|
std::cout << "port = " << port << std::endl;
|
||||||
|
|
||||||
if(false) {
|
if(false) {
|
||||||
server = gethostbyname2("::",AF_INET6);
|
server = gethostbyname2("::",AF_INET6);
|
||||||
memset((char *) &addr6, 0, sizeof(addr6));
|
memset((char *) &addr6, 0, sizeof(addr6));
|
||||||
addr6.sin6_flowinfo = 0;
|
addr6.sin6_flowinfo = 0;
|
||||||
addr6.sin6_family = AF_INET6;
|
addr6.sin6_family = AF_INET6;
|
||||||
addr6.sin6_port = htons(port);
|
addr6.sin6_port = htons(port);
|
||||||
addr6.sin6_addr = in6addr_any;
|
addr6.sin6_addr = in6addr_any;
|
||||||
err = zts_bind(sock, (struct sockaddr *)&addr6, (socklen_t)(sizeof addr6));
|
err = zts_bind(sock, (struct sockaddr *)&addr6, (socklen_t)(sizeof addr6));
|
||||||
}
|
}
|
||||||
@@ -1020,10 +1020,10 @@ int slam_api_test()
|
|||||||
// connect()
|
// connect()
|
||||||
if(false) {
|
if(false) {
|
||||||
server = gethostbyname2("::",AF_INET6);
|
server = gethostbyname2("::",AF_INET6);
|
||||||
memset((char *) &addr6, 0, sizeof(addr6));
|
memset((char *) &addr6, 0, sizeof(addr6));
|
||||||
addr6.sin6_flowinfo = 0;
|
addr6.sin6_flowinfo = 0;
|
||||||
addr6.sin6_family = AF_INET6;
|
addr6.sin6_family = AF_INET6;
|
||||||
addr6.sin6_port = htons(port);
|
addr6.sin6_port = htons(port);
|
||||||
addr6.sin6_addr = in6addr_any;
|
addr6.sin6_addr = in6addr_any;
|
||||||
err = zts_connect(sock, (struct sockaddr *)&addr6, (socklen_t)(sizeof addr6));
|
err = zts_connect(sock, (struct sockaddr *)&addr6, (socklen_t)(sizeof addr6));
|
||||||
}
|
}
|
||||||
@@ -1086,7 +1086,7 @@ int random_api_test()
|
|||||||
int calls_made = 0;
|
int calls_made = 0;
|
||||||
|
|
||||||
// how many calls we'll make
|
// how many calls we'll make
|
||||||
int num_of_api_calls = 10;
|
int num_of_api_calls = 10;
|
||||||
|
|
||||||
|
|
||||||
zts_socket()
|
zts_socket()
|
||||||
@@ -1241,24 +1241,24 @@ void test_bad_args()
|
|||||||
|
|
||||||
int main(int argc , char *argv[])
|
int main(int argc , char *argv[])
|
||||||
{
|
{
|
||||||
if(argc < 5) {
|
if(argc < 5) {
|
||||||
fprintf(stderr, "usage: selftest <selftest.conf> <alice|bob|ted|carol> to <bob|alice|ted|carol>\n");
|
fprintf(stderr, "usage: selftest <selftest.conf> <alice|bob|ted|carol> to <bob|alice|ted|carol>\n");
|
||||||
fprintf(stderr, "e.g. : selftest test/selftest.conf alice to bob\n");
|
fprintf(stderr, "e.g. : selftest test/selftest.conf alice to bob\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string from = argv[2];
|
std::string from = argv[2];
|
||||||
std::string to = argv[4];
|
std::string to = argv[4];
|
||||||
std::string me = from;
|
std::string me = from;
|
||||||
|
|
||||||
std::vector<std::string> results;
|
std::vector<std::string> results;
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
int operation = 0;
|
int operation = 0;
|
||||||
int start_port = 0;
|
int start_port = 0;
|
||||||
int port_offset = 0;
|
int port_offset = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int delay = 0;
|
int delay = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -191,9 +191,9 @@ namespace ZeroTier {
|
|||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
memset(&in6,0,sizeof(in6));
|
memset(&in6,0,sizeof(in6));
|
||||||
in6.sin6_family = AF_INET;
|
in6.sin6_family = AF_INET;
|
||||||
struct hostent *server;
|
struct hostent *server;
|
||||||
server = gethostbyname2((char*)host.c_str(),AF_INET6);
|
server = gethostbyname2((char*)host.c_str(),AF_INET6);
|
||||||
memmove((char *) &in6.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length);
|
memmove((char *) &in6.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length);
|
||||||
in6.sin6_port = Utils::hton(dest_port);
|
in6.sin6_port = Utils::hton(dest_port);
|
||||||
conn->destination_sock = _phy.tcpConnect((const struct sockaddr *)&in6, connected, this);
|
conn->destination_sock = _phy.tcpConnect((const struct sockaddr *)&in6, connected, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace ZeroTier {
|
|||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
|
||||||
TcpConnection *getConnection(PhySocket *sock);
|
TcpConnection *getConnection(PhySocket *sock);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
volatile bool _enabled;
|
volatile bool _enabled;
|
||||||
|
|||||||
Reference in New Issue
Block a user