diff --git a/.gitignore b/.gitignore index 6b3686f..b4e916a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /cmake-build-debug/ /.idea/ */__init__.py -/cmake-build-debug-*/ -/cmake-build-debug_*/ +/cmake-build-dhcpd_*/ +/cmake-build-pppoe_*/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b2b51f..4e5842b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR) PROJECT(vCPE_project) -set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") +OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF) +OPTION(USED_LWIP "PPPoE for vCPE" OFF) +OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF) + +SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") SET(URI_HOME "${CMAKE_SOURCE_DIR}/libs") EXECUTE_PROCESS(COMMAND git describe --tags --always --dirty=-dev @@ -21,5 +25,17 @@ MESSAGE("Version: " ${GIT_VERSION}) ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs/libs) -#ADD_SUBDIRECTORY(srcs/test) -ADD_SUBDIRECTORY(srcs/lwip) + +if (VCPE_AGENT) + MESSAGE("Select Option VCPE_AGENT") +endif () + +if (USED_LWIP) + MESSAGE("Select Option USED_LWIP") + ADD_SUBDIRECTORY(srcs/lwip) +endif () + +if (USED_OPENDHCPD) + MESSAGE("Select Option USED_OPENDHCPD") + ADD_SUBDIRECTORY(srcs/open_dhcp) +endif () diff --git a/srcs/libs/config/agent.cfg b/config/agent.cfg similarity index 89% rename from srcs/libs/config/agent.cfg rename to config/agent.cfg index 990ec9a..5848597 100644 --- a/srcs/libs/config/agent.cfg +++ b/config/agent.cfg @@ -52,11 +52,11 @@ application: vxlan_wan: { enable = true; # 是否启动vxLan隧道封装 - nic = "ens36"; # vxlan 物理网卡名称 + nic = "ens160"; # vxlan 物理网卡名称 peer_ip = "192.168.20.112"; # vxlan 对端IP peer_mac = "00:0C:29:49:CB:27"; # vxlan 对端 MAC 地址 - pkg_filter = "(udp port 4789) and (ether src not 00:0c:29:07:cb:55)"; # 包过滤器 -# pkg_filter = "(pppoed || pppoes || arp || icmp || port domain || (udp and (port 67 or port 68))) && inbound"; +# pkg_filter = "(udp port 4789) and (ether src not 00:0c:29:07:cb:55)"; # 包过滤器 + pkg_filter = "(pppoed || pppoes || arp || icmp || port domain || (udp and (port 67 or port 68))) && inbound"; }; # vcpe 本地服务网络接口配置 diff --git a/srcs/libs/config/banner.txt b/config/banner.txt similarity index 100% rename from srcs/libs/config/banner.txt rename to config/banner.txt diff --git a/srcs/libs/config/zlog.conf b/config/zlog.conf similarity index 100% rename from srcs/libs/config/zlog.conf rename to config/zlog.conf diff --git a/srcs/CMakeLists.txt b/srcs/CMakeLists.txt index 7df5f4e..99f0de8 100644 --- a/srcs/CMakeLists.txt +++ b/srcs/CMakeLists.txt @@ -1,5 +1,8 @@ SET(PROJECT_TARGET vcpe_main) -SET(PROJECT_TARGET_AGENT vcpe_agent) + +if (VCPE_AGENT) + SET(PROJECT_TARGET_AGENT vcpe_agent) +endif () PROJECT(${PROJECT_TARGET}) @@ -21,14 +24,41 @@ SET(CMAKE_C_STANDARD 99) FILE(GLOB VCPE_HEADS include/*.h include/uthash/*.h include/s2j/*.h) -AUX_SOURCE_DIRECTORY(pppoe VCPE_SRC) -AUX_SOURCE_DIRECTORY(user VCPE_SRC) +if (USED_LWIP) + AUX_SOURCE_DIRECTORY(pppoe VCPE_SRC) + AUX_SOURCE_DIRECTORY(user VCPE_SRC) +endif () + +if (USED_LWIP) + ADD_DEFINITIONS(-DLWIP_ON) +endif () + +if (USED_OPENDHCPD) + ADD_DEFINITIONS(-DOPENDHCPD_ON) +endif () ADD_EXECUTABLE(${PROJECT_TARGET} ${VCPE_SRC} ${VCPE_HEADS} vcpe_main.c) -ADD_EXECUTABLE(${PROJECT_TARGET_AGENT} ${VCPE_HEADS} vcpe_agent.c) -TARGET_LINK_LIBRARIES(${PROJECT_TARGET} common lwip_linux ${COMMON_LIBS}) -TARGET_LINK_LIBRARIES(${PROJECT_TARGET_AGENT} common ${COMMON_LIBS}) +if (VCPE_AGENT) + ADD_EXECUTABLE(${PROJECT_TARGET_AGENT} ${VCPE_HEADS} vcpe_agent.c) +endif () + +TARGET_LINK_LIBRARIES(${PROJECT_TARGET} common) + +if (USED_LWIP) + TARGET_LINK_LIBRARIES(${PROJECT_TARGET} lwip_linux) +endif () + +if (USED_OPENDHCPD) + TARGET_LINK_LIBRARIES(${PROJECT_TARGET} opendhcpd) +endif () + +TARGET_LINK_LIBRARIES(${PROJECT_TARGET} ${COMMON_LIBS}) + + +if (VCPE_AGENT) + TARGET_LINK_LIBRARIES(${PROJECT_TARGET_AGENT} common ${COMMON_LIBS}) +endif () # 自动复制配置文件到运行路径 ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET} @@ -38,8 +68,10 @@ ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET} COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/log/" COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/libs/config/agent.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/" + copy_if_different "${PROJECT_SOURCE_DIR}/../config/opendhcp.ini" "${CMAKE_CURRENT_BINARY_DIR}/config/" COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/libs/config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/" + copy_if_different "${PROJECT_SOURCE_DIR}/../config/agent.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/" COMMAND ${CMAKE_COMMAND} -E - copy_if_different "${PROJECT_SOURCE_DIR}/libs/config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/") + copy_if_different "${PROJECT_SOURCE_DIR}/../config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/" + COMMAND ${CMAKE_COMMAND} -E + copy_if_different "${PROJECT_SOURCE_DIR}/../config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/") diff --git a/srcs/libs/mq/mq_data.c b/srcs/libs/mq/mq_data.c index 6b72936..2a3c0b2 100644 --- a/srcs/libs/mq/mq_data.c +++ b/srcs/libs/mq/mq_data.c @@ -309,6 +309,7 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) { dzlog_debug("Process: %s\n", pMqMsg->params); decode_add_user_msg(pMqMsg->params, &p); if (p) { +#if LWIP_ON int m, n; for (m = 0; m < p->infoCount; m++) { PADD_INFO pInfo = &(p->pInfo[m]); @@ -329,6 +330,7 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) { user_info_add(userInfo.userid, &userInfo); } } +#endif free_add_user(p); } } else if (strcmp(AGENT_CMD_REMOVUSER, pMqMsg->message) == 0) { @@ -338,10 +340,12 @@ static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) { decode_remove_user_msg(pMqMsg->params, &p); if (p) { +#if LWIP_ON int m; for (m = 0; m < p->nCount; m++) { user_info_remove(p->pUsers[m]); } +#endif free_remove_user(p); } } diff --git a/srcs/open_dhcp/CMakeLists.txt b/srcs/open_dhcp/CMakeLists.txt new file mode 100644 index 0000000..cf58a61 --- /dev/null +++ b/srcs/open_dhcp/CMakeLists.txt @@ -0,0 +1,13 @@ +SET(DHCPD_PROJECT_TARGET opendhcpd) + +PROJECT(${DHCPD_PROJECT_TARGET} CXX) + +INCLUDE_DIRECTORIES(../libs/include ./) + +FILE(GLOB DHCPD_HEADS ./*.h) + +add_definitions(-Wno-format-overflow) +#ADD_EXECUTABLE(${PROJECT_TARGET} opendhcpd.cpp ${DHCPD_HEADS}) +ADD_LIBRARY(${DHCPD_PROJECT_TARGET} opendhcpd.cpp ${DHCPD_HEADS}) + +#TARGET_LINK_LIBRARIES(${PROJECT_TARGET} -lpthread) \ No newline at end of file diff --git a/srcs/vcpe_main.c b/srcs/vcpe_main.c index 0860728..9c56331 100644 --- a/srcs/vcpe_main.c +++ b/srcs/vcpe_main.c @@ -8,9 +8,10 @@ #include "task_manager.h" #include "init.h" #include "user_info.h" -#include "lwip/sys.h" #include "lwip/tcpip.h" +#include "open_dhcp/dhcpd.h" +#if LWIP_ON static void test_init(void *arg) { /* remove compiler warning */ sys_sem_t *init_sem; @@ -32,20 +33,27 @@ static void lwip_init_env() { sys_sem_wait(&init_sem); sys_sem_free(&init_sem); } +#endif int main(int argc, char **argv) { +#if OPENDHCPD_ON + return dhcpd_main(argc, argv); +#else uv_setup_args(argc, argv); setvbuf(stdout, NULL, _IONBF, 0); menu_run(argc, argv); +#if LWIP_ON lwip_init_env(); user_info_init(); - pppoe_session_init(NULL); + pppoe_session_init(); +#endif task_manager_run(); user_uninit(); return 0; +#endif }