From patchwork Fri Sep 25 20:49:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 522989 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 2C5CB140775 for ; Sat, 26 Sep 2015 06:49:57 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 95F3F10C00; Fri, 25 Sep 2015 13:49:56 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 05D2310BFF for ; Fri, 25 Sep 2015 13:49:55 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id 3D3C8618BEF for ; Fri, 25 Sep 2015 14:49:54 -0600 (MDT) X-ASG-Debug-ID: 1443214193-03dd7b6568e2480001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar3.cudamail.com with ESMTP id vqe6jostfsCGZlXu (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 25 Sep 2015 14:49:53 -0600 (MDT) X-Barracuda-Envelope-From: joestringer@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO mail-pa0-f53.google.com) (209.85.220.53) by mx3-pf3.cudamail.com with ESMTPS (RC4-SHA encrypted); 25 Sep 2015 20:49:51 -0000 Received-SPF: unknown (mx3-pf3.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.53 Received: by pablk4 with SMTP id lk4so18523466pab.3 for ; Fri, 25 Sep 2015 13:49:52 -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; bh=DFbY39QoKpsKGsHhD0UAenjb4F6nup1PkoDfZ+zSt6c=; b=XapSYw+RRCUm2WvClDnLUCBXuNZa+QbaE5t7aIgzjbFJ6OrluaKdVFZDb8h3MQODtD lkp00xAU7hwK3bF9l0Blm+PSflQv7vlYSlA+q6MdmOUDqVb3E888w9AiXZO3tj7GSnoA tp22tAVyJ5nmqLNrXnNUH4z3Bv/SZ0dh3EV2zZk61/9W8OFcYNZ7Q3aAhPhYUdM6zvsI OJDI7DgSODRMepDdLhZMWkrgwKJKiwo9GmxC3BKZCyblnJN9Wy7gmQFcSm187ZEhaAIh MCMcRdV2NubGqR+QaST9Y075r+nYweSy9M13KneCd5SlDpN3s3mgm4+CVbOVj4v96i4q ZNrg== X-Gm-Message-State: ALoCoQkioNK/3Hc1uJ6DGU5e4IIHjpcRulIeXi90uHpfbENZN2RtYlSyisrCWHQ+v46K0EWtWMmB X-Received: by 10.68.68.133 with SMTP id w5mr9781025pbt.143.1443214192189; Fri, 25 Sep 2015 13:49:52 -0700 (PDT) Received: from localhost.localdomain ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id xa4sm5519782pac.28.2015.09.25.13.49.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Sep 2015 13:49:51 -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-V3-924053403 X-CudaMail-DTE: 092515 X-CudaMail-Originating-IP: 209.85.220.53 Date: Fri, 25 Sep 2015 13:49:45 -0700 X-ASG-Orig-Subj: [##CM-V3-924053403##][PATCH 1/2] ofp-actions: Refactor set_field_parse__(). Message-Id: <1443214186-50469-1-git-send-email-joestringer@nicira.com> X-Mailer: git-send-email 2.1.4 X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1443214193 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 1/2] 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; }