Skip to content

net, x/net/route: ParseRIB fail to parse utun up InterfaceMessage #71064

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

Closed
ruokeqx opened this issue Dec 30, 2024 · 9 comments
Closed

net, x/net/route: ParseRIB fail to parse utun up InterfaceMessage #71064

ruokeqx opened this issue Dec 30, 2024 · 9 comments
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ruokeqx
Copy link

ruokeqx commented Dec 30, 2024

Go version

go version go1.22.6 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/ruokeqx/Library/Caches/go-build'
GOENV='/Users/ruokeqx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/ruokeqx/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/ruokeqx/go'
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/opt/go1.22'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/opt/go1.22/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/d8/c7cqtvp515v7tn7xmvv6v2m00000gn/T/go-build3070326303=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

try parse message from AF_ROUTE socket.

unix.Socket(unix.AF_ROUTE, unix.SOCK_RAW, unix.AF_UNSPEC)
msgs, err := route.ParseRIB(route.RIBTypeRoute, data[:n])

What did you see happen?

ParseRIB skip Interface message that indicate utun interface up

// data fetch from AF_ROUTE socket
data := []byte{112, 0, 5, 14, 0, 0, 0, 0, 81, 128, 0, 0, 28, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 220, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 237, 0, 107, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

since no RTA_IFP flag

func (w *wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
...
	if attrs&syscall.RTA_IFP == 0 {
		return nil, nil
	}
...
}

not sure if it is intended

What did you expect to see?

should return InterfaceMessage with Index and flags?

@dmitshur
Copy link
Contributor

CC @neild, @ianlancetaylor.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 30, 2024
@dmitshur dmitshur added this to the Unreleased milestone Dec 30, 2024
@ianlancetaylor
Copy link
Member

Currently the code ensures that m.Name is set in the returned InterfaceMessage. If we permit a message for which RTA_IFP is not set, then the Name field won't be set. In the standard library's net package, that in turn will mean returning a value of type net.Interface for which the Name field is not set. How should programs handle an unnamed interface? Why is the name not being returned?

@gabyhelp
Copy link

gabyhelp commented Jan 2, 2025

We've identified some possible problems with your issue report. Please review
these findings and fix any that you think are appropriate to fix.

  • The issue should provide a complete, runnable program to reproduce the issue.

I'm just a bot; you probably know better than I do whether these findings really need fixing.
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@ruokeqx
Copy link
Author

ruokeqx commented Jan 8, 2025

Currently the code ensures that m.Name is set in the returned InterfaceMessage. If we permit a message for which RTA_IFP is not set, then the Name field won't be set. In the standard library's net package, that in turn will mean returning a value of type net.Interface for which the Name field is not set. How should programs handle an unnamed interface? Why is the name not being returned?

Hi, this message can be easily reproduced in my mbp(macOS 15.2).

  1. go run main.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

func main() {
	routeSocket, err := unix.Socket(unix.AF_ROUTE, unix.SOCK_RAW, unix.AF_UNSPEC)
	if err != nil {
		return
	}

	data := make([]byte, os.Getpagesize())
	for {
		n, err := unix.Read(routeSocket, data)
		if err != nil {
			return
		}

		if data[3] != unix.RTM_IFINFO {
			continue
		}

		fmt.Printf("%d:%v\n", n, data[:n])
	}
}
  1. sudo ifconfig utun0 mtu 1500 up

BTW, i have test for many times in my mbp, all message from NET_RT_IFLIST with RTM_IFINFO type has RTA_IFP, not guarantee in all platform.

Maybe filter work should after getting interfaceMessages in standard library? ParseRIB itself just return basic message

@ianlancetaylor
Copy link
Member

What does the ifconfig program print for the interface? Does it give it a name?

@ruokeqx
Copy link
Author

ruokeqx commented Jan 9, 2025

What does the ifconfig program print for the interface? Does it give it a name?

ifconfig print nothing, it didn't give interface a name. utun0 exists when the system starts, it already has a name.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/641855 mentions this issue: net: permit Interface with no Name

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 9, 2025
@dmitshur dmitshur changed the title x/net/route: ParseRIB fail to parse utun up InterfaceMessage net, x/net/route: ParseRIB fail to parse utun up InterfaceMessage Feb 3, 2025
@dmitshur dmitshur modified the milestones: Unreleased, Go1.25 Feb 3, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/646675 mentions this issue: net: ignore unnamed interfaces in some cases on DragonFly

gopherbot pushed a commit that referenced this issue Feb 5, 2025
On DragonFly it seems that we can see an unnamed interface,
but be unable to retrieve it. Skip unnamed interface cases.

For #71064

Change-Id: Ie9af74bd656d403ddc19cc5f14062cd8e0fa2571
Reviewed-on: https://go-review.googlesource.com/c/go/+/646675
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Commit-Queue: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants