filter empty ipv4 and ipv6 ping packet source addresses (#6474)

* add empty ipv4 and ipv6 to the filtered ping packet source addresses

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/6490/head
garyschulte 10 months ago committed by GitHub
parent f125aed72f
commit 98ab26df2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java
  2. 20
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java

@ -75,7 +75,7 @@ public abstract class PeerDiscoveryAgent {
// clients ignore that, so we add in a little extra padding.
private static final int MAX_PACKET_SIZE_BYTES = 1600;
private static final List<String> PING_PACKET_SOURCE_IGNORED =
List.of("127.0.0.1", "255.255.255.255");
List.of("127.0.0.1", "255.255.255.255", "0.0.0.0", "::", "0:0:0:0:0:0:0:0");
protected final List<DiscoveryPeer> bootstrapPeers;
private final List<PeerRequirement> peerRequirements = new CopyOnWriteArrayList<>();

@ -839,15 +839,31 @@ public class PeerDiscoveryAgentTest {
@Test
public void assertHostCorrectlyRevertsOnIgnoredPacketFrom() {
final String sourceHost = "UDP_SOURCE_ORIGIN_HOST";
final String emptyIPv4Host = "0.0.0.0";
final String emptyIPv6Host = "::";
final String localHost = "127.0.0.1";
final String broadcastDefaultHost = "255.255.255.255";
final String routableHost = "50.50.50.50";
Endpoint source = new Endpoint(sourceHost, 30303, Optional.empty());
Endpoint emptyIPv4 = new Endpoint(emptyIPv4Host, 30303, Optional.empty());
Endpoint emptyIPv6 = new Endpoint(emptyIPv6Host, 30303, Optional.empty());
Endpoint endpointLocal = new Endpoint(localHost, 30303, Optional.empty());
Endpoint endpointBroadcast = new Endpoint(broadcastDefaultHost, 30303, Optional.empty());
Endpoint endpointRoutable = new Endpoint(routableHost, 30303, Optional.empty());
Packet mockEmptyIPv4 =
when(mock(Packet.class).getPacketData(any()))
.thenReturn(
Optional.of(
PingPacketData.create(Optional.of(emptyIPv4), endpointLocal, UInt64.ONE)))
.getMock();
Packet mockEmptyIPv6 =
when(mock(Packet.class).getPacketData(any()))
.thenReturn(
Optional.of(
PingPacketData.create(Optional.of(emptyIPv6), endpointLocal, UInt64.ONE)))
.getMock();
Packet mockLocal =
when(mock(Packet.class).getPacketData(any()))
.thenReturn(
@ -869,6 +885,10 @@ public class PeerDiscoveryAgentTest {
Optional.of(endpointRoutable), endpointLocal, UInt64.ONE)))
.getMock();
// assert a pingpacketdata with empty ipv4 address reverts to the udp source host
assertThat(PeerDiscoveryAgent.deriveHost(source, mockEmptyIPv4)).isEqualTo(sourceHost);
// assert a pingpacketdata with empty ipv6 address reverts to the udp source host
assertThat(PeerDiscoveryAgent.deriveHost(source, mockEmptyIPv6)).isEqualTo(sourceHost);
// assert a pingpacketdata from address of 127.0.0.1 reverts to the udp source host
assertThat(PeerDiscoveryAgent.deriveHost(source, mockLocal)).isEqualTo(sourceHost);
// assert that 255.255.255.255 reverts to the udp source host

Loading…
Cancel
Save