pfctl_parser.h revision 1.3
11.3Syamt/* $NetBSD: pfctl_parser.h,v 1.3 2004/11/14 11:26:48 yamt Exp $ */ 21.3Syamt/* $OpenBSD: pfctl_parser.h,v 1.77 2004/07/16 23:44:25 frantzen Exp $ */ 31.1Sitojun 41.1Sitojun/* 51.1Sitojun * Copyright (c) 2001 Daniel Hartmeier 61.1Sitojun * All rights reserved. 71.1Sitojun * 81.1Sitojun * Redistribution and use in source and binary forms, with or without 91.1Sitojun * modification, are permitted provided that the following conditions 101.1Sitojun * are met: 111.1Sitojun * 121.1Sitojun * - Redistributions of source code must retain the above copyright 131.1Sitojun * notice, this list of conditions and the following disclaimer. 141.1Sitojun * - Redistributions in binary form must reproduce the above 151.1Sitojun * copyright notice, this list of conditions and the following 161.1Sitojun * disclaimer in the documentation and/or other materials provided 171.1Sitojun * with the distribution. 181.1Sitojun * 191.1Sitojun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 201.1Sitojun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 211.1Sitojun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 221.1Sitojun * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 231.1Sitojun * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 241.1Sitojun * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 251.1Sitojun * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 261.1Sitojun * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 271.1Sitojun * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281.1Sitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 291.1Sitojun * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 301.1Sitojun * POSSIBILITY OF SUCH DAMAGE. 311.1Sitojun * 321.1Sitojun */ 331.1Sitojun 341.1Sitojun#ifndef _PFCTL_PARSER_H_ 351.1Sitojun#define _PFCTL_PARSER_H_ 361.1Sitojun 371.1Sitojun#define PF_OSFP_FILE "/etc/pf.os" 381.1Sitojun 391.1Sitojun#define PF_OPT_DISABLE 0x0001 401.1Sitojun#define PF_OPT_ENABLE 0x0002 411.1Sitojun#define PF_OPT_VERBOSE 0x0004 421.1Sitojun#define PF_OPT_NOACTION 0x0008 431.1Sitojun#define PF_OPT_QUIET 0x0010 441.1Sitojun#define PF_OPT_CLRRULECTRS 0x0020 451.1Sitojun#define PF_OPT_USEDNS 0x0040 461.1Sitojun#define PF_OPT_VERBOSE2 0x0080 471.1Sitojun#define PF_OPT_DUMMYACTION 0x0100 481.1Sitojun#define PF_OPT_DEBUG 0x0200 491.1Sitojun#define PF_OPT_SHOWALL 0x0400 501.3Syamt#define PF_OPT_OPTIMIZE 0x0800 511.3Syamt#define PF_OPT_OPTIMIZE_PROFILE 0x1000 521.1Sitojun 531.1Sitojun#define PF_TH_ALL 0xFF 541.1Sitojun 551.1Sitojun#define PF_NAT_PROXY_PORT_LOW 50001 561.1Sitojun#define PF_NAT_PROXY_PORT_HIGH 65535 571.1Sitojun 581.1Sitojun#define FCNT_NAMES { \ 591.1Sitojun "searches", \ 601.1Sitojun "inserts", \ 611.1Sitojun "removals", \ 621.1Sitojun NULL \ 631.1Sitojun} 641.1Sitojun 651.3Syamtstruct pfr_buffer; /* forward definition */ 661.3Syamtstruct pf_opt_rule; 671.3SyamtTAILQ_HEAD(pf_opt_queue, pf_opt_rule); 681.3Syamt 691.3Syamt 701.1Sitojunstruct pfctl { 711.1Sitojun int dev; 721.1Sitojun int opts; 731.1Sitojun int loadopt; 741.1Sitojun u_int32_t tticket; /* table ticket */ 751.1Sitojun int tdirty; /* kernel dirty */ 761.1Sitojun u_int32_t rule_nr; 771.1Sitojun struct pfioc_pooladdr paddr; 781.1Sitojun struct pfioc_altq *paltq; 791.1Sitojun struct pfioc_queue *pqueue; 801.1Sitojun struct pfr_buffer *trans; 811.1Sitojun const char *anchor; 821.1Sitojun const char *ruleset; 831.3Syamt struct pf_opt_queue opt_queue; 841.1Sitojun}; 851.1Sitojun 861.1Sitojunstruct node_if { 871.1Sitojun char ifname[IFNAMSIZ]; 881.1Sitojun u_int8_t not; 891.3Syamt u_int8_t dynamic; /* antispoof */ 901.1Sitojun u_int ifa_flags; 911.1Sitojun struct node_if *next; 921.1Sitojun struct node_if *tail; 931.1Sitojun}; 941.1Sitojun 951.1Sitojunstruct node_host { 961.1Sitojun struct pf_addr_wrap addr; 971.1Sitojun struct pf_addr bcast; 981.1Sitojun struct pf_addr peer; 991.1Sitojun sa_family_t af; 1001.1Sitojun u_int8_t not; 1011.1Sitojun u_int32_t ifindex; /* link-local IPv6 addrs */ 1021.1Sitojun char *ifname; 1031.1Sitojun u_int ifa_flags; 1041.1Sitojun struct node_host *next; 1051.1Sitojun struct node_host *tail; 1061.1Sitojun}; 1071.1Sitojun/* special flags used by ifa_exists */ 1081.1Sitojun#define PF_IFA_FLAG_GROUP 0x10000 1091.1Sitojun#define PF_IFA_FLAG_DYNAMIC 0x20000 1101.1Sitojun#define PF_IFA_FLAG_CLONABLE 0x40000 1111.1Sitojun 1121.1Sitojunstruct node_os { 1131.1Sitojun char *os; 1141.1Sitojun pf_osfp_t fingerprint; 1151.1Sitojun struct node_os *next; 1161.1Sitojun struct node_os *tail; 1171.1Sitojun}; 1181.1Sitojun 1191.1Sitojunstruct node_queue_bw { 1201.1Sitojun u_int32_t bw_absolute; 1211.1Sitojun u_int16_t bw_percent; 1221.1Sitojun}; 1231.1Sitojun 1241.1Sitojunstruct node_hfsc_sc { 1251.1Sitojun struct node_queue_bw m1; /* slope of 1st segment; bps */ 1261.1Sitojun u_int d; /* x-projection of m1; msec */ 1271.1Sitojun struct node_queue_bw m2; /* slope of 2nd segment; bps */ 1281.1Sitojun u_int8_t used; 1291.1Sitojun}; 1301.1Sitojun 1311.1Sitojunstruct node_hfsc_opts { 1321.1Sitojun struct node_hfsc_sc realtime; 1331.1Sitojun struct node_hfsc_sc linkshare; 1341.1Sitojun struct node_hfsc_sc upperlimit; 1351.1Sitojun int flags; 1361.1Sitojun}; 1371.1Sitojun 1381.1Sitojunstruct node_queue_opt { 1391.1Sitojun int qtype; 1401.1Sitojun union { 1411.1Sitojun struct cbq_opts cbq_opts; 1421.1Sitojun struct priq_opts priq_opts; 1431.1Sitojun struct node_hfsc_opts hfsc_opts; 1441.1Sitojun } data; 1451.1Sitojun}; 1461.1Sitojun 1471.1SitojunSIMPLEQ_HEAD(node_tinithead, node_tinit); 1481.1Sitojunstruct node_tinit { /* table initializer */ 1491.1Sitojun SIMPLEQ_ENTRY(node_tinit) entries; 1501.1Sitojun struct node_host *host; 1511.1Sitojun char *file; 1521.1Sitojun}; 1531.1Sitojun 1541.1Sitojun 1551.3Syamt/* optimizer created tables */ 1561.3Syamtstruct pf_opt_tbl { 1571.3Syamt char pt_name[PF_TABLE_NAME_SIZE]; 1581.3Syamt int pt_rulecount; 1591.3Syamt int pt_generated; 1601.3Syamt struct node_tinithead pt_nodes; 1611.3Syamt struct pfr_buffer *pt_buf; 1621.3Syamt}; 1631.3Syamt#define PF_OPT_TABLE_PREFIX "__automatic_" 1641.3Syamt 1651.3Syamt/* optimizer pf_rule container */ 1661.3Syamtstruct pf_opt_rule { 1671.3Syamt struct pf_rule por_rule; 1681.3Syamt struct pf_opt_tbl *por_src_tbl; 1691.3Syamt struct pf_opt_tbl *por_dst_tbl; 1701.3Syamt char por_anchor[MAXPATHLEN]; 1711.3Syamt u_int64_t por_profile_count; 1721.3Syamt TAILQ_ENTRY(pf_opt_rule) por_entry; 1731.3Syamt TAILQ_ENTRY(pf_opt_rule) por_skip_entry[PF_SKIP_COUNT]; 1741.3Syamt}; 1751.3Syamt 1761.3Syamt 1771.3Syamtint pfctl_rules(int, char *, int, char *, struct pfr_buffer *); 1781.3Syamtint pfctl_optimize_rules(struct pfctl *); 1791.1Sitojun 1801.3Syamtint pfctl_add_rule(struct pfctl *, struct pf_rule *, const char *); 1811.1Sitojunint pfctl_add_altq(struct pfctl *, struct pf_altq *); 1821.1Sitojunint pfctl_add_pool(struct pfctl *, struct pf_pool *, sa_family_t); 1831.1Sitojunvoid pfctl_clear_pool(struct pf_pool *); 1841.1Sitojun 1851.1Sitojunint pfctl_set_timeout(struct pfctl *, const char *, int, int); 1861.1Sitojunint pfctl_set_optimization(struct pfctl *, const char *); 1871.1Sitojunint pfctl_set_limit(struct pfctl *, const char *, unsigned int); 1881.1Sitojunint pfctl_set_logif(struct pfctl *, char *); 1891.1Sitojunint pfctl_set_hostid(struct pfctl *, u_int32_t); 1901.1Sitojunint pfctl_set_debug(struct pfctl *, char *); 1911.1Sitojun 1921.1Sitojunint parse_rules(FILE *, struct pfctl *); 1931.1Sitojunint parse_flags(char *); 1941.1Sitojunint pfctl_load_anchors(int, int, struct pfr_buffer *); 1951.1Sitojun 1961.1Sitojunvoid print_pool(struct pf_pool *, u_int16_t, u_int16_t, sa_family_t, int); 1971.1Sitojunvoid print_src_node(struct pf_src_node *, int); 1981.3Syamtvoid print_rule(struct pf_rule *, const char *, int); 1991.1Sitojunvoid print_tabledef(const char *, int, int, struct node_tinithead *); 2001.1Sitojunvoid print_status(struct pf_status *, int); 2011.1Sitojun 2021.1Sitojunint eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *, 2031.1Sitojun struct node_queue_opt *); 2041.1Sitojunint eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *, 2051.1Sitojun struct node_queue_opt *); 2061.1Sitojun 2071.1Sitojunvoid print_altq(const struct pf_altq *, unsigned, struct node_queue_bw *, 2081.1Sitojun struct node_queue_opt *); 2091.1Sitojunvoid print_queue(const struct pf_altq *, unsigned, struct node_queue_bw *, 2101.1Sitojun int, struct node_queue_opt *); 2111.1Sitojun 2121.3Syamtint pfctl_define_table(char *, int, int, const char *, struct pfr_buffer *, 2131.3Syamt u_int32_t); 2141.1Sitojun 2151.1Sitojunvoid pfctl_clear_fingerprints(int, int); 2161.1Sitojunint pfctl_file_fingerprints(int, int, const char *); 2171.1Sitojunpf_osfp_t pfctl_get_fingerprint(const char *); 2181.1Sitojunint pfctl_load_fingerprints(int, int); 2191.1Sitojunchar *pfctl_lookup_fingerprint(pf_osfp_t, char *, size_t); 2201.1Sitojunvoid pfctl_show_fingerprints(int); 2211.1Sitojun 2221.1Sitojun 2231.1Sitojunstruct icmptypeent { 2241.1Sitojun const char *name; 2251.1Sitojun u_int8_t type; 2261.1Sitojun}; 2271.1Sitojun 2281.1Sitojunstruct icmpcodeent { 2291.1Sitojun const char *name; 2301.1Sitojun u_int8_t type; 2311.1Sitojun u_int8_t code; 2321.1Sitojun}; 2331.1Sitojun 2341.1Sitojunconst struct icmptypeent *geticmptypebynumber(u_int8_t, u_int8_t); 2351.1Sitojunconst struct icmptypeent *geticmptypebyname(char *, u_int8_t); 2361.1Sitojunconst struct icmpcodeent *geticmpcodebynumber(u_int8_t, u_int8_t, u_int8_t); 2371.1Sitojunconst struct icmpcodeent *geticmpcodebyname(u_long, char *, u_int8_t); 2381.1Sitojun 2391.1Sitojunstruct pf_timeout { 2401.1Sitojun const char *name; 2411.1Sitojun int timeout; 2421.1Sitojun}; 2431.1Sitojun 2441.1Sitojun#define PFCTL_FLAG_FILTER 0x02 2451.1Sitojun#define PFCTL_FLAG_NAT 0x04 2461.1Sitojun#define PFCTL_FLAG_OPTION 0x08 2471.1Sitojun#define PFCTL_FLAG_ALTQ 0x10 2481.1Sitojun#define PFCTL_FLAG_TABLE 0x20 2491.1Sitojun 2501.1Sitojunextern const struct pf_timeout pf_timeouts[]; 2511.1Sitojun 2521.1Sitojunvoid set_ipmask(struct node_host *, u_int8_t); 2531.1Sitojunint check_netmask(struct node_host *, sa_family_t); 2541.3Syamtint unmask(struct pf_addr *, sa_family_t); 2551.1Sitojunvoid ifa_load(void); 2561.1Sitojunstruct node_host *ifa_exists(const char *, int); 2571.1Sitojunstruct node_host *ifa_lookup(const char *, int); 2581.1Sitojunstruct node_host *host(const char *); 2591.1Sitojun 2601.1Sitojunint append_addr(struct pfr_buffer *, char *, int); 2611.1Sitojunint append_addr_host(struct pfr_buffer *, 2621.1Sitojun struct node_host *, int, int); 2631.1Sitojun 2641.1Sitojun#endif /* _PFCTL_PARSER_H_ */ 265