From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id ECBE468E21 for ; Fri, 28 Aug 2020 14:37:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E08882110C for ; Fri, 28 Aug 2020 14:37:17 +0200 (CEST) Received: from mailpro.odiso.net (mailpro.odiso.net [89.248.211.110]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 8B0C720E52 for ; Fri, 28 Aug 2020 14:37:01 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailpro.odiso.net (Postfix) with ESMTP id 7B61315F9E18; Fri, 28 Aug 2020 14:36:58 +0200 (CEST) Received: from mailpro.odiso.net ([127.0.0.1]) by localhost (mailpro.odiso.net [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id fS3TyStIT6bF; Fri, 28 Aug 2020 14:36:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailpro.odiso.net (Postfix) with ESMTP id 62EAE15F9E1A; Fri, 28 Aug 2020 14:36:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at mailpro.odiso.com Received: from mailpro.odiso.net ([127.0.0.1]) by localhost (mailpro.odiso.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OlF7H4Y9ctyH; Fri, 28 Aug 2020 14:36:58 +0200 (CEST) Received: from pve.fritz.box (unknown [213.211.148.86]) by mailpro.odiso.net (Postfix) with ESMTPSA id 317DF15F9E18; Fri, 28 Aug 2020 14:36:58 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Fri, 28 Aug 2020 14:36:47 +0200 Message-Id: <20200828123649.11125-20-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200828123649.11125-1-aderumier@odiso.com> References: <20200828123649.11125-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [evpnplugin.pm, simpleplugin.pm] Subject: [pve-devel] [PATCH v7 pve-network 19/21] zones: evpn|simple: add snat iptables rules X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 12:37:20 -0000 (use snat instead masquerade for performance) --- PVE/Network/SDN/Zones/EvpnPlugin.pm | 18 ++++++++++++++++++ PVE/Network/SDN/Zones/SimplePlugin.pm | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/PVE/Network/SDN/Zones/EvpnPlugin.pm b/PVE/Network/SDN/Zones/= EvpnPlugin.pm index ff25f12..b89f4b1 100644 --- a/PVE/Network/SDN/Zones/EvpnPlugin.pm +++ b/PVE/Network/SDN/Zones/EvpnPlugin.pm @@ -51,6 +51,7 @@ sub generate_sdn_config { =20 my $vrf_iface =3D "vrf_$zoneid"; my $vrfvxlan =3D $plugin_config->{'vrf-vxlan'}; + my $local_node =3D PVE::INotify::nodename(); =20 die "missing vxlan tag" if !$tag; warn "vlan-aware vnet can't be enabled with evpn plugin" if $vnet->{= vlanaware}; @@ -86,6 +87,23 @@ sub generate_sdn_config { push @iface_config, "address $gateway" if !defined($address->{$gate= way}); $address->{$gateway} =3D 1; } + if ($subnet->{snat}) { + my $gatewaynodes =3D $controller->{'gateway-nodes'}; + my $is_evpn_gateway =3D ""; + foreach my $evpn_gatewaynode (PVE::Tools::split_list($gatewaynodes)= ) { + $is_evpn_gateway =3D 1 if $evpn_gatewaynode eq $local_node; + } + #find outgoing interface + my ($outip, $outiface) =3D PVE::Network::SDN::Zones::Plugin:= :get_local_route_ip('8.8.8.8'); + if ($outip && $outiface && $is_evpn_gateway) { + #use snat, faster than masquerade + push @iface_config, "post-up iptables -t nat -A POSTROUT= ING -s '$cidr' -o $outiface -j SNAT --to-source $outip"; + push @iface_config, "post-down iptables -t nat -D POSTRO= UTING -s '$cidr' -o $outiface -j SNAT --to-source $outip"; + #add conntrack zone once on outgoing interface + push @iface_config, "post-up iptables -t raw -I PREROUTI= NG -i fwbr+ -j CT --zone 1"; + push @iface_config, "post-down iptables -t raw -D PREROU= TING -i fwbr+ -j CT --zone 1"; + } + } } =20 push @iface_config, "hwaddress $mac" if $mac; diff --git a/PVE/Network/SDN/Zones/SimplePlugin.pm b/PVE/Network/SDN/Zone= s/SimplePlugin.pm index a4299dd..c58ae87 100644 --- a/PVE/Network/SDN/Zones/SimplePlugin.pm +++ b/PVE/Network/SDN/Zones/SimplePlugin.pm @@ -48,6 +48,18 @@ sub generate_sdn_config { #add route for /32 pointtopoint my ($ip, $mask) =3D split(/\//, $cidr); push @iface_config, "up ip route add $cidr dev $vnetid" if $mask =3D=3D= 32; + if ($subnet->{snat}) { + #find outgoing interface + my ($outip, $outiface) =3D PVE::Network::SDN::Zones::Plugin::get_lo= cal_route_ip('8.8.8.8'); + if ($outip && $outiface) { + #use snat, faster than masquerade + push @iface_config, "post-up iptables -t nat -A POSTROUTING -s '$cidr'= -o $outiface -j SNAT --to-source $outip"; + push @iface_config, "post-down iptables -t nat -D POSTROUTING -s '$cid= r' -o $outiface -j SNAT --to-source $outip"; + #add conntrack zone once on outgoing interface + push @iface_config, "post-up iptables -t raw -I PREROUTING -i fwbr+ -j= CT --zone 1"; + push @iface_config, "post-down iptables -t raw -D PREROUTING -i fwbr+ = -j CT --zone 1"; + } + } } =20 push @iface_config, "hwaddress $mac" if $mac; --=20 2.20.1