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

Azure/personal/dns warning #78

Merged
merged 17 commits into from
Sep 8, 2023
31 changes: 31 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ is_ip_port_reachable()
nc -w 3 -z $ip $port > /dev/null 2>&1
}

#
# Verify if FQDN is resolved into ipv4_addr by /etc/hosts entry.
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
#
is_present_in_etc_hosts() {
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
local ip="$1"
local hostname="$2"

# Search for the entry in /etc/hosts
if grep -qE "^[[:space:]]*$ip[[:space:]]+[^#]*\<$hostname\>" /etc/hosts; then
return 0
fi

return 1
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
}

#
# Blob fqdn to IPv4 adddress.
# Caller must make sure that it is called only for hostname and not IP address.
Expand All @@ -144,6 +159,7 @@ is_ip_port_reachable()
resolve_ipv4()
{
local hname="$1"
local fail_if_present_in_etc_hosts="$2"
local RETRIES=3

# Some retries for resilience.
Expand Down Expand Up @@ -213,6 +229,21 @@ resolve_ipv4()
return 1
fi

#
# Check if the IP-FQDN pair is present in /etc/hosts
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
#
if is_present_in_etc_hosts "$ipv4_addr" "$hname"; then
if [ "$fail_if_present_in_etc_hosts" == "true" ]; then
eecho "[FATAL] Detected entry $ipv4_addr $hname in /etc/hosts."
eecho "$hname is resolving into $ipv4_addr from /etc/hosts."
eecho "Remove the entry for "$hname" in /etc/hosts to ensure proper handling of endpoint IP address changes by AZNFS."
palashvij-msft marked this conversation as resolved.
Show resolved Hide resolved
return 1
else
wecho "[FATAL] Detected entry $ipv4_addr $hname in /etc/hosts." 1>/dev/null
wecho "Remove the entry for "$hname" in /etc/hosts to ensure proper handling of endpoint IP address changes by AZNFS." 1>/dev/null
Copy link
Contributor

Choose a reason for hiding this comment

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

remove dot at the end of each log, we don't add dot at the end of logs in other places, isn't it?
also why do you want to suppress log coming on stdout at L242 243, let it come on stdout

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here, I have suppressed the this log, as otherwise value of new_ip in aznfswatchdog gets updated to this error log
L 315: new_ip=$(resolve_ipv4 "$l_host" "false").

fi
fi

echo $ipv4_addr
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/aznfswatchdog
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ while :; do
# Check if blob endpoint IP address changed.
# This is the migration check.
#
new_ip=$(resolve_ipv4 "$l_host")
new_ip=$(resolve_ipv4 "$l_host" "false")

# If we fail to resolve the host name, try next time.
if [ $? -ne 0 ]; then
Expand Down
4 changes: 3 additions & 1 deletion src/mountscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,12 @@ if ! is_valid_blob_fqdn "$nfs_host"; then
exit 1
fi

nfs_ip=$(resolve_ipv4 "$nfs_host")
# Resolve the IP address for the NFS host
nfs_ip=$(resolve_ipv4 "$nfs_host" "true")
if [ $? -ne 0 ]; then
echo "$nfs_ip"
eecho "Cannot resolve IP address for ${nfs_host}!"
eecho "Mount failed!"
exit 1
fi

Expand Down