NetGuard Subsystem
NetGuard state machine, D-Bus daemon, and fail-closed firewall enforcement.
5 min readUpdated: 2026-11-12
Snigdha NetGuard — Firewall Policy Specification
1. Overview
The Snigdha NetGuard firewall is the primary enforcement mechanism preventing clearnet packet leakage in Snigdha OS Decentralized. It is written exclusively for the modern Linux nftables netfilter framework, replacing legacy iptables rulesets with atomic, unified IPv4/IPv6 packet processing.
2. Table Ownership and Scoping
- Table Family:
inet(processes dual-stack IPv4 and IPv6 traffic simultaneously). - Table Name:
snigdha(table inet snigdha). - Isolation Guarantee: The ruleset owns only
table inet snigdha. It explicitly avoidsflush ruleset. To modify or reload the ruleset atomically:
Unrelated packet filters, virtualization bridges (KVM/libvirt), or user network namespaces remain untouched.add table inet snigdha delete table inet snigdha table inet snigdha { ... }
3. Chains and Hook Priorities
4. Address Sets
The firewall maintains four static and dynamic interval sets:
set tor_bootstrap_dns_v4: Dynamically populated by NetworkManager dispatcher during interface activation. Contains DHCP-provided IPv4 DNS servers.set tor_bootstrap_dns_v6: Dynamically populated by NetworkManager dispatcher. Contains DHCP-provided IPv6 DNS servers.set private_networks_v4: Static interval set covering RFC 1918, link-local, carrier-grade NAT, and broadcast ranges:10.0.0.0/8,127.0.0.0/8,169.254.0.0/16,172.16.0.0/12,192.168.0.0/16,224.0.0.0/4,240.0.0.0/4
set private_networks_v6: Static interval set covering IPv6 loopback, ULA, link-local, and multicast:::1/128,fc00::/7,fe80::/10,ff00::/8
5. Chain Rules & Evaluation Logic
5.1 chain nat_output (Destination NAT Hook)
Executed before the routing decision for locally generated outbound packets:
- Loopback Exemption:
oif "lo" returnPrevents redirecting traffic already destined for loopback interfaces. - Tor Daemon Exemption:
meta skuid 43 returnPrevents Tor's own outbound connection traffic to guard relays or bridges from looping back into its transparent listener. - DNS Redirection:
udp dport 53 redirect to :5353Intercepts all outbound UDP DNS requests and alters destination port to Tor'sDNSPort(5353). - Private Network Return:
ip daddr @private_networks_v4 returnip6 daddr @private_networks_v6 returnPackets destined for RFC 1918 or local subnets exit the NAT chain unredirected and are subsequent dropped by the filter chain. - TCP Transparent Redirection:
meta l4proto tcp redirect to :9040Intercepts all outbound TCP connections and alters destination port to Tor'sTransPort(9040).
5.2 chain output (Filter Hook)
Executed after routing and destination NAT:
- Loopback Traffic:
oif "lo" acceptAccepts local inter-process communication. - Redirected Tor Listeners:
Accepts packets whose destinations were rewritten byip daddr 127.0.0.1 tcp dport 9040 accept ip6 daddr ::1 tcp dport 9040 accept ip daddr 127.0.0.1 udp dport 5353 accept ip6 daddr ::1 udp dport 5353 acceptnat_outputto Tor's local ports. - Connection State Tracking:
ct state established,related acceptct state invalid drop - Tor Service Identity Exemption:
meta skuid 43 acceptAllows the Tor daemon (UID 43) to initiate outbound connections to guard nodes, relays, and bridges. - Tor Bootstrap DNS Resolution:
Permits Tor (and Tor alone) to query DHCP-provided DNS servers to resolve bridge hostnames.meta skuid 43 udp dport 53 ip daddr @tor_bootstrap_dns_v4 accept meta skuid 43 tcp dport 53 ip daddr @tor_bootstrap_dns_v4 accept meta skuid 43 udp dport 53 ip6 daddr @tor_bootstrap_dns_v6 accept meta skuid 43 tcp dport 53 ip6 daddr @tor_bootstrap_dns_v6 accept - DHCP Client Protocol:
udp sport 68 udp dport 67 acceptAllows local network DHCP requests necessary for network link association. - IPv6 Discovery: Allows ICMPv6 router discovery, neighbor discovery, and packet-too-big MTU messages.
- DHCPv6 Client Protocol:
ip6 nexthdr udp udp sport 546 udp dport 547 accept - DNS Leak Prevention:
udp dport 53 droptcp dport 53 dropudp dport 853 droptcp dport 853 drop - UDP Leak Prevention:
meta l4proto udp dropDrops all other outbound UDP packets, eliminating QUIC, NTP, and STUN leaks. - Default Policy:
drop(fail-closed).
5.3 chain input (Filter Hook)
Filters inbound packets arriving at the host:
iif "lo" accept(Accept loopback).ct state established,related accept(Accept responses to valid outbound flows).ct state invalid drop.udp sport 67 udp dport 68 accept(Accept DHCP server leases).ip6 nexthdr icmpv6 ... accept(Accept ICMPv6 router/neighbor discovery).ip6 nexthdr udp udp sport 547 udp dport 546 accept(Accept DHCPv6 leases).- Default policy:
drop.
6. Pre-Activation Validation
Firewall reload operations are governed by /etc/systemd/system/snigdha-firewall.service:
ExecStartPre=/usr/bin/nft -c -f /etc/nftables.d/snigdha.nftExecStart=/usr/bin/nft -f /etc/nftables.d/snigdha.nft- If syntax or netlink parsing fails, systemd rejects the unit, NetworkManager is prevented from starting, and the live system remains isolated from clearnet.