Revision f4a60a9b proto/static/static.c

View differences:

proto/static/static.c
54 54
p_igp_table(struct proto *p)
55 55
{
56 56
  struct static_config *cf = (void *) p->cf;
57
  return cf->igp_table ? cf->igp_table->table : p->table;
57
  return cf->igp_table ? cf->igp_table->table : p->main_channel->table;
58 58
}
59 59

  
60 60
static void
......
108 108
    }
109 109

  
110 110
  if (r->dest == RTDX_RECURSIVE)
111
    rta_set_recursive_next_hop(p->table, &a, p_igp_table(p), &r->via, &r->via);
111
    rta_set_recursive_next_hop(p->main_channel->table, &a, p_igp_table(p), &r->via, &r->via);
112 112

  
113 113
  /* We skip rta_lookup() here */
114 114

  
115
  n = net_get(p->table, r->net);
115
  n = net_get(p->main_channel->table, r->net);
116 116
  e = rte_get_temp(&a);
117 117
  e->net = n;
118 118
  e->pflags = 0;
......
136 136
    return;
137 137

  
138 138
  DBG("Removing static route %N via %I\n", r->net, r->via);
139
  n = net_find(p->table, r->net);
139
  n = net_find(p->main_channel->table, r->net);
140 140
  rte_update(p, n, NULL);
141 141
  r->installed = 0;
142 142
}
......
309 309
    r->installed = 0;
310 310
  }
311 311

  
312
  /* Handle failure during channel reconfigure */
313
  /* FIXME: This should be handled in a better way */
314
  cf = (void *) p->cf_new;
315
  if (cf)
316
  {
317
    WALK_LIST(r, cf->iface_routes)
318
      r->installed = 0;
319
    WALK_LIST(r, cf->other_routes)
320
      r->installed = 0;
321
  }
322

  
312 323
  return PS_DOWN;
313 324
}
314 325

  
......
450 461
  init_list(&c->other_routes);
451 462
}
452 463

  
464
static void
465
static_postconfig(struct proto_config *CF)
466
{
467
  struct static_config *cf = (void *) CF;
468
  struct static_route *r;
469

  
470
  if (EMPTY_LIST(CF->channels))
471
    cf_error("Channel not specified");
472

  
473

  
474
  WALK_LIST(r, cf->iface_routes)
475
    if (r->net->type != CF->net_type)
476
      cf_error("Route %N incompatible with channel type", r->net);
477

  
478
  WALK_LIST(r, cf->other_routes)
479
    if (r->net->type != CF->net_type)
480
      cf_error("Route %N incompatible with channel type", r->net);
481
}
482

  
483

  
453 484
static struct proto *
454
static_init(struct proto_config *c)
485
static_init(struct proto_config *CF)
455 486
{
456
  struct proto *p = proto_new(c, sizeof(struct proto));
487
  struct proto *P = proto_new(CF);
488
  // struct static_proto *p = (void *) P;
489
  // struct static_config *cf = (void *) CF;
457 490

  
458
  p->neigh_notify = static_neigh_notify;
459
  p->if_notify = static_if_notify;
460
  p->rte_mergable = static_rte_mergable;
491
  P->main_channel = proto_add_channel(P, proto_cf_main_channel(CF));
461 492

  
462
  return p;
493
  P->neigh_notify = static_neigh_notify;
494
  P->if_notify = static_if_notify;
495
  P->rte_mergable = static_rte_mergable;
496

  
497
  return P;
463 498
}
464 499

  
465 500
static inline int
......
543 578
}
544 579

  
545 580
static int
546
static_reconfigure(struct proto *p, struct proto_config *new)
581
static_reconfigure(struct proto *p, struct proto_config *CF)
547 582
{
548 583
  struct static_config *o = (void *) p->cf;
549
  struct static_config *n = (void *) new;
584
  struct static_config *n = (void *) CF;
550 585
  struct static_route *r;
551 586

  
552 587
  if (cf_igp_table(o) != cf_igp_table(n))
553 588
    return 0;
554 589

  
590
  if (!proto_configure_channel(p, &p->main_channel, proto_cf_main_channel(CF)))
591
    return 0;
592

  
555 593
  /* Delete all obsolete routes and reset neighbor entries */
556 594
  WALK_LIST(r, o->iface_routes)
557 595
    static_match(p, r, n);
......
617 655
  struct static_config *d = (struct static_config *) dest;
618 656
  struct static_config *s = (struct static_config *) src;
619 657

  
620
  /* Shallow copy of everything */
621
  proto_copy_rest(dest, src, sizeof(struct static_config));
622

  
623 658
  /* Copy route lists */
624 659
  static_copy_routes(&d->iface_routes, &s->iface_routes);
625 660
  static_copy_routes(&d->other_routes, &s->other_routes);
626 661
}
627 662

  
628

  
629 663
struct protocol proto_static = {
630 664
  .name =		"Static",
631 665
  .template =		"static%d",
632 666
  .preference =		DEF_PREF_STATIC,
667
  .channel_mask =	NB_ANY,
668
  .proto_size =		sizeof(struct proto),
633 669
  .config_size =	sizeof(struct static_config),
670
  .postconfig =		static_postconfig,
634 671
  .init =		static_init,
635 672
  .dump =		static_dump,
636 673
  .start =		static_start,

Also available in: Unified diff