From patchwork Fri Jun 16 17:47: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: 776924 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 3wq7DS5dSxz9s8N for ; Sat, 17 Jun 2017 03:49:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DXxXGGKK"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752685AbdFPRtm (ORCPT ); Fri, 16 Jun 2017 13:49:42 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35849 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752406AbdFPRsY (ORCPT ); Fri, 16 Jun 2017 13:48:24 -0400 Received: by mail-pf0-f193.google.com with SMTP id y7so7563921pfd.3 for ; Fri, 16 Jun 2017 10:48:23 -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=thQvlj1mnS+I9yldbkaI0zMOXY+bqIXlucFbwdYpTz4=; b=DXxXGGKKgKFyMJiR2xxLnx6P3I7MnBUqClmx+EAxKSfXDwX9AyMUwpU8YUiylSEXBo zZs5WrCxQf79uFazhUfQkzX676WI+qlfJltycE1seH4qILiIW5/SXE9xUyQVrPKy0m49 MLnoc0cbfTGfy7fu84YH2/XHXDtXIjSc1XTL755Q+Bl5V60CEJQF1SjGo1Pc0A5mQctz MRU/pXq/JPDkHM/2G3L4ueQso1arXCIjTti1ERdDR94CNnhmXJOB0C9gvperE4jnoits N3fjOpuUHGanMM7M7mZstgv+hpaxVHR9vTtyfd+lPWJraTCQ41EFW1G8/o60foQctuBP cRSQ== 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=thQvlj1mnS+I9yldbkaI0zMOXY+bqIXlucFbwdYpTz4=; b=Uug525V0pmB1G1tkjFGvlUVk/aKgpZC6ZaRUGOAQxgNYUqQhA+gSaKLsoMzI/o8lPj rXKobbpFHE74ZeWfmN9VPM1EbSScWqjsP3XjPRDYnKsPQV4lJFGiejGHTsBsUYWqsOkB 8u9GDzeHDsh72DN2mhfDW4EIJDEBeDL5AL9rA/u7DsRpifrmWAUo5O3kBiXABVfEJS7c /ONSdaijW0cZQeuZFHvt0woFbrKxQAmpjmgpKBpW1L+MOEknYco7OHOFqgUsTTyczGis Ao0irXXgn9fiOxoUXa6AOWZfY/VA8uM9BRSLJDazkWQgyelODPNnPavAf0L5kUMRu+RJ rVyg== X-Gm-Message-State: AKS2vOwHle7zm8C5lGabW5B9tLst1IUfPACQRDOnc75l40vDWC+u1G/F w7wFKNZmjVbt1Q== X-Received: by 10.99.172.67 with SMTP id z3mr6520694pgn.246.1497635303476; Fri, 16 Jun 2017 10:48:23 -0700 (PDT) Received: from weiwan0.mtv.corp.google.com ([100.123.230.66]) by smtp.gmail.com with ESMTPSA id v62sm5292290pfb.124.2017.06.16.10.48.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jun 2017 10:48:22 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Eric Dumazet , Martin KaFai Lau , Wei Wang Subject: [PATCH net-next 05/21] net: introduce a new function dst_dev_put() Date: Fri, 16 Jun 2017 10:47:28 -0700 Message-Id: <20170616174744.139688-6-tracywwnj@gmail.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog In-Reply-To: <20170616174744.139688-1-tracywwnj@gmail.com> References: <20170616174744.139688-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 | 23 +++++++++++++++++++++++ 2 files changed, 24 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..2031f778bf2a 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -296,6 +296,29 @@ 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); +} + void dst_release(struct dst_entry *dst) { if (dst) {