Home | History | Annotate | Line # | Download | only in npfctl
npfctl.h revision 1.8
      1  1.8  rmind /*	$NetBSD: npfctl.h,v 1.8 2012/01/08 21:34:21 rmind Exp $	*/
      2  1.1  rmind 
      3  1.1  rmind /*-
      4  1.8  rmind  * Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
      5  1.1  rmind  * All rights reserved.
      6  1.1  rmind  *
      7  1.1  rmind  * Redistribution and use in source and binary forms, with or without
      8  1.1  rmind  * modification, are permitted provided that the following conditions
      9  1.1  rmind  * are met:
     10  1.1  rmind  * 1. Redistributions of source code must retain the above copyright
     11  1.1  rmind  *    notice, this list of conditions and the following disclaimer.
     12  1.1  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  rmind  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  rmind  *    documentation and/or other materials provided with the distribution.
     15  1.1  rmind  *
     16  1.1  rmind  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  rmind  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  rmind  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  rmind  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  rmind  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  rmind  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  rmind  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  rmind  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  rmind  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  rmind  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  rmind  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  rmind  */
     28  1.1  rmind 
     29  1.1  rmind #ifndef _NPFCTL_H_
     30  1.1  rmind #define _NPFCTL_H_
     31  1.1  rmind 
     32  1.1  rmind #include <stdio.h>
     33  1.1  rmind #include <stdbool.h>
     34  1.8  rmind #include <inttypes.h>
     35  1.1  rmind 
     36  1.6  rmind #include <net/npf_ncode.h>
     37  1.1  rmind #include <net/npf.h>
     38  1.6  rmind 
     39  1.6  rmind #define	_NPF_PRIVATE
     40  1.6  rmind #include <npf.h>
     41  1.1  rmind 
     42  1.8  rmind #include "npf_var.h"
     43  1.1  rmind 
     44  1.1  rmind #define	NPF_DEV_PATH	"/dev/npf"
     45  1.1  rmind #define	NPF_CONF_PATH	"/etc/npf.conf"
     46  1.4  rmind #define	NPF_SESSDB_PATH	"/var/db/npf_sessions.db"
     47  1.1  rmind 
     48  1.8  rmind typedef struct fam_addr_mask {
     49  1.8  rmind 	sa_family_t	fam_family;
     50  1.8  rmind 	npf_addr_t	fam_addr;
     51  1.8  rmind 	npf_netmask_t	fam_mask;
     52  1.8  rmind 	npfvar_t *	fam_interface;
     53  1.8  rmind } fam_addr_mask_t;
     54  1.8  rmind 
     55  1.8  rmind typedef struct port_range {
     56  1.8  rmind 	in_port_t	pr_start;
     57  1.8  rmind 	in_port_t	pr_end;
     58  1.8  rmind } port_range_t;
     59  1.8  rmind 
     60  1.8  rmind typedef struct filt_opts {
     61  1.8  rmind 	npfvar_t *	fo_from;
     62  1.8  rmind 	npfvar_t *	fo_from_port_range;
     63  1.8  rmind 	npfvar_t *	fo_to;
     64  1.8  rmind 	npfvar_t *	fo_to_port_range;
     65  1.8  rmind } filt_opts_t;
     66  1.8  rmind 
     67  1.8  rmind typedef struct opt_proto {
     68  1.8  rmind 	int		op_proto;
     69  1.8  rmind 	npfvar_t *	op_opts;
     70  1.8  rmind } opt_proto_t;
     71  1.8  rmind 
     72  1.8  rmind typedef struct rule_group {
     73  1.8  rmind 	const char *	rg_name;
     74  1.8  rmind 	int		rg_attr;
     75  1.8  rmind 	u_int		rg_ifnum;
     76  1.8  rmind } rule_group_t;
     77  1.8  rmind 
     78  1.8  rmind typedef struct proc_op {
     79  1.8  rmind 	const char *	po_name;
     80  1.8  rmind 	npfvar_t *	po_opts;
     81  1.8  rmind } proc_op_t;
     82  1.8  rmind 
     83  1.8  rmind typedef struct module_arg {
     84  1.8  rmind 	const char *	ma_name;
     85  1.8  rmind 	npfvar_t *	ma_opts;
     86  1.8  rmind } module_arg_t;
     87  1.6  rmind 
     88  1.8  rmind void		yyerror(const char *, ...) __printflike(1, 2);
     89  1.1  rmind void *		zalloc(size_t);
     90  1.8  rmind void *		xrealloc(void *, size_t);
     91  1.1  rmind char *		xstrdup(const char *);
     92  1.8  rmind char *		xstrndup(const char *, size_t);
     93  1.8  rmind 
     94  1.8  rmind bool		npfctl_table_exists_p(const char *);
     95  1.8  rmind in_port_t	npfctl_portno(const char *);
     96  1.8  rmind uint8_t		npfctl_icmpcode(uint8_t, const char *);
     97  1.8  rmind uint8_t		npfctl_icmptype(const char *);
     98  1.8  rmind unsigned long   npfctl_find_ifindex(const char *);
     99  1.8  rmind npfvar_t *	npfctl_parse_tcpflag(const char *);
    100  1.8  rmind npfvar_t *	npfctl_parse_table_id(const char *);
    101  1.8  rmind npfvar_t * 	npfctl_parse_icmpcode(const char *);
    102  1.8  rmind npfvar_t * 	npfctl_parse_icmp(uint8_t, uint8_t);
    103  1.8  rmind npfvar_t *	npfctl_parse_iface(const char *);
    104  1.8  rmind npfvar_t *	npfctl_parse_port_range(in_port_t, in_port_t);
    105  1.8  rmind npfvar_t *	npfctl_parse_fam_addr_mask(const char *, const char *,
    106  1.8  rmind 		    unsigned long *);
    107  1.8  rmind fam_addr_mask_t *npfctl_parse_cidr(char *);
    108  1.8  rmind 
    109  1.8  rmind /*
    110  1.8  rmind  * N-code generation interface.
    111  1.8  rmind  */
    112  1.1  rmind 
    113  1.8  rmind typedef struct nc_ctx nc_ctx_t;
    114  1.1  rmind 
    115  1.8  rmind #define	NC_MATCH_DST		0x01
    116  1.8  rmind #define	NC_MATCH_SRC		0x02
    117  1.8  rmind 
    118  1.8  rmind #define	NC_MATCH_TCP		0x04
    119  1.8  rmind #define	NC_MATCH_UDP		0x08
    120  1.8  rmind 
    121  1.8  rmind nc_ctx_t *	npfctl_ncgen_create(void);
    122  1.8  rmind void *		npfctl_ncgen_complete(nc_ctx_t *, size_t *);
    123  1.8  rmind void		npfctl_ncgen_print(const void *, size_t);
    124  1.8  rmind 
    125  1.8  rmind void		npfctl_ncgen_group(nc_ctx_t *);
    126  1.8  rmind void		npfctl_ncgen_endgroup(nc_ctx_t *);
    127  1.8  rmind 
    128  1.8  rmind void		npfctl_gennc_v4cidr(nc_ctx_t *, int, const npf_addr_t *,
    129  1.8  rmind 		    const npf_netmask_t);
    130  1.8  rmind void		npfctl_gennc_v6cidr(nc_ctx_t *, int, const npf_addr_t *,
    131  1.8  rmind 		    const npf_netmask_t);
    132  1.8  rmind void		npfctl_gennc_ports(nc_ctx_t *, int, in_port_t, in_port_t);
    133  1.8  rmind void		npfctl_gennc_icmp(nc_ctx_t *, int, int);
    134  1.8  rmind void		npfctl_gennc_tbl(nc_ctx_t *, int, u_int);
    135  1.8  rmind void		npfctl_gennc_tcpfl(nc_ctx_t *, uint8_t, uint8_t);
    136  1.8  rmind 
    137  1.8  rmind /*
    138  1.8  rmind  * Configuration building interface.
    139  1.8  rmind  */
    140  1.1  rmind 
    141  1.8  rmind #define	NPFCTL_RDR		1
    142  1.8  rmind #define	NPFCTL_BINAT		2
    143  1.8  rmind #define	NPFCTL_NAT		3
    144  1.8  rmind 
    145  1.8  rmind void		npfctl_config_init(bool);
    146  1.8  rmind int		npfctl_config_send(int);
    147  1.8  rmind int		npfctl_config_flush(int);
    148  1.8  rmind 
    149  1.8  rmind void		npfctl_build_rproc(const char *, npfvar_t *);
    150  1.8  rmind void		npfctl_build_group(const char *, int, u_int);
    151  1.8  rmind void		npfctl_build_rule(int, u_int, sa_family_t,
    152  1.8  rmind 		    const opt_proto_t *, const filt_opts_t *, const char *);
    153  1.8  rmind void		npfctl_build_nat(int, u_int, const filt_opts_t *,
    154  1.8  rmind 		    npfvar_t *, npfvar_t *);
    155  1.8  rmind void		npfctl_build_table(const char *, u_int, const char *);
    156  1.1  rmind 
    157  1.1  rmind #endif
    158