mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-22 09:29:52 +03:00
Merge PR #1859: FreeBSD: Improve client's virtual network interface handling
This commit is contained in:
commit
0f689d9dfc
@ -675,6 +675,8 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define UNIX_VLAN_IFACE_PREFIX "vpn" // Prefix of UNIX virual LAN card interface
|
||||
|
||||
#ifndef UNIX_BSD
|
||||
#define TAP_FILENAME_1 "/dev/net/tun"
|
||||
#define TAP_FILENAME_2 "/dev/tun"
|
||||
|
@ -6524,9 +6524,7 @@ bool CtConnect(CLIENT *c, RPC_CLIENT_CONNECT *connect)
|
||||
// Requires account and VLan lists of the CLIENT argument to be already locked
|
||||
bool CtVLansDown(CLIENT *c)
|
||||
{
|
||||
#ifndef UNIX_LINUX
|
||||
return true;
|
||||
#else
|
||||
#if defined(UNIX_LINUX) || defined(UNIX_BSD)
|
||||
int i;
|
||||
LIST *tmpVLanList;
|
||||
UNIX_VLAN t, *r;
|
||||
@ -6568,6 +6566,8 @@ bool CtVLansDown(CLIENT *c)
|
||||
|
||||
ReleaseList(tmpVLanList);
|
||||
return result;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -6575,9 +6575,7 @@ bool CtVLansDown(CLIENT *c)
|
||||
// Requires VLan list of the CLIENT argument to be already locked
|
||||
bool CtVLansUp(CLIENT *c)
|
||||
{
|
||||
#ifndef UNIX_LINUX
|
||||
return true;
|
||||
#else
|
||||
#if defined(UNIX_LINUX) || defined(UNIX_BSD)
|
||||
int i;
|
||||
UNIX_VLAN *r;
|
||||
|
||||
@ -6591,9 +6589,8 @@ bool CtVLansUp(CLIENT *c)
|
||||
r = LIST_DATA(c->UnixVLanList, i);
|
||||
UnixVLanSetState(r->Name, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the account information
|
||||
|
@ -7987,7 +7987,8 @@ void SmBridgeDlgOnOk(HWND hWnd, SM_SERVER *s)
|
||||
StrCpy(t.HubName, sizeof(t.HubName), hub);
|
||||
t.TapMode = tapmode;
|
||||
|
||||
if (InStrEx(t.DeviceName, "vpn", false) || InStrEx(t.DeviceName, "tun", false)
|
||||
if (InStrEx(t.DeviceName, UNIX_VLAN_IFACE_PREFIX, false)
|
||||
|| InStrEx(t.DeviceName, "tun", false)
|
||||
|| InStrEx(t.DeviceName, "tap", false))
|
||||
{
|
||||
// Trying to make a local bridge to the VPN device
|
||||
|
@ -554,7 +554,7 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool cre
|
||||
}
|
||||
int UnixCreateTapDevice(char *name, UCHAR *mac_address, bool create_up)
|
||||
{
|
||||
return UnixCreateTapDeviceEx(name, "vpn", mac_address, create_up);
|
||||
return UnixCreateTapDeviceEx(name, UNIX_VLAN_IFACE_PREFIX, mac_address, create_up);
|
||||
}
|
||||
|
||||
// Close the tap device
|
||||
@ -569,12 +569,40 @@ void UnixCloseTapDevice(int fd)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
// Destroy the tap device (for FreeBSD)
|
||||
// FreeBSD tap device is still plumbed after closing fd so need to destroy after close
|
||||
void UnixDestroyTapDevice(char *name)
|
||||
{
|
||||
#ifdef UNIX_BSD
|
||||
struct ifreq ifr;
|
||||
char eth_name[MAX_SIZE];
|
||||
int s;
|
||||
|
||||
Zero(&ifr, sizeof(ifr));
|
||||
GenerateTunName(name, UNIX_VLAN_IFACE_PREFIX, eth_name, sizeof(eth_name));
|
||||
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ioctl(s, SIOCIFDESTROY, &ifr);
|
||||
|
||||
close(s);
|
||||
#endif // UNIX_BSD
|
||||
}
|
||||
|
||||
#else // NO_VLAN
|
||||
|
||||
void UnixCloseTapDevice(int fd)
|
||||
{
|
||||
}
|
||||
|
||||
void UnixDestroyTapDevice(char *name)
|
||||
{
|
||||
}
|
||||
|
||||
int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool create_up)
|
||||
{
|
||||
return -1;
|
||||
@ -662,13 +690,13 @@ bool UnixVLanCreateEx(char *name, char *prefix, UCHAR *mac_address, bool create_
|
||||
}
|
||||
bool UnixVLanCreate(char *name, UCHAR *mac_address, bool create_up)
|
||||
{
|
||||
return UnixVLanCreateEx(name, "vpn", mac_address, create_up);
|
||||
return UnixVLanCreateEx(name, UNIX_VLAN_IFACE_PREFIX, mac_address, create_up);
|
||||
}
|
||||
|
||||
// Set a VLAN up/down
|
||||
bool UnixVLanSetState(char* name, bool state_up)
|
||||
{
|
||||
#ifdef UNIX_LINUX
|
||||
#if defined(UNIX_LINUX) || defined(UNIX_BSD)
|
||||
UNIX_VLAN_LIST *t, tt;
|
||||
struct ifreq ifr;
|
||||
int s;
|
||||
@ -689,7 +717,7 @@ bool UnixVLanSetState(char* name, bool state_up)
|
||||
return false;
|
||||
}
|
||||
|
||||
GenerateTunName(name, "vpn", eth_name, sizeof(eth_name));
|
||||
GenerateTunName(name, UNIX_VLAN_IFACE_PREFIX, eth_name, sizeof(eth_name));
|
||||
Zero(&ifr, sizeof(ifr));
|
||||
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);
|
||||
|
||||
@ -714,7 +742,7 @@ bool UnixVLanSetState(char* name, bool state_up)
|
||||
close(s);
|
||||
}
|
||||
UnlockList(unix_vlan);
|
||||
#endif // UNIX_LINUX
|
||||
#endif // UNIX_LINUX || UNIX_BSD
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -769,6 +797,9 @@ void UnixVLanDelete(char *name)
|
||||
if (t != NULL)
|
||||
{
|
||||
UnixCloseTapDevice(t->fd);
|
||||
#ifdef UNIX_BSD
|
||||
UnixDestroyTapDevice(t->Name);
|
||||
#endif
|
||||
Delete(unix_vlan, t);
|
||||
Free(t);
|
||||
}
|
||||
@ -815,6 +846,9 @@ void UnixVLanFree()
|
||||
UNIX_VLAN_LIST *t = LIST_DATA(unix_vlan, i);
|
||||
|
||||
UnixCloseTapDevice(t->fd);
|
||||
#ifdef UNIX_BSD
|
||||
UnixDestroyTapDevice(t->Name);
|
||||
#endif
|
||||
Free(t);
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ struct UNIX_VLAN_LIST
|
||||
int UnixCreateTapDevice(char *name, UCHAR *mac_address, bool create_up);
|
||||
int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool create_up);
|
||||
void UnixCloseTapDevice(int fd);
|
||||
void UnixDestroyTapDevice(char *name);
|
||||
void UnixVLanInit();
|
||||
void UnixVLanFree();
|
||||
bool UnixVLanCreate(char *name, UCHAR *mac_address, bool create_up);
|
||||
|
Loading…
Reference in New Issue
Block a user