kern/189655: [ipfw] ipfw does not pass same_ports option to kernel nat (libalias)

Andriy Mayevskyy major12 at gmail.com
Sun May 11 11:20:00 UTC 2014


>Number:         189655
>Category:       kern
>Synopsis:       [ipfw] ipfw does not pass same_ports option to kernel nat (libalias)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 11 11:20:00 UTC 2014
>Closed-Date:
>Last-Modified:
>Originator:     Andriy Mayevskyy
>Release:        9.2-RELEASE
>Organization:
>Environment:
FreeBSD natbox 9.2-RELEASE FreeBSD 9.2-RELEASE #0: Mon Apr 21 17:32:51 EEST 2014 root at natbox:/usr/obj/usr/src/sys/TEST i386
>Description:
ipfw command is used to configure kernel nat.
ipfw option 'same_ports' seems to be ignored while configuration and kernel nat (libalias) always behaves like this option was enabled.

E.g.
If we send packet from 10.0.0.5 port 200
with same_ports packed should be aliased (if possible) to <alias_addr>:200
and w/o same_ports to <alias_addr>:<random_port>

Currently packets are aliased to port 200 in both cases
ipfw nat 1 config if em1 same_ports
and
ipfw nat 1 config if em1
>How-To-Repeat:
Test kernel is:
-------------
ident TEST
options IPFIREWALL
options IPFIREWALL_DEFAULT_TO_ACCEPT
options IPDIVERT
options LIBALIAS
options IPFIREWALL_NAT
include GENERIC
-------------
ipfw is configured in next way:

ipfw nat 1 config if em1
ipfw add 100 nat 1 ip from any to any via em1

Network layout is
client --(em0) natbox (em1)-- internet

At client I use python script to bind to port 200 and send packets to internet.
At natbox I can check packets with tcpdump -n -i em1
>Fix:
I suppose that there is a bug in
sys/netpfil/ipfw/ip_fw_nat.c

LibAliasSetMode has next prototype

/* Change mode for some operations */
unsigned int
LibAliasSetMode(
    struct libalias *la,
    unsigned int flags,		/* Which state to bring flags to */
    unsigned int mask		/* Mask of which flags to affect (use 0 to
				 * do a probe for flag values) */
)

and it is called in wrong way
LibAliasSetMode(ptr->lib, cfg->mode, cfg->mode);

This code will set only the bits that are 1 (ones). But we need to clear bit that is responsible for SAME_PORTS so this bit value should be 0 in mode and 1 in mask.

So since same_ports are enable by default in libalias and ipfw fails to change it we have described incorrect behavior.

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list