diff --git a/listener/tun/dev/dev_windows.go b/listener/tun/dev/dev_windows.go index e3cc5cc6..0bf25ef9 100644 --- a/listener/tun/dev/dev_windows.go +++ b/listener/tun/dev/dev_windows.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "os" + "sync/atomic" "time" _ "unsafe" @@ -31,7 +32,7 @@ type rateJuggler struct { changing int32 } -var WintunTunnelType = "Clash" +var WintunTunnelType = "Clash.Meta" var WintunStaticRequestedGUID *windows.GUID //go:linkname procyield runtime.procyield @@ -67,6 +68,7 @@ func (tun *tunWindows) ForceMTU(mtu int) { func (tun *tunWindows) Read0(buff []byte, offset int) (int, error) { tun.running.Add(1) + defer tun.running.Done() retry: if atomic.LoadInt32(&tun.close) == 1 { diff --git a/listener/tun/dev/wintun/dll_embed_windows_386.go b/listener/tun/dev/wintun/dll_embed_windows_386.go new file mode 100644 index 00000000..270210ad --- /dev/null +++ b/listener/tun/dev/wintun/dll_embed_windows_386.go @@ -0,0 +1,21 @@ +package wintun + +// Copyright 2020 MeshStep Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + _ "embed" +) + +//go:embed static/386/wintun.dll +var ddlContent []byte diff --git a/listener/tun/dev/wintun/dll_embed_windows_amd64.go b/listener/tun/dev/wintun/dll_embed_windows_amd64.go new file mode 100644 index 00000000..b7104e31 --- /dev/null +++ b/listener/tun/dev/wintun/dll_embed_windows_amd64.go @@ -0,0 +1,21 @@ +package wintun + +// Copyright 2020 MeshStep Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + _ "embed" +) + +//go:embed static/amd64/wintun.dll +var ddlContent []byte diff --git a/listener/tun/dev/wintun/dll_embed_windows_arm.go b/listener/tun/dev/wintun/dll_embed_windows_arm.go new file mode 100644 index 00000000..6fefa06e --- /dev/null +++ b/listener/tun/dev/wintun/dll_embed_windows_arm.go @@ -0,0 +1,21 @@ +package wintun + +// Copyright 2020 MeshStep Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + _ "embed" +) + +//go:embed static/arm/wintun.dll +var ddlContent []byte diff --git a/listener/tun/dev/wintun/dll_embed_windows_arm64.go b/listener/tun/dev/wintun/dll_embed_windows_arm64.go new file mode 100644 index 00000000..37dff496 --- /dev/null +++ b/listener/tun/dev/wintun/dll_embed_windows_arm64.go @@ -0,0 +1,21 @@ +package wintun + +// Copyright 2020 MeshStep Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + _ "embed" +) + +//go:embed static/arm64/wintun.dll +var ddlContent []byte diff --git a/listener/tun/dev/wintun/dll_windows.go b/listener/tun/dev/wintun/dll_windows.go index d9989c1f..0a36c899 100644 --- a/listener/tun/dev/wintun/dll_windows.go +++ b/listener/tun/dev/wintun/dll_windows.go @@ -7,6 +7,7 @@ package wintun import ( "fmt" + "golang.zx2c4.com/wireguard/windows/driver/memmod" "sync" "sync/atomic" "unsafe" @@ -78,12 +79,7 @@ func (d *lazyDLL) Load() error { return nil } - //const ( - // LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 0x00000200 - // LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800 - //) - //module, err := windows.LoadLibraryEx(d.Name, 0, LOAD_LIBRARY_SEARCH_APPLICATION_DIR|LOAD_LIBRARY_SEARCH_SYSTEM32) - module, err := windows.LoadLibraryEx(C.Path.GetAssetLocation(d.Name), 0, windows.LOAD_WITH_ALTERED_SEARCH_PATH) + module, err := memmod.LoadLibrary(ddlContent) if err != nil { return fmt.Errorf("Unable to load library: %w", err) }