-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Exclude 0.0.0.0 from the list of globally routable addresses #31981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,8 @@ impl Ipv4Addr { | |
} | ||
|
||
/// Returns true if the address appears to be globally routable. | ||
/// See [iana-ipv4-special-registry][ipv4-sr]. | ||
/// [ipv4-sr]: http://goo.gl/RaZ7lg | ||
/// | ||
/// The following return false: | ||
/// | ||
|
@@ -129,9 +131,10 @@ impl Ipv4Addr { | |
/// - the link-local address (169.254.0.0/16) | ||
/// - the broadcast address (255.255.255.255/32) | ||
/// - test addresses used for documentation (192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24) | ||
/// - the unspecified address (0.0.0.0) | ||
pub fn is_global(&self) -> bool { | ||
!self.is_private() && !self.is_loopback() && !self.is_link_local() && | ||
!self.is_broadcast() && !self.is_documentation() | ||
!self.is_broadcast() && !self.is_documentation() && !self.is_unspecified() | ||
} | ||
|
||
/// Returns true if this is a multicast address. | ||
|
@@ -725,22 +728,22 @@ mod tests { | |
} | ||
|
||
// address unspec loopbk privt linloc global multicast brdcast doc | ||
check(&[0, 0, 0, 0], true, false, false, false, true, false, false, false); | ||
check(&[0, 0, 0, 1], false, false, false, false, true, false, false, false); | ||
check(&[1, 0, 0, 0], false, false, false, false, true, false, false, false); | ||
check(&[10, 9, 8, 7], false, false, true, false, false, false, false, false); | ||
check(&[127, 1, 2, 3], false, true, false, false, false, false, false, false); | ||
check(&[172, 31, 254, 253], false, false, true, false, false, false, false, false); | ||
check(&[169, 254, 253, 242], false, false, false, true, false, false, false, false); | ||
check(&[192, 0, 2, 183], false, false, false, false, false, false, false, true); | ||
check(&[192, 1, 2, 183], false, false, false, false, true, false, false, false); | ||
check(&[192, 168, 254, 253], false, false, true, false, false, false, false, false); | ||
check(&[198, 51, 100, 0], false, false, false, false, false, false, false, true); | ||
check(&[203, 0, 113, 0], false, false, false, false, false, false, false, true); | ||
check(&[203, 2, 113, 0], false, false, false, false, true, false, false, false); | ||
check(&[224, 0, 0, 0], false, false, false, false, true, true, false, false); | ||
check(&[239, 255, 255, 255], false, false, false, false, true, true, false, false); | ||
check(&[255, 255, 255, 255], false, false, false, false, false, false, true, false); | ||
check(&[0, 0, 0, 0], true, false, false, false, false, false, false, false); | ||
check(&[0, 0, 0, 1], false, false, false, false, true, false, false, false); | ||
check(&[1, 0, 0, 0], false, false, false, false, true, false, false, false); | ||
check(&[10, 9, 8, 7], false, false, true, false, false, false, false, false); | ||
check(&[127, 1, 2, 3], false, true, false, false, false, false, false, false); | ||
check(&[172, 31, 254, 253], false, false, true, false, false, false, false, false); | ||
check(&[169, 254, 253, 242], false, false, false, true, false, false, false, false); | ||
check(&[192, 0, 2, 183], false, false, false, false, false, false, false, true); | ||
check(&[192, 1, 2, 183], false, false, false, false, true, false, false, false); | ||
check(&[192, 168, 254, 253], false, false, true, false, false, false, false, false); | ||
check(&[198, 51, 100, 0], false, false, false, false, false, false, false, true); | ||
check(&[203, 0, 113, 0], false, false, false, false, false, false, false, true); | ||
check(&[203, 2, 113, 0], false, false, false, false, true, false, false, false); | ||
check(&[224, 0, 0, 0], false, false, false, false, true, true, false, false); | ||
check(&[239, 255, 255, 255], false, false, false, false, true, true, false, false); | ||
check(&[255, 255, 255, 255], false, false, false, false, false, false, true, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the extra space added here to all columns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To align with the first row, which expanded one character. If you want, I can leave this as is. |
||
} | ||
|
||
#[test] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should update this list too.
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.
Thanks, done.