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/net/icmp: Hogs CPU on Windows, doesn't capture packets #33117

Open
noam09 opened this issue Jul 15, 2019 · 3 comments
Open

x/net/icmp: Hogs CPU on Windows, doesn't capture packets #33117

noam09 opened this issue Jul 15, 2019 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@noam09
Copy link

noam09 commented Jul 15, 2019

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

$ go version
go version go1.12.7 windows/amd64

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
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\bob\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\bob\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\bob\AppData\Local\Temp\go-build347592694=/tmp/go-build -gno-record-gcc-switchesv

What did you do?

I would like to receive all incoming ICMP packets and their payload/message, and once I am able to do that I would like to filter said packets so only specific IP sources and/or payloads/messages are captured and logged.
I would like this to work on both Linux and Windows, but at the moment I am experiencing issues specifically on Windows (works as expected on Linux). Tested on a Window 7 64-bit virtual machine on VirtualBox (running on Arch Linux).

I'm using the code found in the accepted answer for this StackOverflow question, with slight alterations:
https://stackoverflow.com/questions/33345683/how-to-listen-for-icmp-packets

My code (running as Admin):
https://play.golang.org/p/RmuJmXgLKJk

I've replaced the IP address in ListenPacket() to the local address of the virtual machine on which I would like to log incoming ICMP packets (192.168.0.111 in Playground link, also tried 0.0.0.0).

I've also added if sourceIP == nil { continue } so that only ICMP packets containing a source IP are displayed. Without this condition, I was seeing infinite logs displaying an empty message and nil source address.

When I ping the virtual machine on which this code is running, the program does not display any messages. Also, the program uses up a lot of CPU (%90-%99) and the machine almost freezes up.

What did you expect to see?

Logs of ICMP packets with source IP and message. Minimal CPU usage.

What did you see instead?

With if sourceIP == nil { continue }: No logs, program hogs CPU ~%98.
Without if sourceIP == nil { continue }: Infinite logs, program uses %10-%20 CPU.

@gopherbot gopherbot added this to the Unreleased milestone Jul 15, 2019
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 15, 2019
@dmitshur
Copy link
Contributor

/cc @mikioh @ianlancetaylor per owners.

@VladRico
Copy link

VladRico commented Jul 19, 2019

Hello !
Same issue here with quite the same piece of code.

Running on Windows 10, icmp.ListenPacket(...) doesn't log icmp packet from original ping command (from Windows or Linux) but log icmp packet from https://github.com/sparrc/go-ping.

It seems to only log manually crafted icmp packet, not original ones ?

I've attached pcap files with different ping command :
icmp_pcap.zip

  • git_windowstolinux.pcap : original ping command from host (Windows 10 to linux) --> Not logged
  • git_linuxtowidnows.pcap : original ping command from Linux to the host --> Not logged
  • git_modifiedwintolinux.pcap: custom ping from https://github.com/sparrc/go-ping. --> Logged by icmp.ListenPacket

NB: Don't take care about IP addresses, I've made a classic echo-request / echo-reply capture

No CPU issue on native Windows 10
No issue on Linux (Debian 9 Stretch), work as expected

@noam09
Copy link
Author

noam09 commented Jul 21, 2019

@Valcada thanks for the detailed info. Glad to know it's not just me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants