Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: missing socket constants #53557

Closed
AlonZivony opened this issue Jun 26, 2022 · 9 comments
Closed

x/sys/unix: missing socket constants #53557

AlonZivony opened this issue Jun 26, 2022 · 9 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@AlonZivony
Copy link

What version of Go are you using (go version)?

$ go version 1.18.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/alonz/.cache/go-build"
GOENV="/home/alonz/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/alonz/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/alonz/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/alonz/go/src/libbpfgo/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1901468926=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I am using the x/sys/unix pacakge.
I want to support all possible socket level and optname values for the setsocketopt syscall, but some of the values have no constants (because they are from newer kernel versions).

The following values are missing:

  • level:

    • SOL_MCTCP
    • SOL_MCTP
    • SOL_SMC
  • optname:

    • SO_NETNS_COOKIE
    • SO_BUF_LOCK
    • SO_RESERVE_MEM
    • SO_TXREHASH

What did you expect to see?

I want to use the values like the following - unix.SOL_MCTCP.

@gopherbot gopherbot added this to the Unreleased milestone Jun 26, 2022
@seankhliao seankhliao changed the title x/sys: Missing socket constants x/sys/unix: Missing socket constants Jun 26, 2022
@seankhliao
Copy link
Member

From https://pkg.go.dev/golang.org/x/sys/unix the only ones I see missing are "SOL_MCTCP" and "SOL_SMC", but I also don't see "SOL_MCTCP" mentioned anywhere on the internet at all?

@ianlancetaylor ianlancetaylor changed the title x/sys/unix: Missing socket constants x/sys/unix: missing socket constants Jun 26, 2022
@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 26, 2022
@AlonZivony
Copy link
Author

You are right, it seems that the optname values are available in the newest version.
About the missing level values - you can see that they are supported by the newest kernel in the following source code page - https://elixir.bootlin.com/linux/latest/source/include/linux/socket.h#L330

@tklauser
Copy link
Member

I assume you meant SOL_MPTCP, not SOL_MCTCP?

All but SOL_SMC should be in latest tip of the package:

% git grep -E "SOL_(MPTCP|MCTP|SMC)"
zerrors_linux.go:2583:  SOL_MCTP                                    = 0x11d
zerrors_linux.go:2584:  SOL_MPTCP                                   = 0x11c

It seems we generate these constants from glibc's sys/socket.h, and glibc 2.35 which we currently use to generate the constants doesn't seem to have SOL_SMC yet. If we want SOL_SMC now, without waiting for a glibc version providing it, we could probably add it similarly to how SOL_NETLINK is defined: https://cs.opensource.google/go/x/sys/+/87e55d71:unix/mkerrors.sh;l=294-296

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
@gopherbot
Copy link

Change https://go.dev/cl/417994 mentions this issue: unix: add socket constants

@ianwoolf
Copy link
Contributor

Do the following source code pages support the missing optname? I send a cl according to the following code.

https://elixir.bootlin.com/linux/latest/source/include/uapi/asm-generic/socket.h#L125

@ianwoolf
Copy link
Contributor

I assume you meant SOL_MPTCP, not SOL_MCTCP?

All but SOL_SMC should be in latest tip of the package:

% git grep -E "SOL_(MPTCP|MCTP|SMC)"
zerrors_linux.go:2583:  SOL_MCTP                                    = 0x11d
zerrors_linux.go:2584:  SOL_MPTCP                                   = 0x11c

It seems we generate these constants from glibc's sys/socket.h, and glibc 2.35 which we currently use to generate the constants doesn't seem to have SOL_SMC yet. If we want SOL_SMC now, without waiting for a glibc version providing it, we could probably add it similarly to how SOL_NETLINK is defined: https://cs.opensource.google/go/x/sys/+/87e55d71:unix/mkerrors.sh;l=294-296

the level add to glibc at the following commit

glibc 2.35 not contain these commit. So glibc 2.35 which we currently use to generate the constants doesn't have SOL_SMC SOL_MPTCP and SOL_MCTP yet.

Do we need to wait for glibc to release?

@ianlancetaylor

@ianlancetaylor
Copy link
Contributor

We don't have to wait for glibc. But we do need to ensure that anything we do is correct for all supported operating systems. I'm frankly pretty skeptical about the SOL_NETLINK code mentioned above.

@tklauser
Copy link
Member

We don't have to wait for glibc. But we do need to ensure that anything we do is correct for all supported operating systems. I'm frankly pretty skeptical about the SOL_NETLINK code mentioned above.

Note that SOL_NETLINK is defined in includes_Linux i.e. it is only defined for Linux where its value (and the other values defined in that section) seem to be the same for all Linux architectures. I think this is the case too for SOL_MPTCP anc SOL_MCTP.

@ianlancetaylor
Copy link
Contributor

Argh, I totally missed that. Thanks. This approach seems fine.

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 21, 2022
@golang golang locked and limited conversation to collaborators Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants