Date: Thu, 5 Aug 2004 15:42:46 GMT From: Ming Fu <fming@borderware.com> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/70038: ipfilter rdr rule does not work for non-TCP/UDP protocols Message-ID: <200408051542.i75FgkeC097352@www.freebsd.org> Resent-Message-ID: <200408051550.i75FoOFa026017@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> 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<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> 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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200408051542.i75FgkeC097352>