mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: add log for martian packet dropping
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
This commit is contained in:
committed by
gVisor bot
parent
8b5a0b0614
commit
ce727c3fc5
@@ -17,6 +17,7 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/atomicbitops",
|
||||
"//pkg/buffer",
|
||||
"//pkg/log",
|
||||
"//pkg/sync",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/checksum",
|
||||
|
||||
@@ -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"
|
||||
@@ -69,6 +70,8 @@ const (
|
||||
forwardingEnabled = 1
|
||||
)
|
||||
|
||||
var martianPacketLogger = log.BasicRateLimitedLogger(time.Minute)
|
||||
|
||||
var ipv4BroadcastAddr = header.IPv4Broadcast.WithPrefix()
|
||||
|
||||
var _ stack.LinkResolvableNetworkEndpoint = (*endpoint)(nil)
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user