mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #3449 from benoit-canet/reboot
native: Take care of cleaning up networking properly on reboot
This commit is contained in:
commit
b31f960282
@ -53,6 +53,13 @@ extern dev_eth_tap_t dev_eth_tap;
|
||||
*/
|
||||
void dev_eth_tap_setup(dev_eth_tap_t *dev, const char *name);
|
||||
|
||||
/**
|
||||
* @brief Cleanup dev_eth_tap_t structure.
|
||||
*
|
||||
* @param dev the dev_eth_tap device handle to cleanup
|
||||
*/
|
||||
void dev_eth_tap_cleanup(dev_eth_tap_t *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -36,7 +36,11 @@ extern "C" {
|
||||
*/
|
||||
int tap_init(char *name);
|
||||
|
||||
extern int _native_tap_fd;
|
||||
/**
|
||||
* Close tap device
|
||||
*/
|
||||
void tap_cleanup(void);
|
||||
|
||||
extern unsigned char _native_tap_mac[ETHER_ADDR_LEN];
|
||||
|
||||
struct nativenet_header {
|
||||
|
@ -51,6 +51,10 @@
|
||||
#ifdef MODULE_NATIVENET
|
||||
#include "tap.h"
|
||||
#endif
|
||||
#ifdef MODULE_NG_NATIVENET
|
||||
#include "dev_eth_tap.h"
|
||||
extern dev_eth_tap_t dev_eth_tap;
|
||||
#endif
|
||||
|
||||
#include "native_internal.h"
|
||||
|
||||
@ -73,9 +77,10 @@ int reboot_arch(int mode)
|
||||
/* TODO: close stdio fds */
|
||||
#endif
|
||||
#ifdef MODULE_NATIVENET
|
||||
if (_native_tap_fd != -1) {
|
||||
real_close(_native_tap_fd);
|
||||
}
|
||||
tap_cleanup();
|
||||
#endif
|
||||
#ifdef MODULE_NG_NATIVENET
|
||||
dev_eth_tap_cleanup(&dev_eth_tap);
|
||||
#endif
|
||||
|
||||
if (real_execve(_native_argv[0], _native_argv, NULL) == -1) {
|
||||
|
@ -351,4 +351,20 @@ int tap_init(char *name)
|
||||
DEBUG("RIOT native tap initialized.\n");
|
||||
return _native_tap_fd;
|
||||
}
|
||||
|
||||
void tap_cleanup(void)
|
||||
{
|
||||
unregister_interrupt(SIGIO);
|
||||
#ifdef __MACH__
|
||||
kill(sigio_child_pid, SIGKILL);
|
||||
#endif
|
||||
|
||||
if (_native_tap_fd == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
real_close(_native_tap_fd);
|
||||
_native_tap_fd = -1;
|
||||
|
||||
}
|
||||
/** @} */
|
||||
|
@ -57,6 +57,7 @@ dev_eth_tap_t dev_eth_tap;
|
||||
|
||||
/* dev_eth interface */
|
||||
static int _init(dev_eth_t *ethdev);
|
||||
static void _cleanup(dev_eth_t *ethdev);
|
||||
static int _send(dev_eth_t *ethdev, char* buf, int n);
|
||||
static int _recv(dev_eth_t *ethdev, char* buf, int n);
|
||||
|
||||
@ -82,6 +83,7 @@ static inline void _isr(dev_eth_t *ethdev) {
|
||||
|
||||
static eth_driver_t eth_driver_tap = {
|
||||
.init = _init,
|
||||
.cleanup = _cleanup,
|
||||
.send = _send,
|
||||
.recv = _recv,
|
||||
.get_mac_addr = _get_mac_addr,
|
||||
@ -177,6 +179,13 @@ void dev_eth_tap_setup(dev_eth_tap_t *dev, const char *name) {
|
||||
strncpy(dev->tap_name, name, IFNAMSIZ);
|
||||
}
|
||||
|
||||
void dev_eth_tap_cleanup(dev_eth_tap_t *dev) {
|
||||
if (!dev) {
|
||||
return;
|
||||
}
|
||||
dev_eth_cleanup((dev_eth_t *) dev);
|
||||
}
|
||||
|
||||
static void _tap_isr(void) {
|
||||
dev_eth_isr(((dev_eth_t *) &dev_eth_tap));
|
||||
}
|
||||
@ -269,6 +278,25 @@ static int _init(dev_eth_t *ethdev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _cleanup(dev_eth_t *ethdev)
|
||||
{
|
||||
dev_eth_tap_t *dev = (dev_eth_tap_t*)ethdev;
|
||||
|
||||
/* Do we have a device */
|
||||
if (!dev) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* cleanup signal handling */
|
||||
unregister_interrupt(SIGIO);
|
||||
#ifdef __MACH__
|
||||
kill(_sigio_child_pid, SIGKILL);
|
||||
#endif
|
||||
|
||||
/* close the tap device */
|
||||
real_close(dev->tap_fd);
|
||||
}
|
||||
|
||||
#ifdef __MACH__
|
||||
static void _sigio_child(ng_tapnet_t *dev)
|
||||
{
|
||||
|
@ -137,6 +137,10 @@ typedef struct eth_driver {
|
||||
* @return <=0 on error, >0 on success
|
||||
*/
|
||||
int (*init)(dev_eth_t *dev);
|
||||
/**
|
||||
* @brief the driver's cleanup function (optional)
|
||||
*/
|
||||
void (*cleanup)(dev_eth_t *dev);
|
||||
/**
|
||||
* @brief a driver's user-space ISR handler
|
||||
*
|
||||
@ -162,6 +166,19 @@ static inline int dev_eth_init(dev_eth_t *dev) {
|
||||
return dev->driver->init(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cleanup a device given by dev (convenience function)
|
||||
*
|
||||
* This function is to be called on reboot if the init function is not
|
||||
* idempotent.
|
||||
*
|
||||
*/
|
||||
static inline void dev_eth_cleanup(dev_eth_t *dev) {
|
||||
if (dev->driver->cleanup) {
|
||||
dev->driver->cleanup(dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief global dev_eth interrupt handling function.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user