Feature - add gl-sdk4-wireguard-ipv4-only — enforce IPv4-only on WireGuard when Global IPv6 is disabled#20
Conversation
- Introduced a new init script `wg-noipv6` to manage IPv4-only enforcement based on the `enable_ipv6` toggle for each WireGuard server. - Created a UCI defaults script `80-wg-noipv6` to initialize the `enable_ipv6` option for existing WireGuard server configurations. - Implemented an RPC interface `wireguard_ipv4_only` to read and write the `enable_ipv6` toggle, allowing for dynamic configuration changes. - Added shared functions in `functions.sh` for managing WireGuard server states, including validation, enforcement, and cleanup. - Developed the main script `wg-noipv6` to handle commands for syncing, applying, clearing, and checking the status of IPv4-only enforcement. - Included versioning information in `version.mk` for tracking changes.
- Consolidated logging functions for better readability and consistency. - Simplified validation checks for interface names and configuration sections. - Enhanced the global IPv6 state check to streamline enforcement logic. - Removed redundant comments and improved function documentation. - Updated the status command to provide clearer output regarding enforcement status. - Streamlined the application of IPv4-only enforcement for both GL.iNet and netifd interfaces. - Improved error handling and messaging for invalid device names. - Removed deprecated code and consolidated similar functionalities for maintainability.
- Bump package release version to 5. - Improve package description for clarity. - Update README to reflect new functionality and clarify the restoration process. - Modify hotplug scripts to ensure quiet logging and handle stale enforcement. - Enhance init script to maintain clean logs and ensure proper service reloads. - Add snapshot and restore functionality for UCI configurations to allow seamless re-enabling of IPv6. - Improve logging functions to provide better feedback on enforcement status. - Refactor enforcement application logic to streamline the process for both GL.iNet and netifd interfaces. - Ensure proper cleanup during package removal to restore previous configurations.
…onality in wg-noipv6 script
…kage release version
|
Let me know if any concerns or if anything else here to review for inclusion in the next round of updates? Been testing on my current version and builds here For manual testing until included in main code: Instructions here: Click tab: gl-sdk4-wireguard-ipv4-only Uses the branch of code referenced here Then the site mentions everything about it as well Mainline OpenWrt on Cortex-A53 (ipq60xx / ipq807x) OR GL.iNet ApNos firmware (AXT1800 / AX1800, 23.05-based) Then once repro is referenced (if using my repro with it built and not one built yourself) Install the package:
More background opened up here too: Let me know if any concerns or need anything else Thank you again for the time! |
Summary
Adds a new package,
gl-sdk4-wireguard-ipv4-only, that keys IPv4-only WireGuard enforcement off the existing global IPv6 toggle on/#/ipv6— no new GUI control. When the user disables IPv6, the package strips IPv6 from every WireGuard server / netifd-WG section (kernel device, UCI, live peer programming, firewall) and saves snapshots so the original config can be fully restored when IPv6 is re-enabled or the package is removed.Use case: customers who want IPv4-only WireGuard without manually editing UCI per peer, and who already use
/#/ipv6as their single source of truth for IPv6 on the router.What it does, step by step
When
wg-noipv6 syncruns:glconfig.general.enable_ipv6→network.wan6.disabled→network.wan6.proto=none→network.wan6.auto=0→ default1.wireguard_serversection and every netifdproto=wireguardinterface:/etc/wg-noipv6/backup/).address_v6, IPv6 entries from peerclient_ip/allowed_ips, and IPv6 entries from netifdaddresses. Pinnetwork.<wg>.ipv6=0.wg set ... allowed-ips, refusing to clear a peer entirely./etc/sysctl.d/99-wg-noipv6-<dev>.conf) settingnet.ipv6.conf.<dev>.disable_ipv6 = 1./etc/nftables.d/ifnft/fw4are present, else fw3 ip6tables script + UCI include.wireguard_serverto repush peer programming.Triggers (multiple, defense-in-depth)
The
/#/ipv6toggle behaves inconsistently across firmware revisions, so the package listens through several channels:wireguard_server,network,firewall,glconfig./etc/hotplug.d/iface/99-wg-noipv6) — reacts toifupon tracked WG sections and toifup/ifdownonwan6(the most reliable enable-side signal)./etc/hotplug.d/net/99-wg-noipv6) — required becausewireguard_serverbringswgserverup without firing netifdifup.* * * * * wg-noipv6 cron-tick) — silent unless the global IPv6 state actually changed since last tick. Catches the disable path on firmware revisions where the GUI commitsglconfig.general.enable_ipv6=0without firing any procd/hotplug event.Surfaces
/usr/sbin/wg-noipv6):sync,apply <dev>,clear <dev>,clear-all,status,cron-tick.statusprints PASS/FAIL audit per WG section with extra[INFO]lines (UCIaddress_v6, peer IPv6 count, live kernel-device IPv6 count) so you can confirm at a glance what's there./usr/lib/oui-httpd/rpc/wireguard_ipv4_only):get_statusreturns{global_ipv6_enabled, servers: [...]};synctriggers a reconcile.Uninstall safety
opkg removerunswg-noipv6 clear-all, which:firewall→wireguard_server→network, in safe order, via a deferred-kick mode on the kick helpers. (Earlier iterations triggered cascading reloads that briefly blackholed the router's own outbound traffic, including DNS.)Validation
dash -nclean on all 6 shell files.shellcheck --shell=ash --severity=warningclean (only the long-known SC2034 false-positives onSTART/STOP/USE_PROCDconsumed by/etc/rc.common).luac -pclean on the JSON-RPC module.Files
Notes
PKGARCH:=all(pure shell + Lua, no compiled artifacts).wireguard-tools./#/ipv6toggle is the user-facing control.daemon.notice/daemon.warnunder tagwg-noipv6(matches the conventions used by dropbear / mwan3 / dnscrypt-proxy).