net/netdev: Add signal notification for the case where the network goes down.

This commit is contained in:
Gregory Nutt 2018-09-09 10:39:25 -06:00
parent 28f73bd928
commit 32e3e51678
9 changed files with 108 additions and 3 deletions

View File

@ -59,6 +59,7 @@ enum nxsig_evtype_e
NXSIG_IOB_AVAIL = 1, /* Signal availability of an IOB */
NXSIG_NET_DOWN, /* Signal that the network is down */
NXSIG_TCP_READAHEAD, /* Signal that TCP read-ahead data is available */
NXSIG_TCP_DISCONNECT, /* Signal loss of TCP connection */
NXSIG_UDP_READAHEAD, /* Signal that TCP read-ahead data is available */
};

View File

@ -63,6 +63,7 @@ config IOB_NOTIFIER
bool "Support IOB notifications"
default n
select SIG_NOTIFIER
depends on !DISABLE_SIGNALS
---help---
Enable building of IOB notifier logic that will send a signal to
a kernel thread when an IOB is available. This is is a general

View File

@ -36,4 +36,15 @@ config NETDEV_IFINDEX
When enabled, these option also enables the user interfaces:
if_nametoindex() and if_indextoname().
config NETDOWN_NOTIFIER
bool "Support network down notifications"
default n
select SIG_NOTIFIER
depends on !DISABLE_SIGNALS
---help---
Enable building of logic that will send a signal to a kernel
thread when the network is taken down. This is is a general purpose
notifier, but was developed specifically to support SIGHUP poll()
logic.
endmenu # Network Device Operations

View File

@ -45,6 +45,10 @@ ifeq ($(CONFIG_NETDEV_IFINDEX),y)
NETDEV_CSRCS += netdev_indextoname.c netdev_nametoindex.c
endif
ifeq ($(CONFIG_NETDOWN_NOTIFIER),y)
SOCK_CSRCS += netdown_notifier.c
endif
# Include netdev build support
DEPPATH += --dep-path netdev

View File

@ -466,6 +466,85 @@ int netdev_ipv6_ifconf(FAR struct lifconf *lifc);
int netdev_dev_lladdrsize(FAR struct net_driver_s *dev);
/****************************************************************************
* Name: netdown_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* dev - The network driver to be monitored
*
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
* key that may be used later in a call to
* netdown_notifier_teardown().
* == 0 - The the device is already down. No signal notification will
* be provided.
* < 0 - An unexpected error occurred and no signal will be sent. The
* returned value is a negated errno value that indicates the
* nature of the failure.
*
****************************************************************************/
#ifdef CONFIG_NETDOWN_NOTIFIER
int netdown_notifier_setup(int pid, int signo, FAR struct net_driver_s *dev);
#endif
/****************************************************************************
* Name: netdown_notifier_teardown
*
* Description:
* Eliminate a TCP read-ahead notification previously setup by
* netdown_notifier_setup(). This function should only be called if the
* notification should be aborted prior to the notification. The
* notification will automatically be torn down after the signal is sent.
*
* Input Parameters:
* key - The key value returned from a previous call to
* netdown_notifier_setup().
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
*
****************************************************************************/
#ifdef CONFIG_NETDOWN_NOTIFIER
int netdown_notifier_teardown(int key);
#endif
/****************************************************************************
* Name: netdown_notifier_signal
*
* Description:
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call netdown_notifier_setup() once again.
*
* Input Parameters:
* dev - The TCP connection where read-ahead data was just buffered.
*
* Returned Value:
* None.
*
****************************************************************************/
#ifdef CONFIG_NETDOWN_NOTIFIER
void netdown_notifier_signal(FAR struct net_driver_s *dev);
#endif
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -1789,6 +1789,15 @@ void netdev_ifdown(FAR struct net_driver_s *dev)
/* Notify clients that the network has been taken down */
(void)devif_dev_event(dev, NULL, NETDEV_DOWN);
#ifdef CONFIG_NETDOWN_NOTIFIER
/* Provide signal notifications to threads that want to be
* notified of the network down state via signal.
*/
netdown_notifier_signal(dev);
#endif
}
}

View File

@ -70,7 +70,7 @@ config TCP_READAHEAD_NOTIFIER
bool "Support TCP read-ahead notifications"
default n
select SIG_NOTIFIER
depends on NET_TCP_READAHEAD && !DISABLE_POLL
depends on NET_TCP_READAHEAD && !DISABLE_SIGNALS
---help---
Enable building of TCP read-ahead notifier logic that will send a
signal to a kernel thread when an TCP read-ahead data has been

View File

@ -61,7 +61,7 @@ config UDP_READAHEAD_NOTIFIER
bool "Support UDP read-ahead notifications"
default n
select SIG_NOTIFIER
depends on NET_UDP_READAHEAD && !DISABLE_POLL
depends on NET_UDP_READAHEAD && !DISABLE_SIGNALS
---help---
Enable building of UDP read-ahead notifier logic that will send a
signal to a kernel thread when an UDP read-ahead data has been

View File

@ -1185,7 +1185,7 @@ config SIG_NOTIFIER
config SIG_NOTIFIER_NWAITERS
int "Number of signal waiters"
default 4
default 8
range 1 32766
depends on SIG_NOTIFIER
---help---