From fe89bbded22d3d6ccda685d11828ec696510bc03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 15 Mar 2023 21:47:16 +0800 Subject: [PATCH] Create gVisor stack by default in NE --- stack.go | 3 ++- stack_default.go | 7 +++++++ stack_default_darwin.go | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 stack_default.go create mode 100644 stack_default_darwin.go diff --git a/stack.go b/stack.go index 1eed543..83612a9 100644 --- a/stack.go +++ b/stack.go @@ -24,6 +24,7 @@ type StackOptions struct { UDPTimeout int64 Handler Handler Logger logger.Logger + UnderPlatform bool } func NewStack( @@ -32,7 +33,7 @@ func NewStack( ) (Stack, error) { switch stack { case "": - return NewSystem(options) + return defaultStack(options) case "gvisor": return NewGVisor(options) case "system": diff --git a/stack_default.go b/stack_default.go new file mode 100644 index 0000000..28de3da --- /dev/null +++ b/stack_default.go @@ -0,0 +1,7 @@ +//go:build !darwin + +package tun + +func defaultStack(options StackOptions) (Stack, error) { + return NewSystem(options) +} diff --git a/stack_default_darwin.go b/stack_default_darwin.go new file mode 100644 index 0000000..530ea2b --- /dev/null +++ b/stack_default_darwin.go @@ -0,0 +1,10 @@ +package tun + +func defaultStack(options StackOptions) (Stack, error) { + if options.UnderPlatform { + // Apple Network Extension conflicts with system stack. + return NewGVisor(options) + } else { + return NewSystem(options) + } +}