From patchwork Sun Sep 3 22:03:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Leblond X-Patchwork-Id: 809368 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 3xln7Y2YFtz9sPs for ; Mon, 4 Sep 2017 08:04:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753010AbdICWEI (ORCPT ); Sun, 3 Sep 2017 18:04:08 -0400 Received: from home.regit.org ([37.187.126.138]:38256 "EHLO home.regit.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbdICWEH (ORCPT ); Sun, 3 Sep 2017 18:04:07 -0400 Received: from [2a01:e35:2fb6:1160:f022:11:465e:d69b] (helo=ice-age2.regit.org) by home.regit.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1doczt-0002FD-O2; Mon, 04 Sep 2017 00:04:06 +0200 From: Eric Leblond To: pablo@netfilter.org Cc: netfilter-devel@vger.kernel.org, Eric Leblond Subject: [nft PATCH 1/2] src: add flags fo nft_ctx_new Date: Mon, 4 Sep 2017 00:03:55 +0200 Message-Id: <20170903220356.20178-2-eric@regit.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170903220356.20178-1-eric@regit.org> References: <20170903220356.20178-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 By adding flags to nft_ctx_new, we will have a minimum capabilities of changing the way the nft_ctx is created. For now, this patch uses a simple value that allow the user to specify that he will handle netlink by himself. Signed-off-by: Eric Leblond --- include/nftables.h | 4 ++++ src/main.c | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/nftables.h b/include/nftables.h index 5035567..7c4e93f 100644 --- a/include/nftables.h +++ b/include/nftables.h @@ -49,8 +49,12 @@ struct nft_ctx { struct output_ctx output; bool check; struct nft_cache cache; + uint32_t flags; }; +#define NFT_CTX_CUSTOM_NETLINK (1<<0) +#define NFT_CTX_DEFAULT 0 + enum nftables_exit_codes { NFT_EXIT_SUCCESS = 0, NFT_EXIT_FAILURE = 1, diff --git a/src/main.c b/src/main.c index fce9bfe..94f8a47 100644 --- a/src/main.c +++ b/src/main.c @@ -281,7 +281,12 @@ static void nft_exit(void) mark_table_exit(); } -static struct nft_ctx *nft_ctx_new(void) +static void nft_ctx_netlink_init(struct nft_ctx *ctx) +{ + ctx->nf_sock = netlink_open_sock(); +} + +static struct nft_ctx *nft_ctx_new(uint32_t flags) { struct nft_ctx *ctx; @@ -292,6 +297,10 @@ static struct nft_ctx *nft_ctx_new(void) ctx->num_include_paths = 1; ctx->parser_max_errors = 10; init_list_head(&ctx->cache.list); + ctx->flags = flags; + + if (! (flags & NFT_CTX_CUSTOM_NETLINK)) + nft_ctx_netlink_init(ctx); return ctx; } @@ -307,11 +316,6 @@ static void nft_ctx_free(const struct nft_ctx *ctx) nft_exit(); } -static void nft_ctx_netlink_init(struct nft_ctx *ctx) -{ - ctx->nf_sock = netlink_open_sock(); -} - static int nft_run_cmd_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen) { @@ -367,9 +371,7 @@ int main(int argc, char * const *argv) struct parser_state state; int i, val, rc; - nft = nft_ctx_new(); - - nft_ctx_netlink_init(nft); + nft = nft_ctx_new(NFT_CTX_DEFAULT); while (1) { val = getopt_long(argc, argv, OPTSTRING, options, NULL);