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=-4.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS 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 A4A01C4360F for ; Fri, 5 Apr 2019 14:48:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A09C21726 for ; Fri, 5 Apr 2019 14:48:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="QqbLOhou" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730587AbfDEOsl (ORCPT ); Fri, 5 Apr 2019 10:48:41 -0400 Received: from mail-eopbgr30041.outbound.protection.outlook.com ([40.107.3.41]:55424 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726291AbfDEOsk (ORCPT ); Fri, 5 Apr 2019 10:48:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7yqPj7yqoo0Os5CbePiMjJUtyTBEn0uNfNp+MwCgm+M=; b=QqbLOhouJiw4nzLFeFUK1LTDZVPc0qjmFdnO9saOEsubwoYcyLP4vSHEhTg6mTqkMxqsrb4laT+J6cDFav1ZXsJO9XqT6T66aXGsZLSJ8uZUsUUbUEyHy1cuLXt69pzgeDjlb4BQZTu/eWBsKCmun0JC8G3trLGljhn8nqv+hWY= Received: from VI1PR05MB6111.eurprd05.prod.outlook.com (20.178.204.213) by VI1PR05MB4253.eurprd05.prod.outlook.com (52.133.12.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.16; Fri, 5 Apr 2019 14:48:38 +0000 Received: from VI1PR05MB6111.eurprd05.prod.outlook.com ([fe80::28c7:8df1:920b:ee0e]) by VI1PR05MB6111.eurprd05.prod.outlook.com ([fe80::28c7:8df1:920b:ee0e%5]) with mapi id 15.20.1771.016; Fri, 5 Apr 2019 14:48:38 +0000 From: Ido Schimmel To: David Ahern CC: "davem@davemloft.net" , "netdev@vger.kernel.org" , Jiri Pirko , David Ahern Subject: Re: [PATCH net-next 11/18] ipv4: Add helpers for neigh lookup for nexthop Thread-Topic: [PATCH net-next 11/18] ipv4: Add helpers for neigh lookup for nexthop Thread-Index: AQHU6w7V+3YTWW3w5E2FBltgJ2Eg9qYtpysA Date: Fri, 5 Apr 2019 14:48:38 +0000 Message-ID: <20190405144834.GA20588@splinter> References: <20190404175007.8150-1-dsahern@kernel.org> <20190404175007.8150-12-dsahern@kernel.org> In-Reply-To: <20190404175007.8150-12-dsahern@kernel.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P191CA0060.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::37) To VI1PR05MB6111.eurprd05.prod.outlook.com (2603:10a6:803:eb::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=idosch@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [79.176.7.115] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d8fd1142-83cb-4147-de52-08d6b9d5c963 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:VI1PR05MB4253; x-ms-traffictypediagnostic: VI1PR05MB4253: x-microsoft-antispam-prvs: x-forefront-prvs: 0998671D02 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(7916004)(376002)(39860400002)(136003)(346002)(366004)(396003)(189003)(199004)(316002)(386003)(99286004)(53936002)(68736007)(25786009)(6486002)(229853002)(4326008)(6246003)(33716001)(6436002)(5660300002)(14454004)(102836004)(86362001)(66066001)(476003)(11346002)(256004)(1076003)(71190400001)(71200400001)(486006)(26005)(186003)(446003)(6506007)(76176011)(14444005)(305945005)(33656002)(7736002)(3846002)(6116002)(2906002)(105586002)(81156014)(6916009)(81166006)(106356001)(8676002)(6512007)(54906003)(8936002)(9686003)(97736004)(478600001)(52116002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB4253;H:VI1PR05MB6111.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: OhsGrsuM1B5IT49h4wOjAEvVUY9voYnRuzb/lpoNQR7CQ65bUB4hbsrMdxwRGjOlUGHkwMO5Ipkqd3bbyjpcINNohJRJ40re/JMOKthBCE2u0XZpr37JX4zXPvGw8xXLNFTHNTeCHXEVUyAv3/ONWP5iltXTvvw4c2bYAQZR0jQ24OelzPkl3PSG9Li9BHgHUjA4YRTRBHciSuQS+ZM/16a6TIPzpzG+wVK/9r+8y8y7RLv2EopFnokhHN4rAvp185IzWqnX4uNthGhVivjp3nQhhKAGaXOwxw/X2rJ9i47/t1CKmR47G4QKZy4aLSJ9i5yPJ28HR08jmCahyx94Sheum4H7yYhzE1RaIlYKyHg18RVoW1+s90Kr+r77WVVPtw2AD+hZ7AtojqOxjzVcdX4Cdd0/B0nLQxekA0WnHAE= Content-Type: text/plain; charset="us-ascii" Content-ID: <200E28A8E94D1440B4EFD14E88E700A9@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8fd1142-83cb-4147-de52-08d6b9d5c963 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Apr 2019 14:48:38.0644 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB4253 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Apr 04, 2019 at 10:50:00AM -0700, David Ahern wrote: > From: David Ahern >=20 > A common them in the output path is looking up a neigh entry for a s/them/theme/ > nexthop, either the gateway in an rtable or a fallback to the daddr > in the skb: >=20 > nexthop =3D (__force u32)rt_nexthop(rt, ip_hdr(skb)->daddr); > neigh =3D __ipv4_neigh_lookup_noref(dev, nexthop); > if (unlikely(!neigh)) > neigh =3D __neigh_create(&arp_tbl, &nexthop, dev, false); >=20 > To allow the nexthop to be an IPv6 address we need to consider the > family of the nexthop and then call __ipv*_neigh_lookup_noref based > on it. >=20 > To make this simpler, add a ip_neigh_gw4 helper similar to ip_neigh_gw6 > which handles: >=20 > neigh =3D __ipv4_neigh_lookup_noref(dev, nexthop); > if (unlikely(!neigh)) > neigh =3D __neigh_create(&arp_tbl, &nexthop, dev, false); >=20 > And then add a second one, ip_neigh_for_gw, that calls either > ip_neigh_gw4 or ip_neigh_gw6 based on the address family of the gateway. >=20 > Update the output paths in the VRF driver and core v4 code to use > ip_neigh_for_gw simplifying the family based lookup and making both > ready for a v6 nexthop. >=20 > ipv4_neigh_lookup has a different need - the potential to resolve a > passed in address in addition to any gateway in the rtable or skb. Since > this is a one-off, add ip_neigh_gw4 and ip_neigh_gw6 diectly. The > difference between __neigh_create used by the helpers and neigh_create > called by ipv4_neigh_lookup is taking a refcount, so add rcu_read_lock_bh > and bump the refcnt on the neigh entry. >=20 > Signed-off-by: David Ahern Looks good to me. A couple of nits below. > @@ -572,13 +572,11 @@ static int vrf_finish_output(struct net *net, struc= t sock *sk, struct sk_buff *s > =20 > rcu_read_lock_bh(); > =20 > - nexthop =3D (__force u32)rt_nexthop(rt, ip_hdr(skb)->daddr); > - neigh =3D __ipv4_neigh_lookup_noref(dev, nexthop); > - if (unlikely(!neigh)) > - neigh =3D __neigh_create(&arp_tbl, &nexthop, dev, false); > + neigh =3D ip_neigh_for_gw(rt, skb, &is_v6gw); > if (!IS_ERR(neigh)) { > sock_confirm_neigh(skb, neigh); > - ret =3D neigh_output(neigh, skb, false); > + /* if crossing protocols, can not used the cached header */ s/used/use/ > + ret =3D neigh_output(neigh, skb, is_v6gw); > rcu_read_unlock_bh(); > return ret; > } ... > @@ -218,16 +218,13 @@ static int ip_finish_output2(struct net *net, struc= t sock *sk, struct sk_buff *s > } > =20 > rcu_read_lock_bh(); > - nexthop =3D (__force u32) rt_nexthop(rt, ip_hdr(skb)->daddr); > - neigh =3D __ipv4_neigh_lookup_noref(dev, nexthop); > - if (unlikely(!neigh)) > - neigh =3D __neigh_create(&arp_tbl, &nexthop, dev, false); > + neigh =3D ip_neigh_for_gw(rt, skb, &is_v6gw); > if (!IS_ERR(neigh)) { > int res; > =20 > sock_confirm_neigh(skb, neigh); > - res =3D neigh_output(neigh, skb, false); > - > + /* if crossing protocols, can not used the cached header */ s/used/use/ > + res =3D neigh_output(neigh, skb, is_v6gw); > rcu_read_unlock_bh(); > return res; > }