From patchwork Thu Oct 26 18:09:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 830851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3yNFPs4pSyz9t3V for ; Fri, 27 Oct 2017 05:09:05 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AB767A7F; Thu, 26 Oct 2017 18:09:03 +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 0E2D89C for ; Thu, 26 Oct 2017 18:09:03 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B3C70553 for ; Thu, 26 Oct 2017 18:09:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06C59C0587CA for ; Thu, 26 Oct 2017 18:09:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06C59C0587CA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mmichels@redhat.com Received: from monae.redhat.com (ovpn-123-238.rdu2.redhat.com [10.10.123.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id B54015D969 for ; Thu, 26 Oct 2017 18:09:01 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Thu, 26 Oct 2017 13:09:01 -0500 Message-Id: <20171026180901.19267-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 26 Oct 2017 18:09:02 +0000 (UTC) X-Spam-Status: No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] OVN: Don't let peers be set to "" on port bindings. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org There are a couple of places in ovn-northd that set the "peer" option on certain ports to "" in certain cases. In every case where a peer is looked up on a port binding, the code performs a NULL check in order to ensure a peer exists. None check for the "" string. They assume that the presence of a peer string means a peer is defined and all is well. In the past (OVS 2.6 series), this sometimes led to patch ports being created in ovs that had names like "patch-ro-to-". This particular problem resolved itself in OVS 2.7 since such patch ports were no longer automatically created. However, by naming the peer "" the seeds are still sown for similar issues to occur. The solution this patch suggests is to no longer set the "peer" option on a port binding to "". Instead, if no peer can be set, then we set no peer. Since other code is already equipped to deal with this, this poses no problem. Signed-off-by: Mark Michelson --- ovn/northd/ovn-northd.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 2db238073..ec981541e 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -1924,8 +1924,9 @@ ovn_port_update_sbrec(struct northd_context *ctx, } smap_add(&new, "distributed-port", op->nbrp->name); } else { - const char *peer = op->peer ? op->peer->key : ""; - smap_add(&new, "peer", peer); + if (op->peer) { + smap_add(&new, "peer", op->peer->key); + } if (chassis_name) { smap_add(&new, "l3gateway-chassis", chassis_name); } @@ -1978,16 +1979,20 @@ ovn_port_update_sbrec(struct northd_context *ctx, sbrec_port_binding_set_type(op->sb, "patch"); } - const char *router_port = smap_get_def(&op->nbsp->options, - "router-port", ""); - struct smap new; - smap_init(&new); - smap_add(&new, "peer", router_port); - if (chassis) { - smap_add(&new, "l3gateway-chassis", chassis); + const char *router_port = smap_get(&op->nbsp->options, + "router-port"); + if (router_port || chassis) { + struct smap new; + smap_init(&new); + if (router_port) { + smap_add(&new, "peer", router_port); + } + if (chassis) { + smap_add(&new, "l3gateway-chassis", chassis); + } + sbrec_port_binding_set_options(op->sb, &new); + smap_destroy(&new); } - sbrec_port_binding_set_options(op->sb, &new); - smap_destroy(&new); const char *nat_addresses = smap_get(&op->nbsp->options, "nat-addresses");