Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef _GPXE_RESOLV_H
  2. #define _GPXE_RESOLV_H
  3. /** @file
  4. *
  5. * Name resolution
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <gpxe/refcnt.h>
  10. #include <gpxe/interface.h>
  11. #include <gpxe/tables.h>
  12. #include <gpxe/socket.h>
  13. struct resolv_interface;
  14. /** Name resolution interface operations */
  15. struct resolv_interface_operations {
  16. /** Name resolution completed
  17. *
  18. * @v resolv Name resolution interface
  19. * @v sa Completed socket address (if successful)
  20. * @v rc Final status code
  21. */
  22. void ( * done ) ( struct resolv_interface *resolv,
  23. struct sockaddr *sa, int rc );
  24. };
  25. /** A name resolution interface */
  26. struct resolv_interface {
  27. /** Generic object communication interface */
  28. struct interface intf;
  29. /** Operations for received messages */
  30. struct resolv_interface_operations *op;
  31. };
  32. extern struct resolv_interface null_resolv;
  33. extern struct resolv_interface_operations null_resolv_ops;
  34. /**
  35. * Initialise a name resolution interface
  36. *
  37. * @v resolv Name resolution interface
  38. * @v op Name resolution interface operations
  39. * @v refcnt Containing object reference counter, or NULL
  40. */
  41. static inline void resolv_init ( struct resolv_interface *resolv,
  42. struct resolv_interface_operations *op,
  43. struct refcnt *refcnt ) {
  44. resolv->intf.dest = &null_resolv.intf;
  45. resolv->intf.refcnt = refcnt;
  46. resolv->op = op;
  47. }
  48. /**
  49. * Get name resolution interface from generic object communication interface
  50. *
  51. * @v intf Generic object communication interface
  52. * @ret resolv Name resolution interface
  53. */
  54. static inline __attribute__ (( always_inline )) struct resolv_interface *
  55. intf_to_resolv ( struct interface *intf ) {
  56. return container_of ( intf, struct resolv_interface, intf );
  57. }
  58. /**
  59. * Get reference to destination name resolution interface
  60. *
  61. * @v resolv Name resolution interface
  62. * @ret dest Destination interface
  63. */
  64. static inline __attribute__ (( always_inline )) struct resolv_interface *
  65. resolv_get_dest ( struct resolv_interface *resolv ) {
  66. return intf_to_resolv ( intf_get ( resolv->intf.dest ) );
  67. }
  68. /**
  69. * Drop reference to name resolution interface
  70. *
  71. * @v resolv name resolution interface
  72. */
  73. static inline __attribute__ (( always_inline )) void
  74. resolv_put ( struct resolv_interface *resolv ) {
  75. intf_put ( &resolv->intf );
  76. }
  77. /**
  78. * Plug a name resolution interface into a new destination interface
  79. *
  80. * @v resolv Name resolution interface
  81. * @v dest New destination interface
  82. */
  83. static inline __attribute__ (( always_inline )) void
  84. resolv_plug ( struct resolv_interface *resolv, struct resolv_interface *dest ) {
  85. plug ( &resolv->intf, &dest->intf );
  86. }
  87. /**
  88. * Plug two name resolution interfaces together
  89. *
  90. * @v a Name resolution interface A
  91. * @v b Name resolution interface B
  92. */
  93. static inline __attribute__ (( always_inline )) void
  94. resolv_plug_plug ( struct resolv_interface *a, struct resolv_interface *b ) {
  95. plug_plug ( &a->intf, &b->intf );
  96. }
  97. /**
  98. * Unplug a name resolution interface
  99. *
  100. * @v resolv Name resolution interface
  101. */
  102. static inline __attribute__ (( always_inline )) void
  103. resolv_unplug ( struct resolv_interface *resolv ) {
  104. plug ( &resolv->intf, &null_resolv.intf );
  105. }
  106. /**
  107. * Stop using a name resolution interface
  108. *
  109. * @v resolv Name resolution interface
  110. *
  111. * After calling this method, no further messages will be received via
  112. * the interface.
  113. */
  114. static inline void resolv_nullify ( struct resolv_interface *resolv ) {
  115. resolv->op = &null_resolv_ops;
  116. };
  117. /** A name resolver */
  118. struct resolver {
  119. /** Name of this resolver (e.g. "DNS") */
  120. const char *name;
  121. /** Start name resolution
  122. *
  123. * @v resolv Name resolution interface
  124. * @v name Name to resolve
  125. * @v sa Socket address to complete
  126. * @ret rc Return status code
  127. */
  128. int ( * resolv ) ( struct resolv_interface *resolv, const char *name,
  129. struct sockaddr *sa );
  130. };
  131. /** Numeric resolver priority */
  132. #define RESOLV_NUMERIC 01
  133. /** Normal resolver priority */
  134. #define RESOLV_NORMAL 02
  135. /** Resolvers table */
  136. #define RESOLVERS __table ( struct resolver, "resolvers" )
  137. /** Register as a name resolver */
  138. #define __resolver( resolv_order ) __table_entry ( RESOLVERS, resolv_order )
  139. extern void resolv_done ( struct resolv_interface *resolv,
  140. struct sockaddr *sa, int rc );
  141. extern void ignore_resolv_done ( struct resolv_interface *resolv,
  142. struct sockaddr *sa, int rc );
  143. extern struct resolv_interface_operations null_resolv_ops;
  144. extern struct resolv_interface null_resolv;
  145. extern int resolv ( struct resolv_interface *resolv, const char *name,
  146. struct sockaddr *sa );
  147. #endif /* _GPXE_RESOLV_H */