mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-23 01:49:53 +03:00
commit
dcd9b94381
@ -105,6 +105,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <Mayaqua/Mayaqua.h>
|
#include <Mayaqua/Mayaqua.h>
|
||||||
#include <Cedar/Cedar.h>
|
#include <Cedar/Cedar.h>
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
#include <net/ethernet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef OS_UNIX
|
#ifdef OS_UNIX
|
||||||
|
|
||||||
@ -524,10 +527,11 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)
|
|||||||
|
|
||||||
if (mac_address != NULL)
|
if (mac_address != NULL)
|
||||||
{
|
{
|
||||||
uint8_t macos_mac_address[19];
|
|
||||||
Zero(&ifr, sizeof(ifr));
|
Zero(&ifr, sizeof(ifr));
|
||||||
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), macos_eth_name);
|
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), macos_eth_name);
|
||||||
Copy(&ifr.ifr_addr.sa_data, mac_address, 6);
|
ifr.ifr_addr.sa_len = ETHER_ADDR_LEN;
|
||||||
|
ifr.ifr_addr.sa_family = AF_LINK;
|
||||||
|
Copy(&ifr.ifr_addr.sa_data, mac_address, ETHER_ADDR_LEN);
|
||||||
ioctl(s, SIOCSIFLLADDR, &ifr);
|
ioctl(s, SIOCSIFLLADDR, &ifr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ UINT g_zero = 0;
|
|||||||
// Get the real-time system timer
|
// Get the real-time system timer
|
||||||
UINT TickRealtime()
|
UINT TickRealtime()
|
||||||
{
|
{
|
||||||
#if defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES)
|
#if defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES) || defined(UNIX_MACOS)
|
||||||
return Tick() + 1;
|
return Tick() + 1;
|
||||||
#else
|
#else
|
||||||
return TickRealtimeManual() + 1;
|
return TickRealtimeManual() + 1;
|
||||||
|
@ -129,6 +129,9 @@
|
|||||||
#include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <Mayaqua/Mayaqua.h>
|
#include <Mayaqua/Mayaqua.h>
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
#include <sys/event.h>
|
||||||
|
#endif // UNIX_MACOS
|
||||||
|
|
||||||
#ifdef OS_WIN32
|
#ifdef OS_WIN32
|
||||||
NETWORK_WIN32_FUNCTIONS *w32net;
|
NETWORK_WIN32_FUNCTIONS *w32net;
|
||||||
@ -141,7 +144,7 @@ struct ROUTE_CHANGE_DATA
|
|||||||
#endif // OS_WIN32
|
#endif // OS_WIN32
|
||||||
|
|
||||||
// Whether the blocking occurs in SSL
|
// Whether the blocking occurs in SSL
|
||||||
#if defined(UNIX_BSD)
|
#if defined(UNIX_BSD) || defined(UNIX_MACOS)
|
||||||
#define FIX_SSL_BLOCKING
|
#define FIX_SSL_BLOCKING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -8791,7 +8794,12 @@ void UnixSetSockEvent(SOCK_EVENT *event)
|
|||||||
// Execute 'select' for the socket
|
// Execute 'select' for the socket
|
||||||
void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, UINT timeout)
|
void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, UINT timeout)
|
||||||
{
|
{
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
int kq;
|
||||||
|
struct kevent *kevents;
|
||||||
|
#else // UNIX_MACOS
|
||||||
struct pollfd *p;
|
struct pollfd *p;
|
||||||
|
#endif // UNIX_MACOS
|
||||||
UINT num;
|
UINT num;
|
||||||
UINT i;
|
UINT i;
|
||||||
UINT n;
|
UINT n;
|
||||||
@ -8828,7 +8836,12 @@ void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, U
|
|||||||
}
|
}
|
||||||
|
|
||||||
num = num_read_total + num_write_total;
|
num = num_read_total + num_write_total;
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
kq = kqueue();
|
||||||
|
kevents = ZeroMallocFast(sizeof(struct kevent) * (num + num_write_total));
|
||||||
|
#else // UNIX_MACOS
|
||||||
p = ZeroMallocFast(sizeof(struct pollfd) * num);
|
p = ZeroMallocFast(sizeof(struct pollfd) * num);
|
||||||
|
#endif // UNIX_MACOS
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
@ -8836,9 +8849,13 @@ void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, U
|
|||||||
{
|
{
|
||||||
if (reads[i] != INVALID_SOCKET)
|
if (reads[i] != INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
EV_SET(&kevents[n++], reads[i], EVFILT_READ, EV_ADD, 0, 0, NULL);
|
||||||
|
#else // UNIX_MACOS
|
||||||
struct pollfd *pfd = &p[n++];
|
struct pollfd *pfd = &p[n++];
|
||||||
pfd->fd = reads[i];
|
pfd->fd = reads[i];
|
||||||
pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP;
|
pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP;
|
||||||
|
#endif // UNIX_MACOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8846,22 +8863,44 @@ void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, U
|
|||||||
{
|
{
|
||||||
if (writes[i] != INVALID_SOCKET)
|
if (writes[i] != INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
EV_SET(&kevents[n++], reads[i], EVFILT_READ, EV_ADD, 0, 0, NULL);
|
||||||
|
EV_SET(&kevents[n++], reads[i], EVFILT_WRITE, EV_ADD, 0, 0, NULL);
|
||||||
|
#else // UNIX_MACOS
|
||||||
struct pollfd *pfd = &p[n++];
|
struct pollfd *pfd = &p[n++];
|
||||||
pfd->fd = writes[i];
|
pfd->fd = writes[i];
|
||||||
pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLOUT;
|
pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLOUT;
|
||||||
|
#endif // UNIX_MACOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num != 0)
|
if (num != 0)
|
||||||
{
|
{
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
struct timespec kevent_timeout, *p_kevent_timeout;
|
||||||
|
if (timeout == INFINITE) {
|
||||||
|
p_kevent_timeout = NULL;
|
||||||
|
} else {
|
||||||
|
kevent_timeout.tv_sec = timeout / 1000;
|
||||||
|
kevent_timeout.tv_nsec = (timeout % 1000) * 1000000l;
|
||||||
|
p_kevent_timeout = &kevent_timeout;
|
||||||
|
}
|
||||||
|
kevent(kq, kevents, n, kevents, n, p_kevent_timeout);
|
||||||
|
#else // UNIX_MACOS
|
||||||
poll(p, num, timeout == INFINITE ? -1 : (int)timeout);
|
poll(p, num, timeout == INFINITE ? -1 : (int)timeout);
|
||||||
|
#endif // UNIX_MACOS
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SleepThread(timeout);
|
SleepThread(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
Free(kevents);
|
||||||
|
close(kq);
|
||||||
|
#else // UNIX_MACOS
|
||||||
Free(p);
|
Free(p);
|
||||||
|
#endif // UNIX_MACOS
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean-up of the socket event
|
// Clean-up of the socket event
|
||||||
@ -13198,9 +13237,9 @@ SOCK *Accept(SOCK *sock)
|
|||||||
size = sizeof(addr);
|
size = sizeof(addr);
|
||||||
|
|
||||||
#ifdef OS_UNIX
|
#ifdef OS_UNIX
|
||||||
#ifdef UNIX_LINUX
|
#if defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||||
UnixIgnoreSignalForThread(SIGUSR1);
|
UnixIgnoreSignalForThread(SIGUSR1);
|
||||||
#endif // UNIX_LINUX
|
#endif // defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||||
sock->CallingThread = pthread_self();
|
sock->CallingThread = pthread_self();
|
||||||
#endif // OS_UNIX
|
#endif // OS_UNIX
|
||||||
|
|
||||||
@ -13309,9 +13348,9 @@ SOCK *Accept6(SOCK *sock)
|
|||||||
size = sizeof(addr);
|
size = sizeof(addr);
|
||||||
|
|
||||||
#ifdef OS_UNIX
|
#ifdef OS_UNIX
|
||||||
#ifdef UNIX_LINUX
|
#if defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||||
UnixIgnoreSignalForThread(SIGUSR1);
|
UnixIgnoreSignalForThread(SIGUSR1);
|
||||||
#endif // UNIX_LINUX
|
#endif // defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||||
sock->CallingThread = pthread_self();
|
sock->CallingThread = pthread_self();
|
||||||
#endif // OS_UNIX
|
#endif // OS_UNIX
|
||||||
|
|
||||||
@ -13625,7 +13664,7 @@ void Disconnect(SOCK *sock)
|
|||||||
// Connect to localhost if the socket is in listening
|
// Connect to localhost if the socket is in listening
|
||||||
sock->CancelAccept = true;
|
sock->CancelAccept = true;
|
||||||
|
|
||||||
#ifdef UNIX_LINUX
|
#if defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||||
{
|
{
|
||||||
pthread_t t = sock->CallingThread;
|
pthread_t t = sock->CallingThread;
|
||||||
|
|
||||||
@ -13637,7 +13676,7 @@ void Disconnect(SOCK *sock)
|
|||||||
SleepThread(200);
|
SleepThread(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // UNIX_LINUX
|
#endif // defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||||
|
|
||||||
#ifdef OS_WIN32
|
#ifdef OS_WIN32
|
||||||
if (sock->hAcceptEvent != NULL)
|
if (sock->hAcceptEvent != NULL)
|
||||||
|
@ -106,9 +106,11 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <Mayaqua/Mayaqua.h>
|
#include <Mayaqua/Mayaqua.h>
|
||||||
|
|
||||||
// Struct statfs for MacOS X
|
|
||||||
#ifdef UNIX_MACOS
|
#ifdef UNIX_MACOS
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
#ifdef NO_VLAN
|
#ifdef NO_VLAN
|
||||||
|
// Struct statfs for MacOS X
|
||||||
typedef struct fsid { int32_t val[2]; } fsid_t;
|
typedef struct fsid { int32_t val[2]; } fsid_t;
|
||||||
struct statfs {
|
struct statfs {
|
||||||
short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
|
short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
|
||||||
@ -2057,8 +2059,19 @@ UINT64 UnixGetTick64()
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
static clock_serv_t clock_serv = 0;
|
||||||
|
mach_timespec_t t;
|
||||||
|
UINT64 ret;
|
||||||
|
if (clock_serv == 0) {
|
||||||
|
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clock_serv);
|
||||||
|
}
|
||||||
|
clock_get_time(clock_serv, &t);
|
||||||
|
ret = (UINT64)t.tv_sec * 1000LL + (UINT64)t.tv_nsec / 1000000LL;
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
return TickRealtimeManual();
|
return TickRealtimeManual();
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2553,16 +2566,16 @@ void UnixExecService(char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop
|
|||||||
signal(SIGTERM, &UnixSigTermHandler);
|
signal(SIGTERM, &UnixSigTermHandler);
|
||||||
while (unix_svc_terminate == false)
|
while (unix_svc_terminate == false)
|
||||||
{
|
{
|
||||||
#ifndef UNIX_BSD
|
#if !(defined(UNIX_BSD) || defined(UNIX_MACOS))
|
||||||
pause();
|
pause();
|
||||||
#else // UNIX_BSD
|
#else // defined(UNIX_BSD) || defined(UNIX_MACOS)
|
||||||
if (UnixReadCtlFile() != saved_ctl)
|
if (UnixReadCtlFile() != saved_ctl)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SleepThread(1394);
|
SleepThread(1394);
|
||||||
#endif // UNIX_BSD
|
#endif // defined(UNIX_BSD) || defined(UNIX_MACOS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop
|
// Stop
|
||||||
|
Loading…
Reference in New Issue
Block a user