From 359dd6c8f7531ced8a44660170a13624e041fac6 Mon Sep 17 00:00:00 2001 From: HouzuoGuo Date: Sat, 23 Dec 2017 17:28:52 +0800 Subject: [PATCH] skip port 25 check on Azure as well as GCE --- daemon/maintenance/maintenance.go | 2 +- inet/ip.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/daemon/maintenance/maintenance.go b/daemon/maintenance/maintenance.go index 36d4d746..8e0f96fb 100644 --- a/daemon/maintenance/maintenance.go +++ b/daemon/maintenance/maintenance.go @@ -102,7 +102,7 @@ func (daemon *Daemon) runPortsCheck() error { continue } for _, port := range ports { - if port == 25 && inet.IsGCE() { + if port == 25 && (inet.IsGCE() || inet.IsAzure()) { daemon.logger.Info("runPortsCheck", "", nil, "because Google cloud forbids connection to port 25, port check will skip %s:25", host) continue } diff --git a/inet/ip.go b/inet/ip.go index 826b9864..e46daeab 100644 --- a/inet/ip.go +++ b/inet/ip.go @@ -1,6 +1,7 @@ package inet import ( + "io/ioutil" "strings" "sync" "time" @@ -12,6 +13,10 @@ var ( // isGCE is true only if IsGCE function has determined that the program is running on Google compute engine. isGCE bool isGCEOnce = new(sync.Once) + + // isAzure is true only if IsAzure function has determined that the program is running on Microsoft Azure. + isAzure bool + isAzureOnce = new(sync.Once) ) // IsGCE returns true only if the program is running on Google compute engine (or Google cloud platform, same thing). @@ -28,6 +33,19 @@ func IsGCE() bool { return isGCE } +// IsAzure returns true only if the program is running on Microsoft Azure virtual machine. +func IsAzure() bool { + isAzureOnce.Do(func() { + content, err := ioutil.ReadFile("/var/lib/dhcp/dhclient.eth0.leases") + if err == nil { + if strings.Contains(string(content), "unknown-245") { + isAzure = true + } + } + }) + return isAzure +} + /* GetPublicIP returns the latest public IP address of the computer. If the IP address cannot be determined, it will return an empty string. The function may take up to 3 seconds to return a value.