module kea-dhcp-ddns {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:kea-dhcp-ddns";
  prefix "kea-dhcp-ddns";

  import ietf-inet-types {
    prefix inet;
  }
  import kea-types {
    prefix kea;
    revision-date 2018-11-20;
  }
  import kea-logging {
    prefix logging;
    revision-date 2018-11-20;
  }

  organization "Internet Systems Consortium";
  contact "kea-dev@lists.isc.org";
  description "This model defines a YANG data model that can be
    used to configure and manage a Kea DHCP-DDNS server.";

  revision 2018-11-20 {
    description "Initial revision";
    reference "";
  }

  /*
  * Groupings
  */

  grouping managed-domains {
    description "Contains parameters for forward or reverse DDNS managed
      domains.";

    container ddns-domains {
      description "DDNS domains.";
      list ddns-domain {
        key name;
        description "List of DDNS domains.";
        leaf name {
          type string;
          mandatory true;
          description "DDNS domain name.";
        }
        leaf key-name {
          type string;
          description "TSIG key to use. Blank means no TSIG.";
        }
        container dns-servers {
          description "DNS servers.";
          list server {
            key ip-address;
            description "List of DNS servers.";
            leaf hostname {
              type string;
              description "DNS server hostname.";
            }
            leaf ip-address {
              type inet:ip-address;
              mandatory true;
              description "DNS server IP address.";
            }
            leaf port {
              type uint16;
              description "DNS server port.";
            }
            leaf user-context {
              type kea:user-context;
              description "DNS server user context.";
            }
          }
        }
        leaf user-context {
          type kea:user-context;
          description "DDNS domain user context.";
        }
      }
    }
  }

  /*
  * Data Nodes
  */

  container config {
    // config true;
    description "Contains DHCP-DDNS server configuration.";

    leaf ip-address {
      type inet:ip-address;
      description "IP address on which the server listens for requests.";
    }

    leaf port {
      type uint16;
      description "Port on which the server listens for requests.";
    }

    leaf dns-server-timeout {
      type uint32;
      units "milliseconds";
      description "Maximum amount of time that the server will wait for
        a response from a DNS server to a single DNS update message.";
    }

    leaf ncr-protocol {
      type enumeration {
        enum "UDP" {
          description "UDP transport";
        }
        enum "TCP" {
          description "TCP transport";
        }
      }
      description "Protocol to use when sending requests to the server.";
    }

    leaf ncr-format {
      type enumeration {
        enum "JSON" {
          description "JSON format";
        }
      }
      description "Packet format to use when sending requests to the server.";
    }

    container forward-ddns {
      description "Forward DNS zones.";
      uses managed-domains;
    }

    container reverse-ddns {
      description "Reverse DNS zones.";
      uses managed-domains;
    }

    container tsig-keys {
      description "Keys to use with TSIG.";
      list key {
        key name;
        description "List of TSIG keys.";
        leaf name {
          type string;
          mandatory true;
          description "Key name.";
        }
        leaf algorithm {
          type string;
          mandatory true;
          description "Hashing algorithm to use with the key.";
        }
        leaf digest-bits {
           type uint16;
           units "bits";
           description "Minimum truncated length. 0 means no truncation.";
        }
        leaf secret {
          type string;
          mandatory true;
          description "Shared secret for the key.";
        }
        leaf user-context {
          type kea:user-context;
          description "Key user context.";
        }
      }
    }
    leaf user-context {
      type kea:user-context;
      description "DHCP-DDNS server user context.";
    }

    // Moved from logging
    uses logging:loggers;
  }
}
