|
|
|
@ -58,44 +58,79 @@ ip_str_t ip_to_str(const void *addr, int family) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Get category index by name */ |
|
|
|
static const struct { |
|
|
|
static debug_category_t get_category_by_name(const char* name) { |
|
|
|
const char* name; |
|
|
|
struct { |
|
|
|
debug_category_t category; |
|
|
|
const char* n; |
|
|
|
} g_debug_categories[] = { |
|
|
|
debug_category_t c; |
|
|
|
{"none", DEBUG_CATEGORY_NONE}, |
|
|
|
} map[] = { |
|
|
|
{"uasync", DEBUG_CATEGORY_UASYNC}, |
|
|
|
{"none", DEBUG_CATEGORY_NONE}, |
|
|
|
{"ll_queue", DEBUG_CATEGORY_LL_QUEUE}, |
|
|
|
{"uasync", DEBUG_CATEGORY_UASYNC}, |
|
|
|
{"connection", DEBUG_CATEGORY_CONNECTION}, |
|
|
|
{"ll_queue", DEBUG_CATEGORY_LL_QUEUE}, |
|
|
|
{"etcp", DEBUG_CATEGORY_ETCP}, |
|
|
|
{"connection", DEBUG_CATEGORY_CONNECTION}, |
|
|
|
{"crypto", DEBUG_CATEGORY_CRYPTO}, |
|
|
|
{"etcp", DEBUG_CATEGORY_ETCP}, |
|
|
|
{"memory", DEBUG_CATEGORY_MEMORY}, |
|
|
|
{"crypto", DEBUG_CATEGORY_CRYPTO}, |
|
|
|
{"timing", DEBUG_CATEGORY_TIMING}, |
|
|
|
{"memory", DEBUG_CATEGORY_MEMORY}, |
|
|
|
{"config", DEBUG_CATEGORY_CONFIG}, |
|
|
|
{"timing", DEBUG_CATEGORY_TIMING}, |
|
|
|
{"tun", DEBUG_CATEGORY_TUN}, |
|
|
|
{"config", DEBUG_CATEGORY_CONFIG}, |
|
|
|
{"routing", DEBUG_CATEGORY_ROUTING}, |
|
|
|
{"tun", DEBUG_CATEGORY_TUN}, |
|
|
|
{"timers", DEBUG_CATEGORY_TIMERS}, |
|
|
|
{"routing", DEBUG_CATEGORY_ROUTING}, |
|
|
|
{"normalizer", DEBUG_CATEGORY_NORMALIZER}, |
|
|
|
{"timers", DEBUG_CATEGORY_TIMERS}, |
|
|
|
{"bgp", DEBUG_CATEGORY_BGP}, |
|
|
|
{"normalizer", DEBUG_CATEGORY_NORMALIZER}, |
|
|
|
{"socket", DEBUG_CATEGORY_SOCKET}, |
|
|
|
{"bgp", DEBUG_CATEGORY_BGP}, |
|
|
|
{"control", DEBUG_CATEGORY_CONTROL}, |
|
|
|
{"socket", DEBUG_CATEGORY_SOCKET}, |
|
|
|
{"dump", DEBUG_CATEGORY_DUMP}, |
|
|
|
{"control", DEBUG_CATEGORY_CONTROL}, |
|
|
|
{"traffic", DEBUG_CATEGORY_TRAFFIC}, |
|
|
|
{"dump", DEBUG_CATEGORY_DUMP}, |
|
|
|
{"debug", DEBUG_CATEGORY_DEBUG}, |
|
|
|
{"traffic", DEBUG_CATEGORY_TRAFFIC}, |
|
|
|
{"general", DEBUG_CATEGORY_GENERAL}, |
|
|
|
{"debug", DEBUG_CATEGORY_DEBUG}, |
|
|
|
{"all", DEBUG_CATEGORY_ALL}, |
|
|
|
{"general", DEBUG_CATEGORY_GENERAL}, |
|
|
|
{NULL, DEBUG_CATEGORY_NONE} |
|
|
|
{"all", DEBUG_CATEGORY_ALL}, |
|
|
|
}; |
|
|
|
{NULL, 0} |
|
|
|
|
|
|
|
}; |
|
|
|
static const struct { |
|
|
|
|
|
|
|
const char* name; |
|
|
|
for (int i = 0; map[i].n; i++) { |
|
|
|
debug_level_t level; |
|
|
|
if (strcasecmp(map[i].n, name) == 0) { |
|
|
|
} g_level_table[] = { |
|
|
|
return map[i].c; |
|
|
|
{"none", DEBUG_LEVEL_NONE}, |
|
|
|
|
|
|
|
{"error", DEBUG_LEVEL_ERROR}, |
|
|
|
|
|
|
|
{"warn", DEBUG_LEVEL_WARN}, |
|
|
|
|
|
|
|
{"info", DEBUG_LEVEL_INFO}, |
|
|
|
|
|
|
|
{"debug", DEBUG_LEVEL_DEBUG}, |
|
|
|
|
|
|
|
{"trace", DEBUG_LEVEL_TRACE}, |
|
|
|
|
|
|
|
{NULL, DEBUG_LEVEL_NONE} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_category_t get_category_by_name(const char* name) { |
|
|
|
|
|
|
|
if (!name) return DEBUG_CATEGORY_NONE; |
|
|
|
|
|
|
|
for (int i = 0; g_debug_categories[i].name; i++) { |
|
|
|
|
|
|
|
if (strcasecmp(g_debug_categories[i].name, name) == 0) { |
|
|
|
|
|
|
|
return g_debug_categories[i].category; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return DEBUG_CATEGORY_NONE; |
|
|
|
return DEBUG_CATEGORY_NONE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug_level_t debug_level_from_name(const char* name) { |
|
|
|
|
|
|
|
if (!name) return DEBUG_LEVEL_NONE; |
|
|
|
|
|
|
|
for (int i = 0; g_level_table[i].name; i++) { |
|
|
|
|
|
|
|
if (strcasecmp(g_level_table[i].name, name) == 0) { |
|
|
|
|
|
|
|
return g_level_table[i].level; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Invalid debug level '%s' (valid: none,error,warn,info,debug,trace)", name); |
|
|
|
|
|
|
|
return DEBUG_LEVEL_INFO; /* fallback */ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void debug_set_category_level_by_name(const char* category_name, const char* level_name) { |
|
|
|
|
|
|
|
if (!category_name || !level_name) return; |
|
|
|
|
|
|
|
debug_category_t cat = get_category_by_name(category_name); |
|
|
|
|
|
|
|
if (cat == DEBUG_CATEGORY_NONE) { |
|
|
|
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Unknown debug category '%s'", category_name); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
debug_level_t lvl = debug_level_from_name(level_name); |
|
|
|
|
|
|
|
debug_set_category_level(cat, lvl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Get category name for logging */ |
|
|
|
/* Get category name for logging */ |
|
|
|
const char* debug_get_category_name(debug_category_t category_idx) { |
|
|
|
const char* debug_get_category_name(debug_category_t category_idx) { |
|
|
|
switch (category_idx) { |
|
|
|
switch (category_idx) { |
|
|
|
@ -390,27 +425,12 @@ int debug_parse_config(const char* config_string) { |
|
|
|
|
|
|
|
|
|
|
|
debug_category_t cat = get_category_by_name(category_name); |
|
|
|
debug_category_t cat = get_category_by_name(category_name); |
|
|
|
if (cat == DEBUG_CATEGORY_NONE) { |
|
|
|
if (cat == DEBUG_CATEGORY_NONE) { |
|
|
|
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Unknown debug category '%s'", category_name); |
|
|
|
u_free(str); |
|
|
|
u_free(str); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debug_level_t lev = DEBUG_LEVEL_NONE; |
|
|
|
debug_level_t lev = debug_level_from_name(level_name); |
|
|
|
if (strcasecmp(level_name, "none") == 0) { |
|
|
|
|
|
|
|
lev = DEBUG_LEVEL_NONE; |
|
|
|
|
|
|
|
} else if (strcasecmp(level_name, "error") == 0) { |
|
|
|
|
|
|
|
lev = DEBUG_LEVEL_ERROR; |
|
|
|
|
|
|
|
} else if (strcasecmp(level_name, "warn") == 0) { |
|
|
|
|
|
|
|
lev = DEBUG_LEVEL_WARN; |
|
|
|
|
|
|
|
} else if (strcasecmp(level_name, "info") == 0) { |
|
|
|
|
|
|
|
lev = DEBUG_LEVEL_INFO; |
|
|
|
|
|
|
|
} else if (strcasecmp(level_name, "debug") == 0) { |
|
|
|
|
|
|
|
lev = DEBUG_LEVEL_DEBUG; |
|
|
|
|
|
|
|
} else if (strcasecmp(level_name, "trace") == 0) { |
|
|
|
|
|
|
|
lev = DEBUG_LEVEL_TRACE; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
u_free(str); |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set per-category level */ |
|
|
|
/* Set per-category level */ |
|
|
|
int idx = 0; |
|
|
|
int idx = 0; |
|
|
|
|