Commit cb905245 authored by Jukka Rissanen's avatar Jukka Rissanen Committed by Henrik Brix Andersen
Browse files

net: dns: Properly cleanup DNS servers per network interface



Make sure we cleanup only those DNS servers that belong to
certain network interface when the interface goes down.

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@nordicsemi.no>
parent 248cb3d2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -550,6 +550,16 @@ int dns_resolve_reconfigure_with_interfaces(struct dns_resolve_context *ctx,
					    const struct sockaddr *servers_sa[],
					    int interfaces[]);

/**
 * @brief Remove servers from the DNS resolving context.
 *
 * @param ctx DNS context
 * @param if_index Network interface from which the DNS servers are removed.
 *
 * @return 0 if ok, <0 if error.
 */
int dns_resolve_remove(struct dns_resolve_context *ctx, int if_index);

/**
 * @brief Cancel a pending DNS query.
 *
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ config NET_TX_STACK_SIZE

config NET_RX_STACK_SIZE
	int "RX thread stack size"
	default 1792 if DNS_RESOLVER
	default 1500
	help
	  Set the RX thread stack size in bytes. The RX thread is waiting
+5 −1
Original line number Diff line number Diff line
@@ -2469,6 +2469,9 @@ static inline bool handle_ra_rdnss(struct net_pkt *pkt, uint8_t len)
	const struct sockaddr *dns_servers[] = {
		(struct sockaddr *)&dns, NULL
	};
	int interfaces[] = {
		net_if_get_by_iface(net_pkt_iface(pkt))
	};
	size_t rdnss_size;
	int ret;

@@ -2505,7 +2508,8 @@ static inline bool handle_ra_rdnss(struct net_pkt *pkt, uint8_t len)

	/* TODO: Handle lifetime. */
	ctx = dns_resolve_get_default();
	ret = dns_resolve_reconfigure(ctx, NULL, dns_servers);
	ret = dns_resolve_reconfigure_with_interfaces(ctx, NULL, dns_servers,
						      interfaces);
	if (ret < 0) {
		NET_DBG("Failed to set RDNSS resolve address: %d", ret);
	}
+10 −0
Original line number Diff line number Diff line
@@ -1668,6 +1668,16 @@ static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb,
			if (!net_if_ipv4_addr_rm(iface, &iface->config.dhcpv4.requested_ip)) {
				NET_DBG("Failed to remove addr from iface");
			}

			/* Remove DNS servers as interface is gone. We only need to
			 * do this for this interface. If using global setting, the
			 * DNS servers are removed automatically when the interface
			 * comes back up.
			 */
			if (IS_ENABLED(CONFIG_NET_DHCPV4_DNS_SERVER_VIA_INTERFACE)) {
				dns_resolve_remove(dns_resolve_get_default(),
						   net_if_get_by_iface(iface));
			}
		}
	} else if (mgmt_event == NET_EVENT_IF_UP) {
		NET_DBG("Interface %p coming up", iface);
+10 −0
Original line number Diff line number Diff line
@@ -2217,6 +2217,16 @@ static void dhcpv6_iface_event_handler(struct net_mgmt_event_callback *cb,
	if (mgmt_event == NET_EVENT_IF_DOWN) {
		NET_DBG("Interface %p going down", iface);
		dhcpv6_set_timeout(iface, UINT64_MAX);

		/* Remove DNS servers as interface is gone. We only need to
		 * do this for this interface. If using global setting, the
		 * DNS servers are removed automatically when the interface
		 * comes back up.
		 */
		if (IS_ENABLED(CONFIG_NET_DHCPV6_DNS_SERVER_VIA_INTERFACE)) {
			dns_resolve_remove(dns_resolve_get_default(),
					   net_if_get_by_iface(iface));
		}
	} else if (mgmt_event == NET_EVENT_IF_UP) {
		NET_DBG("Interface %p coming up", iface);
		dhcpv6_enter_state(iface, NET_DHCPV6_INIT);
Loading