From f8798767219ddc5a6dc075b1d2c751ee910e4f10 Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Sun, 17 Jan 2021 19:43:52 +0000 Subject: [PATCH] Fix IPv4 fib bsearch4() lookup array construction. Current code didn't properly handle the case with nested prefixes like 10.0.0.0/24 && 10.0.0.0/25. --- sys/netinet/in_fib_algo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/netinet/in_fib_algo.c b/sys/netinet/in_fib_algo.c index 48e48da395fa..fd817a3fedf0 100644 --- a/sys/netinet/in_fib_algo.c +++ b/sys/netinet/in_fib_algo.c @@ -360,6 +360,18 @@ bsearch4_process_record(struct bsearch4_array *dst_array, if (!add_array_entry(dst_array, &new_entry)) return (false); } + + /* + * Special case: adding more specific prefix at the start of + * the previous interval: + * 10.0.0.0(/24,nh=3), 10.0.0.0(/25,nh=4) + * Alter the last record, seeting new nexthop and mask. + */ + if (br_tmp->addr4 == rib_entry->addr4) { + *br_tmp = *rib_entry; + add_array_entry(stack, rib_entry); + return (true); + } } if (!add_array_entry(dst_array, rib_entry))