VMConfigAdvancedNetworkView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Copyright © 2022 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. import SwiftUI
  17. @available(macOS 11, *)
  18. @available(iOS, introduced: 14, unavailable)
  19. struct VMConfigAdvancedNetworkView: View {
  20. @Binding var config: UTMQemuConfigurationNetwork
  21. var body: some View {
  22. ScrollView {
  23. Form {
  24. IPConfigurationSection(config: $config)
  25. }.padding()
  26. }
  27. }
  28. }
  29. struct IPConfigurationSection: View {
  30. @Binding var config: UTMQemuConfigurationNetwork
  31. var body: some View {
  32. Toggle(isOn: $config.isIsolateFromHost, label: {
  33. Text("Isolate Guest from Host")
  34. })
  35. Group {
  36. DefaultTextField("Guest Network", text: $config.vlanGuestAddress.bound, prompt: "10.0.2.0/24")
  37. .keyboardType(.asciiCapable)
  38. DefaultTextField("Guest Network (IPv6)", text: $config.vlanGuestAddressIPv6.bound, prompt: "fec0::/64")
  39. .keyboardType(.asciiCapable)
  40. if config.mode == .emulated {
  41. DefaultTextField("Host Address", text: $config.vlanHostAddress.bound, prompt: "10.0.2.2")
  42. .keyboardType(.decimalPad)
  43. DefaultTextField("Host Address (IPv6)", text: $config.vlanHostAddressIPv6.bound, prompt: "fec0::2")
  44. .keyboardType(.asciiCapable)
  45. }
  46. DefaultTextField("DHCP Start", text: $config.vlanDhcpStartAddress.bound, prompt: "10.0.2.15")
  47. .keyboardType(.decimalPad)
  48. if config.mode != .emulated {
  49. DefaultTextField("DHCP End", text: $config.vlanDhcpEndAddress.bound, prompt: "10.0.2.254")
  50. .keyboardType(.decimalPad)
  51. }
  52. if config.mode == .emulated {
  53. DefaultTextField("DHCP Domain Name", text: $config.vlanDhcpDomain.bound)
  54. .keyboardType(.asciiCapable)
  55. DefaultTextField("DNS Server", text: $config.vlanDnsServerAddress.bound, prompt: "10.0.2.3")
  56. .keyboardType(.decimalPad)
  57. DefaultTextField("DNS Server (IPv6)", text: $config.vlanDnsServerAddressIPv6.bound, prompt: "fec0::3")
  58. .keyboardType(.asciiCapable)
  59. DefaultTextField("DNS Search Domains", text: $config.vlanDnsSearchDomain.bound)
  60. .keyboardType(.asciiCapable)
  61. }
  62. }.disableAutocorrection(true)
  63. }
  64. }