From owner-freebsd-net@FreeBSD.ORG Fri Jan 30 09:05:39 2015 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6C430210; Fri, 30 Jan 2015 09:05:39 +0000 (UTC) Received: from onlyone.friendlyhosting.spb.ru (onlyone.friendlyhosting.spb.ru [46.4.40.135]) by mx1.freebsd.org (Postfix) with ESMTP id 2D705A3B; Fri, 30 Jan 2015 09:05:39 +0000 (UTC) Received: from [192.168.135.70] (unknown [94.19.235.70]) (Authenticated sender: lev@serebryakov.spb.ru) by onlyone.friendlyhosting.spb.ru (Postfix) with ESMTPSA id F3EF35C002; Fri, 30 Jan 2015 12:04:52 +0300 (MSK) Message-ID: <54CB4943.4050104@FreeBSD.org> Date: Fri, 30 Jan 2015 12:05:07 +0300 From: Lev Serebryakov Reply-To: lev@FreeBSD.org Organization: FreeBSD User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Julian Elischer , freebsd-net@freebsd.org Subject: Re: ipfw, nat and stateful firewall: why "keep-state" on "skipto" works at all and how do this properly? References: <54CAD234.3020407@FreeBSD.org> <54CAED70.1080501@freebsd.org> In-Reply-To: <54CAED70.1080501@freebsd.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jan 2015 09:05:39 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 30.01.2015 05:33, Julian Elischer wrote: >> 12700 skipto 12900 ip from any to any keep-state 12800 deny ip >> from any to any 12900 nat 1 ip from any to any out 12999 allow ip >> from any to any >> >> And rules for inbound ones are: >> >> 11000 deny ip from any to not me 11500 nat 1 ip from any to any >> 11510 check-state 11600 allow tcp from any to me ssh,http setup >> keep-state 11999 deny ip from any to any > ok so the dynamic rule is created on the outgoing packet, and > associated with skipto 12900 which sets up a NAT session. > > on a later incoming packet, the rule 11500 is hit first so the > packets are NAT'd back, and then their state is compared to that > stored in the outgoing path, and if they match, they go to 12900 > where they are not checked again becasue they are not 'out' > packets. so it falls through to 12999 and is allowed in. (in its > changed form). packets that are not in a known session fall through > teh check-state and are dropped. > > it all looks ok to me. kinda cute actually. Not cute at all for me, as 12900 needs "out" (it is already in "out" group of rules!) and incoming packet is jumped to outbound section :) > It would be really cool if state could hold the NAT'd form of the > packets as well. but what you have above is really kinda cute, and > seems to work as far as I can read. what "other filtration" do you > want? Other filtration is hypothetical now, but I don't like this "skip -> nat with additional "redundant" check -> allow" pattern. > I always do what is done here and separate inwards and outwards > packets for the external interface into two different sets of > rules (and another set for other interfaces). Yep, it is exactly what I do, these two groups of rules are not only rules, of course. - -- // Lev Serebryakov AKA Black Lion -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (MingW32) iQJ8BAEBCgBmBQJUy0lDXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXRGOTZEMUNBMEI1RjQzMThCNjc0QjMzMEFF QUIwM0M1OEJGREM0NzhGAAoJEOqwPFi/3EePgH4P+wWTLKxIhvRk1oD3GJqs4GHH d7vf+JoY1S2RDOJHBvNGfyc42YSBn6ubtIs2+dG/si9QzzmO57LFMPwiWFKRbPn4 rzJJ6qox91VMwfFnaDe1sceN072Dw5lbzrZN/AcTUZHBRpkGyKY6XHGamyZhMQzy pDlE0z1tYmnUwJXk7uQa5CitqKkVRozS2DWxpTPhTyfJbYASja68+h1aoRw7vobV mfKYOQpC+m2NHt8O2kT5S9XROAbDsTVtz9tXwqveJjsoBgAKgSamqp/u2YuLbZIy +ioYUHUbuJI1cfHEvpUvcnsZnx83TrIllDTso9WvWK7WRVzTkKnZEakMu3cMqW9S rVnFxRRklMwpbI+VoRY5BSjjdQ25iZlW0AGCgvgMdWstY/dM8Kv1xIdk92b2mAHR 6KlsnVaYPzf5R4gdjFlA6GVgiPhVW2o1/l9ynMZn53wETAHQGWm5pVbTmKWQqp3T ng6SxU7loZNIXHFFEnY+4Gk5e/Fg9qEOKFiKexPQBFD0mSlX0jMCAx/sMIiJPNm7 iU9Ip+MxGQSm7FgJ+GaRGXh3eSsX9/hphVewl6swyrjLkqVQayLRo+UrgwlA2jhw Ii4/XtktupWHMLmZPKXgGDDcRzXQ+PVQsLSdNHDnlNwIFS6Ss0ma+sPoBJM3wQKg SjHn11Rs6CpoHzRfn0oF =NXsa -----END PGP SIGNATURE-----