diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | scripts/vyatta-dhcpv6-client.pl | 157 | ||||
-rwxr-xr-x | scripts/vyatta-interfaces.pl | 9 | ||||
-rw-r--r-- | templates/interfaces/ethernet/node.tag/address/node.def | 43 | ||||
-rw-r--r-- | templates/interfaces/ethernet/node.tag/dhcpv6-options/node.def | 49 | ||||
-rw-r--r-- | templates/interfaces/ethernet/node.tag/dhcpv6-options/parameters-only/node.def | 3 | ||||
-rw-r--r-- | templates/interfaces/ethernet/node.tag/dhcpv6-options/temporary/node.def | 3 |
8 files changed, 263 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index 4a118fbd..3157173c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ sbin_SCRIPTS += scripts/install/install-image-existing sbin_SCRIPTS += scripts/install/install-postinst-new sbin_SCRIPTS += scripts/install/install-image sbin_SCRIPTS += scripts/vyatta-bridgegroup-depedency.pl +sbin_SCRIPTS += scripts/vyatta-dhcpv6-client.pl share_perl5_DATA = lib/Vyatta/Login/User.pm share_perl5_DATA += lib/Vyatta/Login/RadiusServer.pm diff --git a/debian/changelog b/debian/changelog index bdf5d5cc..b63f7977 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +vyatta-cfg-system (0.17.46) unstable; urgency=low + + * Move DHCPv6 client configuration to this package and restructre + parameters. + + -- Bob Gilligan <gilligan@vyatta.com> Wed, 26 May 2010 16:12:45 -0700 + vyatta-cfg-system (0.17.45) unstable; urgency=low * Don't enable PAM Radius by default diff --git a/scripts/vyatta-dhcpv6-client.pl b/scripts/vyatta-dhcpv6-client.pl new file mode 100644 index 00000000..c1a0dbd3 --- /dev/null +++ b/scripts/vyatta-dhcpv6-client.pl @@ -0,0 +1,157 @@ +#!/usr/bin/perl +# +# Module: vyatta-dhcpv6-client.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2005-2009 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Bob Gilligan <gilligan@vyatta.com> +# Date: April 2010 +# Description: Start and stop DHCPv6 client daemon for an interface. +# +# **** End License **** +# +# + +use strict; +use lib "/opt/vyatta/share/perl5/"; +use FileHandle; +use Vyatta::Config; +use Getopt::Long; + +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 = new FileHandle; + + 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); + + print $FD_WR "# This file was auto-generated by the Vyatta\n"; + print $FD_WR "# configuration sub-system. Do not edit it.\n"; + print $FD_WR "\n"; + print $FD_WR "# Generated on $date by $user\n"; + print $FD_WR "#\n"; + print $FD_WR "interface \"$ifname\" {\n"; + 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"; +} + + +# +# Main Section +# + +GetOptions("start" => \$start_flag, + "stop" => \$stop_flag, + "release" => \$release_flag, + "renew" => \$renew_flag, + "temporary" => \$temp_flag, + "parameters-only" => \$params_only_flag, + "ifname=s" => \$ifname, + ); + +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; +} + +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 (! -e $pidfile) { + printf("DHCPv6 client is already released on interface $ifname.\n"); + exit 1; + } +} + +if (defined $renew_flag) { + if (! -e $conffile) { + printf("DHCPv6 client is not configured on interface $ifname.\n"); + exit 1; + } +} + +if (defined $stop_flag || defined $release_flag) { + # Stop dhclient -6 on $ifname + + printf("Stopping daemon...\n"); + my $output=`$cmdname -6 -nw -cf $conffile -pf $pidfile -lf $leasefile -r $ifname`; + printf($output); + + # Delete files it leaves behind... + printf("Deleting related files...\n"); + unlink($pidfile); + if (defined $stop_flag) { + # If just releasing, leave the config file around as a flag that + # DHCPv6 remains configured on this interface. + unlink($conffile); + } +} + +if (defined $start_flag || defined $renew_flag) { + # Generate the DHCP client config file... + gen_conf_file($conffile, $ifname); + + # First, kill any previous instance of dhclient running on this interface + # + printf("Stopping old daemon...\n"); + my $output = `$cmdname -6 -pf $pidfile -x $ifname`; + printf($output); + + # start "dhclient -6" on $ifname + + my $args = ""; + if (defined $temp_flag) { + $args .= " -T"; + } + if (defined $params_only_flag) { + $args .= " -S"; + } + + printf("Starting new daemon...\n"); + my $output=`$cmdname -6 -nw -cf $conffile -pf $pidfile -lf $leasefile $args $ifname`; + printf($output); +} diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 5b3c9937..a810f2de 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -356,6 +356,13 @@ sub is_valid_addr_set { exit 0; } + if ($addr_net eq "dhcpv6") { + die "Error: can't use dhcpv6 client on loopback interface\n" + if ($intf eq "lo"); + + exit 0; + } + my ($addr, $net); if ($addr_net =~ m/^([0-9a-fA-F\.\:]+)\/(\d+)$/) { $addr = $1; @@ -423,7 +430,7 @@ sub is_valid_addr_commit { $dhcp = 1; } else { my $version = is_ip_v4_or_v6($addr); - if ($version == 4) { + if (defined($version) && $version == 4) { $static_v4 = 1; } } diff --git a/templates/interfaces/ethernet/node.tag/address/node.def b/templates/interfaces/ethernet/node.tag/address/node.def index db87ff05..7ed12bba 100644 --- a/templates/interfaces/ethernet/node.tag/address/node.def +++ b/templates/interfaces/ethernet/node.tag/address/node.def @@ -15,14 +15,41 @@ syntax:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr-set # commit:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr-commit $VAR(@@) --dev $VAR(../@)" -create:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@) - -delete:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@) - -allowed: echo "dhcp <>" +create: + ifname=$VAR(../@) + param=$VAR(@) + if [ "$param" = "dhcpv6" ]; then + if [ -n "$VAR(../dhcpv6-options/parameters-only)" ]; then + echo "parameters-only is set" + arg1="--parameters-only" + fi + if [ -n "$VAR(../dhcpv6-options/temporary)" ]; then + echo "temporary is set" + arg2="--temporary" + fi + + echo "Starting DHCPv6 client on ${ifname}..." + sudo /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --start \ + --ifname $ifname $arg1 $arg2 + else + sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@) + fi + +delete: + ifname=$VAR(../@) + param=$VAR(@) + if [ "$param" = "dhcpv6" ]; then + echo "Stopping DHCPv6 client on ${ifname}..." + sudo /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --stop --ifname \ + $ifname + else + sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@) + fi + +allowed: echo "dhcp dhcpv6 <>" comp_help:Possible completions: - <x.x.x.x/x> Set the IP address and prefix length + <x.x.x.x/x> Set the IPv4 address and prefix length <h:h:h:h:h:h:h:h/x> Set the IPv6 address and prefix length - dhcp Set the IP address and prefix length via DHCP - + dhcp Set the IPv4 address and prefix length via DHCP + dhcpv6 Set the IPv6 address and prefix length via DHCPv6 diff --git a/templates/interfaces/ethernet/node.tag/dhcpv6-options/node.def b/templates/interfaces/ethernet/node.tag/dhcpv6-options/node.def new file mode 100644 index 00000000..aaeca067 --- /dev/null +++ b/templates/interfaces/ethernet/node.tag/dhcpv6-options/node.def @@ -0,0 +1,49 @@ +# This node is run before the rest of the interface is configured. +# We first check to see if DHCPv6 is still configured on the interface by +# looking over at the interface address parameters. Then we check to see +# if the DHCPv6 client program is still running on this interface. If both +# of those are true, then any change to this tree means that the user +# has changed this tree ONLY, and that we are going to have to re-start +# the DHCPv6 client using the new parameters. + + +priority: 317 # Run before interface has been configured + +help: Set options for DHCPv6 + +end: + ifname="$VAR(../@)" + echo "dhcpv6-options: ifname is $ifname" + + dhcpv6_set=0 + for param in $VAR(../address/@@); do + if [ "$param" = "dhcpv6" ]; then + dhcpv6_set=1 + fi + done + + if [ $dhcpv6_set -eq 0 ]; then + echo "DHCPv6 is not configured on this interface" + exit 0 + fi + + conffile=/var/lib/dhcp3/dhclient_v6_$VAR(../@).conf + if [ ! -e $conffile ]; then + echo "Conf file $conffile doesn't exist" + exit 0 + fi + + if [ -n "$VAR(./parameters-only)" ]; then + arg1="--parameters-only" + fi + + if [ -n "$VAR(./temporary)" ]; then + arg2="--temporary" + fi + + echo "Re-starting DHCPv6 client on ${ifname}..." + sudo /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --stop --start \ + --ifname $ifname $arg1 $arg2 + + echo "Done." + exit 0
\ No newline at end of file diff --git a/templates/interfaces/ethernet/node.tag/dhcpv6-options/parameters-only/node.def b/templates/interfaces/ethernet/node.tag/dhcpv6-options/parameters-only/node.def new file mode 100644 index 00000000..0178c469 --- /dev/null +++ b/templates/interfaces/ethernet/node.tag/dhcpv6-options/parameters-only/node.def @@ -0,0 +1,3 @@ + +help: Acquire only config parameters, not address, via DHCPv6 + diff --git a/templates/interfaces/ethernet/node.tag/dhcpv6-options/temporary/node.def b/templates/interfaces/ethernet/node.tag/dhcpv6-options/temporary/node.def new file mode 100644 index 00000000..afb9de9c --- /dev/null +++ b/templates/interfaces/ethernet/node.tag/dhcpv6-options/temporary/node.def @@ -0,0 +1,3 @@ + +help: Acquire a "temporary" IPv6 address + |