-
Notifications
You must be signed in to change notification settings - Fork 1k
Support IPv6 subnets in --net-restrict #10026
Copy link
Copy link
Closed
Labels
Description
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:
- Create
CidrBlockclass usingjava.net.InetAddress+ byte-level prefix comparison (~50 lines) - Update
SubnetInfoConverterto parse both IPv4 (192.168.0.0/24) and IPv6 (fd00::/64) CIDR - Replace
SubnetInfowithCidrBlockacross all usages (~11 files) - Handle edge cases: IPv4-mapped IPv6 addresses (
::ffff:192.168.1.1), mixed v4/v6 CIDR lists
Affected files
app/.../cli/converter/SubnetInfoConverter.javaapp/.../cli/options/P2PDiscoveryOptions.javaethereum/p2p/.../permissions/PeerPermissionSubnet.javaethereum/p2p/.../discovery/discv5/PeerDiscoveryAgentFactoryV5.javaethereum/p2p/.../discovery/DefaultPeerDiscoveryAgentFactory.javaethereum/p2p/.../discovery/P2PDiscoveryConfiguration.javaapp/.../RunnerBuilder.java- Related test files
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done