diff --git a/Sources/cctl/RunCommand.swift b/Sources/cctl/RunCommand.swift index 1670e866..d480b4e6 100644 --- a/Sources/cctl/RunCommand.swift +++ b/Sources/cctl/RunCommand.swift @@ -49,12 +49,6 @@ extension Application { @Option(name: .customLong("mount"), help: "Directory to share into the container (Example: /foo:/bar)") var mounts: [String] = [] - @Option(name: .long, help: "IP address with subnet") - var ip: String? - - @Option(name: .long, help: "Gateway address") - var gateway: String? - @Option(name: .customLong("ns"), help: "Nameserver addresses") var nameservers: [String] = [] @@ -79,9 +73,19 @@ extension Application { path: URL(fileURLWithPath: kernel), platform: .linuxArm ) + + // Choose network implementation based on macOS version + let network: ContainerManager.Network? + if #available(macOS 26, *) { + network = try ContainerManager.VmnetNetwork() + } else { + network = nil + } + var manager = try await ContainerManager( kernel: kernel, initfsReference: "vminit:latest", + network: network, rosetta: rosetta ) let sigwinchStream = AsyncSignalHandler.create(notify: [SIGWINCH]) @@ -119,21 +123,25 @@ extension Application { } var hosts = Hosts.default - if let ip { - guard let gateway else { - throw ContainerizationError(.invalidArgument, message: "gateway must be specified") - } - config.interfaces.append(NATInterface(address: ip, gateway: gateway)) - config.dns = .init(nameservers: [gateway]) - if nameservers.count > 0 { - config.dns = .init(nameservers: nameservers) + if !nameservers.isEmpty { + if #available(macOS 26, *) { + config.dns = DNS(nameservers: nameservers) + } else { + print("Warning: Networking not supported on macOS < 26, ignoring DNS configuration") } + } + + // Add host entry for the container using just the IP (not CIDR) + if #available(macOS 26, *), !config.interfaces.isEmpty { + let interface = config.interfaces[0] + let ipOnly = interface.address.components(separatedBy: "/")[0] // Strip /24 suffix hosts.entries.append( Hosts.Entry( - ipAddress: ip, + ipAddress: ipOnly, hostnames: [id] )) } + config.hosts = hosts if let ociRuntimePath { config.ociRuntimePath = ociRuntimePath