From patchwork Fri Apr 13 14:52:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 897978 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=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 40N14W0mDzz9s15 for ; Sat, 14 Apr 2018 00:53:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751978AbeDMOxq (ORCPT ); Fri, 13 Apr 2018 10:53:46 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:53008 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711AbeDMOxq (ORCPT ); Fri, 13 Apr 2018 10:53:46 -0400 Received: from localhost ([::1]:40052 helo=xsao) by orbyte.nwl.cc with esmtp (Exim 4.90_1) (envelope-from ) id 1f705B-0000K0-7y; Fri, 13 Apr 2018 16:53:45 +0200 From: Phil Sutter To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org Subject: [nft PATCH 06/12] segtree: Fix for last elem at interval end Date: Fri, 13 Apr 2018 16:52:29 +0200 Message-Id: <20180413145235.1204-7-phil@nwl.cc> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180413145235.1204-1-phil@nwl.cc> References: <20180413145235.1204-1-phil@nwl.cc> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Unclosed interval check at end of interval_map_decompose() missed to check whether interval start is the last possible element in given set before creating a range expression. This led to the last element incorrectly printed as range from itself to itself. Fix this by comparing the upper boundary against the lower one. In order to keep indenting level low, invert the entry check and jump to the end if it matches. Signed-off-by: Phil Sutter --- src/segtree.c | 20 ++++++++++++-------- tests/py/ip6/srh.t | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/segtree.c b/src/segtree.c index 1970265a9f11c..5939d8fc7b4a8 100644 --- a/src/segtree.c +++ b/src/segtree.c @@ -857,21 +857,25 @@ void interval_map_decompose(struct expr *set) expr_free(i); } - /* Unclosed interval */ - if (low != NULL) { - i = constant_expr_alloc(&low->location, low->dtype, - low->byteorder, expr_value(low)->len, - NULL); - mpz_init_bitmask(i->value, i->len); + if (!low) /* no unclosed interval at end */ + goto out; + i = constant_expr_alloc(&low->location, low->dtype, + low->byteorder, expr_value(low)->len, NULL); + mpz_init_bitmask(i->value, i->len); + + if (!mpz_cmp(i->value, expr_value(low)->value)) { + expr_free(i); + i = low; + } else { i = range_expr_alloc(&low->location, expr_value(low), i); i = set_elem_expr_alloc(&low->location, i); if (low->ops->type == EXPR_MAPPING) i = mapping_expr_alloc(&i->location, i, low->right); - - compound_expr_add(set, i); } + compound_expr_add(set, i); +out: mpz_clear(range); mpz_clear(p); diff --git a/tests/py/ip6/srh.t b/tests/py/ip6/srh.t index 442c78f0a8ea3..fbaff410c8683 100644 --- a/tests/py/ip6/srh.t +++ b/tests/py/ip6/srh.t @@ -4,15 +4,15 @@ srh last-entry 0;ok srh last-entry 127;ok -srh last-entry { 0, 4-127, 255 };ok;srh last-entry { 0, 4-127, 255-255} +srh last-entry { 0, 4-127, 255 };ok srh flags 0;ok srh flags 127;ok -srh flags { 0, 4-127, 255 };ok;srh flags { 0, 4-127, 255-255} +srh flags { 0, 4-127, 255 };ok srh tag 0;ok srh tag 127;ok -srh tag { 0, 4-127, 0xffff };ok;srh tag { 0, 4-127, 65535-65535} +srh tag { 0, 4-127, 0xffff };ok;srh tag { 0, 4-127, 65535 } srh sid[1] dead::beef;ok srh sid[2] dead::beef;ok