From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BFCE1A0561; Mon, 20 Apr 2020 04:48:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 154C41C2BF; Mon, 20 Apr 2020 04:48:59 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 955911C2B9 for ; Mon, 20 Apr 2020 04:48:56 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id d1so4267865pfh.1 for ; Sun, 19 Apr 2020 19:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tlOpZLgxsai2bxAwnppLMunovQ36i609cCkTKMY9wu8=; b=DLSx+LKv7iZSxI1PGBED7E3b24/gWfucuKnPYj5+IlORYPb4vAAeVrhCvFv1FbbsnI HTxQrminnhrVic3xjZNCL+3vZ/kC4LkYYbqGGDJ2VwfiVrM+Q7b4BCryacH/7ZXesSj1 VcIsRnkrWQzde20CeaYYfYma6sq9y+ygR8rAzKy7JX2jUSsx5HZj0KeiOET9VVwqVSFe zxjE/ukudpO+nLeiWJ5HthoLarM5b+uA/9LEmqMep12iAILR6365J8/JWR3v8JHyYf0N xJuz9p753I0GM9bqY4I3OTrU/0yXblr9U5CQ0eOGYlIxmAJPnynbSN5zdPwFuSXB1X4v K+nw== 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:in-reply-to :references; bh=tlOpZLgxsai2bxAwnppLMunovQ36i609cCkTKMY9wu8=; b=LQXr+Xe1FBxyYFCoLxSFaN9Eu2jlxoL3MHsgSuP+hnHzdP/E16fC9/ooPYydxOXROq ShxnkAmmi8c7Ziuog29haa7WVx3C538yeaov5quku7p2RdfQgodI8MDmjNMfsvyZPdvq 8Pry7kSuD70UaiCKnr1KIjaBs+QExGz7fxvlZrLFbJyHJR3p5hqglUaTSm+dSsTeS8MA 9MJvI28S8UvayZG03I/dhA5gxuLA1kFT3S6SvJ4wBLIV5uWLmXF2XcB0FtZMSh6BGKFb bl05F/kv0D2DqERNsRKSUiXGuRCkZrxl2J2N2xXQ/1y3NvsLY/lAc3Qag8+GT6t0ru7C 25pw== X-Gm-Message-State: AGi0Pua44tL76AyoCwFfxR+l3NmUR7H2mPV9H6YJEtNIcTCAQZnhNzrs L1BeMgRzOMFSUGVXlUqa3PflfpDC/9A= X-Google-Smtp-Source: APiQypJeczXJsHHOJum/c5+pU2WATho3YMx3U1Ol0A4e1+UaPPLlsbDd23odJG8C0Y0O/KRASxjI1Q== X-Received: by 2002:a63:9902:: with SMTP id d2mr14360185pge.8.1587350935580; Sun, 19 Apr 2020 19:48:55 -0700 (PDT) Received: from yateszhou-PC0.tencent.com ([203.205.141.45]) by smtp.gmail.com with ESMTPSA id n17sm18114228pff.81.2020.04.19.19.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 19:48:54 -0700 (PDT) From: Yangchao Zhou To: dev@dpdk.org Cc: Bruce Richardson , Vladimir Medvedkin Date: Mon, 20 Apr 2020 10:48:50 +0800 Message-Id: <20200420024850.21481-1-zhouyates@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200417150912.6911-1-zhouyates@gmail.com> References: <20200417150912.6911-1-zhouyates@gmail.com> Subject: [dpdk-dev] [PATCH v4] lpm: skip table entries update if rules found X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Table entries do not need to be updated if the same rules can be found. Signed-off-by: Yangchao Zhou --- v1-v2: Skip updating when the next hop is the same as the current one v2-v4: Coding style fix --- lib/librte_lpm/rte_lpm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index 268756419..b8a90e385 100644 --- a/lib/librte_lpm/rte_lpm.c +++ b/lib/librte_lpm/rte_lpm.c @@ -285,6 +285,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth, /* If rule already exists update its next_hop and return. */ if (lpm->rules_tbl[rule_index].ip == ip_masked) { + + if (lpm->rules_tbl[rule_index].next_hop == next_hop) + return -EEXIST; lpm->rules_tbl[rule_index].next_hop = next_hop; return rule_index; @@ -674,6 +677,12 @@ rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, /* Add the rule to the rule table. */ rule_index = rule_add(lpm, ip_masked, depth, next_hop); + /* Skip table entries update if The rule is the same as + * the rule in the rules table. + */ + if (rule_index == -EEXIST) + return 0; + /* If the is no space available for new rule return error. */ if (rule_index < 0) { return rule_index; -- 2.17.1