config.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package wireguard
  2. import (
  3. "context"
  4. "github.com/xtls/xray-core/common/errors"
  5. )
  6. func (c *DeviceConfig) preferIP4() bool {
  7. return c.DomainStrategy == DeviceConfig_FORCE_IP ||
  8. c.DomainStrategy == DeviceConfig_FORCE_IP4 ||
  9. c.DomainStrategy == DeviceConfig_FORCE_IP46
  10. }
  11. func (c *DeviceConfig) preferIP6() bool {
  12. return c.DomainStrategy == DeviceConfig_FORCE_IP ||
  13. c.DomainStrategy == DeviceConfig_FORCE_IP6 ||
  14. c.DomainStrategy == DeviceConfig_FORCE_IP64
  15. }
  16. func (c *DeviceConfig) hasFallback() bool {
  17. return c.DomainStrategy == DeviceConfig_FORCE_IP46 || c.DomainStrategy == DeviceConfig_FORCE_IP64
  18. }
  19. func (c *DeviceConfig) fallbackIP4() bool {
  20. return c.DomainStrategy == DeviceConfig_FORCE_IP64
  21. }
  22. func (c *DeviceConfig) fallbackIP6() bool {
  23. return c.DomainStrategy == DeviceConfig_FORCE_IP46
  24. }
  25. func (c *DeviceConfig) createTun() tunCreator {
  26. if !c.IsClient {
  27. // See tun_linux.go createKernelTun()
  28. errors.LogWarning(context.Background(), "Using gVisor TUN. WG inbound doesn't support kernel TUN yet.")
  29. return createGVisorTun
  30. }
  31. if c.NoKernelTun {
  32. errors.LogWarning(context.Background(), "Using gVisor TUN. NoKernelTun is set to true.")
  33. return createGVisorTun
  34. }
  35. kernelTunSupported, err := KernelTunSupported()
  36. if err != nil {
  37. errors.LogWarning(context.Background(), "Using gVisor TUN. Failed to check kernel TUN support:", err)
  38. return createGVisorTun
  39. }
  40. if !kernelTunSupported {
  41. errors.LogWarning(context.Background(), "Using gVisor TUN. Kernel TUN is not supported on your OS, or your permission is insufficient.")
  42. return createGVisorTun
  43. }
  44. errors.LogWarning(context.Background(), "Using kernel TUN.")
  45. return createKernelTun
  46. }