Revision 094d2bdb proto/rip/rip.c

View differences:

proto/rip/rip.c
263 263
 * This part is responsible for any updates that come from network 
264 264
 */
265 265

  
266
static int rip_rte_better(struct rte *new, struct rte *old);
267

  
266 268
static void
267 269
rip_rte_update_if_better(rtable *tab, net *net, struct proto *p, rte *new)
268 270
{
269 271
  rte *old;
270 272

  
271
  old = rte_find(net, p);
272
  if (!old || p->rte_better(new, old) ||
273
  old = rte_find(net, p->main_source);
274
  if (!old || rip_rte_better(new, old) ||
273 275
      (ipa_equal(old->attrs->from, new->attrs->from) &&
274 276
      (old->u.rip.metric != new->u.rip.metric)) )
275
    rte_update(tab, net, p, p, new);
277
    rte_update(p, net, new);
276 278
  else
277 279
    rte_free(new);
278 280
}
......
295 297
  int pxlen;
296 298

  
297 299
  bzero(&A, sizeof(A));
298
  A.proto = p;
300
  A.src= p->main_source;
299 301
  A.source = RTS_RIP;
300 302
  A.scope = SCOPE_UNIVERSE;
301 303
  A.cast = RTC_UNICAST;
......
604 606
  add_head( &P->interfaces, NODE rif );
605 607
  CHK_MAGIC;
606 608

  
607
  rip_init_instance(p);
608

  
609 609
  DBG( "RIP: ...done\n");
610 610
  return PS_UP;
611 611
}
612 612

  
613
static struct proto *
614
rip_init(struct proto_config *cfg)
615
{
616
  struct proto *p = proto_new(cfg, sizeof(struct rip_proto));
617

  
618
  return p;
619
}
620

  
621 613
static void
622 614
rip_dump(struct proto *p)
623 615
{
......
843 835
static int
844 836
rip_import_control(struct proto *p, struct rte **rt, struct ea_list **attrs, struct linpool *pool)
845 837
{
846
  if ((*rt)->attrs->proto == p)	/* My own must not be touched */
838
  if ((*rt)->attrs->src->proto == p)	/* My own must not be touched */
847 839
    return 1;
848 840

  
849 841
  if ((*rt)->attrs->source != RTS_RIP) {
......
895 887
    if (e->metric > P_CF->infinity)
896 888
      e->metric = P_CF->infinity;
897 889

  
898
    if (new->attrs->proto == p)
890
    if (new->attrs->src->proto == p)
899 891
      e->whotoldme = new->attrs->from;
900 892

  
901 893
    if (!e->metric)	/* That's okay: this way user can set his own value for external
......
917 909
static int
918 910
rip_rte_better(struct rte *new, struct rte *old)
919 911
{
920
  struct proto *p = new->attrs->proto;
912
  struct proto *p = new->attrs->src->proto;
921 913

  
922 914
  if (ipa_equal(old->attrs->from, new->attrs->from))
923 915
    return 1;
......
928 920
  if (old->u.rip.metric > new->u.rip.metric)
929 921
    return 1;
930 922

  
931
  if (old->attrs->proto == new->attrs->proto)		/* This does not make much sense for different protocols */
923
  if (old->attrs->src->proto == new->attrs->src->proto)		/* This does not make much sense for different protocols */
932 924
    if ((old->u.rip.metric == new->u.rip.metric) &&
933 925
	((now - old->lastmod) > (P_CF->timeout_time / 2)))
934 926
      return 1;
......
944 936
static void
945 937
rip_rte_insert(net *net UNUSED, rte *rte)
946 938
{
947
  struct proto *p = rte->attrs->proto;
939
  struct proto *p = rte->attrs->src->proto;
948 940
  CHK_MAGIC;
949 941
  DBG( "rip_rte_insert: %p\n", rte );
950 942
  add_head( &P->garbage, &rte->u.rip.garbage );
......
962 954
  rem_node( &rte->u.rip.garbage );
963 955
}
964 956

  
965
void
966
rip_init_instance(struct proto *p)
957
static struct proto *
958
rip_init(struct proto_config *cfg)
967 959
{
960
  struct proto *p = proto_new(cfg, sizeof(struct rip_proto));
961

  
968 962
  p->accept_ra_types = RA_OPTIMAL;
969 963
  p->if_notify = rip_if_notify;
970 964
  p->rt_notify = rip_rt_notify;
......
975 969
  p->rte_same = rip_rte_same;
976 970
  p->rte_insert = rip_rte_insert;
977 971
  p->rte_remove = rip_rte_remove;
972

  
973
  return p;
978 974
}
979 975

  
980 976
void

Also available in: Unified diff