From patchwork Wed Dec 23 14:13:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivani Bhardwaj X-Patchwork-Id: 560554 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D5198140BF9 for ; Thu, 24 Dec 2015 01:13:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=pdoX1TvE; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752420AbbLWON1 (ORCPT ); Wed, 23 Dec 2015 09:13:27 -0500 Received: from mail-pf0-f169.google.com ([209.85.192.169]:36025 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751075AbbLWON0 (ORCPT ); Wed, 23 Dec 2015 09:13:26 -0500 Received: by mail-pf0-f169.google.com with SMTP id 65so8924414pff.3 for ; Wed, 23 Dec 2015 06:13:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=PEel5OoA6ut5FYxPWvUoxaSae6zopa0G/+rkIHYvgpc=; b=pdoX1TvEKv8sW2Lc3TE3s6pl65hvLQtNCCQEhrSOoLS97p5O/P5jzTSL+S2zrHFj3r li8b0vH/tusdaReX/UMiq1GYFW+HWczDxju+yNg8cTNhEuInyyd82OrGvFqfmVn9eVXw 2Hxh0Ds494+bU8v2S1bhXkr5OzMPtINi/G3IZ0SWZM6S/YK7VTdgiw2n1sQM6CayCAgd vM0z1y21hdof4Kss5WaPEYsMAvmTJNlyF7a3Dk04U9fMz11WwyanDjHWKNRA1YiMXqGx 48ACgDcD+LVP7x2DP62S7njLxkj89wKzyJTLu9Ll0gcd76WjLyzMc5zml1Ivdx0bruu1 ut1g== X-Received: by 10.98.67.148 with SMTP id l20mr44665085pfi.109.1450880005723; Wed, 23 Dec 2015 06:13:25 -0800 (PST) Received: from gmail.com ([223.176.140.7]) by smtp.gmail.com with ESMTPSA id n3sm48360586pfa.79.2015.12.23.06.13.23 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 23 Dec 2015 06:13:24 -0800 (PST) Date: Wed, 23 Dec 2015 19:43:19 +0530 From: Shivani Bhardwaj To: netfilter-devel@vger.kernel.org Subject: [PATCH v2] extensions: libxt_mark: Fix inversion code Message-ID: <20151223141318.GA15560@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Fix the code associated with invert flag. Examples: $ sudo iptables-translate -I INPUT -p tcp -m mark ! --mark 0xa/0xa nft insert rule ip filter INPUT ip protocol tcp mark and 0xa != 0xa counter $ sudo iptables-translate -I INPUT -p tcp -m mark ! --mark 0x1 nft insert rule ip filter INPUT ip protocol tcp mark != 0x1 counter Signed-off-by: Shivani Bhardwaj --- Changes in v2: Replace string with enum to make code look better extensions/libxt_mark.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/extensions/libxt_mark.c b/extensions/libxt_mark.c index 3b96a34..93d38d9 100644 --- a/extensions/libxt_mark.c +++ b/extensions/libxt_mark.c @@ -103,13 +103,15 @@ mark_save(const void *ip, const struct xt_entry_match *match) } static void -print_mark_xlate(struct xt_buf *buf, - unsigned int mark, unsigned int mask) +print_mark_xlate(struct xt_buf *buf, unsigned int mark, + unsigned int mask, uint32_t op) { if (mask != 0xffffffffU) - xt_buf_add(buf, " and 0x%x == 0x%x ", mark, mask); + xt_buf_add(buf, " and 0x%x %s 0x%x ", mark, + op == XT_OP_EQ ? "==" : "!=", mask); else - xt_buf_add(buf, " 0x%x ", mark); + xt_buf_add(buf, " %s0x%x ", + op == XT_OP_EQ ? "" : "!= ", mark); } static int @@ -117,9 +119,13 @@ mark_mt_xlate(const struct xt_entry_match *match, struct xt_buf *buf, int numeric) { const struct xt_mark_mtinfo1 *info = (const void *)match->data; + enum xt_op op = XT_OP_EQ; - xt_buf_add(buf, "mark%s", info->invert ? " !=" : ""); - print_mark_xlate(buf, info->mark, info->mask); + if (info->invert) + op = XT_OP_NEQ; + + xt_buf_add(buf, "mark"); + print_mark_xlate(buf, info->mark, info->mask, op); return 1; } @@ -129,9 +135,13 @@ mark_xlate(const struct xt_entry_match *match, struct xt_buf *buf, int numeric) { const struct xt_mark_info *info = (const void *)match->data; + enum xt_op op = XT_OP_EQ; + + if (info->invert) + op = XT_OP_NEQ; - xt_buf_add(buf, "mark%s", info->invert ? " !=" : ""); - print_mark_xlate(buf, info->mark, info->mask); + xt_buf_add(buf, "mark"); + print_mark_xlate(buf, info->mark, info->mask, op); return 1; }