From 664ba3505f977aaca7f6c4f2b188f17f91640008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=98=95?= Date: Mon, 15 May 2023 17:37:53 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E6=9B=B4=E6=96=B0=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=A2=84=E5=88=86=E9=85=8DIP=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=97=B6=EF=BC=8C=E4=B8=8D=E5=90=8CMAC=E5=88=86?= =?UTF-8?q?=E9=85=8D=E5=90=8C=E4=B8=80=E4=B8=AAIP=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/service/dhcpd/lease.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/srcs/service/dhcpd/lease.c b/srcs/service/dhcpd/lease.c index 84c95e0..1aef42a 100644 --- a/srcs/service/dhcpd/lease.c +++ b/srcs/service/dhcpd/lease.c @@ -15,6 +15,8 @@ //static PMAC_FILTER g_blackListTbl = NULL; //static PPRE_ALLOC_IP g_pPreAllocIp = NULL; +static uv_mutex_t g_uvLock; + U32 lease_is_pre_assign(PDHCP_REQ pReq) { char macStr[20] = {0}; U32 ipAddr; @@ -84,7 +86,6 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX LL_FOREACH_SAFE(pUser->pUserPool, pPool, pTemp) { U32 addr; - // 查看是否预分配过该设备 if ((addr = lease_is_pre_assign(pReq)) != 0) { *pOutIp = addr; @@ -92,6 +93,7 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX return ERR_SUCCESS; } + uv_mutex_lock(&g_uvLock); addr = pPool->minAddr; do { PLOCK_IP pLock; @@ -103,12 +105,13 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX *pOutIp = addr; *pOutPool = pPool; db_add_pre_assign(pReq, addr, pPool); + uv_mutex_unlock(&g_uvLock); return ERR_SUCCESS; } } - addr++; } while (addr <= pPool->maxAddr); + uv_mutex_unlock(&g_uvLock); } // 清理所有超时的预分配IP @@ -121,6 +124,8 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX int dhcp_lease_init() { int rc; + uv_mutex_init(&g_uvLock); + rc = db_init_lease_database(); if (rc != ERR_SUCCESS) {