From patchwork Wed Mar 28 01:21:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 891924 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=pass (p=none dis=none) header.from=cumulusnetworks.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b="Gf89uwV0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 409qqX6mxPz9s0x for ; Wed, 28 Mar 2018 12:22:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752859AbeC1BWO (ORCPT ); Tue, 27 Mar 2018 21:22:14 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:46565 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752594AbeC1BWL (ORCPT ); Tue, 27 Mar 2018 21:22:11 -0400 Received: by mail-pg0-f68.google.com with SMTP id t12so325222pgp.13 for ; Tue, 27 Mar 2018 18:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=54YsztpC1mg4mWscMQPNjBiDP9+/yA6Q72nco//CzfA=; b=Gf89uwV0jywLlH28oAwtYW2Pp3qToh1MlZfrbVSLzFKyIPh7TfD1QURZIiMgBF0rzm 25gWcoJkapXYLWQyZ4LR4pyI8RAIt7yPuBD/fBvELjTYArLg+jrkBZPSwm8Z6kNhZpAQ qPXLSkwhaEkuR/tiLX2Mz2UVODGpKuhUseuXQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=54YsztpC1mg4mWscMQPNjBiDP9+/yA6Q72nco//CzfA=; b=ToYCmUYAStLgkhyd15lzb/M2SeVUZhqhEp5nSrr4uyTTiaTOIs62a8OZ3Ic0YKqCon S8vUXNhXpvhwBgFIN+ICBJ1EZYaOSqbvfh5Owywrlvi3fzbQ66Zr1bbtOgLcFXOrtKSr auocBloW97+ZPwbQJd1oMmBw3t+n5Ssgt2dsqbjnGx7y63o3EXN8ITp1W+dnKUg5/qqp 4bcNXvHYloRfEze0ll7BIbjSYJ4LQRszCi9fmZA6yDqhyIKqdHdv2MuyHE6EmIWpszJW F8/XIfSTccic78tBKeLvX7GoYED82FSkB2cEBx3GlM0f7p7lCnPCm2Y4K+kdvoUFPufY WLFw== X-Gm-Message-State: AElRT7FQ98QfE//Lg5aKo0EhHRYhoDt4mqR8vh9xnTm3ys9y3KjC/Qrp wS0dh9BKXn88Qaz0vbnErRZxsyvz X-Google-Smtp-Source: AIpwx49cWTJXo13zWxe3vAI+Wssy9VXTQLqc7ET9cJ/k1IaDKJ2kRRglkvYHfect5IJgVyuJMSQrtA== X-Received: by 10.98.153.86 with SMTP id d83mr1265282pfe.46.1522200130704; Tue, 27 Mar 2018 18:22:10 -0700 (PDT) Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com. [216.129.126.126]) by smtp.googlemail.com with ESMTPSA id y18sm4798595pfe.67.2018.03.27.18.22.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 18:22:09 -0700 (PDT) From: David Ahern To: netdev@vger.kernel.org Cc: davem@davemloft.net, roopa@cumulusnetworks.com, shm@cumulusnetworks.com, jiri@mellanox.com, idosch@mellanox.com, jakub.kicinski@netronome.com, andy.roulin@gmail.com, David Ahern Subject: [PATCH net-next 3/6] net/ipv4: Move call_fib_entry_notifiers up for new routes Date: Tue, 27 Mar 2018 18:21:57 -0700 Message-Id: <20180328012200.15175-4-dsa@cumulusnetworks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180328012200.15175-1-dsa@cumulusnetworks.com> References: <20180328012200.15175-1-dsa@cumulusnetworks.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move call to call_fib_entry_notifiers for new IPv4 routes to right before the call to fib_insert_alias. At this point the only remaining failure path is memory allocations in fib_insert_node. Handle that very unlikely failure with a call to call_fib_entry_notifiers to tell drivers about it. At this point notifier handlers can decide the fate of the new route with a clean path to delete the potential new entry if the notifier returns non-0. Signed-off-by: David Ahern Reviewed-by: Ido Schimmel --- net/ipv4/fib_trie.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index fac0b73e24d1..67116233e2bc 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -1065,6 +1065,9 @@ static int fib_insert_node(struct trie *t, struct key_vector *tp, return -ENOMEM; } +/* fib notifier for ADD is sent before calling fib_insert_alias with + * the expectation that the only possible failure ENOMEM + */ static int fib_insert_alias(struct trie *t, struct key_vector *tp, struct key_vector *l, struct fib_alias *new, struct fib_alias *fa, t_key key) @@ -1263,21 +1266,32 @@ int fib_table_insert(struct net *net, struct fib_table *tb, new_fa->tb_id = tb->tb_id; new_fa->fa_default = -1; + err = call_fib_entry_notifiers(net, event, key, plen, new_fa, extack); + if (err) + goto out_free_new_fa; + /* Insert new entry to the list. */ err = fib_insert_alias(t, tp, l, new_fa, fa, key); if (err) - goto out_free_new_fa; + goto out_fib_notif; if (!plen) tb->tb_num_default++; rt_cache_flush(cfg->fc_nlinfo.nl_net); - call_fib_entry_notifiers(net, event, key, plen, new_fa, extack); rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, new_fa->tb_id, &cfg->fc_nlinfo, nlflags); succeeded: return 0; +out_fib_notif: + /* notifier was sent that entry would be added to trie, but + * the add failed and need to recover. Only failure for + * fib_insert_alias is ENOMEM. + */ + NL_SET_ERR_MSG(extack, "Failed to insert route into trie"); + call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, key, + plen, new_fa, NULL); out_free_new_fa: kmem_cache_free(fn_alias_kmem, new_fa); out: