cache.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include "interface.h"
  20. struct cache_service {
  21. struct avl_node avl;
  22. const char *entry;
  23. const char *host;
  24. uint32_t ttl;
  25. time_t time;
  26. struct interface *iface;
  27. int refresh;
  28. };
  29. struct cache_record {
  30. struct avl_node avl;
  31. const char *record;
  32. uint16_t type;
  33. uint32_t ttl;
  34. int port;
  35. const char *txt;
  36. const uint8_t *rdata;
  37. uint16_t rdlength;
  38. time_t time;
  39. struct interface *iface;
  40. struct sockaddr_storage from;
  41. int refresh;
  42. };
  43. extern struct avl_tree services;
  44. extern struct avl_tree records;
  45. int cache_init(void);
  46. void cache_update(void);
  47. void cache_cleanup(struct interface *iface);
  48. void cache_answer(struct interface *iface, struct sockaddr *from, uint8_t *base,
  49. int blen, char *name, struct dns_answer *a, uint8_t *rdata,
  50. int flush);
  51. int cache_host_is_known(char *record);
  52. void cache_dump_records(struct blob_buf *buf, const char *name, int array,
  53. const char **hostname);
  54. void cache_dump_recursive(struct blob_buf *b, const char *name, uint16_t type, struct interface *iface);
  55. #endif