OCT 1. 删除无用的DNS服务

2. 删除无用的OpenDHCPD配置
3. 增加DHCP服务编译配置
This commit is contained in:
黄昕 2023-05-18 10:09:17 +08:00
parent e02c12f582
commit 395f199ff7
15 changed files with 334 additions and 11199 deletions

View File

@ -4,8 +4,7 @@ INCLUDE(CMakeDependentOption)
OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF) OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF)
OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF) OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF)
OPTION(DHCP_TOOLS "Enable dhcp_tools for test dhcp servers with concurrency and multi-user" OFF) OPTION(DHCP_TOOLS "Enable dhcp_tools for test dhcp servers with concurrency and multi-user" OFF)
OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF) OPTION(USED_DHCPSERVER "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_USER_VNI "Support pass user vni id from console command line" OFF)
OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF) OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF)
OPTION(BUILD_TESTING "Enable tests" OFF) OPTION(BUILD_TESTING "Enable tests" OFF)
@ -14,7 +13,7 @@ OPTION(BUILD_TESTING "Enable tests" OFF)
OPTION(USED_REDIS "Add redis database support for vCPE" OFF) OPTION(USED_REDIS "Add redis database support for vCPE" OFF)
OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF) OPTION(USED_MYSQL "Add mysql database support for vCPE" OFF)
OPTION(USED_SQLITE_CRYPTO "Sqlite3 database support crypto" OFF) OPTION(USED_SQLITE_CRYPTO "Sqlite3 database support crypto" OFF)
CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" ON) CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_DHCPSERVER" ON)
CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF) CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF)
CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF) CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF)
CMAKE_DEPENDENT_OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" ON "USED_SQLITE_CRYPTO" ON) CMAKE_DEPENDENT_OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" ON "USED_SQLITE_CRYPTO" ON)
@ -115,16 +114,10 @@ IF (USED_LWIP)
MESSAGE("Select Option USED_LWIP") MESSAGE("Select Option USED_LWIP")
ENDIF () ENDIF ()
IF (USED_OPENDHCPD) IF (USED_DHCPSERVER)
LIST(APPEND COMMON_DEFINE "-DOPENDHCPD_ON") LIST(APPEND COMMON_DEFINE "-DDHCPD_ON")
MESSAGE("Select Option USED_OPENDHCPD") MESSAGE("Select Option USED_DHCPSERVER")
ADD_SUBDIRECTORY(srcs/opendhcp183) ADD_SUBDIRECTORY(srcs/service)
ENDIF ()
IF (USED_OPENDHCPDDNS)
LIST(APPEND COMMON_DEFINE "-DOPENDHCPDDNS_ON")
MESSAGE("Select Option USED_OPENDHCPDDNS")
ADD_SUBDIRECTORY(srcs/dual_server)
ENDIF () ENDIF ()
IF (VCPE_AGENT) IF (VCPE_AGENT)
@ -157,7 +150,6 @@ ENDIF ()
ADD_SUBDIRECTORY(srcs) ADD_SUBDIRECTORY(srcs)
ADD_SUBDIRECTORY(srcs/libs) ADD_SUBDIRECTORY(srcs/libs)
ADD_SUBDIRECTORY(srcs/service)
IF (DHCP_TOOLS) IF (DHCP_TOOLS)
ADD_SUBDIRECTORY(dhcp_tools) ADD_SUBDIRECTORY(dhcp_tools)

View File

@ -31,10 +31,6 @@ IF (USED_LWIP)
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} lwip_linux) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} lwip_linux)
ENDIF () ENDIF ()
IF (USED_OPENDHCPDDNS)
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} dualserverd)
ENDIF ()
IF (USED_OPENDHCPD) IF (USED_OPENDHCPD)
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} opendhcpd) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} opendhcpd)
ENDIF () ENDIF ()

View File

@ -1,13 +0,0 @@
SET(DHCPD_PROJECT_TARGET dualserverd)
PROJECT(${DHCPD_PROJECT_TARGET} CXX)
INCLUDE_DIRECTORIES(../libs/include ./)
FILE(GLOB DHCPD_HEADS ./*.h)
ADD_DEFINITIONS(-Wno-format-overflow -std=c++11)
#ADD_EXECUTABLE(${PROJECT_TARGET} opendhcpd.cpp ${DHCPD_HEADS})
ADD_LIBRARY(${DHCPD_PROJECT_TARGET} dualserverd.cpp ${DHCPD_HEADS})
#TARGET_LINK_LIBRARIES(${PROJECT_TARGET} -lpthread)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
//
// Created by xajhuang on 2022/10/26.
//
#ifndef VCPE_PROJECT_DUALSVR_H
#define VCPE_PROJECT_DUALSVR_H
#define API_PUBLIC __attribute__((visibility("default")))
#define API_EXPORT API_PUBLIC
#ifdef __cplusplus
extern "C" {
#endif
API_EXPORT int dual_server_main(int argc, char **argv);
#ifdef __cplusplus
}
#endif
#endif//VCPE_PROJECT_DUALSVR_H

View File

@ -166,7 +166,7 @@ typedef enum {
MODE_DHCP_CLIENT, MODE_DHCP_CLIENT,
MODE_DHCP_SERVER MODE_DHCP_SERVER
} DHCP_WORK_MODE; } DHCP_WORK_MODE;
int dhcpd_init(DHCP_WORK_MODE workMode); int dhcpd_init(DHCP_WORK_MODE workMode, const char *pIfName);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -78,8 +78,12 @@ IF (USED_JSON_VALIDATE)
ENDIF () ENDIF ()
IF (USED_OPENDHCPD) IF (USED_OPENDHCPD)
TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd)
ENDIF ()
IF (USED_DHCPSERVER)
#TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd) #TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd)
TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} dhcpd opendhcpd) TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} dhcpd)
ENDIF () ENDIF ()
TARGET_INCLUDE_DIRECTORIES(${LIB_PROJECT_TARGET} PUBLIC ${PROJECT_BINARY_DIR}/ ${CMAKE_BINARY_DIR}/) TARGET_INCLUDE_DIRECTORIES(${LIB_PROJECT_TARGET} PUBLIC ${PROJECT_BINARY_DIR}/ ${CMAKE_BINARY_DIR}/)

View File

@ -3,8 +3,11 @@
// //
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L #if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
#include <openssl/crypto.h> #include <openssl/crypto.h>
#else #else
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#endif #endif
@ -26,6 +29,7 @@
#define REG_ICASE (ARG_REX_ICASE) #define REG_ICASE (ARG_REX_ICASE)
typedef void (*HelpCmdCb)(void *, const char *, void *); typedef void (*HelpCmdCb)(void *, const char *, void *);
typedef int (*ProcessCmdCb)(void **, const char *, void *); typedef int (*ProcessCmdCb)(void **, const char *, void *);
typedef struct { typedef struct {
@ -364,6 +368,34 @@ static int on_cmd6(void *pTbl[], const char *pName, void *pInfo) {
return ERR_MENU_EXIT; return ERR_MENU_EXIT;
} }
#ifdef DHCPD_ON
static int on_cmd8(void *pTbl[], const char *pName, void *pInfo) {
int ret;
PARG_TBL_INFO pArg = (PARG_TBL_INFO)pInfo;
const char *pCfgFile = ((arg_file_t *)pTbl[1])->filename[0];
const char *pCfgDir = ((arg_file_t *)pTbl[2])->filename[0];
const char *pIfName = ((arg_str_t *)pTbl[3])->sval[0];
const char *pKey = ((arg_str_t *)pTbl[4])->sval[0];
int help = get_help_cmd(pTbl, pArg)->count;
if (pArg->pHelp && help > 0) {
pArg->pHelp(pArg->argTbl, pName, pTbl);
return ERR_MENU_EXIT;
}
if ((ret = user_init(pCfgFile, pCfgDir, pKey, 0)) != ERR_SUCCESS) {
printf("System init error: %d\n", ret);
return ret;
}
dhcpd_init(MODE_DHCP_SERVER, pIfName);
return ERR_SUCCESS;
}
#endif
#ifdef OPENDHCPD_ON
typedef struct { typedef struct {
int mode; int mode;
const char *pIni; const char *pIni;
@ -371,12 +403,11 @@ typedef struct {
const char *pIfName; const char *pIfName;
} DHCPD_SETUP, *PDHCPD_SETUP; } DHCPD_SETUP, *PDHCPD_SETUP;
#ifdef OPENDHCPD_ON
static void dhcpd_task(void *pArg) { static void dhcpd_task(void *pArg) {
PDHCPD_SETUP p = (PDHCPD_SETUP)pArg; PDHCPD_SETUP p = (PDHCPD_SETUP)pArg;
if (p) { if (p) {
dhcpd_init(MODE_DHCP_SERVER); //dhcpd_init(MODE_DHCP_SERVER, p->pIfName);
//dhcpd_main(p->mode, p->pIni, p->pStatus, p->pIfName); //dhcpd_main(p->mode, p->pIni, p->pStatus, p->pIfName);
if (p->pIni) { if (p->pIni) {
@ -397,7 +428,7 @@ static void dhcpd_task(void *pArg) {
static int on_cmd7(void *pTbl[], const char *pName, void *pInfo) { static int on_cmd7(void *pTbl[], const char *pName, void *pInfo) {
int ret; int ret;
PDHCPD_SETUP p; // PDHCPD_SETUP p;
static uv_thread_t uvThread; static uv_thread_t uvThread;
PARG_TBL_INFO pArg = (PARG_TBL_INFO)pInfo; PARG_TBL_INFO pArg = (PARG_TBL_INFO)pInfo;
int mode = ((arg_lit_t *)pTbl[1])->count; int mode = ((arg_lit_t *)pTbl[1])->count;
@ -432,6 +463,8 @@ static int on_cmd7(void *pTbl[], const char *pName, void *pInfo) {
return ret; return ret;
} }
dhcpd_init(MODE_DHCP_SERVER, pIfName);
#if 0
p = (PDHCPD_SETUP)malloc(sizeof(DHCPD_SETUP)); p = (PDHCPD_SETUP)malloc(sizeof(DHCPD_SETUP));
if (p) { if (p) {
@ -441,7 +474,7 @@ static int on_cmd7(void *pTbl[], const char *pName, void *pInfo) {
p->pIfName = pIfName ? strdup(pIfName) : NULL; p->pIfName = pIfName ? strdup(pIfName) : NULL;
uv_thread_create(&uvThread, dhcpd_task, p); uv_thread_create(&uvThread, dhcpd_task, p);
} }
#endif
return ERR_SUCCESS; return ERR_SUCCESS;
} }
#endif #endif
@ -454,22 +487,14 @@ static int on_cmd_(void *pTbl[], const char *pName, void *pInfo) {
if (help > 0) { if (help > 0) {
show_help(pName); show_help(pName);
} else { } else {
printf("Application information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n", printf("Application information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n", VCPE_GIT_VERSION, __DATE__,
VCPE_GIT_VERSION, __TIME__, __VERSION__, sizeof(int *) * 8);
__DATE__,
__TIME__,
__VERSION__,
sizeof(int *) * 8);
#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L #if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
printf("OpenSSL information: %s (%s, %s)\n", printf("OpenSSL information: %s (%s, %s)\n", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_BUILT_ON),
OPENSSL_VERSION_TEXT,
SSLeay_version(SSLEAY_BUILT_ON),
SSLeay_version(SSLEAY_PLATFORM)); SSLeay_version(SSLEAY_PLATFORM));
#else #else
printf("OpenSSL information: %s (%s, %s)\n", printf("OpenSSL information: %s (%s, %s)\n", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_BUILT_ON),
OPENSSL_VERSION_TEXT,
OpenSSL_version(OPENSSL_BUILT_ON),
OpenSSL_version(OPENSSL_PLATFORM)); OpenSSL_version(OPENSSL_PLATFORM));
#endif #endif
} }
@ -487,7 +512,8 @@ int menu_run(int argc, char **argv) {
******************************************************************/ ******************************************************************/
// clang-format off // clang-format off
arg_rex_t *cmd1 = arg_rex1(NULL, NULL, "start", NULL, REG_ICASE, NULL); arg_rex_t *cmd1 = arg_rex1(NULL, NULL, "start", NULL, REG_ICASE, NULL);
arg_file_t *cfgfile = arg_filen("c", "config", "[file]", 0, 1, "\tSpecify the current application configuration file path"); arg_file_t *cfgfile = arg_filen("c", "config", "[file]", 0, 1,
"\tSpecify the current application configuration file path");
arg_file_t *cfgdir = arg_file1("d", "directory", "<dir>", "\tSpecify the configuration directory path"); arg_file_t *cfgdir = arg_file1("d", "directory", "<dir>", "\tSpecify the configuration directory path");
arg_str_t *key1 = arg_str0("k", "key", "Key", "\tSpecify the configuration file cryptographic key."); arg_str_t *key1 = arg_str0("k", "key", "Key", "\tSpecify the configuration file cryptographic key.");
arg_lit_t *helpCmd1 = arg_lit0("h", "help", NULL); arg_lit_t *helpCmd1 = arg_lit0("h", "help", NULL);
@ -546,7 +572,8 @@ int menu_run(int argc, char **argv) {
arg_rem(NULL, "\t \033[4m3des_cbc\033[0m: 3DES CBC with PKCS7 padding"), arg_rem(NULL, "\t \033[4m3des_cbc\033[0m: 3DES CBC with PKCS7 padding"),
arg_rem(NULL, "\t \033[4m3des_ofb\033[0m: 3DES OFB with PKCS7 padding"), arg_rem(NULL, "\t \033[4m3des_ofb\033[0m: 3DES OFB with PKCS7 padding"),
arg_rem(NULL, "\t \033[4maes128_ecb\033[0m: 128 bit AES ECB with PKCS7 padding"), arg_rem(NULL, "\t \033[4maes128_ecb\033[0m: 128 bit AES ECB with PKCS7 padding"),
arg_rem(NULL, "\t \033[4maes128_ecb_sha1\033[0m: 128 bit AES ECB and used SHA1 key with PKCS7 padding"), arg_rem(NULL,
"\t \033[4maes128_ecb_sha1\033[0m: 128 bit AES ECB and used SHA1 key with PKCS7 padding"),
arg_rem(NULL, "\t \033[4maes128_cbc\033[0m: 128 bit AES CBC with PKCS7 padding"), arg_rem(NULL, "\t \033[4maes128_cbc\033[0m: 128 bit AES CBC with PKCS7 padding"),
arg_rem(NULL, "\t \033[4maes128_ofb\033[0m: 128 bit AES OFB with PKCS7 padding"), arg_rem(NULL, "\t \033[4maes128_ofb\033[0m: 128 bit AES OFB with PKCS7 padding"),
arg_rem(NULL, "\t \033[4maes192_ecb\033[0m: 192 bit AES ECB with PKCS7 padding"), arg_rem(NULL, "\t \033[4maes192_ecb\033[0m: 192 bit AES ECB with PKCS7 padding"),
@ -566,6 +593,18 @@ int menu_run(int argc, char **argv) {
void *pArgTbl6[] = {cmd6, keyGen, helpCmd6, end6}; void *pArgTbl6[] = {cmd6, keyGen, helpCmd6, end6};
int errCode6 = 0; int errCode6 = 0;
#ifdef DHCPD_ON
arg_rex_t *cmd8 = arg_rex1(NULL, NULL, "dhcpd", NULL, REG_ICASE, NULL);
arg_file_t *cfgfile8 = arg_filen("c", "config", "[file]", 0, 1, "\tSpecify the current application configuration file path");
arg_file_t *cfgdir8 = arg_file1("d", "directory", "<dir>", "\tSpecify the configuration directory path");
arg_str_t *ifname = arg_str1("n", "nic", "<ifname>", "\tSpecify the dhcpd service network interface name.");
arg_str_t *key8 = arg_str0("k", "key", "Key", "\tSpecify the configuration file cryptographic key.");
arg_lit_t *helpCmd8 = arg_lit0("h", "help", NULL);
arg_end_t *end8 = arg_end(20);
void *pArgTbl8[] = {cmd8, cfgfile8, cfgdir8,ifname, key8, helpCmd8, end8};
int errCode8 = 0;
#endif
#ifdef OPENDHCPD_ON #ifdef OPENDHCPD_ON
arg_rex_t *cmd7 = arg_rex1(NULL, NULL, "dhcpd", NULL, REG_ICASE, NULL); arg_rex_t *cmd7 = arg_rex1(NULL, NULL, "dhcpd", NULL, REG_ICASE, NULL);
arg_lit_t *operate7 = arg_lit0("m", "mode", "\tService works on verbatim mode."); arg_lit_t *operate7 = arg_lit0("m", "mode", "\tService works on verbatim mode.");
@ -592,15 +631,25 @@ int menu_run(int argc, char **argv) {
int errCode_ = 0; int errCode_ = 0;
ARG_TBL_INFO argTblInfo[] = { ARG_TBL_INFO argTblInfo[] = {
{pArgTbl1, ARRAY_SIZE(pArgTbl1), &errCode1, on_cmd1, cmdn_help, "\r \033[1;4;36mstart\033[0m: \033[1mRun agent service normally.\033[0m\n"}, {pArgTbl1, ARRAY_SIZE(pArgTbl1), &errCode1, on_cmd1, cmdn_help,
"\r \033[1;4;36mstart\033[0m: \033[1mRun agent service normally.\033[0m\n"},
#ifdef OPENDHCPD_ON #ifdef OPENDHCPD_ON
{pArgTbl7, ARRAY_SIZE(pArgTbl7), &errCode7, on_cmd7, cmdn_help, "\n \033[1;4;36mdhcpd\033[0m: \033[1mRun DHCP service normally.\033[0m\n"}, {pArgTbl7, ARRAY_SIZE(pArgTbl7), &errCode7, on_cmd7, cmdn_help, "\n \033[1;4;36mdhcpd\033[0m: \033[1mRun DHCP service normally.\033[0m\n"},
#endif #endif
{pArgTbl2, ARRAY_SIZE(pArgTbl2), &errCode2, on_cmd2, cmd2_help, "\n \033[1;4;36mif\033[0m: \033[1mRun agent interface tools.\033[0m\n"}, #ifdef DHCPD_ON
{pArgTbl3, ARRAY_SIZE(pArgTbl3), &errCode3, on_cmd3, cmdn_help, "\n \033[1;4;36mbase64\033[0m: \033[1mString base64 encode/decode.\033[0m\n"}, {pArgTbl8, ARRAY_SIZE(pArgTbl8), &errCode8, on_cmd8, cmdn_help,
{pArgTbl4, ARRAY_SIZE(pArgTbl4), &errCode4, on_cmd4, cmdn_help, "\n \033[1;4;36mhash\033[0m: \033[1mCalculate file's hash value.\033[0m\n"}, "\n \033[1;4;36mdhcpd\033[0m: \033[1mRun DHCP service normally.\033[0m\n"},
{pArgTbl5, ARRAY_SIZE(pArgTbl5), &errCode5, on_cmd5, cmdn_help, "\n \033[1;4;36mcipher\033[0m: \033[1mSymmetric cryptography for string.\033[0m\n"}, #endif
{pArgTbl6, ARRAY_SIZE(pArgTbl6), &errCode6, on_cmd6, cmdn_help, "\n \033[1;4;36mconfig\033[0m: \033[1mConfiguration file tools.\033[0m\n"}, {pArgTbl2, ARRAY_SIZE(pArgTbl2), &errCode2, on_cmd2, cmd2_help,
"\n \033[1;4;36mif\033[0m: \033[1mRun agent interface tools.\033[0m\n"},
{pArgTbl3, ARRAY_SIZE(pArgTbl3), &errCode3, on_cmd3, cmdn_help,
"\n \033[1;4;36mbase64\033[0m: \033[1mString base64 encode/decode.\033[0m\n"},
{pArgTbl4, ARRAY_SIZE(pArgTbl4), &errCode4, on_cmd4, cmdn_help,
"\n \033[1;4;36mhash\033[0m: \033[1mCalculate file's hash value.\033[0m\n"},
{pArgTbl5, ARRAY_SIZE(pArgTbl5), &errCode5, on_cmd5, cmdn_help,
"\n \033[1;4;36mcipher\033[0m: \033[1mSymmetric cryptography for string.\033[0m\n"},
{pArgTbl6, ARRAY_SIZE(pArgTbl6), &errCode6, on_cmd6, cmdn_help,
"\n \033[1;4;36mconfig\033[0m: \033[1mConfiguration file tools.\033[0m\n"},
{pArgTbl_, ARRAY_SIZE(pArgTbl_), &errCode_, on_cmd_, NULL, NULL}, {pArgTbl_, ARRAY_SIZE(pArgTbl_), &errCode_, on_cmd_, NULL, NULL},
}; };

View File

@ -114,7 +114,7 @@ static CFG_ITEM g_cfgItem[] = {
#endif #endif
DEF_CFG_ITEM(CFG_PROTO_CRYPTO, "protocol.crypto_type", VAL_INT, "0", "Protocol crypto algorithm"), DEF_CFG_ITEM(CFG_PROTO_CRYPTO, "protocol.crypto_type", VAL_INT, "0", "Protocol crypto algorithm"),
DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"), DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"),
#ifdef OPENDHCPD_ON #ifdef DHCPD_ON
// 配置DHCP服务器 // 配置DHCP服务器
DEF_CFG_ITEM(CFG_DHCP_LEASE_TIME, "dhcp_server.lease_time", VAL_INT, "36000", "DHCP server lease time"), DEF_CFG_ITEM(CFG_DHCP_LEASE_TIME, "dhcp_server.lease_time", VAL_INT, "36000", "DHCP server lease time"),
DEF_CFG_ITEM(CFG_DHCP_LISTEN_ON, "dhcp_server.listen_on", VAL_ARRAY_STR, "", "DHCP listen interface"), DEF_CFG_ITEM(CFG_DHCP_LISTEN_ON, "dhcp_server.listen_on", VAL_ARRAY_STR, "", "DHCP listen interface"),
@ -257,7 +257,7 @@ static int load_array_obj(const char *pKeyName, PCONFIG_ITEM pValue) {
config_setting_t *pObj = config_setting_get_elem(pItem, i); config_setting_t *pObj = config_setting_get_elem(pItem, i);
switch (pValue->cfgId) { switch (pValue->cfgId) {
#if OPENDHCPD_ON #if DHCPD_ON
case CFG_DHCP_RANGE_SET: { case CFG_DHCP_RANGE_SET: {
zvect_index idx = -1; zvect_index idx = -1;
const char *rangAddr, *subnet, *dnsSvr, *gateway; const char *rangAddr, *subnet, *dnsSvr, *gateway;

View File

@ -29,7 +29,7 @@ const char *config_get_proto_crypto_key() {
return cfg_get_string_value(CFG_PROTO_CRYPTO_KEY); return cfg_get_string_value(CFG_PROTO_CRYPTO_KEY);
} }
#if OPENDHCPD_ON #if DHCPD_ON
unsigned int config_get_dhcp_server_lease_time() { unsigned int config_get_dhcp_server_lease_time() {
return cfg_get_integral_value(CFG_DHCP_LEASE_TIME); return cfg_get_integral_value(CFG_DHCP_LEASE_TIME);
} }

View File

@ -75,7 +75,7 @@ typedef enum {
#endif #endif
CFG_PROTO_CRYPTO, CFG_PROTO_CRYPTO,
CFG_PROTO_CRYPTO_KEY, CFG_PROTO_CRYPTO_KEY,
#ifdef OPENDHCPD_ON #ifdef DHCPD_ON
CFG_DHCP_LEASE_TIME, CFG_DHCP_LEASE_TIME,
CFG_DHCP_LISTEN_ON, CFG_DHCP_LISTEN_ON,
CFG_DHCP_REPLICATION_SVR, CFG_DHCP_REPLICATION_SVR,
@ -148,7 +148,7 @@ const char *config_get_proto_crypto_key();
void cfg_set_user_vni_id(int vni); void cfg_set_user_vni_id(int vni);
int cfg_get_user_vni_id(); int cfg_get_user_vni_id();
#endif #endif
#ifdef OPENDHCPD_ON #ifdef DHCPD_ON
unsigned int config_get_dhcp_server_lease_time(); unsigned int config_get_dhcp_server_lease_time();
c_vector config_get_dhcp_server_range_set(); c_vector config_get_dhcp_server_range_set();
c_vector config_get_dhcp_listen_on(); c_vector config_get_dhcp_listen_on();

View File

@ -30,7 +30,7 @@ STRING(REPLACE ";" "," SUPPORTED_OPTIONAL_STR "${SUPPORTED_OPTIONAL}")
ADD_LIBRARY(jsoncdac STATIC ${jsoncdac_SOURCES}) ADD_LIBRARY(jsoncdac STATIC ${jsoncdac_SOURCES})
TARGET_COMPILE_DEFINITIONS(jsoncdac PRIVATE "SUPPORTED_KEYWORDS_BASE=\"${SUPPORTED_BASE_STR}\"" "SUPPORTED_KEYWORDS_OPTIONAL=\"${SUPPORTED_OPTIONAL_STR}\"") TARGET_COMPILE_DEFINITIONS(jsoncdac PRIVATE "SUPPORTED_KEYWORDS_BASE=\"${SUPPORTED_BASE_STR}\"" "SUPPORTED_KEYWORDS_OPTIONAL=\"${SUPPORTED_OPTIONAL_STR}\"")
TARGET_LINK_LIBRARIES(jsoncdac ${EXTRA_LIBS}) TARGET_LINK_LIBRARIES(jsoncdac ${EXTRA_LIBS} -lm)
SET_TARGET_PROPERTIES( SET_TARGET_PROPERTIES(
jsoncdac jsoncdac

View File

@ -3,7 +3,7 @@ INCLUDE_DIRECTORIES(. ../include ../libs/include ./dhcpd/include ../libs/mongoos
AUX_SOURCE_DIRECTORY(dhcpd DHCPD_SRC) AUX_SOURCE_DIRECTORY(dhcpd DHCPD_SRC)
ADD_DEFINITIONS(-DOPENDHCPD_ON) ADD_DEFINITIONS(-DDHCPD_ON)
ADD_DEFINITIONS(${COMMON_DEFINE}) ADD_DEFINITIONS(${COMMON_DEFINE})
ADD_LIBRARY(dhcpd ${DHCPD_SRC} ${DHCPD_HEADS} dhcpd/db_interface.c dhcpd/include/db_interface.h) ADD_LIBRARY(dhcpd ${DHCPD_SRC} ${DHCPD_HEADS} dhcpd/db_interface.c dhcpd/include/db_interface.h)

View File

@ -153,7 +153,7 @@ static uv_udp_t g_uvRawSockReq;
static DHCP_WORK_MODE g_dhcpMode; static DHCP_WORK_MODE g_dhcpMode;
VLAN_TYPE get_package_vlan_type(void *pBuf) { VLAN_TYPE get_package_vlan_type(void *pBuf) {
U8 *p = (U8 *)pBuf; U8 *p = (U8 *) pBuf;
if (p[12] == 0x81 && p[13] == 0x00 && p[16] == 0x81 && p[17] == 0x00) { if (p[12] == 0x81 && p[13] == 0x00 && p[16] == 0x81 && p[17] == 0x00) {
return VLAN_LEVEL2; return VLAN_LEVEL2;
@ -173,11 +173,11 @@ void *get_pkg_free_buf() {
struct tpacket3_hdr *hdr; struct tpacket3_hdr *hdr;
for (i = 0; i < g_pkgRing.send.tp_frame_nr; i++) { for (i = 0; i < g_pkgRing.send.tp_frame_nr; i++) {
hdr = (struct tpacket3_hdr *)(g_pkgRing.tx[0].iov_base + (g_pkgRing.send.tp_frame_size * g_pkgRing.index)); hdr = (struct tpacket3_hdr *) (g_pkgRing.tx[0].iov_base + (g_pkgRing.send.tp_frame_size * g_pkgRing.index));
g_pkgRing.index = (g_pkgRing.index + 1) % g_pkgRing.send.tp_frame_nr; g_pkgRing.index = (g_pkgRing.index + 1) % g_pkgRing.send.tp_frame_nr;
if (!(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING))) { if (!(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING))) {
return (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll); return (U8 *) hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll);
} }
} }
@ -185,7 +185,7 @@ void *get_pkg_free_buf() {
} }
U32 pkg_mmap_tx(U8 *pData, U32 nBytes) { U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
struct tpacket3_hdr *hdr = (struct tpacket3_hdr *)(pData + sizeof(struct sockaddr_ll) - TPACKET3_HDRLEN); struct tpacket3_hdr *hdr = (struct tpacket3_hdr *) (pData + sizeof(struct sockaddr_ll) - TPACKET3_HDRLEN);
hdr->tp_next_offset = 0; hdr->tp_next_offset = 0;
hdr->tp_len = nBytes; hdr->tp_len = nBytes;
@ -195,7 +195,7 @@ U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
} }
static void add_eth_head(U8 *pRsp, struct ethhdr *pEth, int isBst) { static void add_eth_head(U8 *pRsp, struct ethhdr *pEth, int isBst) {
struct ethhdr *p = (struct ethhdr *)pRsp; struct ethhdr *p = (struct ethhdr *) pRsp;
// 二层头 // 二层头
// 目的 MAC 地址 // 目的 MAC 地址
@ -212,7 +212,7 @@ static void add_eth_head(U8 *pRsp, struct ethhdr *pEth, int isBst) {
} }
static void add_vlan_head(U8 *pRsp, PVLAN_HDR pvHdr) { static void add_vlan_head(U8 *pRsp, PVLAN_HDR pvHdr) {
PVLAN_HDR p = (PVLAN_HDR)(pRsp + sizeof(struct ethhdr)); PVLAN_HDR p = (PVLAN_HDR) (pRsp + sizeof(struct ethhdr));
// QinQ 隧道 // QinQ 隧道
p->id = pvHdr->id; p->id = pvHdr->id;
@ -220,7 +220,7 @@ static void add_vlan_head(U8 *pRsp, PVLAN_HDR pvHdr) {
} }
static void add_vlan2_head(U8 *pRsp, PVLAN_HDR2 pvHdr) { static void add_vlan2_head(U8 *pRsp, PVLAN_HDR2 pvHdr) {
PVLAN_HDR2 p = (PVLAN_HDR2)(pRsp + sizeof(struct ethhdr)); PVLAN_HDR2 p = (PVLAN_HDR2) (pRsp + sizeof(struct ethhdr));
// QinQ 隧道 // QinQ 隧道
p->id1 = pvHdr->id1; p->id1 = pvHdr->id1;
@ -281,7 +281,7 @@ static void add_dhcp_common(PDHCP_PROTO p, PDHCP_PROTO pDhcp) {
static PDHCP_PROTO fill_pkg(U8 *pRsp, U8 *pReq) { static PDHCP_PROTO fill_pkg(U8 *pRsp, U8 *pReq) {
U8 *p; U8 *p;
struct ethhdr *pEth = (struct ethhdr *)pReq; struct ethhdr *pEth = (struct ethhdr *) pReq;
struct iphdr *pIp = NULL; struct iphdr *pIp = NULL;
struct udphdr *pUdp = NULL; struct udphdr *pUdp = NULL;
PDHCP_PROTO pDhcp = NULL; PDHCP_PROTO pDhcp = NULL;
@ -289,35 +289,35 @@ static PDHCP_PROTO fill_pkg(U8 *pRsp, U8 *pReq) {
memset(pRsp, 0, MAX_DHCP_PKG_SIZE); memset(pRsp, 0, MAX_DHCP_PKG_SIZE);
switch (get_package_vlan_type(pReq)) { switch (get_package_vlan_type(pReq)) {
default: default:
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET); pIp = (struct iphdr *) (pReq + IP_HDR_OFFSET);
pUdp = (struct udphdr *)(pReq + UDP_HDR_OFFSET); pUdp = (struct udphdr *) (pReq + UDP_HDR_OFFSET);
pDhcp = (PDHCP_PROTO)((U8 *)pReq + DHCP_OFFSET); pDhcp = (PDHCP_PROTO) ((U8 *) pReq + DHCP_OFFSET);
p = pRsp + sizeof(struct ethhdr); p = pRsp + sizeof(struct ethhdr);
break; break;
case VLAN_LEVEL1: case VLAN_LEVEL1:
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR)); pIp = (struct iphdr *) (pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR));
pUdp = (struct udphdr *)(pReq + UDP_HDR_OFFSET + sizeof(VLAN_HDR)); pUdp = (struct udphdr *) (pReq + UDP_HDR_OFFSET + sizeof(VLAN_HDR));
pDhcp = (PDHCP_PROTO)((U8 *)pReq + DHCP_OFFSET + sizeof(VLAN_HDR)); pDhcp = (PDHCP_PROTO) ((U8 *) pReq + DHCP_OFFSET + sizeof(VLAN_HDR));
add_vlan_head(pRsp, (PVLAN_HDR)(pReq + IP_HDR_OFFSET)); add_vlan_head(pRsp, (PVLAN_HDR) (pReq + IP_HDR_OFFSET));
p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR); p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR);
break; break;
case VLAN_LEVEL2: case VLAN_LEVEL2:
pIp = (struct iphdr *)(pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR2)); pIp = (struct iphdr *) (pReq + IP_HDR_OFFSET + sizeof(VLAN_HDR2));
pUdp = (struct udphdr *)(pReq + UDP_HDR_OFFSET + sizeof(VLAN_HDR2)); pUdp = (struct udphdr *) (pReq + UDP_HDR_OFFSET + sizeof(VLAN_HDR2));
pDhcp = (PDHCP_PROTO)((U8 *)pReq + DHCP_OFFSET + sizeof(VLAN_HDR2)); pDhcp = (PDHCP_PROTO) ((U8 *) pReq + DHCP_OFFSET + sizeof(VLAN_HDR2));
add_vlan2_head(pRsp, (PVLAN_HDR2)(pReq + IP_HDR_OFFSET)); add_vlan2_head(pRsp, (PVLAN_HDR2) (pReq + IP_HDR_OFFSET));
p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR2); p = pRsp + sizeof(struct ethhdr) + sizeof(VLAN_HDR2);
break; break;
} }
add_eth_head(pRsp, pEth, (pIp->saddr == 0) ? TRUE : FALSE); add_eth_head(pRsp, pEth, (pIp->saddr == 0) ? TRUE : FALSE);
add_ip_head((struct iphdr *)p, pIp); add_ip_head((struct iphdr *) p, pIp);
p += sizeof(struct iphdr); p += sizeof(struct iphdr);
add_udp_head((struct udphdr *)p, pUdp); add_udp_head((struct udphdr *) p, pUdp);
p += sizeof(struct udphdr); p += sizeof(struct udphdr);
add_dhcp_common((PDHCP_PROTO)p, pDhcp); add_dhcp_common((PDHCP_PROTO) p, pDhcp);
return (PDHCP_PROTO)p; return (PDHCP_PROTO) p;
} }
static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) { static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) {
@ -329,21 +329,21 @@ static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) {
switch (get_package_vlan_type(pRsp)) { switch (get_package_vlan_type(pRsp)) {
default: default:
pIp = (struct iphdr *)(pRsp + IP_HDR_OFFSET); pIp = (struct iphdr *) (pRsp + IP_HDR_OFFSET);
pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET); pUdp = (struct udphdr *) (pRsp + UDP_HDR_OFFSET);
// 计算包总长度 // 计算包总长度
tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET; tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET;
break; break;
case VLAN_LEVEL1: case VLAN_LEVEL1:
pIp = (struct iphdr *)(pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR)); pIp = (struct iphdr *) (pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR));
pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR)); pUdp = (struct udphdr *) (pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR));
// 计算包总长度 // 计算包总长度
tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET + sizeof(VLAN_HDR); tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET + sizeof(VLAN_HDR);
vlanSize = sizeof(VLAN_HDR); vlanSize = sizeof(VLAN_HDR);
break; break;
case VLAN_LEVEL2: case VLAN_LEVEL2:
pIp = (struct iphdr *)(pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR2)); pIp = (struct iphdr *) (pRsp + IP_HDR_OFFSET + sizeof(VLAN_HDR2));
pUdp = (struct udphdr *)(pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR2)); pUdp = (struct udphdr *) (pRsp + UDP_HDR_OFFSET + sizeof(VLAN_HDR2));
// 计算包总长度 // 计算包总长度
tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET + sizeof(VLAN_HDR2); tolSize = optSize + sizeof(DHCP_PROTO) + DHCP_OFFSET + sizeof(VLAN_HDR2);
vlanSize = sizeof(VLAN_HDR2); vlanSize = sizeof(VLAN_HDR2);
@ -356,17 +356,17 @@ static int dhcp_prepare_tx(U8 *pRsp, U32 optSize) {
pUdp->len = htons(tolSize - sizeof(struct ethhdr) - vlanSize - sizeof(struct iphdr)); pUdp->len = htons(tolSize - sizeof(struct ethhdr) - vlanSize - sizeof(struct iphdr));
// 计算 IP 校验和 // 计算 IP 校验和
csum = htons(ip_checksum((unsigned char *)pIp)); csum = htons(ip_checksum((unsigned char *) pIp));
pIp->check = htons(csum); pIp->check = htons(csum);
// 计算 UDP 校验和 // 计算 UDP 校验和
csum = htons(udp_checksum(pIp->saddr, pIp->daddr, (unsigned char *)pUdp)); csum = htons(udp_checksum(pIp->saddr, pIp->daddr, (unsigned char *) pUdp));
pUdp->check = htons(csum); pUdp->check = htons(csum);
LOG_MOD(trace, ZM_DHCP_NET, "Total size: %d\n", tolSize); LOG_MOD(trace, ZM_DHCP_NET, "Total size: %d\n", tolSize);
// 发送数据 // 发送数据
if (pkg_mmap_tx((U8 *)pRsp, tolSize) != tolSize) { if (pkg_mmap_tx((U8 *) pRsp, tolSize) != tolSize) {
LOG_MOD(error, ZM_DHCP_NET, "Send package(%u bytes) error\n", tolSize); LOG_MOD(error, ZM_DHCP_NET, "Send package(%u bytes) error\n", tolSize);
return -ERR_SOCK_SEND; return -ERR_SOCK_SEND;
} }
@ -384,7 +384,7 @@ static int dhcp_resp_nack(void *pReq) {
return -ERR_MALLOC_MEMORY; return -ERR_MALLOC_MEMORY;
} }
pDhcp = fill_pkg(pRsp, (U8 *)pReq); pDhcp = fill_pkg(pRsp, (U8 *) pReq);
// DHCP Options // DHCP Options
pOpt = pDhcp->options; pOpt = pDhcp->options;
@ -393,7 +393,7 @@ static int dhcp_resp_nack(void *pReq) {
pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_NAK); pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_NAK);
*pOpt = OPT_END; *pOpt = OPT_END;
return dhcp_prepare_tx(pRsp, (int)((pOpt - pDhcp->options) + 1)); return dhcp_prepare_tx(pRsp, (int) ((pOpt - pDhcp->options) + 1));
} }
static int dhcp_resp_ack(void *pReq, PPOOL_CTX pIpInfo) { static int dhcp_resp_ack(void *pReq, PPOOL_CTX pIpInfo) {
@ -406,7 +406,7 @@ static int dhcp_resp_ack(void *pReq, PPOOL_CTX pIpInfo) {
return -ERR_MALLOC_MEMORY; return -ERR_MALLOC_MEMORY;
} }
pDhcp = fill_pkg((U8 *)pRsp, (U8 *)pReq); pDhcp = fill_pkg((U8 *) pRsp, (U8 *) pReq);
// 分配的 IP 地址 // 分配的 IP 地址
pDhcp->yiaddr = htonl(pIpInfo->minAddr); pDhcp->yiaddr = htonl(pIpInfo->minAddr);
@ -428,7 +428,7 @@ static int dhcp_resp_ack(void *pReq, PPOOL_CTX pIpInfo) {
pOpt += dhcp_add_u32_option(pOpt, OPT_DNS, htonl(pIpInfo->primeDNS)); pOpt += dhcp_add_u32_option(pOpt, OPT_DNS, htonl(pIpInfo->primeDNS));
} else { } else {
U8 buf[8] = {0}; U8 buf[8] = {0};
U32 *pVal = (U32 *)buf; U32 *pVal = (U32 *) buf;
*pVal++ = htonl(pIpInfo->primeDNS); *pVal++ = htonl(pIpInfo->primeDNS);
*pVal = htonl(pIpInfo->salveDNS); *pVal = htonl(pIpInfo->salveDNS);
pOpt += dhcp_add_buf_option(pOpt, OPT_DNS, buf, 8); pOpt += dhcp_add_buf_option(pOpt, OPT_DNS, buf, 8);
@ -442,7 +442,7 @@ static int dhcp_resp_ack(void *pReq, PPOOL_CTX pIpInfo) {
pOpt += dhcp_add_string_option(pOpt, OPT_DOMAINNAME, "workgroup"); pOpt += dhcp_add_string_option(pOpt, OPT_DOMAINNAME, "workgroup");
*pOpt = OPT_END; *pOpt = OPT_END;
return dhcp_prepare_tx(pRsp, (int)((pOpt - pDhcp->options) + 1)); return dhcp_prepare_tx(pRsp, (int) ((pOpt - pDhcp->options) + 1));
} }
static int dhcp_resp_offer(void *pReq, PPOOL_CTX pIpInfo, U32 ip) { static int dhcp_resp_offer(void *pReq, PPOOL_CTX pIpInfo, U32 ip) {
@ -455,7 +455,7 @@ static int dhcp_resp_offer(void *pReq, PPOOL_CTX pIpInfo, U32 ip) {
return -ERR_MALLOC_MEMORY; return -ERR_MALLOC_MEMORY;
} }
pDhcp = fill_pkg(pRsp, (U8 *)pReq); pDhcp = fill_pkg(pRsp, (U8 *) pReq);
// 分配的 IP 地址 // 分配的 IP 地址
pDhcp->yiaddr = htonl(ip); pDhcp->yiaddr = htonl(ip);
@ -477,7 +477,7 @@ static int dhcp_resp_offer(void *pReq, PPOOL_CTX pIpInfo, U32 ip) {
pOpt += dhcp_add_u32_option(pOpt, OPT_DNS, htonl(pIpInfo->primeDNS)); pOpt += dhcp_add_u32_option(pOpt, OPT_DNS, htonl(pIpInfo->primeDNS));
} else { } else {
U8 buf[8] = {0}; U8 buf[8] = {0};
U32 *pVal = (U32 *)buf; U32 *pVal = (U32 *) buf;
*pVal++ = htonl(pIpInfo->primeDNS); *pVal++ = htonl(pIpInfo->primeDNS);
*pVal = htonl(pIpInfo->salveDNS); *pVal = htonl(pIpInfo->salveDNS);
pOpt += dhcp_add_buf_option(pOpt, OPT_DNS, buf, 8); pOpt += dhcp_add_buf_option(pOpt, OPT_DNS, buf, 8);
@ -491,31 +491,31 @@ static int dhcp_resp_offer(void *pReq, PPOOL_CTX pIpInfo, U32 ip) {
pOpt += dhcp_add_string_option(pOpt, OPT_DOMAINNAME, "workgroup"); pOpt += dhcp_add_string_option(pOpt, OPT_DOMAINNAME, "workgroup");
*pOpt = OPT_END; *pOpt = OPT_END;
return dhcp_prepare_tx(pRsp, (int)((pOpt - pDhcp->options) + 1)); return dhcp_prepare_tx(pRsp, (int) ((pOpt - pDhcp->options) + 1));
} }
PDHCP_PROTO get_dhcp_date(void *pBuf, U32 *pOptSize, U32 bufSize) { PDHCP_PROTO get_dhcp_date(void *pBuf, U32 *pOptSize, U32 bufSize) {
U8 *p = (U8 *)pBuf; U8 *p = (U8 *) pBuf;
U32 hdrCom = sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr); U32 hdrCom = sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr);
if (p[12] == 0x81 && p[13] == 0x00 && p[16] == 0x81 && p[17] == 0x00) { if (p[12] == 0x81 && p[13] == 0x00 && p[16] == 0x81 && p[17] == 0x00) {
*pOptSize = bufSize - hdrCom - sizeof(DHCP_PROTO) - sizeof(VLAN_HDR2); *pOptSize = bufSize - hdrCom - sizeof(DHCP_PROTO) - sizeof(VLAN_HDR2);
return (PDHCP_PROTO)(p + hdrCom + 8); return (PDHCP_PROTO) (p + hdrCom + 8);
} else if (p[12] == 0x81 && p[13] == 0x00) { } else if (p[12] == 0x81 && p[13] == 0x00) {
*pOptSize = bufSize - hdrCom - sizeof(DHCP_PROTO) - sizeof(VLAN_HDR); *pOptSize = bufSize - hdrCom - sizeof(DHCP_PROTO) - sizeof(VLAN_HDR);
return (PDHCP_PROTO)(p + hdrCom + 4); return (PDHCP_PROTO) (p + hdrCom + 4);
} else { } else {
*pOptSize = bufSize - hdrCom - sizeof(DHCP_PROTO); *pOptSize = bufSize - hdrCom - sizeof(DHCP_PROTO);
return (PDHCP_PROTO)(p + hdrCom); return (PDHCP_PROTO) (p + hdrCom);
} }
} }
U32 dhcp_get_uid(void *pBuf) { U32 dhcp_get_uid(void *pBuf) {
U8 *p = (U8 *)pBuf; U8 *p = (U8 *) pBuf;
PVLAN_HDR pQinQ = (PVLAN_HDR)(p + sizeof(struct ethhdr)); PVLAN_HDR pQinQ = (PVLAN_HDR) (p + sizeof(struct ethhdr));
if (p[12] == 0x81 && p[13] == 0x00 && p[16] == 0x81 && p[17] == 0x00) { if (p[12] == 0x81 && p[13] == 0x00 && p[16] == 0x81 && p[17] == 0x00) {
PVLAN_HDR2 pHdr = (PVLAN_HDR2)pQinQ; PVLAN_HDR2 pHdr = (PVLAN_HDR2) pQinQ;
return (pHdr->id1 & 0x0FFF) >> 12 | (pHdr->id2 & 0x0FFF) << 12; return (pHdr->id1 & 0x0FFF) >> 12 | (pHdr->id2 & 0x0FFF) << 12;
} else if (p[12] == 0x81 && p[13] == 0x00) { } else if (p[12] == 0x81 && p[13] == 0x00) {
return (pQinQ->id & 0x0FFF); return (pQinQ->id & 0x0FFF);
@ -532,9 +532,9 @@ static void on_sock_recv(uv_work_t *req) {
DHCP_REQ reqDhcp; DHCP_REQ reqDhcp;
DHCP_OPT optMsg, opt; DHCP_OPT optMsg, opt;
int ret; int ret;
PPKG_PROCESS_INFO pWork = (PPKG_PROCESS_INFO)req->data; PPKG_PROCESS_INFO pWork = (PPKG_PROCESS_INFO) req->data;
PDHCP_PROTO pkg = get_dhcp_date(pWork->pPkgBase, &optSize, pWork->nSize); PDHCP_PROTO pkg = get_dhcp_date(pWork->pPkgBase, &optSize, pWork->nSize);
struct iphdr *pIpHdr = (struct iphdr *)((U8 *)pkg - sizeof(struct iphdr) - sizeof(struct udphdr)); struct iphdr *pIpHdr = (struct iphdr *) ((U8 *) pkg - sizeof(struct iphdr) - sizeof(struct udphdr));
//LOG_MSG(info, "Recv, xid: 0x%08X\n", DHCP_XID(pkg->xid)); //LOG_MSG(info, "Recv, xid: 0x%08X\n", DHCP_XID(pkg->xid));
@ -568,32 +568,32 @@ static void on_sock_recv(uv_work_t *req) {
// region DHCP Discover 处理 // region DHCP Discover 处理
ret = dhcp_get_option(OPT_REQUESTEDIPADDR, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_REQUESTEDIPADDR, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) { if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) {
reqDhcp.reqIpAddr = ntohl(*((U32 *)opt.pValue)); reqDhcp.reqIpAddr = ntohl(*((U32 *) opt.pValue));
} }
ret = dhcp_get_option(OPT_IPADDRLEASE, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_IPADDRLEASE, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) { if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) {
reqDhcp.leaseTime = ntohl(*((U32 *)opt.pValue)); reqDhcp.leaseTime = ntohl(*((U32 *) opt.pValue));
} }
ret = dhcp_get_option(OPT_CLIENTID, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_CLIENTID, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS) { if (ret == ERR_SUCCESS) {
strncpy(reqDhcp.clientId, (char *)opt.pValue, MIN((int)opt.len, 256)); strncpy(reqDhcp.clientId, (char *) opt.pValue, MIN((int) opt.len, 256));
} }
ret = dhcp_get_option(OPT_VENDORCLASSID, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_VENDORCLASSID, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS) { if (ret == ERR_SUCCESS) {
memcpy(reqDhcp.vendorClassId, (char *)opt.pValue, MIN((int)opt.len, 256)); memcpy(reqDhcp.vendorClassId, (char *) opt.pValue, MIN((int) opt.len, 256));
// IPTV 组播设备不用分配IP地址 // IPTV 组播设备不用分配IP地址
if (analyze_iptv_multicast_dev((const U8 *)reqDhcp.vendorClassId, opt.len, macStr, reqDhcp.uid)) { if (analyze_iptv_multicast_dev((const U8 *) reqDhcp.vendorClassId, opt.len, macStr, reqDhcp.uid)) {
return; return;
} }
} }
ret = dhcp_get_option(OPT_HOSTNAME, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_HOSTNAME, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS) { if (ret == ERR_SUCCESS) {
strncpy(reqDhcp.hostName, (char *)opt.pValue, MIN((int)opt.len, 256)); strncpy(reqDhcp.hostName, (char *) opt.pValue, MIN((int) opt.len, 256));
} }
ret = pre_alloc_dhcp_res(&reqDhcp, pWork->pUser, &ip, &pIpInfo); ret = pre_alloc_dhcp_res(&reqDhcp, pWork->pUser, &ip, &pIpInfo);
@ -624,7 +624,7 @@ static void on_sock_recv(uv_work_t *req) {
// 客户端请求的服务器 // 客户端请求的服务器
ret = dhcp_get_option(OPT_SERVERID, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_SERVERID, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) { if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) {
reqDhcp.reqServer = ntohl(*((U32 *)opt.pValue)); reqDhcp.reqServer = ntohl(*((U32 *) opt.pValue));
} else { } else {
// Request 服务器IP可以取目的 IP 地址 // Request 服务器IP可以取目的 IP 地址
if (pIpHdr->saddr != 0) { if (pIpHdr->saddr != 0) {
@ -635,7 +635,7 @@ static void on_sock_recv(uv_work_t *req) {
// 客户端请求的IP // 客户端请求的IP
ret = dhcp_get_option(OPT_REQUESTEDIPADDR, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_REQUESTEDIPADDR, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) { if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) {
reqDhcp.reqIpAddr = ntohl(*((U32 *)opt.pValue)); reqDhcp.reqIpAddr = ntohl(*((U32 *) opt.pValue));
} else { } else {
reqDhcp.reqIpAddr = reqDhcp.cliAddr; reqDhcp.reqIpAddr = reqDhcp.cliAddr;
} }
@ -643,7 +643,7 @@ static void on_sock_recv(uv_work_t *req) {
// 客户端主机名 // 客户端主机名
ret = dhcp_get_option(OPT_HOSTNAME, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_HOSTNAME, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS) { if (ret == ERR_SUCCESS) {
strncpy(reqDhcp.hostName, (char *)opt.pValue, MIN((int)opt.len, 256)); strncpy(reqDhcp.hostName, (char *) opt.pValue, MIN((int) opt.len, 256));
} }
// 当改请求的服务端不是本机时,忽略该消息 // 当改请求的服务端不是本机时,忽略该消息
@ -653,8 +653,8 @@ static void on_sock_recv(uv_work_t *req) {
LOG_MOD_HEX(error, ZM_DHCP_NET, pWork->pPkgBase, pWork->nSize); LOG_MOD_HEX(error, ZM_DHCP_NET, pWork->pPkgBase, pWork->nSize);
LOG_MOD(debug, ZM_DHCP_NET, "Receive others server's DHCP request: request need %s, localhost %s\n", LOG_MOD(debug, ZM_DHCP_NET, "Receive others server's DHCP request: request need %s, localhost %s\n",
pReq, pLocal); pReq, pLocal);
free((void *)pReq); free((void *) pReq);
free((void *)pLocal); free((void *) pLocal);
} else { } else {
POOL_CTX ctx = {0}; POOL_CTX ctx = {0};
if ((ret = is_pre_assigned(&reqDhcp, &ctx)) == ERR_SUCCESS) { if ((ret = is_pre_assigned(&reqDhcp, &ctx)) == ERR_SUCCESS) {
@ -680,7 +680,7 @@ static void on_sock_recv(uv_work_t *req) {
// 客户端请求的服务器 // 客户端请求的服务器
ret = dhcp_get_option(OPT_SERVERID, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_SERVERID, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) { if (ret == ERR_SUCCESS && opt.len == sizeof(U32)) {
reqDhcp.reqServer = ntohl(*((U32 *)opt.pValue)); reqDhcp.reqServer = ntohl(*((U32 *) opt.pValue));
} else { } else {
// Request 服务器IP可以取目的 IP 地址 // Request 服务器IP可以取目的 IP 地址
if (pIpHdr->saddr != 0) { if (pIpHdr->saddr != 0) {
@ -699,7 +699,7 @@ static void on_sock_recv(uv_work_t *req) {
// 客户端主机名 // 客户端主机名
ret = dhcp_get_option(OPT_HOSTNAME, pkg->options, optSize, &opt); ret = dhcp_get_option(OPT_HOSTNAME, pkg->options, optSize, &opt);
if (ret == ERR_SUCCESS) { if (ret == ERR_SUCCESS) {
strncpy(reqDhcp.hostName, (char *)opt.pValue, MIN((int)opt.len, 256)); strncpy(reqDhcp.hostName, (char *) opt.pValue, MIN((int) opt.len, 256));
} }
// 当前分配的租约添加到本地数据库中, 后续分配能够发现对应的主机信息 // 当前分配的租约添加到本地数据库中, 后续分配能够发现对应的主机信息
@ -750,8 +750,8 @@ static void on_sock_recv(uv_work_t *req) {
} }
static void after_msg_recv(uv_work_t *req, int UNUSED(status)) { static void after_msg_recv(uv_work_t *req, int UNUSED(status)) {
PPKG_PROCESS_INFO pInfo = (PPKG_PROCESS_INFO)req->data; PPKG_PROCESS_INFO pInfo = (PPKG_PROCESS_INFO) req->data;
PPKG_MSG pMsg = (PPKG_MSG)pInfo->pData; PPKG_MSG pMsg = (PPKG_MSG) pInfo->pData;
pMsg->nf -= 1; pMsg->nf -= 1;
if (pMsg->nf == 0) { if (pMsg->nf == 0) {
@ -766,13 +766,13 @@ void raw_sock_recv_cb(uv_poll_t *handle, int status, int events) {
PRECV_CB_DATA pCbData = handle->data; PRECV_CB_DATA pCbData = handle->data;
if (status >= 0 && (events & UV_READABLE)) { if (status >= 0 && (events & UV_READABLE)) {
struct block_desc *pbd = (struct block_desc *)g_pkgRing.rx[block_num].iov_base; struct block_desc *pbd = (struct block_desc *) g_pkgRing.rx[block_num].iov_base;
if ((pbd->h1.block_status & TP_STATUS_USER) && (pbd->h1.num_pkts > 0)) { if ((pbd->h1.block_status & TP_STATUS_USER) && (pbd->h1.num_pkts > 0)) {
int i; int i;
struct tpacket3_hdr *ppd; struct tpacket3_hdr *ppd;
unsigned int memSize = sizeof(PKG_PROCESS_INFO) * pbd->h1.num_pkts; unsigned int memSize = sizeof(PKG_PROCESS_INFO) * pbd->h1.num_pkts;
PPKG_MSG pMsg = (PPKG_MSG)malloc(sizeof(PKG_MSG)); PPKG_MSG pMsg = (PPKG_MSG) malloc(sizeof(PKG_MSG));
if (pMsg == NULL) { if (pMsg == NULL) {
LOG_MOD(error, ZM_DHCP_NET, "Malloc memory error: %lu\n", sizeof(PKG_MSG)); LOG_MOD(error, ZM_DHCP_NET, "Malloc memory error: %lu\n", sizeof(PKG_MSG));
@ -780,7 +780,7 @@ void raw_sock_recv_cb(uv_poll_t *handle, int status, int events) {
} }
memset(pMsg, 0, sizeof(PKG_MSG)); memset(pMsg, 0, sizeof(PKG_MSG));
pMsg->pPkgInfo = (PPKG_PROCESS_INFO)malloc(memSize); pMsg->pPkgInfo = (PPKG_PROCESS_INFO) malloc(memSize);
if (pMsg->pPkgInfo == NULL) { if (pMsg->pPkgInfo == NULL) {
LOG_MOD(error, ZM_DHCP_NET, "Malloc memory error: %u\n", memSize); LOG_MOD(error, ZM_DHCP_NET, "Malloc memory error: %u\n", memSize);
@ -791,10 +791,10 @@ void raw_sock_recv_cb(uv_poll_t *handle, int status, int events) {
memset(pMsg->pPkgInfo, 0, memSize); memset(pMsg->pPkgInfo, 0, memSize);
pMsg->nf = pbd->h1.num_pkts; pMsg->nf = pbd->h1.num_pkts;
ppd = (struct tpacket3_hdr *)((uint8_t *)pbd + pbd->h1.offset_to_first_pkt); ppd = (struct tpacket3_hdr *) ((uint8_t *) pbd + pbd->h1.offset_to_first_pkt);
for (i = 0; i < pbd->h1.num_pkts; i++) { for (i = 0; i < pbd->h1.num_pkts; i++) {
U32 uid; U32 uid;
pMsg->pPkgInfo[i].pPkgBase = ((uint8_t *)ppd + ppd->tp_mac); pMsg->pPkgInfo[i].pPkgBase = ((uint8_t *) ppd + ppd->tp_mac);
pMsg->pPkgInfo[i].nSize = ppd->tp_snaplen; pMsg->pPkgInfo[i].nSize = ppd->tp_snaplen;
pMsg->pPkgInfo[i].uvWork.data = &pMsg->pPkgInfo[i]; pMsg->pPkgInfo[i].uvWork.data = &pMsg->pPkgInfo[i];
pMsg->pPkgInfo[i].pData = pMsg; pMsg->pPkgInfo[i].pData = pMsg;
@ -814,7 +814,7 @@ void raw_sock_recv_cb(uv_poll_t *handle, int status, int events) {
uv_queue_work(get_task_manager(), &(pMsg->pPkgInfo[i].uvWork), on_sock_recv, after_msg_recv); uv_queue_work(get_task_manager(), &(pMsg->pPkgInfo[i].uvWork), on_sock_recv, after_msg_recv);
} }
ppd = (struct tpacket3_hdr *)((uint8_t *)ppd + ppd->tp_next_offset); ppd = (struct tpacket3_hdr *) ((uint8_t *) ppd + ppd->tp_next_offset);
} }
} }
@ -830,6 +830,8 @@ int create_udp_raw_socket(const char *pNicName) {
int err; int err;
int v = TPACKET_V3; int v = TPACKET_V3;
LOG_MOD(info, ZM_DHCP_NET, "DHCP working on interface %s\n", pNicName);
// 1. create socket // 1. create socket
int sock_fd = socket(PF_PACKET, SOCK_RAW, 0); int sock_fd = socket(PF_PACKET, SOCK_RAW, 0);
if (sock_fd < 0) { if (sock_fd < 0) {
@ -921,14 +923,14 @@ int create_udp_raw_socket(const char *pNicName) {
// 9. bind socket // 9. bind socket
memset(&addr, 0, sizeof(struct sockaddr_ll)); memset(&addr, 0, sizeof(struct sockaddr_ll));
addr.sll_ifindex = (int)if_nametoindex(pNicName); addr.sll_ifindex = (int) if_nametoindex(pNicName);
addr.sll_family = PF_PACKET; addr.sll_family = PF_PACKET;
addr.sll_protocol = htons(ETH_P_ALL); addr.sll_protocol = htons(ETH_P_ALL);
addr.sll_hatype = 0; addr.sll_hatype = 0;
addr.sll_pkttype = 0; addr.sll_pkttype = 0;
addr.sll_halen = 0; addr.sll_halen = 0;
if ((err = bind(sock_fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_ll))) < 0) { if ((err = bind(sock_fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_ll))) < 0) {
LOG_MOD(error, ZM_DHCP_NET, "Bind raw socket failed: %d\n", err); LOG_MOD(error, ZM_DHCP_NET, "Bind raw socket failed: %d\n", err);
return -ERR_SOCK_SETOPT; return -ERR_SOCK_SETOPT;
} }
@ -943,7 +945,7 @@ void socket_send_task(uv_timer_t *UNUSED(pArg)) {
struct tpacket3_hdr *hdr; struct tpacket3_hdr *hdr;
for (i = 0; i < g_pkgRing.send.tp_frame_nr && g_pkgRing.sock != 0; i++) { for (i = 0; i < g_pkgRing.send.tp_frame_nr && g_pkgRing.sock != 0; i++) {
hdr = (struct tpacket3_hdr *)(g_pkgRing.tx[0].iov_base + (g_pkgRing.send.tp_frame_size * i)); hdr = (struct tpacket3_hdr *) (g_pkgRing.tx[0].iov_base + (g_pkgRing.send.tp_frame_size * i));
if ((hdr->tp_status & TP_STATUS_SEND_REQUEST) || (hdr->tp_status & TP_STATUS_SENDING)) { if ((hdr->tp_status & TP_STATUS_SEND_REQUEST) || (hdr->tp_status & TP_STATUS_SENDING)) {
ssize_t ret = sendto(g_pkgRing.sock, NULL, 0, MSG_DONTWAIT, NULL, sizeof(struct sockaddr_ll)); ssize_t ret = sendto(g_pkgRing.sock, NULL, 0, MSG_DONTWAIT, NULL, sizeof(struct sockaddr_ll));
@ -967,7 +969,7 @@ void init_filter(const char *pNetFilter) {
pcap_compile(pd, &fcode, pNetFilter, 1, 0); pcap_compile(pd, &fcode, pNetFilter, 1, 0);
struct bpf_insn *insn = fcode.bf_insns; struct bpf_insn *insn = fcode.bf_insns;
struct sock_filter *g_filters = (struct sock_filter *)malloc(fcode.bf_len * sizeof(struct sock_filter)); struct sock_filter *g_filters = (struct sock_filter *) malloc(fcode.bf_len * sizeof(struct sock_filter));
for (int i = 0; i < fcode.bf_len; ++insn, ++i) { for (int i = 0; i < fcode.bf_len; ++insn, ++i) {
g_filters[i].code = insn->code; g_filters[i].code = insn->code;
g_filters[i].jt = insn->jt; g_filters[i].jt = insn->jt;
@ -1002,14 +1004,19 @@ void init_raw_socket_poll(void *pRecv, void *pClean) {
uv_timer_start(&uvTm, socket_send_task, 3000, 100); uv_timer_start(&uvTm, socket_send_task, 3000, 100);
} }
int dhcpd_init(DHCP_WORK_MODE workMode) { int dhcpd_init(DHCP_WORK_MODE workMode, const char *pIfName) {
int ret; int ret;
size_t size = MAX_PATH; size_t size = MAX_PATH;
g_dhcpMode = workMode; g_dhcpMode = workMode;
memset(&g_nicInfo, 0, sizeof(NIC_INFO)); memset(&g_nicInfo, 0, sizeof(NIC_INFO));
g_nicInfo.pIfName = (char *)config_get_dhcp_nic_name(); if (pIfName && strlen(pIfName) > 0) {
g_nicInfo.pIfName = strdup(pIfName);
} else {
g_nicInfo.pIfName = strdup((char *) config_get_dhcp_nic_name());
}
uv_os_gethostname(g_nicInfo.hostname, &size); uv_os_gethostname(g_nicInfo.hostname, &size);
get_nic_info(g_nicInfo.pIfName, &g_nicInfo.ipAddr, &g_nicInfo.netmask, NULL, g_nicInfo.macAddr); get_nic_info(g_nicInfo.pIfName, &g_nicInfo.ipAddr, &g_nicInfo.netmask, NULL, g_nicInfo.macAddr);
@ -1047,5 +1054,9 @@ int dhcp_uninit() {
munmap(g_pkgRing.map_recv, size); munmap(g_pkgRing.map_recv, size);
if (g_nicInfo.pIfName) {
free(g_nicInfo.pIfName);
}
return ERR_SUCCESS; return ERR_SUCCESS;
} }