From patchwork Tue Apr 7 14:34:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 1267455 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 (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nwl.cc Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48xVLF27d2z9sSG for ; Wed, 8 Apr 2020 00:35:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728992AbgDGOfB (ORCPT ); Tue, 7 Apr 2020 10:35:01 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:54934 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728306AbgDGOfA (ORCPT ); Tue, 7 Apr 2020 10:35:00 -0400 Received: from localhost ([::1]:39792 helo=tatos) by orbyte.nwl.cc with esmtp (Exim 4.91) (envelope-from ) id 1jLpJb-0007e7-CG; Tue, 07 Apr 2020 16:34:59 +0200 From: Phil Sutter To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org Subject: [iptables PATCH 3/3] nft: cache: Fetch sets per table Date: Tue, 7 Apr 2020 16:34:45 +0200 Message-Id: <20200407143445.26394-4-phil@nwl.cc> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200407143445.26394-1-phil@nwl.cc> References: <20200407143445.26394-1-phil@nwl.cc> MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Kernel accepts a table name when dumping sets, so make use of that in case a table was passed to fetch_set_cache() but no set name. Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c index e042bd83bebf5..51b371c51c3f4 100644 --- a/iptables/nft-cache.c +++ b/iptables/nft-cache.c @@ -254,25 +254,31 @@ static int fetch_set_cache(struct nft_handle *h, .h = h, .t = t, }; + uint16_t flags = NLM_F_DUMP; + struct nftnl_set *s = NULL; struct nlmsghdr *nlh; char buf[16536]; int i, ret; - if (t && set) { - struct nftnl_set *s = nftnl_set_alloc(); - + if (t) { + s = nftnl_set_alloc(); if (!s) return -1; - nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, h->family, - NLM_F_ACK, h->seq); nftnl_set_set_str(s, NFTNL_SET_TABLE, t->name); - nftnl_set_set_str(s, NFTNL_SET_NAME, set); + + if (set) { + nftnl_set_set_str(s, NFTNL_SET_NAME, set); + flags = NLM_F_ACK; + } + } + + nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, + h->family, flags, h->seq); + + if (s) { nftnl_set_nlmsg_build_payload(nlh, s); nftnl_set_free(s); - } else { - nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, h->family, - NLM_F_DUMP, h->seq); } ret = mnl_talk(h, nlh, nftnl_set_list_cb, &d); @@ -282,8 +288,6 @@ static int fetch_set_cache(struct nft_handle *h, } if (t && set) { - struct nftnl_set *s; - s = nftnl_set_list_lookup_byname(h->cache->table[t->type].sets, set); set_fetch_elem_cb(s, h);