2019-05-19 10:16:09 +00:00
|
|
|
//
|
|
|
|
// IPv6Settings.swift
|
|
|
|
// TunnelKit
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 5/19/19.
|
2023-03-17 15:58:36 +00:00
|
|
|
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
2019-05-19 10:16:09 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of TunnelKit.
|
|
|
|
//
|
|
|
|
// TunnelKit is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// TunnelKit is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with TunnelKit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
/// Encapsulates the IPv6 settings for the tunnel.
|
2022-03-22 06:14:57 +00:00
|
|
|
public struct IPv6Settings: Codable, Equatable, CustomStringConvertible {
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
/// Represents an IPv6 route in the routing table.
|
2022-03-07 22:50:38 +00:00
|
|
|
public struct Route: Codable, Hashable, CustomStringConvertible {
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
/// The destination host or subnet.
|
|
|
|
public let destination: String
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
/// The address prefix length.
|
|
|
|
public let prefixLength: UInt8
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-29 10:24:28 +00:00
|
|
|
/// The address of the gateway (falls back to global gateway).
|
|
|
|
public let gateway: String?
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-29 10:24:28 +00:00
|
|
|
public init(_ destination: String, _ prefixLength: UInt8?, _ gateway: String?) {
|
2019-05-19 10:16:09 +00:00
|
|
|
self.destination = destination
|
|
|
|
self.prefixLength = prefixLength ?? 3
|
|
|
|
self.gateway = gateway
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
// MARK: CustomStringConvertible
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
public var description: String {
|
2022-10-29 10:24:28 +00:00
|
|
|
"{\(destination.maskedDescription)/\(prefixLength) \(gateway?.maskedDescription ?? "*")}"
|
2019-05-19 10:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
/// The address.
|
|
|
|
public let address: String
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
/// The address prefix length.
|
|
|
|
public let addressPrefixLength: UInt8
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
/// The address of the default gateway.
|
|
|
|
public let defaultGateway: String
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2022-10-29 10:24:28 +00:00
|
|
|
public init(address: String, addressPrefixLength: UInt8, defaultGateway: String) {
|
|
|
|
self.address = address
|
|
|
|
self.addressPrefixLength = addressPrefixLength
|
|
|
|
self.defaultGateway = defaultGateway
|
2021-10-25 14:27:27 +00:00
|
|
|
}
|
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
// MARK: CustomStringConvertible
|
2023-04-20 19:52:45 +00:00
|
|
|
|
2019-05-19 10:16:09 +00:00
|
|
|
public var description: String {
|
2022-10-29 18:28:25 +00:00
|
|
|
"addr \(address)/\(addressPrefixLength) gw \(defaultGateway)"
|
2019-05-19 10:16:09 +00:00
|
|
|
}
|
|
|
|
}
|