OCT 1. log消息增加模块标识

This commit is contained in:
huangxin 2023-02-06 15:10:02 +08:00
parent c80525b6e0
commit 59a7b1798c
29 changed files with 428 additions and 269 deletions

View File

@ -18,7 +18,7 @@ CRIT = 130, LOG_CRIT
[formats] [formats]
simple = "%m" simple = "%m"
normal = "[%d(%F %T).%ms][%-6V][%f:%L] - %m" normal = "[%d(%F %T).%ms][%-6V][%c][%f:%L] - %m"
[rules] [rules]
*.* >stdout; normal *.* >stdout; normal

View File

@ -1,8 +1,8 @@
#include <zlog.h>
#include "configuration.h" #include "configuration.h"
#include "../hw_string.h" #include "../hw_string.h"
#include "../khash.h" #include "../khash.h"
#include "ini.h" #include "ini.h"
#include "zlog_module.h"
KHASH_MAP_INIT_STR(route_hashes, char *) KHASH_MAP_INIT_STR(route_hashes, char *)
@ -23,7 +23,7 @@ int configuration_handler(void *user, const char *section, const char *name, con
configuration *load_configuration(const char *filename) { configuration *load_configuration(const char *filename) {
configuration *config = malloc(sizeof(configuration)); configuration *config = malloc(sizeof(configuration));
if (ini_parse(filename, configuration_handler, config) < 0) { if (ini_parse(filename, configuration_handler, config) < 0) {
dzlog_error("Can't load configuration\n"); LOG_MSG(error, ZLOG_MOD_HTTPD, "Can't load configuration\n");
return NULL; return NULL;
} }
return config; return config;

View File

@ -7,7 +7,6 @@
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <haywire.h> #include <haywire.h>
#include <zlog.h>
#include "uv.h" #include "uv.h"
#include "hw_string.h" #include "hw_string.h"
#include "khash.h" #include "khash.h"
@ -20,8 +19,9 @@
#include "http_connection.h" #include "http_connection.h"
#include "http_request.h" #include "http_request.h"
#include "misc.h" #include "misc.h"
#include "zlog_module.h"
#define UVERR(err, msg) dzlog_error("%s: %s\n", msg, uv_strerror(err)) #define UVERR(err, msg) LOG_MSG(error, ZLOG_MOD_HTTPD, "%s: %s\n", msg, uv_strerror(err))
//fprintf(stderr, "%s: %s\n", msg, uv_strerror(err)) //fprintf(stderr, "%s: %s\n", msg, uv_strerror(err))
#if 0 #if 0
#define CHECK(r, msg) \ #define CHECK(r, msg) \
@ -88,7 +88,7 @@ int hw_init_from_config(char *configuration_filename) {
void print_configuration() { void print_configuration() {
#if 0 #if 0
dzlog_debug("Address: %s\n\tPort: %d\n\tThreads: %d\n\tBalancer: %s\n\t" LOG_MSG(debug, ZLOG_MOD_HTTPD, "Address: %s\n\tPort: %d\n\tThreads: %d\n\tBalancer: %s\n\t"
"Parser: %s\n\tTCP No Delay: %s\n\tListen backlog: %d\n\tMaximum request size: %d\n", "Parser: %s\n\tTCP No Delay: %s\n\tListen backlog: %d\n\tMaximum request size: %d\n",
config->http_listen_address, config->http_listen_address,
config->http_listen_port, config->http_listen_port,
@ -134,7 +134,7 @@ void hw_http_add_route(char *route, http_request_callback callback, void *user_d
routes = kh_init(string_hashmap); routes = kh_init(string_hashmap);
} }
set_route(routes, route, route_entry); set_route(routes, route, route_entry);
// dzlog_debug("Added route path: [%s]\n", route); // TODO: Replace with logging instead. // LOG_MSG(debug, ZLOG_MOD_HTTPD, "Added route path: [%s]\n", route); // TODO: Replace with logging instead.
} }
void free_http_server() { void free_http_server() {
@ -149,7 +149,11 @@ void free_http_server() {
kh_destroy(string_hashmap, routes); kh_destroy(string_hashmap, routes);
uv_close((uv_handle_t *)&server, NULL); uv_close((uv_handle_t *)&server, NULL);
uninit_http_request_cache(); uninit_http_request_cache();
dzlog_info("HTTP Server Close http://%s:%d\n", config->http_listen_address, config->http_listen_port); LOG_MSG(info,
ZLOG_MOD_HTTPD,
"HTTP Server Close http://%s:%d\n",
config->http_listen_address,
config->http_listen_port);
} }
int hw_http_open() { int hw_http_open() {
@ -193,7 +197,7 @@ int hw_http_open() {
int rc; int rc;
rc = uv_tcp_init_ex(uv_loop, &server, AF_INET); rc = uv_tcp_init_ex(uv_loop, &server, AF_INET);
if (rc != 0) { if (rc != 0) {
dzlog_warn("TWO %d\n", rc); LOG_MSG(warn, ZLOG_MOD_HTTPD, "TWO %d\n", rc);
} }
if (strcmp(config->balancer, "reuseport") == 0) { if (strcmp(config->balancer, "reuseport") == 0) {
@ -201,11 +205,11 @@ int hw_http_open() {
int on = 1; int on = 1;
rc = uv_fileno(&server, &fd); rc = uv_fileno(&server, &fd);
if (rc != 0) { if (rc != 0) {
dzlog_warn("ONE %d\n", rc); LOG_MSG(warn, ZLOG_MOD_HTTPD, "ONE %d\n", rc);
} }
rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&on, sizeof(on)); rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&on, sizeof(on));
if (rc != 0) { if (rc != 0) {
dzlog_warn("THREE %d\n", errno); LOG_MSG(warn, ZLOG_MOD_HTTPD, "THREE %d\n", errno);
} }
} }
@ -221,7 +225,11 @@ int hw_http_open() {
uv_listen((uv_stream_t *)&server, (int)config->listen_backlog, http_stream_on_connect); uv_listen((uv_stream_t *)&server, (int)config->listen_backlog, http_stream_on_connect);
print_configuration(); print_configuration();
dzlog_info("HTTP Server Listening at http://%s:%d\n", config->http_listen_address, config->http_listen_port); LOG_MSG(info,
ZLOG_MOD_HTTPD,
"HTTP Server Listening at http://%s:%d\n",
config->http_listen_address,
config->http_listen_port);
//uv_run(uv_loop, UV_RUN_DEFAULT); //uv_run(uv_loop, UV_RUN_DEFAULT);
} else if (listener_count > 0 && strcmp(config->balancer, "ipc") == 0) { } else if (listener_count > 0 && strcmp(config->balancer, "ipc") == 0) {
int i; int i;
@ -261,7 +269,7 @@ int hw_http_open() {
} }
print_configuration(); print_configuration();
dzlog_debug("Listening...\n"); LOG_MSG(debug, ZLOG_MOD_HTTPD, "Listening...\n");
//uv_run(uv_loop, UV_RUN_DEFAULT); //uv_run(uv_loop, UV_RUN_DEFAULT);
} }
@ -291,7 +299,7 @@ void reuseport_thread_start(void *arg) {
uv_fileno(&server, &fd); uv_fileno(&server, &fd);
rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&on, sizeof(on)); rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&on, sizeof(on));
if (rc != 0) { if (rc != 0) {
dzlog_warn("%d\n", errno); LOG_MSG(warn, ZLOG_MOD_HTTPD, "%d\n", errno);
} }
uv_tcp_bind(&server, (const struct sockaddr *)&addr, 0); uv_tcp_bind(&server, (const struct sockaddr *)&addr, 0);

View File

@ -23,6 +23,7 @@ AUX_SOURCE_DIRECTORY(cmdline C_SRC)
AUX_SOURCE_DIRECTORY(crypto C_SRC) AUX_SOURCE_DIRECTORY(crypto C_SRC)
AUX_SOURCE_DIRECTORY(hardware C_SRC) AUX_SOURCE_DIRECTORY(hardware C_SRC)
AUX_SOURCE_DIRECTORY(protocol C_SRC) AUX_SOURCE_DIRECTORY(protocol C_SRC)
AUX_SOURCE_DIRECTORY(zlog_module C_SRC)
IF (USED_REDIS) IF (USED_REDIS)
ADD_DEFINITIONS(-DUSED_REDIS) ADD_DEFINITIONS(-DUSED_REDIS)

View File

@ -2,10 +2,10 @@
// Created by xajhu on 2021/6/29 0029. // Created by xajhu on 2021/6/29 0029.
// //
#include "uthash/utstring.h" #include "uthash/utstring.h"
#include <zlog.h>
#include "banner.h" #include "banner.h"
#include "config.h" #include "config.h"
#include "zlog_module.h"
void banner_show() { void banner_show() {
FILE *fp; FILE *fp;
@ -29,10 +29,13 @@ void banner_show() {
fclose(fp); fclose(fp);
dzlog_info("================== Banner Used ===================\n%s\n", utstring_body(pBannerText)); LOG_MSG(info,
ZLOG_MOD_MAIN,
"================== Banner Used ===================\n%s\n",
utstring_body(pBannerText));
utstring_free(pBannerText); utstring_free(pBannerText);
} else { } else {
dzlog_error("Banner file does not exists: %s\n", utstring_body(pPath)); LOG_MSG(error, ZLOG_MOD_MAIN, "Banner file does not exists: %s\n", utstring_body(pPath));
} }
utstring_free(pPath); utstring_free(pPath);

View File

@ -5,7 +5,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <uv.h> #include <uv.h>
#include <zlog.h>
#include <sds/sds.h> #include <sds/sds.h>
#include "uthash/uthash.h" #include "uthash/uthash.h"
@ -14,6 +13,7 @@
#include "user_errno.h" #include "user_errno.h"
#include "crypto.h" #include "crypto.h"
#include "hardware.h" #include "hardware.h"
#include "zlog_module.h"
typedef struct { typedef struct {
CONFIG_ITEM_ID cfgId; CONFIG_ITEM_ID cfgId;
@ -137,7 +137,7 @@ static int cfg_is_upgrade(PCONFIG_ITEM pItem) {
static const char *load_string_value(const char *pKeyName) { static const char *load_string_value(const char *pKeyName) {
const char *pCfgVal; const char *pCfgVal;
if (config_lookup_string(&g_cfgContent, pKeyName, &pCfgVal) != CONFIG_TRUE) { if (config_lookup_string(&g_cfgContent, pKeyName, &pCfgVal) != CONFIG_TRUE) {
dzlog_error("No {%s} setting in configuration file.\n", pKeyName); LOG_MSG(error, ZLOG_MOD_CONFIG, "No {%s} setting in configuration file.\n", pKeyName);
return NULL; return NULL;
} }
@ -151,7 +151,11 @@ static const char *load_string_value(const char *pKeyName) {
unsigned char *pBuf = base64_decode(&pCfgVal[strlen(ENC_HEAD)], (unsigned int *)&bufSize); unsigned char *pBuf = base64_decode(&pCfgVal[strlen(ENC_HEAD)], (unsigned int *)&bufSize);
if (pBuf == NULL || bufSize <= 0) { if (pBuf == NULL || bufSize <= 0) {
dzlog_error("{%s} setting [%s] maybe a encryption message, base64 decode error.\n", pKeyName, pCfgVal); LOG_MSG(error,
ZLOG_MOD_CONFIG,
"{%s} setting [%s] maybe a encryption message, base64 decode error.\n",
pKeyName,
pCfgVal);
return NULL; return NULL;
} }
@ -176,7 +180,7 @@ static const char *load_string_value(const char *pKeyName) {
static int load_boolean_value(const char *pKeyName) { static int load_boolean_value(const char *pKeyName) {
int val; int val;
if (config_lookup_bool(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) { if (config_lookup_bool(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) {
dzlog_error("No {%s} setting in configuration file.\n", pKeyName); LOG_MSG(error, ZLOG_MOD_CONFIG, "No {%s} setting in configuration file.\n", pKeyName);
return DEFAULT_INTEGRAL_ERR_VALUE; return DEFAULT_INTEGRAL_ERR_VALUE;
} }
@ -186,7 +190,7 @@ static int load_boolean_value(const char *pKeyName) {
static long long int load_integral_value(const char *pKeyName) { static long long int load_integral_value(const char *pKeyName) {
long long val; long long val;
if (config_lookup_int64(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) { if (config_lookup_int64(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) {
dzlog_error("No {%s} setting in configuration file.\n", pKeyName); LOG_MSG(error, ZLOG_MOD_CONFIG, "No {%s} setting in configuration file.\n", pKeyName);
return DEFAULT_INTEGRAL_ERR_VALUE; return DEFAULT_INTEGRAL_ERR_VALUE;
} }
@ -196,7 +200,7 @@ static long long int load_integral_value(const char *pKeyName) {
static double load_float_value(const char *pKeyName) { static double load_float_value(const char *pKeyName) {
double val; double val;
if (config_lookup_float(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) { if (config_lookup_float(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) {
dzlog_error("No {%s} setting in configuration file.\n", pKeyName); LOG_MSG(error, ZLOG_MOD_CONFIG, "No {%s} setting in configuration file.\n", pKeyName);
return DEFAULT_INTEGRAL_ERR_VALUE; return DEFAULT_INTEGRAL_ERR_VALUE;
} }
@ -392,7 +396,9 @@ static void refreshCfgFileCb() {
int cfgUpgrade = FALSE; int cfgUpgrade = FALSE;
if (!config_read_file(&g_cfgContent, g_cfgFilePath)) { if (!config_read_file(&g_cfgContent, g_cfgFilePath)) {
dzlog_error("%s:%d - %s\n", LOG_MSG(error,
ZLOG_MOD_CONFIG,
"%s:%d - %s\n",
config_error_file(&g_cfgContent), config_error_file(&g_cfgContent),
config_error_line(&g_cfgContent), config_error_line(&g_cfgContent),
config_error_text(&g_cfgContent)); config_error_text(&g_cfgContent));
@ -610,37 +616,37 @@ const char *config_item_dump_fmt(const char *titleMessage) {
void config_item_dump(const char *titleMessage) { void config_item_dump(const char *titleMessage) {
const char *pMsg = config_item_dump_fmt(titleMessage); const char *pMsg = config_item_dump_fmt(titleMessage);
dzlog_info("%s", pMsg); LOG_MSG(info, ZLOG_MOD_CONFIG, "%s", pMsg);
free((char *)pMsg); free((char *)pMsg);
#if 0 #if 0
PCONFIG_ITEM pItem, pTmp; PCONFIG_ITEM pItem, pTmp;
//int i, k = ARRAY_SIZE(g_sysConfigMap); //int i, k = ARRAY_SIZE(g_sysConfigMap);
dzlog_info("================== %s ===================\n", titleMessage == NULL ? "" : titleMessage); LOG_MSG(info, ZLOG_MOD_CONFIG, "================== %s ===================\n", titleMessage == NULL ? "" : titleMessage);
HASH_ITER(hh, g_pConfigItem, pItem, pTmp) { HASH_ITER(hh, g_pConfigItem, pItem, pTmp) {
switch (pItem->valType) { switch (pItem->valType) {
case VAL_BOOL: case VAL_BOOL:
dzlog_info("%s%-25s: [%-45s] = %s\n", LOG_MSG(info, ZLOG_MOD_CONFIG, "%s%-25s: [%-45s] = %s\n",
cfg_is_upgrade(pItem) ? "*" : " ", cfg_is_upgrade(pItem) ? "*" : " ",
pItem->pStrId, pItem->pStrId,
pItem->pcfgKey, pItem->pcfgKey,
CFG_BOOL_VALUE(pItem) ? "True" : "False"); CFG_BOOL_VALUE(pItem) ? "True" : "False");
break; break;
case VAL_INT: case VAL_INT:
dzlog_info("%s%-25s: [%-45s] = %lld\n", LOG_MSG(info, ZLOG_MOD_CONFIG, "%s%-25s: [%-45s] = %lld\n",
cfg_is_upgrade(pItem) ? "*" : " ", cfg_is_upgrade(pItem) ? "*" : " ",
pItem->pStrId, pItem->pStrId,
pItem->pcfgKey, pItem->pcfgKey,
CFG_INT_VALUE(pItem)); CFG_INT_VALUE(pItem));
break; break;
case VAL_FLOAT: case VAL_FLOAT:
dzlog_info("%s%-25s: [%-45s] = %Lf\n", LOG_MSG(info, ZLOG_MOD_CONFIG, "%s%-25s: [%-45s] = %Lf\n",
cfg_is_upgrade(pItem) ? "*" : " ", cfg_is_upgrade(pItem) ? "*" : " ",
pItem->pStrId, pItem->pStrId,
pItem->pcfgKey, pItem->pcfgKey,
CFG_FLOAT_VALUE(pItem)); CFG_FLOAT_VALUE(pItem));
break; break;
case VAL_STR: case VAL_STR:
dzlog_info("%s%-25s: [%-45s] = \"%s\"\n", LOG_MSG(info, ZLOG_MOD_CONFIG, "%s%-25s: [%-45s] = \"%s\"\n",
cfg_is_upgrade(pItem) ? "*" : " ", cfg_is_upgrade(pItem) ? "*" : " ",
pItem->pStrId, pItem->pStrId,
pItem->pcfgKey, pItem->pcfgKey,
@ -707,7 +713,7 @@ int init_config_system(const char *pCfgFile, const char *pKey) {
int i; int i;
if (!file_exists(pCfgFile)) { if (!file_exists(pCfgFile)) {
dzlog_error("Configuration file [%s] not exists\n", pCfgFile); LOG_MSG(error, ZLOG_MOD_CONFIG, "Configuration file [%s] not exists\n", pCfgFile);
return -ERR_FILE_NOT_EXISTS; return -ERR_FILE_NOT_EXISTS;
} }
@ -769,7 +775,7 @@ const char *get_config_key(const char *pKeygen) {
unsigned char *pBase64 = (unsigned char *)base64_decode(pKeygen, (unsigned int *)&outSize); unsigned char *pBase64 = (unsigned char *)base64_decode(pKeygen, (unsigned int *)&outSize);
if (pBase64 == NULL) { if (pBase64 == NULL) {
dzlog_error("Base64 decode error: %s\n", pKeygen); LOG_MSG(error, ZLOG_MOD_CONFIG, "Base64 decode error: %s\n", pKeygen);
return NULL; return NULL;
} }

View File

@ -4,9 +4,9 @@
#include <string.h> #include <string.h>
#include <openssl/aes.h> #include <openssl/aes.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <zlog.h>
#include "crypto.h" #include "crypto.h"
#include "zlog_module.h"
#if 0 #if 0
/** /**
@ -129,7 +129,7 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize) {
#else #else
EVP_DecodeInit(pCtx); EVP_DecodeInit(pCtx);
if (EVP_DecodeUpdate(pCtx, pDecode, &enSize, (const unsigned char *)pBase64, size) == -1) { if (EVP_DecodeUpdate(pCtx, pDecode, &enSize, (const unsigned char *)pBase64, size) == -1) {
dzlog_error("Decode [%s] error\n", pBase64); LOG_MSG(error, ZLOG_MOD_CRYPTO, "Decode [%s] error\n", pBase64);
free(pDecode); free(pDecode);
return NULL; return NULL;
} }
@ -142,7 +142,7 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize) {
EVP_DecodeFinal(&ctx, pDecode + enSize, &size); EVP_DecodeFinal(&ctx, pDecode + enSize, &size);
#else #else
if (EVP_DecodeFinal(pCtx, pDecode, &enSize) == -1) { if (EVP_DecodeFinal(pCtx, pDecode, &enSize) == -1) {
dzlog_error("Finish decode [%s] error\n", pBase64); LOG_MSG(error, ZLOG_MOD_CRYPTO, "Finish decode [%s] error\n", pBase64);
free(pDecode); free(pDecode);
return NULL; return NULL;
} }

View File

@ -6,11 +6,11 @@
#include <unistd.h> #include <unistd.h>
#include <openssl/aes.h> #include <openssl/aes.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <zlog.h>
#include "crypto.h" #include "crypto.h"
#include "misc.h" #include "misc.h"
#include "user_errno.h" #include "user_errno.h"
#include "zlog_module.h"
/** /**
* MD5值 * MD5值
@ -57,7 +57,7 @@ int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValu
fd = open(pFileName, O_RDONLY); fd = open(pFileName, O_RDONLY);
if (fd == -1) { if (fd == -1) {
dzlog_error("Open File %s error\n", pFileName); LOG_MSG(error, ZLOG_MOD_CRYPTO, "Open File %s error\n", pFileName);
EVP_MD_CTX_destroy(pCtx); EVP_MD_CTX_destroy(pCtx);
return (-ERR_OPEN_FILE); return (-ERR_OPEN_FILE);
} }

View File

@ -0,0 +1,62 @@
//
// Created by xajhuang on 2023/2/6.
//
#ifndef VCPE_ZLOG_MODULE_H
#define VCPE_ZLOG_MODULE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <zlog.h>
#define MAX_ZLOG_MOD_LEN (8)
typedef enum {
ZLOG_MOD_MAIN,
ZLOG_MOD_TASK,
ZLOG_MOD_INIT,
ZLOG_MOD_MISC,
ZLOG_MOD_CONFIG,
ZLOG_MOD_NET,
ZLOG_MOD_CRYPTO,
ZLOG_MOD_MQ,
ZLOG_MOD_PROTO,
ZLOG_MOD_HTTPD,
#ifdef USED_LWIP
ZLOG_MOD_USER,
ZLOG_MOD_PPPOE,
ZLOG_MOD_VXLAN,
ZLOG_MOD_LWIP,
#endif
ZLOG_MOD_OPENDHCPD,
ZLOG_MOD_MAX,
} ZLOG_MOD_NAME;
#define LOG_MSG(level, mod, format, ...) \
do { \
zlog_category_t *cat; \
if ((cat = zlog_get_mod_cat((mod))) == NULL) { \
printf("Unsupport log mod %d\n", mod); \
break; \
} else { \
zlog_##level((cat), format, ##__VA_ARGS__); \
} \
} while (0)
#define LOG_MSG_HEX(level, mod, format, ...) \
do { \
zlog_category_t *cat; \
if ((cat = zlog_get_mod_cat((mod))) == NULL) { \
printf("Unsupport log mod %d\n", mod); \
break; \
} else { \
hzlog_##level((cat), format, ##__VA_ARGS__); \
} \
} while (0)
zlog_category_t *zlog_get_mod_cat(ZLOG_MOD_NAME logMod);
#ifdef __cplusplus
}
#endif
#endif //VCPE_ZLOG_MODULE_H

View File

@ -2,7 +2,6 @@
// Created by xajhu on 2021/7/5 0005. // Created by xajhu on 2021/7/5 0005.
// //
#include <uv.h> #include <uv.h>
#include <zlog.h>
#include <unistd.h> #include <unistd.h>
#include "init.h" #include "init.h"
@ -20,6 +19,7 @@
#include "haywire.h" #include "haywire.h"
#include "lib_config.h" #include "lib_config.h"
#include "prj_config.h" #include "prj_config.h"
#include "zlog_module.h"
#define DEFAULT_CONFIG_FILE ("vcpe.cfg") #define DEFAULT_CONFIG_FILE ("vcpe.cfg")
#define DEFAULT_CONFIG_DIR ("config") #define DEFAULT_CONFIG_DIR ("config")
@ -30,7 +30,7 @@ static int g_isInited = FALSE;
static void catch_system_interupt(int UNUSED(sig_num)) { static void catch_system_interupt(int UNUSED(sig_num)) {
if (g_pid == uv_os_getpid()) { if (g_pid == uv_os_getpid()) {
printf("\n"); printf("\n");
dzlog_warn("System close, clearing system resources..........\n\n"); LOG_MSG(warn, ZLOG_MOD_INIT, "System close, clearing system resources..........\n\n");
task_manager_exit(); task_manager_exit();
sleep(1); sleep(1);
} }
@ -82,7 +82,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
zlog_profile(); zlog_profile();
return -ERR_ZLOG_INIT; return -ERR_ZLOG_INIT;
} else { } else {
dzlog_info("Zlog used configure file [%s]\n", utstring_body(pPath)); LOG_MSG(info, ZLOG_MOD_INIT, "Zlog used configure file [%s]\n", utstring_body(pPath));
} }
} else { } else {
printf("Zlog configure file [%s] not found, Zlog system not work+++++\n", utstring_body(pPath)); printf("Zlog configure file [%s] not found, Zlog system not work+++++\n", utstring_body(pPath));
@ -94,13 +94,15 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
utstring_free(pPath); utstring_free(pPath);
// 处置化配置文件库,系统集成配置文件支持功能 // 处置化配置文件库,系统集成配置文件支持功能
dzlog_info("System used configure file [%s]\n", bufCfgFile); LOG_MSG(info, ZLOG_MOD_INIT, "System used configure file [%s]\n", bufCfgFile);
if ((ret = init_config_system(bufCfgFile, pKey)) != ERR_SUCCESS) { if ((ret = init_config_system(bufCfgFile, pKey)) != ERR_SUCCESS) {
dzlog_error("Load system configuration error: %d\n", ret); LOG_MSG(error, ZLOG_MOD_INIT, "Load system configuration error: %d\n", ret);
return -ERR_CONFIG_INIT; return -ERR_CONFIG_INIT;
} }
dzlog_info("%s library version %s information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n", LOG_MSG(info,
ZLOG_MOD_INIT,
"%s library version %s information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n",
VCPE_LIB_NAME, VCPE_LIB_NAME,
VCPE_LIB_VER, VCPE_LIB_VER,
VCPE_GIT_VERSION, VCPE_GIT_VERSION,
@ -121,11 +123,11 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
} }
if ((ret = mq_init()) != ERR_SUCCESS) { if ((ret = mq_init()) != ERR_SUCCESS) {
dzlog_error("Message queue init error: %d\n", ret); LOG_MSG(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret);
} }
if ((ret = mq_data_init()) != ERR_SUCCESS) { if ((ret = mq_data_init()) != ERR_SUCCESS) {
dzlog_error("Message queue init error: %d\n", ret); LOG_MSG(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret);
} }
http_svr_init(); http_svr_init();

View File

@ -4,7 +4,6 @@
#include <string.h> #include <string.h>
#include <uv.h> #include <uv.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include <zlog.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
@ -15,6 +14,7 @@
#include "user_errno.h" #include "user_errno.h"
#include "misc.h" #include "misc.h"
#include "zlog_module.h"
const char *basename_v2(const char *path) { const char *basename_v2(const char *path) {
const char *tail = strrchr(path, '/'); const char *tail = strrchr(path, '/');
@ -53,14 +53,14 @@ int copy_file(const char *pSrc, const char *pDest) {
ssize_t sz; ssize_t sz;
if (stat(pSrc, &st) != 0) { if (stat(pSrc, &st) != 0) {
dzlog_error("Get File %s Size Error\n", pSrc); LOG_MSG(error, ZLOG_MOD_MISC, "Get File %s Size Error\n", pSrc);
return (-ERR_GET_FILE_SIZE); return (-ERR_GET_FILE_SIZE);
} }
fdSrc = open(pSrc, O_RDONLY); fdSrc = open(pSrc, O_RDONLY);
if (fdSrc < 0) { if (fdSrc < 0) {
dzlog_error("Open File %s Error\n", pSrc); LOG_MSG(error, ZLOG_MOD_MISC, "Open File %s Error\n", pSrc);
return (-ERR_OPEN_FILE); return (-ERR_OPEN_FILE);
} }
@ -68,14 +68,14 @@ int copy_file(const char *pSrc, const char *pDest) {
if (fdDest < 0) { if (fdDest < 0) {
close(fdSrc); close(fdSrc);
dzlog_error("Open File %s Error\n", pDest); LOG_MSG(error, ZLOG_MOD_MISC, "Open File %s Error\n", pDest);
return (-ERR_OPEN_FILE); return (-ERR_OPEN_FILE);
} }
sz = sendfile(fdDest, fdSrc, NULL, st.st_size); sz = sendfile(fdDest, fdSrc, NULL, st.st_size);
if (sz != st.st_size) { if (sz != st.st_size) {
dzlog_error("Copy File Size Error: %zd, %ld\n", sz, st.st_size); LOG_MSG(error, ZLOG_MOD_MISC, "Copy File Size Error: %zd, %ld\n", sz, st.st_size);
close(fdSrc); close(fdSrc);
close(fdDest); close(fdDest);
return (-ERR_COPY_FILE); return (-ERR_COPY_FILE);
@ -201,7 +201,7 @@ int get_nic_info(const char *pName,
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0) { if (sock < 0) {
dzlog_error("Get local NIC information failed\n"); LOG_MSG(error, ZLOG_MOD_MISC, "Get local NIC information failed\n");
return -ERR_SYS_INIT; return -ERR_SYS_INIT;
} }

View File

@ -5,12 +5,12 @@
#include <zmq.h> #include <zmq.h>
#include <uv.h> #include <uv.h>
#include <string.h> #include <string.h>
#include <zlog.h>
#include "msg_queue.h" #include "msg_queue.h"
#include "config.h" #include "config.h"
#include "s2j/s2j.h" #include "s2j/s2j.h"
#include "user_errno.h" #include "user_errno.h"
#include "zlog_module.h"
#ifdef LWIP_ON #ifdef LWIP_ON
#include "misc.h" #include "misc.h"
@ -300,7 +300,7 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) {
memset(pBuf, 0, size); memset(pBuf, 0, size);
memcpy(pBuf, zmq_msg_data(pMsg), size - 1); memcpy(pBuf, zmq_msg_data(pMsg), size - 1);
dzlog_info("receive(%zu): %s\n", strlen(pdata), pBuf); LOG_MSG(info, ZLOG_MOD_MQ, "receive(%zu): %s\n", strlen(pdata), pBuf);
zmq_msg_close(pMsg); zmq_msg_close(pMsg);
@ -309,7 +309,7 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) {
if (pMqMsg) { if (pMqMsg) {
if (strcmp(AGENT_CMD_ADDUSER, pMqMsg->message) == 0) { if (strcmp(AGENT_CMD_ADDUSER, pMqMsg->message) == 0) {
PMQ_DATA_ADD_USER p = NULL; PMQ_DATA_ADD_USER p = NULL;
dzlog_debug("Process: %s\n", pMqMsg->params); LOG_MSG(debug, ZLOG_MOD_MQ, "Process: %s\n", pMqMsg->params);
decode_add_user_msg(pMqMsg->params, &p); decode_add_user_msg(pMqMsg->params, &p);
if (p) { if (p) {
#ifdef LWIP_ON #ifdef LWIP_ON
@ -338,7 +338,7 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) {
} }
} else if (strcmp(AGENT_CMD_REMOVUSER, pMqMsg->message) == 0) { } else if (strcmp(AGENT_CMD_REMOVUSER, pMqMsg->message) == 0) {
PMQ_DATA_REMOVE_USER p = NULL; PMQ_DATA_REMOVE_USER p = NULL;
dzlog_debug("Process: %s\n", pMqMsg->params); LOG_MSG(debug, ZLOG_MOD_MQ, "Process: %s\n", pMqMsg->params);
decode_remove_user_msg(pMqMsg->params, &p); decode_remove_user_msg(pMqMsg->params, &p);
@ -362,7 +362,7 @@ int mq_data_send_msg(const char *pMsg) {
zmq_msg_t msg; zmq_msg_t msg;
if (pMsg) { if (pMsg) {
dzlog_debug("Send PPPoE Session: %s\n", pMsg); LOG_MSG(debug, ZLOG_MOD_MQ, "Send PPPoE Session: %s\n", pMsg);
zmq_msg_init_size(&msg, strlen(pMsg) + 1); zmq_msg_init_size(&msg, strlen(pMsg) + 1);
memset(zmq_msg_data(&msg), 0, strlen(pMsg) + 1); memset(zmq_msg_data(&msg), 0, strlen(pMsg) + 1);
memcpy(zmq_msg_data(&msg), pMsg, strlen(pMsg)); memcpy(zmq_msg_data(&msg), pMsg, strlen(pMsg));
@ -407,7 +407,7 @@ int mq_data_init() {
memset(buf, 0, 1024); memset(buf, 0, 1024);
sprintf(buf, "%s", cfg_get_zero_mq_data_path()); sprintf(buf, "%s", cfg_get_zero_mq_data_path());
dzlog_info("Start message queue connect: %s\n", buf); LOG_MSG(info, ZLOG_MOD_MQ, "Start message queue connect: %s\n", buf);
if (zmq_connect(g_pDataCh, buf) != 0) { if (zmq_connect(g_pDataCh, buf) != 0) {
zmq_close(g_pDataCh); zmq_close(g_pDataCh);

View File

@ -5,12 +5,14 @@
#include <zmq.h> #include <zmq.h>
#include <uv.h> #include <uv.h>
#include <string.h> #include <string.h>
#include <zlog.h>
#include "zlog_module.h"
#include "msg_queue.h" #include "msg_queue.h"
#include "config.h" #include "config.h"
#include "user_errno.h" #include "user_errno.h"
#ifdef USED_LWIP
#include "misc.h" #include "misc.h"
#endif
static int g_mqExit = FALSE; static int g_mqExit = FALSE;
static void *g_pContext = NULL; static void *g_pContext = NULL;
@ -21,7 +23,7 @@ static void process_msg(zmq_msg_t *pMsg) {
zmq_msg_t msg; zmq_msg_t msg;
const char *pRecMsg = strdup((const char *)zmq_msg_data(pMsg)); const char *pRecMsg = strdup((const char *)zmq_msg_data(pMsg));
dzlog_info("receive(%zu): %s\n", zmq_msg_size(pMsg), pRecMsg); LOG_MSG(info, ZLOG_MOD_MQ, "receive(%zu): %s\n", zmq_msg_size(pMsg), pRecMsg);
zmq_msg_close(pMsg); zmq_msg_close(pMsg);
pResp = on_msg_cmd(pRecMsg); pResp = on_msg_cmd(pRecMsg);
@ -92,7 +94,7 @@ int mq_init(void) {
memset(buf, 0, 1024); memset(buf, 0, 1024);
sprintf(buf, "tcp://*:%d", cfg_get_zero_mq_port()); sprintf(buf, "tcp://*:%d", cfg_get_zero_mq_port());
dzlog_info("Start message queue server: tcp://*:%d\n", cfg_get_zero_mq_port()); LOG_MSG(info, ZLOG_MOD_MQ, "Start message queue server: tcp://*:%d\n", cfg_get_zero_mq_port());
if (zmq_bind(g_pResponse, buf) != 0) { if (zmq_bind(g_pResponse, buf) != 0) {
zmq_close(g_pResponse); zmq_close(g_pResponse);

View File

@ -2,7 +2,6 @@
// Created by xajhu on 2021/7/1 0001. // Created by xajhu on 2021/7/1 0001.
// //
#include <stdlib.h> #include <stdlib.h>
#include <zlog.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <string.h> #include <string.h>
#include <uv.h> #include <uv.h>
@ -15,6 +14,7 @@
#include "uthash/uthash.h" #include "uthash/uthash.h"
#include "task_manager.h" #include "task_manager.h"
#include "user_errno.h" #include "user_errno.h"
#include "zlog_module.h"
#define MAX_TIMEOUT_VALUE (300) #define MAX_TIMEOUT_VALUE (300)
@ -95,7 +95,7 @@ static void uvFsCloseCb(uv_fs_t *puvFs) {
PHTTP_REQ_PARAMS pParams = (PHTTP_REQ_PARAMS)puvFs->data; PHTTP_REQ_PARAMS pParams = (PHTTP_REQ_PARAMS)puvFs->data;
if (puvFs->result < 0) { if (puvFs->result < 0) {
dzlog_error("Error: %zd\n", puvFs->result); LOG_MSG(error, ZLOG_MOD_NET, "Error: %zd\n", puvFs->result);
} }
uv_fs_req_cleanup(puvFs); uv_fs_req_cleanup(puvFs);
@ -136,7 +136,7 @@ static void uvFsDataSyncCb(uv_fs_t *puvFs) {
PHTTP_REQ_PARAMS pParams = (PHTTP_REQ_PARAMS)puvFs->data; PHTTP_REQ_PARAMS pParams = (PHTTP_REQ_PARAMS)puvFs->data;
if (puvFs->result < 0) { if (puvFs->result < 0) {
dzlog_error("Error: %zd\n", puvFs->result); LOG_MSG(error, ZLOG_MOD_NET, "Error: %zd\n", puvFs->result);
} }
uv_fs_req_cleanup(puvFs); uv_fs_req_cleanup(puvFs);
@ -150,7 +150,7 @@ static PCURL_CONTEXT_DATA createCurlContext(curl_socket_t sock) {
pContext->sock = sock; pContext->sock = sock;
if (uv_poll_init_socket(get_task_manager(), &pContext->uvPool, sock) != 0) { if (uv_poll_init_socket(get_task_manager(), &pContext->uvPool, sock) != 0) {
dzlog_error("uv_poll_init_socket Error\n"); LOG_MSG(error, ZLOG_MOD_NET, "uv_poll_init_socket Error\n");
} }
pContext->uvPool.data = pContext; pContext->uvPool.data = pContext;
@ -168,7 +168,7 @@ static void checkMultiInfoTimeout(void) {
case CURLMSG_DONE: case CURLMSG_DONE:
curl_easy_getinfo(pMsg->easy_handle, CURLINFO_PRIVATE, (void *)&pReq); curl_easy_getinfo(pMsg->easy_handle, CURLINFO_PRIVATE, (void *)&pReq);
dzlog_error("Cleanup CURL: %p\n", pMsg->easy_handle); LOG_MSG(error, ZLOG_MOD_NET, "Cleanup CURL: %p\n", pMsg->easy_handle);
curl_multi_remove_handle(g_pCurl, pMsg->easy_handle); curl_multi_remove_handle(g_pCurl, pMsg->easy_handle);
curl_easy_cleanup(pMsg->easy_handle); curl_easy_cleanup(pMsg->easy_handle);
@ -202,7 +202,7 @@ static void checkMultiInfoTimeout(void) {
break; break;
default: default:
dzlog_error("pMsg->msg(%d) != CURLMSG_DONE\n", pMsg->msg); LOG_MSG(error, ZLOG_MOD_NET, "pMsg->msg(%d) != CURLMSG_DONE\n", pMsg->msg);
return; return;
} }
} }
@ -219,7 +219,7 @@ static void checkMultiInfo(void) {
curl_easy_getinfo(pMsg->easy_handle, CURLINFO_PRIVATE, (void *)&pReq); curl_easy_getinfo(pMsg->easy_handle, CURLINFO_PRIVATE, (void *)&pReq);
curl_multi_remove_handle(g_pCurl, pMsg->easy_handle); curl_multi_remove_handle(g_pCurl, pMsg->easy_handle);
dzlog_debug("Cleanup CURL: %p\n", pMsg->easy_handle); LOG_MSG(debug, ZLOG_MOD_NET, "Cleanup CURL: %p\n", pMsg->easy_handle);
curl_easy_cleanup(pMsg->easy_handle); curl_easy_cleanup(pMsg->easy_handle);
if (pReq) { if (pReq) {
@ -302,7 +302,7 @@ static void checkMultiInfo(void) {
break; break;
default: default:
dzlog_error("pMsg->msg(%d) != CURLMSG_DONE\n", pMsg->msg); LOG_MSG(error, ZLOG_MOD_NET, "pMsg->msg(%d) != CURLMSG_DONE\n", pMsg->msg);
return; return;
} }
} }
@ -449,7 +449,7 @@ static int progressCb(void *pData, double total, double now, double UNUSED(ulTot
} }
if (pParams->isCancel) { if (pParams->isCancel) {
dzlog_error("Cancel Download: %s\n", pParams->pTaskUuid); LOG_MSG(error, ZLOG_MOD_NET, "Cancel Download: %s\n", pParams->pTaskUuid);
return (-CURLE_OPERATION_TIMEDOUT); return (-CURLE_OPERATION_TIMEDOUT);
} }
@ -498,7 +498,9 @@ static void onDlTimeoutCb(uv_timer_t *UNUSED(pufTimer)) {
// 下载时间大于10s且平均下载速度小于10K/s超时 // 下载时间大于10s且平均下载速度小于10K/s超时
if ((dlTime * 10000 > pItem->pCurlItem->dlSize) && dlTime > 10) { if ((dlTime * 10000 > pItem->pCurlItem->dlSize) && dlTime > 10) {
dzlog_error("Download Speed less than 10k/s: %s (%uK/%llu(s))\n", LOG_MSG(error,
ZLOG_MOD_NET,
"Download Speed less than 10k/s: %s (%uK/%llu(s))\n",
pItem->pTaskUuid, pItem->pTaskUuid,
pItem->pCurlItem->dlSize / 1000, pItem->pCurlItem->dlSize / 1000,
dlTime); dlTime);
@ -519,7 +521,7 @@ static void onDlTimeoutCb(uv_timer_t *UNUSED(pufTimer)) {
// 5分钟内没有下载任何数据超时 // 5分钟内没有下载任何数据超时
if (pItem->pCurlItem->lastTm > 0) { if (pItem->pCurlItem->lastTm > 0) {
if (curTm > pItem->pCurlItem->lastTm + MAX_TIMEOUT_VALUE) { if (curTm > pItem->pCurlItem->lastTm + MAX_TIMEOUT_VALUE) {
dzlog_error("Download Timeout: %s\n", pItem->pTaskUuid); LOG_MSG(error, ZLOG_MOD_NET, "Download Timeout: %s\n", pItem->pTaskUuid);
cancelDownloadTask(pItem->pCurlItem); cancelDownloadTask(pItem->pCurlItem);
if (pItem->pCurlItem->onRspCb) { if (pItem->pCurlItem->onRspCb) {
pItem->pCurlItem->onRspCb(NULL, pItem->pCurlItem->onRspCb(NULL,
@ -536,7 +538,9 @@ static void onDlTimeoutCb(uv_timer_t *UNUSED(pufTimer)) {
// 下载最长时间设置为1800秒(60分钟) // 下载最长时间设置为1800秒(60分钟)
if (dlTime > 3600) { if (dlTime > 3600) {
dzlog_error("Download More than 1800 seconds: %s (%uK/%llu(s))\n", LOG_MSG(error,
ZLOG_MOD_NET,
"Download More than 1800 seconds: %s (%uK/%llu(s))\n",
pItem->pTaskUuid, pItem->pTaskUuid,
pItem->pCurlItem->dlSize / 1000, pItem->pCurlItem->dlSize / 1000,
dlTime); dlTime);
@ -595,7 +599,7 @@ const char *inet_download_file_async(const char *pURL,
return (NULL); return (NULL);
} }
dzlog_debug("Begin Download: %s --> %s\n", pURL, pPath); LOG_MSG(debug, ZLOG_MOD_NET, "Begin Download: %s --> %s\n", pURL, pPath);
pParams = (PHTTP_REQ_PARAMS)malloc(sizeof(HTTP_REQ_PARAMS)); pParams = (PHTTP_REQ_PARAMS)malloc(sizeof(HTTP_REQ_PARAMS));
@ -639,7 +643,12 @@ const char *inet_download_file_async(const char *pURL,
pParams->uvFsDataSync.data = pParams; pParams->uvFsDataSync.data = pParams;
pParams->uvFsClose.data = pParams; pParams->uvFsClose.data = pParams;
dzlog_debug("[%s]: File %s used temp path %s\n", pParams->pTaskUuid, pParams->sPath, pParams->sDlPath); LOG_MSG(debug,
ZLOG_MOD_NET,
"[%s]: File %s used temp path %s\n",
pParams->pTaskUuid,
pParams->sPath,
pParams->sDlPath);
uv_fs_open(get_task_manager(), uv_fs_open(get_task_manager(),
&pParams->uvFsOpen, &pParams->uvFsOpen,
@ -693,14 +702,14 @@ const char *inet_download_file_async(const char *pURL,
curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif #endif
dzlog_debug("Download(%u): %s --> %p\n", g_TotalDownloads++, pParams->pTaskUuid, pCurl); LOG_MSG(debug, ZLOG_MOD_NET, "Download(%u): %s --> %p\n", g_TotalDownloads++, pParams->pTaskUuid, pCurl);
ret = curl_multi_add_handle(g_pCurl, pCurl); ret = curl_multi_add_handle(g_pCurl, pCurl);
if (ret == CURLE_OK) { if (ret == CURLE_OK) {
addReqIdToTable(pParams->pTaskUuid, pParams); addReqIdToTable(pParams->pTaskUuid, pParams);
return (pParams->pTaskUuid); return (pParams->pTaskUuid);
} else { } else {
free(pParams->pTaskUuid); free(pParams->pTaskUuid);
dzlog_error("Add Handle Error: %d\n", ret); LOG_MSG(error, ZLOG_MOD_NET, "Add Handle Error: %d\n", ret);
return NULL; return NULL;
} }
} }
@ -777,14 +786,14 @@ const char *inet_http_post_async(const char *pURL, const char *pPost, on_http_re
curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif #endif
dzlog_debug("Http POST(%u): %s --> %p\n", g_TotalDownloads++, pParams->pTaskUuid, pCurl); LOG_MSG(debug, ZLOG_MOD_NET, "Http POST(%u): %s --> %p\n", g_TotalDownloads++, pParams->pTaskUuid, pCurl);
ret = curl_multi_add_handle(g_pCurl, pCurl); ret = curl_multi_add_handle(g_pCurl, pCurl);
if (ret == CURLE_OK) { if (ret == CURLE_OK) {
addReqIdToTable(pParams->pTaskUuid, pParams); addReqIdToTable(pParams->pTaskUuid, pParams);
return (pParams->pTaskUuid); return (pParams->pTaskUuid);
} else { } else {
free(pParams->pTaskUuid); free(pParams->pTaskUuid);
dzlog_error("Add Handle Error: %d\n", ret); LOG_MSG(error, ZLOG_MOD_NET, "Add Handle Error: %d\n", ret);
return NULL; return NULL;
} }
} }
@ -795,7 +804,7 @@ int inet_api_init(void) {
ret = curl_global_init(CURL_GLOBAL_ALL); ret = curl_global_init(CURL_GLOBAL_ALL);
if (ret != 0) { if (ret != 0) {
dzlog_error("curl init error: %d\n", ret); LOG_MSG(error, ZLOG_MOD_NET, "curl init error: %d\n", ret);
return ret; return ret;
} }

View File

@ -1,7 +1,6 @@
// //
// Created by xajhuang on 2022/12/2. // Created by xajhuang on 2022/12/2.
// //
#include <zlog.h>
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
@ -10,6 +9,7 @@
#include "proto.h" #include "proto.h"
#include "crypto.h" #include "crypto.h"
#include "user_errno.h" #include "user_errno.h"
#include "zlog_module.h"
#define CURRENT_PROTOCOL_VERSION (1) #define CURRENT_PROTOCOL_VERSION (1)
@ -161,7 +161,10 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) {
} }
if (pKey == NULL || strlen(pKey) == 0) { if (pKey == NULL || strlen(pKey) == 0) {
dzlog_error("Cryptography key empty of algorithm %d, Used default algorithm BASE64\n", cryptoType); LOG_MSG(error,
ZLOG_MOD_PROTO,
"Cryptography key empty of algorithm %d, Used default algorithm BASE64\n",
cryptoType);
base64 = base64_encode((unsigned char *)pStrMsg, strlen(pStrMsg)); base64 = base64_encode((unsigned char *)pStrMsg, strlen(pStrMsg));
pro.cryptoType = CRYPTO_BASE64; pro.cryptoType = CRYPTO_BASE64;
} else { } else {
@ -172,7 +175,10 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) {
ret = symmetric_encrypto(cryptoType, (unsigned char *)pStrMsg, strlen(pStrMsg), &buf, &outSize, pKey); ret = symmetric_encrypto(cryptoType, (unsigned char *)pStrMsg, strlen(pStrMsg), &buf, &outSize, pKey);
if (ret != ERR_SUCCESS) { if (ret != ERR_SUCCESS) {
dzlog_error("Unsupported protocol crypto : %d, Used default algorithm BASE64\n", cryptoType); LOG_MSG(error,
ZLOG_MOD_PROTO,
"Unsupported protocol crypto : %d, Used default algorithm BASE64\n",
cryptoType);
base64 = base64_encode((unsigned char *)pStrMsg, strlen(pStrMsg)); base64 = base64_encode((unsigned char *)pStrMsg, strlen(pStrMsg));
pro.cryptoType = CRYPTO_BASE64; pro.cryptoType = CRYPTO_BASE64;
} else { } else {
@ -185,14 +191,17 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) {
cJSON_free(pro.msgContend); cJSON_free(pro.msgContend);
} break; } break;
default: default:
dzlog_error("Unsupported protocol crypto algorithms: %d, Used default algorithm BASE64\n", pro.cryptoType); LOG_MSG(error,
ZLOG_MOD_PROTO,
"Unsupported protocol crypto algorithms: %d, Used default algorithm BASE64\n",
pro.cryptoType);
cJSON_free(pro.msgContend); cJSON_free(pro.msgContend);
cJSON_Delete(pRoot); cJSON_Delete(pRoot);
return NULL; return NULL;
} }
pStrProto = cJSON_Print(pRoot); pStrProto = cJSON_Print(pRoot);
dzlog_debug("Create: \n%s\n", pStrProto); LOG_MSG(debug, ZLOG_MOD_PROTO, "Create: \n%s\n", pStrProto);
cJSON_Delete(pRoot); cJSON_Delete(pRoot);

View File

@ -3,11 +3,11 @@
// //
#include <stdlib.h> #include <stdlib.h>
#include <zlog.h>
#include "task_manager.h" #include "task_manager.h"
#include "misc.h" #include "misc.h"
#include "uthash/utlist.h" #include "uthash/utlist.h"
#include "user_errno.h" #include "user_errno.h"
#include "zlog_module.h"
typedef struct SYSTEM_EXIT_CONTENT { typedef struct SYSTEM_EXIT_CONTENT {
system_exit_cb cb; system_exit_cb cb;
@ -84,6 +84,6 @@ void task_manager_run() {
free(pCtx); free(pCtx);
} }
dzlog_info("Main task exited..............\n"); LOG_MSG(info, ZLOG_MOD_TASK, "Main task exited..............\n");
g_isSystemExit = TRUE; g_isSystemExit = TRUE;
} }

View File

@ -0,0 +1,42 @@
//
// Created by xajhuang on 2023/2/6.
//
#include "zlog_module.h"
typedef struct {
ZLOG_MOD_NAME logModule;
zlog_category_t *pCat;
char catName[MAX_ZLOG_MOD_LEN];
} ZLOG_MODULE, *PZLOG_MODULE;
static ZLOG_MODULE g_zlogModule[] = {
{ZLOG_MOD_MAIN, NULL, "MAIN" },
{ZLOG_MOD_TASK, NULL, "TASK" },
{ZLOG_MOD_INIT, NULL, "INIT" },
{ZLOG_MOD_MISC, NULL, "MISC" },
{ZLOG_MOD_CONFIG, NULL, "CONFIG"},
{ZLOG_MOD_NET, NULL, "NET" },
{ZLOG_MOD_CRYPTO, NULL, "CRYPTO"},
{ZLOG_MOD_MQ, NULL, "MQ" },
{ZLOG_MOD_PROTO, NULL, "PROTO" },
{ZLOG_MOD_HTTPD, NULL, "HTTPD" },
#ifdef USED_LWIP
{ZLOG_MOD_USER, NULL, "USER" },
{ZLOG_MOD_PPPOE, NULL, "PPPOE" },
{ZLOG_MOD_VXLAN, NULL, "VXLAN" },
{ZLOG_MOD_LWIP, NULL, "LWIP" },
#endif
{ZLOG_MOD_OPENDHCPD, NULL, "DHCPD" }
};
zlog_category_t *zlog_get_mod_cat(ZLOG_MOD_NAME logMod) {
if (logMod >= ZLOG_MOD_MAX) {
return NULL;
}
if (g_zlogModule[logMod].pCat == NULL) {
g_zlogModule[logMod].pCat = zlog_get_category(g_zlogModule[logMod].catName);
}
return g_zlogModule[logMod].pCat;
}

View File

@ -3,12 +3,12 @@
// //
#include <uthash/uthash.h> #include <uthash/uthash.h>
#include <zlog.h>
#include <uv.h> #include <uv.h>
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/vxlan.h" #include "lwip/vxlan.h"
#include "zlog_module.h"
#include "misc.h" #include "misc.h"
#include "user_errno.h" #include "user_errno.h"
@ -30,7 +30,6 @@ typedef struct {
unsigned char snd_pkg_head[VXLAN_HEAD_SIZE]; unsigned char snd_pkg_head[VXLAN_HEAD_SIZE];
} VXLAN_PKG_HEAD, *PVXLAN_PKG_HEAD; } VXLAN_PKG_HEAD, *PVXLAN_PKG_HEAD;
typedef struct { typedef struct {
NIC_INFO nic_info; NIC_INFO nic_info;
PVXLAN_PKG_HEAD pkg_head; PVXLAN_PKG_HEAD pkg_head;
@ -214,7 +213,11 @@ static void vxlan_pkg_head_init(PVXLAN_PKG_HEAD pvxLan) {
int vxlan_peer_add(const char *pIp, const char *pMac) { int vxlan_peer_add(const char *pIp, const char *pMac) {
if (!VERIFY_STRING(pIp) || !VERIFY_STRING(pMac)) { if (!VERIFY_STRING(pIp) || !VERIFY_STRING(pMac)) {
dzlog_error("Input parameters error: %s, %s\n", SAFETY_STR_STRING(pIp), SAFETY_STR_STRING(pMac)); LOG_MSG(error,
ZLOG_MOD_VXLAN,
"Input parameters error: %s, %s\n",
SAFETY_STR_STRING(pIp),
SAFETY_STR_STRING(pMac));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }
@ -226,7 +229,7 @@ int vxlan_peer_add(const char *pIp, const char *pMac) {
str_to_mac(pMac, peerMac); str_to_mac(pMac, peerMac);
if (str_to_ipaddr(pIp, &peerIp) == 0) { if (str_to_ipaddr(pIp, &peerIp) == 0) {
dzlog_error("Get vxLan peer ip address failed: %s\n", pIp); LOG_MSG(error, ZLOG_MOD_VXLAN, "Get vxLan peer ip address failed: %s\n", pIp);
return -ERR_SYS_INIT; return -ERR_SYS_INIT;
} }
@ -245,7 +248,7 @@ int vxlan_peer_add(const char *pIp, const char *pMac) {
// 对发送报文的头部进行初始化 // 对发送报文的头部进行初始化
vxlan_pkg_head_init(pkg); vxlan_pkg_head_init(pkg);
dzlog_debug("Add vxLan Link: vSwitch: %s, %s\n", pIp, pMac); LOG_MSG(debug, ZLOG_MOD_VXLAN, "Add vxLan Link: vSwitch: %s, %s\n", pIp, pMac);
} }
return ERR_SUCCESS; return ERR_SUCCESS;
@ -253,7 +256,7 @@ int vxlan_peer_add(const char *pIp, const char *pMac) {
int vxlan_link_init(const char *pEthName) { int vxlan_link_init(const char *pEthName) {
if (!VERIFY_STRING(pEthName)) { if (!VERIFY_STRING(pEthName)) {
dzlog_error("Input parameters error: %s\n", SAFETY_STR_STRING(pEthName)); LOG_MSG(error, ZLOG_MOD_VXLAN, "Input parameters error: %s\n", SAFETY_STR_STRING(pEthName));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }
@ -267,9 +270,8 @@ int vxlan_link_init(const char *pEthName) {
&g_vxLanLinks.nic_info.ip_addr, &g_vxLanLinks.nic_info.ip_addr,
&g_vxLanLinks.nic_info.ip_mask, &g_vxLanLinks.nic_info.ip_mask,
&g_vxLanLinks.nic_info.ip_gw, &g_vxLanLinks.nic_info.ip_gw,
g_vxLanLinks.nic_info.mac) g_vxLanLinks.nic_info.mac) != ERR_SUCCESS) {
!= ERR_SUCCESS) { LOG_MSG(error, ZLOG_MOD_VXLAN, "Get NIC information failed\n");
dzlog_error("Get NIC information failed\n");
return -ERR_SYS_INIT; return -ERR_SYS_INIT;
} }

View File

@ -32,16 +32,17 @@
#ifndef LWIP_PPPOEIF_H #ifndef LWIP_PPPOEIF_H
#define LWIP_PPPOEIF_H #define LWIP_PPPOEIF_H
#include "zlog_module.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "../../../../../include/pppoe_session.h" #include "../../../../../include/pppoe_session.h"
#define DUMP_IF_BUF(tag, buf, len) \ #define DUMP_IF_BUF(tag, buf, len) \
do { \ do { \
dzlog_debug("%s ++++++\n", (tag)); \ LOG_MSG(debug, ZLOG_MOD_LWIP, "%s ++++++\n", (tag)); \
printf("\n"); \ printf("\n"); \
hdzlog_debug((buf), (len)); \ LOG_MSG_HEX(debug, ZLOG_MOD_LWIP, (buf), (len)); \
printf("\n"); \ printf("\n"); \
dzlog_debug("%s ------\n", (tag)); \ LOG_MSG(debug, ZLOG_MOD_LWIP, "%s ------\n", (tag)); \
} while (0) } while (0)
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -31,7 +31,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <zlog.h>
#include <pcap/pcap.h> #include <pcap/pcap.h>
#include "lwip/opt.h" #include "lwip/opt.h"
@ -51,6 +50,7 @@
#include "lwip/vxlan.h" #include "lwip/vxlan.h"
#include "user_info.h" #include "user_info.h"
#include "lwip/tcpip.h" #include "lwip/tcpip.h"
#include "zlog_module.h"
#include "misc.h" #include "misc.h"
#if defined(LWIP_UNIX_LINUX) #if defined(LWIP_UNIX_LINUX)
@ -133,11 +133,12 @@ static void pcap_pkg_cb(unsigned char *args, const struct pcap_pkthdr *pkthdr, c
memcpy(zmq_msg_data(&msg), packet, pkthdr->caplen); memcpy(zmq_msg_data(&msg), packet, pkthdr->caplen);
rc = zmq_msg_send(&msg, pcapif->msg_input, 0); rc = zmq_msg_send(&msg, pcapif->msg_input, 0);
if (rc == -1) { if (rc == -1) {
dzlog_error("Send %d bytes message error: %s\n", pkthdr->caplen, strerror(errno)); LOG_MSG(error, ZLOG_MOD_LWIP, "Send %d bytes message error: %s\n", pkthdr->caplen, strerror(errno));
} }
zmq_msg_close(&msg); zmq_msg_close(&msg);
} }
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static void low_level_init(struct netif *netif) { static void low_level_init(struct netif *netif) {
struct pcapif *pcapif = (struct pcapif *)netif->state; struct pcapif *pcapif = (struct pcapif *)netif->state;
@ -162,6 +163,7 @@ static void low_level_init(struct netif *netif) {
sys_thread_new("pcapif_msg_thread", pcapif_msg_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); sys_thread_new("pcapif_msg_thread", pcapif_msg_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#endif /* !NO_SYS */ #endif /* !NO_SYS */
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* /*
* low_level_output(): * low_level_output():
@ -284,12 +286,15 @@ _Noreturn static void pcapif_thread(void *arg) {
static void status_callback(struct netif *state_netif) { static void status_callback(struct netif *state_netif) {
if (netif_is_up(state_netif)) { if (netif_is_up(state_netif)) {
#if LWIP_IPV4 #if LWIP_IPV4
dzlog_info("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif))); LOG_MSG(info,
ZLOG_MOD_LWIP,
"status_callback==UP, local interface IP is %s\n",
ip4addr_ntoa(netif_ip4_addr(state_netif)));
#else #else
printf("status_callback==UP\n"); printf("status_callback==UP\n");
#endif #endif
} else { } else {
dzlog_error("status_callback==DOWN\n"); LOG_MSG(error, ZLOG_MOD_LWIP, "status_callback==DOWN\n");
} }
} }
#endif /* LWIP_NETIF_STATUS_CALLBACK */ #endif /* LWIP_NETIF_STATUS_CALLBACK */
@ -297,9 +302,9 @@ static void status_callback(struct netif *state_netif) {
#if LWIP_NETIF_LINK_CALLBACK #if LWIP_NETIF_LINK_CALLBACK
static void link_callback(struct netif *state_netif) { static void link_callback(struct netif *state_netif) {
if (netif_is_link_up(state_netif)) { if (netif_is_link_up(state_netif)) {
dzlog_info("link_callback==UP\n"); LOG_MSG(info, ZLOG_MOD_LWIP, "link_callback==UP\n");
} else { } else {
dzlog_error("link_callback==DOWN\n"); LOG_MSG(error, ZLOG_MOD_LWIP, "link_callback==DOWN\n");
} }
} }
#endif /* LWIP_NETIF_LINK_CALLBACK */ #endif /* LWIP_NETIF_LINK_CALLBACK */
@ -387,7 +392,7 @@ struct netif *bind_pcap_if(const char *eth_name, const char *pkg_filter, int vxl
struct pcapif *pcapif = (struct pcapif *)mem_malloc(sizeof(struct pcapif)); struct pcapif *pcapif = (struct pcapif *)mem_malloc(sizeof(struct pcapif));
if (pcapif == NULL) { if (pcapif == NULL) {
dzlog_error("bind_pcapsocket_if: out of memory for pcapif\n"); LOG_MSG(error, ZLOG_MOD_LWIP, "bind_pcapsocket_if: out of memory for pcapif\n");
return NULL; return NULL;
} }
@ -396,7 +401,7 @@ struct netif *bind_pcap_if(const char *eth_name, const char *pkg_filter, int vxl
if (vxlan_support) { if (vxlan_support) {
if (vxlan_link_init(eth_name) != ERR_OK) { if (vxlan_link_init(eth_name) != ERR_OK) {
dzlog_error("bind_pcapsocket_if: Get local nic info failed\n"); LOG_MSG(error, ZLOG_MOD_LWIP, "bind_pcapsocket_if: Get local nic info failed\n");
free(pcapif); free(pcapif);
return NULL; return NULL;
} }
@ -415,15 +420,15 @@ struct netif *bind_pcap_if(const char *eth_name, const char *pkg_filter, int vxl
pPcap = pcap_open_live(pcapif->eth_name, MAX_BYTES_PACKAGE, 1, -1, errBuf); pPcap = pcap_open_live(pcapif->eth_name, MAX_BYTES_PACKAGE, 1, -1, errBuf);
if (get_nic_info(eth_name, &ipaddr, &netmask, &gw, mac) != ERR_OK) { if (get_nic_info(eth_name, &ipaddr, &netmask, &gw, mac) != ERR_OK) {
dzlog_error("Get NIC %s information error\n", eth_name); LOG_MSG(error, ZLOG_MOD_LWIP, "Get NIC %s information error\n", eth_name);
} }
dzlog_debug("Pcap netif used filter: \"%s\"\n", pcapif->pkg_filter); LOG_MSG(debug, ZLOG_MOD_LWIP, "Pcap netif used filter: \"%s\"\n", pcapif->pkg_filter);
if (pcap_compile(pPcap, &filter, pcapif->pkg_filter, 1, netmask) == -1) { if (pcap_compile(pPcap, &filter, pcapif->pkg_filter, 1, netmask) == -1) {
dzlog_error("Set package fileter[%s] error: %s\n", pcapif->pkg_filter, pcap_geterr(pPcap)); LOG_MSG(error, ZLOG_MOD_LWIP, "Set package fileter[%s] error: %s\n", pcapif->pkg_filter, pcap_geterr(pPcap));
} }
if (pcap_setfilter(pPcap, &filter) == -1) { if (pcap_setfilter(pPcap, &filter) == -1) {
dzlog_error("Set package fileter[%s] error: %s\n", pcapif->pkg_filter, pcap_geterr(pPcap)); LOG_MSG(error, ZLOG_MOD_LWIP, "Set package fileter[%s] error: %s\n", pcapif->pkg_filter, pcap_geterr(pPcap));
} }
pcapif->pcap = pPcap; pcapif->pcap = pPcap;
@ -449,7 +454,7 @@ struct netif *bind_pcap_if(const char *eth_name, const char *pkg_filter, int vxl
if (!netif) { if (!netif) {
mem_free(pcapif); mem_free(pcapif);
dzlog_error("Create netif error\n"); LOG_MSG(error, ZLOG_MOD_LWIP, "Create netif error\n");
return NULL; return NULL;
} }

View File

@ -31,7 +31,6 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <zlog.h>
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/tcpip.h" #include "lwip/tcpip.h"
@ -45,6 +44,7 @@
#include "netif/etharp.h" #include "netif/etharp.h"
#include "zlog_module.h"
#include "netif/pppoeif.h" #include "netif/pppoeif.h"
#include "netif/rawif.h" #include "netif/rawif.h"
#include "pppoe_session.h" #include "pppoe_session.h"
@ -112,6 +112,7 @@ static void low_level_init(struct netif *netif) {
netif_set_link_up(netif); netif_set_link_up(netif);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* /*
* low_level_output(): * low_level_output():
@ -161,12 +162,12 @@ err_t pppoeif_init(struct netif *netif) {
static void status_callback(struct netif *state_netif) { static void status_callback(struct netif *state_netif) {
if (netif_is_up(state_netif)) { if (netif_is_up(state_netif)) {
#if LWIP_IPV4 #if LWIP_IPV4
dzlog_info("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif))); LOG_MSG(info, ZLOG_MOD_LWIP, ("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif)));
#else #else
printf("status_callback==UP\n"); printf("status_callback==UP\n");
#endif #endif
} else { } else {
dzlog_error("status_callback==DOWN\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("status_callback==DOWN\n");
} }
} }
#endif /* LWIP_NETIF_STATUS_CALLBACK */ #endif /* LWIP_NETIF_STATUS_CALLBACK */
@ -174,9 +175,9 @@ static void status_callback(struct netif *state_netif) {
#if LWIP_NETIF_LINK_CALLBACK #if LWIP_NETIF_LINK_CALLBACK
static void link_callback(struct netif *state_netif) { static void link_callback(struct netif *state_netif) {
if (netif_is_link_up(state_netif)) { if (netif_is_link_up(state_netif)) {
dzlog_info("link_callback==UP\n"); LOG_MSG(info, ZLOG_MOD_LWIP, ("link_callback==UP\n");
} else { } else {
dzlog_error("link_callback==DOWN\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("link_callback==DOWN\n");
} }
} }
#endif /* LWIP_NETIF_LINK_CALLBACK */ #endif /* LWIP_NETIF_LINK_CALLBACK */
@ -206,7 +207,7 @@ struct netif *create_pppoe_if(PUSER_INFO_CONTEXT pUser) {
netif = (struct netif *)mem_malloc(sizeof(struct netif)); netif = (struct netif *)mem_malloc(sizeof(struct netif));
if (!netif) { if (!netif) {
dzlog_error("Create PPPoE netif error\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("Create PPPoE netif error\n");
return NULL; return NULL;
} }

View File

@ -38,7 +38,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <zlog.h>
#include <uthash/uthash.h> #include <uthash/uthash.h>
#include "lwip/opt.h" #include "lwip/opt.h"
@ -59,6 +58,7 @@
#include "lwip/prot/udp.h" #include "lwip/prot/udp.h"
#include "zlog_module.h"
#include "config.h" #include "config.h"
#include "pppoe_info.h" #include "pppoe_info.h"
#include "user_info.h" #include "user_info.h"
@ -95,7 +95,6 @@ struct sockaddr_ll {
unsigned char sll_addr[8]; unsigned char sll_addr[8];
}; };
typedef struct { typedef struct {
unsigned int vni; unsigned int vni;
unsigned char *output_head; unsigned char *output_head;
@ -209,6 +208,7 @@ static void low_level_init(struct netif *netif) {
sys_thread_new("rawif_thread", rawif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); sys_thread_new("rawif_thread", rawif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#endif /* !NO_SYS */ #endif /* !NO_SYS */
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* /*
* low_level_output(): * low_level_output():
@ -284,12 +284,12 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
unsigned int dataSize = p->tot_len - sizeof(struct eth_hdr); unsigned int dataSize = p->tot_len - sizeof(struct eth_hdr);
struct eth_hdr *eth = (struct eth_hdr *)buf; struct eth_hdr *eth = (struct eth_hdr *)buf;
struct vxlan_package *pkg = (struct vxlan_package *)sndBuf; struct vxlan_package *pkg = (struct vxlan_package *)sndBuf;
unsigned short udp_len = unsigned short udp_len = p->tot_len + sizeof(struct vxlan_hdr) + sizeof(struct qinq_hdr) +
p->tot_len + sizeof(struct vxlan_hdr) + sizeof(struct qinq_hdr) + sizeof(struct udp_hdr); sizeof(struct udp_hdr);
unsigned short ip_len = udp_len + 20; unsigned short ip_len = udp_len + 20;
unsigned int total_len = ip_len + sizeof(struct eth_hdr); unsigned int total_len = ip_len + sizeof(struct eth_hdr);
dzlog_debug("Found user vxlan connect: %d --> %u\n", pUser->userid, pvxlanBuf->vni); LOG_MSG(debug, ZLOG_MOD_LWIP, ("Found user vxlan connect: %d --> %u\n", pUser->userid, pvxlanBuf->vni);
memcpy(sndBuf, pvxlanBuf->output_head, sizeof(struct vxlan_package)); memcpy(sndBuf, pvxlanBuf->output_head, sizeof(struct vxlan_package));
pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pUser->vxlan.vni)); pkg->vxlan_head.vni_reserved = lwip_htonl(VXLAN_VIN_ID_PACK(pUser->vxlan.vni));
@ -317,29 +317,27 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
if(memcmp(buf, p->payload, p->tot_len) != 0) { if(memcmp(buf, p->payload, p->tot_len) != 0) {
dzlog_debug("INPKG +++++\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("INPKG +++++\n");
hdzlog_debug(p->payload, p->tot_len); hLOG_MSG(debug, ZLOG_MOD_LWIP, (p->payload, p->tot_len);
printf("\n"); printf("\n");
dzlog_debug("INPKG -----\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("INPKG -----\n");
dzlog_debug("BUF +++++\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("BUF +++++\n");
hdzlog_debug(buf, p->tot_len); hLOG_MSG(debug, ZLOG_MOD_LWIP, (buf, p->tot_len);
printf("\n"); printf("\n");
dzlog_debug("BUF -----\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("BUF -----\n");
} }
#if 0 #if 0
dzlog_debug("OUTPKG +++++\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("OUTPKG +++++\n");
hdzlog_debug(sndBuf, total_len); hLOG_MSG(debug, ZLOG_MOD_LWIP, (sndBuf, total_len);
printf("\n"); printf("\n");
dzlog_debug("INPKG -----\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("INPKG -----\n");
#endif #endif
dzlog_debug("In %u, out %u, send %zd\n", p->tot_len, total_len, written); LOG_MSG(debug, ZLOG_MOD_LWIP, ("In %u, out %u, send %zd\n", p->tot_len, total_len, written);
return written == (total_len) ? ERR_OK : ERR_IF; return written == (total_len) ? ERR_OK : ERR_IF;
} else { } else {
/* signal that packet should be sent(); */ /* signal that packet should be sent(); */
written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr)); written = sendto(rawif->fd, buf, p->tot_len, 0, (struct sockaddr *)&dstAddr, sizeof(dstAddr));
@ -363,6 +361,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
return (written == p->tot_len) ? ERR_OK : ERR_IF; return (written == p->tot_len) ? ERR_OK : ERR_IF;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* /*
* low_level_input(): * low_level_input():
@ -449,6 +448,7 @@ static void rawif_input(struct netif *netif) {
pbuf_free(p); pbuf_free(p);
} }
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* /*
* rawif_init(): * rawif_init():
@ -519,12 +519,12 @@ _Noreturn static void rawif_thread(void *arg) {
static void status_callback(struct netif *state_netif) { static void status_callback(struct netif *state_netif) {
if (netif_is_up(state_netif)) { if (netif_is_up(state_netif)) {
#if LWIP_IPV4 #if LWIP_IPV4
dzlog_info("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif))); LOG_MSG(info, ZLOG_MOD_LWIP, ("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif)));
#else #else
printf("status_callback==UP\n"); printf("status_callback==UP\n");
#endif #endif
} else { } else {
dzlog_error("status_callback==DOWN\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("status_callback==DOWN\n");
} }
} }
#endif /* LWIP_NETIF_STATUS_CALLBACK */ #endif /* LWIP_NETIF_STATUS_CALLBACK */
@ -532,9 +532,9 @@ static void status_callback(struct netif *state_netif) {
#if LWIP_NETIF_LINK_CALLBACK #if LWIP_NETIF_LINK_CALLBACK
static void link_callback(struct netif *state_netif) { static void link_callback(struct netif *state_netif) {
if (netif_is_link_up(state_netif)) { if (netif_is_link_up(state_netif)) {
dzlog_info("link_callback==UP\n"); LOG_MSG(info, ZLOG_MOD_LWIP, ("link_callback==UP\n");
} else { } else {
dzlog_error("link_callback==DOWN\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("link_callback==DOWN\n");
} }
} }
#endif /* LWIP_NETIF_LINK_CALLBACK */ #endif /* LWIP_NETIF_LINK_CALLBACK */
@ -696,7 +696,7 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
pbuf_free(p); pbuf_free(p);
return err; return err;
} else { } else {
dzlog_error("Not found: %u, %u, %u\n", tag.vni, tag.q1, tag.q2); LOG_MSG(error, ZLOG_MOD_LWIP, ("Not found: %u, %u, %u\n", tag.vni, tag.q1, tag.q2);
} }
#else #else
VXLAN_TAG tag; VXLAN_TAG tag;
@ -726,7 +726,7 @@ static err_t netif_input_data(struct pbuf *p, struct netif *inp) {
} }
if ((err = pContext->session.nicif->input(ebuf, pContext->session.nicif)) != ERR_OK) { if ((err = pContext->session.nicif->input(ebuf, pContext->session.nicif)) != ERR_OK) {
dzlog_debug("\n"); LOG_MSG(debug, ZLOG_MOD_LWIP, ("\n");
LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n")); LWIP_DEBUGF(NETIF_DEBUG, ("pppoeif_input: netif input error\n"));
} }
@ -759,7 +759,7 @@ struct netif *bind_rawsocket_if(const char *eth_name) {
struct rawif *rawif = (struct rawif *)mem_malloc(sizeof(struct rawif)); struct rawif *rawif = (struct rawif *)mem_malloc(sizeof(struct rawif));
if (rawif == NULL) { if (rawif == NULL) {
dzlog_error("bind_rawsocket_if: out of memory for rawif\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("bind_rawsocket_if: out of memory for rawif\n");
return NULL; return NULL;
} }
@ -770,7 +770,7 @@ struct netif *bind_rawsocket_if(const char *eth_name) {
} }
if (vxlan_link_init(eth_name) != ERR_OK) { if (vxlan_link_init(eth_name) != ERR_OK) {
dzlog_error("bind_rawsocket_if: Get local nic info failed\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("bind_rawsocket_if: Get local nic info failed\n");
return NULL; return NULL;
} }
@ -808,7 +808,7 @@ struct netif *bind_rawsocket_if(const char *eth_name) {
if (!netif) { if (!netif) {
mem_free(rawif); mem_free(rawif);
dzlog_error("Create netif error\n"); LOG_MSG(error, ZLOG_MOD_LWIP, ("Create netif error\n");
return NULL; return NULL;
} }

View File

@ -35,7 +35,6 @@
#include <pthread.h> #include <pthread.h>
#include <map> #include <map>
using namespace std; using namespace std;
#include <zlog.h>
#include "dhcpd.h" #include "dhcpd.h"
#include "opendhcpd.h" #include "opendhcpd.h"
#include "user_errno.h" #include "user_errno.h"

View File

@ -44,6 +44,8 @@
#include <sys/uio.h> #include <sys/uio.h>
#endif #endif
#include "zlog_module.h"
/* /*
//#ifndef _LINUX_IN_H //#ifndef _LINUX_IN_H
//#ifndef _NETINET_IN_H //#ifndef _NETINET_IN_H
@ -84,13 +86,13 @@ typedef struct in_pktinfo IN_PKTINFO;
do { \ do { \
switch ((logLevel)) { \ switch ((logLevel)) { \
case 2: \ case 2: \
dzlog_debug("%s\n", logBuff); \ LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "%s\n", logBuff); \
break; \ break; \
case 0: \ case 0: \
dzlog_error("%s\n", logBuff); \ LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "%s\n", logBuff); \
break; \ break; \
default: \ default: \
dzlog_info("%s\n", logBuff); \ LOG_MSG(info, ZLOG_MOD_OPENDHCPD, "%s\n", logBuff); \
break; \ break; \
} \ } \
} while (0) } while (0)

View File

@ -18,8 +18,6 @@ using namespace std;
#include "haywire.h" #include "haywire.h"
#include "misc.h" #include "misc.h"
#include <net/if_arp.h> #include <net/if_arp.h>
#include <libconfig.h>
#include <zlog.h>
#include <uv.h> #include <uv.h>
#include "config.h" #include "config.h"
#include "proto.h" #include "proto.h"
@ -51,7 +49,7 @@ static int dhcp_get_user_info(data19 *req, const char *pRequest) {
int k; int k;
dhcpMap::iterator p; dhcpMap::iterator p;
dzlog_debug("Input: %s\n", pRequest); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Input: %s\n", pRequest);
if (pRequest == nullptr || strlen(pRequest) == 0) { if (pRequest == nullptr || strlen(pRequest) == 0) {
sprintf(logBuff, "Requeset Json"); sprintf(logBuff, "Requeset Json");
@ -373,7 +371,7 @@ static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
cJSON *pRspRoot; cJSON *pRspRoot;
cJSON *pExpandArray; cJSON *pExpandArray;
dzlog_debug("Input: %s\n", pRequest); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Input: %s\n", pRequest);
if (pRequest == nullptr || strlen(pRequest) == 0) { if (pRequest == nullptr || strlen(pRequest) == 0) {
sprintf(logBuff, "Requeset Json"); sprintf(logBuff, "Requeset Json");
@ -491,7 +489,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
hash_map *delMap = nullptr; hash_map *delMap = nullptr;
int resCount = 0; int resCount = 0;
dzlog_debug("Input: %s\n", pRequest); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Input: %s\n", pRequest);
if (pRequest == nullptr || strlen(pRequest) == 0) { if (pRequest == nullptr || strlen(pRequest) == 0) {
sprintf(logBuff, "Requeset Json"); sprintf(logBuff, "Requeset Json");
@ -767,7 +765,7 @@ int getHwAddr(char *buff, char *mac) {
int arpSet(const char *ifname, char *ipStr, char *mac) { int arpSet(const char *ifname, char *ipStr, char *mac) {
if (ifname == nullptr || ipStr == nullptr || mac == nullptr) { if (ifname == nullptr || ipStr == nullptr || mac == nullptr) {
dzlog_error("para is null.\n"); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "para is null.\n");
return -1; return -1;
} }
@ -785,19 +783,19 @@ int arpSet(const char *ifname, char *ipStr, char *mac) {
req.arp_flags = ATF_PERM | ATF_COM; req.arp_flags = ATF_PERM | ATF_COM;
if (getHwAddr((char *)req.arp_ha.sa_data, mac) < 0) { if (getHwAddr((char *)req.arp_ha.sa_data, mac) < 0) {
dzlog_error("get mac error.\n"); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "get mac error.\n");
return -1; return -1;
} }
sock_fd = socket(AF_INET, SOCK_DGRAM, 0); sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (sock_fd < 0) { if (sock_fd < 0) {
dzlog_error("get socket error.\n"); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "get socket error.\n");
return -1; return -1;
} }
ret = ioctl(sock_fd, SIOCSARP, &req); ret = ioctl(sock_fd, SIOCSARP, &req);
if (ret < 0) { if (ret < 0) {
dzlog_error("ioctl error.\n"); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "ioctl error.\n");
close(sock_fd); close(sock_fd);
return -1; return -1;
} }
@ -1209,11 +1207,11 @@ static void on_http_response_cb(void *pData,
int iFinished, int iFinished,
void *pUserData) { void *pUserData) {
if (iFinished == 0) { if (iFinished == 0) {
dzlog_debug("Request(%s): [%s] Response: [%u] OK:\n", pTaskUuid, pReqUrl, size); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Request(%s): [%s] Response: [%u] OK:\n", pTaskUuid, pReqUrl, size);
} else if (iFinished == 1) { } else if (iFinished == 1) {
dzlog_error("Request(%s): [%s] Response: [%u] Error\n", pTaskUuid, pReqUrl, size); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "Request(%s): [%s] Response: [%u] Error\n", pTaskUuid, pReqUrl, size);
} else { } else {
dzlog_error("Download Error Code: %d\n", iFinished); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "Download Error Code: %d\n", iFinished);
} }
free(pUserData); free(pUserData);
@ -1239,7 +1237,11 @@ void iptvCacheCb(void *UNUSED(pArg)) {
isReport = true; isReport = true;
// 添加到缓存列表供后续查询 // 添加到缓存列表供后续查询
HASH_ADD_STR(g_iptvCacheDevs, iptvMAC, pCacheDev); HASH_ADD_STR(g_iptvCacheDevs, iptvMAC, pCacheDev);
dzlog_debug("Add IPTV device %s vni %d to cache\n", pCacheDev->iptvMAC, pCacheDev->vni); LOG_MSG(debug,
ZLOG_MOD_OPENDHCPD,
"Add IPTV device %s vni %d to cache\n",
pCacheDev->iptvMAC,
pCacheDev->vni);
} }
HASH_DEL(g_iptvNewDevs, pDev); HASH_DEL(g_iptvNewDevs, pDev);
@ -1292,7 +1294,7 @@ void opendhcp_init_http_server() {
added = TRUE; added = TRUE;
#ifdef USER_VNI #ifdef USER_VNI
dzlog_info("User VxLan Id: [%d]\n", cfg_get_user_vni_id()); LOG_MSG(info, ZLOG_MOD_OPENDHCPD, "User VxLan Id: [%d]\n", cfg_get_user_vni_id());
#endif #endif
} }
} }
@ -1320,7 +1322,7 @@ void opendhcp_add_ip_pool_set() {
if (pRange) { if (pRange) {
if (dhcp_add_rangeset_to_options(pRange) != ERR_SUCCESS) { if (dhcp_add_rangeset_to_options(pRange) != ERR_SUCCESS) {
dzlog_error("Add rangeset(\"%s\") failed!\n", pRange->rangAddr); LOG_MSG(error, ZLOG_MOD_OPENDHCPD, "Add rangeset(\"%s\") failed!\n", pRange->rangAddr);
} }
} }
} }
@ -1352,7 +1354,7 @@ int process_iptv_multicast(const unsigned char *p, int size, const char *mac) {
} }
} }
dzlog_debug("Found IPTV %s\n", mac); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Found IPTV %s\n", mac);
return 0; return 0;
} }
@ -1397,12 +1399,12 @@ void opendhcp_add_mac_filter() {
if (sdslen(add) > 0) { if (sdslen(add) > 0) {
sdsrange(add, 0, -3); sdsrange(add, 0, -3);
dzlog_debug("Add MAC [%s] for black list\n", add); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Add MAC [%s] for black list\n", add);
} }
if (sdslen(err) > 0) { if (sdslen(err) > 0) {
sdsrange(err, 0, -2); sdsrange(err, 0, -2);
dzlog_debug("Add MAC [%s] for black list error\n", err); LOG_MSG(debug, ZLOG_MOD_OPENDHCPD, "Add MAC [%s] for black list error\n", err);
} }
sdsfree(add); sdsfree(add);

View File

@ -1,7 +1,6 @@
// //
// Created by xajhuang on 2022/5/10. // Created by xajhuang on 2022/5/10.
// //
#include <zlog.h>
#include <uv/unix.h> #include <uv/unix.h>
#include <uv.h> #include <uv.h>
#include <uthash/utlist.h> #include <uthash/utlist.h>
@ -17,6 +16,7 @@
#include "vxlan_pkg.h" #include "vxlan_pkg.h"
#include "netif/pcapif.h" #include "netif/pcapif.h"
#include "s2j/cJSON.h" #include "s2j/cJSON.h"
#include "zlog_module.h"
typedef struct PPPOE_CACHE { typedef struct PPPOE_CACHE {
PPPPOE_SESSION_DATA pSessionData; PPPPOE_SESSION_DATA pSessionData;
@ -59,7 +59,7 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
switch (errCode) { switch (errCode) {
case PPPERR_NONE: { /* No error. */ case PPPERR_NONE: { /* No error. */
pCache = (PPPPOE_CACHE)malloc(sizeof(PPPOE_CACHE)); pCache = (PPPPOE_CACHE)malloc(sizeof(PPPOE_CACHE));
dzlog_info("<%p> PPPoE user(%05d:%s) connect server succeeded[%08X], Session: %04X\n", LOG_MSG(info, ZLOG_MOD_PPPOE, ("<%p> PPPoE user(%05d:%s) connect server succeeded[%08X], Session: %04X\n",
pcb, pcb,
pUser->userid, pUser->userid,
pUser->user_info.pppoe_user, pUser->user_info.pppoe_user,
@ -78,16 +78,16 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
pUser->user_info.mac_addr[3], pUser->user_info.mac_addr[3],
pUser->user_info.mac_addr[4], pUser->user_info.mac_addr[4],
pUser->user_info.mac_addr[5]); pUser->user_info.mac_addr[5]);
dzlog_info(" our_ipaddr = %s\n", pUser->session.data.clientIp); LOG_MSG(info, ZLOG_MOD_PPPOE, (" our_ipaddr = %s\n", pUser->session.data.clientIp);
dzlog_info(" his_ipaddr = %s\n", pUser->session.data.clientGw); LOG_MSG(info, ZLOG_MOD_PPPOE, (" his_ipaddr = %s\n", pUser->session.data.clientGw);
dzlog_info(" netmask = %s\n", pUser->session.data.clientMask); LOG_MSG(info, ZLOG_MOD_PPPOE, (" netmask = %s\n", pUser->session.data.clientMask);
#endif /* LWIP_IPV4 */ #endif /* LWIP_IPV4 */
#if LWIP_DNS #if LWIP_DNS
dzlog_info(" dns1 = %s\n", ipaddr_ntoa(dns_getserver(0))); LOG_MSG(info, ZLOG_MOD_PPPOE, (" dns1 = %s\n", ipaddr_ntoa(dns_getserver(0)));
dzlog_info(" dns2 = %s\n", ipaddr_ntoa(dns_getserver(1))); LOG_MSG(info, ZLOG_MOD_PPPOE, (" dns2 = %s\n", ipaddr_ntoa(dns_getserver(1)));
#endif /* LWIP_DNS */ #endif /* LWIP_DNS */
#if PPP_IPV6_SUPPORT #if PPP_IPV6_SUPPORT
dzlog_info(" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0))); LOG_MSG(info, ZLOG_MOD_PPPOE, (" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
#endif /* PPP_IPV6_SUPPORT */ #endif /* PPP_IPV6_SUPPORT */
if (pCache) { if (pCache) {
@ -103,7 +103,7 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
case PPPERR_PARAM: case PPPERR_PARAM:
case PPPERR_AUTHFAIL: case PPPERR_AUTHFAIL:
case PPPERR_PROTOCOL: case PPPERR_PROTOCOL:
dzlog_error("<%p> pppLinkStatusCallback: %s(%d)", LOG_MSG(error, ZLOG_MOD_PPPOE, ("<%p> pppLinkStatusCallback: %s(%d)",
pcb, pcb,
g_pppoeErr[errCode].errmsg, g_pppoeErr[errCode].errmsg,
g_pppoeErr[errCode].errid); g_pppoeErr[errCode].errid);
@ -127,7 +127,7 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
} }
break; break;
case PPPERR_USER: case PPPERR_USER:
dzlog_info("User(%05d:%s) disconnect\n", pUser->userid, pUser->user_info.pppoe_user); LOG_MSG(info, ZLOG_MOD_PPPOE, ("User(%05d:%s) disconnect\n", pUser->userid, pUser->user_info.pppoe_user);
pCache = (PPPPOE_CACHE)malloc(sizeof(PPPOE_CACHE)); pCache = (PPPPOE_CACHE)malloc(sizeof(PPPOE_CACHE));
if (pCache) { if (pCache) {
@ -148,7 +148,7 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
case PPPERR_IDLETIMEOUT: case PPPERR_IDLETIMEOUT:
case PPPERR_CONNECTTIME: case PPPERR_CONNECTTIME:
case PPPERR_LOOPBACK: case PPPERR_LOOPBACK:
dzlog_error("<%p> pppLinkStatusCallback: %s(%d)\n", LOG_MSG(error, ZLOG_MOD_PPPOE, ("<%p> pppLinkStatusCallback: %s(%d)\n",
pcb, pcb,
g_pppoeErr[errCode].errmsg, g_pppoeErr[errCode].errmsg,
g_pppoeErr[errCode].errid); g_pppoeErr[errCode].errid);
@ -189,13 +189,13 @@ _Noreturn void sessionCalcCb(void *UNUSED(pArg)) {
switch (pSession->status) { switch (pSession->status) {
case STATUS_TASK_INIT: case STATUS_TASK_INIT:
if (pppoe_session_create(pUser) == ERR_SUCCESS) { if (pppoe_session_create(pUser) == ERR_SUCCESS) {
dzlog_debug("User(%05d:%s) init pppoe session\n", pUser->userid, pUser->user_info.pppoe_user); LOG_MSG(debug, ZLOG_MOD_PPPOE, ("User(%05d:%s) init pppoe session\n", pUser->userid, pUser->user_info.pppoe_user);
pSession->status = STATUS_TASK_DIAL; pSession->status = STATUS_TASK_DIAL;
} }
break; break;
case STATUS_TASK_DIAL: case STATUS_TASK_DIAL:
if (pUser->session.retry.timeout == 0) { if (pUser->session.retry.timeout == 0) {
dzlog_debug("User(%05d:%s) connect PPPoE server\n", pUser->userid, pUser->user_info.pppoe_user); LOG_MSG(debug, ZLOG_MOD_PPPOE, ("User(%05d:%s) connect PPPoE server\n", pUser->userid, pUser->user_info.pppoe_user);
pppapi_connect(pSession->ppp, 0); pppapi_connect(pSession->ppp, 0);
pUser->session.retry.timeout = time(NULL) + PPPOE_MAX_TIMEOUT; pUser->session.retry.timeout = time(NULL) + PPPOE_MAX_TIMEOUT;
} else if (time(NULL) > pUser->session.retry.timeout) { } else if (time(NULL) > pUser->session.retry.timeout) {
@ -204,14 +204,14 @@ _Noreturn void sessionCalcCb(void *UNUSED(pArg)) {
break; break;
case STATUS_TASK_ERROR: case STATUS_TASK_ERROR:
if (pUser->session.retry.timeout == 0) { if (pUser->session.retry.timeout == 0) {
dzlog_error("User(%05d:%s) PPPoE dial error Invalid parameter\n", LOG_MSG(error, ZLOG_MOD_PPPOE, ("User(%05d:%s) PPPoE dial error Invalid parameter\n",
pUser->userid, pUser->userid,
pUser->user_info.pppoe_user); pUser->user_info.pppoe_user);
// 10秒后尝试重新拨号 // 10秒后尝试重新拨号
pUser->session.retry.timeout = time(NULL) + (PPPOE_MAX_TIMEOUT / 2); pUser->session.retry.timeout = time(NULL) + (PPPOE_MAX_TIMEOUT / 2);
pUser->session.retry.count = 0; pUser->session.retry.count = 0;
} else if (time(NULL) > pUser->session.retry.timeout) { } else if (time(NULL) > pUser->session.retry.timeout) {
dzlog_warn("User(%05d:%s) retry dial %u times\n", LOG_MSG(warn, ZLOG_MOD_PPPOE, ("User(%05d:%s) retry dial %u times\n",
pUser->userid, pUser->userid,
pUser->user_info.pppoe_user, pUser->user_info.pppoe_user,
pUser->session.retry.count); pUser->session.retry.count);
@ -224,14 +224,14 @@ _Noreturn void sessionCalcCb(void *UNUSED(pArg)) {
break; break;
case STATUS_TASK_DISCONNECTED: case STATUS_TASK_DISCONNECTED:
dzlog_error("User %s disconnect, auto reconnect\n", pUser->user_info.pppoe_user); LOG_MSG(error, ZLOG_MOD_PPPOE, ("User %s disconnect, auto reconnect\n", pUser->user_info.pppoe_user);
// 自动重新拨号 // 自动重新拨号
pSession->status = STATUS_TASK_DIAL; pSession->status = STATUS_TASK_DIAL;
break; break;
case STATUS_TASK_DELETE: case STATUS_TASK_DELETE:
if (pUser->session.retry.timeout == 0) { if (pUser->session.retry.timeout == 0) {
dzlog_debug("User(%05d:%s) PPPoE deleted\n", pUser->userid, pUser->user_info.pppoe_user); LOG_MSG(debug, ZLOG_MOD_PPPOE, ("User(%05d:%s) PPPoE deleted\n", pUser->userid, pUser->user_info.pppoe_user);
pppapi_close(pUser->session.ppp, 0); pppapi_close(pUser->session.ppp, 0);
pUser->session.retry.timeout = time(NULL); pUser->session.retry.timeout = time(NULL);
pppapi_free(pUser->session.ppp); pppapi_free(pUser->session.ppp);
@ -244,7 +244,7 @@ _Noreturn void sessionCalcCb(void *UNUSED(pArg)) {
if (pUser->session.retry.timeout == 0) { if (pUser->session.retry.timeout == 0) {
pUser->session.retry.timeout = time(NULL) + 30; pUser->session.retry.timeout = time(NULL) + 30;
} else if (time(NULL) > pUser->session.retry.timeout) { } else if (time(NULL) > pUser->session.retry.timeout) {
dzlog_debug("User(%05d:%s) PPPoE disconnected\n", pUser->userid, pUser->user_info.pppoe_user); LOG_MSG(debug, ZLOG_MOD_PPPOE, ("User(%05d:%s) PPPoE disconnected\n", pUser->userid, pUser->user_info.pppoe_user);
pSession->status = STATUS_TASK_DELETE; pSession->status = STATUS_TASK_DELETE;
pppapi_close(pUser->session.ppp, 0); pppapi_close(pUser->session.ppp, 0);
pUser->session.retry.timeout = 0; pUser->session.retry.timeout = 0;
@ -336,9 +336,9 @@ int pppoe_session_init() {
g_rawSocketIf = bind_pcap_if(config_get_vxlan_nic_name(), config_get_vxlan_pkg_filter(), cfg_get_support_vxlan()); g_rawSocketIf = bind_pcap_if(config_get_vxlan_nic_name(), config_get_vxlan_pkg_filter(), cfg_get_support_vxlan());
if (g_rawSocketIf) { if (g_rawSocketIf) {
dzlog_info("Create hardware netif: <%p>\n", (void *)g_rawSocketIf); LOG_MSG(info, ZLOG_MOD_PPPOE, ("Create hardware netif: <%p>\n", (void *)g_rawSocketIf);
} else { } else {
dzlog_info("Create hardware error: <%p>\n", (void *)g_rawSocketIf); LOG_MSG(info, ZLOG_MOD_PPPOE, ("Create hardware error: <%p>\n", (void *)g_rawSocketIf);
} }
// 启动Session状态机线程 // 启动Session状态机线程
@ -353,14 +353,14 @@ int pppoe_session_create(PUSER_INFO_CONTEXT pUser) {
struct netif *ppp_netif = (struct netif *)malloc(sizeof(struct netif)); struct netif *ppp_netif = (struct netif *)malloc(sizeof(struct netif));
if (ppp_netif == NULL) { if (ppp_netif == NULL) {
dzlog_error("Malloc %lu bytes memory error\n", sizeof(struct netif)); LOG_MSG(error, ZLOG_MOD_PPPOE, ("Malloc %lu bytes memory error\n", sizeof(struct netif));
return -ERR_MALLOC_MEMORY; return -ERR_MALLOC_MEMORY;
} }
netif = create_pppoe_if(pUser); netif = create_pppoe_if(pUser);
if (netif == NULL) { if (netif == NULL) {
dzlog_error("Create PPPoE netif error: %u\n", pUser->userid); LOG_MSG(error, ZLOG_MOD_PPPOE, ("Create PPPoE netif error: %u\n", pUser->userid);
free((void *)ppp_netif); free((void *)ppp_netif);
return -ERR_CREATE_PPPOE_NETIF; return -ERR_CREATE_PPPOE_NETIF;
} }
@ -371,7 +371,7 @@ int pppoe_session_create(PUSER_INFO_CONTEXT pUser) {
ppp = pppapi_pppoe_create(pUser->session.pppif, pUser->session.nicif, NULL, NULL, pppLinkStatusCallback, pUser); ppp = pppapi_pppoe_create(pUser->session.pppif, pUser->session.nicif, NULL, NULL, pppLinkStatusCallback, pUser);
if (ppp == NULL) { if (ppp == NULL) {
dzlog_error("Create PPPoE session error: %u\n", pUser->userid); LOG_MSG(error, ZLOG_MOD_PPPOE, ("Create PPPoE session error: %u\n", pUser->userid);
netif_remove(netif); netif_remove(netif);
free((void *)ppp_netif); free((void *)ppp_netif);
return -ERR_CREATE_PPP_SESSION; return -ERR_CREATE_PPP_SESSION;
@ -381,7 +381,7 @@ int pppoe_session_create(PUSER_INFO_CONTEXT pUser) {
ppp_set_auth(ppp, PPPAUTHTYPE_ANY, pUser->user_info.pppoe_user, pUser->user_info.pppoe_passwd); ppp_set_auth(ppp, PPPAUTHTYPE_ANY, pUser->user_info.pppoe_user, pUser->user_info.pppoe_passwd);
dzlog_debug("Create PPPoE netif %p: %u(%c%c:%u, %c%c:%u)\n", LOG_MSG(debug, ZLOG_MOD_PPPOE, ("Create PPPoE netif %p: %u(%c%c:%u, %c%c:%u)\n",
ppp, ppp,
pUser->userid, pUser->userid,
ppp_netif->name[0], ppp_netif->name[0],

View File

@ -2,10 +2,12 @@
// Created by xajhuang on 2022/5/11. // Created by xajhuang on 2022/5/11.
// //
#include <misc.h> #include <misc.h>
#include <zlog.h> #include "zlog_module.h"
#include "user_info.h" #include "user_info.h"
#include "user_errno.h" #include "user_errno.h"
#ifdef USED_LWIP
static PUSER_INFO_CONTEXT g_pUserByIdList = NULL; static PUSER_INFO_CONTEXT g_pUserByIdList = NULL;
static PUSER_INFO_CONTEXT g_pUserByTagsList = NULL; static PUSER_INFO_CONTEXT g_pUserByTagsList = NULL;
static PUSER_INFO_CONTEXT g_pUserByMacList = NULL; static PUSER_INFO_CONTEXT g_pUserByMacList = NULL;
@ -69,7 +71,8 @@ int user_info_add(unsigned int userid, PUSER_PARAMS pInfo) {
HASH_ADD(hh_mac, g_pUserByMacList, mac_addr, 6, pList); HASH_ADD(hh_mac, g_pUserByMacList, mac_addr, 6, pList);
uv_rwlock_wrunlock(&g_userLock); uv_rwlock_wrunlock(&g_userLock);
dzlog_debug( LOG_MSG(debug,
ZLOG_MOD_USER,
"Add user: id = %u, vni = %u, q1 = %u, q2 = %u, ppp_user = %s, mac = %02X:%02X:%02X:%02X:%02X:%02X\n", "Add user: id = %u, vni = %u, q1 = %u, q2 = %u, ppp_user = %s, mac = %02X:%02X:%02X:%02X:%02X:%02X\n",
userid, userid,
pInfo->vni, pInfo->vni,
@ -204,3 +207,4 @@ PUSER_INFO_CONTEXT get_all_user_by_tag() {
uv_rwlock_t *get_user_lock() { uv_rwlock_t *get_user_lock() {
return &g_userLock; return &g_userLock;
} }
#endif

View File

@ -2,7 +2,6 @@
// Created by xajhuang on 2022/6/10. // Created by xajhuang on 2022/6/10.
// //
#include <uv.h> #include <uv.h>
#include <zlog.h>
#include <zmq.h> #include <zmq.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>

View File

@ -2,7 +2,6 @@
// Created by xajhu on 2021/6/29 0029. // Created by xajhu on 2021/6/29 0029.
// //
#include <uv.h> #include <uv.h>
#include <zlog.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "cmdline.h" #include "cmdline.h"
@ -10,6 +9,7 @@
#include "init.h" #include "init.h"
#include "inet_misc.h" #include "inet_misc.h"
#include "config.h" #include "config.h"
#include "zlog_module.h"
#include "prj_config.h" #include "prj_config.h"
#include "user_errno.h" #include "user_errno.h"
@ -65,11 +65,11 @@ static void on_http_response_cb(void *pData,
int iFinished, int iFinished,
void *pUserData) { void *pUserData) {
if (iFinished == 0) { if (iFinished == 0) {
dzlog_debug("Request(%s): [%s] Response: [%u] OK:\n", pTaskUuid, pReqUrl, size); LOG_MSG(debug, ZLOG_MOD_MAIN, "Request(%s): [%s] Response: [%u] OK:\n", pTaskUuid, pReqUrl, size);
} else if (iFinished == 1) { } else if (iFinished == 1) {
dzlog_error("Request(%s): [%s] Response: [%u] Error\n", pTaskUuid, pReqUrl, size); LOG_MSG(error, ZLOG_MOD_MAIN, "Request(%s): [%s] Response: [%u] Error\n", pTaskUuid, pReqUrl, size);
} else { } else {
dzlog_error("Download Error Code: %d\n", iFinished); LOG_MSG(error, ZLOG_MOD_MAIN, "Download Error Code: %d\n", iFinished);
} }
free(pUserData); free(pUserData);