From 0db3f5293181b4a12bbc134cc95aef2f2b779082 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 14 Sep 2022 18:42:13 +0200 Subject: [PATCH] Add methods to remove WireGuard default gateways --- Sources/TunnelKitWireGuardCore/Configuration.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/TunnelKitWireGuardCore/Configuration.swift b/Sources/TunnelKitWireGuardCore/Configuration.swift index a0b60ef..56b8325 100644 --- a/Sources/TunnelKitWireGuardCore/Configuration.swift +++ b/Sources/TunnelKitWireGuardCore/Configuration.swift @@ -176,6 +176,18 @@ extension WireGuard { $0 == Self.defaultGateway6 } } + + public mutating func removeDefaultGateways(fromPeer peerIndex: Int) { + peers[peerIndex].allowedIPs.removeAll { + $0 == Self.defaultGateway4 || $0 == Self.defaultGateway6 + } + } + + public mutating func removeAllDefaultGateways() { + peers.indices.forEach { + removeDefaultGateways(fromPeer: $0) + } + } public mutating func addAllowedIP(_ allowedIP: String, toPeer peerIndex: Int) { guard let addr = IPAddressRange(from: allowedIP) else {