From 6934bb442832406b5c41fc86bd934091b021f7ad Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 7 Feb 2018 20:35:49 +0100 Subject: [PATCH] netif: ext_callback: make LWIP_NSC_ defines, not an enum; fix mdns accordingly --- src/apps/mdns/mdns.c | 37 +++++++++++---------------- src/include/lwip/netif.h | 55 ++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 5926aeed..2af56a22 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1905,28 +1905,21 @@ mdns_netif_ext_status_callback(struct netif *netif, netif_nsc_reason_t reason, c return; } - switch (reason) { - case LWIP_NSC_STATUS_CHANGED: - if (args->status_changed.state != 0) { - mdns_resp_restart(netif); - } - /* TODO: send goodbye message */ - break; - case LWIP_NSC_LINK_CHANGED: - if (args->link_changed.state != 0) { - mdns_resp_restart(netif); - } - break; - case LWIP_NSC_IPV4_ADDRESS_CHANGED: /* fall through */ - case LWIP_NSC_IPV4_GATEWAY_CHANGED: /* fall through */ - case LWIP_NSC_IPV4_NETMASK_CHANGED: /* fall through */ - case LWIP_NSC_IPV4_SETTINGS_CHANGED: /* fall through */ - case LWIP_NSC_IPV6_SET: /* fall through */ - case LWIP_NSC_IPV6_ADDR_STATE_CHANGED: - mdns_resp_announce(netif); - break; - default: - break; + if (reason & LWIP_NSC_STATUS_CHANGED) { + if (args->status_changed.state != 0) { + mdns_resp_restart(netif); + } + /* TODO: send goodbye message */ + } + if (reason & LWIP_NSC_LINK_CHANGED) { + if (args->link_changed.state != 0) { + mdns_resp_restart(netif); + } + } + if (reason & (LWIP_NSC_IPV4_ADDRESS_CHANGED | LWIP_NSC_IPV4_GATEWAY_CHANGED | + LWIP_NSC_IPV4_NETMASK_CHANGED | LWIP_NSC_IPV4_SETTINGS_CHANGED | + LWIP_NSC_IPV6_SET | LWIP_NSC_IPV6_ADDR_STATE_CHANGED)) { + mdns_resp_announce(netif); } } #endif diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index c836d9fc..ec67f0a6 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -529,36 +529,35 @@ struct netif* netif_get_by_index(u8_t idx); /** * @ingroup netif - * Extended netif status callback (NSC) reasons enumeration. + * Extended netif status callback (NSC) reasons flags. * May be extended in the future! */ -typedef enum -{ - /* used for initialization only */ - LWIP_NSC_NONE = 0, - /** netif was added. arg: NULL. Called AFTER netif was added. */ - LWIP_NSC_NETIF_ADDED = 0x1, - /** netif was removed. arg: NULL. Called BEFORE netif is removed. */ - LWIP_NSC_NETIF_REMOVED = 0x2, - /** link changed */ - LWIP_NSC_LINK_CHANGED = 0x4, - /** netif administrative status changed.\n - * up is called AFTER netif is set up.\n - * down is called BEFORE the netif is actually set down. */ - LWIP_NSC_STATUS_CHANGED = 0x8, - /** IPv4 address has changed */ - LWIP_NSC_IPV4_ADDRESS_CHANGED = 0x10, - /** IPv4 gateway has changed */ - LWIP_NSC_IPV4_GATEWAY_CHANGED = 0x20, - /** IPv4 netmask has changed */ - LWIP_NSC_IPV4_NETMASK_CHANGED = 0x40, - /** called AFTER IPv4 address/gateway/netmask changes have been applied */ - LWIP_NSC_IPV4_SETTINGS_CHANGED = 0x80, - /** IPv6 address was added */ - LWIP_NSC_IPV6_SET = 0x100, - /** IPv6 address state has changed */ - LWIP_NSC_IPV6_ADDR_STATE_CHANGED = 0x200 -} netif_nsc_reason_t; +typedef u16_t netif_nsc_reason_t; + +/* used for initialization only */ +#define LWIP_NSC_NONE 0x0000 +/** netif was added. arg: NULL. Called AFTER netif was added. */ +#define LWIP_NSC_NETIF_ADDED 0x0001 +/** netif was removed. arg: NULL. Called BEFORE netif is removed. */ +#define LWIP_NSC_NETIF_REMOVED 0x0002 +/** link changed */ +#define LWIP_NSC_LINK_CHANGED 0x0004 +/** netif administrative status changed.\n + * up is called AFTER netif is set up.\n + * down is called BEFORE the netif is actually set down. */ +#define LWIP_NSC_STATUS_CHANGED 0x0008 +/** IPv4 address has changed */ +#define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010 +/** IPv4 gateway has changed */ +#define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020 +/** IPv4 netmask has changed */ +#define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040 +/** called AFTER IPv4 address/gateway/netmask changes have been applied */ +#define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080 +/** IPv6 address was added */ +#define LWIP_NSC_IPV6_SET 0x0100 +/** IPv6 address state has changed */ +#define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200 /** @ingroup netif * Argument supplied to netif_ext_callback_fn.