Revert to more efficient ternary op in IP header

See #169 and 753927f36b
This commit is contained in:
Davide De Rosa 2020-05-12 12:57:23 +02:00
parent 05a55bec4f
commit f1a28a8d32
1 changed files with 6 additions and 10 deletions

View File

@ -46,12 +46,11 @@ public class NETunnelInterface: TunnelInterface {
private static let ipV6: UInt8 = 6 private static let ipV6: UInt8 = 6
private static let protocolNumbers: [UInt8: NSNumber] = [ private static let ipV4ProtocolNumber = AF_INET as NSNumber
ipV4: NSNumber(value: AF_INET),
ipV6: NSNumber(value: AF_INET6)
]
private static let fallbackProtocolNumber = protocolNumbers[ipV4]! private static let ipV6ProtocolNumber = AF_INET6 as NSNumber
private static let fallbackProtocolNumber = ipV4ProtocolNumber
private weak var impl: NEPacketTunnelFlow? private weak var impl: NEPacketTunnelFlow?
@ -110,10 +109,7 @@ public class NETunnelInterface: TunnelInterface {
// The first 4 bits identify the IP version // The first 4 bits identify the IP version
let ipVersion = (packet[0] & 0xf0) >> 4 let ipVersion = (packet[0] & 0xf0) >> 4
guard let protocolNumber = protocolNumbers[ipVersion] else { assert(ipVersion == ipV4 || ipVersion == ipV6)
log.warning("Unrecognized IP version (\(ipVersion))") return (ipVersion == ipV6) ? ipV6ProtocolNumber : ipV4ProtocolNumber
return fallbackProtocolNumber
}
return protocolNumber
} }
} }