From nobody Sun Feb 8 05:07:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591627940; cv=none; d=zohomail.com; s=zohoarc; b=n8RjMdw+xSEMkzO2KmW+Mp2XIpeH3Mq1H1D1lhzS+3/wVjLWgRjJMJDst+QTWG35uDr8qg6Vxi0nevL+WQ9RhNEQS5VAfrpj2Nt/LK8MNotRAKd7fDBENWa8mX61hy3k8X31HH7QBszWwQPWS38J8CpTm+Bn3K29YRpbFLIUT9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591627940; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f7nphCfTlnJwVIQwU6dPzJCbfIWFcxXJQOyAjGZDR/8=; b=gWPDJDKgg0cTMMzBDyvFAitl2a9EhVaYnlvDk3NK9YcmRTS3LDr4KKIktqt82S85mb8Zlsb/aMrzQWDYGD38hKtNPhg0mUhknQchGKrCQSyCs9xuNhHTXQGuJ6ycixun+/jRYqiZiKqq7ClnOybG0zkMtp3GWToC6OHnzJM+FO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1591627940542145.20193951072883; Mon, 8 Jun 2020 07:52:20 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-TLPyq16kM1uHimefhqVexQ-1; Mon, 08 Jun 2020 10:52:00 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0327835B42; Mon, 8 Jun 2020 14:51:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6CC575D9C9; Mon, 8 Jun 2020 14:51:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 555C518095FF; Mon, 8 Jun 2020 14:51:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 058Epo37003391 for ; Mon, 8 Jun 2020 10:51:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id B5DA69F43; Mon, 8 Jun 2020 14:51:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 693566111F; Mon, 8 Jun 2020 14:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591627939; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=f7nphCfTlnJwVIQwU6dPzJCbfIWFcxXJQOyAjGZDR/8=; b=JOvkkkyQd4BTDk2ySYX6aqdzI8CPm5pmBWOWzNVSZPlwct4uw9XbNkjXM299pECpWu2ffW bOQCaHbFhPkWF80SFgEjHlF4N2o3OGOlF87hHD2uarA1GYXbWPSy/i+XoI/k0U/qxE1nSq it0FZISsZ8dc/JP0OCG4T+7jUxdA1pQ= X-MC-Unique: TLPyq16kM1uHimefhqVexQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/3] util: add support for IPv6 masquerade rules Date: Mon, 8 Jun 2020 15:51:39 +0100 Message-Id: <20200608145141.3616144-2-berrange@redhat.com> In-Reply-To: <20200608145141.3616144-1-berrange@redhat.com> References: <20200608145141.3616144-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Laine Stump X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) IPv6 does support masquerade since Linux 3.9.0 / ip6tables 1.4.18, which is Fedora 18 / RHEL-7 vintage, which covers all our supported Linux versions. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/viriptables.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/util/viriptables.c b/src/util/viriptables.c index e6a1ded8d5..8ccce835b2 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -854,29 +854,24 @@ iptablesForwardMasquerade(virFirewallPtr fw, g_autofree char *portRangeStr =3D NULL; g_autofree char *natRangeStr =3D NULL; virFirewallRulePtr rule; + int af =3D VIR_SOCKET_ADDR_FAMILY(netaddr); + virFirewallLayer layer =3D af =3D=3D AF_INET ? + VIR_FIREWALL_LAYER_IPV4 : VIR_FIREWALL_LAYER_IPV6; =20 if (!(networkstr =3D iptablesFormatNetwork(netaddr, prefix))) return -1; =20 - if (!VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET)) { - /* Higher level code *should* guaranteee it's impossible to get he= re. */ - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Attempted to NAT '%s'. NAT is only supported for= IPv4."), - networkstr); - return -1; - } - - if (VIR_SOCKET_ADDR_IS_FAMILY(&addr->start, AF_INET)) { + if (VIR_SOCKET_ADDR_IS_FAMILY(&addr->start, af)) { if (!(addrStartStr =3D virSocketAddrFormat(&addr->start))) return -1; - if (VIR_SOCKET_ADDR_IS_FAMILY(&addr->end, AF_INET)) { + if (VIR_SOCKET_ADDR_IS_FAMILY(&addr->end, af)) { if (!(addrEndStr =3D virSocketAddrFormat(&addr->end))) return -1; } } =20 if (protocol && protocol[0]) { - rule =3D virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, + rule =3D virFirewallAddRule(fw, layer, "--table", "nat", action =3D=3D ADD ? "--insert" : "--dele= te", pvt ? "LIBVIRT_PRT" : "POSTROUTING", @@ -885,7 +880,7 @@ iptablesForwardMasquerade(virFirewallPtr fw, "!", "--destination", networkstr, NULL); } else { - rule =3D virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, + rule =3D virFirewallAddRule(fw, layer, "--table", "nat", action =3D=3D ADD ? "--insert" : "--dele= te", pvt ? "LIBVIRT_PRT" : "POSTROUTING", @@ -1004,20 +999,14 @@ iptablesForwardDontMasquerade(virFirewallPtr fw, int action) { g_autofree char *networkstr =3D NULL; + virFirewallLayer layer =3D VIR_SOCKET_ADDR_FAMILY(netaddr) =3D=3D AF_I= NET ? + VIR_FIREWALL_LAYER_IPV4 : VIR_FIREWALL_LAYER_IPV6; =20 if (!(networkstr =3D iptablesFormatNetwork(netaddr, prefix))) return -1; =20 - if (!VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET)) { - /* Higher level code *should* guaranteee it's impossible to get he= re. */ - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Attempted to NAT '%s'. NAT is only supported for= IPv4."), - networkstr); - return -1; - } - if (physdev && physdev[0]) - virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, + virFirewallAddRule(fw, layer, "--table", "nat", action =3D=3D ADD ? "--insert" : "--delete", pvt ? "LIBVIRT_PRT" : "POSTROUTING", @@ -1027,7 +1016,7 @@ iptablesForwardDontMasquerade(virFirewallPtr fw, "--jump", "RETURN", NULL); else - virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, + virFirewallAddRule(fw, layer, "--table", "nat", action =3D=3D ADD ? "--insert" : "--delete", pvt ? "LIBVIRT_PRT" : "POSTROUTING", --=20 2.26.2