Basic IP layer

Tools

: isIPforme     \ *pbuf -- flag
Flag true if this packet is for me.

variable ipid   \ -- addr ; for outgoing packets
IP packet identifier, incremented by one for each outgoing IP packet.

: SetIPhdr      \ len ipsrc ipdest ipproto *iphdr --
Initialise and fill in an IP header with no options.

: pb>IPH        \ *ip *pb --
Step the PBuf data pointers back to the IP header from the TCP or UDP header.

Sending IP packets

defer send>other        \ *pb *rt -- len
This allows other routes to be patched in to the stack without changing the stack source.

: NoOther       \ *pb *rt -- len
The default action of SEND>OTHER.

: (IPSend)      \ *pb -- len|-1
Send the data in the supplied PBuf (chain). *PB is the first pbuf in the chain (only 1 allowed) Returns the number of bytes sent if OK else SOCKET_ERROR.

: IPSend        \ *sk *pb -- len|SOCKET_ERROR
Send the data in the supplied PBuf (chain). Returns number of bytes sent if OK else SOCKET_ERROR.

Receiving IP packets

defer RouteIP   \ *pb --
This IP packet is not for me! Vectored routing allows later application dependent patching up. The default action is to discard the packet with FreeQB.

defer CanRouteIP?       \ *pb -- T|F
Returns true if we can route this packet. Vectored routing allows later application dependent patching up.

: NoCanRoute    \ *pb -- False
The default action of CANROUTEIP?

: ProcessPacket \ *pb --
Process an incoming packet

Task PacketTask \ -- addr
The task that handles incoming packets.

: DoIncoming    \ --
The action of the incoming packet task.

: RunIncoming   \ --
Start the incoming packet task.

: GoodIPPacket  { *pb -- }
Process a good packet.

: GoodIPPacket  \ *pb --
Process a good packet.

: RunIncoming   \ --
Start the incoming packet task.

: BadIpPacket   \ *pbuf --
A header check failed, so discard the packet.

: IPHdrLen      \ *ip -- len
Find the length of the IP header.

: +IPhdr        \ *ip -- addr
Step from the IP header to the next item, e.g. TCP header.

: RxIpPacket    \ *pb --
Process a received IP packet.