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

Andriy Mayevskyy major12 at
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
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 11 11:20:00 UTC 2014
>Originator:     Andriy Mayevskyy
>Release:        9.2-RELEASE
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
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.

If we send packet from 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
ipfw nat 1 config if em1
Test kernel is:
ident TEST
options IPDIVERT
options LIBALIAS
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
I suppose that there is a bug in

LibAliasSetMode has next prototype

/* Change mode for some operations */
unsigned int
    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.


More information about the freebsd-bugs mailing list