1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20%%
21%% Defintion for Domain Name System
22%%
23
24%%
25%% Currently defined opcodes
26%%
27-define(QUERY,    16#0).          %% standard query
28-define(IQUERY,   16#1).	      %% inverse query
29-define(STATUS,   16#2).	      %% nameserver status query
30%% -define(xxx,   16#3)  %% 16#3 reserved
31%%  non standard
32-define(UPDATEA,  16#9).	       %% add resource record
33-define(UPDATED,  16#a).	       %% delete a specific resource record
34-define(UPDATEDA, 16#b).	       %% delete all nemed resource record
35-define(UPDATEM,  16#c).	       %% modify a specific resource record
36-define(UPDATEMA, 16#d).	       %% modify all named resource record
37
38-define(ZONEINIT, 16#e).	       %% initial zone transfer
39-define(ZONEREF,  16#f).	       %% incremental zone referesh
40
41
42%%
43%% Currently defined response codes
44%%
45-define(NOERROR,  0).		%% no error
46-define(FORMERR,  1).		%% format error
47-define(SERVFAIL, 2).		%% server failure
48-define(NXDOMAIN, 3).		%% non existent domain
49-define(NOTIMP,	  4).		%% not implemented
50-define(REFUSED,  5).		%% query refused
51%%	non standard
52-define(NOCHANGE, 16#f).		%% update failed to change db
53-define(BADVERS,  16).
54
55%%
56%% Type values for resources and queries
57%%
58-define(T_A,		1).		%% host address
59-define(T_NS,		2).		%% authoritative server
60-define(T_MD,		3).		%% mail destination
61-define(T_MF,		4).		%% mail forwarder
62-define(T_CNAME,	5).		%% connonical name
63-define(T_SOA,		6).		%% start of authority zone
64-define(T_MB,		7).		%% mailbox domain name
65-define(T_MG,		8).		%% mail group member
66-define(T_MR,		9).		%% mail rename name
67-define(T_NULL,		10).		%% null resource record
68-define(T_WKS,		11).		%% well known service
69-define(T_PTR,		12).		%% domain name pointer
70-define(T_HINFO,	13).		%% host information
71-define(T_MINFO,	14).		%% mailbox information
72-define(T_MX,		15).		%% mail routing information
73-define(T_TXT,		16).		%% text strings
74-define(T_AAAA,         28).            %% ipv6 address
75%% SRV (RFC 2052)
76-define(T_SRV,          33).            %% services
77%% NAPTR (RFC 2915)
78-define(T_NAPTR,        35).            %% naming authority pointer
79-define(T_OPT,          41).            %% EDNS pseudo-rr RFC2671(7)
80%% SPF (RFC 4408)
81-define(T_SPF,          99).            %% server policy framework
82%%      non standard
83-define(T_UINFO,	100).		%% user (finger) information
84-define(T_UID,		101).		%% user ID
85-define(T_GID,		102).		%% group ID
86-define(T_UNSPEC,	103).		%% Unspecified format (binary data)
87%%	Query type values which do not appear in resource records
88-define(T_AXFR,		252).		%% transfer zone of authority
89-define(T_MAILB,	253).		%% transfer mailbox records
90-define(T_MAILA,	254).		%% transfer mail agent records
91-define(T_ANY,		255).		%% wildcard match
92
93%%
94%% Symbolic Type values for resources and queries
95%%
96-define(S_A,		a).		%% host address
97-define(S_NS,		ns).		%% authoritative server
98-define(S_MD,		md).		%% mail destination
99-define(S_MF,		mf).		%% mail forwarder
100-define(S_CNAME,	cname).		%% connonical name
101-define(S_SOA,		soa).		%% start of authority zone
102-define(S_MB,		mb).		%% mailbox domain name
103-define(S_MG,		mg).		%% mail group member
104-define(S_MR,		mr).		%% mail rename name
105-define(S_NULL,		null).		%% null resource record
106-define(S_WKS,		wks).		%% well known service
107-define(S_PTR,		ptr).		%% domain name pointer
108-define(S_HINFO,	hinfo).		%% host information
109-define(S_MINFO,	minfo).		%% mailbox information
110-define(S_MX,		mx).		%% mail routing information
111-define(S_TXT,		txt).		%% text strings
112-define(S_AAAA,         aaaa).          %% ipv6 address
113%% SRV (RFC 2052)
114-define(S_SRV,          srv).           %% services
115%% NAPTR (RFC 2915)
116-define(S_NAPTR,        naptr).         %% naming authority pointer
117-define(S_OPT,          opt).           %% EDNS pseudo-rr RFC2671(7)
118%% SPF (RFC 4408)
119-define(S_SPF,          spf).           %% server policy framework
120%%      non standard
121-define(S_UINFO,	uinfo).		%% user (finger) information
122-define(S_UID,		uid).		%% user ID
123-define(S_GID,		gid).		%% group ID
124-define(S_UNSPEC,	unspec).        %% Unspecified format (binary data)
125%%	Query type values which do not appear in resource records
126-define(S_AXFR,		axfr).		%% transfer zone of authority
127-define(S_MAILB,	mailb).		%% transfer mailbox records
128-define(S_MAILA,	maila).		%% transfer mail agent records
129-define(S_ANY,		any).		%% wildcard match
130
131%%
132%% Values for class field
133%%
134
135-define(C_IN,		1).      	%% the arpa internet
136-define(C_CHAOS,	3).		%% for chaos net at MIT
137-define(C_HS,		4).		%% for Hesiod name server at MIT
138%%  Query class values which do not appear in resource records
139-define(C_ANY,		255).		%% wildcard match
140
141
142%% indirection mask for compressed domain names
143-define(INDIR_MASK, 16#c0).
144
145%%
146%% Structure for query header, the order of the fields is machine and
147%% compiler dependent, in our case, the bits within a byte are assignd
148%% least significant first, while the order of transmition is most
149%% significant first.  This requires a somewhat confusing rearrangement.
150%%
151-record(dns_header,
152	{
153	 id = 0,       %% ushort query identification number
154	 %% byte F0
155	 qr = 0,       %% :1   response flag
156	 opcode = 0,   %% :4   purpose of message
157	 aa = 0,       %% :1   authoritive answer
158	 tc = 0,       %% :1   truncated message
159	 rd = 0,       %% :1   recursion desired
160	 %% byte F1
161	 ra = 0,       %% :1   recursion available
162	 pr = 0,       %% :1   primary server required (non standard)
163	               %% :2   unused bits
164	 rcode = 0     %% :4   response code
165	}).
166
167-record(dns_rec,
168	{
169	 header,       %% dns_header record
170	 qdlist = [],  %% list of question entries
171	 anlist = [],  %% list of answer entries
172	 nslist = [],  %% list of authority entries
173	 arlist = []   %% list of resource entries
174	}).
175
176%% DNS resource record
177-record(dns_rr,
178	{
179	 domain = "",   %% resource domain
180	 type = any,    %% resource type
181	 class = in,    %% reource class
182	 cnt = 0,       %% access count
183	 ttl = 0,       %% time to live
184	 data = [],     %% raw data
185	  %%
186	 tm,            %% creation time
187         bm = [],       %% Bitmap storing domain character case information.
188         func = false   %% Optional function calculating the data field.
189	}).
190
191-define(DNS_UDP_PAYLOAD_SIZE, 1280).
192
193-record(dns_rr_opt,           %% EDNS RR OPT (RFC2671), dns_rr{type=opt}
194	{
195	  domain = "",        %% should be the root domain
196	  type = opt,
197	  udp_payload_size = ?DNS_UDP_PAYLOAD_SIZE, %% RFC2671(4.5 CLASS)
198	  ext_rcode = 0,      %% RFC2671(4.6 EXTENDED-RCODE)
199	  version = 0,        %% RFC2671(4.6 VERSION)
200	  z = 0,              %% RFC2671(4.6 Z)
201	  data = []           %% RFC2671(4.4)
202	 }).
203
204-record(dns_query,
205	{
206	 domain,     %% query domain
207	 type,        %% query type
208	 class      %% query class
209	 }).
210