Skip to content

Commit 8090bc4

Browse files
committed
Merge pull request #11609 from Amaindex:master
PiperOrigin-RevId: 753253721
2 parents e5f3875 + 868dfbc commit 8090bc4

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

pkg/tcpip/network/ipv4/icmp.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,20 @@ func (e *endpoint) handleICMP(pkt *stack.PacketBuffer) {
356356
replyData := stack.PayloadSince(pkt.TransportHeader())
357357
defer replyData.Release()
358358
ipHdr := header.IPv4(pkt.NetworkHeader().Slice())
359+
localAddressTemporary := pkt.NetworkPacketInfo.LocalAddressTemporary
359360
localAddressBroadcast := pkt.NetworkPacketInfo.LocalAddressBroadcast
360361

361-
// It's possible that a raw socket expects to receive this.
362+
// It's possible that a raw socket or custom defaultHandler expects to
363+
// receive this packet.
362364
e.dispatcher.DeliverTransportPacket(header.ICMPv4ProtocolNumber, pkt)
363365
pkt = nil
364366

367+
// Skip direct ICMP echo reply if the packet was received with a temporary
368+
// address, allowing custom handlers to take over.
369+
if localAddressTemporary {
370+
return
371+
}
372+
365373
sent := e.stats.icmp.packetsSent
366374
if !e.protocol.allowICMPReply(header.ICMPv4EchoReply, header.ICMPv4UnusedCode) {
367375
sent.rateLimited.Increment()

pkg/tcpip/network/ipv4/ipv4.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ func (e *endpoint) handleValidatedPacket(h header.IPv4, pkt *stack.PacketBuffer,
11691169
// If the packet is destined for this device, then it should be delivered
11701170
// locally. Otherwise, if forwarding is enabled, it should be forwarded.
11711171
if addressEndpoint := e.AcquireAssignedAddress(dstAddr, e.nic.Promiscuous(), stack.CanBePrimaryEndpoint, true /* readOnly */); addressEndpoint != nil {
1172+
pkt.NetworkPacketInfo.LocalAddressTemporary = addressEndpoint.Temporary()
11721173
subnet := addressEndpoint.AddressWithPrefix().Subnet()
11731174
pkt.NetworkPacketInfo.LocalAddressBroadcast = subnet.IsBroadcast(dstAddr) || dstAddr == header.IPv4Broadcast
11741175
e.deliverPacketLocally(h, pkt, inNICName)

pkg/tcpip/stack/addressable_endpoint_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func (a *AddressableEndpointState) AcquireAssignedAddressOrMatching(localAddr tc
602602

603603
// Proceed to add a new temporary endpoint.
604604
addr := localAddr.WithPrefix()
605-
ep, err := a.addAndAcquireAddressLocked(addr, AddressProperties{PEB: tempPEB}, Temporary)
605+
ep, err := a.addAndAcquireAddressLocked(addr, AddressProperties{PEB: tempPEB, Temporary: true}, Temporary)
606606
if err != nil {
607607
// addAndAcquireAddressLocked only returns an error if the address is
608608
// already assigned but we just checked above if the address exists so we

pkg/tcpip/stack/registration.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ type NetworkPacketInfo struct {
5858
// address.
5959
LocalAddressBroadcast bool
6060

61+
// LocalAddressTemporary is true if the packet's local address is a temporary
62+
// address.
63+
LocalAddressTemporary bool
64+
6165
// IsForwardedPacket is true if the packet is being forwarded.
6266
IsForwardedPacket bool
6367
}

0 commit comments

Comments
 (0)