Revision 600998fc nest/route.h

View differences:

nest/route.h
65 65
  fib_init_fn init;			/* Constructor */
66 66
};
67 67

  
68
static inline void * fib_node_to_user(struct fib *f, struct fib_node *e)
69
{ return e ? (void *) ((char *) e - f->node_offset) : NULL; }
70

  
71
static inline struct fib_node * fib_user_to_node(struct fib *f, void *e)
72
{ return e ? (void *) ((char *) e + f->node_offset) : NULL; }
73

  
68 74
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 75
void *fib_find(struct fib *, const net_addr *);	/* Find or return NULL if doesn't exist */
70 76
void *fib_get(struct fib *, const net_addr *); 	/* Find or create new if nonexistent */
......
78 84
void fit_put(struct fib_iterator *, struct fib_node *);
79 85
void fit_put_next(struct fib *f, struct fib_iterator *i, struct fib_node *n, uint hpos);
80 86

  
81
/* XXXX: return user entries */
82
#define FIB_WALK(fib, z) do {					\
83
	struct fib_node *z, **ff = (fib)->hash_table;		\
84
	uint count = (fib)->hash_size;				\
85
	while (count--)						\
86
	  for(z = *ff++; z; z=z->next)
87

  
88
#define FIB_WALK(fib, type, z) do {				\
89
	struct fib_node *fn_, **ff_ = (fib)->hash_table;	\
90
	uint count_ = (fib)->hash_size;				\
91
	type *z;						\
92
	while (count_--)					\
93
	  for (fn_ = *ff_++; z = fib_node_to_user(fib, fn_); fn_=fn_->next)
87 94

  
88 95
#define FIB_WALK_END } while (0)
89 96

  
90 97
#define FIB_ITERATE_INIT(it, fib) fit_init(it, fib)
91 98

  
92
#define FIB_ITERATE_START(fib, it, z) do {			\
93
	struct fib_node *z = fit_get(fib, it);			\
94
	uint count = (fib)->hash_size;				\
95
	uint hpos = (it)->hash;					\
99
#define FIB_ITERATE_START(fib, it, type, z) do {		\
100
	struct fib_node *fn_ = fit_get(fib, it);		\
101
	uint count_ = (fib)->hash_size;				\
102
	uint hpos_ = (it)->hash;				\
103
	type *z;						\
96 104
	for(;;) {						\
97
	  if (!z)						\
105
	  if (!fn_)						\
98 106
            {							\
99
	       if (++hpos >= count)				\
107
	       if (++hpos_ >= count_)				\
100 108
		 break;						\
101
	       z = (fib)->hash_table[hpos];			\
109
	       fn_ = (fib)->hash_table[hpos_];			\
102 110
	       continue;					\
103
	    }
111
	    }							\
112
	  z = fib_node_to_user(fib, fn_);
104 113

  
105
#define FIB_ITERATE_END(z) z = z->next; } } while(0)
114
#define FIB_ITERATE_END fn_ = fn_->next; } } while(0)
106 115

  
107
#define FIB_ITERATE_PUT(it, z) fit_put(it, z)
116
#define FIB_ITERATE_PUT(it) fit_put(it, fn_)
108 117

  
109
#define FIB_ITERATE_PUT_NEXT(it, fib, z) fit_put_next(fib, it, z, hpos)
118
#define FIB_ITERATE_PUT_NEXT(it, fib) fit_put_next(fib, it, fn_, hpos_)
110 119

  
111 120
#define FIB_ITERATE_UNLINK(it, fib) fit_get(fib, it)
112 121

  

Also available in: Unified diff