mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-06 01:30:40 +03:00
Supporting VLAN for Mac OS X using TunTapOSX
This commit is contained in:
parent
c32bf3b84f
commit
8779e59295
@ -696,7 +696,15 @@
|
|||||||
|
|
||||||
#define TAP_FILENAME_1 "/dev/net/tun"
|
#define TAP_FILENAME_1 "/dev/net/tun"
|
||||||
#define TAP_FILENAME_2 "/dev/tun"
|
#define TAP_FILENAME_2 "/dev/tun"
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
#ifdef NO_VLAN
|
||||||
#define TAP_MACOS_FILENAME "/dev/tap0"
|
#define TAP_MACOS_FILENAME "/dev/tap0"
|
||||||
|
#else
|
||||||
|
#define TAP_MACOS_FILENAME "tap"
|
||||||
|
#endif
|
||||||
|
#define TAP_MACOS_DIR "/dev/"
|
||||||
|
#define TAP_MACOS_NUMBER (16)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7446,12 +7446,14 @@ bool CtDisableVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *vlan)
|
|||||||
|
|
||||||
#ifndef OS_WIN32
|
#ifndef OS_WIN32
|
||||||
|
|
||||||
|
#ifdef NO_VLAN
|
||||||
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
||||||
{
|
{
|
||||||
// Can not be added or removed the virtual LAN card in MacOS X
|
// Can not be added or removed the virtual LAN card in MacOS X
|
||||||
CiSetError(c, ERR_NOT_SUPPORTED);
|
CiSetError(c, ERR_NOT_SUPPORTED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check whether the virtual LAN card with the specified name is not
|
// Check whether the virtual LAN card with the specified name is not
|
||||||
// being used by one or more accounts
|
// being used by one or more accounts
|
||||||
@ -7597,12 +7599,14 @@ bool CtEnableVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *vlan)
|
|||||||
|
|
||||||
#ifndef OS_WIN32
|
#ifndef OS_WIN32
|
||||||
|
|
||||||
|
#ifdef NO_VLAN
|
||||||
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
||||||
{
|
{
|
||||||
// Can not be added or removed the virtual LAN card in MacOS X
|
// Can not be added or removed the virtual LAN card in MacOS X
|
||||||
CiSetError(c, ERR_NOT_SUPPORTED);
|
CiSetError(c, ERR_NOT_SUPPORTED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Search the virtual LAN card
|
// Search the virtual LAN card
|
||||||
LockList(c->UnixVLanList);
|
LockList(c->UnixVLanList);
|
||||||
@ -7693,12 +7697,14 @@ bool CtDeleteVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *d)
|
|||||||
|
|
||||||
#ifndef OS_WIN32
|
#ifndef OS_WIN32
|
||||||
|
|
||||||
|
#ifdef NO_VLAN
|
||||||
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
||||||
{
|
{
|
||||||
// Can not be added or removed the virtual LAN card in MacOS X
|
// Can not be added or removed the virtual LAN card in MacOS X
|
||||||
CiSetError(c, ERR_NOT_SUPPORTED);
|
CiSetError(c, ERR_NOT_SUPPORTED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check whether the virtual LAN card with the specified name is not
|
// Check whether the virtual LAN card with the specified name is not
|
||||||
// being used by one or more accounts
|
// being used by one or more accounts
|
||||||
@ -8265,12 +8271,14 @@ bool CtCreateVLan(CLIENT *c, RPC_CLIENT_CREATE_VLAN *create)
|
|||||||
#ifndef OS_WIN32
|
#ifndef OS_WIN32
|
||||||
|
|
||||||
// Non-Win32
|
// Non-Win32
|
||||||
|
#ifdef NO_VLAN
|
||||||
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
||||||
{
|
{
|
||||||
// A virtual LAN card can not be added or removed in MacOS X
|
// A virtual LAN card can not be added or removed in MacOS X
|
||||||
CiSetError(c, ERR_NOT_SUPPORTED);
|
CiSetError(c, ERR_NOT_SUPPORTED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check whether the specified name is valid or not
|
// Check whether the specified name is valid or not
|
||||||
if (IsSafeStr(create->DeviceName) == false)
|
if (IsSafeStr(create->DeviceName) == false)
|
||||||
@ -9792,7 +9800,11 @@ bool CiReadSettingFromCfg(CLIENT *c, FOLDER *root)
|
|||||||
// Eraser
|
// Eraser
|
||||||
c->Eraser = NewEraser(c->Logger, CfgGetInt64(config, "AutoDeleteCheckDiskFreeSpaceMin"));
|
c->Eraser = NewEraser(c->Logger, CfgGetInt64(config, "AutoDeleteCheckDiskFreeSpaceMin"));
|
||||||
|
|
||||||
if (OS_IS_UNIX(GetOsInfo()->OsType) && GetOsInfo()->OsType != OSTYPE_MACOS_X)
|
if (OS_IS_UNIX(GetOsInfo()->OsType)
|
||||||
|
#ifdef NO_VLAN
|
||||||
|
&& GetOsInfo()->OsType != OSTYPE_MACOS_X
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Read the UNIX version virtual LAN card list (except MacOS)
|
// Read the UNIX version virtual LAN card list (except MacOS)
|
||||||
vlan = CfgGetFolder(root, "UnixVLan");
|
vlan = CfgGetFolder(root, "UnixVLan");
|
||||||
@ -9802,6 +9814,7 @@ bool CiReadSettingFromCfg(CLIENT *c, FOLDER *root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NO_VLAN
|
||||||
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
if (GetOsInfo()->OsType == OSTYPE_MACOS_X)
|
||||||
{
|
{
|
||||||
#ifdef OS_UNIX
|
#ifdef OS_UNIX
|
||||||
@ -9822,6 +9835,7 @@ bool CiReadSettingFromCfg(CLIENT *c, FOLDER *root)
|
|||||||
Add(c->UnixVLanList, uv);
|
Add(c->UnixVLanList, uv);
|
||||||
#endif // OS_UNIX
|
#endif // OS_UNIX
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
CiLoadAccountDatabase(c, db);
|
CiLoadAccountDatabase(c, db);
|
||||||
|
|
||||||
@ -10328,7 +10342,11 @@ void CiWriteSettingToCfg(CLIENT *c, FOLDER *root)
|
|||||||
CiWriteCAList(c, ca);
|
CiWriteCAList(c, ca);
|
||||||
|
|
||||||
// VLAN
|
// VLAN
|
||||||
if (OS_IS_UNIX(GetOsInfo()->OsType) && GetOsInfo()->OsType != OSTYPE_MACOS_X)
|
if (OS_IS_UNIX(GetOsInfo()->OsType)
|
||||||
|
#ifdef NO_VLAN
|
||||||
|
&& GetOsInfo()->OsType != OSTYPE_MACOS_X
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
vlan = CfgCreateFolder(root, "UnixVLan");
|
vlan = CfgCreateFolder(root, "UnixVLan");
|
||||||
CiWriteVLanList(c, vlan);
|
CiWriteVLanList(c, vlan);
|
||||||
|
@ -302,11 +302,7 @@ CANCEL *VLanGetCancel(VLAN *v)
|
|||||||
|
|
||||||
fd = v->fd;
|
fd = v->fd;
|
||||||
|
|
||||||
#ifndef UNIX_MACOS
|
|
||||||
UnixSetSocketNonBlockingMode(fd, true);
|
UnixSetSocketNonBlockingMode(fd, true);
|
||||||
#else // UNIX_MACOS
|
|
||||||
UnixSetSocketNonBlockingMode(fd, false);
|
|
||||||
#endif // UNIX_MACOS
|
|
||||||
|
|
||||||
c->SpecialFlag = true;
|
c->SpecialFlag = true;
|
||||||
c->pipe_read = fd;
|
c->pipe_read = fd;
|
||||||
@ -402,6 +398,9 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)
|
|||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
char *tap_name = TAP_FILENAME_1;
|
char *tap_name = TAP_FILENAME_1;
|
||||||
int s;
|
int s;
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
char tap_macos_name[256] = TAP_MACOS_DIR TAP_MACOS_FILENAME;
|
||||||
|
#endif
|
||||||
// Validate arguments
|
// Validate arguments
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
{
|
{
|
||||||
@ -445,13 +444,23 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)
|
|||||||
tap_name = TAP_FILENAME_2;
|
tap_name = TAP_FILENAME_2;
|
||||||
}
|
}
|
||||||
#else // UNIX_MACOS
|
#else // UNIX_MACOS
|
||||||
// MacOS X
|
|
||||||
fd = open(TAP_MACOS_FILENAME, O_RDWR);
|
|
||||||
if (fd == -1)
|
|
||||||
{
|
{
|
||||||
return -1;
|
int i;
|
||||||
|
fd = -1;
|
||||||
|
for (i = 0; i < TAP_MACOS_NUMBER; i++) {
|
||||||
|
sprintf(tap_macos_name + strlen(TAP_MACOS_DIR TAP_MACOS_FILENAME), "%d", i);
|
||||||
|
fd = open(tap_macos_name, O_RDWR);
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
tap_name = tap_macos_name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tap_name = TAP_MACOS_FILENAME;
|
|
||||||
#endif // UNIX_MACOS
|
#endif // UNIX_MACOS
|
||||||
|
|
||||||
#ifdef UNIX_LINUX
|
#ifdef UNIX_LINUX
|
||||||
@ -479,7 +488,7 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)
|
|||||||
Zero(&ifr, sizeof(ifr));
|
Zero(&ifr, sizeof(ifr));
|
||||||
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);
|
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);
|
||||||
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
|
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
|
||||||
Copy(&ifr.ifr_hwaddr.sa_data, mac_address, 6);
|
Copy(&ifr.ifr_addr.sa_data, mac_address, 6);
|
||||||
ioctl(s, SIOCSIFHWADDR, &ifr);
|
ioctl(s, SIOCSIFHWADDR, &ifr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,6 +503,33 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else // UNIX_LINUX
|
#else // UNIX_LINUX
|
||||||
|
#ifdef UNIX_MACOS
|
||||||
|
// MAC address setting
|
||||||
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (s != -1)
|
||||||
|
{
|
||||||
|
char *macos_eth_name;
|
||||||
|
macos_eth_name = tap_macos_name + strlen(TAP_MACOS_DIR);
|
||||||
|
|
||||||
|
if (mac_address != NULL)
|
||||||
|
{
|
||||||
|
uint8_t macos_mac_address[19];
|
||||||
|
Zero(&ifr, sizeof(ifr));
|
||||||
|
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), macos_eth_name);
|
||||||
|
Copy(&ifr.ifr_addr.sa_data, mac_address, 6);
|
||||||
|
ioctl(s, SIOCSIFLLADDR, &ifr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Zero(&ifr, sizeof(ifr));
|
||||||
|
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), macos_eth_name);
|
||||||
|
ioctl(s, SIOCGIFFLAGS, &ifr);
|
||||||
|
|
||||||
|
ifr.ifr_flags |= IFF_UP;
|
||||||
|
ioctl(s, SIOCSIFFLAGS, &ifr);
|
||||||
|
|
||||||
|
close(s);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef UNIX_SOLARIS
|
#ifdef UNIX_SOLARIS
|
||||||
// Create a tap for Solaris
|
// Create a tap for Solaris
|
||||||
{
|
{
|
||||||
|
@ -227,11 +227,14 @@ struct tundladdr {
|
|||||||
|
|
||||||
#else // UNIX_SOLARIS
|
#else // UNIX_SOLARIS
|
||||||
|
|
||||||
#ifdef UNIX_BSD
|
#if defined(UNIX_BSD) || (!defined(NO_VLAN) && defined(UNIX_MACOS))
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Tap header for FreeBSD
|
// Tap header for FreeBSD
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
// -----------------------------------------------------------------
|
||||||
|
// Tap header For MacOS
|
||||||
|
// -----------------------------------------------------------------
|
||||||
/* $NetBSD: if_tun.h,v 1.5 1994/06/29 06:36:27 cgd Exp $ */
|
/* $NetBSD: if_tun.h,v 1.5 1994/06/29 06:36:27 cgd Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -283,17 +286,7 @@ struct tuninfo {
|
|||||||
|
|
||||||
#else // UNIX_BSD
|
#else // UNIX_BSD
|
||||||
|
|
||||||
#ifdef UNIX_MACOS
|
#endif // UNIX_BSD || UNIX_MACOS
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
|
||||||
// Tap header For MacOS
|
|
||||||
// -----------------------------------------------------------------
|
|
||||||
|
|
||||||
#else // UNIX_MACOS
|
|
||||||
|
|
||||||
#endif // UNIX_MACOS
|
|
||||||
|
|
||||||
#endif // UNIX_BSD
|
|
||||||
|
|
||||||
#endif // UNIX_SOLARIS
|
#endif // UNIX_SOLARIS
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@
|
|||||||
|
|
||||||
// Struct statfs for MacOS X
|
// Struct statfs for MacOS X
|
||||||
#ifdef UNIX_MACOS
|
#ifdef UNIX_MACOS
|
||||||
|
#ifdef NO_VLAN
|
||||||
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 */
|
||||||
@ -117,6 +118,9 @@ struct statfs {
|
|||||||
char f_mntonname[90]; /* directory on which mounted */
|
char f_mntonname[90]; /* directory on which mounted */
|
||||||
char f_mntfromname[90];/* mounted filesystem */
|
char f_mntfromname[90];/* mounted filesystem */
|
||||||
};
|
};
|
||||||
|
#else
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#endif
|
||||||
#endif // UNIX_MACOS
|
#endif // UNIX_MACOS
|
||||||
|
|
||||||
// Scandir() function for Solaris
|
// Scandir() function for Solaris
|
||||||
|
@ -24,11 +24,13 @@
|
|||||||
# Variables
|
# Variables
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
|
NO_VLAN?=-DNO_VLAN
|
||||||
|
|
||||||
|
OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP $(NO_VLAN) -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char
|
||||||
|
|
||||||
OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
OPTIONS_LINK_DEBUG=-g -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
||||||
|
|
||||||
OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP -DNO_VLAN -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
|
OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP $(NO_VLAN) -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char
|
||||||
|
|
||||||
OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
OPTIONS_LINK_RELEASE=-O2 -fsigned-char -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
||||||
|
|
||||||
|
@ -24,11 +24,13 @@
|
|||||||
# Variables
|
# Variables
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char -m64
|
NO_VLAN?=-DNO_VLAN
|
||||||
|
|
||||||
|
OPTIONS_COMPILE_DEBUG=-D_DEBUG -DDEBUG -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP $(NO_VLAN) -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -g -fsigned-char -m64
|
||||||
|
|
||||||
OPTIONS_LINK_DEBUG=-g -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
OPTIONS_LINK_DEBUG=-g -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
||||||
|
|
||||||
OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP -DNO_VLAN -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -m64
|
OPTIONS_COMPILE_RELEASE=-DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_MACOS -DBRIDGE_PCAP $(NO_VLAN) -DCPU_64 -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64 -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -m64
|
||||||
|
|
||||||
OPTIONS_LINK_RELEASE=-O2 -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
OPTIONS_LINK_RELEASE=-O2 -fsigned-char -m64 -lm -lpthread -lssl -lcrypto -liconv -lreadline -lncurses -lz -lpcap
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user