diff options
author | Neale Ranns <nranns@cisco.com> | 2019-11-06 11:17:54 +0000 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2019-11-14 12:25:21 +0000 |
commit | 11b5d24cde2a5ecbfed5925b2b748fd3dd955fc2 (patch) | |
tree | 6d1ba65540fc93047e51639a4bd17a2abee87bcd | |
parent | faf62c8b20e8335bf0e86a68d34636bf4c312fef (diff) |
fib: Copy the prefix before use in case the underlying entry reallocs.
Type: fix
all other uses of the fib_entry_get_preifx in the code base don't pass
the prefix into recursive functions.
Change-Id: Ic1c56acd406a733b215ee2fd98b6bed58b490a4f
Signed-off-by: Neale Ranns <nranns@cisco.com>
(cherry picked from commit 320dfcf2aa8f4617b51a2bb15f3d0f93ee62d4dc)
-rw-r--r-- | src/vnet/fib/fib_attached_export.c | 12 | ||||
-rw-r--r-- | src/vnet/fib/fib_types.c | 7 | ||||
-rw-r--r-- | src/vnet/fib/fib_types.h | 6 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/vnet/fib/fib_attached_export.c b/src/vnet/fib/fib_attached_export.c index da83a3d4184..e815ba421ec 100644 --- a/src/vnet/fib/fib_attached_export.c +++ b/src/vnet/fib/fib_attached_export.c @@ -152,7 +152,7 @@ fib_entry_import_add (fib_ae_import_t *import, fib_node_index_t entry_index) { fib_node_index_t *existing; - const fib_prefix_t *prefix; + fib_prefix_t prefix; /* * ensure we only add the exported entry once, since @@ -168,15 +168,15 @@ fib_entry_import_add (fib_ae_import_t *import, /* * this is the first time this export entry has been imported - * Add it to the import FIB and to the list of importeds + * Add it to the import FIB and to the list of importeds. + * make a copy of the prefix in case the underlying entry reallocs. */ - prefix = fib_entry_get_prefix(entry_index); + fib_prefix_copy(&prefix, fib_entry_get_prefix(entry_index)); /* * don't import entries that have the same prefix the import entry */ - if (0 != fib_prefix_cmp(prefix, - &import->faei_prefix)) + if (0 != fib_prefix_cmp(&prefix, &import->faei_prefix)) { const dpo_id_t *dpo; @@ -185,7 +185,7 @@ fib_entry_import_add (fib_ae_import_t *import, if (dpo_id_is_valid(dpo) && !dpo_is_drop(dpo)) { fib_table_entry_special_dpo_add(import->faei_import_fib, - prefix, + &prefix, FIB_SOURCE_AE, (fib_entry_get_flags(entry_index) | FIB_ENTRY_FLAG_EXCLUSIVE), diff --git a/src/vnet/fib/fib_types.c b/src/vnet/fib/fib_types.c index 7f0f13079ee..3eba4488efa 100644 --- a/src/vnet/fib/fib_types.c +++ b/src/vnet/fib/fib_types.c @@ -101,6 +101,13 @@ fib_prefix_from_mpls_label (mpls_label_t label, pfx->fp_eos = eos; } +void +fib_prefix_copy (fib_prefix_t *dst, + const fib_prefix_t *src) +{ + memcpy(dst, src, sizeof(*dst)); +} + int fib_prefix_cmp (const fib_prefix_t *p1, const fib_prefix_t *p2) diff --git a/src/vnet/fib/fib_types.h b/src/vnet/fib/fib_types.h index 472ce888b4e..c7716c70f47 100644 --- a/src/vnet/fib/fib_types.h +++ b/src/vnet/fib/fib_types.h @@ -248,6 +248,12 @@ extern int fib_prefix_cmp(const fib_prefix_t *p1, const fib_prefix_t *p2); /** + * \brief Copy a prefix + */ +extern void fib_prefix_copy(fib_prefix_t *dst, + const fib_prefix_t *src); + +/** * \brief Compare two prefixes for covering relationship * * \return non-zero if the first prefix is a cover for the second |