OCT 1. 优化dhcp协议回包内存分配
This commit is contained in:
parent
ba11669324
commit
c9b4bb1105
|
@ -227,7 +227,7 @@ static PACKET_MMAP_RING g_pkgRing;
|
|||
static NIC_INFO g_nicInfo;
|
||||
static uv_udp_t g_uvRawSockReq;
|
||||
|
||||
U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
|
||||
void *get_pkg_memory() {
|
||||
int i;
|
||||
ssize_t ret;
|
||||
struct tpacket3_hdr *hdr;
|
||||
|
@ -237,24 +237,28 @@ U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
|
|||
g_pkgRing.index = (g_pkgRing.index + 1) % g_pkgRing.send.tp_frame_nr;
|
||||
|
||||
if (!(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING))) {
|
||||
U8 *p = (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll);
|
||||
memcpy(p, pData, nBytes);
|
||||
return (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
|
||||
struct tpacket3_hdr *hdr = (struct tpacket3_hdr *)(pData + sizeof(struct sockaddr_ll) - TPACKET3_HDRLEN);
|
||||
|
||||
hdr->tp_next_offset = 0;
|
||||
hdr->tp_len = nBytes;
|
||||
hdr->tp_snaplen = nBytes;
|
||||
hdr->tp_status = TP_STATUS_SEND_REQUEST;
|
||||
return hdr->tp_len;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) {
|
||||
U8 *pOpt;
|
||||
U16 csum;
|
||||
int tolSize;
|
||||
PDHCP_PACKAGE pRsp = (PDHCP_PACKAGE)malloc(MAX_DHCP_PKG_SIZE);
|
||||
U8 *pOpt = pRsp->dhcp.options;
|
||||
PDHCP_PACKAGE pRsp = get_pkg_memory();
|
||||
|
||||
if (pRsp == NULL) {
|
||||
LOG_MOD(error, ZLOG_MOD_DHCPD, "Malloc memory error: %u\n", MAX_DHCP_PKG_SIZE);
|
||||
|
@ -319,6 +323,8 @@ static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) {
|
|||
pRsp->dhcp.giaddr = 0;
|
||||
|
||||
// DHCP Options
|
||||
pOpt = pRsp->dhcp.options;
|
||||
|
||||
// DHCP 消息类型
|
||||
pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_OFFER);
|
||||
// 子网掩码
|
||||
|
|
Loading…
Reference in New Issue