Skip to content

feat(wire): add subnet/CIDR support to BanMan#899

Draft
Micah-Shallom wants to merge 2 commits intogetfloresta:masterfrom
Micah-Shallom:feat/wire-banman-subnet
Draft

feat(wire): add subnet/CIDR support to BanMan#899
Micah-Shallom wants to merge 2 commits intogetfloresta:masterfrom
Micah-Shallom:feat/wire-banman-subnet

Conversation

@Micah-Shallom
Copy link
Copy Markdown

Summary

Adds BanSubnet to support banning entire subnets (e.g. 192.168.1.0/24) instead of only single IPs. Uses bitwise mask matching, same approach as Bitcoin Core's CSubNet::Match.

  • BanSubnet holds an IpAddr + prefix length, with contains(ip) for matching
  • BanMan keyed by BanSubnet instead of IpAddr; is_banned() does linear scan over all entries
  • Single-IP bans are just /32 or /128 subnets
  • Integration points in peer_man.rs wrapped with BanSubnet::from_ip()

Follow-up to #892 as discussed — showing the direction for subnet banning.

Test plan

  • Existing unit tests updated and passing
  • New: test_subnet_ban_covers_all_ips_in_range — bans /24, checks IPs inside and outside
  • Clippy and fmt clean

Introduce a BanMan struct that centralizes IP ban tracking,
replacing the scattered ban logic across AddressMan and peer_man.

- Add BanMan with add_ban() and is_banned() methods
- Wire BanMan into NodeCommon alongside AddressMan
- Check banned status before creating new connections
- Register bans in both disconnect_and_ban() and increase_banscore()
- Add PeerBanned variant to WireError

Closes getfloresta#820 (partial — single-IP banning only)
Add BanSubnet struct with bitwise mask matching so BanMan can ban
entire subnets (e.g. 192.168.1.0/24) instead of only single IPs.
Single-IP bans are represented as /32 (IPv4) or /128 (IPv6).

Closes getfloresta#820 (subnet support)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants