mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-26 08:03:18 +00:00
pihole -d: Fix gateway ping if it is a LL address (#5527)
This commit is contained in:
commit
e781311f23
1 changed files with 34 additions and 22 deletions
|
@ -547,17 +547,24 @@ ping_gateway() {
|
|||
ping_ipv4_or_ipv6 "${protocol}"
|
||||
# Check if we are using IPv4 or IPv6
|
||||
# Find the default gateways using IPv4 or IPv6
|
||||
local gateway
|
||||
local gateway gateway_addr gateway_iface
|
||||
|
||||
log_write "${INFO} Default IPv${protocol} gateway(s):"
|
||||
|
||||
while IFS= read -r gateway; do
|
||||
log_write " ${gateway}"
|
||||
done < <(ip -"${protocol}" route | grep default | cut -d ' ' -f 3)
|
||||
log_write " $(cut -d ' ' -f 3 <<< "${gateway}")%$(cut -d ' ' -f 5 <<< "${gateway}")"
|
||||
done < <(ip -"${protocol}" route | grep default)
|
||||
|
||||
gateway=$(ip -"${protocol}" route | grep default | cut -d ' ' -f 3 | head -n 1)
|
||||
gateway_addr=$(ip -"${protocol}" route | grep default | cut -d ' ' -f 3 | head -n 1)
|
||||
gateway_iface=$(ip -"${protocol}" route | grep default | cut -d ' ' -f 5 | head -n 1)
|
||||
# If there was at least one gateway
|
||||
if [ -n "${gateway}" ]; then
|
||||
if [ -n "${gateway_addr}" ]; then
|
||||
# Append the interface to the gateway address if it is a link-local address
|
||||
if [[ "${gateway_addr}" =~ ^fe80 ]]; then
|
||||
gateway="${gateway_addr}%${gateway_iface}"
|
||||
else
|
||||
gateway="${gateway_addr}"
|
||||
fi
|
||||
# Let the user know we will ping the gateway for a response
|
||||
log_write " * Pinging first gateway ${gateway}..."
|
||||
# Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only,
|
||||
|
@ -757,24 +764,29 @@ dig_at() {
|
|||
# Removes CIDR and everything thereafter (e.g., scope properties)
|
||||
addresses="$(ip address show dev "${iface}" | sed "/${sed_selector} /!d;s/^.*${sed_selector} //g;s/\/.*$//g;")"
|
||||
if [ -n "${addresses}" ]; then
|
||||
while IFS= read -r local_address ; do
|
||||
while IFS= read -r local_address ; do
|
||||
# If ${local_address} is an IPv6 link-local address, append the interface name to it
|
||||
if [[ "${local_address}" =~ ^fe80 ]]; then
|
||||
local_address="${local_address}%${iface}"
|
||||
fi
|
||||
|
||||
# Check if Pi-hole can use itself to block a domain
|
||||
if local_dig="$(dig +tries=1 +time=2 -"${protocol}" "${random_url}" @"${local_address}" "${record_type}")"; then
|
||||
# If it can, show success
|
||||
if [[ "${local_dig}" == *"status: NOERROR"* ]]; then
|
||||
local_dig="NOERROR"
|
||||
elif [[ "${local_dig}" == *"status: NXDOMAIN"* ]]; then
|
||||
local_dig="NXDOMAIN"
|
||||
else
|
||||
# Extract the first entry in the answer section from dig's output,
|
||||
# replacing any multiple spaces and tabs with a single space
|
||||
local_dig="$(echo "${local_dig}" | grep -A1 "ANSWER SECTION" | grep -v "ANSWER SECTION" | tr -s " \t" " ")"
|
||||
fi
|
||||
log_write "${TICK} ${random_url} ${COL_GREEN}is ${local_dig}${COL_NC} on ${COL_CYAN}${iface}${COL_NC} (${COL_CYAN}${local_address}${COL_NC})"
|
||||
else
|
||||
# Otherwise, show a failure
|
||||
log_write "${CROSS} ${COL_RED}Failed to resolve${COL_NC} ${random_url} on ${COL_RED}${iface}${COL_NC} (${COL_RED}${local_address}${COL_NC})"
|
||||
fi
|
||||
if local_dig="$(dig +tries=1 +time=2 -"${protocol}" "${random_url}" @"${local_address}" "${record_type}")"; then
|
||||
# If it can, show success
|
||||
if [[ "${local_dig}" == *"status: NOERROR"* ]]; then
|
||||
local_dig="NOERROR"
|
||||
elif [[ "${local_dig}" == *"status: NXDOMAIN"* ]]; then
|
||||
local_dig="NXDOMAIN"
|
||||
else
|
||||
# Extract the first entry in the answer section from dig's output,
|
||||
# replacing any multiple spaces and tabs with a single space
|
||||
local_dig="$(echo "${local_dig}" | grep -A1 "ANSWER SECTION" | grep -v "ANSWER SECTION" | tr -s " \t" " ")"
|
||||
fi
|
||||
log_write "${TICK} ${random_url} ${COL_GREEN}is ${local_dig}${COL_NC} on ${COL_CYAN}${iface}${COL_NC} (${COL_CYAN}${local_address}${COL_NC})"
|
||||
else
|
||||
# Otherwise, show a failure
|
||||
log_write "${CROSS} ${COL_RED}Failed to resolve${COL_NC} ${random_url} on ${COL_RED}${iface}${COL_NC} (${COL_RED}${local_address}${COL_NC})"
|
||||
fi
|
||||
done <<< "${addresses}"
|
||||
else
|
||||
log_write "${TICK} No IPv${protocol} address available on ${COL_CYAN}${iface}${COL_NC}"
|
||||
|
|
Loading…
Reference in a new issue