net: dhcpv4: Honor network interface for DNS servers
Bind the network interface to the network interface we have received the DNS servers from. This is now the default. The previous behavior can be restored by disabling the CONFIG_NET_DHCPV4_DNS_SERVER_VIA_INTERFACE option. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
2af5dba995
commit
1224c5a43a
2 changed files with 36 additions and 1 deletions
|
@ -96,6 +96,23 @@ config NET_DHCPV4_OPTION_PRINT_IGNORED
|
|||
received and ignored. If this is not set, then we print these as unknown
|
||||
options.
|
||||
|
||||
config NET_DHCPV4_DNS_SERVER_VIA_INTERFACE
|
||||
bool "Make DNS servers specific to the network interface"
|
||||
depends on NET_DHCPV4_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 192.0.2.53 DHCPv4 option from Wi-Fi
|
||||
interface and DNS server 198.51.100.53 from Ethernet interface.
|
||||
When this option is set, the DNS resolver will use DNS server
|
||||
192.0.2.53 when sending DNS query to the Wi-Fi interface and DNS
|
||||
server 198.51.100.53 when sending DNS query to the Ethernet
|
||||
interface.
|
||||
|
||||
endif # NET_DHCPV4
|
||||
|
||||
config NET_DHCPV4_SERVER
|
||||
|
|
|
@ -1171,7 +1171,25 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
|
|||
for (uint8_t i = 0; i < dns_servers_cnt; i++) {
|
||||
dnses[i].sin_family = AF_INET;
|
||||
}
|
||||
status = dns_resolve_reconfigure(ctx, NULL, dns_servers);
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_DHCPV4_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(iface);
|
||||
int interfaces[MAX_DNS_SERVERS];
|
||||
|
||||
for (uint8_t i = 0; i < dns_servers_cnt; 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("options_dns, failed to set "
|
||||
"resolve address: %d", status);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue