openwrt refactor & apply rules

This commit is contained in:
ari committed 2026-08-27 13:09:38 -04:00
1 parent c1c17ec8e6
commit a9aaae3da9
7 files changed
+735 -149

No files matched your search

+31 -8
View File
@@ -9,10 +9,18 @@ so this provides a declarative, reviewable way to push `dnsmasq.conf` and `/etc/
```
openwrt/
├── default.nix # Builds the Rust generator + the openwrt-deploy script
└── generator/ # Rust crate (openwrt-gen) that turns a JSON config into OpenWrt files
├── default.nix # Thin Nix wrapper: builds the generator, exports store paths as
│ # env vars, and inlines the .sh files below via builtins.readFile
├── skyg-apply.sh # Runs ON THE ROUTER (POSIX sh) — backup/apply/validate/restore
├── openwrt-deploy.sh # openwrt-deploy's logic (bash) — reads $ROUTER/$GENERATOR/etc.
├── openwrt-dry-run.sh # openwrt-dry-run's logic (bash) — reads $GENERATOR
└── generator/ # Rust crate (openwrt-gen) that turns a JSON config into OpenWrt files
```
The three `.sh` files are real, directly-editable/shellcheck-able scripts — `default.nix` only
supplies the Nix-computed values (router address, generator/apply-script store paths) as
exported env vars before inlining each file's content via `builtins.readFile`.
## How it works
1. The router config lives as an **agenix secret** (e.g. `secrets/glmain.json.age`).
@@ -23,9 +31,12 @@ openwrt/
`-> N added, M removed` summary, then lists the `skyg_*` rule names that will be
applied, and prompts for confirmation.
4. On the router it **backs up** the configs it overrides to `/etc/skyg-backups/` with a
timestamp, then applies them. `dnsmasq.conf` is validated with `dnsmasq --test` and the
firewall is committed + reloaded; **any failure auto-restores** from that timestamp's
backups. Backups persist so you can restore later if something breaks:
timestamp, then applies them. It also ensures `net.bridge.bridge-nf-call-iptables` /
`-ip6tables` are enabled via a managed block in `/etc/sysctl.conf` (see Conventions below
— required for the firewall rules to actually see LAN-to-LAN traffic). `dnsmasq.conf` is
validated with `dnsmasq --test` and the firewall is committed + reloaded; **any failure
auto-restores** from that timestamp's backups. Backups persist so you can restore later if
something breaks:
```sh
cp /etc/skyg-backups/firewall.<ts> /etc/config/firewall
uci commit firewall && /etc/init.d/firewall restart
@@ -45,7 +56,7 @@ is passed as a command-line argument (default `glmain`).
skyg openwrt --dry-run
# → .tmp/openwrt-glmain/dnsmasq.conf
# → .tmp/openwrt-glmain/ethers
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci batch` that would be applied
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci -m import firewall` input
```
Use this to inspect what a deploy *would* do (especially the firewall rules) before running
@@ -60,5 +71,17 @@ the real `skyg openwrt`.
confirmation and self-reverts on a bad dnsmasq config.
- `generator/target/` is gitignored Rust build output — ignore it.
- Firewall rules are **managed by name**: the deploy script only touches rules named
`skyg_*`. It deletes existing `skyg_*` rules, adds the newly generated ones, commits, and
reloads — so deploys are idempotent and never clobber hand-written rules.
`skyg_*`. It deletes existing `skyg_*` rules, adds the newly generated ones as real named
UCI sections via `uci -m import firewall` (not `uci batch` — the generator's output is
declarative `config rule 'name'` syntax, not batch commands), commits, and reloads — so
deploys are idempotent and never clobber hand-written rules.
- **The LAN is one flat L2 bridge, not real per-network VLANs.** `apl`, `cam`, `lab`, etc. are
just address-range conventions within a single `br-lan` (one `/16`, all ports bridged
together). Because of this, unicast traffic between two hosts on the bridge is normally
switched at L2 and never reaches the router's iptables FORWARD chain — so the `skyg_*`
internet-only DROP rules would silently never fire. `skyg-apply.sh` works around this by
enabling `net.bridge.bridge-nf-call-iptables` / `-ip6tables` (via a managed block appended
to `/etc/sysctl.conf`, since `/etc/sysctl.d/*.conf` ships them disabled and is reset on
firmware upgrades) so bridged traffic is actually filtered. Confirmed live: without this,
an `internetOnly`-flagged device's DROP rule showed 0/0 packet/byte counters in
`iptables -L -v -n` despite matching traffic; with it enabled, blocking works as expected.
+16 -130
View File
@@ -9,148 +9,34 @@ let
};
# Remote apply script: backs up the configs it overrides, applies the new
# firewall/dnsmasq/ethers, validates, and auto-restores on failure.
# Run on the router as: TS=<timestamp> bash skyg-apply.sh
# Expects the new files staged at /tmp/skyg_firewall.batch,
# /tmp/dnsmasq.new.conf and /tmp/ethers.new.
applyScript = pkgs.writeText "skyg-apply.sh" ''
set -euo pipefail
BK=/etc/skyg-backups
mkdir -p "$BK"
cp /etc/config/firewall "$BK/firewall.$TS"
cp /etc/dnsmasq.conf "$BK/dnsmasq.conf.$TS"
cp /etc/ethers "$BK/ethers.$TS" 2>/dev/null || true
# --- Firewall: replace the skyg-managed rules ---
for ref in $(uci show firewall | awk -F. '/\.name=.skyg_/{print $1"."$2}'); do
uci -q del "$ref" || true
done
if ! uci batch < /tmp/skyg_firewall.batch; then
echo 'FIREWALL: uci batch failed, restoring'
cp "$BK/firewall.$TS" /etc/config/firewall
exit 1
fi
if ! uci commit firewall; then
echo 'FIREWALL: uci commit failed, restoring'
cp "$BK/firewall.$TS" /etc/config/firewall
exit 1
fi
/etc/init.d/firewall reload
# --- dnsmasq ---
cp /tmp/dnsmasq.new.conf /etc/dnsmasq.conf
if dnsmasq --test; then
/etc/init.d/dnsmasq restart
else
echo 'dnsmasq config invalid, restoring'
cp "$BK/dnsmasq.conf.$TS" /etc/dnsmasq.conf
exit 1
fi
# --- ethers ---
cp /tmp/ethers.new /etc/ethers
echo 'Done'
'';
# firewall/dnsmasq/ethers, ensures bridge-netfilter sysctls are enabled,
# validates, and auto-restores on failure. Runs on the router as-is (no Nix
# templating needed), so it's just referenced directly from disk.
applyScript = ./skyg-apply.sh;
in
config:
let
# Config JSON is read from stdin at deploy time — caller decrypts the age secret.
# Usage: age -d secrets/glmain.json.age | openwrt-deploy
#
# The bulk of the logic lives in ./openwrt-deploy.sh; this just exports the
# Nix-computed values it needs (router address, generator/apply-script store
# paths) and inlines the file's content after them.
deployScript = pkgs.writeShellScriptBin "openwrt-deploy" ''
set -euo pipefail
ROUTER="${config.router.ip}"
ROUTER_USER="${config.router.user}"
SERVER="$ROUTER_USER@$ROUTER"
CONFIG=$(cat)
DNSMASQ=$(echo "$CONFIG" | ${generator}/bin/openwrt-gen dnsmasq)
ETHERS=$(echo "$CONFIG" | ${generator}/bin/openwrt-gen ethers)
FIREWALL=$(echo "$CONFIG" | ${generator}/bin/openwrt-gen firewall)
# Colorized unified diff with a per-file change summary.
# $1 = label, $2 = current (may be empty), $3 = new
show_diff() {
local label="$1" old="$2" new="$3"
local oldf newf d
oldf=$(mktemp) newf=$(mktemp)
if [ -n "$old" ]; then printf '%s\n' "$old" > "$oldf"; else : > "$oldf"; fi
if [ -n "$new" ]; then printf '%s\n' "$new" > "$newf"; else : > "$newf"; fi
echo ""
echo "=== $label ==="
if d=$(diff -u "$oldf" "$newf"); then
echo " (no changes)"
else
printf '%s\n' "$d" | awk '
/^---/ {printf "\033[2m%s\033[0m\n", $0; next}
/^\+\+\+/ {printf "\033[2m%s\033[0m\n", $0; next}
/^@@/ {printf "\033[36m%s\033[0m\n", $0; next}
/^-/ {printf "\033[31m%s\033[0m\n", $0; next}
/^\+/ {printf "\033[32m%s\033[0m\n", $0; next}
{print}
'
local added removed
added=$(printf '%s\n' "$d" | grep -c '^[+][^+]' || true)
removed=$(printf '%s\n' "$d" | grep -c '^[-][^-]' || true)
echo " -> $added added, $removed removed"
fi
rm -f "$oldf" "$newf"
}
echo "Fetching current config from $SERVER..."
CURRENT_DNSMASQ=$(ssh "$SERVER" 'cat /etc/dnsmasq.conf' 2>/dev/null || echo "")
CURRENT_ETHERS=$(ssh "$SERVER" 'cat /etc/ethers' 2>/dev/null || echo "")
CURRENT_FIREWALL_ALL=$(ssh "$SERVER" 'uci export firewall' 2>/dev/null || echo "")
# Keep only the skyg-managed rule blocks (for the diff)
CURRENT_FIREWALL=$(echo "$CURRENT_FIREWALL_ALL" | awk '/^config /{if(have && block ~ /skyg_/) print block; block=$0; have=1; next}{if(have) block=block ORS $0}END{if(have && block ~ /skyg_/) print block}')
# Drop the header comment from the generated firewall for a clean diff
NEW_FIREWALL=$(echo "$FIREWALL" | tail -n +2)
show_diff "dnsmasq.conf" "$CURRENT_DNSMASQ" "$DNSMASQ"
show_diff "ethers" "$CURRENT_ETHERS" "$ETHERS"
show_diff "firewall (skyg rules)" "$CURRENT_FIREWALL" "$NEW_FIREWALL"
echo ""
echo "skyg firewall rules to be applied:"
echo "$NEW_FIREWALL" | awk -F"'" '/option name/{print " " $2}'
echo ""
read -p "Deploy to $SERVER? [y/N] " -n 1 -r < /dev/tty; echo
[[ $REPLY =~ ^[Yy]$ ]] || exit 1
TS=$(date +%Y%m%d-%H%M%S)
# Stage the apply script and the new config files on the router
ssh "$SERVER" 'cat > /tmp/skyg_apply.sh' < "${applyScript}"
echo "$DNSMASQ" | ssh "$SERVER" 'cat > /tmp/dnsmasq.new.conf'
echo "$ETHERS" | ssh "$SERVER" 'cat > /tmp/ethers.new'
echo "$FIREWALL" | ssh "$SERVER" 'cat > /tmp/skyg_firewall.batch'
# Back up, apply, validate, auto-restore on failure (OpenWrt has no bash, use sh)
ssh "$SERVER" "TS=$TS sh /tmp/skyg_apply.sh"
export ROUTER="${config.router.ip}"
export ROUTER_USER="${config.router.user}"
export GENERATOR="${generator}"
export APPLY_SCRIPT="${applyScript}"
${builtins.readFile ./openwrt-deploy.sh}
'';
# Dry-run: render the configs locally and write them to .tmp/openwrt-<router>/
# for review. No SSH, no uci, no router changes. Run from the repo root.
# The router name is passed as $1 (defaults to glmain).
# The router name is passed as $1 (defaults to glmain) — see ./openwrt-dry-run.sh.
dryRunScript = pkgs.writeShellScriptBin "openwrt-dry-run" ''
set -euo pipefail
if [ $# -ge 1 ]; then ROUTER="$1"; else ROUTER=glmain; fi
OUTDIR=".tmp/openwrt-$ROUTER"
mkdir -p "$OUTDIR"
CONFIG=$(cat)
echo "$CONFIG" | ${generator}/bin/openwrt-gen dnsmasq > "$OUTDIR/dnsmasq.conf"
echo "$CONFIG" | ${generator}/bin/openwrt-gen ethers > "$OUTDIR/ethers"
echo "$CONFIG" | ${generator}/bin/openwrt-gen firewall > "$OUTDIR/firewall.batch"
echo "Dry-run configs written to $OUTDIR (no router changes made):"
echo " $OUTDIR/dnsmasq.conf"
echo " $OUTDIR/ethers"
echo " $OUTDIR/firewall.batch"
export GENERATOR="${generator}"
${builtins.readFile ./openwrt-dry-run.sh}
'';
in
{
@@ -1,8 +1,8 @@
use crate::config::Config;
use crate::network::{prefix_for, process_network, ULA_PREFIX};
/// Renders UCI firewall rules (in `uci batch` format) that restrict devices to
/// internet-only access.
/// Renders UCI firewall rules (in `uci` declarative import/export syntax — suitable for
/// `uci -m import firewall`) that restrict devices to internet-only access.
///
/// Two sources of restriction:
/// - **Network-level** (`config.internet_only`): for each restricted network,
@@ -12,7 +12,10 @@ use crate::network::{prefix_for, process_network, ULA_PREFIX};
/// - **Device-level** (a device with `internetOnly: true`): IPv4 + IPv6 DROP rules
/// matched by that device's MAC, on any network.
///
/// Rules are named `skyg_*` so the deploy script can manage exactly the rules it owns.
/// Every rule is a real named section (`config rule 'skyg_...'`, name unique per rule) so
/// the deploy script can address and manage exactly the rules it owns. Every rule also sets
/// `proto 'all'` — without it, fw3 defaults to matching TCP+UDP only, which would silently
/// let ICMP (ping) and other protocols through.
pub fn generate(config: &Config) -> String {
let mut out = String::new();
out.push_str("# Managed by skyg openwrt — do not edit by hand\n");
@@ -27,33 +30,37 @@ pub fn generate(config: &Config) -> String {
let v4_prefix = prefix_for(network);
let v4_subnet = format!("{}.0/24", v4_prefix.trim_end_matches('.'));
out.push_str(&format!(
"config rule\n\
\toption name 'skyg_{net}_drop_lan'\n\
"config rule 'skyg_{net}_drop_lan'\n\
\toption src 'lan'\n\
\toption dest 'lan'\n\
\toption src_ip '{subnet}'\n\
\toption dest_ip '10.0.0.0/16'\n\
\toption proto 'all'\n\
\toption target 'DROP'\n\
\toption family 'ipv4'\n",
net = network,
subnet = v4_subnet,
));
out.push_str("\n");
// IPv6: block each known device's MAC from reaching the ULA LAN.
for pd in process_network(network, devices) {
let slug = mac_slug(&pd.device.mac);
out.push_str(&format!(
"config rule\n\
\toption name 'skyg_{net}_drop_lan_v6'\n\
"config rule 'skyg_{net}_drop_lan_v6_{slug}'\n\
\toption src 'lan'\n\
\toption dest 'lan'\n\
\toption src_mac '{mac}'\n\
\toption dest_ip '{ula}'\n\
\toption proto 'all'\n\
\toption target 'DROP'\n\
\toption family 'ipv6'\n",
net = network,
slug = slug,
mac = pd.device.mac,
ula = ULA_PREFIX,
));
out.push_str("\n");
}
}
@@ -65,30 +72,32 @@ pub fn generate(config: &Config) -> String {
}
let slug = mac_slug(&pd.device.mac);
out.push_str(&format!(
"config rule\n\
\toption name 'skyg_mac_{slug}_drop_lan'\n\
"config rule 'skyg_mac_{slug}_drop_lan'\n\
\toption src 'lan'\n\
\toption dest 'lan'\n\
\toption src_mac '{mac}'\n\
\toption dest_ip '10.0.0.0/16'\n\
\toption proto 'all'\n\
\toption target 'DROP'\n\
\toption family 'ipv4'\n",
slug = slug,
mac = pd.device.mac,
));
out.push_str("\n");
out.push_str(&format!(
"config rule\n\
\toption name 'skyg_mac_{slug}_drop_lan_v6'\n\
"config rule 'skyg_mac_{slug}_drop_lan_v6'\n\
\toption src 'lan'\n\
\toption dest 'lan'\n\
\toption src_mac '{mac}'\n\
\toption dest_ip '{ula}'\n\
\toption proto 'all'\n\
\toption target 'DROP'\n\
\toption family 'ipv6'\n",
slug = slug,
mac = pd.device.mac,
ula = ULA_PREFIX,
));
out.push_str("\n");
}
}
@@ -151,6 +160,7 @@ mod tests {
assert!(result.contains("skyg_cam_drop_lan"));
assert!(result.contains("option src_ip '10.0.13.0/24'"));
assert!(result.contains("option dest_ip '10.0.0.0/16'"));
assert!(result.contains("option proto 'all'"));
assert!(result.contains("option target 'DROP'"));
assert!(result.contains("option family 'ipv4'"));
}
@@ -166,6 +176,16 @@ mod tests {
assert!(result.contains("option family 'ipv6'"));
}
#[test]
fn test_network_level_v6_rules_have_unique_names_per_device() {
// Two devices on a network-level-restricted network must not collide on one
// UCI section name, or only the last device's rule would actually apply.
let config = config_with_devices(vec!["cam".to_string()]);
let result = generate(&config);
assert!(result.contains("config rule 'skyg_cam_drop_lan_v6_aabbccddee01'"));
assert!(result.contains("config rule 'skyg_cam_drop_lan_v6_aabbccddee02'"));
}
#[test]
fn test_unknown_network_is_skipped() {
let config = config_with_devices(vec!["nonexistent".to_string()]);
@@ -195,10 +215,22 @@ mod tests {
assert!(result.contains("option src_mac '11:22:33:44:55:66'"));
assert!(result.contains("option dest_ip '10.0.0.0/16'"));
assert!(result.contains("option dest_ip 'fd59:de0a:bff5::/48'"));
assert!(result.contains("option proto 'all'"));
// No subnet rules were generated (no network-level internetOnly).
assert!(!result.contains("skyg_lab_drop_lan\n"));
}
#[test]
fn test_every_rule_blocks_all_protocols() {
// A DROP rule without `proto` only blocks TCP+UDP (fw3 default) — every rule must
// explicitly set `proto 'all'` so ICMP (ping) etc. is blocked too, not just TCP/UDP.
let config = config_with_devices(vec!["cam".to_string()]);
let result = generate(&config);
let rule_count = result.matches("config rule").count();
let proto_count = result.matches("option proto 'all'").count();
assert_eq!(rule_count, proto_count);
}
#[test]
fn test_mac_slug_strips_colons() {
assert_eq!(mac_slug("aa:bb:cc:dd:ee:ff"), "aabbccddeeff");
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Interactive deploy entrypoint. Reads router config JSON from stdin — caller
# decrypts the age secret. Usage: age -d secrets/glmain.json.age | openwrt-deploy
#
# Expects these to be exported by the Nix wrapper before this file's content runs:
# ROUTER - router IP/hostname
# ROUTER_USER - SSH user
# GENERATOR - store path of the openwrt-gen package (bin/openwrt-gen inside)
# APPLY_SCRIPT - store path of skyg-apply.sh
set -euo pipefail
SERVER="$ROUTER_USER@$ROUTER"
CONFIG=$(cat)
DNSMASQ=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen dnsmasq)
ETHERS=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen ethers)
FIREWALL=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen firewall)
# Colorized unified diff with a per-file change summary.
# $1 = label, $2 = current (may be empty), $3 = new
show_diff() {
local label="$1" old="$2" new="$3"
local oldf newf d
oldf=$(mktemp) newf=$(mktemp)
if [ -n "$old" ]; then printf '%s\n' "$old" > "$oldf"; else : > "$oldf"; fi
if [ -n "$new" ]; then printf '%s\n' "$new" > "$newf"; else : > "$newf"; fi
echo ""
echo "=== $label ==="
if d=$(diff -u "$oldf" "$newf"); then
echo " (no changes)"
else
printf '%s\n' "$d" | awk '
/^---/ {printf "\033[2m%s\033[0m\n", $0; next}
/^\+\+\+/ {printf "\033[2m%s\033[0m\n", $0; next}
/^@@/ {printf "\033[36m%s\033[0m\n", $0; next}
/^-/ {printf "\033[31m%s\033[0m\n", $0; next}
/^\+/ {printf "\033[32m%s\033[0m\n", $0; next}
{print}
'
local added removed
added=$(printf '%s\n' "$d" | grep -c '^[+][^+]' || true)
removed=$(printf '%s\n' "$d" | grep -c '^[-][^-]' || true)
echo " -> $added added, $removed removed"
fi
rm -f "$oldf" "$newf"
}
echo "Fetching current config from $SERVER..."
CURRENT_DNSMASQ=$(ssh "$SERVER" 'cat /etc/dnsmasq.conf' 2>/dev/null || echo "")
CURRENT_ETHERS=$(ssh "$SERVER" 'cat /etc/ethers' 2>/dev/null || echo "")
CURRENT_FIREWALL_ALL=$(ssh "$SERVER" 'uci export firewall' 2>/dev/null || echo "")
# Keep only the skyg-managed rule blocks (for the diff)
CURRENT_FIREWALL=$(echo "$CURRENT_FIREWALL_ALL" | awk '/^config /{if(have && block ~ /skyg_/) print block; block=$0; have=1; next}{if(have) block=block ORS $0}END{if(have && block ~ /skyg_/) print block}')
# Drop the header comment from the generated firewall for a clean diff
NEW_FIREWALL=$(echo "$FIREWALL" | tail -n +2)
show_diff "dnsmasq.conf" "$CURRENT_DNSMASQ" "$DNSMASQ"
show_diff "ethers" "$CURRENT_ETHERS" "$ETHERS"
show_diff "firewall (skyg rules)" "$CURRENT_FIREWALL" "$NEW_FIREWALL"
echo ""
echo "skyg firewall rules to be applied:"
echo "$NEW_FIREWALL" | awk -F"'" '/^config rule/{print " " $2}'
echo ""
read -p "Deploy to $SERVER? [y/N] " -n 1 -r < /dev/tty; echo
[[ $REPLY =~ ^[Yy]$ ]] || exit 1
TS=$(date +%Y%m%d-%H%M%S)
# Stage the apply script and the new config files on the router
ssh "$SERVER" 'cat > /tmp/skyg_apply.sh' < "$APPLY_SCRIPT"
echo "$DNSMASQ" | ssh "$SERVER" 'cat > /tmp/dnsmasq.new.conf'
echo "$ETHERS" | ssh "$SERVER" 'cat > /tmp/ethers.new'
echo "$FIREWALL" | ssh "$SERVER" 'cat > /tmp/skyg_firewall.batch'
# Back up, apply, validate, auto-restore on failure (OpenWrt has no bash, use sh)
ssh "$SERVER" "TS=$TS sh /tmp/skyg_apply.sh"
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Renders the same three configs locally into .tmp/openwrt-<router>/ for review
# - no SSH, no uci, no router changes. Run from the repo root. Router name is
# passed as $1 (defaults to glmain).
#
# Expects GENERATOR to be exported by the Nix wrapper before this file's
# content runs (store path of the openwrt-gen package, bin/openwrt-gen inside).
set -euo pipefail
if [ $# -ge 1 ]; then ROUTER="$1"; else ROUTER=glmain; fi
OUTDIR=".tmp/openwrt-$ROUTER"
mkdir -p "$OUTDIR"
CONFIG=$(cat)
echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen dnsmasq > "$OUTDIR/dnsmasq.conf"
echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen ethers > "$OUTDIR/ethers"
echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen firewall > "$OUTDIR/firewall.batch"
echo "Dry-run configs written to $OUTDIR (no router changes made):"
echo " $OUTDIR/dnsmasq.conf"
echo " $OUTDIR/ethers"
echo " $OUTDIR/firewall.batch"
+64
View File
@@ -0,0 +1,64 @@
#!/bin/sh
# Runs ON THE ROUTER (OpenWrt has no bash, this must stay POSIX sh).
# Invoked as: TS=<timestamp> sh skyg-apply.sh
# Expects the new files staged at /tmp/skyg_firewall.batch, /tmp/dnsmasq.new.conf
# and /tmp/ethers.new. Backs up the configs it overrides, applies the new
# firewall/dnsmasq/ethers, ensures bridge-netfilter sysctls are enabled,
# validates, and auto-restores on failure.
set -euo pipefail
BK=/etc/skyg-backups
mkdir -p "$BK"
cp /etc/config/firewall "$BK/firewall.$TS"
cp /etc/dnsmasq.conf "$BK/dnsmasq.conf.$TS"
cp /etc/ethers "$BK/ethers.$TS" 2>/dev/null || true
cp /etc/sysctl.conf "$BK/sysctl.conf.$TS" 2>/dev/null || true
# --- sysctl: enable bridge netfilter ---
# All of this router's "networks" (apl, cam, lab, ...) are just address
# ranges on one flat L2 bridge (br-lan, single /16 across the whole LAN) --
# there's no real VLAN separation. Without bridge-nf-call-iptables, unicast
# traffic between two hosts on the same bridge is switched at L2 and never
# reaches the FORWARD chain, so the skyg_* DROP rules below silently never
# fire. /etc/sysctl.d/*.conf ships bridge-nf-call-* disabled and is reset on
# firmware upgrades, but /etc/sysctl.conf is applied last and persists.
if ! grep -q '^# BEGIN skyg-managed$' /etc/sysctl.conf 2>/dev/null; then
{
echo ''
echo '# BEGIN skyg-managed'
echo 'net.bridge.bridge-nf-call-iptables=1'
echo 'net.bridge.bridge-nf-call-ip6tables=1'
echo '# END skyg-managed'
} >> /etc/sysctl.conf
fi
sysctl -e -p /etc/sysctl.conf >/dev/null
# --- Firewall: replace the skyg-managed rules ---
for ref in $(uci show firewall | grep -E '^firewall\.skyg_[^.=]+=' | cut -d= -f1); do
uci -q del "$ref" || true
done
if ! uci -m import firewall < /tmp/skyg_firewall.batch; then
echo 'FIREWALL: uci import failed, restoring'
cp "$BK/firewall.$TS" /etc/config/firewall
exit 1
fi
if ! uci commit firewall; then
echo 'FIREWALL: uci commit failed, restoring'
cp "$BK/firewall.$TS" /etc/config/firewall
exit 1
fi
/etc/init.d/firewall reload
# --- dnsmasq ---
cp /tmp/dnsmasq.new.conf /etc/dnsmasq.conf
if dnsmasq --test; then
/etc/init.d/dnsmasq restart
else
echo 'dnsmasq config invalid, restoring'
cp "$BK/dnsmasq.conf.$TS" /etc/dnsmasq.conf
exit 1
fi
# --- ethers ---
cp /tmp/ethers.new /etc/ethers
echo 'Done'
+480
View File
@@ -0,0 +1,480 @@
Script started on 2026-08-27 12:53:46-04:00 [TERM="xterm-ghostty" TTY="/dev/pts/5" COLUMNS="90" LINES="46"]
complete: command not found
\[\][\[]0;ari@fwbook: ~/nixos-setup\]ari@fwbook:~/nixos-setup]$\[\] skyg openwrt
warning: unknown setting 'eval-cores'
warning: unknown setting 'lazy-trees'
Decrypted to .tmp/unencrypted-glmain.json
[?25l␍␍warning: Git tree '/home/ari/nixos-setup' has uncommitted changes
␍␍[?25hFetching current config from root@10.0.0.1...
=== dnsmasq.conf ===
(no changes)
=== ethers ===
(no changes)
=== firewall (skyg rules) ===
(no changes)
skyg firewall rules to be applied:
skyg_cam_drop_lan
skyg_cam_drop_lan_v6_9C8ECD25831F
skyg_cam_drop_lan_v6_A0603203868A
skyg_cam_drop_lan_v6_489E9D4A3280
skyg_cam_drop_lan_v6_EC71DBA1078C
skyg_cam_drop_lan_v6_3460F9D7513F
skyg_cam_drop_lan_v6_EC71DB0C5A6E
skyg_cam_drop_lan_v6_EC71DB2E6FF5
skyg_mac_489EBDCB07E3_drop_lan
skyg_mac_489EBDCB07E3_drop_lan_v6
skyg_mac_CC6A108B7DD3_drop_lan
skyg_mac_CC6A108B7DD3_drop_lan_v6
skyg_mac_F0704F54F3F0_drop_lan
skyg_mac_F0704F54F3F0_drop_lan_v6
skyg_mac_3CE90E6214D8_drop_lan
skyg_mac_3CE90E6214D8_drop_lan_v6
skyg_mac_1C9DC23961F8_drop_lan
skyg_mac_1C9DC23961F8_drop_lan_v6
skyg_mac_D8BE65F2ED18_drop_lan
skyg_mac_D8BE65F2ED18_drop_lan_v6
skyg_mac_B04A39F7E58E_drop_lan
skyg_mac_B04A39F7E58E_drop_lan_v6
skyg_mac_001BA9B937B7_drop_lan
skyg_mac_001BA9B937B7_drop_lan_v6
skyg_mac_FCEE28064754_drop_lan
skyg_mac_FCEE28064754_drop_lan_v6
skyg_mac_6074F44DB8C5_drop_lan
skyg_mac_6074F44DB8C5_drop_lan_v6
skyg_mac_DC4F22240CE4_drop_lan
skyg_mac_DC4F22240CE4_drop_lan_v6
skyg_mac_446132FC10EC_drop_lan
skyg_mac_446132FC10EC_drop_lan_v6
skyg_mac_9483C431D5CE_drop_lan
skyg_mac_9483C431D5CE_drop_lan_v6
Deploy to root@10.0.0.1? [y/N] y
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
Warning: Option @zone[1].masq6 is unknown
Warning: Section @zone[1] (wan) cannot resolve device of network 'wwan'
Warning: Section @zone[1] (wan) cannot resolve device of network 'secondwan'
Warning: Option 'sambasharewan'.dest_proto is unknown
Warning: Section 'sambasharewan' does not specify a protocol, assuming TCP+UDP
Warning: Option 'sambasharelan'.dest_proto is unknown
Warning: Section 'sambasharelan' does not specify a protocol, assuming TCP+UDP
Warning: Option 'glnas_ser'.dest_proto is unknown
Warning: Section 'glnas_ser' does not specify a protocol, assuming TCP+UDP
Warning: Option 'webdav_wan'.dest_proto is unknown
Warning: Section 'webdav_wan' does not specify a protocol, assuming TCP+UDP
Warning: Section 'wgserver_drop_leaked_dns' refers to not existing zone 'wgserver'
Warning: Section 'ovpnserver_drop_leaked_dns' refers to not existing zone 'ovpnserver'
Warning: Section 'wgserver_drop_leaked_adgdns' refers to not existing zone 'wgserver'
Warning: Section 'ovpnserver_drop_leaked_adgdns' refers to not existing zone 'ovpnserver'
Warning: Section @redirect[0] (GL-) has no target specified, defaulting to DNAT
Warning: Section @redirect[1] (GL-) has no target specified, defaulting to DNAT
* Clearing IPv4 filter table
* Clearing IPv4 nat table
* Clearing IPv4 mangle table
* Clearing IPv4 raw table
* Populating IPv4 filter table
* Rule 'guest_drop_leaked_dns'
* Rule 'guest_drop_leak_adgdns'
* Rule 'Allow-DHCP-Renew'
* Rule 'Allow-IGMP'
* Rule 'Allow-IPSec-ESP'
* Rule 'Allow-ISAKMP'
* Rule 'Allow-DHCP'
* Rule 'Allow-DNS'
* Rule #12
* Rule #13
* Rule #14
* Rule #15
* Rule 'lan_drop_leaked_dns'
* Rule 'lan_drop_leak_adgdns'
* Rule #20
* Rule #28
* Rule #30
* Rule #32
* Rule #34
* Rule #36
* Rule #38
* Rule #40
* Rule #42
* Rule #44
* Rule #46
* Rule #48
* Rule #50
* Rule #52
* Redirect 'GL-'
* Redirect 'GL-'
* Forward 'lan' -> 'wan'
* Forward 'guest' -> 'wan'
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv4 nat table
* Redirect 'GL-'
* Redirect 'GL-'
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv4 mangle table
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv4 raw table
* Zone 'lan'
- Using automatic conntrack helper attachment
* Zone 'wan'
* Zone 'guest'
- Using automatic conntrack helper attachment
* Clearing IPv6 filter table
* Clearing IPv6 nat table
* Clearing IPv6 mangle table
* Clearing IPv6 raw table
* Populating IPv6 filter table
* Rule 'guest_drop_leaked_dns'
* Rule 'guest_drop_leak_adgdns'
* Rule 'Allow-DHCPv6'
* Rule 'Allow-MLD'
* Rule 'Allow-ICMPv6-Input'
* Rule 'Allow-ICMPv6-Forward'
* Rule 'Allow-IPSec-ESP'
* Rule 'Allow-ISAKMP'
* Rule 'Allow-DHCP'
* Rule 'Allow-DNS'
* Rule #12
* Rule #13
* Rule #14
* Rule #15
* Rule 'Allow-DHCP-IPV6'
* Rule 'Allow-ICMP-IPV6'
* Rule 'lan_drop_leaked_dns'
* Rule 'lan_drop_leak_adgdns'
* Rule #21
* Rule #22
* Rule #23
* Rule #24
* Rule #25
* Rule #26
* Rule #27
* Rule #29
* Rule #31
* Rule #33
* Rule #35
* Rule #37
* Rule #39
* Rule #41
* Rule #43
* Rule #45
* Rule #47
* Rule #49
* Rule #51
* Rule #53
* Forward 'lan' -> 'wan'
* Forward 'guest' -> 'wan'
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv6 nat table
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv6 mangle table
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv6 raw table
* Zone 'lan'
- Using automatic conntrack helper attachment
* Zone 'wan'
* Zone 'guest'
- Using automatic conntrack helper attachment
* Set tcp_ecn to off
* Set tcp_syncookies to on
* Set tcp_window_scaling to on
* Running script '/etc/firewall.nat6'
nat6: Firewall config="cfg06dc81" zone="lan" zone_masq6="0".
nat6: Firewall config="cfg07dc81" zone="wan" zone_masq6="1".
nat6: Found firewall zone_name="wan" with zone_masq6="1" zone_masq6_privacy="1".
nat6: Setting up masquerading nat6 for zone_name="wan" with zone_masq6_privacy="1"
nat6: Ensuring ip6tables chain="zone_wan_postrouting" contains our MASQUERADE.
nat6: Ensuring ip6tables chain="zone_wan_input" contains our permissive DNAT rule.
nat6: Ensuring ip6tables chain="zone_wan_forward" contains our permissive DNAT rule.
nat6: Found device="eth1" for network_name="wan".
nat6: Enabling IPv6 temporary addresses for device="eth1".
nat6: Accepting router advertisements on eth1 even if forwarding is enabled (required for temporary addresses)
nat6: Using temporary addresses for outgoing connections on interface eth1
nat6: Already configured device="eth1", so leaving as is.
nat6: Done setting up nat6 for zone="wan" on devices: eth1
nat6: Firewall config="cfg13dc81" zone="guest" zone_masq6="0".
* Running script '/etc/firewall.dns_order'
* Running script '/usr/bin/gl_block.sh'
* Running script '/etc/firewall.dmz.exclude'
dnsmasq: syntax check OK.
udhcpc: started, v1.33.2
udhcpc: sending discover
udhcpc: no lease, failing
Done
\[\][\[]0;ari@fwbook: ~/nixos-setup\]ari@fwbook:~/nixos-setup]$\[\] ^[[A    skyg openwrt
warning: unknown setting 'eval-cores'
warning: unknown setting 'lazy-trees'
Decrypted to .tmp/unencrypted-glmain.json
[?25l␍␍warning: Git tree '/home/ari/nixos-setup' has uncommitted changes
␍␍[?25hFetching current config from root@10.0.0.1...
=== dnsmasq.conf ===
(no changes)
=== ethers ===
(no changes)
=== firewall (skyg rules) ===
(no changes)
skyg firewall rules to be applied:
skyg_cam_drop_lan
skyg_cam_drop_lan_v6_9C8ECD25831F
skyg_cam_drop_lan_v6_A0603203868A
skyg_cam_drop_lan_v6_489E9D4A3280
skyg_cam_drop_lan_v6_EC71DBA1078C
skyg_cam_drop_lan_v6_3460F9D7513F
skyg_cam_drop_lan_v6_EC71DB0C5A6E
skyg_cam_drop_lan_v6_EC71DB2E6FF5
skyg_mac_489EBDCB07E3_drop_lan
skyg_mac_489EBDCB07E3_drop_lan_v6
skyg_mac_CC6A108B7DD3_drop_lan
skyg_mac_CC6A108B7DD3_drop_lan_v6
skyg_mac_F0704F54F3F0_drop_lan
skyg_mac_F0704F54F3F0_drop_lan_v6
skyg_mac_3CE90E6214D8_drop_lan
skyg_mac_3CE90E6214D8_drop_lan_v6
skyg_mac_1C9DC23961F8_drop_lan
skyg_mac_1C9DC23961F8_drop_lan_v6
skyg_mac_D8BE65F2ED18_drop_lan
skyg_mac_D8BE65F2ED18_drop_lan_v6
skyg_mac_B04A39F7E58E_drop_lan
skyg_mac_B04A39F7E58E_drop_lan_v6
skyg_mac_001BA9B937B7_drop_lan
skyg_mac_001BA9B937B7_drop_lan_v6
skyg_mac_FCEE28064754_drop_lan
skyg_mac_FCEE28064754_drop_lan_v6
skyg_mac_6074F44DB8C5_drop_lan
skyg_mac_6074F44DB8C5_drop_lan_v6
skyg_mac_DC4F22240CE4_drop_lan
skyg_mac_DC4F22240CE4_drop_lan_v6
skyg_mac_446132FC10EC_drop_lan
skyg_mac_446132FC10EC_drop_lan_v6
skyg_mac_9483C431D5CE_drop_lan
skyg_mac_9483C431D5CE_drop_lan_v6
Deploy to root@10.0.0.1? [y/N] y
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
** WARNING: connection is not using a post-quantum key exchange algorithm.␍
** This session may be vulnerable to "store now, decrypt later" attacks.␍
** The server may need to be upgraded. See https://openssh.com/pq.html␍
Warning: remote port forwarding failed for listen path /tmp/ssh-notify.sock␍
Warning: Option @zone[1].masq6 is unknown
Warning: Section @zone[1] (wan) cannot resolve device of network 'wwan'
Warning: Section @zone[1] (wan) cannot resolve device of network 'secondwan'
Warning: Option 'sambasharewan'.dest_proto is unknown
Warning: Section 'sambasharewan' does not specify a protocol, assuming TCP+UDP
Warning: Option 'sambasharelan'.dest_proto is unknown
Warning: Section 'sambasharelan' does not specify a protocol, assuming TCP+UDP
Warning: Option 'glnas_ser'.dest_proto is unknown
Warning: Section 'glnas_ser' does not specify a protocol, assuming TCP+UDP
Warning: Option 'webdav_wan'.dest_proto is unknown
Warning: Section 'webdav_wan' does not specify a protocol, assuming TCP+UDP
Warning: Section 'wgserver_drop_leaked_dns' refers to not existing zone 'wgserver'
Warning: Section 'ovpnserver_drop_leaked_dns' refers to not existing zone 'ovpnserver'
Warning: Section 'wgserver_drop_leaked_adgdns' refers to not existing zone 'wgserver'
Warning: Section 'ovpnserver_drop_leaked_adgdns' refers to not existing zone 'ovpnserver'
Warning: Section @redirect[0] (GL-) has no target specified, defaulting to DNAT
Warning: Section @redirect[1] (GL-) has no target specified, defaulting to DNAT
* Clearing IPv4 filter table
* Clearing IPv4 nat table
* Clearing IPv4 mangle table
* Clearing IPv4 raw table
* Populating IPv4 filter table
* Rule 'guest_drop_leaked_dns'
* Rule 'guest_drop_leak_adgdns'
* Rule 'Allow-DHCP-Renew'
* Rule 'Allow-IGMP'
* Rule 'Allow-IPSec-ESP'
* Rule 'Allow-ISAKMP'
* Rule 'Allow-DHCP'
* Rule 'Allow-DNS'
* Rule #12
* Rule #13
* Rule #14
* Rule #15
* Rule 'lan_drop_leaked_dns'
* Rule 'lan_drop_leak_adgdns'
* Rule #20
* Rule #28
* Rule #30
* Rule #32
* Rule #34
* Rule #36
* Rule #38
* Rule #40
* Rule #42
* Rule #44
* Rule #46
* Rule #48
* Rule #50
* Rule #52
* Redirect 'GL-'
* Redirect 'GL-'
* Forward 'lan' -> 'wan'
* Forward 'guest' -> 'wan'
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv4 nat table
* Redirect 'GL-'
* Redirect 'GL-'
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv4 mangle table
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv4 raw table
* Zone 'lan'
- Using automatic conntrack helper attachment
* Zone 'wan'
* Zone 'guest'
- Using automatic conntrack helper attachment
* Clearing IPv6 filter table
* Clearing IPv6 nat table
* Clearing IPv6 mangle table
* Clearing IPv6 raw table
* Populating IPv6 filter table
* Rule 'guest_drop_leaked_dns'
* Rule 'guest_drop_leak_adgdns'
* Rule 'Allow-DHCPv6'
* Rule 'Allow-MLD'
* Rule 'Allow-ICMPv6-Input'
* Rule 'Allow-ICMPv6-Forward'
* Rule 'Allow-IPSec-ESP'
* Rule 'Allow-ISAKMP'
* Rule 'Allow-DHCP'
* Rule 'Allow-DNS'
* Rule #12
* Rule #13
* Rule #14
* Rule #15
* Rule 'Allow-DHCP-IPV6'
* Rule 'Allow-ICMP-IPV6'
* Rule 'lan_drop_leaked_dns'
* Rule 'lan_drop_leak_adgdns'
* Rule #21
* Rule #22
* Rule #23
* Rule #24
* Rule #25
* Rule #26
* Rule #27
* Rule #29
* Rule #31
* Rule #33
* Rule #35
* Rule #37
* Rule #39
* Rule #41
* Rule #43
* Rule #45
* Rule #47
* Rule #49
* Rule #51
* Rule #53
* Forward 'lan' -> 'wan'
* Forward 'guest' -> 'wan'
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv6 nat table
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv6 mangle table
* Zone 'lan'
* Zone 'wan'
* Zone 'guest'
* Populating IPv6 raw table
* Zone 'lan'
- Using automatic conntrack helper attachment
* Zone 'wan'
* Zone 'guest'
- Using automatic conntrack helper attachment
* Set tcp_ecn to off
* Set tcp_syncookies to on
* Set tcp_window_scaling to on
* Running script '/etc/firewall.nat6'
nat6: Firewall config="cfg06dc81" zone="lan" zone_masq6="0".
nat6: Firewall config="cfg07dc81" zone="wan" zone_masq6="1".
nat6: Found firewall zone_name="wan" with zone_masq6="1" zone_masq6_privacy="1".
nat6: Setting up masquerading nat6 for zone_name="wan" with zone_masq6_privacy="1"
nat6: Ensuring ip6tables chain="zone_wan_postrouting" contains our MASQUERADE.
nat6: Ensuring ip6tables chain="zone_wan_input" contains our permissive DNAT rule.
nat6: Ensuring ip6tables chain="zone_wan_forward" contains our permissive DNAT rule.
nat6: Found device="eth1" for network_name="wan".
nat6: Enabling IPv6 temporary addresses for device="eth1".
nat6: Accepting router advertisements on eth1 even if forwarding is enabled (required for temporary addresses)
nat6: Using temporary addresses for outgoing connections on interface eth1
nat6: Already configured device="eth1", so leaving as is.
nat6: Done setting up nat6 for zone="wan" on devices: eth1
nat6: Firewall config="cfg13dc81" zone="guest" zone_masq6="0".
* Running script '/etc/firewall.dns_order'
* Running script '/usr/bin/gl_block.sh'
* Running script '/etc/firewall.dmz.exclude'
dnsmasq: syntax check OK.
udhcpc: started, v1.33.2
udhcpc: sending discover
Done
udhcpc: no lease, failing
\[\][\[]0;ari@fwbook: ~/nixos-setup\]ari@fwbook:~/nixos-setup]$\[\]
\[\][\[]0;ari@fwbook: ~/nixos-setup\]ari@fwbook:~/nixos-setup]$\[\] ^C
\[\][\[]0;ari@fwbook: ~/nixos-setup\]ari@fwbook:~/nixos-setup]$\[\] exit
Script done on 2026-08-27 12:54:13-04:00 [COMMAND_EXIT_CODE="130"]