Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncm-network: nmstate - fix default gateway and policy routing table #1642

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ sub generate_vip_config {
# to add additional options, it should be constructed here.
sub generate_nmstate_config
{
my ($self, $name, $net, $ipv6, $routing_table) = @_;
my ($self, $name, $net, $ipv6, $routing_table, $default_gw) = @_;

my $bonded_eth = get_bonded_eth($self, $net->{interfaces});
my $iface = $net->{interfaces}->{$name};
Expand Down Expand Up @@ -356,12 +356,15 @@ sub generate_nmstate_config

# create default route entry.
my %default_rt;
if (defined($iface->{gateway})){
$default_rt{destination} = '0.0.0.0/0';
$default_rt{'next-hop-address'} = $iface->{gateway};
$default_rt{'next-hop-interface'} = $device;
if ($default_gw) {
# create only default gw entry if gw entry match interface gateway defined
# otherwise this interface is not the default gw interface.
if ((defined($iface->{gateway})) and ($iface->{gateway} eq $default_gw)) {
$default_rt{destination} = '0.0.0.0/0';
$default_rt{'next-hop-address'} = $default_gw;
$default_rt{'next-hop-interface'} = $device;
}
}

# combined default route with any policy routing/rule, if any
# combination of default route, plus any additional policy routes.
# read and set by tt module as
Expand Down Expand Up @@ -604,7 +607,10 @@ sub Configure

my $hostname = $nwtree->{realhostname} || "$nwtree->{hostname}.$nwtree->{domainname}";
my $manage_dns = $nwtree->{nm_manage_dns} || 0;

my $dgw = $nwtree->{default_gateway};
if (!$dgw) {
$self->warn ("No default gateway configured");
}
# The original, assumed to be working resolv.conf
# Using an FileEditor: it will read the current content, so we can do a close later to save it
# in case something changed it behind our back. Only if NM is not set to manage dns.
Expand All @@ -614,10 +620,13 @@ sub Configure
*$resolv_conf_fh->{original_content} = undef;
}

# create routing tables if defined.
$self->routing_table($nwtree->{routing_table});

my $ipv6 = $nwtree->{ipv6};
foreach my $ifacename (sort keys %$ifaces) {
my $iface = $ifaces->{$ifacename};
my $nmstate_cfg = generate_nmstate_config($self, $ifacename, $net, $ipv6, $nwtree->{routing_table});
my $nmstate_cfg = generate_nmstate_config($self, $ifacename, $net, $ipv6, $nwtree->{routing_table}, $dgw);
my $file_name = $self->iface_filename($ifacename);
$exifiles->{$file_name} = $self->nmstate_file_dump($file_name, $nmstate_cfg);

Expand Down