From ff880b78ef2d480b381d29487812279d57c0bbac Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 2 Oct 2017 22:06:04 -0300 Subject: *: introduce new rb-tree to optimize interface lookup by ifindex Performance tests showed that, when running on a system with a large number of interfaces, some daemons would spend a considerable amount of time in the if_lookup_by_index() function. Introduce a new rb-tree to solve this problem. With this change, we need to use the if_set_index() function whenever we want to change the ifindex of an interface. This is necessary to ensure that the 'ifaces_by_index' rb-tree is updated accordingly. The return value of all insert/remove operations in the interface rb-trees is checked to ensure that an error is logged if a corruption is detected. Signed-off-by: Renato Westphal --- zebra/kernel_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'zebra/kernel_socket.c') diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index cbfc371199..89c933f90f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -324,7 +324,7 @@ static int ifan_read(struct if_announcemsghdr *ifan) /* Create Interface */ ifp = if_get_by_name(ifan->ifan_name, VRF_DEFAULT, 0); - ifp->ifindex = ifan->ifan_index; + if_set_index(ifp, ifan->ifan_index); if_get_metric(ifp); if_add_update(ifp); @@ -528,7 +528,7 @@ int ifm_read(struct if_msghdr *ifm) * Fill in newly created interface structure, or larval * structure with ifindex IFINDEX_INTERNAL. */ - ifp->ifindex = ifm->ifm_index; + if_set_index(ifp, ifm->ifm_index); #ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */ bsd_linkdetect_translate(ifm); -- cgit v1.2.3