Changeset View
Changeset View
Standalone View
Standalone View
sys/netpfil/ipfw/ip_fw_table_value.c
| Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | static uint32_t hash_table_value(struct namedobj_instance *ni, const void *key, | ||||
| uint32_t kopt); | uint32_t kopt); | ||||
| static int cmp_table_value(struct named_object *no, const void *key, | static int cmp_table_value(struct named_object *no, const void *key, | ||||
| uint32_t kopt); | uint32_t kopt); | ||||
| static int list_table_values(struct ip_fw_chain *ch, ip_fw3_opheader *op3, | static int list_table_values(struct ip_fw_chain *ch, ip_fw3_opheader *op3, | ||||
| struct sockopt_data *sd); | struct sockopt_data *sd); | ||||
| static struct ipfw_sopt_handler scodes[] = { | static struct ipfw_sopt_handler scodes[] = { | ||||
| { IP_FW_TABLE_VLIST, 0, HDIR_GET, list_table_values }, | { IP_FW_TABLE_VLIST, IP_FW3_OPVER, HDIR_GET, list_table_values }, | ||||
| }; | }; | ||||
| #define CHAIN_TO_VI(chain) (CHAIN_TO_TCFG(chain)->valhash) | #define CHAIN_TO_VI(chain) (CHAIN_TO_TCFG(chain)->valhash) | ||||
| struct table_val_link | struct table_val_link | ||||
| { | { | ||||
| struct named_object no; | struct named_object no; | ||||
| struct table_value *pval; /* Pointer to real table value */ | struct table_value *pval; /* Pointer to real table value */ | ||||
| }; | }; | ||||
| #define VALDATA_START_SIZE 64 /* Allocate 64-items array by default */ | #define VALDATA_START_SIZE 64 /* Allocate 64-items array by default */ | ||||
| #define VALDATA_HASH_SIZE 65536 | |||||
| struct vdump_args { | struct vdump_args { | ||||
| struct ip_fw_chain *ch; | struct ip_fw_chain *ch; | ||||
| struct sockopt_data *sd; | struct sockopt_data *sd; | ||||
| struct table_value *pval; | struct table_value *pval; | ||||
| int error; | int error; | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * Allocate new value index in either shared or per-table array. | * Allocate new value index in either shared or per-table array. | ||||
| * Function may drop/reacquire UH lock. | * Function may drop/reacquire UH lock. | ||||
| * | * | ||||
| * Returns 0 on success. | * Returns 0 on success. | ||||
| */ | */ | ||||
| static int | static int | ||||
| alloc_table_vidx(struct ip_fw_chain *ch, struct tableop_state *ts, | alloc_table_vidx(struct ip_fw_chain *ch, struct tableop_state *ts, | ||||
| struct namedobj_instance *vi, uint16_t *pvidx, uint8_t flags) | struct namedobj_instance *vi, uint32_t *pvidx, uint8_t flags) | ||||
| { | { | ||||
| int error, vlimit; | int error, vlimit; | ||||
| uint16_t vidx; | uint32_t vidx; | ||||
| IPFW_UH_WLOCK_ASSERT(ch); | IPFW_UH_WLOCK_ASSERT(ch); | ||||
| error = ipfw_objhash_alloc_idx(vi, &vidx); | error = ipfw_objhash_alloc_idx(vi, &vidx); | ||||
| if (error != 0) { | if (error != 0) { | ||||
| /* | /* | ||||
| * We need to resize array. This involves | * We need to resize array. This involves | ||||
| * lock/unlock, so we need to check "modified" | * lock/unlock, so we need to check "modified" | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| int | int | ||||
| ipfw_link_table_values(struct ip_fw_chain *ch, struct tableop_state *ts, | ipfw_link_table_values(struct ip_fw_chain *ch, struct tableop_state *ts, | ||||
| uint8_t flags) | uint8_t flags) | ||||
| { | { | ||||
| int error, i, found; | int error, i, found; | ||||
| struct namedobj_instance *vi; | struct namedobj_instance *vi; | ||||
| struct table_config *tc; | struct table_config *tc; | ||||
| struct tentry_info *tei, *ptei; | struct tentry_info *tei, *ptei; | ||||
| uint32_t count, vlimit; | uint32_t count, vidx, vlimit; | ||||
| uint16_t vidx; | |||||
| struct table_val_link *ptv; | struct table_val_link *ptv; | ||||
| struct table_value tval, *pval; | struct table_value tval, *pval; | ||||
| /* | /* | ||||
| * Stage 1: reference all existing values and | * Stage 1: reference all existing values and | ||||
| * save their indices. | * save their indices. | ||||
| */ | */ | ||||
| IPFW_UH_WLOCK_ASSERT(ch); | IPFW_UH_WLOCK_ASSERT(ch); | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | for (i = 0; i < count; i++) { | ||||
| pval[vidx].refcnt = 1; | pval[vidx].refcnt = 1; | ||||
| ipfw_objhash_add(vi, &ptv->no); | ipfw_objhash_add(vi, &ptv->no); | ||||
| } | } | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| /* | /* | ||||
| * Compatibility function used to import data from old | |||||
| * IP_FW_TABLE_ADD / IP_FW_TABLE_XADD opcodes. | |||||
| */ | |||||
| void | |||||
| ipfw_import_table_value_legacy(uint32_t value, struct table_value *v) | |||||
| { | |||||
| memset(v, 0, sizeof(*v)); | |||||
| v->tag = value; | |||||
| v->pipe = value; | |||||
| v->divert = value; | |||||
| v->skipto = value; | |||||
| v->netgraph = value; | |||||
| v->fib = value; | |||||
| v->nat = value; | |||||
| v->nh4 = value; /* host format */ | |||||
| v->dscp = value; | |||||
| v->limit = value; | |||||
| v->mark = value; | |||||
| } | |||||
| /* | |||||
| * Export data to legacy table dumps opcodes. | |||||
| */ | |||||
| uint32_t | |||||
| ipfw_export_table_value_legacy(struct table_value *v) | |||||
| { | |||||
| /* | |||||
| * TODO: provide more compatibility depending on | |||||
| * vmask value. | |||||
| */ | |||||
| return (v->tag); | |||||
| } | |||||
| /* | |||||
| * Imports table value from current userland format. | * Imports table value from current userland format. | ||||
| * Saves value in kernel format to the same place. | * Saves value in kernel format to the same place. | ||||
| */ | */ | ||||
| void | void | ||||
| ipfw_import_table_value_v1(ipfw_table_value *iv) | ipfw_import_table_value_v1(ipfw_table_value *iv) | ||||
| { | { | ||||
| struct table_value v; | struct table_value v; | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | ipfw_table_value_init(struct ip_fw_chain *ch, int first) | ||||
| struct tables_config *tcfg; | struct tables_config *tcfg; | ||||
| ch->valuestate = malloc(VALDATA_START_SIZE * sizeof(struct table_value), | ch->valuestate = malloc(VALDATA_START_SIZE * sizeof(struct table_value), | ||||
| M_IPFW, M_WAITOK | M_ZERO); | M_IPFW, M_WAITOK | M_ZERO); | ||||
| tcfg = ch->tblcfg; | tcfg = ch->tblcfg; | ||||
| tcfg->val_size = VALDATA_START_SIZE; | tcfg->val_size = VALDATA_START_SIZE; | ||||
| tcfg->valhash = ipfw_objhash_create(tcfg->val_size); | tcfg->valhash = ipfw_objhash_create(tcfg->val_size, VALDATA_HASH_SIZE); | ||||
| ipfw_objhash_set_funcs(tcfg->valhash, hash_table_value, | ipfw_objhash_set_funcs(tcfg->valhash, hash_table_value, | ||||
| cmp_table_value); | cmp_table_value); | ||||
| IPFW_ADD_SOPT_HANDLER(first, scodes); | IPFW_ADD_SOPT_HANDLER(first, scodes); | ||||
| } | } | ||||
| static int | static int | ||||
| destroy_value(struct namedobj_instance *ni, struct named_object *no, | destroy_value(struct namedobj_instance *ni, struct named_object *no, | ||||
| Show All 17 Lines | |||||