Skip to content

Commit

Permalink
network: Fetch based browser networking (#1061)
Browse files Browse the repository at this point in the history
Emulate a networking stack, intercept HTTP requests, serve
them with fetch().  Enable by setting networking_proxy=fetch

Somewhat fixes #198

Just enough networking for http to work for package managers and
net-boot. The networking stack just reflects the macaddress of
packets it receives, so shouldnt be bothered by mac address
changes. Services include:

- ARP replies by establishing the gateways IP
- DHCP server sending gateway, dns, and client-ip
  - Gateway: 192.168.86.1
  - Client: 192.168.86.100
  - Netmask: 255.255.255.0
- UDP DNS server, all addresses resolve to: 192.168.87.1
- NTP Server, giving out the current time from Date()
- Replies to ICMP pings to any IP address
- UDP echo server on port 8

Limitations:
- Request are limited by CORS rules, but CORS-proxies can work around
  this.
- Redirects are handled transparently by fetch. The upside is sites that
  force an http->https upgrade appear to the VM to work over http.

Future Work:
- Allow HTTP requests from browser to be served by VM.
- HTTPS support (maybe with help of a rust based TLS stack in WASM)
- Support for POSTing binary data

* Run devices tests in CI
* Allow multiple Ne2k adapters

Co-authored-by: Fabian <[email protected]>
  • Loading branch information
basicer and copy authored Jul 24, 2024
1 parent 5435c2f commit 92c936d
Show file tree
Hide file tree
Showing 10 changed files with 1,715 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ jobs:
- name: Run integration tests
run: MAX_PARALLEL_TESTS=1 make tests

- name: Run devices tests
run: make devices-test

- name: Run expect tests
run: make expect-tests

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ CORE_FILES=const.js config.js io.js main.js lib.js buffer.js ide.js pci.js flopp
LIB_FILES=9p.js filesystem.js jor1k.js marshall.js utf8.js
BROWSER_FILES=screen.js keyboard.js mouse.js speaker.js serial.js \
network.js starter.js worker_bus.js dummy_screen.js \
print_stats.js filestorage.js
fetch_network.js print_stats.js filestorage.js

RUST_FILES=$(shell find src/rust/ -name '*.rs') \
src/rust/gen/interpreter.rs src/rust/gen/interpreter0f.rs \
Expand Down Expand Up @@ -305,6 +305,7 @@ expect-tests: all-debug build/libwabt.js
devices-test: all-debug
./tests/devices/virtio_9p.js
./tests/devices/virtio_console.js
./tests/devices/fetch_network.js

rust-test: $(RUST_FILES)
env RUSTFLAGS="-D warnings" RUST_BACKTRACE=full RUST_TEST_THREADS=1 cargo test -- --nocapture
Expand Down
2 changes: 1 addition & 1 deletion debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"memory.js dma.js pit.js vga.js ps2.js rtc.js uart.js acpi.js apic.js ioapic.js sb16.js " +
"ne2k.js state.js virtio.js virtio_console.js bus.js elf.js kernel.js";

var BROWSER_FILES = "main.js screen.js keyboard.js mouse.js speaker.js serial.js network.js starter.js worker_bus.js print_stats.js filestorage.js";
var BROWSER_FILES = "main.js screen.js keyboard.js mouse.js speaker.js serial.js network.js fetch_network.js starter.js worker_bus.js print_stats.js filestorage.js";
var LIB_FILES = "";

// jor1k stuff
Expand Down
Loading

0 comments on commit 92c936d

Please sign in to comment.