From patchwork Mon Jan 8 11:36:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Zhenyu X-Patchwork-Id: 856774 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UW+VB+6u"; dkim-atps=neutral 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 3zFYBr5sp2z9s82 for ; Mon, 8 Jan 2018 22:36:35 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 0BCDEF03; Mon, 8 Jan 2018 11:36:33 +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 5F0FEECE for ; Mon, 8 Jan 2018 11:36:32 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id DE3A818A for ; Mon, 8 Jan 2018 11:36:31 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id j3so1893264pfh.8 for ; Mon, 08 Jan 2018 03:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=eDU8T49HFgB0H5UKQoHkQAp7m1jbGBRS98NVCpv7vlU=; b=UW+VB+6u5dMZTuejjVy9g8tsdsB55mhZk+Xl29B0uXOEkj8gvTrRYnVOg/UKozwogW uwlrm9Sly4Md+qhJQe9TtBRApDVfaos0rwN+Qfisejl5N6rJsHHTdjHfDhuQz26hC/6I TGpg6LgbZ2JVmSTc1FtfWo91XCdtaUzNNbOueBrI4+ISfE3U4zFLM3K34Lb7kPxecNV3 seqkA2OnUhpzgtntbCFAg+hOdCsAChJIXpuxfKwP86lUwubCCzQX1LjjpVqwd1pX1wNz vwQ77IuudtEGDxP5yZJXFJ5buaK13Q5HnYolRmcTcY8p5iuvVv4DJzf40W/NC2/6ufJE qqhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eDU8T49HFgB0H5UKQoHkQAp7m1jbGBRS98NVCpv7vlU=; b=b6QCdpCzoRZ1jr+na2ULX1KBJMDxhu2x5qxFUmlBtSkPS/aPYU2rMRbArrPk+nCl34 oE3sdFtAPiIPegzHzM8c2enkviacUkHZ/dXTG0MqdHCaVozlxQ/hPkCXnvBYMxhBhmz1 Ytt2ZWj489avHtFI6W3b1Vqi9+eYq5Owzopt1UoGs/EeAMwkDrlJtBBGzyUzq6C34xKQ QHuEgUfP/lefDmMTHsd1TRnHqrsiWqHeEIouelFxOJcd/vl3HOnrYh0xjcFY3pUQh2Dn Cb0utkszaWOMZMV/dmn/QFHq7WACwI4FZAsrVTeo/5UHpaCa5/oV8+ieDHWWC9TaDB0S HrMA== X-Gm-Message-State: AKGB3mJDmiWFqC3OnLhLFkBqmql9tc+jDdVpKBEvZq4GkNXfCmf2/V90 /6pdKY8Jmqe/bvhQCJmbKhNZCKLE X-Google-Smtp-Source: ACJfBot6HzSIvulo41m/Upd7sDMuGgst1cr1LuXzb1iAQ60qgwbkqbDb3Oi7tIDOnHmeSGDRzMaCrQ== X-Received: by 10.159.197.75 with SMTP id d11mr11868217plo.240.1515411391351; Mon, 08 Jan 2018 03:36:31 -0800 (PST) Received: from vultr.guest ([45.77.33.88]) by smtp.gmail.com with ESMTPSA id p10sm27464815pfl.32.2018.01.08.03.36.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 03:36:30 -0800 (PST) From: Zhenyu Gao To: dev@openvswitch.org, majopela@redhat.com Date: Mon, 8 Jan 2018 11:36:22 +0000 Message-Id: <20180108113622.14686-1-sysugaozhenyu@gmail.com> X-Mailer: git-send-email 2.11.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v1] ovn: Add sanity check when adding tunnel port 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 1. ovs cannot create two ports with same tunnel type and options:remote_ip 2. add santity check to detect if two chassises have same encap ip 3. add a sset to store tunnel ports' type & encap ip information Signed-off-by: Zhenyu Gao --- ovn/controller/encaps.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ovn/controller/encaps.c b/ovn/controller/encaps.c index f187a8f..06bffe8 100644 --- a/ovn/controller/encaps.c +++ b/ovn/controller/encaps.c @@ -50,6 +50,10 @@ struct tunnel_ctx { * adding a new tunnel. */ struct sset port_names; + /* IP,type of all tunnel ports in bridge, to allow checking uniqueness + * when adding a new tunnel. */ + struct sset tunnel_type_ips; + struct ovsdb_idl_txn *ovs_txn; const struct ovsrec_bridge *br_int; }; @@ -78,6 +82,19 @@ tunnel_create_name(struct tunnel_ctx *tc, const char *chassis_id) return NULL; } +static char* +create_tunnel_type_ip_key(struct tunnel_ctx *tc, const char *type, + const char *ip) +{ + char *tunnel_type_ip = xasprintf("%s-%s", type, ip); + if (!sset_contains(&tc->tunnel_type_ips, tunnel_type_ip)) { + return tunnel_type_ip; + } + + free(tunnel_type_ip); + return NULL; +} + static void tunnel_add(struct tunnel_ctx *tc, const char *new_chassis_id, const struct sbrec_encap *encap) @@ -116,6 +133,15 @@ tunnel_add(struct tunnel_ctx *tc, const char *new_chassis_id, goto exit; } + char *tunnel_type_ip = create_tunnel_type_ip_key(tc, encap->type, + encap->ip); + if (!tunnel_type_ip) { + VLOG_WARN("Unable to allocate unique remote_ip for '%s' %s tunnel", + encap->type, new_chassis_id); + free(port_name); + goto exit; + } + struct ovsrec_interface *iface = ovsrec_interface_insert(tc->ovs_txn); ovsrec_interface_set_name(iface, port_name); ovsrec_interface_set_type(iface, encap->type); @@ -130,6 +156,7 @@ tunnel_add(struct tunnel_ctx *tc, const char *new_chassis_id, ovsrec_bridge_update_ports_addvalue(tc->br_int, port); sset_add_and_free(&tc->port_names, port_name); + sset_add_and_free(&tc->tunnel_type_ips, tunnel_type_ip); exit: smap_destroy(&options); @@ -166,6 +193,7 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int, struct tunnel_ctx tc = { .chassis = SHASH_INITIALIZER(&tc.chassis), .port_names = SSET_INITIALIZER(&tc.port_names), + .tunnel_type_ips = SSET_INITIALIZER(&tc.tunnel_type_ips), .br_int = br_int }; @@ -194,6 +222,24 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int, * to delete this one. */ ovsrec_bridge_update_ports_delvalue(br, port); } + for (size_t i = 0; i< port->n_interfaces; i++) { + const struct ovsrec_interface *iface = port->interfaces[i]; + if (strcmp(iface->type, "geneve") + && strcmp(iface->type, "stt") + && strcmp(iface->type, "vxlan")) { + continue; + } + const char *if_remote_ip = smap_get(&iface->options, + "remote_ip"); + char *tunnel_type_ip; + tunnel_type_ip = create_tunnel_type_ip_key(&tc, + iface->type, + if_remote_ip); + if (!tunnel_type_ip) { + continue; + } + sset_add_and_free(&tc.tunnel_type_ips, tunnel_type_ip); + } } } }