diff --git a/config/vcpe.cfg b/config/vcpe.cfg index 51574cd..834c0cf 100644 --- a/config/vcpe.cfg +++ b/config/vcpe.cfg @@ -78,7 +78,8 @@ application: # DHCP Server Config dhcp_server: { listen_on = ["192.168.30.1", "192.168.100.1"]; - http_client = ["192.168.30.1", "192.168.30.110", "192.168.100.1", "192.168.100.110"]; + # 主备服务器设置 + # replication = ["192.168.100.211", "192.168.100.215"]; range_set: ( { dhcp_range = "192.168.30.110-192.168.30.120"; diff --git a/srcs/libs/CMakeLists.txt b/srcs/libs/CMakeLists.txt index 16f58b2..5f3a02e 100644 --- a/srcs/libs/CMakeLists.txt +++ b/srcs/libs/CMakeLists.txt @@ -23,11 +23,10 @@ AUX_SOURCE_DIRECTORY(mq C_SRC) AUX_SOURCE_DIRECTORY(cmdline C_SRC) AUX_SOURCE_DIRECTORY(crypto C_SRC) AUX_SOURCE_DIRECTORY(hardware C_SRC) -AUX_SOURCE_DIRECTORY(vector C_SRC) SET(CMAKE_C_STANDARD 99) -SET_SOURCE_FILES_PROPERTIES(vector/zvector.c PROPERTIES COMPILE_FLAGS "-Wall -Wextra -flto") +SET_SOURCE_FILES_PROPERTIES(misc/zvector.c PROPERTIES COMPILE_FLAGS "-Wall -Wextra -flto") ADD_DEFINITIONS(-DBUILD_VERSION="${GIT_VERSION}" ${COMMON_DEFINE}) diff --git a/srcs/libs/configure/config.c b/srcs/libs/configure/config.c index 2fd6de3..af5b4c6 100644 --- a/srcs/libs/configure/config.c +++ b/srcs/libs/configure/config.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "uthash/uthash.h" #include "config.h" @@ -14,7 +14,6 @@ #include "user_errno.h" #include "crypto.h" #include "hardware.h" -#include "zvector/zvector.h" #define CFG_INT_VALUE(p) (p->value.longValue) #define CFG_BOOL_VALUE(p) (p->value.longValue == FALSE ? FALSE : TRUE) @@ -67,7 +66,7 @@ do { ADD_CFG_ITEM(CFG_HTTP_SVR_PORT, "application.http_svr.listen_port", VALUE_TYPE_INTEGRAL, "6789", "Network port to listen on"); \ ADD_CFG_ITEM(CFG_HTTP_SVR_TCP_NODELAY, "application.http_svr.tcp_nodelay", VALUE_TYPE_BOOL, "1", "TCP delay switch"); \ ADD_CFG_ITEM(CFG_DHCP_LISTEN_ON, "application.dhcp_server.listen_on", VALUE_TYPE_ARRAY_STR, "", "DHCP listen interface"); \ - ADD_CFG_ITEM(CFG_DHCP_HTTP_CLIENT, "application.dhcp_server.http_client", VALUE_TYPE_ARRAY_STR, "", "DHCP http server client write list"); \ + ADD_CFG_ITEM(CFG_DHCP_REPLICATION_SVR, "application.dhcp_server.replication", VALUE_TYPE_ARRAY_STR, "", "DHCP replication server master and secondary"); \ ADD_CFG_ITEM(CFG_DHCP_RANGE_SET, "application.dhcp_server.range_set", VALUE_TYPE_ARRAY_OBJ, "", "DHCP IP pool"); \ } while (0)// clang-format on diff --git a/srcs/libs/configure/config_help.c b/srcs/libs/configure/config_help.c index e894893..9a100db 100644 --- a/srcs/libs/configure/config_help.c +++ b/srcs/libs/configure/config_help.c @@ -7,6 +7,14 @@ const vector config_get_dhcp_server_range_set() { return cfg_get_vector(CFG_DHCP_RANGE_SET); } +const vector config_get_dhcp_listen_on() { + return cfg_get_vector(CFG_DHCP_LISTEN_ON); +} + +const vector config_get_dhcp_replication_svr() { + return cfg_get_vector(CFG_DHCP_REPLICATION_SVR); +} + const char* config_get_http_server_addr() { return cfg_get_string_value(CFG_HTTP_SVR_ADDR); } diff --git a/srcs/libs/hardware/disk.c b/srcs/libs/hardware/disk.c index 086b8d3..7679624 100644 --- a/srcs/libs/hardware/disk.c +++ b/srcs/libs/hardware/disk.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "misc.h" #include "user_errno.h" diff --git a/srcs/libs/hardware/ipmltools.c b/srcs/libs/hardware/ipmltools.c index cbaad14..450987b 100644 --- a/srcs/libs/hardware/ipmltools.c +++ b/srcs/libs/hardware/ipmltools.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "hardware.h" #include "user_errno.h" diff --git a/srcs/libs/hardware/memory.c b/srcs/libs/hardware/memory.c index 0d31710..6f86294 100644 --- a/srcs/libs/hardware/memory.c +++ b/srcs/libs/hardware/memory.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "hardware.h" #include "task_manager.h" diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index 1dc2714..b8acc56 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -2,7 +2,7 @@ // Created by xajhu on 2021/7/1 0001. // -#include "zvector/zvector.h" +#include #ifndef DAEMON_AGENT_INCLUDE_CONFIG_H #define DAEMON_AGENT_INCLUDE_CONFIG_H @@ -62,7 +62,7 @@ typedef enum { CFG_HTTP_SVR_PORT = 30, CFG_HTTP_SVR_TCP_NODELAY = 31, CFG_DHCP_LISTEN_ON = 32, - CFG_DHCP_HTTP_CLIENT = 33, + CFG_DHCP_REPLICATION_SVR = 33, CFG_DHCP_RANGE_SET = 34, CONFIG_ITEM_ID_MAX } CONFIG_ITEM_ID; @@ -114,6 +114,8 @@ const char *config_get_http_server_addr(); unsigned int config_get_http_server_port(); int config_get_http_server_tcp_nodelay(); const vector config_get_dhcp_server_range_set(); +const vector config_get_dhcp_listen_on(); +const vector config_get_dhcp_replication_svr(); #ifdef __cplusplus } #endif diff --git a/srcs/libs/misc/alloc.h b/srcs/libs/include/sds/alloc.h similarity index 100% rename from srcs/libs/misc/alloc.h rename to srcs/libs/include/sds/alloc.h diff --git a/srcs/libs/include/sds.h b/srcs/libs/include/sds/sds.h similarity index 100% rename from srcs/libs/include/sds.h rename to srcs/libs/include/sds/sds.h diff --git a/srcs/libs/misc/sdsalloc.h b/srcs/libs/include/sds/sdsalloc.h similarity index 100% rename from srcs/libs/misc/sdsalloc.h rename to srcs/libs/include/sds/sdsalloc.h diff --git a/srcs/libs/misc/sds.c b/srcs/libs/misc/sds.c index f853ad7..fe5c04a 100644 --- a/srcs/libs/misc/sds.c +++ b/srcs/libs/misc/sds.c @@ -36,9 +36,8 @@ #include #include #include -#include "sds.h" -#include "sdsalloc.h" - +#include +#include hiredisAllocFuncs hiredisAllocFns = { .mallocFn = malloc, diff --git a/srcs/libs/vector/zvector.c b/srcs/libs/misc/zvector.c similarity index 100% rename from srcs/libs/vector/zvector.c rename to srcs/libs/misc/zvector.c diff --git a/srcs/libs/mq/mq_proto.c b/srcs/libs/mq/mq_proto.c index 3839049..33d9b92 100644 --- a/srcs/libs/mq/mq_proto.c +++ b/srcs/libs/mq/mq_proto.c @@ -3,7 +3,7 @@ // #include #include -#include +#include #include "msg_queue.h" #include "s2j/s2j.h" diff --git a/srcs/open_dhcp/query.cpp b/srcs/open_dhcp/query.cpp index bd98ee8..cf49585 100644 --- a/srcs/open_dhcp/query.cpp +++ b/srcs/open_dhcp/query.cpp @@ -33,7 +33,7 @@ static void sendUserList(data19 *req, const char *pRequest) { char logBuff[512]; dhcpMap::iterator p; - printf("Input: %s\n", pRequest); + dzlog_debug("Input: %s\n", pRequest); if (pRequest == nullptr || strlen(pRequest) == 0) { sprintf(logBuff, "Requeset Json"); @@ -370,7 +370,7 @@ int getHwAddr(char *buff, char *mac) { int arpSet(const char *ifname, char *ipStr, char *mac) { if (ifname == nullptr || ipStr == nullptr || mac == nullptr) { - printf("para is null.\n"); + dzlog_error("para is null.\n"); return -1; } @@ -388,19 +388,19 @@ int arpSet(const char *ifname, char *ipStr, char *mac) { req.arp_flags = ATF_PERM | ATF_COM; if (getHwAddr((char *)req.arp_ha.sa_data, mac) < 0) { - printf("get mac error.\n"); + dzlog_error("get mac error.\n"); return -1; } sock_fd = socket(AF_INET, SOCK_DGRAM, 0); if (sock_fd < 0) { - printf("get socket error.\n"); + dzlog_error("get socket error.\n"); return -1; } ret = ioctl(sock_fd, SIOCSARP, &req); if (ret < 0) { - printf("ioctl error.\n"); + dzlog_error("ioctl error.\n"); close(sock_fd); return -1; } diff --git a/srcs/vcpe_main.c b/srcs/vcpe_main.c index 32754dd..897d279 100644 --- a/srcs/vcpe_main.c +++ b/srcs/vcpe_main.c @@ -15,7 +15,6 @@ #ifdef OPENDHCPD_ON #include "user_errno.h" -#include "libs/misc/sdsalloc.h" #endif #ifdef OPENDHCPDDNS_ON @@ -59,8 +58,7 @@ int main(int argc, char **argv) { if(ret == ERR_MENU_EXIT) { user_uninit(); exit(0); - } - if (ret != ERR_SUCCESS) { + } else if (ret != ERR_SUCCESS) { printf("Application setup error(%d), please used --help to show usage, exited!!!\n", ret); user_uninit(); exit(0); @@ -79,6 +77,7 @@ int main(int argc, char **argv) { } user_uninit(); - return 0; + + return ret; #endif }