Revision 153f02da sysdep/unix/krt.c

View differences:

sysdep/unix/krt.c
89 89
static timer *kif_scan_timer;
90 90
static bird_clock_t kif_last_shot;
91 91

  
92
static struct kif_iface_config kif_default_iface = {};
93

  
94
struct kif_iface_config *
95
kif_get_iface_config(struct iface *iface)
96
{
97
  struct kif_config *cf = (void *) (kif_proto->p.cf);
98
  struct kif_iface_config *ic = (void *) iface_patt_find(&cf->iface_list, iface, NULL);
99
  return ic ?: &kif_default_iface;
100
}
101

  
92 102
static void
93 103
kif_scan(timer *t)
94 104
{
......
116 126
    tm_start(kif_scan_timer, 1);
117 127
}
118 128

  
119
static inline int
120
prefer_addr(struct ifa *a, struct ifa *b)
121
{
122
  int sa = a->scope > SCOPE_LINK;
123
  int sb = b->scope > SCOPE_LINK;
124

  
125
  if (sa < sb)
126
    return 0;
127
  else if (sa > sb)
128
    return 1;
129
  else
130
    return ipa_compare(a->ip, b->ip) < 0;
131
}
132

  
133
static inline struct ifa *
134
find_preferred_ifa(struct iface *i, const net_addr *n)
135
{
136
  struct ifa *a, *b = NULL;
137

  
138
  WALK_LIST(a, i->addrs)
139
    {
140
      if (!(a->flags & IA_SECONDARY) &&
141
	  (!n || ipa_in_netX(a->ip, n)) &&
142
	  (!b || prefer_addr(a, b)))
143
	b = a;
144
    }
145

  
146
  return b;
147
}
148

  
149
struct ifa *
150
kif_choose_primary(struct iface *i)
151
{
152
  struct kif_config *cf = (struct kif_config *) (kif_proto->p.cf);
153
  struct kif_primary_item *it;
154
  struct ifa *a;
155

  
156
  WALK_LIST(it, cf->primary)
157
    {
158
      if (!it->pattern || patmatch(it->pattern, i->name))
159
	if (a = find_preferred_ifa(i, &it->addr))
160
	  return a;
161
    }
162

  
163
  if (a = kif_get_primary_ip(i))
164
    return a;
165

  
166
  return find_preferred_ifa(i, NULL);
167
}
168

  
169

  
170 129
static struct proto *
171 130
kif_init(struct proto_config *c)
172 131
{
......
224 183
      tm_start(kif_scan_timer, n->scan_time);
225 184
    }
226 185

  
227
  if (!EMPTY_LIST(o->primary) || !EMPTY_LIST(n->primary))
186
  if (!EMPTY_LIST(o->iface_list) || !EMPTY_LIST(n->iface_list))
228 187
    {
229 188
      /* This is hack, we have to update a configuration
230 189
       * to the new value just now, because it is used
231
       * for recalculation of primary addresses.
190
       * for recalculation of preferred addresses.
232 191
       */
233 192
      p->cf = new;
234 193

  
235
      ifa_recalc_all_primary_addresses();
194
      if_recalc_all_preferred_addresses();
236 195
    }
237 196

  
238 197
  return 1;
......
254 213

  
255 214
  kif_cf = (struct kif_config *) proto_config_new(&proto_unix_iface, class);
256 215
  kif_cf->scan_time = 60;
257
  init_list(&kif_cf->primary);
216
  init_list(&kif_cf->iface_list);
258 217

  
259 218
  kif_sys_init_config(kif_cf);
260 219
  return (struct proto_config *) kif_cf;
......
266 225
  struct kif_config *d = (struct kif_config *) dest;
267 226
  struct kif_config *s = (struct kif_config *) src;
268 227

  
269
  /* Copy primary addr list */
270
  cfg_copy_list(&d->primary, &s->primary, sizeof(struct kif_primary_item));
228
  /* Copy interface config list */
229
  cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct kif_iface_config));
271 230

  
272 231
  /* Fix sysdep parts */
273 232
  kif_sys_copy_config(d, s);
274 233
}
275 234

  
276

  
277 235
struct protocol proto_unix_iface = {
278 236
  .name = 		"Device",
279 237
  .template = 		"device%d",

Also available in: Unified diff