From patchwork Fri Oct 2 21:16:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 525805 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 BB6AE1402C4 for ; Sat, 3 Oct 2015 07:17:13 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 1005D22C4A9; Fri, 2 Oct 2015 14:16:37 -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 6DBB822C49F for ; Fri, 2 Oct 2015 14:16:35 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id E520161854F for ; Fri, 2 Oct 2015 15:16:33 -0600 (MDT) X-ASG-Debug-ID: 1443820591-03dd7b65e032720001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar3.cudamail.com with ESMTP id ix4PURrrzflL2dv5 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 02 Oct 2015 15:16:31 -0600 (MDT) X-Barracuda-Envelope-From: joestringer@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mail-pa0-f51.google.com) (209.85.220.51) by mx3-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 2 Oct 2015 21:16:31 -0000 Received-SPF: unknown (mx3-pf2.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.51 Received: by pablk4 with SMTP id lk4so115631802pab.3 for ; Fri, 02 Oct 2015 14:16:31 -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=6DJRFPemlETMKpadOEbpdUcJR/yZcRj0p3bPYBKXj/Y=; b=QIOJ103Td0mra9CF/ERaSywpZG5R2d9hj2WNiaI10E9opOyr5f/HhNlcSfxYsQ9Ot9 0GXGF40yomgCPg5qeR62YwzSfDIOTChxl9GGuJ+EHlwFtzkUsqyj95StV8WU2/0RYPRc oDe25Mn/jLpZECNWQfq7XZonl/qJ9yhUMpnVqML7Ve3gkss5+gjnGBuGANRe91sPF3wa cS+y7NpymFlYVvFfcmKvSLr3tQADH6OHbpyWBIINDxxGTt6nxfJXE+KGO3+MSQRQKGtW BT/avIv2A2MwDwDV1/E7Mrrkz4/xI6eFNehCif+V9Ws8h+SaROIM8S7RKiM/idryhuoS ESfg== X-Gm-Message-State: ALoCoQnmD7IdysQY/5TswnKAynfTUHJO9IALE1iD35bSceIQUmfjOd9ld1amYAdS+HavrHa8qMEA X-Received: by 10.68.129.198 with SMTP id ny6mr22690149pbb.42.1443820590900; Fri, 02 Oct 2015 14:16:30 -0700 (PDT) Received: from localhost.localdomain ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id z6sm13633900pbt.51.2015.10.02.14.16.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Oct 2015 14:16:30 -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-V2-1001056317 X-CudaMail-DTE: 100215 X-CudaMail-Originating-IP: 209.85.220.51 Date: Fri, 2 Oct 2015 14:16:09 -0700 X-ASG-Orig-Subj: [##CM-V2-1001056317##][PATCHv4 02/11] ofp-actions: Extend reg_load parsing to >64bits. Message-Id: <1443820578-9287-3-git-send-email-joestringer@nicira.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443820578-9287-1-git-send-email-joestringer@nicira.com> References: <1443820578-9287-1-git-send-email-joestringer@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1443820591 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] [PATCHv4 02/11] ofp-actions: Extend reg_load parsing to >64bits. 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" Previously, reg_load would only understand 64-bit values passed to it. This patch extends the parsing to handle larger fields, if they are specified in hexadecimal. Internally they are stored as a single action, but they are converted into multiple 64-bit modifications when re-serialised. Signed-off-by: Joe Stringer Acked-by: Ben Pfaff --- v4: Reduce change to allowing >64bit values to be specified in hex. --- lib/ofp-actions.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 6c9e1cb..0b22ce1 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -2571,10 +2571,9 @@ static char * OVS_WARN_UNUSED_RESULT parse_reg_load(char *arg, struct ofpbuf *ofpacts) { struct ofpact_set_field *sf = ofpact_put_reg_load(ofpacts); - const char *full_arg = arg; - uint64_t value = strtoull(arg, (char **) &arg, 0); struct mf_subfield dst; char *key, *value_str; + union mf_value value; char *error; error = set_field_split_str(arg, &key, &value_str, NULL); @@ -2587,16 +2586,29 @@ parse_reg_load(char *arg, struct ofpbuf *ofpacts) return error; } - if (dst.n_bits < 64 && (value >> dst.n_bits) != 0) { - return xasprintf("%s: value %"PRIu64" does not fit into %d bits", - full_arg, value, dst.n_bits); + if (parse_int_string(value_str, (uint8_t *)&value, dst.field->n_bytes, + &key)) { + return xasprintf("%s: cannot parse integer value", arg); + } + + if (!bitwise_is_all_zeros(&value, dst.field->n_bytes, dst.n_bits, + dst.field->n_bytes * 8 - dst.n_bits)) { + struct ds ds; + + ds_init(&ds); + mf_format(dst.field, &value, NULL, &ds); + error = xasprintf("%s: value %s does not fit into %d bits", + arg, ds_cstr(&ds), dst.n_bits); + ds_destroy(&ds); + return error; } sf->field = dst.field; memset(&sf->value, 0, sizeof sf->value); - bitwise_put(value, &sf->value, dst.field->n_bytes, dst.ofs, dst.n_bits); - bitwise_put(UINT64_MAX, &sf->mask, - dst.field->n_bytes, dst.ofs, dst.n_bits); + bitwise_copy(&value, dst.field->n_bytes, 0, &sf->value, + dst.field->n_bytes, dst.ofs, dst.n_bits); + bitwise_one(&sf->mask, dst.field->n_bytes, dst.ofs, dst.n_bits); + return NULL; }