add mtu and nic type options to the interface

This commit is contained in:
ading2210 2025-11-06 13:20:00 -08:00 committed by Fabian
parent d093088616
commit 0beafeee07
4 changed files with 68 additions and 4 deletions

View file

@ -147,6 +147,10 @@
</td> </td>
</tr> </tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr> <tr>
<td><label for="relay_url">Networking proxy (leave blank to disable)</label></td> <td><label for="relay_url">Networking proxy (leave blank to disable)</label></td>
<td> <td>
@ -154,6 +158,24 @@
</td> </td>
</tr> </tr>
<tr>
<td><label for="net_device_type">Network Device Type</label></td>
<td>
<select id="net_device_type">
<option value="ne2k">ne2k</option>
<option value="virtio">virtio</option>
</select>
</td>
</tr>
<tr>
<td><label for="mtu">Network MTU (only used for virtio)</label></td>
<td>
<input id="mtu" type="number" value="1500" min="68" max="65535" step="1"> B<br>
</td>
</tr>
<tr> <tr>
<td colspan="2"><hr></td> <td colspan="2"><hr></td>
</tr> </tr>

View file

@ -247,6 +247,10 @@
</td> </td>
</tr> </tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr> <tr>
<td><label for="relay_url">Networking proxy</label><br> <td><label for="relay_url">Networking proxy</label><br>
Presets: <a id="network_none">none</a>, <a id="network_inbrowser">inbrowser</a>, <a id="network_relay">public relay</a>, <a id="network_wisp">wisp</a>, <a id="network_fetch">fetch</a></td> Presets: <a id="network_none">none</a>, <a id="network_inbrowser">inbrowser</a>, <a id="network_relay">public relay</a>, <a id="network_wisp">wisp</a>, <a id="network_fetch">fetch</a></td>
@ -255,6 +259,23 @@
</td> </td>
</tr> </tr>
<tr>
<td><label for="net_device_type">Network Device Type</label></td>
<td>
<select id="net_device_type">
<option value="ne2k">ne2k</option>
<option value="virtio">virtio</option>
</select>
</td>
</tr>
<tr>
<td><label for="mtu">Network MTU (only used for virtio)</label></td>
<td>
<input id="mtu" type="number" value="1500" min="68" max="65535" step="1"> B<br>
</td>
</tr>
<tr> <tr>
<td colspan="2"><hr></td> <td colspan="2"><hr></td>
</tr> </tr>

View file

@ -12,6 +12,8 @@ const DEFAULT_NETWORKING_PROXIES = ["wss://relay.widgetry.org/", "ws://localhost
const DEFAULT_MEMORY_SIZE = 128; const DEFAULT_MEMORY_SIZE = 128;
const DEFAULT_VGA_MEMORY_SIZE = 8; const DEFAULT_VGA_MEMORY_SIZE = 8;
const DEFAULT_BOOT_ORDER = 0; const DEFAULT_BOOT_ORDER = 0;
const DEFAULT_MTU = 1500;
const DEFAULT_NIC_TYPE = "ne2k";
const MAX_ARRAY_BUFFER_SIZE_MB = 2000; const MAX_ARRAY_BUFFER_SIZE_MB = 2000;
@ -1689,6 +1691,8 @@ function onload()
if(query_args.has("mute")) $("disable_audio").checked = bool_arg(query_args.get("mute")); if(query_args.has("mute")) $("disable_audio").checked = bool_arg(query_args.get("mute"));
if(query_args.has("acpi")) $("acpi").checked = bool_arg(query_args.get("acpi")); if(query_args.has("acpi")) $("acpi").checked = bool_arg(query_args.get("acpi"));
if(query_args.has("boot_order")) $("boot_order").value = query_args.get("boot_order"); if(query_args.has("boot_order")) $("boot_order").value = query_args.get("boot_order");
if(query_args.has("net_device_type")) $("net_device_type").value = query_args.get("net_device_type");
if(query_args.has("mtu")) $("mtu").value = query_args.get("mtu");
for(const dev of ["fda", "fdb"]) for(const dev of ["fda", "fdb"])
{ {
@ -2091,12 +2095,12 @@ function start_emulation(profile, query_args)
settings.acpi = query_args.has("acpi") ? bool_arg(query_args.get("acpi")) : settings.acpi; settings.acpi = query_args.has("acpi") ? bool_arg(query_args.get("acpi")) : settings.acpi;
settings.use_bochs_bios = query_args.get("bios") === "bochs"; settings.use_bochs_bios = query_args.get("bios") === "bochs";
settings.net_device_type = query_args.get("net_device_type") || settings.net_device_type; settings.net_device_type = query_args.get("net_device_type") || settings.net_device_type;
settings.mtu = parseInt(query_args.get("mtu"), 10) || undefined;
} }
settings.relay_url = query_args.get("relay_url"); settings.relay_url = query_args.get("relay_url");
settings.disable_jit = bool_arg(query_args.get("disable_jit")); settings.disable_jit = bool_arg(query_args.get("disable_jit"));
settings.disable_audio = bool_arg(query_args.get("mute")); settings.disable_audio = bool_arg(query_args.get("mute"));
settings.mtu = parseInt(query_args.get("mtu"), 10) || undefined;
} }
if(!settings.relay_url) if(!settings.relay_url)
@ -2240,6 +2244,21 @@ function start_emulation(profile, query_args)
settings.bios = { url: BIOSPATH + "bochs-bios.bin" }; settings.bios = { url: BIOSPATH + "bochs-bios.bin" };
settings.vga_bios = { url: BIOSPATH + "bochs-vgabios.bin" }; settings.vga_bios = { url: BIOSPATH + "bochs-vgabios.bin" };
} }
const nic_type = $("net_device_type").value || DEFAULT_NIC_TYPE;
if(!settings.net_device_type || nic_type !== DEFAULT_NIC_TYPE)
{
settings.net_device_type = nic_type;
}
if(settings.net_device_type !== DEFAULT_NIC_TYPE) new_query_args.set("net_device_type", settings.net_device_type);
const mtu = parseInt($("mtu").value, 10) || DEFAULT_MTU;
if(!settings.mtu || mtu !== DEFAULT_MTU)
{
settings.mtu = mtu;
}
if(settings.mtu !== DEFAULT_MTU) new_query_args.set("mtu", settings.mtu.toString());
} }
if(!query_args) if(!query_args)
@ -2254,7 +2273,7 @@ function start_emulation(profile, query_args)
use_graphical_text: false, use_graphical_text: false,
}, },
net_device: { net_device: {
type: settings.net_device_type || "ne2k", type: settings.net_device_type || DEFAULT_NIC_TYPE,
relay_url: settings.relay_url, relay_url: settings.relay_url,
cors_proxy: settings.cors_proxy, cors_proxy: settings.cors_proxy,
mtu: settings.mtu mtu: settings.mtu

View file

@ -9,6 +9,8 @@ import * as marshall from "../lib/marshall.js";
import { CPU } from "./cpu.js"; import { CPU } from "./cpu.js";
import { BusConnector } from "./bus.js"; import { BusConnector } from "./bus.js";
const DEFAULT_MTU = 1500;
const VIRTIO_NET_F_MAC = 5; const VIRTIO_NET_F_MAC = 5;
const VIRTIO_NET_F_CTRL_VQ = 17; const VIRTIO_NET_F_CTRL_VQ = 17;
const VIRTIO_NET_F_STATUS = 16; const VIRTIO_NET_F_STATUS = 16;
@ -24,9 +26,9 @@ const VIRTIO_NET_CTRL_MAC_ADDR_SET = 1;
* @param {CPU} cpu * @param {CPU} cpu
* @param {BusConnector} bus * @param {BusConnector} bus
* @param {Boolean} preserve_mac_from_state_image * @param {Boolean} preserve_mac_from_state_image
* @param {Number} mtu * @param {number} mtu
*/ */
export function VirtioNet(cpu, bus, preserve_mac_from_state_image, mtu = 1500) export function VirtioNet(cpu, bus, preserve_mac_from_state_image, mtu = DEFAULT_MTU)
{ {
/** @const @type {BusConnector} */ /** @const @type {BusConnector} */
this.bus = bus; this.bus = bus;