ipfw blocks IP address not in table

February 20, 2017 116 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
ipfw table 1 add
ipfw table 1 add
ipfw table 1 add
ipfw table 1 add
ipfw table 1 add
ipfw table 1 add
##ipfw table 1 add

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

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

Feb 20 10:04:17 theranch kernel: ipfw: 553 Deny TCP 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.

ipfw table 1 add
instead of
ipfw table 1 add

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.