<net/packetring.h>¶
Single-producer, single-consumer ring of Ethernet frames between a NIC driver and netd.
#include <net/packetring.h>
Constants¶
Structures¶
NicFrame¶
One frame slot.
| Field | Type | Description |
|---|---|---|
len |
uint32_t |
Bytes of data in use. |
data |
uint8_t |
Frame bytes. |
NicRing¶
A ring of frames in shared memory; empty when head == tail.
| Field | Type | Description |
|---|---|---|
slots |
NicFrame |
Frame slots. |
head |
volatile uint32_t |
Next slot the producer writes. |
tail |
volatile uint32_t |
Next slot the consumer reads. |
Functions¶
PacketRingPush¶
int PacketRingPush(NicRing *r, void *src, uint16_t len);
Producer: copies a frame into the ring.
| Parameter | Direction | Description |
|---|---|---|
r |
inout | Ring. |
src |
in | Frame bytes. |
len |
in | Frame length, at most NIC_FRAME_SIZE. |
Returns: 0, or an error code.
| Error | Condition |
|---|---|
ERR_OVERFLOW |
r or src is NULL, or len is too large. |
ERR_BUFFULL |
The ring is full. |
PacketRingPop¶
int PacketRingPop(NicFrame *dst, NicRing *r);
Consumer: copies the oldest frame out of the ring.
| Parameter | Direction | Description |
|---|---|---|
dst |
out | Where to copy the frame. |
r |
inout | Ring. |
Returns: 0, or an error code.
| Error | Condition |
|---|---|
ERR_BADARG |
dst or r is NULL. |
ERR_BUFEMPTY |
The ring is empty. |
ERR_OVERFLOW |
The slot claimed an impossible length; it has been skipped. |
PacketRingReserve¶
NicFrame * PacketRingReserve(NicRing *r);
Producer: returns the next free slot to fill in place, without copying.
Fill in its data and len, then call PacketRingCommit().
| Parameter | Direction | Description |
|---|---|---|
r |
in | Ring. |
Returns: The slot, or NULL if the ring is full or r is NULL.
PacketRingCommit¶
void PacketRingCommit(NicRing *r);
Producer: publishes the slot from PacketRingReserve().
A barrier orders the slot's contents before the new head.
| Parameter | Direction | Description |
|---|---|---|
r |
inout | Ring. |
PacketRingPeek¶
NicFrame * PacketRingPeek(NicRing *r);
Consumer: returns the oldest frame to read in place, without copying.
Call PacketRingConsume() when done with it.
| Parameter | Direction | Description |
|---|---|---|
r |
in | Ring. |
Returns: The slot, or NULL if the ring is empty or r is NULL.
PacketRingConsume¶
void PacketRingConsume(NicRing *r);
Consumer: releases the slot from PacketRingPeek() back to the producer.
| Parameter | Direction | Description |
|---|---|---|
r |
inout | Ring. |