Commit 1252f233 authored by 神楽坂玲奈's avatar 神楽坂玲奈

not work

parent 7e384573
......@@ -4,6 +4,7 @@ import child_process from 'child_process';
export class RouteWriter {
static input: string[] = [];
static via: Record<number, number> = {};
static reset() {
this.input.push(`route flush table ${config.table} proto ${config.proto}`);
......@@ -16,11 +17,18 @@ export class RouteWriter {
console.log(toId, viaId);
const to = routers.find(r => r.id === toId);
const via = routers.find(r => r.id === viaId);
RouteWriter.via
for (const address of [to.address, ...to.subnets]) {
this.input.push(`route replace ${address} dev ${via.interface} table ${config.table} proto ${config.proto}`);
}
}
static plan(table: number, to: number) {
console.log(table, viaId);
const via = routers.find(r => r.id === viaId);
this.input.push(`route replace default dev ${via.interface} table ${table} proto ${config.proto}`);
}
static commit() {
// 可能改成异步的会更好点
child_process.execFileSync('ip', ['-batch', '-'], { input: this.input.join('\n') });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment