diff options
author | Nathan Skrzypczak <nathan.skrzypczak@gmail.com> | 2021-09-17 17:29:14 +0200 |
---|---|---|
committer | Neale Ranns <neale@graphiant.com> | 2021-10-11 12:04:03 +0000 |
commit | 275bd796346c3b1618170f4eda36b9a41ade9c87 (patch) | |
tree | 197df1102b0a3981c6a875100f521806a170f45c /src/vnet/fib/fib_table.c | |
parent | bd23b405fbe99034d75a46b060567e5adf62c04e (diff) |
ip: fix fib and mfib locks
This patches fixes an issue that could cause
fib locks to underflow: if an API user deletes
a fib and quickly recreates it, the fib may not
have been actually deleted. As a result, the
lock would not be incremented on the create call
leading to the fib potentially disappearing
afterwards - or to the lock to underflow when
the fib is deleted again.
In order to keep the existing API semantics,
we use the locks with API and CLI source as flags.
This means we need to use a different counter
for the interface-related locks.
This also prevents an issue where an interface being
bound to a vrf via API and released via CLI could
mess up the lock counter.
Finally, this will help with cleaning up the
interface-related locks on interface deletion
in a later patch.
Type: fix
Change-Id: I93030a7660646d6dd179ddf27fe4e708aa11b90e
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Signed-off-by: Aloys Augustin <aloaugus@cisco.com>
Diffstat (limited to 'src/vnet/fib/fib_table.c')
-rw-r--r-- | src/vnet/fib/fib_table.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/vnet/fib/fib_table.c b/src/vnet/fib/fib_table.c index f222828898b..3a46d226ebd 100644 --- a/src/vnet/fib/fib_table.c +++ b/src/vnet/fib/fib_table.c @@ -1338,6 +1338,36 @@ fib_table_lock_inc (fib_table_t *fib_table, fib_table->ft_total_locks++; } + +static void +fib_table_lock_clear (fib_table_t *fib_table, + fib_source_t source) +{ + vec_validate(fib_table->ft_locks, source); + + ASSERT(fib_table->ft_locks[source] <= 1); + if (fib_table->ft_locks[source]) + { + fib_table->ft_locks[source]--; + fib_table->ft_total_locks--; + } +} + +static void +fib_table_lock_set (fib_table_t *fib_table, + fib_source_t source) +{ + vec_validate(fib_table->ft_locks, source); + + ASSERT(fib_table->ft_locks[source] <= 1); + ASSERT(fib_table->ft_total_locks < (0xffffffff - 1)); + if (!fib_table->ft_locks[source]) + { + fib_table->ft_locks[source]++; + fib_table->ft_total_locks++; + } +} + void fib_table_unlock (u32 fib_index, fib_protocol_t proto, @@ -1346,7 +1376,11 @@ fib_table_unlock (u32 fib_index, fib_table_t *fib_table; fib_table = fib_table_get(fib_index, proto); - fib_table_lock_dec(fib_table, source); + + if (source == FIB_SOURCE_API || source == FIB_SOURCE_CLI) + fib_table_lock_clear(fib_table, source); + else + fib_table_lock_dec(fib_table, source); if (0 == fib_table->ft_total_locks) { @@ -1366,7 +1400,10 @@ fib_table_lock (u32 fib_index, fib_table = fib_table_get(fib_index, proto); - fib_table_lock_inc(fib_table, source); + if (source == FIB_SOURCE_API || source == FIB_SOURCE_CLI) + fib_table_lock_set(fib_table, source); + else + fib_table_lock_inc(fib_table, source); } u32 |