Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp765365ybc; Fri, 22 Nov 2019 12:45:51 -0800 (PST) X-Google-Smtp-Source: APXvYqwCtFiH/AF/WTkNSFbK+9nWktvFtOTRvkC+Vinp3bgBAVx8PGq02tzVlRVz1Bp58fp83MPB X-Received: by 2002:a05:6402:282:: with SMTP id l2mr3723525edv.187.1574455551590; Fri, 22 Nov 2019 12:45:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574455551; cv=none; d=google.com; s=arc-20160816; b=x9r/1ij6n72JOzD6PVrt+IoerVcyp4+nwyUVgHxxHqpvC4O7K/UjfJLtA9oWOjbPft Pwqfl8TGJKXwhpgqHcQQ5IA+BEaHHXOLG9LFd6lpqUITGJvCdEzTYij81QxzIS4Z/nYL NSHDRBYMbsM90K+bMUSXSi1yrK0ciKP5/1vhKzfWB/3gdS/sNa3LFlhsL9WIJ+dDsN/O MY9E8SH86Hfi8EoxhKFgvNFWPxFcpS9MnGi7wLov/U03/IJ9oRxWmCREL+5gn4yOTJWd hDJMT0oLKp7Med2M7UDqF5XO+q1et4PNjmghkYYa0JnBsPgMD1pSO30dQIi0BeU68pT7 5d0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nEv2txPCVLSV4T8XOiHXL1dnMJXAnHX5LR4vdUFzACU=; b=Zir7N+aPb4KLlFg9i8pnre+htujA/DkZLeW+NhcAueX/E1elpMVCZ1gZn5vWGLpMJu fq54VBzK2sx9fs9rJ5Z4iQuJc2ulI5q9PqmQUCL4/IrhflBXNFJUHZg0xJqQa+ovZjuW H0Sd2pRhHuZfgNUR0NSqV7NX2L22ZoEkGIXwYl0EZ0zzi/IJ5wSE4z5bMGOymPmGKg7z 9Grh/3Rfke9nEVsSQIBlT77bZCX5+BmNuQA1q6uJeiyRAs6xU1DBAycT3gOxDO6laOUD R0HfDWBRg0YwLY/FaqESPQy9W0kJEsOjJ7EC3wsiW3Sj3BJz8YnKHYnH9ge2mcm9rLd/ mTcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oM6RXqw8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si4954298eju.229.2019.11.22.12.45.28; Fri, 22 Nov 2019 12:45:51 -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=@gmail.com header.s=20161025 header.b=oM6RXqw8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727259AbfKVUnN (ORCPT + 99 others); Fri, 22 Nov 2019 15:43:13 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43916 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbfKVUnN (ORCPT ); Fri, 22 Nov 2019 15:43:13 -0500 Received: by mail-qk1-f194.google.com with SMTP id p14so7453515qkm.10; Fri, 22 Nov 2019 12:43:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nEv2txPCVLSV4T8XOiHXL1dnMJXAnHX5LR4vdUFzACU=; b=oM6RXqw8iLUj+Ehpij017e9+fohwwSATEdVEux0stfyhSaBNuVE4s2ePhoaz9gQ+eq w5NqPEJNCP7qvXVDFjISFHQDQospQu4Bae0VYYelBzc45G5XLegFqss/jpkSiqRpbKG2 4EmXGtuDST1iGrfeU3YcNafHvAElHMXBucuCN0MjmcZZsLmbMaU2ZKKDKoOoeVpywgfw 0MeQLkcrnL8oaHJPmVE8quA35e0RX9znxT+PGYCp5yHhVYty961LC5uI5eTbWDIlE2Tp ghAM2dC9GJwvm3tZbMNVNN+WkBcvf6LP4++VoHMpT1kJfOsJi7PDSot0TGC8zA86X8L5 FBng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nEv2txPCVLSV4T8XOiHXL1dnMJXAnHX5LR4vdUFzACU=; b=QipIfKs2yjEIfOFmOpPujXzRQvuVgZ0Ee3AGuUHE/EEz8rFAb/PeOYnVUImkYNtZ1U QjrzRkZ0EptODQEkJ7XJkg5nKCc1J4VlwX44hpLJ7T9N41IEZS78iv2v7xyy9+2HkIq5 T0slJ9CD/O5LLpdyw1+FtpJBMtjarZGWBsfrMjZtDDB1YlJVq5J1WihixfUhBeHiEETf w/ilN7QZZQlzVGZn6r50gw2H3cQ1sxuCJaGBJNStHEJefqX49IMNmYLswRbaYhtzAUSY O6iiX5LKkUJ23UPVM6iH9ZiSJjVucs5pzK9YP08KlVfMIKn372NGMxhWxIAav4IX+4qX f9yA== X-Gm-Message-State: APjAAAUZOZdJ5k6CDxzM5UcwIbDJS/MMo7TlLbh4pChTFUKK6CZf31F8 xQJWEPyvDUGxetSEM1QyxGPJZI8Cd177Rw== X-Received: by 2002:a37:9146:: with SMTP id t67mr9276700qkd.98.1574455391169; Fri, 22 Nov 2019 12:43:11 -0800 (PST) Received: from localhost.localdomain ([177.220.176.157]) by smtp.gmail.com with ESMTPSA id d18sm3461078qko.112.2019.11.22.12.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2019 12:43:10 -0800 (PST) Received: by localhost.localdomain (Postfix, from userid 1000) id 61954C3AB5; Fri, 22 Nov 2019 17:43:07 -0300 (-03) Date: Fri, 22 Nov 2019 17:43:07 -0300 From: Marcelo Ricardo Leitner To: Aaron Conole 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 Message-ID: <20191122204307.GG388551@localhost.localdomain> References: <20191108210714.12426-1-aconole@redhat.com> <20191108210714.12426-2-aconole@redhat.com> <20191114162949.GB3419@localhost.localdomain> <20191118224054.GB388551@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 22, 2019 at 03:39:16PM -0500, Aaron Conole wrote: > Marcelo Ricardo Leitner writes: > > > On Mon, Nov 18, 2019 at 04:21:39PM -0500, Aaron Conole wrote: > >> Marcelo Ricardo Leitner writes: > >> > >> > 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 and > >> >> DNAT manipulation, due to e.g. tuple collision. Netfilter can support > >> >> this because it runs through the NAT table twice - once on ingress and > >> >> again after egress. The act_ct action doesn't have such capability. > >> >> > >> >> Like netfilter hook infrastructure, we should run through NAT twice to > >> >> keep the symmetry. > >> >> > >> >> Fixes: b57dc7c13ea9 ("net/sched: Introduce action ct") > >> >> > >> >> Signed-off-by: Aaron Conole > >> >> --- > >> >> net/sched/act_ct.c | 13 ++++++++++++- > >> >> 1 file changed, 12 insertions(+), 1 deletion(-) > >> >> > >> >> 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, > >> >> bool commit) > >> >> { > >> >> #if IS_ENABLED(CONFIG_NF_NAT) > >> >> + int err; > >> >> enum nf_nat_manip_type maniptype; > >> >> > >> >> if (!(ct_action & TCA_CT_ACT_NAT)) > >> >> @@ -359,7 +360,17 @@ static int tcf_ct_act_nat(struct sk_buff *skb, > >> >> return NF_ACCEPT; > >> >> } > >> >> > >> >> - return ct_nat_execute(skb, ct, ctinfo, range, maniptype); > >> >> + err = ct_nat_execute(skb, ct, ctinfo, range, maniptype); > >> >> + if (err == NF_ACCEPT && > >> >> + ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) { > >> >> + if (maniptype == NF_NAT_MANIP_SRC) > >> >> + maniptype = NF_NAT_MANIP_DST; > >> >> + else > >> >> + maniptype = NF_NAT_MANIP_SRC; > >> >> + > >> >> + err = ct_nat_execute(skb, ct, ctinfo, range, maniptype); > >> >> + } > >> > > >> > I keep thinking about this and I'm not entirely convinced that this > >> > shouldn't be simpler. More like: > >> > > >> > if (DNAT) > >> > DNAT > >> > if (SNAT) > >> > SNAT > >> > > >> > So it always does DNAT before SNAT, similarly to what iptables would > >> > do on PRE/POSTROUTING chains. > >> > >> 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). > >> > >> 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: > > > > - return ct_nat_execute(skb, ct, ctinfo, range, maniptype); > > + err = ct_nat_execute(skb, ct, ctinfo, range, maniptype); > > + if (err == NF_ACCEPT && maniptype == NF_NAT_MANIP_DST && > > + ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) { > > + maniptype = NF_NAT_MANIP_SRC; > > + err = ct_nat_execute(skb, ct, ctinfo, range, maniptype); > > + } > > + return 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. Interesting, ok. > > 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. Thanks for digging on it. Acked-by: Marcelo Ricardo Leitner > > >> >> + return err; > >> >> #else > >> >> return NF_ACCEPT; > >> >> #endif > >> >> -- > >> >> 2.21.0 > >> >> > >> >