Revision 7e95c05d nest/rt-attr.c

View differences:

nest/rt-attr.c
57 57
pool *rta_pool;
58 58

  
59 59
static slab *rta_slab;
60
static slab *mpnh_slab;
60 61

  
61 62
struct protocol *attr_class_to_protocol[EAP_MAX];
62 63

  
64
static inline unsigned int
65
mpnh_hash(struct mpnh *x)
66
{
67
  unsigned int h = 0;
68
  for (; x; x = x->next)
69
    h ^= ipa_hash(x->gw);
70

  
71
  return h;
72
}
73

  
74
int
75
mpnh__same(struct mpnh *x, struct mpnh *y)
76
{
77
  for (; x && y; x = x->next, y = y->next)
78
    if (!ipa_equal(x->gw, y->gw) || (x->iface != y->iface) || (x->weight != y->weight))
79
      return 0;
80

  
81
  return x == y;
82
}
83

  
84
static struct mpnh *
85
mpnh_copy(struct mpnh *o)
86
{
87
  struct mpnh *first = NULL;
88
  struct mpnh **last = &first;
89

  
90
  for (; o; o = o->next)
91
    {
92
      struct mpnh *n = sl_alloc(mpnh_slab);
93
      n->gw = o->gw;
94
      n->iface = o->iface;
95
      n->next = NULL;
96
      n->weight = o->weight;
97

  
98
      *last = n;
99
      last = &(n->next);
100
    }
101

  
102
  return first;
103
}
104

  
105
static void
106
mpnh_free(struct mpnh *o)
107
{
108
  struct mpnh *n;
109

  
110
  while (o)
111
    {
112
      n = o->next;
113
      sl_free(mpnh_slab, o);
114
      o = n;
115
    }
116
}
117

  
118

  
63 119
/*
64 120
 *	Extended Attributes
65 121
 */
......
587 643
static inline unsigned int
588 644
rta_hash(rta *a)
589 645
{
590
  return (a->proto->hash_key ^ ipa_hash(a->gw) ^ ea_hash(a->eattrs)) & 0xffff;
646
  return (a->proto->hash_key ^ ipa_hash(a->gw) ^
647
	  mpnh_hash(a->nexthops) ^ ea_hash(a->eattrs)) & 0xffff;
591 648
}
592 649

  
593 650
static inline int
......
604 661
	  ipa_equal(x->from, y->from) &&
605 662
	  x->iface == y->iface &&
606 663
	  x->hostentry == y->hostentry &&
664
	  mpnh_same(x->nexthops, y->nexthops) &&
607 665
	  ea_same(x->eattrs, y->eattrs));
608 666
}
609 667

  
......
614 672

  
615 673
  memcpy(r, o, sizeof(rta));
616 674
  r->uc = 1;
675
  r->nexthops = mpnh_copy(o->nexthops);
617 676
  r->eattrs = ea_list_copy(o->eattrs);
618 677
  return r;
619 678
}
......
707 766
    a->next->pprev = a->pprev;
708 767
  a->aflags = 0;		/* Poison the entry */
709 768
  rt_unlock_hostentry(a->hostentry);
769
  mpnh_free(a->nexthops);
710 770
  ea_free(a->eattrs);
711 771
  sl_free(rta_slab, a);
712 772
}
......
798 858
{
799 859
  rta_pool = rp_new(&root_pool, "Attributes");
800 860
  rta_slab = sl_new(rta_pool, sizeof(rta));
861
  mpnh_slab = sl_new(rta_pool, sizeof(struct mpnh));
801 862
  rta_alloc_hash();
802 863
}
803 864

  

Also available in: Unified diff