-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add network extension manager
- Loading branch information
1 parent
4d0b3da
commit 7e24349
Showing
10 changed files
with
406 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import NetworkExtension | ||
import os | ||
|
||
// swiftlint:disable function_body_length | ||
public func convertNetworkSettingsRequest(_ req: Vpn_NetworkSettingsRequest) -> NEPacketTunnelNetworkSettings { | ||
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: req.tunnelRemoteAddress) | ||
networkSettings.tunnelOverheadBytes = NSNumber(value: req.tunnelOverheadBytes) | ||
networkSettings.mtu = NSNumber(value: req.mtu) | ||
|
||
if req.hasDnsSettings { | ||
let dnsSettings = NEDNSSettings(servers: req.dnsSettings.servers) | ||
dnsSettings.searchDomains = req.dnsSettings.searchDomains | ||
dnsSettings.domainName = req.dnsSettings.domainName | ||
dnsSettings.matchDomains = req.dnsSettings.matchDomains | ||
dnsSettings.matchDomainsNoSearch = req.dnsSettings.matchDomainsNoSearch | ||
networkSettings.dnsSettings = dnsSettings | ||
} | ||
|
||
if req.hasIpv4Settings { | ||
let ipv4Settings = NEIPv4Settings(addresses: req.ipv4Settings.addrs, subnetMasks: req.ipv4Settings.subnetMasks) | ||
ipv4Settings.router = req.ipv4Settings.router | ||
ipv4Settings.includedRoutes = req.ipv4Settings.includedRoutes.map { | ||
let route = NEIPv4Route(destinationAddress: $0.destination, subnetMask: $0.mask) | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
ipv4Settings.excludedRoutes = req.ipv4Settings.excludedRoutes.map { | ||
let route = NEIPv4Route(destinationAddress: $0.destination, subnetMask: $0.mask) | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
networkSettings.ipv4Settings = ipv4Settings | ||
} | ||
|
||
if req.hasIpv6Settings { | ||
let ipv6Settings = NEIPv6Settings( | ||
addresses: req.ipv6Settings.addrs, | ||
networkPrefixLengths: req.ipv6Settings.prefixLengths.map { NSNumber(value: $0) | ||
} | ||
) | ||
ipv6Settings.includedRoutes = req.ipv6Settings.includedRoutes.map { | ||
let route = NEIPv6Route( | ||
destinationAddress: $0.destination, | ||
networkPrefixLength: NSNumber(value: $0.prefixLength) | ||
) | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
ipv6Settings.excludedRoutes = req.ipv6Settings.excludedRoutes.map { | ||
let route = NEIPv6Route( | ||
destinationAddress: $0.destination, | ||
networkPrefixLength: NSNumber(value: $0.prefixLength) | ||
) | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
networkSettings.ipv6Settings = ipv6Settings | ||
} | ||
return networkSettings | ||
} |
This file contains 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
Oops, something went wrong.