[lxc-devel] [lxd/master] Resolve both core.https_address and cluster.https_address when comparing IPs
freeekanayaka on Github
lxc-bot at linuxcontainers.org
Tue Apr 28 08:56:04 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 378 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200428/0814098f/attachment.bin>
-------------- next part --------------
From a5a57156823156d018eba9e701c59da1cb46d74e Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Tue, 28 Apr 2020 09:53:57 +0100
Subject: [PATCH] Resolve both core.https_address and cluster.https_address
when comparing IPs
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/util/net.go | 12 ++++++++++++
lxd/util/net_test.go | 1 +
2 files changed, 13 insertions(+)
diff --git a/lxd/util/net.go b/lxd/util/net.go
index 8dbbce4e8f..b5a4046523 100644
--- a/lxd/util/net.go
+++ b/lxd/util/net.go
@@ -167,6 +167,18 @@ func IsAddressCovered(address1, address2 string) bool {
return false
}
+ // If address1 contains a host name, let's try to resolve it, in order
+ // to compare the actual IPs.
+ if host1 != "" {
+ ip1 := net.ParseIP(host1)
+ if ip1 == nil {
+ ips, err := net.LookupHost(host1)
+ if err == nil && len(ips) > 0 {
+ host1 = ips[0]
+ }
+ }
+ }
+
// If address2 contains a host name, let's try to resolve it, in order
// to compare the actual IPs.
if host2 != "" {
diff --git a/lxd/util/net_test.go b/lxd/util/net_test.go
index e79ace9c3b..9702629bc2 100644
--- a/lxd/util/net_test.go
+++ b/lxd/util/net_test.go
@@ -72,6 +72,7 @@ func TestIsAddressCovered(t *testing.T) {
{":8443", "[::]:8443", true},
{"0.0.0.0:8443", "[::]:8443", true},
{"10.30.0.8:8443", "[::]", true},
+ {"localhost:8443", "127.0.0.1:8443", true},
}
// Test some localhost cases too
More information about the lxc-devel
mailing list