From patchwork Thu Mar 8 16:46:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harsha Sharma X-Patchwork-Id: 883222 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="k4WFWi79"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zxxHP4RJTz9s1b for ; Fri, 9 Mar 2018 03:46:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752135AbeCHQqk (ORCPT ); Thu, 8 Mar 2018 11:46:40 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36817 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752094AbeCHQqh (ORCPT ); Thu, 8 Mar 2018 11:46:37 -0500 Received: by mail-pg0-f66.google.com with SMTP id i14so2430998pgv.3 for ; Thu, 08 Mar 2018 08:46:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RpYrkCxdHOu4b8PYzPHCSpFt8zbdKTwYPaAw1Az/igk=; b=k4WFWi79XK/W48jACQ89mcrLo513Y7yK+11ytnDARKhzHLQCD9QfLROLyVw4ob7v2B IP0cXZ27SReodR31SUR/9QesWocor8X6K/FeOPElIhIsalsYKiRwpiKb9f64nomLZMAL UjP2Q1RXWUrDO6Wsyj4xBJfQE6fdgHlB4rtCfvAHYJhms2yOtLIfsmdc6TRweBwPjMIi GE/9b7hO8wlJ6gSYL8UM/GM+I81MRufa8jr3VsYRJs99IF5MpMNDgYmX4uWJa92S4vOR eWgmwLrGIqWuo4vgeuMbqy4USh+foLNUUGJ2S+4OZpBn4Rf1fPma3fmh1YTq3fcMFAEP MTvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RpYrkCxdHOu4b8PYzPHCSpFt8zbdKTwYPaAw1Az/igk=; b=k6uPHUkXuQWyJ3lXaT8jhNWGmqw6Blbfp1e8zWn95VtDTGdx1JQC618+bE2P7Z6u7E mZSIQCQhn5ufE4GBl9Y1Vh68dq3lP4UHwuuGP+vI1KUmXY2Y1hI55GkWZbtm+F4u5pey m+YXApnEY9xDUHYwrsyGjCB3dxo7HvKOdySU053DA2nCG08pAsGWNEC3a32R/8TJxLir BQzfkaMSBRS3CUIXOiYqx+ylbIrBQ+1KadSf6BVrPQ6gRCrFBmBSEoFI4XhtAC98iB1n cWI5oU1CuxchW2m2t2jW1Gx5wxJuGf7G/oHZgNvkGMyarjuWpk7PHUoGMYY9dYN1HpbT TGrw== X-Gm-Message-State: APf1xPBiwUZmnvwSsxxWem2EwAM2i0lOCo2PDt3/NT7Eg/B0+iZeL8/m Hr1dHBgDcUxRWE5+H8UVOlg= X-Google-Smtp-Source: AG47ELuQA+0qZ+Mqecu3FHHCzvaZpy3FjbJq52mH4mo7VVgx6giZ73LTfTysVPflzQQq7OO+Ei19Bg== X-Received: by 10.98.160.90 with SMTP id r87mr26638032pfe.151.1520527597208; Thu, 08 Mar 2018 08:46:37 -0800 (PST) Received: from XDDDDD.iitr.ernet.in ([103.37.201.27]) by smtp.gmail.com with ESMTPSA id p24sm31887755pfk.102.2018.03.08.08.46.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 08:46:36 -0800 (PST) From: Harsha Sharma To: pablo@netfilter.org, harshasharmaiitr@gmail.com Cc: netfilter-devel@vger.kernel.org Subject: [PATCH] rule: print handle attribute in more clearer manner Date: Thu, 8 Mar 2018 22:16:13 +0530 Message-Id: <20180308164613.25668-1-harshasharmaiitr@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Print handles in this way: table ip filter { # handle 2 } Similarly, for chain, set and object handles Signed-off-by: Harsha Sharma --- src/rule.c | 63 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/rule.c b/src/rule.c index 99b12e9..9845541 100644 --- a/src/rule.c +++ b/src/rule.c @@ -303,8 +303,11 @@ static void set_print_declaration(const struct set *set, if (opts->table != NULL) nft_print(octx, " %s", opts->table); - nft_print(octx, " %s {%s", set->handle.set, opts->nl); + nft_print(octx, " %s {", set->handle.set); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, set->handle.handle.id); + nft_print(octx, "%s", opts->nl); nft_print(octx, "%s%stype %s", opts->tab, opts->tab, set->key->dtype->name); if (set->flags & NFT_SET_MAP) @@ -377,11 +380,7 @@ static void do_set_print(const struct set *set, struct print_fmt_options *opts, expr_print(set->init, octx); nft_print(octx, "%s", opts->nl); } - nft_print(octx, "%s}", opts->tab); - if (octx->handle > 0) - nft_print(octx, " # handle %" PRIu64, set->handle.handle.id); - nft_print(octx, "%s", opts->nl); - + nft_print(octx, "%s}%s", opts->tab, opts->nl); } void set_print(const struct set *s, struct output_ctx *octx) @@ -728,7 +727,10 @@ static const char *chain_policy2str(uint32_t policy) static void chain_print_declaration(const struct chain *chain, struct output_ctx *octx) { - nft_print(octx, "\tchain %s {\n", chain->handle.chain); + nft_print(octx, "\tchain %s {", chain->handle.chain); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, chain->handle.handle.id); + nft_print(octx, "\n"); if (chain->flags & CHAIN_F_BASECHAIN) { nft_print(octx, "\t\ttype %s hook %s", chain->type, hooknum2str(chain->handle.family, chain->hooknum)); @@ -750,10 +752,7 @@ static void chain_print(const struct chain *chain, struct output_ctx *octx) rule_print(rule, octx); nft_print(octx, "\n"); } - nft_print(octx, "\t}"); - if (octx->handle > 0) - nft_print(octx, " # handle %" PRIu64, chain->handle.handle.id); - nft_print(octx, "\n"); + nft_print(octx, "\t}\n"); } void chain_print_plain(const struct chain *chain, struct output_ctx *octx) @@ -863,7 +862,10 @@ static void table_print(const struct table *table, struct output_ctx *octx) const char *delim = ""; const char *family = family2str(table->handle.family); - nft_print(octx, "table %s %s {\n", family, table->handle.table); + nft_print(octx, "table %s %s {", family, table->handle.table); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, table->handle.handle.id); + nft_print(octx, "\n"); table_print_options(table, &delim, octx); list_for_each_entry(obj, &table->objs, list) { @@ -888,12 +890,7 @@ static void table_print(const struct table *table, struct output_ctx *octx) chain_print(chain, octx); delim = "\n"; } - nft_print(octx, "}"); - - if (octx->handle > 0) - nft_print(octx, " # handle %" PRIu64, table->handle.handle.id); - - nft_print(octx, "\n"); + nft_print(octx, "}\n"); } struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj, @@ -1390,8 +1387,10 @@ static void obj_print_data(const struct obj *obj, { switch (obj->type) { case NFT_OBJECT_COUNTER: - nft_print(octx, " %s {%s%s%s", obj->handle.obj, - opts->nl, opts->tab, opts->tab); + nft_print(octx, " %s {", obj->handle.obj); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, obj->handle.handle.id); + nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab); if (octx->stateless) { nft_print(octx, "packets 0 bytes 0"); break; @@ -1403,8 +1402,10 @@ static void obj_print_data(const struct obj *obj, const char *data_unit; uint64_t bytes; - nft_print(octx, " %s {%s%s%s", obj->handle.obj, - opts->nl, opts->tab, opts->tab); + nft_print(octx, " %s {", obj->handle.obj); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, obj->handle.handle.id); + nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab); data_unit = get_rate(obj->quota.bytes, &bytes); nft_print(octx, "%s%" PRIu64 " %s", obj->quota.flags & NFT_QUOTA_F_INV ? "over " : "", @@ -1417,7 +1418,10 @@ static void obj_print_data(const struct obj *obj, } break; case NFT_OBJECT_CT_HELPER: - nft_print(octx, "ct helper %s {\n", obj->handle.obj); + nft_print(octx, "ct helper %s {", obj->handle.obj); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, obj->handle.handle.id); + nft_print(octx, "%s", opts->nl); nft_print(octx, "\t\ttype \"%s\" protocol ", obj->ct_helper.name); print_proto_name_proto(obj->ct_helper.l4proto, octx); @@ -1429,8 +1433,10 @@ static void obj_print_data(const struct obj *obj, const char *data_unit; uint64_t rate; - nft_print(octx, " %s {%s%s%s", obj->handle.obj, - opts->nl, opts->tab, opts->tab); + nft_print(octx, " %s {", obj->handle.obj); + if (octx->handle > 0) + nft_print(octx, " # handle %" PRIu64, obj->handle.handle.id); + nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab); switch (obj->limit.type) { case NFT_LIMIT_PKTS: nft_print(octx, "rate %s%" PRIu64 "/%s", @@ -1505,12 +1511,7 @@ static void obj_print_declaration(const struct obj *obj, obj_print_data(obj, opts, octx); - nft_print(octx, "%s%s}", opts->nl, opts->tab); - - if (octx->handle > 0) - nft_print(octx, " # handle %" PRIu64, obj->handle.handle.id); - - nft_print(octx, "%s", opts->nl); + nft_print(octx, "%s%s}%s", opts->nl, opts->tab, opts->nl); } void obj_print(const struct obj *obj, struct output_ctx *octx)