Skip to content

[draft] feat(usbgadget): share JetKVM's internet via USB ethernet #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

dlorch
Copy link
Contributor

@dlorch dlorch commented May 16, 2025

An early PoC implementation to share JetKVM's internet via USB Ethernet to the target host.

usb networking

What can be seen on the screenshot:

  • A USB Ethernet device is connected
  • A traceroute that sends packets through the JetKVM device to the internet

Prerequisites

Requires USB Ethernet, NAT and nftables support in the OS from jetkvm/rv1106-system#16

USB gadget ethernet

Following USB ethernet protocols are available:

  • Ethernet Control Model (ECM)
  • Ethernet Emulation Model (EEM)
  • Network Control Model (NCM)
  • Remote Network Driver Interface Specification (RNDIS)

I am not an expert in the standards. I have used ECM for testing.

The standards basically differ in terms of transfer speeds and driver support in the OS. The Wiki page on Ethernet over USB has more information.

Setup

On the JetKVM, in /userdata/kvm_config.json, enable:

  • "ethernet_ecm": true
  • "network_config": { "nat_enable": true }

Observe the following log entries from JetKVM to validate the setup has worked:

2025-05-15T20:38:32Z INF jetkvm network enabling NAT iface=eth0
2025-05-15T20:38:33Z INF jetkvm usb enabling USB Ethernet iface=usb0 ipv4addr=172.16.55.1/24

On the target device, bring the interface up and set it up as a default route:

ip addr add 172.16.55.12/24 dev enxf2252a378082
ip link set dev enxf2252a378082 up
ip addr show dev enxf2252a378082

ping 172.16.55.1 # JetKVM
ip route replace default via 172.16.55.1 dev enxf2252a378082

I've picked the network 172.16.55.0/24 (RFC 1918) as a private network for USB ethernet

TODO

  • Enable USB Ethernet and NAT
  • Automatically set up target device via DHCP
  • UI support for
    • Enable NAT
    • Set USB Ethernet MAC address (now: randomly assigned)
    • Set USB Ethernet Network CIDR (now: 172.16.55.0/24)
    • Select one of USB Ethernet protocol (ECM, EEM, NCM, RNDIS)

@dlorch dlorch changed the title feat(usbgadget): Share JetKVM's internet via USB Ethernet [draft] feat(usbgadget): Share JetKVM's internet via USB Ethernet May 16, 2025
@dlorch dlorch changed the title [draft] feat(usbgadget): Share JetKVM's internet via USB Ethernet [draft] feat(usbgadget): share JetKVM's internet via USB ethernet May 16, 2025
@IDisposable
Copy link
Contributor

IDisposable commented May 21, 2025

This is super nice... why 172.16.55.0/24 instead of 172.16.0.0/12?

@dlorch
Copy link
Contributor Author

dlorch commented May 21, 2025

This is super nice... why 172.16.55.0/24 instead of 172.16.0.0/12?

The smallest possible network that's hopefully not overlapping with anything existing on the host. I randomly chose this network from the available RFC 1918 space.

  • /24 is easy to work with (first three octets represent the network, the last octet is available for hosts)
  • We could also go smaller with a /30 (2^2 = 4 addresses) or possibly a /31 (2^1 = 2 addresses)

Copy link
Contributor

@IDisposable IDisposable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really cool, can't wait for the kernel system image to support it.

@dlorch
Copy link
Contributor Author

dlorch commented May 21, 2025

@IDisposable thank you for sharing the excitement on this feature. As you've noticed, the code needs a lot of work and is not yet ready for line-by-line scrutiny. This PR is in DRAFT state for this reason.

The main things I wanted to learn and that are demonstrated as part of this PoC:

There has been a lot of great improvements lately on network interface management in dev, and there is a lot of potential to re-use that for configuring the USB Ethernet device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants