1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Merge pull request #1781 from metalefty/vm-detection/freebsd-on-vm

Mayaqua/Unix: Make VM detection work on FreeBSD
This commit is contained in:
Ilya Shipitsin 2023-02-28 20:32:26 +06:00 committed by GitHub
commit 8c64dc0cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -295,16 +295,25 @@ void UnixDisableInterfaceOffload(char *name)
#endif // UNIX_LINUX #endif // UNIX_LINUX
} }
// Validate whether the UNIX is running in a VM // Validate whether the Linux/FreeBSD is running in a VM
// Not implemented yet on other OS
bool UnixIsInVmMain() bool UnixIsInVmMain()
{ {
TOKEN_LIST *t = NULL; TOKEN_LIST *t = NULL;
bool ret = false; bool ret = false;
#if defined(UNIX_LINUX)
char *vm_str_list = "Hypervisor detected,VMware Virtual Platform,VMware Virtual USB,qemu,xen,paravirtualized,virtual hd,virtualhd,virtual pc,virtualpc,kvm,oracle vm,oraclevm,parallels,xvm,bochs"; char *vm_str_list = "Hypervisor detected,VMware Virtual Platform,VMware Virtual USB,qemu,xen,paravirtualized,virtual hd,virtualhd,virtual pc,virtualpc,kvm,oracle vm,oraclevm,parallels,xvm,bochs";
#elif defined(__FreeBSD__)
char *vm_str_list = "generic,xen,hv,vmware,kvm,bhyve";
#endif
#ifdef UNIX_LINUX #if defined(UNIX_LINUX)
t = UnixExec("/bin/dmesg"); t = UnixExec("/bin/dmesg");
#elif defined(__FreeBSD__)
t = UnixExec("/sbin/sysctl -n kern.vm_guest");
#endif
#if defined(UNIX_LINUX) || defined(__FreeBSD__)
if (t != NULL) if (t != NULL)
{ {
BUF *b = NewBuf(); BUF *b = NewBuf();
@ -327,10 +336,11 @@ bool UnixIsInVmMain()
FreeBuf(b); FreeBuf(b);
FreeToken(t); FreeToken(t);
} }
#endif // UNIX_LINUX #endif // defined(UNIX_LINUX) || defined(__FreeBSD)
return ret; return ret;
} }
bool UnixIsInVm() bool UnixIsInVm()
{ {
static bool is_in_vm_flag = false; static bool is_in_vm_flag = false;