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

net: dns: Allow reconfiguration with network interfaces



Allow user to specify which network interfaces to bind the
server to when reconfiguring the DNS system.

Signed-off-by: default avatarJukka Rissanen <jukka.rissanen@nordicsemi.no>
parent 1fc628b0
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -524,6 +524,32 @@ int dns_resolve_reconfigure(struct dns_resolve_context *ctx,
			    const char *servers_str[],
			    const struct sockaddr *servers_sa[]);

/**
 * @brief Reconfigure DNS resolving context with new server list and
 *        allowing servers to be specified to a specific network interface.
 *
 * @param ctx DNS context
 * @param servers_str DNS server addresses using textual strings. The
 *        array is NULL terminated. The port number can be given in the string.
 *        Syntax for the server addresses with or without port numbers:
 *           IPv4        : 10.0.9.1
 *           IPv4 + port : 10.0.9.1:5353
 *           IPv6        : 2001:db8::22:42
 *           IPv6 + port : [2001:db8::22:42]:5353
 * @param servers_sa DNS server addresses as struct sockaddr. The array
 *        is NULL terminated. Port numbers are optional in struct sockaddr, the
 *        default will be used if set to 0.
 * @param interfaces Network interfaces to which the DNS servers are bound.
 *        This is an array of network interface indices. The array must be
 *        the same length as the servers_str and servers_sa arrays.
 *
 * @return 0 if ok, <0 if error.
 */
int dns_resolve_reconfigure_with_interfaces(struct dns_resolve_context *ctx,
					    const char *servers_str[],
					    const struct sockaddr *servers_sa[],
					    int interfaces[]);

/**
 * @brief Cancel a pending DNS query.
 *
+16 −4
Original line number Diff line number Diff line
@@ -1877,9 +1877,10 @@ static bool dns_servers_exists(struct dns_resolve_context *ctx,
	return true;
}

int dns_resolve_reconfigure(struct dns_resolve_context *ctx,
int dns_resolve_reconfigure_with_interfaces(struct dns_resolve_context *ctx,
					    const char *servers[],
			    const struct sockaddr *servers_sa[])
					    const struct sockaddr *servers_sa[],
					    int interfaces[])
{
	int err;

@@ -1909,7 +1910,8 @@ int dns_resolve_reconfigure(struct dns_resolve_context *ctx,
		}
	}

	err = dns_resolve_init_locked(ctx, servers, servers_sa, &resolve_svc, 0, NULL);
	err = dns_resolve_init_locked(ctx, servers, servers_sa,
				      &resolve_svc, 0, interfaces);

unlock:
	k_mutex_unlock(&ctx->lock);
@@ -1917,6 +1919,16 @@ unlock:
	return err;
}

int dns_resolve_reconfigure(struct dns_resolve_context *ctx,
			    const char *servers[],
			    const struct sockaddr *servers_sa[])
{
	return dns_resolve_reconfigure_with_interfaces(ctx,
						       servers,
						       servers_sa,
						       NULL);
}

struct dns_resolve_context *dns_resolve_get_default(void)
{
	return &dns_default_ctx;