Skip to content

Commit

Permalink
p2p/discover: unwrap 4-in-6 UDP source addresses (ethereum#29944)
Browse files Browse the repository at this point in the history
Fixes an issue where discovery responses were not recognized.
  • Loading branch information
fjl authored and jorgemmsilva committed Jun 17, 2024
1 parent 1f8d07d commit d3b32d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions p2p/discover/v4_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ func (t *UDPv4) readLoop(unhandled chan<- ReadPacket) {
}

func (t *UDPv4) handlePacket(from netip.AddrPort, buf []byte) error {
// Unwrap IPv4-in-6 source address.
if from.Addr().Is4In6() {
from = netip.AddrPortFrom(netip.AddrFrom4(from.Addr().As4()), from.Port())
}

rawpacket, fromKey, hash, err := v4wire.Decode(buf)
if err != nil {
t.log.Debug("Bad discv4 packet", "addr", from, "err", err)
Expand Down
4 changes: 4 additions & 0 deletions p2p/discover/v5_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ func (t *UDPv5) readLoop() {

// dispatchReadPacket sends a packet into the dispatch loop.
func (t *UDPv5) dispatchReadPacket(from netip.AddrPort, content []byte) bool {
// Unwrap IPv4-in-6 source address.
if from.Addr().Is4In6() {
from = netip.AddrPortFrom(netip.AddrFrom4(from.Addr().As4()), from.Port())
}
select {
case t.packetInCh <- ReadPacket{content, from}:
return true
Expand Down

0 comments on commit d3b32d6

Please sign in to comment.