From patchwork Thu Dec 21 19:33:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 852088 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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; dkim=pass (2048-bit key; unprotected) header.d=quantonium-net.20150623.gappssmtp.com header.i=@quantonium-net.20150623.gappssmtp.com header.b="vPQEMcc4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z2hfK05k1z9s84 for ; Fri, 22 Dec 2017 06:34:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755461AbdLUTeO (ORCPT ); Thu, 21 Dec 2017 14:34:14 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36889 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755430AbdLUTeJ (ORCPT ); Thu, 21 Dec 2017 14:34:09 -0500 Received: by mail-pf0-f194.google.com with SMTP id n6so14354662pfa.4 for ; Thu, 21 Dec 2017 11:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantonium-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X7Ovj+WOvHsAQCxHLmWX6FS4WucxSB1gEoHcs4Rqpqk=; b=vPQEMcc48447k29+ci/b/hjzvjCrbdeSw5fl36WjTjP0mCFnUvmKftktyksPVWmBYF 7K8grSBIDnQB4piY+96f6rRkzFReiMPK1BYMWYcr5O+k5mmSFkD+XlWzf6FF7Qg96Uu7 xgQUTJ9YuQuSlZAulvUuqxY134PjFq4bHDCc0jiySpFJk9jU9HxvpvjsrtFfzkYvpqO/ /wzDs4rAy+9qGcqUsh2KbpG44rKbAFSTly+7QvcvpqLxzmcb9GGqg2VvfD0odxDOY2eF UXiJJZQ6GNCqUBf5TDaOoIGo8/4rF3Mpmdo4ZjQaFp+MEenAwW6bvLZ9G0fXcYgdtJab TWbA== 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=X7Ovj+WOvHsAQCxHLmWX6FS4WucxSB1gEoHcs4Rqpqk=; b=Qn8DxX6qPe2kTnb1jcJT1xBG0gnIvdENA09VDvx37sKRFooT2bW5Z51NuFiQtdvBUt qbmCcHXEoJZTsatMH21pti0dC0+ovjv6FB2VIiWP2Tx9CZ3FbcxBiEnDugJcC3l+1oqm bSK+N/Ptpg8I41OfpMyOzQbQkndHOioxFFNNuaFN7BfwcImukESzKeeiuL7QMWxAA3/z cpOLga+yn2ujGApoqDzVxg+05jccXlJ/YoCbw+sDoyhx18W/SMUvBgxSVXCJ0bwopJsV LrM1ysyZzq26jlUH6ZUHAqjw53le9X3MqGinQJrF7qgktX3UEV+3p7w9GMbig3Nde4dL KOeQ== X-Gm-Message-State: AKGB3mIZm0AnxSI8HcOngixH3k5FmCDhmfHUqTKtLJW6ecqssadKBilx elYTB2dxT1wmMfGk/2KLILuk5A== X-Google-Smtp-Source: ACJfBosdE4KNs6ErRUNn5NUkpb5ZE11A0SFOlsdLcAo9VjpiwyQ5i7DIU82ANiQm735z6v/5QWkY4g== X-Received: by 10.101.89.5 with SMTP id f5mr10565272pgu.370.1513884849178; Thu, 21 Dec 2017 11:34:09 -0800 (PST) Received: from localhost.localdomain (c-73-162-13-107.hsd1.ca.comcast.net. [73.162.13.107]) by smtp.gmail.com with ESMTPSA id p126sm35384464pga.58.2017.12.21.11.34.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2017 11:34:08 -0800 (PST) From: Tom Herbert To: davem@davemloft.net Cc: netdev@vger.kernel.org, roopa@cumulusnetworks.com, rohit@quantonium.net, Tom Herbert Subject: [PATCH v5 net-next 6/7] ila: Flush netlink command to clear xlat table Date: Thu, 21 Dec 2017 11:33:31 -0800 Message-Id: <20171221193332.15303-7-tom@quantonium.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171221193332.15303-1-tom@quantonium.net> References: <20171221193332.15303-1-tom@quantonium.net> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add ILA_CMD_FLUSH netlink command to clear the ILA translation table. Signed-off-by: Tom Herbert --- include/uapi/linux/ila.h | 1 + net/ipv6/ila/ila.h | 1 + net/ipv6/ila/ila_main.c | 6 +++++ net/ipv6/ila/ila_xlat.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/ila.h b/include/uapi/linux/ila.h index 483b77af4eb8..db45d3e49a12 100644 --- a/include/uapi/linux/ila.h +++ b/include/uapi/linux/ila.h @@ -30,6 +30,7 @@ enum { ILA_CMD_ADD, ILA_CMD_DEL, ILA_CMD_GET, + ILA_CMD_FLUSH, __ILA_CMD_MAX, }; diff --git a/net/ipv6/ila/ila.h b/net/ipv6/ila/ila.h index faba7824ea56..1f747bcbec29 100644 --- a/net/ipv6/ila/ila.h +++ b/net/ipv6/ila/ila.h @@ -123,6 +123,7 @@ void ila_xlat_exit_net(struct net *net); int ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info); int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info); int ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info); +int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info); int ila_xlat_nl_dump_start(struct netlink_callback *cb); int ila_xlat_nl_dump_done(struct netlink_callback *cb); int ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb); diff --git a/net/ipv6/ila/ila_main.c b/net/ipv6/ila/ila_main.c index f6ac6b14577e..18fac76b9520 100644 --- a/net/ipv6/ila/ila_main.c +++ b/net/ipv6/ila/ila_main.c @@ -27,6 +27,12 @@ static const struct genl_ops ila_nl_ops[] = { .flags = GENL_ADMIN_PERM, }, { + .cmd = ILA_CMD_FLUSH, + .doit = ila_xlat_nl_cmd_flush, + .policy = ila_nl_policy, + .flags = GENL_ADMIN_PERM, + }, + { .cmd = ILA_CMD_GET, .doit = ila_xlat_nl_cmd_get_mapping, .start = ila_xlat_nl_dump_start, diff --git a/net/ipv6/ila/ila_xlat.c b/net/ipv6/ila/ila_xlat.c index d05de891dfb6..51a15ce50a64 100644 --- a/net/ipv6/ila/ila_xlat.c +++ b/net/ipv6/ila/ila_xlat.c @@ -164,9 +164,9 @@ static inline void ila_release(struct ila_map *ila) kfree_rcu(ila, rcu); } -static void ila_free_cb(void *ptr, void *arg) +static void ila_free_node(struct ila_map *ila) { - struct ila_map *ila = (struct ila_map *)ptr, *next; + struct ila_map *next; /* Assume rcu_readlock held */ while (ila) { @@ -176,6 +176,11 @@ static void ila_free_cb(void *ptr, void *arg) } } +static void ila_free_cb(void *ptr, void *arg) +{ + ila_free_node((struct ila_map *)ptr); +} + static int ila_xlat_addr(struct sk_buff *skb, bool sir2ila); static unsigned int @@ -365,6 +370,59 @@ int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info) return 0; } +static inline spinlock_t *lock_from_ila_map(struct ila_net *ilan, + struct ila_map *ila) +{ + return ila_get_lock(ilan, ila->xp.ip.locator_match); +} + +int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info) +{ + struct net *net = genl_info_net(info); + struct ila_net *ilan = net_generic(net, ila_net_id); + struct rhashtable_iter iter; + struct ila_map *ila; + spinlock_t *lock; + int ret; + + ret = rhashtable_walk_init(&ilan->xlat.rhash_table, &iter, GFP_KERNEL); + if (ret) + goto done; + + rhashtable_walk_start(&iter); + + for (;;) { + ila = rhashtable_walk_next(&iter); + + if (IS_ERR(ila)) { + if (PTR_ERR(ila) == -EAGAIN) + continue; + ret = PTR_ERR(ila); + goto done; + } else if (!ila) { + break; + } + + lock = lock_from_ila_map(ilan, ila); + + spin_lock(lock); + + ret = rhashtable_remove_fast(&ilan->xlat.rhash_table, + &ila->node, rht_params); + if (!ret) + ila_free_node(ila); + + spin_unlock(lock); + + if (ret) + break; + } + +done: + rhashtable_walk_stop(&iter); + return ret; +} + static int ila_fill_info(struct ila_map *ila, struct sk_buff *msg) { if (nla_put_u64_64bit(msg, ILA_ATTR_LOCATOR,