Rename find_name_tlv_type() to ipfw_find_name_tlv_type() and make it

global. Use it in ip_fw_table.c instead of find_name_tlv() to reduce
duplicated code.

Obtained from:	Yandex LLC
Sponsored by:	Yandex LLC
This commit is contained in:
ae 2016-05-05 20:15:46 +00:00
parent fa522a56a9
commit 59075b2688
3 changed files with 9 additions and 44 deletions

View File

@ -684,6 +684,8 @@ void ipfw_objhash_set_funcs(struct namedobj_instance *ni,
int ipfw_objhash_find_type(struct namedobj_instance *ni, struct tid_info *ti,
uint32_t etlv, struct named_object **pno);
void ipfw_export_obj_ntlv(struct named_object *no, ipfw_obj_ntlv *ntlv);
ipfw_obj_ntlv *ipfw_find_name_tlv_type(void *tlvs, int len, uint16_t uidx,
uint32_t etlv);
void ipfw_init_obj_rewriter(void);
void ipfw_destroy_obj_rewriter(void);
void ipfw_add_obj_rewriter(struct opcode_obj_rewrite *rw, size_t count);

View File

@ -4089,8 +4089,8 @@ ipfw_objhash_lookup_name(struct namedobj_instance *ni, uint32_t set, char *name)
*
* Returns pointer to found TLV or NULL.
*/
static ipfw_obj_ntlv *
find_name_tlv_type(void *tlvs, int len, uint16_t uidx, uint32_t etlv)
ipfw_obj_ntlv *
ipfw_find_name_tlv_type(void *tlvs, int len, uint16_t uidx, uint32_t etlv)
{
ipfw_obj_ntlv *ntlv;
uintptr_t pa, pe;
@ -4145,7 +4145,7 @@ ipfw_objhash_find_type(struct namedobj_instance *ni, struct tid_info *ti,
if (ti->tlvs == NULL)
return (EINVAL);
ntlv = find_name_tlv_type(ti->tlvs, ti->tlen, ti->uidx, etlv);
ntlv = ipfw_find_name_tlv_type(ti->tlvs, ti->tlen, ti->uidx, etlv);
if (ntlv == NULL)
return (EINVAL);
name = ntlv->name;

View File

@ -1879,7 +1879,6 @@ create_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
/*
* Creates new table based on @ti and @aname.
*
* Relies on table name checking inside find_name_tlv()
* Assume @aname to be checked and valid.
* Stores allocated table kidx inside @pkidx (if non-NULL).
* Reference created table if @compat is non-zero.
@ -2926,44 +2925,6 @@ check_table_name(const char *name)
return (ipfw_check_object_name_generic(name));
}
/*
* Find tablename TLV by @uid.
* Check @tlvs for valid data inside.
*
* Returns pointer to found TLV or NULL.
*/
static ipfw_obj_ntlv *
find_name_tlv(void *tlvs, int len, uint16_t uidx)
{
ipfw_obj_ntlv *ntlv;
uintptr_t pa, pe;
int l;
pa = (uintptr_t)tlvs;
pe = pa + len;
l = 0;
for (; pa < pe; pa += l) {
ntlv = (ipfw_obj_ntlv *)pa;
l = ntlv->head.length;
if (l != sizeof(*ntlv))
return (NULL);
if (ntlv->head.type != IPFW_TLV_TBL_NAME)
continue;
if (ntlv->idx != uidx)
continue;
if (check_table_name(ntlv->name) != 0)
return (NULL);
return (ntlv);
}
return (NULL);
}
/*
* Finds table config based on either legacy index
* or name in ntlv.
@ -2981,7 +2942,8 @@ find_table_err(struct namedobj_instance *ni, struct tid_info *ti,
uint32_t set;
if (ti->tlvs != NULL) {
ntlv = find_name_tlv(ti->tlvs, ti->tlen, ti->uidx);
ntlv = ipfw_find_name_tlv_type(ti->tlvs, ti->tlen, ti->uidx,
IPFW_TLV_TBL_NAME);
if (ntlv == NULL)
return (EINVAL);
name = ntlv->name;
@ -3039,7 +3001,8 @@ alloc_table_config(struct ip_fw_chain *ch, struct tid_info *ti,
uint32_t set;
if (ti->tlvs != NULL) {
ntlv = find_name_tlv(ti->tlvs, ti->tlen, ti->uidx);
ntlv = ipfw_find_name_tlv_type(ti->tlvs, ti->tlen, ti->uidx,
IPFW_TLV_TBL_NAME);
if (ntlv == NULL)
return (NULL);
name = ntlv->name;