Function Prototypes:tt6UserFilterCallback
Table of Contents >> Programmer's Reference >> tf6UserRegisterFilter
| int tt6UserFilterCallback | ( |
| ttUserInterface interfaceHandle, | |
| void * iph6Ptr, | |
| int totalLength, | |
| int direction | |
| ); |
Function Description
This function prototype should be used for IPv6 User Filter Callbacks registered to handle IPv6 Datagrams. As traffic flows through each interface that has IPv6 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 tf6UserRegisterFilter(). This function is used to perform additional comparison logic of IPv6 packet content to determine how the packet should be handled by the stack. Various return values dictate further stack processing as noted below:
Parameters
- interfaceHandle
- This is the interface on which the IP datagram was delivered.
- iphPtr
- This is the start of the IPv6 header.
- 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 ICMPv6 Destination Unreachable message, administratively prohibited.
- TM_EHOSTUNREACH
- (Incoming packets only) The stack is to respond with an ICMPv6 Destination Unreachable message, administratively prohibited.
- TM_6_EADMIN_SOURCE
- Similar to TM_EHOSTUNREACH, but the reason is more specific: "Source address failed ingress/egress policy." This addition is to support new code 5 mentioned in RFC 4443 section 3.1.
- TM_6_EADMIN_DESTINATION
- Similar to TM_EHOSTUNREACH, but the reason is more specific: "Reject route to destination." This addition is to support new code 6 mentioned in RFC 4443 section 3.1.
Example Code
int filterCallback(ttUserInterface interfaceHandle, void TM_FAR * iph6Ptr, int totalLength, int direction) { tt6IpHeaderPtr ip6HeaderPtr;Ptr; ttUdpHeaderPtr udpHeaderPtr; int errorCode; #if !defined(TM_USE_DRV_SCAT_RECV) || defined(TM_6_USE_FILTERING_CONT_DATA) ttUdpHeaderPtr udpHeaderPtr; #endif /* !TM_USE_DRV_SCAT_RECV || TM_6_USE_FILTERING_CONT_DATA */ int errorCode; #if !defined(TM_USE_DRV_SCAT_RECV) || defined(TM_6_USE_FILTERING_CONT_DATA) int hdrLength; tt8Bit hdrType; #endif /* !TM_USE_DRV_SCAT_RECV || TM_6_USE_FILTERING_CONT_DATA */ /* Filter for all devices and all length of packets */ TM_UNREF_IN_ARG(interfaceHandle); TM_UNREF_IN_ARG(totalLength); ip6HeaderPtr = (tt6IpHeaderPtr)iph6Ptr; /* Process packet by default */ errorCode = TM_ENOERROR; /* Filter only incoming packets */ if (direction == TM_FILTER_INCOMING) { #if !defined(TM_USE_DRV_SCAT_RECV) || defined(TM_6_USE_FILTERING_CONT_DATA) /* Only check one header past IPv6 header */ hdrType = ip6HeaderPtr->iph6Nxt; hdrLength = TM_6_IP_MIN_HDR_LEN; switch (hdrType) { case TM_IP_UDP: udpHeaderPtr = (ttUdpHeaderPtr)((ttCharPtr)iph6Ptr + hdrLength); if (ntohs(udpHeaderPtr->udpDstPort) == 7) { /* Block all UDP traffic destined for port 7 */ errorCode = TM_EOPNOTSUPP; } break; default: break; } #endif /* !TM_USE_DRV_SCAT_RECV || TM_6_USE_FILTERING_CONT_DATA */ } return errorCode; }
Table of Contents >> Programmer's Reference >> tf6UserRegisterFilter