Revision 0f7d5b1a

View differences:

nest/route.h
66 66
};
67 67

  
68 68
void fib_init(struct fib *f, pool *p, uint addr_type, uint node_size, uint node_offset, uint hash_order, fib_init_fn init);
69
void *fib_find(struct fib *, net_addr *);	/* Find or return NULL if doesn't exist */
70
void *fib_get(struct fib *, net_addr *); 	/* Find or create new if nonexistent */
71
void *fib_route(struct fib *, net_addr *);	/* Longest-match routing lookup */
69
void *fib_find(struct fib *, const net_addr *);	/* Find or return NULL if doesn't exist */
70
void *fib_get(struct fib *, const net_addr *); 	/* Find or create new if nonexistent */
71
void *fib_route(struct fib *, const net_addr *); /* Longest-match routing lookup */
72 72
void fib_delete(struct fib *, void *);	/* Remove fib entry */
73 73
void fib_free(struct fib *);		/* Destroy the fib */
74 74
void fib_check(struct fib *);		/* Consistency check for debugging */
nest/rt-fib.c
81 81

  
82 82

  
83 83
static u32
84
fib_hash(struct fib *f, net_addr *a);
84
fib_hash(struct fib *f, const net_addr *a);
85 85

  
86 86
/**
87 87
 * fib_init - initialize a new FIB
......
158 158
  fib_ht_free(m);
159 159
}
160 160

  
161
#define CAST(t) (net_addr_##t *)
161
#define CAST(t) (const net_addr_##t *)
162
#define CAST2(t) (net_addr_##t *)
162 163

  
163 164
#define FIB_HASH(f,a,t) (net_hash_##t(CAST(t) a) >> f->hash_shift)
164 165

  
......
179 180
  while ((g = *ee) && (net_hash_##t(CAST(t) g->addr) < h))		\
180 181
    ee = &g->next;							\
181 182
									\
182
  net_copy_##t(CAST(t) e->addr, CAST(t) a);				\
183
  net_copy_##t(CAST2(t) e->addr, CAST(t) a);				\
183 184
  e->next = *ee;							\
184 185
  *ee = e;								\
185 186
  })
186 187

  
187 188

  
188 189
static u32
189
fib_hash(struct fib *f, net_addr *a)
190
fib_hash(struct fib *f, const net_addr *a)
190 191
{
191 192
  switch (f->addr_type)
192 193
  {
......
198 199
  }
199 200
}
200 201

  
202
/**
203
 * fib_find - search for FIB node by prefix
204
 * @f: FIB to search in
205
 * @n: network address
206
 *
207
 * Search for a FIB node corresponding to the given prefix, return
208
 * a pointer to it or %NULL if no such node exists.
209
 */
201 210
void *
202
fib_find(struct fib *f, net_addr *a)
211
fib_find(struct fib *f, const net_addr *a)
203 212
{
204 213
  ASSERT(f->addr_type == a->type);
205 214

  
......
214 223
}
215 224

  
216 225
static void
217
fib_insert(struct fib *f, net_addr *a, struct fib_node *e)
226
fib_insert(struct fib *f, const net_addr *a, struct fib_node *e)
218 227
{
219 228
  switch (f->addr_type)
220 229
  {
......
227 236
}
228 237

  
229 238

  
230

  
231
/**
232
 * fib_find - search for FIB node by prefix
233
 * @f: FIB to search in
234
 * @a: pointer to IP address of the prefix
235
 * @len: prefix length
236
 *
237
 * Search for a FIB node corresponding to the given prefix, return
238
 * a pointer to it or %NULL if no such node exists.
239
 */
240
/*
241
void *
242
fib_find(struct fib *f, net_addr *a)
243
{
244
  struct fib_node *e = f->hash_table[fib_hash(f, a)];
245

  
246
  while (e && (e->pxlen != len || !ipa_equal(*a, e->prefix)))
247
    e = e->next;
248
  return e;
249
}
250
*/
251

  
252 239
/**
253 240
 * fib_get - find or create a FIB node
254 241
 * @f: FIB to work with
255
 * @a: pointer to IP address of the prefix
256
 * @len: prefix length
242
 * @n: network address
257 243
 *
258 244
 * Search for a FIB node corresponding to the given prefix and
259 245
 * return a pointer to it. If no such node exists, create it.
260 246
 */
261 247
void *
262
fib_get(struct fib *f, net_addr *a)
248
fib_get(struct fib *f, const net_addr *a)
263 249
{
264 250
  char *b = fib_find(f, a);
265 251
  if (b)
......
286 272
  return b;
287 273
}
288 274

  
275
static void *
276
fib_route_ip4(struct fib *f, const net_addr *n0)
277
{
278
  net_addr net;
279
  net_addr_ip4 *n = (net_addr_ip4 *) &net;
280
  void *b;
281

  
282
  net_copy(&net, n0);
283
  while (!(b = fib_find(f, &net)) && (n->pxlen > 0))
284
  {
285
    n->pxlen--;
286
    ip4_clrbit(&n->prefix, n->pxlen);
287
  }
288

  
289
  return b;
290
}
291

  
292
static void *
293
fib_route_ip6(struct fib *f, const net_addr *n0)
294
{
295
  net_addr net;
296
  net_addr_ip6 *n = (net_addr_ip6 *) &net;
297
  void *b;
298

  
299
  net_copy(&net, n0);
300
  while (!(b = fib_find(f, &net)) && (n->pxlen > 0))
301
  {
302
    n->pxlen--;
303
    ip6_clrbit(&n->prefix, n->pxlen);
304
  }
305

  
306
  return b;
307
}
308

  
289 309
/**
290 310
 * fib_route - CIDR routing lookup
291 311
 * @f: FIB to search in
292
 * @a: pointer to IP address of the prefix
293
 * @len: prefix length
312
 * @n: network address
294 313
 *
295 314
 * Search for a FIB node with longest prefix matching the given
296 315
 * network, that is a node which a CIDR router would use for routing
297 316
 * that network.
298 317
 */
299
/*
300 318
void *
301
fib_route(struct fib *f, ip_addr a, int len)
319
fib_route(struct fib *f, const net_addr *n)
302 320
{
303
  ip_addr a0;
304
  void *t;
321
  ASSERT(f->addr_type == n->type);
305 322

  
306
  while (len >= 0)
307
    {
308
      a0 = ipa_and(a, ipa_mkmask(len));
309
      t = fib_find(f, &a0, len);
310
      if (t)
311
	return t;
312
      len--;
313
    }
314
  return NULL;
323
  switch (n->type)
324
  {
325
  case NET_IP4:
326
  case NET_VPN4:
327
    return fib_route_ip4(f, n);
328

  
329
  case NET_IP6:
330
  case NET_VPN6:
331
    return fib_route_ip6(f, n);
332

  
333
  default:
334
    return NULL;
335
  }
315 336
}
316
*/
317 337

  
318 338
static inline void
319 339
fib_merge_readers(struct fib_iterator *i, struct fib_node *to)

Also available in: Unified diff