Add kernel forwarding for bypassed devices
This commit is contained in:
@@ -14,7 +14,11 @@ const { settings } = await import("../../src/server/config.js");
|
||||
|
||||
test("default source bypass chain name fits iptables chain length limit", () => {
|
||||
assert.equal(settings.tproxySourceBypassChain, "VPN_PROXY_SRC_BYPASS");
|
||||
assert.equal(settings.tproxySourceForwardChain, "VPN_PROXY_FWD_BYPASS");
|
||||
assert.equal(settings.tproxySourceNatChain, "VPN_PROXY_NAT_BYPASS");
|
||||
assert.ok(settings.tproxySourceBypassChain.length <= 28);
|
||||
assert.ok(settings.tproxySourceForwardChain.length <= 28);
|
||||
assert.ok(settings.tproxySourceNatChain.length <= 28);
|
||||
});
|
||||
|
||||
test("device profiles preserve bypass mode for kernel-level TProxy bypass", () => {
|
||||
@@ -95,9 +99,14 @@ test("source bypass iptables commands use ACCEPT inside the managed subchain", (
|
||||
assert.deepEqual(
|
||||
buildSourceBypassIptablesCommands(["192.168.50.25/32"], {
|
||||
chain: "VPN_PROXY_SOURCE_BYPASS",
|
||||
forwardChain: "VPN_PROXY_FWD_BYPASS",
|
||||
natChain: "VPN_PROXY_NAT_BYPASS",
|
||||
natBypassCidrs: ["10.0.0.0/8"],
|
||||
}),
|
||||
[
|
||||
["-w", "-t", "mangle", "-F", "VPN_PROXY_SOURCE_BYPASS"],
|
||||
["-w", "-F", "VPN_PROXY_FWD_BYPASS"],
|
||||
["-w", "-t", "nat", "-F", "VPN_PROXY_NAT_BYPASS"],
|
||||
[
|
||||
"-w",
|
||||
"-t",
|
||||
@@ -109,6 +118,50 @@ test("source bypass iptables commands use ACCEPT inside the managed subchain", (
|
||||
"-j",
|
||||
"ACCEPT",
|
||||
],
|
||||
[
|
||||
"-w",
|
||||
"-A",
|
||||
"VPN_PROXY_FWD_BYPASS",
|
||||
"-s",
|
||||
"192.168.50.25/32",
|
||||
"-j",
|
||||
"ACCEPT",
|
||||
],
|
||||
[
|
||||
"-w",
|
||||
"-A",
|
||||
"VPN_PROXY_FWD_BYPASS",
|
||||
"-d",
|
||||
"192.168.50.25/32",
|
||||
"-m",
|
||||
"conntrack",
|
||||
"--ctstate",
|
||||
"RELATED,ESTABLISHED",
|
||||
"-j",
|
||||
"ACCEPT",
|
||||
],
|
||||
[
|
||||
"-w",
|
||||
"-t",
|
||||
"nat",
|
||||
"-A",
|
||||
"VPN_PROXY_NAT_BYPASS",
|
||||
"-d",
|
||||
"10.0.0.0/8",
|
||||
"-j",
|
||||
"RETURN",
|
||||
],
|
||||
[
|
||||
"-w",
|
||||
"-t",
|
||||
"nat",
|
||||
"-A",
|
||||
"VPN_PROXY_NAT_BYPASS",
|
||||
"-s",
|
||||
"192.168.50.25/32",
|
||||
"-j",
|
||||
"MASQUERADE",
|
||||
],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -35,6 +35,13 @@ exit 0
|
||||
`#!/usr/bin/env bash
|
||||
printf 'ipset %s\\n' "$*" >> "$COMMAND_LOG"
|
||||
exit 0
|
||||
`,
|
||||
);
|
||||
writeExecutable(
|
||||
path.join(tmp, "sysctl"),
|
||||
`#!/usr/bin/env bash
|
||||
printf 'sysctl %s\\n' "$*" >> "$COMMAND_LOG"
|
||||
exit 0
|
||||
`,
|
||||
);
|
||||
writeExecutable(
|
||||
@@ -82,12 +89,34 @@ exit 0
|
||||
const tproxyIndex = commands.findIndex((line) =>
|
||||
line.includes("-p tcp -j TPROXY --on-port 7895"),
|
||||
);
|
||||
const ipForwardIndex = commands.findIndex((line) =>
|
||||
line.includes("sysctl -w net.ipv4.ip_forward=1"),
|
||||
);
|
||||
const forwardAcceptIndex = commands.findIndex((line) =>
|
||||
line.includes(
|
||||
"iptables -w -A VPN_PROXY_FWD_BYPASS -s 192.168.50.25/32 -j ACCEPT",
|
||||
),
|
||||
);
|
||||
const forwardReturnIndex = commands.findIndex((line) =>
|
||||
line.includes(
|
||||
"iptables -w -A VPN_PROXY_FWD_BYPASS -d 192.168.50.25/32 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT",
|
||||
),
|
||||
);
|
||||
const natMasqueradeIndex = commands.findIndex((line) =>
|
||||
line.includes(
|
||||
"iptables -w -t nat -A VPN_PROXY_NAT_BYPASS -s 192.168.50.25/32 -j MASQUERADE",
|
||||
),
|
||||
);
|
||||
|
||||
assert.notEqual(sourceBypassIndex, -1);
|
||||
assert.notEqual(secondSourceBypassIndex, -1);
|
||||
assert.notEqual(sourceBypassJumpIndex, -1);
|
||||
assert.notEqual(directCacheIndex, -1);
|
||||
assert.notEqual(tproxyIndex, -1);
|
||||
assert.notEqual(ipForwardIndex, -1);
|
||||
assert.notEqual(forwardAcceptIndex, -1);
|
||||
assert.notEqual(forwardReturnIndex, -1);
|
||||
assert.notEqual(natMasqueradeIndex, -1);
|
||||
assert.ok(sourceBypassJumpIndex < directCacheIndex);
|
||||
assert.ok(sourceBypassJumpIndex < tproxyIndex);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user