Merge branch 'master' of github.com:apache/incubator-nuttx into openamp
This commit is contained in:
commit
434086ff93
|
@ -1,353 +0,0 @@
|
|||
/****************************************************************************
|
||||
* arch/mips/src/pic32mz/chip/pic32mz_oneshot_lowerhalf.c
|
||||
*
|
||||
* Copyright (C) 2019 Abdelatif Guettouche. All rights reserved.
|
||||
* Author: Abdelatif Guettouche <abdelatif.guettouche@gmail.com>
|
||||
*
|
||||
* This file is a part of NuttX:
|
||||
*
|
||||
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/timers/oneshot.h>
|
||||
|
||||
#include "pic32mz_oneshot.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the state of the oneshot lower-half driver */
|
||||
|
||||
struct pic32mz_oneshot_lowerhalf_s
|
||||
{
|
||||
/* This is the part of the lower half driver that is visible to the upper-
|
||||
* half client of the driver. This must be the first thing in this
|
||||
* structure so that pointers to struct oneshot_lowerhalf_s are cast
|
||||
* compatible to struct pic32mz_oneshot_lowerhalf_s and vice versa.
|
||||
*/
|
||||
|
||||
struct oneshot_lowerhalf_s lh; /* Common lower-half driver fields */
|
||||
|
||||
/* Private lower half data follows */
|
||||
|
||||
struct pic32mz_oneshot_s oneshot; /* PIC32MZ-specific oneshot state */
|
||||
oneshot_callback_t callback; /* Handler that receives callback */
|
||||
FAR void *arg; /* Argument passed to the handler */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void pic32mz_oneshot_handler(void *arg);
|
||||
|
||||
static int pic32mz_max_delay(FAR struct oneshot_lowerhalf_s *lower,
|
||||
FAR struct timespec *ts);
|
||||
static int pic32mz_start(FAR struct oneshot_lowerhalf_s *lower,
|
||||
oneshot_callback_t callback, FAR void *arg,
|
||||
FAR const struct timespec *ts);
|
||||
static int pic32mz_cancel(FAR struct oneshot_lowerhalf_s *lower,
|
||||
FAR struct timespec *ts);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Lower half operations */
|
||||
|
||||
static const struct oneshot_operations_s g_oneshot_ops =
|
||||
{
|
||||
.max_delay = pic32mz_max_delay,
|
||||
.start = pic32mz_start,
|
||||
.cancel = pic32mz_cancel,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pic32mz_oneshot_handler
|
||||
*
|
||||
* Description:
|
||||
* Timer expiration handler
|
||||
*
|
||||
* Input Parameters:
|
||||
* arg Should be the same argument provided when pic32mz_oneshot_start()
|
||||
* was called.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void pic32mz_oneshot_handler(void *arg)
|
||||
{
|
||||
FAR struct pic32mz_oneshot_lowerhalf_s *priv =
|
||||
(FAR struct pic32mz_oneshot_lowerhalf_s *)arg;
|
||||
oneshot_callback_t callback;
|
||||
FAR void *cbarg;
|
||||
|
||||
DEBUGASSERT(priv != NULL);
|
||||
|
||||
/* Perhaps the callback was nullified in a race condition with
|
||||
* pic32mz_cancel?
|
||||
*/
|
||||
|
||||
if (priv->callback)
|
||||
{
|
||||
/* Sample and nullify BEFORE executing callback (in case the callback
|
||||
* restarts the oneshot).
|
||||
*/
|
||||
|
||||
callback = priv->callback;
|
||||
cbarg = priv->arg;
|
||||
priv->callback = NULL;
|
||||
priv->arg = NULL;
|
||||
|
||||
/* Then perform the callback */
|
||||
|
||||
callback(&priv->lh, cbarg);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pic32mz_max_delay
|
||||
*
|
||||
* Description:
|
||||
* Determine the maximum delay of the one-shot timer (in microseconds)
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower An instance of the lower-half oneshot state structure. This
|
||||
* structure must have been previously initialized via a call to
|
||||
* oneshot_initialize();
|
||||
* ts The location in which to return the maximum delay.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned
|
||||
* on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pic32mz_max_delay(FAR struct oneshot_lowerhalf_s *lower,
|
||||
FAR struct timespec *ts)
|
||||
{
|
||||
FAR struct pic32mz_oneshot_lowerhalf_s *priv =
|
||||
(FAR struct pic32mz_oneshot_lowerhalf_s *)lower;
|
||||
uint64_t usecs;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv != NULL && ts != NULL);
|
||||
|
||||
ret = pic32mz_oneshot_max_delay(&priv->oneshot, &usecs);
|
||||
tmrinfo("max delay %lu\n", usecs);
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
uint64_t sec = usecs / 1000000;
|
||||
usecs -= 1000000 * sec;
|
||||
|
||||
ts->tv_sec = (time_t)sec;
|
||||
ts->tv_nsec = (long)(usecs * 1000);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pic32mz_start
|
||||
*
|
||||
* Description:
|
||||
* Start the oneshot timer
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower An instance of the lower-half oneshot state structure. This
|
||||
* structure must have been previously initialized via a call to
|
||||
* oneshot_initialize();
|
||||
* handler The function to call when when the oneshot timer expires.
|
||||
* arg An opaque argument that will accompany the callback.
|
||||
* ts Provides the duration of the one shot timer.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned
|
||||
* on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pic32mz_start(FAR struct oneshot_lowerhalf_s *lower,
|
||||
oneshot_callback_t callback, FAR void *arg,
|
||||
FAR const struct timespec *ts)
|
||||
{
|
||||
FAR struct pic32mz_oneshot_lowerhalf_s *priv =
|
||||
(FAR struct pic32mz_oneshot_lowerhalf_s *)lower;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv != NULL && callback != NULL && ts != NULL);
|
||||
|
||||
/* Save the callback information and start the timer */
|
||||
|
||||
flags = enter_critical_section();
|
||||
priv->callback = callback;
|
||||
priv->arg = arg;
|
||||
ret = pic32mz_oneshot_start(&priv->oneshot,
|
||||
pic32mz_oneshot_handler,
|
||||
priv, ts);
|
||||
leave_critical_section(flags);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
tmrerr("ERROR: pic32mz_oneshot_start failed: %d\n", flags);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pic32mz_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel the oneshot timer and return the time remaining on the timer.
|
||||
*
|
||||
* NOTE: This function may execute at a high rate with no timer running (as
|
||||
* when pre-emption is enabled and disabled).
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower Caller allocated instance of the oneshot state structure. This
|
||||
* structure must have been previously initialized via a call to
|
||||
* oneshot_initialize();
|
||||
* ts The location in which to return the time remaining on the
|
||||
* oneshot timer. A time of zero is returned if the timer is
|
||||
* not running.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success. A call to up_timer_cancel() when
|
||||
* the timer is not active should also return success; a negated errno
|
||||
* value is returned on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int pic32mz_cancel(FAR struct oneshot_lowerhalf_s *lower,
|
||||
FAR struct timespec *ts)
|
||||
{
|
||||
FAR struct pic32mz_oneshot_lowerhalf_s *priv =
|
||||
(FAR struct pic32mz_oneshot_lowerhalf_s *)lower;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv != NULL);
|
||||
|
||||
/* Cancel the timer */
|
||||
|
||||
flags = enter_critical_section();
|
||||
ret = pic32mz_oneshot_cancel(&priv->oneshot, ts);
|
||||
priv->callback = NULL;
|
||||
priv->arg = NULL;
|
||||
leave_critical_section(flags);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
tmrerr("ERROR: pic32mz_oneshot_cancel failed: %d\n", flags);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: oneshot_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the oneshot timer and return a oneshot lower half driver
|
||||
* instance.
|
||||
*
|
||||
* Input Parameters:
|
||||
* chan Timer counter channel to be used.
|
||||
* resolution The required resolution of the timer in units of
|
||||
* microseconds. NOTE that the range is restricted to the
|
||||
* range of uint16_t (excluding zero).
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL instance of the oneshot lower-half driver is
|
||||
* returned. NULL is return on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct oneshot_lowerhalf_s *oneshot_initialize(int chan,
|
||||
uint16_t resolution)
|
||||
{
|
||||
FAR struct pic32mz_oneshot_lowerhalf_s *priv;
|
||||
int ret;
|
||||
|
||||
/* Allocate an instance of the lower half driver */
|
||||
|
||||
priv = (FAR struct pic32mz_oneshot_lowerhalf_s *)
|
||||
kmm_zalloc(sizeof(struct pic32mz_oneshot_lowerhalf_s));
|
||||
|
||||
if (priv == NULL)
|
||||
{
|
||||
tmrerr("ERROR: Failed to initialized state structure\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the lower-half driver structure */
|
||||
|
||||
priv->lh.ops = &g_oneshot_ops;
|
||||
|
||||
/* Initialize the contained PIC32MZ oneshot timer */
|
||||
|
||||
ret = pic32mz_oneshot_initialize(&priv->oneshot, chan, resolution);
|
||||
if (ret < 0)
|
||||
{
|
||||
tmrerr("ERROR: pic32mz_oneshot_initialize failed: %d\n", ret);
|
||||
kmm_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &priv->lh;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* arch/mips/src/pic32mz/chip/pic32mz_oneshot-lowerhalf.c
|
||||
* arch/mips/src/pic32mz/chip/pic32mz_oneshot_lowerhalf.c
|
||||
*
|
||||
* Copyright (C) 2019 Abdelatif Guettouche. All rights reserved.
|
||||
* Author: Abdelatif Guettouche <abdelatif.guettouche@gmail.com>
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The DNS message header */
|
||||
/* The DNS message header */
|
||||
|
||||
struct dns_header_s
|
||||
{
|
||||
|
@ -208,20 +208,20 @@ extern "C"
|
|||
int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_del_nameserver
|
||||
* Name: dns_default_nameserver
|
||||
*
|
||||
* Description:
|
||||
* Remove a DNS server so it is no longer available for further use.
|
||||
* Reset the resolver to use only the default DNS server, if any.
|
||||
*
|
||||
****************************************************************************/
|
||||
/* REVISIT: Not implemented */
|
||||
|
||||
int dns_default_nameserver(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_foreach_nameserver
|
||||
*
|
||||
* Description:
|
||||
* Traverse each nameserver entry in the resolv.conf file and perform the
|
||||
* the provided callback.
|
||||
* Traverse each nameserver entry and perform the provided callback.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ config NETDB_DNSCLIENT_ENTRIES
|
|||
cached and if the name mapping can be found in that cache, the
|
||||
network query can be avoid. Of course, this is only useful if you
|
||||
query the same name often and if the IP address of the name is
|
||||
stable. If the IP address can change, then cachin DNS address
|
||||
stable. If the IP address can change, then caching DNS address
|
||||
might have undesirable side-effects (see help for
|
||||
CONFIG_NETDB_DNSCLIENT_LIFESEC).
|
||||
|
||||
|
@ -155,6 +155,14 @@ config NETDB_RESOLVCONF_NONSTDPORT
|
|||
|
||||
endif # NETDB_RESOLVCONF
|
||||
|
||||
config NETDB_DNSSERVER_NAMESERVERS
|
||||
int "Max number of configured nameservers"
|
||||
default 1
|
||||
depends on !NETDB_RESOLVCONF
|
||||
---help---
|
||||
This setting determines how many nameservers there can be
|
||||
in use concurrently.
|
||||
|
||||
choice
|
||||
prompt "DNS server address type"
|
||||
default NETDB_DNSSERVER_IPv4 if NET_IPv4
|
||||
|
@ -166,7 +174,7 @@ config NETDB_DNSSERVER_NOADDR
|
|||
bool "No default DNS server address"
|
||||
---help---
|
||||
There is not default DNS nameserver address. Application must call
|
||||
dns_add_server() at runtime to add the DNS server address.
|
||||
dns_add_nameserver() at runtime to add the DNS server address.
|
||||
|
||||
config NETDB_DNSSERVER_IPv4
|
||||
bool "IPv4 DNS server address"
|
||||
|
@ -174,7 +182,7 @@ config NETDB_DNSSERVER_IPv4
|
|||
---help---
|
||||
An IPv4 default DNS nameserver address will be provided. Application
|
||||
may overwrite this start default server address by calling
|
||||
dns_add_server() at runtime.
|
||||
dns_add_nameserver() at runtime.
|
||||
|
||||
config NETDB_DNSSERVER_IPv6
|
||||
bool "IPv6 DNS server address"
|
||||
|
@ -182,7 +190,7 @@ config NETDB_DNSSERVER_IPv6
|
|||
---help---
|
||||
An IPv6 default DNS nameserver address will be provided. Application
|
||||
may overwrite this start default server address by calling
|
||||
dns_add_server() at runtime.
|
||||
dns_add_nameserver() at runtime.
|
||||
|
||||
endchoice # DNS server address type
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ endif
|
|||
# Add DNS lookup support
|
||||
|
||||
ifeq ($(CONFIG_NETDB_DNSCLIENT),y)
|
||||
CSRCS += lib_dnsinit.c lib_dnsbind.c lib_dnsquery.c lib_dnsaddserver.c
|
||||
CSRCS += lib_dnsinit.c lib_dnsbind.c lib_dnsquery.c
|
||||
CSRCS += lib_dnsaddserver.c lib_dnsdefaultserver.c
|
||||
CSRCS += lib_dnsforeach.c lib_dnsnotify.c
|
||||
|
||||
ifneq ($(CONFIG_NETDB_DNSCLIENT_ENTRIES),0)
|
||||
|
|
|
@ -80,6 +80,10 @@
|
|||
# define CONFIG_NETDB_RESOLVCONF_PATH "/etc/resolv.conf"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NETDB_DNSSERVER_NAMESERVERS
|
||||
# define CONFIG_NETDB_DNSSERVER_NAMESERVERS 1
|
||||
#endif
|
||||
|
||||
#define DNS_MAX_ADDRSTR 48
|
||||
#define DNS_MAX_LINE 64
|
||||
#define NETDB_DNS_KEYWORD "nameserver"
|
||||
|
@ -117,10 +121,10 @@ extern "C"
|
|||
#endif
|
||||
|
||||
#ifndef CONFIG_NETDB_RESOLVCONF
|
||||
/* The DNS server address */
|
||||
/* The DNS server addresses */
|
||||
|
||||
EXTERN union dns_addr_u g_dns_server;
|
||||
EXTERN bool g_dns_address; /* true: We have the address of the DNS server */
|
||||
EXTERN union dns_addr_u g_dns_servers[];
|
||||
EXTERN uint8_t g_dns_nservers;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -141,7 +145,7 @@ bool dns_initialize(void);
|
|||
* Name: dns_semtake
|
||||
*
|
||||
* Description:
|
||||
* Take the DNS semaphore, ignoring errors do to the receipt of signals.
|
||||
* Take the DNS semaphore, ignoring errors due to the receipt of signals.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
|
@ -43,10 +43,10 @@
|
|||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETDB_RESOLVCONF
|
||||
/* The DNS server address */
|
||||
/* The DNS server addresses */
|
||||
|
||||
union dns_addr_u g_dns_server;
|
||||
bool g_dns_address; /* true: We have the address of the DNS server */
|
||||
union dns_addr_u g_dns_servers[CONFIG_NETDB_DNSSERVER_NAMESERVERS];
|
||||
uint8_t g_dns_nservers; /* Number of currently configured nameservers */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -198,10 +198,24 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||
{
|
||||
FAR uint16_t *pport;
|
||||
size_t copylen;
|
||||
int nservers;
|
||||
int idx;
|
||||
|
||||
DEBUGASSERT(addr != NULL);
|
||||
|
||||
/* Copy the new server IP address into our private global data structure */
|
||||
/* Get the index of the next free nameserver slot. */
|
||||
|
||||
dns_semtake();
|
||||
if (g_dns_nservers == CONFIG_NETDB_DNSSERVER_NAMESERVERS)
|
||||
{
|
||||
idx = 0;
|
||||
nservers = g_dns_nservers;
|
||||
}
|
||||
else
|
||||
{
|
||||
idx = g_dns_nservers;
|
||||
nservers = idx + 1;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
/* Check for an IPv4 address */
|
||||
|
@ -211,7 +225,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||
/* Set up for the IPv4 address copy */
|
||||
|
||||
copylen = sizeof(struct sockaddr_in);
|
||||
pport = &g_dns_server.ipv4.sin_port;
|
||||
pport = &g_dns_servers[idx].ipv4.sin_port;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
@ -224,12 +238,13 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||
/* Set up for the IPv6 address copy */
|
||||
|
||||
copylen = sizeof(struct sockaddr_in6);
|
||||
pport = &g_dns_server.ipv6.sin6_port;
|
||||
pport = &g_dns_servers[idx].ipv6.sin6_port;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nerr("ERROR: Unsupported family: %d\n", addr->sa_family);
|
||||
dns_semgive();
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
|
@ -239,10 +254,11 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||
{
|
||||
nerr("ERROR: Invalid addrlen %ld for family %d\n",
|
||||
(long)addrlen, addr->sa_family);
|
||||
dns_semgive();
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memcpy(&g_dns_server.addr, addr, copylen);
|
||||
memcpy(&g_dns_servers[idx].addr, addr, copylen);
|
||||
|
||||
/* A port number of zero means to use the default DNS server port number */
|
||||
|
||||
|
@ -253,7 +269,8 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen)
|
|||
|
||||
/* We now have a valid DNS address */
|
||||
|
||||
g_dns_address = true;
|
||||
g_dns_nservers = nservers;
|
||||
dns_semgive();
|
||||
dns_notify_nameserver(addr, addrlen);
|
||||
return OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/netdb/lib_dnsdefaultserver.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 <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/dns.h>
|
||||
|
||||
#include "netdb/lib_dns.h"
|
||||
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_default_nameserver
|
||||
*
|
||||
* Description:
|
||||
* Reset the resolver to use only the default DNS server, if any.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDB_RESOLVCONF
|
||||
int dns_default_nameserver(void)
|
||||
{
|
||||
/* REVISIT: not implemented */
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
#else /* CONFIG_NETDB_RESOLVCONF */
|
||||
int dns_default_nameserver(void)
|
||||
{
|
||||
dns_semtake();
|
||||
g_dns_nservers = 0;
|
||||
dns_semgive();
|
||||
return OK;
|
||||
}
|
||||
#endif /* CONFIG_NETDB_RESOLVCONF */
|
||||
#endif /* CONFIG_NETDB_DNSCLIENT */
|
|
@ -81,7 +81,7 @@ static FAR char *find_spaces(FAR char *ptr)
|
|||
* Name: dns_foreach_nameserver
|
||||
*
|
||||
* Description:
|
||||
* Traverse each nameserver entry in the resolv.conf file and perform the
|
||||
* Traverse each nameserver entry in the resolv.conf file and perform
|
||||
* the provided callback.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
@ -247,19 +247,30 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
|||
|
||||
int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
||||
{
|
||||
FAR struct sockaddr *addr;
|
||||
int ret = OK;
|
||||
int i;
|
||||
|
||||
if (g_dns_address)
|
||||
dns_semtake();
|
||||
for (i = 0; i < g_dns_nservers; i++)
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
/* Check for an IPv4 address */
|
||||
|
||||
if (g_dns_server.addr.sa_family == AF_INET)
|
||||
if (g_dns_servers[i].addr.sa_family == AF_INET)
|
||||
{
|
||||
struct sockaddr_in copy;
|
||||
|
||||
/* Operate on copy of server address, in case it changes. */
|
||||
|
||||
memcpy(©, &g_dns_servers[i].ipv4, sizeof(struct sockaddr_in));
|
||||
addr = (FAR struct sockaddr *)©
|
||||
|
||||
/* Perform the callback */
|
||||
|
||||
ret = callback(arg, (FAR struct sockaddr *)&g_dns_server.ipv4,
|
||||
sizeof(struct sockaddr_in));
|
||||
dns_semgive();
|
||||
ret = callback(arg, addr, sizeof(struct sockaddr_in));
|
||||
dns_semtake();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
@ -267,22 +278,36 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
|
|||
#ifdef CONFIG_NET_IPv6
|
||||
/* Check for an IPv6 address */
|
||||
|
||||
if (g_dns_server.addr.sa_family == AF_INET6)
|
||||
if (g_dns_servers[i].addr.sa_family == AF_INET6)
|
||||
{
|
||||
struct sockaddr_in6 copy;
|
||||
|
||||
/* Operate on copy of server address, in case it changes. */
|
||||
|
||||
memcpy(©, &g_dns_servers[i].ipv6, sizeof(struct sockaddr_in6));
|
||||
addr = (FAR struct sockaddr *)©
|
||||
|
||||
/* Perform the callback */
|
||||
|
||||
ret = callback(arg, (FAR struct sockaddr *)&g_dns_server.ipv6,
|
||||
sizeof(struct sockaddr_in6));
|
||||
dns_semgive();
|
||||
ret = callback(arg, addr, sizeof(struct sockaddr_in6));
|
||||
dns_semtake();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nerr("ERROR: Unsupported family: %d\n",
|
||||
g_dns_server.addr.sa_family);
|
||||
g_dns_servers[i].addr.sa_family);
|
||||
ret = -ENOSYS;
|
||||
}
|
||||
|
||||
if (ret != OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dns_semgive();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Protects g_seqno, DNS cache and notify */
|
||||
/* Protects DNS cache, nameserver list and notify list. */
|
||||
|
||||
static sem_t g_dns_sem = SEM_INITIALIZER(1);
|
||||
|
||||
|
@ -94,9 +94,15 @@ static const uint16_t g_ipv6_hostaddr[8] =
|
|||
bool dns_initialize(void)
|
||||
{
|
||||
#ifndef CONFIG_NETDB_RESOLVCONF
|
||||
/* Has the DNS server IP address been assigned? */
|
||||
int nservers;
|
||||
|
||||
if (!g_dns_address)
|
||||
dns_semtake();
|
||||
nservers = g_dns_nservers;
|
||||
dns_semgive();
|
||||
|
||||
/* Has at least one DNS server IP address been assigned? */
|
||||
|
||||
if (nservers == 0)
|
||||
{
|
||||
#if defined(CONFIG_NETDB_DNSSERVER_IPv4)
|
||||
struct sockaddr_in addr4;
|
||||
|
@ -147,7 +153,7 @@ bool dns_initialize(void)
|
|||
* Name: dns_semtake
|
||||
*
|
||||
* Description:
|
||||
* Take the DNS semaphore, ignoring errors do to the receipt of signals.
|
||||
* Take the DNS semaphore, ignoring errors due to the receipt of signals.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
|
@ -161,8 +161,9 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
|
|||
|
||||
if (servname != NULL)
|
||||
{
|
||||
FAR char *endp;
|
||||
struct servent ent;
|
||||
FAR struct servent *sp;
|
||||
FAR char *endp;
|
||||
|
||||
port = strtol(servname, &endp, 10);
|
||||
if (port > 0 && port <= 65535 && *endp == '\0')
|
||||
|
@ -175,7 +176,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
|
|||
{
|
||||
return EAI_NONAME;
|
||||
}
|
||||
else if ((sp = getservbyname(servname, NULL)) != NULL)
|
||||
else if (getservbyname_r(servname, NULL, &ent, NULL, 0, &sp) == OK)
|
||||
{
|
||||
/* The s_port field of struct servent is required to
|
||||
* be in network byte order (per OpenGroup.org)
|
||||
|
|
|
@ -69,7 +69,7 @@ bool convert_hostent(const FAR struct hostent_s *in,
|
|||
int i;
|
||||
int j;
|
||||
|
||||
/* Initialize the ouptut of hostent */
|
||||
/* Initialize the output of hostent */
|
||||
|
||||
out->h_name = in->h_name;
|
||||
out->h_aliases = in->h_aliases;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/netdb/lib_parsehostile.c
|
||||
* libs/libc/netdb/lib_parsehostfile.c
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
|
Loading…
Reference in New Issue