diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-22 10:32:04 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-22 11:14:18 -0800 |
commit | 39a799dac616edd4b42a1b4de2c861f248318e1f (patch) | |
tree | 821d778a77ff75015dba4936ca10652824224ef9 /scripts/vyatta-dhcpv6-client.pl | |
parent | b17d21023482c752c490754a11450d4c41c83607 (diff) | |
download | vyatta-cfg-quagga-39a799dac616edd4b42a1b4de2c861f248318e1f.tar.gz vyatta-cfg-quagga-39a799dac616edd4b42a1b4de2c861f248318e1f.zip |
Use script vyatta-address to set interface
Avoid the overhead of perl compilation of vyatta-interfaces for each
address added. Handle the case of deleting address on deleted device
cleanly.
Clean up dhcpv6 script so it can be used on interfaces other
than ethernet.
Diffstat (limited to 'scripts/vyatta-dhcpv6-client.pl')
-rwxr-xr-x | scripts/vyatta-dhcpv6-client.pl | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/scripts/vyatta-dhcpv6-client.pl b/scripts/vyatta-dhcpv6-client.pl index 3f01a677..283b6d2b 100755 --- a/scripts/vyatta-dhcpv6-client.pl +++ b/scripts/vyatta-dhcpv6-client.pl @@ -26,7 +26,7 @@ use strict; use lib "/opt/vyatta/share/perl5/"; -use FileHandle; +use Sys::hostname; use Vyatta::Config; use Getopt::Long; @@ -34,26 +34,17 @@ my $start_flag; # Start the daemon my $stop_flag; # Stop the daemon and delete all config files my $release_flag; # Stop the daemon, but leave config file my $renew_flag; # Re-start the daemon. Functionally same as start_flag -my $temp_flag; -my $params_only_flag; my $ifname; - sub gen_conf_file { my ($conffile, $ifname) = @_; + my $FD_WR; - my $FD_WR = new FileHandle; + open($FD_WR, '>', $conffile) + or die "Can't write config file: $conffile : $!\n"; - if (!open($FD_WR, ">$conffile")) { - printf("Can't write config file: $conffile\n"); - exit 1; - } - my $date = `date`; - my $user = `id -un`; - my $hostname = `hostname`; - chomp($date); - chomp($user); - chomp($hostname); + my $date = localtime; + my $user = getpwuid($<); print $FD_WR "# This file was auto-generated by the Vyatta\n"; print $FD_WR "# configuration sub-system. Do not edit it.\n"; @@ -61,11 +52,37 @@ sub gen_conf_file { print $FD_WR "# Generated on $date by $user\n"; print $FD_WR "#\n"; print $FD_WR "interface \"$ifname\" {\n"; +# my $hostname = hostname; # print $FD_WR " send host-name \"$hostname\";\n"; # print $FD_WR " send dhcp6.oro 1, 2, 7, 12, 13, 23, 24, 39;\n"; print $FD_WR "}\n"; + close $FD_WR; } +sub usage { + print "Usage: $0 --ifname=ethX --{start|stop|renew|release}\n"; + exit 1; +} + +sub dhcpv6_options { + my $ifname = shift; + my $intf = new Vyatta::Interface($name); + + die "Unknown interface type for $ifname" unless $intf; + + my $config = new Vyatta::Config; + $config->setLevel($intf->path()); + + my $args = ""; + + $args .= " -T" + if ($config->exists("dhcpv6-options/temporary")); + + $args .= " -S" + if ($config->exists("dhcpv6-options/parameters-only")); + + return $args; +} # # Main Section @@ -75,46 +92,31 @@ GetOptions("start" => \$start_flag, "stop" => \$stop_flag, "release" => \$release_flag, "renew" => \$renew_flag, - "temporary" => \$temp_flag, - "parameters-only" => \$params_only_flag, "ifname=s" => \$ifname, - ); + ) or usage(); -if ((defined $temp_flag) && (defined $params_only_flag)) { - printf("Error: --temporary and --parameters-only flags are mutually exclusive.\n"); - exit 1; -} - -if (!defined $ifname) { - printf("Error: Interface name must be specified with --ifname parameter.\n"); - exit 1; -} +die "Error: Interface name must be specified with --ifname parameter.\n" + unless $ifname; my $pidfile = "/var/lib/dhcp3/dhclient_v6_$ifname.pid"; my $leasefile = "/var/lib/dhcp3/dhclient_v6_$ifname.leases"; my $conffile = "/var/lib/dhcp3/dhclient_v6_$ifname.conf"; my $cmdname = "/sbin/dhclient"; -if (defined $release_flag) { - if (! -e $conffile) { - printf("DHCPv6 client is not configured on interface $ifname.\n"); - exit 1; - } +if ($release_flag) { + die "DHCPv6 client is not configured on interface $ifname.\n" + unless (-e $conffile); - if (! -e $pidfile) { - printf("DHCPv6 client is already released on interface $ifname.\n"); - exit 1; - } + die "DHCPv6 client is already released on interface $ifname.\n" + unless (-e $pidfile); } -if (defined $renew_flag) { - if (! -e $conffile) { - printf("DHCPv6 client is not configured on interface $ifname.\n"); - exit 1; - } +if ($renew_flag) { + die "DHCPv6 client is not configured on interface $ifname.\n" + unless (-e $conffile); } -if (defined $stop_flag || defined $release_flag) { +if (defined($stop_flag)|| defined ($release_flag)) { # Stop dhclient -6 on $ifname printf("Stopping daemon...\n"); @@ -131,7 +133,8 @@ if (defined $stop_flag || defined $release_flag) { } } -if (defined $start_flag || defined $renew_flag) { +if (defined($start_flag) || defined ($renew_flag)) { + # Generate the DHCP client config file... gen_conf_file($conffile, $ifname); @@ -142,14 +145,7 @@ if (defined $start_flag || defined $renew_flag) { printf($output); # start "dhclient -6" on $ifname - - my $args = ""; - if (defined $temp_flag) { - $args .= " -T"; - } - if (defined $params_only_flag) { - $args .= " -S"; - } + my $args = dhcpv6_options($ifname); printf("Starting new daemon...\n"); my $output=`$cmdname -6 -nw -cf $conffile -pf $pidfile -lf $leasefile $args $ifname`; |