Skip to content

Commit

Permalink
Fix: net bridge (UPC#1715)
Browse files Browse the repository at this point in the history
fix: expose ports only when there are nat interfaces
  • Loading branch information
frankiejol authored Mar 8, 2022
1 parent 750f03a commit b15e16f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
18 changes: 18 additions & 0 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3517,6 +3517,11 @@ sub open_exposed_ports($self) {
return if !@ports;
return if !$self->is_active;

if (!$self->has_nat_interfaces) {
$self->_set_ports_direct();
return;
}

my $ip = $self->ip;
if ( ! $ip ) {
die "Error: No ip in domain ".$self->name.". Retry.\n";
Expand All @@ -3533,6 +3538,15 @@ sub open_exposed_ports($self) {
}
}

sub _set_ports_direct($self) {
my $sth_update = $$CONNECTOR->dbh->prepare(
"UPDATE domain_ports set public_port=NULL "
." WHERE id_domain=?"
);
$sth_update->execute($self->id);

}

sub _close_exposed_port($self,$internal_port_req=undef) {
my $query = "SELECT public_port,internal_port, internal_ip "
." FROM domain_ports"
Expand Down Expand Up @@ -6329,6 +6343,10 @@ sub has_non_shared_storage($self, $node=$self->_vm->new(host => 'localhost')) {
return $has_non_shared;
}

sub has_nat_interfaces($self) {
return 0;
}

sub _base_in_nodes($self) {
my $base = Ravada::Front::Domain->open($self->id_base);
confess "Error: no id_base ".($self->id_base or '<NULL>')
Expand Down
11 changes: 11 additions & 0 deletions lib/Ravada/Domain/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3060,4 +3060,15 @@ sub _remove_backingstore($self, $file) {
$self->reload_config($doc);
}

sub has_nat_interfaces($self) {
my $doc = XML::LibXML->load_xml(string
=> $self->xml_description(Sys::Virt::Domain::XML_INACTIVE))
or die "ERROR: $!\n";

for my $if ($doc->findnodes('/domain/devices/interface/source')) {
return 1 if $if->getAttribute('network');
}
return 0;
}

1;
19 changes: 15 additions & 4 deletions lib/Ravada/Domain/Void.pm
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,17 @@ sub _set_default_info($self, $listen_ip=undef) {
,time => time
};

$info->{interfaces}->[0] = {
$self->_store(info => $info);
$self->_set_display($listen_ip);
my $hardware = $self->_value('hardware');

$hardware->{network}->[0] = {
hwaddr => $info->{mac}
,address => $info->{ip}
,type => 'nat'
};
$self->_store(hardware => $hardware );

$self->_store(info => $info);
$self->_set_display($listen_ip);
my $hardware = $self->_value('hardware');
my %controllers = $self->list_controllers;
for my $name ( sort keys %controllers) {
next if $name eq 'disk' || $name eq 'display';
Expand Down Expand Up @@ -1045,4 +1048,12 @@ sub copy_config($self, $domain) {
}
}

sub has_nat_interfaces($self) {
my $config = $self->_load();
for my $if (@{$config->{hardware}->{network}}) {
return 1 if exists $if->{type} && $if->{type} eq 'nat';
}
return 0;
}

1;
1 change: 1 addition & 0 deletions t/vm/92_ports.t
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ sub _iptables_save($vm,$table=undef,$chain=undef) {
}

sub test_interfaces($vm) {
return if $vm->type ne 'KVM';
my $domain = $BASE->clone(name => new_domain_name, user => user_admin);
$domain->start( remote_ip => '10.1.1.2', user => user_admin);

Expand Down

0 comments on commit b15e16f

Please sign in to comment.