Merge branch 'master' of http://git.komect.net/ZNJK/vcpe
Conflicts: srcs/open_dhcp/query.cpp
This commit is contained in:
commit
9e222f9481
|
@ -4,7 +4,7 @@
|
|||
# own values below if you need change settings.
|
||||
|
||||
|
||||
[LISTEN_ON]
|
||||
#[LISTEN_ON]
|
||||
# Specify the Interfaces you would like Server to listen
|
||||
# if you have more than one NIC card on your server
|
||||
# always specify which cards will listen DHCP/DNS requests
|
||||
|
@ -16,16 +16,16 @@
|
|||
# 192.168.100.1
|
||||
|
||||
|
||||
[LOGGING]
|
||||
#[LOGGING]
|
||||
# LogLevel can be set as None, Errors or All
|
||||
# It is advisable to keep logging to Normal, Normal include errors
|
||||
# and DHCP renewal messages. Normal is defaul logging also.
|
||||
;LogLevel=None
|
||||
;LogLevel=Normal
|
||||
LogLevel=All
|
||||
#LogLevel=All
|
||||
|
||||
|
||||
[REPLICATION_SERVERS]
|
||||
#[REPLICATION_SERVERS]
|
||||
# You can have 2 instances of Open DHCP Servers in a network. Open DHCP Server
|
||||
# will send replication inform messages to other instance of Open DHCP
|
||||
# server and leases will be replicated. The IP address alloted by one server
|
||||
|
@ -35,11 +35,11 @@ LogLevel=All
|
|||
# Make sure that Primary & Secondary Server entries are identical on both
|
||||
# servers. You may copy the entire ini file on both servers and change the
|
||||
# LISTEN_ON on individual servers, if needed.
|
||||
;Primary=192.168.0.253
|
||||
;Secondary=192.168.0.254
|
||||
#Primary=192.168.30.1
|
||||
#Secondary=192.168.30.3
|
||||
|
||||
|
||||
[HTTP_INTERFACE]
|
||||
#[HTTP_INTERFACE]
|
||||
# This is http inerface for viewing lease status,
|
||||
# Default is 127.0.0.1:6789
|
||||
# You can change it here to any network interface.
|
||||
|
@ -107,30 +107,30 @@ LogLevel=All
|
|||
# with relay Agent IP. If not relay agent IP is sent, Listening Interface's IP
|
||||
# will be matched. You can also override the Target Relay Agent using TargetRelayAgent option.
|
||||
|
||||
[RANGE_SET]
|
||||
#[RANGE_SET]
|
||||
# This is first and simple DHCP range section example,
|
||||
# This example may be good enough for simple/home use.
|
||||
# If you need range filters, look at example below
|
||||
DHCPRange=192.168.30.110-192.168.30.120
|
||||
#DHCPRange=192.168.30.110-192.168.30.120
|
||||
;DHCPRange=192.168.5.1-192.168.5.254
|
||||
# Following are range specific DHCP options.
|
||||
# You can copy more options names from [GLOBAL_OPTIONS]
|
||||
SubnetMask=255.255.255.0
|
||||
DomainServer=114.114.114.114,8.8.8.8
|
||||
#SubnetMask=255.255.255.0
|
||||
#DomainServer=114.114.114.114,8.8.8.8
|
||||
#Router is default gateway
|
||||
Router=192.168.30.1
|
||||
#Router=192.168.30.1
|
||||
# Lease Time can be different for this Range
|
||||
;AddressTime=360
|
||||
#AddressTime=450
|
||||
|
||||
[RANGE_SET]
|
||||
DHCPRange=192.168.100.110-192.168.100.200
|
||||
#[RANGE_SET]
|
||||
#DHCPRange=192.168.100.110-192.168.100.200
|
||||
;DHCPRange=192.168.5.1-192.168.5.254
|
||||
# Following are range specific DHCP options.
|
||||
# You can copy more options names from [GLOBAL_OPTIONS]
|
||||
SubnetMask=255.255.255.0
|
||||
DomainServer=114.114.114.114,8.8.8.8
|
||||
#SubnetMask=255.255.255.0
|
||||
#DomainServer=114.114.114.114,8.8.8.8
|
||||
#Router is default gateway
|
||||
Router=192.168.100.1
|
||||
#Router=192.168.100.1
|
||||
|
||||
[RANGE_SET]
|
||||
# This section is also simple [RANGE_SET] section
|
||||
|
@ -149,7 +149,7 @@ Router=192.168.100.1
|
|||
;51=11000
|
||||
|
||||
|
||||
[RANGE_SET]
|
||||
#[RANGE_SET]
|
||||
# This is filtered [RANGE_SET] section.
|
||||
# First eight entries in this example are filters.
|
||||
# Currently only following types of filters are supported
|
||||
|
|
|
@ -91,22 +91,22 @@ application:
|
|||
|
||||
# DHCP Server Config
|
||||
dhcp_server: {
|
||||
listen_on = ["192.168.30.1", "192.168.100.1"];
|
||||
listen_on = ["192.168.30.1"];
|
||||
# 主备服务器设置
|
||||
# replication = ["192.168.100.211", "192.168.100.215"];
|
||||
replication = ["192.168.30.1", "192.168.30.2"];
|
||||
|
||||
range_set: (
|
||||
{ dhcp_range = "192.168.30.110-192.168.30.120";
|
||||
{ dhcp_range = "192.168.30.150-192.168.30.155";
|
||||
subnet_mask = "255.255.255.0";
|
||||
domain_server = "114.114.114.114,8.8.8.8";
|
||||
gateway = "192.168.30.1";
|
||||
lease_time = 360;
|
||||
lease_time = 36000;
|
||||
},
|
||||
{ dhcp_range = "192.168.100.110-192.168.100.200";
|
||||
subnet_mask = "255.255.255.0";
|
||||
domain_server = "114.114.114.114,8.8.8.8";
|
||||
gateway = "192.168.100.1";
|
||||
lease_time = 360;
|
||||
lease_time = 36000;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ 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 -i ./config/opendhcp.ini -c ./config/vcpe.cfg -d ./config/ -k pqwAQ81rxg70aoy3v+Jjrw==
|
||||
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
|
|
@ -14,10 +14,15 @@ FIND_PACKAGE(PkgConfig)
|
|||
PKG_SEARCH_MODULE(LIBCURL REQUIRED libcurl)
|
||||
PKG_SEARCH_MODULE(LIBSSL REQUIRED libssl)
|
||||
PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto)
|
||||
LIST(APPEND COMMON_LIBS "${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}")
|
||||
LIST(APPEND COMMON_LIBS "-ldl -lpthread -lzlog -lm -luv -lzmq -luuid -lconfig")
|
||||
PKG_SEARCH_MODULE(LIBUV REQUIRED libuv)
|
||||
PKG_SEARCH_MODULE(LIBCONFIG REQUIRED libconfig)
|
||||
PKG_SEARCH_MODULE(LIBZMQ REQUIRED libzmq)
|
||||
FIND_LIBRARY(LIBZLOG zlog REQUIRED)
|
||||
FIND_LIBRARY(LIBUUID uuid REQUIRED)
|
||||
|
||||
LIST(APPEND COMMON_LIBS "-lpthread")
|
||||
LIST(APPEND COMMON_LIBS "${LIBUV_LDFLAGS} ${LIBCONFIG_LDFLAGS} ${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}")
|
||||
LIST(APPEND COMMON_LIBS "${LIBZMQ_LDFLAGS} ${LIBZLOG} ${LIBUUID}")
|
||||
LIST(APPEND COMMON_LIBS "-lm -lpthread")
|
||||
|
||||
ADD_DEFINITIONS(${COMMON_DEFINE})
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "http_response_cache.h"
|
||||
|
||||
static bool tcp_nodelay;
|
||||
extern uv_read_cb http_stream_on_read;
|
||||
|
||||
void ipc_read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
|
||||
int rc;
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "http_response_cache.h"
|
||||
#include "hw_string.h"
|
||||
|
||||
extern http_server_write_response_cb http_server_write_response;
|
||||
|
||||
#define CRLF "\r\n"
|
||||
KHASH_MAP_INIT_STR(string_hashmap, char *)
|
||||
|
||||
|
@ -78,8 +80,8 @@ hw_string *create_response_buffer(hw_http_response *response) {
|
|||
int header_buffer_incr = 512;
|
||||
int body_size = resp->body.length;
|
||||
int header_size_remaining = header_buffer_incr;
|
||||
int response_size = header_size_remaining + sizeof(length_header) + num_chars(resp->body.length) + 2 * line_sep_size
|
||||
+ body_size + line_sep_size;
|
||||
int response_size = header_size_remaining + sizeof(length_header) + num_chars(resp->body.length) +
|
||||
2 * line_sep_size + body_size + line_sep_size;
|
||||
|
||||
response_string->value = malloc(response_size);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifdef PLATFORM_POSIX
|
||||
#include <signal.h>
|
||||
#endif// PLATFORM_POSIX
|
||||
#endif // PLATFORM_POSIX
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -48,6 +48,8 @@ int listener_count;
|
|||
uv_async_t *listener_async_handles;
|
||||
uv_loop_t *listener_event_loops;
|
||||
uv_barrier_t *listeners_created_barrier;
|
||||
uv_read_cb http_stream_on_read;
|
||||
http_server_write_response_cb http_server_write_response;
|
||||
|
||||
int hw_init_with_config(configuration *c) {
|
||||
#ifdef DEBUG
|
||||
|
@ -132,7 +134,7 @@ void hw_http_add_route(char *route, http_request_callback callback, void *user_d
|
|||
routes = kh_init(string_hashmap);
|
||||
}
|
||||
set_route(routes, route, route_entry);
|
||||
dzlog_debug("Added route path: [%s]\n", route);// TODO: Replace with logging instead.
|
||||
dzlog_debug("Added route path: [%s]\n", route); // TODO: Replace with logging instead.
|
||||
}
|
||||
|
||||
void free_http_server() {
|
||||
|
@ -145,7 +147,7 @@ void free_http_server() {
|
|||
free((char *)v);
|
||||
});
|
||||
kh_destroy(string_hashmap, routes);
|
||||
uv_close((uv_handle_t*)&server, NULL);
|
||||
uv_close((uv_handle_t *)&server, NULL);
|
||||
uninit_http_request_cache();
|
||||
dzlog_debug("HTTP Server Close http://%s:%d\n", config->http_listen_address, config->http_listen_port);
|
||||
}
|
||||
|
@ -168,7 +170,7 @@ int hw_http_open() {
|
|||
|
||||
#ifdef UNIX
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif// UNIX
|
||||
#endif // UNIX
|
||||
|
||||
listener_count = threads;
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ extern uv_async_t *listener_async_handles;
|
|||
extern uv_loop_t *listener_event_loops;
|
||||
extern uv_barrier_t *listeners_created_barrier;
|
||||
|
||||
void (*http_stream_on_read)(uv_stream_t *, ssize_t, const uv_buf_t *);
|
||||
int (*http_server_write_response)(hw_write_context *, hw_string *);
|
||||
typedef int (*http_server_write_response_cb)(hw_write_context *, hw_string *);
|
||||
|
||||
http_connection *create_http_connection();
|
||||
void http_stream_on_connect(uv_stream_t *stream, int status);
|
||||
|
|
|
@ -36,7 +36,7 @@ static int disk_info_refresh() {
|
|||
int i = 0;
|
||||
int errCode = ERR_SUCCESS;
|
||||
FILE *fp;
|
||||
char buf[MAX_PATH];
|
||||
char buf[MAX_PATH * 2];
|
||||
|
||||
fp = popen(CMD_DISK_FILESYSTEM, "r");
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ unsigned int get_sys_total_memory() {
|
|||
static int memory_info_refresh() {
|
||||
int errCode = ERR_SUCCESS;
|
||||
FILE *fp;
|
||||
char buf[MAX_PATH];
|
||||
char buf[MAX_PATH * 2];
|
||||
|
||||
fp = popen(CMD_MEMORY_INFO, "r");
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <cjson/cJSON.h>
|
||||
#include <s2j/cJSON.h>
|
||||
|
||||
typedef enum {
|
||||
CRYPTO_NONE = 0,
|
||||
|
|
|
@ -8,10 +8,14 @@
|
|||
|
||||
static const char *g_enumStrVal[][MAX_DESC_LENGTH] = {DEF_ERR_CODE(GENERATE_STRING)};
|
||||
|
||||
const char *getErrorEnumString(int errCode) {
|
||||
const char *getErrorEnumNameString(int errCode) {
|
||||
return g_enumStrVal[errCode][0];
|
||||
}
|
||||
|
||||
const char *getErrorEnumDesc(int errCode) {
|
||||
return g_enumStrVal[errCode][0];
|
||||
}
|
||||
|
||||
const char *getErrorEnumDescripty(int errCode) {
|
||||
return g_enumStrVal[errCode][1];
|
||||
}
|
||||
|
|
|
@ -701,6 +701,8 @@ static zvect_retval p_vect_set_capacity(vector const v, const zvect_index direct
|
|||
return ZVERR_OUTOFMEM;
|
||||
}
|
||||
|
||||
memset(new_data, 0, sizeof(void *) * (new_capacity + v->cap_right));
|
||||
|
||||
zvect_index nb;
|
||||
zvect_index ne;
|
||||
nb = v->cap_left;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//
|
||||
// Created by xajhu on 2021/8/11 0011.
|
||||
//
|
||||
#include <jemalloc/jemalloc.h>
|
||||
#include <uv.h>
|
||||
#include <sds/sds.h>
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ data71 lump;
|
|||
bool kRunning = true;
|
||||
dhcpMap dhcpCache;
|
||||
char serviceName[] = "OpenDHCPServer";
|
||||
int ERR_PARAM;
|
||||
//char tempbuff[512] = "";
|
||||
//char logBuff[256];
|
||||
//char extbuff[256] = "";
|
||||
|
@ -3027,7 +3026,7 @@ void lockOptions(FILE *f) {
|
|||
}
|
||||
}
|
||||
|
||||
void addDHCPRange(char *dp) {
|
||||
int addDHCPRange(char *dp) {
|
||||
char logBuff[256];
|
||||
|
||||
MYDWORD rs = 0;
|
||||
|
@ -3053,8 +3052,7 @@ void addDHCPRange(char *dp) {
|
|||
(range->rangeEnd >= rs && range->rangeEnd <= re)) {
|
||||
sprintf(logBuff, "Warning: DHCP Range %s overlaps with another range, ignored", dp);
|
||||
logDHCPMess(logBuff, 1);
|
||||
ERR_PARAM = ERR_ITEM_EXISTS;
|
||||
return;
|
||||
return ERR_ITEM_EXISTS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3077,18 +3075,21 @@ void addDHCPRange(char *dp) {
|
|||
|
||||
sprintf(logBuff, "DHCP Ranges Load, Memory Allocation Error");
|
||||
logDHCPMess(logBuff, 1);
|
||||
ERR_PARAM = ERR_MALLOC_MEMORY;
|
||||
return;
|
||||
return ERR_MALLOC_MEMORY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sprintf(logBuff, "Section [%s] Invalid DHCP range %s in ini file, ignored", RANGESET, dp);
|
||||
logDHCPMess(logBuff, 1);
|
||||
return ERR_INPUT_PARAMS;
|
||||
}
|
||||
} else {
|
||||
sprintf(logBuff, "Section [%s] Invalid DHCP range %s in ini file, ignored", RANGESET, dp);
|
||||
logDHCPMess(logBuff, 1);
|
||||
return ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
void addVendClass(MYBYTE rangeSetInd, char *vendClass, MYBYTE vendClassSize) {
|
||||
|
@ -3236,6 +3237,8 @@ void loadDHCP() {
|
|||
cfig.mask = inet_addr("255.255.255.0");
|
||||
}
|
||||
|
||||
opendhcp_add_ip_pool_set();
|
||||
#if 0
|
||||
for (MYBYTE i = 1; i <= MAX_RANGE_SETS; i++) {
|
||||
if ((f = openSection(RANGESET, i))) {
|
||||
MYBYTE m = cfig.rangeCount;
|
||||
|
@ -3260,7 +3263,7 @@ void loadDHCP() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//printf("%s\n", IP2String(ipbuff, cfig.mask));
|
||||
|
||||
for (char rangeInd = 0; rangeInd < cfig.rangeCount; rangeInd++) {
|
||||
|
@ -4337,9 +4340,9 @@ void *init(void *lparam) {
|
|||
FILE *f = nullptr;
|
||||
|
||||
if ((f = openSection("LOGGING", 1))) {
|
||||
cfig.dhcpLogLevel = 1;
|
||||
cfig.dhcpLogLevel = 2;
|
||||
tempbuff[0] = 0;
|
||||
|
||||
#if 0
|
||||
while (readSection(raw, f)) {
|
||||
mySplit(name, value, raw, '=');
|
||||
|
||||
|
@ -4361,6 +4364,7 @@ void *init(void *lparam) {
|
|||
sprintf(tempbuff, "Section [LOGGING], Invalid Entry %s ignored", raw);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (tempbuff[0]) {
|
||||
logDHCPMess(logBuff, 1);
|
||||
}
|
||||
|
@ -4447,6 +4451,8 @@ void *init(void *lparam) {
|
|||
getInterfaces(&newNetwork);
|
||||
memcpy(cfig.oldservers, newNetwork.staticServers, (MAX_SERVERS * sizeof(MYDWORD)));
|
||||
|
||||
opendhcp_set_replication_svr();
|
||||
#if 0
|
||||
if ((f = openSection("REPLICATION_SERVERS", 1))) {
|
||||
while (readSection(raw, f)) {
|
||||
mySplit(name, value, raw, '=');
|
||||
|
@ -4471,7 +4477,7 @@ void *init(void *lparam) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
if (!cfig.zoneServers[0] && cfig.zoneServers[1]) {
|
||||
sprintf(logBuff, "Section [REPLICATION_SERVERS] Missing Primary Server");
|
||||
logDHCPMess(logBuff, 1);
|
||||
|
@ -5357,6 +5363,7 @@ void *logThread(void *lpParam) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void logDHCPMess(char *logBuff, MYBYTE logLevel) {
|
||||
// if (verbatim)
|
||||
// printf("%s\n", logBuff);
|
||||
|
@ -5379,6 +5386,7 @@ void logDHCPMess(char *logBuff, MYBYTE logLevel) {
|
|||
// pthread_attr_destroy(&attr);
|
||||
// }
|
||||
}
|
||||
#endif
|
||||
|
||||
data7 *createCache(data71 *pLump) {
|
||||
MYWORD dataSize = 70 + sizeof(data7) + strlen(pLump->mapname) + pLump->optionSize;
|
||||
|
|
|
@ -72,6 +72,21 @@ typedef struct in_pktinfo IN_PKTINFO;
|
|||
|
||||
#define STR2INT(val) ((int)strtol((val), nullptr, 10))
|
||||
|
||||
#define logDHCPMess(logBuff, logLevel) \
|
||||
do { \
|
||||
switch ((logLevel)) { \
|
||||
case 2: \
|
||||
dzlog_debug("%s\n", logBuff); \
|
||||
break; \
|
||||
case 0: \
|
||||
dzlog_error("%s\n", logBuff); \
|
||||
break; \
|
||||
default: \
|
||||
dzlog_info("%s\n", logBuff); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct data7 //cache
|
||||
{
|
||||
char *mapname;
|
||||
|
@ -573,7 +588,7 @@ MYDWORD sdmess(data9 *);
|
|||
MYDWORD sendRepl(data9 *req);
|
||||
MYDWORD *findServer(MYDWORD *, MYBYTE, MYDWORD);
|
||||
int getIndex(char, MYDWORD);
|
||||
void addDHCPRange(char *dp);
|
||||
int addDHCPRange(char *dp);
|
||||
void addVendClass(MYBYTE rangeSetInd, char *vendClass, MYBYTE vendClassSize);
|
||||
void addUserClass(MYBYTE rangeSetInd, char *userClass, MYBYTE userClassSize);
|
||||
void addMacRange(MYBYTE rangeSetInd, char *macRange);
|
||||
|
@ -587,7 +602,6 @@ void getSecondary();
|
|||
void *init(void *);
|
||||
void lockOptions(FILE *);
|
||||
void loadOptions(FILE *, const char *, data20 *);
|
||||
void logDHCPMess(char *, MYBYTE);
|
||||
void mySplit(char *, char *, const char *, char);
|
||||
void *sendHTTP(void *lpParam);
|
||||
void procHTTP(data19 *);
|
||||
|
@ -609,6 +623,8 @@ MYWORD qLen(char *);
|
|||
const char *getRequestMethod(const char *buffer);
|
||||
void prepareUserHtmlRespStatus(data19 *req);
|
||||
void opendhcp_init_http_server();
|
||||
void opendhcp_set_replication_svr();
|
||||
void opendhcp_add_ip_pool_set();
|
||||
int opendhcp_add_listener();
|
||||
void sendUserList(data19 *req, const char *pRequest, dhcpMap *dhcpCache, data2 *cfig, time_t t);
|
||||
void sendAllLists(data19 *req, bool kRunning, dhcpMap *dhcpCache, data2 *cfig);
|
||||
|
|
|
@ -28,7 +28,6 @@ extern data2 cfig;
|
|||
extern bool kRunning;
|
||||
extern dhcpMap dhcpCache;
|
||||
extern time_t t;
|
||||
extern int ERR_PARAM;
|
||||
|
||||
static int dhcp_get_user_info(data19 *req, const char *pRequest) {
|
||||
char logBuff[512];
|
||||
|
@ -205,42 +204,55 @@ static int dhcp_get_all_user(data19 *req) {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
static void add_options(OBJ_DHCP_RNG pRange, data20 *optionData) {
|
||||
static int dhcp_add_rangeset_to_options(POBJ_DHCP_RNG pRange) {
|
||||
int ret;
|
||||
char buff[1024];
|
||||
MYBYTE hoption[256];
|
||||
MYBYTE *dp = optionData->options;
|
||||
MYBYTE *dp;
|
||||
MYWORD buffSize = sizeof(dhcp_packet) - sizeof(dhcp_header);
|
||||
char value[256] = {0};
|
||||
MYBYTE *options = nullptr;
|
||||
data20 optionData {};
|
||||
|
||||
if (!pRange) {
|
||||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
memset(&optionData, 0, sizeof(data20));
|
||||
|
||||
optionData.rangeSetInd = cfig.rangeCount;
|
||||
cfig.rangeSet[cfig.rangeCount].active = true;
|
||||
|
||||
dp = optionData.options;
|
||||
*dp = 0;
|
||||
dp++;
|
||||
|
||||
//dhcp_range
|
||||
addDHCPRange(pRange.rangAddr);
|
||||
if(ERR_PARAM != ERR_SUCCESS){
|
||||
return;
|
||||
ret = addDHCPRange(pRange->rangAddr);
|
||||
if (ret != ERR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strlen(pRange.subnet) != 0) {
|
||||
strcpy(value, pRange.subnet);
|
||||
if (strlen(pRange->subnet) != 0) {
|
||||
strcpy(value, pRange->subnet);
|
||||
VALUE_TO_DHCP_TLV(buff, value, DHCP_OPTION_NETMASK);
|
||||
optionData->mask = (*((MYDWORD *)value));
|
||||
optionData.mask = (*((MYDWORD *)value));
|
||||
}
|
||||
|
||||
if (strlen(pRange.dnsSvr) != 0) {
|
||||
strcpy(value, pRange.dnsSvr);
|
||||
if (strlen(pRange->dnsSvr) != 0) {
|
||||
strcpy(value, pRange->dnsSvr);
|
||||
VALUE_TO_DHCP_TLV(buff, value, DHCP_OPTION_DNS);
|
||||
}
|
||||
|
||||
if (strlen(pRange.gateway) != 0) {
|
||||
strcpy(value, pRange.gateway);
|
||||
if (strlen(pRange->gateway) != 0) {
|
||||
strcpy(value, pRange->gateway);
|
||||
VALUE_TO_DHCP_TLV(buff, value, DHCP_OPTION_ROUTER);
|
||||
}
|
||||
|
||||
//lease
|
||||
if (pRange.lease != 0) {
|
||||
if (pRange->lease != 0) {
|
||||
MYDWORD j;
|
||||
j = pRange.lease;
|
||||
j = pRange->lease;
|
||||
if (buffSize > 6) {
|
||||
*dp = DHCP_OPTION_IPADDRLEASE;
|
||||
dp++;
|
||||
|
@ -252,18 +264,32 @@ static void add_options(OBJ_DHCP_RNG pRange, data20 *optionData) {
|
|||
|
||||
*dp = DHCP_OPTION_END;
|
||||
dp++;
|
||||
optionData->optionSize = (dp - optionData->options);
|
||||
optionData.optionSize = (dp - optionData.options);
|
||||
|
||||
if (optionData.optionSize > 3) {
|
||||
options = (MYBYTE *)calloc(1, optionData.optionSize);
|
||||
memcpy(options, optionData.options, optionData.optionSize);
|
||||
}
|
||||
|
||||
cfig.dhcpRanges[cfig.rangeCount].rangeSetInd = optionData.rangeSetInd;
|
||||
cfig.dhcpRanges[cfig.rangeCount].options = options;
|
||||
cfig.dhcpRanges[cfig.rangeCount].mask = optionData.mask;
|
||||
if (!cfig.dhcpRanges[cfig.rangeCount].mask) {
|
||||
cfig.dhcpRanges[cfig.rangeCount].mask = cfig.mask;
|
||||
}
|
||||
cfig.rangeCount = (char)(cfig.rangeCount + 1);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||
char logBuff[512];
|
||||
const char *pStrContent;
|
||||
OBJ_DHCP_RNG pRange;
|
||||
OBJ_DHCP_RNG range;
|
||||
char *fp;
|
||||
cJSON *pRspRoot;
|
||||
cJSON *pExpandArray;
|
||||
|
||||
ERR_PARAM = ERR_SUCCESS;
|
||||
dzlog_debug("Input: %s\n", pRequest);
|
||||
|
||||
if (pRequest == nullptr || strlen(pRequest) == 0) {
|
||||
|
@ -305,6 +331,7 @@ static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
cJSON_AddItemToObject(pRspRoot, "rangeSet", pExpandArray);
|
||||
|
||||
for (int i = 0; i < cJSON_GetArraySize(prange_set); i++) {
|
||||
int ret;
|
||||
cJSON *pItem = cJSON_GetArrayItem(prange_set, i);
|
||||
cJSON *pdhcp_range = cJSON_GetObjectItem(pItem, "dhcpRange");
|
||||
cJSON *pEx_range = cJSON_CreateObject();
|
||||
|
@ -320,54 +347,34 @@ static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
cJSON *pgateway = cJSON_GetObjectItem(pItem, "gateway");
|
||||
cJSON *please_time = cJSON_GetObjectItem(pItem, "leaseTime");
|
||||
|
||||
memset(&pRange, 0, sizeof(OBJ_DHCP_RNG));
|
||||
memset(&range, 0, sizeof(OBJ_DHCP_RNG));
|
||||
|
||||
strcpy(pRange.rangAddr, pdhcp_range->valuestring);
|
||||
strcpy(range.rangAddr, pdhcp_range->valuestring);
|
||||
if (psubnet_mask) {
|
||||
strcpy(pRange.subnet, psubnet_mask->valuestring);
|
||||
strcpy(range.subnet, psubnet_mask->valuestring);
|
||||
}
|
||||
|
||||
if (pdomain_server) {
|
||||
strcpy(pRange.dnsSvr, pdomain_server->valuestring);
|
||||
strcpy(range.dnsSvr, pdomain_server->valuestring);
|
||||
}
|
||||
|
||||
if (pgateway) {
|
||||
strcpy(pRange.gateway, pgateway->valuestring);
|
||||
strcpy(range.gateway, pgateway->valuestring);
|
||||
}
|
||||
|
||||
if (please_time) {
|
||||
pRange.lease = please_time->valueint;
|
||||
range.lease = please_time->valueint;
|
||||
}
|
||||
|
||||
//写入cfig
|
||||
MYBYTE m = cfig.rangeCount;
|
||||
data20 optionData {};
|
||||
optionData.rangeSetInd = m;
|
||||
|
||||
MYBYTE *options = nullptr;
|
||||
cfig.rangeSet[optionData.rangeSetInd].active = true;
|
||||
|
||||
add_options(pRange, &optionData);
|
||||
if(ERR_PARAM != ERR_SUCCESS){
|
||||
cJSON_AddNumberToObject(pEx_range, "status", ERR_PARAM);
|
||||
cJSON_AddStringToObject(pEx_range, "message", getErrorEnumDesc(ERR_PARAM));
|
||||
ret = dhcp_add_rangeset_to_options(&range);
|
||||
if (ret != ERR_SUCCESS) {
|
||||
cJSON_AddNumberToObject(pEx_range, "status", ret);
|
||||
cJSON_AddStringToObject(pEx_range, "message", getErrorEnumDesc(ret));
|
||||
cJSON_AddItemToArray(pExpandArray, pEx_range);
|
||||
break;
|
||||
}
|
||||
|
||||
if (optionData.optionSize > 3) {
|
||||
options = (MYBYTE *)calloc(1, optionData.optionSize);
|
||||
memcpy(options, optionData.options, optionData.optionSize);
|
||||
}
|
||||
|
||||
cfig.dhcpRanges[m].rangeSetInd = optionData.rangeSetInd;
|
||||
cfig.dhcpRanges[m].options = options;
|
||||
cfig.dhcpRanges[m].mask = optionData.mask;
|
||||
if (!cfig.dhcpRanges[m].mask) {
|
||||
cfig.dhcpRanges[m].mask = cfig.mask;
|
||||
}
|
||||
cfig.rangeCount = (char)(m + 1);
|
||||
|
||||
cJSON_AddNumberToObject(pEx_range, "status", ERR_SUCCESS);
|
||||
cJSON_AddStringToObject(pEx_range, "message", getErrorEnumDesc(ERR_SUCCESS));
|
||||
cJSON_AddItemToArray(pExpandArray, pEx_range);
|
||||
|
@ -385,7 +392,7 @@ static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static int delete_dhcpd_rangeset(data19 *req, const char *pRequest){
|
||||
static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||
char logBuff[512];
|
||||
const char *pStrContent;
|
||||
char *fp;
|
||||
|
@ -430,13 +437,13 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest){
|
|||
pdelArray = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRspRoot, "rangeSet", pdelArray);
|
||||
|
||||
for(int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++){
|
||||
for (int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++) {
|
||||
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
|
||||
cJSON *pdel_Item = cJSON_CreateObject();
|
||||
char del_range[256];
|
||||
bool deleted_flag = false;
|
||||
|
||||
if(!pdelRange){
|
||||
if (!pdelRange) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -451,36 +458,36 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest){
|
|||
en_addr = htonl(inet_addr(end));
|
||||
|
||||
cJSON_AddStringToObject(pdel_Item, "dhcpRange", pdelRange->valuestring);
|
||||
if(st_addr && en_addr && st_addr <= en_addr){
|
||||
if (st_addr && en_addr && st_addr <= en_addr) {
|
||||
MYBYTE m = 0;
|
||||
|
||||
for (; m < cfig.rangeCount && cfig.dhcpRanges[m].rangeStart; m++) {
|
||||
if(!deleted_flag){
|
||||
if((st_addr == cfig.dhcpRanges[m].rangeStart) && (en_addr == cfig.dhcpRanges[m].rangeEnd)){
|
||||
if (!deleted_flag) {
|
||||
if ((st_addr == cfig.dhcpRanges[m].rangeStart) && (en_addr == cfig.dhcpRanges[m].rangeEnd)) {
|
||||
deleted_flag = true;
|
||||
if(m == cfig.rangeCount-1){
|
||||
if (m == cfig.rangeCount - 1) {
|
||||
memset(&cfig.dhcpRanges[m], 0, sizeof(struct data19));
|
||||
}
|
||||
continue;
|
||||
}else if(st_addr == cfig.dhcpRanges[m].rangeStart||en_addr == cfig.dhcpRanges[m].rangeEnd){
|
||||
} else if (st_addr == cfig.dhcpRanges[m].rangeStart || en_addr == cfig.dhcpRanges[m].rangeEnd) {
|
||||
deleted_flag = false;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
cfig.dhcpRanges[m].rangeSetInd = m-1;
|
||||
memcpy(&(cfig.dhcpRanges[m-1]), &(cfig.dhcpRanges[m]), sizeof(struct data19));
|
||||
memcpy(&(cfig.dhcpRanges[m - 1]), &(cfig.dhcpRanges[m]), sizeof(struct data19));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
cJSON_AddNumberToObject(pdel_Item, "status", ERR_INPUT_PARAMS);
|
||||
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS));
|
||||
cJSON_AddItemToArray(pdelArray, pdel_Item);
|
||||
break;
|
||||
}
|
||||
|
||||
if(deleted_flag){
|
||||
if (deleted_flag) {
|
||||
cfig.rangeCount--;
|
||||
}else{
|
||||
} else {
|
||||
cJSON_AddNumberToObject(pdel_Item, "status", ERR_INPUT_PARAMS);
|
||||
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS));
|
||||
cJSON_AddItemToArray(pdelArray, pdel_Item);
|
||||
|
@ -497,7 +504,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest){
|
|||
|
||||
cJSON_Delete(pRoot);
|
||||
req->bytes = (int)(fp - req->dp);
|
||||
free((void*)pStrPro);
|
||||
free((void *)pStrPro);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
@ -1020,3 +1027,32 @@ void opendhcp_init_http_server() {
|
|||
added = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加 DHCP 主、从服务器配置
|
||||
*/
|
||||
void opendhcp_set_replication_svr() {
|
||||
vector replication = config_get_dhcp_replication_svr();
|
||||
|
||||
if (replication && vect_size(replication) == 2) {
|
||||
cfig.zoneServers[0] = inet_addr((const char *)vect_get_at(replication, 0));
|
||||
cfig.zoneServers[1] = inet_addr((const char *)vect_get_at(replication, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加配置文件中的 DHCP 地址池池配置到服务中
|
||||
*/
|
||||
void opendhcp_add_ip_pool_set() {
|
||||
vector pool = config_get_dhcp_server_range_set();
|
||||
|
||||
for (int i = 0; (pool && i < vect_size(pool)); i++) {
|
||||
auto pRange = (POBJ_DHCP_RNG)vect_get_at(pool, i);
|
||||
|
||||
if (pRange) {
|
||||
if (dhcp_add_rangeset_to_options(pRange) != ERR_SUCCESS) {
|
||||
dzlog_error("Add rangeset(\"%s\") failed!", pRange->rangAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue