Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp761860ybc; Fri, 22 Nov 2019 12:41:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzlv7HoQXEZHHFjt/j5X8tXsvQffGmXv86ncObkvhs2DunGEq4BBZ+LqkqyhvGvTSt5dV9e X-Received: by 2002:a17:906:8548:: with SMTP id h8mr24046621ejy.290.1574455303539; Fri, 22 Nov 2019 12:41:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574455303; cv=none; d=google.com; s=arc-20160816; b=gLG9IaO8t75Y2NQckDEPYU2pfW/ACzZ5ZJXoZG0X+CcCNqxvxfgxFFjtPK2cpVB2CO xMLzpDFp7Tg6CCQMzKGiqTr2qLuJRTzwh0+i2Dp0C9EDFdlOKOrwGHHi/XCjI3IerD1F pdAOOk2bBbf51FwWYUlfk4o1mhTiD9e/9btAy5Eh0PAuXMjK/tKh15gBkl9ZVv3IpjOM rQXVgcjsejWLN135/v5L9h7uKlKjFS3H1/w03rOQl+TCbVyhs33HjZYyPcgNFeNxOt1Z /hsbaMWPG3yLlGgce39M1F60DVbTWRdSwsMOKDP4IZGgQqO9I3TjFQ4dRuWqwsPSrrpA YEgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from:dkim-signature; bh=V/dlCJK+i6cXX9AuNkha8Hfa/aQ9TDGvh5ka3yqobAs=; b=biRYzgovYnM/ajcmHg0YSg10pOt8jcG9/DhHuoGVrAmp+DxLZzt5o3gbl9LCzDyO/h NnTNWfzhlrop4tGLI9wZbFDDxHdTQ+qWGI7U6CYkfQkBnKO34Dj3QSLH0DxxhyRW7ijZ YesOJXaHzMjLV9qBkjWL+vI5/a9mTuNoHaQv5Ww3ruFTRSPOIBa/LVzs4yc/kWuROhCA 6smqtDitFUedQ3KJ41yVpnvTc5lG26YJaU1kS1nIxXRHz4SILLp1+VdZUjH/Eu4542nk cgeed/VO0KlIm7sKXu/tgxLD9FroOOYaxjXgo3ArZTsJK4aMyIHZtsf6HKxsnLJ7fhUf IVwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Se850C/O"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ov16si5035630ejb.274.2019.11.22.12.41.19; Fri, 22 Nov 2019 12:41:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Se850C/O"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727127AbfKVUj3 (ORCPT + 99 others); Fri, 22 Nov 2019 15:39:29 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:31821 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726526AbfKVUj3 (ORCPT ); Fri, 22 Nov 2019 15:39:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574455167; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V/dlCJK+i6cXX9AuNkha8Hfa/aQ9TDGvh5ka3yqobAs=; b=Se850C/Ogt11AV1fMU2ytvwZGYSwBqA15N+fQEHr4Ive0LxPc6HWly5Wcj14BdmoFlfARN 7KBRGKsW7BURaR41KXzjqcLteYGyfLSovDtIS2OAp9m08KmaZmRezJc2DHumbnFu+IcCQQ J3gwlqymFyAQ4mqZv6d4vPIby04SNTc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-DMVZQvRcOuKSr86Ijn8kOQ-1; Fri, 22 Nov 2019 15:39:24 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C7DE8038A1; Fri, 22 Nov 2019 20:39:21 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (unknown [10.18.25.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4B4E6084E; Fri, 22 Nov 2019 20:39:17 +0000 (UTC) From: Aaron Conole To: Marcelo Ricardo Leitner Cc: netdev@vger.kernel.org, Pravin B Shelar , "David S . Miller" , Jamal Hadi Salim , Cong Wang , Jiri Pirko , dev@openvswitch.org, linux-kernel@vger.kernel.org, paulb@mellanox.com, Florian Westphal Subject: Re: [PATCH net 2/2] act_ct: support asymmetric conntrack References: <20191108210714.12426-1-aconole@redhat.com> <20191108210714.12426-2-aconole@redhat.com> <20191114162949.GB3419@localhost.localdomain> <20191118224054.GB388551@localhost.localdomain> Date: Fri, 22 Nov 2019 15:39:16 -0500 In-Reply-To: <20191118224054.GB388551@localhost.localdomain> (Marcelo Ricardo Leitner's message of "Mon, 18 Nov 2019 19:40:54 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: DMVZQvRcOuKSr86Ijn8kOQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Marcelo Ricardo Leitner writes: > On Mon, Nov 18, 2019 at 04:21:39PM -0500, Aaron Conole wrote: >> Marcelo Ricardo Leitner writes: >>=20 >> > On Fri, Nov 08, 2019 at 04:07:14PM -0500, Aaron Conole wrote: >> >> The act_ct TC module shares a common conntrack and NAT infrastructure >> >> exposed via netfilter. It's possible that a packet needs both SNAT a= nd >> >> DNAT manipulation, due to e.g. tuple collision. Netfilter can suppor= t >> >> this because it runs through the NAT table twice - once on ingress an= d >> >> again after egress. The act_ct action doesn't have such capability. >> >>=20 >> >> Like netfilter hook infrastructure, we should run through NAT twice t= o >> >> keep the symmetry. >> >>=20 >> >> Fixes: b57dc7c13ea9 ("net/sched: Introduce action ct") >> >>=20 >> >> Signed-off-by: Aaron Conole >> >> --- >> >> net/sched/act_ct.c | 13 ++++++++++++- >> >> 1 file changed, 12 insertions(+), 1 deletion(-) >> >>=20 >> >> diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c >> >> index fcc46025e790..f3232a00970f 100644 >> >> --- a/net/sched/act_ct.c >> >> +++ b/net/sched/act_ct.c >> >> @@ -329,6 +329,7 @@ static int tcf_ct_act_nat(struct sk_buff *skb, >> >> =09=09=09 bool commit) >> >> { >> >> #if IS_ENABLED(CONFIG_NF_NAT) >> >> +=09int err; >> >> =09enum nf_nat_manip_type maniptype; >> >> =20 >> >> =09if (!(ct_action & TCA_CT_ACT_NAT)) >> >> @@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb, >> >> =09=09return NF_ACCEPT; >> >> =09} >> >> =20 >> >> -=09return ct_nat_execute(skb, ct, ctinfo, range, maniptype); >> >> +=09err =3D ct_nat_execute(skb, ct, ctinfo, range, maniptype); >> >> +=09if (err =3D=3D NF_ACCEPT && >> >> +=09 ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) { >> >> +=09=09if (maniptype =3D=3D NF_NAT_MANIP_SRC) >> >> +=09=09=09maniptype =3D NF_NAT_MANIP_DST; >> >> +=09=09else >> >> +=09=09=09maniptype =3D NF_NAT_MANIP_SRC; >> >> + >> >> +=09=09err =3D ct_nat_execute(skb, ct, ctinfo, range, maniptype); >> >> +=09} >> > >> > I keep thinking about this and I'm not entirely convinced that this >> > shouldn't be simpler. More like: >> > >> > if (DNAT) >> > =09DNAT >> > if (SNAT) >> > =09SNAT >> > >> > So it always does DNAT before SNAT, similarly to what iptables would >> > do on PRE/POSTROUTING chains. >>=20 >> I can rewrite the whole function, but I wanted to start with the smaller >> fix that worked. I also think it needs more testing then (since it's >> something of a rewrite of the function). >>=20 >> I guess it's not too important - do you think it gives any readability >> to do it this way? If so, I can respin the patch changing it like you >> describe. > > I didn't mean a rewrite, but just to never handle SNAT before DNAT. So > the fix here would be like: > > -=09return ct_nat_execute(skb, ct, ctinfo, range, maniptype); > +=09err =3D ct_nat_execute(skb, ct, ctinfo, range, maniptype); > +=09if (err =3D=3D NF_ACCEPT && maniptype =3D=3D NF_NAT_MANIP_DST && > +=09 ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) { > +=09=09maniptype =3D NF_NAT_MANIP_SRC; > +=09=09err =3D ct_nat_execute(skb, ct, ctinfo, range, maniptype); > +=09} > +=09return err; But the maniptype of the first call could be NAT_MANIP_SRC. In fact, that's what I see if the packet is reply direction && !related. So, we need the block to invert the manipulation type. Otherwise, we miss the DNAT manipulation. So I don't think I can use that block. >> >> +=09return err; >> >> #else >> >> =09return NF_ACCEPT; >> >> #endif >> >> --=20 >> >> 2.21.0 >> >>=20 >>=20