From patchwork Thu Oct 20 15:06:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: miter X-Patchwork-Id: 1692590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=Hzq1oCKz; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MtWCh4nJzz23jk for ; Fri, 21 Oct 2022 02:06:56 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D14484059D; Thu, 20 Oct 2022 15:06:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org D14484059D Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=Hzq1oCKz X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2E402ZqkmNds; Thu, 20 Oct 2022 15:06:53 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id DEFDD4052D; Thu, 20 Oct 2022 15:06:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org DEFDD4052D Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C530BC0032; Thu, 20 Oct 2022 15:06:52 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id CA891C002D for ; Thu, 20 Oct 2022 15:06:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id A3CFF4059D for ; Thu, 20 Oct 2022 15:06:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A3CFF4059D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C28rs5t1-_wO for ; Thu, 20 Oct 2022 15:06:49 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A75864052D Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2172.outbound.protection.outlook.com [40.92.62.172]) by smtp2.osuosl.org (Postfix) with ESMTPS id A75864052D for ; Thu, 20 Oct 2022 15:06:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OjNgtoZKFjF29ZI3k50x7hQLcj7scD36PRey6b2Gu4JR+WWdHTwNZTEJRbeb8fwOX+8ayTKzZqAZdRo3oR7cfeyK8fc6QPMklZQZ6XTvgd4nEwTQYmx39BofCVJ15WfZ4xjgAMLGOeRr4Sa405eB6nZwo6qhVMtPQh05it+/qGAcQosFDa4ZPhEg0V/lU6NQ3/RDHdIC0DL+th57mv9BSHEykkueq2GVXQCxx/a/UjNADXgxpY8UkgoComDqKMMIZRrPqE+fuc7e9iNG/v5d/fCLXltF5qcNEUYhGLLpHCrH1BNxslpYcJp0X2Gu33Zff1FvKzq/KqzatpHYdfSC1w== 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=baQPD6SQS3koYyeUD7Kth3jXOo+J7zGpGyQErr31/Gc=; b=YzZwx/ewwLMpdls1pPOjxh9kGlM/WGarxXpdHMIzFBZmyciTwDv+luZ9ePkDFuYJJr3OyuAX0GiWqOXKqhQgJliWjsEkf2Idik70+3T5lp6Ko8LsDwbHwveuZgvg8Ny9NKXVn8mGkcE8pZSSLxLDNnGify6XF9/UHDAirEJYToqOjaCjevJ0lc+g8QidfnodspImJ5oSFUqH+qHxyuAR9jToIEvt8mT25PvseVIMRV9T3AlmFsssFDTknCRS6700bSJD28mBzcYzyPvaMzP29fV8T4K4DytcRa8XQNGe6aowvMGOnaocnU2fTVOrYgawtTm9vJxGAPKa34yK4shAzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=baQPD6SQS3koYyeUD7Kth3jXOo+J7zGpGyQErr31/Gc=; b=Hzq1oCKzKZIknwH9d2HPGQpyx6onuF1KOKsYpNA+DBPrGDuo0Kq6FW+kY4+hmoct5YAdmdDODP/ix6Nj4hNxYxYVj9rG0QtfcUDw7Uh4QQfGEotdHH+D5gl8/KEmjdCSgCYBFPHyZOyUzkGW5g+Ga1u+toy+IEnUxt6S/bJ/YACl2+Ek3eNPDOv5S7IpUufitzpSsAMcRSei2++rs/sg1Kb4ugAEUQROJh5tyhjsqTSjeMAAtm3KVqWNg+kj/2JE2s6QeeBF5Aqc5hBhKbHGIO+B4VESIY8aPoJut+T2xny6KIQNm80l8Fu67Lq5vOTwUP+SKpSjakhpru/n5p6quw== Received: from SY4PR01MB8438.ausprd01.prod.outlook.com (2603:10c6:10:19e::10) by ME2PR01MB3891.ausprd01.prod.outlook.com (2603:10c6:220:31::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.34; Thu, 20 Oct 2022 15:06:46 +0000 Received: from SY4PR01MB8438.ausprd01.prod.outlook.com ([fe80::181:e529:664a:ac4b]) by SY4PR01MB8438.ausprd01.prod.outlook.com ([fe80::181:e529:664a:ac4b%4]) with mapi id 15.20.5723.035; Thu, 20 Oct 2022 15:06:46 +0000 From: miterv@outlook.com To: ovs-dev@openvswitch.org, echaudro@redhat.com Date: Thu, 20 Oct 2022 23:06:16 +0800 Message-ID: X-Mailer: git-send-email 2.37.1.windows.1 X-TMN: [G1HcNMqyYMMRU9VxG/8GDtBHqXIVpQ07] X-ClientProxiedBy: SI2PR01CA0002.apcprd01.prod.exchangelabs.com (2603:1096:4:191::21) To SY4PR01MB8438.ausprd01.prod.outlook.com (2603:10c6:10:19e::10) X-Microsoft-Original-Message-ID: <20221020150616.1210-1-miterv@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4PR01MB8438:EE_|ME2PR01MB3891:EE_ X-MS-Office365-Filtering-Correlation-Id: e27a5c5a-fa20-41e6-3d4e-08dab2acb498 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f4NiD13bhJKDL8BDojCTNLEJ9n6CGG9dBOrLD8PLz0UqyTsgDsm3yz4vfe7Zb5KsYdJxy/dIbZj7chPhOW4Lvnz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/qBGJRTx7KoZgW/NaQk4VtMRkZzD+kEwnTQckmx5X3hnRxBthijnHNlWZvyYTDfrSCsDr5V1vlVZomRS2xav5pINy1I8JQ44YEOj3d35thb6QB0czUgE0wG+/pNaArVvXZiWUFRxBvBEnLQvYtQynOQ+dUgsi1JMYK5JhKXjAIBt7sSUo/9FoYEYOQz7ifg7VuDgKFOdhIigJV4iesn5tmBhT9kGh/aHxzMmgEMDMRDgtqnIVkxboos9+UP1Zm7fkenAJmuWqLfo4VdaK4UmhZl48OHK/AioniE2Qbj/FlU5yTnsiKn2o7x+9l7oXUawRjp4GsDZQDLsb5rH+pr+wDpI0Nifr+Dz1mMOQQ0BtyAGwrsv+bu/2KwR0rM3K8v1G0bBTlA7/5/+yfE+WHrk3vxEg3uDyYlu/AjTmw9ObzNyMTDgn2+iuu8xjkdCafZ0MO9jYX39uf/Uzajv5zWKxUs2TtmVZT+A7BWsVhVC/d4LgYiQCndK8I2xzJL4/6KZw8MO9j6ZpZyYTCsOLqtjbB4YxqA+MtL/gHIWz7cqwMFQmSDXYL6+bJujfBDL2ME1ldPymGecSxTo+CePuUNputVpFstBYDQQ8Aq5Acp/mn3E84QMl3Dx66lDT1nGFZBSWNLjtaBiF2SQPCahUNg115ElHJl956RqR6WfPEdbdbtjE+MtDpFiOW4TKKPdczeSfRluDWNPbov1yXAdYyeHP/pfN9h58CmKzUTkEqhkZBDFBiQmjeh9H2DBya3RUIcuE5A15HA0rBz/4z4VjxzjPvdVz+kBjkfT6D6MIpJuBIwdO22ffBZlxVZ4V8uoBeWVWkVA97gAfjwUEdrBdMQj3o3ZvspZ3JB6LocMOpmKZ07RTHg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e27a5c5a-fa20-41e6-3d4e-08dab2acb498 X-MS-Exchange-CrossTenant-AuthSource: SY4PR01MB8438.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 15:06:46.2841 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: ME2PR01MB3891 Cc: Lin Huang , Zhang Yuhuang Subject: [ovs-dev] [PATCH] mac-learning: Fix learned fdb entries not age out issue. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Lin Huang After user add a static fdb entry, the get_lru() function will always return the static fdb entry. That's normal fdb entries will not age out through mac_learning_run(). Fix the issue by modify the get_lru() function to check the entry->expires field and not return the entry which entry->expires is MAC_ENTRY_AGE_STATIC_ENTRY. Adding a unit test for this. Fixes: ccc24fc88d59 ("ofproto-dpif: APIs and CLI option to add/delete static fdb entry.") Tested-by: Zhang Yuhuang Signed-off-by: Lin Huang Acked-by: Eelco Chaudron --- lib/mac-learning.c | 36 +++++++++++++----------------------- tests/ofproto-dpif.at | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/mac-learning.c b/lib/mac-learning.c index a60794fb2..e8ead51af 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -176,12 +176,17 @@ get_lru(struct mac_learning *ml, struct mac_entry **e) OVS_REQ_RDLOCK(ml->rwlock) { if (!ovs_list_is_empty(&ml->lrus)) { - *e = mac_entry_from_lru_node(ml->lrus.next); - return true; - } else { - *e = NULL; - return false; + struct mac_entry *entry; + LIST_FOR_EACH (entry, lru_node, &ml->lrus) { + if (entry->expires != MAC_ENTRY_AGE_STATIC_ENTRY) { + *e = entry; + return true; + } + } } + + *e = NULL; + return false; } static unsigned int @@ -618,25 +623,10 @@ mac_learning_expire(struct mac_learning *ml, struct mac_entry *e) void mac_learning_flush(struct mac_learning *ml) { - struct mac_entry *e, *first_static_mac = NULL; - - while (get_lru(ml, &e) && (e != first_static_mac)) { - - /* Static mac should not be evicted. */ - if (MAC_ENTRY_AGE_STATIC_ENTRY == e->expires) { - - /* Make note of first static-mac encountered, so that this while - * loop will break on visting this mac again via get_lru(). */ - if (!first_static_mac) { - first_static_mac = e; - } + struct mac_entry *e; - /* Remove from lru head and append it to tail. */ - ovs_list_remove(&e->lru_node); - ovs_list_push_back(&ml->lrus, &e->lru_node); - } else { - mac_learning_expire(ml, e); - } + while (get_lru(ml, &e)) { + mac_learning_expire(ml, e); } hmap_shrink(&ml->table); } diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index 8e993c585..eb4cd1896 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -7287,6 +7287,29 @@ AT_CHECK([ovs-appctl coverage/read-counter mac_learning_static_none_move], [0], OVS_VSWITCHD_STOP AT_CLEANUP +AT_SETUP([ofproto-dpif - static-mac learned mac age out]) +OVS_VSWITCHD_START([set bridge br0 fail-mode=standalone -- set bridge br0 other_config:mac-aging-time=5]) +add_of_ports br0 1 2 + +dnl Add some static mac entries. +AT_CHECK([ovs-appctl fdb/add br0 p1 0 50:54:00:00:01:01]) +AT_CHECK([ovs-appctl fdb/add br0 p2 0 50:54:00:00:02:02]) + +dnl Generate some dynamic fdb entries on some ports. +OFPROTO_TRACE([ovs-dummy], [in_port(1),eth(src=60:54:00:00:00:01)], [-generate], [100,2]) +OFPROTO_TRACE([ovs-dummy], [in_port(2),eth(src=60:54:00:00:00:02)], [-generate], [100,1]) + +dnl Waiting for aging out. +ovs-appctl time/warp 20000 + +dnl Count number of static entries remaining. +AT_CHECK_UNQUOTED([ovs-appctl fdb/stats-show br0 | grep expired], [0], [dnl + Total number of expired MAC entries : 2 +]) + +OVS_VSWITCHD_STOP +AT_CLEANUP + AT_SETUP([ofproto-dpif - basic truncate action]) OVS_VSWITCHD_START add_of_ports br0 1 2 3 4 5