Skip to content

Commit

Permalink
netstack: add log for martian packet dropping
Browse files Browse the repository at this point in the history
Martian packets are dropped by default, but some setups require accepting them.
A rate limited log will help users quickly hone in on the issue, which is
otherwise unclear and time-consuming to debug.

PiperOrigin-RevId: 693487838
  • Loading branch information
kevinGC authored and gvisor-bot committed Nov 5, 2024
1 parent 8b5a0b0 commit ce727c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/tcpip/network/ipv4/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
deps = [
"//pkg/atomicbitops",
"//pkg/buffer",
"//pkg/log",
"//pkg/sync",
"//pkg/tcpip",
"//pkg/tcpip/checksum",
Expand Down
5 changes: 5 additions & 0 deletions pkg/tcpip/network/ipv4/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"gvisor.dev/gvisor/pkg/atomicbitops"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
Expand Down Expand Up @@ -69,6 +70,8 @@ const (
forwardingEnabled = 1
)

var martianPacketLogger = log.BasicRateLimitedLogger(time.Minute)

var ipv4BroadcastAddr = header.IPv4Broadcast.WithPrefix()

var _ stack.LinkResolvableNetworkEndpoint = (*endpoint)(nil)
Expand Down Expand Up @@ -839,11 +842,13 @@ func (e *endpoint) HandlePacket(pkt *stack.PacketBuffer) {
if !e.nic.IsLoopback() {
if !e.protocol.options.AllowExternalLoopbackTraffic {
if header.IsV4LoopbackAddress(h.SourceAddress()) {
martianPacketLogger.Infof("Martian packet dropped with loopback source address. If your traffic is unexpectedly dropped, you may want to allow martian packets.")
stats.InvalidSourceAddressesReceived.Increment()
return
}

if header.IsV4LoopbackAddress(h.DestinationAddress()) {
martianPacketLogger.Infof("Martian packet dropped with loopback destination address. If your traffic is unexpectedly dropped, you may want to allow martian packets.")
stats.InvalidDestinationAddressesReceived.Increment()
return
}
Expand Down

0 comments on commit ce727c3

Please sign in to comment.