cache.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <libubox/blob.h>
  18. #include "dns.h"
  19. struct cache_entry {
  20. struct avl_node avl;
  21. const char *entry;
  22. const char *host;
  23. uint32_t ttl;
  24. time_t time;
  25. };
  26. struct cache_record {
  27. struct avl_node avl;
  28. const char *record;
  29. uint16_t type;
  30. uint32_t ttl;
  31. int port;
  32. const char *txt;
  33. const uint8_t *rdata;
  34. uint16_t rdlength;
  35. time_t time;
  36. };
  37. extern struct avl_tree entries;
  38. int cache_init(void);
  39. void cache_scan(void);
  40. void cache_cleanup(void);
  41. void cache_answer(struct interface *iface, uint8_t *base, int blen,
  42. char *name, struct dns_answer *a, uint8_t *rdata);
  43. int cache_host_is_known(char *record);
  44. char *cache_lookup_name(const char *key);
  45. void cache_dump_records(struct blob_buf *buf, const char *name);
  46. #endif