Skip to content

Support IPv6 subnets in --net-restrict #10026

@usmansaleem

Description

@usmansaleem

Description

--net-restrict currently only supports IPv4 CIDR subnets because it relies on Apache Commons Net SubnetUtils/SubnetInfo, which is IPv4-only. When a peer has an IPv6 address and --net-restrict is configured, SubnetInfo.isInRange() throws IllegalArgumentException on the IPv6 address string.

This affects both DiscV4 (PeerPermissionSubnet) and DiscV5 (PeerDiscoveryAgentFactoryV5.createAddressAccessPolicy()).

Impact

Scenario Behavior
IPv4 only ✅ Works correctly
Dual-stack, peer on IPv4 ✅ Works correctly
Dual-stack, peer on IPv6 isInRange() throws on IPv6 address
IPv6 only ❌ No subnet filtering possible

Proposed Solution

Replace SubnetUtils.SubnetInfo with a dual-stack CidrBlock abstraction that handles both IPv4 and IPv6 CIDR notation:

  1. Create CidrBlock class using java.net.InetAddress + byte-level prefix comparison (~50 lines)
  2. Update SubnetInfoConverter to parse both IPv4 (192.168.0.0/24) and IPv6 (fd00::/64) CIDR
  3. Replace SubnetInfo with CidrBlock across all usages (~11 files)
  4. Handle edge cases: IPv4-mapped IPv6 addresses (::ffff:192.168.1.1), mixed v4/v6 CIDR lists

Affected files

  • app/.../cli/converter/SubnetInfoConverter.java
  • app/.../cli/options/P2PDiscoveryOptions.java
  • ethereum/p2p/.../permissions/PeerPermissionSubnet.java
  • ethereum/p2p/.../discovery/discv5/PeerDiscoveryAgentFactoryV5.java
  • ethereum/p2p/.../discovery/DefaultPeerDiscoveryAgentFactory.java
  • ethereum/p2p/.../discovery/P2PDiscoveryConfiguration.java
  • app/.../RunnerBuilder.java
  • Related test files

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions