OpenDNSSEC-signer  1.4.6
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 "shared/allocator.h"
37 #include "shared/locks.h"
38 #include "shared/status.h"
39 #include "wire/acl.h"
40 #include "wire/buffer.h"
41 #include "wire/netio.h"
42 #include "wire/tsig.h"
43 
44 #include <stdint.h>
45 #include <time.h>
46 
47 #define XFRD_MAX_ROUNDS 3 /* max number of rounds along the masters */
48 #define XFRD_MAX_UDP 100 /* max number of udp sockets at a time for ixfr */
49 #define XFRD_NO_IXFR_CACHE 172800 /* 48h before retrying ixfr after notimpl */
50 #define XFRD_TCP_TIMEOUT 120 /* seconds, before a tcp request times out */
51 #define XFRD_UDP_TIMEOUT 5 /* seconds, before a udp request times out */
52 
58  XFRD_PKT_BAD, /* drop the packet/connection */
59  XFRD_PKT_MORE, /* more packets to follow on tcp */
60  XFRD_PKT_NOTIMPL, /* server responded with NOTIMPL or FORMATERR */
61  XFRD_PKT_TC, /* try tcp connection */
62  XFRD_PKT_XFR, /* server responded with transfer*/
63  XFRD_PKT_NEWLEASE /* no changes, soa OK */
64 };
66 
67 /*
68  * Zone transfer SOA information.
69  */
70 typedef struct soa_struct soa_type;
71 struct soa_struct {
72  /* owner equals zone apex */
73  /* class equals zone klass */
74  /* type is SOA */
75  uint32_t ttl;
76  /* rdata count = 7 */
77  uint8_t mname[MAXDOMAINLEN + 2];
78  uint8_t rname[MAXDOMAINLEN + 2];
79  uint32_t serial;
80  uint32_t refresh;
81  uint32_t retry;
82  uint32_t expire;
83  uint32_t minimum;
84 };
85 
90 typedef struct xfrd_struct xfrd_type;
92 {
94  void* xfrhandler;
95  void* zone;
96  lock_basic_type serial_lock; /* mutexes soa serial management */
97  lock_basic_type rw_lock; /* mutexes <zone>.xfrd file */
98 
99  /* transfer request handling */
100  int tcp_conn;
105 
106  /* soa serial management */
107  uint32_t serial_xfr;
108  uint32_t serial_notify;
109  uint32_t serial_disk;
115 
116  /* timeout and event handling */
117  struct timespec timeout;
119 
120  /* packet handling */
121  uint16_t query_id;
122  uint32_t msg_seq_nr;
123  uint32_t msg_old_serial;
124  uint32_t msg_new_serial;
125  size_t msg_rr_count;
126  uint8_t msg_is_ixfr;
129 
132  unsigned tcp_waiting : 1;
133  unsigned udp_waiting : 1;
134 
135 };
136 
144 xfrd_type* xfrd_create(void* xfrhandler, void* zone);
145 
151 void xfrd_set_timer_now(xfrd_type* xfrd);
152 
158 void xfrd_set_timer_retry(xfrd_type* xfrd);
159 
166 
174 socklen_t xfrd_acl_sockaddr_to(acl_type* acl,
175  struct sockaddr_storage* to);
176 
183 void xfrd_cleanup(xfrd_type* xfrd, int backup);
184 
185 #endif /* WIRE_XFRD_H */
int next_master
Definition: xfrd.h:103
xfrd_type * tcp_waiting_next
Definition: xfrd.h:130
xfrd_type * xfrd_create(void *xfrhandler, void *zone)
Definition: xfrd.c:316
time_t serial_xfr_acquired
Definition: xfrd.h:110
uint32_t serial_notify
Definition: xfrd.h:108
size_t msg_rr_count
Definition: xfrd.h:125
int round_num
Definition: xfrd.h:101
time_t serial_notify_acquired
Definition: xfrd.h:111
allocator_type * allocator
Definition: xfrd.h:93
void * zone
Definition: xfrd.h:95
uint8_t mname[MAXDOMAINLEN+2]
Definition: xfrd.h:77
uint32_t msg_seq_nr
Definition: xfrd.h:122
uint32_t retry
Definition: xfrd.h:81
xfrd_pkt_enum
Definition: xfrd.h:57
lock_basic_type serial_lock
Definition: xfrd.h:96
uint32_t ttl
Definition: xfrd.h:75
unsigned tcp_waiting
Definition: xfrd.h:132
xfrd_type * udp_waiting_next
Definition: xfrd.h:131
uint32_t refresh
Definition: xfrd.h:80
uint32_t msg_new_serial
Definition: xfrd.h:124
acl_type * master
Definition: xfrd.h:104
int lock_basic_type
Definition: locks.h:88
void xfrd_set_timer_refresh(xfrd_type *xfrd)
Definition: xfrd.c:510
int tcp_conn
Definition: xfrd.h:100
uint32_t minimum
Definition: xfrd.h:83
tsig_rr_type * tsig_rr
Definition: xfrd.h:128
uint32_t expire
Definition: xfrd.h:82
uint8_t rname[MAXDOMAINLEN+2]
Definition: xfrd.h:78
uint32_t msg_old_serial
Definition: xfrd.h:123
struct timespec timeout
Definition: xfrd.h:117
uint8_t msg_is_ixfr
Definition: xfrd.h:126
#define MAXDOMAINLEN
Definition: buffer.h:44
uint8_t serial_retransfer
Definition: xfrd.h:113
void xfrd_set_timer_retry(xfrd_type *xfrd)
Definition: xfrd.c:491
uint32_t serial_xfr
Definition: xfrd.h:107
uint16_t query_id
Definition: xfrd.h:121
void * xfrhandler
Definition: xfrd.h:94
int master_num
Definition: xfrd.h:102
void xfrd_cleanup(xfrd_type *xfrd, int backup)
Definition: xfrd.c:2159
lock_basic_type rw_lock
Definition: xfrd.h:97
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
Definition: xfrd.c:558
unsigned udp_waiting
Definition: xfrd.h:133
uint32_t serial
Definition: xfrd.h:79
netio_handler_type handler
Definition: xfrd.h:118
soa_type soa
Definition: xfrd.h:114
enum xfrd_pkt_enum xfrd_pkt_status
Definition: xfrd.h:65
time_t serial_disk_acquired
Definition: xfrd.h:112
uint32_t serial_disk
Definition: xfrd.h:109
void xfrd_set_timer_now(xfrd_type *xfrd)
Definition: xfrd.c:472
uint8_t msg_do_retransfer
Definition: xfrd.h:127
Definition: acl.h:58