db: accept TCP IP-only addresses while preserving stored projections
This commit is contained in:
1 parent
2c7c3c9e8b
commit
d2a8e6fda7
2 files changed
+56
-2
No files matched your search
@@ -250,12 +250,38 @@ int topo_node_sqlite_init(sqlite3* db) {
|
||||
/* Проекция адресов производная. Старый формат пересоздаём, не интерпретируя NAT_TYPE_* как новый профиль. */
|
||||
sqlite3_stmt *schema = NULL;
|
||||
int legacy_profile = 0;
|
||||
if (sqlite3_prepare_v2(db, "SELECT 1 FROM sqlite_master WHERE type='table' AND name='node_addresses'",
|
||||
if (sqlite3_prepare_v2(db, "SELECT sql FROM sqlite_master WHERE type='table' AND name='node_addresses'",
|
||||
-1, &schema, NULL) != SQLITE_OK) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "address schema inspection failed: %s", sqlite3_errmsg(db)); return -1;
|
||||
}
|
||||
int exists = sqlite3_step(schema) == SQLITE_ROW;
|
||||
char *zero_port_schema = NULL;
|
||||
if (exists) {
|
||||
const char *ddl = (const char *)sqlite3_column_text(schema, 0);
|
||||
const char *strict_port = ddl ? strstr(ddl, "port > 0") : NULL;
|
||||
if (strict_port) {
|
||||
zero_port_schema = sqlite3_mprintf("%.*sport >= 0%s", (int)(strict_port - ddl), ddl, strict_port + strlen("port > 0"));
|
||||
if (!zero_port_schema) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "address zero-port schema allocation failed"); sqlite3_finalize(schema); return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(schema); schema = NULL;
|
||||
if (zero_port_schema) {
|
||||
int failed = sqlite3_exec(db, "SAVEPOINT address_zero_port; ALTER TABLE node_addresses RENAME TO address_previous_ports",
|
||||
NULL, NULL, NULL) != SQLITE_OK ||
|
||||
sqlite3_exec(db, zero_port_schema, NULL, NULL, NULL) != SQLITE_OK ||
|
||||
sqlite3_exec(db, "INSERT INTO node_addresses SELECT * FROM address_previous_ports;"
|
||||
"DROP TABLE address_previous_ports; RELEASE address_zero_port", NULL, NULL, NULL) != SQLITE_OK;
|
||||
sqlite3_free(zero_port_schema);
|
||||
if (failed) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "address zero-port schema rebuild failed: %s", sqlite3_errmsg(db));
|
||||
if (sqlite3_exec(db, "ROLLBACK TO address_zero_port; RELEASE address_zero_port", NULL, NULL, NULL) != SQLITE_OK)
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "address zero-port schema rollback failed: %s", sqlite3_errmsg(db));
|
||||
return -1;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "address schema now accepts TCP IP-only port=0; stored addresses preserved");
|
||||
}
|
||||
if (exists) {
|
||||
int compatible = sqlite3_prepare_v2(db,
|
||||
"SELECT nat_mapping,nat_inbound,nat_source,address_kind FROM node_addresses LIMIT 0",
|
||||
@@ -303,7 +329,7 @@ int topo_node_sqlite_init(sqlite3* db) {
|
||||
" family INTEGER NOT NULL CHECK(family IN (4, 6)),"
|
||||
" protocol INTEGER NOT NULL DEFAULT 1,"
|
||||
" address BLOB NOT NULL,"
|
||||
" port INTEGER NOT NULL CHECK(port > 0 AND port <= 65535),"
|
||||
" port INTEGER NOT NULL CHECK(port >= 0 AND port <= 65535),"
|
||||
" rtt INTEGER,"
|
||||
" addr_type INTEGER DEFAULT 0,"
|
||||
" config_type INTEGER DEFAULT 0,"
|
||||
|
||||
Reference in new issue
Block a user