mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 22:08:35 +08:00
Compare commits
3 commits
0231f763a7
...
e1ab83f3f5
Author | SHA1 | Date | |
---|---|---|---|
|
e1ab83f3f5 | ||
|
43797ea6cc | ||
|
5d227b43d9 |
7 changed files with 234 additions and 2 deletions
|
@ -439,6 +439,14 @@ menuconfig WATCHDOG_AUTOMONITOR
|
|||
|
||||
if WATCHDOG_AUTOMONITOR
|
||||
|
||||
config WATCHDOG_TIMEOUT_NOTIFIER
|
||||
bool "Enable watchdog timeout notifier"
|
||||
default n
|
||||
---help---
|
||||
The watchdog timeout notifier chain mechanism supports users registering
|
||||
custom callback functions, which will be called when the watchdog timer
|
||||
managed by Auto-monitor times out.
|
||||
|
||||
choice
|
||||
prompt "Auto-monitor keepalive by"
|
||||
default WATCHDOG_AUTOMONITOR_BY_WDOG
|
||||
|
|
|
@ -71,6 +71,20 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
|
||||
# define WATCHDOG_NOTIFIER_ACTION WATCHDOG_KEEPALIVE_BY_ONESHOT
|
||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_TIMER)
|
||||
# define WATCHDOG_NOTIFIER_ACTION WATCHDOG_KEEPALIVE_BY_TIMER
|
||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WDOG)
|
||||
# define WATCHDOG_NOTIFIER_ACTION WATCHDOG_KEEPALIVE_BY_WDOG
|
||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_WORKER)
|
||||
# define WATCHDOG_NOTIFIER_ACTION WATCHDOG_KEEPALIVE_BY_WORKER
|
||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_CAPTURE)
|
||||
# define WATCHDOG_NOTIFIER_ACTION WATCHDOG_KEEPALIVE_BY_CAPTURE
|
||||
#elif defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_IDLE)
|
||||
# define WATCHDOG_NOTIFIER_ACTION WATCHDOG_KEEPALIVE_BY_IDLE
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Definitions
|
||||
****************************************************************************/
|
||||
|
@ -135,6 +149,10 @@ static const struct file_operations g_wdogops =
|
|||
wdog_ioctl, /* ioctl */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
|
||||
static ATOMIC_NOTIFIER_HEAD(g_watchdog_notifier_list);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -699,6 +717,55 @@ static int wdog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
|
||||
/****************************************************************************
|
||||
* Name: watchdog_notifier_chain_register
|
||||
*
|
||||
* Description:
|
||||
* Add notifier to the watchdog notifier chain
|
||||
*
|
||||
* Input Parameters:
|
||||
* nb - New entry in notifier chain
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void watchdog_notifier_chain_register(FAR struct notifier_block *nb)
|
||||
{
|
||||
atomic_notifier_chain_register(&g_watchdog_notifier_list, nb);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: watchdog_notifier_chain_unregister
|
||||
*
|
||||
* Description:
|
||||
* Remove notifier from the watchdog notifier chain
|
||||
*
|
||||
* Input Parameters:
|
||||
* nb - Entry to remove from notifier chain
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void watchdog_notifier_chain_unregister(FAR struct notifier_block *nb)
|
||||
{
|
||||
atomic_notifier_chain_unregister(&g_watchdog_notifier_list, nb);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: watchdog_automonitor_timeout
|
||||
*
|
||||
* Description:
|
||||
* This function can be called in the watchdog timeout interrupt handler.
|
||||
* If so, callbacks on the watchdog timer notify chain are called when the
|
||||
* watchdog timer times out.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void watchdog_automonitor_timeout(void)
|
||||
{
|
||||
atomic_notifier_call_chain(&g_watchdog_notifier_list, action, data);
|
||||
}
|
||||
#endif /* CONFIG_WATCHDOG_TIMEOUT_NOTIFIER */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: watchdog_register
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/notifier.h>
|
||||
|
||||
#ifdef CONFIG_WATCHDOG
|
||||
|
||||
|
@ -88,6 +89,35 @@
|
|||
#define WDFLAGS_CAPTURE (1 << 2) /* 1=Call the user function when the
|
||||
* watchdog timer expires */
|
||||
|
||||
/* Keepalive Actions ********************************************************/
|
||||
|
||||
/* According to the keepalive action specified by the Auto-monitor, callback
|
||||
* functions registered on the watchdog notifier chain may take corresponding
|
||||
* actions.
|
||||
*
|
||||
* These are detected and handled by the "upper half" watchdog timer driver.
|
||||
*
|
||||
* WATCHDOG_KEEPALIVE_BY_ONESHOT - The watchdog timer is keepalive by
|
||||
* oneshot timer.
|
||||
* WATCHDOG_KEEPALIVE_BY_TIMER - The watchdog timer is keepalive by
|
||||
* timer.
|
||||
* WATCHDOG_KEEPALIVE_BY_WDOG - The watchdog timer is keepalive by
|
||||
* wdog.
|
||||
* WATCHDOG_KEEPALIVE_BY_WORKER - The watchdog timer is keepalive by
|
||||
* worker queue.
|
||||
* WATCHDOG_KEEPALIVE_BY_CAPTURE - The watchdog timer is keepalive by
|
||||
* capture.
|
||||
* WATCHDOG_KEEPALIVE_BY_IDLE - The watchdog timer is keepalive by
|
||||
* idle task.
|
||||
*/
|
||||
|
||||
#define WATCHDOG_KEEPALIVE_BY_ONESHOT 0
|
||||
#define WATCHDOG_KEEPALIVE_BY_TIMER 1
|
||||
#define WATCHDOG_KEEPALIVE_BY_WDOG 2
|
||||
#define WATCHDOG_KEEPALIVE_BY_WORKER 3
|
||||
#define WATCHDOG_KEEPALIVE_BY_CAPTURE 4
|
||||
#define WATCHDOG_KEEPALIVE_BY_IDLE 5
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
@ -197,6 +227,47 @@ extern "C"
|
|||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_WATCHDOG_TIMEOUT_NOTIFIER
|
||||
/****************************************************************************
|
||||
* Name: watchdog_notifier_chain_register
|
||||
*
|
||||
* Description:
|
||||
* Add notifier to the watchdog notifier chain
|
||||
*
|
||||
* Input Parameters:
|
||||
* nb - New entry in notifier chain
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void watchdog_notifier_chain_register(FAR struct notifier_block *nb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: watchdog_notifier_chain_unregister
|
||||
*
|
||||
* Description:
|
||||
* Remove notifier from the watchdog notifier chain
|
||||
*
|
||||
* Input Parameters:
|
||||
* nb - Entry to remove from notifier chain
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void watchdog_notifier_chain_unregister(FAR struct notifier_block *nb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: watchdog_automonitor_timeout
|
||||
*
|
||||
* Description:
|
||||
* This function can be called in the watchdog timeout interrupt handler.
|
||||
* If so, callbacks on the watchdog timer notify chain are called when the
|
||||
* watchdog timer times out.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void watchdog_automonitor_timeout(void);
|
||||
|
||||
#endif /* CONFIG_WATCHDOG_TIMEOUT_NOTIFIER */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: watchdog_register
|
||||
*
|
||||
|
|
|
@ -237,6 +237,13 @@ config NETDB_DNSSERVER_IPv4ADDR
|
|||
Default DNS server IPv4 address in host byte order. Default value
|
||||
10.0.0.1. This may be changed via dns_add_nameserver().
|
||||
|
||||
config NETDB_DNS_STREAM
|
||||
bool "DNS supports TCP transmission"
|
||||
depends on LIBC_NETDB
|
||||
default n
|
||||
---help---
|
||||
Enable support for DNS Name resolution over TCP.
|
||||
|
||||
if NETDB_DNSSERVER_IPv6
|
||||
|
||||
config NETDB_DNSSERVER_IPv6ADDR_1
|
||||
|
|
|
@ -170,7 +170,11 @@ void dns_restorelock(unsigned int count);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
int dns_bind(sa_family_t family);
|
||||
#else
|
||||
int dns_bind(sa_family_t family, bool stream);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_query
|
||||
|
|
|
@ -63,16 +63,28 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
int dns_bind(sa_family_t family)
|
||||
#else
|
||||
int dns_bind(sa_family_t family, bool stream)
|
||||
#endif
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
int stype = stream ? SOCK_STREAM : SOCK_DGRAM;
|
||||
#endif
|
||||
|
||||
struct timeval tv;
|
||||
int sd;
|
||||
int ret;
|
||||
|
||||
/* Create a new socket */
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
sd = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
#else
|
||||
sd = socket(family, stype | SOCK_CLOEXEC, 0);
|
||||
#endif
|
||||
|
||||
if (sd < 0)
|
||||
{
|
||||
ret = -get_errno();
|
||||
|
|
|
@ -124,6 +124,7 @@ struct dns_query_data_s
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
static ssize_t stream_send(int fd, FAR const void *buf, size_t len)
|
||||
{
|
||||
ssize_t total = 0;
|
||||
|
@ -292,6 +293,7 @@ static ssize_t stream_recv_record(int fd, FAR void *buf, size_t len)
|
|||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dns_parse_name
|
||||
|
@ -380,11 +382,18 @@ static inline uint16_t dns_alloc_id(void)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
static int dns_send_query(int sd, FAR const char *name,
|
||||
FAR union dns_addr_u *uaddr, uint16_t rectype,
|
||||
FAR struct dns_query_info_s *qinfo,
|
||||
FAR uint8_t *buffer)
|
||||
#else
|
||||
static int dns_send_query(int sd, FAR const char *name,
|
||||
FAR union dns_addr_u *uaddr, uint16_t rectype,
|
||||
FAR struct dns_query_info_s *qinfo,
|
||||
FAR uint8_t *buffer,
|
||||
bool stream)
|
||||
#endif
|
||||
{
|
||||
FAR struct dns_header_s *hdr;
|
||||
FAR uint8_t *dest;
|
||||
|
@ -488,11 +497,13 @@ static int dns_send_query(int sd, FAR const char *name,
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
if (stream)
|
||||
{
|
||||
ret = stream_send_record(sd, buffer, dest - buffer);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ret = send(sd, buffer, dest - buffer, 0);
|
||||
}
|
||||
|
@ -519,10 +530,16 @@ static int dns_send_query(int sd, FAR const char *name,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
|
||||
FAR struct dns_query_info_s *qinfo,
|
||||
FAR uint32_t *ttl, FAR uint8_t *buffer)
|
||||
#else
|
||||
static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
|
||||
FAR struct dns_query_info_s *qinfo,
|
||||
FAR uint32_t *ttl, FAR uint8_t *buffer,
|
||||
bool stream, bool *should_try_stream)
|
||||
#endif
|
||||
{
|
||||
FAR uint8_t *nameptr;
|
||||
FAR uint8_t *namestart;
|
||||
|
@ -543,11 +560,13 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
|
|||
|
||||
/* Receive the response */
|
||||
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
if (stream)
|
||||
{
|
||||
ret = stream_recv_record(sd, buffer, RECV_BUFFER_SIZE);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ret = recv(sd, buffer, RECV_BUFFER_SIZE, 0);
|
||||
}
|
||||
|
@ -579,6 +598,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
|
|||
|
||||
/* Check for error */
|
||||
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
if ((hdr->flags1 & DNS_FLAG1_TRUNC) != 0)
|
||||
{
|
||||
/* RFC 2181
|
||||
|
@ -601,6 +621,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int naddr,
|
|||
*should_try_stream = true;
|
||||
return -EAGAIN;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((hdr->flags2 & DNS_FLAG2_ERR_MASK) != 0)
|
||||
{
|
||||
|
@ -851,7 +872,9 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
|
|||
int retries;
|
||||
int ret;
|
||||
int sd;
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
bool stream = false;
|
||||
#endif
|
||||
|
||||
/* Loop while receive timeout errors occur and there are remaining
|
||||
* retries.
|
||||
|
@ -859,25 +882,37 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
|
|||
|
||||
for (retries = 0; retries < CONFIG_NETDB_DNSCLIENT_RETRIES; retries++)
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
bool should_try_stream;
|
||||
|
||||
try_stream:
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (dns_is_queryfamily(AF_INET6))
|
||||
{
|
||||
/* Send the IPv6 query */
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
sd = dns_bind(addr->sa_family);
|
||||
#else
|
||||
sd = dns_bind(addr->sa_family, stream);
|
||||
#endif
|
||||
if (sd < 0)
|
||||
{
|
||||
query->result = sd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
ret = dns_send_query(sd, query->hostname,
|
||||
(FAR union dns_addr_u *)addr,
|
||||
DNS_RECTYPE_AAAA, &qdata->qinfo,
|
||||
qdata->buffer);
|
||||
#else
|
||||
ret = dns_send_query(sd, query->hostname,
|
||||
(FAR union dns_addr_u *)addr,
|
||||
DNS_RECTYPE_AAAA, &qdata->qinfo,
|
||||
qdata->buffer, stream);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
dns_query_error("ERROR: IPv6 dns_send_query failed",
|
||||
|
@ -887,25 +922,33 @@ try_stream:
|
|||
else
|
||||
{
|
||||
/* Obtain the IPv6 response */
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
ret = dns_recv_response(sd, &query->addr[next],
|
||||
CONFIG_NETDB_MAX_IPv6ADDR,
|
||||
&qdata->qinfo,
|
||||
&query->ttl, qdata->buffer);
|
||||
#else
|
||||
should_try_stream = false;
|
||||
ret = dns_recv_response(sd, &query->addr[next],
|
||||
CONFIG_NETDB_MAX_IPv6ADDR,
|
||||
&qdata->qinfo,
|
||||
&query->ttl, qdata->buffer,
|
||||
stream, &should_try_stream);
|
||||
#endif
|
||||
if (ret >= 0)
|
||||
{
|
||||
next += ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
if (!stream && should_try_stream)
|
||||
{
|
||||
stream = true;
|
||||
goto try_stream; /* Don't consume retry count */
|
||||
}
|
||||
|
||||
#endif
|
||||
dns_query_error("ERROR: IPv6 dns_recv_response failed",
|
||||
ret, (FAR union dns_addr_u *)addr);
|
||||
query->result = ret;
|
||||
|
@ -914,6 +957,7 @@ try_stream:
|
|||
|
||||
close(sd);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
|
@ -921,17 +965,27 @@ try_stream:
|
|||
{
|
||||
/* Send the IPv4 query */
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
sd = dns_bind(addr->sa_family);
|
||||
#else
|
||||
sd = dns_bind(addr->sa_family, stream);
|
||||
#endif
|
||||
if (sd < 0)
|
||||
{
|
||||
query->result = sd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
ret = dns_send_query(sd, query->hostname,
|
||||
(FAR union dns_addr_u *)addr,
|
||||
DNS_RECTYPE_A, &qdata->qinfo, qdata->buffer);
|
||||
#else
|
||||
ret = dns_send_query(sd, query->hostname,
|
||||
(FAR union dns_addr_u *)addr,
|
||||
DNS_RECTYPE_A, &qdata->qinfo, qdata->buffer,
|
||||
stream);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
dns_query_error("ERROR: IPv4 dns_send_query failed",
|
||||
|
@ -947,24 +1001,33 @@ try_stream:
|
|||
next = *query->naddr / 2;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_NETDB_DNS_STREAM
|
||||
ret = dns_recv_response(sd, &query->addr[next],
|
||||
CONFIG_NETDB_MAX_IPv4ADDR,
|
||||
&qdata->qinfo,
|
||||
&query->ttl, qdata->buffer);
|
||||
#else
|
||||
should_try_stream = false;
|
||||
ret = dns_recv_response(sd, &query->addr[next],
|
||||
CONFIG_NETDB_MAX_IPv4ADDR,
|
||||
&qdata->qinfo,
|
||||
&query->ttl, qdata->buffer,
|
||||
stream, &should_try_stream);
|
||||
#endif
|
||||
if (ret >= 0)
|
||||
{
|
||||
next += ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNS_STREAM
|
||||
if (!stream && should_try_stream)
|
||||
{
|
||||
stream = true;
|
||||
goto try_stream; /* Don't consume retry count */
|
||||
}
|
||||
|
||||
#endif
|
||||
dns_query_error("ERROR: IPv4 dns_recv_response failed",
|
||||
ret, (FAR union dns_addr_u *)addr);
|
||||
query->result = ret;
|
||||
|
|
Loading…
Reference in a new issue