Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDB05C04AB6 for ; Tue, 28 May 2019 21:03:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E9A021019 for ; Tue, 28 May 2019 21:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbfE1VDs (ORCPT ); Tue, 28 May 2019 17:03:48 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:38470 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727701AbfE1VDr (ORCPT ); Tue, 28 May 2019 17:03:47 -0400 Received: from localhost ([::1]:51558 helo=tatos) by orbyte.nwl.cc with esmtp (Exim 4.91) (envelope-from ) id 1hVjG6-0002KL-CE; Tue, 28 May 2019 23:03:46 +0200 From: Phil Sutter To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org, Eric Garver Subject: [nft PATCH v4 5/7] rule: Introduce rule_lookup_by_index() Date: Tue, 28 May 2019 23:03:21 +0200 Message-Id: <20190528210323.14605-6-phil@nwl.cc> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528210323.14605-1-phil@nwl.cc> References: <20190528210323.14605-1-phil@nwl.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org In contrast to rule_lookup(), this function returns a chain's rule at a given index instead of by handle. Signed-off-by: Phil Sutter --- include/rule.h | 2 ++ src/rule.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/rule.h b/include/rule.h index 61aa040a2e891..a7dd042d60e3f 100644 --- a/include/rule.h +++ b/include/rule.h @@ -260,6 +260,8 @@ extern struct rule *rule_get(struct rule *rule); extern void rule_free(struct rule *rule); extern void rule_print(const struct rule *rule, struct output_ctx *octx); extern struct rule *rule_lookup(const struct chain *chain, uint64_t handle); +extern struct rule *rule_lookup_by_index(const struct chain *chain, + uint64_t index); /** * struct set - nftables set diff --git a/src/rule.c b/src/rule.c index 78e0388e41e93..dc2dd3628b17f 100644 --- a/src/rule.c +++ b/src/rule.c @@ -716,6 +716,17 @@ struct rule *rule_lookup(const struct chain *chain, uint64_t handle) return NULL; } +struct rule *rule_lookup_by_index(const struct chain *chain, uint64_t index) +{ + struct rule *rule; + + list_for_each_entry(rule, &chain->rules, list) { + if (!--index) + return rule; + } + return NULL; +} + struct scope *scope_init(struct scope *scope, const struct scope *parent) { scope->parent = parent; -- 2.21.0