mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-01-24 23:52:55 -05:00
109 lines
3.8 KiB
C
109 lines
3.8 KiB
C
/*
|
|
* util/data/msgreply.h - store message and reply data.
|
|
*
|
|
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
|
*
|
|
* This software is open source.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* Neither the name of the NLNET LABS nor the names of its contributors may
|
|
* be used to endorse or promote products derived from this software without
|
|
* specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
/**
|
|
* \file
|
|
*
|
|
* This file contains a data structure to store a message and its reply.
|
|
*/
|
|
|
|
#ifndef UTIL_DATA_MSGREPLY_H
|
|
#define UTIL_DATA_MSGREPLY_H
|
|
|
|
/**
|
|
* Structure to store query information that makes answers to queries
|
|
* different.
|
|
*/
|
|
struct query_info {
|
|
/** salient data on the query: qname, in wireformat. */
|
|
uint8_t* qname;
|
|
/** length of qname (including last 0 octet) */
|
|
size_t qnamesize;
|
|
/** qtype */
|
|
uint16_t qtype;
|
|
/** qclass */
|
|
uint16_t qclass;
|
|
/** does query have CD bit set */
|
|
int has_cd;
|
|
};
|
|
|
|
/**
|
|
* Structure to store DNS query and the reply packet.
|
|
* To use it, copy over the flags from reply and modify using flags from
|
|
* the query (RD,CD if not AA). prepend ID.
|
|
*/
|
|
struct msgreply {
|
|
/** id of this entry. */
|
|
struct query_info q;
|
|
/** if q.qname is allocated by malloc or not */
|
|
int qname_malloced;
|
|
/** the reply packet, skips ID, starts with flags/opcode/rcode word */
|
|
uint8_t* reply;
|
|
/** the reply size */
|
|
size_t replysize;
|
|
};
|
|
|
|
/**
|
|
* Parse wire query into a queryinfo structure, return 0 on parse error.
|
|
* initialises the (prealloced) queryinfo structure as well. sets reply to 0.
|
|
* This query structure contains a pointer back info the buffer!
|
|
* This pointer avoids memory allocation.
|
|
* @param m: the prealloced queryinfo structure to put query into.
|
|
* must be unused, or _clear()ed.
|
|
* @param query: the wireformat packet query. starts with ID.
|
|
* @return: 0 on format error.
|
|
*/
|
|
int query_info_parse(struct query_info* m, ldns_buffer* query);
|
|
|
|
/**
|
|
* Compare two queryinfo structures, on query,
|
|
* The qname is _not_ sorted in canonical ordering.
|
|
* @param m1: struct query_info* , void* here to ease use as function pointer.
|
|
* @param m2: struct query_info* , void* here to ease use as function pointer.
|
|
* @return: 0 = same, -1 m1 is smaller, +1 m1 is larger.
|
|
*/
|
|
int query_info_compare(void* m1, void* m2);
|
|
|
|
/** clear out query info structure. */
|
|
void query_info_clear(struct query_info* m);
|
|
|
|
/** helper routine, determine length of dname in buffer, no compression ptrs
|
|
* allowed, returns 0 on failure. */
|
|
size_t query_dname_len(ldns_buffer* query);
|
|
|
|
/** clear out msgreply structure */
|
|
void msgreply_clear(struct msgreply* m);
|
|
|
|
#endif /* UTIL_DATA_MSGREPLY_H */
|