Home | History | Annotate | Line # | Download | only in pfctl
pfctl_parser.h revision 1.4.22.1
      1  1.4.22.1  wrstuden /*	$NetBSD: pfctl_parser.h,v 1.4.22.1 2008/06/23 04:28:53 wrstuden Exp $	*/
      2  1.4.22.1  wrstuden /*	$OpenBSD: pfctl_parser.h,v 1.86 2006/10/31 23:46:25 mcbride Exp $ */
      3       1.1    itojun 
      4       1.1    itojun /*
      5       1.1    itojun  * Copyright (c) 2001 Daniel Hartmeier
      6       1.1    itojun  * All rights reserved.
      7       1.1    itojun  *
      8       1.1    itojun  * Redistribution and use in source and binary forms, with or without
      9       1.1    itojun  * modification, are permitted provided that the following conditions
     10       1.1    itojun  * are met:
     11       1.1    itojun  *
     12       1.1    itojun  *    - Redistributions of source code must retain the above copyright
     13       1.1    itojun  *      notice, this list of conditions and the following disclaimer.
     14       1.1    itojun  *    - Redistributions in binary form must reproduce the above
     15       1.1    itojun  *      copyright notice, this list of conditions and the following
     16       1.1    itojun  *      disclaimer in the documentation and/or other materials provided
     17       1.1    itojun  *      with the distribution.
     18       1.1    itojun  *
     19       1.1    itojun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20       1.1    itojun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21       1.1    itojun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     22       1.1    itojun  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     23       1.1    itojun  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     24       1.1    itojun  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     25       1.1    itojun  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26       1.1    itojun  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     27       1.1    itojun  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28       1.1    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     29       1.1    itojun  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30       1.1    itojun  * POSSIBILITY OF SUCH DAMAGE.
     31       1.1    itojun  *
     32       1.1    itojun  */
     33       1.1    itojun 
     34       1.1    itojun #ifndef _PFCTL_PARSER_H_
     35       1.1    itojun #define _PFCTL_PARSER_H_
     36       1.1    itojun 
     37       1.1    itojun #define PF_OSFP_FILE		"/etc/pf.os"
     38       1.1    itojun 
     39       1.1    itojun #define PF_OPT_DISABLE		0x0001
     40       1.1    itojun #define PF_OPT_ENABLE		0x0002
     41       1.1    itojun #define PF_OPT_VERBOSE		0x0004
     42       1.1    itojun #define PF_OPT_NOACTION		0x0008
     43       1.1    itojun #define PF_OPT_QUIET		0x0010
     44       1.1    itojun #define PF_OPT_CLRRULECTRS	0x0020
     45       1.1    itojun #define PF_OPT_USEDNS		0x0040
     46       1.1    itojun #define PF_OPT_VERBOSE2		0x0080
     47       1.1    itojun #define PF_OPT_DUMMYACTION	0x0100
     48       1.1    itojun #define PF_OPT_DEBUG		0x0200
     49       1.1    itojun #define PF_OPT_SHOWALL		0x0400
     50       1.3      yamt #define PF_OPT_OPTIMIZE		0x0800
     51       1.4     peter #define PF_OPT_MERGE		0x2000
     52  1.4.22.1  wrstuden #define PF_OPT_RECURSE		0x4000
     53       1.1    itojun 
     54       1.1    itojun #define PF_TH_ALL		0xFF
     55       1.1    itojun 
     56       1.1    itojun #define PF_NAT_PROXY_PORT_LOW	50001
     57       1.1    itojun #define PF_NAT_PROXY_PORT_HIGH	65535
     58       1.1    itojun 
     59  1.4.22.1  wrstuden #define PF_OPTIMIZE_BASIC	0x0001
     60  1.4.22.1  wrstuden #define PF_OPTIMIZE_PROFILE	0x0002
     61  1.4.22.1  wrstuden 
     62       1.1    itojun #define FCNT_NAMES { \
     63       1.1    itojun 	"searches", \
     64       1.1    itojun 	"inserts", \
     65       1.1    itojun 	"removals", \
     66       1.1    itojun 	NULL \
     67       1.1    itojun }
     68       1.1    itojun 
     69       1.3      yamt struct pfr_buffer;	/* forward definition */
     70       1.3      yamt 
     71       1.3      yamt 
     72       1.1    itojun struct pfctl {
     73       1.1    itojun 	int dev;
     74       1.1    itojun 	int opts;
     75  1.4.22.1  wrstuden 	int optimize;
     76       1.1    itojun 	int loadopt;
     77  1.4.22.1  wrstuden 	int asd;			/* anchor stack depth */
     78  1.4.22.1  wrstuden 	int bn;				/* brace number */
     79  1.4.22.1  wrstuden 	int brace;
     80       1.1    itojun 	int tdirty;			/* kernel dirty */
     81  1.4.22.1  wrstuden #define PFCTL_ANCHOR_STACK_DEPTH 64
     82  1.4.22.1  wrstuden 	struct pf_anchor *astack[PFCTL_ANCHOR_STACK_DEPTH];
     83       1.1    itojun 	struct pfioc_pooladdr paddr;
     84       1.1    itojun 	struct pfioc_altq *paltq;
     85       1.1    itojun 	struct pfioc_queue *pqueue;
     86       1.1    itojun 	struct pfr_buffer *trans;
     87  1.4.22.1  wrstuden 	struct pf_anchor *anchor, *alast;
     88       1.1    itojun 	const char *ruleset;
     89       1.4     peter 
     90       1.4     peter 	/* 'set foo' options */
     91       1.4     peter 	u_int32_t	 timeout[PFTM_MAX];
     92       1.4     peter 	u_int32_t	 limit[PF_LIMIT_MAX];
     93       1.4     peter 	u_int32_t	 debug;
     94       1.4     peter 	u_int32_t	 hostid;
     95       1.4     peter 	char		*ifname;
     96       1.4     peter 
     97       1.4     peter 	u_int8_t	 timeout_set[PFTM_MAX];
     98       1.4     peter 	u_int8_t	 limit_set[PF_LIMIT_MAX];
     99       1.4     peter 	u_int8_t	 debug_set;
    100       1.4     peter 	u_int8_t	 hostid_set;
    101       1.4     peter 	u_int8_t	 ifname_set;
    102       1.1    itojun };
    103       1.1    itojun 
    104       1.1    itojun struct node_if {
    105       1.1    itojun 	char			 ifname[IFNAMSIZ];
    106       1.1    itojun 	u_int8_t		 not;
    107       1.3      yamt 	u_int8_t		 dynamic; /* antispoof */
    108       1.1    itojun 	u_int			 ifa_flags;
    109       1.1    itojun 	struct node_if		*next;
    110       1.1    itojun 	struct node_if		*tail;
    111       1.1    itojun };
    112       1.1    itojun 
    113       1.1    itojun struct node_host {
    114       1.1    itojun 	struct pf_addr_wrap	 addr;
    115       1.1    itojun 	struct pf_addr		 bcast;
    116       1.1    itojun 	struct pf_addr		 peer;
    117       1.1    itojun 	sa_family_t		 af;
    118       1.1    itojun 	u_int8_t		 not;
    119       1.1    itojun 	u_int32_t		 ifindex;	/* link-local IPv6 addrs */
    120       1.1    itojun 	char			*ifname;
    121       1.1    itojun 	u_int			 ifa_flags;
    122       1.1    itojun 	struct node_host	*next;
    123       1.1    itojun 	struct node_host	*tail;
    124       1.1    itojun };
    125       1.1    itojun 
    126       1.1    itojun struct node_os {
    127       1.1    itojun 	char			*os;
    128       1.1    itojun 	pf_osfp_t		 fingerprint;
    129       1.1    itojun 	struct node_os		*next;
    130       1.1    itojun 	struct node_os		*tail;
    131       1.1    itojun };
    132       1.1    itojun 
    133       1.1    itojun struct node_queue_bw {
    134       1.1    itojun 	u_int32_t	bw_absolute;
    135       1.1    itojun 	u_int16_t	bw_percent;
    136       1.1    itojun };
    137       1.1    itojun 
    138       1.1    itojun struct node_hfsc_sc {
    139       1.1    itojun 	struct node_queue_bw	m1;	/* slope of 1st segment; bps */
    140       1.1    itojun 	u_int			d;	/* x-projection of m1; msec */
    141       1.1    itojun 	struct node_queue_bw	m2;	/* slope of 2nd segment; bps */
    142       1.1    itojun 	u_int8_t		used;
    143       1.1    itojun };
    144       1.1    itojun 
    145       1.1    itojun struct node_hfsc_opts {
    146       1.1    itojun 	struct node_hfsc_sc	realtime;
    147       1.1    itojun 	struct node_hfsc_sc	linkshare;
    148       1.1    itojun 	struct node_hfsc_sc	upperlimit;
    149       1.1    itojun 	int			flags;
    150       1.1    itojun };
    151       1.1    itojun 
    152       1.1    itojun struct node_queue_opt {
    153       1.1    itojun 	int			 qtype;
    154       1.1    itojun 	union {
    155       1.1    itojun 		struct cbq_opts		cbq_opts;
    156       1.1    itojun 		struct priq_opts	priq_opts;
    157       1.1    itojun 		struct node_hfsc_opts	hfsc_opts;
    158       1.1    itojun 	}			 data;
    159       1.1    itojun };
    160       1.1    itojun 
    161       1.1    itojun SIMPLEQ_HEAD(node_tinithead, node_tinit);
    162       1.1    itojun struct node_tinit {	/* table initializer */
    163       1.1    itojun 	SIMPLEQ_ENTRY(node_tinit)	 entries;
    164       1.1    itojun 	struct node_host		*host;
    165       1.1    itojun 	char				*file;
    166       1.1    itojun };
    167       1.1    itojun 
    168       1.1    itojun 
    169       1.3      yamt /* optimizer created tables */
    170       1.3      yamt struct pf_opt_tbl {
    171       1.3      yamt 	char			 pt_name[PF_TABLE_NAME_SIZE];
    172       1.3      yamt 	int			 pt_rulecount;
    173       1.3      yamt 	int			 pt_generated;
    174       1.3      yamt 	struct node_tinithead	 pt_nodes;
    175       1.3      yamt 	struct pfr_buffer	*pt_buf;
    176       1.3      yamt };
    177       1.3      yamt #define PF_OPT_TABLE_PREFIX	"__automatic_"
    178       1.3      yamt 
    179       1.3      yamt /* optimizer pf_rule container */
    180       1.3      yamt struct pf_opt_rule {
    181       1.3      yamt 	struct pf_rule		 por_rule;
    182       1.3      yamt 	struct pf_opt_tbl	*por_src_tbl;
    183       1.3      yamt 	struct pf_opt_tbl	*por_dst_tbl;
    184       1.3      yamt 	u_int64_t		 por_profile_count;
    185       1.3      yamt 	TAILQ_ENTRY(pf_opt_rule) por_entry;
    186       1.3      yamt 	TAILQ_ENTRY(pf_opt_rule) por_skip_entry[PF_SKIP_COUNT];
    187       1.3      yamt };
    188       1.3      yamt 
    189  1.4.22.1  wrstuden TAILQ_HEAD(pf_opt_queue, pf_opt_rule);
    190       1.3      yamt 
    191  1.4.22.1  wrstuden int	pfctl_rules(int, char *, FILE *, int, int, char *, struct pfr_buffer *);
    192  1.4.22.1  wrstuden int	pfctl_optimize_ruleset(struct pfctl *, struct pf_ruleset *);
    193       1.1    itojun 
    194       1.3      yamt int	pfctl_add_rule(struct pfctl *, struct pf_rule *, const char *);
    195       1.1    itojun int	pfctl_add_altq(struct pfctl *, struct pf_altq *);
    196       1.1    itojun int	pfctl_add_pool(struct pfctl *, struct pf_pool *, sa_family_t);
    197  1.4.22.1  wrstuden void	pfctl_move_pool(struct pf_pool *, struct pf_pool *);
    198       1.1    itojun void	pfctl_clear_pool(struct pf_pool *);
    199       1.1    itojun 
    200       1.1    itojun int	pfctl_set_timeout(struct pfctl *, const char *, int, int);
    201       1.1    itojun int	pfctl_set_optimization(struct pfctl *, const char *);
    202       1.1    itojun int	pfctl_set_limit(struct pfctl *, const char *, unsigned int);
    203       1.1    itojun int	pfctl_set_logif(struct pfctl *, char *);
    204       1.1    itojun int	pfctl_set_hostid(struct pfctl *, u_int32_t);
    205       1.1    itojun int	pfctl_set_debug(struct pfctl *, char *);
    206       1.4     peter int	pfctl_set_interface_flags(struct pfctl *, char *, int, int);
    207       1.1    itojun 
    208       1.1    itojun int	parse_rules(FILE *, struct pfctl *);
    209       1.1    itojun int	parse_flags(char *);
    210  1.4.22.1  wrstuden int	pfctl_load_anchors(int, struct pfctl *, struct pfr_buffer *);
    211       1.1    itojun 
    212       1.1    itojun void	print_pool(struct pf_pool *, u_int16_t, u_int16_t, sa_family_t, int);
    213       1.1    itojun void	print_src_node(struct pf_src_node *, int);
    214       1.3      yamt void	print_rule(struct pf_rule *, const char *, int);
    215       1.1    itojun void	print_tabledef(const char *, int, int, struct node_tinithead *);
    216       1.1    itojun void	print_status(struct pf_status *, int);
    217       1.1    itojun 
    218       1.1    itojun int	eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *,
    219       1.1    itojun 	    struct node_queue_opt *);
    220       1.1    itojun int	eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *,
    221       1.1    itojun 	    struct node_queue_opt *);
    222       1.1    itojun 
    223       1.1    itojun void	 print_altq(const struct pf_altq *, unsigned, struct node_queue_bw *,
    224       1.1    itojun 	    struct node_queue_opt *);
    225       1.1    itojun void	 print_queue(const struct pf_altq *, unsigned, struct node_queue_bw *,
    226       1.1    itojun 	    int, struct node_queue_opt *);
    227       1.1    itojun 
    228       1.3      yamt int	pfctl_define_table(char *, int, int, const char *, struct pfr_buffer *,
    229       1.3      yamt 	    u_int32_t);
    230       1.1    itojun 
    231       1.1    itojun void		 pfctl_clear_fingerprints(int, int);
    232       1.1    itojun int		 pfctl_file_fingerprints(int, int, const char *);
    233       1.1    itojun pf_osfp_t	 pfctl_get_fingerprint(const char *);
    234       1.1    itojun int		 pfctl_load_fingerprints(int, int);
    235       1.1    itojun char		*pfctl_lookup_fingerprint(pf_osfp_t, char *, size_t);
    236       1.1    itojun void		 pfctl_show_fingerprints(int);
    237       1.1    itojun 
    238       1.1    itojun 
    239       1.1    itojun struct icmptypeent {
    240       1.1    itojun 	const char *name;
    241       1.1    itojun 	u_int8_t type;
    242       1.1    itojun };
    243       1.1    itojun 
    244       1.1    itojun struct icmpcodeent {
    245       1.1    itojun 	const char *name;
    246       1.1    itojun 	u_int8_t type;
    247       1.1    itojun 	u_int8_t code;
    248       1.1    itojun };
    249       1.1    itojun 
    250       1.1    itojun const struct icmptypeent *geticmptypebynumber(u_int8_t, u_int8_t);
    251       1.1    itojun const struct icmptypeent *geticmptypebyname(char *, u_int8_t);
    252       1.1    itojun const struct icmpcodeent *geticmpcodebynumber(u_int8_t, u_int8_t, u_int8_t);
    253       1.1    itojun const struct icmpcodeent *geticmpcodebyname(u_long, char *, u_int8_t);
    254       1.1    itojun 
    255       1.1    itojun struct pf_timeout {
    256       1.1    itojun 	const char	*name;
    257       1.1    itojun 	int		 timeout;
    258       1.1    itojun };
    259       1.1    itojun 
    260       1.1    itojun #define PFCTL_FLAG_FILTER	0x02
    261       1.1    itojun #define PFCTL_FLAG_NAT		0x04
    262       1.1    itojun #define PFCTL_FLAG_OPTION	0x08
    263       1.1    itojun #define PFCTL_FLAG_ALTQ		0x10
    264       1.1    itojun #define PFCTL_FLAG_TABLE	0x20
    265       1.1    itojun 
    266       1.1    itojun extern const struct pf_timeout pf_timeouts[];
    267       1.1    itojun 
    268       1.1    itojun void			 set_ipmask(struct node_host *, u_int8_t);
    269       1.1    itojun int			 check_netmask(struct node_host *, sa_family_t);
    270       1.3      yamt int			 unmask(struct pf_addr *, sa_family_t);
    271       1.1    itojun void			 ifa_load(void);
    272  1.4.22.1  wrstuden struct node_host	*ifa_exists(const char *);
    273       1.1    itojun struct node_host	*ifa_lookup(const char *, int);
    274       1.1    itojun struct node_host	*host(const char *);
    275       1.1    itojun 
    276       1.1    itojun int			 append_addr(struct pfr_buffer *, char *, int);
    277       1.1    itojun int			 append_addr_host(struct pfr_buffer *,
    278       1.1    itojun 			    struct node_host *, int, int);
    279       1.1    itojun 
    280       1.1    itojun #endif /* _PFCTL_PARSER_H_ */
    281