From owner-svn-src-projects@FreeBSD.ORG Wed Sep 3 21:57:07 2014 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BD469E70; Wed, 3 Sep 2014 21:57:07 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9E05C1C03; Wed, 3 Sep 2014 21:57:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83Lv7Wx089034; Wed, 3 Sep 2014 21:57:07 GMT (envelope-from melifaro@FreeBSD.org) Received: (from melifaro@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s83Lv6m0089028; Wed, 3 Sep 2014 21:57:06 GMT (envelope-from melifaro@FreeBSD.org) Message-Id: <201409032157.s83Lv6m0089028@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: melifaro set sender to melifaro@FreeBSD.org using -f From: "Alexander V. Chernikov" Date: Wed, 3 Sep 2014 21:57:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r271056 - projects/ipfw/sys/netpfil/ipfw X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 21:57:07 -0000 Author: melifaro Date: Wed Sep 3 21:57:06 2014 New Revision: 271056 URL: http://svnweb.freebsd.org/changeset/base/271056 Log: Be consistent and use same arguments for ctl3 opcodes. Move legacy IP_FW_TABLE_XGETSIZE handling to separate function. Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_iface.c projects/ipfw/sys/netpfil/ipfw/ip_fw_private.h projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_iface.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_iface.c Wed Sep 3 21:45:39 2014 (r271055) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_iface.c Wed Sep 3 21:57:06 2014 (r271056) @@ -484,7 +484,8 @@ export_iface_internal(struct namedobj_in * Returns 0 on success */ int -ipfw_list_ifaces(struct ip_fw_chain *ch, struct sockopt_data *sd) +ipfw_list_ifaces(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd) { struct namedobj_instance *ii; struct _ipfw_obj_lheader *olh; Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_private.h ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_private.h Wed Sep 3 21:45:39 2014 (r271055) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_private.h Wed Sep 3 21:57:06 2014 (r271056) @@ -520,7 +520,8 @@ int ipfw_iface_ref(struct ip_fw_chain *c void ipfw_iface_unref(struct ip_fw_chain *ch, struct ipfw_ifc *ic); void ipfw_iface_add_notify(struct ip_fw_chain *ch, struct ipfw_ifc *ic); void ipfw_iface_del_notify(struct ip_fw_chain *ch, struct ipfw_ifc *ic); -int ipfw_list_ifaces(struct ip_fw_chain *ch, struct sockopt_data *sd); +int ipfw_list_ifaces(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd); /* In ip_fw_sockopt.c */ void ipfw_init_skipto_cache(struct ip_fw_chain *chain); Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c Wed Sep 3 21:45:39 2014 (r271055) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c Wed Sep 3 21:57:06 2014 (r271056) @@ -1926,7 +1926,8 @@ dump_static_rules(struct ip_fw_chain *ch * Returns 0 on success. */ static int -dump_config(struct ip_fw_chain *chain, struct sockopt_data *sd) +dump_config(struct ip_fw_chain *chain, ip_fw3_opheader *op3, + struct sockopt_data *sd) { ipfw_cfg_lheader *hdr; struct ip_fw *rule; @@ -2436,7 +2437,7 @@ ipfw_ctl3(struct sockopt *sopt) switch (opt) { case IP_FW_XGET: - error = dump_config(chain, &sdata); + error = dump_config(chain, op3, &sdata); break; case IP_FW_XADD: @@ -2463,7 +2464,7 @@ ipfw_ctl3(struct sockopt *sopt) break; case IP_FW_XIFLIST: - error = ipfw_list_ifaces(chain, &sdata); + error = ipfw_list_ifaces(chain, op3, &sdata); break; /*--- TABLE opcodes ---*/ @@ -2481,11 +2482,11 @@ ipfw_ctl3(struct sockopt *sopt) break; case IP_FW_TABLE_XINFO: - error = ipfw_describe_table(chain, &sdata); + error = ipfw_describe_table(chain, op3, &sdata); break; case IP_FW_TABLES_XLIST: - error = ipfw_list_tables(chain, &sdata); + error = ipfw_list_tables(chain, op3, &sdata); break; case IP_FW_TABLE_XLIST: @@ -2506,7 +2507,7 @@ ipfw_ctl3(struct sockopt *sopt) break; case IP_FW_TABLES_ALIST: - error = ipfw_list_table_algo(chain, &sdata); + error = ipfw_list_table_algo(chain, op3, &sdata); break; case IP_FW_TABLE_VLIST: @@ -2514,26 +2515,7 @@ ipfw_ctl3(struct sockopt *sopt) break; case IP_FW_TABLE_XGETSIZE: - { - uint32_t *tbl; - struct tid_info ti; - - if (IP_FW3_OPLENGTH(sopt) < sizeof(uint32_t)) { - error = EINVAL; - break; - } - - tbl = (uint32_t *)(op3 + 1); - - memset(&ti, 0, sizeof(ti)); - ti.uidx = *tbl; - IPFW_UH_RLOCK(chain); - error = ipfw_count_xtable(chain, &ti, tbl); - IPFW_UH_RUNLOCK(chain); - if (error) - break; - error = sooptcopyout(sopt, op3, sopt->sopt_valsize); - } + error = ipfw_get_table_size(chain, op3, &sdata); break; default: Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Wed Sep 3 21:45:39 2014 (r271055) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Wed Sep 3 21:57:06 2014 (r271056) @@ -1754,7 +1754,8 @@ ipfw_lookup_table_extended(struct ip_fw_ * Returns 0 on success */ int -ipfw_list_tables(struct ip_fw_chain *ch, struct sockopt_data *sd) +ipfw_list_tables(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd) { struct _ipfw_obj_lheader *olh; int error; @@ -1781,7 +1782,8 @@ ipfw_list_tables(struct ip_fw_chain *ch, * Returns 0 on success. */ int -ipfw_describe_table(struct ip_fw_chain *ch, struct sockopt_data *sd) +ipfw_describe_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd) { struct _ipfw_obj_header *oh; struct table_config *tc; @@ -2390,6 +2392,32 @@ ipfw_dump_table_v0(struct ip_fw_chain *c } /* + * Legacy function to retrieve number of items in table. + */ +int +ipfw_get_table_size(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + 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); +} + +/* * Legacy IP_FW_TABLE_GETSIZE handler */ int @@ -2773,7 +2801,8 @@ ipfw_del_table_algo(struct ip_fw_chain * * Returns 0 on success */ int -ipfw_list_table_algo(struct ip_fw_chain *ch, struct sockopt_data *sd) +ipfw_list_table_algo(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd) { struct _ipfw_obj_lheader *olh; struct tables_config *tcfg; Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Wed Sep 3 21:45:39 2014 (r271055) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Wed Sep 3 21:57:06 2014 (r271056) @@ -163,10 +163,12 @@ void ipfw_table_algo_destroy(struct ip_f /* direct ipfw_ctl handlers */ -int ipfw_list_tables(struct ip_fw_chain *ch, struct sockopt_data *sd); +int ipfw_list_tables(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd); int ipfw_dump_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd); -int ipfw_describe_table(struct ip_fw_chain *ch, struct sockopt_data *sd); +int ipfw_describe_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd); int ipfw_find_table_entry(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd); @@ -178,7 +180,8 @@ int ipfw_manage_table_ent(struct ip_fw_c struct sockopt_data *sd); int ipfw_flush_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd); -int ipfw_list_table_algo(struct ip_fw_chain *ch, struct sockopt_data *sd); +int ipfw_list_table_algo(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd); int ipfw_swap_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd); /* Exported to support legacy opcodes */ @@ -189,6 +192,8 @@ int del_table_entry(struct ip_fw_chain * int flush_table(struct ip_fw_chain *ch, struct tid_info *ti); void ipfw_import_table_value_legacy(uint32_t value, struct table_value *v); uint32_t ipfw_export_table_value_legacy(struct table_value *v); +int ipfw_get_table_size(struct ip_fw_chain *ch, ip_fw3_opheader *op3, + struct sockopt_data *sd); /* ipfw_table_value.c functions */ int ipfw_list_table_values(struct ip_fw_chain *ch, ip_fw3_opheader *op3,