1 /* srp-mdns-proxy.h 2 * 3 * Copyright (c) 2019 Apple Computer, Inc. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * This file contains structure definitions used by the SRP Advertising Proxy. 18 */ 19 20 typedef struct adv_instance adv_instance_t; 21 typedef struct adv_address_registration adv_address_t; 22 typedef struct adv_host adv_host_t; 23 typedef struct adv_update adv_update_t; 24 typedef struct client_update client_update_t; 25 typedef struct adv_instance_vec adv_instance_vec_t; 26 typedef struct adv_host_vec adv_host_vec_t; 27 typedef struct adv_address_vec adv_address_vec_t; 28 29 30 struct adv_instance { 31 int ref_count; 32 dnssd_txn_t *NULLABLE txn; // Outstanding mDNSServiceRegister transaction, if any. 33 adv_host_t *NONNULL host; // Host to which this service instance belongs 34 adv_update_t *NULLABLE update; // Ongoing update that currently owns this instance, if any. 35 char *NONNULL instance_name; // Single label instance name (future: service instance FQDN) 36 char *NONNULL service_type; // Two label service type (e.g., _ipps._tcp) 37 int port; // Port on which service can be found. 38 char *NULLABLE txt_data; // Contents of txt record 39 uint16_t txt_length; // length of txt record contents 40 }; 41 42 // An address registration 43 struct adv_address_registration { 44 int ref_count; 45 // dnssd_txn_t *txn; // The registration 46 adv_host_t *NONNULL host; // The host this record belongs to 47 uint16_t rrtype; // A or AAAA 48 uint16_t rdlen; // 4 or 16 49 uint8_t rdata[16]; // Room for either IPv4 or IPv6 address 50 }; 51 52 struct adv_host { 53 int ref_count; 54 wakeup_t *NONNULL retry_wakeup; // Wakeup for retry when we run into a temporary failure 55 wakeup_t *NONNULL lease_wakeup; // Wakeup at least expiry time 56 dnssd_txn_t *NULLABLE txn; // dnssd transaction for host RR 57 adv_host_t *NULLABLE next; // Hosts are maintained in a linked list. 58 adv_update_t *NULLABLE updates; // Updates to this host, if any 59 client_update_t *NULLABLE clients; // Updates that clients have sent for which replies have not yet been sent. 60 char *NONNULL name; // Name of host (without domain) 61 char *NONNULL registered_name; // The name that is registered, which may be different due to mDNS conflict 62 int name_serial; // The number we are using to disambiguate the name. 63 int num_addresses; // Number of addresses registered (we only actually support one) 64 adv_address_t *NULLABLE *NULLABLE addresses; // One or more addresses 65 adv_instance_vec_t *NONNULL instances; // Zero or more service instances. 66 DNSRecordRef NULLABLE rref; // Record reference for key or address. 67 dns_rr_t key; // The key data represented as an RR; key->name is NULL. 68 uint32_t key_id; // A possibly-unique id that is computed across the key for brevity in 69 // debugging 70 int retry_interval; // Interval to wait before attempting to re-register after the daemon has 71 // died. 72 uint16_t key_rdlen; // Length of key 73 uint8_t *NONNULL key_rdata; // Raw KEY rdata, suitable for DNSServiceRegisterRecord(). 74 uint32_t lease_interval; // Interval for address lease 75 uint32_t key_lease; // Interval for key lease 76 int64_t lease_expiry; // Time when lease expires, relative to ioloop_timenow(). 77 bool have_registration; // True if we've registered a key or address record for the host. 78 79 // True if we have a pending late conflict resolution. If we get a conflict after the update for the 80 // host registration has expired, and there happens to be another update in progress, then we want 81 // to defer the host registration. 82 bool hostname_update_pending; 83 }; 84 85 struct adv_update { 86 adv_host_t *NONNULL host; // Host being updated 87 88 // Ordinarily NULL, but may be non-NULL if we lost the server during an update and had 89 // to construct an update to re-add the host. 90 adv_update_t *NULLABLE next; 91 92 // Connection state, if applicable, of the client request that produced this update. 93 client_update_t *NULLABLE client; 94 int num_outstanding_updates; // Total count updates that have been issued but not yet confirmed. 95 96 // Addresses to apply to the host. At present only one address is ever advertised, but we remember all the 97 // addresses that were registered. 98 int num_remove_addresses; 99 adv_address_t *NULLABLE *NULLABLE remove_addresses; 100 int num_add_addresses; 101 adv_address_t *NULLABLE *NONNULL add_addresses; 102 103 // If non-null, this update is changing the advertised address of the host to the referenced address. 104 adv_address_t *NULLABLE selected_addr; 105 106 // The set of instances from the update that already exist but have changed. 107 // This array mirrors the array of instances configured on the host; entries to be updated 108 // are non-NULL, entries that don't need updated are NULL. 109 adv_instance_vec_t *NONNULL update_instances; 110 111 // The set of instances that exist and need to be removed. 112 adv_instance_vec_t *NONNULL remove_instances; 113 114 // The set of instances that need to be added. 115 adv_instance_vec_t *NONNULL add_instances; 116 117 // Outstanding instance updates 118 int num_instances_started; 119 int num_instances_completed; 120 121 // Lease intervals for host entry and key entry. 122 uint32_t host_lease, key_lease; 123 124 // If nonzero, this is an explicit expiry time for the lease, because the update is restoring 125 // a host after a server restart, or else renaming a host after a late name conflict. In this 126 // case, we do not want to extend the lease--just get the host registration right. 127 uint64_t lease_expiry; 128 129 // True if we are registering the key to hold the hostname. 130 bool registering_key; 131 }; 132 133 struct adv_instance_vec { 134 int ref_count; 135 int num; 136 adv_instance_t * NULLABLE *NONNULL vec; 137 }; 138 139 struct adv_host_vec { 140 int ref_count; 141 int num; 142 adv_host_t * NULLABLE *NONNULL vec; 143 }; 144 145 struct adv_address_vec { 146 int ref_count; 147 int num; 148 adv_address_t * NULLABLE *NONNULL vec; 149 }; 150 151 struct client_update { 152 client_update_t *NULLABLE next; 153 comm_t *NONNULL connection; // Connection on which in-process update was received. 154 dns_message_t *NONNULL parsed_message; // Message that triggered the update. 155 message_t *NONNULL message; // Message that triggered the update. 156 157 dns_host_description_t *NONNULL host; // Host data parsed from message 158 service_instance_t *NULLABLE instances; // Service instances parsed from message 159 service_t *NONNULL services; // Services parsed from message 160 dns_name_t *NONNULL update_zone; // Zone being updated 161 uint32_t host_lease, key_lease; // Lease intervals for host entry and key entry. 162 }; 163 164 // Local Variables: 165 // mode: C 166 // tab-width: 4 167 // c-file-style: "bsd" 168 // c-basic-offset: 4 169 // fill-column: 120 170 // indent-tabs-mode: nil 171 // End: 172