From 0d510dd66ddd38fa5c1330b9a763319d2929ac41 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 26 Aug 2016 11:21:49 +0200 Subject: [PATCH] Add API macros for netif client data handling and update documentation accordingly --- doc/doxygen/lwip.Doxyfile | 1 + src/core/ipv4/autoip.c | 6 +++--- src/core/ipv4/dhcp.c | 8 ++++---- src/core/netif.c | 7 ++++++- src/include/lwip/netif.h | 8 ++++++++ src/include/lwip/opt.h | 3 ++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index 8a638ba8..c86326b0 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2096,6 +2096,7 @@ PREDEFINED = __DOXYGEN__=1 \ LWIP_NETIF_STATUS_CALLBACK=1 \ LWIP_NETIF_REMOVE_CALLBACK=1 \ LWIP_NETIF_LINK_CALLBACK=1 \ + LWIP_NUM_NETIF_CLIENT_DATA=1 \ ENABLE_LOOPBACK=1 \ LWIP_AUTOIP=1 \ ARP_QUEUEING=1 \ diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 7b53ef1d..01fccf8a 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -95,7 +95,7 @@ static err_t autoip_arp_announce(struct netif *netif); static void autoip_start_probing(struct netif *netif); -#define netif_autoip_data(netif) ((struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]) +#define netif_autoip_data(netif) ((struct autoip*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP)) /** * @ingroup autoip @@ -116,7 +116,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) /* clear data structure */ memset(autoip, 0, sizeof(struct autoip)); /* autoip->state = AUTOIP_STATE_OFF; */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] = autoip; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); } /** Restart AutoIP client and check the next address (conflict detected) @@ -281,7 +281,7 @@ autoip_start(struct netif *netif) } memset(autoip, 0, sizeof(struct autoip)); /* store this AutoIP client in the netif */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] = autoip; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); } else { autoip->state = AUTOIP_STATE_OFF; diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index d9ee38ed..46bfcf2c 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -193,7 +193,7 @@ static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif); /* always add the DHCP options trailer to end and pad */ static void dhcp_option_trailer(struct dhcp *dhcp); -#define netif_dhcp_data(netif) ((struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]) +#define netif_dhcp_data(netif) ((struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)) /** Ensure DHCP PCB is allocated and bound */ static err_t @@ -668,7 +668,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) /* clear data structure */ memset(dhcp, 0, sizeof(struct dhcp)); /* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp); } /** @@ -686,7 +686,7 @@ void dhcp_cleanup(struct netif *netif) if (netif_dhcp_data(netif) != NULL) { mem_free(netif_dhcp_data(netif)); - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = NULL; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, NULL); } } @@ -730,7 +730,7 @@ dhcp_start(struct netif *netif) } /* store this dhcp client in the netif */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp")); /* already has DHCP client attached */ } else { diff --git a/src/core/netif.c b/src/core/netif.c index d6cfb55c..1c4b1b42 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -10,6 +10,11 @@ * * @defgroup netif_ip6 IPv6 address handling * @ingroup netif + * + * @defgroup netif_cd Client data handling + * Store data (void*) on a netif for application usage. + * @see @ref LWIP_NUM_NETIF_CLIENT_DATA + * @ingroup netif */ /* @@ -967,7 +972,7 @@ netif_poll_all(void) #if LWIP_NUM_NETIF_CLIENT_DATA > 0 /** - * @ingroup netif + * @ingroup netif_cd * Allocate an index to store data in client_data member of struct netif. * Returned value is an index in mentioned array. * @see LWIP_NUM_NETIF_CLIENT_DATA diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 1b5f21c7..c039da1f 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -426,6 +426,14 @@ err_t netif_input(struct pbuf *p, struct netif *inp); #if LWIP_NUM_NETIF_CLIENT_DATA > 0 u8_t netif_alloc_client_data_id(void); +/** @ingroup netif_cd + * Set client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) +/** @ingroup netif_cd + * Get client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_get_client_data(netif, id) (netif)->client_data[(id)] #endif #if LWIP_IPV6 diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index eeb3e6c0..01631c62 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2495,7 +2495,8 @@ /** * LWIP_HOOK_VLAN_SET: - * Hook can be used to set prio_vid field of vlan_hdr. + * Hook can be used to set prio_vid field of vlan_hdr. If you need to store data + * on per-netif basis to implement this callback, see @ref netif_cd. * Called from ethernet_output() if VLAN support (@ref ETHARP_SUPPORT_VLAN) is enabled.\n * Signature: s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);\n * Arguments: