From patchwork Sat Feb 25 02:57:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Di Proietto X-Patchwork-Id: 732325 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 3vVXjZ60vgz9s1y for ; Sat, 25 Feb 2017 13:58:42 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8532FB56; Sat, 25 Feb 2017 02:58:13 +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 D2AE6412 for ; Sat, 25 Feb 2017 02:58:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com [208.91.0.190]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id CF41213E for ; Sat, 25 Feb 2017 02:58:07 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 24 Feb 2017 18:57:55 -0800 Received: from sc9-mailhost3.vmware.com (htb-1n-eng-dhcp149.eng.vmware.com [10.33.74.149]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 7E114B0436; Fri, 24 Feb 2017 18:58:06 -0800 (PST) From: Daniele Di Proietto To: Date: Fri, 24 Feb 2017 18:57:55 -0800 Message-ID: <20170225025801.86791-2-diproiettod@vmware.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170225025801.86791-1-diproiettod@vmware.com> References: <20170225025801.86791-1-diproiettod@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: diproiettod@vmware.com does not designate permitted sender hosts) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Daniele Di Proietto Subject: [ovs-dev] [PATCH 1/7] ofp-actions: Factor out decode_LEARN_common(). 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org No functional change, it will be used by next commit. Signed-off-by: Daniele Di Proietto Acked-by: Ben Pfaff --- lib/ofp-actions.c | 77 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index ce80f57e8..78f8c4366 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -4313,43 +4313,14 @@ learn_min_len(uint16_t header) return min_len; } -/* Converts 'nal' into a "struct ofpact_learn" and appends that struct to - * 'ofpacts'. Returns 0 if successful, otherwise an OFPERR_*. */ static enum ofperr -decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal, - enum ofp_version ofp_version OVS_UNUSED, - const struct vl_mff_map *vl_mff_map, - struct ofpbuf *ofpacts) +decode_LEARN_common(const void *p, const void *end, + const struct vl_mff_map *vl_mff_map, + struct ofpbuf *ofpacts) { - struct ofpact_learn *learn; - const void *p, *end; + struct ofpact_learn *learn = ofpacts->header; - if (nal->pad) { - return OFPERR_OFPBAC_BAD_ARGUMENT; - } - - learn = ofpact_put_LEARN(ofpacts); - - learn->idle_timeout = ntohs(nal->idle_timeout); - learn->hard_timeout = ntohs(nal->hard_timeout); - learn->priority = ntohs(nal->priority); - learn->cookie = nal->cookie; - learn->table_id = nal->table_id; - learn->fin_idle_timeout = ntohs(nal->fin_idle_timeout); - learn->fin_hard_timeout = ntohs(nal->fin_hard_timeout); - - learn->flags = ntohs(nal->flags); - if (learn->flags & ~(NX_LEARN_F_SEND_FLOW_REM | - NX_LEARN_F_DELETE_LEARNED)) { - return OFPERR_OFPBAC_BAD_ARGUMENT; - } - - if (learn->table_id == 0xff) { - return OFPERR_OFPBAC_BAD_ARGUMENT; - } - - end = (char *) nal + ntohs(nal->len); - for (p = nal + 1; p != end; ) { + while (p != end) { struct ofpact_learn_spec *spec; uint16_t header = ntohs(get_be16(&p)); @@ -4422,6 +4393,44 @@ decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal, return 0; } +/* Converts 'nal' into a "struct ofpact_learn" and appends that struct to + * 'ofpacts'. Returns 0 if successful, otherwise an OFPERR_*. */ +static enum ofperr +decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal, + enum ofp_version ofp_version OVS_UNUSED, + const struct vl_mff_map *vl_mff_map, + struct ofpbuf *ofpacts) +{ + struct ofpact_learn *learn; + + if (nal->pad) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + + learn = ofpact_put_LEARN(ofpacts); + + learn->idle_timeout = ntohs(nal->idle_timeout); + learn->hard_timeout = ntohs(nal->hard_timeout); + learn->priority = ntohs(nal->priority); + learn->cookie = nal->cookie; + learn->table_id = nal->table_id; + learn->fin_idle_timeout = ntohs(nal->fin_idle_timeout); + learn->fin_hard_timeout = ntohs(nal->fin_hard_timeout); + + learn->flags = ntohs(nal->flags); + if (learn->flags & ~(NX_LEARN_F_SEND_FLOW_REM | + NX_LEARN_F_DELETE_LEARNED)) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + + if (learn->table_id == 0xff) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + + return decode_LEARN_common(nal + 1, (char *) nal + ntohs(nal->len), + vl_mff_map, ofpacts); +} + static void put_be16(struct ofpbuf *b, ovs_be16 x) {