From patchwork Sat Jun 17 17:42:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 777344 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wql3F4Jp7z9s8V for ; Sun, 18 Jun 2017 03:43:53 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XbI8HQhv"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752647AbdFQRni (ORCPT ); Sat, 17 Jun 2017 13:43:38 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34941 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752502AbdFQRnh (ORCPT ); Sat, 17 Jun 2017 13:43:37 -0400 Received: by mail-pf0-f195.google.com with SMTP id s66so11093269pfs.2 for ; Sat, 17 Jun 2017 10:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PeyNGaUXs0saTJdocbuhNaFYaY0umr6/S4l40PermLQ=; b=XbI8HQhvcFkRjoxaKAaJlSg66giqooEjODgta+Kauc/IPmNWCrkvIKgJc9NDoNsthc Zv4faiO8TmmEnTd1B8wDpbq86ypikOoe4CCbIm1tMeY/+9XM0NzkBa1fu6uuI9xrcq6h mhhOF4LWXqJUCsgxAszVPG3JYClJGiFHAeC53nyuaPEyObPhNMrykCJnwdMgDFkf1e0o slmKvNFpBdDCNzQypMkrNEog0g/NiQqRudXoCpkllR7mFXxF8Qa+t46fzCptJkkLzEHD 9Mk13pM3KBAHfStBjOWFCEOyiB3MUicMv06pVkzazHGrbVCctYBFFdvZsGauSiYUTZWh 0T8g== 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=PeyNGaUXs0saTJdocbuhNaFYaY0umr6/S4l40PermLQ=; b=mU8YaMnDH3Ab/epUMNL+ozy1kiyXgzk3wdSX0HI1CzLj+o0P/yg+AXvk20Jh6p+cuN /jPZ50oV+GK0cYmcFUBPJ6NWB9Vp/PuZmCvxrB4WgKfZ4Cly0/K2JeB9OrOy29scy+4P Shlil3czGwPvbIjY4EqnUP1Yrk8nFfqDLvDIAsoxjuSh0zfH+t0L549h6SLs/Mn0rwjo N31w/qdHka6JF3mtefH+UQFqdFDtG6JT9yERDoKBNoJWhiQMnhJWOAfi+Sqzax3jBlV3 bTxO2gF1earkW4EXb2uk31U9M4OO2IhOkGTOykka+M/V6mP27rIN35GKmmY86p9hvNsP jEAg== X-Gm-Message-State: AKS2vOwkKsfqKzGARwSw4k3T3dFsrNQGgs7EBJgHTNbYJF+apMJqEGLK mrMN1VbIVTKFJvjxdRo= X-Received: by 10.84.200.200 with SMTP id u8mr19411437plh.63.1497721416426; Sat, 17 Jun 2017 10:43:36 -0700 (PDT) Received: from weiwan0.mtv.corp.google.com ([100.123.230.66]) by smtp.gmail.com with ESMTPSA id h7sm11352777pfc.97.2017.06.17.10.43.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Jun 2017 10:43:35 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Eric Dumazet , Martin KaFai Lau , Wei Wang Subject: [PATCH v2 net-next 05/21] net: introduce a new function dst_dev_put() Date: Sat, 17 Jun 2017 10:42:28 -0700 Message-Id: <20170617174244.132862-6-tracywwnj@gmail.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog In-Reply-To: <20170617174244.132862-1-tracywwnj@gmail.com> References: <20170617174244.132862-1-tracywwnj@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang This function should be called when removing routes from fib tree after the dst gc is no longer in use. We first mark DST_OBSOLETE_DEAD on this dst to make sure next dst_ops->check() fails and returns NULL. Secondly, as we no longer keep the gc_list, we need to properly release dst->dev right at the moment when the dst is removed from the fib/fib6 tree. It does the following: 1. change dst->input and output pointers to dst_discard/dst_dscard_out to discard all packets 2. replace dst->dev with loopback interface Signed-off-by: Wei Wang Acked-by: Martin KaFai Lau --- include/net/dst.h | 1 + net/core/dst.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/net/dst.h b/include/net/dst.h index 2735d5a1e774..11d779803c0d 100644 --- a/include/net/dst.h +++ b/include/net/dst.h @@ -428,6 +428,7 @@ void dst_init(struct dst_entry *dst, struct dst_ops *ops, unsigned short flags); void __dst_free(struct dst_entry *dst); struct dst_entry *dst_destroy(struct dst_entry *dst); +void dst_dev_put(struct dst_entry *dst); static inline void dst_free(struct dst_entry *dst) { diff --git a/net/core/dst.c b/net/core/dst.c index 551834c3363f..56998f69b84e 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -296,6 +296,30 @@ static void dst_destroy_rcu(struct rcu_head *head) __dst_free(dst); } +/* Operations to mark dst as DEAD and clean up the net device referenced + * by dst: + * 1. put the dst under loopback interface and discard all tx/rx packets + * on this route. + * 2. release the net_device + * This function should be called when removing routes from the fib tree + * in preparation for a NETDEV_DOWN/NETDEV_UNREGISTER event and also to + * make the next dst_ops->check() fail. + */ +void dst_dev_put(struct dst_entry *dst) +{ + struct net_device *dev = dst->dev; + + dst->obsolete = DST_OBSOLETE_DEAD; + if (dst->ops->ifdown) + dst->ops->ifdown(dst, dev, true); + dst->input = dst_discard; + dst->output = dst_discard_out; + dst->dev = dev_net(dst->dev)->loopback_dev; + dev_hold(dst->dev); + dev_put(dev); +} +EXPORT_SYMBOL(dst_dev_put); + void dst_release(struct dst_entry *dst) { if (dst) {