| ban_loglimit | option | 100 | scan only the last n log entries permanently. A value of `0` disables the monitor |
| ban_logcount | option | 1 | how many times the IP must appear in the log per blocking cycle to trigger auto-blocking |
| ban_logterm | list | regex | various regex for logfile parsing (default: dropbear, sshd, luci, asterisk and cgi-remote events) |
-| ban_logreadfile | option | - / logread | parse this log file via tail instead of the default logread; if left empty (default) banIP reads the system log via logread |
+| ban_logreadfile | option | - / logread | parse this log file via tail instead of the default logread; by default banIP reads the system log via logread |
| ban_autodetect | option | 1 | auto-detect wan interfaces, devices and subnets |
| ban_debug | option | 0 | enable banIP related debug logging |
| ban_icmplimit | option | 25 | threshold in number of packets to detect icmp DoS in prerouting chain. A value of `0` disables this safeguard |
| ban_triggerdelay | option | 20 | trigger timeout during interface reload and boot |
| ban_deduplicate | option | 1 | deduplicate IP addresses across all active Sets (see optional feed flag `dup` below) |
| ban_splitsize | option | 0 | split the processing/loading of Sets in chunks of n lines/members (saves RAM) |
-| ban_cores | option | - / autodetect | limit the cpu cores used by banIP (saves RAM) |
+| ban_cores | option | - / autodetect | limit the cpu cores used by banIP; only auto-detection is memory-capped |
| ban_nftloglevel | option | warn | nft loglevel, values: emerg, alert, crit, err, warn, notice, info, debug |
| ban_nftpriority | option | -100 | nft priority for the banIP table (the prerouting table is fixed to priority -150) |
| ban_nftpolicy | option | memory | nft policy for banIP-related Sets, values: memory, performance |
nftables supports the atomic loading of firewall rules (incl. elements), which is cool but unfortunately is also very memory intensive. To reduce the memory pressure on low memory systems (i.e. those with 256-512MB RAM), you should optimize your configuration with the following options:
* point `ban_basedir`, `ban_reportdir`, `ban_backupdir` and `ban_errordir` to an external usb drive or ssd
-* set `ban_cores` to `1` (only useful on a multicore system) to force sequential feed processing
+* set `ban_cores` to `1` (only useful on a multicore system) to force sequential feed processing. The autodetected value is additionally capped to the available memory; a manually set value is always used as-is and is never lowered
* set `ban_splitsize` e.g. to `1024` to split the load of an external Set after every 1024 lines/elements
* set `ban_nftcount` to `0` to deactivate the CPU- and memory-intensive creation of counter elements at chain / Set level. With this setting, all packet counters are disabled, the Set Reporting will show zero values for these even when the protection rules are actively dropping traffic. Only the DoS protection counters (`syn-flood`, `udp-flood`, `icmp-flood`, etc.) are always enabled.
ban_sysver="$("${ban_ubuscmd}" -S call system board 2>>"${ban_errorlog}" | "${ban_jsoncmd}" -ql1 -e '@.model' -e '@.release.target' -e '@.release.distribution' -e '@.release.version' -e '@.release.revision' |
"${ban_awkcmd}" 'BEGIN{RS="";FS="\n"}{printf "%s, %s, %s %s (%s)",$1,$2,$3,$4,$5}')"
- # detect cpu cores and cap them by available memory for memory-aware
- # parallel processing (>= 48 MiB per job, floored to 1 core); a user-set
- # ban_cores is only ever lowered by the cap, never raised
+ # detect cpu cores and available memory for memory-aware parallel processing
+ # 'mem_cores' is only calculated for auto-detected cores, a manually set 'ban_cores' is never capped
#
- [ -z "${ban_cores}" ] && ban_cores="$("${ban_grepcmd}" -cm16 '^processor' /proc/cpuinfo 2>>"${ban_errorlog}")"
- case "${ban_cores}" in "" | 0 | *[!0-9]*) ban_cores="1" ;; esac
free_mem="$(f_mem)"
- mem_cores="$((free_mem / 48))"
- [ "${mem_cores}" -lt "1" ] && mem_cores="1"
- [ "${ban_cores}" -gt "1" ] && [ "${mem_cores}" -lt "${ban_cores}" ] && ban_cores="${mem_cores}"
+ if [ -z "${ban_cores}" ]; then
+ ban_cores="$("${ban_grepcmd}" -cm16 '^processor' /proc/cpuinfo 2>>"${ban_errorlog}")"
+ mem_cores="$((free_mem / 48))"
+ [ "${mem_cores}" -lt "1" ] && mem_cores="1"
+ fi
+ case "${ban_cores}" in "" | 0 | *[!0-9]*) ban_cores="1" ;; esac
+ [ -n "${mem_cores}" ] && [ "${mem_cores}" -lt "${ban_cores}" ] && ban_cores="${mem_cores}"
# derive the GNU sort buffer from available memory (>= 8 MiB per core);
# only applied when a coreutils sort is present (busybox sort has no --buffer-size)