Revision e86cfd41 sysdep/unix/krt.c

View differences:

sysdep/unix/krt.c
417 417
      net *n = (net *) f;
418 418
      rte *e, **ee, *best, **pbest, *old_best;
419 419

  
420
      old_best = n->routes;
420
      /*
421
       * Note that old_best may be NULL even if there was an old best route in
422
       * the previous step, because it might be replaced in krt_learn_scan().
423
       * But in that case there is a new valid best route.
424
       */
425

  
426
      old_best = NULL;
421 427
      best = NULL;
422 428
      pbest = NULL;
423 429
      ee = &n->routes;
424 430
      while (e = *ee)
425 431
	{
432
	  if (e->u.krt.best)
433
	    old_best = e;
434

  
426 435
	  if (!e->u.krt.seen)
427 436
	    {
428 437
	      *ee = e->next;
429 438
	      rte_free(e);
430 439
	      continue;
431 440
	    }
441

  
432 442
	  if (!best || best->u.krt.metric > e->u.krt.metric)
433 443
	    {
434 444
	      best = e;
435 445
	      pbest = ee;
436 446
	    }
447

  
437 448
	  e->u.krt.seen = 0;
449
	  e->u.krt.best = 0;
438 450
	  ee = &e->next;
439 451
	}
440 452
      if (!n->routes)
441 453
	{
442 454
	  DBG("%I/%d: deleting\n", n->n.prefix, n->n.pxlen);
443 455
	  if (old_best)
444
	    {
445
	      krt_learn_announce_delete(p, n);
446
	      n->n.flags &= ~KRF_INSTALLED;
447
	    }
456
	    krt_learn_announce_delete(p, n);
457

  
448 458
	  FIB_ITERATE_PUT(&fit, f);
449 459
	  fib_delete(fib, f);
450 460
	  goto again;
451 461
	}
462

  
463
      best->u.krt.best = 1;
452 464
      *pbest = best->next;
453 465
      best->next = n->routes;
454 466
      n->routes = best;
455
      if (best != old_best || !(n->n.flags & KRF_INSTALLED) || p->reload)
467

  
468
      if ((best != old_best) || p->reload)
456 469
	{
457 470
	  DBG("%I/%d: announcing (metric=%d)\n", n->n.prefix, n->n.pxlen, best->u.krt.metric);
458 471
	  krt_learn_announce_update(p, best);
459
	  n->n.flags |= KRF_INSTALLED;
460 472
	}
461 473
      else
462 474
	DBG("%I/%d: uptodate (metric=%d)\n", n->n.prefix, n->n.pxlen, best->u.krt.metric);
......
515 527
  best = n->routes;
516 528
  bestp = &n->routes;
517 529
  for(gg=&n->routes; g=*gg; gg=&g->next)
530
  {
518 531
    if (best->u.krt.metric > g->u.krt.metric)
519 532
      {
520 533
	best = g;
521 534
	bestp = gg;
522 535
      }
536

  
537
    g->u.krt.best = 0;
538
  }
539

  
523 540
  if (best)
524 541
    {
542
      best->u.krt.best = 1;
525 543
      *bestp = best->next;
526 544
      best->next = n->routes;
527 545
      n->routes = best;
528 546
    }
547

  
529 548
  if (best != old_best)
530 549
    {
531 550
      DBG("krt_learn_async: distributing change\n");
532 551
      if (best)
533
	{
534
	  krt_learn_announce_update(p, best);
535
	  n->n.flags |= KRF_INSTALLED;
536
	}
552
	krt_learn_announce_update(p, best);
537 553
      else
538
	{
539
	  n->routes = NULL;
540
	  krt_learn_announce_delete(p, n);
541
	  n->n.flags &= ~KRF_INSTALLED;
542
	}
554
	krt_learn_announce_delete(p, n);
543 555
    }
544 556
}
545 557

  
......
564 576
static void
565 577
krt_dump_attrs(rte *e)
566 578
{
567
  debug(" [m=%d,p=%d,t=%d]", e->u.krt.metric, e->u.krt.proto, e->u.krt.type);
579
  debug(" [m=%d,p=%d]", e->u.krt.metric, e->u.krt.proto);
568 580
}
569 581

  
570 582
#endif

Also available in: Unified diff