From patchwork Tue Sep 1 02:57:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Gross X-Patchwork-Id: 512676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 138491401DA for ; Tue, 1 Sep 2015 12:57:26 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 2D61B106F3; Mon, 31 Aug 2015 19:57:19 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id CB8061061A for ; Mon, 31 Aug 2015 19:57:16 -0700 (PDT) Received: from bar2.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id C6742420465 for ; Mon, 31 Aug 2015 20:57:15 -0600 (MDT) X-ASG-Debug-ID: 1441076235-03dc5333c808040001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar2.cudamail.com with ESMTP id lWXvIhN1brLLfFX5 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 31 Aug 2015 20:57:15 -0600 (MDT) X-Barracuda-Envelope-From: jesse@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-pa0-f51.google.com) (209.85.220.51) by mx1-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 1 Sep 2015 02:57:14 -0000 Received-SPF: unknown (mx1-pf2.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.51 Received: by pacgr6 with SMTP id gr6so8851602pac.3 for ; Mon, 31 Aug 2015 19:57:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=z2v8Z3qGKxV65D6aAP3x2edl5WsNBhCq2k8h7NjozEU=; b=VnuMZgP7TVSr+DdvhwmXXG46iborb5AUGbk8Xe/IRRM8l3nMX+hOnH2jPEbRa9HWsD Uy9XsM2XwZ2lcu7lHoW2y1zyAk+7lvSiqgZhuo+9zE7DQABZomIbzWz8dgs9AnHB0UEi qys5XbKnMWsvNUPOvxw/MJzlGSjQzNO/fvPl9xzHK62rvGxU+QNw4+v2eJA4ckE06qBQ dbiICT+lfT3SjfUpphVljdd7m+p46r0/KyE8zR7kXFwwDLUlH9Thz3Y5TIQvdFMBBYGt /y5vT0WbJ3mcr6ppKC25pG7hFfoSE+CkMho8njGdc2L6QDytgN70/Omc5Lt6AEOfrVTz Exbw== X-Gm-Message-State: ALoCoQlp40zIsSDZOcRbzBAj87F9YE9xd1lHH+ZHkExMbN5C/Ynp49cHQn0UNt/cAtrgOiRx2Zi/ X-Received: by 10.68.131.33 with SMTP id oj1mr40687646pbb.96.1441076233181; Mon, 31 Aug 2015 19:57:13 -0700 (PDT) Received: from ubuntu.localdomain (c-71-202-123-143.hsd1.ca.comcast.net. [71.202.123.143]) by smtp.gmail.com with ESMTPSA id fu4sm16085715pbb.59.2015.08.31.19.57.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Aug 2015 19:57:12 -0700 (PDT) X-CudaMail-Envelope-Sender: jesse@nicira.com X-Barracuda-Apparent-Source-IP: 71.202.123.143 From: Jesse Gross To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-830101319 X-CudaMail-DTE: 083115 X-CudaMail-Originating-IP: 209.85.220.51 Date: Mon, 31 Aug 2015 19:57:05 -0700 X-ASG-Orig-Subj: [##CM-E2-830101319##][PATCH 2/3] ofp-parse: Allow ofctl flow monitor filtering on field existence. Message-Id: <1441076226-60939-2-git-send-email-jesse@nicira.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441076226-60939-1-git-send-email-jesse@nicira.com> References: <1441076226-60939-1-git-send-email-jesse@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1441076235 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 2/3] ofp-parse: Allow ofctl flow monitor filtering on field existence. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" It is supposed to be possible to allow ovs-ofctl to filter flows it is monitoring based on a match string. However, the parser will reject expressions that match only on a field's existence (such as Geneve options). This relaxes the restriction to bring it in line with matches supported by other commands. Signed-off-by: Jesse Gross Acked-by: Ben Pfaff --- lib/ofp-parse.c | 70 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index a6190ed..855d732 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -221,6 +221,12 @@ parse_field(const struct mf_field *mf, const char *s, struct match *match, union mf_value value, mask; char *error; + if (!s) { + /* If there's no string, we're just trying to match on the + * existence of the field, so use a no-op value. */ + s = "0/0"; + } + error = mf_parse(mf, s, &value, &mask); if (!error) { *usable_protocols &= mf_set(mf, &value, &mask, match); @@ -372,11 +378,6 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string, value = field; if (mf_from_name(name)) { - if (!value) { - /* If there's no value, we're just trying to match on the - * existence of the field, so use a no-op value. */ - value = "0/0"; - } error = parse_field(mf_from_name(name), value, &fm->match, usable_protocols); } else { @@ -774,7 +775,7 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr, { static atomic_count id = ATOMIC_COUNT_INIT(0); char *save_ptr = NULL; - char *name; + char *field; fmr->id = atomic_count_inc(&id); @@ -784,52 +785,53 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr, fmr->table_id = 0xff; match_init_catchall(&fmr->match); - for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name; - name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) { + for (field = strtok_r(string, ", \t\r\n", &save_ptr); field; + field = strtok_r(NULL, ", \t\r\n", &save_ptr)) { const struct protocol *p; - if (!strcmp(name, "!initial")) { + if (!strcmp(field, "!initial")) { fmr->flags &= ~NXFMF_INITIAL; - } else if (!strcmp(name, "!add")) { + } else if (!strcmp(field, "!add")) { fmr->flags &= ~NXFMF_ADD; - } else if (!strcmp(name, "!delete")) { + } else if (!strcmp(field, "!delete")) { fmr->flags &= ~NXFMF_DELETE; - } else if (!strcmp(name, "!modify")) { + } else if (!strcmp(field, "!modify")) { fmr->flags &= ~NXFMF_MODIFY; - } else if (!strcmp(name, "!actions")) { + } else if (!strcmp(field, "!actions")) { fmr->flags &= ~NXFMF_ACTIONS; - } else if (!strcmp(name, "!own")) { + } else if (!strcmp(field, "!own")) { fmr->flags &= ~NXFMF_OWN; - } else if (parse_protocol(name, &p)) { + } else if (parse_protocol(field, &p)) { match_set_dl_type(&fmr->match, htons(p->dl_type)); if (p->nw_proto) { match_set_nw_proto(&fmr->match, p->nw_proto); } } else { - char *value; - - value = strtok_r(NULL, ", \t\r\n", &save_ptr); - if (!value) { - return xasprintf("%s: field %s missing value", str_, name); - } + char *name, *value; + char *error = NULL; - if (!strcmp(name, "table")) { - char *error = str_to_u8(value, "table", &fmr->table_id); - if (error) { - return error; - } - } else if (!strcmp(name, "out_port")) { - fmr->out_port = u16_to_ofp(atoi(value)); - } else if (mf_from_name(name)) { - char *error; + name = strsep(&field, "="); + value = field; + if (mf_from_name(name)) { error = parse_field(mf_from_name(name), value, &fmr->match, usable_protocols); - if (error) { - return error; - } } else { - return xasprintf("%s: unknown keyword %s", str_, name); + if (!value) { + return xasprintf("%s: field %s missing value", str_, name); + } + + if (!strcmp(name, "table")) { + error = str_to_u8(value, "table", &fmr->table_id); + } else if (!strcmp(name, "out_port")) { + fmr->out_port = u16_to_ofp(atoi(value)); + } else { + return xasprintf("%s: unknown keyword %s", str_, name); + } + } + + if (error) { + return error; } } }