Home | History | Annotate | Line # | Download | only in npfctl
npfctl.h revision 1.3
      1 /*	$NetBSD: npfctl.h,v 1.3 2010/11/11 06:30:39 rmind Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2009-2010 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _NPFCTL_H_
     30 #define _NPFCTL_H_
     31 
     32 #include <sys/types.h>
     33 #include <stdio.h>
     34 #include <stdbool.h>
     35 
     36 #ifndef _NPF_TESTING
     37 #include <net/npf.h>
     38 #include <net/npf_ncode.h>
     39 #else
     40 #include "npf.h"
     41 #include "npf_ncode.h"
     42 #endif
     43 
     44 #ifdef DEBUG
     45 #define	DPRINTF(x)	printf x
     46 #else
     47 #define	DPRINTF(x)
     48 #endif
     49 
     50 #define	NPF_DEV_PATH	"/dev/npf"
     51 #define	NPF_CONF_PATH	"/etc/npf.conf"
     52 
     53 typedef struct {
     54 	char *		e_data;
     55 	void *		e_next;
     56 } element_t;
     57 
     58 #define	VAR_SINGLE	1
     59 #define	VAR_ARRAY	2
     60 #define	VAR_TABLE	3
     61 
     62 typedef struct {
     63 	char *		v_key;
     64 	element_t *	v_elements;
     65 	int		v_type;
     66 	int		v_count;
     67 	void *		v_next;
     68 } var_t;
     69 
     70 void *		zalloc(size_t);
     71 char *		xstrdup(const char *);
     72 
     73 void		npfctl_init_data(void);
     74 int		npfctl_ioctl_send(int);
     75 
     76 bool		npfctl_parse_v4mask(char *, in_addr_t *, in_addr_t *);
     77 
     78 prop_dictionary_t npfctl_mk_rule(bool);
     79 void		npfctl_add_rule(prop_dictionary_t, prop_dictionary_t);
     80 void		npfctl_rule_setattr(prop_dictionary_t, int, char *,
     81 		    bool, int, int);
     82 void		npfctl_rule_protodata(prop_dictionary_t, char *, char *,
     83 		    int, int, var_t *, var_t *, var_t *, var_t *);
     84 void		npfctl_rule_icmpdata(prop_dictionary_t, var_t *, var_t *);
     85 
     86 prop_dictionary_t npfctl_lookup_table(char *);
     87 prop_dictionary_t npfctl_mk_table(void);
     88 void		npfctl_table_setup(prop_dictionary_t, char *, char *);
     89 void		npfctl_construct_table(prop_dictionary_t, char *);
     90 void		npfctl_add_table(prop_dictionary_t);
     91 
     92 prop_dictionary_t npfctl_mk_nat(void);
     93 void		npfctl_add_nat(prop_dictionary_t);
     94 void		npfctl_nat_setup(prop_dictionary_t, int, int,
     95 		    char *, char *, char *);
     96 
     97 size_t		npfctl_calc_ncsize(int []);
     98 size_t		npfctl_failure_offset(int []);
     99 
    100 void		npfctl_gennc_ether(void **, int, uint16_t);
    101 void		npfctl_gennc_v4cidr(void **, int,
    102 		    in_addr_t, in_addr_t, bool);
    103 void		npfctl_gennc_icmp(void **, int, int, int);
    104 void		npfctl_gennc_tcpfl(void **, int , uint8_t, uint8_t);
    105 void		npfctl_gennc_ports(void **, int,
    106 		    in_port_t, in_port_t, bool, bool);
    107 void		npfctl_gennc_tbl(void **, int, u_int , bool);
    108 void		npfctl_gennc_complete(void **);
    109 
    110 int		npf_parseline(char *);
    111 
    112 #endif
    113