From patchwork Wed Sep 30 13:46:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1374370 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=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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=f6/uYDjc; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C1cxp6xm9z9sTv for ; Wed, 30 Sep 2020 23:47:08 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B71B287221; Wed, 30 Sep 2020 13:47:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RKyF4yWukokm; Wed, 30 Sep 2020 13:47:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id BE6B1871DE; Wed, 30 Sep 2020 13:47:01 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A0407C0890; Wed, 30 Sep 2020 13:47:01 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9AB96C016F for ; Wed, 30 Sep 2020 13:47:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 7EA021FCA0 for ; Wed, 30 Sep 2020 13:47:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2ZEMZZIYVwnZ for ; Wed, 30 Sep 2020 13:46:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by silver.osuosl.org (Postfix) with ESMTPS id 4C7E320368 for ; Wed, 30 Sep 2020 13:46:59 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gIPo2vG2BqG4xIG0lSPjGNSdCzMAbZDp7GwE7Q+9Yhw=; b=f6/uYDjcRSSdfSziJFfKRC7zLMHiJL6rUQF0th077vOo4ox/wzH6F1XvCKCGc3hgjZ218w DheZBaLRib50Z7UF5/ROxWX74rWKiB5Q5/q2gRA6gbrfxfgeGybLDmJbjYq3j4n+NVh8A8 4UGaRexII/XImXg2WcE6AlFKOQDLhjQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-1Mkz-relNv-zNqVITQx6_Q-1; Wed, 30 Sep 2020 09:46:40 -0400 X-MC-Unique: 1Mkz-relNv-zNqVITQx6_Q-1 Received: by mail-wm1-f71.google.com with SMTP id l26so490076wmg.7 for ; Wed, 30 Sep 2020 06:46:40 -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:mime-version :content-transfer-encoding; bh=gIPo2vG2BqG4xIG0lSPjGNSdCzMAbZDp7GwE7Q+9Yhw=; b=bakDDxRtt15SAidfOr/G36CACIY1Ion6yZVoSLQR3PcEG2/LYUeByy+Yz6a0ZVSfVw vW4JIDSaF+hf02crp9buRWEBptXle38S94IypE+JD8HAFV1ujRQetGa11czx6k/QyZlj zz0hmUhAvXqfKk350T1SHrNFuPgPeaQzRhZTxANnXKWbHUn9BX0VJBoqkAE0F9hDPzzC JL2+BD3lSdGGIg63eSUs/E9dD+CdlF8rD8IoyLqnTe5yeZqEs+ul5sb51fY+IQtFhXHT 4/Xq+8CyuNkWHXwe1DnCS1ia7W/Q0cw/ZbFelp1NbJc3tYbgGh8xbkmBV8irCHa3JP4Z nK6w== X-Gm-Message-State: AOAM531+hTfREy/FD9oP3zMksi2DJ466c8WNTQz5opmt7DkMoGQxyuhv vqKWPGZbTah8isNyKrM5TpS8TFMX7iFaGb6CdHXmyRnvcOxlv56m2ZaCcLJrMjWVO/RhFNSPcTi yTAwt1BYmDTwRQULTQg== X-Received: by 2002:adf:9027:: with SMTP id h36mr3260672wrh.259.1601473598801; Wed, 30 Sep 2020 06:46:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVTxsPyfSlyJYw6QQLqMSMgV4L/U8FnXbJBNU6zLbWeIDYN5IRSlA3uNxf/HJSRG+3qR9ILA== X-Received: by 2002:adf:9027:: with SMTP id h36mr3260652wrh.259.1601473598560; Wed, 30 Sep 2020 06:46:38 -0700 (PDT) Received: from lore-desk.redhat.com ([176.207.245.61]) by smtp.gmail.com with ESMTPSA id y1sm2847601wma.36.2020.09.30.06.46.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 06:46:37 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Wed, 30 Sep 2020 15:46:33 +0200 Message-Id: <3ea0c31c625993d8670cfc6e01aecb7af4647d6a.1601473450.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn] northd: properly reconfigure ipam when subnet is changed 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" Reconfigure dynamic assigned addresses if subnet is modified removing IP out of configured netmask if present Signed-off-by: Lorenzo Bianconi --- northd/ovn-northd.c | 48 ++++++++++++++++++++++++++------------------- tests/ovn.at | 10 ++++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 5fddc5e3e..e527e90fa 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -1665,24 +1665,6 @@ ipam_get_unused_mac(ovs_be32 ip) return mac64; } -static uint32_t -ipam_get_unused_ip(struct ovn_datapath *od) -{ - if (!od || !od->ipam_info.allocated_ipv4s) { - return 0; - } - - size_t new_ip_index = bitmap_scan(od->ipam_info.allocated_ipv4s, 0, 0, - od->ipam_info.total_ipv4s - 1); - if (new_ip_index == od->ipam_info.total_ipv4s - 1) { - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); - VLOG_WARN_RL( &rl, "Subnet address space has been exhausted."); - return 0; - } - - return od->ipam_info.start_ipv4 + new_ip_index; -} - enum dynamic_update_type { NONE, /* No change to the address */ REMOVE, /* Address is no longer dynamic */ @@ -1705,6 +1687,32 @@ struct dynamic_address_update { enum dynamic_update_type ipv6; }; +static uint32_t +ipam_get_unused_ip(struct dynamic_address_update *update) +{ + struct ovn_datapath *od = update->od; + + if (!od || !od->ipam_info.allocated_ipv4s) { + return 0; + } + + size_t new_ip_index = bitmap_scan(od->ipam_info.allocated_ipv4s, 0, 0, + od->ipam_info.total_ipv4s - 1); + if (new_ip_index == od->ipam_info.total_ipv4s - 1) { + const struct nbrec_logical_switch_port *nbsp = update->op->nbsp; + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL( &rl, "Subnet address space has been exhausted."); + + if (nbsp->dynamic_addresses) { + nbrec_logical_switch_port_set_dynamic_addresses(nbsp, NULL); + } + + return 0; + } + + return od->ipam_info.start_ipv4 + new_ip_index; +} + static enum dynamic_update_type dynamic_mac_changed(const char *lsp_addresses, struct dynamic_address_update *update) @@ -1758,7 +1766,7 @@ dynamic_ip4_changed(const char *lsp_addrs, } uint32_t index = ip4 - ipam->start_ipv4; - if (index > ipam->total_ipv4s || + if (index >= ipam->total_ipv4s - 1 || bitmap_is_set(ipam->allocated_ipv4s, index)) { /* Previously assigned dynamic IPv4 address can no longer be used. * It's either outside the subnet, conflicts with an excluded IP, @@ -1964,7 +1972,7 @@ update_dynamic_addresses(struct dynamic_address_update *update) ip4 = update->static_ip; break; case DYNAMIC: - ip4 = htonl(ipam_get_unused_ip(update->od)); + ip4 = htonl(ipam_get_unused_ip(update)); VLOG_INFO("Assigned dynamic IPv4 address '"IP_FMT"' to port '%s'", IP_ARGS(ip4), update->op->nbsp->name); } diff --git a/tests/ovn.at b/tests/ovn.at index 7769b69ed..e27a74081 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -7473,6 +7473,16 @@ AT_CHECK([ovn-nbctl get Logical-Switch-Port p103 dynamic_addresses], [0], ["22:33:44:55:66:77 172.16.1.250" ]) +ovn-nbctl ls-add sw12 +for i in $(seq 1 200); do + ovn-nbctl lsp-add sw12 sw12-p$i -- lsp-set-addresses sw12-p$i "00:00:00:00:00:$i dynamic" +done +ovn-nbctl set Logical-Switch sw12 other_config:subnet=192.10.2.0/24 +ovn-nbctl set Logical-Switch sw12 other_config:subnet=192.10.2.0/25 +AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.127], [1]) +AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.128], [1]) +AT_CHECK([ovn-nbctl list Logical-Switch-Port | grep -q 192.10.2.180], [1]) + as ovn-sb OVS_APP_EXIT_AND_WAIT([ovsdb-server])