You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dns.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2023 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RSPAMD_DNS_H
  17. #define RSPAMD_DNS_H
  18. #include "config.h"
  19. #include "mem_pool.h"
  20. #include "async_session.h"
  21. #include "logger.h"
  22. #include "rdns.h"
  23. #include "upstream.h"
  24. #include "libutil/hash.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. struct rspamd_config;
  29. struct rspamd_task;
  30. struct event_loop;
  31. struct rspamd_dns_resolver {
  32. struct rdns_resolver *r;
  33. struct ev_loop *event_loop;
  34. rspamd_lru_hash_t *fails_cache;
  35. void *uidna;
  36. double fails_cache_time;
  37. struct upstream_list *ups;
  38. struct rspamd_config *cfg;
  39. double request_timeout;
  40. unsigned int max_retransmits;
  41. };
  42. /* Rspamd DNS API */
  43. /**
  44. * Init DNS resolver, params are obtained from a config file or system file /etc/resolv.conf
  45. */
  46. struct rspamd_dns_resolver *rspamd_dns_resolver_init(rspamd_logger_t *logger,
  47. struct ev_loop *ev_base,
  48. struct rspamd_config *cfg);
  49. void rspamd_dns_resolver_deinit(struct rspamd_dns_resolver *resolver);
  50. struct rspamd_dns_request_ud;
  51. /**
  52. * Make a DNS request
  53. * @param resolver resolver object
  54. * @param session async session to register event
  55. * @param pool memory pool for storage
  56. * @param cb callback to call on resolve completing
  57. * @param ud user data for callback
  58. * @param type request type
  59. * @param ... string or ip address based on a request type
  60. * @return TRUE if request was sent.
  61. */
  62. struct rspamd_dns_request_ud *rspamd_dns_resolver_request(struct rspamd_dns_resolver *resolver,
  63. struct rspamd_async_session *session,
  64. rspamd_mempool_t *pool,
  65. dns_callback_type cb,
  66. gpointer ud,
  67. enum rdns_request_type type,
  68. const char *name);
  69. gboolean rspamd_dns_resolver_request_task(struct rspamd_task *task,
  70. dns_callback_type cb,
  71. gpointer ud,
  72. enum rdns_request_type type,
  73. const char *name);
  74. gboolean rspamd_dns_resolver_request_task_forced(struct rspamd_task *task,
  75. dns_callback_type cb,
  76. gpointer ud,
  77. enum rdns_request_type type,
  78. const char *name);
  79. /**
  80. * Converts a name into idna from UTF8
  81. * @param resolver resolver (must be initialised)
  82. * @param pool optional memory pool (can be NULL, then you need to g_free) the result
  83. * @param name input name
  84. * @param namelen length of input (-1 for zero terminated)
  85. * @return encoded string
  86. */
  87. char *rspamd_dns_resolver_idna_convert_utf8(struct rspamd_dns_resolver *resolver,
  88. rspamd_mempool_t *pool,
  89. const char *name,
  90. int namelen,
  91. unsigned int *outlen);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif