1238106Sdes/*
2238106Sdes * iterator/iter_resptype.h - response type information and classification.
3238106Sdes *
4238106Sdes * Copyright (c) 2007, NLnet Labs. All rights reserved.
5238106Sdes *
6238106Sdes * This software is open source.
7238106Sdes *
8238106Sdes * Redistribution and use in source and binary forms, with or without
9238106Sdes * modification, are permitted provided that the following conditions
10238106Sdes * are met:
11238106Sdes *
12238106Sdes * Redistributions of source code must retain the above copyright notice,
13238106Sdes * this list of conditions and the following disclaimer.
14238106Sdes *
15238106Sdes * Redistributions in binary form must reproduce the above copyright notice,
16238106Sdes * this list of conditions and the following disclaimer in the documentation
17238106Sdes * and/or other materials provided with the distribution.
18238106Sdes *
19238106Sdes * Neither the name of the NLNET LABS nor the names of its contributors may
20238106Sdes * be used to endorse or promote products derived from this software without
21238106Sdes * specific prior written permission.
22238106Sdes *
23238106Sdes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24269257Sdes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25269257Sdes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26269257Sdes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27269257Sdes * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28269257Sdes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29269257Sdes * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30269257Sdes * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31269257Sdes * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32269257Sdes * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33269257Sdes * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34238106Sdes */
35238106Sdes
36238106Sdes/**
37238106Sdes * \file
38238106Sdes *
39238106Sdes * This file defines the response type. DNS Responses can be classified as
40238106Sdes * one of the response types.
41238106Sdes */
42238106Sdes
43238106Sdes#ifndef ITERATOR_ITER_RESPTYPE_H
44238106Sdes#define ITERATOR_ITER_RESPTYPE_H
45238106Sdesstruct dns_msg;
46238106Sdesstruct query_info;
47238106Sdesstruct delegpt;
48238106Sdes
49238106Sdes/**
50238106Sdes * The response type is used to interpret the response.
51238106Sdes */
52238106Sdesenum response_type {
53238106Sdes	/**
54238106Sdes	 * 'untyped' means that the type of this response hasn't been
55238106Sdes	 * assigned.
56238106Sdes	 */
57238106Sdes	RESPONSE_TYPE_UNTYPED   = 0,
58238106Sdes
59238106Sdes	/**
60238106Sdes	 * 'answer' means that the response terminates the resolution
61238106Sdes	 * process.
62238106Sdes	 */
63238106Sdes	RESPONSE_TYPE_ANSWER,
64238106Sdes
65238106Sdes	/** 'delegation' means that the response is a delegation. */
66238106Sdes	RESPONSE_TYPE_REFERRAL,
67238106Sdes
68238106Sdes	/**
69238106Sdes	 * 'cname' means that the response is a cname without the final
70238106Sdes	 * answer, and thus must be restarted.
71238106Sdes	 */
72238106Sdes	RESPONSE_TYPE_CNAME,
73238106Sdes
74238106Sdes	/**
75238106Sdes	 * 'throwaway' means that this particular response should be
76238106Sdes	 * discarded and the next nameserver should be contacted
77238106Sdes	 */
78238106Sdes	RESPONSE_TYPE_THROWAWAY,
79238106Sdes
80238106Sdes	/**
81238106Sdes	 * 'lame' means that this particular response indicates that
82238106Sdes	 * the nameserver knew nothing about the question.
83238106Sdes	 */
84238106Sdes	RESPONSE_TYPE_LAME,
85238106Sdes
86238106Sdes	/**
87238106Sdes	 * Recursion lame means that the nameserver is some sort of
88238106Sdes	 * open recursor, and not authoritative for the question.
89238106Sdes	 * It may know something, but not authoritatively.
90238106Sdes	 */
91238106Sdes	RESPONSE_TYPE_REC_LAME
92238106Sdes};
93238106Sdes
94238106Sdes/**
95238106Sdes * Classifies a response message from cache based on the current request.
96238106Sdes * Note that this routine assumes that THROWAWAY or LAME responses will not
97238106Sdes * occur. Also, it will not detect REFERRAL type messages, since those are
98238106Sdes * (currently) automatically classified based on how they came from the
99238106Sdes * cache (findDelegation() instead of lookup()).
100238106Sdes *
101238106Sdes * @param msg: the message from the cache.
102238106Sdes * @param request: the request that generated the response.
103238106Sdes * @return the response type (CNAME or ANSWER).
104238106Sdes */
105238106Sdesenum response_type response_type_from_cache(struct dns_msg* msg,
106238106Sdes	struct query_info* request);
107238106Sdes
108238106Sdes/**
109238106Sdes * Classifies a response message (from the wire) based on the current
110238106Sdes * request.
111238106Sdes *
112238106Sdes * NOTE: currently this routine uses the AA bit in the response to help
113238106Sdes * distinguish between some non-standard referrals and answers. It also
114238106Sdes * relies somewhat on the originating zone to be accurate (for lameness
115238106Sdes * detection, mostly).
116238106Sdes *
117238106Sdes * @param rdset: if RD bit was sent in query sent by unbound.
118238106Sdes * @param msg: the message from the cache.
119238106Sdes * @param request: the request that generated the response.
120238106Sdes * @param dp: The delegation point that was being queried
121238106Sdes *          when the response was returned.
122238106Sdes * @return the response type (CNAME or ANSWER).
123238106Sdes */
124238106Sdesenum response_type response_type_from_server(int rdset,
125238106Sdes	struct dns_msg* msg, struct query_info* request, struct delegpt* dp);
126238106Sdes
127238106Sdes#endif /* ITERATOR_ITER_RESPTYPE_H */
128