From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 07D801FF0B4 for ; Tue, 08 Sep 2026 12:17:53 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C58E721598; Tue, 08 Sep 2026 12:17:38 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Subject: [PATCH installer 05/15] install: factor out /etc/network/interfaces setup into own subroutine Date: Tue, 8 Sep 2026 12:16:19 +0200 Message-ID: <20260908101647.1057780-6-c.heiss@proxmox.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260908101647.1057780-1-c.heiss@proxmox.com> References: <20260908101647.1057780-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788862636527 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.397 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ILTABJGA6Z6QBQBI5A46M5FGGJTMB7C4 X-Message-ID-Hash: ILTABJGA6Z6QBQBI5A46M5FGGJTMB7C4 X-MailFrom: c.heiss@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Makes it more readable and a bit easier to add more logic in the future. Signed-off-by: Christoph Heiss --- Proxmox/Install.pm | 124 +++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/Proxmox/Install.pm b/Proxmox/Install.pm index 7bb8e29..45aa53b 100644 --- a/Proxmox/Install.pm +++ b/Proxmox/Install.pm @@ -798,6 +798,71 @@ my sub setup_proxmox_first_boot_service { } } +my sub setup_ifupdown2_config { + my ($targetdir) = @_; + + my $run_env = Proxmox::Install::RunEnv::get(); + my $iso_env = Proxmox::Install::ISOEnv::get(); + + my $ip_version = Proxmox::Install::Config::get_ip_version(); + my $ntype = $ip_version == 4 ? 'inet' : 'inet6'; + + my $interfaces = $run_env->{network}->{interfaces}; + my $ethdev = Proxmox::Install::Config::get_mngmt_nic(); + my $cidr = Proxmox::Install::Config::get_cidr(); + my $gateway = Proxmox::Install::Config::get_gateway(); + + my $netif_pin_map = Proxmox::Install::Config::get_network_interface_pin_map(); + + my $ifaces = "auto lo\niface lo inet loopback\n\n"; + + # iproute2 omits the gateway and protocol keys for some routes; route devices are original + # kernel interface names, while $ethdev can be the pinned one + my $gateways6 = $run_env->{network}->{routes}->{gateways6} // []; + my $is_gateway6_from_ra = grep { + my $dev = $_->{dev} // ''; + if (defined($netif_pin_map) && defined($interfaces->{$dev})) { + $dev = $netif_pin_map->{ $interfaces->{$dev}->{mac} } // $dev; + } + $dev eq $ethdev + && ($_->{gateway} // '') eq $gateway + && ($_->{protocol} // '') eq 'ra'; + } $gateways6->@*; + + if ($iso_env->{cfg}->{bridged_network}) { + $ifaces .= "iface $ethdev $ntype manual\n"; + + $ifaces .= + "\nauto vmbr0\niface vmbr0 $ntype static\n" + . "\taddress $cidr\n" + . "\tgateway $gateway\n" + . "\tbridge-ports $ethdev\n" + . "\tbridge-stp off\n" + . "\tbridge-fd 0\n"; + } else { + $ifaces .= "auto $ethdev\n" . # + "iface $ethdev $ntype static\n" . # + "\taddress $cidr\n"; + + if (!$is_gateway6_from_ra) { + $ifaces .= "\tgateway $gateway\n"; + } + } + + foreach my $iface (sort keys $interfaces->%*) { + my $if = $interfaces->{$iface}; + my $name = defined($netif_pin_map) ? $netif_pin_map->{ $if->{mac} } : $if->{name}; + + next if $name eq $ethdev; + + $ifaces .= "\niface $name $ntype manual\n"; + } + + $ifaces .= "\n\nsource /etc/network/interfaces.d/*\n"; + + file_write_all("$targetdir/etc/network/interfaces", $ifaces); +} + sub extract_data { my $iso_env = Proxmox::Install::ISOEnv::get(); my $run_env = Proxmox::Install::RunEnv::get(); @@ -1140,19 +1205,14 @@ sub extract_data { # configure interfaces - my $ifaces = "auto lo\niface lo inet loopback\n\n"; - - my $ip_version = Proxmox::Install::Config::get_ip_version(); - my $ntype = $ip_version == 4 ? 'inet' : 'inet6'; - - my $ethdev = Proxmox::Install::Config::get_mngmt_nic(); - my $cidr = Proxmox::Install::Config::get_cidr(); - my $gateway = Proxmox::Install::Config::get_gateway(); + setup_ifupdown2_config($targetdir); # configure pinned names for all network interfaces, if enabled my $netif_pin_map = Proxmox::Install::Config::get_network_interface_pin_map(); if (defined($netif_pin_map)) { + my $ethdev = Proxmox::Install::Config::get_mngmt_nic(); + mkdir "$targetdir/usr/local/lib/systemd", 0755; mkdir "$targetdir/usr/local/lib/systemd/network", 0755; @@ -1189,54 +1249,6 @@ sub extract_data { } } - my $interfaces = $run_env->{network}->{interfaces}; - - # iproute2 omits the gateway and protocol keys for some routes; route devices are original - # kernel interface names, while $ethdev can be the pinned one - my $gateways6 = $run_env->{network}->{routes}->{gateways6} // []; - my $is_gateway6_from_ra = grep { - my $dev = $_->{dev} // ''; - if (defined($netif_pin_map) && defined($interfaces->{$dev})) { - $dev = $netif_pin_map->{ $interfaces->{$dev}->{mac} } // $dev; - } - $dev eq $ethdev - && ($_->{gateway} // '') eq $gateway - && ($_->{protocol} // '') eq 'ra'; - } $gateways6->@*; - - if ($iso_env->{cfg}->{bridged_network}) { - $ifaces .= "iface $ethdev $ntype manual\n"; - - $ifaces .= - "\nauto vmbr0\niface vmbr0 $ntype static\n" - . "\taddress $cidr\n" - . "\tgateway $gateway\n" - . "\tbridge-ports $ethdev\n" - . "\tbridge-stp off\n" - . "\tbridge-fd 0\n"; - } else { - $ifaces .= "auto $ethdev\n" . # - "iface $ethdev $ntype static\n" . # - "\taddress $cidr\n"; - - if (!$is_gateway6_from_ra) { - $ifaces .= "\tgateway $gateway\n"; - } - } - - foreach my $iface (sort keys $interfaces->%*) { - my $if = $interfaces->{$iface}; - my $name = defined($netif_pin_map) ? $netif_pin_map->{ $if->{mac} } : $if->{name}; - - next if $name eq $ethdev; - - $ifaces .= "\niface $name $ntype manual\n"; - } - - $ifaces .= "\n\nsource /etc/network/interfaces.d/*\n"; - - file_write_all("$targetdir/etc/network/interfaces", $ifaces); - # configure dns my $dnsserver = Proxmox::Install::Config::get_dns(); -- 2.55.0