1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-13 19:24:57 +03:00

Cedar/BridgeUnix: make sure to destroy tap device for bridge on FreeBSD

Also, rename NewTap/FreeTap to NewBridgeTap/FreeBridgeTap because these
functions are used to create/destroy tap device used for bridge
destination.
This commit is contained in:
Koichiro IWAO
2023-06-05 18:29:22 +09:00
parent 696a9bc0a1
commit 09708bc8cb
3 changed files with 36 additions and 14 deletions

View File

@ -263,7 +263,7 @@ void FreeVLan(VLAN *v)
}
// 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;
VLAN *v;
@ -288,7 +288,7 @@ VLAN *NewTap(char *name, char *mac_address, bool create_up)
}
// Close the tap
void FreeTap(VLAN *v)
void FreeBridgeTap(VLAN *v)
{
// Validate arguments
if (v == NULL)
@ -296,7 +296,11 @@ void FreeTap(VLAN *v)
return;
}
close(v->fd);
UnixCloseTapDevice(v->fd);
#ifdef UNIX_BSD
UnixDestroyBridgeTapDevice(v->InstanceName);
#endif
FreeVLan(v);
}
@ -582,7 +586,7 @@ void UnixCloseTapDevice(int 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)
void UnixDestroyTapDeviceEx(char *name, char *prefix)
{
#ifdef UNIX_BSD
struct ifreq ifr;
@ -590,7 +594,7 @@ void UnixDestroyTapDevice(char *name)
int s;
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);
s = socket(AF_INET, SOCK_DGRAM, 0);
@ -604,12 +608,29 @@ void UnixDestroyTapDevice(char *name)
#endif // UNIX_BSD
}
void UnixDestroyBridgeTapDevice(char *name)
{
#ifdef UNIX_BSD
UnixDestroyTapDeviceEx(name, UNIX_VLAN_BRDEST_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
void UnixCloseTapDevice(int fd)
void UnixCloseBridgeTapDevice(int fd)
{
}
void UnixCloseClientTapDevice(int fd)
{
void UnixDestroyTapDevice(char *name)
{
}
@ -809,7 +830,7 @@ void UnixVLanDelete(char *name)
{
UnixCloseTapDevice(t->fd);
#ifdef UNIX_BSD
UnixDestroyTapDevice(t->Name);
UnixDestroyClientTapDevice(t->Name);
#endif
Delete(unix_vlan, t);
Free(t);
@ -858,7 +879,7 @@ void UnixVLanFree()
UnixCloseTapDevice(t->fd);
#ifdef UNIX_BSD
UnixDestroyTapDevice(t->Name);
UnixDestroyClientTapDevice(t->Name);
#endif
Free(t);
}