// !! This file has been generated by dnsdist-settings-generator.py, do not edit by hand!!
// START INCLUDE dnsdist-configuration-yaml-items-pre-in.cc
/*
 * This file is part of PowerDNS or dnsdist.
 * Copyright -- PowerDNS.COM B.V. and its contributors
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * In addition, for the avoidance of any doubt, permission is granted to
 * link this program with OpenSSL and to (re)distribute the binaries
 * produced as the result of such linking.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "dnsdist-configuration.hh"
#include "dnsdist-configuration-yaml.hh"
// END INCLUDE dnsdist-configuration-yaml-items-pre-in.cc
#if defined(HAVE_YAML_CONFIGURATION)
#include "rust/cxx.h"
#include "rust/lib.rs.h"
#include "dnsdist-configuration-yaml-internal.hh"

namespace dnsdist::configuration::yaml
{
void convertRuntimeFlatSettingsFromRust(const dnsdist::rust::settings::GlobalConfiguration& yamlConfig, dnsdist::configuration::RuntimeConfiguration& config)
{
  if (config.d_consoleOutputMsgMaxSize == 10000000) {
    config.d_consoleOutputMsgMaxSize = yamlConfig.console.maximum_output_size;
  }
  if (config.d_logConsoleConnections == true) {
    config.d_logConsoleConnections = yamlConfig.console.log_connections;
  }
  if (config.d_ecsOverride == false) {
    config.d_ecsOverride = yamlConfig.edns_client_subnet.override_existing;
  }
  if (config.d_ECSSourcePrefixV4 == 32) {
    config.d_ECSSourcePrefixV4 = yamlConfig.edns_client_subnet.source_prefix_v4;
  }
  if (config.d_ECSSourcePrefixV6 == 56) {
    config.d_ECSSourcePrefixV6 = yamlConfig.edns_client_subnet.source_prefix_v6;
  }
  if (config.d_dynBlocksPurgeInterval == 60) {
    config.d_dynBlocksPurgeInterval = yamlConfig.dynamic_rules_settings.purge_interval;
  }
  if (config.d_tcpRecvTimeout == 2) {
    config.d_tcpRecvTimeout = yamlConfig.tuning.tcp.receive_timeout;
  }
  if (config.d_tcpSendTimeout == 2) {
    config.d_tcpSendTimeout = yamlConfig.tuning.tcp.send_timeout;
  }
  if (config.d_maxTCPQueriesPerConn == 0) {
    config.d_maxTCPQueriesPerConn = yamlConfig.tuning.tcp.max_queries_per_connection;
  }
  if (config.d_maxTCPConnectionDuration == 0) {
    config.d_maxTCPConnectionDuration = yamlConfig.tuning.tcp.max_connection_duration;
  }
  if (config.d_tlsSessionCacheCleanupDelay == 60) {
    config.d_tlsSessionCacheCleanupDelay = yamlConfig.tuning.tls.outgoing_tickets_cache_cleanup_delay;
  }
  if (config.d_tlsSessionCacheSessionValidity == 600) {
    config.d_tlsSessionCacheSessionValidity = yamlConfig.tuning.tls.outgoing_tickets_cache_validity;
  }
  if (config.d_tlsSessionCacheMaxSessionsPerBackend == 20) {
    config.d_tlsSessionCacheMaxSessionsPerBackend = yamlConfig.tuning.tls.max_outgoing_tickets_per_backend;
  }
  if (config.d_staleCacheEntriesTTL == 0) {
    config.d_staleCacheEntriesTTL = yamlConfig.cache_settings.stale_entries_ttl;
  }
  if (config.d_cacheCleaningDelay == 60) {
    config.d_cacheCleaningDelay = yamlConfig.cache_settings.cleaning_delay;
  }
  if (config.d_cacheCleaningPercentage == 100) {
    config.d_cacheCleaningPercentage = yamlConfig.cache_settings.cleaning_percentage;
  }
  if (config.d_secPollInterval == 3600) {
    config.d_secPollInterval = yamlConfig.security_polling.polling_interval;
  }
  if (config.d_secPollSuffix == "secpoll.powerdns.com.") {
    config.d_secPollSuffix = std::string(yamlConfig.security_polling.suffix);
  }
  if (config.d_verbose == false) {
    config.d_verbose = yamlConfig.logging.verbose;
  }
  if (config.d_verboseHealthChecks == false) {
    config.d_verboseHealthChecks = yamlConfig.logging.verbose_health_checks;
  }
  if (config.d_openTelemetryTracing == false) {
    config.d_openTelemetryTracing = yamlConfig.logging.open_telemetry_tracing;
  }
  if (config.d_payloadSizeSelfGenAnswers == 1232) {
    config.d_payloadSizeSelfGenAnswers = yamlConfig.general.edns_udp_payload_size_self_generated_answers;
  }
  if (config.d_addEDNSToSelfGeneratedResponses == true) {
    config.d_addEDNSToSelfGeneratedResponses = yamlConfig.general.add_edns_to_self_generated_answers;
  }
  if (config.d_truncateTC == false) {
    config.d_truncateTC = yamlConfig.general.truncate_tc_answers;
  }
  if (config.d_fixupCase == false) {
    config.d_fixupCase = yamlConfig.general.fixup_case;
  }
  if (config.d_allowEmptyResponse == false) {
    config.d_allowEmptyResponse = yamlConfig.general.allow_empty_responses;
  }
  if (config.d_dropEmptyQueries == false) {
    config.d_dropEmptyQueries = yamlConfig.general.drop_empty_queries;
  }
  if (config.d_proxyProtocolMaximumSize == 512) {
    config.d_proxyProtocolMaximumSize = yamlConfig.proxy_protocol.maximum_payload_size;
  }
  if (config.d_applyACLToProxiedClients == false) {
    config.d_applyACLToProxiedClients = yamlConfig.proxy_protocol.apply_acl_to_proxied_clients;
  }
  if (config.d_servFailOnNoPolicy == false) {
    config.d_servFailOnNoPolicy = yamlConfig.load_balancing_policies.servfail_on_no_server;
  }
  if (config.d_roundrobinFailOnNoServer == false) {
    config.d_roundrobinFailOnNoServer = yamlConfig.load_balancing_policies.round_robin_servfail_on_no_server;
  }
}
void convertImmutableFlatSettingsFromRust(const dnsdist::rust::settings::GlobalConfiguration& yamlConfig, dnsdist::configuration::ImmutableConfiguration& config)
{
  if (config.d_consoleMaxConcurrentConnections == 0) {
    config.d_consoleMaxConcurrentConnections = yamlConfig.console.max_concurrent_connections;
  }
  if (config.d_ringsCapacity == 10000) {
    config.d_ringsCapacity = yamlConfig.ring_buffers.size;
  }
  if (config.d_ringsNumberOfShards == 10) {
    config.d_ringsNumberOfShards = yamlConfig.ring_buffers.shards;
  }
  if (config.d_ringsNbLockTries == 5) {
    config.d_ringsNbLockTries = yamlConfig.ring_buffers.lock_retries;
  }
  if (config.d_ringsRecordQueries == true) {
    config.d_ringsRecordQueries = yamlConfig.ring_buffers.record_queries;
  }
  if (config.d_ringsRecordResponses == true) {
    config.d_ringsRecordResponses = yamlConfig.ring_buffers.record_responses;
  }
  if (config.d_ringsSamplingRate == 0) {
    config.d_ringsSamplingRate = yamlConfig.ring_buffers.sampling_rate;
  }
  if (config.d_maxTCPClientThreads == 10) {
    config.d_maxTCPClientThreads = yamlConfig.tuning.tcp.worker_threads;
  }
  if (config.d_maxTCPQueuedConnections == 10000) {
    config.d_maxTCPQueuedConnections = yamlConfig.tuning.tcp.max_queued_connections;
  }
  if (config.d_tcpInternalPipeBufferSize == 1048576) {
    config.d_tcpInternalPipeBufferSize = yamlConfig.tuning.tcp.internal_pipe_buffer_size;
  }
  if (config.d_outgoingTCPMaxIdleTime == 300) {
    config.d_outgoingTCPMaxIdleTime = yamlConfig.tuning.tcp.outgoing_max_idle_time;
  }
  if (config.d_outgoingTCPCleanupInterval == 60) {
    config.d_outgoingTCPCleanupInterval = yamlConfig.tuning.tcp.outgoing_cleanup_interval;
  }
  if (config.d_outgoingTCPMaxIdlePerBackend == 10) {
    config.d_outgoingTCPMaxIdlePerBackend = yamlConfig.tuning.tcp.outgoing_max_idle_connection_per_backend;
  }
  if (config.d_maxTCPConnectionsPerClient == 0) {
    config.d_maxTCPConnectionsPerClient = yamlConfig.tuning.tcp.max_connections_per_client;
  }
  if (config.d_tcpConnectionsOverloadThreshold == 90) {
    config.d_tcpConnectionsOverloadThreshold = yamlConfig.tuning.tcp.connections_overload_threshold;
  }
  if (config.d_maxTCPConnectionsRatePerClient == 0) {
    config.d_maxTCPConnectionsRatePerClient = yamlConfig.tuning.tcp.max_connection_rate_per_client;
  }
  if (config.d_tcpConnectionsRatePerClientInterval == 5) {
    config.d_tcpConnectionsRatePerClientInterval = yamlConfig.tuning.tcp.connection_rate_interval;
  }
  if (config.d_maxTLSNewSessionsRatePerClient == 0) {
    config.d_maxTLSNewSessionsRatePerClient = yamlConfig.tuning.tcp.max_tls_new_session_rate_per_client;
  }
  if (config.d_maxTLSResumedSessionsRatePerClient == 0) {
    config.d_maxTLSResumedSessionsRatePerClient = yamlConfig.tuning.tcp.max_tls_resumed_session_rate_per_client;
  }
  if (config.d_maxTCPReadIOsPerQuery == 50) {
    config.d_maxTCPReadIOsPerQuery = yamlConfig.tuning.tcp.max_read_ios_per_query;
  }
  if (config.d_tcpBanDurationForExceedingMaxReadIOsPerQuery == 60) {
    config.d_tcpBanDurationForExceedingMaxReadIOsPerQuery = yamlConfig.tuning.tcp.ban_duration_for_exceeding_max_read_ios_per_query;
  }
  if (config.d_tcpBanDurationForExceedingTCPTLSRate == 10) {
    config.d_tcpBanDurationForExceedingTCPTLSRate = yamlConfig.tuning.tcp.ban_duration_for_exceeding_tcp_tls_rate;
  }
  if (config.d_tcpConnectionsMaskV4 == 32) {
    config.d_tcpConnectionsMaskV4 = yamlConfig.tuning.tcp.connections_mask_v4;
  }
  if (config.d_tcpConnectionsMaskV6 == 128) {
    config.d_tcpConnectionsMaskV6 = yamlConfig.tuning.tcp.connections_mask_v6;
  }
  if (config.d_tcpConnectionsMaskV4Port == 0) {
    config.d_tcpConnectionsMaskV4Port = yamlConfig.tuning.tcp.connections_mask_v4_port;
  }
  if (config.d_udpVectorSize == 1) {
    config.d_udpVectorSize = yamlConfig.tuning.udp.messages_per_round;
  }
  if (config.d_socketUDPSendBuffer == 0) {
    config.d_socketUDPSendBuffer = yamlConfig.tuning.udp.send_buffer_size;
  }
  if (config.d_socketUDPRecvBuffer == 0) {
    config.d_socketUDPRecvBuffer = yamlConfig.tuning.udp.receive_buffer_size;
  }
  if (config.d_maxUDPOutstanding == 65535) {
    config.d_maxUDPOutstanding = yamlConfig.tuning.udp.max_outstanding_per_backend;
  }
  if (config.d_udpTimeout == 2) {
    config.d_udpTimeout = yamlConfig.tuning.udp.timeout;
  }
  if (config.d_randomizeUDPSocketsToBackend == false) {
    config.d_randomizeUDPSocketsToBackend = yamlConfig.tuning.udp.randomize_outgoing_sockets_to_backend;
  }
  if (config.d_randomizeIDsToBackend == false) {
    config.d_randomizeIDsToBackend = yamlConfig.tuning.udp.randomize_ids_to_backend;
  }
  if (config.d_outgoingDoHWorkers == 10) {
    config.d_outgoingDoHWorkers = yamlConfig.tuning.doh.outgoing_worker_threads;
  }
  if (config.d_outgoingDoHMaxIdleTime == 300) {
    config.d_outgoingDoHMaxIdleTime = yamlConfig.tuning.doh.outgoing_max_idle_time;
  }
  if (config.d_outgoingDoHCleanupInterval == 60) {
    config.d_outgoingDoHCleanupInterval = yamlConfig.tuning.doh.outgoing_cleanup_interval;
  }
  if (config.d_outgoingDoHMaxIdlePerBackend == 10) {
    config.d_outgoingDoHMaxIdlePerBackend = yamlConfig.tuning.doh.outgoing_max_idle_connection_per_backend;
  }
  if (config.d_snmpEnabled == false) {
    config.d_snmpEnabled = yamlConfig.snmp.enabled;
  }
  if (config.d_snmpTrapsEnabled == false) {
    config.d_snmpTrapsEnabled = yamlConfig.snmp.traps_enabled;
  }
  if (config.d_snmpDaemonSocketPath == "") {
    config.d_snmpDaemonSocketPath = std::string(yamlConfig.snmp.daemon_socket);
  }
  if (config.d_weightedBalancingFactor == 0.0) {
    config.d_weightedBalancingFactor = yamlConfig.load_balancing_policies.weighted_balancing_factor;
  }
  if (config.d_consistentHashBalancingFactor == 0.0) {
    config.d_consistentHashBalancingFactor = yamlConfig.load_balancing_policies.consistent_hashing_balancing_factor;
  }
  if (config.d_hashPerturbation == 0) {
    config.d_hashPerturbation = yamlConfig.load_balancing_policies.hash_perturbation;
  }
}

}
#endif /* defined(HAVE_YAML_CONFIGURATION) */
