The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6708

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Fixes #6682.

Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
From f506d831b5cd7c11fe1d214992519e6a399f4d6f Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanay...@canonical.com>
Date: Tue, 14 Jan 2020 15:47:50 +0000
Subject: [PATCH] lxd/util: IsAddressCovered takes into account host names

Fixes #6682.

Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
---
 lxd/util/net.go      | 20 ++++++++++++++++++--
 lxd/util/net_test.go |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lxd/util/net.go b/lxd/util/net.go
index 51b192d1ae..154a0d98f5 100644
--- a/lxd/util/net.go
+++ b/lxd/util/net.go
@@ -158,11 +158,27 @@ func IsAddressCovered(address1, address2 string) bool {
                return false
        }
 
+       // If address2 contains a host name, let's try to resolve it, in order
+       // to compare the actual IPs.
+       if host2 != "" {
+               ip2 := net.ParseIP(host2)
+               if ip2 == nil {
+                       ips, err := net.LookupHost(host2)
+                       if err == nil && len(ips) > 0 {
+                               host2 = ips[0]
+                       }
+               }
+       }
+
+       if host2 == host1 {
+               return true
+       }
+
        // If address2 is using an IPv4 wildcard for the host, then address2 is
        // only covered if it's an IPv4 address.
        if host2 == "0.0.0.0" {
-               ip := net.ParseIP(host1)
-               if ip != nil && ip.To4() != nil {
+               ip1 := net.ParseIP(host1)
+               if ip1 != nil && ip1.To4() != nil {
                        return true
                }
                return false
diff --git a/lxd/util/net_test.go b/lxd/util/net_test.go
index 8509a76cb9..ee7845a90a 100644
--- a/lxd/util/net_test.go
+++ b/lxd/util/net_test.go
@@ -69,6 +69,7 @@ func TestIsAddressCovered(t *testing.T) {
                {"[::1]:8443", ":8443", true},
                {":8443", "[::]:8443", true},
                {"0.0.0.0:8443", "[::]:8443", true},
+               {"127.0.0.1:8443", "localhost:8443", true},
        }
 
        for _, c := range cases {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to