From 5ff87d7bfdb95967279073074ad0ef6f473f3e5c Mon Sep 17 00:00:00 2001 From: Lionel Jouin Date: Tue, 28 Nov 2023 16:53:30 +0000 Subject: [PATCH 1/4] unix: add Netfilter and NFTables constants Fixes golang/go#64426 Change-Id: I7332f73e27396d187ed63715100af299a949eaf9 GitHub-Last-Rev: a6b267b590ec1d0c2a5b04517790fa7968bdb895 GitHub-Pull-Request: golang/sys#182 Reviewed-on: https://go-review.googlesource.com/c/sys/+/545495 Auto-Submit: Tobias Klauser Reviewed-by: Tobias Klauser Run-TryBot: Tobias Klauser LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Mauri de Souza Meneguzzo TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- unix/mkerrors.sh | 22 ++++++++++++++++++ unix/zerrors_linux.go | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 6202638bae..12f6d2dc01 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -248,6 +248,7 @@ struct ltchars { #include #include #include +#include #include #include #include @@ -324,6 +325,24 @@ struct ltchars { // and netinet/in.h included via net/route.h above. #define IPPROTO_L2TP 115 +// Copied from linux/netfilter/nf_nat.h +// Including linux/netfilter/nf_nat.h here causes conflicts between linux/in.h +// and netinet/in.h. +#define NF_NAT_RANGE_MAP_IPS (1 << 0) +#define NF_NAT_RANGE_PROTO_SPECIFIED (1 << 1) +#define NF_NAT_RANGE_PROTO_RANDOM (1 << 2) +#define NF_NAT_RANGE_PERSISTENT (1 << 3) +#define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4) +#define NF_NAT_RANGE_PROTO_OFFSET (1 << 5) +#define NF_NAT_RANGE_NETMAP (1 << 6) +#define NF_NAT_RANGE_PROTO_RANDOM_ALL \ + (NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY) +#define NF_NAT_RANGE_MASK \ + (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED | \ + NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PERSISTENT | \ + NF_NAT_RANGE_PROTO_RANDOM_FULLY | NF_NAT_RANGE_PROTO_OFFSET | \ + NF_NAT_RANGE_NETMAP) + // Copied from linux/hid.h. // Keep in sync with the size of the referenced fields. #define _HIDIOCGRAWNAME_LEN 128 // sizeof_field(struct hid_device, name) @@ -603,6 +622,9 @@ ccflags="$@" $2 ~ /^FSOPT_/ || $2 ~ /^WDIO[CFS]_/ || $2 ~ /^NFN/ || + $2 !~ /^NFT_META_IIFTYPE/ && + $2 ~ /^NFT_/ || + $2 ~ /^NF_NAT_/ || $2 ~ /^XDP_/ || $2 ~ /^RWF_/ || $2 ~ /^(HDIO|WIN|SMART)_/ || diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index c73cfe2f10..a5d3ff8df9 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -2127,6 +2127,60 @@ const ( NFNL_SUBSYS_QUEUE = 0x3 NFNL_SUBSYS_ULOG = 0x4 NFS_SUPER_MAGIC = 0x6969 + NFT_CHAIN_FLAGS = 0x7 + NFT_CHAIN_MAXNAMELEN = 0x100 + NFT_CT_MAX = 0x17 + NFT_DATA_RESERVED_MASK = 0xffffff00 + NFT_DATA_VALUE_MAXLEN = 0x40 + NFT_EXTHDR_OP_MAX = 0x4 + NFT_FIB_RESULT_MAX = 0x3 + NFT_INNER_MASK = 0xf + NFT_LOGLEVEL_MAX = 0x8 + NFT_NAME_MAXLEN = 0x100 + NFT_NG_MAX = 0x1 + NFT_OBJECT_CONNLIMIT = 0x5 + NFT_OBJECT_COUNTER = 0x1 + NFT_OBJECT_CT_EXPECT = 0x9 + NFT_OBJECT_CT_HELPER = 0x3 + NFT_OBJECT_CT_TIMEOUT = 0x7 + NFT_OBJECT_LIMIT = 0x4 + NFT_OBJECT_MAX = 0xa + NFT_OBJECT_QUOTA = 0x2 + NFT_OBJECT_SECMARK = 0x8 + NFT_OBJECT_SYNPROXY = 0xa + NFT_OBJECT_TUNNEL = 0x6 + NFT_OBJECT_UNSPEC = 0x0 + NFT_OBJ_MAXNAMELEN = 0x100 + NFT_OSF_MAXGENRELEN = 0x10 + NFT_QUEUE_FLAG_BYPASS = 0x1 + NFT_QUEUE_FLAG_CPU_FANOUT = 0x2 + NFT_QUEUE_FLAG_MASK = 0x3 + NFT_REG32_COUNT = 0x10 + NFT_REG32_SIZE = 0x4 + NFT_REG_MAX = 0x4 + NFT_REG_SIZE = 0x10 + NFT_REJECT_ICMPX_MAX = 0x3 + NFT_RT_MAX = 0x4 + NFT_SECMARK_CTX_MAXLEN = 0x100 + NFT_SET_MAXNAMELEN = 0x100 + NFT_SOCKET_MAX = 0x3 + NFT_TABLE_F_MASK = 0x3 + NFT_TABLE_MAXNAMELEN = 0x100 + NFT_TRACETYPE_MAX = 0x3 + NFT_TUNNEL_F_MASK = 0x7 + NFT_TUNNEL_MAX = 0x1 + NFT_TUNNEL_MODE_MAX = 0x2 + NFT_USERDATA_MAXLEN = 0x100 + NFT_XFRM_KEY_MAX = 0x6 + NF_NAT_RANGE_MAP_IPS = 0x1 + NF_NAT_RANGE_MASK = 0x7f + NF_NAT_RANGE_NETMAP = 0x40 + NF_NAT_RANGE_PERSISTENT = 0x8 + NF_NAT_RANGE_PROTO_OFFSET = 0x20 + NF_NAT_RANGE_PROTO_RANDOM = 0x4 + NF_NAT_RANGE_PROTO_RANDOM_ALL = 0x14 + NF_NAT_RANGE_PROTO_RANDOM_FULLY = 0x10 + NF_NAT_RANGE_PROTO_SPECIFIED = 0x2 NILFS_SUPER_MAGIC = 0x3434 NL0 = 0x0 NL1 = 0x100 From f0c7190c5ee2c4ec638b0e505866bb6456fc83c4 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 20 Dec 2023 14:46:10 +0000 Subject: [PATCH 2/4] unix: remove extra trailing newlines in zsyscall_openbsd_*.go These newlines are written by mksyscall.go but should not appear in the final generated files once the output is passed through gofmt. This is done by mkall.sh but I had written a custom script just to generate these openbsd zsyscall files in CL 468095. Running the mksyscall.go output through gofmt fixes this issue. Fixes golang/go#64820 Change-Id: I1b1bf55145bd5a5208e091ded24a973f953c479f GitHub-Last-Rev: 514272bd56a9bfbcf1ff1e787aece426e235da37 GitHub-Pull-Request: golang/sys#183 Reviewed-on: https://go-review.googlesource.com/c/sys/+/551715 Reviewed-by: Tobias Klauser Reviewed-by: Carlos Amedee Run-TryBot: Jorropo TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh LUCI-TryBot-Result: Go LUCI --- unix/zsyscall_openbsd_386.go | 2 -- unix/zsyscall_openbsd_amd64.go | 2 -- unix/zsyscall_openbsd_arm.go | 2 -- unix/zsyscall_openbsd_arm64.go | 2 -- unix/zsyscall_openbsd_mips64.go | 2 -- unix/zsyscall_openbsd_ppc64.go | 2 -- unix/zsyscall_openbsd_riscv64.go | 2 -- 7 files changed, 14 deletions(-) diff --git a/unix/zsyscall_openbsd_386.go b/unix/zsyscall_openbsd_386.go index a1d061597c..9dc42410b7 100644 --- a/unix/zsyscall_openbsd_386.go +++ b/unix/zsyscall_openbsd_386.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - diff --git a/unix/zsyscall_openbsd_amd64.go b/unix/zsyscall_openbsd_amd64.go index 5b2a740977..0d3a0751cd 100644 --- a/unix/zsyscall_openbsd_amd64.go +++ b/unix/zsyscall_openbsd_amd64.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - diff --git a/unix/zsyscall_openbsd_arm.go b/unix/zsyscall_openbsd_arm.go index f6eda1344a..c39f7776db 100644 --- a/unix/zsyscall_openbsd_arm.go +++ b/unix/zsyscall_openbsd_arm.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - diff --git a/unix/zsyscall_openbsd_arm64.go b/unix/zsyscall_openbsd_arm64.go index 55df20ae9d..57571d072f 100644 --- a/unix/zsyscall_openbsd_arm64.go +++ b/unix/zsyscall_openbsd_arm64.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - diff --git a/unix/zsyscall_openbsd_mips64.go b/unix/zsyscall_openbsd_mips64.go index 8c1155cbc0..e62963e67e 100644 --- a/unix/zsyscall_openbsd_mips64.go +++ b/unix/zsyscall_openbsd_mips64.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - diff --git a/unix/zsyscall_openbsd_ppc64.go b/unix/zsyscall_openbsd_ppc64.go index 7cc80c58d9..00831354c8 100644 --- a/unix/zsyscall_openbsd_ppc64.go +++ b/unix/zsyscall_openbsd_ppc64.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - diff --git a/unix/zsyscall_openbsd_riscv64.go b/unix/zsyscall_openbsd_riscv64.go index 0688737f49..79029ed584 100644 --- a/unix/zsyscall_openbsd_riscv64.go +++ b/unix/zsyscall_openbsd_riscv64.go @@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) { var libc_unveil_trampoline_addr uintptr //go:cgo_import_dynamic libc_unveil unveil "libc.so" - - From 32cdffc66120e843f9768b765d98b513ce77d6a7 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 22 Dec 2023 13:28:28 +0100 Subject: [PATCH 3/4] unix: don't redefine constants already defined in glibc headers These are all present in glibc 2.37 which is currently used to generate these constants. Change-Id: I3ffbd8f8581e85e8854222ad3f2c7f44aac106c7 Reviewed-on: https://go-review.googlesource.com/c/sys/+/552417 Reviewed-by: David Chase Auto-Submit: Tobias Klauser Reviewed-by: Matt Layher LUCI-TryBot-Result: Go LUCI Reviewed-by: Than McIntosh --- unix/mkerrors.sh | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 12f6d2dc01..c6492020ec 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -284,10 +284,6 @@ struct ltchars { #include #endif -#ifndef MSG_FASTOPEN -#define MSG_FASTOPEN 0x20000000 -#endif - #ifndef PTRACE_GETREGS #define PTRACE_GETREGS 0xc #endif @@ -296,14 +292,6 @@ struct ltchars { #define PTRACE_SETREGS 0xd #endif -#ifndef SOL_NETLINK -#define SOL_NETLINK 270 -#endif - -#ifndef SOL_SMC -#define SOL_SMC 286 -#endif - #ifdef SOL_BLUETOOTH // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h // but it is already in bluetooth_linux.go @@ -320,11 +308,6 @@ struct ltchars { #undef TIPC_WAIT_FOREVER #define TIPC_WAIT_FOREVER 0xffffffff -// Copied from linux/l2tp.h -// Including linux/l2tp.h here causes conflicts between linux/in.h -// and netinet/in.h included via net/route.h above. -#define IPPROTO_L2TP 115 - // Copied from linux/netfilter/nf_nat.h // Including linux/netfilter/nf_nat.h here causes conflicts between linux/in.h // and netinet/in.h. From 0829ab15b6946f47c40012db2e0c04772730317d Mon Sep 17 00:00:00 2001 From: Kanak Agrawal Date: Wed, 9 Aug 2023 11:53:20 +0530 Subject: [PATCH 4/4] windows: add SetFileValidData Fixes golang/go#61834 Change-Id: Iaff01f5662aa2309e8ac41b346e0d3a42d28af91 Reviewed-on: https://go-review.googlesource.com/c/sys/+/517575 Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Reviewed-by: Alex Brainman TryBot-Result: Gopher Robot Run-TryBot: Quim Muntal Reviewed-by: Quim Muntal Reviewed-by: Keith Randall --- windows/syscall_windows.go | 1 + windows/zsyscall_windows.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 47dc579676..ffb8708ccf 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -194,6 +194,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys GetComputerName(buf *uint16, n *uint32) (err error) = GetComputerNameW //sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW //sys SetEndOfFile(handle Handle) (err error) +//sys SetFileValidData(handle Handle, validDataLength int64) (err error) //sys GetSystemTimeAsFileTime(time *Filetime) //sys GetSystemTimePreciseAsFileTime(time *Filetime) //sys GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) [failretval==0xffffffff] diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 146a1f0196..e8791c82c3 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -342,6 +342,7 @@ var ( procSetDefaultDllDirectories = modkernel32.NewProc("SetDefaultDllDirectories") procSetDllDirectoryW = modkernel32.NewProc("SetDllDirectoryW") procSetEndOfFile = modkernel32.NewProc("SetEndOfFile") + procSetFileValidData = modkernel32.NewProc("SetFileValidData") procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW") procSetErrorMode = modkernel32.NewProc("SetErrorMode") procSetEvent = modkernel32.NewProc("SetEvent") @@ -2988,6 +2989,14 @@ func SetEndOfFile(handle Handle) (err error) { return } +func SetFileValidData(handle Handle, validDataLength int64) (err error) { + r1, _, e1 := syscall.Syscall(procSetFileValidData.Addr(), 2, uintptr(handle), uintptr(validDataLength), 0) + if r1 == 0 { + err = errnoErr(e1) + } + return +} + func SetEnvironmentVariable(name *uint16, value *uint16) (err error) { r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0) if r1 == 0 {