octeon: enable ethernet pause frame support
[vpp.git] / src / plugins / dns / dns_packet.h
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #ifndef included_dns_packet_h
17 #define included_dns_packet_h
18
19 /**
20  * DNS packet header format
21  */
22
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 */
30 }) dns_header_t;
31
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
39
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  */
49
50
51 /*
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.
57  *
58  * All RRs have the same top level format shown below:
59  *
60  *                                    1  1  1  1  1  1
61  *      0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
62  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
63  *    |                                               |
64  *    /                                               /
65  *    /                      NAME                     /
66  *    |                                               |
67  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
68  *    |                      TYPE                     |
69  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
70  *    |                     CLASS                     |
71  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
72  *    |                      TTL                      |
73  *    |                                               |
74  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
75  *    |                   RDLENGTH                    |
76  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
77  *    /                     RDATA                     /
78  *    /                                               /
79  *    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
80  *
81  *
82  *  DNS "questions" have the following format:
83  *
84  *                                     1  1  1  1  1  1
85  *       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
86  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
87  *     |                                               |
88  *     /                     QNAME                     /
89  *     /                                               /
90  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
91  *     |                     QTYPE                     |
92  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
93  *     |                     QCLASS                    |
94  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
95  */
96
97 /**
98  * DNS "question" fixed header.
99  */
100 typedef CLIB_PACKED (struct {
101   u16 type;     /**< record type requested */
102   u16 class;    /**< class, 1 = internet */
103 }) dns_query_t;
104
105 /**
106  * DNS RR fixed header.
107  */
108 typedef CLIB_PACKED (struct {
109   u16 type;     /**< record type */
110   u16 class;    /**< class, 1 = internet */
111   u32 ttl;      /**< time to live, in seconds */
112   u16 rdlength;
113   /**< length of r */
114   u8 rdata[0];
115 }) dns_rr_t;
116
117 /*
118  * There are quite a number of DNS record types
119  * Feel free to add as needed
120  */
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 */
131
132 typedef enum
133 {
134 #define _(name,value) DNS_TYPE_##name = value,
135   foreach_dns_type
136 #undef _
137 } dns_type_t;
138
139 #define DNS_CLASS_IN    1       /**< The Internet */
140
141
142 #endif /* included_dns_packet_h */
143
144 /*
145  * fd.io coding-style-patch-verification: ON
146  *
147  * Local Variables:
148  * eval: (c-set-style "gnu")
149  * End:
150  */