From patchwork Thu Mar 1 11:03:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serhey Popovych X-Patchwork-Id: 879724 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="AQCJaRSC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zsV0b3nxmz9s19 for ; Thu, 1 Mar 2018 22:03:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967198AbeCALDZ (ORCPT ); Thu, 1 Mar 2018 06:03:25 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:45046 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967614AbeCALDS (ORCPT ); Thu, 1 Mar 2018 06:03:18 -0500 Received: by mail-lf0-f67.google.com with SMTP id v9so8152382lfa.11 for ; Thu, 01 Mar 2018 03:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=7/ALUr/Ex8ZDhSgtI0kwH/J481urQWt7EUJUknUASrM=; b=AQCJaRSC6PBnKQrxeKqEpTf6MDLk+etTUSL3BvpV8/R/1EA4xBUxi3D9lmqG47D+SZ xebisd4RRK73gfE5uKmUaq694bT5Gy58B9ONiGA3yJxDhBm9+V88ModgADzHHfo8eGBf cw+CEaUUsR4fQxS6G3qKFSkz0kgAOMYpDw1B8EnEbWdEuv8r0/PdK9CkxleTIb8cJG4U 5knfetp4Gz2aAdg+fqBXpphhQrVa+/ahp8PBmNup81QhkqPCw4qt7bW1kP5NY6JKdqvD QnoXVY+wDpWCIcTVt49HIRdTl5TnLm2exghVscx92GADggNG2ESbcFxS47ziAV1cH4zY uXmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=7/ALUr/Ex8ZDhSgtI0kwH/J481urQWt7EUJUknUASrM=; b=PPAQVoixKvKur48/icobZvsQoXtnuKOFAK/C76nOZXxVNRxzbTWO1fkuErnInh4cVN mpuksU9/HraKiZUDBTY0gC9z9r26GBbBqYGqIZtNdna0ttkJj2hTUy3oa9kWzaKuH0xk 8AU/H3I+sh1bgT3vK5/msYzyP0ekmHh56M7B5DXyiuZklDx8X+asKb85iKSVxE/Fyu3v VkG4En6C1PHazUxncxHybGWLZdODcjcnj8pFEu+mnKhDiHzOjb9LCG8AhCnzYAFEejrg NSQWaMyE3YjVBJ8Ns1FpXi12rrLdrmN7ttqGM9UU9RBGfnaGzWtHugUT2/xPTgr/7ETs Kv5w== X-Gm-Message-State: AElRT7E2LC7lS/eUo32KF2IN0Wp/UD1YFx1qHptMOYCEsTAwUjOhoLAY 1tUqUKWo0gzJ+480sE8TaGUR3g== X-Google-Smtp-Source: AG47ELvYVvuMM/O/MQ2fHUyyeUH+LOODxOBPj8bQLWD5Hzhzihz6gaDB44tYONeYVhmRP+GAIV4DwA== X-Received: by 10.46.88.27 with SMTP id m27mr1075141ljb.132.1519902196256; Thu, 01 Mar 2018 03:03:16 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id g17sm813846ljf.22.2018.03.01.03.03.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 03:03:15 -0800 (PST) From: Serhey Popovych To: netfilter-devel@vger.kernel.org Subject: [PATCH iptables 1/3] extensions: Initialize linear mapping of symbols in _init() of extension Date: Thu, 1 Mar 2018 13:03:10 +0200 Message-Id: <1519902192-17312-2-git-send-email-serhe.popovych@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1519902192-17312-1-git-send-email-serhe.popovych@gmail.com> References: <1519902192-17312-1-git-send-email-serhe.popovych@gmail.com> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org libxt_devgroup and libipt_realm currently unable to display symbolic names in save/print commands because linear mapping is not initialized. It looks bit confusing as linear mapping initialization is done in init() of extension, which is expected to be called before any other function of extension. However init is called only when '-m' option specified on command line, that is true only for insert, append, replace and destroy iptables commands. Move initialization to extension _init() function before calling any function in extension. Before: ------- ... src-group 0x1 dst-group 0x2 ... src-group 0x2 dst-group 0x1 After: ------ ... src-group grp1 dst-group grp2 ... src-group grp2 dst-group grp1 Signed-off-by: Serhey Popovych --- extensions/libipt_realm.c | 18 +++++++----------- extensions/libxt_devgroup.c | 17 +++++++---------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/extensions/libipt_realm.c b/extensions/libipt_realm.c index 8eea787..7500910 100644 --- a/extensions/libipt_realm.c +++ b/extensions/libipt_realm.c @@ -28,18 +28,10 @@ static const struct xt_option_entry realm_opts[] = { XTOPT_TABLEEND, }; -/* array of realms from /etc/iproute2/rt_realms */ +static const char f_realms[] = "/etc/iproute2/rt_realms"; +/* array of realms from f_realms[] */ static struct xtables_lmap *realms; -static void realm_init(struct xt_entry_match *m) -{ - const char file[] = "/etc/iproute2/rt_realms"; - - realms = xtables_lmap_init(file); - if (realms == NULL && errno != ENOENT) - fprintf(stderr, "Warning: %s: %s\n", file, strerror(errno)); -} - static void realm_parse(struct xt_option_call *cb) { struct xt_realm_info *realminfo = cb->data; @@ -151,7 +143,6 @@ static struct xtables_match realm_mt_reg = { .size = XT_ALIGN(sizeof(struct xt_realm_info)), .userspacesize = XT_ALIGN(sizeof(struct xt_realm_info)), .help = realm_help, - .init = realm_init, .print = realm_print, .save = realm_save, .x6_parse = realm_parse, @@ -161,5 +152,10 @@ static struct xtables_match realm_mt_reg = { void _init(void) { + realms = xtables_lmap_init(f_realms); + if (realms == NULL && errno != ENOENT) + fprintf(stderr, "Warning: %s: %s\n", f_realms, + strerror(errno)); + xtables_register_match(&realm_mt_reg); } diff --git a/extensions/libxt_devgroup.c b/extensions/libxt_devgroup.c index 2ec3905..f1352c4 100644 --- a/extensions/libxt_devgroup.c +++ b/extensions/libxt_devgroup.c @@ -31,17 +31,10 @@ static const struct xt_option_entry devgroup_opts[] = { XTOPT_TABLEEND, }; -/* array of devgroups from /etc/iproute2/group */ +static const char f_devgroups[] = "/etc/iproute2/group"; +/* array of devgroups from f_devgroups[] */ static struct xtables_lmap *devgroups; -static void devgroup_init(struct xt_entry_match *match) -{ - const char file[] = "/etc/iproute2/group"; - devgroups = xtables_lmap_init(file); - if (devgroups == NULL && errno != ENOENT) - fprintf(stderr, "Warning: %s: %s\n", file, strerror(errno)); -} - static void devgroup_parse_groupspec(const char *arg, unsigned int *group, unsigned int *mask) { @@ -212,7 +205,6 @@ static struct xtables_match devgroup_mt_reg = { .family = NFPROTO_UNSPEC, .size = XT_ALIGN(sizeof(struct xt_devgroup_info)), .userspacesize = XT_ALIGN(sizeof(struct xt_devgroup_info)), - .init = devgroup_init, .help = devgroup_help, .print = devgroup_print, .save = devgroup_save, @@ -224,5 +216,10 @@ static struct xtables_match devgroup_mt_reg = { void _init(void) { + devgroups = xtables_lmap_init(f_devgroups); + if (devgroups == NULL && errno != ENOENT) + fprintf(stderr, "Warning: %s: %s\n", f_devgroups, + strerror(errno)); + xtables_register_match(&devgroup_mt_reg); }