Lines Matching refs:update
18 * for SRP clients to update DNS servers that don't support SRP.
37 // 3. Check that the message is a valid SRP update according to the rules
39 // 5. Do a DNS Update with prerequisites to prevent overwriting a host record with the same owner name but
66 static dns_name_t *service_update_zone; // The zone to update when we receive an update for default.service.arpa.
87 // Free the data structures into which the SRP update was parsed. The pointers to the various DNS objects that these
116 // Free all the stuff that we accumulated while processing the SRP update.
118 update_free(update_t *update)
121 update_free_parts(update->instances, update->added_instances, update->services, update->host);
124 message_free(update->message);
125 dns_message_free(update->parsed_message);
126 free(update);
234 // Copy the RR we received in the SRP update out in wire format.
249 // Construct an update of the specified type, assuming that the record being updated
251 // to be update are taken from the update_t.
255 // The goal of the update is to either bring the zone to the state described in the SRP update, or
256 // determine that the state described in the SRP update conflicts with what is already present in
260 // 1. Update and Zone are the same (A and AAAA records may differ):
264 // Update:
272 // know without trying. We can at this point either try to add each service instance in a separate update,
276 // 2. Nothing in update is present in zone:
280 // Update:
286 // and host update one by one. This is a bit nasty because we actually have to try twice: once assuming
287 // the RR exists, and once assuming it doesn't. If any of the instance updates fail, or the host update
290 // In the cases other than (1) and (2), we can add all the service PTRs in the host update, because they're
291 // only added if the host update succeeds; if it fails, we have to go back and remove all the service
298 // - Try to update assuming everything is there already (case 1)
299 // - Try to update assuming nothing is there already (case 2)
301 // - Try to update assuming it's not there; if this succeeds, add this instance to the list of
303 // - Try to update assuming it is there
305 // - Try to update the host (and also services) assuming the host is not there. If this fails:
306 // - Try to update the host (and also services) assuming the host is there. If this succeeds:
312 // One thing that isn't accounted for here: it's possible that a previous update added some but not all
313 // instances in the current update. Subsequently, some other device may have claimed an instance that is
314 // present but in conflict in the current update. In this case, all of the instances prior to that one
315 // in the update will actually have been updated by this update, but then the update as a whole will fail.
320 construct_update(update_t *update)
323 dns_wire_t *msg = update->update; // Solely to reduce the amount of typing.
331 towire.lim = &msg->data[0] + update->update_max; // This is the limit to how much we can store.
334 // Initialize the update message...
340 // An update always has one question, which is the zone name.
342 name_to_wire(&towire, update->zone_name);
346 switch(update->state) {
348 ERROR("Update construction requested when still connecting.");
349 update->update_length = 0;
352 // Do a DNS Update for a service instance
355 for (instance = update->instances; instance; instance = instance->next) {
356 add_prerequisite(msg, &towire, update_rrset_equals, instance->name, update->host->key);
358 add_prerequisite(msg, &towire, update_rrset_equals, update->host->name, update->host->key);
360 for (instance = update->instances; instance; instance = instance->next) {
363 add_delete(msg, &towire, delete_name, update->host->name);
366 // Now add the update for each instance.
367 for (instance = update->instances; instance; instance = instance->next) {
368 add_rr(msg, &towire, instance->name, update->host->key);
372 // Add the update for each service
373 for (service = update->services; service; service = service->next) {
377 add_rr(msg, &towire, update->host->name, update->host->key);
378 for (host_addr = update->host->addrs; host_addr; host_addr = host_addr->next) {
379 add_rr(msg, &towire, update->host->name, &host_addr->rr);
385 for (instance = update->instances; instance; instance = instance->next) {
388 add_prerequisite(msg, &towire, update_name_not_in_use, update->host->name, (dns_rr_t *)NULL);
393 add_prerequisite(msg, &towire, update_name_not_in_use, update->instance->name, (dns_rr_t *)NULL);
399 add_prerequisite(msg, &towire, update_rrset_equals, update->instance->name, update->host->key);
400 add_delete(msg, &towire, delete_name, update->instance->name);
402 add_rr(msg, &towire, update->instance->name, update->host->key);
403 add_rr(msg, &towire, update->instance->name, update->instance->srv);
404 add_rr(msg, &towire, update->instance->name, update->instance->txt);
408 add_prerequisite(msg, &towire, update_name_not_in_use, update->host->name, (dns_rr_t *)NULL);
412 add_prerequisite(msg, &towire, update_rrset_equals, update->host->name, update->host->key);
413 add_delete(msg, &towire, delete_name, update->host->name);
414 // Add the service PTRs here--these don't need to be in a separate update, because if we get here
416 // Add the update for each service
417 for (service = update->services; service; service = service->next) {
422 add_rr(msg, &towire, update->host->name, update->host->key);
423 for (host_addr = update->host->addrs; host_addr; host_addr = host_addr->next) {
424 add_rr(msg, &towire, update->host->name, &host_addr->rr);
435 for (instance = update->instances; instance; instance = instance->next) {
441 ERROR("construct_update: error %s while generating update at line %d", strerror(towire.error), towire.line);
444 update->update_length = towire.p - (uint8_t *)msg;
449 update_finished(update_t *update, int rcode)
451 comm_t *comm = update->client;
454 INFO("Update Finished, rcode = " PUB_S_SRP, dns_rcode_name(rcode));
457 response.id = update->message->wire.id;
458 response.bitfield = update->message->wire.bitfield;
465 comm->send_response(comm, update->message, &iov, 1);
476 ioloop_close(&update->server->io);
477 update_free(update);
481 update_send(update_t *update)
485 dns_wire_t *msg = update->update;
494 towire.p = (uint8_t *)msg + update->update_length; // We start storing RR data here.
495 towire.lim = &msg->data[0] + update->update_max; // This is the limit to how much we can store.
546 update->update_length = towire.p - (const uint8_t *)msg;
550 ERROR("update_send: error \"%s\" while generating update at line %d",
552 update_finished(update, dns_rcode_servfail);
557 if (!dns_wire_parse(&decoded, msg, update->update_length, false)) {
559 update_finished(update, dns_rcode_servfail);
564 // Transmit the update
565 iov[0].iov_base = update->update;
566 iov[0].iov_len = update->update_length;
567 update->server->send_response(update->server, update->message, iov, 1);
573 update_t *update = comm->context;
575 // Once we're connected, construct the first update.
578 update->state = refresh_existing;
579 if (!construct_update(update)) {
580 update_finished(update, dns_rcode_servfail);
583 update_send(update);
618 update_t *update = comm->context;
620 if (update->state == connect_to_server) {
622 update_finished(update, dns_rcode_servfail);
625 ERROR("%s disconnected during update in state %s: %s",
626 comm->name, update_state_name(update->state), strerror(error));
627 update_finished(update, dns_rcode_servfail);
634 update_t *update = comm->context;
641 initial_instance = update->instance;
642 initial_state = update->state;
645 update_state_name(update->state), dns_rcode_name(dns_rcode_get(wire)));
650 update_finished(update, dns_rcode_servfail);
656 update_finished(update, dns_rcode_servfail);
659 if (update->update == NULL) {
660 ERROR("Received a response from auth server when no update has been sent yet.");
661 update_finished(update, dns_rcode_servfail);
665 if (update->update->id != wire->id) {
666 ERROR("Response doesn't have the expected id: %x != %x.", wire->id, update->update->id);
667 update_finished(update, dns_rcode_servfail);
670 // Handle the case where the update succeeded.
673 switch(update->state) {
677 dns_rcode_name(dns_rcode_get(wire)), update_state_name(update->state));
678 update_finished(update, dns_rcode_servfail);
682 DM_NAME_GEN_SRP(update->host->name, freshly_added_name_buf);
683 INFO("SRP Update for host " PRI_DM_NAME_SRP " was freshly added.",
684 DM_NAME_PARAM_SRP(update->host->name, freshly_added_name_buf));
685 update_finished(update, dns_rcode_noerror);
689 DM_NAME_GEN_SRP(update->host->name, refreshed_name_buf);
690 INFO("SRP Update for host " PRI_DM_NAME_SRP " was refreshed.",
691 DM_NAME_PARAM_SRP(update->host->name, refreshed_name_buf));
692 update_finished(update, dns_rcode_noerror);
696 DM_NAME_GEN_SRP(update->instance->name, create_instance_buf);
698 DM_NAME_PARAM_SRP(update->instance->name, create_instance_buf));
701 for (pinstance = &update->instances; *pinstance != NULL; pinstance = &((*pinstance)->next)) {
702 if (*pinstance == update->instance) {
706 *pinstance = update->instance->next;
707 // If there are no more instances to update, then do the host add.
710 update->state = create_nonexistent_host;
713 update->instance = *pinstance;
718 DM_NAME_GEN_SRP(update->instance->name, refreshed_instance_buf);
720 DM_NAME_PARAM_SRP(update->instance->name, refreshed_instance_buf));
722 // Move on to the next instance to update.
723 update->instance = update->instance->next;
724 // If there are no more instances to update, then do the host add.
725 if (update->instance == NULL) {
727 update->state = create_nonexistent_host;
731 update->state = create_nonexistent_instance;
736 DM_NAME_GEN_SRP(update->instance->name, new_host_buf);
737 INFO("SRP Update for new host " PRI_S_SRP " was successful.",
738 DM_NAME_PARAM_SRP(update->instance->name, new_host_buf));
739 update_finished(update, dns_rcode_noerror);
743 DM_NAME_GEN_SRP(update->instance->name, existing_host_buf);
744 INFO("SRP Update for existing host " PRI_S_SRP " was successful.",
745 DM_NAME_PARAM_SRP(update->instance->name, existing_host_buf));
746 update_finished(update, dns_rcode_noerror);
750 DM_NAME_GEN_SRP(update->host->name, failed_instance_buf);
752 DM_NAME_PARAM_SRP(update->host->name, failed_instance_buf));
753 update_finished(update, update->fail_rcode);
762 switch(update->state) {
777 update->state = create_nonexistent;
778 update->instance = update->instances;
782 // In this case, we tried to update an existing instance and found that the prerequisite
785 // we attempted to update it. We could account for this with an create_nonexistent_instance_again
789 if (update->added_instances != NULL) {
791 update->state = delete_failed_instance;
793 update->instance = update->added_instances;
794 update->fail_rcode = dns_rcode_get(wire);
797 update_finished(update, dns_rcode_get(wire));
806 if (update->added_instances != NULL) {
808 update->state = delete_failed_instance;
811 update_finished(update, dns_rcode_get(wire));
817 switch(update->state) {
831 update->state = create_nonexistent_instance;
832 update->instance = update->instances;
837 update->state = refresh_existing_instance;
842 update->state = refresh_existing_host;
848 ERROR("DNS Authoritative server does not think we are authorized to update it, please fix.");
849 update_finished(update, dns_rcode_servfail);
864 if (update->state != initial_state) {
865 INFO("Update state changed from " PUB_S_SRP " to " PUB_S_SRP, update_state_name(initial_state),
866 update_state_name(update->state));
868 if (update->instance != initial_instance) {
870 DM_NAME_GEN_SRP(update->instance->name, updated_name_buf);
871 INFO("Update instance changed from " PRI_DM_NAME_SRP " to " PRI_DM_NAME_SRP,
873 DM_NAME_PARAM_SRP(update->instance->name, updated_name_buf));
875 if (construct_update(update)) {
876 update_send(update);
878 ERROR("Failed to construct update");
879 update_finished(update, dns_rcode_servfail);
889 update_t *update;
892 update = calloc(1, sizeof *update);
893 if (update == NULL) {
894 ERROR("start_dns_update: unable to allocate update structure!");
898 update->update = calloc(1, DNS_MAX_UDP_PAYLOAD);
899 if (update->update == NULL) {
900 ERROR("start_dns_update: unable to allocate update message buffer.");
903 update->update_max = DNS_DATA_SIZE;
906 update->host = host;
907 update->instances = instance;
908 update->services = service;
909 update->parsed_message = parsed_message;
910 update->message = connection->message;
911 update->state = connect_to_server;
912 update->zone_name = update_zone;
913 update->client = connection;
916 update->server = ioloop_connect(&dns_server, false, true, update_reply_callback,
917 update_connect_callback, update_disconnect_callback, update_finalize, update);
918 if (update->server == NULL) {
919 free(update);