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
24 typedef CLIB_PACKED (struct {
25 u16 id; /**< transaction ID */
26 u16 flags; /**< flags */
27 u16 qdcount; /**< number of questions */
28 u16 anscount; /**< number of answers */
29 u16 nscount; /**< number of name servers */
30 u16 arcount; /**< number of additional records */
34 #define DNS_RCODE_MASK (0xf)
35 #define DNS_RCODE_NO_ERROR 0
36 #define DNS_RCODE_FORMAT_ERROR 1
37 #define DNS_RCODE_SERVER_FAILURE 2
38 #define DNS_RCODE_NAME_ERROR 3
39 #define DNS_RCODE_NOT_IMPLEMENTED 4
40 #define DNS_RCODE_REFUSED 5
42 #define DNS_RA (1<<7) /**< recursion available */
43 #define DNS_RD (1<<8) /**< recursion desired */
44 #define DNS_TC (1<<9) /**< truncation */
45 #define DNS_AA (1<<10) /**< authoritative answer */
46 #define DNS_OPCODE_MASK (0xf<<11) /**< opcode mask */
47 #define DNS_OPCODE_QUERY (0<<11) /**< standard query */
48 #define DNS_OPCODE_IQUERY (1<<11) /**< inverse query (deprecated) */
49 #define DNS_OPCODE_STATUS (2<<11) /**< server status */
50 #define DNS_QR (1<<15) /**< query=0, response=1 */
54 * Note: in DNS-land, www.foobar.com is encoded as three "labels,"
55 * each of which amount to a 1 octet length followed by up to 63
56 * octets of name. Don't forget to add a "null root label" after the last
57 * real one, or the poor slob trying to parse the name will have
58 * no chance whatsoever.
60 * All RRs have the same top level format shown below:
63 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
64 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
69 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
71 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
73 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
76 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
78 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
81 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
84 * DNS "questions" have the following format:
87 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
88 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
92 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
94 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
96 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
100 * DNS "question" fixed header.
103 typedef CLIB_PACKED (struct {
104 u16 type; /**< record type requested */
105 u16 class; /**< class, 1 = internet */
110 * DNS RR fixed header.
113 typedef CLIB_PACKED (struct {
114 u16 type; /**< record type */
115 u16 class; /**< class, 1 = internet */
116 u32 ttl; /**< time to live, in seconds */
124 * There are quite a number of DNS record types
125 * Feel free to add as needed
127 #define foreach_dns_type \
128 _(A, 1) /**< ip4 host address */ \
129 _(AAAA, 28) /**< ip6 host address */ \
130 _(ALL, 255) /**< all available data */ \
131 _(TEXT, 16) /**< a text string */ \
132 _(NAMESERVER, 2) /**< a nameserver */ \
133 _(CNAME, 5) /**< a CNAME (alias) */ \
134 _(MAIL_EXCHANGE, 15) /**< a mail exchange */ \
135 _(PTR, 12) /**< a PTR (pointer) record */ \
136 _(HINFO, 13) /**< Host info */
140 #define _(name,value) DNS_TYPE_##name = value,
145 #define DNS_CLASS_IN 1 /**< The Internet */
148 #endif /* included_dns_packet_h */
151 * fd.io coding-style-patch-verification: ON
154 * eval: (c-set-style "gnu")