From 226e7d32cb855e69b3bf7a28791a17235074e49a Mon Sep 17 00:00:00 2001 From: Ghanan Gowripalan Date: Mon, 13 Sep 2021 19:40:40 -0700 Subject: Accept packets destined to bound address ...if bound to an address. We previously checked the source of a packet instead of the destination of a packet when bound to an address. PiperOrigin-RevId: 396497647 --- pkg/tcpip/transport/raw/endpoint.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'pkg') diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index 3bf6c0a8f..4a5858bdd 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -562,8 +562,6 @@ func (e *endpoint) HandlePacket(pkt *stack.PacketBuffer) { return } - remoteAddr := pkt.Network().SourceAddress() - if e.bound { // If bound to a NIC, only accept data for that NIC. if e.BindNICID != 0 && e.BindNICID != pkt.NICID { @@ -572,16 +570,17 @@ func (e *endpoint) HandlePacket(pkt *stack.PacketBuffer) { return } // If bound to an address, only accept data for that address. - if e.BindAddr != "" && e.BindAddr != remoteAddr { + if e.BindAddr != "" && e.BindAddr != pkt.Network().DestinationAddress() { e.rcvMu.Unlock() e.mu.RUnlock() return } } + srcAddr := pkt.Network().SourceAddress() // If connected, only accept packets from the remote address we // connected to. - if e.connected && e.route.RemoteAddress() != remoteAddr { + if e.connected && e.route.RemoteAddress() != srcAddr { e.rcvMu.Unlock() e.mu.RUnlock() return @@ -593,7 +592,7 @@ func (e *endpoint) HandlePacket(pkt *stack.PacketBuffer) { packet := &rawPacket{ senderAddr: tcpip.FullAddress{ NIC: pkt.NICID, - Addr: remoteAddr, + Addr: srcAddr, }, } -- cgit v1.2.3