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 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef _GPXE_DNS_H
  2. #define _GPXE_DNS_H
  3. /** @file
  4. *
  5. * DNS protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <gpxe/in.h>
  11. /*
  12. * Constants
  13. *
  14. */
  15. #define DNS_TYPE_A 1
  16. #define DNS_TYPE_CNAME 5
  17. #define DNS_TYPE_ANY 255
  18. #define DNS_CLASS_IN 1
  19. #define DNS_CLASS_CS 2
  20. #define DNS_CLASS_CH 3
  21. #define DNS_CLASS_HS 4
  22. #define DNS_FLAG_QUERY ( 0x00 << 15 )
  23. #define DNS_FLAG_RESPONSE ( 0x01 << 15 )
  24. #define DNS_FLAG_QR(flags) ( (flags) & ( 0x01 << 15 ) )
  25. #define DNS_FLAG_OPCODE_QUERY ( 0x00 << 11 )
  26. #define DNS_FLAG_OPCODE_IQUERY ( 0x01 << 11 )
  27. #define DNS_FLAG_OPCODE_STATUS ( 0x02 << 11 )
  28. #define DNS_FLAG_OPCODE(flags) ( (flags) & ( 0x0f << 11 ) )
  29. #define DNS_FLAG_RD ( 0x01 << 8 )
  30. #define DNS_FLAG_RA ( 0x01 << 7 )
  31. #define DNS_FLAG_RCODE_OK ( 0x00 << 0 )
  32. #define DNS_FLAG_RCODE_NX ( 0x03 << 0 )
  33. #define DNS_FLAG_RCODE(flags) ( (flags) & ( 0x0f << 0 ) )
  34. #define DNS_PORT 53
  35. #define DNS_MAX_RETRIES 3
  36. #define DNS_MAX_CNAME_RECURSION 0x30
  37. /*
  38. * DNS protocol structures
  39. *
  40. */
  41. struct dns_header {
  42. uint16_t id;
  43. uint16_t flags;
  44. uint16_t qdcount;
  45. uint16_t ancount;
  46. uint16_t nscount;
  47. uint16_t arcount;
  48. } __attribute__ (( packed ));
  49. struct dns_query_info {
  50. uint16_t qtype;
  51. uint16_t qclass;
  52. } __attribute__ (( packed ));
  53. struct dns_query {
  54. struct dns_header dns;
  55. char payload[ 256 + sizeof ( struct dns_query_info ) ];
  56. } __attribute__ (( packed ));
  57. struct dns_rr_info_common {
  58. uint16_t type;
  59. uint16_t class;
  60. uint32_t ttl;
  61. uint16_t rdlength;
  62. } __attribute__ (( packed ));
  63. struct dns_rr_info_a {
  64. struct dns_rr_info_common common;
  65. struct in_addr in_addr;
  66. } __attribute__ (( packed ));
  67. struct dns_rr_info_cname {
  68. struct dns_rr_info_common common;
  69. char cname[0];
  70. } __attribute__ (( packed ));
  71. union dns_rr_info {
  72. struct dns_rr_info_common common;
  73. struct dns_rr_info_a a;
  74. struct dns_rr_info_cname cname;
  75. };
  76. #endif /* _GPXE_DNS_H */