Skip to content

Commit

Permalink
ncm-network: Implement support for secondary IPv6 addresses
Browse files Browse the repository at this point in the history
Based on the new IPv4 code.
  • Loading branch information
jrha committed Jul 11, 2024
1 parent 1e857f4 commit 6f9a69f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 19 additions & 10 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,20 @@ sub generate_alias_ips {
return \@$all_ip;
}


sub generate_ipv6_secondaries {
my ($self, $secondaries) = @_;
my $ips = [];
foreach my $secondary (@$secondaries) {
my $ip = NetAddr::IP->new($secondary);
if (defined($ip)) {
my $ip_list = {};
$ip_list->{ip} = $ip->addr;
$ip_list->{'prefix-length'} = $ip->masklen;
push @$ips, $ip_list;
}
}
return \@$ips;
}

# generates the hashrefs for interface in yaml file format needed by nmstate.
# bulk of the config settings needed by the nmstate yml is done here.
Expand Down Expand Up @@ -450,16 +463,12 @@ sub generate_nmstate_config
$ip_list->{'prefix-length'} = $ip->masklen;
push @$ips, $ip_list;

my @ipv6_secondaries = $iface->{ipv6addr_secondaries};
foreach my $ipv6_sec ( @ipv6_secondaries ) {
# label ipv6
my $ip = NetAddr::IP->new($ipv6_sec);
my $ip_tmp = {};
$ip_tmp->{ip} = $ip->{addr};
$ip_tmp->{'prefix-length'} = $ipv6_sec;
# push @ips, $ip_tmp;
print $ip_tmp;
if ($iface->{ipv6addr_secondaries}) {
# If interface has additional ipv6 addresses defined, add them
$self->verbose("additional ip (ipv6) addr defined for $name, configuring additional ips");
push @$ips, @{$self->generate_ipv6_secondaries($iface->{ipv6addr_secondaries})};
}

$ifaceconfig->{ipv6}->{address} = $ips;
$ifaceconfig->{ipv6}->{enabled} = $YTRUE;
} else {
Expand Down
4 changes: 4 additions & 0 deletions ncm-network/src/test/perl/nmstate_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ interfaces:
address:
- ip: 2001:678:123:E012:0:0:0:45
prefix-length: 64
- ip: 2001:678:123:E012:0:0:0:46
prefix-length: 64
- ip: 2001:678:123:E012:0:0:0:47
prefix-length: 64
enabled: true
name: eth0
profile-name: eth0
Expand Down

0 comments on commit 6f9a69f

Please sign in to comment.