From patchwork Tue Mar 26 20:57:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 1066089 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sysclose.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sysclose.org header.i=fbl@sysclose.org header.b="C58GsBia"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44TNky3Vblz9sV0 for ; Wed, 27 Mar 2019 07:58:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732871AbfCZU6R (ORCPT ); Tue, 26 Mar 2019 16:58:17 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21001 "EHLO sender-of-o51.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732716AbfCZU6Q (ORCPT ); Tue, 26 Mar 2019 16:58:16 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1553633880; cv=none; d=zoho.com; s=zohoarc; b=Bq+l9U2WHzPgWd4reTaP6NjV2hMPBqFSMx1pTjoTrOaDpoLBrWrdjZO9Ifnv5uDmxl+QS65LNYLHh6cfUuoy3a4/LCsQquZP6XBnmPGoC5+GyawxqzqhyE2Y7UiHaSE4BcprpLfNjsJR5IoyDMBwu7kZEtdDrxXcjdlf80AUgDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1553633880; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=G8QQucY9Kz1XJ+21AaQeXMshwUdjgwC5KoHAY8pdQqQ=; b=jWaZH/zWi1b8Cf9q3ZHYDjaF8Yl2nStc8b1hmrCP4XWKbay5lOOVnJWsDTtpsODN4BcggdKDtMMmhuJBuoJiwcp3S6Iel7dxnZDvtVcMFiRjSq777SYtsBvhsbwrFvBzAYNYQIYWfydSBiD+5oCgdze/nsQUjYdpEgX7xtbQCFY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=sysclose.org; spf=pass smtp.mailfrom=fbl@sysclose.org; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1553633880; s=zoho; d=sysclose.org; i=fbl@sysclose.org; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; l=2480; bh=G8QQucY9Kz1XJ+21AaQeXMshwUdjgwC5KoHAY8pdQqQ=; b=C58GsBia7jJJpbaZZBcyuQZqiS3PXP2Yj0DYRFFExDTfoAtIVk76wiSLqwX/mvux xdaCfpsxGkewiXOuiLmf6ZJjrJGNY6kr+/1tYob1UzHfkY5CMogR5mF3UyURbmJmWtg HlQbXdxfndO6QiGwo2JsZmO3uxXJ5sgFxhxOmRKs= Received: from localhost (177.183.215.126 [177.183.215.126]) by mx.zohomail.com with SMTPS id 1553633879367456.6709163022415; Tue, 26 Mar 2019 13:57:59 -0700 (PDT) From: Flavio Leitner To: netdev@vger.kernel.org Cc: Joe Stringer , Pravin B Shelar , dev@openvswitch.org, netfilter-devel@vger.kernel.org Message-ID: <20190326205715.22288-9-fbl@sysclose.org> Subject: [PATCH net-next 8/8] openvswitch: load and reference the NAT helper. Date: Tue, 26 Mar 2019 17:57:15 -0300 X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190326205715.22288-1-fbl@sysclose.org> References: <20190326205715.22288-1-fbl@sysclose.org> MIME-Version: 1.0 X-ZohoMailClient: External Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This improves the original commit 17c357efe5ec ("openvswitch: load NAT helper") where it unconditionally tries to load the module for every flow using NAT, so not efficient when loading multiple flows. It also doesn't hold any references to the NAT module while the flow is active. This change fixes those problems. It will try to load the module only if it's not present. It grabs a reference to the NAT module and holds it while the flow is active. Finally, an error message shows up if either actions above fails. Fixes: 17c357efe5ec ("openvswitch: load NAT helper") Signed-off-by: Flavio Leitner --- net/openvswitch/conntrack.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c index 845b83598e0d..fb58637a27c9 100644 --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -1305,6 +1305,7 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name, { struct nf_conntrack_helper *helper; struct nf_conn_help *help; + int ret = 0; helper = nf_conntrack_helper_try_module_get(name, info->family, key->ip.proto); @@ -1319,13 +1320,22 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name, return -ENOMEM; } +#ifdef CONFIG_NF_NAT_NEEDED + if (info->nat) { + ret = nf_conntrack_helper_nat_try_module_get(name, + info->family, + key->ip.proto); + if (ret) { + nf_conntrack_helper_put(helper); + OVS_NLERR(log, "Failed to load \"%s\" NAT helper, err: %d", + name, ret); + return ret; + } + } +#endif rcu_assign_pointer(help->helper, helper); info->helper = helper; - - if (info->nat) - request_module("ip_nat_%s", name); - - return 0; + return ret; } #ifdef CONFIG_NF_NAT_NEEDED @@ -1776,8 +1786,13 @@ void ovs_ct_free_action(const struct nlattr *a) static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info) { - if (ct_info->helper) + if (ct_info->helper) { +#ifdef CONFIG_NF_NAT_NEEDED + if (ct_info->nat) + nf_conntrack_helper_nat_put(ct_info->helper); +#endif nf_conntrack_helper_put(ct_info->helper); + } if (ct_info->ct) nf_ct_tmpl_free(ct_info->ct); }