Debian boot-time IPv6 interface editing now working
authorJamie Cameron <jcameron@webmin.com>
Thu, 20 Jan 2011 01:02:13 +0000 (17:02 -0800)
committerJamie Cameron <jcameron@webmin.com>
Thu, 20 Jan 2011 01:02:13 +0000 (17:02 -0800)
net/debian-linux-lib.pl
net/edit_aifc.cgi
net/edit_bifc.cgi
net/net-lib.pl
net/save_bifc.cgi

index 900d8c2..9ab2844 100755 (executable)
@@ -261,7 +261,34 @@ else {
                }
        }
 
-# XXX update inet6 section too
+# Create IPv6 options
+my @options6;
+my @address6 = @{$cfg->{'address6'}};
+my @netmask6 = @{$cfg->{'netmask6'}};
+if (@address6) {
+       push(@options6, [ "address", shift(@address6) ]);
+       push(@options6, [ "netmask", shift(@netmask6) ]);
+       }
+while(@address6) {
+       my $a = shift(@address6);
+       my $n = shift(@netmask6);
+       push(@options6, [ "up","ifconfig $cfg->{'fullname'} inet6 add $a/$n" ]);
+       }
+
+if (!$found6 && @{$cfg->{'address6'}}) {
+       # Need to add IPv6 block
+       &new_interface_def($cfg->{'fullname'},
+                          'inet6', 'static', \@options6);
+       }
+elsif ($found6 && @{$cfg->{'address6'}}) {
+       # Need to update IPv6 block
+       &modify_interface_def($cfg->{'fullname'},
+                             'inet6', 'static', \@options6, 0);
+       }
+elsif ($found6 && !@{$cfg->{'address6'}}) {
+       # Need to delete IPv6 block
+       &delete_interface_def($cfg->{'fullname'}, 'inet6');
+       }
 
 # Set auto option to include this interface, or not
 if ($amode) {
@@ -421,14 +448,15 @@ sub new_module_def
 # Delete a boot-time interface
 sub delete_interface
 {
-# XXX inet6 too
 my $cfg = $_[0];
-       local @address = ('address',$cfg->{'address'});
-       delete_interface_def(&is_ipv6_address($cfg->{'address'})?$cfg->{'name'}:$cfg->{'fullname'}, &is_ipv6_address($cfg->{'address'})?'inet6':'inet','',\@address);
-       my @autos = get_auto_defs();
-       if ($gconfig{'os_version'} >= 3 || scalar(@autos)) {
-               @autos = grep { $_ ne $cfg->{'fullname'} } @autos;
-               &modify_auto_defs(@autos);
+&delete_interface_def($cfg->{'fullname'}, 'inet');
+if (@{$cfg->{'address6'}}) {
+       &delete_interface_def($cfg->{'fullname'}, 'inet6');
+       }
+my @autos = get_auto_defs();
+if ($gconfig{'os_version'} >= 3 || scalar(@autos)) {
+       @autos = grep { $_ ne $cfg->{'fullname'} } @autos;
+       &modify_auto_defs(@autos);
        }
 }
 
@@ -829,9 +857,9 @@ foreach $option (@$options) {
 # the parameters should be (name, addrfam)
 sub delete_interface_def
 {
-       local ($name, $addrfam, $method) = @_;
-       modify_interface_def($name, $addrfam, '', [], 1);
-       modify_module_def($name, 1);
+local ($name, $addrfam, $method) = @_;
+&modify_interface_def($name, $addrfam, '', [], 1);
+&modify_module_def($name, 1);
 }
 
 sub os_feedback_files
index b2e4a52..38e45ed 100755 (executable)
@@ -74,24 +74,22 @@ else {
        }
 print &ui_table_row($text{'ifcs_mask'}, $netmaskfield);
 
-# Broadcast address field, except for IPv6
-if ($in{'new'} || !&is_ipv6_address($a->{'address'})) {
-       if (!$access{'broadcast'}) {
-               # Cannot be edited
-               $broadfield = $a ? $a->{'broadcast'} : $config{'def_broadcast'};
-               }
-       elsif ($in{'new'}) {
-               # Can enter or use default
-               $broadfield = &ui_opt_textbox(
-                       "broadcast", $config{'def_broadcast'}, 15,
-                       $text{'ifcs_auto'});
-               }
-       else {
-               # Allow editing
-               $broadfield = &ui_textbox("broadcast", $a->{'broadcast'}, 15);
-               }
-       print &ui_table_row($text{'ifcs_broad'}, $broadfield);
+# Broadcast address field
+if (!$access{'broadcast'}) {
+       # Cannot be edited
+       $broadfield = $a ? $a->{'broadcast'} : $config{'def_broadcast'};
+       }
+elsif ($in{'new'}) {
+       # Can enter or use default
+       $broadfield = &ui_opt_textbox(
+               "broadcast", $config{'def_broadcast'}, 15,
+               $text{'ifcs_auto'});
+       }
+else {
+       # Allow editing
+       $broadfield = &ui_textbox("broadcast", $a->{'broadcast'}, 15);
        }
+print &ui_table_row($text{'ifcs_broad'}, $broadfield);
 
 # Show the IPv6 field
 if (&supports_address6($a)) {
index 5a842bf..e3b1263 100755 (executable)
@@ -117,18 +117,16 @@ elsif ($b && $b->{'netmask'}) {
        # Cannot edit
        push(@grid, $text{'ifcs_mask'}, "<tt>$b->{'netmask'}</tt>");
        }
-if (!$b || !&is_ipv6_address($b->{'address'})){
-       if (&can_edit("broadcast", $b) && $access{'broadcast'}) {
-               # Can edit broadcast address
-               push(@grid, $text{'ifcs_broad'},
-                   &ui_opt_textbox("broadcast",
-                       $b ? $b->{'broadcast'} : $config{'def_broadcast'},
-                       15, $text{'ifcs_auto'}));
-               }
-       elsif ($b && $b->{'broadcast'}) {
-               # Broadcast is fixed
-               push(@grid, $text{'ifcs_broad'}, "<tt>$b->{'broadcast'}</tt>");
-               }
+if (&can_edit("broadcast", $b) && $access{'broadcast'}) {
+       # Can edit broadcast address
+       push(@grid, $text{'ifcs_broad'},
+           &ui_opt_textbox("broadcast",
+               $b ? $b->{'broadcast'} : $config{'def_broadcast'},
+               15, $text{'ifcs_auto'}));
+       }
+elsif ($b && $b->{'broadcast'}) {
+       # Broadcast is fixed
+       push(@grid, $text{'ifcs_broad'}, "<tt>$b->{'broadcast'}</tt>");
        }
 push(@opts, [ "address", $text{'ifcs_static2'}, &ui_grid_table(\@grid, 2) ]);
 
index 861fa1c..bddfe2e 100755 (executable)
@@ -350,16 +350,6 @@ foreach my $a (&boot_interfaces()) {
 return @rv;
 }
 
-# is_ipv6_address(ipaddr)
-# Returns 1 if the given ip address is from IPV6 type, 0 if not.
-# IPV6 address field separator is ":", this character is researched inside IP adress string
-sub is_ipv6_address
-{
-  local ($ipaddr) = @_;
-  return 1 if (index($ipaddr,":") != -1);
-  return 0;
-}
-
 # check_netmask(netmask,ipaddress_associated)
 # check if some netmask is properly formatted accordingly
 # the associated address format (IPv4 or IPv6)
index 82a5702..e823195 100755 (executable)
@@ -84,7 +84,7 @@ else {
        elsif ($in{'name'} =~/^[a-z]+\d*(\.\d+)?$/) {
                # creating a real interface
                foreach $eb (@boot) {
-                       if ($eb->{'fullname'} eq $in{'name'} && (!&is_ipv6_address($in{'address'}))) {
+                       if ($eb->{'fullname'} eq $in{'name'}) {
                                &error(&text('bifc_edup', $in{'name'}));
                                }
                        }
@@ -161,8 +161,7 @@ else {
                }
        elsif (&can_edit("broadcast", $b)) {
                # Manually entered broadcast
-               &is_ipv6_address($in{'address'}) || 
-                   ($auto && !$in{'broadcast'}) ||
+               ($auto && !$in{'broadcast'}) ||
                        &check_ipaddress($in{'broadcast'}) ||
                        &error(&text('bifc_ebroad', $in{'broadcast'}));
                $b->{'broadcast'} = $in{'broadcast'};
@@ -227,42 +226,41 @@ else {
                $b->{'netmask6'} = \@netmask6;
                }
 
+       # Save bonding settings
        if ($in{'bond'}) {
                $b->{'bond'} = 1;
                if ($in{'partner'}) {
                        $b->{'partner'} = $in{'partner'};
-               }
+                       }
                if ($in{'bondmode'} ne ''){
                        $mode = $in{'bondmode'};
                        $b->{'mode'} = $mode;
-               }
+                       }
                if ($in{'miimon'} ne ''){
                        $b->{'miimon'} = $in{'miimon'};
-               }
+                       }
                if ($in{'updelay'} ne ''){
                        $b->{'updelay'} = $in{'updelay'};
-               }
+                       }
                if ($in{'downdelay'} ne ''){
                        $b->{'downdelay'} = $in{'downdelay'};
+                       }
                }
-       }
        
-       if($in{'vlan'} == 1) {
+       # Save VLAN settings
+       if ($in{'vlan'} == 1) {
                $b->{'vlan'} = 1;
-               
-               if($in{'physical'}) {
+               if ($in{'physical'}) {
                        $b->{'physical'} = $in{'physical'};
-               }
-               if($in{'vlanid'}) {
+                       }
+               if ($in{'vlanid'}) {
                        $b->{'vlanid'} = $in{'vlanid'};
+                       }
                }
-  }
-  if(&is_ipv6_address){
-     $b->{'fullname'} = $in{'name'};
-  }   
-  else{
-    $b->{'fullname'} = $b->{'name'}.( $b->{'virtual'} eq '' ? '' : ':'.$b->{'virtual'});
-  } 
+
+       # Save the interface with its final name
+       $b->{'fullname'} = $b->{'name'}.
+               ( $b->{'virtual'} eq '' ? '' : ':'.$b->{'virtual'});
        &save_interface($b);
 
        if ($in{'activate'}) {
@@ -276,9 +274,10 @@ else {
                        }
                else {
                        if ($in{'bond'}) {
-                               if (($gconfig{'os_type'} eq 'debian-linux') && ($gconfig{'os_version'} >= 5)) {}
+                               if (($gconfig{'os_type'} eq 'debian-linux') &&
+                                   ($gconfig{'os_version'} >= 5)) {}
                                else {&load_module($b);}
-                       }
+                               }
                        &activate_interface($b);
                        }
                }