This is the shared implementation walkthrough for the advanced split-gateway guides. Choose one use case and one address-family profile, then follow the same preparation, installation and operating sequence. The Ubuntu reference explains the platform choices; the individual guides explain the policy and its failure behavior.
The supplied controller and preparation tools have offline tests. These Linux instructions have not been executed or accepted on a real host. Start with an isolated Ubuntu Server 24.04 LTS amd64 machine and an independent console. Initial installation and rollback deliberately hold that machine’s IP traffic. That maintenance hold is separate from ordinary operation, where DNS, payload and address-family failures affect only their approved scopes.
Choose the use case and family
| Case | DNS scope and path | Selected application payload | Guides |
|---|---|---|---|
| 1 | Selected applications use VPN 1 DNS; ordinary applications retain their normal direct DNS | VPN 1 | IPv4 · IPv6 |
| 2A | Host-wide DNS through VPN 1; no direct fallback | VPN 1 | IPv4 · IPv6 |
| 2B | Host-wide VPN 1 DNS preferred; one designated direct DNS fallback | VPN 1 in both DNS modes | IPv4 · IPv6 |
| 3 | Host-wide designated direct DNS, independent of the VPN | VPN 1 | IPv4 · IPv6 |
| 4A | Host-wide VPN 1’s native DNS through VPN 1 | VPN 2 | IPv4 · IPv6 |
| 4B | Host-wide independently chosen DNS provider through VPN 1 | VPN 2 | IPv4 · IPv6 |
Ordinary application payload remains direct. Only 2B has DNS fallback, with the existing choice of manual or automatic return. A DNS failure does not stop healthy known-address payload; payload failure does not stop independently healthy DNS. A common tunnel or control failure can affect the scopes that actually depend on it.
The ipv4 profile denies protected IPv6. The ipv6 profile is dual-stack: it adds independently controlled IPv6 payload and the declared DNS transports. Both A and AAAA answer checks are required even when DNS transport is IPv4. Read dual-stack preparation before choosing that profile.
Obtain the reference files
Download the unarmed reference source bundle and its SHA-256 checksum. It contains all twelve profile directories, source, unit templates, preparation tools and offline tests. It contains no credentials, compiled native library or accepted host configuration.
On the later Ubuntu lab host, verify the archive before extracting it into a new working directory:
sha256sum -c ARCHIVE.sha256
unzip advanced-controls-source.zip -d datahacker-vpn-reference
cd datahacker-vpn-reference/backend/advanced-vpn-controls
CASE=2B
FAMILY=ipv4
mkdir -m 700 review
cp "examples/$FAMILY/$CASE/manifest.example.json" review/manifest.json
cp "examples/$FAMILY/$CASE/protection.example.json" review/protection.json
cp "examples/$FAMILY/$CASE/bindings.example.json" review/bindings.json
cp "examples/$FAMILY/$CASE/launch.example.json" review/launch.json
Use FAMILY=ipv6 for the third set. These are alternative deployments, not configurations to stack on the same machine. Before privileged execution, keep a verified root-owned copy of the extracted source under /root/dhvpn-reference, outside the installed module directory, so rollback can still import it after installed files are removed. Run the privileged source-tree commands below from that protected copy.
Prepare Ubuntu and record the OpenVPN build
The reference is OpenVPN Community 2.6 on Ubuntu 24.04, using its management interface and dedicated systemd instances. Ubuntu’s Noble package catalog lists that release family. The guide uses the 2.6 manual, without treating every patch or a newer major/minor release as automatically accepted. Install supported distribution updates; record the version actually installed. A provider-branded client, Access Server or OpenVPN Connect is not the executable assumed here.
Prepare distribution dependencies before closing the installation guard. These commands are for the isolated reference machine; they were not run during this documentation work:
sudo apt update
sudo apt install python3 openvpn nftables iproute2 chrony ca-certificates netplan.io \
build-essential cmake pkg-config libmnl-dev libnftnl-dev unzip
/usr/sbin/openvpn --version
/usr/sbin/openvpn --help
dpkg-query -W -f='${binary:Package}\t${Version}\t${db:Status-Abbrev}\n' \
python3 openvpn systemd nftables iproute2 chrony ca-certificates netplan.io
systemctl --version
nft --version
ip -Version
uname -r
The version review distinguishes this reference from upstream 2.7. In particular, 2.7 supplies DNS helpers and changes defaults that affect an integration’s ownership of DNS and routes. A newer version is not automatically a substitute for this guide’s reviewed 2.6 options. See the backend/library checks as well.
Use the exact executable configured in each VPN unit, not just a command found on PATH. The controller checks its version, binary/profile hashes and advertised options, including management HOLD, bounded native retries, disable-dco, route-noexec and ifconfig-noexec. Do not silently drop an unsupported option. The example version field is intentionally unaccepted and must be replaced with observed output. Package revision and OpenVPN’s own version string are separate fields.
Keep Netplan/networkd as the uplink owner and chrony as the sole online clock owner. Inventory and resolve competing NetworkManager, time-sync, firewall, container and provider reconnect services on this dedicated host. Do not apply a generic service-disable list to an existing production machine. Keep native OpenVPN/DCO acceleration disabled for the reference path until its coverage is separately established.
Build the userspace nftables helper without installing it:
cmake -S native -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
The result is build/libdhvpn_gate.so. A successful compilation would establish only compilation; it would not prove packet containment or expiry behavior. The source uses libmnl/libnftnl and ordinary nftables, with no eBPF component.
Fill in the host and application configuration
Use a concrete inventory. For example, an isolated reference deployment could reserve UID 62000 for selected applications and 62001 for ordinary applications, with separate probe/verification UIDs from the profile. Those numbers are illustrative: first check for collisions and record every participating host service. “Host-wide DNS” requires enrollment of ordinary clients and host services as well as the selected application. An unidentified client cannot be assumed covered.
| File | What to supply |
|---|---|
manifest.json |
Case/family/return mode; host revision; each VPN’s exact executable, package, version, numeric peer and private profile; each DNS/payload path’s namespace, interface, source, destination and route table; gate identifiers; reviewed clock configuration hash and kernel HZ |
protection.json |
The same routing namespace; immutable nftables fingerprint; a selector for each traffic scope; separate round/client probe UIDs and gates; workload UID lists and exact IPv4/IPv6 rule/table fingerprints; private resolver directories |
bindings.json |
One Unix socket and server UID per role/operation; distinct normal/revoke workers; the actual socket names used by the dedicated systemd instances |
launch.json |
Protected paths, every role template/runtime target, policy/launch/maintenance journals, and effective unit/socket/supervisor fingerprints |
chrony.conf |
The reviewed flat online clock profile, derived from deployment/chrony-online.conf.example, with explicitly permitted time-source paths |
Use /proc/1/ns/net as the reference routing namespace. The current backend controls local workloads on one dedicated host. Separate mount/resolver views do not imply separate routing namespaces. LAN forwarding, containers and additional namespace owners require their own reviewed extension.
The sample addresses 192.0.2.0/24 and 2001:db8::/32 and names under .example are documentation values. Replace them with provider-authorized tunnel addresses, numeric VPN peers, DNS providers and controlled probe endpoints. The DNS checks need uncached nonce names with known A/AAAA answers. Payload checks need a small authenticated TLS exchange with the expected server name. A random public web server or ping reply cannot stand in for those controls.
Use vpn1 for the shared tunnel in 1/2A/2B/3. In 4A/4B, vpn1 carries DNS and vpn2 carries selected payload. The direct DNS path in case 3 has no VPN owner. The direct fallback in 2B likewise has no VPN owner. Keep the path and scope names from the selected profile; do not rename them independently in different files.
When a manifest field changes, update the manifest digests recorded in protection/launch configuration. The canonical digest is available from the supplied code:
python3 -c 'import json; from vpn_controls.host import digest; print(digest(json.load(open("review/manifest.json"))))'
Store provider credentials only in the private provider profiles on the host. They are never copied into the public bundle or installation payload directory. The bootstrap reads their hashes locally; no secret contents belong in the review report.
Establish routes, resolver views and closed nftables rules
The controller manages permission to use declared routes. The reviewed underlying routes, addresses and resolver contexts must exist before it can qualify them. OpenVPN’s route-noexec and ifconfig-noexec make that ownership explicit. Configure the provider-authorized tunnel addresses and return routing; do not assume the daemon will apply them for you.
For a selected application UID and a dedicated IPv4 routing table, the basic terminal-route pattern is:
# Illustrative values: reconcile interface, gateway, table and priority first.
ip -4 route add table 100 unreachable default metric 32760
ip -4 rule add priority 10000 uidrange 62000-62000 lookup 100
Add the permitted VPN route with a preferable metric when its interface/addressing is ready. The unreachable default prevents a failed lookup from continuing to a normal default route. This is only the underlying routing restriction; the advanced nftables permission still decides whether traffic may use it. DNS paths need their own destination/transport rules when they differ from payload. In dual-stack, establish and inspect the corresponding IPv6 rules and terminal route independently. The six use-case worksheets identify which paths are permitted.
Prepare the immutable inet dhvpn layout as a reviewed nftables JSON file, review/layout.json. The provided source does not invent a host firewall. The packet path must be:
classified application traffic
-> q_<scope selector>
-> p_<selected path gate> [exact interface/provider/family restriction]
-> s_<path gate> [independently expiring runtime permission]
-> accept only while that permission remains valid
Use terminal classification so an empty selector or expired grant cannot return to a later broad allow rule. Keep all q_ and s_ selector chains empty at installation. Include the required regular p_ chains and default-drop input/output/forward hooks. Do not put a_ activation chains or t_ timed sets in the installation layout; the native broker creates those. Confined probes have their own gates, identities and exact destinations. OpenVPN transport and time synchronization have narrow, separately reviewed control paths.
Cover return packets and established flows without accepting them ahead of the relevant gate. Do not use a global conntrack/ruleset flush. Include the required IPv6 control/error traffic in the dual-stack profile; the IPv6 enforcement instructions explain the additional boundaries. A structural fingerprint cannot prove that every packet reaches the correct gate; that is a later capture/test requirement.
Inspect the candidate JSON without applying it:
sudo nft --check --json --file review/layout.json
Use vpn_controls.service_adapters.static_rules_digest for the immutable nftables fingerprint and vpn_controls.host.digest over the parsed JSON from each actual ip -j -4/-6 rule show and corresponding route-table observation. The protection backend compares these family-specific inventories. The bundle’s HOST-PROTECTION.md explains the readback boundary. The install plan contains typed add commands confined to inet dhvpn; no global flush or shell script is accepted.
For DNS, create private root-owned directories under /run/datahacker-vpn/resolvers/. Bind each directory into its workload’s resolver view, rather than bind-mounting just the resolv.conf inode: the controller atomically replaces that file when the selected provider changes. Keep separate candidate-probe and actual-client verification views. The reference file contents use options timeout:2 attempts:1; external deadlines still cover the entire lookup. Inventory NSS, local resolver sockets/bus access and application-specific DNS/proxy paths. A port-53 rule alone cannot establish that arbitrary HTTPS-based DNS is contained.
Prepare profiles, units and role files
For each VPN, retain the provider’s authenticated peer identity and private credentials. Merge the profile’s supplied vpn1.options.example/vpn2.options.example into that reviewed configuration. Use the numeric remote and declared device, native HOLD, one management owner and the approved retry settings. Do not add another NetworkManager/provider helper or management client beside this owner. The management protocol reference explains the native control channel.
Render the .in unit templates in deployment/ using the exact executable, namespace, users/groups, address families, writable paths and resolver mounts for each role. The generic adapter service can be accompanied by explicit per-instance vendor units where identities or mount views differ. Probe and actual-client identities must match protection.json; verify their configuration-read access, callback peer credentials and inherited socket ownership. Do not give applications probe credentials to make a failed check pass.
Every launch.json role declares datahacker-vpn-adapter@<instance>.service and the matching socket. Its binding must be /run/datahacker-vpn/<instance>.sock. Update the selection-client socket paths in protection.json too. Once those declarations agree, generate the corresponding role JSON files:
python3 -m vpn_controls.walkthrough render-roles \
--manifest review/manifest.json --launch review/launch.json \
--bindings review/bindings.json --protection review/protection.json \
--output review/roles
These templates deliberately contain UNSTARTED identities. The fenced launcher supplies real boot/session/generation values; readers must not manufacture them. A broker and its revoker share that gate’s publication journal, while different gates have different journals.
Use /etc/datahacker-vpn/chrony.conf as the declared flat clock configuration and configure the actual chrony invocation to use those reviewed contents. Preserve maxslewrate 500, maxdrift 500, slew handling and the existing step/suspend interlock. Configuration is not proof of the assumed clock-rate bounds. Create persistent history and authority directories and required runtime/resolver directories with protected root ownership. For example, sudo install -d -o root -g root -m 0700 /var/lib/datahacker-vpn/history creates the history directory without initializing any journal; create the declared /run/datahacker-vpn/roles and resolver directories with the reviewed reader permissions. Recreate transient directories under a reviewed boot prerequisite before the handoff; do not recreate lost SQLite authority as a boot convenience.
The supervisor template’s boot prerequisite must refer to the owned deny-only bootstrap guard. The handoff starts that guard before removing its current-boot kernel table. It remains an active oneshot during the boot and reinstates denial before networkd on the next boot. Do not independently enable adapter/VPN/supervisor instances at boot: a fresh boot requires explicit reconciliation through the handoff.
Record effective unit hashes from exact systemctl cat output, including source headers and drop-ins. Those differ from the raw staged-file hashes. The plan checks staged bytes; the handoff checks the effective VPN unit before release; the launcher checks adapter/socket units, and supervisor startup checks its own unit. The bound plan records expected effective-unit identities for the reviewed staged unit text and final vendor paths. Confirm those expectations against actual systemctl cat output while the host is held, before granting test or runtime permission; do not edit an admitted plan or its saved identities to hide a mismatch. Unknown/changed units stop the procedure.
Assemble and inspect the installation plan
Copy the selected bootstrap.plan.pending.json into the plan member of a local review/binding.json. Fill its ID, bound-unarmed status, first-install/upgrade mode, observed machine ID and boot ID, exact configured prerequisite-package versions and executable hashes, reviewed maintenance-record hash, and the completed manifest/launch/protection/layout objects. Leave runtime_acceptance and deployment_allowed false.
The binding file has three top-level members:
{
"plan": "Replace this string with the completed plan object",
"payload_sources": {
"/etc/datahacker-vpn/manifest.json": "manifest.json",
"/etc/datahacker-vpn/launch.json": "launch.json",
"/etc/datahacker-vpn/protection.json": "protection.json",
"/etc/datahacker-vpn/bindings.json": "bindings.json",
"/etc/datahacker-vpn/chrony.conf": "chrony.conf",
"/usr/lib/datahacker-vpn/libdhvpn_gate.so": "../build/libdhvpn_gate.so"
},
"preimages": {}
}
Add every rendered role JSON, adapter template, socket, supervisor and VPN vendor unit to payload_sources. The renderer’s payload-sources.json supplies the role-target mapping; prefix its source names with roles/ when merging it here. The assembler automatically adds all bundled controller modules at /usr/lib/python3/dist-packages/vpn_controls.
For a first installation, every target must be absent. For an upgrade, preimages must contain every target, including module files, with the observed SHA-256, numeric mode, UID and GID (or explicit absence for a genuinely new target). No guessed preimage is accepted. The source assembler uses root-owned mode 0644 for these public code/configuration payloads; private provider material is excluded.
python3 -m vpn_controls.walkthrough assemble \
--binding review/binding.json --output review/staged
python3 -m vpn_controls.bootstrap_cli check-plan --plan review/staged/plan.json
Expected output identifies the plan hash and file count, with host_commands_run: false and runtime_acceptance: false. A pending worksheet, missing target, changed source, arbitrary target or incomplete upgrade preimages is a refusal. The assembler never overwrites an existing output directory.
Install while the host stays closed
Only on the isolated host, place the reviewed plan and hash-named payloads in a root-owned staging directory. Protect their ancestors and contents; do not stage under a user-writable home directory. Record the plan hash returned above. From the retained source tree, use the real values below:
sudo python3 -m vpn_controls.bootstrap_cli install \
--plan /root/dhvpn-stage/plan.json --payloads /root/dhvpn-stage/payloads \
--confirm-plan ACTUAL_PLAN_SHA256 --console-maintenance --new-journal
Use --new-journal only for the genuinely first installation. Upgrades use the existing journal. The command establishes the deny-only bootstrap table, masks dedicated units and networkd, fences old processes, saves preimages, installs reviewed files and creates first authority exclusively—or preserves existing authority on upgrade. It finishes as installed-unarmed; no application permission has been granted. An interrupted initialization retains its partial files and requires reconciliation.
The installed artifact inventory is /var/lib/datahacker-vpn/installed.json. Transaction records and verified backups are under /var/lib/datahacker-vpn/bootstrap/. Keep that directory, current policy journals and the retained source tree. Do not rerun a partially applied plan as though it were new.
Authorize a lab test or supply measured acceptance
The first real Linux run needs permission to collect evidence before it can have passed evidence. The source therefore recognizes two separate documents at the protected acceptance.json path:
| Document | Meaning |
|---|---|
kind: isolated-host-test |
Explicit permission for a reviewed isolated machine, exact installed identities and one current boot. It asserts no successful acceptance tests. |
| Measured acceptance record | Existing complete evidence categories and report hashes bound to the exact installed identities. It is required before describing the deployment as accepted. |
For a later authorized lab session, start from isolated-test.pending.json in the bundle. Supply the installed host/manifest identity, the exact identities object from installed.json, current boot ID and a hash of the reviewed isolation/console/test-boundary record. Change authorized to true only after that review. Keep the file root-owned and protected. Do not populate fictitious passed checks. This lab permission is rejected by the measured-acceptance validator and becomes invalid on another boot or changed build.
Nothing in this walkthrough’s preparation tools issues either permission automatically. The documentation work has issued no permission for an actual host and has performed no Linux tests.
Hand off to the running controls
Read the current saved session from /var/lib/datahacker-vpn/launch-current.json. With a stable new request ID and the reviewed plan hash, run:
sudo python3 -I -m vpn_controls.handoff_cli start \
--plan /root/dhvpn-stage/plan.json --confirm-plan ACTUAL_PLAN_SHA256 \
--console-maintenance --id first-start-001 --session ACTUAL_SAVED_SESSION
The handoff validates the exact installation and execution permission, then records its intent. It retains the bootstrap guard while transferring only installer-owned persistent masks to the launcher’s runtime inhibition. It starts the deny-only boot guard and requests networkd while traffic is still held. It never starts a VPN directly.
The existing launcher then fences writers, closes and reads back the static layout and every scope, preserves manual holds/selections, reconciles the approved restart allowance, and publishes the new generation. Immediately before runtime activation, the handoff rechecks closure and removes only inet dhvpn_bootstrap. The permanent dhvpn protections remain. The guardian starts bounded observation and counted OpenVPN repair; each scope still needs fresh qualification before traffic can pass. The supervisor is requested after the launcher lock is released.
Expected handoff output includes activation: requested, traffic_revalidated: false, and either isolated-host-test or accepted-host. This is not proof that a route is healthy. Inspect status and the supervisor result. An unconfirmed observer start is a separate operational failure; do not rename it a successful handoff or reset budgets to hide it.
On an actual new boot, reestablish the required transient directories and reviewed closed static layout behind the bootstrap guard, supply permission valid for that boot, and use --reason host-boot with the current saved session. That invokes the approved once-per-boot reset. A same-boot automatic crash remains the supervisor’s existing bounded recovery; it must not invoke this operator handoff for another allowance.
Inspect, hold and recover a scope
For the 2B example:
sudo python3 -I -m vpn_controls.launch_cli --manifest /etc/datahacker-vpn/manifest.json --config /etc/datahacker-vpn/launch.json status
sudo python3 -I -m vpn_controls.launch_cli --manifest /etc/datahacker-vpn/manifest.json --config /etc/datahacker-vpn/launch.json hold --scope dns.host --id dns-hold-001
sudo python3 -I -m vpn_controls.launch_cli --manifest /etc/datahacker-vpn/manifest.json --config /etc/datahacker-vpn/launch.json result --id dns-hold-001
Inspect selected paths, manual holds, current observations, incident/attempt counts and control faults. The initial command response may be queued_not_applied; query its result using the same ID. A failed journal acknowledgment is not durable success.
Use reset --scope dns.host --id ... to replenish eligible recovery authority while retaining a manual hold; use rearm when explicitly clearing that hold as well. Both require fresh checks. return-preferred requests an already-qualified preferred path in 2B; it does not override failed qualification. Case 1 uses dns.selected and dns.ordinary; the other cases use dns.host. Selected IPv4 payload is selected.payload4; dual-stack adds selected.payload6. Read the actual profile rather than applying a DNS command to all scopes.
The approved timers are unchanged: fifteen-minute repair windows, three 4:30 attempts per window, an eighty-second qualification ceiling, fifteen-minute cooldown, and 120-second confirmation outside each window. Healthy permitted 2B fallback can remain working during preferred repair, cooldown and failed repair. The timing guide remains the detailed authority.
Handle an interruption and roll back
If handoff is interrupted, inspect its record and the launch journal before retrying. The same command cannot automatically replay a possibly submitted start. Close and cancel the attempted handoff explicitly:
sudo python3 -I -m vpn_controls.handoff_cli cancel \
--plan /root/dhvpn-stage/plan.json --confirm-plan ACTUAL_PLAN_SHA256 --console-maintenance
Cancellation restores the bootstrap guard, inhibits/fences the owned processes, collects recorded permissions and archives the handoff record. It preserves policy journals and does not reset allowances. Stop and verify retirement of a running supervisor before an explicit control operation that needs its lock. A busy lock is a refusal, not a reason to delete the lock file.
If the launcher has a nonterminal transaction, a later reviewed start uses a new stable ID, the actual saved session, and --reconcile-interrupted OLD_LAUNCH_ID. It still closes/fences before retiring the old intent. A completed launch is not an interrupted transaction. For cancellation/rollback after a real reboot, explicitly supply --rollback-boot ACTUAL_CURRENT_BOOT; this does not rewrite old authority.
To restore the installation’s owned files while keeping traffic held, use the retained source tree:
sudo python3 -m vpn_controls.bootstrap_cli rollback \
--plan /root/dhvpn-stage/plan.json --confirm-plan ACTUAL_PLAN_SHA256 --console-maintenance
Rollback restores only attempted files that still match the recorded before/after images. It retains current journals, manual holds, histories, bootstrap masks and static protections. Changed files, corrupt backups, unknown permission objects or ambiguous ownership stop restoration. The artifact inventory receives a new rollback identity, so old execution acceptance cannot silently authorize the restored installation.
Rollback does not mean “resume direct networking.” Returning to a simple guide requires a separate verified replacement policy before removing protection. Never replace this sequence with a general unmask, firewall flush, deletion of the state directory or reinitialization of an existing journal.
Validate the guide on the later lab host
Use the selected profile’s host-acceptance.worksheet.json, the IPv4 failure checks and dual-stack checks. Record actual outputs and packet captures. Exercise DNS-only loss, payload-only loss, degraded/unknown monitoring, repair exhaustion, 2B fallback continuity, delayed permission writes, controller failures, restart, suspend/clock transitions and interrupted installation/rollback.
Check effective units and callback identities, resolver/NSS coverage, new and established traffic, return paths, independent IPv6 behavior and every boot/network activation path. Measure the original deadlines and clock-rate assumptions. A successful offline test, syntax check, interface, service state or installation receipt is insufficient evidence of those outcomes.
The documentation and local reference source are available now. Linux compilation, execution, packet tests and actual host acceptance remain deferred. The OpenVPN version review now connects the historical articles to this reference while preserving their earlier release history.