1
This commit is contained in:
1 parent
46b62e2e77
commit
14bf6328a6
3 files changed
+80
-70
No files matched your search
+69
-49
@@ -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}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; map[i].n; i++) {
|
static const struct {
|
||||||
if (strcasecmp(map[i].n, name) == 0) {
|
const char* name;
|
||||||
return map[i].c;
|
debug_level_t level;
|
||||||
|
} g_level_table[] = {
|
||||||
|
{"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;
|
||||||
|
|||||||
@@ -126,6 +126,15 @@ debug_level_t debug_get_level(void);
|
|||||||
/* Get category name by index */
|
/* Get category name by index */
|
||||||
const char* debug_get_category_name(debug_category_t category_idx);
|
const char* debug_get_category_name(debug_category_t category_idx);
|
||||||
|
|
||||||
|
/* Get category by name string */
|
||||||
|
debug_category_t get_category_by_name(const char* name);
|
||||||
|
|
||||||
|
/* Get level by name string with error reporting */
|
||||||
|
debug_level_t debug_level_from_name(const char* name);
|
||||||
|
|
||||||
|
/* Set category level using text names (main API) */
|
||||||
|
void debug_set_category_level_by_name(const char* category_name, const char* level_name);
|
||||||
|
|
||||||
/* Format and output debug message (internal use by macros) */
|
/* Format and output debug message (internal use by macros) */
|
||||||
void debug_output(debug_level_t level, debug_category_t category_idx,
|
void debug_output(debug_level_t level, debug_category_t category_idx,
|
||||||
const char* function, const char* file, int line,
|
const char* function, const char* file, int line,
|
||||||
|
|||||||
+2
-21
@@ -157,27 +157,8 @@ struct UTUN_INSTANCE* utun_instance_create(struct UASYNC* ua, const char *config
|
|||||||
const char* cat_name = config->global.debug_levels.category[i];
|
const char* cat_name = config->global.debug_levels.category[i];
|
||||||
const char* lvl_str = config->global.debug_levels.level[i];
|
const char* lvl_str = config->global.debug_levels.level[i];
|
||||||
|
|
||||||
debug_category_t cat = 0;
|
debug_category_t cat = get_category_by_name(cat_name);
|
||||||
// Map category name to bitmask
|
if (cat != DEBUG_CATEGORY_NONE) {
|
||||||
if (strcmp(cat_name, "uasync") == 0) cat = DEBUG_CATEGORY_UASYNC;
|
|
||||||
else if (strcmp(cat_name, "ll_queue") == 0) cat = DEBUG_CATEGORY_LL_QUEUE;
|
|
||||||
else if (strcmp(cat_name, "connection") == 0) cat = DEBUG_CATEGORY_CONNECTION;
|
|
||||||
else if (strcmp(cat_name, "etcp") == 0) cat = DEBUG_CATEGORY_ETCP;
|
|
||||||
else if (strcmp(cat_name, "crypto") == 0) cat = DEBUG_CATEGORY_CRYPTO;
|
|
||||||
else if (strcmp(cat_name, "memory") == 0) cat = DEBUG_CATEGORY_MEMORY;
|
|
||||||
else if (strcmp(cat_name, "timing") == 0) cat = DEBUG_CATEGORY_TIMING;
|
|
||||||
else if (strcmp(cat_name, "config") == 0) cat = DEBUG_CATEGORY_CONFIG;
|
|
||||||
else if (strcmp(cat_name, "tun") == 0) cat = DEBUG_CATEGORY_TUN;
|
|
||||||
else if (strcmp(cat_name, "routing") == 0) cat = DEBUG_CATEGORY_ROUTING;
|
|
||||||
else if (strcmp(cat_name, "timers") == 0) cat = DEBUG_CATEGORY_TIMERS;
|
|
||||||
else if (strcmp(cat_name, "normalizer") == 0) cat = DEBUG_CATEGORY_NORMALIZER;
|
|
||||||
else if (strcmp(cat_name, "bgp") == 0) cat = DEBUG_CATEGORY_BGP;
|
|
||||||
else if (strcmp(cat_name, "socket") == 0) cat = DEBUG_CATEGORY_SOCKET;
|
|
||||||
else if (strcmp(cat_name, "control") == 0) cat = DEBUG_CATEGORY_CONTROL;
|
|
||||||
else if (strcmp(cat_name, "dump") == 0) cat = DEBUG_CATEGORY_DUMP;
|
|
||||||
else if (strcmp(cat_name, "traffic") == 0) cat = DEBUG_CATEGORY_TRAFFIC;
|
|
||||||
|
|
||||||
if (cat) {
|
|
||||||
debug_level_t lvl = DEBUG_LEVEL_NONE;
|
debug_level_t lvl = DEBUG_LEVEL_NONE;
|
||||||
if (strcmp(lvl_str, "error") == 0) lvl = DEBUG_LEVEL_ERROR;
|
if (strcmp(lvl_str, "error") == 0) lvl = DEBUG_LEVEL_ERROR;
|
||||||
else if (strcmp(lvl_str, "warn") == 0) lvl = DEBUG_LEVEL_WARN;
|
else if (strcmp(lvl_str, "warn") == 0) lvl = DEBUG_LEVEL_WARN;
|
||||||
|
|||||||
Reference in new issue
Block a user