Function Prototypes:ttUserFilterCallback

Jump to: navigation, search

Table of Contents >> Programmer's Reference >> tfUserRegisterFilter


int ttUserFilterCallback (
ttUserInterface interfaceHandle,
void TM_FAR * iphPtr,
void TM_FAR * ulpPtr,
int totalLength,
int direction
);


Function Description

This function prototype should be used for user filter callbacks registered to handle IP datagrams. As traffic flows through each interface that has filtering enabled this function is invoked with the associated parameters as described below.

Usage

Implement an instance of this function and register it with a call to tfUserRegisterFilter(). This function is used to perform additional comparison logic of packet content to determine how the packet should be handled by the stack. Various return values dictate further stack processing.


Parameters

  • interfaceHandle
    This is the interface on which the IP datagram was delivered.
  • iphPtr
    This is the start of the IPv4 header.
  • ulpPtr
    This is the start of the IPv4 upper layer protocol.
  • totalLength
    This is the total length of the IP datagram.
  • direction
    This is the direction of the IP datagram (TM_FILTER_OUTGOING or TM_FILTER_INCOMING).


Returns

  • TM_ENOERROR
    The packet is acceptable and Treck is to process the packet normally.
  • TM_EOPNOTSUPP
    The packet is not acceptable and Treck is to drop the packet.
  • TM_ENETUNREACH
    (Incoming packets only) The stack is to respond with an ICMP Network Unreachable message.
  • TM_EHOSTUNREACH
    (Incoming packets only) The stack is to respond with an ICMP Host Unreachable message.


Example

int filterCallback(ttUserInterface interfaceHandle,
                    void TM_FAR * iphPtr,
                    void TM_FAR * ulpPtr,
                    int totalLength,
                    int direction)
{
    ttIpHeaderPtr ipHeaderPtr;
    ttUdpHeaderPtr udpHeaderPtr;
    ttTcpHeaderPtr tcpHeaderPtr;
    int errorCode;
 
/* Filter for all devices and all length of packets */
    TM_UNREF_IN_ARG(interfaceHandle);
    TM_UNREF_IN_ARG(totalLength);
 
    ipHeaderPtr = (ttIpHeaderPtr)iphPtr;
 
/* Allow all traffic by default */
    errorCode = TM_ENOERROR;
 
/* Filter only incoming packets */
    if (direction == TM_FILTER_INCOMING)
    {
        switch (ipHeaderPtr->iphUlp)
        {
            case TM_IP_UDP:
                udpHeaderPtr = (ttUdpHeaderPtr)ulpPtr;
                if (    (ntohs(udpHeaderPtr->udpDstPort) == 7)
                     && ((ipHeaderPtr->iphFlagsFragOff & TM_IP_FRAG_OFFSET) == 0) )
                {
/* Block all UDP traffic destined for port 7. Cannot check the port on IP fragments at an offset */
                    errorCode = TM_EOPNOTSUPP;
                }
                break;
            case TM_IP_TCP:
                tcpHeaderPtr = (ttTcpHeaderPtr)ulpPtr;
                if (    (ntohs(tcpHeaderPtr->tcpDstPort) != 20)
                     && ((ipHeaderPtr->iphFlagsFragOff & TM_IP_FRAG_OFFSET) == 0) )
                {
/* Block all TCP traffic not destined for port 20. Cannot check the port on IP fragments at an offset*/
                    errorCode = TM_EOPNOTSUPP;
                }
                break;
            case TM_IP_IGMP:
/* Block all IGMP traffic */
                errorCode = TM_EOPNOTSUPP;
                break;
            default:
                break;
        }
    }
    return errorCode;
}

Table of Contents >> Programmer's Reference >> tfUserRegisterFilter