From patchwork Tue May 18 07:50:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Adri=C3=A1n_Moreno?= X-Patchwork-Id: 1480068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W+BiGl0M; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fkp8M1YGwz9sWF for ; Tue, 18 May 2021 17:50:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id C4502405F7; Tue, 18 May 2021 07:50:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o24qDnkOD0Rf; Tue, 18 May 2021 07:50:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTP id 956E4402F1; Tue, 18 May 2021 07:50:38 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 706C4C000D; Tue, 18 May 2021 07:50:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2C751C0001 for ; Tue, 18 May 2021 07:50:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0EC00606A8 for ; Tue, 18 May 2021 07:50:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d7OtsORAXwaa for ; Tue, 18 May 2021 07:50:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id C6B516067B for ; Tue, 18 May 2021 07:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621324234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=usFixB6EnkIU8iKih6RCDO2fA6WhWUSCSmHN/ZSbHl8=; b=W+BiGl0Mho0g/NXiFDm7AbzNvYHW+Mv7Wz72UnAjQspNroCruAuzQIk8XZ8M2V2W0urN5T 9Wyf7/Sd9IWdlWMIZnj9cini325sOw4kzhc6sEr3t8Mpeycna0DoP+x/AaA3DVQiPYc7ec IpTHk9GJxN7K8C9YQy+q4AZq5CF/cVU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-401-idRz0Ly-PImv4nzq02BwMg-1; Tue, 18 May 2021 03:50:33 -0400 X-MC-Unique: idRz0Ly-PImv4nzq02BwMg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D5271A8A64; Tue, 18 May 2021 07:50:32 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-224.ams2.redhat.com [10.36.114.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62B9C60657; Tue, 18 May 2021 07:50:29 +0000 (UTC) From: Adrian Moreno To: dev@openvswitch.org Date: Tue, 18 May 2021 09:50:27 +0200 Message-Id: <20210518075027.412363-1-amorenoz@redhat.com> In-Reply-To: <20210507130214.1219199-1-amorenoz@redhat.com> References: <20210507130214.1219199-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH v3] ofp_actions: fix set_mpls_tc formatting X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Apart from a cut-and-paste typo, the man page claims that mpls_labels can be provided in hexadecimal format but that's currently not the case. Fix mpls ofp-action formatting, add size checks on ofp-action parsing and add some unit tests. Signed-off-by: Adrian Moreno --- lib/ofp-actions.c | 35 +++++++++++++++++++++++++++++++---- tests/ofp-actions.at | 9 +++++++++ tests/ovs-ofctl.at | 20 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 0342a228b..6fb3da507 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -3777,11 +3777,22 @@ parse_SET_MPLS_LABEL(char *arg, const struct ofpact_parse_params *pp) { struct ofpact_mpls_label *mpls_label = ofpact_put_SET_MPLS_LABEL(pp->ofpacts); + uint32_t label; + char *error; + if (*arg == '\0') { return xstrdup("set_mpls_label: expected label."); } - mpls_label->label = htonl(atoi(arg)); + error = str_to_u32(arg, &label); + if (error) { + return error; + } + + if (label & ~0xfffff) { + return xasprintf("%s: not a valid MPLS label", arg); + } + mpls_label->label = htonl(label); return NULL; } @@ -3837,12 +3848,22 @@ static char * OVS_WARN_UNUSED_RESULT parse_SET_MPLS_TC(char *arg, const struct ofpact_parse_params *pp) { struct ofpact_mpls_tc *mpls_tc = ofpact_put_SET_MPLS_TC(pp->ofpacts); + uint8_t tc; + char *error; if (*arg == '\0') { return xstrdup("set_mpls_tc: expected tc."); } - mpls_tc->tc = atoi(arg); + error = str_to_u8(arg, "MPLS TC", &tc); + if (error) { + return error; + } + + if (tc & ~7) { + return xasprintf("%s: not a valid MPLS TC", arg); + } + mpls_tc->tc = tc; return NULL; } @@ -3850,7 +3871,7 @@ static void format_SET_MPLS_TC(const struct ofpact_mpls_tc *a, const struct ofpact_format_params *fp) { - ds_put_format(fp->s, "%sset_mpls_ttl(%s%"PRIu8"%s)%s", + ds_put_format(fp->s, "%sset_mpls_tc(%s%"PRIu8"%s)%s", colors.paren, colors.end, a->tc, colors.paren, colors.end); } @@ -3889,12 +3910,18 @@ static char * OVS_WARN_UNUSED_RESULT parse_SET_MPLS_TTL(char *arg, const struct ofpact_parse_params *pp) { struct ofpact_mpls_ttl *mpls_ttl = ofpact_put_SET_MPLS_TTL(pp->ofpacts); + uint8_t ttl; + char *error; if (*arg == '\0') { return xstrdup("set_mpls_ttl: expected ttl."); } - mpls_ttl->ttl = atoi(arg); + error = str_to_u8(arg, "MPLS TTL", &ttl); + if (error) { + return error; + } + mpls_ttl->ttl = ttl; return NULL; } diff --git a/tests/ofp-actions.at b/tests/ofp-actions.at index 199db8ed0..59093c03c 100644 --- a/tests/ofp-actions.at +++ b/tests/ofp-actions.at @@ -1007,12 +1007,21 @@ bad_action 'dec_ttl(,)' 'dec_ttl_cnt_ids: expected at least one controller id.' # set_mpls_label bad_action 'set_mpls_label' 'set_mpls_label: expected label.' +# set_mpls_label oversized +bad_action 'set_mpls_label(0x100000)' '0x100000: not a valid MPLS label' + # set_mpls_tc bad_action 'set_mpls_tc' 'set_mpls_tc: expected tc.' +# set_mpls_tc oversized +bad_action 'set_mpls_tc(8)' '8: not a valid MPLS TC' + # set_mpls_ttl bad_action 'set_mpls_ttl' 'set_mpls_ttl: expected ttl.' +# set_mpls_ttl oversized +bad_action 'set_mpls_ttl(256)' 'invalid MPLS TTL "256"' + # fin_timeout bad_action 'fin_timeout(foo=bar)' "invalid key 'foo' in 'fin_timeout' argument" diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index 5ddca67e7..604f15c2d 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -449,6 +449,16 @@ actions=output(max_len=100,port=123) actions=output(port=100,max_len=123) actions=output(port=LOCAL,max_len=123) actions=output(port=IN_PORT,max_len=123) +mpls,mpls_label=1,actions=set_mpls_label(0) +mpls,mpls_label=1,actions=set_mpls_label(10) +mpls,mpls_label=1,actions=set_mpls_label(0x10) +mpls,mpls_label=1,actions=set_mpls_label(0xfffff) +mpls,mpls_tc=1,actions=set_mpls_tc(0) +mpls,mpls_tc=1,actions=set_mpls_tc(3) +mpls,mpls_tc=1,actions=set_mpls_tc(7) +mpls,mpls_ttl=1,actions=set_mpls_ttl(0) +mpls,mpls_ttl=1,actions=set_mpls_ttl(200) +mpls,mpls_ttl=1,actions=set_mpls_ttl(255) ]]) AT_CHECK([ovs-ofctl parse-flows flows.txt @@ -506,6 +516,16 @@ NXT_FLOW_MOD: ADD table:255 actions=output(port=123,max_len=100) NXT_FLOW_MOD: ADD table:255 actions=output(port=100,max_len=123) NXT_FLOW_MOD: ADD table:255 actions=output(port=LOCAL,max_len=123) NXT_FLOW_MOD: ADD table:255 actions=output(port=IN_PORT,max_len=123) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_label=1 actions=set_mpls_label(0) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_label=1 actions=set_mpls_label(10) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_label=1 actions=set_mpls_label(16) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_label=1 actions=set_mpls_label(1048575) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_tc=1 actions=set_mpls_tc(0) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_tc=1 actions=set_mpls_tc(3) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_tc=1 actions=set_mpls_tc(7) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_ttl=1 actions=set_mpls_ttl(0) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_ttl=1 actions=set_mpls_ttl(200) +NXT_FLOW_MOD: ADD table:255 mpls,mpls_ttl=1 actions=set_mpls_ttl(255) ]]) AT_CLEANUP