Skip to content

Network Stack

opencode-agent[bot] edited this page May 11, 2026 · 8 revisions

Network Stack

JNode features a completely custom, pure-Java network stack implementation spanning from network device drivers up to the standard java.net.Socket API.

Overview

Because JNode does not rely on a host OS (like Linux or Windows), it cannot use host socket implementations. The entire networking OSI model—from Link Layer to Transport Layer—is implemented in the net/ subproject.

Architecture

The stack is heavily object-oriented and modular, allowing new protocols and layers to be plugged in dynamically.

OSI Layer JNode Concept Example Protocols / Packages
Application java.net.Socket, java.net.DatagramSocket HTTP, FTP (via standard Java APIs)
Transport TransportLayer TCP (org.jnode.net.ipv4.tcp), UDP (org.jnode.net.ipv4.udp)
Network NetworkLayer IPv4 (org.jnode.net.ipv4), ICMP, ARP (org.jnode.net.arp)
Data Link LinkLayer, NetDeviceAPI Ethernet (org.jnode.net.ethernet), Wi-Fi (org.jnode.net.wireless)
Physical Network Device Drivers RTL8139, NE2000, Intel eepro100

Core Components

Location: net/src/net/org/jnode/net/

1. Packet Processing (SocketBuffer)

The fundamental unit of data in the JNode network stack is the SocketBuffer (inspired by Linux's sk_buff).

  • It contains the raw packet payload.
  • As a packet travels up or down the stack, layers prepend or strip headers (e.g., MAC header, IP header, TCP header) using the SocketBuffer without needing to allocate new arrays or copy the payload.
  • LayerHeader (and its subclasses LinkLayerHeader, NetworkLayerHeader, TransportLayerHeader) represent the parsed headers attached to a buffer.

2. Network Drivers (org.jnode.driver.net)

Location: net/src/driver/org/jnode/driver/net/

Network cards are Devices managed by the standard DeviceManager. They expose the NetDeviceAPI (or WirelessNetDeviceAPI).

  • Drivers handle the raw hardware ring buffers, DMA transfers, and IRQs.
  • When a packet arrives, the driver allocates a SocketBuffer, copies the data, and passes it up to the active LinkLayer.

3. Layer Managers

The stack is assembled dynamically via registries:

  • NetworkLayerManager: Registers network layers (like IPv4) and routes incoming packets from the Link Layer based on protocol IDs (e.g., 0x0800 for IPv4).
  • Similarly, the Network Layer routes packets to the correct Transport Layer based on the IP protocol field (e.g., 6 for TCP, 17 for UDP).

Java Socket Integration

To make standard Java networking work seamlessly on top of this custom stack, JNode integrates with OpenJDK/GNU Classpath's java.net mechanism.

  • SocketImplFactory: JNode registers a custom SocketImplFactory that creates JNode-specific socket implementations (e.g., JNodeSocketImpl).
  • These implementations bridge the standard java.net calls (connect(), read(), write()) into the internal TransportLayer APIs (TCP/UDP state machines).
  • NetAPI: The NetAPIImpl class provides the application-facing network API for device enumeration, address resolution, and DNS lookup. See NetAPI-Implementation for details.

Related Pages

  • Network-Layers — Detailed three-layer architecture (LinkLayer, NetworkLayer, TransportLayer) and SocketBuffer
  • NetAPI-Implementation — Application network API for device enumeration, address resolution, and DNS
  • Network Device Plugin — Plugin interface for network device drivers, NetPlugin lifecycle, device abstraction
  • IPv4-Protocol — IPv4 packet processing, fragment reassembly, routing table, and checksum handling
  • Driver-Framework — How network cards are probed and initialized.
  • Plugin-System — How protocol layers are registered.
  • Code-Conventions — Important rules regarding resource handling (MemoryResource and IRQs) in network drivers.
  • ARP — IPv4-to-MAC address resolution with cache management.
  • DNS-Resolver — DNS hostname resolution with DHCP integration and dnsjava library.
  • NetPermission — Security permission class for DHCP and BOOTP operations.

Clone this wiki locally