From d25a8b08db9795da330a8634e1999d7833ea29ea Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Mon, 26 Aug 2024 08:55:27 +0000 Subject: [PATCH 1/5] [-] fix "`run.skip-dirs` is deprecated" --- iphlpapi/iphlpapi.go | 3 +++ iphlpapi/mksyscall.go | 5 +++- iphlpapi/ziphlapi.go | 61 ------------------------------------------- 3 files changed, 7 insertions(+), 62 deletions(-) delete mode 100644 iphlpapi/ziphlapi.go diff --git a/iphlpapi/iphlpapi.go b/iphlpapi/iphlpapi.go index 2c5db304..6f399ee2 100644 --- a/iphlpapi/iphlpapi.go +++ b/iphlpapi/iphlpapi.go @@ -1,3 +1,6 @@ +//go:build windows +// +build windows + package iphlpapi //sys AddIPAddress(Address uint32, IpMask uint32, IfIndex uint32, NTEContext *uint32, NTEInstance *uint32) (errcode error) = iphlpapi.AddIPAddress diff --git a/iphlpapi/mksyscall.go b/iphlpapi/mksyscall.go index bc84a13d..a38de2ab 100644 --- a/iphlpapi/mksyscall.go +++ b/iphlpapi/mksyscall.go @@ -1,5 +1,8 @@ +//go:build windows +// +build windows + // +build generate package iphlpapi -//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output ziphlapi.go iphlpapi.go +//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output ziphlapi_windows.go iphlpapi.go diff --git a/iphlpapi/ziphlapi.go b/iphlpapi/ziphlapi.go deleted file mode 100644 index be514764..00000000 --- a/iphlpapi/ziphlapi.go +++ /dev/null @@ -1,61 +0,0 @@ -// Code generated by 'go generate'; DO NOT EDIT. - -package iphlpapi - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var _ unsafe.Pointer - -// Do the interface allocations only once for common -// Errno values. -const ( - errnoERROR_IO_PENDING = 997 -) - -var ( - errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) - errERROR_EINVAL error = syscall.EINVAL -) - -// errnoErr returns common boxed Errno values, to prevent -// allocations at runtime. -func errnoErr(e syscall.Errno) error { - switch e { - case 0: - return errERROR_EINVAL - case errnoERROR_IO_PENDING: - return errERROR_IO_PENDING - } - // TODO: add more here, after collecting data on the common - // error values see on Windows. (perhaps when running - // all.bat?) - return e -} - -var ( - modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll") - - procAddIPAddress = modiphlpapi.NewProc("AddIPAddress") - procDeleteIPAddress = modiphlpapi.NewProc("DeleteIPAddress") -) - -func AddIPAddress(Address uint32, IpMask uint32, IfIndex uint32, NTEContext *uint32, NTEInstance *uint32) (errcode error) { - r0, _, _ := syscall.Syscall6(procAddIPAddress.Addr(), 5, uintptr(Address), uintptr(IpMask), uintptr(IfIndex), uintptr(unsafe.Pointer(NTEContext)), uintptr(unsafe.Pointer(NTEInstance)), 0) - if r0 != 0 { - errcode = syscall.Errno(r0) - } - return -} - -func DeleteIPAddress(NTEContext uint32) (errcode error) { - r0, _, _ := syscall.Syscall(procDeleteIPAddress.Addr(), 1, uintptr(NTEContext), 0, 0) - if r0 != 0 { - errcode = syscall.Errno(r0) - } - return -} From ea78910b64ec9844e293cf32e5da997a87416b14 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Mon, 26 Aug 2024 11:09:56 +0200 Subject: [PATCH 2/5] [-] fix generation for Windows build --- .github/workflows/build.yml | 1 + iphlpapi/{iphlpapi.go => iphlpapi_windows.go} | 3 --- iphlpapi/{mksyscall.go => mksyscall_windows.go} | 6 ++---- 3 files changed, 3 insertions(+), 7 deletions(-) rename iphlpapi/{iphlpapi.go => iphlpapi_windows.go} (86%) rename iphlpapi/{mksyscall.go => mksyscall_windows.go} (58%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff667e74..243025f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,7 @@ jobs: run: | go mod download go version + go generate ./... go build - name: GolangCI-Lint diff --git a/iphlpapi/iphlpapi.go b/iphlpapi/iphlpapi_windows.go similarity index 86% rename from iphlpapi/iphlpapi.go rename to iphlpapi/iphlpapi_windows.go index 6f399ee2..2c5db304 100644 --- a/iphlpapi/iphlpapi.go +++ b/iphlpapi/iphlpapi_windows.go @@ -1,6 +1,3 @@ -//go:build windows -// +build windows - package iphlpapi //sys AddIPAddress(Address uint32, IpMask uint32, IfIndex uint32, NTEContext *uint32, NTEInstance *uint32) (errcode error) = iphlpapi.AddIPAddress diff --git a/iphlpapi/mksyscall.go b/iphlpapi/mksyscall_windows.go similarity index 58% rename from iphlpapi/mksyscall.go rename to iphlpapi/mksyscall_windows.go index a38de2ab..0593ab83 100644 --- a/iphlpapi/mksyscall.go +++ b/iphlpapi/mksyscall_windows.go @@ -1,8 +1,6 @@ -//go:build windows -// +build windows - +//go:build generate // +build generate package iphlpapi -//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output ziphlapi_windows.go iphlpapi.go +//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output ziphlapi_windows.go iphlpapi_windows.go From 5df13822dd42f296879834197ee8a689c74126cf Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Mon, 26 Aug 2024 11:12:05 +0200 Subject: [PATCH 3/5] [-] remove warning --- .golangci.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 779fa0f9..11054b18 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,10 +8,4 @@ linters: linters-settings: gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 16 - -run: - skip-dirs: - - iphlpapi - - package - - test + min-complexity: 16 \ No newline at end of file From e1e6327d8df24aa1bd5e64fe9cf07e3c6b7c1460 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Mon, 26 Aug 2024 09:31:52 +0000 Subject: [PATCH 4/5] [+] add 'go generate' pre-build hook --- .goreleaser.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index d97bd0ba..0bd68804 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -3,7 +3,6 @@ version: 2 before: hooks: - go mod tidy - - go generate ./... builds: - env: @@ -11,7 +10,8 @@ builds: goos: - linux - windows - # - darwin + hooks: + pre: go generate ./... archives: - name_template: >- From 6daa375627dc1a606eac4d45a7300be9f25bfd30 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Mon, 26 Aug 2024 11:43:23 +0200 Subject: [PATCH 5/5] [-] add Windows suffix to `ziphlapi.go` --- iphlpapi/ziphlapi_windows.go | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 iphlpapi/ziphlapi_windows.go diff --git a/iphlpapi/ziphlapi_windows.go b/iphlpapi/ziphlapi_windows.go new file mode 100644 index 00000000..be514764 --- /dev/null +++ b/iphlpapi/ziphlapi_windows.go @@ -0,0 +1,61 @@ +// Code generated by 'go generate'; DO NOT EDIT. + +package iphlpapi + +import ( + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +var _ unsafe.Pointer + +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) + errERROR_EINVAL error = syscall.EINVAL +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return errERROR_EINVAL + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + +var ( + modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll") + + procAddIPAddress = modiphlpapi.NewProc("AddIPAddress") + procDeleteIPAddress = modiphlpapi.NewProc("DeleteIPAddress") +) + +func AddIPAddress(Address uint32, IpMask uint32, IfIndex uint32, NTEContext *uint32, NTEInstance *uint32) (errcode error) { + r0, _, _ := syscall.Syscall6(procAddIPAddress.Addr(), 5, uintptr(Address), uintptr(IpMask), uintptr(IfIndex), uintptr(unsafe.Pointer(NTEContext)), uintptr(unsafe.Pointer(NTEInstance)), 0) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func DeleteIPAddress(NTEContext uint32) (errcode error) { + r0, _, _ := syscall.Syscall(procDeleteIPAddress.Addr(), 1, uintptr(NTEContext), 0, 0) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +}