828acd31daf8dc792ab5648c022433ae66902901vboxsync/* -*- indent-tabs-mode: nil; -*- */
828acd31daf8dc792ab5648c022433ae66902901vboxsync#ifndef __VBOX_LWIP_LOG_H__
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define __VBOX_LWIP_LOG_H__
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#include <VBox/log.h>
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#ifdef LWIP_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync/*
828acd31daf8dc792ab5648c022433ae66902901vboxsync * All LWIP_DBG_* constants fit into a byte, so we use upper bits to
828acd31daf8dc792ab5648c022433ae66902901vboxsync * encode the VBox log group.
828acd31daf8dc792ab5648c022433ae66902901vboxsync *
828acd31daf8dc792ab5648c022433ae66902901vboxsync * Mapping between FOO_DEBUG and LOG_GROUP_LWIP_FOO is straightforward
828acd31daf8dc792ab5648c022433ae66902901vboxsync * except for IP4 where extra '4' was added to the group names to make
828acd31daf8dc792ab5648c022433ae66902901vboxsync * it possible to specify lwip_ip4* instead of lwip_ip*, where the
828acd31daf8dc792ab5648c022433ae66902901vboxsync * latter would enable both IP4 and IP6 logging.
828acd31daf8dc792ab5648c022433ae66902901vboxsync *
828acd31daf8dc792ab5648c022433ae66902901vboxsync * We ignore LWIP_DBG_STATE &c since in our scheme they would traslate
828acd31daf8dc792ab5648c022433ae66902901vboxsync * into additional log groups and require combinatorial explosion. We
828acd31daf8dc792ab5648c022433ae66902901vboxsync * probably can use LWIP_DBG_TYPES_ON for finer selection if need be
828acd31daf8dc792ab5648c022433ae66902901vboxsync * (for internal debugging only, as it requires recompilation).
828acd31daf8dc792ab5648c022433ae66902901vboxsync *
828acd31daf8dc792ab5648c022433ae66902901vboxsync * Debug levels are mapped to RT debug levels so lwip's default level
828acd31daf8dc792ab5648c022433ae66902901vboxsync * ends up as RT's level4. Non-default levels are currently not used
828acd31daf8dc792ab5648c022433ae66902901vboxsync * much in lwip sources, so enable l4 to get the logs.
828acd31daf8dc792ab5648c022433ae66902901vboxsync */
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define LWIP_DEBUGF_LOG_GROUP_SHIFT 8
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define LWIP_DEBUGF_LOG_GROUP(_g) \
828acd31daf8dc792ab5648c022433ae66902901vboxsync (((_g) << LWIP_DEBUGF_LOG_GROUP_SHIFT) | LWIP_DBG_ON)
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define API_LIB_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_API_LIB)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define API_MSG_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_API_MSG)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define ETHARP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_ETHARP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define ICMP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_ICMP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define IGMP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_IGMP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define INET_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_INET)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define IP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_IP4)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define IP_REASS_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_IP4_REASS)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define IP6_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_IP6)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define MEM_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_MEM)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define MEMP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_MEMP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define NETIF_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_NETIF)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define PBUF_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_PBUF)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define RAW_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_RAW)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define SOCKETS_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_SOCKETS)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define SYS_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_SYS)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_CWND_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_CWND)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_FR_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_FR)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_INPUT_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_INPUT)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_OUTPUT_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_OUTPUT)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_QLEN_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_QLEN)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_RST_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_RST)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_RTO_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_RTO)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCP_WND_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCP_WND)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TCPIP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TCPIP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define TIMERS_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_TIMERS)
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define UDP_DEBUG LWIP_DEBUGF_LOG_GROUP(LOG_GROUP_LWIP_UDP)
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync/*
828acd31daf8dc792ab5648c022433ae66902901vboxsync * The following symbols are for debugging of modules that are not
828acd31daf8dc792ab5648c022433ae66902901vboxsync * compiled in. They are listed here for reference but there're no
828acd31daf8dc792ab5648c022433ae66902901vboxsync * log groups defined for them currently.
828acd31daf8dc792ab5648c022433ae66902901vboxsync */
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef AUTOIP_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef DHCP_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef DNS_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef PPP_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef SLIP_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef SNMP_MIB_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync#undef SNMP_MSG_DEBUG
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#ifdef LOG_ENABLED
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define LWIP_DEBUGF(_when, _args) \
828acd31daf8dc792ab5648c022433ae66902901vboxsync do { \
828acd31daf8dc792ab5648c022433ae66902901vboxsync const VBOX_LOGGROUP _group = (_when) >> LWIP_DEBUGF_LOG_GROUP_SHIFT; \
828acd31daf8dc792ab5648c022433ae66902901vboxsync if (_group >= LOG_GROUP_DEFAULT) { \
828acd31daf8dc792ab5648c022433ae66902901vboxsync /* severe => l1; serious => l2; warning => l3; default => l4 */ \
828acd31daf8dc792ab5648c022433ae66902901vboxsync const unsigned int _level = \
828acd31daf8dc792ab5648c022433ae66902901vboxsync 1 << (LWIP_DBG_MASK_LEVEL+1 - ((_when) & LWIP_DBG_MASK_LEVEL)); \
828acd31daf8dc792ab5648c022433ae66902901vboxsync LogIt(LOG_INSTANCE, _level, _group, _args); \
828acd31daf8dc792ab5648c022433ae66902901vboxsync } \
828acd31daf8dc792ab5648c022433ae66902901vboxsync } while (0)
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#else /* !LOG_ENABLED */
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#define LWIP_DEBUGF(_when, _args) do { } while (0)
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#endif /* !LOG_ENABLED */
828acd31daf8dc792ab5648c022433ae66902901vboxsync
828acd31daf8dc792ab5648c022433ae66902901vboxsync#endif /* LWIP_DEBUG */
828acd31daf8dc792ab5648c022433ae66902901vboxsync#endif /* __VBOX_LWIP_LOG_H__ */