From nobody Fri Mar 11 21:05:46 2022 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E53071A07F4E for ; Fri, 11 Mar 2022 21:05:50 +0000 (UTC) (envelope-from matteo@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KFdkk61RHz3R33; Fri, 11 Mar 2022 21:05:50 +0000 (UTC) (envelope-from matteo@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647032750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1zdHB+JkOw7MSfXvu2PkJAoTxhb9FTaQmIeKN6eZz1Q=; b=PywfWVmoKDnYExT9asl1ob2tPjz0+dafsJQTAOuIVg0tFoQjSwMjZMGiMNEztlKy7zZhbm ZxaRSc9Dggl/j2CNV9q+myXPkvRWeKyszbhun1PtVzHqxiBZKe4HuvsZBseh6a2Izuu58w bnuBxfu6kh2dj0bPD/rgCMIERnu2+pruRlcKqPofLzSHQ9zC2CqbOfW4AyD6ifw2Z7cH3p 8+9qVx6Snf+Jr6GyWfLT7biY0FwBTpToHy4DmGqahzv8C/gwIu8MAoG3xgruzdwNDBBzcm duZwc2PztRAOvuaekMonlsIBabu79UvYFQh2Ja4LQqIWyK3QgkL1pIKcVuD9Bw== Received: from ubertino.local (unknown [IPv6:2601:19b:4400:1779::1000]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: matteo/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 90CB723F; Fri, 11 Mar 2022 21:05:50 +0000 (UTC) (envelope-from matteo@freebsd.org) Date: Fri, 11 Mar 2022 16:05:46 -0500 From: Matteo Riondato To: "Andrey V. Elsukov" Cc: freebsd-net@freebsd.org Subject: Re: if_enc(4) and net.inet.ipcomp.ipcomp_enable Message-ID: <20220311210546.sqdtgrtv4haxz3rg@ubertino.local> X-PGP-Key: http://rionda.to/files/matteogpg.asc References: <00EA8894-6B8C-4D21-8D5D-DA490FD24697@FreeBSD.org> <2eb08961-3db2-ee21-e434-e058cd360170@yandex.ru> List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="j5hitlvbukpt3k6h" Content-Disposition: inline In-Reply-To: <2eb08961-3db2-ee21-e434-e058cd360170@yandex.ru> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647032750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1zdHB+JkOw7MSfXvu2PkJAoTxhb9FTaQmIeKN6eZz1Q=; b=oc6cnBDMJooWwvqd6gZAOkOBEkIav0Xt1pUUMp1L9HppcnlhApuL//4MdA7+OE9ujmKQCQ EZxkYxWtCYw4bMMLnZtsWbghNWMQdCOtc+G0EG7hduZBvGrhbtGaWVbhv5zOA3+g6m+37N r+PL7DOypvvYgmwngQnZtxRafDtrjji9lMSz9vJHen7E1+gDgIuKS/kFoOcPfCJ2rS3nae 48zU5pDcTbApPLVgm/ig0R4dAWqrMVBFn2rbeS85rbm/6IsOyc/0YJfFeiLpRofbgnh+CX YMIGVpvtj/LJGlEi8w3YBqdQVNQWBYF28G8XJPZtGyEV4n2WVKm/I+xLKiL2tw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647032750; a=rsa-sha256; cv=none; b=T1dTD1Vo28ZZMynrdnCop8NxTdELHwbtGxztDFQ2yJywarAjMHQRSKWIi8+qlQy5eiNenh IYrzDcvcywFMblSLkuG9wHP64qIn3i9E0/CvoRrxrrxi4lts7iaDtDEDXOLMvqtpAUebJP QPd/4OISf1l0uQraJHLQvQN/9/N3SU9BHlePviOjeGafud2glJ+6syyJKFkDbIgAUJDup9 Sv3W8BnFweW9+1t48f6vC85MPJ1frpI+FvAb7uJGHRHfRnP0PiziIRSl3taXEkqnXi6INx Awq34WavOh1hXmyy91MtQ8uY/CjHDtPAgHe5rQsxnPeuuxB5824k9Bj5VFmvdA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N --j5hitlvbukpt3k6h Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2022-03-01 at 05:52 EST, Andrey V. Elsukov wrote: >28.02.2022 02:54, Matteo Riondato =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >>Hello net@, >> >>I am trying to use pf to filter packets in ipsec tunnels by filtering=20 >>on enc0 from if_enc(4). >> >>I have the following values for the net.enc sysctl subtree:=20 >>net.enc.out.ipsec_bpf_mask: 1 >>net.enc.out.ipsec_filter_mask: 1 >>net.enc.in.ipsec_bpf_mask: 2 >>net.enc.in.ipsec_filter_mask: 2 >> >>and I have >> >>net.inet.ipsec.filtertunnel: 1 >> >>Everything works well when the tunnel does not use ipcomp, but when it=20 >>does, the incoming packets seem to ignore the value of the=20 >>net.enc.in.ipsec_filter_mask sysctl, thus they show up in pf =E2=80=9Ctwi= ce=E2=80=9D:=20 >>once with both external and internall headers, and once only with=20 >>internal (the value of 2 for this sysctl should make these packets=20 >>show up only with internal headers). The same can be observed with=20 >>tcpdump on enc0. This behavior makes it hard to do filtering. >> >>Is this behavior expected? >are you sure that it is not just on ingress and egress? You can use -Q =20 >flag for tcpdump to make sure. Thank you for the suggestion, I realized I was just misinterpreting the=20 output of tcpdump. >The first time when you see IPcomp packet in PF, it is when it arrives=20 >into IP stack on a physical interface (em, igb, ix, etc.). The second=20 >time is after decompression on if_enc interface, it is called from=20 >IPsec stack. Are you sure about the above? It seems to me (only by observing the effects of changing pf rules)=20 that, with the net.enc sysctl values as above, the ipcomp packet is=20 first seen by pf on if_enc, and then on the physical interface. I should perhaps specify that by "ipcomp packets", I also mean the ipip=20 packets that may go through the tunnel uncompressed because they are not=20 large enough to warrant compression. I wonder whether the handling of=20 ipip packets vs "real" ipcomp ones is different. Thanks, Matteo --j5hitlvbukpt3k6h Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEa9uKZL0hP4E8Nl5vGwL9SVQlVQEFAmIruaUTGGhrcHM6Ly9w Z3AubWl0LmVkdQAKCRAbAv1JVCVVAaJnEADjoDk9oRCbsY133k7ZKa/LMFi2tzNe vm2nV8gmRxST7ta5GVpCRYyixwU7BzOQHSdOpuxK9jn5r24we7m0XXUB5mZmFPAw vbFutaYLdX20oaUTIy2XAxNPkNgZ3xwHCOnRoItt5FUD0jFciCLPd4MqzFVHzMVp ++8+A9PYOqwFQ6jLSkvQMzvDMKkjQLMjxxnMBnwUVH9grrOgqxmt/g9dQYEsOWUb uczD8Om4pLCuoi2m3NxgCIRVVtT9OUtsHrGglY7ecc47swC06fRogbPc7vout1nK fHNoBMeISMhqxqc9vK87B9+SSbFsje1KahqSH32LLjNTiip/NYEztBbRrrEmo17D vD46QE3dGHEFNiwNtMXqfJrWiql3VueiALuUwYevH5a1BLkhmklgJ2HckR6JKIR3 iYgdQbC9XtdWWu6It0qots51IZK8OTgMo0TzdpPE2Y0VG7XQEFS88mjRIQ5b/Az4 RJAEV1qrJv3LCYnlYNG6v0c3g5GfPFwYtOzMsWH7rHhgo8B9kQGkJ7WP4AZ+lmpw 0bpY7KiAgdX8p8bsEYGWaEtwWP/Vc6WI45CvRvtrszmgdZ73AoCETOiiSx1jTwsP 2mP7NggEYRiQSQCmyAp/hXAdtA3Imws0JVUIpQdD4WD3nneUTks6DZtPgHdXdDBi hu9F18nihKOTmw== =haNo -----END PGP SIGNATURE----- --j5hitlvbukpt3k6h--