From owner-freebsd-bugs@FreeBSD.ORG Sun May 11 11:20:00 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 94076DDE for ; Sun, 11 May 2014 11:20:00 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 70A962A4A for ; Sun, 11 May 2014 11:20:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s4BBK0NI033773 for ; Sun, 11 May 2014 11:20:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s4BBK0eH033772; Sun, 11 May 2014 11:20:00 GMT (envelope-from gnats) Resent-Date: Sun, 11 May 2014 11:20:00 GMT Resent-Message-Id: <201405111120.s4BBK0eH033772@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Andriy Mayevskyy Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 62B7ACE0 for ; Sun, 11 May 2014 11:14:37 +0000 (UTC) Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 304672A30 for ; Sun, 11 May 2014 11:14:37 +0000 (UTC) Received: from cgiserv.freebsd.org ([127.0.1.6]) by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s4BBEbUA093937 for ; Sun, 11 May 2014 11:14:37 GMT (envelope-from nobody@cgiserv.freebsd.org) Received: (from nobody@localhost) by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s4BBEbnk093936; Sun, 11 May 2014 11:14:37 GMT (envelope-from nobody) Message-Id: <201405111114.s4BBEbnk093936@cgiserv.freebsd.org> Date: Sun, 11 May 2014 11:14:37 GMT From: Andriy Mayevskyy To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: kern/189655: [ipfw] ipfw does not pass same_ports option to kernel nat (libalias) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 May 2014 11:20:00 -0000 >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@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 :200 and w/o same_ports to : 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: