/*****************************************************************************
* Copyright (c) 2005 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/

#ifndef naipfilter_h

#define naipfilter_h

#include "Npttypes.h"
#include "nastatus.h"
#include <sockapi.h>

/*ad*
 * These are possible values for direction argument for the @link naIpFilterUserCallback.
 *
 * @external
 * @include     <naipfilter.h>
 * @category Networking:IP_Packet_Filtering
 * @since 7.5
 * @name IPFILTER_DIRECTIONS    "Values for IP filter direction"
 *
 * @param  NA_IP_FILTER_INCOMING	Incomming packet.
 * @param  NA_IP_FILTER_OUTGOING    Outgoing packet.
 *
*ad*/
#define NA_IP_FILTER_INCOMING	TM_FILTER_INCOMING
#define NA_IP_FILTER_OUTGOING	TM_FILTER_OUTGOING

/*ad*
 * These are possible return codes of the @link naIpFilterUserCallback and @link naIpv6FilterUserCallback.
 *
 * @external
 * @include     <naipfilter.h>
 * @category Networking:IP_Packet_Filtering
 * @since 7.5
 * @name IPFILTER_RETURNS    "Return values of IPv4 and IPv6 user filters"
 *
 * @param  NA_IP_FILTER_ENOERROR		Allows the IP stack to process the IP packet normally (0).
 * @param  NA_IP_FILTER_EOPNOTSUPP		Forces the IP stack to drop the IP packet.
 * @param  NA_IP_FILTER_ENETUNREACH		Forces the IP stack to respond with ICMMP NETWORK UNREACH (used only for incomming packets).
 * @param  NA_IP_FILTER_EHOSTUNREACH    Forces the IP stack to respond with ICMP HOST UNREACH (used only for incomming packets).
 *
 *ad*/
#define NA_IP_FILTER_ENOERROR		TM_ENOERROR
#define NA_IP_FILTER_EOPNOTSUPP		TM_EOPNOTSUPP
#define NA_IP_FILTER_ENETUNREACH	TM_ENETUNREACH
#define NA_IP_FILTER_EHOSTUNREACH   TM_EHOSTUNREACH

/*ad* 
 * This type defines the callback function for filtering IPv4 packets.  The return
 * value of this function determines how the IP stack continues processing the IP packet.
 *
 * @external
 * @category Networking:IP_Packet_Filtering
 * @since 7.4
 *
 * @param interfaceHandle  This is the interface from/to where the IP packet was received/sent.
 *                         Use @link naIfConfigGetInterfaceHandle to get the handle for the interface name.
 * @param iphPtr           The pointer to the IP header.
 * @param ulpPtr           The pointer to the ULP header.
 * @param totalLength      The total length of the IP datagram.
 * @param direction        Indicates an incoming (NA_IP_FILTER_INCOMING) or outgoing (NA_IP_FILTER_OUTGOING) packet.
 *                  
 * @return NA_IP_FILTER_ENOERROR      Allows the IP stack to process the IP packet normally.
 * @return NA_IP_FILTER_EOPNOTSUPP    Forces the IP stack to drop the IP packet.
 * @return NA_IP_FILTER_ENETUNREACH   Forces the IP stack to respond with ICMMP NETWORK UNREACH (used only for incomming packets).
 * @return NA_IP_FILTER_EHOSTUNREACH  Forces the IP stack to respond with ICMP HOST UNREACH (used only for incomming packets).
 *
 *ad*/

typedef int (* naIpFilterUserCallback)( void * interfaceHandle, void * iphPtr, void * ulpPtr, int totalLength, int direction );

/*ad*
 * This type defines the callback function for filtering IPv6 packets.  The return
 * values determine how the IP stack continues processing the IP packet.
 *
 * @external
 * @category Networking:IP_Packet_Filtering
 * @since 7.5
 *
 * @param interfaceHandle  This is the interface from/to the packet was received/sent.
 *						   Use @link naIfConfigGetInterfaceHandle to get the handle for the interface name.
 * @param iph6Ptr          The pointer to the IPv6 header. 
 * @param totalLength      The total length of the IP datagram.
 * @param direction        Indicates an incoming (NA_IP_FILTER_INCOMING) or outgoing 
 *						   (NA_IP_FILTER_OUTGOING) packet.
 *                  
 * @return NA_IP_FILTER_ENOERROR      Allows the IP stack to process the IPv6 packet normally.
 * @return NA_IP_FILTER_EOPNOTSUPP    Forces the IP stack to drop the IPv6 packet.
 * @return NA_IP_FILTER_ENETUNREACH   Forces the IP stack to respond with ICMMP NETWORK UNREACH (used only for incomming packets).
 * @return NA_IP_FILTER_EHOSTUNREACH  Forces the IP stack to respond with ICMP HOST UNREACH (used only for incomming packets).
 *
 *ad*/
typedef int (* naIpv6FilterUserCallback)( void * interfaceHandle, void * iph6Ptr, int totalLength, int direction);

NaStatus naIpFilterRegisterUserCallback(naIpFilterUserCallback filterCallback);
NaStatus naIpv6FilterRegisterUserCallback(naIpv6FilterUserCallback filterCallback);
NaStatus naIpFilterEnableFiltering(const char * ifname);

#endif
