Open lubronzhan opened 2 weeks ago
go version go1.22.0 darwin/amd64
go env
GO111MODULE='on' GOARCH='amd64' GOBIN='' GOCACHE='/Users/lzhan/Library/Caches/go-build' GOENV='/Users/lzhan/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/lzhan/work/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/Users/lzhan/work' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/opt/go/libexec' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/opt/go/libexec/pkg/tool/darwin_amd64' GOVCS='' GOVERSION='go1.22.0' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='cc' CXX='c++' CGO_ENABLED='1' GOMOD='/dev/null' 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/yz/2cfkf6v56cg_p1srf2dsk6pm0000gp/T/go-build2040811365=/tmp/go-build -gno-record-gcc-switches -fno-common' ~/work/src/gitlab.eng.vmware.com/TKG/bolt/yaml topic/lubron
I followed this example and wrote a simple program to subscribe netlink message using syscall.ParseNetlinkMessage But the pid of the message is always 0
package main import ( "fmt" "syscall" ) func main() { l, _ := ListenNetlink() for { msgs, err := l.ReadMsgs() if err != nil { fmt.Println("Could not read netlink: %s", err) } for _, m := range msgs { fmt.Println(m.Header.Pid) } } } type NetlinkListener struct { fd int sa *syscall.SockaddrNetlink } func ListenNetlink() (*NetlinkListener, error) { groups := (1 << (syscall.RTNLGRP_LINK - 1)) | (1 << (syscall.RTNLGRP_IPV4_IFADDR - 1)) | (1 << (syscall.RTNLGRP_IPV6_IFADDR - 1)) s, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_DGRAM, syscall.NETLINK_ROUTE) if err != nil { return nil, fmt.Errorf("socket: %s", err) } saddr := &syscall.SockaddrNetlink{ Family: syscall.AF_NETLINK, Pid: uint32(0), Groups: uint32(groups), } err = syscall.Bind(s, saddr) if err != nil { return nil, fmt.Errorf("bind: %s", err) } return &NetlinkListener{fd: s, sa: saddr}, nil } func (l *NetlinkListener) ReadMsgs() ([]syscall.NetlinkMessage, error) { defer func() { recover() }() pkt := make([]byte, 2048) n, err := syscall.Read(l.fd, pkt) if err != nil { return nil, fmt.Errorf("read: %s", err) } msgs, err := syscall.ParseNetlinkMessage(pkt[:n]) if err != nil { return nil, fmt.Errorf("parse: %s", err) } return msgs, nil } }
Then I tried create kubernetes pod on the node, CNI is calico
sender PID is always 0
The pid should be the id of process who sent out the request. For example, in my case it should be calico.
If I use rtmon and extract the message using iproute2, I could see correct pid
rtmon
Just checking: you are reporting that you are using darwin/amd64, but SockaddrNetlink is only defined on Linux.
SockaddrNetlink
Sorry, I compiled using GOOS=linux and GOARCH=amd64. Let me update the description
Go version
go version go1.22.0 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
I followed this example and wrote a simple program to subscribe netlink message using syscall.ParseNetlinkMessage But the pid of the message is always 0
Then I tried create kubernetes pod on the node, CNI is calico
What did you see happen?
sender PID is always 0
What did you expect to see?
The pid should be the id of process who sent out the request. For example, in my case it should be calico.
If I use
rtmon
and extract the message using iproute2, I could see correct pid