5 #ifndef __CNET_FIB_INFO_H
6 #define __CNET_FIB_INFO_H
15 #include <sys/queue.h>
16 #include <bsd/sys/queue.h>
26 typedef struct fib_info {
46 static inline uint32_t
49 uint32_t obj_idx = UINT32_MAX;
52 obj_idx = (idx & ((1UL << fi->index_shift) - 1));
71 uint32_t idx, prev_idx;
74 idx = prev_idx = fi->index;
77 prev_idx = (prev_idx & fi->mask);
78 while (fi->idx2obj[idx] && (idx != prev_idx)) {
80 idx = (idx & fi->mask);
83 if (idx == prev_idx) {
88 fi->idx2obj[idx] = obj;
114 if (idx < fi->objcnt) {
115 obj = fi->idx2obj[idx];
117 fi->idx2obj[idx] = NULL;
156 static inline fib_info_t *
161 if (!fib || objcnt == 0 || index_shift == 0)
164 fi = calloc(1,
sizeof(fib_info_t));
168 fi->mask = fi->objcnt - 1;
169 fi->index_shift = index_shift;
172 fi->idx2obj = calloc(fi->objcnt,
sizeof(
void *));
200 if (idx >= fi->objcnt)
203 return fi->idx2obj[idx];
221 if (fi && (idx < fi->objcnt))
235 static inline struct cne_fib *
238 return (fi) ? fi->fib : NULL;
241 typedef int (*fib_func_t)(
void *obj,
void *arg);
259 for (uint32_t i = 0; i < fi->objcnt; i++) {
262 if (obj && (func(obj, arg) < 0))
295 memset(objs, 0,
sizeof(
void *) * n);
297 for (i = 0, k = 0; i < n; i++) {
349 if (!fi || !ip || !idxs)
static uint32_t cne_align32pow2(uint32_t x)
int cne_fib_lookup_bulk(struct cne_fib *fib, uint32_t *ips, uint64_t *next_hops, int n)
void cne_fib_free(struct cne_fib *fib)
static void cne_rwlock_write_unlock(cne_rwlock_t *rwl)
static void cne_rwlock_init(cne_rwlock_t *rwl)
static void cne_rwlock_write_lock(cne_rwlock_t *rwl)
static int fib_info_get(fib_info_t *fi, uint64_t *idxs, void **objs, int n)
static void * fib_info_object_get(fib_info_t *fi, uint32_t idx)
static int fib_info_alloc(fib_info_t *fi, void *obj)
static int fib_info_foreach(fib_info_t *fi, fib_func_t func, void *arg)
static void * fib_info_free(fib_info_t *fi, uint32_t idx)
static fib_info_t * fib_info_create(struct cne_fib *fib, uint32_t objcnt, uint32_t index_shift)
static uint32_t fi_obj_index(fib_info_t *fi, uint32_t idx)
static int fib_info_index_valid(fib_info_t *fi, uint32_t idx)
static int fib_info_lookup(fib_info_t *fi, uint32_t *ip, void **objs, int n)
static struct cne_fib * fib_info_get_fib(fib_info_t *fi)
static void fib_info_destroy(fib_info_t *fi)
static int fib_info_lookup_index(fib_info_t *fi, uint32_t *ip, uint64_t *idxs, int n)