43 lines
1.4 KiB
C
43 lines
1.4 KiB
C
//
|
|
// Created by xajhuang on 2023/3/23.
|
|
//
|
|
|
|
#include "lease.h"
|
|
#include "user_errno.h"
|
|
#include "zlog_module.h"
|
|
#include "database.h"
|
|
|
|
#define LEASE_DB_NAME ("lease")
|
|
|
|
static PMAC_FILTER g_allowTbl = NULL;
|
|
static PMAC_FILTER g_blackListTbl = NULL;
|
|
|
|
#define CREATE_LEASE_TABLE(name) \
|
|
"CREATE TABLE IF NOT EXISTS " #name \
|
|
" ( id INTEGER PRIMARY KEY AUTOINCREMENT," \
|
|
" uid INTEGER NOT NULL," \
|
|
" mac CHAR(20) NOT NULL," \
|
|
" ip INTEGER NOT NULL," \
|
|
" lease INTEGER NOT NULL," \
|
|
" create INTEGER NOT NULL," \
|
|
" netmask INTEGER," \
|
|
" gateway INTEGER," \
|
|
" dns1 INTEGER," \
|
|
" dns2 INTEGER," \
|
|
" server INTEGER NOT NULL," \
|
|
" hostname CHAR(64) DEFAULT '' NOT NULL," \
|
|
" keyType INTEGER NOT NULL" \
|
|
");" \
|
|
"CREATE INDEX IF NOT EXISTS " #name "_index ON " #name " (uid, mac);"
|
|
|
|
int dhcp_lease_init() {
|
|
int rc = 0;
|
|
|
|
rc = db_sqlite3_sql_exec(CREATE_LEASE_TABLE(lease), NULL, NULL, NULL);
|
|
|
|
if (rc != ERR_SUCCESS) {
|
|
return rc;
|
|
}
|
|
|
|
return ERR_SUCCESS;
|
|
} |