# Copyright (c) 2016 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

config DNS_RESOLVER
	bool "DNS resolver"
	depends on NET_NATIVE
	select NET_SOCKETS
	select NET_SOCKETS_SERVICE
	select CRC
	help
	  This option enables the DNS client side support for Zephyr

if DNS_RESOLVER

config DNS_RESOLVER_AUTO_INIT
	bool "Automatically initialize the default DNS context"
	default y
	help
	  Automatically initialize the default DNS context so dns_resolve_init
	  does not need to be manually called.

config MDNS_RESOLVER
	bool "MDNS support"
	select NET_MGMT
	select NET_MGMT_EVENT
	help
	  This option enables multicast DNS client side support.
	  See RFC 6762 for details.

	  When the mDNS responder is not enabled, the resolver joins the mDNS
	  multicast groups itself and needs the network management events to
	  rejoin them if an interface goes down and comes back up.

config LLMNR_RESOLVER
	bool "LLMNR support [DEPRECATED]"
	select DEPRECATED
	help
	  This option enables link local multicast name resolution client side
	  support. See RFC 4795 for details. LLMNR is typically used by Windows
	  hosts. If you enable this option, then single-label queries are sent
	  to the LLMNR well known multicast address 224.0.0.252:5355 or
	  [ff02::1:3]:5355. Queries containing dots continue using the
	  configured DNS servers.

	  LLMNR is being phased out (Microsoft is retiring it) and this option
	  is deprecated and will be removed in a future release. Use mDNS
	  (CONFIG_MDNS_RESOLVER) or unicast DNS instead.

config DNS_RESOLVER_ADDITIONAL_QUERIES
	int "Additional DNS queries"
	range 0 2
	default 1
	help
	  Number of additional DNS queries that the DNS resolver may
	  generate when the RR ANSWER only contains CNAME(s).
	  The maximum value of this variable is constrained to avoid
	  'alias loops'.

config DNS_RESOLVER_AI_MAX_ENTRIES
	int "Maximum number of IP addresses for DNS name"
	default 2
	help
	  Defines the max number of IP addresses per domain name
	  resolution the DNS resolver can handle.

config DNS_RESOLVER_MAX_ANSWER_SIZE
	int "Max length of a DNS answer"
	range 1 $(UINT16_MAX)
	default 512
	help
	  Max length of the returned DNS answer we can process.
	  Recommended value by RFC 1035 is 512 bytes.

config DNS_RESOLVER_MAX_QUERY_LEN
	int "Max length of a DNS query"
	range 1 $(UINT8_MAX)
	default $(UINT8_MAX)
	help
	  Max length of a DNS query that should be looked up including the
	  trailing 0. So e.g. "example.com" would have a query len of 12.

config DNS_RESOLVER_MAX_NAME_LEN
	int "Max length of the resolved DNS name"
	range 1 $(UINT8_MAX)
	default 128 if DNS_SD
	default 46 if NET_IPV6
	default 20
	help
	  Max length of a buffer that is used to store information returned from
	  DNS server. For example if we query a DNS-SD service, then this value should
	  be long enough to store the returned string.

config DNS_RESOLVER_MAX_TEXT_LEN
	int "Max length of the resolved DNS text string in a record"
	range 1 $(UINT8_MAX)
	default 255 if DNS_SD
	default 64
	help
	  Max length of a buffer that is used to store text record string
	  returned from a DNS server.

menuconfig DNS_SERVER_IP_ADDRESSES
	bool "Set DNS server IP addresses"
	help
	  Allow DNS IP addresses to be set in config file for
	  networking applications.

if DNS_SERVER_IP_ADDRESSES

config DNS_SERVER1
	string "DNS server 1"
	help
	  DNS server IP address 1. The address can be either IPv4 or IPv6
	  address. An optional port number can be given.
	  Following syntax is supported:
	  192.0.2.1
	  192.0.2.1:5353
	  2001:db8::1
	  [2001:db8::1]:5353
	  It is possible to bind the DNS connection via a certain network
	  interface by appending "%" and network interface name to the server
	  address. For example: 192.0.2.1%eth1 would bind the connection socket
	  to the network interface eth1. This is optional and by default the
	  resolver connects to server by selecting the output network interface
	  using normal IP routing.
	  It is not mandatory to use this Kconfig option at all.
	  The one calling dns_resolve_init() can use this option or not
	  to populate the server list. If the DNS server addresses are
	  set here, then we automatically create default DNS context
	  for the user.

config DNS_SERVER2
	string "DNS server 2"
	help
	  See help in "DNS server 1" option.

config DNS_SERVER3
	string "DNS server 3"
	help
	  See help in "DNS server 1" option.

config DNS_SERVER4
	string "DNS server 4"
	help
	  See help in "DNS server 1" option.

config DNS_SERVER5
	string "DNS server 5"
	help
	  See help in "DNS server 1" option.

endif # DNS_SERVER_IP_ADDRESSES

config DNS_RECONFIGURE_CLEANUP
	bool "Cleanup old DNS server entries when reconfiguring"
	help
	  If calling dns_resolve_reconfigure() when new DNS servers
	  are being set, for example if receiving new ones from DHCP server,
	  remove the old entries before setting up the new ones.
	  If you have only one network interface, then this can be enabled.
	  If you have multiple network interfaces, then this should be disabled
	  because the later configuration update would remove the entries
	  set by the other network interface configuration.
	  The previous default in Zephyr 4.1 or earlier was to have this enabled.
	  The current default in Zephyr 4.2 is to disable this option.

config DNS_NUM_CONCUR_QUERIES
	int "Number of simultaneous DNS queries per one DNS context"
	default 1
	help
	  This defines how many concurrent DNS queries can be generated using
	  same DNS context. Normally 1 is a good default value.

module = DNS_RESOLVER
module-dep = NET_LOG
module-str = Log level for DNS resolver
module-help = Enables DNS resolver code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"

menuconfig DNS_RESOLVER_CACHE
	bool "DNS resolver cache"
	help
	   This option enables the dns resolver cache. DNS queries
	   will be cached based on TTL and delivered from cache
	   whenever possible. This reduces network usage.

if DNS_RESOLVER_CACHE

config DNS_RESOLVER_CACHE_MAX_ENTRIES
	int "Number of cache entries supported by the dns cache"
	default 6
	help
	  This defines how many entries the DNS cache can hold. If
	  not enough entries for caching are available the oldest
	  entry gets replaced. Adjusting this value will affect
	  RAM usage.

endif # DNS_RESOLVER_CACHE

config DNS_RESOLVER_PACKET_FORWARDING
	bool "Forwards received DNS packets to application"
	depends on !DNS_RESOLVER_CACHE
	help
	  This allows forwarding of received packets from DNS servers
	  to applications that register the forwarding callback.

config DNS_RESOLVER_PRIVATE_RR_SUPPORT
	bool "Support for private DNS resource records"
	help
	  Enable support for private DNS resource records (types 65280-65534).
	  Private RR types can be used for custom DNS record types.

config DNS_RESOLVER_MAX_PRIVATE_DATA_LEN
	int "Maximum size of private RR data"
	range 1 DNS_RESOLVER_MAX_ANSWER_SIZE
	default 512 if DNS_RESOLVER_PRIVATE_RR_SUPPORT
	default 128
	help
	  Maximum size in bytes for private DNS resource record data.

config DNS_RESOLVER_QUERY_ALL_AVAILABLE_SERVERS
	bool "Send DNS queries to all configured servers"
	help
	  When enabled, DNS queries will be sent to all available DNS servers
	  simultaneously. The first successful response received will be used.
	  This can improve reliability and response time when multiple DNS
	  servers are configured, but will increase network traffic.
	  When disabled, DNS queries are sent to one configured server at a
	  time and the resolver will fall back to the next server if the
	  current one times out or returns a failure.
	  Default behavior is to avoid querying all servers at once in order
	  to minimize network traffic.

endif # DNS_RESOLVER

config MDNS_RESPONDER
	bool "mDNS responder"
	select NET_IPV4_IGMP if NET_IPV4
	select NET_IPV6_MLD if NET_IPV6
	select NET_MGMT
	select NET_MGMT_EVENT
	select NET_SOCKETS
	select NET_SOCKETS_SERVICE
	depends on NET_HOSTNAME_ENABLE
	help
	  This option enables the mDNS responder support for Zephyr.
	  It will listen well-known address ff02::fb and 224.0.0.251.
	  Currently this only returns IP address information.
	  You must set CONFIG_NET_HOSTNAME to some meaningful value and
	  then mDNS will start to respond to <hostname>.local mDNS queries.
	  See RFC 6762 for more details about mDNS.

if MDNS_RESPONDER

config MDNS_RESOLVER_BUF_SIZE
	int "Size of the net_buf pool buffers"
	default 512
	help
	  For larger DNS SD TXT records and long service instance names, bigger buffers
	  are necessary

config MDNS_RESPONDER_TTL
	int "Time-to-Live of returned DNS name"
	default 600
	help
	  DNS answers will use the TTL (in seconds).

config MDNS_RESPONDER_INIT_PRIO
	int "Startup priority for the mDNS responder init"
	default 96
	help
	  Note that if NET_CONFIG_AUTO_INIT is enabled, then this value
	  should be bigger than its value.

choice
	prompt "mDNS responder interface policy"
	default MDNS_RESPONDER_IFACE_POLICY_ALL
	help
	  Select on which network interfaces the mDNS responder operates.
	  This allows the responder to be kept off interfaces that do not
	  need local service discovery, or that have hardware which is not
	  ready when the responder is initialized.

config MDNS_RESPONDER_IFACE_POLICY_ALL
	bool "All interfaces"
	help
	  The mDNS responder attaches to every network interface. This is
	  the default and backward compatible behavior.

config MDNS_RESPONDER_IFACE_POLICY_ALLOWLIST
	bool "Only listed interfaces"
	select NET_INTERFACE_NAME
	help
	  The mDNS responder attaches only to interfaces whose name is
	  listed in MDNS_RESPONDER_IFACE_LIST.

config MDNS_RESPONDER_IFACE_POLICY_DENYLIST
	bool "All except listed interfaces"
	select NET_INTERFACE_NAME
	help
	  The mDNS responder attaches to every interface except those whose
	  name is listed in MDNS_RESPONDER_IFACE_LIST.

endchoice

config MDNS_RESPONDER_IFACE_LIST
	string "Comma separated list of interface names"
	depends on MDNS_RESPONDER_IFACE_POLICY_ALLOWLIST || MDNS_RESPONDER_IFACE_POLICY_DENYLIST
	help
	  Comma separated list of network interface names (for example
	  "eth0,wlan0") that the interface policy applies to. Interface
	  names are used instead of interface indexes because the indexes
	  can change depending on configuration.

config MDNS_RESPONDER_RUNTIME_IFACE_CONTROL
	bool "Runtime control of the mDNS responder per interface"
	help
	  Provide mdns_responder_enable_iface() and
	  mdns_responder_disable_iface() so that the application can enable or
	  disable the mDNS responder on a specific network interface at
	  runtime. The runtime setting overrides the build-time interface
	  policy for that interface. When this option is not set, the
	  responder follows the build-time interface policy only.

config MDNS_RESPONDER_PROBE
	bool "mDNS probing support [EXPERIMENTAL]"
	select NET_CONNECTION_MANAGER
	select MDNS_RESOLVER
	select DNS_RESOLVER
	select EXPERIMENTAL
	help
	  Note that for probing to work, the mDNS and DNS resolver need to
	  be enabled. The probing is made optional to allow smaller memory
	  usage.

config MDNS_WORKQ_STACK_SIZE
	int "mDNS work queue thread stack size"
	default 1200 if X86
	default 1024
	depends on MDNS_RESPONDER_PROBE
	help
	  Set the mDNS work queue thread stack size in bytes.

config MDNS_WORKER_PRIO
	int "Priority of the mDNS work queue"
	default 2
	depends on MDNS_RESPONDER_PROBE
	help
	  Set the priority of the mDNS worker queue, that handles all
	  mDNS probing. Value 0 = highest priortity.
	  When CONFIG_NET_TC_THREAD_COOPERATIVE = y, lowest priority is
	  CONFIG_NUM_COOP_PRIORITIES-1 else lowest priority is
	  CONFIG_NUM_PREEMPT_PRIORITIES-1.

config MDNS_RESPONDER_DNS_SD
	bool "DNS Service Discovery via mDNS"
	default y
	depends on DNS_SD
	help
	  Selecting this option ensures that the MDNS Responder
	  processes PTR, SRV, and TXT records according to RFC 6763.
	  By doing so, Zephyr network services are discoverable
	  using e.g. 'avahi-browse -t -r _greybus._tcp'.

if MDNS_RESPONDER_DNS_SD

config MDNS_RESPONDER_DNS_SD_SERVICE_TYPE_ENUMERATION
	bool "DNS SD Service Type Enumeration"
	default y
	help
	  Selecting this option ensures that the MDNS Responder
	  performs DNS-SD Service Type Enumeration according to RFC 6763,
	  Chapter 9. By doing so, Zephyr network services are discoverable
	  using e.g. 'avahi-browse -t -r _services._dns-sd._udp.local'.

config MDNS_RESPONDER_ANNOUNCE_DNS_SD
	bool "Include DNS-SD service records in mDNS announcements"
	depends on MDNS_RESPONDER_PROBE
	help
	  RFC 6762 Section 8.3 requires the startup announcement to contain
	  all of a responder's newly registered resource records, not just
	  address records -- this covers the shared PTR record and unique
	  SRV/TXT records for every DNS-SD service registered via
	  DNS_SD_REGISTER_SERVICE() (and any records set through
	  mdns_responder_set_ext_records()).

	  Enable this for full RFC 6762 compliance. Leave disabled to keep
	  announcements limited to address records only (smaller, less
	  frequent traffic on startup) -- clients that actively query for
	  services (e.g. avahi-browse) are unaffected either way, since
	  normal query/response handling already answers DNS-SD queries
	  regardless of this option.

endif # MDNS_RESPONDER_DNS_SD

module = MDNS_RESPONDER
module-dep = NET_LOG
module-str = Log level for mDNS responder
module-help = Enables mDNS responder code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"

config MDNS_RESOLVER_ADDITIONAL_BUF_CTR
	int "Additional DNS buffers"
	default 0
	help
	  Number of additional buffers available for the mDNS responder.

endif # MDNS_RESPONDER

config LLMNR_RESPONDER
	bool "LLMNR responder [DEPRECATED]"
	select DEPRECATED
	select NET_IPV4_IGMP if NET_IPV4
	select NET_IPV6_MLD if NET_IPV6
	select NET_MGMT
	select NET_MGMT_EVENT
	select NET_SOCKETS
	select NET_SOCKETS_SERVICE
	depends on NET_HOSTNAME_ENABLE
	help
	  This option enables the LLMNR responder support for Zephyr.
	  It will listen well-known address ff02::1:3 and 224.0.0.252.
	  Currently this only returns IP address information.
	  You must set CONFIG_NET_HOSTNAME to some meaningful value and
	  then LLMNR will start to respond to <hostname> LLMNR queries.
	  Note that LLMNR queries should only contain single-label names
	  so there should be NO dot (".") in the name (RFC 4795 ch 3).
	  Current implementation does not support TCP.
	  See RFC 4795 for more details about LLMNR.

	  LLMNR is being phased out (Microsoft is retiring it) and this option
	  is deprecated and will be removed in a future release. Use the mDNS
	  responder (CONFIG_MDNS_RESPONDER) instead.

if LLMNR_RESPONDER

config LLMNR_RESPONDER_TTL
	int "Time-to-Live of returned DNS name"
	default 30
	help
	  DNS answers will use the TTL (in seconds). A default value is 30
	  seconds as recommended by RFC 4795 chapter 2.8

config LLMNR_RESPONDER_INIT_PRIO
	int "Startup priority for the LLMNR responder init"
	default 96
	help
	  Note that if NET_CONFIG_AUTO_INIT is enabled, then this value
	  should be bigger than its value.

module = LLMNR_RESPONDER
module-dep = NET_LOG
module-str = Log level for LLMNR responder
module-help = Enables LLMNR responder code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"

config LLMNR_RESOLVER_ADDITIONAL_BUF_CTR
	int "Additional DNS buffers"
	default 0
	help
	  Number of additional buffers available for the LLMNR responder.

endif # LLMNR_RESPONDER

config DNS_SD
	bool "DNS Service Discovery"
	help
	  This option enables DNS Service Discovery for Zephyr. It can
	  be enabled for virtually any network service with only a few
	  lines of code and works for both Unicast and Multicast DNS.
	  See RFC 6763 for more details about DNS-SD.

if DNS_SD

module = DNS_SD
module-dep = NET_LOG
module-str = Log level for DNS-SD
module-help = Enables DNS Service Discovery code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"

endif # DNS_SD

config DNS_RESOLVER_MAX_SERVERS_LIMIT
	int
	depends on (DNS_RESOLVER || MDNS_RESPONDER)
	default 32 if NET_MAX_CONTEXTS > 32
	default NET_MAX_CONTEXTS

config DNS_RESOLVER_MAX_SERVERS
	int "Number of DNS server addresses"
	depends on (DNS_RESOLVER || MDNS_RESPONDER)
	range 1 DNS_RESOLVER_MAX_SERVERS_LIMIT
	default 1
	help
	  Max number of DNS servers that we can connect to. Normally one
	  DNS server is enough. Each connection to DNS server will use one
	  network context.

# Note that we enable the DNS socket dispatcher always if either responder or
# resolver support is enabled to simplify things. Strictly speaking the
# dispatcher is really needed for supporting resolver and responder at the same
# time.
config DNS_SOCKET_DISPATCHER
	bool
	depends on (DNS_RESOLVER || MDNS_RESPONDER)
	select NET_SOCKETS_SERVICE
	default y
	help
	  A DNS socket dispatcher that allows both the DNS resolver and
	  mDNS responder to be used at the same time.

if DNS_SOCKET_DISPATCHER

config DNS_RESOLVER_ADDITIONAL_BUF_CTR
	int "Additional DNS buffers"
	default DNS_RESOLVER_MAX_SERVERS
	help
	  Number of additional buffers available for the DNS resolver.
	  The DNS resolver requires at least one buffer. This option
	  adds buffers needed for concurrent DNS server connections,
	  so the default tracks the configured number of DNS servers.

module = DNS_SOCKET_DISPATCHER
module-dep = NET_LOG
module-str = Log level for DNS socket dispatcher
module-help = Enables DNS socket dispatcher code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"

endif # DNS_SOCKET_DISPATCHER
