Work on IPv6 address auto-configuration
authorJamie Cameron <jcameron@webmin.com>
Fri, 21 Jan 2011 00:55:21 +0000 (16:55 -0800)
committerJamie Cameron <jcameron@webmin.com>
Fri, 21 Jan 2011 00:55:21 +0000 (16:55 -0800)
net/debian-linux-lib.pl
net/edit_bifc.cgi
net/lang/en
net/list_ifcs.cgi
net/redhat-linux-lib.pl
net/save_bifc.cgi
net/solaris-lib.pl

index 2ac7e9f..cf00e28 100755 (executable)
@@ -113,6 +113,9 @@ foreach $iface (@ifaces) {
                                push(@{$v6cfg->{'netmask6'}}, $3);
                                }
                        }
+               if ($method eq "manual" && !@{$v6cfg->{'address6'}}) {
+                       $v6cfg->{'auto6'} = 1;
+                       }
                $v6map{$name} = $v6cfg;
                }
        }
@@ -262,7 +265,7 @@ else {
 my @options6;
 my @address6 = @{$cfg->{'address6'}};
 my @netmask6 = @{$cfg->{'netmask6'}};
-if (@address6) {
+if (@address6 || $cfg->{'auto6'}) {
        push(@options6, ['pre-up', '/sbin/modprobe -q ipv6 ; /bin/true']);
        }
 if (@address6) {
@@ -275,17 +278,19 @@ while(@address6) {
        push(@options6, [ "up","ifconfig $cfg->{'fullname'} inet6 add $a/$n" ]);
        }
 
-if (!$found6 && @{$cfg->{'address6'}}) {
+# Add, update or delete IPv6 inteface
+my $method = $cfg->{'auto6'} ? "manual" : "static";
+if (!$found6 && @options6) {
        # Need to add IPv6 block
        &new_interface_def($cfg->{'fullname'},
-                          'inet6', 'static', \@options6);
+                          'inet6', $method, \@options6);
        }
-elsif ($found6 && @{$cfg->{'address6'}}) {
+elsif ($found6 && @options6) {
        # Need to update IPv6 block
        &modify_interface_def($cfg->{'fullname'},
-                             'inet6', 'static', \@options6, 0);
+                             'inet6', $method, \@options6, 0);
        }
-elsif ($found6 && !@{$cfg->{'address6'}}) {
+elsif ($found6 && !@options6) {
        # Need to delete IPv6 block
        &delete_interface_def($cfg->{'fullname'}, 'inet6');
        }
index e3b1263..83c97a8 100755 (executable)
@@ -154,7 +154,10 @@ if (&supports_address6($b)) {
                                $b->{'netmask6'}->[$i] || 64, 10) ]);
                }
        $table6 .= &ui_columns_end();
-       print &ui_table_row($text{'ifcs_mode6'}, $table6, 3);
+       print &ui_table_row($text{'ifcs_mode6'},
+               &ui_radio_table("mode6", $b->{'auto6'} ? "auto" : "address",
+                       [ [ "auto", $text{'ifcs_auto6'} ],
+                         [ "address", $text{'ifcs_static2'}, $table6 ] ]));
        }
 
 # MTU
index 077fd7d..f6a7316 100644 (file)
@@ -28,6 +28,7 @@ ifcs_boot=Activated at Boot
 ifcs_act=Activate
 ifcs_bootp=From BOOTP
 ifcs_dhcp=From DHCP
+ifcs_auto6=From IPv6 discovery
 ifcs_broad=Broadcast
 ifcs_auto=Automatic
 ifcs_mtu=MTU
@@ -41,7 +42,7 @@ ifcs_ecannot_this=You are not allowed to edit this network interface
 ifcs_range=Range $1
 ifcs_static2=Static configuration
 ifcs_mode=IPv4 address
-ifcs_mode6=Static IPv6 addresses
+ifcs_mode6=IPv6 addresses
 ifcs_address6=IPv6 address
 ifcs_netmask6=Netmask
 ifcs_mode6a=IPv6 addresses
index 81a7a25..f96ea67 100755 (executable)
@@ -204,7 +204,8 @@ foreach $a (@boot) {
                push(@cols, $a->{'netmask'} ? &html_escape($a->{'netmask'})
                                            : $text{'ifcs_auto'});
                if (&supports_address6()) {
-                       push(@cols, join("<br>\n", map { &html_escape($_) }
+                       push(@cols, $a->{'auto6'} ? $text{'ifcs_auto6'} :
+                                     join("<br>\n", map { &html_escape($_) }
                                                    @{$a->{'address6'}}));
                        }
                }
index ed065b4..a156917 100755 (executable)
@@ -110,8 +110,14 @@ while($f = readdir(CONF)) {
                        if ($conf{'IPV6ADDR'});
                push(@ip6s, map { [ split(/\//, $_) ] }
                                split(/\s+/, $conf{'IPV6ADDR_SECONDARIES'}));
-               $b->{'address6'} = [ map { $_->[0] } @ip6s ];
-               $b->{'netmask6'} = [ map { $_->[1] } @ip6s ];
+               if (@ip6s) {
+                       # Static IPv6 addresses
+                       $b->{'address6'} = [ map { $_->[0] } @ip6s ];
+                       $b->{'netmask6'} = [ map { $_->[1] } @ip6s ];
+                       }
+               elsif ($conf{'IPV6INIT'}) {
+                       $b->{'auto6'} = 1;
+                       }
                $b->{'edit'} = ($b->{'name'} !~ /^ppp|irlan/);
                $b->{'desc'} = $conf{'NAME'};
                $b->{'index'} = scalar(@rv);
@@ -179,11 +185,13 @@ else {
                push(@ip6s, $b->{'address6'}->[$i]."/".
                            $b->{'netmask6'}->[$i]);
                }
-       if (@ip6s && lc($conf{'IPV6INIT'}) ne 'yes') {
+       if ((@ip6s || $b->{'auto6'}) && lc($conf{'IPV6INIT'}) ne 'yes') {
                $conf{'IPV6INIT'} = 'yes';
                }
-       $conf{'IPV6ADDR'} = shift(@ip6s);
-       $conf{'IPV6ADDR_SECONDARIES'} = join(" ", @ip6s);
+       if (@ip6s) {
+               $conf{'IPV6ADDR'} = shift(@ip6s);
+               $conf{'IPV6ADDR_SECONDARIES'} = join(" ", @ip6s);
+               }
        }
 $conf{'NAME'} = $_[0]->{'desc'};
 &write_env_file("$net_scripts_dir/ifcfg-$name", \%conf);
index e823195..c84ef0a 100755 (executable)
@@ -197,7 +197,14 @@ else {
                }
 
        # Save IPv6 addresses
-       if (&supports_address6($b) && defined($in{'address6_0'})) {
+       if (&supports_address6($b) && $in{'mode6'} eq 'auto') {
+               # Dynamic configuration
+               delete($b->{'address6'});
+               delete($b->{'netmask6'});
+               $b->{'auto6'} = 1;
+               }
+       elsif (&supports_address6($b) && $in{'mode6'} eq 'address') {
+               # Static addresses
                @address6 = ( );
                @netmask6 = ( );
                %clash6 = ( );
@@ -222,6 +229,7 @@ else {
                        push(@netmask6, $in{'netmask6_'.$i});
                        $clash6{$in{'address6_'.$i}} = $b;
                        }
+               delete($b->{'auto6'});
                $b->{'address6'} = \@address6;
                $b->{'netmask6'} = \@netmask6;
                }
index e995a12..2ab89bd 100755 (executable)
@@ -128,6 +128,22 @@ while($f = readdir(ETC)) {
                        $ifc{'dhcp'}++;
                        }
                $ifc{'up'}++;
+               if (open(FILE6, "$etc/hostname6\.$ifc{'fullname'}")) {
+                       # Also has an IPv6 address
+                       local $address6 = <FILE6>;
+                       chop($address6);
+                       close(FILE6);
+                       if ($address6) {
+                               local $netmask6;
+                               ($address6, $netmask6) = split(/\//, $address6);
+                               $netmask6 ||= 64;
+                               $ifc{'address6'} = [ $address6 ];
+                               $ifc{'netmask6'} = [ $netmask6 ];
+                               }
+                       else {
+                               $ifc{'auto6'} = 1;
+                               }
+                       }
                push(@rv, \%ifc);
                }
        }
@@ -146,6 +162,16 @@ if (!$_[0]->{'dhcp'}) {
        &print_tempfile(IFACE, $_[0]->{'address'},"\n");
        }
 &close_tempfile(IFACE);
+if (@{$_[0]->{'address6'}} || $_[0]->{'auto6'}) {
+       &open_lock_tempfile(IFACE6, ">/etc/hostname6.$name");
+       if (!$_[0]->{'auto6'}) {
+               &print_tempfile(IFACE6, $_[0]->{'address6'}->[0],"\n");
+               }
+       &close_tempfile(IFACE6);
+       }
+else {
+       &unlink_logged("/etc/hostname6.$name");
+       }
 }
 
 # delete_interface(&details)
@@ -155,6 +181,7 @@ sub delete_interface
 local $name = $_[0]->{'virtual'} ne "" ? $_[0]->{'name'}.":".$_[0]->{'virtual'}
                                       : $_[0]->{'name'};
 &unlink_logged("/etc/hostname.$name");
+&unlink_logged("/etc/hostname6.$name");
 }
 
 # iface_type(name)