Hi,
in the first post of this thread I referenced the initial nft test version of banIP! :slight_smile:
A big warning: This is WIP, unfinished and (most probably) full of bugs!

nft concept:

  • banIP uses it's own namespace, nft table banIP (not fw4!)
  • for incoming blocking it uses the inet ingress hook (first hook right after the network adapter :slight_smile: )
  • for outgoing blocking it uses the inet forward hook
  • banIP supports IMHO the best feature of nft - atomic rule loading per set
  • the log parsing service was completely rewritten: logterms can be freely selected via regex and the adhoc blocking of suspicious IPs are made in "realtime"
  • the ruleset can always be checked with nft -t list table inet banIP

Example run (Turris Omnia with latest OpenWrt master):

Sat Nov 19 21:03:41 2022 user.info banIP-0.8.0pre0-1[6119]: start banIP processing (init)
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_mkdir  ::: used directory: /tmp
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_tmp    ::: tmp_base: /tmp, tmp_dir: /tmp/tmp.AnCnjl
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_cpu    ::: cpu_cores: 2
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_fetch  ::: fetch_cmd: /usr/bin/curl, fetch_parm:  --connect-timeout 20 --fail --silent --show-error --location -o
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_getif  ::: auto_detect: 1, interface(s)(4/6): wan/wan6, protocols (4/6): 1/1
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_getdev ::: device(s): eth2
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_getsub ::: auto_allowlist: 1, subnet(s):  91.67.204.171/24 2a02:810c:0:80:e442:4b0c:845d:1d43/128
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_mkfile ::: used file: /etc/banip/banip.blocklist
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_mkfile ::: used file: /etc/banip/banip.allowlist
Sat Nov 19 21:03:41 2022 user.info banIP-0.8.0pre0-1[6119]: banIP nft namespace initialized
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: allowlistv4, rc: 0, count_dl: 3, count_set: 2, time: 0, log: -
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: allowlistv6, rc: 0, count_dl: 1, count_set: 1, time: 0, log: -
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: blocklistv6, rc: 0, count_dl: 3, count_set: 3, time: 0, log: -
Sat Nov 19 21:03:41 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: blocklistv4, rc: 0, count_dl: 238, count_set: 227, time: 0, log: -
Sat Nov 19 21:03:42 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: dohv4, rc: 0, count_dl: 440, count_set: 370, time: 1, log: -
Sat Nov 19 21:03:42 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: dohv6, rc: 0, count_dl: 306, count_set: 264, time: 1, log: -
Sat Nov 19 21:03:42 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: deblv6, rc: 0, count_dl: 39, count_set: 39, time: 0, log: -
Sat Nov 19 21:03:43 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: bogonv4, rc: 0, count_dl: 1208, count_set: 1103, time: 1, log: -
Sat Nov 19 21:03:44 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: deblv4, rc: 0, count_dl: 20542, count_set: 12366, time: 2, log: -
Sat Nov 19 21:03:54 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: bogonv6, rc: 0, count_dl: 136382, count_set: 31930, time: 12, log: -
Sat Nov 19 21:03:55 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: asnv4, rc: 0, count_dl: 141, count_set: 17, time: 1, log: -
Sat Nov 19 21:03:55 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: asnv6, rc: 0, count_dl: 255, count_set: 2, time: 1, log: -
Sat Nov 19 21:03:56 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: countryv6, rc: 0, count_dl: 4908, count_set: 4898, time: 2, log: -
Sat Nov 19 21:03:56 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: countryv4, rc: 0, count_dl: 14390, count_set: 11751, time: 2, log: -
Sat Nov 19 21:04:11 2022 user.debug banIP-0.8.0pre0-1[6119]: f_down   ::: name: uceprotect1v4, rc: 0, count_dl: 135222, count_set: 125755, time: 15, log: -
Sat Nov 19 21:04:11 2022 user.debug banIP-0.8.0pre0-1[6119]: f_rmset  ::: sets: -, rc: -, log: -
Sat Nov 19 21:04:11 2022 user.debug banIP-0.8.0pre0-1[6119]: f_rmdir  ::: deleted directory: /tmp/tmp.AnCnjl
Sat Nov 19 21:04:11 2022 user.info banIP-0.8.0pre0-1[6119]: starting banIP log service

If you like to test this early bird please remove all configs & directories of old banIP installations beforehand. A commented config file will be provided - that's the current "documentation" ... :wink:

Another big warning: Please don't use this on a production like router and don't use it on weak devices with less than 256 MByte RAM ... nft requires significantly more RAM.

init start/restart/reload and stop of the banIPservice should work - nothing more ... nevertheless it's a beginning.

Have fun!

11 Likes