resolv_conf.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Extended resolver state separate from struct __res_state.
  2. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library 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 GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef RESOLV_STATE_H
  16. #define RESOLV_STATE_H
  17. #include <netinet/in.h>
  18. #include <stdbool.h>
  19. #include <stddef.h>
  20. /* This type corresponds to members of the _res.sort_list array. */
  21. struct resolv_sortlist_entry
  22. {
  23. struct in_addr addr;
  24. uint32_t mask;
  25. };
  26. /* Extended resolver state associated with res_state objects. Client
  27. code can reach this state through a struct resolv_context
  28. object. */
  29. struct resolv_conf
  30. {
  31. /* Reference counter. The object is deallocated once it reaches
  32. zero. For internal use within resolv_conf only. */
  33. size_t __refcount;
  34. /* List of IPv4 and IPv6 name server addresses. */
  35. const struct sockaddr **nameserver_list;
  36. size_t nameserver_list_size;
  37. /* The domain names forming the search list. */
  38. const char *const *search_list;
  39. size_t search_list_size;
  40. /* IPv4 address preference rules. */
  41. const struct resolv_sortlist_entry *sort_list;
  42. size_t sort_list_size;
  43. /* _res.options has type unsigned long, but we can only use 32 bits
  44. for portability across all architectures. */
  45. unsigned int options;
  46. unsigned int retrans; /* Timeout. */
  47. unsigned int retry; /* Number of times to retry. */
  48. unsigned int ndots; /* Dots needed for initial non-search query. */
  49. };
  50. /* The functions below are for use by the res_init resolv.conf parser
  51. and the struct resolv_context facility. */
  52. struct __res_state;
  53. /* Read /etc/resolv.conf and return a configuration object, or NULL if
  54. /etc/resolv.conf cannot be read due to memory allocation errors.
  55. If PREINIT is not NULL, some configuration values are taken from the
  56. struct __res_state object. */
  57. struct resolv_conf *__resolv_conf_load (struct __res_state *preinit)
  58. attribute_hidden __attribute__ ((warn_unused_result));
  59. /* Return a configuration object for the current /etc/resolv.conf
  60. settings, or NULL on failure. The object is cached. */
  61. struct resolv_conf *__resolv_conf_get_current (void)
  62. attribute_hidden __attribute__ ((warn_unused_result));
  63. /* Return the extended resolver state for *RESP, or NULL if it cannot
  64. be determined. A call to this function must be paired with a call
  65. to __resolv_conf_put. */
  66. struct resolv_conf *__resolv_conf_get (struct __res_state *) attribute_hidden;
  67. /* Converse of __resolv_conf_get. */
  68. void __resolv_conf_put (struct resolv_conf *) attribute_hidden;
  69. /* Allocate a new struct resolv_conf object and copy the
  70. pre-configured values from *INIT. Return NULL on allocation
  71. failure. The object must be deallocated using
  72. __resolv_conf_put. */
  73. struct resolv_conf *__resolv_conf_allocate (const struct resolv_conf *init)
  74. attribute_hidden __attribute__ ((nonnull (1), warn_unused_result));
  75. /* Associate an existing extended resolver state with *RESP. Return
  76. false on allocation failure. In addition, update *RESP with the
  77. overlapping non-extended resolver state. */
  78. bool __resolv_conf_attach (struct __res_state *, struct resolv_conf *)
  79. attribute_hidden;
  80. /* Detach the extended resolver state from *RESP. */
  81. void __resolv_conf_detach (struct __res_state *resp) attribute_hidden;
  82. #endif /* RESOLV_STATE_H */