I'm trying to restrict some UDP-traffic in my Raspberry Pi 4B hardware with
OpenWrt version 23.05.0.
Scenario 1
An attempt to stop traffic from the 'lan' zone to 'wan' zone succeeded,
where a PC was blocked as follows.
Edit the file /etc/config/firewall so that
option log '1'
is added to the zone 'wan'.- Add the following rule last in the file:
config rule
option name 'block-all-else'
list proto 'all'
option src 'lan'
list src_ip '192.168.2.161'
option dest 'wan'
option target 'REJECT'
Run the command "fw4 reload".
Let a web browser in the PC at 192.168.2.161 try to connect any web site.
Run the command "logread".
You can now watch logs as this example:
Wed Jan 10 10:37:35 2024 kern.warn kernel: [ 4032.055866] reject wan out: IN=br-lan OUT=eth1 MAC=d8:3a:dd:6e:b0:eb:54:04:a6:c4:63:54:08:00 SRC=192.168.2.161 DST=x.x.x.x LEN=52 TOS=0x00 PREC=0x00 TTL=127 ID=27587 DF PROTO=TCP SPT=54370 DPT=443 WINDOW=64240 RES=0x00 SYN URGP=0
The web browser fails when trying to connect.
Scenario 2.
Edit the file /etc/config/firewall so that src_ip in the last rule (block-all-else) is changed to 192.168.2.12:
option src 'lan'
list src_ip '192.168.2.12'
The only difference from scenario 1 is the IP-address, which is an IP-address
of an IoT-device.
Run the command "fw4 reload".
With tcpdump, I can observe that the device sends an UDP-packet every
10:th second. Example:
11:16:47.407457 IP 192.168.2.12.8888 > x.x.com.9999: UDP, length ...
But now nothing is logged in the syslog.
I guess that the UDP-packets are not blocked, since:
a) the device works
b) the server x.x.com sends a UDP-packet to the device a few milliseconds after some of the packets the device sends. That seems to be acknowledgments.
Both the PC and the device are connected with wires via an Ethernet bridge to the same port in Raspberry Pi.
So the difference between the two scenarios is that the first uses TCP,
and the second uses UDP.
Reboot the router.
Now the filter works as intended.
I would really like to understand what can cause a reboot to work.
It seems that rebooting does some additional things that "fw4 reload" doesn't.
Some IP-addresses, domain names, port numbers and packet lengths above have been made anonymous.