Message ID | SY4PR01MB8438009B66608ED47C12ED43CD2F9@SY4PR01MB8438.ausprd01.prod.outlook.com |
---|---|
State | Accepted |
Commit | f1eb850aea833c5fd0cc106020184b0db63d7a30 |
Headers | show |
Series | mac-learning: Fix learned fdb entries not age out issue. | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/intel-ovs-compilation | success | test: success |
On 23 Oct 2022, at 6:58, miterv@outlook.com wrote: > From: Lin Huang <linhuang@ruijie.com.cn> > > 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 <zhangyuhuang@ruijie.com.cn> > Signed-off-by: Lin Huang <linhuang@ruijie.com.cn> Thanks for fixing the nit! Acked-by: Eelco Chaudron <echaudro@redhat.com> Cheers, Eelco
On 10/31/22 11:45, Eelco Chaudron wrote: > > > On 23 Oct 2022, at 6:58, miterv@outlook.com wrote: > >> From: Lin Huang <linhuang@ruijie.com.cn> >> >> 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 <zhangyuhuang@ruijie.com.cn> >> Signed-off-by: Lin Huang <linhuang@ruijie.com.cn> > > > Thanks for fixing the nit! > > Acked-by: Eelco Chaudron <echaudro@redhat.com> Thanks! Applied and backported down to 2.17. Best regards, Ilya Maximets.
diff --git a/lib/mac-learning.c b/lib/mac-learning.c index a60794fb2..5932e2709 100644 --- a/lib/mac-learning.c +++ b/lib/mac-learning.c @@ -176,12 +176,18 @@ 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 +624,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