• Home
  • Raw
  • Download

Lines Matching refs:list

37 static struct tlpm_node *tlpm_match(struct tlpm_node *list,
41 static struct tlpm_node *tlpm_add(struct tlpm_node *list, in tlpm_add() argument
51 node = tlpm_match(list, key, n_bits); in tlpm_add()
54 return list; in tlpm_add()
62 node->next = list; in tlpm_add()
69 static void tlpm_clear(struct tlpm_node *list) in tlpm_clear() argument
75 while ((node = list)) { in tlpm_clear()
76 list = list->next; in tlpm_clear()
81 static struct tlpm_node *tlpm_match(struct tlpm_node *list, in tlpm_match() argument
94 for ( ; list; list = list->next) { in tlpm_match()
95 for (i = 0; i < n_bits && i < list->n_bits; ++i) { in tlpm_match()
97 (list->key[i / 8] & (1 << (7 - i % 8)))) in tlpm_match()
101 if (i >= list->n_bits) { in tlpm_match()
103 best = list; in tlpm_match()
110 static struct tlpm_node *tlpm_delete(struct tlpm_node *list, in tlpm_delete() argument
114 struct tlpm_node *best = tlpm_match(list, key, n_bits); in tlpm_delete()
118 return list; in tlpm_delete()
120 if (best == list) { in tlpm_delete()
126 for (node = list; node; node = node->next) { in tlpm_delete()
130 return list; in tlpm_delete()
135 return list; in tlpm_delete()
140 struct tlpm_node *list = NULL, *t1, *t2; in test_lpm_basic() local
144 assert(!tlpm_match(list, (uint8_t[]){ 0xff }, 8)); in test_lpm_basic()
146 t1 = list = tlpm_add(list, (uint8_t[]){ 0xff }, 8); in test_lpm_basic()
147 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff }, 8)); in test_lpm_basic()
148 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 16)); in test_lpm_basic()
149 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0x00 }, 16)); in test_lpm_basic()
150 assert(!tlpm_match(list, (uint8_t[]){ 0x7f }, 8)); in test_lpm_basic()
151 assert(!tlpm_match(list, (uint8_t[]){ 0xfe }, 8)); in test_lpm_basic()
152 assert(!tlpm_match(list, (uint8_t[]){ 0xff }, 7)); in test_lpm_basic()
154 t2 = list = tlpm_add(list, (uint8_t[]){ 0xff, 0xff }, 16); in test_lpm_basic()
155 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff }, 8)); in test_lpm_basic()
156 assert(t2 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 16)); in test_lpm_basic()
157 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 15)); in test_lpm_basic()
158 assert(!tlpm_match(list, (uint8_t[]){ 0x7f, 0xff }, 16)); in test_lpm_basic()
160 list = tlpm_delete(list, (uint8_t[]){ 0xff, 0xff }, 16); in test_lpm_basic()
161 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff }, 8)); in test_lpm_basic()
162 assert(t1 == tlpm_match(list, (uint8_t[]){ 0xff, 0xff }, 16)); in test_lpm_basic()
164 list = tlpm_delete(list, (uint8_t[]){ 0xff }, 8); in test_lpm_basic()
165 assert(!tlpm_match(list, (uint8_t[]){ 0xff }, 8)); in test_lpm_basic()
167 tlpm_clear(list); in test_lpm_basic()
212 struct tlpm_node *t, *list = NULL; in test_lpm_map() local
248 list = tlpm_add(list, value, value[keysize]); in test_lpm_map()
260 t = tlpm_match(list, data, 8 * keysize); in test_lpm_map()
283 for (i = 0, t = list; t; i++, t = t->next) in test_lpm_map()
286 key->prefixlen = list->n_bits; in test_lpm_map()
287 memcpy(key->data, list->key, keysize); in test_lpm_map()
290 list = tlpm_delete(list, list->key, list->n_bits); in test_lpm_map()
291 assert(list); in test_lpm_map()
297 t = tlpm_match(list, data, 8 * keysize); in test_lpm_map()
315 tlpm_clear(list); in test_lpm_map()