// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package envoy.extensions.network.dns_resolver.cares.v3;

import "envoy/config/core/v3/address.proto";
import "envoy/config/core/v3/resolver.proto";

import "google/protobuf/wrappers.proto";

import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.network.dns_resolver.cares.v3";
option java_outer_classname = "CaresDnsResolverProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/network/dns_resolver/cares/v3;caresv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: c-ares DNS resolver]
// [#extension: envoy.network.dns_resolver.cares]

// Configuration for c-ares DNS resolver.
// [#next-free-field: 9]
message CaresDnsResolverConfig {
  // A list of DNS resolver addresses.
  // :ref:`use_resolvers_as_fallback <envoy_v3_api_field_extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig.use_resolvers_as_fallback>`
  // below dictates if the DNS client should override system defaults or only use the provided
  // resolvers if the system defaults are not available, i.e., as a fallback.
  repeated config.core.v3.Address resolvers = 1;

  // If true use the resolvers listed in the
  // :ref:`resolvers <envoy_v3_api_field_extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig.resolvers>`
  // field only if c-ares is unable to obtain a
  // nameserver from the system (e.g., ``/etc/resolv.conf``).
  // Otherwise, the resolvers listed in the resolvers list will override the default system
  // resolvers. Defaults to false.
  bool use_resolvers_as_fallback = 3;

  // The resolver will query available network interfaces and determine if there are no available
  // interfaces for a given IP family. It will then filter these addresses from the results it
  // presents. e.g., if there are no available IPv4 network interfaces, the resolver will not
  // provide IPv4 addresses.
  bool filter_unroutable_families = 4;

  // Configuration of DNS resolver option flags which control the behavior of the DNS resolver.
  config.core.v3.DnsResolverOptions dns_resolver_options = 2;

  // This option allows the number of UDP based DNS queries to be capped.
  //
  // .. note::
  //   This is only applicable to c-ares DNS resolver currently.
  //
  google.protobuf.UInt32Value udp_max_queries = 5;

  // The number of seconds each name server is given to respond to a query on the first try of any given server.
  //
  // .. note::
  //   While the c-ares library defaults to 2 seconds, Envoy's default (if this field is unset) is 5 seconds.
  //   This adjustment was made to maintain the previous behavior after users reported an increase in DNS resolution times.
  //
  google.protobuf.UInt64Value query_timeout_seconds = 6 [(validate.rules).uint64 = {gte: 1}];

  // The maximum number of query attempts the resolver will make before giving up.
  // Each attempt may use a different name server.
  //
  // .. note::
  //   While the c-ares library defaults to 3 attempts, Envoy's default (if this field is unset) is 4 attempts.
  //   This adjustment was made to maintain the previous behavior after users reported an increase in DNS resolution times.
  //
  google.protobuf.UInt32Value query_tries = 7 [(validate.rules).uint32 = {gte: 1}];

  // Enable round-robin selection of name servers for DNS resolution. When enabled, the resolver will cycle through the
  // list of name servers for each resolution request. This can help distribute the query load across multiple name
  // servers. If disabled (default), the resolver will try name servers in the order they are configured.
  //
  // .. note::
  //   This setting overrides any system configuration for name server rotation.
  //
  bool rotate_nameservers = 8;
}
