Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Refactor --allow-ips to handle custom ip-ranges #6144

Merged
merged 21 commits into from
Jul 28, 2017
Merged

Refactor --allow-ips to handle custom ip-ranges #6144

merged 21 commits into from
Jul 28, 2017

Conversation

sjeohp-zz
Copy link

@sjeohp-zz sjeohp-zz commented Jul 25, 2017

Filter some additional reserved ranges from the predefined public and private lists, as in #5872. Also:

--allow-ips FILTER supports everything it did before but accepts more args:

FILTER can be one of:
private - connect to private network IP addresses only;
public - connect to public network IP addresses only;
all - connect to any IP address;
none - block all (for use with a custom filter as below);
a custom filter list in the format: "private,ip_range1,-ip_range2,...".
Where ip_range1 would be allowed and ip_range2 blocked;
Custom blocks ("-ip_range") override custom allows ("ip_range");
(default: {flag_allow_ips}).

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.

Joseph Mark added 15 commits July 17, 2017 20:03
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.
@sjeohp-zz sjeohp-zz added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Jul 25, 2017
@arkpar
Copy link
Collaborator

arkpar commented Jul 26, 2017

Please re-format changed files to use tabs instead of spaces. We use tabs consistently in our codebase. The only exception is usage.txt

}

impl IpFilter {
pub fn new() -> IpFilter {
Copy link
Collaborator

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

"none" => filter.predefined = AllowIP::Non,
custom => {
if custom.starts_with("-") {
match IpNetwork::from_str(&custom.to_owned().split_off(1)) {
Copy link
Collaborator

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.

pub enum AllowIP {
/// Connect to any address
All,
/// Connect to private network only
Private,
/// Connect to public network only
Public,

Non,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None?

Copy link
Author

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

@arkpar
Copy link
Collaborator

arkpar commented Jul 26, 2017

Looks great apart from minor style issues.

@arkpar arkpar added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 26, 2017
@sjeohp-zz sjeohp-zz added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jul 27, 2017
@sjeohp-zz sjeohp-zz added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 27, 2017
Joseph Mark added 2 commits July 27, 2017 13:36
@sjeohp-zz sjeohp-zz added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Jul 27, 2017
@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 27, 2017
@gavofyork gavofyork merged commit b5f1524 into master Jul 28, 2017
@gavofyork gavofyork deleted the issues/5872 branch July 28, 2017 17:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants