From ad06f31aea48af91c7a5e19c171f930a4f158d23 Mon Sep 17 00:00:00 2001 From: huangxin Date: Fri, 13 Jan 2023 16:44:43 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E6=81=A2=E5=A4=8D=E4=B8=8D=E5=B8=A6?= =?UTF-8?q?VNI=E5=90=AF=E5=8A=A8=E5=8F=82=E6=95=B0=E7=9A=84=20systemd=20?= =?UTF-8?q?=E5=AE=88=E6=8A=A4=E8=BF=9B=E7=A8=8B=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=202.=20=E5=A2=9E=E5=8A=A0=20VNI=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=85=8D=E7=BD=AE=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 27 ++++++++++++--------------- config/vcpe.service | 18 ++++++++++++++++++ srcs/libs/cmdline/cmd_menu.c | 12 +++++++++--- srcs/libs/configure/config_help.c | 4 +++- srcs/libs/include/config.h | 6 ++++-- srcs/open_dhcp/query.cpp | 7 ++++++- 6 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 config/vcpe.service diff --git a/CMakeLists.txt b/CMakeLists.txt index 5547cc9..d7f653e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF) OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" OFF) OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF) OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF) +OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF) # 数据库开关 OPTION(USED_REDIS "Add redis database support for vCPE" OFF) @@ -64,44 +65,40 @@ CONFIGURE_FILE(prj_config.h.in prj_config.h) MESSAGE("Git Tag: " ${VERSION_GIT_TAG}) +IF (USED_USER_VNI) + LIST(APPEND COMMON_DEFINE "-DUSER_VNI") + MESSAGE("Select Option USED_USER_VNI") +ENDIF () + IF (USED_LWIP) LIST(APPEND COMMON_DEFINE "-DLWIP_ON") + MESSAGE("Select Option USED_LWIP") ENDIF () IF (USED_OPENDHCPD) LIST(APPEND COMMON_DEFINE "-DOPENDHCPD_ON") + MESSAGE("Select Option USED_OPENDHCPD") + ADD_SUBDIRECTORY(srcs/open_dhcp) ENDIF () IF (USED_OPENDHCPDDNS) LIST(APPEND COMMON_DEFINE "-DOPENDHCPDDNS_ON") + MESSAGE("Select Option USED_OPENDHCPDDNS") + ADD_SUBDIRECTORY(srcs/dual_server) ENDIF () IF (VCPE_AGENT) MESSAGE("Select Option VCPE_AGENT") ENDIF () -IF (USED_LWIP) - MESSAGE("Select Option USED_LWIP") -ENDIF () - IF (USED_SQLITE) MESSAGE("Select Option USED_SQLITE") ENDIF () -IF (USED_OPENDHCPD) - MESSAGE("Select Option USED_OPENDHCPD") - ADD_SUBDIRECTORY(srcs/open_dhcp) -ENDIF () - -IF (USED_OPENDHCPDDNS) - MESSAGE("Select Option USED_OPENDHCPDDNS") - ADD_SUBDIRECTORY(srcs/dual_server) -ENDIF () - IF (USED_LWIP OR VCPE_AGENT) ADD_SUBDIRECTORY(srcs/lwip) ENDIF () ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs/libs) -ADD_SUBDIRECTORY(srcs/httpserver) \ No newline at end of file +ADD_SUBDIRECTORY(srcs/httpserver) diff --git a/config/vcpe.service b/config/vcpe.service new file mode 100644 index 0000000..0a6971b --- /dev/null +++ b/config/vcpe.service @@ -0,0 +1,18 @@ +# sudo cp vcpe.service /lib/systemd/system/ +# sudo ln -s /lib/systemd/system/vcpe.service /etc/systemd/system/multi-user.target.wants/vcpe.service +# sudo systemctl daemon-reload +# sudo systemctl enable vcpe +[Unit] +Description=vCPE Service +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=5 +User=root +WorkingDirectory=/home/jw/vcpe/srcs +ExecStart=/usr/bin/env /home/jw/vcpe/srcs/vcpe_main dhcpd -m -n vxlan0 -c ./config/vcpe.cfg -d ./config/ -k pqwAQ81rxg70aoy3v+Jjrw== + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/srcs/libs/cmdline/cmd_menu.c b/srcs/libs/cmdline/cmd_menu.c index dbb0bcc..43d1d07 100644 --- a/srcs/libs/cmdline/cmd_menu.c +++ b/srcs/libs/cmdline/cmd_menu.c @@ -401,20 +401,26 @@ static int on_cmd7(void *pTbl[], const char *pName, void *pInfo) { const char *piniFile = ((arg_file_t *)pTbl[4])->filename[0]; const char *pstatFile = ((arg_file_t *)pTbl[5])->filename[0]; const char *pIfName = ((arg_str_t *)pTbl[6])->sval[0]; - int *pVni = ((arg_int_t *)pTbl[7])->ival; - const char *pKey = ((arg_str_t *)pTbl[8])->sval[0]; - int help = get_help_cmd(pTbl, pArg)->count; +#ifdef USER_VNI + int *pVni = ((arg_int_t *)pTbl[7])->ival; + const char *pKey = ((arg_str_t *)pTbl[8])->sval[0]; +#else + const char *pKey = ((arg_str_t *)pTbl[7])->sval[0]; +#endif + int help = get_help_cmd(pTbl, pArg)->count; if (pArg->pHelp && help > 0) { pArg->pHelp(pArg->argTbl, pName, pTbl); return ERR_MENU_EXIT; } +#ifdef USER_VNI if (pVni && *pVni > 0) { cfg_set_user_vni_id(*pVni); } else { cfg_set_user_vni_id(0); } +#endif if ((ret = user_init(pCfgFile, pCfgDir, pKey, 0)) != ERR_SUCCESS) { printf("System init error: %d\n", ret); diff --git a/srcs/libs/configure/config_help.c b/srcs/libs/configure/config_help.c index bf61369..262096e 100644 --- a/srcs/libs/configure/config_help.c +++ b/srcs/libs/configure/config_help.c @@ -3,6 +3,7 @@ // #include "config.h" +#ifdef USER_VNI static int g_user_vni_id = -1; void cfg_set_user_vni_id(int vni) { @@ -15,9 +16,10 @@ int cfg_get_user_vni_id() { if (g_user_vni_id > 0xFFFFFF) { return 0; } - + return g_user_vni_id; } +#endif unsigned int config_get_proto_crypto_type() { return cfg_get_integral_value(CFG_PROTO_CRYPTO); diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index 0386699..04527b0 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -141,8 +141,10 @@ unsigned int config_get_http_server_port(); int config_get_http_server_tcp_nodelay(); unsigned int config_get_proto_crypto_type(); const char *config_get_proto_crypto_key(); -void cfg_set_user_vni_id(int vni); -int cfg_get_user_vni_id(); +#ifdef USER_VNI +void cfg_set_user_vni_id(int vni); +int cfg_get_user_vni_id(); +#endif #ifdef OPENDHCPD_ON unsigned int config_get_dhcp_server_lease_time(); c_vector config_get_dhcp_server_range_set(); diff --git a/srcs/open_dhcp/query.cpp b/srcs/open_dhcp/query.cpp index ee276b2..eaeba6b 100644 --- a/srcs/open_dhcp/query.cpp +++ b/srcs/open_dhcp/query.cpp @@ -1264,8 +1264,9 @@ void opendhcp_init_http_server() { uv_thread_create(&uvThread, iptvCacheCb, nullptr); added = TRUE; - +#ifdef USER_VNI dzlog_info("User VxLan Id: [%d]\n", cfg_get_user_vni_id()); +#endif } } @@ -1312,7 +1313,11 @@ int process_iptv_multicast(const unsigned char *p, int size, const char *mac) { memset(pDev, 0, sizeof(IPTV_DEV_SET)); strcpy(pDev->iptvMAC, mac); +#ifdef USER_VNI pDev->vni = cfg_get_user_vni_id(); +#else + pDev->vni = 0; +#endif pDev->isReport = 0; uv_rwlock_wrlock(&g_uvCacheLock); HASH_ADD_STR(g_iptvNewDevs, iptvMAC, pDev);