query.h
Go to the documentation of this file.
/*
* Copyright (c) 2011 NLNet Labs. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
*/
#ifndef WIRE_QUERY_H
#define WIRE_QUERY_H
#include "config.h"
#include "status.h"
#include "signer/zone.h"
#include "wire/buffer.h"
#include "wire/edns.h"
#include "wire/tsig.h"
#define UDP_MAX_MESSAGE_LEN 512
#define TCP_MAX_MESSAGE_LEN 65535
#define QUERY_RESPONSE_MAX_RRSET 10 /* should be enough */
enum query_enum {
QUERY_PROCESSED = 0,
QUERY_DISCARDED,
QUERY_AXFR,
QUERY_IXFR
};
typedef enum query_enum query_state;
typedef struct query_struct query_type;
struct query_struct {
/* Query from addres */
struct sockaddr_storage addr;
socklen_t addrlen;
/* Maximum supported query size */
size_t maxlen;
size_t reserved_space;
/* TSIG */
tsig_rr_type* tsig_rr;
/* EDNS */
edns_rr_type* edns_rr;
/* TCP */
int tcp;
uint16_t tcplen;
buffer_type* buffer;
/* QNAME, QTYPE, QCLASS */
/* Zone */
zone_type* zone;
/* Compression */
/* AXFR IXFR */
FILE* axfr_fd;
uint32_t serial;
size_t startpos;
/* Bits */
unsigned axfr_is_done : 1;
unsigned tsig_prepare_it : 1;
unsigned tsig_update_it : 1;
unsigned tsig_sign_it : 1;
};
typedef struct response_struct response_type;
struct response_struct {
size_t rrset_count;
ldns_pkt_section sections[QUERY_RESPONSE_MAX_RRSET];
rrset_type* rrsets[QUERY_RESPONSE_MAX_RRSET];
};
query_type* query_create(void);
void query_prepare(query_type* q);
query_state query_process(query_type* q, engine_type* engine);
void query_reset(query_type* q, size_t maxlen, int is_tcp);
void query_add_optional(query_type* q, engine_type* engine);
int query_add_rr(query_type* q, ldns_rr* rr);
void query_cleanup(query_type* q);
#endif /* WIRE_QUERY_H */
query_prepare
void query_prepare(query_type *q)
Definition: query.c:612
query_struct::maxlen
size_t maxlen
Definition: query.h:64
query_struct::tcplen
uint16_t tcplen
Definition: query.h:72
query_add_rr
int query_add_rr(query_type *q, ldns_rr *rr)
Definition: query.c:1035
QUERY_IXFR
Definition: query.h:50
query_struct::tsig_sign_it
unsigned tsig_sign_it
Definition: query.h:88
query_struct::tcp
int tcp
Definition: query.h:71
query_struct::tsig_rr
tsig_rr_type * tsig_rr
Definition: query.h:67
query_struct::zone
zone_type * zone
Definition: query.h:77
query_add_optional
void query_add_optional(query_type *q, engine_type *engine)
Definition: query.c:956
query_struct::tsig_update_it
unsigned tsig_update_it
Definition: query.h:87
zone_struct
Definition: zone.h:60
query_process
query_state query_process(query_type *q, engine_type *engine)
Definition: query.c:842
tsig.h
response_struct::rrset_count
size_t rrset_count
Definition: query.h:97
query_create
query_type * query_create(void)
Definition: query.c:48
tsig_rr_struct
Definition: tsig.h:123
QUERY_DISCARDED
Definition: query.h:48
query_struct::reserved_space
size_t reserved_space
Definition: query.h:65
query_struct::edns_rr
edns_rr_type * edns_rr
Definition: query.h:69
query_cleanup
void query_cleanup(query_type *q)
Definition: query.c:1092
query_struct
Definition: query.h:59
query_struct::tsig_prepare_it
unsigned tsig_prepare_it
Definition: query.h:86
query_struct::addr
struct sockaddr_storage addr
Definition: query.h:61
query_enum
query_enum
Definition: query.h:46
QUERY_AXFR
Definition: query.h:49
buffer_struct
Definition: buffer.h:112
edns_rr_struct
Definition: edns.h:76
query_reset
void query_reset(query_type *q, size_t maxlen, int is_tcp)
Definition: query.c:80
query_struct::serial
uint32_t serial
Definition: query.h:82
query_state
enum query_enum query_state
Definition: query.h:52
query_struct::buffer
buffer_type * buffer
Definition: query.h:73
QUERY_PROCESSED
Definition: query.h:47
query_struct::startpos
size_t startpos
Definition: query.h:83
query_struct::axfr_is_done
unsigned axfr_is_done
Definition: query.h:85
response_struct
Definition: query.h:96
zone.h
engine_struct
Definition: engine.h:51
buffer.h
query_struct::addrlen
socklen_t addrlen
Definition: query.h:62
edns.h
rrset_struct
Definition: rrset.h:59
query_struct::axfr_fd
FILE * axfr_fd
Definition: query.h:81
QUERY_RESPONSE_MAX_RRSET
#define QUERY_RESPONSE_MAX_RRSET
Definition: query.h:44