/*

                                   _JNJ`                        
                               .JNMH`                           
                              JMMF`       `;.                   
                            .NMM)          `MN.                 
                            MMM)            (MML                
                           (MMM`             MMML               
                     M  I  D  N  I  G  H  T    C  o  D  E       
                           (NMMF             MHNH               
                            NMML            .MMM                
                             NMML          .NMH                 
                              4MMNL       .#F                   
                               `4HNNL_   `                      
                                   `"""`                        

                          Copyright (C) 2004-2006
       "Ian (Larry) Latter" <ian dot latter at midnightcode dot org>

    Midnight Code is a registered trademark of Ian Latter.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, and mirrored at the Midnight Code web
    site; as at version 2 of the License only.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
  
    You should have received a copy of the GNU General Public License
    (version 2) along with this program; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA, or see http://midnightcode.org/gplv2.txt

*/


/* midnightcode-filter.h :: Midnight Code packet filter library		*/


#ifndef __MIDNIGHTCODE_FILTER_H
#define __MIDNIGHTCODE_FILTER_H 1


enum midnightcode_filter_action_t
{
  MIDNIGHTCODE_FILTER_ACTION_NONE = 0,
  MIDNIGHTCODE_FILTER_ACTION_INITIALISE,
  MIDNIGHTCODE_FILTER_ACTION_FIND,
  MIDNIGHTCODE_FILTER_ACTION_INSERT,
  MIDNIGHTCODE_FILTER_ACTION_ADD,
  MIDNIGHTCODE_FILTER_ACTION_DELETE,
  MIDNIGHTCODE_FILTER_ACTION_APPLY,
  MIDNIGHTCODE_FILTER_ACTION_SHUTDOWN
};

enum midnightcode_filter_policy_t
{
  MIDNIGHTCODE_FILTER_POLICY_NONE = 0,
  MIDNIGHTCODE_FILTER_POLICY_ACCEPT,
  MIDNIGHTCODE_FILTER_POLICY_DROP,
  MIDNIGHTCODE_FILTER_POLICY_REJECT,
  MIDNIGHTCODE_FILTER_POLICY_RETURN
};

enum midnightcode_filter_error_t
{
  MIDNIGHTCODE_FILTER_ERROR_NONE = 0,
  MIDNIGHTCODE_FILTER_ERROR_ACTION = -1,
  MIDNIGHTCODE_FILTER_ERROR_INITIALISE = -2,
  MIDNIGHTCODE_FILTER_ERROR_FIND = -3,
  MIDNIGHTCODE_FILTER_ERROR_INSERT = -4,
  MIDNIGHTCODE_FILTER_ERROR_ADD = -5,
  MIDNIGHTCODE_FILTER_ERROR_DELETE = -6,
  MIDNIGHTCODE_FILTER_ERROR_APPLY = -7,
  MIDNIGHTCODE_FILTER_ERROR_SHUTDOWN = -8
};

struct midnightcode_filter_target_element_t
{
  char name[32];
  int policy;
};

midnightcode_list_head(midnightcode_filter_target_head_t,
                       midnightcode_filter_target_element_t)

struct midnightcode_filter_rule_element_t
{
  int protocol;
  struct in_addr ipv4_source_ip;
  int ipv4_source_port;
  struct in_addr ipv4_destination_ip;
  int ipv4_destination_port;
  int target;
  int options;
  midnightcode_list_entry(midnightcode_filter_rule_element_t)
};

midnightcode_list_head(midnightcode_filter_rule_head_t,
                       midnightcode_filter_rule_element_t)

struct midnightcode_filter_chain_element_t
{
  int target;
  struct midnightcode_filter_rule_head_t * rules;
  int policy;
  midnightcode_list_entry(midnightcode_filter_chain_element_t)
};

midnightcode_list_head(midnightcode_filter_chain_head_t,
                       midnightcode_filter_chain_element_t)

struct midnightcode_filter_command_t
{
  const char * exec;
};

int midnightcode_filter_bycommand(
                     struct midnightcode_filter_command_t * commands,
                     char * executable);
int midnightcode_filter(int action, char * chain, int position,
                     struct midnightcode_filter_rule_head_t * rule_element,
                     struct midnightcode_filter_chain_head_t * chain_elements);


#endif
