From ca7d0536eb14403a1ae5fd108d4f0db9faaa4a80 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 7 Jun 2018 13:01:36 -0400 Subject: [PATCH] TT#37224 support setting IPv6 prefix length Change-Id: I10e66d8c00d6cbd8844377c359b3fc61770e750a --- sbin/ngcp-network | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/sbin/ngcp-network b/sbin/ngcp-network index 9d7afe83..175b5d25 100755 --- a/sbin/ngcp-network +++ b/sbin/ngcp-network @@ -49,6 +49,7 @@ my $man; my $move_from; my $move_to; my $netmask; +my $netmask_ip_v6; my $outputfile = $inputfile; my $peer; my @remove_host; @@ -84,6 +85,7 @@ GetOptions( 'move-from=s' => \$move_from, 'move-to=s' => \$move_to, 'netmask=s' => \$netmask, + 'netmask-ipv6=s' => \$netmask_ip_v6, 'output-file=s' => \$outputfile, 'peer=s' => \$peer, 'remove-host=s' => \@remove_host, @@ -138,7 +140,8 @@ foreach my $opt ( $gateway, @set_interface, $host, $hwaddr, $internal_iface, $ip, $ip_v6, $move_from, $move_to, $netmask, $peer, @remove_host, - @remove_interface, @roles, @type, $vlan_raw_device + @remove_interface, @roles, @type, $vlan_raw_device, + $netmask_ip_v6 ) { if ( defined $opt && $opt =~ /\s/msx ) { @@ -181,9 +184,9 @@ sub get_interface_details { return $s->$setting($interface); } -sub get_ip6_addr { +sub get_ip6_addrs { - my $interface = shift or croak 'Usage: runcmd '; + my $interface = shift or croak 'Usage: get_ip6_addrs '; my $cmd = 'ip'; my @args = ( '-6', 'addr', 'show', 'dev', $interface, 'scope', 'global' ); @@ -205,6 +208,13 @@ sub get_ip6_addr { croak "Problem with execution [return code $CHILD_ERROR]:\n@stderr"; } + return @stdout; +} + +sub get_ip6_addr { + + my @stdout = get_ip6_addrs(@_); + foreach my $line (@stdout) { if ( $line =~ /^\s*inet6\s+($IPv6_re)\/\d+.*scope.*global.*$/msx ) { return $1; @@ -214,6 +224,19 @@ sub get_ip6_addr { return; } +sub get_ip6_mask { + + my @stdout = get_ip6_addrs(@_); + + foreach my $line (@stdout) { + if ( $line =~ /^\s*inet6\s+($IPv6_re)\/(\d+).*scope.*global.*$/msx ) { + return $2; + } + } + + return; +} + sub set_interface { my $iface = shift; @@ -226,7 +249,7 @@ sub set_interface { } if ( defined $ip_v6 && $ip_v6 =~ /^auto$/msx ) { - logger("get_interface_details( $iface, 'if_addr' );"); + logger("get_ip6_addr( $iface );"); $ip_v6 = get_ip6_addr($iface); } @@ -235,6 +258,11 @@ sub set_interface { $netmask = get_interface_details( $iface, 'if_netmask' ); } + if ( defined $netmask_ip_v6 && $netmask_ip_v6 =~ /^auto$/msx ) { + logger("get_ip6_mask( $iface );"); + $netmask_ip_v6 = get_ip6_mask($iface); + } + if ( defined $hwaddr && $hwaddr =~ /^auto$/msx ) { logger("get_interface_details( $iface, 'if_hwaddr' );"); $hwaddr = get_interface_details( $iface, 'if_hwaddr' ); @@ -250,6 +278,7 @@ sub set_interface { 'hwaddr' => $hwaddr, 'ip' => $ip, 'netmask' => $netmask, + 'v6netmask' => $netmask_ip_v6, 'shared_ip' => $shared_ip, 'shared_v6ip' => $shared_ip_v6, 'v6ip' => $ip_v6, @@ -693,6 +722,10 @@ used in combination with B<--move-to>. Set netmask configuration to specified argument. +=item B<--netmask-ipv6>=I + +Set IPv6 netmask (prefix length) configuration to specified argument. + =item B<--output-file>=I Store resulting file under specified argument. If unset defaults to