From patchwork Tue Sep 29 20:40:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 524014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 6941E140180 for ; Wed, 30 Sep 2015 06:41:00 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id E43CA106BA; Tue, 29 Sep 2015 13:40:56 -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 A1A80106B7 for ; Tue, 29 Sep 2015 13:40:55 -0700 (PDT) Received: from bar2.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 2D3A64203A5 for ; Tue, 29 Sep 2015 14:40:55 -0600 (MDT) X-ASG-Debug-ID: 1443559254-03dc537fe38acef0001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar2.cudamail.com with ESMTP id OkZZxxGENCgnMYY5 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 29 Sep 2015 14:40:54 -0600 (MDT) X-Barracuda-Envelope-From: joestringer@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mail-pa0-f52.google.com) (209.85.220.52) by mx1-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 29 Sep 2015 20:40:54 -0000 Received-SPF: unknown (mx1-pf1.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.52 Received: by pablk4 with SMTP id lk4so15594459pab.3 for ; Tue, 29 Sep 2015 13:40:53 -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:cc:subject:date:message-id:in-reply-to :references; bh=DFbY39QoKpsKGsHhD0UAenjb4F6nup1PkoDfZ+zSt6c=; b=S5Fa8r8jyShen2ACGYkb868BxfdLFbYcUVEdsgfZvC7slAeMwvevtFRn5KjkW6jAyS bcKMQrsC7XEQjVrCIhI9mEzESxO+WM0eAGHq5t/Fnm1n9DSY/jeN1wOfqg+eg38i3jWJ RWU7567bCyGjMWLurLa6CFS+vEe+lNupGHiZARe+G5xHTpIOQohktcaFXX8dZMtXhJRN rq4bmjRGnm20lQHWoEGh4ozoe/bhvlA7qC45Gdb+iDYq4BLSfyWP+a4SO+HDYzPLlxYs HxsFJYgDLBLfNT0HZ85Jkt0WzxeWCqO7VmuRQ+rkl1sWn8kzkadhBHPF0WuNQ3orCb1j wFZw== X-Gm-Message-State: ALoCoQn9m0nW/ox9eowkiV7bNmddVJU6KacTh90o+kjO6Sry3CGjW9ihMIuzmdWRAAClZQFy7sor X-Received: by 10.68.137.3 with SMTP id qe3mr47390pbb.26.1443559253636; Tue, 29 Sep 2015 13:40:53 -0700 (PDT) Received: from localhost.localdomain ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id fe8sm27450431pab.40.2015.09.29.13.40.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Sep 2015 13:40:53 -0700 (PDT) X-CudaMail-Envelope-Sender: joestringer@nicira.com X-Barracuda-Apparent-Source-IP: 208.91.2.4 From: Joe Stringer To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-928098891 X-CudaMail-DTE: 092915 X-CudaMail-Originating-IP: 209.85.220.52 Date: Tue, 29 Sep 2015 13:40:24 -0700 X-ASG-Orig-Subj: [##CM-E1-928098891##][PATCHv3 01/11] ofp-actions: Refactor set_field_parse__(). Message-Id: <1443559234-7330-2-git-send-email-joestringer@nicira.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443559234-7330-1-git-send-email-joestringer@nicira.com> References: <1443559234-7330-1-git-send-email-joestringer@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1443559254 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] [PATCHv3 01/11] ofp-actions: Refactor set_field_parse__(). 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" Split out some common functions that may be used by REG_LOAD in the following patch. Signed-off-by: Joe Stringer --- lib/ofp-actions.c | 81 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 88f0f85..d33e429 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -2476,51 +2476,58 @@ encode_SET_FIELD(const struct ofpact_set_field *sf, } } -/* Parses a "set_field" action with argument 'arg', appending the parsed - * action to 'ofpacts'. +/* Parses the input argument 'arg' into the key, value, and delimiter + * components that are common across the reg_load and set_field action format. + * + * With an argument like "1->metadata", sets the following pointers to + * point within 'arg': + * key: "metadata" + * value: "1" + * delim: "->" * * Returns NULL if successful, otherwise a malloc()'d string describing the * error. The caller is responsible for freeing the returned string. */ static char * OVS_WARN_UNUSED_RESULT -set_field_parse__(char *arg, struct ofpbuf *ofpacts, - enum ofputil_protocol *usable_protocols) +set_field_split_str(char *arg, char **key, char **value, char **delim) { - struct ofpact_set_field *sf = ofpact_put_SET_FIELD(ofpacts); - char *value; - char *delim; - char *key; - const struct mf_field *mf; - char *error; + *value = arg; + *delim = strstr(arg, "->"); + *key = *delim + strlen("->"); - value = arg; - delim = strstr(arg, "->"); - if (!delim) { + if (!*delim) { return xasprintf("%s: missing `->'", arg); } - if (strlen(delim) <= strlen("->")) { + if (strlen(*delim) <= strlen("->")) { return xasprintf("%s: missing field name following `->'", arg); } - key = delim + strlen("->"); - mf = mf_from_name(key); - if (!mf) { - return xasprintf("%s is not a valid OXM field name", key); - } + return NULL; +} + +/* Wraps mf_parse() to parse the input field 'mf' from the 'key' and 'value' + * strings, placing the output into 'dst' and (optionally) 'mask'. + * + * Returns NULL if successful, otherwise a malloc()'d string describing the + * error. The caller is responsible for freeing the returned string. */ +static char * OVS_WARN_UNUSED_RESULT +set_field_parse__(const struct mf_field *mf, const char *key, + const char *value, union mf_value *dst, union mf_value *mask) +{ + char *error; + if (!mf->writable) { return xasprintf("%s is read-only", key); } - sf->field = mf; - delim[0] = '\0'; - error = mf_parse(mf, value, &sf->value, &sf->mask); + + error = mf_parse(mf, value, dst, mask); if (error) { return error; } - if (!mf_is_value_valid(mf, &sf->value)) { + if (!mf_is_value_valid(mf, dst)) { return xasprintf("%s is not a valid value for field %s", value, key); } - *usable_protocols &= mf->usable_protocols_exact; return NULL; } @@ -2533,8 +2540,32 @@ static char * OVS_WARN_UNUSED_RESULT parse_SET_FIELD(const char *arg, struct ofpbuf *ofpacts, enum ofputil_protocol *usable_protocols) { + struct ofpact_set_field *sf = ofpact_put_SET_FIELD(ofpacts); char *copy = xstrdup(arg); - char *error = set_field_parse__(copy, ofpacts, usable_protocols); + char *key, *value, *delim; + const struct mf_field *mf; + char *error = NULL; + + error = set_field_split_str(copy, &key, &value, &delim); + if (error) { + goto error; + } + + mf = mf_from_name(key); + if (!mf) { + error = xasprintf("%s is not a valid OXM field name", key); + goto error; + } + delim[0] = '\0'; + + error = set_field_parse__(mf, key, value, &sf->value, &sf->mask); + if (error) { + goto error; + } + sf->field = mf; + *usable_protocols &= mf->usable_protocols_exact; + +error: free(copy); return error; }