diff options
| author | Michael Brown | 2005-04-30 16:50:33 +0200 |
|---|---|---|
| committer | Michael Brown | 2005-04-30 16:50:33 +0200 |
| commit | 78cdb1da8b3e938624cf9061ca634792ca6e9c9f (patch) | |
| tree | b43cdf251f5137e99fae26ace06d0204af6ba534 /src/include | |
| parent | "dns_resolver" changed to "dns" (diff) | |
| download | ipxe-78cdb1da8b3e938624cf9061ca634792ca6e9c9f.tar.gz ipxe-78cdb1da8b3e938624cf9061ca634792ca6e9c9f.tar.xz ipxe-78cdb1da8b3e938624cf9061ca634792ca6e9c9f.zip | |
DNS resolver rewritten, moved to proto/dns.c
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/dns.h | 81 | ||||
| -rw-r--r-- | src/include/dns_resolver.h | 58 |
2 files changed, 81 insertions, 58 deletions
diff --git a/src/include/dns.h b/src/include/dns.h new file mode 100644 index 000000000..cd26a9611 --- /dev/null +++ b/src/include/dns.h @@ -0,0 +1,81 @@ +#ifndef DNS_RESOLVER_H +#define DNS_RESOLVER_H + +#include "stdint.h" +#include "nic.h" +#include "in.h" + +/* + * Constants + * + */ + +#define DNS_TYPE_A 1 +#define DNS_TYPE_CNAME 5 +#define DNS_TYPE_ANY 255 + +#define DNS_CLASS_IN 1 +#define DNS_CLASS_CS 2 +#define DNS_CLASS_CH 3 +#define DNS_CLASS_HS 4 + +#define DNS_FLAG_QUERY ( 0x00 << 15 ) +#define DNS_FLAG_RESPONSE ( 0x01 << 15 ) +#define DNS_FLAG_QR(flags) ( (flags) & ( 0x01 << 15 ) ) +#define DNS_FLAG_OPCODE_QUERY ( 0x00 << 11 ) +#define DNS_FLAG_OPCODE_IQUERY ( 0x01 << 11 ) +#define DNS_FLAG_OPCODE_STATUS ( 0x02 << 11 ) +#define DNS_FLAG_OPCODE(flags) ( (flags) & ( 0x0f << 11 ) ) +#define DNS_FLAG_RD ( 0x01 << 8 ) +#define DNS_FLAG_RA ( 0x01 << 7 ) +#define DNS_FLAG_RCODE_OK ( 0x00 << 0 ) +#define DNS_FLAG_RCODE_NX ( 0x03 << 0 ) +#define DNS_FLAG_RCODE(flags) ( (flags) & ( 0x0f << 0 ) ) + +#define DNS_UDP_PORT 53 +#define DNS_MAX_RETRIES 3 +#define DNS_MAX_CNAME_RECURSION 0x30 + +/* + * DNS protocol structures + * + */ +struct dns_header { + uint16_t id; + uint16_t flags; + uint16_t qdcount; + uint16_t ancount; + uint16_t nscount; + uint16_t arcount; +} __attribute__ (( packed )); + +struct dns_query_info { + uint16_t qtype; + uint16_t qclass; +} __attribute__ (( packed )); + +struct dns_query { + struct iphdr ip; + struct udphdr udp; + struct dns_header dns; + char payload[ 256 + sizeof ( struct dns_query_info ) ]; +} __attribute__ (( packed )); + +struct dns_rr_info { + uint16_t type; + uint16_t class; + uint16_t ttl; + uint16_t rdlength; +} __attribute__ (( packed )); + +struct dns_rr_info_a { + struct dns_rr_info; + struct in_addr in_addr; +} __attribute__ (( packed )); + +struct dns_rr_info_cname { + struct dns_rr_info; + char cname[0]; +}; + +#endif /* DNS_RESOLVER_H */ diff --git a/src/include/dns_resolver.h b/src/include/dns_resolver.h deleted file mode 100644 index b04a9764f..000000000 --- a/src/include/dns_resolver.h +++ /dev/null @@ -1,58 +0,0 @@ -// dns_resolver.h - #define statements for the DNS resolver - -// We only need A and CNAME queries (later possibly AAAA/A6?) -#define QUERYTYPE_A 1 -#define QUERYTYPE_CNAME 5 - -// We only query with INTERNET class (not CHAOS or whatever) -#define QUERYCLASS_INET 1 - -// Our first query will have the identifier <1> (arbitrary - -// remember however that (256 - QUERYIDENTIFIER)/2 > MAX_CNAME_RECURSION !!! -#define QUERYIDENTIFIER 1 - -// Query flags are standard values here -#define QUERYFLAGS 0x0100 -#define QUERYFLAGS_MASK 0xf8 -#define QUERYFLAGS_WANT 0x80 - -// Indices inside the byte array that holds DNS queries/answers -#define QINDEX_ID 0 -#define QINDEX_FLAGS 2 -#define QINDEX_NUMQUEST 4 -#define QINDEX_NUMANSW 6 -#define QINDEX_NUMAUTH 8 -#define QINDEX_NUMADDIT 10 -#define QINDEX_QUESTION 12 -#define QINDEX_QTYPE 14 -#define QINDEX_QCLASS 16 -#define QINDEX_STORE_A 256 - -// Constant UDP port number for DNS traffic -#define UDP_PORT_DNS 53 - -// Return values that the package parser may give -// This packet was not for us (broadcast or whatever) -#define RET_PACK_GARBAG 0 -// Retrieved an address - query finishes -#define RET_GOT_ADDR 1 -// No A record for that hostname - try running a CNAME query -#define RET_RUN_CNAME_Q 2 -// The CNAME query returned a valid hostname - run A query on that -#define RET_RUN_NEXT_A 3 -// The CNAME query failed - stop resolving -#define RET_CNAME_FAIL 4 -// We have a reliable input that claims that the hostname does not exist -#define RET_NOSUCHNAME 5 -// The name server response is somehow bogus/can not be parsed -> Abort -#define RET_DNSERROR 6 - -// Return values that the query engine may give -// DNS query succeeded, IP address delivered -#define RET_DNS_OK 0 -// DNS query failed -#define RET_DNS_FAIL 1 - -// Error codes the DNS server can send to us -#define ERR_NOSUCHNAME 3 - |
