From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57255C282CE for ; Fri, 5 Apr 2019 23:31:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2687721726 for ; Fri, 5 Apr 2019 23:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554507076; bh=dqW+dnTfik/yVjPJdWQyLaxP/ku0BMJrr8LQSJ+4npE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wW/AuHim8DBNsw4W4dJy+uAgxOE0JSuxx/7TCygbMuDNNgZf7Fe+ztzt3BAqqFF7P Y+sVP8hNH7xgmD8BAcwrbtw/mo9SXMYAM4XurN6FfPGYejf03r9YJx/y+VxUBvSkkS x1gkodPm9WkCZXWFRYMuxeNtAwFBj7OAL2Mw6FVk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbfDEXbP (ORCPT ); Fri, 5 Apr 2019 19:31:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:56594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726204AbfDEXab (ORCPT ); Fri, 5 Apr 2019 19:30:31 -0400 Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com [216.129.126.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5558821871; Fri, 5 Apr 2019 23:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554507030; bh=dqW+dnTfik/yVjPJdWQyLaxP/ku0BMJrr8LQSJ+4npE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t0UKZhU7dKHSZgyde4+LjYTSqN2ByY4K+djhGm+yYLCIT98LHvYvRmBQ3PmtbMOek sW6PcxTatD3G9nzdZSqzQzonMJ1qEAcS19ewHY1DVZMA41Y8GY6Gdc3IcmdAwF+gVc p+M5VuKjd8aVDM0leupZdaGdjNo2EIGrqasedn0o= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, jiri@mellanox.com, David Ahern Subject: [PATCH v2 net-next 02/18] ipv6: Add neighbor helpers that use the ipv6 stub Date: Fri, 5 Apr 2019 16:30:25 -0700 Message-Id: <20190405233041.30775-3-dsahern@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190405233041.30775-1-dsahern@kernel.org> References: <20190405233041.30775-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern Add ipv6 helpers to handle ndisc references via the stub. Update bpf_ipv6_fib_lookup to use __ipv6_neigh_lookup_noref_stub instead of the open code ___neigh_lookup_noref with the stub. Signed-off-by: David Ahern Reviewed-by: Ido Schimmel --- include/net/ndisc.h | 40 ++++++++++++++++++++++++++++++++++++++++ net/core/filter.c | 6 ++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/net/ndisc.h b/include/net/ndisc.h index ddfbb591e2c5..366150053043 100644 --- a/include/net/ndisc.h +++ b/include/net/ndisc.h @@ -2,6 +2,8 @@ #ifndef _NDISC_H #define _NDISC_H +#include + /* * ICMP codes for neighbour discovery messages */ @@ -379,6 +381,14 @@ static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev return ___neigh_lookup_noref(&nd_tbl, neigh_key_eq128, ndisc_hashfn, pkey, dev); } +static inline +struct neighbour *__ipv6_neigh_lookup_noref_stub(struct net_device *dev, + const void *pkey) +{ + return ___neigh_lookup_noref(ipv6_stub->nd_tbl, neigh_key_eq128, + ndisc_hashfn, pkey, dev); +} + static inline struct neighbour *__ipv6_neigh_lookup(struct net_device *dev, const void *pkey) { struct neighbour *n; @@ -409,6 +419,36 @@ static inline void __ipv6_confirm_neigh(struct net_device *dev, rcu_read_unlock_bh(); } +static inline void __ipv6_confirm_neigh_stub(struct net_device *dev, + const void *pkey) +{ + struct neighbour *n; + + rcu_read_lock_bh(); + n = __ipv6_neigh_lookup_noref_stub(dev, pkey); + if (n) { + unsigned long now = jiffies; + + /* avoid dirtying neighbour */ + if (n->confirmed != now) + n->confirmed = now; + } + rcu_read_unlock_bh(); +} + +/* uses ipv6_stub and is meant for use outside of IPv6 core */ +static inline struct neighbour *ip_neigh_gw6(struct net_device *dev, + const void *addr) +{ + struct neighbour *neigh; + + neigh = __ipv6_neigh_lookup_noref_stub(dev, addr); + if (unlikely(!neigh)) + neigh = __neigh_create(ipv6_stub->nd_tbl, addr, dev, false); + + return neigh; +} + int ndisc_init(void); int ndisc_late_init(void); diff --git a/net/core/filter.c b/net/core/filter.c index 8904e3407163..26d9cd785ae2 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4759,11 +4759,9 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params, params->rt_metric = f6i->fib6_metric; /* xdp and cls_bpf programs are run in RCU-bh so rcu_read_lock_bh is - * not needed here. Can not use __ipv6_neigh_lookup_noref here - * because we need to get nd_tbl via the stub + * not needed here. */ - neigh = ___neigh_lookup_noref(ipv6_stub->nd_tbl, neigh_key_eq128, - ndisc_hashfn, dst, dev); + neigh = __ipv6_neigh_lookup_noref_stub(dev, dst); if (!neigh) return BPF_FIB_LKUP_RET_NO_NEIGH; -- 2.11.0