Skip to content

Ethernet Driver

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

Ethernet Driver

Ethernet network driver with MAC address handling and IEEE 802.3 frame processing.

Overview

JNode's Ethernet driver subsystem provides the link layer for network communication. It handles 48-bit MAC addresses, IEEE 802.3 frame parsing/construction, and serves as the base for hardware-specific network drivers (RTL8139, ViaRhine, EEPRO100, etc.).

Key Components

Class/File Path Purpose
EthernetAddress net/src/net/org/jnode/net/ethernet/EthernetAddress.java 48-bit MAC address wrapper
EthernetHeader net/src/net/org/jnode/net/ethernet/EthernetHeader.java IEEE 802.3 frame header
EthernetConstants net/src/net/org/jnode/net/ethernet/EthernetConstants.java Protocol IDs and frame sizes
EthernetUtils net/src/net/org/jnode/net/ethernet/EthernetUtils.java Protocol extraction helper
AbstractEthernetDriver net/src/driver/org/jnode/driver/net/ethernet/spi/AbstractEthernetDriver.java Base driver class
BasicEthernetDriver net/src/driver/org/jnode/driver/net/ethernet/spi/BasicEthernetDriver.java Extended driver with transmit

How It Works

MAC Address Handling

EthernetAddress wraps a 6-byte MAC address with parsing, formatting, and broadcast detection:

// Create from string (colon or hyphen separated)
EthernetAddress addr = new EthernetAddress("00:11:22:33:44:55");

// Broadcast address
EthernetAddress broadcast = EthernetAddress.BROADCAST;

// Check if broadcast
boolean isBc = addr.isBroadcast();

// Format to string
String formatted = addr.toString(); // "00:11:22:33:44:55"

Frame Header Structure

EthernetHeader parses the 14-byte IEEE 802.3 header:

+0  Destination MAC (6 bytes)
+6  Source MAC (6 bytes)
+12 Length/Type (2 bytes) — >1500 = protocol ID, <=1500 = length
+14 Payload starts here
// Parse from socket buffer
EthernetHeader hdr = new EthernetHeader(skbuf);

// Access fields
EthernetAddress dst = hdr.getDestination();
EthernetAddress src = hdr.getSource();
int lengthType = hdr.getLengthType(); // Protocol ID or length

// Construct and prepend header
EthernetHeader newHdr = new EthernetHeader(dst, src, protocolID);
newHdr.prefixTo(skbuf);

Protocol Type Detection

EthernetUtils.getProtocol() distinguishes between 802.3 length fields and Ethernet II type values:

int protocol = EthernetUtils.getProtocol(hdr);
// Returns ETH_P_802_2 if length <= 1500
// Returns the type value if length > 1500

Driver Hierarchy

AbstractNetDriver (abstract base)
    └── AbstractEthernetDriver
            └── BasicEthernetDriver
                    ├── RTL8139Driver (Realtek)
                    ├── ViaRhineDriver
                    ├── EEPRO100Driver (Intel)
                    ├── LanceDriver
                    └── BCM570xDriver (Broadcom)

Receive Path

When a packet arrives, AbstractEthernetDriver.onReceive():

  1. Extracts the Ethernet header from the buffer
  2. Sets the link layer header on the socket buffer
  3. Determines protocol ID using EthernetUtils.getProtocol()
  4. Pulls the header and passes to upper layers

Transmit Path

AbstractEthernetDriver.doTransmit() handles outgoing packets:

  1. Pre-allocates space for 14-byte header
  2. Uses broadcast as default destination if none specified
  3. Writes destination and source MAC addresses
  4. Writes protocol ID from socket buffer's protocol field
  5. Loops back to self if destination matches our address
  6. Otherwise calls doTransmitEthernet() for hardware-specific transmission

BasicEthernetDriver adds frame padding to meet minimum 60-byte frame size (ETH_ZLEN).

Constants

Key values from EthernetConstants:

Constant Value Meaning
ETH_ALEN 6 MAC address length
ETH_HLEN 14 Header length
ETH_ZLEN 60 Minimum frame size (without FCS)
ETH_DATA_LEN 1500 Maximum payload
ETH_FRAME_LEN 1514 Maximum frame (without FCS)
ETH_P_IP 0x0800 IPv4
ETH_P_ARP 0x0806 ARP
ETH_P_IPV6 0x86DD IPv6
ETH_P_802_1Q 0x8100 VLAN tagging
ETH_P_PPP_SES 0x8864 PPPoE

Gotchas

  • MAC address byte order: Ethernet uses network byte order (big-endian) in the frame, but EthernetAddress stores bytes in the natural array order.
  • Length vs Type ambiguity: Values 0x0500-0xFFFF are treated as protocol types; 0x0000-0x0500 as 802.3 length (with ETH_P_802_2 as default protocol).
  • Broadcast loopback: doTransmit() checks if destination equals our address and calls onReceive() instead of transmitting — prevents duplicate processing for addressed-to-self traffic.
  • Frame padding: BasicEthernetDriver pads frames under 60 bytes before transmission; this happens in the driver layer, not the protocol layer.
  • No CRC/FCS handling: The frame check sequence (CRC) is handled by hardware; JNode's driver operates on the header + payload only.

Related Pages

Clone this wiki locally