cache.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License version 2.1
  6. * as published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _CACHE_H__
  14. #define _CACHE_H__
  15. #include <libubox/avl.h>
  16. #include <libubox/list.h>
  17. #include "dns.h"
  18. struct cache_entry {
  19. struct avl_node avl;
  20. const char *entry;
  21. const char *host;
  22. uint32_t ttl;
  23. time_t time;
  24. };
  25. struct cache_record {
  26. struct avl_node avl;
  27. const char *record;
  28. uint16_t type;
  29. uint32_t ttl;
  30. int port;
  31. const char *txt;
  32. const uint8_t *rdata;
  33. uint16_t rdlength;
  34. time_t time;
  35. };
  36. extern struct avl_tree records, entries;
  37. extern int cache_init(void);
  38. extern void cache_scan(void);
  39. extern void cache_cleanup(void);
  40. extern void cache_answer(struct interface *iface, uint8_t *base, int blen,
  41. char *name, struct dns_answer *a, uint8_t *rdata);
  42. extern int cache_host_is_known(char *record);
  43. extern char* cache_lookup_name(const char *key);
  44. #endif