40 #include <sys/socket.h> 42 static const char* notify_str =
"notify";
44 static void notify_handle_zone(
netio_type* netio,
55 ods_log_assert(notify);
75 if(t > notify_time(notify) + 10) {
76 time_t extra = t - notify_time(notify);
77 time_t base = extra*9/10;
78 #ifdef HAVE_ARC4RANDOM_UNIFORM 79 t = notify_time(notify) + base +
80 arc4random_uniform(extra-base);
82 t = notify_time(notify) + base +
83 arc4random()%(extra-base);
85 t = notify_time(notify) + base +
86 random()%(extra-base);
103 if (!xfrhandler || !zone) {
108 ods_log_error(
"[%s] unable to create notify structure: " 109 " allocator_alloc() failed", notify_str);
150 ods_log_assert(zone);
157 ods_log_debug(
"[%s] setup notify for zone %s", notify_str, zone->
name);
158 notify_set_timer(notify, notify_time(notify));
175 ods_log_assert(xfrhandler);
177 ods_log_assert(zone);
178 ods_log_assert(zone->
name);
195 ods_log_debug(
"[%s] zone %s notify off waiting list",
196 notify_str, zone->
name);
202 ods_log_debug(
"[%s] notify for zone %s disabled", notify_str, zone->
name);
221 ods_log_assert(zone);
222 ods_log_assert(zone->
name);
223 ods_log_debug(
"[%s] zone %s no more secondaries, disable notify",
224 notify_str, zone->
name);
225 notify_disable(notify);
238 ssize_t received = 0;
239 ods_log_assert(notify);
241 ods_log_assert(xfrhandler);
245 if (received == -1) {
246 ods_log_error(
"[%s] unable to read packet: recvfrom() failed fd %d " 247 "(%s)", notify_str, notify->
handler.
fd, strerror(errno));
264 ods_log_assert(notify);
269 ods_log_assert(xfrhandler);
270 ods_log_assert(zone);
271 ods_log_assert(zone->
name);
275 ods_log_error(
"[%s] zone %s received bad notify reply opcode/qr from %s",
280 ods_log_error(
"[%s] zone %s received bad notify reply id from %s",
287 ods_log_error(
"[%s] zone %s received bad notify rcode %s from %s",
288 notify_str, zone->
name, str?str:
"UNKNOWN",
295 ods_log_debug(
"[%s] zone %s secondary %s notify reply ok", notify_str,
308 struct sockaddr_storage to;
309 socklen_t to_len = 0;
313 ods_log_assert(buffer);
314 ods_log_assert(notify);
324 fd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
326 ods_log_error(
"[%s] unable to send data over udp to %s: " 334 ods_log_deeebug(
"[%s] send %ld bytes over udp to %s", notify_str,
337 (
struct sockaddr*)&to, to_len);
339 ods_log_error(
"[%s] unable to send data over udp to %s: " 364 ods_log_error(
"[%s] unable to sign notify: tsig unknown algorithm " 368 ods_log_assert(algo);
381 ods_log_debug(
"[%s] tsig append rr to notify id=%u", notify_str,
398 ods_log_assert(notify);
403 ods_log_assert(xfrhandler);
404 ods_log_assert(zone);
405 ods_log_assert(zone->
name);
421 notify_tsig_sign(notify, xfrhandler->
packet);
426 ods_log_error(
"[%s] unable to send notify retry %u for zone %s to " 427 "%s: notify_send_udp() failed", notify_str, notify->
retry,
431 ods_log_verbose(
"[%s] notify retry %u for zone %s sent to %s", notify_str,
441 notify_handle_zone(
netio_type* ATTR_UNUSED(netio),
451 ods_log_assert(notify);
454 ods_log_assert(xfrhandler);
455 ods_log_assert(zone);
456 ods_log_assert(zone->
name);
457 ods_log_debug(
"[%s] handle notify for zone %s", notify_str, zone->
name);
460 ods_log_debug(
"[%s] already waiting, skipping notify for zone %s",
461 notify_str, zone->
name);
462 ods_log_assert(notify->
handler.
fd == -1);
466 ods_log_debug(
"[%s] read notify ok for zone %s", notify_str,
468 ods_log_assert(notify->
handler.
fd != -1);
469 if (notify_udp_read_packet(notify)) {
470 if (notify_handle_reply(notify)) {
475 ods_log_debug(
"[%s] notify timeout for zone %s", notify_str,
484 ods_log_verbose(
"[%s] notify max retry for zone %s, %s unreachable",
499 notify_update_soa(
notify_type* notify, ldns_rr* soa)
505 ldns_rr_free(notify->
soa);
525 ods_log_assert(xfrhandler);
527 ods_log_assert(zone);
528 ods_log_assert(zone->
name);
534 ods_log_warning(
"[%s] zone %s has no notify acl", notify_str,
539 ods_log_debug(
"[%s] zone %s already on waiting list", notify_str,
543 notify_update_soa(notify, soa);
545 notify_setup(notify);
547 ods_log_debug(
"[%s] zone %s notify enabled", notify_str,
562 ods_log_debug(
"[%s] zone %s notify on waiting list", notify_str,
582 ldns_rr_free(notify->
soa);
ldns_pkt_opcode buffer_pkt_opcode(buffer_type *buffer)
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
void notify_enable(notify_type *notify, ldns_rr *soa)
void notify_send(notify_type *notify)
uint16_t buffer_pkt_arcount(buffer_type *buffer)
void buffer_flip(buffer_type *buffer)
void buffer_clear(buffer_type *buffer)
enum netio_events_enum netio_events_type
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
tsig_algo_type * tsig_lookup_algo(const char *name)
int buffer_pkt_qr(buffer_type *buffer)
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
uint16_t buffer_pkt_id(buffer_type *buffer)
void notify_cleanup(notify_type *notify)
uint8_t * buffer_current(buffer_type *buffer)
adapter_type * adoutbound
tsig_rr_type * tsig_rr_create()
void tsig_rr_prepare(tsig_rr_type *trr)
time_t xfrhandler_time(xfrhandler_type *xfrhandler)
void buffer_pkt_set_ancount(buffer_type *buffer, uint16_t count)
void buffer_set_limit(buffer_type *buffer, size_t limit)
notify_type * notify_waiting_first
netio_event_handler_type event_handler
void tsig_rr_cleanup(tsig_rr_type *trr)
notify_type * notify_create(xfrhandler_type *xfrhandler, zone_type *zone)
void log_dname(ldns_rdf *rdf, const char *pre, int level)
notify_type * notify_waiting_last
#define NOTIFY_RETRY_TIMEOUT
void buffer_pkt_set_aa(buffer_type *buffer)
const char * buffer_rcode2str(ldns_pkt_rcode rcode)
xfrhandler_type * xfrhandler
netio_events_type event_types
void buffer_pkt_notify(buffer_type *buffer, ldns_rdf *qname, ldns_rr_class qclass)
size_t buffer_remaining(buffer_type *buffer)
int buffer_write_rr(buffer_type *buffer, ldns_rr *rr)
void tsig_rr_sign(tsig_rr_type *trr)
notify_type * waiting_next
size_t buffer_position(buffer_type *buffer)
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
netio_handler_type handler
struct timespec * timeout
uint16_t original_query_id
uint8_t * buffer_begin(buffer_type *buffer)
ldns_pkt_rcode buffer_pkt_rcode(buffer_type *buffer)