OCT 1. 重命名数据库接口相关函数

This commit is contained in:
黄昕 2023-05-12 09:26:09 +08:00
parent 312880d1ea
commit a5d99d5dba
5 changed files with 31 additions and 33 deletions

View File

@ -103,7 +103,7 @@ application:
net_filter = "vlan and udp and dst port 67";
# IP地址池配置
range_set: (
{ dhcp_range = "192.168.101.2-192.168.101.4";
{ dhcp_range = "192.168.101.2-192.168.101.40";
subnet_mask = "255.255.255.0";
domain_server = "114.114.114.114,8.8.8.8";
gateway = "192.168.101.1";

View File

@ -318,7 +318,6 @@ static gboolean upgrade_statusbar_proc(gpointer user_data) {
}
}
sprintf(buf, "Offer %d.%03ds | ACK %d.%03ds | ip: %s | netmask: %s | gateway: %s | dns1: %s | dns2: %s |",
tmOffer / 1000000, (tmOffer % 1000000) / 1000, tmAck / 1000000, (tmAck % 1000000) / 1000,
SAFETY_STR_STRING(pIp, ""), SAFETY_STR_STRING(pNetmask, ""), SAFETY_STR_STRING(pGw, ""),
@ -546,7 +545,6 @@ void details_wnd_create(GtkBuilder *builder) {
gtk_widget_set_name(notebook, "nbDhcpInfo");
for (int i = 0; i < 4; i++) {
GtkTreeIter iter;
const char *pTabName[] = {"Discover", "Offer", "Request", "ACK/NACK"};
// 第一个页面
GtkWidget *label = gtk_label_new(pTabName[i]);

View File

@ -194,7 +194,7 @@ int db_release_lease(PDHCP_REQ pReq) {
return ERR_SUCCESS;
}
int lease_lock_pre_assign_ip() {
int db_lock_pre_assign_ip() {
int rc;
char buf[1024] = {0};
char **dbResult;
@ -239,7 +239,7 @@ int lease_lock_pre_assign_ip() {
return ERR_SUCCESS;
}
int lease_clearup_timeout_items() {
int db_clearup_timeout_lease() {
int rc;
char buf[1024] = {0};
@ -263,7 +263,7 @@ int lease_clearup_timeout_items() {
return ERR_SUCCESS;
}
int lease_ip_is_pre_assign(U32 uid, U32 ip) {
int db_ip_is_pre_assign(U32 uid, U32 ip) {
int rc;
char buf[1024] = {0};
char **dbResult;
@ -312,7 +312,7 @@ int lease_ip_is_pre_assign(U32 uid, U32 ip) {
return TRUE;
}
static int lease_get_info(PPOOL_CTX pAssign, const char *pRunSql, U64 *pDbId) {
static int db_get_table_items(PPOOL_CTX pAssign, const char *pRunSql, U64 *pDbId) {
int rc;
char **dbResult;
int nRow = 0, nColumn = 0;
@ -356,7 +356,7 @@ static int lease_get_info(PPOOL_CTX pAssign, const char *pRunSql, U64 *pDbId) {
}
}
int lease_get_from_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
int db_get_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
int rc;
U64 id;
char buf[2048] = {0};
@ -365,7 +365,7 @@ int lease_get_from_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
MAC_TO_STR(pReq->cliMac, macStr);
snprintf(buf, 2048, GET_LEASE_INFO_FMT, macStr, pReq->hostName, pReq->uid, u32_to_str_ip(pReq->serverAddr));
rc = lease_get_info(pAssign, buf, &id);
rc = db_get_table_items(pAssign, buf, &id);
if (rc == ERR_SUCCESS) {
// 更新租约时间信息
memset(buf, 0, 1024);
@ -380,7 +380,7 @@ int lease_get_from_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
return -ERR_ITEM_UNEXISTS;
}
int lease_get_from_pre_assign(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
int db_get_pre_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
int rc;
char buf[2048] = {0};
char macStr[20] = {0};
@ -390,7 +390,7 @@ int lease_get_from_pre_assign(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
snprintf(buf, 2048, GET_ASSIGN_IP_INFO_FMT, macStr, pReq->hostName, pReq->uid, u32_to_str_ip(pReq->serverAddr),
DCHP_STEP_REQUEST_TIMEOUT);
rc = lease_get_info(pAssign, buf, &id);
rc = db_get_table_items(pAssign, buf, &id);
if (rc == ERR_SUCCESS) {
const char *pNetmask = u32_to_str_ip_safe(htonl(pAssign->netMask));
@ -461,7 +461,7 @@ int lease_get_from_pre_assign(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
#endif
}
int lease_get_pre_assign(U32 uid, const char *mac, const char *hostname, U32 *preAssign) {
int db_get_pre_assign(U32 uid, const char *mac, const char *hostname, U32 *preAssign) {
int rc;
char buf[1024] = {0};
char **dbResult;
@ -504,7 +504,7 @@ int lease_get_pre_assign(U32 uid, const char *mac, const char *hostname, U32 *pr
return ERR_ITEM_UNEXISTS;
}
int lease_db_add_pre_assign(PDHCP_REQ pReq, U32 ip, PPOOL_CTX pPool) {
int db_add_pre_assign(PDHCP_REQ pReq, U32 ip, PPOOL_CTX pPool) {
int rc;
char buf[1024] = {0};
char macStr[20] = {0};
@ -535,7 +535,7 @@ int lease_db_add_pre_assign(PDHCP_REQ pReq, U32 ip, PPOOL_CTX pPool) {
return ERR_SUCCESS;
}
int lease_init_database() {
int db_init_lease_database() {
int rc;
rc = db_sqlite3_sql_exec(CREATE_LEASE_TABLE(), NULL, NULL, NULL);

View File

@ -7,14 +7,14 @@
#ifdef __cplusplus
extern "C" {
#endif
int lease_db_add_pre_assign(PDHCP_REQ pReq, U32 ip, PPOOL_CTX pPool);
int lease_init_database();
int lease_get_pre_assign(U32 uid, const char *mac, const char *hostname, U32 *preAssign);
int lease_ip_is_pre_assign(U32 uid, U32 ip);
int lease_get_from_pre_assign(PDHCP_REQ pReq, PPOOL_CTX pAssign);
int lease_get_from_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign);
int lease_clearup_timeout_items();
int lease_lock_pre_assign_ip();
int db_add_pre_assign(PDHCP_REQ pReq, U32 ip, PPOOL_CTX pPool);
int db_init_lease_database();
int db_get_pre_assign(U32 uid, const char *mac, const char *hostname, U32 *preAssign);
int db_ip_is_pre_assign(U32 uid, U32 ip);
int db_get_pre_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign);
int db_get_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign);
int db_clearup_timeout_lease();
int db_lock_pre_assign_ip();
int db_release_lease(PDHCP_REQ pReq);
int db_add_lease(PDHCP_REQ pReq, PPOOL_CTX pCtx);
#ifdef __cplusplus

View File

@ -20,7 +20,7 @@ U32 lease_is_pre_assign(PDHCP_REQ pReq) {
U32 ipAddr;
MAC_TO_STR(pReq->cliMac, macStr);
if (lease_get_pre_assign(pReq->uid, macStr, pReq->hostName, &ipAddr) == ERR_ITEM_EXISTS) {
if (db_get_pre_assign(pReq->uid, macStr, pReq->hostName, &ipAddr) == ERR_ITEM_EXISTS) {
return ipAddr;
}
@ -62,11 +62,11 @@ int lease_add_host(PDHCP_REQ pReq) {
int is_pre_assigned(PDHCP_REQ pReq, PPOOL_CTX pCtx) {
// 首先从租约信息中获取数据
if (lease_get_from_lease(pReq, pCtx) == ERR_SUCCESS) {
if (db_get_lease(pReq, pCtx) == ERR_SUCCESS) {
return ERR_SUCCESS;
}
// 从预分配IP中获取信息
return lease_get_from_pre_assign(pReq, pCtx);
return db_get_pre_lease(pReq, pCtx);
}
int lease_release(PDHCP_REQ pReq) {
@ -100,12 +100,12 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX
// 该 IP 可用
if (pLock == NULL) {
if (lease_ip_is_pre_assign(pReq->uid, addr) == FALSE) {
if (db_ip_is_pre_assign(pReq->uid, addr) == FALSE) {
usr_lease_lock_ip(pUser, addr);
*pOutIp = addr;
*pOutPool = pPool;
lease_db_add_pre_assign(pReq, addr, pPool);
db_add_pre_assign(pReq, addr, pPool);
return ERR_SUCCESS;
}
@ -116,7 +116,7 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX
}
// 清理所有超时的预分配IP
lease_clearup_timeout_items();
db_clearup_timeout_lease();
// 没有可预分配的IP报错
//LOG_MOD(error, ZM_DHCP_LEASE, "No free ipaddress in poll: uid = %u, pool = %p\n", pReq->uid, pUser->pUserPool);
return -ERR_DHCP_NO_ADDR;
@ -125,16 +125,16 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX
int dhcp_lease_init() {
int rc;
rc = lease_init_database();
rc = db_init_lease_database();
if (rc != ERR_SUCCESS) {
return rc;
}
// 清理所有超时的预分配IP
lease_clearup_timeout_items();
db_clearup_timeout_lease();
// lock 预分配 IP
lease_lock_pre_assign_ip();
db_lock_pre_assign_ip();
return ERR_SUCCESS;
}