Deleted Added
full compact
ip_fw_table.c (232865) ip_fw_table.c (233478)
1/*-
2 * Copyright (c) 2004 Ruslan Ermilov and Vsevolod Lobko.
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.

--- 10 unchanged lines hidden (view full) ---

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
26#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2004 Ruslan Ermilov and Vsevolod Lobko.
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.

--- 10 unchanged lines hidden (view full) ---

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
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: head/sys/netinet/ipfw/ip_fw_table.c 232865 2012-03-12 14:07:57Z melifaro $");
27__FBSDID("$FreeBSD: head/sys/netinet/ipfw/ip_fw_table.c 233478 2012-03-25 20:37:59Z melifaro $");
28
29/*
30 * Lookup table support for ipfw
31 *
32 * Lookup tables are implemented (at the moment) using the radix
33 * tree used for routing tables. Tables store key-value entries, where
34 * keys are network prefixes (addr/masklen), and values are integers.
35 * As a degenerate case we can interpret keys as 32-bit integers

--- 419 unchanged lines hidden (view full) ---

455 /* Allocate pointers */
456 ch->tables = malloc(V_fw_tables_max * sizeof(void *), M_IPFW, M_WAITOK | M_ZERO);
457 ch->xtables = malloc(V_fw_tables_max * sizeof(void *), M_IPFW, M_WAITOK | M_ZERO);
458 ch->tabletype = malloc(V_fw_tables_max * sizeof(uint8_t), M_IPFW, M_WAITOK | M_ZERO);
459 return (0);
460}
461
462int
28
29/*
30 * Lookup table support for ipfw
31 *
32 * Lookup tables are implemented (at the moment) using the radix
33 * tree used for routing tables. Tables store key-value entries, where
34 * keys are network prefixes (addr/masklen), and values are integers.
35 * As a degenerate case we can interpret keys as 32-bit integers

--- 419 unchanged lines hidden (view full) ---

455 /* Allocate pointers */
456 ch->tables = malloc(V_fw_tables_max * sizeof(void *), M_IPFW, M_WAITOK | M_ZERO);
457 ch->xtables = malloc(V_fw_tables_max * sizeof(void *), M_IPFW, M_WAITOK | M_ZERO);
458 ch->tabletype = malloc(V_fw_tables_max * sizeof(uint8_t), M_IPFW, M_WAITOK | M_ZERO);
459 return (0);
460}
461
462int
463ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables)
464{
465 struct radix_node_head **tables, **xtables, *rnh;
466 struct radix_node_head **tables_old, **xtables_old;
467 uint8_t *tabletype, *tabletype_old;
468 unsigned int ntables_old, tbl;
469
470 /* Check new value for validity */
471 if (ntables > IPFW_TABLES_MAX)
472 ntables = IPFW_TABLES_MAX;
473
474 /* Allocate new pointers */
475 tables = malloc(ntables * sizeof(void *), M_IPFW, M_WAITOK | M_ZERO);
476 xtables = malloc(ntables * sizeof(void *), M_IPFW, M_WAITOK | M_ZERO);
477 tabletype = malloc(ntables * sizeof(uint8_t), M_IPFW, M_WAITOK | M_ZERO);
478
479 IPFW_WLOCK(ch);
480
481 tbl = (ntables >= V_fw_tables_max) ? V_fw_tables_max : ntables;
482
483 /* Copy old table pointers */
484 memcpy(tables, ch->tables, sizeof(void *) * tbl);
485 memcpy(xtables, ch->xtables, sizeof(void *) * tbl);
486 memcpy(tabletype, ch->tabletype, sizeof(uint8_t) * tbl);
487
488 /* Change pointers and number of tables */
489 tables_old = ch->tables;
490 xtables_old = ch->xtables;
491 tabletype_old = ch->tabletype;
492 ch->tables = tables;
493 ch->xtables = xtables;
494 ch->tabletype = tabletype;
495
496 ntables_old = V_fw_tables_max;
497 V_fw_tables_max = ntables;
498
499 IPFW_WUNLOCK(ch);
500
501 /* Check if we need to destroy radix trees */
502 if (ntables < ntables_old) {
503 for (tbl = ntables; tbl < ntables_old; tbl++) {
504 if ((rnh = tables_old[tbl]) != NULL) {
505 rnh->rnh_walktree(rnh, flush_table_entry, rnh);
506 rn_detachhead((void **)&rnh);
507 }
508
509 if ((rnh = xtables_old[tbl]) != NULL) {
510 rnh->rnh_walktree(rnh, flush_table_entry, rnh);
511 rn_detachhead((void **)&rnh);
512 }
513 }
514 }
515
516 /* Free old pointers */
517 free(tables_old, M_IPFW);
518 free(xtables_old, M_IPFW);
519 free(tabletype_old, M_IPFW);
520
521 return (0);
522}
523
524int
463ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
464 uint32_t *val)
465{
466 struct radix_node_head *rnh;
467 struct table_entry *ent;
468 struct sockaddr_in sa;
469
470 if (tbl >= V_fw_tables_max)

--- 222 unchanged lines hidden ---
525ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
526 uint32_t *val)
527{
528 struct radix_node_head *rnh;
529 struct table_entry *ent;
530 struct sockaddr_in sa;
531
532 if (tbl >= V_fw_tables_max)

--- 222 unchanged lines hidden ---