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