Skip to content

Network Layer Manager

opencode-agent[bot] edited this page May 11, 2026 · 1 revision

Network Layer Manager

Central registry for network protocol layers that routes incoming packets to the appropriate protocol handler based on protocol ID.

Overview

The Network Layer Manager is a core service in JNode's network stack that manages network protocol layers (such as IPv4, ARP) and routes received packets to the correct handler. It acts as a central registry where network device drivers deliver received packets, and where protocol implementations register themselves to handle specific protocol types.

Key Components

Class/File Path Purpose
NetworkLayerManager net/src/net/org/jnode/net/NetworkLayerManager.java Interface defining the contract for protocol layer management
DefaultNetworkLayerManager net/src/net/org/jnode/net/service/DefaultNetworkLayerManager.java Implementation that manages protocol layers and packet routing
NetworkLayer net/src/net/org/jnode/net/NetworkLayer.java Interface implemented by protocol handlers (IPv4, ARP, etc.)
SocketBuffer net/src/net/org/jnode/net/SocketBuffer.java Container for network packets with protocol metadata
NetPlugin net/src/net/org/jnode/net/service/NetPlugin.java Plugin that initializes the manager at startup
NetDeviceAPI net/src/driver/org/jnode/driver/net/NetDeviceAPI.java Device API that delivers packets to the manager

How It Works

Initialization

The NetPlugin creates the DefaultNetworkLayerManager during plugin startup:

// From NetPlugin.java:57
ptm = new DefaultNetworkLayerManager(descriptor.getExtensionPoint("networkLayers"));
InitialNaming.bind(NetworkLayerManager.NAME, ptm);

The manager is bound to InitialNaming so other components can look it up by type.

Protocol Registration

Network layers are loaded dynamically via JNode's plugin extension point system. The refreshNetworkLayers() method reads extensions from the networkLayers extension point:

// From DefaultNetworkLayerManager.java:173-185
protected void refreshNetworkLayers() {
    if (networkLayersEP != null) {
        layers.clear();
        final Extension[] extensions = networkLayersEP.getExtensions();
        for (final Extension ext : extensions) {
            final ConfigurationElement[] elements = ext.getConfigurationElements();
            for (ConfigurationElement element : elements) {
                configureLayer(layers, element);
            }
        }
    }
    log.debug("Found " + layers.size() + " network layers");
}

Each extension specifies a class attribute that implements NetworkLayer, which is instantiated and registered by protocol ID.

Packet Receive Flow

When a network device receives a packet, it calls NetworkLayerManager.receive():

// From DefaultNetworkLayerManager.java:126-128
public void receive(SocketBuffer skbuf) {
    packetQueue.add(skbuf);
}

The packet is queued and processed asynchronously by the QueueProcessor thread. The process() method dispatches to the appropriate protocol handler:

// From DefaultNetworkLayerManager.java:135-161
public synchronized void process(SocketBuffer skbuf) {
    final int protoID = skbuf.getProtocolID();
    final Device dev = skbuf.getDevice();
    
    try {
        final NetworkLayer pt = getNetworkLayer(protoID);
        if (pt.isAllowedForDevice(dev)) {
            pt.receive(skbuf, deviceAPI);
        }
    } catch (NoSuchProtocolException ex) {
        log.debug("No network layer handler for protocol 0x" + NumberUtils.hex(protoID, 4));
    }
}

Layer Lookup

Protocol handlers can retrieve other layers programmatically:

// From NetUtils.java:50-54
public static NetworkLayerManager getNLM() throws NetworkException {
    return InitialNaming.lookup(NetworkLayerManager.NAME);
}
// From IPv4NetworkLayer.java:400
arp = (ARPNetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_ARP);

Extension Point Configuration

Network layers are declared in plugin descriptors:

<extension point="org.jnode.net.networkLayers">
    <networkLayer class="org.jnode.net.ipv4.layer.IPv4NetworkLayer"/>
    <networkLayer class="org.jnode.net.arp.ARPNetworkLayer"/>
</extension>

Each networkLayer element must have a class attribute pointing to a class implementing NetworkLayer.

Gotchas

  • Dynamic Reload: The manager listens to extension point changes and refreshes layers automatically when plugins are added/removed
  • Protocol ID Matching: Packets are routed by exact protocol ID match; unknown protocols are silently dropped
  • Device Filtering: Each network layer can optionally restrict which devices it accepts packets from via isAllowedForDevice()
  • Singleton Access: The manager is accessed via InitialNaming.lookup(NetworkLayerManager.class) — not a static singleton
  • Async Processing: Packet processing is asynchronous via a queue; the QueueProcessor thread handles dispatch
  • No Default Route: If no registered layer matches the protocol ID, the packet is discarded with a debug log message

Related Pages

Clone this wiki locally