Home | History | Annotate | Line # | Download | only in npfctl
npfctl.h revision 1.26
      1  1.26     rmind /*	$NetBSD: npfctl.h,v 1.26 2013/02/10 23:47:37 rmind Exp $	*/
      2   1.1     rmind 
      3   1.1     rmind /*-
      4  1.25     rmind  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
      5   1.1     rmind  * All rights reserved.
      6   1.1     rmind  *
      7  1.25     rmind  * This material is based upon work partially supported by The
      8  1.25     rmind  * NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
      9  1.25     rmind  *
     10   1.1     rmind  * Redistribution and use in source and binary forms, with or without
     11   1.1     rmind  * modification, are permitted provided that the following conditions
     12   1.1     rmind  * are met:
     13   1.1     rmind  * 1. Redistributions of source code must retain the above copyright
     14   1.1     rmind  *    notice, this list of conditions and the following disclaimer.
     15   1.1     rmind  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1     rmind  *    notice, this list of conditions and the following disclaimer in the
     17   1.1     rmind  *    documentation and/or other materials provided with the distribution.
     18   1.1     rmind  *
     19   1.1     rmind  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1     rmind  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1     rmind  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1     rmind  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1     rmind  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1     rmind  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1     rmind  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1     rmind  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1     rmind  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1     rmind  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1     rmind  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     rmind  */
     31   1.1     rmind 
     32   1.1     rmind #ifndef _NPFCTL_H_
     33   1.1     rmind #define _NPFCTL_H_
     34   1.1     rmind 
     35   1.1     rmind #include <stdio.h>
     36   1.1     rmind #include <stdbool.h>
     37   1.8     rmind #include <inttypes.h>
     38  1.17     rmind #include <assert.h>
     39  1.22     rmind #include <util.h>
     40   1.1     rmind 
     41   1.6     rmind #include <net/npf_ncode.h>
     42   1.1     rmind #include <net/npf.h>
     43   1.6     rmind 
     44   1.6     rmind #define	_NPF_PRIVATE
     45   1.6     rmind #include <npf.h>
     46   1.1     rmind 
     47   1.8     rmind #include "npf_var.h"
     48   1.1     rmind 
     49   1.1     rmind #define	NPF_DEV_PATH	"/dev/npf"
     50   1.1     rmind #define	NPF_CONF_PATH	"/etc/npf.conf"
     51   1.4     rmind #define	NPF_SESSDB_PATH	"/var/db/npf_sessions.db"
     52   1.1     rmind 
     53   1.8     rmind typedef struct fam_addr_mask {
     54   1.8     rmind 	sa_family_t	fam_family;
     55   1.8     rmind 	npf_addr_t	fam_addr;
     56   1.8     rmind 	npf_netmask_t	fam_mask;
     57  1.23     rmind 	unsigned long	fam_ifindex;
     58   1.8     rmind } fam_addr_mask_t;
     59   1.8     rmind 
     60  1.23     rmind typedef struct ifnet_addr {
     61  1.23     rmind 	unsigned long	ifna_index;
     62  1.23     rmind 	sa_family_t	ifna_family;
     63  1.23     rmind 	npfvar_t *	ifna_filter;
     64  1.23     rmind 	npfvar_t *	ifna_addrs;
     65  1.23     rmind } ifnet_addr_t;
     66  1.23     rmind 
     67   1.8     rmind typedef struct port_range {
     68   1.8     rmind 	in_port_t	pr_start;
     69   1.8     rmind 	in_port_t	pr_end;
     70   1.8     rmind } port_range_t;
     71   1.8     rmind 
     72  1.15     rmind typedef struct addr_port {
     73  1.15     rmind 	npfvar_t *	ap_netaddr;
     74  1.15     rmind 	npfvar_t *	ap_portrange;
     75  1.15     rmind } addr_port_t;
     76  1.15     rmind 
     77   1.8     rmind typedef struct filt_opts {
     78  1.15     rmind 	addr_port_t	fo_from;
     79  1.15     rmind 	addr_port_t	fo_to;
     80   1.8     rmind } filt_opts_t;
     81   1.8     rmind 
     82   1.8     rmind typedef struct opt_proto {
     83   1.8     rmind 	int		op_proto;
     84   1.8     rmind 	npfvar_t *	op_opts;
     85   1.8     rmind } opt_proto_t;
     86   1.8     rmind 
     87   1.8     rmind typedef struct rule_group {
     88   1.8     rmind 	const char *	rg_name;
     89  1.14     rmind 	uint32_t	rg_attr;
     90   1.8     rmind 	u_int		rg_ifnum;
     91  1.25     rmind 	bool		rg_default;
     92   1.8     rmind } rule_group_t;
     93   1.8     rmind 
     94  1.20     rmind typedef struct proc_call {
     95  1.20     rmind 	const char *	pc_name;
     96  1.20     rmind 	npfvar_t *	pc_opts;
     97  1.20     rmind } proc_call_t;
     98  1.20     rmind 
     99  1.20     rmind typedef struct proc_param {
    100  1.20     rmind 	const char *	pp_param;
    101  1.20     rmind 	const char *	pp_value;
    102  1.20     rmind } proc_param_t;
    103   1.6     rmind 
    104  1.25     rmind enum { NPFCTL_PARSE_FILE, NPFCTL_PARSE_STRING };
    105  1.25     rmind 
    106   1.9     joerg void		yyerror(const char *, ...) __printflike(1, 2) __dead;
    107  1.25     rmind void		npfctl_parse_file(const char *);
    108  1.25     rmind void		npfctl_parse_string(const char *);
    109   1.8     rmind 
    110  1.11     rmind void		npfctl_print_error(const nl_error_t *);
    111  1.21     rmind char *		npfctl_print_addrmask(int, npf_addr_t *, npf_netmask_t);
    112   1.8     rmind bool		npfctl_table_exists_p(const char *);
    113  1.16     rmind int		npfctl_protono(const char *);
    114   1.8     rmind in_port_t	npfctl_portno(const char *);
    115  1.18       spz uint8_t		npfctl_icmpcode(int, uint8_t, const char *);
    116  1.18       spz uint8_t		npfctl_icmptype(int, const char *);
    117   1.8     rmind unsigned long   npfctl_find_ifindex(const char *);
    118  1.23     rmind npfvar_t *	npfctl_parse_ifnet(const char *, const int);
    119   1.8     rmind npfvar_t *	npfctl_parse_tcpflag(const char *);
    120   1.8     rmind npfvar_t *	npfctl_parse_table_id(const char *);
    121  1.18       spz npfvar_t * 	npfctl_parse_icmp(int, int, int);
    122   1.8     rmind npfvar_t *	npfctl_parse_port_range(in_port_t, in_port_t);
    123  1.12  christos npfvar_t *	npfctl_parse_port_range_variable(const char *);
    124   1.8     rmind npfvar_t *	npfctl_parse_fam_addr_mask(const char *, const char *,
    125   1.8     rmind 		    unsigned long *);
    126  1.17     rmind bool		npfctl_parse_cidr(char *, fam_addr_mask_t *, int *);
    127   1.8     rmind 
    128   1.8     rmind /*
    129  1.20     rmind  * NPF extension loading.
    130  1.20     rmind  */
    131  1.20     rmind 
    132  1.20     rmind typedef struct npf_extmod npf_extmod_t;
    133  1.20     rmind 
    134  1.20     rmind npf_extmod_t *	npf_extmod_get(const char *, nl_ext_t **);
    135  1.20     rmind int		npf_extmod_param(npf_extmod_t *, nl_ext_t *,
    136  1.20     rmind 		    const char *, const char *);
    137  1.20     rmind 
    138  1.20     rmind /*
    139   1.8     rmind  * N-code generation interface.
    140   1.8     rmind  */
    141   1.1     rmind 
    142   1.8     rmind typedef struct nc_ctx nc_ctx_t;
    143   1.1     rmind 
    144   1.8     rmind #define	NC_MATCH_DST		0x01
    145   1.8     rmind #define	NC_MATCH_SRC		0x02
    146   1.8     rmind 
    147   1.8     rmind #define	NC_MATCH_TCP		0x04
    148   1.8     rmind #define	NC_MATCH_UDP		0x08
    149  1.15     rmind #define	NC_MATCH_ICMP		0x10
    150  1.18       spz #define	NC_MATCH_ICMP6		0x20
    151   1.8     rmind 
    152   1.8     rmind nc_ctx_t *	npfctl_ncgen_create(void);
    153   1.8     rmind void *		npfctl_ncgen_complete(nc_ctx_t *, size_t *);
    154   1.8     rmind void		npfctl_ncgen_print(const void *, size_t);
    155   1.8     rmind 
    156   1.8     rmind void		npfctl_ncgen_group(nc_ctx_t *);
    157   1.8     rmind void		npfctl_ncgen_endgroup(nc_ctx_t *);
    158   1.8     rmind 
    159   1.8     rmind void		npfctl_gennc_v4cidr(nc_ctx_t *, int, const npf_addr_t *,
    160   1.8     rmind 		    const npf_netmask_t);
    161   1.8     rmind void		npfctl_gennc_v6cidr(nc_ctx_t *, int, const npf_addr_t *,
    162   1.8     rmind 		    const npf_netmask_t);
    163   1.8     rmind void		npfctl_gennc_ports(nc_ctx_t *, int, in_port_t, in_port_t);
    164   1.8     rmind void		npfctl_gennc_icmp(nc_ctx_t *, int, int);
    165  1.18       spz void		npfctl_gennc_icmp6(nc_ctx_t *, int, int);
    166   1.8     rmind void		npfctl_gennc_tbl(nc_ctx_t *, int, u_int);
    167   1.8     rmind void		npfctl_gennc_tcpfl(nc_ctx_t *, uint8_t, uint8_t);
    168  1.16     rmind void		npfctl_gennc_proto(nc_ctx_t *ctx, uint8_t, uint8_t);
    169   1.8     rmind 
    170   1.8     rmind /*
    171  1.15     rmind  * N-code disassembler.
    172  1.15     rmind  */
    173  1.15     rmind 
    174  1.15     rmind typedef struct nc_inf nc_inf_t;
    175  1.15     rmind 
    176  1.15     rmind nc_inf_t *	npfctl_ncode_disinf(FILE *);
    177  1.15     rmind int		npfctl_ncode_disassemble(nc_inf_t *, const void *, size_t);
    178  1.15     rmind 
    179  1.15     rmind /*
    180   1.8     rmind  * Configuration building interface.
    181   1.8     rmind  */
    182   1.1     rmind 
    183  1.15     rmind #define	NPFCTL_NAT_DYNAMIC	1
    184  1.15     rmind #define	NPFCTL_NAT_STATIC	2
    185   1.8     rmind 
    186   1.8     rmind void		npfctl_config_init(bool);
    187  1.19     rmind int		npfctl_config_send(int, const char *);
    188  1.24     rmind nl_config_t *	npfctl_config_ref(void);
    189  1.14     rmind int		npfctl_config_show(int);
    190  1.26     rmind int		npfctl_ruleset_show(int, const char *);
    191  1.26     rmind 
    192  1.25     rmind nl_rule_t *	npfctl_rule_ref(void);
    193  1.19     rmind unsigned long	npfctl_debug_addif(const char *);
    194   1.8     rmind 
    195   1.8     rmind void		npfctl_build_rproc(const char *, npfvar_t *);
    196  1.25     rmind void		npfctl_build_group(const char *, int, u_int, bool);
    197  1.25     rmind void		npfctl_build_group_end(void);
    198   1.8     rmind void		npfctl_build_rule(int, u_int, sa_family_t,
    199   1.8     rmind 		    const opt_proto_t *, const filt_opts_t *, const char *);
    200  1.19     rmind void		npfctl_build_natseg(int, int, u_int, const addr_port_t *,
    201  1.15     rmind 		    const addr_port_t *, const filt_opts_t *);
    202   1.8     rmind void		npfctl_build_table(const char *, u_int, const char *);
    203  1.14     rmind 
    204   1.1     rmind #endif
    205