better openwrt sub lan control

This commit is contained in:
ari committed 2026-08-26 16:31:48 -04:00
1 parent 07d5bffef2
commit e3866d75a9
15 files changed
+384 -573

No files matched your search

+23 -4
View File
@@ -15,17 +15,19 @@ generator/
│ ├── config.rs # serde Deserialize structs for the input JSON (+ unit tests)
│ ├── network.rs # process_network — expands per-network device lists
│ └── generators/
│ ├── mod.rs # re-exports dnsmasq + ethers
│ ├── mod.rs # re-exports dnsmasq + ethers + firewall
│ ├── dnsmasq.rs # renders dnsmasq.conf (server= + address= lines)
│ └── ethers.rs # renders /etc/ethers (MAC → name/IP)
│ ├── ethers.rs # renders /etc/ethers (MAC → name/IP)
│ └── firewall.rs # renders UCI firewall rules (internet-only networks)
└── target/ # gitignored Cargo build output — ignore it
```
## Usage
```
openwrt-gen dnsmasq < config.json # prints dnsmasq.conf
openwrt-gen ethers < config.json # prints /etc/ethers
openwrt-gen dnsmasq < config.json # prints dnsmasq.conf
openwrt-gen ethers < config.json # prints /etc/ethers
openwrt-gen firewall < config.json # prints UCI firewall rules (uci batch format)
```
## Input shape (`config.rs`)
@@ -33,6 +35,23 @@ openwrt-gen ethers < config.json # prints /etc/ethers
- `generalMappings`: `[{ ip, domains[] }]` — shared domain→IP records.
- `networks`: `{ <network>: [ { mac, name, id?, domains?, justMac? } ] }` — per-network hosts.
- `dnsResolvers`: `[{ ip, port?, name? }]` — upstream `server=` entries for dnsmasq.
- `internetOnly`: `[<network>, ...]` — networks restricted to internet-only access.
## Internet-only firewall rules (`firewall.rs`)
For each network in `internetOnly`, the generator emits UCI `config rule` blocks that DROP
forwarded traffic from that network to the rest of the LAN (`10.0.0.0/16`):
- **IPv4** — one rule per network matching the whole subnet (catches every device on it).
- **IPv6** — one rule per known device MAC. All subnets share a single ULA /64
(`fd59:de0a:bff5::/48`, see `network::ULA_PREFIX`), so subnets are not distinguishable
in IPv6 and blocking is done per known device. An *unknown* IPv6-only device on those
subnets is **not** blocked (inherent to the flat-L2 topology).
Rules are named `skyg_<network>_drop_lan` (IPv4) and `skyg_<network>_drop_lan_v6` (IPv6) so
the deploy script owns exactly these. They are inserted before port-specific ACCEPT rules
(e.g. the existing `sambasharelan`) so the DROPs win. Reverse direction (LAN → restricted
network) stays open, and within-subnet traffic (e.g. cam→cam) is blocked.
## Conventions