Commit 39534d74 authored by Maria Matejka's avatar Maria Matejka
Browse files

Fixed hostentry update for sorted tables

Best route recalculation after nexthop update completely ignored the
table's sortedness.
parent 1ca7665f
Loading
Loading
Loading
Loading
+45 −12
Original line number Diff line number Diff line
@@ -2075,6 +2075,34 @@ rt_next_hop_update_rte(rtable *tab UNUSED, rte *old)
  return e;
}

static struct rte *
rte_recalc_sort(struct rte *chain)
{
  ASSERT(chain);

  /* Single route -> nothing to do */
  if (!chain->next)
    return chain;

  /* Simple insert sort (TODO: something faster for long chains) */
  struct rte *best = chain, *next = chain->next, *cur;
  chain->next = NULL;

  while (cur = next)
  {
    next = cur->next;
    for (struct rte **k = &best; *k; k = &((*k)->next))
      if (rte_better(cur, *k))
      {
	cur->next = *k;
	*k = cur;
	break;
      }
  }

  return best;
}

static inline int
rt_next_hop_update_net(rtable *tab, net *n)
{
@@ -2113,6 +2141,10 @@ rt_next_hop_update_net(rtable *tab, net *n)
    return 0;

  /* Find the new best route */
  if (tab->config->sorted)
    new = n->routes = rte_recalc_sort(n->routes);
  else
    {
      new_best = NULL;
      for (k = &n->routes; e = *k; k = &e->next)
      {
@@ -2128,6 +2160,7 @@ rt_next_hop_update_net(rtable *tab, net *n)
	new->next = n->routes;
	n->routes = new;
      }
    }

  /* Announce the new best route */
  if (new != old_best)