TCPIP_IPV4_PACKET_HANDLER Type
C
typedef bool (* TCPIP_IPV4_PACKET_HANDLER)(TCPIP_NET_HANDLE hNet, struct _tag_TCPIP_MAC_PACKET* rxPkt, const void* hParam);
Description
IPv4 packet handler pointer.
Pointer to a function that will be called by the IPv4 module when a RX packet is available.
Parameters
Parameters | Description |
---|---|
hNet | Network handle on which the packet has arrived. |
rxPkt | Pointer to incoming packet. |
hParam | User passed parameter when handler was registered. |
Returns
True - If the packet is processed by the external handler. In this case the IPv4 module will no longer process the packet.
False - The packet needs to be processed internally by the IPv4 as usual.
Remarks
The packet handler is called in the IPv4 context. The handler should be kept as short as possible as it affects the processing of all the other IPv4 RX traffic.
Before calling the external packet handler:
The rxPkt->pNetLayer points to an IPV4_HEADER data structure.
The rxPkt->pktIf points to the interface receiving the packet.
No other checks are done (checksum, versions, etc.).
IMPORTANT: When the packet handler returns true, once it's done processing the packet, it needs to acknowledge it, i.e. return to the owner, which is the MAC driver serving the network interface. This means that the packet acknowledge function needs to be called, with a proper acknowledge parameter and the QUEUED flag needs to be cleared, if needed:
if((*rxPkt->ackFunc)(rxPkt, rxPkt->ackParam)) { rxPkt->pktFlags &= ~TCPIP_MAC_PKT_FLAG_QUEUED; }
Failure to do that will result in memory leaks and starvation of the MAC driver. See the tcpip_mac.h for details.