Merge branch 'v1.2.0_dev' of http://git.komect.net/ZNJK/vcpe into v1.2.0_dev

This commit is contained in:
dongwenze 2023-03-16 10:08:29 +08:00
commit 65cb52e156
3 changed files with 119 additions and 95 deletions

View File

@ -1904,18 +1904,33 @@ MYDWORD sdmess(data9 *req) {
req->dhcpp.header.bp_op = BOOTP_REPLY;
errno = 0;
#if DISCOVER_RSP_NOT_BOARDCAST
sockaddr_in cliAddr = get_cliAddr(nicif, tempbuff, req);
#endif
if (req->req_type == DHCP_MESS_DISCOVER && !req->remote.sin_addr.s_addr) {
req->bytes = (int)sendto(network.dhcpConn[req->sockInd].sock,
req->raw,
packSize,
MSG_DONTROUTE,
#if DISCOVER_RSP_NOT_BOARDCAST
(sockaddr *)&cliAddr,
sizeof(cliAddr));
#else
(sockaddr *)&req->remote,
sizeof(req->remote));
#endif
} else {
req->bytes = (int)
sendto(network.dhcpConn[req->sockInd].sock, req->raw, packSize, 0, (sockaddr *)&cliAddr, sizeof(cliAddr));
req->bytes = (int)sendto(network.dhcpConn[req->sockInd].sock,
req->raw,
packSize,
0,
#if DISCOVER_RSP_NOT_BOARDCAST
(sockaddr *)&cliAddr,
sizeof(cliAddr));
#else
(sockaddr *)&req->remote,
sizeof(req->remote));
#endif
}
if (errno || req->bytes <= 0) {

View File

@ -39,7 +39,7 @@
#endif
#ifndef SIOCGIFCONF
#include <sys/sockio.h>
#include <sys/ioctl.h>
#endif
#ifndef _UIO_H_
@ -84,6 +84,8 @@ typedef struct in_pktinfo IN_PKTINFO;
#define STR2INT(val) ((int)strtol((val), nullptr, 10))
#define DISCOVER_RSP_NOT_BOARDCAST (0)
#define logDHCPMess(logBuff, logLevel) \
do { \
switch ((logLevel)) { \
@ -775,5 +777,7 @@ int opendhcp_add_listener();
unsigned int opendhcp_set_lease_time();
int getHwAddr(char *buff, char *mac);
int arpSet(const char *ifname, char *ipStr, char *mac);
#if DISCOVER_RSP_NOT_BOARDCAST
sockaddr_in get_cliAddr(char *nicif, char *tempbuff, data9 *req);
#endif
#pragma clang diagnostic pop

View File

@ -5,18 +5,14 @@
#include <map>
using namespace std;
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <memory.h>
#include <cstdlib>
#include "opendhcpd.h"
#include "s2j/cJSON.h"
#include "misc.h"
#include <net/if_arp.h>
#include <uv.h>
#include "config.h"
#include "proto.h"
@ -27,6 +23,12 @@ using namespace std;
#include "http_svr.h"
#include "task_manager.h"
#if DISCOVER_RSP_NOT_BOARDCAST
#include <sys/socket.h>
#include <unistd.h>
#include <net/if_arp.h>
#endif
extern data2 cfig;
extern bool kRunning;
extern dhcpMap dhcpCache;
@ -45,11 +47,12 @@ static PIPTV_DEV_SET g_iptvCacheDevs = nullptr;
static uv_rwlock_t g_uvCacheLock;
#ifdef JSON_SCHEMA_ON
// clang-format off
const char *g_json_msg[] = {
"{\"type\":\"object\",\"required\":[\"rangeSet\"],\"properties\":{\"rangeSet\":{\"type\":\"array\",\"minItems\":1,\"items\":{\"type\":\"object\",\"required\":[\"dhcpRange\"]}}}}",
"{\"type\":\"object\",\"required\":[\"dhcpRange\"],\"properties\":{\"dhcpRange\":{\"type\":\"array\",\"minItems\":1}}}",
"{\"type\":\"object\",\"required\":[\"userMac\"],\"properties\":{\"userMac\":{\"type\":\"array\",\"minItems\":1}}}"
};
R"({"type":"object","required":["rangeSet"],"properties":{"rangeSet":{"type":"array","minItems":1,"items":{"type":"object","required":["dhcpRange"]}}}})",
R"({"type":"object","required":["dhcpRange"],"properties":{"dhcpRange":{"type":"array","minItems":1}}})",
R"({"type":"object","required":["userMac"],"properties":{"userMac":{"type":"array","minItems":1}}})"};
// clang-format on
#endif
static int dhcp_get_user_info(const char **pRsp, const char *pRequest) {
@ -706,6 +709,7 @@ int getHwAddr(char *buff, char *mac) {
#pragma clang diagnostic pop
#if DISCOVER_RSP_NOT_BOARDCAST
int arpSet(const char *ifname, char *ipStr, char *mac) {
if (ifname == nullptr || ipStr == nullptr || mac == nullptr) {
LOG_MOD(error, ZLOG_MOD_OPENDHCPD, "para is null.\n");
@ -755,6 +759,7 @@ sockaddr_in get_cliAddr(char *nicif, char *tempbuff, data9 *req) {
cliAddr.sin_addr.s_addr = inet_addr(IP2String(tempbuff, req->dhcpp.header.bp_yiaddr));
return cliAddr;
}
#endif
unsigned int opendhcp_set_lease_time() {
return config_get_dhcp_server_lease_time();