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.

resolv.h 4.3KB

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