OCT 1. 重命名数据库接口相关函数
This commit is contained in:
parent
312880d1ea
commit
a5d99d5dba
|
@ -103,7 +103,7 @@ application:
|
||||||
net_filter = "vlan and udp and dst port 67";
|
net_filter = "vlan and udp and dst port 67";
|
||||||
# IP地址池配置
|
# IP地址池配置
|
||||||
range_set: (
|
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";
|
subnet_mask = "255.255.255.0";
|
||||||
domain_server = "114.114.114.114,8.8.8.8";
|
domain_server = "114.114.114.114,8.8.8.8";
|
||||||
gateway = "192.168.101.1";
|
gateway = "192.168.101.1";
|
||||||
|
|
|
@ -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 |",
|
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,
|
tmOffer / 1000000, (tmOffer % 1000000) / 1000, tmAck / 1000000, (tmAck % 1000000) / 1000,
|
||||||
SAFETY_STR_STRING(pIp, ""), SAFETY_STR_STRING(pNetmask, ""), SAFETY_STR_STRING(pGw, ""),
|
SAFETY_STR_STRING(pIp, ""), SAFETY_STR_STRING(pNetmask, ""), SAFETY_STR_STRING(pGw, ""),
|
||||||
|
@ -465,8 +464,8 @@ static gboolean button_release_event(GtkWidget *self, GdkEventButton UNUSED(even
|
||||||
|
|
||||||
//printf("Select at(%d, %d), %d, %d, %d of %d\n", row, col, k, (k + 1) / 3, id, g_curPage);
|
//printf("Select at(%d, %d), %d, %d, %d of %d\n", row, col, k, (k + 1) / 3, id, g_curPage);
|
||||||
memcpy(valBuf, &g_HexBuf[g_curPage]->p[id], MIN(8, g_HexBuf[g_curPage]->buf_size - id));
|
memcpy(valBuf, &g_HexBuf[g_curPage]->p[id], MIN(8, g_HexBuf[g_curPage]->buf_size - id));
|
||||||
// printf("%d, %d, %s, %s\n", valBuf[0] >> 4, valBuf[0] & 0x0F, binTbl[(valBuf[0] >> 4) & 0xF],
|
// printf("%d, %d, %s, %s\n", valBuf[0] >> 4, valBuf[0] & 0x0F, binTbl[(valBuf[0] >> 4) & 0xF],
|
||||||
// binTbl[valBuf[0] & 0x0F]);
|
// binTbl[valBuf[0] & 0x0F]);
|
||||||
|
|
||||||
sprintf(s, "%s%s", binTbl[(valBuf[0] >> 4) & 0xF], binTbl[valBuf[0] & 0x0F]);
|
sprintf(s, "%s%s", binTbl[(valBuf[0] >> 4) & 0xF], binTbl[valBuf[0] & 0x0F]);
|
||||||
gtk_list_store_append(store, &it);
|
gtk_list_store_append(store, &it);
|
||||||
|
@ -546,7 +545,6 @@ void details_wnd_create(GtkBuilder *builder) {
|
||||||
gtk_widget_set_name(notebook, "nbDhcpInfo");
|
gtk_widget_set_name(notebook, "nbDhcpInfo");
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
GtkTreeIter iter;
|
|
||||||
const char *pTabName[] = {"Discover", "Offer", "Request", "ACK/NACK"};
|
const char *pTabName[] = {"Discover", "Offer", "Request", "ACK/NACK"};
|
||||||
// 第一个页面
|
// 第一个页面
|
||||||
GtkWidget *label = gtk_label_new(pTabName[i]);
|
GtkWidget *label = gtk_label_new(pTabName[i]);
|
||||||
|
|
|
@ -194,7 +194,7 @@ int db_release_lease(PDHCP_REQ pReq) {
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lease_lock_pre_assign_ip() {
|
int db_lock_pre_assign_ip() {
|
||||||
int rc;
|
int rc;
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
char **dbResult;
|
char **dbResult;
|
||||||
|
@ -239,7 +239,7 @@ int lease_lock_pre_assign_ip() {
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lease_clearup_timeout_items() {
|
int db_clearup_timeout_lease() {
|
||||||
int rc;
|
int rc;
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ int lease_clearup_timeout_items() {
|
||||||
return ERR_SUCCESS;
|
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;
|
int rc;
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
char **dbResult;
|
char **dbResult;
|
||||||
|
@ -312,7 +312,7 @@ int lease_ip_is_pre_assign(U32 uid, U32 ip) {
|
||||||
return TRUE;
|
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;
|
int rc;
|
||||||
char **dbResult;
|
char **dbResult;
|
||||||
int nRow = 0, nColumn = 0;
|
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;
|
int rc;
|
||||||
U64 id;
|
U64 id;
|
||||||
char buf[2048] = {0};
|
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);
|
MAC_TO_STR(pReq->cliMac, macStr);
|
||||||
snprintf(buf, 2048, GET_LEASE_INFO_FMT, macStr, pReq->hostName, pReq->uid, u32_to_str_ip(pReq->serverAddr));
|
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) {
|
if (rc == ERR_SUCCESS) {
|
||||||
// 更新租约时间信息
|
// 更新租约时间信息
|
||||||
memset(buf, 0, 1024);
|
memset(buf, 0, 1024);
|
||||||
|
@ -380,7 +380,7 @@ int lease_get_from_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign) {
|
||||||
return -ERR_ITEM_UNEXISTS;
|
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;
|
int rc;
|
||||||
char buf[2048] = {0};
|
char buf[2048] = {0};
|
||||||
char macStr[20] = {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),
|
snprintf(buf, 2048, GET_ASSIGN_IP_INFO_FMT, macStr, pReq->hostName, pReq->uid, u32_to_str_ip(pReq->serverAddr),
|
||||||
DCHP_STEP_REQUEST_TIMEOUT);
|
DCHP_STEP_REQUEST_TIMEOUT);
|
||||||
|
|
||||||
rc = lease_get_info(pAssign, buf, &id);
|
rc = db_get_table_items(pAssign, buf, &id);
|
||||||
|
|
||||||
if (rc == ERR_SUCCESS) {
|
if (rc == ERR_SUCCESS) {
|
||||||
const char *pNetmask = u32_to_str_ip_safe(htonl(pAssign->netMask));
|
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
|
#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;
|
int rc;
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
char **dbResult;
|
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;
|
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;
|
int rc;
|
||||||
char buf[1024] = {0};
|
char buf[1024] = {0};
|
||||||
char macStr[20] = {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;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lease_init_database() {
|
int db_init_lease_database() {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = db_sqlite3_sql_exec(CREATE_LEASE_TABLE(), NULL, NULL, NULL);
|
rc = db_sqlite3_sql_exec(CREATE_LEASE_TABLE(), NULL, NULL, NULL);
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
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 lease_init_database();
|
int db_init_lease_database();
|
||||||
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 lease_ip_is_pre_assign(U32 uid, U32 ip);
|
int db_ip_is_pre_assign(U32 uid, U32 ip);
|
||||||
int lease_get_from_pre_assign(PDHCP_REQ pReq, PPOOL_CTX pAssign);
|
int db_get_pre_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign);
|
||||||
int lease_get_from_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign);
|
int db_get_lease(PDHCP_REQ pReq, PPOOL_CTX pAssign);
|
||||||
int lease_clearup_timeout_items();
|
int db_clearup_timeout_lease();
|
||||||
int lease_lock_pre_assign_ip();
|
int db_lock_pre_assign_ip();
|
||||||
int db_release_lease(PDHCP_REQ pReq);
|
int db_release_lease(PDHCP_REQ pReq);
|
||||||
int db_add_lease(PDHCP_REQ pReq, PPOOL_CTX pCtx);
|
int db_add_lease(PDHCP_REQ pReq, PPOOL_CTX pCtx);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -20,7 +20,7 @@ U32 lease_is_pre_assign(PDHCP_REQ pReq) {
|
||||||
U32 ipAddr;
|
U32 ipAddr;
|
||||||
|
|
||||||
MAC_TO_STR(pReq->cliMac, macStr);
|
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;
|
return ipAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ int lease_add_host(PDHCP_REQ pReq) {
|
||||||
|
|
||||||
int is_pre_assigned(PDHCP_REQ pReq, PPOOL_CTX pCtx) {
|
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;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
// 从预分配IP中获取信息
|
// 从预分配IP中获取信息
|
||||||
return lease_get_from_pre_assign(pReq, pCtx);
|
return db_get_pre_lease(pReq, pCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lease_release(PDHCP_REQ pReq) {
|
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 可用
|
// 该 IP 可用
|
||||||
if (pLock == NULL) {
|
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);
|
usr_lease_lock_ip(pUser, addr);
|
||||||
*pOutIp = addr;
|
*pOutIp = addr;
|
||||||
*pOutPool = pPool;
|
*pOutPool = pPool;
|
||||||
|
|
||||||
lease_db_add_pre_assign(pReq, addr, pPool);
|
db_add_pre_assign(pReq, addr, pPool);
|
||||||
|
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ int pre_alloc_dhcp_res(PDHCP_REQ pReq, PDHCP_USER pUser, U32 *pOutIp, PPOOL_CTX
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理所有超时的预分配IP
|
// 清理所有超时的预分配IP
|
||||||
lease_clearup_timeout_items();
|
db_clearup_timeout_lease();
|
||||||
// 没有可预分配的IP,报错
|
// 没有可预分配的IP,报错
|
||||||
//LOG_MOD(error, ZM_DHCP_LEASE, "No free ipaddress in poll: uid = %u, pool = %p\n", pReq->uid, pUser->pUserPool);
|
//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;
|
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 dhcp_lease_init() {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = lease_init_database();
|
rc = db_init_lease_database();
|
||||||
|
|
||||||
if (rc != ERR_SUCCESS) {
|
if (rc != ERR_SUCCESS) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理所有超时的预分配IP
|
// 清理所有超时的预分配IP
|
||||||
lease_clearup_timeout_items();
|
db_clearup_timeout_lease();
|
||||||
|
|
||||||
// lock 预分配 IP
|
// lock 预分配 IP
|
||||||
lease_lock_pre_assign_ip();
|
db_lock_pre_assign_ip();
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
Loading…
Reference in New Issue