Firewall filter and mangle

My understanding is that they can both be used for:
match connection by port, interface, etc → put connection into address-list

Previously I use filter to do it and drop ssh brute forcers. As copied from wiki:

add chain=input protocol=tcp dst-port=22 src-address-list=ssh_blacklist action=drop \
comment="drop ssh brute forcers" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new \
src-address-list=ssh_stage3 action=add-src-to-address-list address-list=ssh_blacklist \
address-list-timeout=10d comment="" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new \
src-address-list=ssh_stage2 action=add-src-to-address-list address-list=ssh_stage3 \
address-list-timeout=1m comment="" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new src-address-list=ssh_stage1 \
action=add-src-to-address-list address-list=ssh_stage2 address-list-timeout=1m comment="" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new action=add-src-to-address-list \
address-list=ssh_stage1 address-list-timeout=1m comment="" disabled=no

However I think using mangle to do it maybe better? (cpu consuming wise)
In mangle I can match on new input connection and mark the packet, then match on the packet-mark to manipulate the address lists.

;;; mark new ssh connection
chain=input action=mark-packet new-packet-mark=remote_ssh_login passthrough=yes connection-state=new protocol=tcp in-interface=ether1-gateway dst-port=22

chain=input action=add-src-to-address-list src-address-list=ssh_stage3 address-list=ssh_blacklist address-list-timeout=1w3d packet-mark=remote_ssh_login

chain=input action=add-src-to-address-list src-address-list=ssh_stage2 address-list=ssh_stage3 address-list-timeout=4m packet-mark=remote_ssh_login

chain=input action=add-src-to-address-list src-address-list=ssh_stage1 address-list=ssh_stage2 address-list-timeout=2m packet-mark=remote_ssh_login

chain=input action=add-src-to-address-list address-list=ssh_stage1 address-list-timeout=1m packet-mark=remote_ssh_login

Then in filter I just need to drop the connect where src-address is in blacklist.

Do I understand it correctly?

Can anyone say some idea? Thanks :slight_smile: