From owner-freebsd-bugs@FreeBSD.ORG Thu Aug 5 15:50:44 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DC2EE16A57A for ; Thu, 5 Aug 2004 15:50:44 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C306043D64 for ; Thu, 5 Aug 2004 15:50:24 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i75FoOMd026020 for ; Thu, 5 Aug 2004 15:50:24 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i75FoOFa026017; Thu, 5 Aug 2004 15:50:24 GMT (envelope-from gnats) Resent-Date: Thu, 5 Aug 2004 15:50:24 GMT Resent-Message-Id: <200408051550.i75FoOFa026017@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, Ming Fu Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5782116A4CE for ; Thu, 5 Aug 2004 15:42:46 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3D9CB43D73 for ; Thu, 5 Aug 2004 15:42:46 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i75FgkZI097353 for ; Thu, 5 Aug 2004 15:42:46 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i75FgkeC097352; Thu, 5 Aug 2004 15:42:46 GMT (envelope-from nobody) Message-Id: <200408051542.i75FgkeC097352@www.freebsd.org> Date: Thu, 5 Aug 2004 15:42:46 GMT From: Ming Fu To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: kern/70038: ipfilter rdr rule does not work for non-TCP/UDP protocols X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Aug 2004 15:50:46 -0000 >Number: 70038 >Category: kern >Synopsis: ipfilter rdr rule does not work for non-TCP/UDP protocols >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 05 15:50:24 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Ming Fu >Release: 4.10 and 4.7 >Organization: Borderware Technologies Ltd >Environment: FreeBSD bsd410.borderware.com 4.10-RELEASE FreeBSD 4.10-RELEASE #0: Tue May 25 22:47:12 GMT 2004 root@perseus.cse.buffalo.edu:/usr/obj/src/sys/GENERIC i386 >Description: ipfilter redirect rule can not match for non-TCP/UDP protocols if there is specific source destination filter on the rule. The rule matching code in sys/contrib/ipfilter/netinet/ip_nat.c: ip_natin() will always fail the match. >How-To-Repeat: On a machine with two interface card: lnc0: flags=8843 mtu 1500 inet 10.1.19.3 netmask 0xff000000 broadcast 10.255.255.255 inet6 fe80::20c:29ff:fe90:3a47%lnc0 prefixlen 64 scopeid 0x1 ether 00:0c:29:90:3a:47 lnc1: flags=8843 mtu 1500 inet 172.31.19.3 netmask 0xffff0000 broadcast 172.31.255.255 inet6 fe80::20c:29ff:fe90:3a51%lnc1 prefixlen 64 scopeid 0x2 ether 00:0c:29:90:3a:51 Apply these two ipfilter rules: you can substitude esp with any protocol other than TCP and UDP. pass in log quick on lnc1 proto esp from 0.0.0.0/0 to 0.0.0.0/0 rdr lnc1 from 172.31.2.146 to 172.31.19.3 -> 10.1.19.1 port 0 esp send an esp packet from ip 172.31.2.146 to 172.31.19.3 from ipmon, you can see that the packet hit filter rule without NAT. >Fix: In the /usr/src/sys/contrib/ipfilter/netinet/ip_nat.c function ip_natin(), after search through known nat states and find none, it starts to look through the rules. However, because the rdr rule has src/dst restriction, the np->in_flags will have IPN_FILTER bit set, and the nflags will always be zero if the incoming packet is not of TCP and UDP. The test on the line #3 of the if statement will always fail. As far as I know, the line #3 only test if the TCP or UDP protocol matches, which has already tested by the line #2 of the if. The test looked redundant to me. The fix was tested on FreeBSD 4.7 *** 2631,2638 **** hv = NAT_HASH_FN(iph, 0, ipf_rdrrules_sz); for (np = rdr_rules[hv]; np; np = np->in_rnext) { if ((np->in_ifp && (np->in_ifp != ifp)) || ! (np->in_p && (np->in_p != fin->fin_p)) || ! (np->in_flags && !(nflags & np->in_flags))) continue; if (np->in_flags & IPN_FILTER) { if (!nat_match(fin, np, ip)) --- 2649,2656 ---- hv = NAT_HASH_FN(iph, 0, ipf_rdrrules_sz); for (np = rdr_rules[hv]; np; np = np->in_rnext) { if ((np->in_ifp && (np->in_ifp != ifp)) || ! (np->in_p && (np->in_p != fin->fin_p)) ! ) continue; if (np->in_flags & IPN_FILTER) { if (!nat_match(fin, np, ip)) >Release-Note: >Audit-Trail: >Unformatted: