-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Refactor --allow-ips to handle custom ip-ranges #6144
Conversation
100.64.0.0/10 and 240.0.0.0/4 are both reserved but not currently filtered.
192.0.0.0/24 - Used for the IANA IPv4 Special Purpose Address Registry
* Add checks for all ipv4 special use addresses * Add comprehensive ipv4 test cases
* Add IpFilter struct to wrap predefined filter (AllowIP) with custom allow/block filters. * Refactor parsing of --allow-ips to handle custom filters. * Move AllowIP/IpFilter from ethsync to ethcore-network where they are used.
* Add "none" as a valid argument for --allow-ips to allow narrow custom ranges, eg.: --allow-ips="none 10.0.0.0/8" * Add tests for parsing filter arguments and node endpoints. * Add ipnetwork crate to dev dependencies for testing.
Please re-format changed files to use tabs instead of spaces. We use tabs consistently in our codebase. The only exception is |
util/network/src/lib.rs
Outdated
} | ||
|
||
impl IpFilter { | ||
pub fn new() -> IpFilter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd name it default
or none
or empty
to show that it creates an empty filter
util/network/src/lib.rs
Outdated
"none" => filter.predefined = AllowIP::Non, | ||
custom => { | ||
if custom.starts_with("-") { | ||
match IpNetwork::from_str(&custom.to_owned().split_off(1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be just filter.custom_block.push(IpNetwork::from_str(&custom.to_owned().split_off(1)?)
; Same for the match
below.
util/network/src/lib.rs
Outdated
pub enum AllowIP { | ||
/// Connect to any address | ||
All, | ||
/// Connect to private network only | ||
Private, | ||
/// Connect to public network only | ||
Public, | ||
|
||
Non, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I didn't want it to be confused with Option::None
but reading it now I can see that it might be more confusing :-p
Looks great apart from minor style issues. |
Filter some additional reserved ranges from the predefined
public
andprivate
lists, as in #5872. Also:--allow-ips FILTER
supports everything it did before but accepts more args:Accepts one predefined symbol (public, private, all, or none) and unlimited custom ranges. Could potentially support combinations of predefined like "public private ..." but not sure it would be useful/worthwhile.