diff options
author | Andrey V. Elsukov <ae@FreeBSD.org> | 2016-08-13 15:48:56 +0000 |
---|---|---|
committer | Andrey V. Elsukov <ae@FreeBSD.org> | 2016-08-13 15:48:56 +0000 |
commit | 6951cecf71368b1c2da9a262ddc918352b1bf9b2 (patch) | |
tree | 6f31bbfa808eaa4a661749e6b4f094a7aa5ea937 /sys/netpfil | |
parent | 56132dcc0d6f2227a9f48fe1c1dce9bec9508f35 (diff) | |
download | src-6951cecf71368b1c2da9a262ddc918352b1bf9b2.tar.gz src-6951cecf71368b1c2da9a262ddc918352b1bf9b2.zip |
Add three helper function to manage tables from external modules.
ipfw_objhash_lookup_table_kidx does lookup kernel index of table;
ipfw_ref_table/ipfw_unref_table takes and releases reference to table.
Obtained from: Yandex LLC
Sponsored by: Yandex LLC
Notes
Notes:
svn path=/head/; revision=304043
Diffstat (limited to 'sys/netpfil')
-rw-r--r-- | sys/netpfil/ipfw/ip_fw_private.h | 8 | ||||
-rw-r--r-- | sys/netpfil/ipfw/ip_fw_table.c | 51 |
2 files changed, 57 insertions, 2 deletions
diff --git a/sys/netpfil/ipfw/ip_fw_private.h b/sys/netpfil/ipfw/ip_fw_private.h index 3b7c0aa43278..3b483625c86e 100644 --- a/sys/netpfil/ipfw/ip_fw_private.h +++ b/sys/netpfil/ipfw/ip_fw_private.h @@ -743,8 +743,12 @@ typedef int (table_lookup_t)(struct table_info *ti, void *key, uint32_t keylen, int ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, uint32_t *val); -int ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, uint16_t plen, - void *paddr, uint32_t *val); +int ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, + uint16_t plen, void *paddr, uint32_t *val); +struct named_object *ipfw_objhash_lookup_table_kidx(struct ip_fw_chain *ch, + uint16_t kidx); +int ipfw_ref_table(struct ip_fw_chain *ch, ipfw_obj_ntlv *ntlv, uint16_t *kidx); +void ipfw_unref_table(struct ip_fw_chain *ch, uint16_t kidx); int ipfw_init_tables(struct ip_fw_chain *ch, int first); int ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables); int ipfw_switch_tables_namespace(struct ip_fw_chain *ch, unsigned int nsets); diff --git a/sys/netpfil/ipfw/ip_fw_table.c b/sys/netpfil/ipfw/ip_fw_table.c index 68225b3bba29..000a8df88457 100644 --- a/sys/netpfil/ipfw/ip_fw_table.c +++ b/sys/netpfil/ipfw/ip_fw_table.c @@ -1602,6 +1602,57 @@ ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables) } /* + * 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--; +} + +/* * Lookup an IP @addr in table @tbl. * Stores found value in @val. * |