Home | History | Annotate | Line # | Download | only in ServiceRegistration
      1 /* srp-gw.c
      2  *
      3  * Copyright (c) 2019-2022 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  *     https://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  * Structure definitions for the Service Registration Protocol gateway.
     18  */
     19 
     20 #ifndef SRP_GW_H
     21 #define SRP_GW_H
     22 typedef struct subnet subnet_t;
     23 struct subnet {
     24     subnet_t *NULLABLE next;
     25     uint8_t preflen;
     26     uint8_t family;
     27     char bytes[8];
     28 };
     29 
     30 typedef struct udp_validator udp_validator_t;
     31 struct udp_validator {
     32     udp_validator_t *NULLABLE next;
     33     char *NONNULL ifname;
     34     int ifindex;
     35     subnet_t *NONNULL subnets;
     36 };
     37 
     38 typedef struct delete delete_t;
     39 struct delete {
     40     delete_t *NULLABLE next;
     41     dns_name_t *NONNULL name;
     42     dns_name_t *NONNULL zone;
     43     bool consumed;
     44 };
     45 
     46 typedef struct host_addr host_addr_t;
     47 struct host_addr {
     48     host_addr_t *NULLABLE next;
     49     dns_rr_t rr;
     50 };
     51 typedef struct dns_host_description dns_host_description_t;
     52 struct dns_host_description {
     53     dns_name_t *NONNULL name;
     54     host_addr_t *NULLABLE addrs;
     55     dns_rr_t *NULLABLE key;
     56     delete_t *NULLABLE delete;
     57     int num_instances;
     58 };
     59 
     60 typedef struct service service_t;
     61 struct service {
     62     service_t *NULLABLE next;
     63     service_t *NULLABLE base_type; // A pointer back in the list, or to self
     64     dns_rr_t *NONNULL rr; // The service name is rr->name.
     65     dns_name_t *NONNULL zone;
     66 };
     67 
     68 typedef struct service_instance service_instance_t;
     69 struct service_instance {
     70     service_instance_t *NULLABLE next;
     71     dns_host_description_t *NULLABLE host;
     72     dns_name_t *NONNULL name;
     73     delete_t *NULLABLE delete;
     74     service_t *NONNULL service;
     75     int num_instances;
     76     dns_rr_t *NULLABLE srv, *NULLABLE txt;
     77     bool skip_update;
     78 };
     79 
     80 // The update_t structure is used to maintain the ongoing state of a particular DNS Update.
     81 
     82 typedef enum update_state update_state_t;
     83 enum update_state {
     84     connect_to_server,              // Establish a connection with the auth server.
     85     create_nonexistent,             // Update service instance assuming it's not already there (case 1).
     86     refresh_existing,               // Update service instance assuming it's already there and the same (case 2).
     87     create_nonexistent_instance,    // Update service instance assuming it's not there
     88     refresh_existing_instance,      // Update host assuming it's there and the same
     89     create_nonexistent_host,        // Update a host that's not present (and also the services)
     90     refresh_existing_host,          // Update a host that's present (and also the services)
     91     delete_failed_instance,         // The update failed, so delete service instances that were successfully added.
     92 };
     93 
     94 typedef enum update_event update_event_t;
     95 enum update_event {
     96     update_event_connected,
     97     update_event_disconnected,
     98     update_event_response_received
     99 };
    100 
    101 typedef struct update update_t;
    102 struct update {
    103     comm_t *NONNULL server;                       // Connection to authoritative server
    104     comm_t *NONNULL client;                       // Connection to SRP client (which might just be a UDP socket).
    105     update_state_t state;
    106     dns_host_description_t *NONNULL host;
    107     service_instance_t *NONNULL instances;
    108     service_instance_t *NULLABLE instance;        // If we are updating instances one at a time.
    109     service_instance_t *NULLABLE added_instances; // Instances we have successfully added.
    110     service_t *NONNULL services;
    111     dns_name_t *NULLABLE zone_name;               // If NULL, we are processing an update for services.arpa.
    112     message_t *NONNULL message;
    113     dns_message_t *NONNULL parsed_message;
    114     dns_wire_t *NONNULL update;                   // The current update...
    115     size_t update_length;
    116     size_t update_max;
    117     uint8_t fail_rcode;                           // rcode to return after deleting added service instances.
    118 };
    119 #endif  //SRP_GW_H
    120 // Local Variables:
    121 // mode: C
    122 // tab-width: 4
    123 // c-file-style: "bsd"
    124 // c-basic-offset: 4
    125 // fill-column: 108
    126 // indent-tabs-mode: nil
    127 // End:
    128