2009-12-15 21:24:12 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2009-12-18 17:22:21 +00:00
|
|
|
* Copyright (c) 2004 Ruslan Ermilov and Vsevolod Lobko.
|
2014-09-05 14:19:02 +00:00
|
|
|
* Copyright (c) 2014 Yandex LLC
|
|
|
|
* Copyright (c) 2014 Alexander V. Chernikov
|
2009-12-15 21:24:12 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
/*
|
2014-06-28 23:20:24 +00:00
|
|
|
* Lookup table support for ipfw.
|
2009-12-16 10:48:40 +00:00
|
|
|
*
|
2014-07-03 22:25:59 +00:00
|
|
|
* This file contains handlers for all generic tables' operations:
|
2014-06-28 23:20:24 +00:00
|
|
|
* add/del/flush entries, list/dump tables etc..
|
2009-12-22 13:53:34 +00:00
|
|
|
*
|
2014-09-05 14:19:02 +00:00
|
|
|
* Table data modification is protected by both UH and runtime lock
|
2014-06-28 23:20:24 +00:00
|
|
|
* while reading configuration/data is protected by UH lock.
|
|
|
|
*
|
|
|
|
* Lookup algorithms for all table types are located in ip_fw_table_algo.c
|
2009-12-15 21:24:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_ipfw.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/rwlock.h>
|
2014-10-04 11:40:35 +00:00
|
|
|
#include <sys/rmlock.h>
|
2009-12-15 21:24:12 +00:00
|
|
|
#include <sys/socket.h>
|
2014-06-14 22:47:25 +00:00
|
|
|
#include <sys/socketvar.h>
|
2012-09-14 11:51:49 +00:00
|
|
|
#include <sys/queue.h>
|
2009-12-15 21:24:12 +00:00
|
|
|
#include <net/if.h> /* ip_fw.h requires IFNAMSIZ */
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
2010-01-07 10:08:05 +00:00
|
|
|
#include <netinet/ip_var.h> /* struct ipfw_rule_ref */
|
2009-12-15 21:24:12 +00:00
|
|
|
#include <netinet/ip_fw.h>
|
2012-09-14 11:51:49 +00:00
|
|
|
|
|
|
|
#include <netpfil/ipfw/ip_fw_private.h>
|
2014-06-14 11:13:02 +00:00
|
|
|
#include <netpfil/ipfw/ip_fw_table.h>
|
2009-12-15 21:24:12 +00:00
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
/*
|
|
|
|
* Table has the following `type` concepts:
|
|
|
|
*
|
2014-08-14 21:43:20 +00:00
|
|
|
* `no.type` represents lookup key type (addr, ifp, uid, etc..)
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
* vmask represents bitmask of table values which are present at the moment.
|
|
|
|
* Special IPFW_VTYPE_LEGACY ( (uint32_t)-1 ) represents old
|
|
|
|
* single-value-for-all approach.
|
2014-06-12 09:59:11 +00:00
|
|
|
*/
|
|
|
|
struct table_config {
|
|
|
|
struct named_object no;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
uint8_t tflags; /* type flags */
|
2014-08-11 18:09:37 +00:00
|
|
|
uint8_t locked; /* 1 if locked from changes */
|
2014-08-08 09:27:49 +00:00
|
|
|
uint8_t linked; /* 1 if already linked */
|
|
|
|
uint8_t ochanged; /* used by set swapping */
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
uint8_t vshared; /* 1 if using shared value array */
|
|
|
|
uint8_t spare[3];
|
|
|
|
uint32_t count; /* Number of records */
|
|
|
|
uint32_t limit; /* Max number of records */
|
|
|
|
uint32_t vmask; /* bitmask with supported values */
|
2014-08-07 21:37:31 +00:00
|
|
|
uint32_t ocount; /* used by set swapping */
|
|
|
|
uint64_t gencnt; /* generation count */
|
2014-06-12 09:59:11 +00:00
|
|
|
char tablename[64]; /* table name */
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_algo *ta; /* Callbacks for given algo */
|
|
|
|
void *astate; /* algorithm state */
|
2014-10-09 14:33:20 +00:00
|
|
|
struct table_info ti_copy; /* data to put to table_info */
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct namedobj_instance *vi;
|
2014-06-12 09:59:11 +00:00
|
|
|
};
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
static int find_table_err(struct namedobj_instance *ni, struct tid_info *ti,
|
|
|
|
struct table_config **tc);
|
2014-06-12 09:59:11 +00:00
|
|
|
static struct table_config *find_table(struct namedobj_instance *ni,
|
|
|
|
struct tid_info *ti);
|
2014-07-28 19:01:25 +00:00
|
|
|
static struct table_config *alloc_table_config(struct ip_fw_chain *ch,
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct tid_info *ti, struct table_algo *ta, char *adata, uint8_t tflags);
|
2014-06-12 09:59:11 +00:00
|
|
|
static void free_table_config(struct namedobj_instance *ni,
|
|
|
|
struct table_config *tc);
|
2014-07-26 13:37:25 +00:00
|
|
|
static int create_table_internal(struct ip_fw_chain *ch, struct tid_info *ti,
|
2014-08-23 12:41:39 +00:00
|
|
|
char *aname, ipfw_xtable_info *i, uint16_t *pkidx, int ref);
|
2014-08-12 09:48:54 +00:00
|
|
|
static void link_table(struct ip_fw_chain *ch, struct table_config *tc);
|
|
|
|
static void unlink_table(struct ip_fw_chain *ch, struct table_config *tc);
|
2014-08-23 11:27:49 +00:00
|
|
|
static int find_ref_table(struct ip_fw_chain *ch, struct tid_info *ti,
|
2014-08-23 12:41:39 +00:00
|
|
|
struct tentry_info *tei, uint32_t count, int op, struct table_config **ptc);
|
2014-08-23 11:27:49 +00:00
|
|
|
#define OP_ADD 1
|
|
|
|
#define OP_DEL 0
|
2014-06-27 10:07:00 +00:00
|
|
|
static int export_tables(struct ip_fw_chain *ch, ipfw_obj_lheader *olh,
|
|
|
|
struct sockopt_data *sd);
|
2014-07-03 22:25:59 +00:00
|
|
|
static void export_table_info(struct ip_fw_chain *ch, struct table_config *tc,
|
|
|
|
ipfw_xtable_info *i);
|
2014-07-06 18:16:04 +00:00
|
|
|
static int dump_table_tentry(void *e, void *arg);
|
2014-06-14 22:47:25 +00:00
|
|
|
static int dump_table_xentry(void *e, void *arg);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-07 21:37:31 +00:00
|
|
|
static int swap_tables(struct ip_fw_chain *ch, struct tid_info *a,
|
2014-08-03 21:37:12 +00:00
|
|
|
struct tid_info *b);
|
2014-07-03 22:25:59 +00:00
|
|
|
|
2015-11-03 10:29:46 +00:00
|
|
|
static int check_table_name(const char *name);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
static int check_table_space(struct ip_fw_chain *ch, struct tableop_state *ts,
|
|
|
|
struct table_config *tc, struct table_info *ti, uint32_t count);
|
2014-07-03 22:25:59 +00:00
|
|
|
static int destroy_table(struct ip_fw_chain *ch, struct tid_info *ti);
|
2014-06-15 13:40:27 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
static struct table_algo *find_table_algo(struct tables_config *tableconf,
|
2014-06-16 13:05:07 +00:00
|
|
|
struct tid_info *ti, char *name);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-03 21:37:12 +00:00
|
|
|
static void objheader_to_ti(struct _ipfw_obj_header *oh, struct tid_info *ti);
|
|
|
|
static void ntlv_to_ti(struct _ipfw_obj_ntlv *ntlv, struct tid_info *ti);
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
#define CHAIN_TO_NI(chain) (CHAIN_TO_TCFG(chain)->namehash)
|
2014-06-14 10:58:39 +00:00
|
|
|
#define KIDX_TO_TI(ch, k) (&(((struct table_info *)(ch)->tablestate)[k]))
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
#define TA_BUF_SZ 128 /* On-stack buffer for add/delete state */
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
void
|
|
|
|
rollback_toperation_state(struct ip_fw_chain *ch, void *object)
|
|
|
|
{
|
|
|
|
struct tables_config *tcfg;
|
|
|
|
struct op_state *os;
|
|
|
|
|
|
|
|
tcfg = CHAIN_TO_TCFG(ch);
|
|
|
|
TAILQ_FOREACH(os, &tcfg->state_list, next)
|
2014-09-02 20:46:18 +00:00
|
|
|
os->func(object, os);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_toperation_state(struct ip_fw_chain *ch, struct tableop_state *ts)
|
|
|
|
{
|
|
|
|
struct tables_config *tcfg;
|
|
|
|
|
|
|
|
tcfg = CHAIN_TO_TCFG(ch);
|
|
|
|
TAILQ_INSERT_HEAD(&tcfg->state_list, &ts->opstate, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
del_toperation_state(struct ip_fw_chain *ch, struct tableop_state *ts)
|
|
|
|
{
|
|
|
|
struct tables_config *tcfg;
|
|
|
|
|
|
|
|
tcfg = CHAIN_TO_TCFG(ch);
|
|
|
|
TAILQ_REMOVE(&tcfg->state_list, &ts->opstate, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tc_ref(struct table_config *tc)
|
|
|
|
{
|
|
|
|
|
|
|
|
tc->no.refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tc_unref(struct table_config *tc)
|
|
|
|
{
|
|
|
|
|
|
|
|
tc->no.refcnt--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct table_value *
|
|
|
|
get_table_value(struct ip_fw_chain *ch, struct table_config *tc, uint32_t kidx)
|
|
|
|
{
|
|
|
|
struct table_value *pval;
|
|
|
|
|
|
|
|
pval = (struct table_value *)ch->valuestate;
|
|
|
|
|
|
|
|
return (&pval[kidx]);
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/*
|
|
|
|
* Checks if we're able to insert/update entry @tei into table
|
|
|
|
* w.r.t @tc limits.
|
|
|
|
* May alter @tei to indicate insertion error / insert
|
|
|
|
* options.
|
|
|
|
*
|
|
|
|
* Returns 0 if operation can be performed/
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_table_limit(struct table_config *tc, struct tentry_info *tei)
|
|
|
|
{
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
if (tc->limit == 0 || tc->count < tc->limit)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if ((tei->flags & TEI_FLAGS_UPDATE) == 0) {
|
|
|
|
/* Notify userland on error cause */
|
|
|
|
tei->flags |= TEI_FLAGS_LIMIT;
|
|
|
|
return (EFBIG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have UPDATE flag set.
|
|
|
|
* Permit updating record (if found),
|
|
|
|
* but restrict adding new one since we've
|
|
|
|
* already hit the limit.
|
|
|
|
*/
|
|
|
|
tei->flags |= TEI_FLAGS_DONTADD;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-08-11 22:38:13 +00:00
|
|
|
* Convert algorithm callback return code into
|
|
|
|
* one of pre-defined states known by userland.
|
|
|
|
*/
|
|
|
|
static void
|
2014-08-23 12:41:39 +00:00
|
|
|
store_tei_result(struct tentry_info *tei, int op, int error, uint32_t num)
|
2014-08-11 22:38:13 +00:00
|
|
|
{
|
|
|
|
int flag;
|
|
|
|
|
|
|
|
flag = 0;
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
case 0:
|
2014-08-23 12:41:39 +00:00
|
|
|
if (op == OP_ADD && num != 0)
|
2014-08-11 22:38:13 +00:00
|
|
|
flag = TEI_FLAGS_ADDED;
|
2014-08-23 12:41:39 +00:00
|
|
|
if (op == OP_DEL)
|
2014-08-11 22:38:13 +00:00
|
|
|
flag = TEI_FLAGS_DELETED;
|
|
|
|
break;
|
|
|
|
case ENOENT:
|
|
|
|
flag = TEI_FLAGS_NOTFOUND;
|
|
|
|
break;
|
|
|
|
case EEXIST:
|
|
|
|
flag = TEI_FLAGS_EXISTS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flag = TEI_FLAGS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
tei->flags |= flag;
|
|
|
|
}
|
|
|
|
|
2014-08-12 10:22:46 +00:00
|
|
|
/*
|
|
|
|
* Creates and references table with default parameters.
|
|
|
|
* Saves table config, algo and allocated kidx info @ptc, @pta and
|
|
|
|
* @pkidx if non-zero.
|
|
|
|
* Used for table auto-creation to support old binaries.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2014-08-12 09:48:54 +00:00
|
|
|
static int
|
|
|
|
create_table_compat(struct ip_fw_chain *ch, struct tid_info *ti,
|
2014-08-23 12:41:39 +00:00
|
|
|
uint16_t *pkidx)
|
2014-08-12 09:48:54 +00:00
|
|
|
{
|
|
|
|
ipfw_xtable_info xi;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
memset(&xi, 0, sizeof(xi));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
/* Set default value mask for legacy clients */
|
|
|
|
xi.vmask = IPFW_VTYPE_LEGACY;
|
2014-08-12 09:48:54 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
error = create_table_internal(ch, ti, NULL, &xi, pkidx, 1);
|
2014-08-12 09:48:54 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:38:13 +00:00
|
|
|
/*
|
|
|
|
* Find and reference existing table optionally
|
|
|
|
* creating new one.
|
2014-08-11 17:34:25 +00:00
|
|
|
*
|
2014-08-23 12:41:39 +00:00
|
|
|
* Saves found table config into @ptc.
|
|
|
|
* Note function may drop/acquire UH_WLOCK.
|
2014-08-11 22:38:13 +00:00
|
|
|
* Returns 0 if table was found/created and referenced
|
|
|
|
* or non-zero return code.
|
2014-08-11 17:34:25 +00:00
|
|
|
*/
|
2014-08-11 22:38:13 +00:00
|
|
|
static int
|
|
|
|
find_ref_table(struct ip_fw_chain *ch, struct tid_info *ti,
|
2014-08-23 11:27:49 +00:00
|
|
|
struct tentry_info *tei, uint32_t count, int op,
|
2014-08-23 12:41:39 +00:00
|
|
|
struct table_config **ptc)
|
2009-12-15 21:24:12 +00:00
|
|
|
{
|
2014-08-11 22:38:13 +00:00
|
|
|
struct namedobj_instance *ni;
|
2014-07-26 13:37:25 +00:00
|
|
|
struct table_config *tc;
|
2014-08-23 12:41:39 +00:00
|
|
|
uint16_t kidx;
|
2014-08-11 22:38:13 +00:00
|
|
|
int error;
|
2009-12-15 21:24:12 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-11 22:38:13 +00:00
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
tc = NULL;
|
2014-06-14 10:58:39 +00:00
|
|
|
if ((tc = find_table(ni, ti)) != NULL) {
|
|
|
|
/* check table type */
|
2015-04-27 08:29:39 +00:00
|
|
|
if (tc->no.subtype != ti->type)
|
2012-03-12 14:07:57 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
if (tc->locked != 0)
|
2014-08-11 18:09:37 +00:00
|
|
|
return (EACCES);
|
|
|
|
|
2014-08-01 15:17:46 +00:00
|
|
|
/* Try to exit early on limit hit */
|
2014-08-23 11:27:49 +00:00
|
|
|
if (op == OP_ADD && count == 1 &&
|
2014-08-23 12:41:39 +00:00
|
|
|
check_table_limit(tc, tei) != 0)
|
2014-08-11 22:38:13 +00:00
|
|
|
return (EFBIG);
|
2014-08-01 15:17:46 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
/* Reference and return */
|
2014-06-14 10:58:39 +00:00
|
|
|
tc->no.refcnt++;
|
2014-08-23 12:41:39 +00:00
|
|
|
*ptc = tc;
|
|
|
|
return (0);
|
2012-03-12 14:07:57 +00:00
|
|
|
}
|
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
if (op == OP_DEL)
|
|
|
|
return (ESRCH);
|
2014-08-11 22:38:13 +00:00
|
|
|
|
2016-05-03 18:05:43 +00:00
|
|
|
/* Compatibility mode: create new table for old clients */
|
2014-08-23 12:41:39 +00:00
|
|
|
if ((tei->flags & TEI_FLAGS_COMPAT) == 0)
|
|
|
|
return (ESRCH);
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
error = create_table_compat(ch, ti, &kidx);
|
|
|
|
IPFW_UH_WLOCK(ch);
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
tc = (struct table_config *)ipfw_objhash_lookup_kidx(ni, kidx);
|
|
|
|
KASSERT(tc != NULL, ("create_table_compat returned bad idx %d", kidx));
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
/* OK, now we've got referenced table. */
|
2014-08-11 22:38:13 +00:00
|
|
|
*ptc = tc;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-08-23 12:41:39 +00:00
|
|
|
* Rolls back already @added to @tc entries using state array @ta_buf_m.
|
2014-08-11 22:38:13 +00:00
|
|
|
* Assume the following layout:
|
|
|
|
* 1) ADD state (ta_buf_m[0] ... t_buf_m[added - 1]) for handling update cases
|
|
|
|
* 2) DEL state (ta_buf_m[count[ ... t_buf_m[count + added - 1])
|
|
|
|
* for storing deleted state
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
rollback_added_entries(struct ip_fw_chain *ch, struct table_config *tc,
|
|
|
|
struct table_info *tinfo, struct tentry_info *tei, caddr_t ta_buf_m,
|
|
|
|
uint32_t count, uint32_t added)
|
|
|
|
{
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct tentry_info *ptei;
|
|
|
|
caddr_t v, vv;
|
|
|
|
size_t ta_buf_sz;
|
|
|
|
int error, i;
|
|
|
|
uint32_t num;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
|
|
|
|
ta = tc->ta;
|
|
|
|
ta_buf_sz = ta->ta_buf_size;
|
|
|
|
v = ta_buf_m;
|
|
|
|
vv = v + count * ta_buf_sz;
|
|
|
|
for (i = 0; i < added; i++, v += ta_buf_sz, vv += ta_buf_sz) {
|
|
|
|
ptei = &tei[i];
|
|
|
|
if ((ptei->flags & TEI_FLAGS_UPDATED) != 0) {
|
|
|
|
/*
|
|
|
|
* We have old value stored by previous
|
|
|
|
* call in @ptei->value. Do add once again
|
|
|
|
* to restore it.
|
|
|
|
*/
|
|
|
|
error = ta->add(tc->astate, tinfo, ptei, v, &num);
|
|
|
|
KASSERT(error == 0, ("rollback UPDATE fail"));
|
|
|
|
KASSERT(num == 0, ("rollback UPDATE fail2"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ta->prepare_del(ch, ptei, vv);
|
|
|
|
KASSERT(error == 0, ("pre-rollback INSERT failed"));
|
|
|
|
error = ta->del(tc->astate, tinfo, ptei, vv, &num);
|
|
|
|
KASSERT(error == 0, ("rollback INSERT failed"));
|
|
|
|
tc->count -= num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepares add/del state for all @count entries in @tei.
|
|
|
|
* Uses either stack buffer (@ta_buf) or allocates a new one.
|
|
|
|
* Stores pointer to allocated buffer back to @ta_buf.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
prepare_batch_buffer(struct ip_fw_chain *ch, struct table_algo *ta,
|
2014-08-23 11:27:49 +00:00
|
|
|
struct tentry_info *tei, uint32_t count, int op, caddr_t *ta_buf)
|
2014-08-11 22:38:13 +00:00
|
|
|
{
|
|
|
|
caddr_t ta_buf_m, v;
|
|
|
|
size_t ta_buf_sz, sz;
|
|
|
|
struct tentry_info *ptei;
|
|
|
|
int error, i;
|
|
|
|
|
|
|
|
error = 0;
|
2014-08-11 17:34:25 +00:00
|
|
|
ta_buf_sz = ta->ta_buf_size;
|
|
|
|
if (count == 1) {
|
2017-03-09 09:54:23 +00:00
|
|
|
/* Single add/delete, use on-stack buffer */
|
2014-08-11 22:38:13 +00:00
|
|
|
memset(*ta_buf, 0, TA_BUF_SZ);
|
|
|
|
ta_buf_m = *ta_buf;
|
2014-08-11 17:34:25 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2014-08-11 22:38:13 +00:00
|
|
|
* Multiple adds/deletes, allocate larger buffer
|
|
|
|
*
|
|
|
|
* Note we need 2xcount buffer for add case:
|
|
|
|
* we have hold both ADD state
|
2014-08-11 17:34:25 +00:00
|
|
|
* and DELETE state (this may be needed
|
|
|
|
* if we need to rollback all changes)
|
|
|
|
*/
|
2014-08-11 22:38:13 +00:00
|
|
|
sz = count * ta_buf_sz;
|
2014-08-23 11:27:49 +00:00
|
|
|
ta_buf_m = malloc((op == OP_ADD) ? sz * 2 : sz, M_TEMP,
|
2014-08-11 17:34:25 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
}
|
2014-08-11 22:38:13 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
v = ta_buf_m;
|
|
|
|
for (i = 0; i < count; i++, v += ta_buf_sz) {
|
2014-08-11 22:38:13 +00:00
|
|
|
ptei = &tei[i];
|
2014-08-23 11:27:49 +00:00
|
|
|
error = (op == OP_ADD) ?
|
2014-08-11 22:38:13 +00:00
|
|
|
ta->prepare_add(ch, ptei, v) : ta->prepare_del(ch, ptei, v);
|
2014-08-11 17:34:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some syntax error (incorrect mask, or address, or
|
|
|
|
* anything). Return error regardless of atomicity
|
|
|
|
* settings.
|
|
|
|
*/
|
|
|
|
if (error != 0)
|
2014-08-11 22:38:13 +00:00
|
|
|
break;
|
2014-08-11 17:34:25 +00:00
|
|
|
}
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-11 22:38:13 +00:00
|
|
|
*ta_buf = ta_buf_m;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flushes allocated state for each @count entries in @tei.
|
|
|
|
* Frees @ta_buf_m if differs from stack buffer @ta_buf.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
flush_batch_buffer(struct ip_fw_chain *ch, struct table_algo *ta,
|
2014-08-23 12:41:39 +00:00
|
|
|
struct tentry_info *tei, uint32_t count, int rollback,
|
2014-08-11 22:38:13 +00:00
|
|
|
caddr_t ta_buf_m, caddr_t ta_buf)
|
|
|
|
{
|
|
|
|
caddr_t v;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct tentry_info *ptei;
|
2014-08-11 22:38:13 +00:00
|
|
|
size_t ta_buf_sz;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ta_buf_sz = ta->ta_buf_size;
|
|
|
|
|
|
|
|
/* Run cleaning callback anyway */
|
|
|
|
v = ta_buf_m;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
for (i = 0; i < count; i++, v += ta_buf_sz) {
|
|
|
|
ptei = &tei[i];
|
|
|
|
ta->flush_entry(ch, ptei, v);
|
|
|
|
if (ptei->ptv != NULL) {
|
|
|
|
free(ptei->ptv, M_IPFW);
|
|
|
|
ptei->ptv = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 22:38:13 +00:00
|
|
|
|
|
|
|
/* Clean up "deleted" state in case of rollback */
|
|
|
|
if (rollback != 0) {
|
|
|
|
v = ta_buf_m + count * ta_buf_sz;
|
|
|
|
for (i = 0; i < count; i++, v += ta_buf_sz)
|
|
|
|
ta->flush_entry(ch, &tei[i], v);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ta_buf_m != ta_buf)
|
|
|
|
free(ta_buf_m, M_TEMP);
|
|
|
|
}
|
|
|
|
|
2014-09-02 14:27:12 +00:00
|
|
|
static void
|
|
|
|
rollback_add_entry(void *object, struct op_state *_state)
|
|
|
|
{
|
|
|
|
struct ip_fw_chain *ch;
|
|
|
|
struct tableop_state *ts;
|
|
|
|
|
|
|
|
ts = (struct tableop_state *)_state;
|
|
|
|
|
|
|
|
if (ts->tc != object && ts->ch != object)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ch = ts->ch;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
|
|
|
|
/* Call specifid unlockers */
|
|
|
|
rollback_table_values(ts);
|
|
|
|
|
|
|
|
/* Indicate we've called */
|
|
|
|
ts->modified = 1;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:38:13 +00:00
|
|
|
/*
|
|
|
|
* Adds/updates one or more entries in table @ti.
|
2014-09-02 14:27:12 +00:00
|
|
|
*
|
|
|
|
* Function may drop/reacquire UH wlock multiple times due to
|
|
|
|
* items alloc, algorithm callbacks (check_space), value linkage
|
|
|
|
* (new values, value storage realloc), etc..
|
|
|
|
* Other processes like other adds (which may involve storage resize),
|
|
|
|
* table swaps (which changes table data and may change algo type),
|
|
|
|
* table modify (which may change value mask) may be executed
|
|
|
|
* simultaneously so we need to deal with it.
|
|
|
|
*
|
|
|
|
* The following approach was implemented:
|
|
|
|
* we have per-chain linked list, protected with UH lock.
|
|
|
|
* add_table_entry prepares special on-stack structure wthich is passed
|
|
|
|
* to its descendants. Users add this structure to this list before unlock.
|
|
|
|
* After performing needed operations and acquiring UH lock back, each user
|
|
|
|
* checks if structure has changed. If true, it rolls local state back and
|
|
|
|
* returns without error to the caller.
|
|
|
|
* add_table_entry() on its own checks if structure has changed and restarts
|
|
|
|
* its operation from the beginning (goto restart).
|
|
|
|
*
|
|
|
|
* Functions which are modifying fields of interest (currently
|
|
|
|
* resize_shared_value_storage() and swap_tables() )
|
|
|
|
* traverses given list while holding UH lock immediately before
|
|
|
|
* performing their operations calling function provided be list entry
|
|
|
|
* ( currently rollback_add_entry ) which performs rollback for all necessary
|
|
|
|
* state and sets appropriate values in structure indicating rollback
|
|
|
|
* has happened.
|
|
|
|
*
|
|
|
|
* Algo interaction:
|
2014-08-12 09:48:54 +00:00
|
|
|
* Function references @ti first to ensure table won't
|
|
|
|
* disappear or change its type.
|
|
|
|
* After that, prepare_add callback is called for each @tei entry.
|
|
|
|
* Next, we try to add each entry under UH+WHLOCK
|
|
|
|
* using add() callback.
|
|
|
|
* Finally, we free all state by calling flush_entry callback
|
|
|
|
* for each @tei.
|
2014-08-11 22:38:13 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
add_table_entry(struct ip_fw_chain *ch, struct tid_info *ti,
|
|
|
|
struct tentry_info *tei, uint8_t flags, uint32_t count)
|
|
|
|
{
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
uint16_t kidx;
|
|
|
|
int error, first_error, i, rollback;
|
|
|
|
uint32_t num, numadd;
|
|
|
|
struct tentry_info *ptei;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct tableop_state ts;
|
2014-08-11 22:38:13 +00:00
|
|
|
char ta_buf[TA_BUF_SZ];
|
|
|
|
caddr_t ta_buf_m, v;
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
memset(&ts, 0, sizeof(ts));
|
2014-10-04 13:57:14 +00:00
|
|
|
ta = NULL;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
|
2014-08-11 22:38:13 +00:00
|
|
|
/*
|
|
|
|
* Find and reference existing table.
|
|
|
|
*/
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
restart:
|
|
|
|
if (ts.modified != 0) {
|
2014-10-07 10:54:53 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
flush_batch_buffer(ch, ta, tei, count, rollback,
|
|
|
|
ta_buf_m, ta_buf);
|
|
|
|
memset(&ts, 0, sizeof(ts));
|
2014-10-07 10:54:53 +00:00
|
|
|
ta = NULL;
|
|
|
|
IPFW_UH_WLOCK(ch);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
}
|
2014-10-07 10:54:53 +00:00
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
error = find_ref_table(ch, ti, tei, count, OP_ADD, &tc);
|
|
|
|
if (error != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-08-11 22:38:13 +00:00
|
|
|
return (error);
|
2014-08-23 12:41:39 +00:00
|
|
|
}
|
|
|
|
ta = tc->ta;
|
2014-09-02 20:46:18 +00:00
|
|
|
|
|
|
|
/* Fill in tablestate */
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
ts.ch = ch;
|
2014-09-02 14:27:12 +00:00
|
|
|
ts.opstate.func = rollback_add_entry;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
ts.tc = tc;
|
|
|
|
ts.vshared = tc->vshared;
|
|
|
|
ts.vmask = tc->vmask;
|
|
|
|
ts.ta = ta;
|
|
|
|
ts.tei = tei;
|
|
|
|
ts.count = count;
|
|
|
|
rollback = 0;
|
|
|
|
add_toperation_state(ch, &ts);
|
2014-08-23 12:41:39 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-08-11 22:38:13 +00:00
|
|
|
|
|
|
|
/* Allocate memory and prepare record(s) */
|
|
|
|
/* Pass stack buffer by default */
|
|
|
|
ta_buf_m = ta_buf;
|
2014-08-23 11:27:49 +00:00
|
|
|
error = prepare_batch_buffer(ch, ta, tei, count, OP_ADD, &ta_buf_m);
|
2014-08-11 22:38:13 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
2015-05-06 07:53:43 +00:00
|
|
|
del_toperation_state(ch, &ts);
|
2014-08-12 17:03:13 +00:00
|
|
|
/* Drop reference we've used in first search */
|
|
|
|
tc->no.refcnt--;
|
|
|
|
|
2015-05-06 07:53:43 +00:00
|
|
|
/* Check prepare_batch_buffer() error */
|
|
|
|
if (error != 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/*
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
* Check if table swap has happened.
|
|
|
|
* (so table algo might be changed).
|
|
|
|
* Restart operation to achieve consistent behavior.
|
2014-08-02 17:18:47 +00:00
|
|
|
*/
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
if (ts.modified != 0)
|
|
|
|
goto restart;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Link all values values to shared/per-table value array.
|
|
|
|
*
|
|
|
|
* May release/reacquire UH_WLOCK.
|
|
|
|
*/
|
2019-12-19 10:22:16 +00:00
|
|
|
error = ipfw_link_table_values(ch, &ts, flags);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
if (error != 0)
|
2014-08-11 17:34:25 +00:00
|
|
|
goto cleanup;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
if (ts.modified != 0)
|
|
|
|
goto restart;
|
2014-08-02 17:18:47 +00:00
|
|
|
|
2014-08-12 17:03:13 +00:00
|
|
|
/*
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
* Ensure we are able to add all entries without additional
|
|
|
|
* memory allocations. May release/reacquire UH_WLOCK.
|
2014-08-12 17:03:13 +00:00
|
|
|
*/
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
kidx = tc->no.kidx;
|
|
|
|
error = check_table_space(ch, &ts, tc, KIDX_TO_TI(ch, kidx), count);
|
|
|
|
if (error != 0)
|
2014-08-12 17:03:13 +00:00
|
|
|
goto cleanup;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
if (ts.modified != 0)
|
|
|
|
goto restart;
|
2014-08-12 17:03:13 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/* We've got valid table in @tc. Let's try to add data */
|
|
|
|
kidx = tc->no.kidx;
|
|
|
|
ta = tc->ta;
|
|
|
|
numadd = 0;
|
|
|
|
first_error = 0;
|
|
|
|
|
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
|
|
|
|
v = ta_buf_m;
|
2014-08-11 22:38:13 +00:00
|
|
|
for (i = 0; i < count; i++, v += ta->ta_buf_size) {
|
2014-08-11 17:34:25 +00:00
|
|
|
ptei = &tei[i];
|
|
|
|
num = 0;
|
|
|
|
/* check limit before adding */
|
|
|
|
if ((error = check_table_limit(tc, ptei)) == 0) {
|
2019-12-19 10:22:16 +00:00
|
|
|
/*
|
|
|
|
* It should be safe to insert a record w/o
|
|
|
|
* a properly-linked value if atomicity is
|
|
|
|
* not required.
|
|
|
|
*
|
|
|
|
* If the added item does not have a valid value
|
|
|
|
* index, it would get rejected by ta->add().
|
|
|
|
* */
|
2014-08-11 17:34:25 +00:00
|
|
|
error = ta->add(tc->astate, KIDX_TO_TI(ch, kidx),
|
|
|
|
ptei, v, &num);
|
|
|
|
/* Set status flag to inform userland */
|
2014-08-23 12:41:39 +00:00
|
|
|
store_tei_result(ptei, OP_ADD, error, num);
|
2014-08-11 17:34:25 +00:00
|
|
|
}
|
|
|
|
if (error == 0) {
|
|
|
|
/* Update number of records to ease limit checking */
|
|
|
|
tc->count += num;
|
|
|
|
numadd += num;
|
|
|
|
continue;
|
2014-08-01 15:17:46 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
if (first_error == 0)
|
|
|
|
first_error = error;
|
|
|
|
|
2014-08-01 15:17:46 +00:00
|
|
|
/*
|
2014-08-11 17:34:25 +00:00
|
|
|
* Some error have happened. Check our atomicity
|
|
|
|
* settings: continue if atomicity is not required,
|
|
|
|
* rollback changes otherwise.
|
2014-08-01 15:17:46 +00:00
|
|
|
*/
|
2014-08-11 17:34:25 +00:00
|
|
|
if ((flags & IPFW_CTF_ATOMIC) == 0)
|
|
|
|
continue;
|
2014-08-01 15:17:46 +00:00
|
|
|
|
2014-08-11 22:38:13 +00:00
|
|
|
rollback_added_entries(ch, tc, KIDX_TO_TI(ch, kidx),
|
|
|
|
tei, ta_buf_m, count, i);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
|
|
|
|
rollback = 1;
|
2014-08-11 17:34:25 +00:00
|
|
|
break;
|
2014-08-02 17:18:47 +00:00
|
|
|
}
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
IPFW_WUNLOCK(ch);
|
|
|
|
|
2014-09-02 14:27:12 +00:00
|
|
|
ipfw_garbage_table_values(ch, tc, tei, count, rollback);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/* Permit post-add algorithm grow/rehash. */
|
|
|
|
if (numadd != 0)
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
check_table_space(ch, NULL, tc, KIDX_TO_TI(ch, kidx), 0);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/* Return first error to user, if any */
|
|
|
|
error = first_error;
|
|
|
|
|
|
|
|
cleanup:
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
flush_batch_buffer(ch, ta, tei, count, rollback, ta_buf_m, ta_buf);
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
return (error);
|
2009-12-15 21:24:12 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/*
|
|
|
|
* Deletes one or more entries in table @ti.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2009-12-15 21:24:12 +00:00
|
|
|
int
|
2014-07-04 07:02:11 +00:00
|
|
|
del_table_entry(struct ip_fw_chain *ch, struct tid_info *ti,
|
2014-08-11 17:34:25 +00:00
|
|
|
struct tentry_info *tei, uint8_t flags, uint32_t count)
|
2009-12-15 21:24:12 +00:00
|
|
|
{
|
2014-06-12 09:59:11 +00:00
|
|
|
struct table_config *tc;
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_algo *ta;
|
2014-08-11 17:34:25 +00:00
|
|
|
struct tentry_info *ptei;
|
2014-06-12 09:59:11 +00:00
|
|
|
uint16_t kidx;
|
2014-08-11 17:34:25 +00:00
|
|
|
int error, first_error, i;
|
|
|
|
uint32_t num, numdel;
|
2014-08-02 17:18:47 +00:00
|
|
|
char ta_buf[TA_BUF_SZ];
|
2014-08-11 17:34:25 +00:00
|
|
|
caddr_t ta_buf_m, v;
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/*
|
2014-08-11 22:38:13 +00:00
|
|
|
* Find and reference existing table.
|
2014-08-02 17:18:47 +00:00
|
|
|
*/
|
2014-08-23 12:41:39 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
error = find_ref_table(ch, ti, tei, count, OP_DEL, &tc);
|
|
|
|
if (error != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-08-02 17:18:47 +00:00
|
|
|
return (error);
|
2014-08-23 12:41:39 +00:00
|
|
|
}
|
|
|
|
ta = tc->ta;
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-08-11 17:34:25 +00:00
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/* Allocate memory and prepare record(s) */
|
2014-08-11 22:38:13 +00:00
|
|
|
/* Pass stack buffer by default */
|
|
|
|
ta_buf_m = ta_buf;
|
2014-08-23 11:27:49 +00:00
|
|
|
error = prepare_batch_buffer(ch, ta, tei, count, OP_DEL, &ta_buf_m);
|
2014-08-11 22:38:13 +00:00
|
|
|
if (error != 0)
|
|
|
|
goto cleanup;
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
|
|
|
|
/* Drop reference we've used in first search */
|
|
|
|
tc->no.refcnt--;
|
|
|
|
|
2014-08-12 17:03:13 +00:00
|
|
|
/*
|
|
|
|
* Check if table algo is still the same.
|
|
|
|
* (changed ta may be the result of table swap).
|
|
|
|
*/
|
|
|
|
if (ta != tc->ta) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
error = EINVAL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
kidx = tc->no.kidx;
|
2014-08-11 17:34:25 +00:00
|
|
|
numdel = 0;
|
|
|
|
first_error = 0;
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_WLOCK(ch);
|
2014-08-11 17:34:25 +00:00
|
|
|
v = ta_buf_m;
|
2014-08-11 22:38:13 +00:00
|
|
|
for (i = 0; i < count; i++, v += ta->ta_buf_size) {
|
2014-08-11 17:34:25 +00:00
|
|
|
ptei = &tei[i];
|
|
|
|
num = 0;
|
|
|
|
error = ta->del(tc->astate, KIDX_TO_TI(ch, kidx), ptei, v,
|
|
|
|
&num);
|
|
|
|
/* Save state for userland */
|
2014-08-23 12:41:39 +00:00
|
|
|
store_tei_result(ptei, OP_DEL, error, num);
|
2014-08-11 17:34:25 +00:00
|
|
|
if (error != 0 && first_error == 0)
|
|
|
|
first_error = error;
|
|
|
|
tc->count -= num;
|
|
|
|
numdel += num;
|
|
|
|
}
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_WUNLOCK(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
/* Unlink non-used values */
|
2014-09-02 14:27:12 +00:00
|
|
|
ipfw_garbage_table_values(ch, tc, tei, count, 0);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
if (numdel != 0) {
|
2014-08-02 17:18:47 +00:00
|
|
|
/* Run post-del hook to permit shrinking */
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
check_table_space(ch, NULL, tc, KIDX_TO_TI(ch, kidx), 0);
|
2014-08-02 17:18:47 +00:00
|
|
|
}
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2009-12-15 21:24:12 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/* Return first error to user, if any */
|
|
|
|
error = first_error;
|
|
|
|
|
|
|
|
cleanup:
|
2014-08-23 12:41:39 +00:00
|
|
|
flush_batch_buffer(ch, ta, tei, count, 0, ta_buf_m, ta_buf);
|
2014-07-03 22:25:59 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-07-26 13:37:25 +00:00
|
|
|
/*
|
2014-08-02 17:18:47 +00:00
|
|
|
* Ensure that table @tc has enough space to add @count entries without
|
|
|
|
* need for reallocation.
|
2014-07-26 13:37:25 +00:00
|
|
|
*
|
|
|
|
* Callbacks order:
|
2014-08-12 14:09:15 +00:00
|
|
|
* 0) need_modify() (UH_WLOCK) - checks if @count items can be added w/o resize.
|
2014-08-02 17:18:47 +00:00
|
|
|
*
|
2014-07-26 13:37:25 +00:00
|
|
|
* 1) alloc_modify (no locks, M_WAITOK) - alloc new state based on @pflags.
|
|
|
|
* 2) prepare_modifyt (UH_WLOCK) - copy old data into new storage
|
|
|
|
* 3) modify (UH_WLOCK + WLOCK) - switch pointers
|
2014-08-02 17:18:47 +00:00
|
|
|
* 4) flush_modify (UH_WLOCK) - free state, if needed
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
2014-07-26 13:37:25 +00:00
|
|
|
*/
|
|
|
|
static int
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
check_table_space(struct ip_fw_chain *ch, struct tableop_state *ts,
|
|
|
|
struct table_config *tc, struct table_info *ti, uint32_t count)
|
2014-07-26 13:37:25 +00:00
|
|
|
{
|
2014-08-02 17:18:47 +00:00
|
|
|
struct table_algo *ta;
|
|
|
|
uint64_t pflags;
|
|
|
|
char ta_buf[TA_BUF_SZ];
|
2014-07-26 13:37:25 +00:00
|
|
|
int error;
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
error = 0;
|
|
|
|
ta = tc->ta;
|
2014-08-14 17:31:04 +00:00
|
|
|
if (ta->need_modify == NULL)
|
|
|
|
return (0);
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/* Acquire reference not to loose @tc between locks/unlocks */
|
|
|
|
tc->no.refcnt++;
|
2014-07-26 13:37:25 +00:00
|
|
|
|
|
|
|
/*
|
2014-08-02 17:18:47 +00:00
|
|
|
* TODO: think about avoiding race between large add/large delete
|
|
|
|
* operation on algorithm which implements shrinking along with
|
|
|
|
* growing.
|
2014-07-26 13:37:25 +00:00
|
|
|
*/
|
2014-08-02 17:18:47 +00:00
|
|
|
while (true) {
|
|
|
|
pflags = 0;
|
2014-08-12 14:09:15 +00:00
|
|
|
if (ta->need_modify(tc->astate, ti, count, &pflags) == 0) {
|
2014-08-11 20:00:51 +00:00
|
|
|
error = 0;
|
|
|
|
break;
|
2014-08-02 17:18:47 +00:00
|
|
|
}
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/* We have to shrink/grow table */
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
if (ts != NULL)
|
|
|
|
add_toperation_state(ch, ts);
|
2014-08-02 17:18:47 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-08-12 14:09:15 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
memset(&ta_buf, 0, sizeof(ta_buf));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
error = ta->prepare_mod(ta_buf, &pflags);
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
if (ts != NULL)
|
|
|
|
del_toperation_state(ch, ts);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ts != NULL && ts->modified != 0) {
|
|
|
|
/*
|
|
|
|
* Swap operation has happened
|
|
|
|
* so we're currently operating on other
|
|
|
|
* table data. Stop doing this.
|
|
|
|
*/
|
|
|
|
ta->flush_mod(ta_buf);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/* Check if we still need to alter table */
|
|
|
|
ti = KIDX_TO_TI(ch, tc->no.kidx);
|
2014-08-12 14:09:15 +00:00
|
|
|
if (ta->need_modify(tc->astate, ti, count, &pflags) == 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-07-26 13:37:25 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/*
|
2014-08-11 20:00:51 +00:00
|
|
|
* Other thread has already performed resize.
|
|
|
|
* Flush our state and return.
|
2014-08-02 17:18:47 +00:00
|
|
|
*/
|
|
|
|
ta->flush_mod(ta_buf);
|
|
|
|
break;
|
|
|
|
}
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
error = ta->fill_mod(tc->astate, ti, ta_buf, &pflags);
|
|
|
|
if (error == 0) {
|
|
|
|
/* Do actual modification */
|
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
ta->modify(tc->astate, ti, ta_buf, pflags);
|
|
|
|
IPFW_WUNLOCK(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Anyway, flush data and retry */
|
|
|
|
ta->flush_mod(ta_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
tc->no.refcnt--;
|
2014-07-26 13:37:25 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
/*
|
2014-07-03 22:25:59 +00:00
|
|
|
* Adds or deletes record in table.
|
|
|
|
* Data layout (v0):
|
|
|
|
* Request: [ ip_fw3_opheader ipfw_table_xentry ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
2014-06-12 09:59:11 +00:00
|
|
|
*/
|
2014-07-03 22:25:59 +00:00
|
|
|
static int
|
2014-09-05 11:11:15 +00:00
|
|
|
manage_table_ent_v0(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-07-03 22:25:59 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
ipfw_table_xentry *xent;
|
|
|
|
struct tentry_info tei;
|
|
|
|
struct tid_info ti;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct table_value v;
|
2014-07-03 22:25:59 +00:00
|
|
|
int error, hdrlen, read;
|
|
|
|
|
|
|
|
hdrlen = offsetof(ipfw_table_xentry, k);
|
|
|
|
|
|
|
|
/* Check minimum header size */
|
|
|
|
if (sd->valsize < (sizeof(*op3) + hdrlen))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
read = sizeof(ip_fw3_opheader);
|
|
|
|
|
|
|
|
/* Check if xentry len field is valid */
|
|
|
|
xent = (ipfw_table_xentry *)(op3 + 1);
|
|
|
|
if (xent->len < hdrlen || xent->len + read > sd->valsize)
|
|
|
|
return (EINVAL);
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
memset(&tei, 0, sizeof(tei));
|
|
|
|
tei.paddr = &xent->k;
|
|
|
|
tei.masklen = xent->masklen;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
ipfw_import_table_value_legacy(xent->value, &v);
|
|
|
|
tei.pvalue = &v;
|
2016-05-03 18:05:43 +00:00
|
|
|
/* Old requests compatibility */
|
2014-07-26 13:37:25 +00:00
|
|
|
tei.flags = TEI_FLAGS_COMPAT;
|
2014-08-14 21:43:20 +00:00
|
|
|
if (xent->type == IPFW_TABLE_ADDR) {
|
2014-07-03 22:25:59 +00:00
|
|
|
if (xent->len - hdrlen == sizeof(in_addr_t))
|
|
|
|
tei.subtype = AF_INET;
|
|
|
|
else
|
|
|
|
tei.subtype = AF_INET6;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&ti, 0, sizeof(ti));
|
|
|
|
ti.uidx = xent->tbl;
|
|
|
|
ti.type = xent->type;
|
|
|
|
|
|
|
|
error = (op3->opcode == IP_FW_TABLE_XADD) ?
|
2014-08-11 17:34:25 +00:00
|
|
|
add_table_entry(ch, &ti, &tei, 0, 1) :
|
|
|
|
del_table_entry(ch, &ti, &tei, 0, 1);
|
2014-07-03 22:25:59 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adds or deletes record in table.
|
|
|
|
* Data layout (v1)(current):
|
2014-07-26 13:37:25 +00:00
|
|
|
* Request: [ ipfw_obj_header
|
|
|
|
* ipfw_obj_ctlv(IPFW_TLV_TBLENT_LIST) [ ipfw_obj_tentry x N ]
|
|
|
|
* ]
|
2014-07-03 22:25:59 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
|
|
|
static int
|
2014-09-05 11:11:15 +00:00
|
|
|
manage_table_ent_v1(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-07-03 22:25:59 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
2014-08-11 17:34:25 +00:00
|
|
|
ipfw_obj_tentry *tent, *ptent;
|
2014-07-26 13:37:25 +00:00
|
|
|
ipfw_obj_ctlv *ctlv;
|
2014-07-03 22:25:59 +00:00
|
|
|
ipfw_obj_header *oh;
|
2014-08-11 17:34:25 +00:00
|
|
|
struct tentry_info *ptei, tei, *tei_buf;
|
2014-07-03 22:25:59 +00:00
|
|
|
struct tid_info ti;
|
2014-08-11 17:34:25 +00:00
|
|
|
int error, i, kidx, read;
|
2014-07-03 22:25:59 +00:00
|
|
|
|
|
|
|
/* Check minimum header size */
|
2014-07-26 13:37:25 +00:00
|
|
|
if (sd->valsize < (sizeof(*oh) + sizeof(*ctlv)))
|
2014-07-03 22:25:59 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Check if passed data is too long */
|
|
|
|
if (sd->valsize != sd->kavail)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
oh = (ipfw_obj_header *)sd->kbuf;
|
|
|
|
|
|
|
|
/* Basic length checks for TLVs */
|
|
|
|
if (oh->ntlv.head.length != sizeof(oh->ntlv))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
read = sizeof(*oh);
|
|
|
|
|
2014-07-26 13:37:25 +00:00
|
|
|
ctlv = (ipfw_obj_ctlv *)(oh + 1);
|
|
|
|
if (ctlv->head.length + read != sd->valsize)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
read += sizeof(*ctlv);
|
|
|
|
tent = (ipfw_obj_tentry *)(ctlv + 1);
|
2014-08-11 17:34:25 +00:00
|
|
|
if (ctlv->count * sizeof(*tent) + read != sd->valsize)
|
2014-07-03 22:25:59 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
if (ctlv->count == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark entire buffer as "read".
|
2014-08-11 20:00:51 +00:00
|
|
|
* This instructs sopt api write it back
|
2014-08-11 17:34:25 +00:00
|
|
|
* after function return.
|
|
|
|
*/
|
|
|
|
ipfw_get_sopt_header(sd, sd->valsize);
|
|
|
|
|
|
|
|
/* Perform basic checks for each entry */
|
|
|
|
ptent = tent;
|
|
|
|
kidx = tent->idx;
|
|
|
|
for (i = 0; i < ctlv->count; i++, ptent++) {
|
|
|
|
if (ptent->head.length != sizeof(*ptent))
|
|
|
|
return (EINVAL);
|
|
|
|
if (ptent->idx != kidx)
|
|
|
|
return (ENOTSUP);
|
|
|
|
}
|
2014-07-03 22:25:59 +00:00
|
|
|
|
2014-08-11 17:34:25 +00:00
|
|
|
/* Convert data into kernel request objects */
|
2014-07-06 18:16:04 +00:00
|
|
|
objheader_to_ti(oh, &ti);
|
2014-07-03 22:25:59 +00:00
|
|
|
ti.type = oh->ntlv.type;
|
2014-08-11 17:34:25 +00:00
|
|
|
ti.uidx = kidx;
|
|
|
|
|
|
|
|
/* Use on-stack buffer for single add/del */
|
|
|
|
if (ctlv->count == 1) {
|
|
|
|
memset(&tei, 0, sizeof(tei));
|
|
|
|
tei_buf = &tei;
|
|
|
|
} else
|
|
|
|
tei_buf = malloc(ctlv->count * sizeof(tei), M_TEMP,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
ptei = tei_buf;
|
|
|
|
ptent = tent;
|
|
|
|
for (i = 0; i < ctlv->count; i++, ptent++, ptei++) {
|
|
|
|
ptei->paddr = &ptent->k;
|
|
|
|
ptei->subtype = ptent->subtype;
|
|
|
|
ptei->masklen = ptent->masklen;
|
|
|
|
if (ptent->head.flags & IPFW_TF_UPDATE)
|
|
|
|
ptei->flags |= TEI_FLAGS_UPDATE;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
|
|
|
|
ipfw_import_table_value_v1(&ptent->v.value);
|
|
|
|
ptei->pvalue = (struct table_value *)&ptent->v.value;
|
2014-08-11 17:34:25 +00:00
|
|
|
}
|
2014-07-03 22:25:59 +00:00
|
|
|
|
|
|
|
error = (oh->opheader.opcode == IP_FW_TABLE_XADD) ?
|
2014-08-11 17:34:25 +00:00
|
|
|
add_table_entry(ch, &ti, tei_buf, ctlv->flags, ctlv->count) :
|
|
|
|
del_table_entry(ch, &ti, tei_buf, ctlv->flags, ctlv->count);
|
|
|
|
|
|
|
|
/* Translate result back to userland */
|
|
|
|
ptei = tei_buf;
|
|
|
|
ptent = tent;
|
|
|
|
for (i = 0; i < ctlv->count; i++, ptent++, ptei++) {
|
|
|
|
if (ptei->flags & TEI_FLAGS_ADDED)
|
|
|
|
ptent->result = IPFW_TR_ADDED;
|
|
|
|
else if (ptei->flags & TEI_FLAGS_DELETED)
|
|
|
|
ptent->result = IPFW_TR_DELETED;
|
|
|
|
else if (ptei->flags & TEI_FLAGS_UPDATED)
|
|
|
|
ptent->result = IPFW_TR_UPDATED;
|
|
|
|
else if (ptei->flags & TEI_FLAGS_LIMIT)
|
|
|
|
ptent->result = IPFW_TR_LIMIT;
|
|
|
|
else if (ptei->flags & TEI_FLAGS_ERROR)
|
|
|
|
ptent->result = IPFW_TR_ERROR;
|
|
|
|
else if (ptei->flags & TEI_FLAGS_NOTFOUND)
|
|
|
|
ptent->result = IPFW_TR_NOTFOUND;
|
|
|
|
else if (ptei->flags & TEI_FLAGS_EXISTS)
|
|
|
|
ptent->result = IPFW_TR_EXISTS;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
ipfw_export_table_value_v1(ptei->pvalue, &ptent->v.value);
|
2014-08-11 17:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tei_buf != &tei)
|
|
|
|
free(tei_buf, M_TEMP);
|
2014-07-03 22:25:59 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-07-06 18:16:04 +00:00
|
|
|
/*
|
|
|
|
* Looks up an entry in given table.
|
|
|
|
* Data layout (v0)(current):
|
|
|
|
* Request: [ ipfw_obj_header ipfw_obj_tentry ]
|
|
|
|
* Reply: [ ipfw_obj_header ipfw_obj_tentry ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
find_table_entry(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-07-06 18:16:04 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
ipfw_obj_tentry *tent;
|
|
|
|
ipfw_obj_header *oh;
|
|
|
|
struct tid_info ti;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct table_info *kti;
|
2016-10-19 11:51:17 +00:00
|
|
|
struct table_value *pval;
|
2014-07-06 18:16:04 +00:00
|
|
|
struct namedobj_instance *ni;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
int error;
|
2014-07-06 18:16:04 +00:00
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
/* Check minimum header size */
|
|
|
|
sz = sizeof(*oh) + sizeof(*tent);
|
|
|
|
if (sd->valsize != sz)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
oh = (struct _ipfw_obj_header *)ipfw_get_sopt_header(sd, sz);
|
|
|
|
tent = (ipfw_obj_tentry *)(oh + 1);
|
|
|
|
|
|
|
|
/* Basic length checks for TLVs */
|
|
|
|
if (oh->ntlv.head.length != sizeof(oh->ntlv))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
objheader_to_ti(oh, &ti);
|
|
|
|
ti.type = oh->ntlv.type;
|
|
|
|
ti.uidx = tent->idx;
|
|
|
|
|
|
|
|
IPFW_UH_RLOCK(ch);
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find existing table and check its type .
|
|
|
|
*/
|
|
|
|
ta = NULL;
|
|
|
|
if ((tc = find_table(ni, &ti)) == NULL) {
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check table type */
|
2015-04-27 08:29:39 +00:00
|
|
|
if (tc->no.subtype != ti.type) {
|
2014-07-06 18:16:04 +00:00
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
kti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
ta = tc->ta;
|
|
|
|
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
if (ta->find_tentry == NULL)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
error = ta->find_tentry(tc->astate, kti, tent);
|
2016-10-19 11:51:17 +00:00
|
|
|
if (error == 0) {
|
|
|
|
pval = get_table_value(ch, tc, tent->v.kidx);
|
|
|
|
ipfw_export_table_value_v1(pval, &tent->v.value);
|
|
|
|
}
|
2014-07-06 18:16:04 +00:00
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-08-03 21:37:12 +00:00
|
|
|
/*
|
|
|
|
* Flushes all entries or destroys given table.
|
|
|
|
* Data layout (v0)(current):
|
|
|
|
* Request: [ ipfw_obj_header ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
flush_table_v0(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-07-03 22:25:59 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct _ipfw_obj_header *oh;
|
|
|
|
struct tid_info ti;
|
|
|
|
|
|
|
|
if (sd->valsize != sizeof(*oh))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
oh = (struct _ipfw_obj_header *)op3;
|
|
|
|
objheader_to_ti(oh, &ti);
|
|
|
|
|
2014-07-04 07:02:11 +00:00
|
|
|
if (op3->opcode == IP_FW_TABLE_XDESTROY)
|
2014-07-03 22:25:59 +00:00
|
|
|
error = destroy_table(ch, &ti);
|
2014-07-04 07:02:11 +00:00
|
|
|
else if (op3->opcode == IP_FW_TABLE_XFLUSH)
|
2014-07-03 22:25:59 +00:00
|
|
|
error = flush_table(ch, &ti);
|
|
|
|
else
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-09-02 20:46:18 +00:00
|
|
|
static void
|
|
|
|
restart_flush(void *object, struct op_state *_state)
|
|
|
|
{
|
|
|
|
struct tableop_state *ts;
|
|
|
|
|
|
|
|
ts = (struct tableop_state *)_state;
|
|
|
|
|
|
|
|
if (ts->tc != object)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Indicate we've called */
|
|
|
|
ts->modified = 1;
|
|
|
|
}
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Flushes given table.
|
|
|
|
*
|
|
|
|
* Function create new table instance with the same
|
|
|
|
* parameters, swaps it with old one and
|
2014-09-02 20:46:18 +00:00
|
|
|
* flushes state without holding runtime WLOCK.
|
2014-08-11 20:00:51 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2014-07-04 07:02:11 +00:00
|
|
|
int
|
2014-07-03 22:25:59 +00:00
|
|
|
flush_table(struct ip_fw_chain *ch, struct tid_info *ti)
|
2009-12-15 21:24:12 +00:00
|
|
|
{
|
2014-06-12 09:59:11 +00:00
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct table_config *tc;
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_algo *ta;
|
|
|
|
struct table_info ti_old, ti_new, *tablestate;
|
|
|
|
void *astate_old, *astate_new;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
char algostate[64], *pstate;
|
2014-09-02 20:46:18 +00:00
|
|
|
struct tableop_state ts;
|
2015-02-05 13:49:04 +00:00
|
|
|
int error, need_gc;
|
2014-06-12 09:59:11 +00:00
|
|
|
uint16_t kidx;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
uint8_t tflags;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2012-03-12 14:07:57 +00:00
|
|
|
/*
|
2016-05-03 18:05:43 +00:00
|
|
|
* Stage 1: save table algorithm.
|
2014-06-12 09:59:11 +00:00
|
|
|
* Reference found table to ensure it won't disappear.
|
2012-03-12 14:07:57 +00:00
|
|
|
*/
|
2014-06-12 09:59:11 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
if ((tc = find_table(ni, ti)) == NULL) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
2015-02-05 13:49:04 +00:00
|
|
|
need_gc = 0;
|
|
|
|
astate_new = NULL;
|
|
|
|
memset(&ti_new, 0, sizeof(ti_new));
|
2014-09-02 20:46:18 +00:00
|
|
|
restart:
|
|
|
|
/* Set up swap handler */
|
|
|
|
memset(&ts, 0, sizeof(ts));
|
|
|
|
ts.opstate.func = restart_flush;
|
|
|
|
ts.tc = tc;
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
ta = tc->ta;
|
2014-08-14 17:31:04 +00:00
|
|
|
/* Do not flush readonly tables */
|
|
|
|
if ((ta->flags & TA_FLAG_READONLY) != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EACCES);
|
|
|
|
}
|
2014-08-11 20:00:51 +00:00
|
|
|
/* Save startup algo parameters */
|
2014-07-30 09:17:40 +00:00
|
|
|
if (ta->print_config != NULL) {
|
|
|
|
ta->print_config(tc->astate, KIDX_TO_TI(ch, tc->no.kidx),
|
|
|
|
algostate, sizeof(algostate));
|
|
|
|
pstate = algostate;
|
|
|
|
} else
|
|
|
|
pstate = NULL;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
tflags = tc->tflags;
|
2014-09-02 20:46:18 +00:00
|
|
|
tc->no.refcnt++;
|
|
|
|
add_toperation_state(ch, &ts);
|
2014-06-12 09:59:11 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
|
2015-02-05 13:49:04 +00:00
|
|
|
/*
|
|
|
|
* Stage 1.5: if this is not the first attempt, destroy previous state
|
|
|
|
*/
|
|
|
|
if (need_gc != 0) {
|
|
|
|
ta->destroy(astate_new, &ti_new);
|
|
|
|
need_gc = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
/*
|
2014-06-14 10:58:39 +00:00
|
|
|
* Stage 2: allocate new table instance using same algo.
|
2014-06-12 09:59:11 +00:00
|
|
|
*/
|
2014-06-14 10:58:39 +00:00
|
|
|
memset(&ti_new, 0, sizeof(struct table_info));
|
2014-09-02 20:46:18 +00:00
|
|
|
error = ta->init(ch, &astate_new, &ti_new, pstate, tflags);
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
/*
|
|
|
|
* Stage 3: swap old state pointers with newly-allocated ones.
|
|
|
|
* Decrease refcount.
|
|
|
|
*/
|
|
|
|
IPFW_UH_WLOCK(ch);
|
2014-09-02 20:46:18 +00:00
|
|
|
tc->no.refcnt--;
|
|
|
|
del_toperation_state(ch, &ts);
|
|
|
|
|
|
|
|
if (error != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restart operation if table swap has happened:
|
|
|
|
* even if algo may be the same, algo init parameters
|
|
|
|
* may change. Restart operation instead of doing
|
|
|
|
* complex checks.
|
|
|
|
*/
|
|
|
|
if (ts.modified != 0) {
|
2015-02-05 13:49:04 +00:00
|
|
|
/* Delay destroying data since we're holding UH lock */
|
|
|
|
need_gc = 1;
|
2014-09-02 20:46:18 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
2014-06-12 09:59:11 +00:00
|
|
|
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
kidx = tc->no.kidx;
|
2014-06-14 10:58:39 +00:00
|
|
|
tablestate = (struct table_info *)ch->tablestate;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
ti_old = tablestate[kidx];
|
|
|
|
tablestate[kidx] = ti_new;
|
|
|
|
IPFW_WUNLOCK(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
astate_old = tc->astate;
|
|
|
|
tc->astate = astate_new;
|
2014-10-09 14:33:20 +00:00
|
|
|
tc->ti_copy = ti_new;
|
2014-06-14 10:58:39 +00:00
|
|
|
tc->count = 0;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-10-07 16:46:11 +00:00
|
|
|
/* Notify algo on real @ti address */
|
|
|
|
if (ta->change_ti != NULL)
|
|
|
|
ta->change_ti(tc->astate, &tablestate[kidx]);
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
/*
|
|
|
|
* Stage 4: unref values.
|
|
|
|
*/
|
|
|
|
ipfw_unref_table_values(ch, tc, ta, astate_old, &ti_old);
|
2014-06-12 09:59:11 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
/*
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
* Stage 5: perform real flush/destroy.
|
2014-06-12 09:59:11 +00:00
|
|
|
*/
|
2014-06-14 10:58:39 +00:00
|
|
|
ta->destroy(astate_old, &ti_old);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-08-03 21:37:12 +00:00
|
|
|
/*
|
|
|
|
* Swaps two tables.
|
|
|
|
* Data layout (v0)(current):
|
|
|
|
* Request: [ ipfw_obj_header ipfw_obj_ntlv ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
swap_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-08-03 21:37:12 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct _ipfw_obj_header *oh;
|
|
|
|
struct tid_info ti_a, ti_b;
|
|
|
|
|
|
|
|
if (sd->valsize != sizeof(*oh) + sizeof(ipfw_obj_ntlv))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
oh = (struct _ipfw_obj_header *)op3;
|
|
|
|
ntlv_to_ti(&oh->ntlv, &ti_a);
|
|
|
|
ntlv_to_ti((ipfw_obj_ntlv *)(oh + 1), &ti_b);
|
|
|
|
|
2014-08-07 21:37:31 +00:00
|
|
|
error = swap_tables(ch, &ti_a, &ti_b);
|
2014-08-03 21:37:12 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Swaps two tables of the same type/valtype.
|
|
|
|
*
|
|
|
|
* Checks if tables are compatible and limits
|
2014-08-12 17:03:13 +00:00
|
|
|
* permits swap, than actually perform swap.
|
|
|
|
*
|
|
|
|
* Each table consists of 2 different parts:
|
|
|
|
* config:
|
|
|
|
* @tc (with name, set, kidx) and rule bindings, which is "stable".
|
|
|
|
* number of items
|
|
|
|
* table algo
|
|
|
|
* runtime:
|
|
|
|
* runtime data @ti (ch->tablestate)
|
|
|
|
* runtime cache in @tc
|
|
|
|
* algo-specific data (@tc->astate)
|
|
|
|
*
|
|
|
|
* So we switch:
|
|
|
|
* all runtime data
|
|
|
|
* number of items
|
|
|
|
* table algo
|
2014-08-11 20:00:51 +00:00
|
|
|
*
|
2014-08-12 17:03:13 +00:00
|
|
|
* After that we call @ti change handler for each table.
|
|
|
|
*
|
|
|
|
* Note that referencing @tc won't protect tc->ta from change.
|
|
|
|
* XXX: Do we need to restrict swap between locked tables?
|
|
|
|
* XXX: Do we need to exchange ftype?
|
2014-08-11 20:00:51 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2014-08-03 21:37:12 +00:00
|
|
|
static int
|
2014-08-07 21:37:31 +00:00
|
|
|
swap_tables(struct ip_fw_chain *ch, struct tid_info *a,
|
2014-08-03 21:37:12 +00:00
|
|
|
struct tid_info *b)
|
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct table_config *tc_a, *tc_b;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct table_info ti, *tablestate;
|
|
|
|
void *astate;
|
|
|
|
uint32_t count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stage 1: find both tables and ensure they are of
|
2014-08-11 20:00:51 +00:00
|
|
|
* the same type.
|
2014-08-03 21:37:12 +00:00
|
|
|
*/
|
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
if ((tc_a = find_table(ni, a)) == NULL) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
|
|
|
if ((tc_b = find_table(ni, b)) == NULL) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It is very easy to swap between the same table */
|
|
|
|
if (tc_a == tc_b) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check type and value are the same */
|
2015-04-27 08:29:39 +00:00
|
|
|
if (tc_a->no.subtype!=tc_b->no.subtype || tc_a->tflags!=tc_b->tflags) {
|
2014-08-03 21:37:12 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check limits before swap */
|
|
|
|
if ((tc_a->limit != 0 && tc_b->count > tc_a->limit) ||
|
|
|
|
(tc_b->limit != 0 && tc_a->count > tc_b->limit)) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EFBIG);
|
|
|
|
}
|
|
|
|
|
2014-08-14 17:31:04 +00:00
|
|
|
/* Check if one of the tables is readonly */
|
|
|
|
if (((tc_a->ta->flags | tc_b->ta->flags) & TA_FLAG_READONLY) != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EACCES);
|
|
|
|
}
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
/* Notify we're going to swap */
|
|
|
|
rollback_toperation_state(ch, tc_a);
|
|
|
|
rollback_toperation_state(ch, tc_b);
|
|
|
|
|
2014-08-03 21:37:12 +00:00
|
|
|
/* Everything is fine, prepare to swap */
|
|
|
|
tablestate = (struct table_info *)ch->tablestate;
|
|
|
|
ti = tablestate[tc_a->no.kidx];
|
|
|
|
ta = tc_a->ta;
|
|
|
|
astate = tc_a->astate;
|
|
|
|
count = tc_a->count;
|
|
|
|
|
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
/* a <- b */
|
|
|
|
tablestate[tc_a->no.kidx] = tablestate[tc_b->no.kidx];
|
|
|
|
tc_a->ta = tc_b->ta;
|
|
|
|
tc_a->astate = tc_b->astate;
|
|
|
|
tc_a->count = tc_b->count;
|
|
|
|
/* b <- a */
|
|
|
|
tablestate[tc_b->no.kidx] = ti;
|
|
|
|
tc_b->ta = ta;
|
|
|
|
tc_b->astate = astate;
|
|
|
|
tc_b->count = count;
|
|
|
|
IPFW_WUNLOCK(ch);
|
|
|
|
|
|
|
|
/* Ensure tc.ti copies are in sync */
|
2014-10-09 14:33:20 +00:00
|
|
|
tc_a->ti_copy = tablestate[tc_a->no.kidx];
|
|
|
|
tc_b->ti_copy = tablestate[tc_b->no.kidx];
|
2014-08-03 21:37:12 +00:00
|
|
|
|
|
|
|
/* Notify both tables on @ti change */
|
|
|
|
if (tc_a->ta->change_ti != NULL)
|
|
|
|
tc_a->ta->change_ti(tc_a->astate, &tablestate[tc_a->no.kidx]);
|
|
|
|
if (tc_b->ta->change_ti != NULL)
|
|
|
|
tc_b->ta->change_ti(tc_b->astate, &tablestate[tc_b->no.kidx]);
|
|
|
|
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
/*
|
2014-06-14 10:58:39 +00:00
|
|
|
* Destroys table specified by @ti.
|
2014-07-03 22:25:59 +00:00
|
|
|
* Data layout (v0)(current):
|
|
|
|
* Request: [ ip_fw3_opheader ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
2014-06-12 09:59:11 +00:00
|
|
|
*/
|
2014-07-03 22:25:59 +00:00
|
|
|
static int
|
|
|
|
destroy_table(struct ip_fw_chain *ch, struct tid_info *ti)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct table_config *tc;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
if ((tc = find_table(ni, ti)) == NULL) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
2012-03-12 14:07:57 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/* Do not permit destroying referenced tables */
|
|
|
|
if (tc->no.refcnt > 0) {
|
2014-06-12 09:59:11 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EBUSY);
|
2012-03-12 14:07:57 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
unlink_table(ch, tc);
|
|
|
|
IPFW_WUNLOCK(ch);
|
|
|
|
|
|
|
|
/* Free obj index */
|
2014-07-03 22:25:59 +00:00
|
|
|
if (ipfw_objhash_free_idx(ni, tc->no.kidx) != 0)
|
2014-06-12 09:59:11 +00:00
|
|
|
printf("Error unlinking kidx %d from table %s\n",
|
|
|
|
tc->no.kidx, tc->tablename);
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
/* Unref values used in tables while holding UH lock */
|
2014-10-09 14:33:20 +00:00
|
|
|
ipfw_unref_table_values(ch, tc, tc->ta, tc->astate, &tc->ti_copy);
|
2014-06-12 09:59:11 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
|
|
|
|
free_table_config(ni, tc);
|
|
|
|
|
2009-12-15 21:24:12 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-10-19 11:15:19 +00:00
|
|
|
static uint32_t
|
|
|
|
roundup2p(uint32_t v)
|
|
|
|
{
|
|
|
|
|
|
|
|
v--;
|
|
|
|
v |= v >> 1;
|
|
|
|
v |= v >> 2;
|
|
|
|
v |= v >> 4;
|
|
|
|
v |= v >> 8;
|
|
|
|
v |= v >> 16;
|
|
|
|
v++;
|
|
|
|
|
|
|
|
return (v);
|
|
|
|
}
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Grow tables index.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2012-03-25 20:37:59 +00:00
|
|
|
int
|
|
|
|
ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables)
|
|
|
|
{
|
|
|
|
unsigned int ntables_old, tbl;
|
2014-06-12 09:59:11 +00:00
|
|
|
struct namedobj_instance *ni;
|
2014-06-14 10:58:39 +00:00
|
|
|
void *new_idx, *old_tablestate, *tablestate;
|
2014-07-28 19:01:25 +00:00
|
|
|
struct table_info *ti;
|
|
|
|
struct table_config *tc;
|
|
|
|
int i, new_blocks;
|
2012-03-25 20:37:59 +00:00
|
|
|
|
|
|
|
/* Check new value for validity */
|
2014-10-19 11:15:19 +00:00
|
|
|
if (ntables == 0)
|
|
|
|
return (EINVAL);
|
2012-03-25 20:37:59 +00:00
|
|
|
if (ntables > IPFW_TABLES_MAX)
|
|
|
|
ntables = IPFW_TABLES_MAX;
|
2014-10-19 11:15:19 +00:00
|
|
|
/* Alight to nearest power of 2 */
|
|
|
|
ntables = (unsigned int)roundup2p(ntables);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
|
|
|
/* Allocate new pointers */
|
2014-06-14 10:58:39 +00:00
|
|
|
tablestate = malloc(ntables * sizeof(struct table_info),
|
|
|
|
M_IPFW, M_WAITOK | M_ZERO);
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
ipfw_objhash_bitmap_alloc(ntables, (void *)&new_idx, &new_blocks);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
|
|
|
tbl = (ntables >= V_fw_tables_max) ? V_fw_tables_max : ntables;
|
2014-06-12 09:59:11 +00:00
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/* Temporary restrict decreasing max_tables */
|
|
|
|
if (ntables < V_fw_tables_max) {
|
|
|
|
/*
|
|
|
|
* FIXME: Check if we really can shrink
|
|
|
|
*/
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2012-03-25 20:37:59 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/* Copy table info/indices */
|
|
|
|
memcpy(tablestate, ch->tablestate, sizeof(struct table_info) * tbl);
|
|
|
|
ipfw_objhash_bitmap_merge(ni, &new_idx, &new_blocks);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
|
|
|
|
/* Change pointers */
|
|
|
|
old_tablestate = ch->tablestate;
|
|
|
|
ch->tablestate = tablestate;
|
|
|
|
ipfw_objhash_bitmap_swap(ni, &new_idx, &new_blocks);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
|
|
|
ntables_old = V_fw_tables_max;
|
|
|
|
V_fw_tables_max = ntables;
|
|
|
|
|
|
|
|
IPFW_WUNLOCK(ch);
|
2014-07-28 19:01:25 +00:00
|
|
|
|
|
|
|
/* Notify all consumers that their @ti pointer has changed */
|
|
|
|
ti = (struct table_info *)ch->tablestate;
|
|
|
|
for (i = 0; i < tbl; i++, ti++) {
|
|
|
|
if (ti->lookup == NULL)
|
|
|
|
continue;
|
|
|
|
tc = (struct table_config *)ipfw_objhash_lookup_kidx(ni, i);
|
|
|
|
if (tc == NULL || tc->ta->change_ti == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tc->ta->change_ti(tc->astate, ti);
|
|
|
|
}
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
|
|
|
/* Free old pointers */
|
2014-06-14 10:58:39 +00:00
|
|
|
free(old_tablestate, M_IPFW);
|
2014-06-12 09:59:11 +00:00
|
|
|
ipfw_objhash_bitmap_free(new_idx, new_blocks);
|
2012-03-25 20:37:59 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-08-13 15:48:56 +00:00
|
|
|
/*
|
|
|
|
* Lookup table's named object by its @kidx.
|
|
|
|
*/
|
|
|
|
struct named_object *
|
|
|
|
ipfw_objhash_lookup_table_kidx(struct ip_fw_chain *ch, uint16_t kidx)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ipfw_objhash_lookup_kidx(CHAIN_TO_NI(ch), kidx));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take reference to table specified in @ntlv.
|
|
|
|
* On success return its @kidx.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipfw_ref_table(struct ip_fw_chain *ch, ipfw_obj_ntlv *ntlv, uint16_t *kidx)
|
|
|
|
{
|
|
|
|
struct tid_info ti;
|
|
|
|
struct table_config *tc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
|
|
|
|
ntlv_to_ti(ntlv, &ti);
|
|
|
|
error = find_table_err(CHAIN_TO_NI(ch), &ti, &tc);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (tc == NULL)
|
|
|
|
return (ESRCH);
|
|
|
|
|
|
|
|
tc_ref(tc);
|
|
|
|
*kidx = tc->no.kidx;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ipfw_unref_table(struct ip_fw_chain *ch, uint16_t kidx)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct named_object *no;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
no = ipfw_objhash_lookup_kidx(ni, kidx);
|
|
|
|
KASSERT(no != NULL, ("Table with index %d not found", kidx));
|
|
|
|
no->refcnt--;
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:03:13 +00:00
|
|
|
/*
|
2017-07-21 03:04:55 +00:00
|
|
|
* Lookup an arbitrary key @paddr of length @plen in table @tbl.
|
2014-08-12 17:03:13 +00:00
|
|
|
* Stores found value in @val.
|
|
|
|
*
|
|
|
|
* Returns 1 if key was found.
|
|
|
|
*/
|
2012-03-12 14:07:57 +00:00
|
|
|
int
|
2017-03-05 23:48:24 +00:00
|
|
|
ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, uint16_t plen,
|
2014-06-14 10:58:39 +00:00
|
|
|
void *paddr, uint32_t *val)
|
2012-03-12 14:07:57 +00:00
|
|
|
{
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_info *ti;
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-08-12 17:03:13 +00:00
|
|
|
ti = KIDX_TO_TI(ch, tbl);
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
return (ti->lookup(ti, paddr, plen, val));
|
|
|
|
}
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/*
|
|
|
|
* Info/List/dump support for tables.
|
|
|
|
*
|
|
|
|
*/
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-06-14 22:47:25 +00:00
|
|
|
/*
|
2014-06-15 13:40:27 +00:00
|
|
|
* High-level 'get' cmds sysctl handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lists all tables currently available in kernel.
|
2014-07-03 22:25:59 +00:00
|
|
|
* Data layout (v0)(current):
|
2014-06-15 13:40:27 +00:00
|
|
|
* Request: [ ipfw_obj_lheader ], size = ipfw_obj_lheader.size
|
|
|
|
* Reply: [ ipfw_obj_lheader ipfw_xtable_info x N ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
list_tables(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-09-03 21:57:06 +00:00
|
|
|
struct sockopt_data *sd)
|
2014-06-14 22:47:25 +00:00
|
|
|
{
|
|
|
|
struct _ipfw_obj_lheader *olh;
|
|
|
|
int error;
|
|
|
|
|
2014-06-27 10:07:00 +00:00
|
|
|
olh = (struct _ipfw_obj_lheader *)ipfw_get_sopt_header(sd,sizeof(*olh));
|
|
|
|
if (olh == NULL)
|
2014-06-15 13:40:27 +00:00
|
|
|
return (EINVAL);
|
2014-07-28 19:01:25 +00:00
|
|
|
if (sd->valsize < olh->size)
|
|
|
|
return (EINVAL);
|
2014-06-15 13:40:27 +00:00
|
|
|
|
2014-06-14 22:47:25 +00:00
|
|
|
IPFW_UH_RLOCK(ch);
|
2014-06-27 10:07:00 +00:00
|
|
|
error = export_tables(ch, olh, sd);
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
2014-06-14 22:47:25 +00:00
|
|
|
|
2014-06-27 10:07:00 +00:00
|
|
|
return (error);
|
2014-06-14 22:47:25 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 13:40:27 +00:00
|
|
|
/*
|
2014-06-27 10:07:00 +00:00
|
|
|
* Store table info to buffer provided by @sd.
|
2014-07-03 22:25:59 +00:00
|
|
|
* Data layout (v0)(current):
|
2014-06-15 13:40:27 +00:00
|
|
|
* Request: [ ipfw_obj_header ipfw_xtable_info(empty)]
|
|
|
|
* Reply: [ ipfw_obj_header ipfw_xtable_info ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
describe_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-09-03 21:57:06 +00:00
|
|
|
struct sockopt_data *sd)
|
2014-06-15 13:40:27 +00:00
|
|
|
{
|
|
|
|
struct _ipfw_obj_header *oh;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct tid_info ti;
|
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
sz = sizeof(*oh) + sizeof(ipfw_xtable_info);
|
2014-06-27 10:07:00 +00:00
|
|
|
oh = (struct _ipfw_obj_header *)ipfw_get_sopt_header(sd, sz);
|
|
|
|
if (oh == NULL)
|
2014-06-15 13:40:27 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
objheader_to_ti(oh, &ti);
|
|
|
|
|
|
|
|
IPFW_UH_RLOCK(ch);
|
|
|
|
if ((tc = find_table(CHAIN_TO_NI(ch), &ti)) == NULL) {
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
export_table_info(ch, tc, (ipfw_xtable_info *)(oh + 1));
|
2014-06-15 13:40:27 +00:00
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
|
2014-06-27 10:07:00 +00:00
|
|
|
return (0);
|
2014-06-15 13:40:27 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 09:27:49 +00:00
|
|
|
/*
|
|
|
|
* Modifies existing table.
|
|
|
|
* Data layout (v0)(current):
|
|
|
|
* Request: [ ipfw_obj_header ipfw_xtable_info ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
modify_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-08-08 09:27:49 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
struct _ipfw_obj_header *oh;
|
|
|
|
ipfw_xtable_info *i;
|
|
|
|
char *tname;
|
|
|
|
struct tid_info ti;
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct table_config *tc;
|
|
|
|
|
|
|
|
if (sd->valsize != sizeof(*oh) + sizeof(ipfw_xtable_info))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
oh = (struct _ipfw_obj_header *)sd->kbuf;
|
|
|
|
i = (ipfw_xtable_info *)(oh + 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify user-supplied strings.
|
|
|
|
* Check for null-terminated/zero-length strings/
|
|
|
|
*/
|
|
|
|
tname = oh->ntlv.name;
|
2015-11-03 10:29:46 +00:00
|
|
|
if (check_table_name(tname) != 0)
|
2014-08-08 09:27:49 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
objheader_to_ti(oh, &ti);
|
|
|
|
ti.type = i->type;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
if ((tc = find_table(ni, &ti)) == NULL) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
2014-08-14 17:31:04 +00:00
|
|
|
|
|
|
|
/* Do not support any modifications for readonly tables */
|
|
|
|
if ((tc->ta->flags & TA_FLAG_READONLY) != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EACCES);
|
|
|
|
}
|
|
|
|
|
2014-08-08 09:27:49 +00:00
|
|
|
if ((i->mflags & IPFW_TMFLAGS_LIMIT) != 0)
|
|
|
|
tc->limit = i->limit;
|
2014-08-11 18:09:37 +00:00
|
|
|
if ((i->mflags & IPFW_TMFLAGS_LOCK) != 0)
|
|
|
|
tc->locked = ((i->flags & IPFW_TGFLAGS_LOCKED) != 0);
|
2014-08-08 09:27:49 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-06-16 13:05:07 +00:00
|
|
|
/*
|
|
|
|
* Creates new table.
|
2014-07-03 22:25:59 +00:00
|
|
|
* Data layout (v0)(current):
|
2014-06-16 13:05:07 +00:00
|
|
|
* Request: [ ipfw_obj_header ipfw_xtable_info ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
create_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-07-03 22:25:59 +00:00
|
|
|
struct sockopt_data *sd)
|
2014-06-16 13:05:07 +00:00
|
|
|
{
|
|
|
|
struct _ipfw_obj_header *oh;
|
|
|
|
ipfw_xtable_info *i;
|
|
|
|
char *tname, *aname;
|
|
|
|
struct tid_info ti;
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
if (sd->valsize != sizeof(*oh) + sizeof(ipfw_xtable_info))
|
2014-06-16 13:05:07 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
oh = (struct _ipfw_obj_header *)sd->kbuf;
|
2014-06-16 13:05:07 +00:00
|
|
|
i = (ipfw_xtable_info *)(oh + 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify user-supplied strings.
|
2014-06-27 10:07:00 +00:00
|
|
|
* Check for null-terminated/zero-length strings/
|
2014-06-16 13:05:07 +00:00
|
|
|
*/
|
2014-07-03 22:25:59 +00:00
|
|
|
tname = oh->ntlv.name;
|
2014-06-16 13:05:07 +00:00
|
|
|
aname = i->algoname;
|
2015-11-03 10:29:46 +00:00
|
|
|
if (check_table_name(tname) != 0 ||
|
2014-06-16 13:05:07 +00:00
|
|
|
strnlen(aname, sizeof(i->algoname)) == sizeof(i->algoname))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (aname[0] == '\0') {
|
|
|
|
/* Use default algorithm */
|
|
|
|
aname = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
objheader_to_ti(oh, &ti);
|
2014-07-03 22:25:59 +00:00
|
|
|
ti.type = i->type;
|
2014-06-16 13:05:07 +00:00
|
|
|
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
|
|
|
|
IPFW_UH_RLOCK(ch);
|
2014-11-04 10:25:52 +00:00
|
|
|
if (find_table(ni, &ti) != NULL) {
|
2014-06-16 13:05:07 +00:00
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (EEXIST);
|
|
|
|
}
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
|
2014-08-23 12:41:39 +00:00
|
|
|
return (create_table_internal(ch, &ti, aname, i, NULL, 0));
|
2014-07-26 13:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates new table based on @ti and @aname.
|
|
|
|
*
|
|
|
|
* Assume @aname to be checked and valid.
|
2014-08-23 12:41:39 +00:00
|
|
|
* Stores allocated table kidx inside @pkidx (if non-NULL).
|
2014-08-12 09:48:54 +00:00
|
|
|
* Reference created table if @compat is non-zero.
|
2014-07-26 13:37:25 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
create_table_internal(struct ip_fw_chain *ch, struct tid_info *ti,
|
2014-08-23 12:41:39 +00:00
|
|
|
char *aname, ipfw_xtable_info *i, uint16_t *pkidx, int compat)
|
2014-07-26 13:37:25 +00:00
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
2014-08-12 17:03:13 +00:00
|
|
|
struct table_config *tc, *tc_new, *tmp;
|
2014-07-26 13:37:25 +00:00
|
|
|
struct table_algo *ta;
|
|
|
|
uint16_t kidx;
|
|
|
|
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
|
|
|
|
ta = find_table_algo(CHAIN_TO_TCFG(ch), ti, aname);
|
2014-06-16 13:05:07 +00:00
|
|
|
if (ta == NULL)
|
|
|
|
return (ENOTSUP);
|
2014-08-01 15:17:46 +00:00
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
tc = alloc_table_config(ch, ti, ta, aname, i->tflags);
|
2014-08-01 15:17:46 +00:00
|
|
|
if (tc == NULL)
|
2014-06-16 13:05:07 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
tc->vmask = i->vmask;
|
2014-08-01 15:17:46 +00:00
|
|
|
tc->limit = i->limit;
|
2014-08-14 17:31:04 +00:00
|
|
|
if (ta->flags & TA_FLAG_READONLY)
|
|
|
|
tc->locked = 1;
|
|
|
|
else
|
|
|
|
tc->locked = (i->flags & IPFW_TGFLAGS_LOCKED) != 0;
|
2014-08-01 15:17:46 +00:00
|
|
|
|
2014-06-16 13:05:07 +00:00
|
|
|
IPFW_UH_WLOCK(ch);
|
2014-07-26 13:37:25 +00:00
|
|
|
|
|
|
|
/* Check if table has been already created */
|
2014-08-12 09:48:54 +00:00
|
|
|
tc_new = find_table(ni, ti);
|
|
|
|
if (tc_new != NULL) {
|
|
|
|
/*
|
|
|
|
* Compat: do not fail if we're
|
|
|
|
* requesting to create existing table
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
* which has the same type
|
2014-08-12 09:48:54 +00:00
|
|
|
*/
|
2015-04-27 08:29:39 +00:00
|
|
|
if (compat == 0 || tc_new->no.subtype != tc->no.subtype) {
|
2014-08-12 09:48:54 +00:00
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
free_table_config(ni, tc);
|
|
|
|
return (EEXIST);
|
|
|
|
}
|
2014-06-16 13:05:07 +00:00
|
|
|
|
2014-08-12 09:48:54 +00:00
|
|
|
/* Exchange tc and tc_new for proper refcounting & freeing */
|
|
|
|
tmp = tc;
|
|
|
|
tc = tc_new;
|
|
|
|
tc_new = tmp;
|
|
|
|
} else {
|
|
|
|
/* New table */
|
|
|
|
if (ipfw_objhash_alloc_idx(ni, &kidx) != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
printf("Unable to allocate table index."
|
|
|
|
" Consider increasing net.inet.ip.fw.tables_max");
|
|
|
|
free_table_config(ni, tc);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
tc->no.kidx = kidx;
|
2015-04-27 08:29:39 +00:00
|
|
|
tc->no.etlv = IPFW_TLV_TBL_NAME;
|
2014-06-16 13:05:07 +00:00
|
|
|
|
2014-08-12 09:48:54 +00:00
|
|
|
link_table(ch, tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compat != 0)
|
|
|
|
tc->no.refcnt++;
|
|
|
|
if (pkidx != NULL)
|
|
|
|
*pkidx = tc->no.kidx;
|
2014-06-16 13:05:07 +00:00
|
|
|
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
|
2014-08-12 09:48:54 +00:00
|
|
|
if (tc_new != NULL)
|
|
|
|
free_table_config(ni, tc_new);
|
|
|
|
|
2014-06-16 13:05:07 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-08-03 21:37:12 +00:00
|
|
|
static void
|
|
|
|
ntlv_to_ti(ipfw_obj_ntlv *ntlv, struct tid_info *ti)
|
2014-06-15 13:40:27 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
memset(ti, 0, sizeof(struct tid_info));
|
2014-08-03 21:37:12 +00:00
|
|
|
ti->set = ntlv->set;
|
|
|
|
ti->uidx = ntlv->idx;
|
|
|
|
ti->tlvs = ntlv;
|
|
|
|
ti->tlen = ntlv->head.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
objheader_to_ti(struct _ipfw_obj_header *oh, struct tid_info *ti)
|
|
|
|
{
|
|
|
|
|
|
|
|
ntlv_to_ti(&oh->ntlv, ti);
|
2014-06-15 13:40:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
struct namedobj_instance *
|
|
|
|
ipfw_get_table_objhash(struct ip_fw_chain *ch)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (CHAIN_TO_NI(ch));
|
|
|
|
}
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Exports basic table info as name TLV.
|
|
|
|
* Used inside dump_static_rules() to provide info
|
|
|
|
* about all tables referenced by current ruleset.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2014-06-28 23:20:24 +00:00
|
|
|
int
|
|
|
|
ipfw_export_table_ntlv(struct ip_fw_chain *ch, uint16_t kidx,
|
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct named_object *no;
|
|
|
|
ipfw_obj_ntlv *ntlv;
|
|
|
|
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
no = ipfw_objhash_lookup_kidx(ni, kidx);
|
2014-06-28 23:20:24 +00:00
|
|
|
KASSERT(no != NULL, ("invalid table kidx passed"));
|
|
|
|
|
|
|
|
ntlv = (ipfw_obj_ntlv *)ipfw_get_sopt_space(sd, sizeof(*ntlv));
|
|
|
|
if (ntlv == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
ntlv->head.type = IPFW_TLV_TBL_NAME;
|
|
|
|
ntlv->head.length = sizeof(*ntlv);
|
|
|
|
ntlv->idx = no->kidx;
|
|
|
|
strlcpy(ntlv->name, no->name, sizeof(ntlv->name));
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
struct dump_args {
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct ip_fw_chain *ch;
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
struct table_info *ti;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct sockopt_data *sd;
|
|
|
|
uint32_t cnt;
|
|
|
|
uint16_t uidx;
|
|
|
|
int error;
|
|
|
|
uint32_t size;
|
2014-08-23 11:27:49 +00:00
|
|
|
ipfw_table_entry *ent;
|
|
|
|
ta_foreach_f *f;
|
|
|
|
void *farg;
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
ipfw_obj_tentry tent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
count_ext_entries(void *e, void *arg)
|
|
|
|
{
|
|
|
|
struct dump_args *da;
|
|
|
|
|
|
|
|
da = (struct dump_args *)arg;
|
|
|
|
da->cnt++;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets number of items from table either using
|
|
|
|
* internal counter or calling algo callback for
|
|
|
|
* externally-managed tables.
|
|
|
|
*
|
|
|
|
* Returns number of records.
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
table_get_count(struct ip_fw_chain *ch, struct table_config *tc)
|
|
|
|
{
|
|
|
|
struct table_info *ti;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct dump_args da;
|
|
|
|
|
|
|
|
ti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
ta = tc->ta;
|
|
|
|
|
|
|
|
/* Use internal counter for self-managed tables */
|
|
|
|
if ((ta->flags & TA_FLAG_READONLY) == 0)
|
|
|
|
return (tc->count);
|
|
|
|
|
|
|
|
/* Use callback to quickly get number of items */
|
|
|
|
if ((ta->flags & TA_FLAG_EXTCOUNTER) != 0)
|
|
|
|
return (ta->get_count(tc->astate, ti));
|
|
|
|
|
|
|
|
/* Count number of iterms ourselves */
|
|
|
|
memset(&da, 0, sizeof(da));
|
|
|
|
ta->foreach(tc->astate, ti, count_ext_entries, &da);
|
|
|
|
|
|
|
|
return (da.cnt);
|
|
|
|
}
|
2014-08-12 10:22:46 +00:00
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Exports table @tc info into standard ipfw_xtable_info format.
|
|
|
|
*/
|
2014-06-14 10:58:39 +00:00
|
|
|
static void
|
2014-07-03 22:25:59 +00:00
|
|
|
export_table_info(struct ip_fw_chain *ch, struct table_config *tc,
|
|
|
|
ipfw_xtable_info *i)
|
2014-06-14 10:58:39 +00:00
|
|
|
{
|
2014-07-03 22:25:59 +00:00
|
|
|
struct table_info *ti;
|
2014-08-03 12:19:45 +00:00
|
|
|
struct table_algo *ta;
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
i->type = tc->no.subtype;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
i->tflags = tc->tflags;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
i->vmask = tc->vmask;
|
2014-06-14 10:58:39 +00:00
|
|
|
i->set = tc->no.set;
|
|
|
|
i->kidx = tc->no.kidx;
|
|
|
|
i->refcnt = tc->no.refcnt;
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
i->count = table_get_count(ch, tc);
|
2014-08-01 15:17:46 +00:00
|
|
|
i->limit = tc->limit;
|
2014-08-11 18:09:37 +00:00
|
|
|
i->flags |= (tc->locked != 0) ? IPFW_TGFLAGS_LOCKED : 0;
|
2016-01-10 00:28:44 +00:00
|
|
|
i->size = i->count * sizeof(ipfw_obj_tentry);
|
2014-06-14 22:47:25 +00:00
|
|
|
i->size += sizeof(ipfw_obj_header) + sizeof(ipfw_xtable_info);
|
2014-06-14 10:58:39 +00:00
|
|
|
strlcpy(i->tablename, tc->tablename, sizeof(i->tablename));
|
2014-08-03 12:19:45 +00:00
|
|
|
ti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
ta = tc->ta;
|
|
|
|
if (ta->print_config != NULL) {
|
2014-07-03 22:25:59 +00:00
|
|
|
/* Use algo function to print table config to string */
|
2014-08-03 12:19:45 +00:00
|
|
|
ta->print_config(tc->astate, ti, i->algoname,
|
2014-07-03 22:25:59 +00:00
|
|
|
sizeof(i->algoname));
|
|
|
|
} else
|
2014-08-03 12:19:45 +00:00
|
|
|
strlcpy(i->algoname, ta->name, sizeof(i->algoname));
|
|
|
|
/* Dump algo-specific data, if possible */
|
|
|
|
if (ta->dump_tinfo != NULL) {
|
|
|
|
ta->dump_tinfo(tc->astate, ti, &i->ta_info);
|
|
|
|
i->ta_info.flags |= IPFW_TATFLAGS_DATA;
|
|
|
|
}
|
2012-03-12 14:07:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
struct dump_table_args {
|
|
|
|
struct ip_fw_chain *ch;
|
|
|
|
struct sockopt_data *sd;
|
|
|
|
};
|
|
|
|
|
2016-05-06 03:18:51 +00:00
|
|
|
static int
|
2014-06-14 10:58:39 +00:00
|
|
|
export_table_internal(struct namedobj_instance *ni, struct named_object *no,
|
|
|
|
void *arg)
|
2009-12-15 21:24:12 +00:00
|
|
|
{
|
2014-06-14 10:58:39 +00:00
|
|
|
ipfw_xtable_info *i;
|
2014-07-03 22:25:59 +00:00
|
|
|
struct dump_table_args *dta;
|
2009-12-15 21:24:12 +00:00
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
dta = (struct dump_table_args *)arg;
|
|
|
|
|
|
|
|
i = (ipfw_xtable_info *)ipfw_get_sopt_space(dta->sd, sizeof(*i));
|
2016-04-15 12:24:01 +00:00
|
|
|
KASSERT(i != NULL, ("previously checked buffer is not enough"));
|
2014-06-14 10:58:39 +00:00
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
export_table_info(dta->ch, (struct table_config *)no, i);
|
2016-05-06 03:18:51 +00:00
|
|
|
return (0);
|
2009-12-15 21:24:12 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 22:47:25 +00:00
|
|
|
/*
|
|
|
|
* Export all tables as ipfw_xtable_info structures to
|
2014-06-27 10:07:00 +00:00
|
|
|
* storage provided by @sd.
|
2014-08-08 06:36:26 +00:00
|
|
|
*
|
|
|
|
* If supplied buffer is too small, fills in required size
|
|
|
|
* and returns ENOMEM.
|
2014-06-14 22:47:25 +00:00
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
static int
|
2014-06-27 10:07:00 +00:00
|
|
|
export_tables(struct ip_fw_chain *ch, ipfw_obj_lheader *olh,
|
|
|
|
struct sockopt_data *sd)
|
2009-12-15 21:24:12 +00:00
|
|
|
{
|
2014-06-14 10:58:39 +00:00
|
|
|
uint32_t size;
|
|
|
|
uint32_t count;
|
2014-07-03 22:25:59 +00:00
|
|
|
struct dump_table_args dta;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
|
|
|
count = ipfw_objhash_count(CHAIN_TO_NI(ch));
|
|
|
|
size = count * sizeof(ipfw_xtable_info) + sizeof(ipfw_obj_lheader);
|
2014-06-27 10:07:00 +00:00
|
|
|
|
|
|
|
/* Fill in header regadless of buffer size */
|
|
|
|
olh->count = count;
|
|
|
|
olh->objsize = sizeof(ipfw_xtable_info);
|
|
|
|
|
2014-06-14 22:47:25 +00:00
|
|
|
if (size > olh->size) {
|
|
|
|
olh->size = size;
|
2014-06-14 10:58:39 +00:00
|
|
|
return (ENOMEM);
|
2014-06-14 22:47:25 +00:00
|
|
|
}
|
2014-07-28 19:01:25 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
olh->size = size;
|
2014-06-27 10:07:00 +00:00
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
dta.ch = ch;
|
|
|
|
dta.sd = sd;
|
|
|
|
|
|
|
|
ipfw_objhash_foreach(CHAIN_TO_NI(ch), export_table_internal, &dta);
|
2009-12-15 21:24:12 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-08-12 10:22:46 +00:00
|
|
|
/*
|
|
|
|
* Dumps all table data
|
|
|
|
* Data layout (v1)(current):
|
|
|
|
* Request: [ ipfw_obj_header ], size = ipfw_xtable_info.size
|
|
|
|
* Reply: [ ipfw_obj_header ipfw_xtable_info ipfw_obj_tentry x N ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2012-03-12 14:07:57 +00:00
|
|
|
static int
|
2014-09-05 11:11:15 +00:00
|
|
|
dump_table_v1(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
|
|
|
struct sockopt_data *sd)
|
2012-03-12 14:07:57 +00:00
|
|
|
{
|
2014-08-12 10:22:46 +00:00
|
|
|
struct _ipfw_obj_header *oh;
|
|
|
|
ipfw_xtable_info *i;
|
|
|
|
struct tid_info ti;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct dump_args da;
|
|
|
|
uint32_t sz;
|
|
|
|
|
|
|
|
sz = sizeof(ipfw_obj_header) + sizeof(ipfw_xtable_info);
|
|
|
|
oh = (struct _ipfw_obj_header *)ipfw_get_sopt_header(sd, sz);
|
|
|
|
if (oh == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
i = (ipfw_xtable_info *)(oh + 1);
|
|
|
|
objheader_to_ti(oh, &ti);
|
|
|
|
|
|
|
|
IPFW_UH_RLOCK(ch);
|
|
|
|
if ((tc = find_table(CHAIN_TO_NI(ch), &ti)) == NULL) {
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
|
|
|
export_table_info(ch, tc, i);
|
|
|
|
|
|
|
|
if (sd->valsize < i->size) {
|
|
|
|
/*
|
|
|
|
* Submitted buffer size is not enough.
|
|
|
|
* WE've already filled in @i structure with
|
|
|
|
* relevant table info including size, so we
|
|
|
|
* can return. Buffer will be flushed automatically.
|
|
|
|
*/
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the actual dump in eXtended format
|
|
|
|
*/
|
|
|
|
memset(&da, 0, sizeof(da));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
da.ch = ch;
|
2014-08-12 10:22:46 +00:00
|
|
|
da.ti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
da.tc = tc;
|
|
|
|
da.sd = sd;
|
|
|
|
|
|
|
|
ta = tc->ta;
|
|
|
|
|
|
|
|
ta->foreach(tc->astate, da.ti, dump_table_tentry, &da);
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
|
|
|
|
return (da.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dumps all table data
|
|
|
|
* Data layout (version 0)(legacy):
|
|
|
|
* Request: [ ipfw_xtable ], size = IP_FW_TABLE_XGETSIZE()
|
|
|
|
* Reply: [ ipfw_xtable ipfw_table_xentry x N ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
|
|
|
static int
|
2014-09-05 11:11:15 +00:00
|
|
|
dump_table_v0(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
|
|
|
struct sockopt_data *sd)
|
2014-08-12 10:22:46 +00:00
|
|
|
{
|
|
|
|
ipfw_xtable *xtbl;
|
|
|
|
struct tid_info ti;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct dump_args da;
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
size_t sz, count;
|
2014-08-12 10:22:46 +00:00
|
|
|
|
|
|
|
xtbl = (ipfw_xtable *)ipfw_get_sopt_header(sd, sizeof(ipfw_xtable));
|
|
|
|
if (xtbl == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
memset(&ti, 0, sizeof(ti));
|
|
|
|
ti.uidx = xtbl->tbl;
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-08-12 10:22:46 +00:00
|
|
|
IPFW_UH_RLOCK(ch);
|
|
|
|
if ((tc = find_table(CHAIN_TO_NI(ch), &ti)) == NULL) {
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (0);
|
|
|
|
}
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
count = table_get_count(ch, tc);
|
|
|
|
sz = count * sizeof(ipfw_table_xentry) + sizeof(ipfw_xtable);
|
2014-08-12 10:22:46 +00:00
|
|
|
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
xtbl->cnt = count;
|
2014-08-12 10:22:46 +00:00
|
|
|
xtbl->size = sz;
|
2015-04-27 08:29:39 +00:00
|
|
|
xtbl->type = tc->no.subtype;
|
2014-08-12 10:22:46 +00:00
|
|
|
xtbl->tbl = ti.uidx;
|
|
|
|
|
|
|
|
if (sd->valsize < sz) {
|
|
|
|
/*
|
|
|
|
* Submitted buffer size is not enough.
|
|
|
|
* WE've already filled in @i structure with
|
|
|
|
* relevant table info including size, so we
|
|
|
|
* can return. Buffer will be flushed automatically.
|
|
|
|
*/
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the actual dump in eXtended format */
|
|
|
|
memset(&da, 0, sizeof(da));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
da.ch = ch;
|
2014-08-12 10:22:46 +00:00
|
|
|
da.ti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
da.tc = tc;
|
|
|
|
da.sd = sd;
|
|
|
|
|
|
|
|
ta = tc->ta;
|
|
|
|
|
|
|
|
ta->foreach(tc->astate, da.ti, dump_table_xentry, &da);
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-09-03 21:57:06 +00:00
|
|
|
/*
|
|
|
|
* Legacy function to retrieve number of items in table.
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
get_table_size(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-09-03 21:57:06 +00:00
|
|
|
struct sockopt_data *sd)
|
|
|
|
{
|
|
|
|
uint32_t *tbl;
|
|
|
|
struct tid_info ti;
|
|
|
|
size_t sz;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sz = sizeof(*op3) + sizeof(uint32_t);
|
|
|
|
op3 = (ip_fw3_opheader *)ipfw_get_sopt_header(sd, sz);
|
|
|
|
if (op3 == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
tbl = (uint32_t *)(op3 + 1);
|
|
|
|
memset(&ti, 0, sizeof(ti));
|
|
|
|
ti.uidx = *tbl;
|
|
|
|
IPFW_UH_RLOCK(ch);
|
|
|
|
error = ipfw_count_xtable(ch, &ti, tbl);
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-08-12 10:22:46 +00:00
|
|
|
/*
|
|
|
|
* Legacy IP_FW_TABLE_GETSIZE handler
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipfw_count_table(struct ip_fw_chain *ch, struct tid_info *ti, uint32_t *cnt)
|
|
|
|
{
|
|
|
|
struct table_config *tc;
|
|
|
|
|
|
|
|
if ((tc = find_table(CHAIN_TO_NI(ch), ti)) == NULL)
|
|
|
|
return (ESRCH);
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
*cnt = table_get_count(ch, tc);
|
2014-08-12 10:22:46 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Legacy IP_FW_TABLE_XGETSIZE handler
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipfw_count_xtable(struct ip_fw_chain *ch, struct tid_info *ti, uint32_t *cnt)
|
|
|
|
{
|
|
|
|
struct table_config *tc;
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
uint32_t count;
|
2014-08-12 10:22:46 +00:00
|
|
|
|
|
|
|
if ((tc = find_table(CHAIN_TO_NI(ch), ti)) == NULL) {
|
|
|
|
*cnt = 0;
|
|
|
|
return (0); /* 'table all list' requires success */
|
|
|
|
}
|
* Add cidr:kfib algo type just for fun. It binds kernel fib
of given number to a table.
Example:
# ipfw table fib2 create algo "cidr:kfib fib=2"
# ipfw table fib2 info
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
# ipfw table fib2 list
+++ table(fib2), set(0) +++
10.0.0.0/24 0
127.0.0.1/32 0
::/96 0
::1/128 0
::ffff:0.0.0.0/96 0
2a02:978:2::/112 0
fe80::/10 0
fe80:1::/64 0
fe80:2::/64 0
fe80:3::/64 0
ff02::/16 0
# ipfw table fib2 lookup 10.0.0.5
10.0.0.0/24 0
# ipfw table fib2 lookup 2a02:978:2::11
2a02:978:2::/112 0
# ipfw table fib2 detail
+++ table(fib2), set(0) +++
kindex: 2, type: cidr, locked
valtype: number, references: 0
algorithm: cidr:kfib fib=2
items: 11, size: 288
IPv4 algorithm radix info
items: 0 itemsize: 200
IPv6 algorithm radix info
items: 0 itemsize: 200
2014-08-14 20:17:23 +00:00
|
|
|
|
|
|
|
count = table_get_count(ch, tc);
|
|
|
|
*cnt = count * sizeof(ipfw_table_xentry);
|
|
|
|
if (count > 0)
|
2014-08-12 10:22:46 +00:00
|
|
|
*cnt += sizeof(ipfw_xtable);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dump_table_entry(void *e, void *arg)
|
|
|
|
{
|
|
|
|
struct dump_args *da;
|
|
|
|
struct table_config *tc;
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_algo *ta;
|
|
|
|
ipfw_table_entry *ent;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct table_value *pval;
|
2014-07-06 18:16:04 +00:00
|
|
|
int error;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
|
|
|
da = (struct dump_args *)arg;
|
|
|
|
|
|
|
|
tc = da->tc;
|
|
|
|
ta = tc->ta;
|
2012-03-12 14:07:57 +00:00
|
|
|
|
|
|
|
/* Out of memory, returning */
|
2014-06-14 22:47:25 +00:00
|
|
|
if (da->cnt == da->size)
|
2012-03-12 14:07:57 +00:00
|
|
|
return (1);
|
2014-06-14 22:47:25 +00:00
|
|
|
ent = da->ent++;
|
|
|
|
ent->tbl = da->uidx;
|
|
|
|
da->cnt++;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
2014-07-06 18:16:04 +00:00
|
|
|
error = ta->dump_tentry(tc->astate, da->ti, e, &da->tent);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ent->addr = da->tent.k.addr.s_addr;
|
|
|
|
ent->masklen = da->tent.masklen;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
pval = get_table_value(da->ch, da->tc, da->tent.v.kidx);
|
|
|
|
ent->value = ipfw_export_table_value_legacy(pval);
|
2014-07-06 18:16:04 +00:00
|
|
|
|
|
|
|
return (0);
|
2014-06-14 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 22:47:25 +00:00
|
|
|
/*
|
|
|
|
* Dumps table in pre-8.1 legacy format.
|
|
|
|
*/
|
2014-06-14 10:58:39 +00:00
|
|
|
int
|
2014-06-14 22:47:25 +00:00
|
|
|
ipfw_dump_table_legacy(struct ip_fw_chain *ch, struct tid_info *ti,
|
|
|
|
ipfw_table *tbl)
|
2014-06-14 10:58:39 +00:00
|
|
|
{
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct dump_args da;
|
|
|
|
|
|
|
|
tbl->cnt = 0;
|
|
|
|
|
|
|
|
if ((tc = find_table(CHAIN_TO_NI(ch), ti)) == NULL)
|
|
|
|
return (0); /* XXX: We should return ESRCH */
|
|
|
|
|
|
|
|
ta = tc->ta;
|
|
|
|
|
2014-07-06 18:16:04 +00:00
|
|
|
/* This dump format supports IPv4 only */
|
2015-04-27 08:29:39 +00:00
|
|
|
if (tc->no.subtype != IPFW_TABLE_ADDR)
|
2014-07-06 18:16:04 +00:00
|
|
|
return (0);
|
2014-06-14 10:58:39 +00:00
|
|
|
|
2014-06-15 13:40:27 +00:00
|
|
|
memset(&da, 0, sizeof(da));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
da.ch = ch;
|
2014-06-14 10:58:39 +00:00
|
|
|
da.ti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
da.tc = tc;
|
2014-06-14 22:47:25 +00:00
|
|
|
da.ent = &tbl->ent[0];
|
|
|
|
da.size = tbl->size;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
|
|
|
tbl->cnt = 0;
|
|
|
|
ta->foreach(tc->astate, da.ti, dump_table_entry, &da);
|
2014-06-14 22:47:25 +00:00
|
|
|
tbl->cnt = da.cnt;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
2012-03-12 14:07:57 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-06-16 13:05:07 +00:00
|
|
|
/*
|
2014-07-06 18:16:04 +00:00
|
|
|
* Dumps table entry in eXtended format (v1)(current).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dump_table_tentry(void *e, void *arg)
|
|
|
|
{
|
|
|
|
struct dump_args *da;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct table_value *pval;
|
2014-07-06 18:16:04 +00:00
|
|
|
ipfw_obj_tentry *tent;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
int error;
|
2014-07-06 18:16:04 +00:00
|
|
|
|
|
|
|
da = (struct dump_args *)arg;
|
|
|
|
|
|
|
|
tc = da->tc;
|
|
|
|
ta = tc->ta;
|
|
|
|
|
|
|
|
tent = (ipfw_obj_tentry *)ipfw_get_sopt_space(da->sd, sizeof(*tent));
|
|
|
|
/* Out of memory, returning */
|
|
|
|
if (tent == NULL) {
|
|
|
|
da->error = ENOMEM;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
tent->head.length = sizeof(ipfw_obj_tentry);
|
|
|
|
tent->idx = da->uidx;
|
|
|
|
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
error = ta->dump_tentry(tc->astate, da->ti, e, tent);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
pval = get_table_value(da->ch, da->tc, tent->v.kidx);
|
|
|
|
ipfw_export_table_value_v1(pval, &tent->v.value);
|
|
|
|
|
|
|
|
return (0);
|
2014-07-06 18:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dumps table entry in eXtended format (v0).
|
2014-06-16 13:05:07 +00:00
|
|
|
*/
|
2012-03-12 14:07:57 +00:00
|
|
|
static int
|
2014-06-14 10:58:39 +00:00
|
|
|
dump_table_xentry(void *e, void *arg)
|
2012-03-12 14:07:57 +00:00
|
|
|
{
|
2014-06-14 10:58:39 +00:00
|
|
|
struct dump_args *da;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
2012-03-12 14:07:57 +00:00
|
|
|
ipfw_table_xentry *xent;
|
2014-07-06 18:16:04 +00:00
|
|
|
ipfw_obj_tentry *tent;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct table_value *pval;
|
2014-07-06 18:16:04 +00:00
|
|
|
int error;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
|
|
|
da = (struct dump_args *)arg;
|
|
|
|
|
|
|
|
tc = da->tc;
|
|
|
|
ta = tc->ta;
|
|
|
|
|
2014-06-27 10:07:00 +00:00
|
|
|
xent = (ipfw_table_xentry *)ipfw_get_sopt_space(da->sd, sizeof(*xent));
|
2012-03-12 14:07:57 +00:00
|
|
|
/* Out of memory, returning */
|
2014-06-27 10:07:00 +00:00
|
|
|
if (xent == NULL)
|
2012-03-12 14:07:57 +00:00
|
|
|
return (1);
|
|
|
|
xent->len = sizeof(ipfw_table_xentry);
|
2014-06-14 22:47:25 +00:00
|
|
|
xent->tbl = da->uidx;
|
2012-03-12 14:07:57 +00:00
|
|
|
|
2014-07-06 18:16:04 +00:00
|
|
|
memset(&da->tent, 0, sizeof(da->tent));
|
|
|
|
tent = &da->tent;
|
|
|
|
error = ta->dump_tentry(tc->astate, da->ti, e, tent);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Convert current format to previous one */
|
|
|
|
xent->masklen = tent->masklen;
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
pval = get_table_value(da->ch, da->tc, da->tent.v.kidx);
|
|
|
|
xent->value = ipfw_export_table_value_legacy(pval);
|
2014-07-06 18:16:04 +00:00
|
|
|
/* Apply some hacks */
|
2015-04-27 08:29:39 +00:00
|
|
|
if (tc->no.subtype == IPFW_TABLE_ADDR && tent->subtype == AF_INET) {
|
2014-07-06 18:16:04 +00:00
|
|
|
xent->k.addr6.s6_addr32[3] = tent->k.addr.s_addr;
|
|
|
|
xent->flags = IPFW_TCF_INET;
|
|
|
|
} else
|
|
|
|
memcpy(&xent->k, &tent->k, sizeof(xent->k));
|
|
|
|
|
|
|
|
return (0);
|
2012-03-12 14:07:57 +00:00
|
|
|
}
|
|
|
|
|
2014-08-23 11:27:49 +00:00
|
|
|
/*
|
|
|
|
* Helper function to export table algo data
|
|
|
|
* to tentry format before calling user function.
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
prepare_table_tentry(void *e, void *arg)
|
|
|
|
{
|
|
|
|
struct dump_args *da;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
da = (struct dump_args *)arg;
|
|
|
|
|
|
|
|
tc = da->tc;
|
|
|
|
ta = tc->ta;
|
|
|
|
|
|
|
|
error = ta->dump_tentry(tc->astate, da->ti, e, &da->tent);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
da->f(&da->tent, da->farg);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow external consumers to read table entries in standard format.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipfw_foreach_table_tentry(struct ip_fw_chain *ch, uint16_t kidx,
|
|
|
|
ta_foreach_f *f, void *arg)
|
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct table_config *tc;
|
|
|
|
struct table_algo *ta;
|
|
|
|
struct dump_args da;
|
|
|
|
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
|
|
|
|
tc = (struct table_config *)ipfw_objhash_lookup_kidx(ni, kidx);
|
|
|
|
if (tc == NULL)
|
|
|
|
return (ESRCH);
|
|
|
|
|
|
|
|
ta = tc->ta;
|
|
|
|
|
|
|
|
memset(&da, 0, sizeof(da));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
da.ch = ch;
|
2014-08-23 11:27:49 +00:00
|
|
|
da.ti = KIDX_TO_TI(ch, tc->no.kidx);
|
|
|
|
da.tc = tc;
|
|
|
|
da.f = f;
|
|
|
|
da.farg = arg;
|
|
|
|
|
|
|
|
ta->foreach(tc->astate, da.ti, prepare_table_tentry, &da);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/*
|
|
|
|
* Table algorithms
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-05-03 18:05:43 +00:00
|
|
|
* Finds algorithm by index, table type or supplied name.
|
2014-08-11 20:00:51 +00:00
|
|
|
*
|
|
|
|
* Returns pointer to algo or NULL.
|
2014-06-14 10:58:39 +00:00
|
|
|
*/
|
|
|
|
static struct table_algo *
|
2014-06-16 13:05:07 +00:00
|
|
|
find_table_algo(struct tables_config *tcfg, struct tid_info *ti, char *name)
|
2014-06-14 10:58:39 +00:00
|
|
|
{
|
2014-06-16 13:05:07 +00:00
|
|
|
int i, l;
|
|
|
|
struct table_algo *ta;
|
2014-06-14 10:58:39 +00:00
|
|
|
|
2014-08-01 07:35:17 +00:00
|
|
|
if (ti->type > IPFW_TABLE_MAXTYPE)
|
|
|
|
return (NULL);
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/* Search by index */
|
|
|
|
if (ti->atype != 0) {
|
|
|
|
if (ti->atype > tcfg->algo_count)
|
|
|
|
return (NULL);
|
|
|
|
return (tcfg->algo[ti->atype]);
|
|
|
|
}
|
|
|
|
|
2014-08-14 17:31:04 +00:00
|
|
|
if (name == NULL) {
|
|
|
|
/* Return default algorithm for given type if set */
|
|
|
|
return (tcfg->def_algo[ti->type]);
|
|
|
|
}
|
2014-06-16 13:05:07 +00:00
|
|
|
|
2014-08-14 17:31:04 +00:00
|
|
|
/* Search by name */
|
|
|
|
/* TODO: better search */
|
|
|
|
for (i = 1; i <= tcfg->algo_count; i++) {
|
|
|
|
ta = tcfg->algo[i];
|
2014-06-16 13:05:07 +00:00
|
|
|
|
2014-08-14 17:31:04 +00:00
|
|
|
/*
|
|
|
|
* One can supply additional algorithm
|
|
|
|
* parameters so we compare only the first word
|
|
|
|
* of supplied name:
|
2014-08-14 21:43:20 +00:00
|
|
|
* 'addr:chash hsize=32'
|
2014-08-14 17:31:04 +00:00
|
|
|
* '^^^^^^^^^'
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
l = strlen(ta->name);
|
|
|
|
if (strncmp(name, ta->name, l) != 0)
|
|
|
|
continue;
|
|
|
|
if (name[l] != '\0' && name[l] != ' ')
|
|
|
|
continue;
|
|
|
|
/* Check if we're requesting proper table type */
|
|
|
|
if (ti->type != 0 && ti->type != ta->type)
|
|
|
|
return (NULL);
|
|
|
|
return (ta);
|
2014-06-16 13:05:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 17:31:04 +00:00
|
|
|
return (NULL);
|
2014-06-14 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/*
|
|
|
|
* Register new table algo @ta.
|
2014-08-11 20:00:51 +00:00
|
|
|
* Stores algo id inside @idx.
|
2014-08-02 17:18:47 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
2014-07-29 21:38:06 +00:00
|
|
|
int
|
|
|
|
ipfw_add_table_algo(struct ip_fw_chain *ch, struct table_algo *ta, size_t size,
|
|
|
|
int *idx)
|
2014-06-14 10:58:39 +00:00
|
|
|
{
|
|
|
|
struct tables_config *tcfg;
|
2014-07-29 21:38:06 +00:00
|
|
|
struct table_algo *ta_new;
|
2014-08-02 17:18:47 +00:00
|
|
|
size_t sz;
|
2014-07-29 21:38:06 +00:00
|
|
|
|
|
|
|
if (size > sizeof(struct table_algo))
|
|
|
|
return (EINVAL);
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/* Check for the required on-stack size for add/del */
|
|
|
|
sz = roundup2(ta->ta_buf_size, sizeof(void *));
|
|
|
|
if (sz > TA_BUF_SZ)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2014-08-13 16:53:12 +00:00
|
|
|
KASSERT(ta->type <= IPFW_TABLE_MAXTYPE,("Increase IPFW_TABLE_MAXTYPE"));
|
2014-08-01 07:35:17 +00:00
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/* Copy algorithm data to stable storage. */
|
2014-07-29 21:38:06 +00:00
|
|
|
ta_new = malloc(sizeof(struct table_algo), M_IPFW, M_WAITOK | M_ZERO);
|
|
|
|
memcpy(ta_new, ta, size);
|
2014-06-14 10:58:39 +00:00
|
|
|
|
|
|
|
tcfg = CHAIN_TO_TCFG(ch);
|
|
|
|
|
|
|
|
KASSERT(tcfg->algo_count < 255, ("Increase algo array size"));
|
|
|
|
|
2014-07-29 21:38:06 +00:00
|
|
|
tcfg->algo[++tcfg->algo_count] = ta_new;
|
|
|
|
ta_new->idx = tcfg->algo_count;
|
|
|
|
|
2014-08-01 07:35:17 +00:00
|
|
|
/* Set algorithm as default one for given type */
|
|
|
|
if ((ta_new->flags & TA_FLAG_DEFAULT) != 0 &&
|
|
|
|
tcfg->def_algo[ta_new->type] == NULL)
|
|
|
|
tcfg->def_algo[ta_new->type] = ta_new;
|
|
|
|
|
2014-07-29 21:38:06 +00:00
|
|
|
*idx = ta_new->idx;
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-07-29 21:38:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
/*
|
|
|
|
* Unregisters table algo using @idx as id.
|
2014-08-12 17:03:13 +00:00
|
|
|
* XXX: It is NOT safe to call this function in any place
|
|
|
|
* other than ipfw instance destroy handler.
|
2014-08-02 17:18:47 +00:00
|
|
|
*/
|
2014-07-29 21:38:06 +00:00
|
|
|
void
|
|
|
|
ipfw_del_table_algo(struct ip_fw_chain *ch, int idx)
|
|
|
|
{
|
|
|
|
struct tables_config *tcfg;
|
|
|
|
struct table_algo *ta;
|
|
|
|
|
|
|
|
tcfg = CHAIN_TO_TCFG(ch);
|
|
|
|
|
2014-08-02 17:18:47 +00:00
|
|
|
KASSERT(idx <= tcfg->algo_count, ("algo idx %d out of range 1..%d",
|
|
|
|
idx, tcfg->algo_count));
|
2014-07-29 21:38:06 +00:00
|
|
|
|
|
|
|
ta = tcfg->algo[idx];
|
|
|
|
KASSERT(ta != NULL, ("algo idx %d is NULL", idx));
|
2014-08-01 07:35:17 +00:00
|
|
|
|
|
|
|
if (tcfg->def_algo[ta->type] == ta)
|
|
|
|
tcfg->def_algo[ta->type] = NULL;
|
|
|
|
|
2014-07-29 21:38:06 +00:00
|
|
|
free(ta, M_IPFW);
|
2014-06-14 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 22:44:26 +00:00
|
|
|
/*
|
|
|
|
* Lists all table algorithms currently available.
|
|
|
|
* Data layout (v0)(current):
|
|
|
|
* Request: [ ipfw_obj_lheader ], size = ipfw_obj_lheader.size
|
|
|
|
* Reply: [ ipfw_obj_lheader ipfw_ta_info x N ]
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
2014-09-05 11:11:15 +00:00
|
|
|
static int
|
|
|
|
list_table_algo(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
|
2014-09-03 21:57:06 +00:00
|
|
|
struct sockopt_data *sd)
|
2014-07-29 22:44:26 +00:00
|
|
|
{
|
|
|
|
struct _ipfw_obj_lheader *olh;
|
|
|
|
struct tables_config *tcfg;
|
|
|
|
ipfw_ta_info *i;
|
|
|
|
struct table_algo *ta;
|
|
|
|
uint32_t count, n, size;
|
|
|
|
|
|
|
|
olh = (struct _ipfw_obj_lheader *)ipfw_get_sopt_header(sd,sizeof(*olh));
|
|
|
|
if (olh == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (sd->valsize < olh->size)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
IPFW_UH_RLOCK(ch);
|
|
|
|
tcfg = CHAIN_TO_TCFG(ch);
|
|
|
|
count = tcfg->algo_count;
|
|
|
|
size = count * sizeof(ipfw_ta_info) + sizeof(ipfw_obj_lheader);
|
|
|
|
|
|
|
|
/* Fill in header regadless of buffer size */
|
|
|
|
olh->count = count;
|
|
|
|
olh->objsize = sizeof(ipfw_ta_info);
|
|
|
|
|
|
|
|
if (size > olh->size) {
|
|
|
|
olh->size = size;
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
olh->size = size;
|
|
|
|
|
|
|
|
for (n = 1; n <= count; n++) {
|
|
|
|
i = (ipfw_ta_info *)ipfw_get_sopt_space(sd, sizeof(*i));
|
2016-04-15 12:24:01 +00:00
|
|
|
KASSERT(i != NULL, ("previously checked buffer is not enough"));
|
2014-07-29 22:44:26 +00:00
|
|
|
ta = tcfg->algo[n];
|
|
|
|
strlcpy(i->algoname, ta->name, sizeof(i->algoname));
|
|
|
|
i->type = ta->type;
|
|
|
|
i->refcnt = ta->refcnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPFW_UH_RUNLOCK(ch);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
static int
|
2015-04-27 08:29:39 +00:00
|
|
|
classify_srcdst(ipfw_insn *cmd, uint16_t *puidx, uint8_t *ptype)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
2015-04-27 08:29:39 +00:00
|
|
|
/* Basic IPv4/IPv6 or u32 lookups */
|
|
|
|
*puidx = cmd->arg1;
|
|
|
|
/* Assume ADDR by default */
|
|
|
|
*ptype = IPFW_TABLE_ADDR;
|
|
|
|
int v;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
if (F_LEN(cmd) > F_INSN_SIZE(ipfw_insn_u32)) {
|
|
|
|
/*
|
|
|
|
* generic lookup. The key must be
|
|
|
|
* in 32bit big-endian format.
|
|
|
|
*/
|
|
|
|
v = ((ipfw_insn_u32 *)cmd)->d[1];
|
|
|
|
switch (v) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
/* IPv4 src/dst */
|
2014-06-12 09:59:11 +00:00
|
|
|
break;
|
2015-04-27 08:29:39 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
/* src/dst port */
|
|
|
|
*ptype = IPFW_TABLE_NUMBER;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* uid/gid */
|
|
|
|
*ptype = IPFW_TABLE_NUMBER;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
/* jid */
|
|
|
|
*ptype = IPFW_TABLE_NUMBER;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
/* dscp */
|
|
|
|
*ptype = IPFW_TABLE_NUMBER;
|
|
|
|
break;
|
|
|
|
}
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
classify_via(ipfw_insn *cmd, uint16_t *puidx, uint8_t *ptype)
|
|
|
|
{
|
|
|
|
ipfw_insn_if *cmdif;
|
|
|
|
|
|
|
|
/* Interface table, possibly */
|
|
|
|
cmdif = (ipfw_insn_if *)cmd;
|
|
|
|
if (cmdif->name[0] != '\1')
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
*ptype = IPFW_TABLE_INTERFACE;
|
|
|
|
*puidx = cmdif->p.kidx;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
classify_flow(ipfw_insn *cmd, uint16_t *puidx, uint8_t *ptype)
|
|
|
|
{
|
|
|
|
|
|
|
|
*puidx = cmd->arg1;
|
|
|
|
*ptype = IPFW_TABLE_FLOW;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_arg1(ipfw_insn *cmd, uint16_t idx)
|
|
|
|
{
|
|
|
|
|
|
|
|
cmd->arg1 = idx;
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-04-27 08:29:39 +00:00
|
|
|
update_via(ipfw_insn *cmd, uint16_t idx)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
|
|
|
ipfw_insn_if *cmdif;
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
cmdif = (ipfw_insn_if *)cmd;
|
|
|
|
cmdif->p.kidx = idx;
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
static int
|
|
|
|
table_findbyname(struct ip_fw_chain *ch, struct tid_info *ti,
|
|
|
|
struct named_object **pno)
|
|
|
|
{
|
|
|
|
struct table_config *tc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
|
|
|
|
error = find_table_err(CHAIN_TO_NI(ch), ti, &tc);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
*pno = &tc->no;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: sets-sets! */
|
|
|
|
static struct named_object *
|
|
|
|
table_findbykidx(struct ip_fw_chain *ch, uint16_t idx)
|
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct table_config *tc;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
tc = (struct table_config *)ipfw_objhash_lookup_kidx(ni, idx);
|
|
|
|
KASSERT(tc != NULL, ("Table with index %d not found", idx));
|
|
|
|
|
|
|
|
return (&tc->no);
|
|
|
|
}
|
|
|
|
|
2016-05-17 07:47:23 +00:00
|
|
|
static int
|
|
|
|
table_manage_sets(struct ip_fw_chain *ch, uint16_t set, uint8_t new_set,
|
|
|
|
enum ipfw_sets_cmd cmd)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SWAP_ALL:
|
|
|
|
case TEST_ALL:
|
2016-09-13 18:16:15 +00:00
|
|
|
case MOVE_ALL:
|
2016-05-17 07:47:23 +00:00
|
|
|
/*
|
2016-09-13 18:16:15 +00:00
|
|
|
* Always return success, the real action and decision
|
|
|
|
* should make table_manage_sets_all().
|
2016-05-17 07:47:23 +00:00
|
|
|
*/
|
2016-09-13 18:16:15 +00:00
|
|
|
return (0);
|
2016-05-17 07:47:23 +00:00
|
|
|
case TEST_ONE:
|
|
|
|
case MOVE_ONE:
|
|
|
|
/*
|
|
|
|
* NOTE: we need to use ipfw_objhash_del/ipfw_objhash_add
|
|
|
|
* if set number will be used in hash function. Currently
|
|
|
|
* we can just use generic handler that replaces set value.
|
|
|
|
*/
|
|
|
|
if (V_fw_tables_sets == 0)
|
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
case COUNT_ONE:
|
|
|
|
/*
|
|
|
|
* Return EOPNOTSUPP for COUNT_ONE when per-set sysctl is
|
|
|
|
* disabled. This allow skip table's opcodes from additional
|
|
|
|
* checks when specific rules moved to another set.
|
|
|
|
*/
|
|
|
|
if (V_fw_tables_sets == 0)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
/* Use generic sets handler when per-set sysctl is enabled. */
|
|
|
|
return (ipfw_obj_manage_sets(CHAIN_TO_NI(ch), IPFW_TLV_TBL_NAME,
|
|
|
|
set, new_set, cmd));
|
|
|
|
}
|
|
|
|
|
2016-09-13 18:16:15 +00:00
|
|
|
/*
|
|
|
|
* We register several opcode rewriters for lookup tables.
|
|
|
|
* All tables opcodes have the same ETLV type, but different subtype.
|
|
|
|
* To avoid invoking sets handler several times for XXX_ALL commands,
|
|
|
|
* we use separate manage_sets handler. O_RECV has the lowest value,
|
|
|
|
* so it should be called first.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
table_manage_sets_all(struct ip_fw_chain *ch, uint16_t set, uint8_t new_set,
|
|
|
|
enum ipfw_sets_cmd cmd)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SWAP_ALL:
|
|
|
|
case TEST_ALL:
|
|
|
|
/*
|
|
|
|
* Return success for TEST_ALL, since nothing prevents
|
|
|
|
* move rules from one set to another. All tables are
|
|
|
|
* accessible from all sets when per-set tables sysctl
|
|
|
|
* is disabled.
|
|
|
|
*/
|
|
|
|
case MOVE_ALL:
|
|
|
|
if (V_fw_tables_sets == 0)
|
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (table_manage_sets(ch, set, new_set, cmd));
|
|
|
|
}
|
|
|
|
/* Use generic sets handler when per-set sysctl is enabled. */
|
|
|
|
return (ipfw_obj_manage_sets(CHAIN_TO_NI(ch), IPFW_TLV_TBL_NAME,
|
|
|
|
set, new_set, cmd));
|
|
|
|
}
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
static struct opcode_obj_rewrite opcodes[] = {
|
|
|
|
{
|
2016-05-17 07:47:23 +00:00
|
|
|
.opcode = O_IP_SRC_LOOKUP,
|
|
|
|
.etlv = IPFW_TLV_TBL_NAME,
|
|
|
|
.classifier = classify_srcdst,
|
|
|
|
.update = update_arg1,
|
|
|
|
.find_byname = table_findbyname,
|
|
|
|
.find_bykidx = table_findbykidx,
|
|
|
|
.create_object = create_table_compat,
|
|
|
|
.manage_sets = table_manage_sets,
|
2015-04-27 08:29:39 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-17 07:47:23 +00:00
|
|
|
.opcode = O_IP_DST_LOOKUP,
|
|
|
|
.etlv = IPFW_TLV_TBL_NAME,
|
|
|
|
.classifier = classify_srcdst,
|
|
|
|
.update = update_arg1,
|
|
|
|
.find_byname = table_findbyname,
|
|
|
|
.find_bykidx = table_findbykidx,
|
|
|
|
.create_object = create_table_compat,
|
|
|
|
.manage_sets = table_manage_sets,
|
2015-04-27 08:29:39 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-17 07:47:23 +00:00
|
|
|
.opcode = O_IP_FLOW_LOOKUP,
|
|
|
|
.etlv = IPFW_TLV_TBL_NAME,
|
|
|
|
.classifier = classify_flow,
|
|
|
|
.update = update_arg1,
|
|
|
|
.find_byname = table_findbyname,
|
|
|
|
.find_bykidx = table_findbykidx,
|
|
|
|
.create_object = create_table_compat,
|
|
|
|
.manage_sets = table_manage_sets,
|
2015-04-27 08:29:39 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-17 07:47:23 +00:00
|
|
|
.opcode = O_XMIT,
|
|
|
|
.etlv = IPFW_TLV_TBL_NAME,
|
|
|
|
.classifier = classify_via,
|
|
|
|
.update = update_via,
|
|
|
|
.find_byname = table_findbyname,
|
|
|
|
.find_bykidx = table_findbykidx,
|
|
|
|
.create_object = create_table_compat,
|
|
|
|
.manage_sets = table_manage_sets,
|
2015-04-27 08:29:39 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-17 07:47:23 +00:00
|
|
|
.opcode = O_RECV,
|
|
|
|
.etlv = IPFW_TLV_TBL_NAME,
|
|
|
|
.classifier = classify_via,
|
|
|
|
.update = update_via,
|
|
|
|
.find_byname = table_findbyname,
|
|
|
|
.find_bykidx = table_findbykidx,
|
|
|
|
.create_object = create_table_compat,
|
2016-09-13 18:16:15 +00:00
|
|
|
.manage_sets = table_manage_sets_all,
|
2015-04-27 08:29:39 +00:00
|
|
|
},
|
|
|
|
{
|
2016-05-17 07:47:23 +00:00
|
|
|
.opcode = O_VIA,
|
|
|
|
.etlv = IPFW_TLV_TBL_NAME,
|
|
|
|
.classifier = classify_via,
|
|
|
|
.update = update_via,
|
|
|
|
.find_byname = table_findbyname,
|
|
|
|
.find_bykidx = table_findbykidx,
|
|
|
|
.create_object = create_table_compat,
|
|
|
|
.manage_sets = table_manage_sets,
|
2015-04-27 08:29:39 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-05-17 07:47:23 +00:00
|
|
|
static int
|
|
|
|
test_sets_cb(struct namedobj_instance *ni __unused, struct named_object *no,
|
|
|
|
void *arg __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Check that there aren't any tables in not default set */
|
|
|
|
if (no->set != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch between "set 0" and "rule's set" table binding,
|
|
|
|
* Check all ruleset bindings and permits changing
|
|
|
|
* IFF each binding has both rule AND table in default set (set 0).
|
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipfw_switch_tables_namespace(struct ip_fw_chain *ch, unsigned int sets)
|
|
|
|
{
|
|
|
|
struct opcode_obj_rewrite *rw;
|
|
|
|
struct namedobj_instance *ni;
|
|
|
|
struct named_object *no;
|
|
|
|
struct ip_fw *rule;
|
|
|
|
ipfw_insn *cmd;
|
|
|
|
int cmdlen, i, l;
|
|
|
|
uint16_t kidx;
|
|
|
|
uint8_t subtype;
|
|
|
|
|
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
|
|
|
|
if (V_fw_tables_sets == sets) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
ni = CHAIN_TO_NI(ch);
|
|
|
|
if (sets == 0) {
|
|
|
|
/*
|
|
|
|
* Prevent disabling sets support if we have some tables
|
|
|
|
* in not default sets.
|
|
|
|
*/
|
|
|
|
if (ipfw_objhash_foreach_type(ni, test_sets_cb,
|
|
|
|
NULL, IPFW_TLV_TBL_NAME) != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Scan all rules and examine tables opcodes.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ch->n_rules; i++) {
|
|
|
|
rule = ch->map[i];
|
|
|
|
|
|
|
|
l = rule->cmd_len;
|
|
|
|
cmd = rule->cmd;
|
|
|
|
cmdlen = 0;
|
|
|
|
for ( ; l > 0 ; l -= cmdlen, cmd += cmdlen) {
|
|
|
|
cmdlen = F_LEN(cmd);
|
|
|
|
/* Check only tables opcodes */
|
|
|
|
for (kidx = 0, rw = opcodes;
|
|
|
|
rw < opcodes + nitems(opcodes); rw++) {
|
|
|
|
if (rw->opcode != cmd->opcode)
|
|
|
|
continue;
|
|
|
|
if (rw->classifier(cmd, &kidx, &subtype) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (kidx == 0)
|
|
|
|
continue;
|
|
|
|
no = ipfw_objhash_lookup_kidx(ni, kidx);
|
|
|
|
/* Check if both table object and rule has the set 0 */
|
|
|
|
if (no->set != 0 || rule->set != 0) {
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
V_fw_tables_sets = sets;
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
return (0);
|
|
|
|
}
|
2015-04-27 08:29:39 +00:00
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
/*
|
|
|
|
* Checks table name for validity.
|
|
|
|
* Enforce basic length checks, the rest
|
|
|
|
* should be done in userland.
|
|
|
|
*
|
|
|
|
* Returns 0 if name is considered valid.
|
|
|
|
*/
|
2015-11-03 10:29:46 +00:00
|
|
|
static int
|
|
|
|
check_table_name(const char *name)
|
2014-07-03 22:25:59 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: do some more complicated checks
|
|
|
|
*/
|
2015-11-03 10:29:46 +00:00
|
|
|
return (ipfw_check_object_name_generic(name));
|
2014-07-03 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finds table config based on either legacy index
|
|
|
|
* or name in ntlv.
|
|
|
|
* Note @ti structure contains unchecked data from userland.
|
|
|
|
*
|
2015-04-27 08:29:39 +00:00
|
|
|
* Returns 0 in success and fills in @tc with found config
|
2014-07-03 22:25:59 +00:00
|
|
|
*/
|
2015-04-27 08:29:39 +00:00
|
|
|
static int
|
|
|
|
find_table_err(struct namedobj_instance *ni, struct tid_info *ti,
|
|
|
|
struct table_config **tc)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
|
|
|
char *name, bname[16];
|
|
|
|
struct named_object *no;
|
2014-07-03 22:25:59 +00:00
|
|
|
ipfw_obj_ntlv *ntlv;
|
|
|
|
uint32_t set;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
|
|
|
if (ti->tlvs != NULL) {
|
2016-05-05 20:15:46 +00:00
|
|
|
ntlv = ipfw_find_name_tlv_type(ti->tlvs, ti->tlen, ti->uidx,
|
|
|
|
IPFW_TLV_TBL_NAME);
|
2014-07-03 22:25:59 +00:00
|
|
|
if (ntlv == NULL)
|
2015-04-27 08:29:39 +00:00
|
|
|
return (EINVAL);
|
2014-07-03 22:25:59 +00:00
|
|
|
name = ntlv->name;
|
2014-08-13 12:04:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use set provided by @ti instead of @ntlv one.
|
|
|
|
* This is needed due to different sets behavior
|
|
|
|
* controlled by V_fw_tables_sets.
|
|
|
|
*/
|
2016-05-17 07:47:23 +00:00
|
|
|
set = (V_fw_tables_sets != 0) ? ti->set : 0;
|
2014-06-12 09:59:11 +00:00
|
|
|
} else {
|
|
|
|
snprintf(bname, sizeof(bname), "%d", ti->uidx);
|
|
|
|
name = bname;
|
2014-07-03 22:25:59 +00:00
|
|
|
set = 0;
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 22:25:59 +00:00
|
|
|
no = ipfw_objhash_lookup_name(ni, set, name);
|
2015-04-27 08:29:39 +00:00
|
|
|
*tc = (struct table_config *)no;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finds table config based on either legacy index
|
|
|
|
* or name in ntlv.
|
|
|
|
* Note @ti structure contains unchecked data from userland.
|
|
|
|
*
|
|
|
|
* Returns pointer to table_config or NULL.
|
|
|
|
*/
|
|
|
|
static struct table_config *
|
|
|
|
find_table(struct namedobj_instance *ni, struct tid_info *ti)
|
|
|
|
{
|
|
|
|
struct table_config *tc;
|
|
|
|
|
|
|
|
if (find_table_err(ni, ti, &tc) != 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
return (tc);
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Allocate new table config structure using
|
|
|
|
* specified @algo and @aname.
|
|
|
|
*
|
|
|
|
* Returns pointer to config or NULL.
|
|
|
|
*/
|
2014-06-12 09:59:11 +00:00
|
|
|
static struct table_config *
|
2014-07-28 19:01:25 +00:00
|
|
|
alloc_table_config(struct ip_fw_chain *ch, struct tid_info *ti,
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
struct table_algo *ta, char *aname, uint8_t tflags)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
|
|
|
char *name, bname[16];
|
|
|
|
struct table_config *tc;
|
|
|
|
int error;
|
2014-07-03 22:25:59 +00:00
|
|
|
ipfw_obj_ntlv *ntlv;
|
|
|
|
uint32_t set;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
|
|
|
if (ti->tlvs != NULL) {
|
2016-05-05 20:15:46 +00:00
|
|
|
ntlv = ipfw_find_name_tlv_type(ti->tlvs, ti->tlen, ti->uidx,
|
|
|
|
IPFW_TLV_TBL_NAME);
|
2014-07-03 22:25:59 +00:00
|
|
|
if (ntlv == NULL)
|
2014-06-12 09:59:11 +00:00
|
|
|
return (NULL);
|
2014-07-03 22:25:59 +00:00
|
|
|
name = ntlv->name;
|
Fix ipfw table creation when net.inet.ip.fw.tables_sets = 0 and non zero set
specified on table creation. This fixes following:
# sysctl net.inet.ip.fw.tables_sets
net.inet.ip.fw.tables_sets: 0
# ipfw table all info
# ipfw set 1 table 1 create type addr
# ipfw set 1 table 1 create type addr
# ipfw add 10 set 1 count ip from table\(1\) to any
00010 count ip from table(1) to any
# ipfw add 10 set 1 count ip from table\(1\) to any
00010 count ip from table(1) to any
# ipfw table all info
--- table(1), set(1) ---
kindex: 4, type: addr
references: 1, valtype: legacy
algorithm: addr:radix
items: 0, size: 296
--- table(1), set(1) ---
kindex: 3, type: addr
references: 1, valtype: legacy
algorithm: addr:radix
items: 0, size: 296
--- table(1), set(1) ---
kindex: 2, type: addr
references: 0, valtype: legacy
algorithm: addr:radix
items: 0, size: 296
--- table(1), set(1) ---
kindex: 1, type: addr
references: 0, valtype: legacy
algorithm: addr:radix
items: 0, size: 296
#
MFC after: 1 week
2018-04-11 11:12:20 +00:00
|
|
|
set = (V_fw_tables_sets == 0) ? 0 : ntlv->set;
|
2014-06-12 09:59:11 +00:00
|
|
|
} else {
|
2015-04-27 08:29:39 +00:00
|
|
|
/* Compat part: convert number to string representation */
|
2014-06-12 09:59:11 +00:00
|
|
|
snprintf(bname, sizeof(bname), "%d", ti->uidx);
|
|
|
|
name = bname;
|
2014-07-03 22:25:59 +00:00
|
|
|
set = 0;
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tc = malloc(sizeof(struct table_config), M_IPFW, M_WAITOK | M_ZERO);
|
|
|
|
tc->no.name = tc->tablename;
|
2015-04-27 08:29:39 +00:00
|
|
|
tc->no.subtype = ta->type;
|
2014-07-03 22:25:59 +00:00
|
|
|
tc->no.set = set;
|
* Add new "flow" table type to support N=1..5-tuple lookups
* Add "flow:hash" algorithm
Kernel changes:
* Add O_IP_FLOW_LOOKUP opcode to support "flow" lookups
* Add IPFW_TABLE_FLOW table type
* Add "struct tflow_entry" as strage for 6-tuple flows
* Add "flow:hash" algorithm. Basically it is auto-growing chained hash table.
Additionally, we store mask of fields we need to compare in each instance/
* Increase ipfw_obj_tentry size by adding struct tflow_entry
* Add per-algorithm stat (ifpw_ta_tinfo) to ipfw_xtable_info
* Increase algoname length: 32 -> 64 (algo options passed there as string)
* Assume every table type can be customized by flags, use u8 to store "tflags" field.
* Simplify ipfw_find_table_entry() by providing @tentry directly to algo callback.
* Fix bug in cidr:chash resize procedure.
Userland changes:
* add "flow table(NAME)" syntax to support n-tuple checking tables.
* make fill_flags() separate function to ease working with _s_x arrays
* change "table info" output to reflect longer "type" fields
Syntax:
ipfw table fl2 create type flow:[src-ip][,proto][,src-port][,dst-ip][dst-port] [algo flow:hash]
Examples:
0:02 [2] zfscurr0# ipfw table fl2 create type flow:src-ip,proto,dst-port algo flow:hash
0:02 [2] zfscurr0# ipfw table fl2 info
+++ table(fl2), set(0) +++
kindex: 0, type: flow:src-ip,proto,dst-port
valtype: number, references: 0
algorithm: flow:hash
items: 0, size: 280
0:02 [2] zfscurr0# ipfw table fl2 add 2a02:6b8::333,tcp,443 45000
0:02 [2] zfscurr0# ipfw table fl2 add 10.0.0.92,tcp,80 22000
0:02 [2] zfscurr0# ipfw table fl2 list
+++ table(fl2), set(0) +++
2a02:6b8::333,6,443 45000
10.0.0.92,6,80 22000
0:02 [2] zfscurr0# ipfw add 200 count tcp from me to 78.46.89.105 80 flow 'table(fl2)'
00200 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
0:03 [2] zfscurr0# ipfw show
00200 0 0 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 617 59416 allow ip from any to any
0:03 [2] zfscurr0# telnet -s 10.0.0.92 78.46.89.105 80
Trying 78.46.89.105...
..
0:04 [2] zfscurr0# ipfw show
00200 5 272 count tcp from me to 78.46.89.105 dst-port 80 flow table(fl2)
65535 682 66733 allow ip from any to any
2014-07-31 20:08:19 +00:00
|
|
|
tc->tflags = tflags;
|
2014-06-14 10:58:39 +00:00
|
|
|
tc->ta = ta;
|
2014-06-12 09:59:11 +00:00
|
|
|
strlcpy(tc->tablename, name, sizeof(tc->tablename));
|
Add support for multi-field values inside ipfw tables.
This is the last major change in given branch.
Kernel changes:
* Use 64-bytes structures to hold multi-value variables.
* Use shared array to hold values from all tables (assume
each table algo is capable of holding 32-byte variables).
* Add some placeholders to support per-table value arrays in future.
* Use simple eventhandler-style API to ease the process of adding new
table items. Currently table addition may required multiple UH drops/
acquires which is quite tricky due to atomic table modificatio/swap
support, shared array resize, etc. Deal with it by calling special
notifier capable of rolling back state before actually performing
swap/resize operations. Original operation then restarts itself after
acquiring UH lock.
* Bump all objhash users default values to at least 64
* Fix custom hashing inside objhash.
Userland changes:
* Add support for dumping shared value array via "vlist" internal cmd.
* Some small print/fill_flags dixes to support u32 values.
* valtype is now bitmask of
<skipto|pipe|fib|nat|dscp|tag|divert|netgraph|limit|ipv4|ipv6>.
New values can hold distinct values for each of this types.
* Provide special "legacy" type which assumes all values are the same.
* More helpers/docs following..
Some examples:
3:41 [1] zfscurr0# ipfw table mimimi create valtype skipto,limit,ipv4,ipv6
3:41 [1] zfscurr0# ipfw table mimimi info
+++ table(mimimi), set(0) +++
kindex: 2, type: addr
references: 0, valtype: skipto,limit,ipv4,ipv6
algorithm: addr:radix
items: 0, size: 296
3:42 [1] zfscurr0# ipfw table mimimi add 10.0.0.5 3000,10,10.0.0.1,2a02:978:2::1
added: 10.0.0.5/32 3000,10,10.0.0.1,2a02:978:2::1
3:42 [1] zfscurr0# ipfw table mimimi list
+++ table(mimimi), set(0) +++
10.0.0.5/32 3000,0,10.0.0.1,2a02:978:2::1
2014-08-31 23:51:09 +00:00
|
|
|
/* Set "shared" value type by default */
|
|
|
|
tc->vshared = 1;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
|
|
|
/* Preallocate data structures for new tables */
|
2014-10-09 14:33:20 +00:00
|
|
|
error = ta->init(ch, &tc->astate, &tc->ti_copy, aname, tflags);
|
2014-06-12 09:59:11 +00:00
|
|
|
if (error != 0) {
|
|
|
|
free(tc, M_IPFW);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
return (tc);
|
|
|
|
}
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
/*
|
|
|
|
* Destroys table state and config.
|
|
|
|
*/
|
2014-06-12 09:59:11 +00:00
|
|
|
static void
|
|
|
|
free_table_config(struct namedobj_instance *ni, struct table_config *tc)
|
|
|
|
{
|
|
|
|
|
2014-08-11 20:00:51 +00:00
|
|
|
KASSERT(tc->linked == 0, ("free() on linked config"));
|
2015-02-05 13:49:04 +00:00
|
|
|
/* UH lock MUST NOT be held */
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-08-12 09:48:54 +00:00
|
|
|
/*
|
|
|
|
* We're using ta without any locking/referencing.
|
|
|
|
* TODO: fix this if we're going to use unloadable algos.
|
|
|
|
*/
|
2014-10-09 14:33:20 +00:00
|
|
|
tc->ta->destroy(tc->astate, &tc->ti_copy);
|
2014-06-12 09:59:11 +00:00
|
|
|
free(tc, M_IPFW);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Links @tc to @chain table named instance.
|
|
|
|
* Sets appropriate type/states in @chain table info.
|
|
|
|
*/
|
|
|
|
static void
|
2014-06-14 10:58:39 +00:00
|
|
|
link_table(struct ip_fw_chain *ch, struct table_config *tc)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_info *ti;
|
2014-06-12 09:59:11 +00:00
|
|
|
uint16_t kidx;
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
ni = CHAIN_TO_NI(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
kidx = tc->no.kidx;
|
|
|
|
|
|
|
|
ipfw_objhash_add(ni, &tc->no);
|
2014-06-14 10:58:39 +00:00
|
|
|
|
|
|
|
ti = KIDX_TO_TI(ch, kidx);
|
2014-10-09 14:33:20 +00:00
|
|
|
*ti = tc->ti_copy;
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-07-28 19:01:25 +00:00
|
|
|
/* Notify algo on real @ti address */
|
|
|
|
if (tc->ta->change_ti != NULL)
|
|
|
|
tc->ta->change_ti(tc->astate, ti);
|
|
|
|
|
2014-06-12 09:59:11 +00:00
|
|
|
tc->linked = 1;
|
2014-07-29 22:44:26 +00:00
|
|
|
tc->ta->refcnt++;
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlinks @tc from @chain table named instance.
|
|
|
|
* Zeroes states in @chain and stores them in @tc.
|
|
|
|
*/
|
|
|
|
static void
|
2014-06-14 10:58:39 +00:00
|
|
|
unlink_table(struct ip_fw_chain *ch, struct table_config *tc)
|
2014-06-12 09:59:11 +00:00
|
|
|
{
|
|
|
|
struct namedobj_instance *ni;
|
2014-06-14 10:58:39 +00:00
|
|
|
struct table_info *ti;
|
2014-06-12 09:59:11 +00:00
|
|
|
uint16_t kidx;
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
IPFW_UH_WLOCK_ASSERT(ch);
|
|
|
|
IPFW_WLOCK_ASSERT(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
ni = CHAIN_TO_NI(ch);
|
2014-06-12 09:59:11 +00:00
|
|
|
kidx = tc->no.kidx;
|
|
|
|
|
2014-06-14 10:58:39 +00:00
|
|
|
/* Clear state. @ti copy is already saved inside @tc */
|
2014-06-12 09:59:11 +00:00
|
|
|
ipfw_objhash_del(ni, &tc->no);
|
2014-06-14 10:58:39 +00:00
|
|
|
ti = KIDX_TO_TI(ch, kidx);
|
|
|
|
memset(ti, 0, sizeof(struct table_info));
|
2014-06-12 09:59:11 +00:00
|
|
|
tc->linked = 0;
|
2014-07-29 22:44:26 +00:00
|
|
|
tc->ta->refcnt--;
|
2014-07-28 19:01:25 +00:00
|
|
|
|
|
|
|
/* Notify algo on real @ti address */
|
|
|
|
if (tc->ta->change_ti != NULL)
|
|
|
|
tc->ta->change_ti(tc->astate, NULL);
|
2014-06-12 09:59:11 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 11:11:15 +00:00
|
|
|
static struct ipfw_sopt_handler scodes[] = {
|
|
|
|
{ IP_FW_TABLE_XCREATE, 0, HDIR_SET, create_table },
|
|
|
|
{ IP_FW_TABLE_XDESTROY, 0, HDIR_SET, flush_table_v0 },
|
|
|
|
{ IP_FW_TABLE_XFLUSH, 0, HDIR_SET, flush_table_v0 },
|
|
|
|
{ IP_FW_TABLE_XMODIFY, 0, HDIR_BOTH, modify_table },
|
|
|
|
{ IP_FW_TABLE_XINFO, 0, HDIR_GET, describe_table },
|
|
|
|
{ IP_FW_TABLES_XLIST, 0, HDIR_GET, list_tables },
|
|
|
|
{ IP_FW_TABLE_XLIST, 0, HDIR_GET, dump_table_v0 },
|
|
|
|
{ IP_FW_TABLE_XLIST, 1, HDIR_GET, dump_table_v1 },
|
|
|
|
{ IP_FW_TABLE_XADD, 0, HDIR_BOTH, manage_table_ent_v0 },
|
|
|
|
{ IP_FW_TABLE_XADD, 1, HDIR_BOTH, manage_table_ent_v1 },
|
|
|
|
{ IP_FW_TABLE_XDEL, 0, HDIR_BOTH, manage_table_ent_v0 },
|
|
|
|
{ IP_FW_TABLE_XDEL, 1, HDIR_BOTH, manage_table_ent_v1 },
|
|
|
|
{ IP_FW_TABLE_XFIND, 0, HDIR_GET, find_table_entry },
|
|
|
|
{ IP_FW_TABLE_XSWAP, 0, HDIR_SET, swap_table },
|
|
|
|
{ IP_FW_TABLES_ALIST, 0, HDIR_GET, list_table_algo },
|
|
|
|
{ IP_FW_TABLE_XGETSIZE, 0, HDIR_GET, get_table_size },
|
|
|
|
};
|
|
|
|
|
2016-05-06 03:18:51 +00:00
|
|
|
static int
|
2014-09-05 11:11:15 +00:00
|
|
|
destroy_table_locked(struct namedobj_instance *ni, struct named_object *no,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
unlink_table((struct ip_fw_chain *)arg, (struct table_config *)no);
|
|
|
|
if (ipfw_objhash_free_idx(ni, no->kidx) != 0)
|
|
|
|
printf("Error unlinking kidx %d from table %s\n",
|
|
|
|
no->kidx, no->name);
|
|
|
|
free_table_config(ni, (struct table_config *)no);
|
2016-05-06 03:18:51 +00:00
|
|
|
return (0);
|
2014-09-05 11:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shuts tables module down.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ipfw_destroy_tables(struct ip_fw_chain *ch, int last)
|
|
|
|
{
|
|
|
|
|
|
|
|
IPFW_DEL_SOPT_HANDLER(last, scodes);
|
2015-04-27 08:29:39 +00:00
|
|
|
IPFW_DEL_OBJ_REWRITER(last, opcodes);
|
2014-09-05 11:11:15 +00:00
|
|
|
|
|
|
|
/* Remove all tables from working set */
|
|
|
|
IPFW_UH_WLOCK(ch);
|
|
|
|
IPFW_WLOCK(ch);
|
|
|
|
ipfw_objhash_foreach(CHAIN_TO_NI(ch), destroy_table_locked, ch);
|
|
|
|
IPFW_WUNLOCK(ch);
|
|
|
|
IPFW_UH_WUNLOCK(ch);
|
|
|
|
|
|
|
|
/* Free pointers itself */
|
|
|
|
free(ch->tablestate, M_IPFW);
|
|
|
|
|
|
|
|
ipfw_table_value_destroy(ch, last);
|
|
|
|
ipfw_table_algo_destroy(ch);
|
|
|
|
|
|
|
|
ipfw_objhash_destroy(CHAIN_TO_NI(ch));
|
|
|
|
free(CHAIN_TO_TCFG(ch), M_IPFW);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Starts tables module.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipfw_init_tables(struct ip_fw_chain *ch, int first)
|
|
|
|
{
|
|
|
|
struct tables_config *tcfg;
|
|
|
|
|
|
|
|
/* Allocate pointers */
|
|
|
|
ch->tablestate = malloc(V_fw_tables_max * sizeof(struct table_info),
|
|
|
|
M_IPFW, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
tcfg = malloc(sizeof(struct tables_config), M_IPFW, M_WAITOK | M_ZERO);
|
|
|
|
tcfg->namehash = ipfw_objhash_create(V_fw_tables_max);
|
|
|
|
ch->tblcfg = tcfg;
|
|
|
|
|
|
|
|
ipfw_table_value_init(ch, first);
|
|
|
|
ipfw_table_algo_init(ch);
|
|
|
|
|
2015-04-27 08:29:39 +00:00
|
|
|
IPFW_ADD_OBJ_REWRITER(first, opcodes);
|
2014-09-05 11:11:15 +00:00
|
|
|
IPFW_ADD_SOPT_HANDLER(first, scodes);
|
|
|
|
return (0);
|
|
|
|
}
|