diff --git a/subsys/net/lib/dhcpv6/Kconfig b/subsys/net/lib/dhcpv6/Kconfig index dad049dac77..7fda850ec5e 100644 --- a/subsys/net/lib/dhcpv6/Kconfig +++ b/subsys/net/lib/dhcpv6/Kconfig @@ -31,6 +31,23 @@ config NET_DHCPV6_OPTION_DNS_ADDRESS option from the server, and if available, use obtained information to configure DNS resolver. +config NET_DHCPV6_DNS_SERVER_VIA_INTERFACE + bool "Make DNS servers specific to the network interface" + depends on NET_DHCPV6_OPTION_DNS_ADDRESS + default y + help + If this is set, then if the system has multiple network interfaces + and each has DHCP enabled, then assign DNS servers received from that + network interface, to that specific interface. + If this option is not set, then any interface can be used for all + the configured DNS server addresses when doing DNS queries. + Example: We receive DNS server 2001:db8::1:53 DHCPv6 option from Wi-Fi + interface and DNS server 2001:db8::2:53 from Ethernet interface. + When this option is set, the DNS resolver will use DNS server + 2001:db8::1:53 when sending DNS query to the Wi-Fi interface and DNS + server 2001:db8::2:53 when sending DNS query to the Ethernet + interface. + if NET_DHCPV6 module = NET_DHCPV6 module-dep = NET_LOG diff --git a/subsys/net/lib/dhcpv6/dhcpv6.c b/subsys/net/lib/dhcpv6/dhcpv6.c index 29dd652d428..f5984273cc3 100644 --- a/subsys/net/lib/dhcpv6/dhcpv6.c +++ b/subsys/net/lib/dhcpv6/dhcpv6.c @@ -1412,7 +1412,25 @@ static int dhcpv6_handle_dns_server_option(struct net_pkt *pkt) } ctx = dns_resolve_get_default(); - status = dns_resolve_reconfigure(ctx, NULL, dns_servers); + + if (IS_ENABLED(CONFIG_NET_DHCPV6_DNS_SERVER_VIA_INTERFACE)) { + /* If we are using the interface to resolve DNS servers, + * we need to save the interface index. + */ + int ifindex = net_if_get_by_iface(net_pkt_iface(pkt)); + int interfaces[MAX_DNS_SERVERS]; + + for (uint8_t i = 0; i < server_count; i++) { + interfaces[i] = ifindex; + } + + status = dns_resolve_reconfigure_with_interfaces(ctx, NULL, + dns_servers, + interfaces); + } else { + status = dns_resolve_reconfigure(ctx, NULL, dns_servers); + } + if (status < 0) { NET_DBG("Failed to reconfigure DNS resolver from DHCPv6 " "option: %d", status);