Add ZNJK-1000 修改vCPE工程,支持Open DHCP Server

This commit is contained in:
huangxin 2022-09-19 09:53:11 +08:00
parent fefb5c4b89
commit 6ec429b814
9 changed files with 92 additions and 19 deletions

4
.gitignore vendored
View File

@ -1,5 +1,5 @@
/cmake-build-debug/
/.idea/
*/__init__.py
/cmake-build-debug-*/
/cmake-build-debug_*/
/cmake-build-dhcpd_*/
/cmake-build-pppoe_*/

View File

@ -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)
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 ()

View File

@ -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 本地服务网络接口配置

View File

@ -1,5 +1,8 @@
SET(PROJECT_TARGET vcpe_main)
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)
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})
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/")

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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
}