From 510b1046e186a913ea4195d27009e95794dd1e51 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Mon, 28 Aug 2023 15:36:40 +0200 Subject: [PATCH] Hostentry application locking Due to a race condition between rta_apply_hostentry() and rt_update_hostentry(), happening when a new route is inserted to a table, this commit makes it mandatory to lock the next hop resolution table while resolving the next hop. This may be slow, we'll fix it better in some future release --- nest/rt-table.c | 9 ++++++--- nest/rt.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/nest/rt-table.c b/nest/rt-table.c index c1bb1588e..6d99a7b3e 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -3416,7 +3416,7 @@ ea_set_hostentry(ea_list **to, rtable *dep, rtable *src, ip_addr gw, ip_addr ll, static void -rta_apply_hostentry(ea_list **to, struct hostentry_adata *head) +rta_apply_hostentry(struct rtable_private *tab UNUSED, ea_list **to, struct hostentry_adata *head) { struct hostentry *he = head->he; u32 *labels = head->labels; @@ -3544,7 +3544,8 @@ rt_next_hop_update_rte(rte *old, rte *new) return 0; *new = *old; - rta_apply_hostentry(&new->attrs, head); + RT_LOCKED(head->he->owner, tab) + rta_apply_hostentry(tab, &new->attrs, head); return 1; } @@ -3557,7 +3558,8 @@ rt_next_hop_resolve_rte(rte *r) struct hostentry_adata *head = (struct hostentry_adata *) heea->u.ptr; - rta_apply_hostentry(&r->attrs, head); + RT_LOCKED(head->he->owner, tab) + rta_apply_hostentry(tab, &r->attrs, head); } #ifdef CONFIG_BGP @@ -4875,6 +4877,7 @@ rt_get_hostentry(struct rtable_private *tab, ip_addr a, ip_addr ll, rtable *dep) if (!he) { he = hc_new_hostentry(hc, tab->rp, a, link, dep, k); + he->owner = RT_PUB(tab); rt_update_hostentry(tab, he); } diff --git a/nest/rt.h b/nest/rt.h index 76d33ec78..a251b3a58 100644 --- a/nest/rt.h +++ b/nest/rt.h @@ -489,6 +489,7 @@ struct hostentry { ip_addr link; /* (link-local) IP address of host, used as gw if host is directly attached */ rtable *tab; /* Dependent table, part of key */ + rtable *owner; /* Nexthop owner table */ struct hostentry *next; /* Next in hash chain */ unsigned hash_key; /* Hash key */ unsigned uc; /* Use count */ -- 2.47.2