Skip to content

Commit 87b58dd

Browse files
committed
On NetworkManager systems, apply the boot-time IP config rather than activating a single interface
1 parent a565d25 commit 87b58dd

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

Diff for: feature-virt.pl

+26-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ sub setup_virt
4343
};
4444
$virt->{'fullname'} = $virt->{'name'}.":".$virt->{'virtual'};
4545
&net::save_interface($virt);
46-
&net::activate_interface($virt);
46+
if (&auto_apply_interface()) {
47+
&net::apply_network();
48+
}
49+
else {
50+
&net::activate_interface($virt);
51+
}
4752
$d->{'iface'} = $virt->{'fullname'};
4853
&$second_print(&text('setup_virtdone', $d->{'iface'}));
4954
}
@@ -83,8 +88,12 @@ sub delete_virt
8388
}
8489
elsif ($biface->{'virtual'} ne '') {
8590
&net::delete_interface($biface);
86-
&net::deactivate_interface($aiface)
87-
if ($aiface && $aiface->{'virtual'} ne '');
91+
if (&auto_apply_interface()) {
92+
&net::apply_network();
93+
}
94+
elsif ($aiface && $aiface->{'virtual'} ne '') {
95+
&net::deactivate_interface($aiface)
96+
}
8897
&$second_print($text{'setup_done'});
8998
}
9099
else {
@@ -112,12 +121,15 @@ sub modify_virt
112121
&net::boot_interfaces();
113122
local ($aiface) = grep { $_->{'address'} eq $oldd->{'ip'} }
114123
&net::active_interfaces();
115-
if ($biface && $aiface) {
124+
if ($biface) {
116125
if ($biface->{'virtual'} ne '') {
117126
$biface->{'address'} = $d->{'ip'};
118127
&net::save_interface($biface);
119128
}
120-
if ($aiface->{'virtual'} ne '') {
129+
if (&auto_apply_interface()) {
130+
&net::apply_network();
131+
}
132+
elsif ($aiface->{'virtual'} ne '') {
121133
$aiface->{'address'} = $d->{'ip'};
122134
&net::activate_interface($aiface);
123135
}
@@ -488,6 +500,15 @@ sub can_reset_virt
488500
return 0;
489501
}
490502

503+
# auto_apply_interface()
504+
# Returns 1 if changes should only be made to the boot-time interface config,
505+
# and then applied
506+
sub auto_apply_interface
507+
{
508+
&foreign_require("net");
509+
return $net::net_mode eq "nm";
510+
}
511+
491512
$done_feature_script{'virt'} = 1;
492513

493514
1;

Diff for: feature-virt6.pl

+29-19
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,17 @@ sub activate_ip6_interface
363363
{
364364
local ($iface) = @_;
365365
&foreign_require("net");
366-
my @active = &net::active_interfaces();
367-
my ($active) = grep { $_->{'fullname'} eq $iface->{'name'} } @active;
368-
$active || &error("No active interface found for $iface->{'name'}");
369-
push(@{$active->{'address6'}}, $iface->{'address'});
370-
push(@{$active->{'netmask6'}}, $iface->{'netmask'});
371-
&net::activate_interface($active);
366+
if (&auto_apply_interface()) {
367+
&net::apply_network();
368+
}
369+
else {
370+
my @active = &net::active_interfaces();
371+
my ($active) = grep { $_->{'fullname'} eq $iface->{'name'} } @active;
372+
$active || &error("No active interface found for $iface->{'name'}");
373+
push(@{$active->{'address6'}}, $iface->{'address'});
374+
push(@{$active->{'netmask6'}}, $iface->{'netmask'});
375+
&net::activate_interface($active);
376+
}
372377
}
373378

374379
# save_ip6_interface(&iface)
@@ -390,20 +395,25 @@ sub save_ip6_interface
390395
sub deactivate_ip6_interface
391396
{
392397
local ($iface) = @_;
393-
my @active = &net::active_interfaces();
394-
my ($active) = grep { $_->{'fullname'} eq $iface->{'name'} } @active;
395-
$active || &error("No active interface found for $iface->{'name'}");
396-
my $found = 0;
397-
for(my $i=0; $i<@{$active->{'address6'}}; $i++) {
398-
if (&canonicalize_ip6($iface->{'address'}) eq
399-
&canonicalize_ip6($active->{'address6'}->[$i])) {
400-
splice(@{$active->{'address6'}}, $i, 1);
401-
splice(@{$active->{'netmask6'}}, $i, 1);
402-
$found++;
403-
}
398+
if (&auto_apply_interface()) {
399+
&net::apply_network();
404400
}
405-
if ($found) {
406-
&net::activate_interface($active);
401+
else {
402+
my @active = &net::active_interfaces();
403+
my ($active) = grep { $_->{'fullname'} eq $iface->{'name'} } @active;
404+
$active || &error("No active interface found for $iface->{'name'}");
405+
my $found = 0;
406+
for(my $i=0; $i<@{$active->{'address6'}}; $i++) {
407+
if (&canonicalize_ip6($iface->{'address'}) eq
408+
&canonicalize_ip6($active->{'address6'}->[$i])) {
409+
splice(@{$active->{'address6'}}, $i, 1);
410+
splice(@{$active->{'netmask6'}}, $i, 1);
411+
$found++;
412+
}
413+
}
414+
if ($found) {
415+
&net::activate_interface($active);
416+
}
407417
}
408418
}
409419

Diff for: virtual-server-lib-funcs.pl

+6-1
Original file line numberDiff line numberDiff line change
@@ -17313,7 +17313,12 @@ sub activate_shared_ip
1731317313
};
1731417314
$virt->{'fullname'} = $virt->{'name'}.":".$virt->{'virtual'};
1731517315
&net::save_interface($virt);
17316-
&net::activate_interface($virt);
17316+
if (&auto_apply_interface()) {
17317+
&net::apply_network();
17318+
}
17319+
else {
17320+
&net::activate_interface($virt);
17321+
}
1731717322
return undef;
1731817323
}
1731917324

0 commit comments

Comments
 (0)