banip: update to 0.8.2-4
authorDirk Brenken <dev@brenken.org>
Sun, 26 Mar 2023 20:52:05 +0000 (22:52 +0200)
committerDirk Brenken <dev@brenken.org>
Sun, 26 Mar 2023 20:52:34 +0000 (22:52 +0200)
* fixed a race condition if the service is in a disabled state

Signed-off-by: Dirk Brenken <dev@brenken.org>
net/banip/Makefile
net/banip/files/banip-functions.sh

index 9983e08b06fd2e25c54ac1767dd7dd0cd7c84484..ca8b5fa3725dd18daa528a0af27a402f4b0cd3d5 100644 (file)
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=banip
 PKG_VERSION:=0.8.2
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 PKG_LICENSE:=GPL-3.0-or-later
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
 
index 692a9bd49ecff916486c27674f754aa8e5798959..fc3c73225611734de1ed4474171a39b078eb20f2 100644 (file)
@@ -168,9 +168,15 @@ f_log() {
                fi
        fi
        if [ "${class}" = "err" ]; then
-               f_genstatus "error"
-               [ "${ban_mailnotification}" = "1" ] && [ -n "${ban_mailreceiver}" ] && [ -x "${ban_mailcmd}" ] && f_mail
+               "${ban_nftcmd}" delete table inet banIP >/dev/null 2>&1
+               if [ "${ban_enabled}" = "1" ]; then
+                       f_genstatus "error"
+                       [ "${ban_mailnotification}" = "1" ] && [ -n "${ban_mailreceiver}" ] && [ -x "${ban_mailcmd}" ] && f_mail
+               else
+                       f_genstatus "disabled"
+               fi
                f_rmdir "${ban_tmpdir}"
+               f_rmpid
                rm -rf "${ban_lock}"
                exit 1
        fi
@@ -859,7 +865,6 @@ f_genstatus() {
                fi
                runtime="action: ${ban_action:-"-"}, duration: ${duration:-"-"}, date: $(date "+%Y-%m-%d %H:%M:%S")"
        fi
-       f_system
        [ ${ban_splitsize:-"0"} -gt "0" ] && split="1"
 
        : >"${ban_rtfile}"
@@ -1034,7 +1039,6 @@ f_report() {
        local detail set_details jsnval timestamp autoadd_allow autoadd_block sum_sets sum_setinput sum_setforwardwan sum_setforwardlan sum_setelements sum_cntinput sum_cntforwardwan sum_cntforwardlan
 
        [ -z "${ban_dev}" ] && f_conf
-       f_system
        f_mkdir "${ban_reportdir}"
        report_jsn="${ban_reportdir}/ban_report.jsn"
        report_txt="${ban_reportdir}/ban_report.txt"
@@ -1196,9 +1200,6 @@ f_report() {
 f_search() {
        local table_sets ip proto run_search search="${1}"
 
-       f_system
-       run_search="/var/run/banIP.search"
-
        if [ -n "${search}" ]; then
                ip="$(printf "%s" "${search}" | "${ban_awkcmd}" 'BEGIN{RS="(([0-9]{1,3}\\.){3}[0-9]{1,3})+"}{printf "%s",RT}')"
                [ -n "${ip}" ] && proto="v4"
@@ -1217,6 +1218,7 @@ f_search() {
        printf "%s\n" "    Looking for IP '${ip}' on $(date "+%Y-%m-%d %H:%M:%S")"
        printf "%s\n" "    ---"
        cnt="1"
+       run_search="/var/run/banIP.search"
        for set in ${table_sets}; do
                (
                        if "${ban_nftcmd}" get element inet banIP "${set}" "{ ${ip} }" >/dev/null 2>&1; then
@@ -1241,7 +1243,6 @@ f_search() {
 f_survey() {
        local set_elements set="${1}"
 
-       f_system
        [ -n "${set}" ] && set_elements="$("${ban_nftcmd}" -j list set inet banIP "${set}" 2>/dev/null | jsonfilter -qe '@.nftables[*].set.elem[*]')"
 
        if [ -z "${set}" ] || [ -z "${set_elements}" ]; then
@@ -1279,6 +1280,7 @@ f_mail() {
 
 # check banIP availability and initial sourcing
 #
+f_system
 if [ "${ban_action}" != "stop" ]; then
        if [ -r "/lib/functions.sh" ] && [ -r "/lib/functions/network.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]; then
                . "/lib/functions.sh"