forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libs:netdb: Restrict DNS query types
Corresponds to the problem of name resolution with different IP address types in networks where only one of IPv4 or IPv6 can be used due to physical layer reasons (e.g., LTE networks).
- Loading branch information
Showing
6 changed files
with
192 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/**************************************************************************** | ||
* libs/libc/netdb/lib_dnsqueryfamily.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <sys/types.h> | ||
#include <errno.h> | ||
#include <assert.h> | ||
#include <debug.h> | ||
|
||
#include "netdb/lib_dns.h" | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
static int g_query_family = AF_UNSPEC; | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: dns_is_queryfamily | ||
* | ||
* Description: | ||
* Determine if the specified address family is available for DNS query. | ||
* | ||
****************************************************************************/ | ||
|
||
bool dns_is_queryfamily(sa_family_t family) | ||
{ | ||
DEBUGASSERT(family == AF_INET || family == AF_INET6); | ||
|
||
return (g_query_family == AF_UNSPEC) ? true : | ||
(g_query_family == family); | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: dns_set_queryfamily | ||
* | ||
* Description: | ||
* Configure the address family to be used for queries. | ||
* | ||
****************************************************************************/ | ||
|
||
int dns_set_queryfamily(sa_family_t family) | ||
{ | ||
int ret = OK; | ||
|
||
switch (family) | ||
{ | ||
#ifdef CONFIG_NET_IPv4 | ||
case AF_INET: | ||
#endif | ||
#ifdef CONFIG_NET_IPv6 | ||
case AF_INET6: | ||
#endif | ||
case AF_UNSPEC: | ||
dns_lock(); | ||
g_query_family = family; | ||
dns_unlock(); | ||
ninfo("Configure address type for dns query: %d\n", family); | ||
break; | ||
default: | ||
nerr("ERROR: Unsupported family: %d\n", family); | ||
ret = -ENOSYS; | ||
break; | ||
} | ||
|
||
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 | ||
dns_clear_answer(); | ||
#endif | ||
|
||
return ret; | ||
} | ||
|