From owner-freebsd-net@freebsd.org Wed Jul 26 12:32:43 2017 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5F522DBD716 for ; Wed, 26 Jul 2017 12:32:43 +0000 (UTC) (envelope-from m.muenz@spam-fetish.org) Received: from mailout-02.maxonline.de (mailout-02.maxonline.de [81.24.66.23]) (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 18AD61E30 for ; Wed, 26 Jul 2017 12:32:42 +0000 (UTC) (envelope-from m.muenz@spam-fetish.org) Received: from web03-01.max-it.de (web03-01.max-it.de [81.24.64.215]) by mailout-02.maxonline.de (Postfix) with ESMTPS id 862024B; Wed, 26 Jul 2017 14:32:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by web03-01.max-it.de (Postfix) with ESMTP id 75AD528B848; Wed, 26 Jul 2017 14:32:40 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at web03-01.max-it.de Received: from web03-01.max-it.de ([127.0.0.1]) by localhost (web03-01.max-it.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tZQaLzRzeBdt; Wed, 26 Jul 2017 14:32:40 +0200 (CEST) Received: from [81.24.66.132] (unknown [81.24.66.132]) (Authenticated sender: m.muenz@spam-fetish.org) by web03-01.max-it.de (Postfix) with ESMTPA id 362AA28B847; Wed, 26 Jul 2017 14:32:40 +0200 (CEST) Subject: Re: NAT before IPSEC - reply packets stuck at enc0 To: freebsd-net@freebsd.org References: <459d59f7-2895-8aed-d547-be46a0fbb918@spam-fetish.org> <1279753e-9ad1-2c02-304e-5001e2bbc82f@spam-fetish.org> <15e6eb38-ef0c-7bfd-5f2c-d2acc8ea1af4@yandex.ru> <63e80fcf-915e-2dd5-d8c9-1904c8261c6f@yandex.ru> <1c91cd8f-105d-e886-3126-67505c6c3900@spam-fetish.org> <1e889acf-49d1-b70f-7097-82e6e4dfabb6@spam-fetish.org> <454ed1b7-a80f-b096-cfa1-3c32d1e60f7d@yandex.ru> <5dfdfbb3-1046-5abe-b23a-b62c215b5d08@yandex.ru> <860b48aa-b99e-7b71-3724-587ee0a7fe80@spam-fetish.org> <1b831b84-1d3f-38cb-acee-07a339315417@yandex.ru> <0bbf5bb9-8089-f9ce-3b1d-e9bcbdbc6c76@spam-fetish.org> <3a7d5a5b-3b72-4cfe-2d8e-c832f7bfab5c@spam-fetish.org> <2672efbc-49f2-efba-07d6-feeb5c8e3757@yandex.ru> From: "Muenz, Michael" Message-ID: <6bf87e8a-f557-bfab-13ce-dd8accb88299@spam-fetish.org> Date: Wed, 26 Jul 2017 14:33:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <2672efbc-49f2-efba-07d6-feeb5c8e3757@yandex.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jul 2017 12:32:43 -0000 Am 26.07.2017 um 12:20 schrieb Andrey V. Elsukov: > On 26.07.2017 12:47, Muenz, Michael wrote: >> When I type setkey -PD I get: >> >> 10.24.66.0/24[any] 10.26.1.0/24[any] any >> in ipsec >> esp/tunnel/81.24.74.3-213.244.192.191/unique:2 >> created: Jul 26 11:03:53 2017 lastused: Jul 26 11:40:02 2017 >> lifetime: 9223372036854775807(s) validtime: 0(s) >> spid=5 seq=1 pid=4292 >> refcnt=1 >> 10.26.1.0/24[any] 10.24.66.0/24[any] any >> out ipsec >> esp/tunnel/213.244.192.191-81.24.74.3/unique:2 >> created: Jul 26 11:03:53 2017 lastused: Jul 26 11:40:02 2017 >> lifetime: 9223372036854775807(s) validtime: 0(s) >> spid=6 seq=0 pid=4292 >> refcnt=1 >> >> >> So it's in use. >> >> But when I type in your command it just "hangs". Not the system, but the >> command doesn't get completed. >> >> root@PB-FW1-FRA:~ # setkey -v -c spdadd -4 10.26.2.0/24 10.24.66.0/24 >> any -P out ipsec esp/tunnel/213.244.192.191-81.24.74.3/require ; >> > You need to do it this way: > 1. setkey -v -c > 2. type the policy specification > 3. press Enter and then press ^D > > > # setkey -v -c > spdadd -4 10.26.2.0/24 10.24.66.0/24 any -P out ipsec > esp/tunnel/213.244.192.191-81.24.74.3/unique:2 ; > ^D > > Also, since your policies uses "unique" level, you need to specify the > same level using "unique:N" syntax. > > Also if it is interesting to you, I patched ipfw_nat to be able specify > needed direction. The patch is untested at all :) > https://people.freebsd.org/~ae/nat_in_out.diff > > You need to rebuild ipfw(4) and ipfw_nat(4) kernel modules, and also > ipfw(8) binary. > > With this patch you can use the following commands: > > ipfw nat 1 config ip 10.26.1.1 log > ipfw add 179 nat-out 1 all from 10.26.2.0/24 to 10.24.66.0/24 in recv vtnet1 > ipfw add 179 nat-in 1 all from 10.24.66.0/24 to 10.26.1.1 in recv enc0 > > or these: > ipfw nat 1 config ip 10.26.1.1 log reverse > ipfw add 179 nat-in 1 all from 10.26.2.0/24 to 10.24.66.0/24 in recv vtnet1 > ipfw add 179 nat-out 1 all from 10.24.66.0/24 to 10.26.1.1 in recv enc0 > > Or maybe guys from OpenSense can help with testing. > You are a genius! Many thanks for you patience with me! Now I have a running setup and it also works with unpatched OPNsense kernel: kldload ipfw_nat ipfw nat 1 config ip 10.26.1.1 log ipfw add 179 nat 1 log all from 10.26.2.0/24 to 10.24.66.0/24 out xmit enc0 ipfw add 179 nat 1 log all from 10.24.66.0/24 to 10.26.1.1 in recv enc0 setkey -PD | grep unique setkey -v -c spdadd -4 10.26.2.0/24 10.24.66.0/24 any -P out ipsec esp/tunnel/213.244.192.191-81.24.74.3/unique:X ; ^D Thats all! I got it running, did a reboot and then it failed everytime until I saw the number after unique changes. How is this number calculated? I need this for templating the script. Thanks for you help, you made my day/week/month/year :) Michael