From owner-svn-src-projects@FreeBSD.ORG Fri Aug 8 06:36:27 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 E168BC01 for ; Fri, 8 Aug 2014 06:36:27 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C1CB12268 for ; Fri, 8 Aug 2014 06:36:27 +0000 (UTC) Received: from melifaro (uid 1268) (envelope-from melifaro@FreeBSD.org) id 20ae by svn.freebsd.org (DragonFly Mail Agent v0.9+); Fri, 08 Aug 2014 06:36:26 +0000 From: Alexander V. Chernikov Date: Fri, 8 Aug 2014 06:36:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r269704 - in projects/ipfw: sbin/ipfw sys/netinet sys/netpfil/ipfw X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <53e46feb.20ae.3a588865@svn.freebsd.org> X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.18 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: Fri, 08 Aug 2014 06:36:28 -0000 Author: melifaro Date: Fri Aug 8 06:36:26 2014 New Revision: 269704 URL: http://svnweb.freebsd.org/changeset/base/269704 Log: Remove IP_FW_TABLES_XGETSIZE opcode. It is superseded by IP_FW_TABLES_XLIST. Modified: projects/ipfw/sbin/ipfw/tables.c projects/ipfw/sys/netinet/ip_fw.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/sbin/ipfw/tables.c ============================================================================== --- projects/ipfw/sbin/ipfw/tables.c Fri Aug 8 06:30:17 2014 (r269703) +++ projects/ipfw/sbin/ipfw/tables.c Fri Aug 8 06:36:26 2014 (r269704) @@ -1147,41 +1147,46 @@ tablename_cmp(const void *a, const void static int tables_foreach(table_cb_t *f, void *arg, int sort) { - ipfw_obj_lheader req, *olh; + ipfw_obj_lheader *olh; ipfw_xtable_info *info; size_t sz; int i, error; - memset(&req, 0, sizeof(req)); - sz = sizeof(req); - - if ((error = do_get3(IP_FW_TABLES_XGETSIZE, &req.opheader, &sz)) != 0) - return (errno); + /* Start with reasonable default */ + sz = sizeof(*olh) + 16 * sizeof(ipfw_xtable_info); - sz = req.size; - if ((olh = calloc(1, sz)) == NULL) - return (ENOMEM); + for (;;) { + if ((olh = calloc(1, sz)) == NULL) + return (ENOMEM); + + olh->size = sz; + error = do_get3(IP_FW_TABLES_XLIST, &olh->opheader, &sz); + if (error == ENOMEM) { + sz = olh->size; + free(olh); + continue; + } else if (error != 0) { + free(olh); + return (error); + } - olh->size = sz; - if ((error = do_get3(IP_FW_TABLES_XLIST, &olh->opheader, &sz)) != 0) { - free(olh); - return (errno); - } + if (sort != 0) + qsort(olh + 1, olh->count, olh->objsize, tablename_cmp); - if (sort != 0) - qsort(olh + 1, olh->count, olh->objsize, tablename_cmp); + info = (ipfw_xtable_info *)(olh + 1); + for (i = 0; i < olh->count; i++) { + error = f(info, arg); /* Ignore errors for now */ + info = (ipfw_xtable_info *)((caddr_t)info + olh->objsize); + } - info = (ipfw_xtable_info *)(olh + 1); - for (i = 0; i < olh->count; i++) { - error = f(info, arg); /* Ignore errors for now */ - info = (ipfw_xtable_info *)((caddr_t)info + olh->objsize); + free(olh); + break; } - free(olh); - return (0); } + /* * Retrieves all entries for given table @i in * eXtended format. Assumes buffer of size Modified: projects/ipfw/sys/netinet/ip_fw.h ============================================================================== --- projects/ipfw/sys/netinet/ip_fw.h Fri Aug 8 06:30:17 2014 (r269703) +++ projects/ipfw/sys/netinet/ip_fw.h Fri Aug 8 06:36:26 2014 (r269704) @@ -79,7 +79,6 @@ typedef struct _ip_fw3_opheader { #define IP_FW_TABLE_XGETSIZE 88 /* get table size (deprecated) */ #define IP_FW_TABLE_XLIST 89 /* list table contents */ #define IP_FW_TABLE_XDESTROY 90 /* destroy table */ -#define IP_FW_TABLES_XGETSIZE 91 /* get size for tables list */ #define IP_FW_TABLES_XLIST 92 /* list all tables */ #define IP_FW_TABLE_XINFO 93 /* request info for one table */ #define IP_FW_TABLE_XFLUSH 94 /* flush table data */ Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c Fri Aug 8 06:30:17 2014 (r269703) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_sockopt.c Fri Aug 8 06:36:26 2014 (r269704) @@ -2325,10 +2325,6 @@ ipfw_ctl3(struct sockopt *sopt) error = ipfw_describe_table(chain, &sdata); break; - case IP_FW_TABLES_XGETSIZE: - error = ipfw_listsize_tables(chain, &sdata); - break; - case IP_FW_TABLES_XLIST: error = ipfw_list_tables(chain, &sdata); break; Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Fri Aug 8 06:30:17 2014 (r269703) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Fri Aug 8 06:36:26 2014 (r269704) @@ -1115,32 +1115,6 @@ ipfw_lookup_table_extended(struct ip_fw_ */ /* - * Get buffer size needed to list info for all tables. - * Data layout (v0)(current): - * Request: [ empty ], size = sizeof(ipfw_obj_lheader) - * Reply: [ ipfw_obj_lheader ] - * - * Returns 0 on success - */ -int -ipfw_listsize_tables(struct ip_fw_chain *ch, struct sockopt_data *sd) -{ - struct _ipfw_obj_lheader *olh; - - olh = (struct _ipfw_obj_lheader *)ipfw_get_sopt_header(sd,sizeof(*olh)); - if (olh == NULL) - return (EINVAL); - - olh->size = sizeof(*olh); /* Make export_table store needed size */ - - IPFW_UH_RLOCK(ch); - export_tables(ch, olh, sd); - IPFW_UH_RUNLOCK(ch); - - return (0); -} - -/* * Lists all tables currently available in kernel. * Data layout (v0)(current): * Request: [ ipfw_obj_lheader ], size = ipfw_obj_lheader.size @@ -1570,6 +1544,9 @@ export_table_internal(struct namedobj_in /* * Export all tables as ipfw_xtable_info structures to * storage provided by @sd. + * + * If supplied buffer is too small, fills in required size + * and returns ENOMEM. * Returns 0 on success. */ static int Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Fri Aug 8 06:30:17 2014 (r269703) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Fri Aug 8 06:36:26 2014 (r269704) @@ -137,7 +137,6 @@ void ipfw_table_algo_destroy(struct ip_f /* direct ipfw_ctl handlers */ -int ipfw_listsize_tables(struct ip_fw_chain *ch, struct sockopt_data *sd); int ipfw_list_tables(struct ip_fw_chain *ch, struct sockopt_data *sd); int ipfw_dump_table(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);