From: Christoph Heiss <c.heiss@proxmox.com>
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 [thread overview]
Message-ID: <20260908101647.1057780-6-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260908101647.1057780-1-c.heiss@proxmox.com>
Makes it more readable and a bit easier to add more logic in the future.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
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
next prev parent reply other threads:[~2026-09-08 10:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 10:16 [PATCH installer/proxmox 00/15] partially fix #2164: add bond setup across all installers Christoph Heiss
2026-09-08 10:16 ` [PATCH proxmox 01/15] installer-types: use `MacAddress` type where applicable Christoph Heiss
2026-09-08 10:16 ` [PATCH proxmox 02/15] installer-types: answer: add options for configuring management bond Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 03/15] install: run make tidy Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 04/15] tree-wide: use `MacAddress` type instead of string for MAC addresses Christoph Heiss
2026-09-08 10:16 ` Christoph Heiss [this message]
2026-09-08 10:16 ` [PATCH installer 06/15] install: do not rely on interface name map to be fully populated Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 07/15] install: config: add option for setting up bond on management interface Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 08/15] install: network: set up management bond if requested Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 09/15] gui: network: factor out name pinning into advanced options dialog Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 10/15] gui: network: add bond setup options to " Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 11/15] auto: pass trough management network bond options to low-level installer Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 12/15] tui: drop long obsolete comment about logo formatting Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 13/15] tui: views: add widget for displaying a group of checkboxes Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 14/15] tui: network: factor out name pinning into advanced options dialog Christoph Heiss
2026-09-08 10:16 ` [PATCH installer 15/15] tui: network: add bond setup options to advanced network dialog Christoph Heiss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908101647.1057780-6-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox