2019-05-30 19:23:15 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
|
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
|
|
|
# (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
|
|
|
# ARP table interaction
|
|
|
|
#
|
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
|
|
|
coltable="/opt/pihole/COL_TABLE"
|
|
|
|
if [[ -f ${coltable} ]]; then
|
|
|
|
source ${coltable}
|
|
|
|
fi
|
|
|
|
|
2024-06-19 20:49:11 +00:00
|
|
|
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
|
|
|
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
|
|
|
source "${utilsfile}"
|
|
|
|
|
2019-05-30 19:23:15 +00:00
|
|
|
# Determine database location
|
2024-06-19 20:49:11 +00:00
|
|
|
DBFILE=$(getFTLConfigValue "files.database")
|
2019-05-30 19:23:15 +00:00
|
|
|
if [ -z "$DBFILE" ]; then
|
|
|
|
DBFILE="/etc/pihole/pihole-FTL.db"
|
|
|
|
fi
|
|
|
|
|
|
|
|
flushARP(){
|
|
|
|
local output
|
2019-05-31 06:42:22 +00:00
|
|
|
if [[ "${args[1]}" != "quiet" ]]; then
|
2019-05-30 19:23:15 +00:00
|
|
|
echo -ne " ${INFO} Flushing network table ..."
|
|
|
|
fi
|
|
|
|
|
2024-06-19 20:49:11 +00:00
|
|
|
# Stop FTL to prevent database access
|
|
|
|
if ! output=$(pihole-FTL service stop 2>&1); then
|
|
|
|
echo -e "${OVER} ${CROSS} Failed to stop FTL"
|
|
|
|
echo " Output: ${output}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-06-15 07:15:12 +00:00
|
|
|
# Truncate network_addresses table in pihole-FTL.db
|
|
|
|
# This needs to be done before we can truncate the network table due to
|
2021-01-19 18:33:38 +00:00
|
|
|
# foreign key constraints
|
2023-12-09 22:06:50 +00:00
|
|
|
if ! output=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM network_addresses" 2>&1); then
|
2019-06-15 07:15:12 +00:00
|
|
|
echo -e "${OVER} ${CROSS} Failed to truncate network_addresses table"
|
|
|
|
echo " Database location: ${DBFILE}"
|
|
|
|
echo " Output: ${output}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-05-30 19:32:35 +00:00
|
|
|
# Truncate network table in pihole-FTL.db
|
2023-12-09 22:06:50 +00:00
|
|
|
if ! output=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM network" 2>&1); then
|
2019-05-30 19:23:15 +00:00
|
|
|
echo -e "${OVER} ${CROSS} Failed to truncate network table"
|
|
|
|
echo " Database location: ${DBFILE}"
|
|
|
|
echo " Output: ${output}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2024-06-19 20:49:11 +00:00
|
|
|
# Flush ARP cache of the host
|
|
|
|
if ! output=$(ip -s -s neigh flush all 2>&1); then
|
|
|
|
echo -e "${OVER} ${CROSS} Failed to flush ARP cache"
|
|
|
|
echo " Output: ${output}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Start FTL again
|
|
|
|
if ! output=$(pihole-FTL service restart 2>&1); then
|
|
|
|
echo -e "${OVER} ${CROSS} Failed to restart FTL"
|
|
|
|
echo " Output: ${output}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-05-31 06:42:22 +00:00
|
|
|
if [[ "${args[1]}" != "quiet" ]]; then
|
2019-05-30 19:23:15 +00:00
|
|
|
echo -e "${OVER} ${TICK} Flushed network table"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
args=("$@")
|
|
|
|
|
|
|
|
case "${args[0]}" in
|
|
|
|
"arpflush" ) flushARP;;
|
|
|
|
esac
|