From patchwork Thu Mar 22 22:57:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 889718 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="Jt/YJqxc"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406hsp0Gk3z9s0q for ; Fri, 23 Mar 2018 09:58:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbeCVW6T (ORCPT ); Thu, 22 Mar 2018 18:58:19 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:42713 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751841AbeCVW6Q (ORCPT ); Thu, 22 Mar 2018 18:58:16 -0400 Received: by mail-pf0-f196.google.com with SMTP id a16so3970298pfn.9 for ; Thu, 22 Mar 2018 15:58:16 -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=0zznXGfFotp/Rp7YwyF9NZp5zk/m3mItoF6rO9OZ/SA=; b=Jt/YJqxcbxlx93F8LHohzwhDEvSK0YqfW62Nn+MYyVUbjdETN1WZBiJQIbK1qpU1N0 H/uXgNMJ1dhhPYzcPSFC0gEXWxC8i/gegPNDHNx5t5+QCI9EzjHOZhXXYkEHgGZ81ZTr OQWgsRyp/duYIyFgNHDeiltTTEfb3Tzv5lwrA= 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=0zznXGfFotp/Rp7YwyF9NZp5zk/m3mItoF6rO9OZ/SA=; b=NfJqjFXGVJ7ap+adKYJmuj+i7m2KvXZfWwLa3NZiAxEiAt/7yCNLnGoBZcxe8EpP58 j/fl09BJZqMMI5DawQUqCZC3g4UEIiuHeDI7lJYXJtKIJBctcs/aAD+RUram7CyTmFM8 jkD/PNhxWTE4hIzQXQlXNAsI8HCysUoNZqTETNRXM98PT0olNYagpvKT0ghVHhRkKQBE LN2SPni+IyNvtMglFSIM3UG+yxYpq1CbfNJKGfxBEvMfN+I8DDxs3Z8GTlTiWz8p45Sk i4H5I7TSVE7PSRTJMTmCZQYWVZNVp4yVYSQgdMF+3Q6cXkA5Ip1DRUMbIA8lOq0kZX0z IZ0g== X-Gm-Message-State: AElRT7GrNMo5xsGRl6JhZ6H0qHS/s2IwA9tBTVVjzpbPPMFNNllET8tF vsMC47bkach5aIcNtq13y9SZ/6zG X-Google-Smtp-Source: AG47ELs8t0p6wEEhPBfFT1v8JtB7Ys2MK5ZuyipnreTpJVxykIicDgA/IOmxOi/L2J7sAYvpQn1G6w== X-Received: by 10.98.204.12 with SMTP id a12mr21307752pfg.3.1521759495206; Thu, 22 Mar 2018 15:58:15 -0700 (PDT) Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com. [216.129.126.126]) by smtp.googlemail.com with ESMTPSA id b78sm15807767pfe.88.2018.03.22.15.58.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 15:58:14 -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, David Ahern Subject: [PATCH RFC net-next 3/7] net/ipv4: Move call_fib_entry_notifiers up for new routes Date: Thu, 22 Mar 2018 15:57:53 -0700 Message-Id: <20180322225757.10377-4-dsa@cumulusnetworks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180322225757.10377-1-dsa@cumulusnetworks.com> References: <20180322225757.10377-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 --- 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 62243a8abf92..d0f70a16f8de 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: