Lines Matching refs:crecp
41 static void cache_free(struct crec* crecp);
42 static void cache_unlink(struct crec* crecp);
43 static void cache_link(struct crec* crecp);
45 static void cache_hash(struct crec* crecp);
48 struct crec* crecp; in cache_init() local
56 crecp = safe_malloc(daemon->cachesize * sizeof(struct crec)); in cache_init()
58 for (i = 0; i < daemon->cachesize; i++, crecp++) { in cache_init()
59 cache_link(crecp); in cache_init()
60 crecp->flags = 0; in cache_init()
61 crecp->uid = uid++; in cache_init()
118 static void cache_hash(struct crec* crecp) { in cache_hash() argument
124 struct crec** up = hash_bucket(cache_get_name(crecp)); in cache_hash()
126 if (!(crecp->flags & F_REVERSE)) { in cache_hash()
129 if (crecp->flags & F_IMMORTAL) in cache_hash()
132 crecp->hash_next = *up; in cache_hash()
133 *up = crecp; in cache_hash()
136 static void cache_free(struct crec* crecp) { in cache_free() argument
137 crecp->flags &= ~F_FORWARD; in cache_free()
138 crecp->flags &= ~F_REVERSE; in cache_free()
139 crecp->uid = uid++; /* invalidate CNAMES pointing to this. */ in cache_free()
142 cache_tail->next = crecp; in cache_free()
144 cache_head = crecp; in cache_free()
145 crecp->prev = cache_tail; in cache_free()
146 crecp->next = NULL; in cache_free()
147 cache_tail = crecp; in cache_free()
150 if (crecp->flags & F_BIGNAME) { in cache_free()
151 crecp->name.bname->next = big_free; in cache_free()
152 big_free = crecp->name.bname; in cache_free()
153 crecp->flags &= ~F_BIGNAME; in cache_free()
158 static void cache_link(struct crec* crecp) { in cache_link() argument
160 cache_head->prev = crecp; in cache_link()
161 crecp->next = cache_head; in cache_link()
162 crecp->prev = NULL; in cache_link()
163 cache_head = crecp; in cache_link()
164 if (!cache_tail) cache_tail = crecp; in cache_link()
168 static void cache_unlink(struct crec* crecp) { in cache_unlink() argument
169 if (crecp->prev) in cache_unlink()
170 crecp->prev->next = crecp->next; in cache_unlink()
172 cache_head = crecp->next; in cache_unlink()
174 if (crecp->next) in cache_unlink()
175 crecp->next->prev = crecp->prev; in cache_unlink()
177 cache_tail = crecp->prev; in cache_unlink()
180 char* cache_get_name(struct crec* crecp) { in cache_get_name() argument
181 if (crecp->flags & F_BIGNAME) in cache_get_name()
182 return crecp->name.bname->name; in cache_get_name()
183 else if (crecp->flags & (F_DHCP | F_CONFIG)) in cache_get_name()
184 return crecp->name.namep; in cache_get_name()
186 return crecp->name.sname; in cache_get_name()
189 static int is_outdated_cname_pointer(struct crec* crecp) { in is_outdated_cname_pointer() argument
190 if (!(crecp->flags & F_CNAME)) return 0; in is_outdated_cname_pointer()
192 if (crecp->addr.cname.cache && crecp->addr.cname.uid == crecp->addr.cname.cache->uid) return 0; in is_outdated_cname_pointer()
197 static int is_expired(time_t now, struct crec* crecp) { in is_expired() argument
198 if (crecp->flags & F_IMMORTAL) return 0; in is_expired()
200 if (difftime(now, crecp->ttd) < 0) return 0; in is_expired()
220 struct crec *crecp, **up; in cache_scan_free() local
223 for (up = hash_bucket(name), crecp = *up; crecp; crecp = crecp->hash_next) in cache_scan_free()
224 if (is_expired(now, crecp) || is_outdated_cname_pointer(crecp)) { in cache_scan_free()
225 *up = crecp->hash_next; in cache_scan_free()
226 if (!(crecp->flags & (F_HOSTS | F_DHCP))) { in cache_scan_free()
227 cache_unlink(crecp); in cache_scan_free()
228 cache_free(crecp); in cache_scan_free()
230 } else if ((crecp->flags & F_FORWARD) && in cache_scan_free()
231 ((flags & crecp->flags & (F_IPV4 | F_IPV6)) || in cache_scan_free()
232 ((crecp->flags | flags) & F_CNAME)) && in cache_scan_free()
233 hostname_isequal(cache_get_name(crecp), name)) { in cache_scan_free()
234 if (crecp->flags & (F_HOSTS | F_DHCP)) return 0; in cache_scan_free()
235 *up = crecp->hash_next; in cache_scan_free()
236 cache_unlink(crecp); in cache_scan_free()
237 cache_free(crecp); in cache_scan_free()
239 up = &crecp->hash_next; in cache_scan_free()
248 for (crecp = hash_table[i], up = &hash_table[i]; in cache_scan_free()
249 crecp && ((crecp->flags & F_REVERSE) || !(crecp->flags & F_IMMORTAL)); in cache_scan_free()
250 crecp = crecp->hash_next) in cache_scan_free()
251 if (is_expired(now, crecp)) { in cache_scan_free()
252 *up = crecp->hash_next; in cache_scan_free()
253 if (!(crecp->flags & (F_HOSTS | F_DHCP))) { in cache_scan_free()
254 cache_unlink(crecp); in cache_scan_free()
255 cache_free(crecp); in cache_scan_free()
257 } else if (!(crecp->flags & (F_HOSTS | F_DHCP)) && in cache_scan_free()
258 (flags & crecp->flags & F_REVERSE) && in cache_scan_free()
259 (flags & crecp->flags & (F_IPV4 | F_IPV6)) && in cache_scan_free()
260 memcmp(&crecp->addr.addr, addr, addrlen) == 0) { in cache_scan_free()
261 *up = crecp->hash_next; in cache_scan_free()
262 cache_unlink(crecp); in cache_scan_free()
263 cache_free(crecp); in cache_scan_free()
265 up = &crecp->hash_next; in cache_scan_free()
409 struct crec* cache_find_by_name(struct crec* crecp, char* name, time_t now, unsigned short prot) { in cache_find_by_name() argument
412 if (crecp) /* iterating */ in cache_find_by_name()
413 ans = crecp->next; in cache_find_by_name()
420 for (up = hash_bucket(name), crecp = *up; crecp; crecp = next) { in cache_find_by_name()
421 next = crecp->hash_next; in cache_find_by_name()
423 if (!is_expired(now, crecp) && !is_outdated_cname_pointer(crecp)) { in cache_find_by_name()
424 if ((crecp->flags & F_FORWARD) && (crecp->flags & prot) && in cache_find_by_name()
425 hostname_isequal(cache_get_name(crecp), name)) { in cache_find_by_name()
426 if (crecp->flags & (F_HOSTS | F_DHCP)) { in cache_find_by_name()
427 *chainp = crecp; in cache_find_by_name()
428 chainp = &crecp->next; in cache_find_by_name()
430 cache_unlink(crecp); in cache_find_by_name()
431 cache_link(crecp); in cache_find_by_name()
439 if (insert && (crecp->flags & (F_REVERSE | F_IMMORTAL)) == ins_flags) { in cache_find_by_name()
440 *up = crecp->hash_next; in cache_find_by_name()
441 crecp->hash_next = *insert; in cache_find_by_name()
442 *insert = crecp; in cache_find_by_name()
443 insert = &crecp->hash_next; in cache_find_by_name()
447 ins_flags = crecp->flags & (F_REVERSE | F_IMMORTAL); in cache_find_by_name()
449 up = &crecp->hash_next; in cache_find_by_name()
453 up = &crecp->hash_next; in cache_find_by_name()
456 *up = crecp->hash_next; in cache_find_by_name()
457 if (!(crecp->flags & (F_HOSTS | F_DHCP))) { in cache_find_by_name()
458 cache_unlink(crecp); in cache_find_by_name()
459 cache_free(crecp); in cache_find_by_name()
474 struct crec* cache_find_by_addr(struct crec* crecp, struct all_addr* addr, time_t now, in cache_find_by_addr() argument
483 if (crecp) /* iterating */ in cache_find_by_addr()
484 ans = crecp->next; in cache_find_by_addr()
494 for (crecp = hash_table[i], up = &hash_table[i]; crecp && (crecp->flags & F_REVERSE); in cache_find_by_addr()
495 crecp = crecp->hash_next) in cache_find_by_addr()
496 if (!is_expired(now, crecp)) { in cache_find_by_addr()
497 if ((crecp->flags & prot) && memcmp(&crecp->addr.addr, addr, addrlen) == 0) { in cache_find_by_addr()
498 if (crecp->flags & (F_HOSTS | F_DHCP)) { in cache_find_by_addr()
499 *chainp = crecp; in cache_find_by_addr()
500 chainp = &crecp->next; in cache_find_by_addr()
502 cache_unlink(crecp); in cache_find_by_addr()
503 cache_link(crecp); in cache_find_by_addr()
506 up = &crecp->hash_next; in cache_find_by_addr()
508 *up = crecp->hash_next; in cache_find_by_addr()
509 if (!(crecp->flags & (F_HOSTS | F_DHCP))) { in cache_find_by_addr()
510 cache_unlink(crecp); in cache_find_by_addr()
511 cache_free(crecp); in cache_find_by_addr()