Lines Matching defs:crecp
67 static void cache_free(struct crec *crecp);
68 static void cache_unlink(struct crec *crecp);
69 static void cache_link(struct crec *crecp);
71 static void cache_hash(struct crec *crecp);
75 struct crec *crecp;
85 crecp = safe_malloc(daemon->cachesize*sizeof(struct crec));
87 for (i=0; i < daemon->cachesize; i++, crecp++)
89 cache_link(crecp);
90 crecp->flags = 0;
91 crecp->uid = uid++;
154 static void cache_hash(struct crec *crecp)
161 struct crec **up = hash_bucket(cache_get_name(crecp));
163 if (!(crecp->flags & F_REVERSE))
168 if (crecp->flags & F_IMMORTAL)
172 crecp->hash_next = *up;
173 *up = crecp;
176 static void cache_free(struct crec *crecp)
178 crecp->flags &= ~F_FORWARD;
179 crecp->flags &= ~F_REVERSE;
180 crecp->uid = uid++; /* invalidate CNAMES pointing to this. */
183 cache_tail->next = crecp;
185 cache_head = crecp;
186 crecp->prev = cache_tail;
187 crecp->next = NULL;
188 cache_tail = crecp;
191 if (crecp->flags & F_BIGNAME)
193 crecp->name.bname->next = big_free;
194 big_free = crecp->name.bname;
195 crecp->flags &= ~F_BIGNAME;
200 static void cache_link(struct crec *crecp)
203 cache_head->prev = crecp;
204 crecp->next = cache_head;
205 crecp->prev = NULL;
206 cache_head = crecp;
208 cache_tail = crecp;
212 static void cache_unlink (struct crec *crecp)
214 if (crecp->prev)
215 crecp->prev->next = crecp->next;
217 cache_head = crecp->next;
219 if (crecp->next)
220 crecp->next->prev = crecp->prev;
222 cache_tail = crecp->prev;
225 char *cache_get_name(struct crec *crecp)
227 if (crecp->flags & F_BIGNAME)
228 return crecp->name.bname->name;
229 else if (crecp->flags & (F_DHCP | F_CONFIG))
230 return crecp->name.namep;
232 return crecp->name.sname;
235 static int is_outdated_cname_pointer(struct crec *crecp)
237 if (!(crecp->flags & F_CNAME))
240 if (crecp->addr.cname.cache && crecp->addr.cname.uid == crecp->addr.cname.cache->uid)
246 static int is_expired(time_t now, struct crec *crecp)
248 if (crecp->flags & F_IMMORTAL)
251 if (difftime(now, crecp->ttd) < 0)
272 struct crec *crecp, **up;
276 for (up = hash_bucket(name), crecp = *up; crecp; crecp = crecp->hash_next)
277 if (is_expired(now, crecp) || is_outdated_cname_pointer(crecp))
279 *up = crecp->hash_next;
280 if (!(crecp->flags & (F_HOSTS | F_DHCP)))
282 cache_unlink(crecp);
283 cache_free(crecp);
286 else if ((crecp->flags & F_FORWARD) &&
287 ((flags & crecp->flags & (F_IPV4 | F_IPV6)) || ((crecp->flags | flags) & F_CNAME)) &&
288 hostname_isequal(cache_get_name(crecp), name))
290 if (crecp->flags & (F_HOSTS | F_DHCP))
292 *up = crecp->hash_next;
293 cache_unlink(crecp);
294 cache_free(crecp);
297 up = &crecp->hash_next;
308 for (crecp = hash_table[i], up = &hash_table[i];
309 crecp && ((crecp->flags & F_REVERSE) || !(crecp->flags & F_IMMORTAL));
310 crecp = crecp->hash_next)
311 if (is_expired(now, crecp))
313 *up = crecp->hash_next;
314 if (!(crecp->flags & (F_HOSTS | F_DHCP)))
316 cache_unlink(crecp);
317 cache_free(crecp);
320 else if (!(crecp->flags & (F_HOSTS | F_DHCP)) &&
321 (flags & crecp->flags & F_REVERSE) &&
322 (flags & crecp->flags & (F_IPV4 | F_IPV6)) &&
323 memcmp(&crecp->addr.addr, addr, addrlen) == 0)
325 *up = crecp->hash_next;
326 cache_unlink(crecp);
327 cache_free(crecp);
330 up = &crecp->hash_next;
495 struct crec *cache_find_by_name(struct crec *crecp, char *name, time_t now, unsigned short prot)
499 if (crecp) /* iterating */
500 ans = crecp->next;
508 for (up = hash_bucket(name), crecp = *up; crecp; crecp = next)
510 next = crecp->hash_next;
512 if (!is_expired(now, crecp) && !is_outdated_cname_pointer(crecp))
514 if ((crecp->flags & F_FORWARD) &&
515 (crecp->flags & prot) &&
516 hostname_isequal(cache_get_name(crecp), name))
518 if (crecp->flags & (F_HOSTS | F_DHCP))
520 *chainp = crecp;
521 chainp = &crecp->next;
525 cache_unlink(crecp);
526 cache_link(crecp);
534 if (insert && (crecp->flags & (F_REVERSE | F_IMMORTAL)) == ins_flags)
536 *up = crecp->hash_next;
537 crecp->hash_next = *insert;
538 *insert = crecp;
539 insert = &crecp->hash_next;
546 ins_flags = crecp->flags & (F_REVERSE | F_IMMORTAL);
548 up = &crecp->hash_next;
553 up = &crecp->hash_next;
558 *up = crecp->hash_next;
559 if (!(crecp->flags & (F_HOSTS | F_DHCP)))
561 cache_unlink(crecp);
562 cache_free(crecp);
579 struct crec *cache_find_by_addr(struct crec *crecp, struct all_addr *addr,
589 if (crecp) /* iterating */
590 ans = crecp->next;
601 for (crecp = hash_table[i], up = &hash_table[i];
602 crecp && (crecp->flags & F_REVERSE);
603 crecp = crecp->hash_next)
604 if (!is_expired(now, crecp))
606 if ((crecp->flags & prot) &&
607 memcmp(&crecp->addr.addr, addr, addrlen) == 0)
609 if (crecp->flags & (F_HOSTS | F_DHCP))
611 *chainp = crecp;
612 chainp = &crecp->next;
616 cache_unlink(crecp);
617 cache_link(crecp);
620 up = &crecp->hash_next;
624 *up = crecp->hash_next;
625 if (!(crecp->flags & (F_HOSTS | F_DHCP)))
627 cache_unlink(crecp);
628 cache_free(crecp);