From patchwork Sat Feb 19 15:45:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12752329 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04AD2C433F5 for ; Sat, 19 Feb 2022 15:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242544AbiBSPqZ (ORCPT ); Sat, 19 Feb 2022 10:46:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234373AbiBSPqY (ORCPT ); Sat, 19 Feb 2022 10:46:24 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2068.outbound.protection.outlook.com [40.107.94.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4771A606DF for ; Sat, 19 Feb 2022 07:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P50pkOmPT/cEVlcDP/pRpV3QZUiZTR7e7pgYyZJY8t6vSnTHLl4lOSwGg7R8wtt6DBAeMUa6p/DuepuPaQDtuWFZekgPcWjK8sjDmchHEpQAt0Oz/hisJJ3Ltt7IbeQkcBvuSpCjYWvRcv6vCwwTpSpAdEiXHPnliXJv0Lejdmx9JE5LmtKkWQ44aVUq5m1ZwsipZjPpwpTV9yS6ODuYiaXrN/ZJi1tmy7zpx+SjgkrQjViDFh2L5LVrl1cb+RX94WN8lWHjk1FC5n35MyWMcKHvaHnB/FP64CEgmyHXIw6zPzVJ9BNZUkecLCSfNNDyqgRJ/Lccdr4dTOH/OF3OCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KO02xwJ2rvu6iTO6VaJ+K12kOcn9oK8JOLR+FElIJ30=; b=Ukjn+ayPR73XlcAlOQwH0VOVzoL3p8njPQ+Agow9TS87uaguDcUOZJjZJEGeczmTeDMMQhHpnc13/85W04noT0UJjPc5b/8A0w+ubQqU5MJ2c0iuheDtZm3X5tSsCyM9PewXKwXOeobjFN6mnId0iv65cB9FscGdgzB14YXtun1VqM2r7q6qL3Rqz6YSOBK5C/lIezL558xhHWBTJONpLiCziYxfy2Ub2dIX5yUMqCzqAhGGqPHdTr9ie32IhkRwSeCS6099cga27nTwlBa1SfWmvCihGlvvaI280lhlrTkh1RS0KS066UgtyyYCJijHejwnawou8iHhZ80lBavObg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KO02xwJ2rvu6iTO6VaJ+K12kOcn9oK8JOLR+FElIJ30=; b=WMTWCuFYFfoghOU/nPwri1tUmRhvsyTwwXxjtDC0P9v6OApc/Ch+yRaxvJCyXBzQteiH3+srRX6x4D3ECAlDMJ5gNOfD4AAvHahAsEZouJRVyA8F8MEnXo43wy9MffCEqJPz8oQY2jZ7EO6wAUbZj5W3hW2z0IU/HbMMPQ8rGlg6lChap26U/nP0ZNlaRTUATgjBt8kSnnA+bUEudHhakcuvO9RVozP8wMkCuTpBrexS43oKWsjzAag1oqEpeAxewU1LpnWeXOSXyL/V7SiI3NMQRFIgQS7xdSDU1ueWnxuP6LRaW+9E3bLQoh5VXLoOsG0B45mX/3uYdeU2d3qQ1A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by DM6PR12MB4340.namprd12.prod.outlook.com (2603:10b6:5:2a8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Sat, 19 Feb 2022 15:46:04 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%5]) with mapi id 15.20.4995.024; Sat, 19 Feb 2022 15:46:04 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, dsahern@gmail.com, wanghai38@huawei.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 1/2] ipv4: Invalidate neighbour for broadcast address upon address addition Date: Sat, 19 Feb 2022 17:45:19 +0200 Message-Id: <20220219154520.344057-2-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220219154520.344057-1-idosch@nvidia.com> References: <20220219154520.344057-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR09CA0079.eurprd09.prod.outlook.com (2603:10a6:802:29::23) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca95fe5d-4d28-4da7-bf86-08d9f3beefaa X-MS-TrafficTypeDiagnostic: DM6PR12MB4340:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qle5kEXSY7LiLoIzaiFmc0jAke4+Bj9CR0hErDuDpJrnhTp10a6H4xGnTV0yfHiLpgWFfRctM85LdkO8+AUA78yrn07FqwiA7yIDnRy9JhafzJlk6YPGUqiI5ys/KPerY6YGju/HfE/jjp9V+vlYTxYQhppuUyaX0BDHCJoCTfSE/XPgMLjq+XTl660g/v0Z7ZTnc5w6m0BIF5dzBBhNgGJ6Yxhg5CGCJ6T1t/BVEsKuqMWKUFUwv4IBGUeoPcRbqOi/TtwWlhFpBGwwAEjExn6XKKFGGqX5vMu2tP987cm9kCpUDHmAqoExidf2qRy4sFcdy1BqSVI7qwri4dq+YSDJ9SE6ayl6p1HSfOZcq4cEJvazIWlWJ2FHPX/kXZ/hbcjBdQXjGSKWu76okhtee6MrnTk4eW5ivKxcUoVgfVwavdDJh39dV0MUx07vU0JEbFVbDCnvVaYja0lChtNiY6flYckGAwvDOtEDrbRgCHZhOTQlQrEA1Ig+snGQcjQLy+jJNc2cl5/iJXT7FJ0cGtfS6L663ZvqJT7Ll18ZiTDU3+jhkSl9U53zYB/Av6ujxSlJpOdxLhtKC2Y5sKtERcS66pGTmKX858K/Fanp6wSYiHs8awWy2bHGhJYls+AV25X0PEv7PCD4e+GU5uB/Q2AO0L9xRUtuEz4RqR7JJZhsCPwgvbbRMVz2+hS2yFyo+gE3r87I6yLAMzUvsilmH4s1X9Jmlq5+VPjevn8a5HY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(86362001)(38100700002)(6486002)(966005)(5660300002)(6916009)(8936002)(66476007)(66946007)(2906002)(66556008)(4326008)(8676002)(83380400001)(107886003)(6666004)(6512007)(6506007)(508600001)(2616005)(1076003)(186003)(26005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J8Hn+nt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RtUxcPt6XpMdvMqeJjK3W/je2+IseS6AS0ShQCzle/KpT4I1xSzea3ef7YRCkIfK2TczxqtHD9TldIaW7XPT4u+3Nq8qXy6DTCshGrgOUxjZEFWS4iJhLk7pYYJAOtcPOFHeQItuJfTeYH/pP0oFNxdM3Bsvy8Px0mzGdin2SnDVCjjNikLSyDgfggbia5IGvLWTXnHpJFrVvIqe5S/ChLzrtknjhihzjOhF68PkVJLqoY5S+XXFPQAGLxT+E+K7VupZy0s0E7clbsDoPnH+TlmxnLgpnnMqiywLNxxWU12BDeyq4c9nf/sb5pzcbd8e0imUdQSTLSRMZ+KLi5/W+RU0+dzG4dLkTjm8UnxdZph27lib6B3IoxGaxMv/rPP0+UOcLY1UfePt6yVy5GQ76GN1Np+UkMCBHQLkTi+OeNekZNl7ixYXXV83PpGnjy9zxqVzfE1FtnVUICi2wYQ7D/4p+9bRCLv74NyeMpt7ytj/rdXZ9nIyT4zuZogY7ZGzAJZiAPHxvDupkg+exidzlru/AtQnxIX12BkU87NmllPY= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca95fe5d-4d28-4da7-bf86-08d9f3beefaa X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2022 15:46:04.1766 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: doem/jHNq9K2iIFESoo0tWkVdlBZDZc2A+RkN6L44xggcw6KctOP3W1xc/OpQ4dmuuk6VOcYdhhACnrVHZEkzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4340 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In case user space sends a packet destined to a broadcast address when a matching broadcast route is not configured, the kernel will create a unicast neighbour entry that will never be resolved [1]. When the broadcast route is configured, the unicast neighbour entry will not be invalidated and continue to linger, resulting in packets being dropped. Solve this by invalidating unresolved neighbour entries for broadcast addresses after routes for these addresses are internally configured by the kernel. This allows the kernel to create a broadcast neighbour entry following the next route lookup. Another possible solution that is more generic but also more complex is to have the ARP code register a listener to the FIB notification chain and invalidate matching neighbour entries upon the addition of broadcast routes. It is also possible to wave off the issue as a user space problem, but it seems a bit excessive to expect user space to be that intimately familiar with the inner workings of the FIB/neighbour kernel code. [1] https://lore.kernel.org/netdev/55a04a8f-56f3-f73c-2aea-2195923f09d1@huawei.com/ Reported-by: Wang Hai Signed-off-by: Ido Schimmel Tested-by: Wang Hai --- Wang Hai, please retest as I have changed the patch a bit. --- include/net/arp.h | 1 + net/ipv4/arp.c | 9 +++++++-- net/ipv4/fib_frontend.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/net/arp.h b/include/net/arp.h index 031374ac2f22..d7ef4ec71dfe 100644 --- a/include/net/arp.h +++ b/include/net/arp.h @@ -65,6 +65,7 @@ void arp_send(int type, int ptype, __be32 dest_ip, const unsigned char *src_hw, const unsigned char *th); int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir); void arp_ifdown(struct net_device *dev); +int arp_invalidate(struct net_device *dev, __be32 ip, bool force); struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip, struct net_device *dev, __be32 src_ip, diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 4db0325f6e1a..dc28f0588e54 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1116,13 +1116,18 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev) return err; } -static int arp_invalidate(struct net_device *dev, __be32 ip) +int arp_invalidate(struct net_device *dev, __be32 ip, bool force) { struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev); int err = -ENXIO; struct neigh_table *tbl = &arp_tbl; if (neigh) { + if ((neigh->nud_state & NUD_VALID) && !force) { + neigh_release(neigh); + return 0; + } + if (neigh->nud_state & ~NUD_NOARP) err = neigh_update(neigh, NULL, NUD_FAILED, NEIGH_UPDATE_F_OVERRIDE| @@ -1169,7 +1174,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r, if (!dev) return -EINVAL; } - return arp_invalidate(dev, ip); + return arp_invalidate(dev, ip, true); } /* diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index e0730c4d07d6..7408051632ac 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -1124,9 +1124,11 @@ void fib_add_ifaddr(struct in_ifaddr *ifa) return; /* Add broadcast address, if it is explicitly assigned. */ - if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF)) + if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF)) { fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim, 0); + arp_invalidate(dev, ifa->ifa_broadcast, false); + } if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) && (prefix != addr || ifa->ifa_prefixlen < 32)) { @@ -1140,6 +1142,7 @@ void fib_add_ifaddr(struct in_ifaddr *ifa) if (ifa->ifa_prefixlen < 31) { fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix | ~mask, 32, prim, 0); + arp_invalidate(dev, prefix | ~mask, false); } } } From patchwork Sat Feb 19 15:45:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12752330 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87088C433EF for ; Sat, 19 Feb 2022 15:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242556AbiBSPqb (ORCPT ); Sat, 19 Feb 2022 10:46:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234373AbiBSPq3 (ORCPT ); Sat, 19 Feb 2022 10:46:29 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2080.outbound.protection.outlook.com [40.107.236.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5CA6606DF for ; Sat, 19 Feb 2022 07:46:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WtpP5zNpkze2EwE5Su8FDujVI098zBCppg3dGf9EOIxknDjCH7txPkkjCbs7AKqnGGWpIoZ+zOeqlUA/T/k0DZ8yJRTRh4PpcgOB79Xe5kmJA22LPG2DzhafbPwce/Xw2Hvteu3Qyt3xD8QqRjWVv1nF/P/PSpSoPftaWWb7V1plglHO5AtEHRgM+J/HjNSm27y7UgEnqc2NKCaxDfTrIFAtnkkJvJ7bS/1yy/YsrJ4tI88g+YTAhraBHRbFellq18POU/mtqNrZbP/Vd4GhGzSFA50bUIU4brMYQRqAR3sXtH+z0bYVIfcRXlDMoaotlPLql64qEZxr9SY9ZXuQiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p+Vbk0pnXtDU7GsknKW6k/295NBu/l030kH2N8vGWO4=; b=RmONqXOTIwdOJgpfsIAZ/4ploU6KISTMuAK6NM1syVq7ONnxwK1eU07meD1iiyUutGesS6MRzJkyt4p1bpZAd6XBOs/ouZPF8DvqMVaV94QS2MVs5bki/yuyk9IcOBl0q1R62IMeSQo6mQ0jUNKvETJ97iCYv1jDRP4GmBjnFJb0skCRKtfeiPyPHMxXy2NEOz+vZaVvDANyYfsLmi/V11PIEzR6Ov2V51x3rl6ZKL8R36LfjvOtSTu/STAFdfYcFawJi70r3gHTa417320kRuY2vMuAohNp0E2M/NJdDE8rYu3K1IdhRyobIluIF3dEvBmxB/NHMCN5v/xJ6c0cXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p+Vbk0pnXtDU7GsknKW6k/295NBu/l030kH2N8vGWO4=; b=HeCO4wWVCKKGWWwu6puO+63PSBmbTnuo2LVvD82x+f23qwNcirYrK22hovg2hezO79nAeCzhPH7UI22DVx+DRHX9wTP34tbtytjcuPYXlJzc4i9XYOuM5skHaOCtBQw+Tvo3LJXGysy4AzmvD8qJDpCaBUM6RABD8Lsj9nDxtAY6mzGgzx1GjuYmVW5VZhL5uq94GUvC7rf8Bcn0wqOPeXR3oGQNIUei35OQKcDBrLsod8ANs58FmkIUUE+92d9yL3keOtU4GUw8hMqNZDry3RwwPVxT1aUHvYW/zHb4BvcFXR+LYGuU1UnnGzHQxkENrBVq9QFdkZakip9AHzIZfA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by DM6PR12MB4340.namprd12.prod.outlook.com (2603:10b6:5:2a8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Sat, 19 Feb 2022 15:46:09 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%5]) with mapi id 15.20.4995.024; Sat, 19 Feb 2022 15:46:09 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, dsahern@gmail.com, wanghai38@huawei.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 2/2] selftests: fib_test: Add a test case for IPv4 broadcast neighbours Date: Sat, 19 Feb 2022 17:45:20 +0200 Message-Id: <20220219154520.344057-3-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220219154520.344057-1-idosch@nvidia.com> References: <20220219154520.344057-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P193CA0009.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::19) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ec3c121a-95e4-4c64-c81f-08d9f3bef2e3 X-MS-TrafficTypeDiagnostic: DM6PR12MB4340:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dAtYQJSgL/51CXheES+faA27Y7ctcX7Jg98Dvh+mSh6tb3t3EiDhxKGD+lR0TcgGXXiAKYvMxbV68lxjV9Y2MmzNg0CVQLKvt4o6KzaX9Mx/PE0ly4UvqReqqJ75IWnnHiK7Flu1t3JUEyjulemVN3omvfa2uzRY9J1Z++xQN8OYEn/UbKFyzv8CCVFebk/iEf1ClsaVNedGzqnWs7+1XAk4YkAAumvmvA7QGalvUe/EpbGPQgjQGzWwKI76fzq2/pzaBNTVd+NKClKqP1ZDX/fHu5JN16QJ7sOuizT3hwIINS72H12HdZg5k+8ueGqhs2pD38vJ7KNZWTRyweAnL7RQNGQUDdCZI1n39/k9WjyXSv+082x2K7dtrAAVbV6htJ/QvVKTWGImxkYsawE/PtouDFyU/s0gZuukojUZiiYEE/RdhDQkzBsF2MiO6x9123xtg1iNHjI6IYP8Qjl/o5iMi2RXJwWbSEpkiBJ+Z6qeaXpGxpqvhf9rtPcoDiyT5iw2UotWANyGm8VokovOKkUh4NrqCa9ePoY5J4y0k1C0EypP7q/9/CfRp/j3jIITJvcQ41tKZ6nevwngDrMBc4bYJshiKDTCkdBKfvMhwuex5Fy5ikF/ZA5G+h0rJpTILUceNj0oexEvHjmvubjPUA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(86362001)(38100700002)(6486002)(5660300002)(6916009)(8936002)(66476007)(66946007)(2906002)(66556008)(4326008)(8676002)(83380400001)(107886003)(6666004)(6512007)(6506007)(508600001)(2616005)(1076003)(186003)(26005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tZToswBhw8LjcxqneHSQZthlmmQV9ZmVQxMKfanQItVpsaJaRSv6R+SYSajnRyrWYn17bYpfwp6vdYv4cZLpYsce0THKgfcI4SwGWHci6oB/efHsGzSw/KSf15J948NKWhPav5BMRrTT6/CVO9YlffT2mIrxrpUN1QAWhmTGJ6otUguYNwgaRyJW7r0JhMqGG5drTrXGdFLxN12KrA/OQAG7yd+6aWuUBaPm0ARdyLWssfrWIQz5npi0uXZRkN+RykscAzjA/6kyoLPVb/VFCqc8M957/5MaQ8BwjDnWhJabbvxERUBOHtg6OCnMNjbn3Ro3c1n3++1zJUxZepdO7wjG7fXWBxWFdLtNToGqHiawCQO2FEvvGSDnyonS9VDi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EfFxH/tcEVXEtabmweYXJYD58gjCYIhE4b2Xu2qWns3ShW6jCmZVnajjtJ5fBuVz7EyRAtVXEXyKjf8V20sVLwpbAALnKs2glw2CxK+Bmicw1do5t/TuTHZ9csz5J4ewXRt5w6vDzzqf4Z3DpEKfjaRF5u4epWQGkhwWEOJ9SKrvYDFB/MDRE= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec3c121a-95e4-4c64-c81f-08d9f3bef2e3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2022 15:46:09.4610 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wgZJOnnU0BKDVYcfryPr3te1NoFU+C8hChxcrA54gvKLyQqof0se+AmqzUVv78FowifSNuZtxm72QiEvBFeHgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4340 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Test that resolved neighbours for IPv4 broadcast addresses are unaffected by the configuration of matching broadcast routes, whereas unresolved neighbours are invalidated. Without previous patch: # ./fib_tests.sh -t ipv4_bcast_neigh IPv4 broadcast neighbour tests TEST: Resolved neighbour for broadcast address [ OK ] TEST: Resolved neighbour for network broadcast address [ OK ] TEST: Unresolved neighbour for broadcast address [FAIL] TEST: Unresolved neighbour for network broadcast address [FAIL] Tests passed: 2 Tests failed: 2 With previous patch: # ./fib_tests.sh -t ipv4_bcast_neigh IPv4 broadcast neighbour tests TEST: Resolved neighbour for broadcast address [ OK ] TEST: Resolved neighbour for network broadcast address [ OK ] TEST: Unresolved neighbour for broadcast address [ OK ] TEST: Unresolved neighbour for network broadcast address [ OK ] Tests passed: 4 Tests failed: 0 Signed-off-by: Ido Schimmel --- tools/testing/selftests/net/fib_tests.sh | 58 +++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index e2690cc42da3..2271a8727f62 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -9,7 +9,7 @@ ret=0 ksft_skip=4 # all tests in this script. Can be overridden with -t option -TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle" +TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh" VERBOSE=0 PAUSE_ON_FAIL=no @@ -1954,6 +1954,61 @@ ipv6_mangle_test() route_cleanup } +ip_neigh_get_check() +{ + ip neigh help 2>&1 | grep -q 'ip neigh get' + if [ $? -ne 0 ]; then + echo "iproute2 command does not support neigh get. Skipping test" + return 1 + fi + + return 0 +} + +ipv4_bcast_neigh_test() +{ + local rc + + echo + echo "IPv4 broadcast neighbour tests" + + ip_neigh_get_check || return 1 + + setup + + set -e + run_cmd "$IP neigh add 192.0.2.111 lladdr 00:11:22:33:44:55 nud perm dev dummy0" + run_cmd "$IP neigh add 192.0.2.255 lladdr 00:11:22:33:44:55 nud perm dev dummy0" + + run_cmd "$IP neigh get 192.0.2.111 dev dummy0" + run_cmd "$IP neigh get 192.0.2.255 dev dummy0" + + run_cmd "$IP address add 192.0.2.1/24 broadcast 192.0.2.111 dev dummy0" + + run_cmd "$IP neigh add 203.0.113.111 nud failed dev dummy0" + run_cmd "$IP neigh add 203.0.113.255 nud failed dev dummy0" + + run_cmd "$IP neigh get 203.0.113.111 dev dummy0" + run_cmd "$IP neigh get 203.0.113.255 dev dummy0" + + run_cmd "$IP address add 203.0.113.1/24 broadcast 203.0.113.111 dev dummy0" + set +e + + run_cmd "$IP neigh get 192.0.2.111 dev dummy0" + log_test $? 0 "Resolved neighbour for broadcast address" + + run_cmd "$IP neigh get 192.0.2.255 dev dummy0" + log_test $? 0 "Resolved neighbour for network broadcast address" + + run_cmd "$IP neigh get 203.0.113.111 dev dummy0" + log_test $? 2 "Unresolved neighbour for broadcast address" + + run_cmd "$IP neigh get 203.0.113.255 dev dummy0" + log_test $? 2 "Unresolved neighbour for network broadcast address" + + cleanup +} + ################################################################################ # usage @@ -2028,6 +2083,7 @@ do ipv4_route_v6_gw) ipv4_route_v6_gw_test;; ipv4_mangle) ipv4_mangle_test;; ipv6_mangle) ipv6_mangle_test;; + ipv4_bcast_neigh) ipv4_bcast_neigh_test;; help) echo "Test names: $TESTS"; exit 0;; esac