Fix peer IP allocation: fill subnet gaps, sort peers by IP, backup config - #80
Open
leonidorlov-hash wants to merge 1 commit into
Open
Fix peer IP allocation: fill subnet gaps, sort peers by IP, backup config#80leonidorlov-hash wants to merge 1 commit into
leonidorlov-hash wants to merge 1 commit into
Conversation
…nfig - _get_next_ip now returns the first free address in the subnet instead of incrementing the last IP found in file order, which could hand out duplicate IPs and never reused addresses freed by deleted clients - new peers are inserted into the server config keeping [Peer] sections sorted by AllowedIPs - a timestamped backup of the config is created inside the container before it is overwritten
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_get_next_ip()inmanagers/awg_manager.pyandmanagers/wireguard_manager.pytook the last IP in config file order and incremented it. This caused:awg0.conf/wg0.confare not sorted ascending (after manual edits, migrations, deletions), the next client could get anAllowedIPsalready used by another peer. WireGuard then applies only the last matching[Peer], breaking one of the clients.10.8.1.5) left the address unused forever; new clients kept getting higher IPs.awg_managerproduced invalid octets (254 → 257,255 → 257).Fix
_get_next_ip()now collects all used addresses into a set and returns the first free IP in the subnet (.2–.254), filling gaps. Raises a clear error when the subnet is exhausted.>> config). A new helper_insert_peer_sorted()rewrites the config with all[Peer]sections sorted by AllowedIPs, keeping the[Interface]header intact.awg0.conf.bak.YYYYMMDD_HHMMSS) is created inside the container.Notes