From patchwork Wed Jun 21 18:06:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi-Hung Wei X-Patchwork-Id: 779049 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wtCP13vGrz9s7F for ; Thu, 22 Jun 2017 04:07:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mdN9LnWZ"; dkim-atps=neutral Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 34D51AD9; Wed, 21 Jun 2017 18:07:03 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 61277ABA for ; Wed, 21 Jun 2017 18:07:00 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id EA767AB for ; Wed, 21 Jun 2017 18:06:59 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id s66so32123611pfs.2 for ; Wed, 21 Jun 2017 11:06:59 -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=zwFh1CrRS8yieanLYNe5ZmmXS1VvQ7ONgh0lK2x4BRM=; b=mdN9LnWZpeDTLFIJo+R++dD9VZ89F32sLJf9vwiRdd8WVFsrhhxUNlbY8GJRUJOz9N kEWPcNKEQ5V9M0Qf/WkIBX3jUQ+pz7s8vBEuzQKUv8Ca/fDh5V/n/g549A/AwnCg8ucw k31ewQ72Gnic3fd2LvTvd16I51utFGk+5xn/4nYfjVhmpwAvZYZKmZAdxCYMELtslViO eNlWUjrs7H5C7vQGgJU5SQkn3MAMeW/QCwgdVfDb5U0npNj5xYLNNaXtG8q8Xujz0bLs XnySx3nH2upMXMArYPg8wtfYwwn+160OhJN8cRKxxqlzQCHG2uEEZOpVecD/RStHZ/Da SkUA== 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=zwFh1CrRS8yieanLYNe5ZmmXS1VvQ7ONgh0lK2x4BRM=; b=MTB6XHBkS8HheBkOThaM53HXlYzYb7j1iF3IjSKkJsU0GjjM3jmPeRp4ONtF9D0BqU HdaFe4lmenNkJRQgaG+qVZIlVftoJveCDTwoIJLKlFXejHrTBNjaCL218XFqRW1psstx 4FthPwSjtnUuawkw0oIBsmJLeVQl96l2Qaehl/Xa+ilYcPUuP4P5jVN12PWW4BXPMYdL qtsLQmSQVehdxOqdCMGD3eyVZKItvzKc6S72fNwUqR2oFKZcNVvFlaiqSRrgbMYTvjKw jb5FVHDV+BXJFE/gUE0ZistJLKw96Dix5LRzrJPw00svCYcyuSx/ltYYoCAYl3ZSjXqs ck6A== X-Gm-Message-State: AKS2vOx9MTKy4Fe1TEJDLdAiBFuMEyAQXN2VDPGqVINqOEBTqQ2gQ7I8 K8hn81wRnuRCipWxdy4= X-Received: by 10.98.212.1 with SMTP id a1mr37787403pfh.0.1498068419346; Wed, 21 Jun 2017 11:06:59 -0700 (PDT) Received: from sc9-mailhost1.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id 189sm34690933pgi.66.2017.06.21.11.06.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 11:06:58 -0700 (PDT) From: Yi-Hung Wei To: dev@openvswitch.org Date: Wed, 21 Jun 2017 11:06:50 -0700 Message-Id: <1498068412-89824-2-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498068412-89824-1-git-send-email-yihung.wei@gmail.com> References: <1498068412-89824-1-git-send-email-yihung.wei@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/3] conntrack: Move ct_state parsing to lib/conntrack.c X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This patch moves conntrack state parsing function from ovn-trace.c to lib/conntrack.c, because it will be used by ofproto/trace unixctl command later on. It also updates the ct_state checking logic, since we no longer assume CS_TRACKED is enable by default. Signed-off-by: Yi-Hung Wei --- lib/conntrack.c | 40 ++++++++++++++++++++++++++++++++++++++++ lib/conntrack.h | 1 + ovn/utilities/ovn-trace.c | 30 ++---------------------------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 90b154a87a74..901003ae0801 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -2030,3 +2030,43 @@ conntrack_flush(struct conntrack *ct, const uint16_t *zone) } return 0; } + +uint32_t +parse_ct_state(const char *state_s_, uint32_t default_state) +{ + uint32_t state = default_state; + + char *state_s = xstrdup(state_s_); + char *save_ptr = NULL; + for (char *cs = strtok_r(state_s, ", ", &save_ptr); cs; + cs = strtok_r(NULL, ", ", &save_ptr)) { + uint32_t bit = ct_state_from_string(cs); + if (!bit) { + ovs_fatal(0, "%s: unknown connection tracking state flag", cs); + } + state |= bit; + } + free(state_s); + + /* Check constraints listed in ovs-fields(7). */ + if (state && !(state & CS_TRACKED)) { + VLOG_WARN("%s: invalid connection state: " + "If \"trk\" is unset, no other flags are set", + state_s_); + } + if (state & CS_INVALID && state & ~(CS_TRACKED | CS_INVALID)) { + VLOG_WARN("%s: invalid connection state: " + "when \"inv\" is set, only \"trk\" may also be set", + state_s_); + } + if (state & CS_NEW && state & CS_ESTABLISHED) { + VLOG_WARN("%s: invalid connection state: " + "\"new\" and \"est\" are mutually exclusive", state_s_); + } + if (state & CS_NEW && state & CS_REPLY_DIR) { + VLOG_WARN("%s: invalid connection state: " + "\"new\" and \"rpy\" are mutually exclusive", state_s_); + } + + return state; +} diff --git a/lib/conntrack.h b/lib/conntrack.h index 243aebb642f7..c623d79c1803 100644 --- a/lib/conntrack.h +++ b/lib/conntrack.h @@ -113,6 +113,7 @@ int conntrack_dump_next(struct conntrack_dump *, struct ct_dpif_entry *); int conntrack_dump_done(struct conntrack_dump *); int conntrack_flush(struct conntrack *, const uint16_t *zone); +uint32_t parse_ct_state(const char *ct_states, uint32_t default_state); /* 'struct ct_lock' is a wrapper for an adaptive mutex. It's useful to try * different types of locks (e.g. spinlocks) */ diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c index 8bdb7d8a304d..7bec26e27d2b 100644 --- a/ovn/utilities/ovn-trace.c +++ b/ovn/utilities/ovn-trace.c @@ -20,6 +20,7 @@ #include "command-line.h" #include "compiler.h" +#include "conntrack.h" #include "daemon.h" #include "dirs.h" #include "fatal-signal.h" @@ -169,34 +170,7 @@ default_ovs(void) static void parse_ct_option(const char *state_s_) { - uint32_t state = CS_TRACKED; - - char *state_s = xstrdup(state_s_); - char *save_ptr = NULL; - for (char *cs = strtok_r(state_s, ", ", &save_ptr); cs; - cs = strtok_r(NULL, ", ", &save_ptr)) { - uint32_t bit = ct_state_from_string(cs); - if (!bit) { - ovs_fatal(0, "%s: unknown connection tracking state flag", cs); - } - state |= bit; - } - free(state_s); - - /* Check constraints listed in ovs-fields(7). */ - if (state & CS_INVALID && state & ~(CS_TRACKED | CS_INVALID)) { - VLOG_WARN("%s: invalid connection state: " - "when \"inv\" is set, only \"trk\" may also be set", - state_s_); - } - if (state & CS_NEW && state & CS_ESTABLISHED) { - VLOG_WARN("%s: invalid connection state: " - "\"new\" and \"est\" are mutually exclusive", state_s_); - } - if (state & CS_NEW && state & CS_REPLY_DIR) { - VLOG_WARN("%s: invalid connection state: " - "\"new\" and \"rpy\" are mutually exclusive", state_s_); - } + uint32_t state = parse_ct_state(state_s_, CS_TRACKED); ct_states = xrealloc(ct_states, (n_ct_states + 1) * sizeof *ct_states); ct_states[n_ct_states++] = state;