driver.net.proto.eth2¶
Ethernet II (DIX) framing layer.
Overview¶
This unit implements Ethernet II frame encapsulation and de-multiplexing. It maintains a 65536-entry dispatch table indexed by EtherType for exclusive per-protocol receive handlers, and a parallel boolean array for promiscuous handlers that receive all frames regardless of EtherType or destination. On transmit, it prepends the Ethernet header and pads short payloads to the minimum Ethernet frame size.
Dependencies¶
driver.netdriver.net.typesdriver.net.utilsyslog
Functions and Procedures¶
register¶
Initialises the dispatch table and registers itself as the layer-2 receive handler viadriver.net.registerNextLayer.
registerType¶
Registers an exclusive receive handler for the given EtherType. Only one handler per EtherType is supported; subsequent registrations replace the previous entry.registerTypePromisc¶
Registers a promiscuous receive handler. The handler receives every incoming frame, regardless of the destination MAC or whether another handler is registered for the same EtherType.send¶
Constructs aTEthernetHeader with the destination MAC, the local MAC from driver.net.getMAC as source, and the given EtherType. Pads the payload to a minimum of 46 bytes if necessary, then calls driver.net.send.
recv¶
Called bydriver.net for each received frame. Parses the TEthernetHeader from the frame, fills ctx.src_mac, ctx.dst_mac, and ctx.protocol. Discards unicast frames not addressed to the local MAC (broadcast and promiscuous frames are always passed through). Dispatches to the registered EtherType handler and to all promiscuous handlers.
Notes¶
- The dispatch table occupies 65536 pointer entries; entries for unregistered EtherTypes are
nil. - Promiscuous handlers are notified after the regular EtherType handler.
- Minimum Ethernet frame payload is 46 bytes (to achieve the 64-byte minimum frame size including header and CRC); padding is zero-filled.