summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMichael Larson <slioch@slioch.vyatta.com>2010-06-21 11:09:51 -0700
committerMichael Larson <slioch@slioch.vyatta.com>2010-06-21 11:09:51 -0700
commitd801c05f63b0b16f485b176db64e3147ad7d3086 (patch)
tree9829f0bf340a55986aa6d11f1b1d8d5334306abd /scripts
parent6d59b5077ef1834379a950437b01d15d687c7a53 (diff)
parent7369bf61abd3eed1fdd17a56908cf2c0ffc9843f (diff)
downloadvyatta-cfg-system-d801c05f63b0b16f485b176db64e3147ad7d3086.tar.gz
vyatta-cfg-system-d801c05f63b0b16f485b176db64e3147ad7d3086.zip
Merge branch 'larkspur' of http://git.vyatta.com/vyatta-cfg-system into larkspur
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install-system27
-rwxr-xr-xscripts/install/install-image33
-rwxr-xr-xscripts/install/install-image-existing51
-rwxr-xr-xscripts/install/install-image-new31
-rwxr-xr-xscripts/install/install-postinst-new6
-rwxr-xr-xscripts/keepalived/vyatta-keepalived.pl805
-rwxr-xr-xscripts/rl-system.init4
-rw-r--r--scripts/snmp/vyatta-snmp.pl117
-rwxr-xr-xscripts/system/vyatta_update_resolv.pl32
-rw-r--r--scripts/vyatta-dhcpv6-client.pl157
-rwxr-xr-xscripts/vyatta-interfaces.pl24
11 files changed, 833 insertions, 454 deletions
diff --git a/scripts/install-system b/scripts/install-system
index d17f0c2e..4f92ca37 100755
--- a/scripts/install-system
+++ b/scripts/install-system
@@ -890,6 +890,23 @@ create_partitions() {
fi
}
+# Copy directory with pretty progress bar
+copy_filesystem() {
+ cp -r -v --preserve=all "$@" | awk '{
+ ++files
+ if ((files % 10) == 0) {
+ percent = files / total_files * 100
+ printf "%3d%% [", percent
+ for (i=0;i<percent; i+=2)
+ printf "="
+ printf ">"
+ for (;i<100;i+=2)
+ printf " "
+ printf "]\r"
+ }
+ }' total_files=$(find "$@" | wc -l)
+}
+
# Install the root filesystem
# $1 is the partition to install on
install_root_filesystem () {
@@ -914,8 +931,7 @@ install_root_filesystem () {
fi
if [ -z $UNION ]; then
- echo -n "Copying system image files to /dev/$ROOT_PARTITION: "
- progress_indicator start
+ echo "Copying system files to /dev/$ROOT_PARTITION: "
# Mount the squashfs for copying
output=$(mkdir -p /mnt/squashfs)
if [ -f /live/image/live/filesystem.squashfs ]; then
@@ -936,12 +952,13 @@ install_root_filesystem () {
exit 1
fi
- output=$(cp -pR /mnt/squashfs/* $rootfsdir/)
+ echo "Copying /mnt/squashfs/* to $rootfsddir" >>$INSTALL_LOG
+ copy_filesystem /mnt/squashfs/* $rootfsdir 2>>$INSTALL_LOG
status=$?
-
+ echo
+
if [ "$status" != 0 ]; then
echo -e "Error trying to copy the rootfs.\nPlease see install log for more details.\nExiting..."
- echo -e "Error trying to copy the rootfs.\ncp -pR /mnt/squashfs/* $rootfsdir/\n$output" >> $INSTALL_LOG
exit 1
fi
diff --git a/scripts/install/install-image b/scripts/install/install-image
index 607dcc98..c4bf3800 100755
--- a/scripts/install/install-image
+++ b/scripts/install/install-image
@@ -69,6 +69,39 @@ fetch_iso_by_url ()
fi
echo "ISO download suceeded."
+
+ echo "Checking for digital signature file..."
+ curl -f -o ${filename}.asc ${NEW_ISO}.asc
+ if [ $? -ne 0 ]; then
+ echo "Unable to fetch digital signature file."
+ echo -n "Do you want to continue without signature check? (yes/no) [yes] "
+
+ response=$(get_response "Yes" "Yes No Y N")
+ if [ "$response" == "no" ] || [ "$response" == "n" ]; then
+ fail_exit 'OK. Installation will not be performed.'
+ fi
+
+ # In case signature file was partially downloaded...
+ rm -f ${filename}.asc
+ fi
+
+ if [ -e ${filename}.asc ]; then
+ echo "Found it. Checking digital signature..."
+ gpg --keyring /etc/apt/trusted.gpg --verify ${filename}.asc
+ if [ $? -ne 0 ]; then
+ echo "Signature check FAILED."
+ echo -n "Do you want to continue anyway? (yes/no) [no] "
+ response=$(get_response "Yes" "Yes No Y N")
+ if [ "$response" == "no" ] || [ "$response" == "n" ]; then
+ fail_exit 'OK. Installation will not be performed.'
+ fi
+
+ echo "OK. Proceding with installation anyway."
+ else
+ echo "Digital signature is valid."
+ fi
+ fi
+
NEW_ISO=$filename
}
diff --git a/scripts/install/install-image-existing b/scripts/install/install-image-existing
index ce0e502d..e8f723a0 100755
--- a/scripts/install/install-image-existing
+++ b/scripts/install/install-image-existing
@@ -54,16 +54,27 @@ fi
# get new version string. this is from the squashfs image.
NEWVER=`dpkg -l --root=${CD_SQUASH_ROOT} | grep "^.. vyatta-version " | awk '{print $3}'`
+NEWNAME=$NEWVER
-if [ -z "$NEWVER" ]; then
- failure_exit 'Cannot find new release version.'
+echo -n "What would you like to name this image? [$NEWNAME]: "
+read response
+if [ -n "$response" ]; then
+ NEWNAME=$response
fi
-if [ "$CURVER" == "$NEWVER" ]; then
- echo "Image version $NEWVER is the same as the running system."
- echo "Cannot install the same release version as the running system."
- exit 1
+
+# Validate image name
+if [ "$NEWNAME" = "grub" -o "${NEWNAME:0:7}" = "vmlinuz" -o \
+ "${NEWNAME:0:6}" = "initrd" -o "${NEWNAME:0:10}" = "System.map" -o \
+ "$NEWNAME" = "Old-non-image-installation" ]; then
+ echo "Can't use $NEWNAME. It is a reserved image name."
+ exit 1;
+fi
+
+if [ -z "$NEWNAME" ]; then
+ failure_exit 'Invalid image name.'
fi
+echo "OK. This image will be named: $NEWNAME"
# this is the default if current install is union
BOOT_DIR=/live/image/boot
@@ -74,24 +85,30 @@ elif [ "$CUR_INSTALL" != 'union' ]; then
exit 1
fi
-if [ -d $BOOT_DIR/$NEWVER ]; then
- echo "Version $NEWVER is already installed on this system."
+if [ -d $BOOT_DIR/$NEWNAME ]; then
+ if [ "$CURVER" = "$NEWNAME" ]; then
+ echo "$NEWNAME is the image you are currently running. Can't"
+ echo "Re-install over the running image."
+ exit 1
+ fi
+
+ echo "An image named $NEWNAME is already installed on this system."
echo "Proceeding with this installation will delete this copy of"
- echo "$NEWVER and replace it with a new copy."
+ echo "$NEWNAME and replace it with a new copy."
echo -n "Do you want to replace it? (Yes/No) [No]: "
resp=$(get_response "No" "Yes No Y N")
if [ "$resp" != 'yes' ] && [ "$resp" != 'y' ]; then
- echo "OK. Will not replace $NEWVER"
+ echo "OK. Will not replace $NEWNAME"
echo "Exiting..."
exit 1
fi
fi
# start the install
-echo "Installing \"$NEWVER\" release."
+echo "Installing \"$NEWNAME\" image."
# create the new release directories
-REL_ROOT=$BOOT_DIR/$NEWVER
+REL_ROOT=$BOOT_DIR/$NEWNAME
RW_DIR="$REL_ROOT/live-rw"
if ! mkdir -p "$RW_DIR"; then
failure_exit 'Cannot create directory for new release.'
@@ -108,7 +125,7 @@ if [ ! -f "$squash_img" ] || [ -z "$boot_files" ]; then
fi
target_squash=$REL_ROOT/$NEWVER.squashfs
cp -p $squash_img $target_squash >&/dev/null
-cp -dp $boot_files $REL_ROOT/ >&/dev/null
+cp --no-dereference --preserve=all $boot_files $REL_ROOT/ >&/dev/null
# mount copied squashfs
if ! try_mount "-o loop,ro $target_squash $READ_ROOT"; then
@@ -163,10 +180,16 @@ if [ -e "$DEF_GRUB" ]; then
echo "Setting up grub configuration..."
new_index=$(get_grub_index)
+ def_grub_vers=/tmp/def_grub.$$
+ cp $DEF_GRUB $def_grub_vers
+ sed -i "s/menuentry \"Vyatta.*(/menuentry \"Vyatta image $NEWNAME (/" $def_grub_vers
+ sed -i "s/menuentry \"Lost password change.*(/menuentry \"Lost password change $NEWNAME (/" $def_grub_vers
+ sed -i "sX/boot/[A-Za-z0-9\.\-]*X/boot/${NEWNAME}Xg" $def_grub_vers
+
old_grub_cfg=$BOOT_DIR/grub/grub.cfg
new_grub_cfg=/tmp/grub.cfg.$$
sed -n '/^menuentry/q;p' $old_grub_cfg >$new_grub_cfg
- cat $DEF_GRUB >>$new_grub_cfg
+ cat $def_grub_vers >> $new_grub_cfg
sed -n '/^menuentry/,${p}' $old_grub_cfg >>$new_grub_cfg
sed -i "s/^set default=[0-9]\+$/set default=$new_index/" $new_grub_cfg
mv $new_grub_cfg $old_grub_cfg
diff --git a/scripts/install/install-image-new b/scripts/install/install-image-new
index 7294fc35..5726fa03 100755
--- a/scripts/install/install-image-new
+++ b/scripts/install/install-image-new
@@ -24,15 +24,36 @@ if ! try_mount "/dev/$ROOT_PARTITION $WRITE_ROOT"; then
fi
version=$(get_new_version)
-if [ -z "$version" ]; then
+image_name=$version
+if [ -z "$image_name" ]; then
echo 'Cannot find new version. Exiting...'
exit 1
fi
+echo -n "What would you like to name this image? [$image_name]: "
+read response
+if [ -n "$response" ]; then
+ image_name=$response
+fi
+
+# Validate image name
+if [ "$image_name" = "grub" -o "${image_name:0:7}" = "vmlinuz" -o \
+ "${image_name:0:6}" = "initrd" -o "${image_name:0:10}" = "System.map" -o \
+ "$image_name" = "Old-non-image-installation" ]; then
+ echo "Can't use $image_name. It is a reserved image name."
+ exit 1;
+fi
+
+if [ -z "$image_name" ]; then
+ failure_exit 'Invalid image name.'
+fi
+
+echo "OK. This image will be named: $image_name"
+
# make the dir for the new version
-mkdir -p $WRITE_ROOT/boot/$version
+mkdir -p $WRITE_ROOT/boot/$image_name
# make dir for backing store
-rw_dir=$WRITE_ROOT/boot/$version/live-rw
+rw_dir=$WRITE_ROOT/boot/$image_name/live-rw
mkdir -p $rw_dir
echo Copying squashfs image...
@@ -53,10 +74,10 @@ if [ ! -f "$squash_img" ] || [ -z "$boot_files" ]; then
fi
fi
-target_squash=$WRITE_ROOT/boot/$version/$version.squashfs
+target_squash=$WRITE_ROOT/boot/$image_name/$version.squashfs
cp -p $squash_img $target_squash
echo Copying kernel and initrd images...
-cp -dp $boot_files $WRITE_ROOT/boot/$version/
+cp -dp $boot_files $WRITE_ROOT/boot/$image_name/
# set up union root for postinst
mkdir -p $INST_ROOT $READ_ROOT
diff --git a/scripts/install/install-postinst-new b/scripts/install/install-postinst-new
index 65c6cd7f..c96f5657 100755
--- a/scripts/install/install-postinst-new
+++ b/scripts/install/install-postinst-new
@@ -133,9 +133,13 @@ if [ -z "$version" ]; then
exit 1
fi
+array=( $WRITE_ROOT/boot/* )
+image_name=${array[0]}
+image_name=${image_name#$WRITE_ROOT/boot/}
+
# these are the defaults for "union"
grub_root=$WRITE_ROOT
-grub_setup_args="-u $version"
+grub_setup_args="-u $image_name"
if [ "$INSTALL_TYPE" == 'old' ]; then
grub_root=$INST_ROOT
grub_setup_args="-v $version"
diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl
index e87c9f64..d06b9e36 100755
--- a/scripts/keepalived/vyatta-keepalived.pl
+++ b/scripts/keepalived/vyatta-keepalived.pl
@@ -1,12 +1,12 @@
#!/usr/bin/perl
#
# Module: vyatta-keepalived.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
@@ -15,11 +15,11 @@
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2007-2009 Vyatta, Inc.
# All Rights Reserved.
-#
+#
# Author: Stig Thormodsrud
# Date: October 2007
# Description: Script to glue vyatta cli to keepalived daemon
-#
+#
# **** End License ****
#
@@ -28,445 +28,506 @@ use Vyatta::Config;
use Vyatta::Keepalived;
use Vyatta::TypeChecker;
use Vyatta::Interface;
+use Vyatta::ConntrackSync;
use Vyatta::Misc;
use Getopt::Long;
use strict;
use warnings;
-my ($action, $vrrp_intf, $vrrp_group, $vrrp_vip);
-my ($conf_file, $changes_file);
+my ( $action, $vrrp_intf, $vrrp_group, $vrrp_vip, $ctsync );
+my ( $conf_file, $changes_file );
my %HoA_sync_groups;
+my $ctsync_script = "/opt/vyatta/sbin/vyatta-vrrp-conntracksync.sh";
sub validate_source_addr {
- my ($ifname, $source_addr) = @_;
-
- my @ipaddrs;
- if (defined $source_addr) {
- my %config_ipaddrs;
- my @ipaddrs = Vyatta::Misc::getInterfacesIPadresses('all');
- foreach my $ip (@ipaddrs) {
- if ($ip =~ /^([\d.]+)\/([\d.]+)$/) { # strip /mask
- $config_ipaddrs{$1} = 1;
- }
- }
- if (!defined $config_ipaddrs{$source_addr}) {
- vrrp_log("no hello-source");
- return "hello-source-address [$source_addr] must be " .
- "configured on the interface\n";
- }
- return;
+ my ( $ifname, $source_addr ) = @_;
+
+ my @ipaddrs;
+ if ( defined $source_addr ) {
+ my %config_ipaddrs;
+ my @ipaddrs = Vyatta::Misc::getInterfacesIPadresses('all');
+ foreach my $ip (@ipaddrs) {
+ if ( $ip =~ /^([\d.]+)\/([\d.]+)$/ ) { # strip /mask
+ $config_ipaddrs{$1} = 1;
+ }
}
- # if the hello-source-address wasn't configured, check that the
- # interface has an IPv4 address configured on it.
- my $intf = new Vyatta::Interface($ifname);
- @ipaddrs = $intf->address(4);
- if (scalar(@ipaddrs) < 1) {
- vrrp_log("no primary or hello-source");
- return "must configure either a primary address on [$ifname] or" .
- " a hello-source-address\n";
+ if ( !defined $config_ipaddrs{$source_addr} ) {
+ vrrp_log("no hello-source");
+ return "hello-source-address [$source_addr] must be "
+ . "configured on the interface\n";
}
return;
+ }
+
+ # if the hello-source-address wasn't configured, check that the
+ # interface has an IPv4 address configured on it.
+ my $intf = new Vyatta::Interface($ifname);
+ @ipaddrs = $intf->address(4);
+ if ( scalar(@ipaddrs) < 1 ) {
+ vrrp_log("no primary or hello-source");
+ return "must configure either a primary address on [$ifname] or"
+ . " a hello-source-address\n";
+ }
+ return;
+}
+
+sub get_ctsync_syncgrp {
+ my ($origfunc) = @_;
+ my $failover_sync_grp = undef;
+
+ my $listnodesfunc = "listNodes";
+ my $returnvalfunc = "returnValue";
+ if ( defined $origfunc ) {
+ $listnodesfunc = "listOrigNodes";
+ $returnvalfunc = "returnOrigValue";
+ }
+
+ my @failover_mechanism =
+ Vyatta::ConntrackSync::get_conntracksync_val( $listnodesfunc,
+ "failover-mechanism" );
+
+ if ( defined $failover_mechanism[0] && $failover_mechanism[0] eq 'vrrp' ) {
+ $failover_sync_grp =
+ Vyatta::ConntrackSync::get_conntracksync_val( $returnvalfunc,
+ "failover-mechanism $failover_mechanism[0] vrrp-sync-group" );
+ }
+ return $failover_sync_grp;
}
sub keepalived_get_values {
- my ($intf, $path) = @_;
-
- my @errs = ();
- my $output = '';
- my $config = new Vyatta::Config;
-
- my $state_transition_script = get_state_script();
-
- vrrp_log("keepalived_get_values [$intf][$path]");
- $config->setLevel("$path vrrp vrrp-group");
- my @groups = $config->listNodes();
- foreach my $group (@groups) {
- my $vrrp_instance = "vyatta-$intf-$group";
- $config->setLevel("$path vrrp vrrp-group $group");
- if ($config->exists("disable")) {
- vrrp_log("$vrrp_instance disabled - skipping");
- my $state_file = get_state_file($intf, $group);
- system("rm -f $state_file");
- next;
- }
- my @vips = $config->returnValues("virtual-address");
- my $num_vips = scalar(@vips);
- if ($num_vips == 0) {
- push @errs, "must define a virtual-address for vrrp-group $group\n";
- next;
- }
- if ($num_vips > 20) {
- push @errs, "can not set more than 20 VIPs per group\n";
- next
- }
- my $priority = $config->returnValue("priority");
- if (!defined $priority) {
- $priority = 1;
- }
- my $preempt = $config->returnValue("preempt");
- if (!defined $preempt) {
- $preempt = "true";
- }
- my $preempt_delay = $config->returnValue("preempt-delay");
- if (defined $preempt_delay and $preempt eq "false") {
- print "Warning: preempt delay is ignored when preempt=false\n";
- }
- my $advert_int = $config->returnValue("advertise-interval");
- if (!defined $advert_int) {
- $advert_int = 1;
- }
- my $sync_group = $config->returnValue("sync-group");
- if (defined $sync_group && $sync_group ne "") {
- push @{ $HoA_sync_groups{$sync_group} }, $vrrp_instance;
- }
- my $hello_source_addr = $config->returnValue("hello-source-address");
- my $err = validate_source_addr($intf, $hello_source_addr);
- if (defined $err) {
- push @errs, $err;
- next;
- }
-
- $config->setLevel("$path vrrp vrrp-group $group authentication");
- my $auth_type = $config->returnValue("type");
- my $auth_pass;
- if (defined $auth_type) {
- $auth_type = "PASS" if $auth_type eq "simple";
- $auth_type = uc($auth_type);
- $auth_pass = $config->returnValue("password");
- if (! defined $auth_pass) {
- push @errs, "vrrp authentication password not set\n";
- next;
- }
- }
-
- $config->setLevel("$path vrrp vrrp-group $group run-transition-scripts");
- my $run_backup_script = $config->returnValue("backup");
- if(!defined $run_backup_script){
- $run_backup_script = "null";
- }
- my $run_fault_script = $config->returnValue("fault");
- if(!defined $run_fault_script){
- $run_fault_script = "null";
- }
- my $run_master_script = $config->returnValue("master");
- if(!defined $run_master_script){
- $run_master_script = "null";
- }
+ my ( $intf, $path ) = @_;
+
+ my @errs = ();
+ my $output = '';
+ my $config = new Vyatta::Config;
+
+ my $state_transition_script = get_state_script();
+
+ vrrp_log("keepalived_get_values [$intf][$path]");
+ $config->setLevel("$path vrrp vrrp-group");
+ my @groups = $config->listNodes();
+ foreach my $group (@groups) {
+ my $vrrp_instance = "vyatta-$intf-$group";
+ $config->setLevel("$path vrrp vrrp-group $group");
+ if ( $config->exists("disable") ) {
+ vrrp_log("$vrrp_instance disabled - skipping");
+ my $state_file = get_state_file( $intf, $group );
+ system("rm -f $state_file");
+ next;
+ }
+ my @vips = $config->returnValues("virtual-address");
+ my $num_vips = scalar(@vips);
+ if ( $num_vips == 0 ) {
+ push @errs, "must define a virtual-address for vrrp-group $group\n";
+ next;
+ }
+ if ( $num_vips > 20 ) {
+ push @errs, "can not set more than 20 VIPs per group\n";
+ next;
+ }
+ my $priority = $config->returnValue("priority");
+ if ( !defined $priority ) {
+ $priority = 1;
+ }
+ my $preempt = $config->returnValue("preempt");
+ if ( !defined $preempt ) {
+ $preempt = "true";
+ }
+ my $preempt_delay = $config->returnValue("preempt-delay");
+ if ( defined $preempt_delay and $preempt eq "false" ) {
+ print "Warning: preempt delay is ignored when preempt=false\n";
+ }
+ my $advert_int = $config->returnValue("advertise-interval");
+ if ( !defined $advert_int ) {
+ $advert_int = 1;
+ }
+ my $sync_group = $config->returnValue("sync-group");
+ if ( defined $sync_group && $sync_group ne "" ) {
+ push @{ $HoA_sync_groups{$sync_group} }, $vrrp_instance;
+ }
+ my $hello_source_addr = $config->returnValue("hello-source-address");
+ my $err = validate_source_addr( $intf, $hello_source_addr );
+ if ( defined $err ) {
+ push @errs, $err;
+ next;
+ }
+
+ $config->setLevel("$path vrrp vrrp-group $group authentication");
+ my $auth_type = $config->returnValue("type");
+ my $auth_pass;
+ if ( defined $auth_type ) {
+ $auth_type = "PASS" if $auth_type eq "simple";
+ $auth_type = uc($auth_type);
+ $auth_pass = $config->returnValue("password");
+ if ( !defined $auth_pass ) {
+ push @errs, "vrrp authentication password not set\n";
+ next;
+ }
+ }
- # We now have the values and have validated them, so
- # generate the config.
-
- $output .= "vrrp_instance $vrrp_instance \{\n";
- my $init_state;
- $init_state = vrrp_get_init_state($intf, $group, $vips[0], $preempt);
- $output .= "\tstate $init_state\n";
- $output .= "\tinterface $intf\n";
- $output .= "\tvirtual_router_id $group\n";
- $output .= "\tpriority $priority\n";
- if ($preempt eq "false") {
- $output .= "\tnopreempt\n";
- }
- if (defined $preempt_delay) {
- $output .= "\tpreempt_delay $preempt_delay\n";
- }
- $output .= "\tadvert_int $advert_int\n";
- if (defined $auth_type) {
- $output .= "\tauthentication {\n";
- $output .= "\t\tauth_type $auth_type\n";
- $output .= "\t\tauth_pass $auth_pass\n\t}\n";
- }
- if (defined $hello_source_addr) {
- $output .= "\tmcast_src_ip $hello_source_addr\n";
- }
- $output .= "\tvirtual_ipaddress \{\n";
- foreach my $vip (@vips) {
- $output .= "\t\t$vip\n";
- }
- $output .= "\t\}\n";
- $output .= "\tnotify_master \"$state_transition_script master ";
- $output .= "$intf $group $run_master_script @vips\" \n";
- $output .= "\tnotify_backup \"$state_transition_script backup ";
- $output .= "$intf $group $run_backup_script @vips\" \n";
- $output .= "\tnotify_fault \"$state_transition_script fault ";
- $output .= "$intf $group $run_fault_script @vips\" \n";
- $output .= "\}\n\n";
+ $config->setLevel("$path vrrp vrrp-group $group run-transition-scripts");
+ my $run_backup_script = $config->returnValue("backup");
+ if ( !defined $run_backup_script ) {
+ $run_backup_script = "null";
+ }
+ my $run_fault_script = $config->returnValue("fault");
+ if ( !defined $run_fault_script ) {
+ $run_fault_script = "null";
+ }
+ my $run_master_script = $config->returnValue("master");
+ if ( !defined $run_master_script ) {
+ $run_master_script = "null";
}
- return ($output, @errs);
+ # We now have the values and have validated them, so
+ # generate the config.
+
+ $output .= "vrrp_instance $vrrp_instance \{\n";
+ my $init_state;
+ if ( defined $ctsync ) {
+
+ # check if this group is part of conntrack-sync vrrp-sync-group
+ my $ctsync_syncgrp = get_ctsync_syncgrp();
+ my $vrrpsyncgrp =
+ list_vrrp_sync_group( $intf, $group, 'returnOrigPlusComValue' );
+ if ( defined $ctsync_syncgrp
+ && defined $vrrpsyncgrp
+ && ( $ctsync_syncgrp eq $vrrpsyncgrp ) )
+ {
+ $init_state = 'BACKUP';
+ } else {
+ $init_state = vrrp_get_init_state( $intf, $group, $vips[0], $preempt );
+ }
+ } else {
+ $init_state = vrrp_get_init_state( $intf, $group, $vips[0], $preempt );
+ }
+ $output .= "\tstate $init_state\n";
+ $output .= "\tinterface $intf\n";
+ $output .= "\tvirtual_router_id $group\n";
+ $output .= "\tpriority $priority\n";
+ if ( $preempt eq "false" ) {
+ $output .= "\tnopreempt\n";
+ }
+ if ( defined $preempt_delay ) {
+ $output .= "\tpreempt_delay $preempt_delay\n";
+ }
+ $output .= "\tadvert_int $advert_int\n";
+ if ( defined $auth_type ) {
+ $output .= "\tauthentication {\n";
+ $output .= "\t\tauth_type $auth_type\n";
+ $output .= "\t\tauth_pass $auth_pass\n\t}\n";
+ }
+ if ( defined $hello_source_addr ) {
+ $output .= "\tmcast_src_ip $hello_source_addr\n";
+ }
+ $output .= "\tvirtual_ipaddress \{\n";
+ foreach my $vip (@vips) {
+ $output .= "\t\t$vip\n";
+ }
+ $output .= "\t\}\n";
+ $output .= "\tnotify_master \"$state_transition_script master ";
+ $output .= "$intf $group $run_master_script @vips\" \n";
+ $output .= "\tnotify_backup \"$state_transition_script backup ";
+ $output .= "$intf $group $run_backup_script @vips\" \n";
+ $output .= "\tnotify_fault \"$state_transition_script fault ";
+ $output .= "$intf $group $run_fault_script @vips\" \n";
+ $output .= "\}\n\n";
+ }
+
+ return ( $output, @errs );
}
sub vrrp_get_sync_groups {
-
- my $output = "";
-
- foreach my $sync_group ( keys %HoA_sync_groups) {
- $output .= "vrrp_sync_group $sync_group \{\n\tgroup \{\n";
- foreach my $vrrp_instance ( 0 .. $#{ $HoA_sync_groups{$sync_group} } ) {
- $output .= "\t\t$HoA_sync_groups{$sync_group}[$vrrp_instance]\n";
- }
- $output .= "\t\}\n\}\n";
+
+ my $output = "";
+
+ foreach my $sync_group ( keys %HoA_sync_groups ) {
+ $output .= "vrrp_sync_group $sync_group \{\n\tgroup \{\n";
+ foreach my $vrrp_instance ( 0 .. $#{ $HoA_sync_groups{$sync_group} } ) {
+ $output .= "\t\t$HoA_sync_groups{$sync_group}[$vrrp_instance]\n";
+ }
+ $output .= "\t\}\n";
+
+ ## add conntrack-sync part here if configured ##
+ my $origfunc = undef;
+ $origfunc = 'true' if !defined $ctsync;
+ my $failover_sync_grp = get_ctsync_syncgrp($origfunc);
+ if ( defined $failover_sync_grp && $failover_sync_grp eq $sync_group ) {
+ $output .= "\tnotify_master \"$ctsync_script master $sync_group\"\n";
+ $output .= "\tnotify_backup \"$ctsync_script backup $sync_group\"\n";
+ $output .= "\tnotify_fault \"$ctsync_script fault $sync_group\"\n";
}
- return $output;
+ $output .= "\}\n";
+ }
+ return $output;
}
sub vrrp_read_changes {
- my @lines = ();
- open(my $FILE, "<", $changes_file) or die "Error: read $!";
- @lines = <$FILE>;
- close($FILE);
- chomp @lines;
- return @lines;
+ my @lines = ();
+ return @lines if !-e $changes_file;
+ open( my $FILE, "<", $changes_file ) or die "Error: read $!";
+ @lines = <$FILE>;
+ close($FILE);
+ chomp @lines;
+ return @lines;
}
sub vrrp_save_changes {
- my @list = @_;
+ my @list = @_;
- my $num_changes = scalar(@list);
- vrrp_log("saving changes file $num_changes");
- open(my $FILE, ">", $changes_file) or die "Error: write $!";
- print $FILE join("\n", @list), "\n";
- close($FILE);
+ my $num_changes = scalar(@list);
+ vrrp_log("saving changes file $num_changes");
+ open( my $FILE, ">", $changes_file ) or die "Error: write $!";
+ print $FILE join( "\n", @list ), "\n";
+ close($FILE);
}
sub vrrp_find_changes {
- my @list = ();
- my $config = new Vyatta::Config;
- my $vrrp_instances = 0;
-
- foreach my $name ( getInterfaces() ) {
- my $intf = new Vyatta::Interface($name);
- next unless $intf;
- my $path = $intf->path();
- $config->setLevel($path);
- if ($config->exists("vrrp")) {
- my %vrrp_status_hash = $config->listNodeStatus("vrrp");
- my ($vrrp, $vrrp_status) = each(%vrrp_status_hash);
- if ($vrrp_status ne "static") {
- push @list, $name;
- vrrp_log("$vrrp_status found $name");
- }
- }
-
- #
- # Now look for deleted from the origin tree
- #
- $config->setLevel($path);
- if ($config->isDeleted("vrrp")) {
- push @list, $name;
- vrrp_log("Delete found $name");
- }
-
+ my @list = ();
+ my $config = new Vyatta::Config;
+ my $vrrp_instances = 0;
+ foreach my $name ( getInterfaces() ) {
+ my $intf = new Vyatta::Interface($name);
+ next unless $intf;
+ my $path = $intf->path();
+ $config->setLevel($path);
+ if ( $config->exists("vrrp") ) {
+ my %vrrp_status_hash = $config->listNodeStatus("vrrp");
+ my ( $vrrp, $vrrp_status ) = each(%vrrp_status_hash);
+ if ( $vrrp_status ne "static" ) {
+ push @list, $name;
+ vrrp_log("$vrrp_status found $name");
+ }
}
- my $num = scalar(@list);
- vrrp_log("Start transation: $num changes");
- if ($num) {
- vrrp_save_changes(@list);
+ #
+ # Now look for deleted from the origin tree
+ #
+ $config->setLevel($path);
+ if ( $config->isDeleted("vrrp") ) {
+ push @list, $name;
+ vrrp_log("Delete found $name");
}
- return $num;
+
+ }
+
+ my $num = scalar(@list);
+ vrrp_log("Start transation: $num changes");
+ if ($num) {
+ vrrp_save_changes(@list);
+ }
+ return $num;
}
sub remove_from_changes {
- my $intf = shift;
-
- my @lines = vrrp_read_changes();
- if (scalar(@lines) < 1) {
- #
- # we shouldn't get to this point, but try to handle it if we do
- #
- vrrp_log("unexpected remove_from_changes()");
- system("rm -f $changes_file");
- return 0;
- }
- my @new_lines = ();
- foreach my $line (@lines) {
- if ($line =~ /$intf$/) {
- vrrp_log("remove_from_changes [$line]");
- } else {
- push @new_lines, $line;
- }
- }
-
- my $num_changes = scalar(@new_lines);
- if ($num_changes > 0) {
- vrrp_save_changes(@new_lines);
+ my $intf = shift;
+
+ my @lines = vrrp_read_changes();
+ if ( scalar(@lines) < 1 ) {
+
+ #
+ # we shouldn't get to this point, but try to handle it if we do
+ #
+ vrrp_log("unexpected remove_from_changes()");
+ system("rm -f $changes_file");
+ return 0;
+ }
+ my @new_lines = ();
+ foreach my $line (@lines) {
+ if ( $line =~ /$intf$/ ) {
+ vrrp_log("remove_from_changes [$line]");
} else {
- system("rm -f $changes_file");
+ push @new_lines, $line;
}
- return $num_changes;
+ }
+
+ my $num_changes = scalar(@new_lines);
+ if ( $num_changes > 0 ) {
+ vrrp_save_changes(@new_lines);
+ } else {
+ system("rm -f $changes_file");
+ }
+ return $num_changes;
}
sub vrrp_update_config {
- my ($intf) = @_;
-
- my @errs = ();
- my $date = localtime();
- my $output = "#\n# autogenerated by $0 on $date\n#\n\n";
-
- my $config = new Vyatta::Config;
- my $vrrp_instances = 0;
-
- foreach my $name ( getInterfaces() ) {
- my $intf = new Vyatta::Interface($name);
- next unless $intf;
- my $path = $intf->path();
- $config->setLevel($path);
- if ($config->exists("vrrp")) {
- #
- # keepalived gets real grumpy with interfaces that
- # don't exist, so skip vlans that haven't been
- # instantiated yet (typically occurs at boot up).
- #
- if (!(-d "/sys/class/net/$name")) {
- push @errs, "$name doesn't exist";
- next;
- }
- my ($inst_output, @inst_errs) =
- keepalived_get_values($name, $path);
- if (scalar(@inst_errs)) {
- push @errs, @inst_errs;
- } else {
- $output .= $inst_output;
- $vrrp_instances++;
- }
- }
- }
-
- if ($vrrp_instances > 0) {
- my $sync_groups = vrrp_get_sync_groups();
- if (defined $sync_groups && $sync_groups ne "") {
- $output = $sync_groups . $output;
- }
- keepalived_write_file($conf_file, $output);
- }
- return ($vrrp_instances, @errs);
-}
-sub keepalived_write_file {
- my ($file, $data) = @_;
+ my @errs = ();
+ my $date = localtime();
+ my $output = "#\n# autogenerated by $0 on $date\n#\n\n";
- open(my $fh, '>', $file) || die "Couldn't open $file - $!";
- print $fh $data;
- close $fh;
-}
+ my $config = new Vyatta::Config;
+ my $vrrp_instances = 0;
-sub list_vrrp_intf {
- my $config = new Vyatta::Config;
- my @intfs = ();
-
- foreach my $name ( getInterfaces() ) {
- my $intf = new Vyatta::Interface($name);
- next unless $intf;
- my $path = $intf->path();
- $config->setLevel($path);
- push @intfs, $name if $config->existsOrig("vrrp");
+ foreach my $name ( getInterfaces() ) {
+ my $intf = new Vyatta::Interface($name);
+ next unless $intf;
+ my $path = $intf->path();
+ $config->setLevel($path);
+ if ( $config->exists("vrrp") ) {
+
+ #
+ # keepalived gets real grumpy with interfaces that
+ # don't exist, so skip vlans that haven't been
+ # instantiated yet (typically occurs at boot up).
+ #
+ if ( !( -d "/sys/class/net/$name" ) ) {
+ push @errs, "$name doesn't exist";
+ next;
+ }
+ my ( $inst_output, @inst_errs ) = keepalived_get_values( $name, $path );
+ if ( scalar(@inst_errs) ) {
+ push @errs, @inst_errs;
+ } else {
+ $output .= $inst_output;
+ $vrrp_instances++;
+ }
}
+ }
- return @intfs;
+ if ( $vrrp_instances > 0 ) {
+ my $sync_groups = vrrp_get_sync_groups();
+ if ( defined $sync_groups && $sync_groups ne "" ) {
+ $output = $sync_groups . $output;
+ }
+ keepalived_write_file( $conf_file, $output );
+ }
+ return ( $vrrp_instances, @errs );
}
-sub list_vrrp_group {
- my ($name) = @_;
- my $config = new Vyatta::Config;
- my $path;
+sub keepalived_write_file {
+ my ( $file, $data ) = @_;
- my $intf = new Vyatta::Interface($name);
- next unless $intf;
- $path = $intf->path();
- $path .= " vrrp vrrp-group";
- $config->setLevel($path);
- my @groups = $config->listOrigNodes();
- return @groups;
+ open( my $fh, '>', $file ) || die "Couldn't open $file - $!";
+ print $fh $data;
+ close $fh;
}
-
#
# main
#
-GetOptions("vrrp-action=s" => \$action,
- "intf=s" => \$vrrp_intf,
- "group=s" => \$vrrp_group,
- "vip=s" => \$vrrp_vip);
-
-if (! defined $action) {
- print "no action\n";
- exit 1;
+GetOptions(
+ "vrrp-action=s" => \$action,
+ "intf=s" => \$vrrp_intf,
+ "group=s" => \$vrrp_group,
+ "vip=s" => \$vrrp_vip,
+ "ctsync=s" => \$ctsync,
+);
+
+if ( !defined $action ) {
+ print "no action\n";
+ exit 1;
}
-if ($action eq "update") {
- $changes_file = get_changes_file();
- $conf_file = get_conf_file();
- vrrp_log("vrrp update $vrrp_intf");
- if ( ! -e $changes_file) {
- my $num_changes = vrrp_find_changes();
- if ($num_changes == 0) {
- #
- # Shouldn't happen, but ...
- #
- vrrp_log("unexpected 0 changes");
- }
- }
- my ($vrrp_instances, @errs) = vrrp_update_config($vrrp_intf);
- my $more_changes = remove_from_changes($vrrp_intf);
- vrrp_log(" instances $vrrp_instances, $more_changes");
- if ($vrrp_instances > 0 and $more_changes == 0) {
- restart_daemon($conf_file);
- }
- if ($vrrp_instances == 0) {
- stop_daemon();
- system("rm -f $conf_file");
+if ( !defined $ctsync ) {
+
+ # make sure sync-group used by ctsync has not been deleted
+
+ my $failover_sync_grp = get_ctsync_syncgrp();
+ if ( defined $failover_sync_grp ) {
+
+ # make sure vrrp-sync-group exists
+ my $sync_grp_exists = 'false';
+ my @vrrp_intfs = list_vrrp_intf('exists');
+ foreach my $vrrp_intf (@vrrp_intfs) {
+ my @vrrp_groups = list_vrrp_group( $vrrp_intf, 'listNodes' );
+ foreach my $vrrp_group (@vrrp_groups) {
+ my $sync_grp =
+ list_vrrp_sync_group( $vrrp_intf, $vrrp_group, 'returnValue' );
+ if ( defined $sync_grp && $sync_grp eq "$failover_sync_grp" ) {
+ $sync_grp_exists = 'true';
+ last;
+ }
+ }
+ last if $sync_grp_exists eq 'true';
}
- if (scalar(@errs)) {
- print join("\n", @errs);
- vrrp_log(join("\n", @errs));
- exit 1
+
+ if ( $sync_grp_exists eq 'false' ) {
+ print "sync-group $failover_sync_grp used for conntrack-sync"
+ . " is either deleted or undefined\n";
+ exit 1;
}
- exit 0;
+ }
+
}
-if ($action eq "delete") {
- if (! defined $vrrp_intf || ! defined $vrrp_group) {
- print "must include interface & group";
- exit 1;
+if ( $action eq "update" ) {
+ $changes_file = get_changes_file();
+ $conf_file = get_conf_file();
+ vrrp_log("vrrp update $vrrp_intf") if defined $vrrp_intf;
+ vrrp_log("vrrp update conntrack-sync") if defined $ctsync;
+ if ( !-e $changes_file ) {
+ my $num_changes = vrrp_find_changes();
+ if ( $num_changes == 0 ) {
+
+ #
+ # Shouldn't happen, but ...
+ #
+ vrrp_log("unexpected 0 changes");
}
- vrrp_log("vrrp delete $vrrp_intf $vrrp_group");
- my $state_file = get_state_file($vrrp_intf, $vrrp_group);
- system("rm -f $state_file");
- exit 0;
+ }
+ my ( $vrrp_instances, @errs ) = vrrp_update_config();
+ my $more_changes = 0;
+ $more_changes = remove_from_changes($vrrp_intf) if !defined $ctsync;
+ vrrp_log(" instances $vrrp_instances, $more_changes");
+ if ( $vrrp_instances > 0 and $more_changes == 0 ) {
+ restart_daemon($conf_file);
+ }
+ if ( $vrrp_instances == 0 ) {
+ stop_daemon();
+ system("rm -f $conf_file");
+ }
+ if ( scalar(@errs) ) {
+ print join( "\n", @errs );
+ vrrp_log( join( "\n", @errs ) );
+ exit 1;
+ }
+ exit 0;
}
-if ($action eq "check-vip") {
- if (! defined $vrrp_vip) {
- print "must include the virtual-address to check";
- exit 1;
- }
- my $rc = 1;
- if ($vrrp_vip =~ /\//) {
- $rc = Vyatta::TypeChecker::validateType('ipv4net', $vrrp_vip, 1);
- } else {
- $rc = Vyatta::TypeChecker::validateType('ipv4', $vrrp_vip, 1);
- }
- exit 1 if ! $rc;
- exit 0;
+if ( $action eq "delete" ) {
+ if ( !defined $vrrp_intf || !defined $vrrp_group ) {
+ print "must include interface & group";
+ exit 1;
+ }
+ vrrp_log("vrrp delete $vrrp_intf $vrrp_group");
+ my $state_file = get_state_file( $vrrp_intf, $vrrp_group );
+ system("rm -f $state_file");
+ exit 0;
}
-if ($action eq "list-vrrp-intf") {
- my @intfs = list_vrrp_intf();
- print join(' ', @intfs);
- exit 0;
+if ( $action eq "check-vip" ) {
+ if ( !defined $vrrp_vip ) {
+ print "must include the virtual-address to check";
+ exit 1;
+ }
+ my $rc = 1;
+ if ( $vrrp_vip =~ /\// ) {
+ $rc = Vyatta::TypeChecker::validateType( 'ipv4net', $vrrp_vip, 1 );
+ } else {
+ $rc = Vyatta::TypeChecker::validateType( 'ipv4', $vrrp_vip, 1 );
+ }
+ exit 1 if !$rc;
+ exit 0;
}
-if ($action eq "list-vrrp-group") {
- if (! defined $vrrp_intf) {
- print "must include interface\n";
- exit 1;
- }
- my @groups = list_vrrp_group($vrrp_intf);
- print join(' ', @groups);
- exit 0;
+if ( $action eq "list-vrrp-intf" ) {
+ my @intfs = list_vrrp_intf();
+ print join( ' ', @intfs );
+ exit 0;
+}
+
+if ( $action eq "list-vrrp-group" ) {
+ if ( !defined $vrrp_intf ) {
+ print "must include interface\n";
+ exit 1;
+ }
+ my @groups = list_vrrp_group($vrrp_intf);
+ print join( ' ', @groups );
+ exit 0;
}
exit 0;
diff --git a/scripts/rl-system.init b/scripts/rl-system.init
index d95fcafa..fd5b9eea 100755
--- a/scripts/rl-system.init
+++ b/scripts/rl-system.init
@@ -173,7 +173,9 @@ security_reset () {
# restore PAM back to virgin state (no radius other services)
rm -f /etc/pam_radius_auth.conf
if grep -q radius /etc/pam.d/common-auth
- then pam-auth-update --remove radius
+ then
+ pam-auth-update --package --remove radius
+ rm /usr/share/pam-configs/radius
fi
# Disable root login with ssh
diff --git a/scripts/snmp/vyatta-snmp.pl b/scripts/snmp/vyatta-snmp.pl
index 3adb37b7..a3be64ad 100644
--- a/scripts/snmp/vyatta-snmp.pl
+++ b/scripts/snmp/vyatta-snmp.pl
@@ -26,6 +26,7 @@
use lib "/opt/vyatta/share/perl5/";
use Vyatta::Config;
use Vyatta::Misc;
+use NetAddr::IP;
use Getopt::Long;
use File::Copy;
@@ -40,6 +41,7 @@ my $snmp_tmp = "/tmp/snmpd.conf.$$";
my $snmp_snmpv3_user_conf = '/usr/share/snmp/snmpd.conf';
my $snmp_snmpv3_createuser_conf = '/var/lib/snmp/snmpd.conf';
my $versionfile = '/opt/vyatta/etc/version';
+my $local_agent = 'unix:/var/run/snmpd.socket';
my $snmp_level = 'service snmp';
@@ -60,7 +62,7 @@ sub snmp_start {
snmp_get_values();
close $fh;
select STDOUT;
-
+
snmp_client_config();
move($snmp_tmp, $snmp_conf)
@@ -85,14 +87,60 @@ sub get_version {
return $version;
}
+# convert address to snmpd transport syntax
+sub transport_syntax {
+ my ($addr, $port) = @_;
+ my $ip = new NetAddr::IP $addr;
+ die "$addr: not a valid IP address" unless $ip;
+
+ my $version = $ip->version();
+ return "udp:$addr:$port" if ($version == 4);
+ return "udp6:[$addr]:$port" if ($version == 6);
+ die "$addr: unknown IP version $version";
+}
+
+sub ipv6_disabled {
+ my $config = new Vyatta::Config;
+ return $config->exists("system ipv6 disable");
+}
+
+# Find SNMP agent listening addresses
+sub get_listen_address {
+ my $config = new Vyatta::Config;
+ my @listen;
+
+ $config->setLevel('service snmp listen-address');
+ my @address = $config->listNodes();
+
+ if(@address) {
+ foreach my $addr (@address) {
+ my $port = $config->returnValue("$addr port");
+ push @listen, transport_syntax($addr, $port);
+ }
+ } else {
+ # default if no address specified
+ @listen = ( 'udp:161' );
+ push @listen, 'udp6:161' unless ipv6_disabled();
+ return @listen;
+ }
+
+ return @listen;
+}
+
sub snmp_get_constants {
my $version = get_version();
my $now = localtime;
+ my @addr = get_listen_address();
+
+ # add local unix domain target for use by operational commands
+ unshift @addr, $local_agent;
print "# autogenerated by vyatta-snmp.pl on $now\n";
print "sysDescr Vyatta $version\n";
print "sysObjectID 1.3.6.1.4.1.30803\n";
print "sysServices 14\n";
+ print "agentaddress ", join(',',@addr), "\n";
+
print "smuxpeer .1.3.6.1.4.1.3317.1.2.2\n"; # ospfd
print "smuxpeer .1.3.6.1.4.1.3317.1.2.5\n"; # bgpd
print "smuxpeer .1.3.6.1.4.1.3317.1.2.3\n"; # ripd
@@ -106,44 +154,43 @@ sub randhex {
return join "", map { unpack "H*", chr(rand(256)) } 1..($length/2);
}
+# output snmpd.conf file syntax for community
+sub print_community {
+ my ($config, $community) = @_;
+ my $ro = $config->returnValue('authorization');
+ $ro = 'ro' unless $ro;
+
+ my @clients = $config->returnValues('client');
+ my @networks = $config->returnValues('network');
+
+ my @restriction = (@clients, @networks);
+ if (!@restriction) {
+ print $ro . "community $community\n";
+ print $ro . "community6 $community\n" unless ipv6_disabled();
+ return;
+ }
+
+ foreach my $addr (@restriction) {
+ my $ip = new NetAddr::IP $addr;
+ die "$addr: Not a valid IP address" unless $ip;
+
+ if ($ip->version() == 4) {
+ print $ro . "community $community $addr\n";
+ } elsif ($ip->version() == 6) {
+ print $ro . "community6 $community $addr\n";
+ } else {
+ die "$addr: bad IP version ", $ip->version();
+ }
+ }
+}
+
sub snmp_get_values {
my $config = new Vyatta::Config;
- $config->setLevel("service snmp community");
- my @communities = $config->listNodes();
-
+ my @communities = $config->listNodes("service snmp community");
foreach my $community (@communities) {
- my $authorization = $config->returnValue("$community authorization");
- my @clients = $config->returnValues("$community client");
- my @networks = $config->returnValues("$community network");
-
- if (scalar(@clients) == 0 and scalar(@networks) == 0){
- if (defined $authorization and $authorization eq "rw") {
- print "rwcommunity $community\n";
- } else {
- print "rocommunity $community\n";
- }
- } else {
- if (scalar(@clients) != 0) {
- foreach my $client (@clients){
- if (defined $authorization and $authorization eq "rw") {
- print "rwcommunity $community $client\n";
- } else {
- print "rocommunity $community $client\n";
- }
- }
- }
- if (scalar(@networks) != 0){
- foreach my $network (@networks){
- if (defined $authorization and $authorization eq "rw") {
- print "rwcommunity $community $network\n";
- } else {
- print "rocommunity $community $network\n";
- }
-
- }
- }
- }
+ $config->setLevel("service snmp community $community");
+ print_community($config, $community);
}
$config->setLevel($snmp_level);
diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl
index 7f2b84b2..a4e2b9ba 100755
--- a/scripts/system/vyatta_update_resolv.pl
+++ b/scripts/system/vyatta_update_resolv.pl
@@ -134,10 +134,11 @@ if ($dhclient_script == 1) {
}
}
if ($ns_in_resolvconf == 0) {
- open (APPEND, ">>/etc/resolv.conf") or die "$! error trying to overwrite";
- print APPEND "nameserver\t$ns\t\t#nameserver written by $0\n";
- close (APPEND);
- $restart_ntp = 1;
+ open (my $rf, '>>', '/etc/resolv.conf')
+ or die "$! error trying to overwrite";
+ print $rf "nameserver\t$ns\t\t#nameserver written by $0\n";
+ close $rf;
+ $restart_ntp = 1;
}
}
}
@@ -190,37 +191,40 @@ if ($dhclient_script == 1) {
my @resolv;
if (-e '/etc/resolv.conf') {
- open (RESOLV, '</etc/resolv.conf') or die("$0: Error! Unable to open '/etc/resolv.conf' for input: $!\n");
- @resolv = <RESOLV>;
- close (RESOLV);
+ open (my $f, '<', '/etc/resolv.conf')
+ or die("$0: Error! Unable to open '/etc/resolv.conf' for input: $!\n");
+ @resolv = <$f>;
+ close ($f);
}
my $foundSearch = 0;
my $foundDomain = 0;
-open (RESOLV, '>/etc/resolv.conf') or die("$0: Error! Unable to open '/etc/resolv.conf' for output: $!\n");
+open (my $r, '>', '/etc/resolv.conf')
+ or die("$0: Error! Unable to open '/etc/resolv.conf' for output: $!\n");
+
foreach my $line (@resolv) {
if ($line =~ /^search\s/) {
$foundSearch = 1;
if (length($search) > 0) {
- print RESOLV $search;
+ print $r $search;
}
} elsif ($line =~ /^domain\s/) {
$foundDomain = 1;
if (length($domain) > 0) {
- print RESOLV $domain;
+ print $r $domain;
}
} else {
- print RESOLV $line;
+ print $r $line;
}
}
if ($foundSearch == 0 && length($search) > 0) {
- print RESOLV $search;
+ print $r $search;
}
if ($foundDomain == 0 && length($domain) > 0) {
- print RESOLV $domain;
+ print $r $domain;
}
-close (RESOLV);
+close ($r);
diff --git a/scripts/vyatta-dhcpv6-client.pl b/scripts/vyatta-dhcpv6-client.pl
new file mode 100644
index 00000000..b23d1700
--- /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 90d8dfc7..a303c82c 100755
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -47,10 +47,11 @@ use warnings;
my $dhcp_daemon = '/sbin/dhclient';
-my ($eth_update, $eth_delete, $addr_set, @addr_commit, $dev, $mac, $mac_update);
+my ($eth_update, $eth_delete, $addr_set, $dev, $mac, $mac_update);
+my %skip_interface;
my ($check_name, $show_names, $intf_cli_path, $vif_name, $warn_name);
my ($check_up, $show_path, $dhcp_command);
-my @speed_duplex;
+my (@speed_duplex, @addr_commit);
sub usage {
print <<EOF;
@@ -80,6 +81,7 @@ GetOptions("eth-addr-update=s" => \$eth_update,
"dhcp=s" => \$dhcp_command,
"check=s" => \$check_name,
"show=s" => \$show_names,
+ "skip=s" => sub { $skip_interface{$_[1]} = 1 },
"vif=s" => \$vif_name,
"warn" => \$warn_name,
"path" => \$show_path,
@@ -312,14 +314,14 @@ sub update_mac {
if (POSIX::strtoul($flags) & 1) {
# NB: Perl 5 system return value is bass-ackwards
- system "sudo ip link set $intf down"
+ system "ip link set $intf down"
and die "Could not set $intf down ($!)\n";
- system "sudo ip link set $intf address $mac"
+ system "ip link set $intf address $mac"
and die "Could not set $intf address ($!)\n";
- system "sudo ip link set $intf up"
+ system "ip link set $intf up"
and die "Could not set $intf up ($!)\n";
} else {
- system "sudo ip link set $intf address $mac"
+ system "ip link set $intf address $mac"
and die "Could not set $intf address ($!)\n";
}
exit 0;
@@ -356,6 +358,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 +432,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;
}
}
@@ -516,6 +525,7 @@ sub show_interfaces {
foreach my $name (@interfaces) {
my $intf = new Vyatta::Interface($name);
next unless $intf; # skip unknown types
+ next if $skip_interface{$name};
next unless ($type eq 'all' || $type eq $intf->type());
if ($vif_name) {