Merge pull request #13 from despair86/master

periodic porting of new code
pull/14/head
Jeff 6 years ago committed by GitHub
commit e8daf53600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,8 +47,10 @@ else()
set(THREAD_LIB pthread)
endif()
if (NOT MSVC)
add_cflags("-march=native")
add_cxxflags("-march=native")
endif(NOT MSVC)
if(STATIC_LINK)
add_cflags("-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
@ -165,12 +167,12 @@ if(UNIX)
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
else()
message(FATAL_ERROR "Your operating system is not supported yet")
endif()

@ -1,5 +1,6 @@
#include <libntrup/ntru.h>
#include <stdbool.h>
#include <stdio.h>
#if __AVX2__
#include <cpuid.h>

@ -6,6 +6,9 @@
#define qshift 2295
#define p 761
#ifdef _MSC_VER
#define LOOPS 2*p+1
#endif
#define w 286
#define rq_encode_len 1218

@ -40,8 +40,13 @@ int r3_recip(small *r,const small *s)
int loop;
small f[p + 1];
small g[p + 1];
#ifdef _MSC_VER
small u[LOOPS + 1];
small v[LOOPS + 1];
#else
small u[loops + 1];
small v[loops + 1];
#endif
small c;
int i;
int d = p;

@ -39,8 +39,13 @@ int rq_recip3(modq *r,const small *s)
int loop;
modq f[p + 1];
modq g[p + 1];
#ifdef _MSC_VER
modq u[LOOPS + 1];
modq v[LOOPS + 1];
#else
modq u[loops + 1];
modq v[loops + 1];
#endif
modq c;
int i;
int d = p;

@ -2,6 +2,9 @@
#define LLARP_CODEL_QUEUE_HPP
#ifdef _MSC_VER
#define NOMINMAX
#ifdef min
#undef min
#endif
#endif
#include <llarp/time.h>
#include <llarp/logger.hpp>

@ -8,6 +8,26 @@
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/endian.h>
#elif defined(__sun)
#include <sys/byteorder.h>
#define htobe16(x) htons(x)
#define htole16(x) (x)
#define be16toh(x) ntohs(x)
#define le16toh(x) (x)
#define htobe32(x) htonl(x)
#define htole32(x) (x)
#define be32toh(x) ntohl(x)
#define le32toh(x) (x)
#define htobe64(x) \
(((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) \
| (((uint64_t)htonl(((uint32_t)(x)))) << 32))
#define htole64(x) (x)
#define be64toh(x) \
(((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) \
| (((uint64_t)ntohl(((uint32_t)(x)))) << 32))
#define le64toh(x) (x)
#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GLIBC__)
#include <endian.h>
#elif defined(__APPLE__) && defined(__MACH__)

@ -2,8 +2,47 @@
#define LLARP_IP_HPP
#include <llarp/buffer.h>
#include <llarp/time.h>
#ifndef _WIN32
#include <netinet/in.h>
#include <netinet/ip.h>
#else
#include <winsock2.h>
// Apparently this does not seem to be located _anywhere_ in the windows sdk???
// -despair86
typedef struct ip_hdr
{
unsigned char
ip_header_len : 4; // 4-bit header length (in 32-bit words) normally=5
// (Means 20 Bytes may be 24 also)
unsigned char ip_version : 4; // 4-bit IPv4 version
unsigned char ip_tos; // IP type of service
unsigned short ip_total_length; // Total length
unsigned short ip_id; // Unique identifier
unsigned char ip_frag_offset : 5; // Fragment offset field
unsigned char ip_more_fragment : 1;
unsigned char ip_dont_fragment : 1;
unsigned char ip_reserved_zero : 1;
unsigned char ip_frag_offset1; // fragment offset
unsigned char ip_ttl; // Time to live
unsigned char ip_protocol; // Protocol(TCP,UDP etc)
unsigned short ip_checksum; // IP checksum
unsigned int ip_srcaddr; // Source address
unsigned int ip_destaddr; // Source address
} IPV4_HDR;
#define iphdr IPV4_HDR
#define saddr ip_srcaddr;
#define daddr ip_destaddr;
#endif
#include <memory>
#if !defined(__linux__) && !defined(_WIN32)
#define iphdr ip
#define saddr ip_src.s_addr
#define daddr ip_dst.s_addr
#endif
namespace llarp
{

@ -5,6 +5,12 @@
#include "router.hpp"
#include "session.hpp"
#ifndef __linux__
#ifdef saddr
#undef saddr
#endif
#endif
#include <algorithm>
#include <fstream>

@ -37,8 +37,8 @@
#else
#include <net/if.h>
#endif
#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif
#include <stdint.h>
@ -56,7 +56,7 @@
*/
#if defined ETH_ALEN /* Linux */
#define ETHER_ADDR_LEN ETH_ALEN
#elif defined Windows
#elif defined Windows || defined __sun__
#define ETHER_ADDR_LEN 6
#endif
@ -86,7 +86,7 @@
*/
#if defined Windows
#include <in6addr.h>
#include <winsock.h>
#include <winsock2.h>
typedef HANDLE t_tun;
typedef IN_ADDR t_tun_in_addr;
typedef IN6_ADDR t_tun_in6_addr;

@ -20,7 +20,7 @@ extern "C" void
SetThreadName(DWORD dwThreadID, LPCSTR szThreadName);
#endif
#ifdef _WIN32
#if _WIN32 || __sun
#define wmin(x, y) (((x) < (y)) ? (x) : (y))
#define MIN wmin
#endif

@ -4,7 +4,8 @@
#define EV_TICK_INTERVAL 100
#ifdef __linux__
// apparently current Solaris will emulate epoll.
#if __linux__ || __sun__
#include "ev_epoll.hpp"
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
@ -18,7 +19,7 @@
void
llarp_ev_loop_alloc(struct llarp_ev_loop **ev)
{
#ifdef __linux__
#if __linux__ || __sun__
*ev = new llarp_epoll_loop;
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
@ -27,12 +28,6 @@ llarp_ev_loop_alloc(struct llarp_ev_loop **ev)
#endif
#if defined(_WIN32) || defined(_WIN64) || defined(__NT__)
*ev = new llarp_win32_loop;
#endif
// a) I assume that the libre fork of Solaris is still
// 5.10, and b) the current commercial version is 5.11, naturally.
// -despair86
#if defined(__SunOS_5_10) || defined(__SunOS_5_11)
*ev = new llarp_sun_iocp_loop;
#endif
(*ev)->init();
}
@ -116,4 +111,4 @@ bool
llarp_ev_tun_async_write(struct llarp_tun_io *tun, const void *pkt, size_t sz)
{
return static_cast< llarp::ev_io * >(tun->impl)->queue_write(pkt, sz);
}
}

@ -52,7 +52,12 @@ namespace llarp
flush_write()
{
m_writeq.Process([this](const std::unique_ptr< WriteBuffer >& buffer) {
// todo: wtf???
#ifndef _WIN32
write(fd, buffer->buf, buffer->bufsz);
#else
// writefile
#endif
});
/// reset errno
errno = 0;

@ -21,12 +21,6 @@ namespace llarp
WSAOVERLAPPED portfds[2] = {0};
size_t iosz;
// the unique completion key that helps us to
// identify the object instance for which we receive data
// Here, we'll use the address of the udp_listener instance, converted to
// its literal int/int64 representation.
ULONG_PTR listener_id = 0;
udp_listener(SOCKET fd, llarp_udp_io* u) : ev_io(fd), udp(u){};
~udp_listener()
@ -97,8 +91,6 @@ struct llarp_win32_loop : public llarp_ev_loop
{
HANDLE iocpfd;
bool _running = false;
llarp_win32_loop() : iocpfd(INVALID_HANDLE_VALUE)
{
WSADATA wsockd;
@ -127,7 +119,7 @@ struct llarp_win32_loop : public llarp_ev_loop
if(iocpfd == INVALID_HANDLE_VALUE)
return false;
_running = true;
return true;
}
@ -300,7 +292,7 @@ struct llarp_win32_loop : public llarp_ev_loop
}
bool
add_ev(llarp::ev_io* ev)
add_ev(llarp::ev_io* ev, bool write)
{
ev->listener_id = reinterpret_cast< ULONG_PTR >(ev);
if(!::CreateIoCompletionPort(reinterpret_cast< HANDLE >(ev->fd), iocpfd,
@ -331,13 +323,13 @@ struct llarp_win32_loop : public llarp_ev_loop
bool
running() const
{
return _running;
return iocpfd != INVALID_HANDLE_VALUE;
}
void
stop()
{
_running = false;
// still does nothing
}
};

@ -12,7 +12,7 @@
// win32 is the only one that doesn't use cpp17::filesystem
// because cpp17::filesystem is unimplemented for Windows
// -despair86
#if defined(__MINGW32__) || defined(_MSC_VER)
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun)
namespace fs = std::experimental::filesystem;
#else
namespace fs = std::filesystem;

@ -41,9 +41,9 @@ namespace llarp
pthread_setname_np(name);
#elif(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__)
pthread_set_name_np(pthread_self(), name);
#elif !defined(_MSC_VER) || !defined(_WIN32)
#elif(__linux__) || (__MINGW32__)
pthread_setname_np(pthread_self(), name);
#else
#elif defined(_MSC_VER)
SetThreadName(GetCurrentThreadId(), name);
#endif
}

@ -7,10 +7,12 @@
*
* -despair86 30/07/18
*/
// these need to be in a specific order
#include <assert.h>
#include <iphlpapi.h>
#include <llarp/net.h>
#include <windows.h>
#include <iphlpapi.h>
#include "win32_intrnl.h"
const char *

@ -2,8 +2,9 @@
/*
* All the user-mode scaffolding necessary to backport GetAdaptersAddresses(2))
* to the NT 5.x series. See further comments for any limitations.
*
* -despair86 30/07/18
* NOTE: this is dead code, i haven't had time to debug it yet due to illness.
* For now, downlevel platforms use GetAdaptersInfo(2) which is inet4 only.
* -despair86 20/08/18
*/
#include <assert.h>
#include <stdio.h>
@ -14,9 +15,10 @@
#undef WIN32_LEAN_AND_MEAN
#endif
#include <tdi.h>
// these need to be in a specific order
#include <windows.h>
#include <winternl.h>
#include <tdi.h>
#include "win32_intrnl.h"
const PWCHAR TcpFileName = L"\\Device\\Tcp";
@ -501,7 +503,10 @@ getInterfaceIndexTable(void)
*/
#ifdef _MSC_VER
#include <windows.h>
typedef HRESULT(FAR PASCAL *p_SetThreadDescription)(void *, const wchar_t *);
#define EXCEPTION_SET_THREAD_NAME ((DWORD)0x406D1388)
typedef struct _THREADNAME_INFO
{
DWORD dwType; /* must be 0x1000 */
@ -515,20 +520,43 @@ SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
{
THREADNAME_INFO info;
DWORD infosize;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
infosize = sizeof(info) / sizeof(DWORD);
__try
HANDLE hThread;
/* because loonix is SHIT and limits thread names to 16 bytes */
wchar_t thr_name_w[16];
p_SetThreadDescription _SetThreadDescription;
/* current win10 flights now have a new named-thread API, let's try to use
* that first! */
/* first, dlsym(2) the new call from system library */
_SetThreadDescription = (p_SetThreadDescription)GetProcAddress(
GetModuleHandle("kernel32"), "SetThreadDescription");
if(_SetThreadDescription)
{
RaiseException(EXCEPTION_SET_THREAD_NAME, 0, infosize, (DWORD *)&info);
hThread = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, dwThreadID);
MultiByteToWideChar(CP_ACP, 0, szThreadName, -1, thr_name_w, 16);
if(hThread)
_SetThreadDescription(hThread, thr_name_w);
else
goto old; /* for whatever reason, we couldn't get a handle to the thread.
Just use the old method. */
}
__except(EXCEPTION_EXECUTE_HANDLER)
else
{
old:
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
infosize = sizeof(info) / sizeof(DWORD);
__try
{
RaiseException(EXCEPTION_SET_THREAD_NAME, 0, infosize, (DWORD *)&info);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
}
#endif

@ -39,7 +39,7 @@
#include "version.h"
#if defined(CPP17) && defined(USE_CXX17_FILESYSTEM)
#if defined(__MINGW32__) || defined(_MSC_VER)
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun)
// win32 needs experimental
#include <experimental/filesystem>
#else

@ -34,49 +34,58 @@
#include "tuntap.h"
/* TODO(despair): port all this shit */
static int
tuntap_sys_create_dev(struct device *dev, int tun) {
return -1;
tuntap_sys_create_dev(struct device *dev, int tun)
{
return -1;
}
int
tuntap_sys_start(struct device *dev, int mode, int tun) {
return -1;
tuntap_sys_start(struct device *dev, int mode, int tun)
{
return -1;
}
void
tuntap_sys_destroy(struct device *dev) {
return -1;
tuntap_sys_destroy(struct device *dev)
{
return /*-1*/;
}
int
tuntap_sys_set_hwaddr(struct device *dev, struct ether_addr *eth_addr) {
return -1;
tuntap_sys_set_hwaddr(struct device *dev, struct ether_addr *eth_addr)
{
return -1;
}
int
tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t imask) {
return -1;
tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t imask)
{
return -1;
}
int
tuntap_sys_set_ipv6(struct device *dev, t_tun_in6_addr *s6, uint32_t imask) {
return -1;
tuntap_sys_set_ipv6(struct device *dev, t_tun_in6_addr *s6, uint32_t imask)
{
return -1;
}
int
tuntap_sys_set_ifname(struct device *dev, const char *ifname, size_t len) {
(void)dev;
(void)ifname;
(void)len;
return -1;
tuntap_sys_set_ifname(struct device *dev, const char *ifname, size_t len)
{
(void)dev;
(void)ifname;
(void)len;
return -1;
}
int
tuntap_sys_set_descr(struct device *dev, const char *descr, size_t len) {
(void)dev;
(void)descr;
(void)len;
return -1;
tuntap_sys_set_descr(struct device *dev, const char *descr, size_t len)
{
(void)dev;
(void)descr;
(void)len;
return -1;
}

@ -25,6 +25,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef __sun
#define BSD_COMP
#define TUNSDEBUG _IOW('t', 90, int)
#endif
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>

Loading…
Cancel
Save