From patchwork Fri Oct 26 16:25:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 989661 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; dmarc=fail (p=none dis=none) header.from=redhat.com 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 42hTsS0YVYz9s0t for ; Sat, 27 Oct 2018 03:26:52 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EB1DD29BC; Fri, 26 Oct 2018 16:26:23 +0000 (UTC) X-Original-To: ovs-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 4E2A529AE for ; Fri, 26 Oct 2018 16:26:10 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B15867EA for ; Fri, 26 Oct 2018 16:26:09 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id f1-v6so4568762wmg.1 for ; Fri, 26 Oct 2018 09:26:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=AG3+Ns5mvQuL8XT8Z6DFC8sY5XhNqnL9/MfsRFIzvkA=; b=laSM2MoMgJ4OOS3o8ZIJvC95ZdgyUa1RNglzzTpDDkTx4JtLAo0Gyt8y9t76KQxkKc aQj72asmvOWhIOxTXQ3Vq2mOuMGcOmCzlRdY7FK0pQDlQ/sziaPvVVHvKC+xd94QtMhh qwtEgcT9B2aAONimowk5g6UucekivLi9+U2lo0TrMZyl8Hf600VkavlajkJjT26lpssa 6ld+ju7vvVsOOedMWCO/nyYTP+a7RqvvyNgD3rRTGE+cmMuGjYK32crRXMUZjQZwnle6 xH91a/ZBwgF6CSkz+v9LanKrkDs1XTJgiPW9TovNnLitWZACNM09t0TN73Y8eEHD2FrL oMaQ== X-Gm-Message-State: AGRZ1gLC+MzGoYkF3AEOtCQsH986rbjFN8uYRRbMYq0lFlo2c2TQC4aW 3hgxQLvbnCtnZjv/UJ44uaLqk8cLDDM= X-Google-Smtp-Source: AJdET5cWRs0MUpB2O+TTCWxSujBOBY6vWQFplQ6ygCPP1YTIkMsIH3cQf2ZDF1Bxi4kzNOBKTW4APQ== X-Received: by 2002:a1c:ed07:: with SMTP id l7-v6mr5980530wmh.47.1540571167950; Fri, 26 Oct 2018 09:26:07 -0700 (PDT) Received: from localhost.localdomain.com ([151.66.52.234]) by smtp.gmail.com with ESMTPSA id e142-v6sm11779507wmf.20.2018.10.26.09.26.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 09:26:07 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Fri, 26 Oct 2018 18:25:58 +0200 Message-Id: X-Mailer: git-send-email 2.17.2 In-Reply-To: References: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 1/2] OVN: assign new addresses at the end of build_ipam routine 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 Visit all ovn datapaths before adding new dynamic addresses to the system in order to avoid possible L2 address duplication when the same MAC address is configured on different ovn logical switches. Current implementation can miss the duplicated address since macam is cleared at each ovn run and there is no guarantee on visit order of ovn datapath hash table Signed-off-by: Lorenzo Bianconi --- ovn/northd/ovn-northd.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 816c72311..33fc94f72 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -1093,6 +1093,7 @@ enum dynamic_update_type { struct dynamic_address_update { struct ovs_list node; /* In build_ipam()'s list of updates. */ + struct ovn_datapath *od; struct ovn_port *op; struct lport_addresses current_addresses; @@ -1284,8 +1285,7 @@ set_dynamic_updates(const char *addrspec, } static void -update_dynamic_addresses(struct ovn_datapath *od, - struct dynamic_address_update *update) +update_dynamic_addresses(struct dynamic_address_update *update) { struct eth_addr mac; switch (update->mac) { @@ -1314,7 +1314,7 @@ update_dynamic_addresses(struct ovn_datapath *od, case STATIC: OVS_NOT_REACHED(); case DYNAMIC: - ip4 = htonl(ipam_get_unused_ip(od)); + ip4 = htonl(ipam_get_unused_ip(update->od)); } struct in6_addr ip6 = in6addr_any; @@ -1329,14 +1329,14 @@ update_dynamic_addresses(struct ovn_datapath *od, case STATIC: OVS_NOT_REACHED(); case DYNAMIC: - in6_generate_eui64(mac, &od->ipam_info.ipv6_prefix, &ip6); + in6_generate_eui64(mac, &update->od->ipam_info.ipv6_prefix, &ip6); break; } struct ds new_addr = DS_EMPTY_INITIALIZER; ds_put_format(&new_addr, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac)); if (ip4) { - ipam_insert_ip(od, ntohl(ip4)); + ipam_insert_ip(update->od, ntohl(ip4)); ds_put_format(&new_addr, " "IP_FMT, IP_ARGS(ip4)); } if (!IN6_ARE_ADDR_EQUAL(&ip6, &in6addr_any)) { @@ -1362,13 +1362,14 @@ build_ipam(struct hmap *datapaths, struct hmap *ports) /* If the switch's other_config:subnet is set, allocate new addresses for * ports that have the "dynamic" keyword in their addresses column. */ struct ovn_datapath *od; + struct ovs_list updates; + + ovs_list_init(&updates); HMAP_FOR_EACH (od, key_node, datapaths) { if (!od->nbs) { continue; } - struct ovs_list updates; - ovs_list_init(&updates); for (size_t i = 0; i < od->nbs->n_ports; i++) { const struct nbrec_logical_switch_port *nbsp = od->nbs->ports[i]; @@ -1405,6 +1406,7 @@ build_ipam(struct hmap *datapaths, struct hmap *ports) struct dynamic_address_update *update = xzalloc(sizeof *update); update->op = op; + update->od = od; if (nbsp->dynamic_addresses) { bool any_changed; extract_lsp_addresses(nbsp->dynamic_addresses, @@ -1431,15 +1433,16 @@ build_ipam(struct hmap *datapaths, struct hmap *ports) } } - /* After retaining all unchanged dynamic addresses, now assign - * new ones. - */ - struct dynamic_address_update *update; - LIST_FOR_EACH_POP (update, node, &updates) { - update_dynamic_addresses(od, update); - destroy_lport_addresses(&update->current_addresses); - free(update); - } + } + + /* After retaining all unchanged dynamic addresses, now assign + * new ones. + */ + struct dynamic_address_update *update; + LIST_FOR_EACH_POP (update, node, &updates) { + update_dynamic_addresses(update); + destroy_lport_addresses(&update->current_addresses); + free(update); } }