Only check IPv6 if system is enabled.

This commit is contained in:
Dan Schaper 2016-10-26 12:22:20 -07:00
parent 98db002770
commit fc360abe43

View file

@ -26,6 +26,9 @@ ADLISTSFILE="/etc/pihole/adlists.list"
PIHOLELOG="/var/log/pihole.log" PIHOLELOG="/var/log/pihole.log"
WHITELISTMATCHES="/tmp/whitelistmatches.list" WHITELISTMATCHES="/tmp/whitelistmatches.list"
# Default to no IPv6, will check and enable if needed.
IPV6=ENABLED=false
# Header info and introduction # Header info and introduction
cat << EOM cat << EOM
::: Beginning Pi-hole debug at $(date)! ::: Beginning Pi-hole debug at $(date)!
@ -105,22 +108,30 @@ distro_check() {
echo ":::" echo ":::"
} }
ipv6_check() {
# Check if system is IPv6 enabled, for use in other functions
if [[ -a /proc/net/if_inet6 ]]; then
IPV6_ENABLED=true
return 0
else
return 1
fi
}
ip_check() { ip_check() {
header_write "IP Address Information" header_write "IP Address Information"
# Get the current interface for Internet traffic # Get the current interface for Internet traffic
local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5)
# Check if IPv6 enabled
local IPv6_interface
ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)}
# If declared in setupVars.conf use it, otherwise defer to default # If declared in setupVars.conf use it, otherwise defer to default
# http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash
local IPv6_interface=${piholeInterface:-$IPv6_temp_interface}
echo "::: Collecting local IP info." echo "::: Collecting local IP info."
local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \
&& (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found."
local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \
&& (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") || log_echo "No IPv6 addresses found."
echo "::: Locating default gateway and checking connectivity" echo "::: Locating default gateway and checking connectivity"
local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
@ -135,22 +146,28 @@ ip_check() {
log_write "${IPv4_inet_check}" log_write "${IPv4_inet_check}"
fi fi
local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ IPV6_ENABLED ]]; then
if [[ $? = 0 ]]; then local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \
echo -n "::: Pinging default IPv6 gateway: " && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \
local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ || log_echo "No IPv6 addresses found."
&& echo "Gateway Responded." || echo "Gateway did not respond."
log_write "${IPv6_def_gateway_check}"
echo -n "::: Pinging Internet via IPv6: " local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3)
local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ if [[ $? = 0 ]]; then
&& echo "Query responded." || echo "Query did not respond." echo -n "::: Pinging default IPv6 gateway: "
else local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \
IPv6_inet_check="No IPv6 Gateway Detected" && echo "Gateway Responded." || echo "Gateway did not respond."
fi log_write "${IPv6_def_gateway_check}"
log_write "${IPv6_inet_check}"
log_write "" echo -n "::: Pinging Internet via IPv6: "
echo ":::" local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \
&& echo "Query responded." || echo "Query did not respond."
else
IPv6_inet_check="No IPv6 Gateway Detected"
fi
log_write "${IPv6_inet_check}"
log_write ""
echo ":::"
fi
} }
hostnameCheck() { hostnameCheck() {