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 NIC_INFO g_nicInfo;
|
||||||
static uv_udp_t g_uvRawSockReq;
|
static uv_udp_t g_uvRawSockReq;
|
||||||
|
|
||||||
U32 pkg_mmap_tx(U8 *pData, U32 nBytes) {
|
void *get_pkg_memory() {
|
||||||
int i;
|
int i;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
struct tpacket3_hdr *hdr;
|
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;
|
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))) {
|
||||||
U8 *p = (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll);
|
return (U8 *)hdr + TPACKET3_HDRLEN - sizeof(struct sockaddr_ll);
|
||||||
memcpy(p, pData, nBytes);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_next_offset = 0;
|
||||||
hdr->tp_len = nBytes;
|
hdr->tp_len = nBytes;
|
||||||
hdr->tp_snaplen = nBytes;
|
hdr->tp_snaplen = nBytes;
|
||||||
hdr->tp_status = TP_STATUS_SEND_REQUEST;
|
hdr->tp_status = TP_STATUS_SEND_REQUEST;
|
||||||
return hdr->tp_len;
|
return hdr->tp_len;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) {
|
static int dhcp_resp_offer(PDHCP_PACKAGE pReq, PIPPOOL_INFO pIpInfo, U32 ip) {
|
||||||
|
U8 *pOpt;
|
||||||
U16 csum;
|
U16 csum;
|
||||||
int tolSize;
|
int tolSize;
|
||||||
PDHCP_PACKAGE pRsp = (PDHCP_PACKAGE)malloc(MAX_DHCP_PKG_SIZE);
|
PDHCP_PACKAGE pRsp = get_pkg_memory();
|
||||||
U8 *pOpt = pRsp->dhcp.options;
|
|
||||||
|
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
LOG_MOD(error, ZLOG_MOD_DHCPD, "Malloc memory error: %u\n", MAX_DHCP_PKG_SIZE);
|
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;
|
pRsp->dhcp.giaddr = 0;
|
||||||
|
|
||||||
// DHCP Options
|
// DHCP Options
|
||||||
|
pOpt = pRsp->dhcp.options;
|
||||||
|
|
||||||
// DHCP 消息类型
|
// DHCP 消息类型
|
||||||
pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_OFFER);
|
pOpt += dhcp_add_u8_option(pOpt, OPT_MESSAGETYPE, DHCP_MSG_OFFER);
|
||||||
// 子网掩码
|
// 子网掩码
|
||||||
|
|
Loading…
Reference in New Issue