ipfw blocks IP address not in table

February 20, 2017 380 views
Firewall FreeBSD

uname -a
FreeBSD theranch 10.3-RELEASE-p11 FreeBSD 10.3-RELEASE-p11 #0: Mon Oct 24 18:49:24 UTC 2016 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64

Here is the situation. I am using IPFW to block ranges of IPs from accessing email ports other than 25. (Port 25 is needed for incoming mail). I'm blocking all the IMAP and POP ports using several tables I have created. The particular problem is with IPFW table 1 that I create with a shell script. Occasionally my IP address starts with 208 (i.e. 208.xxx.xxx.xxx) and the table blocks it EVEN though my IP is not contained in the table.

As a test, I comments out any line that puts an IP starting with 208 in the table. For example

#joes datacenter
ipfw table 1 add   66.85.72.0/21
ipfw table 1 add   69.195.128.0/19
ipfw table 1 add   96.43.128.0/20
ipfw table 1 add   104.192.168.0/22
ipfw table 1 add   104.218.16.0/21
ipfw table 1 add   172.86.176.0/21
ipfw table 1 add   204.27.56.0/21
##ipfw table 1 add   208.94.240.0/21

Using ipfw table 1 list >file and editing that file, here is the proof that IPs starting with 208 are not in the table:

207.244.64.0/18 0
207.244.144.0/20 0
207.250.234.100/32 0
207.254.208.0/20 0
209.11.0.0/16 0
209.15.0.0/20 0
209.15.16.0/23 0
209.15.18.0/23 0
209.15.20.0/22 0

From /var/log/security (with a little sanitizing):

Feb 20 10:04:17 theranch kernel: ipfw: 553 Deny TCP 208.54.5.229:18791 mydoip.198:143 in via vtnet0

Here is the relevant rc.firewall line that creates rule 553:

00553 deny log ip from table(1) to any dst-port 143

In summary, I have shown that there are no entries in ipfw table 1 that start with 208 (i.e. 208.xxx.xxx.xxx). Yet my IP is blocked.

1 Answer

Solved. I found a line where I had no value after the slash in the CIDR.

Visually
ipfw table 1 add 204.27.56.0/
instead of
ipfw table 1 add 204.27.56.0/21

This is just an example. The bug was on a different line. I suppose ipfw has an undefined behavior with that typo.

Have another answer? Share your knowledge.