1*472cd20dSToomas Soome /* 2*472cd20dSToomas Soome * Copyright (c) 2002-2019 Apple Inc. All rights reserved. 34b22b933Srs * 44b22b933Srs * Licensed under the Apache License, Version 2.0 (the "License"); 54b22b933Srs * you may not use this file except in compliance with the License. 64b22b933Srs * You may obtain a copy of the License at 75ffb0c9bSToomas Soome * 84b22b933Srs * http://www.apache.org/licenses/LICENSE-2.0 95ffb0c9bSToomas Soome * 104b22b933Srs * Unless required by applicable law or agreed to in writing, software 114b22b933Srs * distributed under the License is distributed on an "AS IS" BASIS, 124b22b933Srs * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134b22b933Srs * See the License for the specific language governing permissions and 144b22b933Srs * limitations under the License. 155ffb0c9bSToomas Soome */ 164b22b933Srs 174b22b933Srs #ifndef __mDNSDebug_h 184b22b933Srs #define __mDNSDebug_h 194b22b933Srs 20*472cd20dSToomas Soome #include "mDNSFeatures.h" 21*472cd20dSToomas Soome 22*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 23*472cd20dSToomas Soome #include <os/log.h> 24*472cd20dSToomas Soome #endif 25*472cd20dSToomas Soome 264b22b933Srs // Set MDNS_DEBUGMSGS to 0 to optimize debugf() calls out of the compiled code 274b22b933Srs // Set MDNS_DEBUGMSGS to 1 to generate normal debugging messages 284b22b933Srs // Set MDNS_DEBUGMSGS to 2 to generate verbose debugging messages 294b22b933Srs // MDNS_DEBUGMSGS is normally set in the project options (or makefile) but can also be set here if desired 304b22b933Srs // (If you edit the file here to turn on MDNS_DEBUGMSGS while you're debugging some code, be careful 314b22b933Srs // not to accidentally check-in that change by mistake when you check in your other changes.) 324b22b933Srs 334b22b933Srs //#undef MDNS_DEBUGMSGS 344b22b933Srs //#define MDNS_DEBUGMSGS 2 354b22b933Srs 364b22b933Srs // Set MDNS_CHECK_PRINTF_STYLE_FUNCTIONS to 1 to enable extra GCC compiler warnings 374b22b933Srs // Note: You don't normally want to do this, because it generates a bunch of 384b22b933Srs // spurious warnings for the following custom extensions implemented by mDNS_vsnprintf: 394b22b933Srs // warning: `#' flag used with `%s' printf format (for %#s -- pascal string format) 404b22b933Srs // warning: repeated `#' flag in format (for %##s -- DNS name string format) 414b22b933Srs // warning: double format, pointer arg (arg 2) (for %.4a, %.16a, %#a -- IP address formats) 424b22b933Srs #define MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 0 435ffb0c9bSToomas Soome 44*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 45*472cd20dSToomas Soome typedef os_log_t mDNSLogCategory_t; 46*472cd20dSToomas Soome 47*472cd20dSToomas Soome typedef os_log_type_t mDNSLogLevel_t; 48*472cd20dSToomas Soome #define MDNS_LOG_FAULT OS_LOG_TYPE_FAULT 49*472cd20dSToomas Soome #define MDNS_LOG_ERROR OS_LOG_TYPE_ERROR 50*472cd20dSToomas Soome #define MDNS_LOG_WARNING OS_LOG_TYPE_DEFAULT 51*472cd20dSToomas Soome #define MDNS_LOG_DEFAULT OS_LOG_TYPE_DEFAULT 52*472cd20dSToomas Soome #define MDNS_LOG_INFO OS_LOG_TYPE_DEFAULT 53*472cd20dSToomas Soome #define MDNS_LOG_DEBUG OS_LOG_TYPE_DEBUG 54*472cd20dSToomas Soome #else 55*472cd20dSToomas Soome typedef const char * mDNSLogCategory_t; 565ffb0c9bSToomas Soome typedef enum 575ffb0c9bSToomas Soome { 58*472cd20dSToomas Soome MDNS_LOG_FAULT = 1, 59*472cd20dSToomas Soome MDNS_LOG_ERROR = 2, 60*472cd20dSToomas Soome MDNS_LOG_WARNING = 3, 61*472cd20dSToomas Soome MDNS_LOG_DEFAULT = 4, 62*472cd20dSToomas Soome MDNS_LOG_INFO = 5, 63*472cd20dSToomas Soome MDNS_LOG_DEBUG = 6 645ffb0c9bSToomas Soome } mDNSLogLevel_t; 65*472cd20dSToomas Soome #endif 665ffb0c9bSToomas Soome 67*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 68*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_Default; 69*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_mDNS; 70*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_uDNS; 71*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_SPS; 72*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_XPC; 73*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_Analytics; 74*472cd20dSToomas Soome extern os_log_t mDNSLogCategory_DNSSEC; 75*472cd20dSToomas Soome 76*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_DEFINITION(NAME) mDNSLogCategory_ ## NAME 77*472cd20dSToomas Soome #else 78*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_DEFINITION(NAME) # NAME 79*472cd20dSToomas Soome #endif 80*472cd20dSToomas Soome 81*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_DEFAULT MDNS_LOG_CATEGORY_DEFINITION(Default) 82*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_MDNS MDNS_LOG_CATEGORY_DEFINITION(mDNS) 83*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_UDNS MDNS_LOG_CATEGORY_DEFINITION(uDNS) 84*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_SPS MDNS_LOG_CATEGORY_DEFINITION(SPS) 85*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_XPC MDNS_LOG_CATEGORY_DEFINITION(XPC) 86*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_ANALYTICS MDNS_LOG_CATEGORY_DEFINITION(Analytics) 87*472cd20dSToomas Soome #define MDNS_LOG_CATEGORY_DNSSEC MDNS_LOG_CATEGORY_DEFINITION(DNSSEC) 88*472cd20dSToomas Soome 89*472cd20dSToomas Soome // Set this symbol to 1 to answer remote queries for our Address, and reverse mapping PTR 905ffb0c9bSToomas Soome #define ANSWER_REMOTE_HOSTNAME_QUERIES 0 915ffb0c9bSToomas Soome 925ffb0c9bSToomas Soome // Set this symbol to 1 to do extra debug checks on malloc() and free() 935ffb0c9bSToomas Soome // Set this symbol to 2 to write a log message for every malloc() and free() 94*472cd20dSToomas Soome // #define MDNS_MALLOC_DEBUGGING 1 95*472cd20dSToomas Soome 96*472cd20dSToomas Soome #if (MDNS_MALLOC_DEBUGGING > 0) && defined(WIN32) 97*472cd20dSToomas Soome #error "Malloc debugging does not yet work on Windows" 98*472cd20dSToomas Soome #endif 995ffb0c9bSToomas Soome 1005ffb0c9bSToomas Soome //#define ForceAlerts 1 1015ffb0c9bSToomas Soome //#define LogTimeStamps 1 1025ffb0c9bSToomas Soome 1035ffb0c9bSToomas Soome // Developer-settings section ends here 1045ffb0c9bSToomas Soome 1054b22b933Srs #if MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 1064b22b933Srs #define IS_A_PRINTF_STYLE_FUNCTION(F,A) __attribute__ ((format(printf,F,A))) 1074b22b933Srs #else 1084b22b933Srs #define IS_A_PRINTF_STYLE_FUNCTION(F,A) 1094b22b933Srs #endif 1104b22b933Srs 1115ffb0c9bSToomas Soome #ifdef __cplusplus 1125ffb0c9bSToomas Soome extern "C" { 1135ffb0c9bSToomas Soome #endif 1145ffb0c9bSToomas Soome 1155ffb0c9bSToomas Soome // Variable argument macro support. Use ANSI C99 __VA_ARGS__ where possible. Otherwise, use the next best thing. 1165ffb0c9bSToomas Soome 1175ffb0c9bSToomas Soome #if (defined(__GNUC__)) 1185ffb0c9bSToomas Soome #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2))) 1195ffb0c9bSToomas Soome #define MDNS_C99_VA_ARGS 1 1205ffb0c9bSToomas Soome #define MDNS_GNU_VA_ARGS 0 1215ffb0c9bSToomas Soome #else 1225ffb0c9bSToomas Soome #define MDNS_C99_VA_ARGS 0 1235ffb0c9bSToomas Soome #define MDNS_GNU_VA_ARGS 1 1245ffb0c9bSToomas Soome #endif 1255ffb0c9bSToomas Soome #define MDNS_HAS_VA_ARG_MACROS 1 1265ffb0c9bSToomas Soome #elif (_MSC_VER >= 1400) // Visual Studio 2005 and later 1275ffb0c9bSToomas Soome #define MDNS_C99_VA_ARGS 1 1285ffb0c9bSToomas Soome #define MDNS_GNU_VA_ARGS 0 1295ffb0c9bSToomas Soome #define MDNS_HAS_VA_ARG_MACROS 1 1305ffb0c9bSToomas Soome #elif (defined(__MWERKS__)) 1315ffb0c9bSToomas Soome #define MDNS_C99_VA_ARGS 1 1325ffb0c9bSToomas Soome #define MDNS_GNU_VA_ARGS 0 1335ffb0c9bSToomas Soome #define MDNS_HAS_VA_ARG_MACROS 1 1345ffb0c9bSToomas Soome #else 1353b436d06SToomas Soome #define MDNS_C99_VA_ARGS 1 1365ffb0c9bSToomas Soome #define MDNS_GNU_VA_ARGS 0 1373b436d06SToomas Soome #define MDNS_HAS_VA_ARG_MACROS 1 1385ffb0c9bSToomas Soome #endif 1395ffb0c9bSToomas Soome 1405ffb0c9bSToomas Soome #if (MDNS_HAS_VA_ARG_MACROS) 1415ffb0c9bSToomas Soome #if (MDNS_C99_VA_ARGS) 142*472cd20dSToomas Soome #define MDNS_LOG_DEFINITION(LEVEL, ...) \ 143*472cd20dSToomas Soome do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_CATEGORY_DEFAULT, LEVEL, __VA_ARGS__); } while (0) 144*472cd20dSToomas Soome 145*472cd20dSToomas Soome #define debug_noop(...) do {} while(0) 146*472cd20dSToomas Soome #define LogMsg(...) LogMsgWithLevel(MDNS_LOG_CATEGORY_DEFAULT, MDNS_LOG_DEFAULT, __VA_ARGS__) 147*472cd20dSToomas Soome #define LogOperation(...) MDNS_LOG_DEFINITION(MDNS_LOG_INFO, __VA_ARGS__) 148*472cd20dSToomas Soome #define LogSPS(...) MDNS_LOG_DEFINITION(MDNS_LOG_INFO, __VA_ARGS__) 149*472cd20dSToomas Soome #define LogInfo(...) MDNS_LOG_DEFINITION(MDNS_LOG_INFO, __VA_ARGS__) 150*472cd20dSToomas Soome #define LogDebug(...) MDNS_LOG_DEFINITION(MDNS_LOG_DEBUG, __VA_ARGS__) 1515ffb0c9bSToomas Soome #elif (MDNS_GNU_VA_ARGS) 152*472cd20dSToomas Soome #define MDNS_LOG_DEFINITION(LEVEL, ARGS...) \ 153*472cd20dSToomas Soome do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_CATEGORY_DEFAULT, LEVEL, ARGS); } while (0) 154*472cd20dSToomas Soome 155*472cd20dSToomas Soome #define debug_noop(ARGS...) do {} while (0) 156*472cd20dSToomas Soome #define LogMsg(ARGS... ) LogMsgWithLevel(MDNS_LOG_CATEGORY_DEFAULT, MDNS_LOG_DEFAULT, ARGS) 157*472cd20dSToomas Soome #define LogOperation(ARGS...) MDNS_LOG_DEFINITION(MDNS_LOG_INFO, ARGS) 158*472cd20dSToomas Soome #define LogSPS(ARGS...) MDNS_LOG_DEFINITION(MDNS_LOG_INFO, ARGS) 159*472cd20dSToomas Soome #define LogInfo(ARGS...) MDNS_LOG_DEFINITION(MDNS_LOG_INFO, ARGS) 160*472cd20dSToomas Soome #define LogDebug(ARGS...) MDNS_LOG_DEFINITION(MDNS_LOG_DEBUG, ARGS) 1615ffb0c9bSToomas Soome #else 162*472cd20dSToomas Soome #error "Unknown variadic macros" 1635ffb0c9bSToomas Soome #endif 1645ffb0c9bSToomas Soome #else 1655ffb0c9bSToomas Soome // If your platform does not support variadic macros, you need to define the following variadic functions. 1665ffb0c9bSToomas Soome // See mDNSShared/mDNSDebug.c for sample implementation 1675ffb0c9bSToomas Soome #define debug_noop 1 ? (void)0 : (void) 1685ffb0c9bSToomas Soome #define LogMsg LogMsg_ 1695ffb0c9bSToomas Soome #define LogOperation (mDNS_LoggingEnabled == 0) ? ((void)0) : LogOperation_ 1705ffb0c9bSToomas Soome #define LogSPS (mDNS_LoggingEnabled == 0) ? ((void)0) : LogSPS_ 1715ffb0c9bSToomas Soome #define LogInfo (mDNS_LoggingEnabled == 0) ? ((void)0) : LogInfo_ 1723b436d06SToomas Soome #define LogDebug (mDNS_LoggingEnabled == 0) ? ((void)0) : LogDebug_ 1735ffb0c9bSToomas Soome extern void LogMsg_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1745ffb0c9bSToomas Soome extern void LogOperation_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1755ffb0c9bSToomas Soome extern void LogSPS_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1765ffb0c9bSToomas Soome extern void LogInfo_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1773b436d06SToomas Soome extern void LogDebug_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1784b22b933Srs #endif 1794b22b933Srs 180*472cd20dSToomas Soome 1814b22b933Srs #if MDNS_DEBUGMSGS 1824b22b933Srs #define debugf debugf_ 1834b22b933Srs extern void debugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1845ffb0c9bSToomas Soome #else 1855ffb0c9bSToomas Soome #define debugf debug_noop 1864b22b933Srs #endif 1874b22b933Srs 1884b22b933Srs #if MDNS_DEBUGMSGS > 1 1894b22b933Srs #define verbosedebugf verbosedebugf_ 1904b22b933Srs extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 1914b22b933Srs #else 1925ffb0c9bSToomas Soome #define verbosedebugf debug_noop 1934b22b933Srs #endif 1944b22b933Srs 1955ffb0c9bSToomas Soome extern int mDNS_LoggingEnabled; 1965ffb0c9bSToomas Soome extern int mDNS_PacketLoggingEnabled; 1975ffb0c9bSToomas Soome extern int mDNS_McastLoggingEnabled; 1985ffb0c9bSToomas Soome extern int mDNS_McastTracingEnabled; 1995ffb0c9bSToomas Soome extern int mDNS_DebugMode; // If non-zero, LogMsg() writes to stderr instead of syslog 2005ffb0c9bSToomas Soome extern const char ProgramName[]; 2014b22b933Srs 202*472cd20dSToomas Soome extern void LogMsgWithLevel(mDNSLogCategory_t category, mDNSLogLevel_t level, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(3,4); 2035ffb0c9bSToomas Soome // LogMsgNoIdent needs to be fixed so that it logs without the ident prefix like it used to 2045ffb0c9bSToomas Soome // (or completely overhauled to use the new "log to a separate file" facility) 2055ffb0c9bSToomas Soome #define LogMsgNoIdent LogMsg 2064b22b933Srs 207cda73f64SToomas Soome #if APPLE_OSX_mDNSResponder 208cda73f64SToomas Soome extern void LogFatalError(const char *format, ...); 209cda73f64SToomas Soome #else 210cda73f64SToomas Soome #define LogFatalError LogMsg 211cda73f64SToomas Soome #endif 212cda73f64SToomas Soome 213*472cd20dSToomas Soome #if MDNS_MALLOC_DEBUGGING >= 1 214*472cd20dSToomas Soome extern void *mallocL(const char *msg, mDNSu32 size); 215*472cd20dSToomas Soome extern void *callocL(const char *msg, mDNSu32 size); 216*472cd20dSToomas Soome extern void freeL(const char *msg, void *x); 217*472cd20dSToomas Soome #if APPLE_OSX_mDNSResponder 218cda73f64SToomas Soome extern void LogMemCorruption(const char *format, ...); 2194b22b933Srs #else 220*472cd20dSToomas Soome #define LogMemCorruption LogMsg 221*472cd20dSToomas Soome #endif 222*472cd20dSToomas Soome #else 223*472cd20dSToomas Soome #define mallocL(MSG, SIZE) malloc(SIZE) 224*472cd20dSToomas Soome #define callocL(MSG, SIZE) calloc(1, SIZE) 225*472cd20dSToomas Soome #define freeL(MSG, PTR) free(PTR) 2264b22b933Srs #endif 2274b22b933Srs 2285ffb0c9bSToomas Soome #ifdef __cplusplus 2295ffb0c9bSToomas Soome } 2304b22b933Srs #endif 2314b22b933Srs 232*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 233*472cd20dSToomas Soome /** @brief Write a log message to system's log storage(memory or disk). 234*472cd20dSToomas Soome * 235*472cd20dSToomas Soome * On Apple platform, os_log() will be called to log a message. 236*472cd20dSToomas Soome * 237*472cd20dSToomas Soome * @param CATEGORY A custom log object previously created by the os_log_create function, and such an object is 238*472cd20dSToomas Soome * used to specify "subsystem" and "category". For mDNSResponder, the subsystem should always 239*472cd20dSToomas Soome * be set to "com.apple.mDNSResponder"; and the category is used for categorization and 240*472cd20dSToomas Soome * filtering of related log messages within the subsystem’s settings. We have 4 categories that 241*472cd20dSToomas Soome * are pre-defined: MDNS_LOG_CATEGORY_DEFAULT, MDNS_LOG_CATEGORY_MDNS, MDNS_LOG_CATEGORY_UDNS, 242*472cd20dSToomas Soome * MDNS_LOG_CATEGORY_SPS. If these categories are not enough, use os_log_create to create more. 243*472cd20dSToomas Soome * 244*472cd20dSToomas Soome * @param LEVEL The log level that determines the importance of the message. The levels are, in order of 245*472cd20dSToomas Soome * decreasing importance: 246*472cd20dSToomas Soome * MDNS_LOG_FAULT Fault-level messages are intended for capturing system-level errors 247*472cd20dSToomas Soome * that are critical to the system. They are always saved in the data store. 248*472cd20dSToomas Soome * MDNS_LOG_ERROR Error-level messages are intended for reporting process-level errors 249*472cd20dSToomas Soome * that are unexpected and incorrect during the normal operation. They 250*472cd20dSToomas Soome * are always saved in the data store. 251*472cd20dSToomas Soome * MDNS_LOG_WARNING Warning-level messages are intended for capturing unexpected and 252*472cd20dSToomas Soome * possible incorrect behavior that might be used later to root cause 253*472cd20dSToomas Soome * an error or fault. They are are initially stored in memory buffers 254*472cd20dSToomas Soome * and then moved to a data store. 255*472cd20dSToomas Soome * MDNS_LOG_DEFAULT Default-level messages are intended for reporting things that might 256*472cd20dSToomas Soome * result a failure. They are are initially stored in memory buffers 257*472cd20dSToomas Soome * and then moved to a data store. 258*472cd20dSToomas Soome * MDNS_LOG_INFO Info-level messages are intended for capturing information that may 259*472cd20dSToomas Soome * be helpful, but isn’t essential, for troubleshooting errors. They 260*472cd20dSToomas Soome * are initially stored in memory buffers, but will only be moved into 261*472cd20dSToomas Soome * data store when faults and, optionally, errors occur. 262*472cd20dSToomas Soome * MDNS_LOG_DEBUG Debug-level messages are intended for information that may be useful 263*472cd20dSToomas Soome * during development or while troubleshooting a specific problem, Debug 264*472cd20dSToomas Soome * logging should not be used in shipping software. They are only 265*472cd20dSToomas Soome * captured in memory when debug logging is enabled through a 266*472cd20dSToomas Soome * configuration change. 267*472cd20dSToomas Soome * 268*472cd20dSToomas Soome * @param FORMAT A constant string or format string that produces a human-readable log message. The format 269*472cd20dSToomas Soome * string follows the IEEE printf specification, besides the following customized format specifiers: 270*472cd20dSToomas Soome * %{mdnsresponder:domain_name}.*P the pointer to a DNS lable sequence 271*472cd20dSToomas Soome * %{mdnsresponder:ip_addr}.20P the pointer to a mDNSAddr variable 272*472cd20dSToomas Soome * %{network:in_addr}.4P the pointer to a mDNSv4Addr variable 273*472cd20dSToomas Soome * %{network:in6_addr}.16P the pointer to a mDNSv6Addr variable 274*472cd20dSToomas Soome * %{mdnsresponder:mac_addr}.6P the pointer to a 6-byte-length MAC address 275*472cd20dSToomas Soome * 276*472cd20dSToomas Soome * @param ... The parameter list that will be formated by the format string. Note that if the customized 277*472cd20dSToomas Soome * format specifiers are used and the data length is not specified in the format string, the 278*472cd20dSToomas Soome * size should be listed before the pointer to the data, for example: 279*472cd20dSToomas Soome * "%{mdnsresponder:domain_name}.*P", (name ? (int)DomainNameLength((const domainname *)name) : 0), <the pointer to a DNS label sequence> 280*472cd20dSToomas Soome * 281*472cd20dSToomas Soome */ 282*472cd20dSToomas Soome #define LogRedact(CATEGORY, LEVEL, FORMAT, ...) os_log_with_type(CATEGORY, LEVEL, FORMAT, ## __VA_ARGS__) 283*472cd20dSToomas Soome #else 284*472cd20dSToomas Soome #if (MDNS_HAS_VA_ARG_MACROS) 285*472cd20dSToomas Soome #if (MDNS_C99_VA_ARGS) 286*472cd20dSToomas Soome #define LogRedact(CATEGORY, LEVEL, ...) \ 287*472cd20dSToomas Soome do { if (mDNS_LoggingEnabled) LogMsgWithLevel(CATEGORY, LEVEL, __VA_ARGS__); } while (0) 288*472cd20dSToomas Soome #elif (MDNS_GNU_VA_ARGS) 289*472cd20dSToomas Soome #define LogRedact(CATEGORY, LEVEL, ARGS...) \ 290*472cd20dSToomas Soome do { if (mDNS_LoggingEnabled) LogMsgWithLevel(CATEGORY, LEVEL, ARGS); } while (0) 291*472cd20dSToomas Soome #else 292*472cd20dSToomas Soome #error "Unknown variadic macros" 293*472cd20dSToomas Soome #endif 294*472cd20dSToomas Soome #else 295*472cd20dSToomas Soome #define LogRedact (mDNS_LoggingEnabled == 0) ? ((void)0) : LogRedact_ 296*472cd20dSToomas Soome extern void LogRedact_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 297*472cd20dSToomas Soome #endif 298*472cd20dSToomas Soome #endif // MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 299*472cd20dSToomas Soome 300*472cd20dSToomas Soome // The followings are the customized log specifier defined in os_log. For compatibility, we have to define it when it is 301*472cd20dSToomas Soome // not on the Apple platform, for example, the Posix platform. The keyword "public" or "private" is used to control whether 302*472cd20dSToomas Soome // the content would be redacted when the redaction is turned on: "public" means the content will always be printed; 303*472cd20dSToomas Soome // "private" means the content will be printed as <mask.hash: '<The hashed string from binary data>'> if the redaction is turned on, 304*472cd20dSToomas Soome // only when the redaction is turned off, the content will be printed as what it should be. Note that the hash performed 305*472cd20dSToomas Soome // to the data is a salted hashing transformation, and the salt is generated randomly on a per-process basis, meaning 306*472cd20dSToomas Soome // that hashes cannot be correlated across processes or devices. 307*472cd20dSToomas Soome 308*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 309*472cd20dSToomas Soome #define PUB_S "%{public}s" 310*472cd20dSToomas Soome #define PRI_S "%{private, mask.hash}s" 311*472cd20dSToomas Soome #else 312*472cd20dSToomas Soome #define PUB_S "%s" 313*472cd20dSToomas Soome #define PRI_S PUB_S 314*472cd20dSToomas Soome #endif 315*472cd20dSToomas Soome 316*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 317*472cd20dSToomas Soome #define PUB_DM_NAME "%{public, mdnsresponder:domain_name}.*P" 318*472cd20dSToomas Soome #define PRI_DM_NAME "%{private, mask.hash, mdnsresponder:domain_name}.*P" 319*472cd20dSToomas Soome // When DM_NAME_PARAM is used, the file where the function is defined must include DNSEmbeddedAPI.h 320*472cd20dSToomas Soome #define DM_NAME_PARAM(name) ((name) ? ((int)DomainNameLength((name))) : 0), (name) 321*472cd20dSToomas Soome #else 322*472cd20dSToomas Soome #define PUB_DM_NAME "%##s" 323*472cd20dSToomas Soome #define PRI_DM_NAME PUB_DM_NAME 324*472cd20dSToomas Soome #define DM_NAME_PARAM(name) (name) 3254b22b933Srs #endif 326*472cd20dSToomas Soome 327*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 328*472cd20dSToomas Soome #define PUB_IP_ADDR "%{public, mdnsresponder:ip_addr}.20P" 329*472cd20dSToomas Soome #define PRI_IP_ADDR "%{private, mask.hash, mdnsresponder:ip_addr}.20P" 330*472cd20dSToomas Soome 331*472cd20dSToomas Soome #define PUB_IPv4_ADDR "%{public, network:in_addr}.4P" 332*472cd20dSToomas Soome #define PRI_IPv4_ADDR "%{private, mask.hash, network:in_addr}.4P" 333*472cd20dSToomas Soome 334*472cd20dSToomas Soome #define PUB_IPv6_ADDR "%{public, network:in6_addr}.16P" 335*472cd20dSToomas Soome #define PRI_IPv6_ADDR "%{private, mask.hash, network:in6_addr}.16P" 336*472cd20dSToomas Soome #else 337*472cd20dSToomas Soome #define PUB_IP_ADDR "%#a" 338*472cd20dSToomas Soome #define PRI_IP_ADDR PUB_IP_ADDR 339*472cd20dSToomas Soome 340*472cd20dSToomas Soome #define PUB_IPv4_ADDR "%.4a" 341*472cd20dSToomas Soome #define PRI_IPv4_ADDR PUB_IPv4_ADDR 342*472cd20dSToomas Soome 343*472cd20dSToomas Soome #define PUB_IPv6_ADDR "%.16a" 344*472cd20dSToomas Soome #define PRI_IPv6_ADDR PUB_IPv6_ADDR 345*472cd20dSToomas Soome #endif 346*472cd20dSToomas Soome 347*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 348*472cd20dSToomas Soome #define PUB_MAC_ADDR "%{public, mdnsresponder:mac_addr}.6P" 349*472cd20dSToomas Soome #define PRI_MAC_ADDR "%{private, mask.hash, mdnsresponder:mac_addr}.6P" 350*472cd20dSToomas Soome #else 351*472cd20dSToomas Soome #define PUB_MAC_ADDR "%.6a" 352*472cd20dSToomas Soome #define PRI_MAC_ADDR PUB_MAC_ADDR 353*472cd20dSToomas Soome #endif 354*472cd20dSToomas Soome 355*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 356*472cd20dSToomas Soome #define PUB_DNSKEY "%{public, mdns:rd.dnskey}.*P" 357*472cd20dSToomas Soome #define PRI_DNSKEY "%{private, mask.hash, mdns:rd.dnskey}.*P" 358*472cd20dSToomas Soome #define DNSKEY_PARAM(rdata, rdata_length) (rdata_length), (rdata) 359*472cd20dSToomas Soome #else 360*472cd20dSToomas Soome #define PUB_DNSKEY "%p" 361*472cd20dSToomas Soome #define PRI_DNSKEY PUB_DNSKEY 362*472cd20dSToomas Soome #define DNSKEY_PARAM(rdata, rdata_length) (rdata) 363*472cd20dSToomas Soome #endif 364*472cd20dSToomas Soome 365*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 366*472cd20dSToomas Soome #define PUB_DS "%{public, mdns:rd.ds}.*P" 367*472cd20dSToomas Soome #define PRI_DS "%{private, mask.hash, mdns:rd.ds}.*P" 368*472cd20dSToomas Soome #define DS_PARAM(rdata, rdata_length) (rdata_length), (rdata) 369*472cd20dSToomas Soome #else 370*472cd20dSToomas Soome #define PUB_DS "%p" 371*472cd20dSToomas Soome #define PRI_DS PUB_DS 372*472cd20dSToomas Soome #define DS_PARAM(rdata, rdata_length) (rdata) 373*472cd20dSToomas Soome #endif 374*472cd20dSToomas Soome 375*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 376*472cd20dSToomas Soome #define PUB_NSEC "%{public, mdns:rd.nsec}.*P" 377*472cd20dSToomas Soome #define PRI_NSEC "%{private, mask.hash, mdns:rd.nsec}.*P" 378*472cd20dSToomas Soome #define NSEC_PARAM(rdata, rdata_length) (rdata_length), (rdata) 379*472cd20dSToomas Soome #else 380*472cd20dSToomas Soome #define PUB_NSEC "%p" 381*472cd20dSToomas Soome #define PRI_NSEC PUB_NSEC 382*472cd20dSToomas Soome #define NSEC_PARAM(rdata, rdata_length) (rdata) 383*472cd20dSToomas Soome #endif 384*472cd20dSToomas Soome 385*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 386*472cd20dSToomas Soome #define PUB_NSEC3 "%{public, mdns:rd.nsec3}.*P" 387*472cd20dSToomas Soome #define PRI_NSEC3 "%{private, mask.hash, mdns:rd.nsec3}.*P" 388*472cd20dSToomas Soome #define NSEC3_PARAM(rdata, rdata_length) (rdata_length), (rdata) 389*472cd20dSToomas Soome #else 390*472cd20dSToomas Soome #define PUB_NSEC3 "%p" 391*472cd20dSToomas Soome #define PRI_NSEC3 PUB_NSEC3 392*472cd20dSToomas Soome #define NSEC3_PARAM(rdata, rdata_length) (rdata) 393*472cd20dSToomas Soome #endif 394*472cd20dSToomas Soome 395*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 396*472cd20dSToomas Soome #define PUB_RRSIG "%{public, mdns:rd.rrsig}.*P" 397*472cd20dSToomas Soome #define PRI_RRSIG "%{private, mask.hash, mdns:rd.rrsig}.*P" 398*472cd20dSToomas Soome #define RRSIG_PARAM(rdata, rdata_length) (rdata_length), (rdata) 399*472cd20dSToomas Soome #else 400*472cd20dSToomas Soome #define PUB_RRSIG "%p" 401*472cd20dSToomas Soome #define PRI_RRSIG PUB_RRSIG 402*472cd20dSToomas Soome #define RRSIG_PARAM(rdata, rdata_length) (rdata) 403*472cd20dSToomas Soome #endif 404*472cd20dSToomas Soome 405*472cd20dSToomas Soome #if MDNSRESPONDER_SUPPORTS(APPLE, OS_LOG) 406*472cd20dSToomas Soome #define PUB_SVCB "%{public, mdns:rd.svcb}.*P" 407*472cd20dSToomas Soome #define PRI_SVCB "%{private, mask.hash, mdns:rd.svcb}.*P" 408*472cd20dSToomas Soome #define SVCB_PARAM(rdata, rdata_length) (rdata_length), (rdata) 409*472cd20dSToomas Soome #else 410*472cd20dSToomas Soome #define PUB_SVCB "%p" 411*472cd20dSToomas Soome #define PRI_SVCB PUB_SVCB 412*472cd20dSToomas Soome #define SVCB_PARAM(rdata, rdata_length) (rdata) 413*472cd20dSToomas Soome #endif 414*472cd20dSToomas Soome 415*472cd20dSToomas Soome extern void LogToFD(int fd, const char *format, ...); 416*472cd20dSToomas Soome 417*472cd20dSToomas Soome #endif // __mDNSDebug_h 418