Author: ae
Date: Thu May  5 20:15:46 2016
New Revision: 299136
URL: https://svnweb.freebsd.org/changeset/base/299136

Log:
  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

Modified:
  head/sys/netpfil/ipfw/ip_fw_private.h
  head/sys/netpfil/ipfw/ip_fw_sockopt.c
  head/sys/netpfil/ipfw/ip_fw_table.c

Modified: head/sys/netpfil/ipfw/ip_fw_private.h
==============================================================================
--- head/sys/netpfil/ipfw/ip_fw_private.h       Thu May  5 19:56:18 2016        
(r299135)
+++ head/sys/netpfil/ipfw/ip_fw_private.h       Thu May  5 20:15:46 2016        
(r299136)
@@ -684,6 +684,8 @@ void ipfw_objhash_set_funcs(struct named
 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);

Modified: head/sys/netpfil/ipfw/ip_fw_sockopt.c
==============================================================================
--- head/sys/netpfil/ipfw/ip_fw_sockopt.c       Thu May  5 19:56:18 2016        
(r299135)
+++ head/sys/netpfil/ipfw/ip_fw_sockopt.c       Thu May  5 20:15:46 2016        
(r299136)
@@ -4089,8 +4089,8 @@ ipfw_objhash_lookup_name(struct namedobj
  *
  * 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_i
        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;

Modified: head/sys/netpfil/ipfw/ip_fw_table.c
==============================================================================
--- head/sys/netpfil/ipfw/ip_fw_table.c Thu May  5 19:56:18 2016        
(r299135)
+++ head/sys/netpfil/ipfw/ip_fw_table.c Thu May  5 20:15:46 2016        
(r299136)
@@ -1879,7 +1879,6 @@ create_table(struct ip_fw_chain *ch, ip_
 /*
  * 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.
@@ -2927,44 +2926,6 @@ check_table_name(const char *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.
  * Note @ti structure contains unchecked data from userland.
@@ -2981,7 +2942,8 @@ find_table_err(struct namedobj_instance 
        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 *c
        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;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to