Compare commits
1 Commits
19abfb919e
...
main
Author | SHA1 | Date | |
---|---|---|---|
b5fa671d8a |
@@ -93,8 +93,23 @@ public class QemuCommandBuilder
|
|||||||
Console.WriteLine($"Info: Bridge networking detected - port forwarding will be configured via iptables");
|
Console.WriteLine($"Info: Bridge networking detected - port forwarding will be configured via iptables");
|
||||||
Console.WriteLine($"Info: Custom port forwards: {customForwards}");
|
Console.WriteLine($"Info: Custom port forwards: {customForwards}");
|
||||||
|
|
||||||
// Automatically configure iptables port forwarding
|
// For bridge networking, we need to wait for the VM to get an IP
|
||||||
ConfigureIptablesPortForwarding();
|
// Port forwarding will be configured after the VM starts and gets an IP
|
||||||
|
Console.WriteLine($"");
|
||||||
|
Console.WriteLine($"📝 Bridge Networking Port Forwarding:");
|
||||||
|
Console.WriteLine($" Port forwarding will be configured automatically once the VM gets an IP address.");
|
||||||
|
Console.WriteLine($" The system will use iptables to forward traffic from host ports to the VM.");
|
||||||
|
Console.WriteLine($"");
|
||||||
|
Console.WriteLine($" Configured forwards:");
|
||||||
|
foreach (var pf in GetPortForwardList())
|
||||||
|
{
|
||||||
|
Console.WriteLine($" • Port {pf.HostPort} → VM:{pf.VmPort} ({pf.Protocol})");
|
||||||
|
}
|
||||||
|
Console.WriteLine($"");
|
||||||
|
Console.WriteLine($" To configure port forwarding manually after VM starts:");
|
||||||
|
Console.WriteLine($" sudo iptables -t nat -A PREROUTING -p tcp --dport 3300 -j DNAT --to-destination <VM_IP>:80");
|
||||||
|
Console.WriteLine($" sudo iptables -A FORWARD -p tcp --dport 80 -d <VM_IP> -j ACCEPT");
|
||||||
|
Console.WriteLine($" (Replace <VM_IP> with the VM's actual IP address from the bridge)");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfigureIptablesPortForwarding()
|
private void ConfigureIptablesPortForwarding()
|
||||||
@@ -450,7 +465,8 @@ public class QemuCommandBuilder
|
|||||||
if (!vmForwards.Any())
|
if (!vmForwards.Any())
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
// Build hostfwd arguments for custom port forwards
|
// For bridge networking, we don't use hostfwd - we use iptables instead
|
||||||
|
// This method is only called for macOS user networking
|
||||||
var forwardArgs = new List<string>();
|
var forwardArgs = new List<string>();
|
||||||
foreach (var pf in vmForwards)
|
foreach (var pf in vmForwards)
|
||||||
{
|
{
|
||||||
@@ -466,6 +482,27 @@ public class QemuCommandBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<QemuVmManager.Models.PortForward> GetPortForwardList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var configFile = "port-forwards.json";
|
||||||
|
if (!File.Exists(configFile))
|
||||||
|
return new List<QemuVmManager.Models.PortForward>();
|
||||||
|
|
||||||
|
var json = File.ReadAllText(configFile);
|
||||||
|
var portForwards = System.Text.Json.JsonSerializer.Deserialize<List<QemuVmManager.Models.PortForward>>(json) ?? new List<QemuVmManager.Models.PortForward>();
|
||||||
|
|
||||||
|
// Filter port forwards for this VM
|
||||||
|
return portForwards.Where(pf => pf.VmName == _config.Name).ToList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Warning: Could not load port forward list: {ex.Message}");
|
||||||
|
return new List<QemuVmManager.Models.PortForward>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void AddMachineConfiguration()
|
private void AddMachineConfiguration()
|
||||||
{
|
{
|
||||||
_arguments.Add("-machine");
|
_arguments.Add("-machine");
|
||||||
|
Reference in New Issue
Block a user