1 /* $OpenBSD: pfctl_parser.h,v 1.74 2004/02/10 22:26:56 dhartmei Exp $ */ 2 /* $DragonFly: src/usr.sbin/pfctl/pfctl_parser.h,v 1.1 2004/09/21 21:25:28 joerg Exp $ */ 3 4 /* 5 * Copyright (c) 2001 Daniel Hartmeier 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * - Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * - Redistributions in binary form must reproduce the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer in the documentation and/or other materials provided 17 * with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 */ 33 34 #ifndef _PFCTL_PARSER_H_ 35 #define _PFCTL_PARSER_H_ 36 37 #define PF_OSFP_FILE "/etc/pf.os" 38 39 #define PF_OPT_DISABLE 0x0001 40 #define PF_OPT_ENABLE 0x0002 41 #define PF_OPT_VERBOSE 0x0004 42 #define PF_OPT_NOACTION 0x0008 43 #define PF_OPT_QUIET 0x0010 44 #define PF_OPT_CLRRULECTRS 0x0020 45 #define PF_OPT_USEDNS 0x0040 46 #define PF_OPT_VERBOSE2 0x0080 47 #define PF_OPT_DUMMYACTION 0x0100 48 #define PF_OPT_DEBUG 0x0200 49 #define PF_OPT_SHOWALL 0x0400 50 51 #define PF_TH_ALL 0xFF 52 53 #define PF_NAT_PROXY_PORT_LOW 50001 54 #define PF_NAT_PROXY_PORT_HIGH 65535 55 56 #define FCNT_NAMES { \ 57 "searches", \ 58 "inserts", \ 59 "removals", \ 60 NULL \ 61 } 62 63 struct pfctl { 64 int dev; 65 int opts; 66 int loadopt; 67 u_int32_t tticket; /* table ticket */ 68 int tdirty; /* kernel dirty */ 69 u_int32_t rule_nr; 70 struct pfioc_pooladdr paddr; 71 struct pfioc_altq *paltq; 72 struct pfioc_queue *pqueue; 73 struct pfr_buffer *trans; 74 const char *anchor; 75 const char *ruleset; 76 }; 77 78 struct node_if { 79 char ifname[IFNAMSIZ]; 80 u_int8_t not; 81 u_int ifa_flags; 82 struct node_if *next; 83 struct node_if *tail; 84 }; 85 86 struct node_host { 87 struct pf_addr_wrap addr; 88 struct pf_addr bcast; 89 struct pf_addr peer; 90 sa_family_t af; 91 u_int8_t not; 92 u_int32_t ifindex; /* link-local IPv6 addrs */ 93 char *ifname; 94 u_int ifa_flags; 95 struct node_host *next; 96 struct node_host *tail; 97 }; 98 /* special flags used by ifa_exists */ 99 #define PF_IFA_FLAG_GROUP 0x10000 100 #define PF_IFA_FLAG_DYNAMIC 0x20000 101 #define PF_IFA_FLAG_CLONABLE 0x40000 102 103 struct node_os { 104 char *os; 105 pf_osfp_t fingerprint; 106 struct node_os *next; 107 struct node_os *tail; 108 }; 109 110 struct node_queue_bw { 111 u_int32_t bw_absolute; 112 u_int16_t bw_percent; 113 }; 114 115 struct node_hfsc_sc { 116 struct node_queue_bw m1; /* slope of 1st segment; bps */ 117 u_int d; /* x-projection of m1; msec */ 118 struct node_queue_bw m2; /* slope of 2nd segment; bps */ 119 u_int8_t used; 120 }; 121 122 struct node_hfsc_opts { 123 struct node_hfsc_sc realtime; 124 struct node_hfsc_sc linkshare; 125 struct node_hfsc_sc upperlimit; 126 int flags; 127 }; 128 129 struct node_queue_opt { 130 int qtype; 131 union { 132 struct cbq_opts cbq_opts; 133 struct priq_opts priq_opts; 134 struct node_hfsc_opts hfsc_opts; 135 } data; 136 }; 137 138 /* XXX should be in machine/limits.h */ 139 #include <limits.h> 140 #define UID_MAX UINT_MAX 141 #define GID_MAX UINT_MAX 142 143 /* 144 * XXX 145 * Absolutely this is not correct location to define this. 146 * Should we use an another sperate header file? 147 * NOTE: This is also defined in sys/bus/usb/usb_port.h 148 * perhaps place in sys/queue.h? 149 */ 150 #define SIMPLEQ_HEAD STAILQ_HEAD 151 #define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER 152 #define SIMPLEQ_ENTRY STAILQ_ENTRY 153 #define SIMPLEQ_FIRST STAILQ_FIRST 154 #define SIMPLEQ_END(head) NULL 155 #define SIMPLEQ_EMPTY STAILQ_EMPTY 156 #define SIMPLEQ_NEXT STAILQ_NEXT 157 /*#define SIMPLEQ_FOREACH STAILQ_FOREACH*/ 158 #define SIMPLEQ_FOREACH(var, head, field) \ 159 for((var) = SIMPLEQ_FIRST(head); \ 160 (var) != SIMPLEQ_END(head); \ 161 (var) = SIMPLEQ_NEXT(var, field)) 162 #define SIMPLEQ_INIT STAILQ_INIT 163 #define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD 164 #define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL 165 #define SIMPLEQ_INSERT_AFTER STAILQ_INSERT_AFTER 166 #define SIMPLEQ_REMOVE_HEAD STAILQ_REMOVE_HEAD 167 168 SIMPLEQ_HEAD(node_tinithead, node_tinit); 169 struct node_tinit { /* table initializer */ 170 SIMPLEQ_ENTRY(node_tinit) entries; 171 struct node_host *host; 172 char *file; 173 }; 174 175 struct pfr_buffer; /* forward definition */ 176 177 int pfctl_rules(int, char *, int, char *, char *, struct pfr_buffer *); 178 179 int pfctl_add_rule(struct pfctl *, struct pf_rule *); 180 int pfctl_add_altq(struct pfctl *, struct pf_altq *); 181 int pfctl_add_pool(struct pfctl *, struct pf_pool *, sa_family_t); 182 void pfctl_clear_pool(struct pf_pool *); 183 184 int pfctl_set_timeout(struct pfctl *, const char *, int, int); 185 int pfctl_set_optimization(struct pfctl *, const char *); 186 int pfctl_set_limit(struct pfctl *, const char *, unsigned int); 187 int pfctl_set_logif(struct pfctl *, char *); 188 int pfctl_set_hostid(struct pfctl *, u_int32_t); 189 int pfctl_set_debug(struct pfctl *, char *); 190 191 int parse_rules(FILE *, struct pfctl *); 192 int parse_flags(char *); 193 int pfctl_load_anchors(int, int, struct pfr_buffer *); 194 195 void print_pool(struct pf_pool *, u_int16_t, u_int16_t, sa_family_t, int); 196 void print_src_node(struct pf_src_node *, int); 197 void print_rule(struct pf_rule *, int); 198 void print_tabledef(const char *, int, int, struct node_tinithead *); 199 void print_status(struct pf_status *, int); 200 201 int eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *, 202 struct node_queue_opt *); 203 int eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *, 204 struct node_queue_opt *); 205 206 void print_altq(const struct pf_altq *, unsigned, struct node_queue_bw *, 207 struct node_queue_opt *); 208 void print_queue(const struct pf_altq *, unsigned, struct node_queue_bw *, 209 int, struct node_queue_opt *); 210 211 int pfctl_define_table(char *, int, int, const char *, const char *, 212 struct pfr_buffer *, u_int32_t); 213 214 void pfctl_clear_fingerprints(int, int); 215 int pfctl_file_fingerprints(int, int, const char *); 216 pf_osfp_t pfctl_get_fingerprint(const char *); 217 int pfctl_load_fingerprints(int, int); 218 char *pfctl_lookup_fingerprint(pf_osfp_t, char *, size_t); 219 void pfctl_show_fingerprints(int); 220 221 222 struct icmptypeent { 223 const char *name; 224 u_int8_t type; 225 }; 226 227 struct icmpcodeent { 228 const char *name; 229 u_int8_t type; 230 u_int8_t code; 231 }; 232 233 const struct icmptypeent *geticmptypebynumber(u_int8_t, u_int8_t); 234 const struct icmptypeent *geticmptypebyname(char *, u_int8_t); 235 const struct icmpcodeent *geticmpcodebynumber(u_int8_t, u_int8_t, u_int8_t); 236 const struct icmpcodeent *geticmpcodebyname(u_long, char *, u_int8_t); 237 238 struct pf_timeout { 239 const char *name; 240 int timeout; 241 }; 242 243 #define PFCTL_FLAG_FILTER 0x02 244 #define PFCTL_FLAG_NAT 0x04 245 #define PFCTL_FLAG_OPTION 0x08 246 #define PFCTL_FLAG_ALTQ 0x10 247 #define PFCTL_FLAG_TABLE 0x20 248 249 extern const struct pf_timeout pf_timeouts[]; 250 251 void set_ipmask(struct node_host *, u_int8_t); 252 int check_netmask(struct node_host *, sa_family_t); 253 void ifa_load(void); 254 struct node_host *ifa_exists(const char *, int); 255 struct node_host *ifa_lookup(const char *, int); 256 struct node_host *host(const char *); 257 258 int append_addr(struct pfr_buffer *, char *, int); 259 int append_addr_host(struct pfr_buffer *, 260 struct node_host *, int, int); 261 262 #endif /* _PFCTL_PARSER_H_ */ 263