xfrd.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_XFRD_H
#define WIRE_XFRD_H
#include "config.h"
#include <stdint.h>
#include <time.h>
enum xfrd_pkt_enum {
XFRD_PKT_BAD, /* drop the packet/connection */
XFRD_PKT_MORE, /* more packets to follow on tcp */
XFRD_PKT_NOTIMPL, /* server responded with NOTIMPL or FORMATERR */
XFRD_PKT_TC, /* try tcp connection */
XFRD_PKT_XFR, /* server responded with transfer*/
XFRD_PKT_NEWLEASE /* no changes, soa OK */
};
typedef enum xfrd_pkt_enum xfrd_pkt_status;
typedef struct soa_struct soa_type;
typedef struct xfrd_struct xfrd_type;
#include "locks.h"
#include "status.h"
#include "wire/acl.h"
#include "wire/buffer.h"
#include "wire/netio.h"
#include "wire/tsig.h"
#include "daemon/xfrhandler.h"
#define XFRD_MAX_ROUNDS 3 /* max number of rounds along the masters */
#define XFRD_MAX_UDP 100 /* max number of udp sockets at a time for ixfr */
#define XFRD_NO_IXFR_CACHE 172800 /* 48h before retrying ixfr after notimpl */
#define XFRD_TCP_TIMEOUT 120 /* seconds, before a tcp request times out */
#define XFRD_UDP_TIMEOUT 5 /* seconds, before a udp request times out */
/*
* Zone transfer SOA information.
*/
struct soa_struct {
/* owner equals zone apex */
/* class equals zone klass */
/* type is SOA */
uint32_t ttl;
/* rdata count = 7 */
uint8_t mname[MAXDOMAINLEN + 2];
uint8_t rname[MAXDOMAINLEN + 2];
uint32_t serial;
uint32_t refresh;
uint32_t retry;
uint32_t expire;
uint32_t minimum;
};
struct xfrd_struct
{
xfrhandler_type* xfrhandler;
zone_type* zone;
pthread_mutex_t serial_lock; /* mutexes soa serial management */
pthread_mutex_t rw_lock; /* mutexes <zone>.xfrd file */
/* transfer request handling */
int tcp_conn;
int round_num;
int master_num;
int next_master;
acl_type* master;
/* soa serial management */
uint32_t serial_xfr;
/* Last received serial via notify. Only valid if
* serial_notify_acquired is not 0 */
uint32_t serial_notify;
/* current serial on inbound side */
uint32_t serial_disk;
time_t serial_xfr_acquired;
/* time of last received notify that is being handled. If non-zero
* it indicates a transfer is in progress */
time_t serial_notify_acquired;
time_t serial_disk_acquired;
uint8_t serial_retransfer;
soa_type soa;
/* timeout and event handling */
struct timespec timeout;
netio_handler_type handler;
/* packet handling */
uint16_t query_id;
uint32_t msg_seq_nr;
uint32_t msg_old_serial;
uint32_t msg_new_serial;
size_t msg_rr_count;
uint8_t msg_is_ixfr;
uint8_t msg_do_retransfer;
tsig_rr_type* tsig_rr;
xfrd_type* tcp_waiting_next;
xfrd_type* udp_waiting_next;
unsigned tcp_waiting : 1;
unsigned udp_waiting : 1;
};
xfrd_type* xfrd_create(xfrhandler_type* xfrhandler, zone_type* zone);
void xfrd_set_timer_now(xfrd_type* xfrd);
void xfrd_set_timer_retry(xfrd_type* xfrd);
void xfrd_set_timer_refresh(xfrd_type* xfrd);
socklen_t xfrd_acl_sockaddr_to(acl_type* acl,
struct sockaddr_storage* to);
void xfrd_cleanup(xfrd_type* xfrd, int backup);
#endif /* WIRE_XFRD_H */
XFRD_PKT_XFR
Definition: xfrd.h:48
xfrd_struct::next_master
int next_master
Definition: xfrd.h:104
xfrd_struct::zone
zone_type * zone
Definition: xfrd.h:96
xfrd_struct::tcp_waiting_next
xfrd_type * tcp_waiting_next
Definition: xfrd.h:136
xfrd_struct::serial_xfr_acquired
time_t serial_xfr_acquired
Definition: xfrd.h:114
xfrd_struct::serial_notify
uint32_t serial_notify
Definition: xfrd.h:111
soa_struct
Definition: xfrd.h:74
zone_struct
Definition: zone.h:60
xfrd_struct::msg_rr_count
size_t msg_rr_count
Definition: xfrd.h:131
xfrhandler.h
tsig.h
xfrhandler_struct
Definition: xfrhandler.h:52
xfrd_struct::round_num
int round_num
Definition: xfrd.h:102
xfrd_struct::serial_notify_acquired
time_t serial_notify_acquired
Definition: xfrd.h:117
soa_struct::mname
uint8_t mname[MAXDOMAINLEN+2]
Definition: xfrd.h:80
tsig_rr_struct
Definition: tsig.h:123
netio.h
xfrd_struct::msg_seq_nr
uint32_t msg_seq_nr
Definition: xfrd.h:128
soa_struct::retry
uint32_t retry
Definition: xfrd.h:84
xfrd_pkt_enum
xfrd_pkt_enum
Definition: xfrd.h:43
xfrd_struct::xfrhandler
xfrhandler_type * xfrhandler
Definition: xfrd.h:95
soa_struct::ttl
uint32_t ttl
Definition: xfrd.h:78
xfrd_struct::tcp_waiting
unsigned tcp_waiting
Definition: xfrd.h:138
xfrd_struct::udp_waiting_next
xfrd_type * udp_waiting_next
Definition: xfrd.h:137
soa_struct::refresh
uint32_t refresh
Definition: xfrd.h:83
XFRD_PKT_NOTIMPL
Definition: xfrd.h:46
acl.h
xfrd_struct::msg_new_serial
uint32_t msg_new_serial
Definition: xfrd.h:130
xfrd_struct::master
acl_type * master
Definition: xfrd.h:105
xfrd_struct::serial_lock
pthread_mutex_t serial_lock
Definition: xfrd.h:97
xfrd_set_timer_refresh
void xfrd_set_timer_refresh(xfrd_type *xfrd)
Definition: xfrd.c:490
netio_handler_struct
Definition: netio.h:102
xfrd_struct::tcp_conn
int tcp_conn
Definition: xfrd.h:101
soa_struct::minimum
uint32_t minimum
Definition: xfrd.h:86
XFRD_PKT_TC
Definition: xfrd.h:47
xfrd_struct::tsig_rr
tsig_rr_type * tsig_rr
Definition: xfrd.h:134
XFRD_PKT_BAD
Definition: xfrd.h:44
soa_struct::expire
uint32_t expire
Definition: xfrd.h:85
soa_struct::rname
uint8_t rname[MAXDOMAINLEN+2]
Definition: xfrd.h:81
xfrd_struct::msg_old_serial
uint32_t msg_old_serial
Definition: xfrd.h:129
buffer.h
xfrd_struct::msg_is_ixfr
uint8_t msg_is_ixfr
Definition: xfrd.h:132
MAXDOMAINLEN
#define MAXDOMAINLEN
Definition: buffer.h:44
xfrd_struct::serial_retransfer
uint8_t serial_retransfer
Definition: xfrd.h:119
xfrd_set_timer_retry
void xfrd_set_timer_retry(xfrd_type *xfrd)
Definition: xfrd.c:472
xfrd_struct::serial_xfr
uint32_t serial_xfr
Definition: xfrd.h:108
xfrd_struct::query_id
uint16_t query_id
Definition: xfrd.h:127
xfrd_struct::master_num
int master_num
Definition: xfrd.h:103
xfrd_cleanup
void xfrd_cleanup(xfrd_type *xfrd, int backup)
Definition: xfrd.c:2179
xfrd_struct
Definition: xfrd.h:93
xfrd_acl_sockaddr_to
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
Definition: xfrd.c:537
xfrd_struct::udp_waiting
unsigned udp_waiting
Definition: xfrd.h:139
soa_struct::serial
uint32_t serial
Definition: xfrd.h:82
XFRD_PKT_NEWLEASE
Definition: xfrd.h:49
xfrd_struct::handler
netio_handler_type handler
Definition: xfrd.h:124
xfrd_struct::soa
soa_type soa
Definition: xfrd.h:120
XFRD_PKT_MORE
Definition: xfrd.h:45
xfrd_create
xfrd_type * xfrd_create(xfrhandler_type *xfrhandler, zone_type *zone)
Definition: xfrd.c:315
xfrd_pkt_status
enum xfrd_pkt_enum xfrd_pkt_status
Definition: xfrd.h:51
xfrd_struct::serial_disk_acquired
time_t serial_disk_acquired
Definition: xfrd.h:118
xfrd_struct::serial_disk
uint32_t serial_disk
Definition: xfrd.h:113
xfrd_set_timer_now
void xfrd_set_timer_now(xfrd_type *xfrd)
Definition: xfrd.c:454
xfrd_struct::rw_lock
pthread_mutex_t rw_lock
Definition: xfrd.h:98
xfrd_struct::msg_do_retransfer
uint8_t msg_do_retransfer
Definition: xfrd.h:133
acl_struct
Definition: acl.h:58