2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef included_dns_packet_h
17 #define included_dns_packet_h
20 * DNS packet header format
23 typedef CLIB_PACKED (struct {
24 u16 id; /**< transaction ID */
25 u16 flags; /**< flags */
26 u16 qdcount; /**< number of questions */
27 u16 anscount; /**< number of answers */
28 u16 nscount; /**< number of name servers */
29 u16 arcount; /**< number of additional records */
32 #define DNS_RCODE_MASK (0xf)
33 #define DNS_RCODE_NO_ERROR 0
34 #define DNS_RCODE_FORMAT_ERROR 1
35 #define DNS_RCODE_SERVER_FAILURE 2
36 #define DNS_RCODE_NAME_ERROR 3
37 #define DNS_RCODE_NOT_IMPLEMENTED 4
38 #define DNS_RCODE_REFUSED 5
40 #define DNS_RA (1<<7) /**< recursion available */
41 #define DNS_RD (1<<8) /**< recursion desired */
42 #define DNS_TC (1<<9) /**< truncation */
43 #define DNS_AA (1<<10) /**< authoritative answer */
44 #define DNS_OPCODE_MASK (0xf<<11) /**< opcode mask */
45 #define DNS_OPCODE_QUERY (0<<11) /**< standard query */
46 #define DNS_OPCODE_IQUERY (1<<11) /**< inverse query (deprecated) */
47 #define DNS_OPCODE_STATUS (2<<11) /**< server status */
48 #define DNS_QR (1<<15) /**< query=0, response=1 */
52 * Note: in DNS-land, www.foobar.com is encoded as three "labels,"
53 * each of which amount to a 1 octet length followed by up to 63
54 * octets of name. Don't forget to add a "null root label" after the last
55 * real one, or the poor slob trying to parse the name will have
56 * no chance whatsoever.
58 * All RRs have the same top level format shown below:
61 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
62 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
67 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
69 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
71 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
74 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
76 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
79 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
82 * DNS "questions" have the following format:
85 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
86 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
90 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
92 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
94 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
98 * DNS "question" fixed header.
100 typedef CLIB_PACKED (struct {
101 u16 type; /**< record type requested */
102 u16 class; /**< class, 1 = internet */
106 * DNS RR fixed header.
108 typedef CLIB_PACKED (struct {
109 u16 type; /**< record type */
110 u16 class; /**< class, 1 = internet */
111 u32 ttl; /**< time to live, in seconds */
118 * There are quite a number of DNS record types
119 * Feel free to add as needed
121 #define foreach_dns_type \
122 _(A, 1) /**< ip4 host address */ \
123 _(AAAA, 28) /**< ip6 host address */ \
124 _(ALL, 255) /**< all available data */ \
125 _(TEXT, 16) /**< a text string */ \
126 _(NAMESERVER, 2) /**< a nameserver */ \
127 _(CNAME, 5) /**< a CNAME (alias) */ \
128 _(MAIL_EXCHANGE, 15) /**< a mail exchange */ \
129 _(PTR, 12) /**< a PTR (pointer) record */ \
130 _(HINFO, 13) /**< Host info */
134 #define _(name,value) DNS_TYPE_##name = value,
139 #define DNS_CLASS_IN 1 /**< The Internet */
142 #endif /* included_dns_packet_h */
145 * fd.io coding-style-patch-verification: ON
148 * eval: (c-set-style "gnu")