-
Notifications
You must be signed in to change notification settings - Fork 0
Ethernet Driver
Ethernet network driver with MAC address handling and IEEE 802.3 frame processing.
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.).
| 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 |
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"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);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 > 1500AbstractNetDriver (abstract base)
└── AbstractEthernetDriver
└── BasicEthernetDriver
├── RTL8139Driver (Realtek)
├── ViaRhineDriver
├── EEPRO100Driver (Intel)
├── LanceDriver
└── BCM570xDriver (Broadcom)
When a packet arrives, AbstractEthernetDriver.onReceive():
- Extracts the Ethernet header from the buffer
- Sets the link layer header on the socket buffer
- Determines protocol ID using
EthernetUtils.getProtocol() - Pulls the header and passes to upper layers
AbstractEthernetDriver.doTransmit() handles outgoing packets:
- Pre-allocates space for 14-byte header
- Uses broadcast as default destination if none specified
- Writes destination and source MAC addresses
- Writes protocol ID from socket buffer's protocol field
- Loops back to self if destination matches our address
- Otherwise calls
doTransmitEthernet()for hardware-specific transmission
BasicEthernetDriver adds frame padding to meet minimum 60-byte frame size (ETH_ZLEN).
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 |
-
MAC address byte order: Ethernet uses network byte order (big-endian) in the frame, but
EthernetAddressstores 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 callsonReceive()instead of transmitting — prevents duplicate processing for addressed-to-self traffic. -
Frame padding:
BasicEthernetDriverpads 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.
- Network-Stack — Full network architecture
- Network-Layers — Protocol layering with SocketBuffer
- ARP — MAC address resolution (uses EthernetAddress)
- IPv4-Protocol — Higher layer IP protocol
- Network Device Plugin — Network device plugin system
- Driver-Framework — Device driver framework