Gateways sharing an address are one gateway
Found by asking what gw-devices and gw-home actually were, in a picture that
finally made them easy to see side by side.
planRouters grouped on the exact address list, so `home` declaring a v4 and a v6
address and `devices` declaring only the v4 became two router containers — both
holding 198.51.100.7 on the same segment. The lab raised it without complaint.
Not theoretical. On the raised instance the transit router resolved that one
address to two different MACs across a cache flush:
198.51.100.7 -> 02:c9:16:70:23:29 (gw0, which HAS the :443 dnat)
198.51.100.7 -> 02:bd:75:0b:b0:75 (gw1, which has none)
So home-server's published port worked or did not depending on which container
answered ARP last — intermittent, and it would have presented as a flaky test
rather than as a broken scenario.
One public address is one box. Checked against the thing this models rather than
argued from the model: a bridged modem, a single gateway holding the public
address, one network behind it, and every port forward landing on one host at
that address. Two routers on one address is not a topology, it is a collision.
Gateways to the same segment sharing any address are now one router and their
address lists union, so a v6 address declared on only one of the segments it
serves is still carried. Where such declarations disagree on nat, forwardable or
mapping_ttl, validate refuses — one box cannot behave two ways.
the-ordinary-shape now raises 7 machines instead of 8, and gw0 holds the public
address on eth0 while serving home on eth1 and devices on eth2.
This commit is contained in:
@@ -2,6 +2,7 @@ import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { parseScenario } from "../src/declaration/parse.ts";
|
||||
import { loadScenario } from "../src/declaration/parse.ts";
|
||||
import { planRouters } from "../src/lifecycle/router.ts";
|
||||
|
||||
/** Every rejection below is a fault that would otherwise be silent at runtime. */
|
||||
function refuses(yaml: string, pattern: RegExp): void {
|
||||
@@ -185,3 +186,60 @@ segments: { island: { kind: private, cidr: [10.9.0.0/24] } }
|
||||
machines: { a: { at: { segment: island, address: [10.9.0.1] } } }`),
|
||||
);
|
||||
});
|
||||
|
||||
test("two gateways sharing an address are one gateway, not two", () => {
|
||||
// Modelled on the real thing: a bridged modem, one gateway holding the public address,
|
||||
// everything behind it. Two routers on one address is not a topology, it is a collision —
|
||||
// and the lab raised it happily, with the address resolving to whichever container
|
||||
// answered ARP last.
|
||||
const scenario = parseScenario(`
|
||||
scenario: shared-gateway
|
||||
segments:
|
||||
isp:
|
||||
kind: public
|
||||
cidr: [198.51.100.0/24, "2001:db8:b::/48"]
|
||||
home:
|
||||
kind: private
|
||||
cidr: [192.168.1.0/24]
|
||||
gateway: { to: isp, address: [198.51.100.7, "2001:db8:b::7"], nat: [v4], forwardable: true, mapping_ttl: 120s }
|
||||
devices:
|
||||
kind: private
|
||||
cidr: [192.168.30.0/24]
|
||||
gateway: { to: isp, address: [198.51.100.7], nat: [v4], forwardable: true, mapping_ttl: 120s }
|
||||
machines:
|
||||
thermostat:
|
||||
at: { segment: devices, address: [192.168.30.20] }
|
||||
`);
|
||||
const plans = planRouters(scenario, "test");
|
||||
assert.equal(plans.length, 1, `expected one gateway, got ${plans.map((p) => p.inside.join("+")).join(" / ")}`);
|
||||
assert.deepEqual([...plans[0]!.inside].sort(), ["devices", "home"]);
|
||||
// The union: a v6 address declared on only one of the segments it serves is still carried.
|
||||
assert.deepEqual([...plans[0]!.outsideAddresses].sort(), ["198.51.100.7", "2001:db8:b::7"]);
|
||||
});
|
||||
|
||||
test("one box cannot behave two ways", () => {
|
||||
// If two gateways share an address they are the same box, so a disagreement about what
|
||||
// that box does is a contradiction — refused rather than silently resolved one way.
|
||||
assert.throws(
|
||||
() =>
|
||||
parseScenario(`
|
||||
scenario: contradictory-gateway
|
||||
segments:
|
||||
isp:
|
||||
kind: public
|
||||
cidr: [198.51.100.0/24]
|
||||
home:
|
||||
kind: private
|
||||
cidr: [192.168.1.0/24]
|
||||
gateway: { to: isp, address: [198.51.100.7], nat: [v4], forwardable: true }
|
||||
devices:
|
||||
kind: private
|
||||
cidr: [192.168.30.0/24]
|
||||
gateway: { to: isp, address: [198.51.100.7], nat: [v4], forwardable: false }
|
||||
machines:
|
||||
thermostat:
|
||||
at: { segment: devices, address: [192.168.30.20] }
|
||||
`),
|
||||
/one gateway.*disagree.*forwardable/s,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user