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];
};
extern query_type* query_create(void);
extern void query_prepare(query_type* q);
extern query_state query_process(query_type* q, engine_type* engine);
extern void query_reset(query_type* q, size_t maxlen, int is_tcp);
extern void query_add_optional(query_type* q, engine_type* engine);
extern int query_add_rr(query_type* q, ldns_rr* rr);
extern void query_cleanup(query_type* q);
#endif /* WIRE_QUERY_H */
buffer.h
edns.h
query_prepare
void query_prepare(query_type *q)
Definition query.c:612
query_create
query_type * query_create(void)
Definition query.c:48
query_reset
void query_reset(query_type *q, size_t maxlen, int is_tcp)
Definition query.c:80
query_enum
query_enum
Definition query.h:46
QUERY_IXFR
@ QUERY_IXFR
Definition query.h:50
QUERY_AXFR
@ QUERY_AXFR
Definition query.h:49
QUERY_DISCARDED
@ QUERY_DISCARDED
Definition query.h:48
QUERY_PROCESSED
@ QUERY_PROCESSED
Definition query.h:47
query_add_optional
void query_add_optional(query_type *q, engine_type *engine)
Definition query.c:962
query_cleanup
void query_cleanup(query_type *q)
Definition query.c:1098
query_process
query_state query_process(query_type *q, engine_type *engine)
Definition query.c:842
query_add_rr
int query_add_rr(query_type *q, ldns_rr *rr)
Definition query.c:1041
QUERY_RESPONSE_MAX_RRSET
#define QUERY_RESPONSE_MAX_RRSET
Definition query.h:44
query_state
enum query_enum query_state
Definition query.h:52
buffer_struct
Definition buffer.h:112
edns_rr_struct
Definition edns.h:76
engine_struct
Definition engine.h:51
query_struct
Definition query.h:59
query_struct::startpos
size_t startpos
Definition query.h:83
query_struct::tcp
int tcp
Definition query.h:71
query_struct::maxlen
size_t maxlen
Definition query.h:64
query_struct::buffer
buffer_type * buffer
Definition query.h:73
query_struct::edns_rr
edns_rr_type * edns_rr
Definition query.h:69
query_struct::tsig_sign_it
unsigned tsig_sign_it
Definition query.h:88
query_struct::addr
struct sockaddr_storage addr
Definition query.h:61
query_struct::axfr_fd
FILE * axfr_fd
Definition query.h:81
query_struct::serial
uint32_t serial
Definition query.h:82
query_struct::axfr_is_done
unsigned axfr_is_done
Definition query.h:85
query_struct::tcplen
uint16_t tcplen
Definition query.h:72
query_struct::addrlen
socklen_t addrlen
Definition query.h:62
query_struct::tsig_update_it
unsigned tsig_update_it
Definition query.h:87
query_struct::tsig_prepare_it
unsigned tsig_prepare_it
Definition query.h:86
query_struct::zone
zone_type * zone
Definition query.h:77
query_struct::tsig_rr
tsig_rr_type * tsig_rr
Definition query.h:67
query_struct::reserved_space
size_t reserved_space
Definition query.h:65
response_struct
Definition query.h:96
response_struct::sections
ldns_pkt_section sections[QUERY_RESPONSE_MAX_RRSET]
Definition query.h:98
response_struct::rrset_count
size_t rrset_count
Definition query.h:97
response_struct::rrsets
rrset_type * rrsets[QUERY_RESPONSE_MAX_RRSET]
Definition query.h:99
rrset_struct
Definition rrset.h:59
tsig_rr_struct
Definition tsig.h:123
zone_struct
Definition zone.h:60
tsig.h
zone.h