From patchwork Thu Jul 25 14:00:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frode Nordahl X-Patchwork-Id: 1964785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WVCFn3Ww3z1yXx for ; Fri, 26 Jul 2024 00:00:29 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id A184960AA2; Thu, 25 Jul 2024 14:00:27 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id xFWGHpYmcaG9; Thu, 25 Jul 2024 14:00:26 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5F9A460AAE Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5F9A460AAE; Thu, 25 Jul 2024 14:00:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 38790C0033; Thu, 25 Jul 2024 14:00:26 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 16079C002A for ; Thu, 25 Jul 2024 14:00:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DC43540986 for ; Thu, 25 Jul 2024 14:00:23 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id lTY7_HZeCq2p for ; Thu, 25 Jul 2024 14:00:23 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.208.180; helo=mail-lj1-f180.google.com; envelope-from=frode.nordahl@gmail.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 6AB91406AA Authentication-Results: smtp4.osuosl.org; dmarc=fail (p=none dis=none) header.from=ubuntu.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 6AB91406AA Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by smtp4.osuosl.org (Postfix) with ESMTPS id 6AB91406AA for ; Thu, 25 Jul 2024 14:00:21 +0000 (UTC) Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2ef2d582e31so2186711fa.2 for ; Thu, 25 Jul 2024 07:00:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721916019; x=1722520819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RkL0tAuLrKymK7/SSJ5hLv2wbDJrw/SCusjcY7krrsk=; b=tdfBz+gqI/apJ9wAsekk+eLFOPDhoekwdeFmP5rpqZAIWBxpWCHCTsWcyhSOHCMVvf FiIv93MRiJTA10B3keT50JbqCzmGuVEK+P1wH2VU4TnlyEaYJcZ3fXCVSlVKhLfIoBac MO/2KiwToknnBnqOfXYtk8o4cxh2PZ6Ci9A7R8+VPCKFKwzrDJpoV+1G5eHBZN7WYa87 3sDkjKkbYasr+K52FWeUSD6fqD6hA3ubCI8hcdwB8TvOsox2gi4cbw/IP8fY6Z0vQ0x+ NjN6UQsN3pgke2c7klia4XflnQmASgqo9CmqQ+VEDKL64XTLRC3SZp4QpBSAsG+EjnfX W6vA== X-Gm-Message-State: AOJu0Yx+AzTnePKXhQs6N6HG7OCJGm8trrMviwyuLK3coBn3UoZQtSYO 8CjxJ/TL78q/tSCFckMdUZCmRNmv2jmFbYJ6AA4q1Fq71q+7hImOo+YctA== X-Google-Smtp-Source: AGHT+IFq4KH3vCFabxaPvdkhp451+JwYkZsvGGIMGKOC4W8HUN2N1CpUPLADsI5Gehz4YBuqoBhGkg== X-Received: by 2002:a2e:868e:0:b0:2ef:2ed2:25b1 with SMTP id 38308e7fff4ca-2f03db909b0mr14589811fa.20.1721916018734; Thu, 25 Jul 2024 07:00:18 -0700 (PDT) Received: from localhost.localdomain ([2001:4643:d087:0:bd05:8094:92b2:c0a]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f03cf0e36csm2027211fa.17.2024.07.25.07.00.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 07:00:18 -0700 (PDT) From: Frode Nordahl To: dev@openvswitch.org Date: Thu, 25 Jul 2024 16:00:07 +0200 Message-ID: <20240725140009.413791-5-fnordahl@ubuntu.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725140009.413791-1-fnordahl@ubuntu.com> References: <20240719020943.380924-1-fnordahl@ubuntu.com> <20240725140009.413791-1-fnordahl@ubuntu.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn v3 5/7] northd: Allow IPv6 in get_nat_addresses(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" While IPv6 and NAT does not ring particularly well together in my mind, it is a supported feature. We need this function to allow them in a subsequent patch adding host route exchange for NAT addresses. Signed-off-by: Frode Nordahl --- northd/northd.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index 5b50ea191..d2d557f0b 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -1121,14 +1121,16 @@ destroy_routable_addresses(struct ovn_port_routable_addresses *ra) static char **get_nat_addresses(const struct ovn_port *op, size_t *n, bool routable_only, bool include_lb_ips, - const struct lr_stateful_record *); + const struct lr_stateful_record *, + bool allow_ipv6); static struct ovn_port_routable_addresses get_op_routable_addresses(struct ovn_port *op, const struct lr_stateful_record *lr_stateful_rec) { size_t n; - char **nats = get_nat_addresses(op, &n, true, true, lr_stateful_rec); + char **nats = get_nat_addresses(op, &n, true, true, lr_stateful_rec, + false); if (!nats) { return (struct ovn_port_routable_addresses) { @@ -2416,7 +2418,8 @@ join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, static char ** get_nat_addresses(const struct ovn_port *op, size_t *n, bool routable_only, bool include_lb_ips, - const struct lr_stateful_record *lr_stateful_rec) + const struct lr_stateful_record *lr_stateful_rec, + bool allow_ipv6) { size_t n_nats = 0; struct eth_addr mac; @@ -2439,6 +2442,7 @@ get_nat_addresses(const struct ovn_port *op, size_t *n, bool routable_only, for (size_t i = 0; i < op->od->nbr->n_nat; i++) { const struct nbrec_nat *nat = op->od->nbr->nat[i]; ovs_be32 ip, mask; + struct in6_addr ip6, mask6; if (routable_only && (!strcmp(nat->type, "snat") || @@ -2449,7 +2453,15 @@ get_nat_addresses(const struct ovn_port *op, size_t *n, bool routable_only, char *error = ip_parse_masked(nat->external_ip, &ip, &mask); if (error || mask != OVS_BE32_MAX) { free(error); - continue; + if (allow_ipv6) { + error = ipv6_parse_masked(nat->external_ip, &ip6, &mask6); + if (error || ipv6_count_cidr_bits(&mask6) != 128) { + free(error); + continue; + } + } else { + continue; + } } /* Not including external IP of NAT rules whose gateway_port is @@ -3783,7 +3795,8 @@ sync_pb_for_lsp(struct ovn_port *op, lr_stateful_table, op->peer->od->index); } nats = get_nat_addresses(op->peer, &n_nats, false, - include_lb_vips, lr_stateful_rec); + include_lb_vips, lr_stateful_rec, + false); } } else if (nat_addresses && (chassis || l3dgw_ports)) { struct lport_addresses laddrs;