mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-09 03:00:41 +03:00
Merge pull request #1863 from metalefty/bsdunixvlan-bridge
FreeBSD: Make sure to destroy tap device for bridge
This commit is contained in:
commit
8ac021a38c
@ -321,7 +321,7 @@ TOKEN_LIST *GetEthListLinux(bool enum_normal, bool enum_rawip)
|
|||||||
{
|
{
|
||||||
if (IsInListStr(o, name) == false)
|
if (IsInListStr(o, name) == false)
|
||||||
{
|
{
|
||||||
if (StartWith(name, "tap_") == false)
|
if (StartWith(name, UNIX_VLAN_BRIDGE_IFACE_PREFIX"_") == false)
|
||||||
{
|
{
|
||||||
Add(o, CopyStr(name));
|
Add(o, CopyStr(name));
|
||||||
}
|
}
|
||||||
@ -506,7 +506,7 @@ ETH *OpenEthLinux(char *name, bool local, bool tapmode, char *tapaddr)
|
|||||||
{
|
{
|
||||||
#ifndef NO_VLAN
|
#ifndef NO_VLAN
|
||||||
// In tap mode
|
// In tap mode
|
||||||
VLAN *v = NewTap(name, tapaddr, true);
|
VLAN *v = NewBridgeTap(name, tapaddr, true);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1399,7 +1399,7 @@ ETH *OpenEthBSD(char *name, bool local, bool tapmode, char *tapaddr)
|
|||||||
{
|
{
|
||||||
#ifndef NO_VLAN
|
#ifndef NO_VLAN
|
||||||
// In tap mode
|
// In tap mode
|
||||||
VLAN *v = NewTap(name, tapaddr, true);
|
VLAN *v = NewBridgeTap(name, tapaddr, true);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1475,7 +1475,7 @@ void CloseEth(ETH *e)
|
|||||||
if (e->Tap != NULL)
|
if (e->Tap != NULL)
|
||||||
{
|
{
|
||||||
#ifndef NO_VLAN
|
#ifndef NO_VLAN
|
||||||
FreeTap(e->Tap);
|
FreeBridgeTap(e->Tap);
|
||||||
#endif // NO_VLAN
|
#endif // NO_VLAN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,7 +675,8 @@
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define UNIX_VLAN_IFACE_PREFIX "vpn" // Prefix of UNIX virual LAN card interface
|
#define UNIX_VLAN_CLIENT_IFACE_PREFIX "vpn" // Prefix of UNIX virtual LAN card interface (used for client)
|
||||||
|
#define UNIX_VLAN_BRIDGE_IFACE_PREFIX "tap" // Prefix of UNIX virtual LAN card interface (used for bridge destination)
|
||||||
|
|
||||||
#ifndef UNIX_BSD
|
#ifndef UNIX_BSD
|
||||||
#define TAP_FILENAME_1 "/dev/net/tun"
|
#define TAP_FILENAME_1 "/dev/net/tun"
|
||||||
|
@ -7987,7 +7987,8 @@ void SmBridgeDlgOnOk(HWND hWnd, SM_SERVER *s)
|
|||||||
StrCpy(t.HubName, sizeof(t.HubName), hub);
|
StrCpy(t.HubName, sizeof(t.HubName), hub);
|
||||||
t.TapMode = tapmode;
|
t.TapMode = tapmode;
|
||||||
|
|
||||||
if (InStrEx(t.DeviceName, UNIX_VLAN_IFACE_PREFIX, false)
|
if (InStrEx(t.DeviceName, UNIX_VLAN_CLIENT_IFACE_PREFIX, false)
|
||||||
|
|| InStrEx(t.DeviceName, UNIX_VLAN_BRIDGE_IFACE_PREFIX, false)
|
||||||
|| InStrEx(t.DeviceName, "tun", false)
|
|| InStrEx(t.DeviceName, "tun", false)
|
||||||
|| InStrEx(t.DeviceName, "tap", false))
|
|| InStrEx(t.DeviceName, "tap", false))
|
||||||
{
|
{
|
||||||
|
@ -263,7 +263,7 @@ void FreeVLan(VLAN *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a tap
|
// Create a tap
|
||||||
VLAN *NewTap(char *name, char *mac_address, bool create_up)
|
VLAN *NewBridgeTap(char *name, char *mac_address, bool create_up)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
VLAN *v;
|
VLAN *v;
|
||||||
@ -273,7 +273,7 @@ VLAN *NewTap(char *name, char *mac_address, bool create_up)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = UnixCreateTapDeviceEx(name, "tap", mac_address, create_up);
|
fd = UnixCreateTapDeviceEx(name, UNIX_VLAN_BRIDGE_IFACE_PREFIX, mac_address, create_up);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -288,7 +288,7 @@ VLAN *NewTap(char *name, char *mac_address, bool create_up)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close the tap
|
// Close the tap
|
||||||
void FreeTap(VLAN *v)
|
void FreeBridgeTap(VLAN *v)
|
||||||
{
|
{
|
||||||
// Validate arguments
|
// Validate arguments
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
@ -296,7 +296,11 @@ void FreeTap(VLAN *v)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(v->fd);
|
UnixCloseTapDevice(v->fd);
|
||||||
|
#ifdef UNIX_BSD
|
||||||
|
UnixDestroyBridgeTapDevice(v->InstanceName);
|
||||||
|
#endif
|
||||||
|
|
||||||
FreeVLan(v);
|
FreeVLan(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +569,7 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool cre
|
|||||||
}
|
}
|
||||||
int UnixCreateTapDevice(char *name, UCHAR *mac_address, bool create_up)
|
int UnixCreateTapDevice(char *name, UCHAR *mac_address, bool create_up)
|
||||||
{
|
{
|
||||||
return UnixCreateTapDeviceEx(name, UNIX_VLAN_IFACE_PREFIX, mac_address, create_up);
|
return UnixCreateTapDeviceEx(name, UNIX_VLAN_CLIENT_IFACE_PREFIX, mac_address, create_up);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the tap device
|
// Close the tap device
|
||||||
@ -582,7 +586,7 @@ void UnixCloseTapDevice(int fd)
|
|||||||
|
|
||||||
// Destroy the tap device (for FreeBSD)
|
// Destroy the tap device (for FreeBSD)
|
||||||
// FreeBSD tap device is still plumbed after closing fd so need to destroy after close
|
// FreeBSD tap device is still plumbed after closing fd so need to destroy after close
|
||||||
void UnixDestroyTapDevice(char *name)
|
void UnixDestroyTapDeviceEx(char *name, char *prefix)
|
||||||
{
|
{
|
||||||
#ifdef UNIX_BSD
|
#ifdef UNIX_BSD
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
@ -590,7 +594,7 @@ void UnixDestroyTapDevice(char *name)
|
|||||||
int s;
|
int s;
|
||||||
|
|
||||||
Zero(&ifr, sizeof(ifr));
|
Zero(&ifr, sizeof(ifr));
|
||||||
GenerateTunName(name, UNIX_VLAN_IFACE_PREFIX, eth_name, sizeof(eth_name));
|
GenerateTunName(name, prefix, eth_name, sizeof(eth_name));
|
||||||
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);
|
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), eth_name);
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
@ -604,9 +608,23 @@ void UnixDestroyTapDevice(char *name)
|
|||||||
#endif // UNIX_BSD
|
#endif // UNIX_BSD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnixDestroyBridgeTapDevice(char *name)
|
||||||
|
{
|
||||||
|
#ifdef UNIX_BSD
|
||||||
|
UnixDestroyTapDeviceEx(name, UNIX_VLAN_BRIDGE_IFACE_PREFIX);
|
||||||
|
#endif // UNIX_BSD
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnixDestroyClientTapDevice(char *name)
|
||||||
|
{
|
||||||
|
#ifdef UNIX_BSD
|
||||||
|
UnixDestroyTapDeviceEx(name, UNIX_VLAN_CLIENT_IFACE_PREFIX);
|
||||||
|
#endif // UNIX_BSD
|
||||||
|
}
|
||||||
|
|
||||||
#else // NO_VLAN
|
#else // NO_VLAN
|
||||||
|
|
||||||
void UnixCloseTapDevice(int fd)
|
void UnixCloseDevice(int fd)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,6 +632,10 @@ void UnixDestroyTapDevice(char *name)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnixDestroyTapDeviceEx(char *name, char *prefix)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool create_up)
|
int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool create_up)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
@ -701,7 +723,7 @@ bool UnixVLanCreateEx(char *name, char *prefix, UCHAR *mac_address, bool create_
|
|||||||
}
|
}
|
||||||
bool UnixVLanCreate(char *name, UCHAR *mac_address, bool create_up)
|
bool UnixVLanCreate(char *name, UCHAR *mac_address, bool create_up)
|
||||||
{
|
{
|
||||||
return UnixVLanCreateEx(name, UNIX_VLAN_IFACE_PREFIX, mac_address, create_up);
|
return UnixVLanCreateEx(name, UNIX_VLAN_CLIENT_IFACE_PREFIX, mac_address, create_up);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a VLAN up/down
|
// Set a VLAN up/down
|
||||||
@ -728,7 +750,7 @@ bool UnixVLanSetState(char* name, bool state_up)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateTunName(name, UNIX_VLAN_IFACE_PREFIX, eth_name, sizeof(eth_name));
|
GenerateTunName(name, UNIX_VLAN_CLIENT_IFACE_PREFIX, eth_name, sizeof(eth_name));
|
||||||
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);
|
||||||
|
|
||||||
@ -809,7 +831,7 @@ void UnixVLanDelete(char *name)
|
|||||||
{
|
{
|
||||||
UnixCloseTapDevice(t->fd);
|
UnixCloseTapDevice(t->fd);
|
||||||
#ifdef UNIX_BSD
|
#ifdef UNIX_BSD
|
||||||
UnixDestroyTapDevice(t->Name);
|
UnixDestroyClientTapDevice(t->Name);
|
||||||
#endif
|
#endif
|
||||||
Delete(unix_vlan, t);
|
Delete(unix_vlan, t);
|
||||||
Free(t);
|
Free(t);
|
||||||
@ -858,7 +880,7 @@ void UnixVLanFree()
|
|||||||
|
|
||||||
UnixCloseTapDevice(t->fd);
|
UnixCloseTapDevice(t->fd);
|
||||||
#ifdef UNIX_BSD
|
#ifdef UNIX_BSD
|
||||||
UnixDestroyTapDevice(t->Name);
|
UnixDestroyClientTapDevice(t->Name);
|
||||||
#endif
|
#endif
|
||||||
Free(t);
|
Free(t);
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,9 @@ struct VLAN
|
|||||||
|
|
||||||
// Function prototype
|
// Function prototype
|
||||||
VLAN *NewVLan(char *instance_name, VLAN_PARAM *param);
|
VLAN *NewVLan(char *instance_name, VLAN_PARAM *param);
|
||||||
VLAN *NewTap(char *name, char *mac_address, bool create_up);
|
VLAN *NewBridgeTap(char *name, char *mac_address, bool create_up);
|
||||||
void FreeVLan(VLAN *v);
|
void FreeVLan(VLAN *v);
|
||||||
void FreeTap(VLAN *v);
|
void FreeBridgeTap(VLAN *v);
|
||||||
CANCEL *VLanGetCancel(VLAN *v);
|
CANCEL *VLanGetCancel(VLAN *v);
|
||||||
bool VLanGetNextPacket(VLAN *v, void **buf, UINT *size);
|
bool VLanGetNextPacket(VLAN *v, void **buf, UINT *size);
|
||||||
bool VLanPutPacket(VLAN *v, void *buf, UINT size);
|
bool VLanPutPacket(VLAN *v, void *buf, UINT size);
|
||||||
@ -60,7 +60,8 @@ struct UNIX_VLAN_LIST
|
|||||||
int UnixCreateTapDevice(char *name, UCHAR *mac_address, bool create_up);
|
int UnixCreateTapDevice(char *name, UCHAR *mac_address, bool create_up);
|
||||||
int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool create_up);
|
int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address, bool create_up);
|
||||||
void UnixCloseTapDevice(int fd);
|
void UnixCloseTapDevice(int fd);
|
||||||
void UnixDestroyTapDevice(char *name);
|
void UnixDestroyBridgeTapDevice(char *name);
|
||||||
|
void UnixDestroyClientTapDevice(char *name);
|
||||||
void UnixVLanInit();
|
void UnixVLanInit();
|
||||||
void UnixVLanFree();
|
void UnixVLanFree();
|
||||||
bool UnixVLanCreate(char *name, UCHAR *mac_address, bool create_up);
|
bool UnixVLanCreate(char *name, UCHAR *mac_address, bool create_up);
|
||||||
|
Loading…
Reference in New Issue
Block a user