1 /*- 2 * Copyright (c) 2002-2009 Luigi Rizzo, Universita` di Pisa 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 * 25 * $FreeBSD$ 26 */ 27 28 #ifndef _IPFW2_PRIVATE_H 29 #define _IPFW2_PRIVATE_H 30 31 /* 32 * Internal constants and data structures used by ipfw components 33 * and not meant to be exported outside the kernel. 34 */ 35 36 #ifdef _KERNEL 37 38 /* 39 * For platforms that do not have SYSCTL support, we wrap the 40 * SYSCTL_* into a function (one per file) to collect the values 41 * into an array at module initialization. The wrapping macros, 42 * SYSBEGIN() and SYSEND, are empty in the default case. 43 */ 44 #ifndef SYSBEGIN 45 #define SYSBEGIN(x) 46 #endif 47 #ifndef SYSEND 48 #define SYSEND 49 #endif 50 51 /* Return values from ipfw_chk() */ 52 enum { 53 IP_FW_PASS = 0, 54 IP_FW_DENY, 55 IP_FW_DIVERT, 56 IP_FW_TEE, 57 IP_FW_DUMMYNET, 58 IP_FW_NETGRAPH, 59 IP_FW_NGTEE, 60 IP_FW_NAT, 61 IP_FW_REASS, 62 }; 63 64 /* 65 * Structure for collecting parameters to dummynet for ip6_output forwarding 66 */ 67 struct _ip6dn_args { 68 struct ip6_pktopts *opt_or; 69 int flags_or; 70 struct ip6_moptions *im6o_or; 71 struct ifnet *origifp_or; 72 struct ifnet *ifp_or; 73 struct sockaddr_in6 dst_or; 74 u_long mtu_or; 75 }; 76 77 78 /* 79 * Arguments for calling ipfw_chk() and dummynet_io(). We put them 80 * all into a structure because this way it is easier and more 81 * efficient to pass variables around and extend the interface. 82 */ 83 struct ip_fw_args { 84 struct mbuf *m; /* the mbuf chain */ 85 struct ifnet *oif; /* output interface */ 86 struct sockaddr_in *next_hop; /* forward address */ 87 struct sockaddr_in6 *next_hop6; /* ipv6 forward address */ 88 89 /* 90 * On return, it points to the matching rule. 91 * On entry, rule.slot > 0 means the info is valid and 92 * contains the starting rule for an ipfw search. 93 * If chain_id == chain->id && slot >0 then jump to that slot. 94 * Otherwise, we locate the first rule >= rulenum:rule_id 95 */ 96 struct ipfw_rule_ref rule; /* match/restart info */ 97 98 struct ether_header *eh; /* for bridged packets */ 99 100 struct ipfw_flow_id f_id; /* grabbed from IP header */ 101 //uint32_t cookie; /* a cookie depending on rule action */ 102 struct inpcb *inp; 103 104 struct _ip6dn_args dummypar; /* dummynet->ip6_output */ 105 struct sockaddr_in hopstore; /* store here if cannot use a pointer */ 106 }; 107 108 MALLOC_DECLARE(M_IPFW); 109 110 /* 111 * Hooks sometime need to know the direction of the packet 112 * (divert, dummynet, netgraph, ...) 113 * We use a generic definition here, with bit0-1 indicating the 114 * direction, bit 2 indicating layer2 or 3, bit 3-4 indicating the 115 * specific protocol 116 * indicating the protocol (if necessary) 117 */ 118 enum { 119 DIR_MASK = 0x3, 120 DIR_OUT = 0, 121 DIR_IN = 1, 122 DIR_FWD = 2, 123 DIR_DROP = 3, 124 PROTO_LAYER2 = 0x4, /* set for layer 2 */ 125 /* PROTO_DEFAULT = 0, */ 126 PROTO_IPV4 = 0x08, 127 PROTO_IPV6 = 0x10, 128 PROTO_IFB = 0x0c, /* layer2 + ifbridge */ 129 /* PROTO_OLDBDG = 0x14, unused, old bridge */ 130 }; 131 132 /* wrapper for freeing a packet, in case we need to do more work */ 133 #ifndef FREE_PKT 134 #if defined(__linux__) || defined(_WIN32) 135 #define FREE_PKT(m) netisr_dispatch(-1, m) 136 #else 137 #define FREE_PKT(m) m_freem(m) 138 #endif 139 #endif /* !FREE_PKT */ 140 141 /* 142 * Function definitions. 143 */ 144 145 /* attach (arg = 1) or detach (arg = 0) hooks */ 146 int ipfw_attach_hooks(int); 147 #ifdef NOTYET 148 void ipfw_nat_destroy(void); 149 #endif 150 151 /* In ip_fw_log.c */ 152 struct ip; 153 struct ip_fw_chain; 154 void ipfw_log_bpf(int); 155 void ipfw_log(struct ip_fw_chain *chain, struct ip_fw *f, u_int hlen, 156 struct ip_fw_args *args, struct mbuf *m, struct ifnet *oif, 157 u_short offset, uint32_t tablearg, struct ip *ip); 158 VNET_DECLARE(u_int64_t, norule_counter); 159 #define V_norule_counter VNET(norule_counter) 160 VNET_DECLARE(int, verbose_limit); 161 #define V_verbose_limit VNET(verbose_limit) 162 163 /* In ip_fw_dynamic.c */ 164 165 enum { /* result for matching dynamic rules */ 166 MATCH_REVERSE = 0, 167 MATCH_FORWARD, 168 MATCH_NONE, 169 MATCH_UNKNOWN, 170 }; 171 172 /* 173 * The lock for dynamic rules is only used once outside the file, 174 * and only to release the result of lookup_dyn_rule(). 175 * Eventually we may implement it with a callback on the function. 176 */ 177 struct ip_fw_chain; 178 struct sockopt_data; 179 int ipfw_is_dyn_rule(struct ip_fw *rule); 180 void ipfw_expire_dyn_rules(struct ip_fw_chain *, ipfw_range_tlv *); 181 void ipfw_dyn_unlock(ipfw_dyn_rule *q); 182 183 struct tcphdr; 184 struct mbuf *ipfw_send_pkt(struct mbuf *, struct ipfw_flow_id *, 185 u_int32_t, u_int32_t, int); 186 int ipfw_install_state(struct ip_fw_chain *chain, struct ip_fw *rule, 187 ipfw_insn_limit *cmd, struct ip_fw_args *args, uint32_t tablearg); 188 ipfw_dyn_rule *ipfw_lookup_dyn_rule(struct ipfw_flow_id *pkt, 189 int *match_direction, struct tcphdr *tcp); 190 void ipfw_remove_dyn_children(struct ip_fw *rule); 191 void ipfw_get_dynamic(struct ip_fw_chain *chain, char **bp, const char *ep); 192 int ipfw_dump_states(struct ip_fw_chain *chain, struct sockopt_data *sd); 193 194 void ipfw_dyn_init(struct ip_fw_chain *); /* per-vnet initialization */ 195 void ipfw_dyn_uninit(int); /* per-vnet deinitialization */ 196 int ipfw_dyn_len(void); 197 int ipfw_dyn_get_count(void); 198 199 /* common variables */ 200 VNET_DECLARE(int, fw_one_pass); 201 #define V_fw_one_pass VNET(fw_one_pass) 202 203 VNET_DECLARE(int, fw_verbose); 204 #define V_fw_verbose VNET(fw_verbose) 205 206 VNET_DECLARE(struct ip_fw_chain, layer3_chain); 207 #define V_layer3_chain VNET(layer3_chain) 208 209 VNET_DECLARE(int, ipfw_vnet_ready); 210 #define V_ipfw_vnet_ready VNET(ipfw_vnet_ready) 211 212 VNET_DECLARE(u_int32_t, set_disable); 213 #define V_set_disable VNET(set_disable) 214 215 VNET_DECLARE(int, autoinc_step); 216 #define V_autoinc_step VNET(autoinc_step) 217 218 VNET_DECLARE(unsigned int, fw_tables_max); 219 #define V_fw_tables_max VNET(fw_tables_max) 220 221 VNET_DECLARE(unsigned int, fw_tables_sets); 222 #define V_fw_tables_sets VNET(fw_tables_sets) 223 224 struct tables_config; 225 226 #ifdef _KERNEL 227 /* 228 * Here we have the structure representing an ipfw rule. 229 * 230 * It starts with a general area 231 * followed by an array of one or more instructions, which the code 232 * accesses as an array of 32-bit values. 233 * 234 * Given a rule pointer r: 235 * 236 * r->cmd is the start of the first instruction. 237 * ACTION_PTR(r) is the start of the first action (things to do 238 * once a rule matched). 239 */ 240 241 struct ip_fw { 242 uint16_t act_ofs; /* offset of action in 32-bit units */ 243 uint16_t cmd_len; /* # of 32-bit words in cmd */ 244 uint16_t rulenum; /* rule number */ 245 uint8_t set; /* rule set (0..31) */ 246 uint8_t flags; /* currently unused */ 247 counter_u64_t cntr; /* Pointer to rule counters */ 248 uint32_t timestamp; /* tv_sec of last match */ 249 uint32_t id; /* rule id */ 250 uint32_t cached_id; /* used by jump_fast */ 251 uint32_t cached_pos; /* used by jump_fast */ 252 253 ipfw_insn cmd[1]; /* storage for commands */ 254 }; 255 256 #define IPFW_RULE_CNTR_SIZE (2 * sizeof(counter_u64_t)) 257 258 #endif 259 260 struct ip_fw_chain { 261 struct ip_fw **map; /* array of rule ptrs to ease lookup */ 262 uint32_t id; /* ruleset id */ 263 int n_rules; /* number of static rules */ 264 LIST_HEAD(nat_list, cfg_nat) nat; /* list of nat entries */ 265 void *tablestate; /* runtime table info */ 266 void *valuestate; /* runtime table value info */ 267 int *idxmap; /* skipto array of rules */ 268 #if defined( __linux__ ) || defined( _WIN32 ) 269 spinlock_t rwmtx; 270 #else 271 struct rmlock rwmtx; 272 #endif 273 int static_len; /* total len of static rules (v0) */ 274 uint32_t gencnt; /* NAT generation count */ 275 struct ip_fw *default_rule; 276 struct tables_config *tblcfg; /* tables module data */ 277 void *ifcfg; /* interface module data */ 278 int *idxmap_back; /* standby skipto array of rules */ 279 #if defined( __linux__ ) || defined( _WIN32 ) 280 spinlock_t uh_lock; 281 #else 282 struct rwlock uh_lock; /* lock for upper half */ 283 #endif 284 }; 285 286 /* 64-byte structure representing multi-field table value */ 287 struct table_value { 288 uint32_t tag; /* O_TAG/O_TAGGED */ 289 uint32_t pipe; /* O_PIPE/O_QUEUE */ 290 uint16_t divert; /* O_DIVERT/O_TEE */ 291 uint16_t skipto; /* skipto, CALLRET */ 292 uint32_t netgraph; /* O_NETGRAPH/O_NGTEE */ 293 uint32_t fib; /* O_SETFIB */ 294 uint32_t nat; /* O_NAT */ 295 uint32_t nh4; 296 uint8_t dscp; 297 uint8_t spare0[3]; 298 /* -- 32 bytes -- */ 299 struct in6_addr nh6; 300 uint32_t limit; /* O_LIMIT */ 301 uint32_t spare1; 302 uint64_t refcnt; /* Number of references */ 303 }; 304 305 struct namedobj_instance; 306 307 struct named_object { 308 TAILQ_ENTRY(named_object) nn_next; /* namehash */ 309 TAILQ_ENTRY(named_object) nv_next; /* valuehash */ 310 char *name; /* object name */ 311 uint8_t type; /* object type */ 312 uint8_t compat; /* Object name is number */ 313 uint16_t kidx; /* object kernel index */ 314 uint16_t uidx; /* userland idx for compat records */ 315 uint32_t set; /* set object belongs to */ 316 uint32_t refcnt; /* number of references */ 317 }; 318 TAILQ_HEAD(namedobjects_head, named_object); 319 320 struct sockopt; /* used by tcp_var.h */ 321 struct sockopt_data { 322 caddr_t kbuf; /* allocated buffer */ 323 size_t ksize; /* given buffer size */ 324 size_t koff; /* data already used */ 325 size_t kavail; /* number of bytes available */ 326 size_t ktotal; /* total bytes pushed */ 327 struct sockopt *sopt; /* socket data */ 328 caddr_t sopt_val; /* sopt user buffer */ 329 size_t valsize; /* original data size */ 330 }; 331 332 struct ipfw_ifc; 333 334 typedef void (ipfw_ifc_cb)(struct ip_fw_chain *ch, void *cbdata, 335 uint16_t ifindex); 336 337 struct ipfw_iface { 338 struct named_object no; 339 char ifname[64]; 340 int resolved; 341 uint16_t ifindex; 342 uint16_t spare; 343 uint64_t gencnt; 344 TAILQ_HEAD(, ipfw_ifc) consumers; 345 }; 346 347 struct ipfw_ifc { 348 TAILQ_ENTRY(ipfw_ifc) next; 349 struct ipfw_iface *iface; 350 ipfw_ifc_cb *cb; 351 void *cbdata; 352 }; 353 354 /* Macro for working with various counters */ 355 #define IPFW_INC_RULE_COUNTER(_cntr, _bytes) do { \ 356 counter_u64_add((_cntr)->cntr, 1); \ 357 counter_u64_add((_cntr)->cntr + 1, _bytes); \ 358 if ((_cntr)->timestamp != time_uptime) \ 359 (_cntr)->timestamp = time_uptime; \ 360 } while (0) 361 362 #define IPFW_INC_DYN_COUNTER(_cntr, _bytes) do { \ 363 (_cntr)->pcnt++; \ 364 (_cntr)->bcnt += _bytes; \ 365 } while (0) 366 367 #define IPFW_ZERO_RULE_COUNTER(_cntr) do { \ 368 counter_u64_zero((_cntr)->cntr); \ 369 counter_u64_zero((_cntr)->cntr + 1); \ 370 (_cntr)->timestamp = 0; \ 371 } while (0) 372 373 #define IPFW_ZERO_DYN_COUNTER(_cntr) do { \ 374 (_cntr)->pcnt = 0; \ 375 (_cntr)->bcnt = 0; \ 376 } while (0) 377 378 #define TARG_VAL(ch, k, f) ((struct table_value *)((ch)->valuestate))[k].f 379 #define IP_FW_ARG_TABLEARG(ch, a, f) \ 380 (((a) == IP_FW_TARG) ? TARG_VAL(ch, tablearg, f) : (a)) 381 /* 382 * The lock is heavily used by ip_fw2.c (the main file) and ip_fw_nat.c 383 * so the variable and the macros must be here. 384 */ 385 386 #if defined( __linux__ ) || defined( _WIN32 ) 387 #define IPFW_LOCK_INIT(_chain) do { \ 388 rw_init(&(_chain)->rwmtx, "IPFW static rules"); \ 389 rw_init(&(_chain)->uh_lock, "IPFW UH lock"); \ 390 } while (0) 391 392 #define IPFW_LOCK_DESTROY(_chain) do { \ 393 rw_destroy(&(_chain)->rwmtx); \ 394 rw_destroy(&(_chain)->uh_lock); \ 395 } while (0) 396 397 #define IPFW_RLOCK_ASSERT(_chain) rw_assert(&(_chain)->rwmtx, RA_RLOCKED) 398 #define IPFW_WLOCK_ASSERT(_chain) rw_assert(&(_chain)->rwmtx, RA_WLOCKED) 399 400 #define IPFW_RLOCK_TRACKER 401 #define IPFW_RLOCK(p) rw_rlock(&(p)->rwmtx) 402 #define IPFW_RUNLOCK(p) rw_runlock(&(p)->rwmtx) 403 #define IPFW_WLOCK(p) rw_wlock(&(p)->rwmtx) 404 #define IPFW_WUNLOCK(p) rw_wunlock(&(p)->rwmtx) 405 #define IPFW_PF_RLOCK(p) IPFW_RLOCK(p) 406 #define IPFW_PF_RUNLOCK(p) IPFW_RUNLOCK(p) 407 #else /* FreeBSD */ 408 #define IPFW_LOCK_INIT(_chain) do { \ 409 rm_init(&(_chain)->rwmtx, "IPFW static rules"); \ 410 rw_init(&(_chain)->uh_lock, "IPFW UH lock"); \ 411 } while (0) 412 413 #define IPFW_LOCK_DESTROY(_chain) do { \ 414 rm_destroy(&(_chain)->rwmtx); \ 415 rw_destroy(&(_chain)->uh_lock); \ 416 } while (0) 417 418 #define IPFW_RLOCK_ASSERT(_chain) rm_assert(&(_chain)->rwmtx, RA_RLOCKED) 419 #define IPFW_WLOCK_ASSERT(_chain) rm_assert(&(_chain)->rwmtx, RA_WLOCKED) 420 421 #define IPFW_RLOCK_TRACKER struct rm_priotracker _tracker 422 #define IPFW_RLOCK(p) rm_rlock(&(p)->rwmtx, &_tracker) 423 #define IPFW_RUNLOCK(p) rm_runlock(&(p)->rwmtx, &_tracker) 424 #define IPFW_WLOCK(p) rm_wlock(&(p)->rwmtx) 425 #define IPFW_WUNLOCK(p) rm_wunlock(&(p)->rwmtx) 426 #define IPFW_PF_RLOCK(p) IPFW_RLOCK(p) 427 #define IPFW_PF_RUNLOCK(p) IPFW_RUNLOCK(p) 428 #endif 429 430 #define IPFW_UH_RLOCK_ASSERT(_chain) rw_assert(&(_chain)->uh_lock, RA_RLOCKED) 431 #define IPFW_UH_WLOCK_ASSERT(_chain) rw_assert(&(_chain)->uh_lock, RA_WLOCKED) 432 433 #define IPFW_UH_RLOCK(p) rw_rlock(&(p)->uh_lock) 434 #define IPFW_UH_RUNLOCK(p) rw_runlock(&(p)->uh_lock) 435 #define IPFW_UH_WLOCK(p) rw_wlock(&(p)->uh_lock) 436 #define IPFW_UH_WUNLOCK(p) rw_wunlock(&(p)->uh_lock) 437 438 struct obj_idx { 439 uint16_t uidx; /* internal index supplied by userland */ 440 uint16_t kidx; /* kernel object index */ 441 uint16_t off; /* tlv offset from rule end in 4-byte words */ 442 uint8_t spare; 443 uint8_t type; /* object type within its category */ 444 }; 445 446 struct rule_check_info { 447 uint16_t flags; /* rule-specific check flags */ 448 uint16_t table_opcodes; /* count of opcodes referencing table */ 449 uint16_t urule_numoff; /* offset of rulenum in bytes */ 450 uint8_t version; /* rule version */ 451 uint8_t spare; 452 ipfw_obj_ctlv *ctlv; /* name TLV containter */ 453 struct ip_fw *krule; /* resulting rule pointer */ 454 caddr_t urule; /* original rule pointer */ 455 struct obj_idx obuf[8]; /* table references storage */ 456 }; 457 458 /* Legacy interface support */ 459 /* 460 * FreeBSD 8 export rule format 461 */ 462 struct ip_fw_rule0 { 463 struct ip_fw *x_next; /* linked list of rules */ 464 struct ip_fw *next_rule; /* ptr to next [skipto] rule */ 465 /* 'next_rule' is used to pass up 'set_disable' status */ 466 467 uint16_t act_ofs; /* offset of action in 32-bit units */ 468 uint16_t cmd_len; /* # of 32-bit words in cmd */ 469 uint16_t rulenum; /* rule number */ 470 uint8_t set; /* rule set (0..31) */ 471 uint8_t _pad; /* padding */ 472 uint32_t id; /* rule id */ 473 474 /* These fields are present in all rules. */ 475 uint64_t pcnt; /* Packet counter */ 476 uint64_t bcnt; /* Byte counter */ 477 uint32_t timestamp; /* tv_sec of last match */ 478 479 ipfw_insn cmd[1]; /* storage for commands */ 480 }; 481 482 struct ip_fw_bcounter0 { 483 uint64_t pcnt; /* Packet counter */ 484 uint64_t bcnt; /* Byte counter */ 485 uint32_t timestamp; /* tv_sec of last match */ 486 }; 487 488 /* Kernel rule length */ 489 /* 490 * RULE _K_ SIZE _V_ -> 491 * get kernel size from userland rool version _V_. 492 * RULE _U_ SIZE _V_ -> 493 * get user size version _V_ from kernel rule 494 * RULESIZE _V_ -> 495 * get user size rule length 496 */ 497 /* FreeBSD8 <> current kernel format */ 498 #define RULEUSIZE0(r) (sizeof(struct ip_fw_rule0) + (r)->cmd_len * 4 - 4) 499 #define RULEKSIZE0(r) roundup2((sizeof(struct ip_fw) + (r)->cmd_len*4 - 4), 8) 500 /* FreeBSD11 <> current kernel format */ 501 #define RULEUSIZE1(r) (roundup2(sizeof(struct ip_fw_rule) + \ 502 (r)->cmd_len * 4 - 4, 8)) 503 #define RULEKSIZE1(r) roundup2((sizeof(struct ip_fw) + (r)->cmd_len*4 - 4), 8) 504 505 506 /* In ip_fw_iface.c */ 507 int ipfw_iface_init(void); 508 void ipfw_iface_destroy(void); 509 void vnet_ipfw_iface_destroy(struct ip_fw_chain *ch); 510 int ipfw_iface_ref(struct ip_fw_chain *ch, char *name, 511 struct ipfw_ifc *ic); 512 void ipfw_iface_unref(struct ip_fw_chain *ch, struct ipfw_ifc *ic); 513 void ipfw_iface_add_notify(struct ip_fw_chain *ch, struct ipfw_ifc *ic); 514 void ipfw_iface_del_notify(struct ip_fw_chain *ch, struct ipfw_ifc *ic); 515 516 /* In ip_fw_sockopt.c */ 517 void ipfw_init_skipto_cache(struct ip_fw_chain *chain); 518 void ipfw_destroy_skipto_cache(struct ip_fw_chain *chain); 519 int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); 520 int ipfw_ctl3(struct sockopt *sopt); 521 int ipfw_chk(struct ip_fw_args *args); 522 void ipfw_reap_add(struct ip_fw_chain *chain, struct ip_fw **head, 523 struct ip_fw *rule); 524 void ipfw_reap_rules(struct ip_fw *head); 525 void ipfw_init_counters(void); 526 void ipfw_destroy_counters(void); 527 struct ip_fw *ipfw_alloc_rule(struct ip_fw_chain *chain, size_t rulesize); 528 int ipfw_match_range(struct ip_fw *rule, ipfw_range_tlv *rt); 529 530 typedef int (sopt_handler_f)(struct ip_fw_chain *ch, 531 ip_fw3_opheader *op3, struct sockopt_data *sd); 532 struct ipfw_sopt_handler { 533 uint16_t opcode; 534 uint8_t version; 535 uint8_t dir; 536 sopt_handler_f *handler; 537 uint64_t refcnt; 538 }; 539 #define HDIR_SET 0x01 /* Handler is used to set some data */ 540 #define HDIR_GET 0x02 /* Handler is used to retrieve data */ 541 #define HDIR_BOTH HDIR_GET|HDIR_SET 542 543 void ipfw_init_sopt_handler(void); 544 void ipfw_destroy_sopt_handler(void); 545 void ipfw_add_sopt_handler(struct ipfw_sopt_handler *sh, size_t count); 546 int ipfw_del_sopt_handler(struct ipfw_sopt_handler *sh, size_t count); 547 caddr_t ipfw_get_sopt_space(struct sockopt_data *sd, size_t needed); 548 caddr_t ipfw_get_sopt_header(struct sockopt_data *sd, size_t needed); 549 #define IPFW_ADD_SOPT_HANDLER(f, c) do { \ 550 if ((f) != 0) \ 551 ipfw_add_sopt_handler(c, \ 552 sizeof(c) / sizeof(c[0])); \ 553 } while(0) 554 #define IPFW_DEL_SOPT_HANDLER(l, c) do { \ 555 if ((l) != 0) \ 556 ipfw_del_sopt_handler(c, \ 557 sizeof(c) / sizeof(c[0])); \ 558 } while(0) 559 560 typedef void (objhash_cb_t)(struct namedobj_instance *ni, struct named_object *, 561 void *arg); 562 typedef uint32_t (objhash_hash_f)(struct namedobj_instance *ni, void *key, 563 uint32_t kopt); 564 typedef int (objhash_cmp_f)(struct named_object *no, void *key, uint32_t kopt); 565 struct namedobj_instance *ipfw_objhash_create(uint32_t items); 566 void ipfw_objhash_destroy(struct namedobj_instance *); 567 void ipfw_objhash_bitmap_alloc(uint32_t items, void **idx, int *pblocks); 568 void ipfw_objhash_bitmap_merge(struct namedobj_instance *ni, 569 void **idx, int *blocks); 570 void ipfw_objhash_bitmap_swap(struct namedobj_instance *ni, 571 void **idx, int *blocks); 572 void ipfw_objhash_bitmap_free(void *idx, int blocks); 573 void ipfw_objhash_set_hashf(struct namedobj_instance *ni, objhash_hash_f *f); 574 struct named_object *ipfw_objhash_lookup_name(struct namedobj_instance *ni, 575 uint32_t set, char *name); 576 struct named_object *ipfw_objhash_lookup_kidx(struct namedobj_instance *ni, 577 uint16_t idx); 578 int ipfw_objhash_same_name(struct namedobj_instance *ni, struct named_object *a, 579 struct named_object *b); 580 void ipfw_objhash_add(struct namedobj_instance *ni, struct named_object *no); 581 void ipfw_objhash_del(struct namedobj_instance *ni, struct named_object *no); 582 uint32_t ipfw_objhash_count(struct namedobj_instance *ni); 583 void ipfw_objhash_foreach(struct namedobj_instance *ni, objhash_cb_t *f, 584 void *arg); 585 int ipfw_objhash_free_idx(struct namedobj_instance *ni, uint16_t idx); 586 int ipfw_objhash_alloc_idx(void *n, uint16_t *pidx); 587 void ipfw_objhash_set_funcs(struct namedobj_instance *ni, 588 objhash_hash_f *hash_f, objhash_cmp_f *cmp_f); 589 590 /* In ip_fw_table.c */ 591 struct table_info; 592 593 typedef int (table_lookup_t)(struct table_info *ti, void *key, uint32_t keylen, 594 uint32_t *val); 595 596 int ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, 597 uint32_t *val); 598 int ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, uint16_t plen, 599 void *paddr, uint32_t *val); 600 int ipfw_init_tables(struct ip_fw_chain *ch, int first); 601 int ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables); 602 int ipfw_switch_tables_namespace(struct ip_fw_chain *ch, unsigned int nsets); 603 void ipfw_destroy_tables(struct ip_fw_chain *ch, int last); 604 605 /* In ip_fw_nat.c -- XXX to be moved to ip_var.h */ 606 607 extern struct cfg_nat *(*lookup_nat_ptr)(struct nat_list *, int); 608 609 typedef int ipfw_nat_t(struct ip_fw_args *, struct cfg_nat *, struct mbuf *); 610 typedef int ipfw_nat_cfg_t(struct sockopt *); 611 612 VNET_DECLARE(int, ipfw_nat_ready); 613 #define V_ipfw_nat_ready VNET(ipfw_nat_ready) 614 #define IPFW_NAT_LOADED (V_ipfw_nat_ready) 615 616 extern ipfw_nat_t *ipfw_nat_ptr; 617 extern ipfw_nat_cfg_t *ipfw_nat_cfg_ptr; 618 extern ipfw_nat_cfg_t *ipfw_nat_del_ptr; 619 extern ipfw_nat_cfg_t *ipfw_nat_get_cfg_ptr; 620 extern ipfw_nat_cfg_t *ipfw_nat_get_log_ptr; 621 622 #endif /* _KERNEL */ 623 #endif /* _IPFW2_PRIVATE_H */ 624