From 0a5755145c1cae11f87626545818e81ed7d2efa7 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Wed, 24 Aug 2011 22:00:10 +0200 Subject: [PATCH] added netif remove callback (bug #32397) --- CHANGELOG | 5 ++++- src/core/netif.c | 18 ++++++++++++++++++ src/include/lwip/netif.h | 7 +++++++ src/include/lwip/opt.h | 8 ++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 34fb7ac8..7cad2831 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,7 +6,10 @@ HISTORY ++ New features: - 2011-08-26: Simon Goldschmidt + 2011-08-24: Simon Goldschmidt + * opt.h, netif.h/.c: added netif remove callback (bug #32397) + + 2011-07-26: Simon Goldschmidt * etharp.c: ETHARP_SUPPORT_VLAN: add support for an external VLAN filter function instead of only checking for one VLAN (define ETHARP_VLAN_CHECK_FN) diff --git a/src/core/netif.c b/src/core/netif.c index 6da84234..c882eade 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -306,6 +306,11 @@ netif_remove(struct netif *netif) /* reset default netif */ netif_set_default(NULL); } +#if LWIP_NETIF_REMOVE_CALLBACK + if (netif->remove_callback) { + netif->remove_callback(netif); + } +#endif /* LWIP_NETIF_REMOVE_CALLBACK */ LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") ); } @@ -550,6 +555,19 @@ void netif_set_status_callback(struct netif *netif, netif_status_callback_fn sta } #endif /* LWIP_NETIF_STATUS_CALLBACK */ +#if LWIP_NETIF_REMOVE_CALLBACK +/** + * Set callback to be called when the interface has been removed + */ +void +netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback) +{ + if (netif) { + netif->remove_callback = remove_callback; + } +} +#endif /* LWIP_NETIF_REMOVE_CALLBACK */ + /** * Called by a driver when its link goes up */ diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index c14289b8..a658e51b 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -197,6 +197,10 @@ struct netif { */ netif_status_callback_fn link_callback; #endif /* LWIP_NETIF_LINK_CALLBACK */ +#if LWIP_NETIF_REMOVE_CALLBACK + /** This function is called when the netif has been removed */ + netif_status_callback_fn remove_callback; +#endif /* LWIP_NETIF_REMOVE_CALLBACK */ /** This field can be set by the device driver and could point * to state information for the device. */ void *state; @@ -331,6 +335,9 @@ void netif_set_down(struct netif *netif); #if LWIP_NETIF_STATUS_CALLBACK void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ +#if LWIP_NETIF_REMOVE_CALLBACK +void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); +#endif /* LWIP_NETIF_REMOVE_CALLBACK */ void netif_set_link_up(struct netif *netif); void netif_set_link_down(struct netif *netif); diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 8ae6ba4d..a345a149 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1115,6 +1115,14 @@ #define LWIP_NETIF_LINK_CALLBACK 0 #endif +/** + * LWIP_NETIF_REMOVE_CALLBACK==1: Support a callback function that is called + * when a netif has been removed + */ +#ifndef LWIP_NETIF_REMOVE_CALLBACK +#define LWIP_NETIF_REMOVE_CALLBACK 0 +#endif + /** * LWIP_NETIF_HWADDRHINT==1: Cache link-layer-address hints (e.g. table * indices) in struct netif. TCP and UDP can make use of this to prevent