summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--scripts/vyatta-address45
-rwxr-xr-xscripts/vyatta-dhcpv6-client.pl98
-rwxr-xr-xscripts/vyatta-interfaces.pl17
-rw-r--r--templates/interfaces/bonding/node.tag/address/node.def4
-rw-r--r--templates/interfaces/bonding/node.tag/vif/node.tag/address/node.def4
-rw-r--r--templates/interfaces/bridge/node.tag/address/node.def15
-rw-r--r--templates/interfaces/ethernet/node.tag/address/node.def31
-rw-r--r--templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def4
-rw-r--r--templates/interfaces/loopback/node.tag/address/node.def6
-rw-r--r--templates/interfaces/pseudo-ethernet/node.tag/address/node.def4
-rw-r--r--templates/interfaces/tunnel/node.tag/address/node.def4
12 files changed, 124 insertions, 109 deletions
diff --git a/Makefile.am b/Makefile.am
index a2635328..5ff82c17 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,6 +43,7 @@ sbin_SCRIPTS += scripts/dns-forwarding/vyatta-dns-forwarding.pl
sbin_SCRIPTS += scripts/dynamic-dns/vyatta-dynamic-dns.pl
sbin_SCRIPTS += scripts/vyatta-system-nameservers
sbin_SCRIPTS += scripts/vyatta-interfaces.pl
+sbin_SCRIPTS += scripts/vyatta-address
sbin_SCRIPTS += scripts/vyatta-tunnel-cleanup
sbin_SCRIPTS += scripts/check-ipv4-ipv6.pl
sbin_SCRIPTS += scripts/vyatta-bonding.pl
diff --git a/scripts/vyatta-address b/scripts/vyatta-address
new file mode 100644
index 00000000..2e521c26
--- /dev/null
+++ b/scripts/vyatta-address
@@ -0,0 +1,45 @@
+#! /bin/bash
+#
+# Wrapper around ip link command that handles IPv4, IPv6 and DHCP
+# This is done in shell rather than perl to avoid the overhead of recompilation
+
+if [ $# -ne 3 ]; then
+ echo "Usage: $0 {add|delete} interface address"
+ exit 1
+fi
+
+case $1 in
+ add)
+ if [[ "$3" = "dhcp" ]]
+ then
+ exec /opt/vyatta/sbin/vyatta-interfaces.pl --dev="$2" --dhcp=start
+ elif [[ "$3" = "dhcpv6" ]]
+ then
+ exec /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --start -ifname "$2"
+ elif [[ "$3" =~ ":" ]]
+ then # Ipv6 address
+ exec ip -6 addr add "$3" dev "$2"
+ else
+ exec ip addr add "$3" broadcast + dev "$2"
+ fi ;;
+
+ delete)
+ if [ ! -d "/sys/class/net/$2" ]
+ then # device is already gone
+ exit 0
+ elif [[ "$3" = "dhcp" ]]
+ then
+ exec /opt/vyatta/sbin/vyatta-interfaces.pl --dev="$2" --dhcp=stop
+ elif [[ "$3" = "dhcpv6" ]]
+ then
+ exec /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --stop --ifname $ifname
+ elif [[ "$3" =~ ":" ]]
+ then
+ exec ip -6 addr del "$3" dev "$2"
+ else
+ exec ip addr del "$3" dev "$2"
+ fi ;;
+ *)
+ echo "Unknown option $1"
+ exit 1 ;;
+esac
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`;
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl
index d625d262..a7384eea 100755
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -486,10 +486,10 @@ sub dhcp {
my ($request, $intf) = @_;
die "$intf is not using DHCP to get an IP address\n"
- unless is_dhcp_enabled($intf);
+ unless ($request eq 'start' || is_dhcp_enabled($intf));
- die "$intf is disabled. Unable to release/renew lease\n"
- if is_intf_down($intf);
+ die "$intf is disabled.\n"
+ if ($request ne 'stop' && is_intf_down($intf));
my $tmp_dhclient_dir = '/var/run/vyatta/dhclient/';
my $release_file = $tmp_dhclient_dir . 'dhclient_release_' . $intf;
@@ -505,6 +505,17 @@ sub dhcp {
print "Renewing DHCP lease on $intf ...\n";
run_dhclient($intf);
unlink ($release_file);
+ } elsif ($request eq "start") {
+ print "Starting DHCP client on $intf ...\n";
+ touch("/var/lib/dhcp3/$intf");
+ run_dhclient($intf);
+ } elsif ($request eq "stop") {
+ print "Stopping DHCP client on $intf ...\n";
+ stop_dhclient($intf);
+ unlink("/var/lib/dhcp3/dhclient_$intf\_lease");
+ unlink("/var/lib/dhcp3/$intf");
+ unlink("/var/run/vyatta/dhclient/dhclient_release_$intf");
+ unlink("/var/lib/dhcp3/dhclient_$intf\.conf");
} else {
die "Unknown DHCP request: $request\n";
}
diff --git a/templates/interfaces/bonding/node.tag/address/node.def b/templates/interfaces/bonding/node.tag/address/node.def
index 8956dba6..93a177b0 100644
--- a/templates/interfaces/bonding/node.tag/address/node.def
+++ b/templates/interfaces/bonding/node.tag/address/node.def
@@ -6,9 +6,9 @@ syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
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(../@)
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../@) $VAR(@)
-delete:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../@) $VAR(@)
allowed: echo "dhcp <>"
val_help: ipv4net; IP address and prefix length
diff --git a/templates/interfaces/bonding/node.tag/vif/node.tag/address/node.def b/templates/interfaces/bonding/node.tag/vif/node.tag/address/node.def
index 236e6ae5..c413194b 100644
--- a/templates/interfaces/bonding/node.tag/vif/node.tag/address/node.def
+++ b/templates/interfaces/bonding/node.tag/vif/node.tag/address/node.def
@@ -6,9 +6,9 @@ syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
commit:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr-commit $VAR(@@) --dev $VAR(../../@).$VAR(../@)"
-create:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../../@).$VAR(../@)
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../../@).$VAR(../@) $VAR(@)
-delete:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../../@).$VAR(../@)
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../../@).$VAR(../@) $VAR(@)
allowed: echo "dhcp <>"
val_help: ipv4; IP address and prefix length
diff --git a/templates/interfaces/bridge/node.tag/address/node.def b/templates/interfaces/bridge/node.tag/address/node.def
index cb08069e..45aa03e2 100644
--- a/templates/interfaces/bridge/node.tag/address/node.def
+++ b/templates/interfaces/bridge/node.tag/address/node.def
@@ -5,19 +5,10 @@ help: IP address
syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
-create: sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@)
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../@) $VAR(@)
+
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../@) $VAR(@)
-delete:
- if /opt/vyatta/sbin/vyatta-bridgegroup-depedency.pl \
- --bridge-notin-proposedcfg \
- --bridge-interface="$VAR(../@)"; then \
- # bridge has higher priority than bridge-address so bridge gets deleted
- # before bridge-address in case the whole of bridge config was deleted.
- # In that case we do not need to delete address here now
- exit 0
- else
- sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)
- fi
allowed: echo "dhcp <>"
val_help: ipv4net; IP address and prefix length
diff --git a/templates/interfaces/ethernet/node.tag/address/node.def b/templates/interfaces/ethernet/node.tag/address/node.def
index c1bd8fc8..3cf32ef7 100644
--- a/templates/interfaces/ethernet/node.tag/address/node.def
+++ b/templates/interfaces/ethernet/node.tag/address/node.def
@@ -6,36 +6,9 @@ syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
commit:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr-commit $VAR(@@) --dev $VAR(../@)"
-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
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../@) $VAR(@)
- 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
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../@) $VAR(@)
allowed: echo "dhcp dhcpv6 <>"
diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def
index 535fa6d2..5c37e92d 100644
--- a/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def
+++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def
@@ -6,9 +6,9 @@ syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
commit:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr-commit $VAR(@@) --dev $VAR(../../@).$VAR(../@)"
-create:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../../@).$VAR(../@)
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../../@).$VAR(../@) $VAR(@)
-delete:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../../@).$VAR(../@)
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../../@).$VAR(../@) $VAR(@)
allowed: echo "dhcp <>"
diff --git a/templates/interfaces/loopback/node.tag/address/node.def b/templates/interfaces/loopback/node.tag/address/node.def
index c0ec9386..98788814 100644
--- a/templates/interfaces/loopback/node.tag/address/node.def
+++ b/templates/interfaces/loopback/node.tag/address/node.def
@@ -6,8 +6,6 @@ help: IP address
syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
-create:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@)"; \
- "Error setting address $VAR(@) on interface $VAR(../@)"
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../@) $VAR(@)
-delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)"; \
- "Error deleting address $VAR(@) on interface $VAR(../@)"
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../@) $VAR(@)
diff --git a/templates/interfaces/pseudo-ethernet/node.tag/address/node.def b/templates/interfaces/pseudo-ethernet/node.tag/address/node.def
index ad900975..b237e108 100644
--- a/templates/interfaces/pseudo-ethernet/node.tag/address/node.def
+++ b/templates/interfaces/pseudo-ethernet/node.tag/address/node.def
@@ -4,9 +4,9 @@ help: IP address
syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
-create:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@)
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../@) $VAR(@)
-delete:sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../@) $VAR(@)
allowed: echo "dhcp <>"
diff --git a/templates/interfaces/tunnel/node.tag/address/node.def b/templates/interfaces/tunnel/node.tag/address/node.def
index e6a1e542..04612379 100644
--- a/templates/interfaces/tunnel/node.tag/address/node.def
+++ b/templates/interfaces/tunnel/node.tag/address/node.def
@@ -6,7 +6,7 @@ help: IP address
syntax:expression: exec "/opt/vyatta/sbin/valid_address $VAR(@)"
-create:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@)"; "Error setting address $VAR(@) on interface $VAR(../@)"
+create: sudo /opt/vyatta/sbin/vyatta-address add $VAR(../@) $VAR(@)
-delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)"; "Error deleting address $VAR(@) on interface $VAR(../@)"
+delete: sudo /opt/vyatta/sbin/vyatta-address delete $VAR(../@) $VAR(@)