Skip to content
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

listener: fix ipv6 error #3912

Merged
merged 4 commits into from
Jul 20, 2018
Merged

Conversation

ramaraochavali
Copy link
Contributor

Signed-off-by: Rama rama.rao@salesforce.com
Description:
Fixes the bug #3911
Risk Level: Low
Testing: Automated
Docs Changes: N/A
Release Notes: N/A

Fixes #3911

Signed-off-by: Rama <rama.rao@salesforce.com>
@ramaraochavali
Copy link
Contributor Author

@PiotrSikora I am not 100% sure if this is the right fix because I am fully familiar with this part. PTAL and suggest. I can change based on your feedback.

std::make_pair<ServerNamesMapSharedPtr, std::vector<Network::Address::CidrRange>>(
std::make_shared<ServerNamesMap>(entry.second),
{Network::Address::CidrRange::create("0.0.0.0/0")}));
}
Copy link
Contributor

@PiotrSikora PiotrSikora Jul 20, 2018

Choose a reason for hiding this comment

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

I think we need support IPv6-only setups as well:

diff --git a/source/server/listener_manager_impl.cc b/source/server/listener_manager_impl.cc
index 393fdfe1e..e69bebe4b 100644
--- a/source/server/listener_manager_impl.cc
+++ b/source/server/listener_manager_impl.cc
@@ -380,17 +380,19 @@ void ListenerImpl::convertDestinationIPsMapToTrie() {
     for (const auto& entry : destination_ips_map) {
       std::vector<Network::Address::CidrRange> subnets;
       if (entry.first == EMPTY_STRING) {
-        list.push_back(
-            std::make_pair<ServerNamesMapSharedPtr, std::vector<Network::Address::CidrRange>>(
-                std::make_shared<ServerNamesMap>(entry.second),
-                {Network::Address::CidrRange::create("0.0.0.0/0"),
-                 Network::Address::CidrRange::create("::/0")}));
+        if (Network::Address::ipFamilySupported(AF_INET)) {
+          subnets.push_back(Network::Address::CidrRange::create("0.0.0.0/0"));
+        }
+        if (Network::Address::ipFamilySupported(AF_INET6)) {
+          subnets.push_back(Network::Address::CidrRange::create("::/0"));
+        }
       } else {
-        list.push_back(
-            std::make_pair<ServerNamesMapSharedPtr, std::vector<Network::Address::CidrRange>>(
-                std::make_shared<ServerNamesMap>(entry.second),
-                {Network::Address::CidrRange::create(entry.first)}));
+        subnets.push_back(Network::Address::CidrRange::create(entry.first));
       }
+      list.push_back(
+          std::make_pair<ServerNamesMapSharedPtr, std::vector<Network::Address::CidrRange>>(
+              std::make_shared<ServerNamesMap>(entry.second),
+              std::vector<Network::Address::CidrRange>(subnets)));
     }
     destination_ips_pair.second = std::make_unique<DestinationIPsTrie>(list, true);
   }

(diff against master branch, since it's more readable)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @PiotrSikora

Signed-off-by: Rama <rama.rao@salesforce.com>
if (Network::Address::ipFamilySupported(AF_INET6)) {
cidr_ranges.push_back(Network::Address::CidrRange::create("::/0"));
}
list.push_back({std::make_shared<ServerNamesMap>(entry.second), cidr_ranges});
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use the patch I provided (using unused subnets and sharing more of the code with the != EMPTY_STRING path)? It's a bit more readable, IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Please check

Signed-off-by: Rama <rama.rao@salesforce.com>
Signed-off-by: Rama <rama.rao@salesforce.com>
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

Ideally I'd like to have some test coverage (which would require mocking ipFamilySupported() or it's underlying syscalls). But I'm ok with committing this as-is if it's urgent for you.

@ggreenway ggreenway merged commit 598f5c9 into envoyproxy:master Jul 20, 2018
@ramaraochavali ramaraochavali deleted the fix/ipv6_error branch July 21, 2018 05:11
@ramaraochavali
Copy link
Contributor Author

@ggreenway Thanks. I was thinking about such a test and checked to see if we can write a mock but looks like for functions like this writing mock is not possible with gmocks. If there is any possible way to do it, do let me know. I will look in to it.

@ggreenway
Copy link
Contributor

@ramaraochavali The way to mock this is to add socket() to OsSysCalls (see envoy/include/envoy/api/os_sys_calls.h). Then use OsSysCalls::socket() in ipFamilySupported(). You can then mock the behavior of ::socket().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants