OpenDNSSEC-signer  2.1.5
xfrd.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 NLNet Labs. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
32 #ifndef WIRE_XFRD_H
33 #define WIRE_XFRD_H
34 
35 #include "config.h"
36 #include <stdint.h>
37 #include <time.h>
38 
44  XFRD_PKT_BAD, /* drop the packet/connection */
45  XFRD_PKT_MORE, /* more packets to follow on tcp */
46  XFRD_PKT_NOTIMPL, /* server responded with NOTIMPL or FORMATERR */
47  XFRD_PKT_TC, /* try tcp connection */
48  XFRD_PKT_XFR, /* server responded with transfer*/
49  XFRD_PKT_NEWLEASE /* no changes, soa OK */
50 };
52 
53 typedef struct soa_struct soa_type;
54 
55 typedef struct xfrd_struct xfrd_type;
56 
57 #include "locks.h"
58 #include "status.h"
59 #include "wire/acl.h"
60 #include "wire/buffer.h"
61 #include "wire/netio.h"
62 #include "wire/tsig.h"
63 #include "daemon/xfrhandler.h"
64 
65 #define XFRD_MAX_ROUNDS 3 /* max number of rounds along the masters */
66 #define XFRD_MAX_UDP 100 /* max number of udp sockets at a time for ixfr */
67 #define XFRD_NO_IXFR_CACHE 172800 /* 48h before retrying ixfr after notimpl */
68 #define XFRD_TCP_TIMEOUT 120 /* seconds, before a tcp request times out */
69 #define XFRD_UDP_TIMEOUT 5 /* seconds, before a udp request times out */
70 
71 /*
72  * Zone transfer SOA information.
73  */
74 struct soa_struct {
75  /* owner equals zone apex */
76  /* class equals zone klass */
77  /* type is SOA */
78  uint32_t ttl;
79  /* rdata count = 7 */
80  uint8_t mname[MAXDOMAINLEN + 2];
81  uint8_t rname[MAXDOMAINLEN + 2];
82  uint32_t serial;
83  uint32_t refresh;
84  uint32_t retry;
85  uint32_t expire;
86  uint32_t minimum;
87 };
88 
94 {
97  pthread_mutex_t serial_lock; /* mutexes soa serial management */
98  pthread_mutex_t rw_lock; /* mutexes <zone>.xfrd file */
99 
100  /* transfer request handling */
101  int tcp_conn;
106 
107  /* soa serial management */
108  uint32_t serial_xfr;
109  /* Last received serial via notify. Only valid if
110  * serial_notify_acquired is not 0 */
111  uint32_t serial_notify;
112  /* current serial on inbound side */
113  uint32_t serial_disk;
115  /* time of last received notify that is being handled. If non-zero
116  * it indicates a transfer is in progress */
121 
122  /* timeout and event handling */
123  struct timespec timeout;
125 
126  /* packet handling */
127  uint16_t query_id;
128  uint32_t msg_seq_nr;
129  uint32_t msg_old_serial;
130  uint32_t msg_new_serial;
131  size_t msg_rr_count;
132  uint8_t msg_is_ixfr;
135 
138  unsigned tcp_waiting : 1;
139  unsigned udp_waiting : 1;
140 
141 };
142 
150 xfrd_type* xfrd_create(xfrhandler_type* xfrhandler, zone_type* zone);
151 
157 void xfrd_set_timer_now(xfrd_type* xfrd);
158 
164 void xfrd_set_timer_retry(xfrd_type* xfrd);
165 
172 
180 socklen_t xfrd_acl_sockaddr_to(acl_type* acl,
181  struct sockaddr_storage* to);
182 
189 void xfrd_cleanup(xfrd_type* xfrd, int backup);
190 
191 #endif /* WIRE_XFRD_H */
soa_struct::retry
uint32_t retry
Definition: xfrd.h:84
xfrd_struct::master_num
int master_num
Definition: xfrd.h:103
netio_handler_struct
Definition: netio.h:102
xfrd_struct::timeout
struct timespec timeout
Definition: xfrd.h:123
xfrd_struct::serial_lock
pthread_mutex_t serial_lock
Definition: xfrd.h:97
xfrd_struct::msg_old_serial
uint32_t msg_old_serial
Definition: xfrd.h:129
xfrd_struct::handler
netio_handler_type handler
Definition: xfrd.h:124
xfrhandler_struct
Definition: xfrhandler.h:52
soa_struct::minimum
uint32_t minimum
Definition: xfrd.h:86
soa_struct::serial
uint32_t serial
Definition: xfrd.h:82
soa_struct::mname
uint8_t mname[MAXDOMAINLEN+2]
Definition: xfrd.h:80
netio.h
zone_struct
Definition: zone.h:60
xfrd_struct::msg_is_ixfr
uint8_t msg_is_ixfr
Definition: xfrd.h:132
soa_struct::ttl
uint32_t ttl
Definition: xfrd.h:78
XFRD_PKT_MORE
Definition: xfrd.h:45
xfrhandler.h
XFRD_PKT_XFR
Definition: xfrd.h:48
xfrd_pkt_status
enum xfrd_pkt_enum xfrd_pkt_status
Definition: xfrd.h:51
tsig_rr_struct
Definition: tsig.h:123
xfrd_struct::serial_notify_acquired
time_t serial_notify_acquired
Definition: xfrd.h:117
xfrd_struct::serial_retransfer
uint8_t serial_retransfer
Definition: xfrd.h:119
xfrd_set_timer_refresh
void xfrd_set_timer_refresh(xfrd_type *xfrd)
Definition: xfrd.c:490
xfrd_struct::serial_xfr
uint32_t serial_xfr
Definition: xfrd.h:108
xfrd_struct::xfrhandler
xfrhandler_type * xfrhandler
Definition: xfrd.h:95
acl.h
MAXDOMAINLEN
#define MAXDOMAINLEN
Definition: buffer.h:44
xfrd_struct::msg_do_retransfer
uint8_t msg_do_retransfer
Definition: xfrd.h:133
xfrd_struct::udp_waiting
unsigned udp_waiting
Definition: xfrd.h:139
xfrd_struct::rw_lock
pthread_mutex_t rw_lock
Definition: xfrd.h:98
acl_struct
Definition: acl.h:58
xfrd_struct::master
acl_type * master
Definition: xfrd.h:105
soa_struct::refresh
uint32_t refresh
Definition: xfrd.h:83
xfrd_set_timer_retry
void xfrd_set_timer_retry(xfrd_type *xfrd)
Definition: xfrd.c:472
xfrd_pkt_enum
xfrd_pkt_enum
Definition: xfrd.h:43
xfrd_acl_sockaddr_to
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
Definition: xfrd.c:537
soa_struct
Definition: xfrd.h:74
xfrd_struct::serial_xfr_acquired
time_t serial_xfr_acquired
Definition: xfrd.h:114
xfrd_struct::serial_disk_acquired
time_t serial_disk_acquired
Definition: xfrd.h:118
xfrd_set_timer_now
void xfrd_set_timer_now(xfrd_type *xfrd)
Definition: xfrd.c:454
tsig.h
xfrd_struct::msg_rr_count
size_t msg_rr_count
Definition: xfrd.h:131
xfrd_struct::round_num
int round_num
Definition: xfrd.h:102
buffer.h
XFRD_PKT_NEWLEASE
Definition: xfrd.h:49
xfrd_cleanup
void xfrd_cleanup(xfrd_type *xfrd, int backup)
Definition: xfrd.c:2179
XFRD_PKT_NOTIMPL
Definition: xfrd.h:46
xfrd_struct::tcp_waiting_next
xfrd_type * tcp_waiting_next
Definition: xfrd.h:136
XFRD_PKT_TC
Definition: xfrd.h:47
xfrd_struct::serial_disk
uint32_t serial_disk
Definition: xfrd.h:113
xfrd_struct::msg_seq_nr
uint32_t msg_seq_nr
Definition: xfrd.h:128
XFRD_PKT_BAD
Definition: xfrd.h:44
soa_struct::rname
uint8_t rname[MAXDOMAINLEN+2]
Definition: xfrd.h:81
xfrd_struct::query_id
uint16_t query_id
Definition: xfrd.h:127
xfrd_create
xfrd_type * xfrd_create(xfrhandler_type *xfrhandler, zone_type *zone)
Definition: xfrd.c:315
xfrd_struct::tcp_conn
int tcp_conn
Definition: xfrd.h:101
xfrd_struct
Definition: xfrd.h:93
xfrd_struct::tsig_rr
tsig_rr_type * tsig_rr
Definition: xfrd.h:134
xfrd_struct::tcp_waiting
unsigned tcp_waiting
Definition: xfrd.h:138
xfrd_struct::next_master
int next_master
Definition: xfrd.h:104
xfrd_struct::soa
soa_type soa
Definition: xfrd.h:120
xfrd_struct::zone
zone_type * zone
Definition: xfrd.h:96
soa_struct::expire
uint32_t expire
Definition: xfrd.h:85
xfrd_struct::msg_new_serial
uint32_t msg_new_serial
Definition: xfrd.h:130
xfrd_struct::serial_notify
uint32_t serial_notify
Definition: xfrd.h:111
xfrd_struct::udp_waiting_next
xfrd_type * udp_waiting_next
Definition: xfrd.h:137