ip_fw_table.c (272840) | ip_fw_table.c (273274) |
---|---|
1/*- 2 * Copyright (c) 2004 Ruslan Ermilov and Vsevolod Lobko. 3 * Copyright (c) 2014 Yandex LLC 4 * Copyright (c) 2014 Alexander V. Chernikov 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2004 Ruslan Ermilov and Vsevolod Lobko. 3 * Copyright (c) 2014 Yandex LLC 4 * Copyright (c) 2014 Alexander V. Chernikov 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/netpfil/ipfw/ip_fw_table.c 272840 2014-10-09 19:32:35Z melifaro $"); | 29__FBSDID("$FreeBSD: head/sys/netpfil/ipfw/ip_fw_table.c 273274 2014-10-19 11:15:19Z melifaro $"); |
30 31/* 32 * Lookup table support for ipfw. 33 * 34 * This file contains handlers for all generic tables' operations: 35 * add/del/flush entries, list/dump tables etc.. 36 * 37 * Table data modification is protected by both UH and runtime lock --- 1446 unchanged lines hidden (view full) --- 1484 ipfw_unref_table_values(ch, tc, tc->ta, tc->astate, &tc->ti_copy); 1485 IPFW_UH_WUNLOCK(ch); 1486 1487 free_table_config(ni, tc); 1488 1489 return (0); 1490} 1491 | 30 31/* 32 * Lookup table support for ipfw. 33 * 34 * This file contains handlers for all generic tables' operations: 35 * add/del/flush entries, list/dump tables etc.. 36 * 37 * Table data modification is protected by both UH and runtime lock --- 1446 unchanged lines hidden (view full) --- 1484 ipfw_unref_table_values(ch, tc, tc->ta, tc->astate, &tc->ti_copy); 1485 IPFW_UH_WUNLOCK(ch); 1486 1487 free_table_config(ni, tc); 1488 1489 return (0); 1490} 1491 |
1492static uint32_t 1493roundup2p(uint32_t v) 1494{ 1495 1496 v--; 1497 v |= v >> 1; 1498 v |= v >> 2; 1499 v |= v >> 4; 1500 v |= v >> 8; 1501 v |= v >> 16; 1502 v++; 1503 1504 return (v); 1505} 1506 |
|
1492/* 1493 * Grow tables index. 1494 * 1495 * Returns 0 on success. 1496 */ 1497int 1498ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables) 1499{ 1500 unsigned int ntables_old, tbl; 1501 struct namedobj_instance *ni; 1502 void *new_idx, *old_tablestate, *tablestate; 1503 struct table_info *ti; 1504 struct table_config *tc; 1505 int i, new_blocks; 1506 1507 /* Check new value for validity */ | 1507/* 1508 * Grow tables index. 1509 * 1510 * Returns 0 on success. 1511 */ 1512int 1513ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables) 1514{ 1515 unsigned int ntables_old, tbl; 1516 struct namedobj_instance *ni; 1517 void *new_idx, *old_tablestate, *tablestate; 1518 struct table_info *ti; 1519 struct table_config *tc; 1520 int i, new_blocks; 1521 1522 /* Check new value for validity */ |
1523 if (ntables == 0) 1524 return (EINVAL); |
|
1508 if (ntables > IPFW_TABLES_MAX) 1509 ntables = IPFW_TABLES_MAX; | 1525 if (ntables > IPFW_TABLES_MAX) 1526 ntables = IPFW_TABLES_MAX; |
1527 /* Alight to nearest power of 2 */ 1528 ntables = (unsigned int)roundup2p(ntables); |
|
1510 1511 /* Allocate new pointers */ 1512 tablestate = malloc(ntables * sizeof(struct table_info), 1513 M_IPFW, M_WAITOK | M_ZERO); 1514 1515 ipfw_objhash_bitmap_alloc(ntables, (void *)&new_idx, &new_blocks); 1516 1517 IPFW_UH_WLOCK(ch); --- 2138 unchanged lines hidden --- | 1529 1530 /* Allocate new pointers */ 1531 tablestate = malloc(ntables * sizeof(struct table_info), 1532 M_IPFW, M_WAITOK | M_ZERO); 1533 1534 ipfw_objhash_bitmap_alloc(ntables, (void *)&new_idx, &new_blocks); 1535 1536 IPFW_UH_WLOCK(ch); --- 2138 unchanged lines hidden --- |