From patchwork Wed Aug 16 20:43:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Leblond X-Patchwork-Id: 802248 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xXj7L1SK4z9t32 for ; Thu, 17 Aug 2017 07:25:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752648AbdHPVZd (ORCPT ); Wed, 16 Aug 2017 17:25:33 -0400 Received: from home.regit.org ([37.187.126.138]:40694 "EHLO home.regit.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659AbdHPVZd (ORCPT ); Wed, 16 Aug 2017 17:25:33 -0400 Received: from [2a01:e34:ee97:b130:c685:8ff:feb3:c9c8] (helo=localhost.localdomain) by home.regit.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1di5BR-0006tM-A4; Wed, 16 Aug 2017 22:44:58 +0200 From: Eric Leblond To: pablo@netfilter.org Cc: netfilter-devel@vger.kernel.org, Eric Leblond Subject: [nft PATH 13/16] libnftables: set max_errors to 1 in library Date: Wed, 16 Aug 2017 22:43:07 +0200 Message-Id: <20170816204310.3371-14-eric@regit.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170816204310.3371-1-eric@regit.org> References: <20170816204310.3371-1-eric@regit.org> X-Spam-Score: -1.0 (-) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org As memory handling is defficient if we don't do so, we can't really use a non 1 value for the parameter in the library due to memory leak. Also this is not a real issue as programmatically a user of the library should only encounter one error at a time. This patch also introduces a function that can be used to modify the max_errors parameter. It is used in main to keep the existing behavior. Signed-off-by: Eric Leblond --- include/nftables/nftables.h | 1 + src/libnftables.c | 8 +++++++- src/main.c | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/nftables/nftables.h b/include/nftables/nftables.h index 2ddb38a..f419884 100644 --- a/include/nftables/nftables.h +++ b/include/nftables/nftables.h @@ -22,6 +22,7 @@ enum nftables_exit_codes { }; void nft_global_init(void); +int nft_global_set_max_errors(unsigned int errors); void nft_global_deinit(void); struct nft_ctx *nft_context_new(void); diff --git a/src/libnftables.c b/src/libnftables.c index 08050e5..c50c068 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -25,7 +25,7 @@ #include -unsigned int max_errors = 10; +unsigned int max_errors = 1; unsigned int numeric_output; unsigned int ip2name_output; unsigned int handle_output; @@ -58,6 +58,12 @@ void nft_global_deinit(void) mark_table_exit(); } +int nft_global_set_max_errors(unsigned int errors) +{ + max_errors = errors; + return 0; +} + __attribute__((format(printf, 2, 0))) static int nft_print(void *ctx, const char *fmt, ...) { diff --git a/src/main.c b/src/main.c index a6305cc..bb08c31 100644 --- a/src/main.c +++ b/src/main.c @@ -192,6 +192,7 @@ int main(int argc, char * const *argv) struct nft_ctx *nft; nft_global_init(); + nft_global_set_max_errors(10); nft = nft_context_new(); while (1) { val = getopt_long(argc, argv, OPTSTRING, options, NULL);