Home | History | Annotate | Line # | Download | only in npfctl
npfctl.h revision 1.41
      1  1.41  christos /*	$NetBSD: npfctl.h,v 1.41 2016/12/27 20:14:35 christos 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.30     rmind #define	NPF_BPFCOP
     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.38     rmind #define	NPF_DB_PATH	"/var/db/npf.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.34     rmind 	char *		ifna_name;
     62  1.23     rmind 	unsigned long	ifna_index;
     63  1.23     rmind 	sa_family_t	ifna_family;
     64  1.23     rmind 	npfvar_t *	ifna_filter;
     65  1.23     rmind 	npfvar_t *	ifna_addrs;
     66  1.23     rmind } ifnet_addr_t;
     67  1.23     rmind 
     68   1.8     rmind typedef struct port_range {
     69   1.8     rmind 	in_port_t	pr_start;
     70   1.8     rmind 	in_port_t	pr_end;
     71   1.8     rmind } port_range_t;
     72   1.8     rmind 
     73  1.15     rmind typedef struct addr_port {
     74  1.15     rmind 	npfvar_t *	ap_netaddr;
     75  1.15     rmind 	npfvar_t *	ap_portrange;
     76  1.15     rmind } addr_port_t;
     77  1.15     rmind 
     78   1.8     rmind typedef struct filt_opts {
     79  1.15     rmind 	addr_port_t	fo_from;
     80  1.15     rmind 	addr_port_t	fo_to;
     81   1.8     rmind } filt_opts_t;
     82   1.8     rmind 
     83   1.8     rmind typedef struct opt_proto {
     84   1.8     rmind 	int		op_proto;
     85   1.8     rmind 	npfvar_t *	op_opts;
     86   1.8     rmind } opt_proto_t;
     87   1.8     rmind 
     88   1.8     rmind typedef struct rule_group {
     89   1.8     rmind 	const char *	rg_name;
     90  1.14     rmind 	uint32_t	rg_attr;
     91  1.34     rmind 	const char *	rg_ifname;
     92  1.25     rmind 	bool		rg_default;
     93   1.8     rmind } rule_group_t;
     94   1.8     rmind 
     95  1.20     rmind typedef struct proc_call {
     96  1.20     rmind 	const char *	pc_name;
     97  1.20     rmind 	npfvar_t *	pc_opts;
     98  1.20     rmind } proc_call_t;
     99  1.20     rmind 
    100  1.20     rmind typedef struct proc_param {
    101  1.20     rmind 	const char *	pp_param;
    102  1.20     rmind 	const char *	pp_value;
    103  1.20     rmind } proc_param_t;
    104   1.6     rmind 
    105  1.25     rmind enum { NPFCTL_PARSE_FILE, NPFCTL_PARSE_STRING };
    106  1.25     rmind 
    107  1.30     rmind bool		join(char *, size_t, int, char **, const char *);
    108   1.9     joerg void		yyerror(const char *, ...) __printflike(1, 2) __dead;
    109  1.39  christos void		npfctl_bpfjit(bool);
    110  1.25     rmind void		npfctl_parse_file(const char *);
    111  1.25     rmind void		npfctl_parse_string(const char *);
    112   1.8     rmind 
    113  1.40  christos void		npfctl_print_error(const npf_error_t *);
    114  1.41  christos char *		npfctl_print_addrmask(int, const char *, const npf_addr_t *,
    115  1.41  christos 		    npf_netmask_t);
    116  1.34     rmind void		npfctl_note_interface(const char *);
    117  1.35     rmind unsigned	npfctl_table_getid(const char *);
    118  1.16     rmind int		npfctl_protono(const char *);
    119   1.8     rmind in_port_t	npfctl_portno(const char *);
    120  1.18       spz uint8_t		npfctl_icmpcode(int, uint8_t, const char *);
    121  1.18       spz uint8_t		npfctl_icmptype(int, const char *);
    122  1.23     rmind npfvar_t *	npfctl_parse_ifnet(const char *, const int);
    123   1.8     rmind npfvar_t *	npfctl_parse_tcpflag(const char *);
    124   1.8     rmind npfvar_t *	npfctl_parse_table_id(const char *);
    125  1.18       spz npfvar_t * 	npfctl_parse_icmp(int, int, int);
    126   1.8     rmind npfvar_t *	npfctl_parse_port_range(in_port_t, in_port_t);
    127  1.12  christos npfvar_t *	npfctl_parse_port_range_variable(const char *);
    128   1.8     rmind npfvar_t *	npfctl_parse_fam_addr_mask(const char *, const char *,
    129   1.8     rmind 		    unsigned long *);
    130  1.17     rmind bool		npfctl_parse_cidr(char *, fam_addr_mask_t *, int *);
    131  1.36     rmind uint16_t	npfctl_npt66_calcadj(npf_netmask_t, const npf_addr_t *,
    132  1.36     rmind 		    const npf_addr_t *);
    133   1.8     rmind 
    134   1.8     rmind /*
    135  1.20     rmind  * NPF extension loading.
    136  1.20     rmind  */
    137  1.20     rmind 
    138  1.20     rmind typedef struct npf_extmod npf_extmod_t;
    139  1.20     rmind 
    140  1.20     rmind npf_extmod_t *	npf_extmod_get(const char *, nl_ext_t **);
    141  1.20     rmind int		npf_extmod_param(npf_extmod_t *, nl_ext_t *,
    142  1.20     rmind 		    const char *, const char *);
    143  1.20     rmind 
    144  1.20     rmind /*
    145  1.30     rmind  * BFF byte-code generation interface.
    146  1.30     rmind  */
    147  1.30     rmind 
    148  1.30     rmind typedef struct npf_bpf npf_bpf_t;
    149  1.30     rmind 
    150  1.30     rmind #define	MATCH_DST	0x01
    151  1.30     rmind #define	MATCH_SRC	0x02
    152  1.30     rmind 
    153  1.30     rmind enum {
    154  1.31     rmind 	BM_IPVER, BM_PROTO, BM_SRC_CIDR, BM_SRC_TABLE, BM_DST_CIDR,
    155  1.31     rmind 	BM_DST_TABLE, BM_SRC_PORTS, BM_DST_PORTS, BM_TCPFL, BM_ICMP_TYPE,
    156  1.30     rmind 	BM_ICMP_CODE,
    157  1.30     rmind };
    158  1.30     rmind 
    159  1.31     rmind npf_bpf_t *	npfctl_bpf_create(void);
    160  1.30     rmind struct bpf_program *npfctl_bpf_complete(npf_bpf_t *);
    161  1.31     rmind const void *	npfctl_bpf_bmarks(npf_bpf_t *, size_t *);
    162  1.31     rmind void		npfctl_bpf_destroy(npf_bpf_t *);
    163  1.15     rmind 
    164  1.31     rmind void		npfctl_bpf_group(npf_bpf_t *);
    165  1.31     rmind void		npfctl_bpf_endgroup(npf_bpf_t *);
    166  1.15     rmind 
    167  1.31     rmind void		npfctl_bpf_proto(npf_bpf_t *, sa_family_t, int);
    168  1.31     rmind void		npfctl_bpf_cidr(npf_bpf_t *, u_int, sa_family_t,
    169  1.31     rmind 		    const npf_addr_t *, const npf_netmask_t);
    170  1.31     rmind void		npfctl_bpf_ports(npf_bpf_t *, u_int, in_port_t, in_port_t);
    171  1.37     rmind void		npfctl_bpf_tcpfl(npf_bpf_t *, uint8_t, uint8_t, bool);
    172  1.31     rmind void		npfctl_bpf_icmp(npf_bpf_t *, int, int);
    173  1.31     rmind void		npfctl_bpf_table(npf_bpf_t *, u_int, u_int);
    174  1.15     rmind 
    175  1.15     rmind /*
    176   1.8     rmind  * Configuration building interface.
    177   1.8     rmind  */
    178   1.1     rmind 
    179  1.15     rmind #define	NPFCTL_NAT_DYNAMIC	1
    180  1.15     rmind #define	NPFCTL_NAT_STATIC	2
    181   1.8     rmind 
    182   1.8     rmind void		npfctl_config_init(bool);
    183  1.19     rmind int		npfctl_config_send(int, const char *);
    184  1.24     rmind nl_config_t *	npfctl_config_ref(void);
    185  1.14     rmind int		npfctl_config_show(int);
    186  1.40  christos void		npfctl_config_save(nl_config_t *, const char *);
    187  1.40  christos 
    188  1.40  christos void		npfctl_show_init(void);
    189  1.26     rmind int		npfctl_ruleset_show(int, const char *);
    190  1.26     rmind 
    191  1.25     rmind nl_rule_t *	npfctl_rule_ref(void);
    192  1.34     rmind bool		npfctl_debug_addif(const char *);
    193   1.8     rmind 
    194  1.29  christos void		npfctl_build_alg(const char *);
    195   1.8     rmind void		npfctl_build_rproc(const char *, npfvar_t *);
    196  1.34     rmind void		npfctl_build_group(const char *, int, const char *, bool);
    197  1.25     rmind void		npfctl_build_group_end(void);
    198  1.34     rmind void		npfctl_build_rule(uint32_t, const char *, sa_family_t,
    199  1.33     rmind 		    const opt_proto_t *, const filt_opts_t *,
    200  1.33     rmind 		    const char *, const char *);
    201  1.34     rmind void		npfctl_build_natseg(int, int, const char *,
    202  1.34     rmind 		    const addr_port_t *, const addr_port_t *,
    203  1.36     rmind 		    const filt_opts_t *, unsigned);
    204  1.34     rmind void		npfctl_build_maprset(const char *, int, const char *);
    205   1.8     rmind void		npfctl_build_table(const char *, u_int, const char *);
    206  1.14     rmind 
    207  1.40  christos /*
    208  1.40  christos  * For the systems which do not define TH_ECE and TW_CRW.
    209  1.40  christos  */
    210  1.40  christos #ifndef TH_ECE
    211  1.40  christos #define	TH_ECE	  0x40
    212  1.40  christos #endif
    213  1.40  christos #ifndef TH_CWR
    214  1.40  christos #define	TH_CWR	  0x80
    215  1.40  christos #endif
    216  1.40  christos 
    217   1.1     rmind #endif
    218