Home | History | Annotate | Line # | Download | only in npfctl
npfctl.h revision 1.6
      1 /*	$NetBSD: npfctl.h,v 1.6 2011/02/02 02:20:25 rmind Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2009-2011 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 #include <net/npf_ncode.h>
     37 #include <net/npf.h>
     38 
     39 #define	_NPF_PRIVATE
     40 #include <npf.h>
     41 
     42 #ifdef DEBUG
     43 #define	DPRINTF(x)	printf x
     44 #else
     45 #define	DPRINTF(x)
     46 #endif
     47 
     48 #define	NPF_DEV_PATH	"/dev/npf"
     49 #define	NPF_CONF_PATH	"/etc/npf.conf"
     50 #define	NPF_SESSDB_PATH	"/var/db/npf_sessions.db"
     51 
     52 typedef struct {
     53 	char *		e_data;
     54 	void *		e_next;
     55 } element_t;
     56 
     57 #define	VAR_SINGLE	1
     58 #define	VAR_ARRAY	2
     59 #define	VAR_TABLE	3
     60 
     61 typedef struct {
     62 	char *		v_key;
     63 	element_t *	v_elements;
     64 	int		v_type;
     65 	int		v_count;
     66 	void *		v_next;
     67 } var_t;
     68 
     69 extern nl_config_t *	npf_conf;
     70 
     71 void *		zalloc(size_t);
     72 char *		xstrdup(const char *);
     73 
     74 void		npfctl_init_data(void);
     75 int		npfctl_ioctl_send(int);
     76 
     77 struct ifaddrs *npfctl_getif(char *, unsigned int *, bool);
     78 bool		npfctl_parse_v4mask(char *, in_addr_t *, in_addr_t *);
     79 void		npfctl_parse_cidr(char *, in_addr_t *, in_addr_t *);
     80 bool		npfctl_parse_port(char *, bool *, in_port_t *, in_port_t *);
     81 
     82 void		npfctl_fill_table(nl_table_t *, char *);
     83 
     84 void		npfctl_rule_ncode(nl_rule_t *, char *, char *,
     85 		    int, int, var_t *, var_t *, var_t *, var_t *);
     86 
     87 size_t		npfctl_calc_ncsize(int []);
     88 size_t		npfctl_failure_offset(int []);
     89 
     90 void		npfctl_gennc_ether(void **, int, uint16_t);
     91 void		npfctl_gennc_v4cidr(void **, int,
     92 		    in_addr_t, in_addr_t, bool);
     93 void		npfctl_gennc_icmp(void **, int, int, int);
     94 void		npfctl_gennc_tcpfl(void **, int , uint8_t, uint8_t);
     95 void		npfctl_gennc_ports(void **, int,
     96 		    in_port_t, in_port_t, bool, bool);
     97 void		npfctl_gennc_tbl(void **, int, u_int , bool);
     98 void		npfctl_gennc_complete(void **);
     99 
    100 int		npf_parseline(char *);
    101 
    102 #endif
    103