IXP2400/2800 Programming: The Complete Microengine Coding Guide

Three of the microblocks in Figure 6.1 are used to either process or generate Ethernet headers. The microblocks are called ethernet_validate, ethernet_strip_header, and ethernet_add_header. The ethernet_ validate microblock ensures that the packet is a valid Ethernet II frame and has different targets for multicast, broadcast, locally-addressed, and other packets that are not multicast, broadcast, or locally-addressed. The ethernet_strip_header microblock removes the Ethernet header so that code that processes higher-layer packets in this case the IPv4 fivetuple classifier can process the packets encapsulated by the Ethernet frame. The ethernet_add_header microblock does the opposite, adding Ethernet encapsulation around the IP frame. It determines the Ethernet destination MAC address from the next-hop ID determined by the classifier.
In our design we split up the ethernet_validate and ethernet_ strip_header microblocks in an attempt to maximize reuse. We might get better performance by combining the two. But, for example, if we were to write an Ethernet bridge, we would find the combination of the two microblocks to be more work than needed, whereas ethernet_ validate by itself might suffice.
The code for ethernet_validate is very straightforward. The packet is validated by checking the actual length to ensure it is greater than or equal to the minimum length and less than or equal to the maximum length of an Ethernet II frame. This microblock also tells the dispatch loop if the frame is locally addressed, multicast, or broadcast. To determine the type of frame, it looks at the destination MAC address in the Ethernet header.
The...