diff options
39 files changed, 897 insertions, 246 deletions
@@ -10,7 +10,6 @@ libtool /aclocal.m4 /autom4te.cache /build-stamp -/ChangeLog /config /config.log /config.guess @@ -21,6 +20,7 @@ libtool /debian/vyatta-cfg /debian/vyatta-cfg.postinst /debian/vyatta-cfg.postrm +/debian/vyatta-cfg.debhelper.log /INSTALL /Makefile.in /Makefile diff --git a/ChangeLog b/ChangeLog new file mode 120000 index 0000000..d526672 --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ +debian/changelog
\ No newline at end of file diff --git a/Makefile.am b/Makefile.am index a309d34..7de4e17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,6 +35,7 @@ sbin_SCRIPTS = scripts/vyatta-cfg-cmd-wrapper sbin_SCRIPTS += scripts/vyatta-validate-type.pl sbin_SCRIPTS += scripts/vyatta-find-type.pl sbin_SCRIPTS += scripts/vyatta-config-loader.pl +sbin_SCRIPTS += scripts/vyatta-config-gen-sets.pl sbin_SCRIPTS += scripts/vyatta-cli-expand-var.pl sbin_SCRIPTS += scripts/vyatta-output-config.pl sbin_SCRIPTS += scripts/vyatta-save-config.pl diff --git a/debian/autogen.sh b/debian/autogen.sh index ff125d1..e8c94af 100755 --- a/debian/autogen.sh +++ b/debian/autogen.sh @@ -1,32 +1,6 @@ #!/bin/sh -if [ -d .git ] ; then -# generate GNU/Debian format ChangeLog from git log - - rm -f ChangeLog - - if which git2cl >/dev/null ; then - git-log --pretty --numstat --summary | git2cl >> ChangeLog - else - git-log --pretty=short >> ChangeLog - fi - -# append repository reference - - url=` git repo-config --get remote.origin.url` - test "x$url" = "x" && url=`pwd` - - branch=`git-branch --no-color | sed '/^\* /!d; s/^\* //'` - test "x$branch" = "x" && branch=master - - sha=`git log --pretty=oneline --no-color -n 1 | cut -c-8` - test "x$sha" = "x" && sha=00000000 - - echo "$url#$branch-$sha" >> ChangeLog - -fi - rm -rf config rm -f aclocal.m4 config.guess config.statusconfig.sub configure INSTALL diff --git a/debian/changelog b/debian/changelog index 734169c..856faaf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,110 @@ +vyatta-cfg (0.10) unstable; urgency=low + + 3.1.0 + [ Mark O'Brien ] + + + [ Stig Thormodsrud ] + * Block reboot from config mode. + * Add exception for /31 and /32 for ipv4 and /128 for ipv6 + * Fix 920: System allows configuration of invalid IP Address for + subnet + + [ rbalocca ] + * Ignore log file + * Fix for bug #3274 https://bugzilla.vyatta.com/show_bug.cgi?id=3274 + + [ Stig Thormodsrud ] + * Force "protocols ospf parameters" to be committed before other ospf + config. + + [ Stephen Hemminger ] + * Avoid any problems with non-device entries in /sys/class/net + * Remove unused dependencies + + [ Stig Thormodsrud ] + * Fix vlan regex. + + [ An-Cheng Huang ] + * fix for bug 3239: now support regex-based ordering for startup + config + + [ Stig Thormodsrud ] + * Add more granularity to config rank (commit rip, ospf, bgp + separately). + + [ rbalocca ] + * Fix problem with Default-Stop + * Convert to our method of changelog creation + + [ Stig Thormodsrud ] + * Only check for dhcp client on eth, vlan, and bridge. + * Fix 3233 dhcp client doesn't work on bridge interface + + [ An-Cheng Huang ] + * support "wildcard" ranking at boot time. only VRRP uses this for + now. + * partial fix for bug 3216: display escaped edit path correctly. + + [ Michael Larson ] + * fix for show -all. note there is a change in how config files are + saved--only set values are now save as opposed to set + + [ rbalocca ] + * Add parted debian package for install-system use + + [ Michael Larson ] + * backing out show cmd change for now on existence of def + * final checkin as fix for bug 1219. + * mask out def markers in config script + * create def file to mark configuration nodes that are created by + default, rather than a node with a default value created by a + * modified fix for 2525--fixes problem introduced with last fix (bug + 3163) + * revert fix for 2525 until delete on commit warnings are resolved. + * reverse sort order on delete + * modified node ordering code. + * partial revert of priority support--will reapply after additional + changes. + * temp removal of free--possible corruption. + * support for node priority. higher value in node.def is higher + priority. + + [ Mohit Mehta ] + * Fix Bug 3069 Help strings should be standardized + + [ An-Cheng Huang ] + * partial fix for bug 2181: add new template field "priority". + + [ Michael Larson ] + * alternate fix for 2525--force directory evaluation upstream. + * Revert "fix for bug 2525" + + [ Mohit Mehta ] + * Fix Bug 3069 Help strings should be standardized + + [ Michael Larson ] + * fix for bug 2525 + * fix for bug 2549. + * fix for bug 2507 + + [ An-Cheng Huang ] + * fix for bug 2689: sort tag nodes appropriately + + [ Mohit Mehta ] + * Fix Bug 2825 Load should read config file from default location when + no argument is provided. + + [ Stig Thormodsrud ] + * Add vlan dependancy for vyatta-cfg. + + [ rbalocca ] + * Fix a changelog problem + + [ Mark O'Brien ] + + -- Mark O'Brien <mobrien@firebolt.vyatta.com> Tue, 17 Jun 2008 09:26:38 -0700 + vyatta-cfg (0.9) unstable; urgency=low 3.0.5 diff --git a/debian/control b/debian/control index 2fdbcfe..c469fb8 100644 --- a/debian/control +++ b/debian/control @@ -15,6 +15,8 @@ Depends: sed (>= 4.1.5), vyatta-quagga | quagga, vyatta-op, vyatta-config-migrate, + vyatta-cfg-system, + parted, dhcp3-client | vyatta-dhcp3-client, bsdutils (>=1:2.13), libc6 (>= 2.7-6), diff --git a/etc/bash_completion.d/20vyatta-cfg b/etc/bash_completion.d/20vyatta-cfg index f979939..f1d100e 100755 --- a/etc/bash_completion.d/20vyatta-cfg +++ b/etc/bash_completion.d/20vyatta-cfg @@ -66,10 +66,38 @@ save () \"umask 0002 ; ${vyatta_sbindir}/vyatta-save-config.pl $@\"" } +discard () +{ + local changes + if [ -f "$VYATTA_TEMP_CONFIG_DIR/$VYATTA_MOD_NAME" ]; then + changes=1 + else + changes=0 + fi + + sudo umount ${VYATTA_TEMP_CONFIG_DIR}; + sudo rm -fr ${VYATTA_CHANGES_ONLY_DIR}; + sudo mkdir -p ${VYATTA_CHANGES_ONLY_DIR}; + sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro unionfs ${VYATTA_TEMP_CONFIG_DIR}; + + if (( changes )); then + echo "Changes have been discarded" + else + echo "No changes have been discarded" + fi + +} + +reboot () +{ + echo "Exit from configure mode before rebooting." +} + declare vyatta_cfg_prompt_level='' set_config_ps1 () { local level=$1 + vyatta_unescape level level if [ -z "$level" ]; then export PS1="[edit]\n\u@\h# " vyatta_cfg_prompt_level='' @@ -107,6 +135,66 @@ top () set_config_ps1 '' } +rename() +{ + mvcp rename Rename mv "$@" +} + +copy() +{ + mvcp copy Copy "cp -a" "$@" +} + +mvcp () +{ + local str=$1 + shift + local Str=$1 + shift + local cmd=$1 + shift + local _otag=$1 + local _ovalu=$2 + local _to=$3 + local _ntag=$4 + local _nvalu=$5 + local _oval='' + local _nval='' + local _mpath=${VYATTA_TEMP_CONFIG_DIR}/${VYATTA_EDIT_LEVEL} + local _tpath=${VYATTA_CONFIG_TEMPLATE}/${VYATTA_TEMPLATE_LEVEL} + vyatta_escape _ovalu _oval + vyatta_escape _nvalu _nval + if [ "$_to" != 'to' ] || [ -z "$_ntag" ] || [ -z "$_nval" ]; then + echo "Invalid $str command" + return 1 + fi + if [ "$_otag" != "$_ntag" ]; then + echo "Cannot $str from \"$_otag\" to \"$_ntag\"" + return 1 + fi + if [ ! -d "$_tpath/$_otag/$VYATTA_TAG_NAME" ]; then + echo "Cannot $str under \"$_otag\"" + return 1 + fi + if [ ! -d "$_mpath/$_otag/$_oval" ]; then + echo "Configuration \"$_otag $_ovalu\" does not exist" + return 1 + fi + if [ -d "$_mpath/$_ntag/$_nval" ]; then + echo "Configuration \"$_ntag $_nvalu\" already exists" + return 1 + fi + if ! /opt/vyatta/sbin/my_set $_ntag "$_nvalu"; then + echo "$Str failed" + return 1 + fi + /opt/vyatta/sbin/my_delete $_ntag "$_nvalu" >&/dev/null 3>&1 + + $cmd "$_mpath/$_otag/$_oval" "$_mpath/$_ntag/$_nval" + + return 0 +} + edit () { local num_comp=${#@} @@ -726,6 +814,7 @@ vyatta_config_complete () if (( ${#COMP_WORDS[@]} < 2 )); then declare -a hitems=( "commit" \ "delete" \ + "discard" \ "edit" \ "exit" \ "load" \ @@ -736,6 +825,7 @@ vyatta_config_complete () declare -a hstrs=( \ "Commit the current set of changes" \ "Delete a configuration element" \ + "Discard uncommitted changes" \ "Edit a sub-element" \ "Exit from this configuration level" \ "Load configuration from a file" \ diff --git a/etc/init.d/vyatta-ofr b/etc/init.d/vyatta-ofr index 776aaf4..104903e 100755 --- a/etc/init.d/vyatta-ofr +++ b/etc/init.d/vyatta-ofr @@ -4,7 +4,7 @@ # Required-Start: $syslog $time $local_fs # Required-Stop: $syslog $time $local_fs # Default-Start: 2 3 4 5 -# Default-Stop: S 0 1 6 +# Default-Stop: 0 1 6 # Short-Description: Vyatta Router # Description: Debian init script for the Vyatta Router ### END INIT INFO @@ -117,6 +117,7 @@ start () ${vyatta_sbindir}/${s}.init start || (log_end_msg $? && return) done load_bootfile + chmod g-w,o-w / log_end_msg $? } diff --git a/etc/shell/level/users/allowed-op b/etc/shell/level/users/allowed-op index 724c235..c387a99 100644 --- a/etc/shell/level/users/allowed-op +++ b/etc/shell/level/users/allowed-op @@ -1,12 +1,18 @@ clear +connect debug +delete +disconnect exit no ping reboot +release +renew set show telnet +terminal traceroute undebug vpn diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index b69723a..f1339c3 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -23,49 +23,56 @@ package VyattaConfigLoad; use strict; use sort 'stable'; use lib "/opt/vyatta/share/perl5/"; -use XorpConfigParser; +use XorpConfigParser; use VyattaConfig; # configuration ordering. higher rank configured before lower rank. my $default_rank = 0; my %config_rank = ( - 'qos-policy' => 110, - 'firewall' => 102, - 'service nat' => 101, - 'interfaces' => 100, - 'interfaces bridge' => 99, - 'interfaces ethernet' => 98, - 'interfaces tunnel' => 91, - 'system' => 90, - 'protocols static' => 85, - 'service ssh' => 84, - 'service telnet' => 83, - 'policy' => 82, - 'vpn' => 80, + 'qos-policy' => 1100, + 'firewall' => 1020, + 'service nat' => 1010, + 'interfaces' => 1000, + 'interfaces bridge' => 990, + 'interfaces ethernet' => 980, + 'interfaces tunnel' => 910, + 'system gateway-address' => 890, + 'system name-server' => 880, + 'system login user' => 870, + 'system' => 860, + 'protocols static' => 850, + 'service ssh' => 840, + 'service telnet' => 830, + 'policy' => 820, + 'protocols bgp' => 790, + 'protocols ospf parameters' => 785, + 'protocols ospf' => 780, + 'protocols rip' => 770, + 'vpn' => 600, + ); -my %wildcard_rank = ( - 'interfaces ethernet * vrrp' => 50, - 'interfaces ethernet * vif * vrrp' => 50, +my %regex_rank = ( + 'interfaces ethernet \S* vrrp' => 500, + 'interfaces ethernet \S* vif \S* vrrp' => 500, + 'protocols bgp \d+ parameters' => 810, + 'protocols bgp \d+ neighbor \S*[^\d.]\S*' => 800, ); my @all_nodes = (); my @all_naked_nodes = (); -# the wildcard matching could use some serious optimization. but probably -# not when we only have a couple of entries. -sub match_wildcard { +sub match_regex { my ($pattern, $str) = @_; - $pattern =~ s/\*/\\S*/g; $pattern =~ s/^(.*)$/\^$1\$/; return ($str =~ m/$pattern/) ? 1 : 0; } -sub get_wildcard_rank { +sub get_regex_rank { my ($str) = @_; - foreach (keys %wildcard_rank) { - if (match_wildcard($_, $str)) { - return $wildcard_rank{$_}; + foreach (keys %regex_rank) { + if (match_regex($_, $str)) { + return $regex_rank{$_}; } } return undef; @@ -79,7 +86,7 @@ sub get_config_rank { if (defined($config_rank{$path_str})) { return ($config_rank{$path_str}); } - my $wrank = get_wildcard_rank($path_str); + my $wrank = get_regex_rank($path_str); return $wrank if (defined($wrank)); pop @path; } @@ -289,6 +296,9 @@ sub findDeletedNodes { $active_cfg->setLevel(join ' ', @active_path); my @active_nodes = $active_cfg->listOrigNodes(); foreach (@active_nodes) { + if ($_ eq 'def') { + next; + } if ($_ eq 'node.val') { findDeletedValues($new_ref, \@active_path); next; diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index 2766b64..5358c21 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -133,8 +133,12 @@ sub displayValues { $nval = "\"$nval\""; } } + + my %cnodes = $config->listNodeStatus(); + my @cnames = sort keys %cnodes; + if (defined($simple_show)) { - if (!defined($default) || $default ne $oval || $show_all) { + if (!$cnodes{'def'} || $show_all) { if ($is_password && $hide_password) { $oval = $HIDE_PASSWORD; } @@ -155,7 +159,7 @@ sub displayValues { $diff = '>'; } } - if (!defined($default) || $default ne $value || $show_all) { + if (!$cnodes{'def'} || $show_all) { if ($is_password && $hide_password) { $value = $HIDE_PASSWORD; } @@ -186,9 +190,12 @@ sub displayDeletedOrigChildren { my $is_tag = $config->isTagNode([ @cur_path, $child ]); $config->setLevel(join ' ', (@cur_path, $child)); my @cnames = sort $config->listOrigNodes(); - if ($#cnames == 0 && $cnames[0] eq 'node.val') { + + if ($cnames[0] eq 'node.val') { displayValues([ @cur_path, $child ], $prefix, $child, $dont_show_as_deleted); + } elsif ($cnames[0] eq 'def') { + #ignore } elsif (scalar($#cnames) >= 0) { if ($is_tag) { @cnames = sort versioncmp @cnames; @@ -242,7 +249,20 @@ sub displayChildren { $config->setLevel(join ' ', (@cur_path, $child)); my %cnodes = $config->listNodeStatus(); my @cnames = sort keys %cnodes; - if ($#cnames == 0 && $cnames[0] eq 'node.val') { + + #if node.val exists and ct == 0 w/o def or ct ==1 w/ def + my $leaf = 0; + if ($cnodes{'def'}) { + if ($#cnames == 1 && $cnodes{'node.val'}) { + $leaf = 1; + } + } else { + if ($#cnames == 0 && $cnodes{'node.val'}) { + $leaf = 1; + } + } + + if ($leaf == 1) { displayValues([ @cur_path, $child ], $prefix, $child); } elsif (scalar($#cnames) >= 0) { if ($is_tag) { @@ -309,7 +329,20 @@ sub outputNewConfig { my %rnodes = $config->listNodeStatus(); if (scalar(keys %rnodes) > 0) { my @rn = keys %rnodes; - if ($#rn == 0 && $rn[0] eq 'node.val') { + + #if node.val exists and ct == 0 w/o def or ct ==1 w/ def + my $leaf = 0; + if ($rnodes{'def'}) { + if ($#rn == 1 && $rnodes{'node.val'}) { + $leaf = 1; + } + } else { + if ($#rn == 0 && $rnodes{'node.val'}) { + $leaf = 1; + } + } + + if ($leaf == 1) { # this is a leaf value-node displayValues([ @_ ], '', $_[$#_]); } else { diff --git a/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl new file mode 100644 index 0000000..b9b083e --- /dev/null +++ b/scripts/vyatta-config-gen-sets.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +# Author: An-Cheng Huang <ancheng@vyatta.com> +# Date: 2007 +# Description: hack of vyatta-config-load.pl to simple generate +# a list of the "set" commands from a config file. + +# **** 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) 2006, 2007, 2008 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +# Perl script for loading the startup config file. +# $0: startup config file. + +use strict; +use lib "/opt/vyatta/share/perl5/"; +use VyattaConfigLoad; + +my $conf_file = '/opt/vyatta/etc/config/config.boot'; + +$conf_file = $ARGV[0] if defined $ARGV[0]; + +# get a list of all config statement in the startup config file +# (sorted by rank). +my @all_nodes = VyattaConfigLoad::getStartupConfigStatements($conf_file); +if (scalar(@all_nodes) == 0) { + # no config statements + exit 1; +} +my $cur_rank = ${$all_nodes[0]}[1]; + +my $ret = 0; +# higher-ranked statements committed before lower-ranked. +foreach (@all_nodes) { + my ($path_ref, $rank) = @$_; + if ($rank != $cur_rank) { + # commit all nodes with the same rank together. + print "commit\n"; + $cur_rank = $rank; + } + my $cmd = "set " . (join ' ', @$path_ref); + print "$cmd\n"; +} +print "commit\n"; + +exit 0; + diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index aa82b78..1511c12 100755..100644 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -37,26 +37,23 @@ use VyattaMisc; use Getopt::Long; use POSIX; use NetAddr::IP; -use Tie::File; -use Fcntl qw (:flock); use strict; use warnings; my $dhcp_daemon = '/sbin/dhclient'; -my $dhcp_conf = '/etc/dhcp3/dhclient.conf'; -my $dhcp_pid = '/var/run/dhclient.pid'; -my $dhcp_leases = '/var/lib/dhcp3/dhclient.leases'; +my $dhclient_dir = '/var/lib/dhcp3/'; -my ($eth_update, $eth_delete, $addr, $restart_dhclient, $dev, $mac, $mac_update); + +my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient); GetOptions("eth-addr-update=s" => \$eth_update, "eth-addr-delete=s" => \$eth_delete, "valid-addr=s" => \$addr, - "restart-dhclient!" => \$restart_dhclient, "dev=s" => \$dev, "valid-mac=s" => \$mac, "set-mac=s" => \$mac_update, + "op-command=s" => \$op_dhclient, ); if (defined $eth_update) { update_eth_addrs($eth_update, $dev); } @@ -64,7 +61,7 @@ if (defined $eth_delete) { delete_eth_addrs($eth_delete, $dev); } if (defined $addr) { is_valid_addr($addr, $dev); } if (defined $mac) { is_valid_mac($mac, $dev); } if (defined $mac_update) { update_mac($mac_update, $dev); } -if (defined $restart_dhclient) { dhcp_restart_daemon(); } +if (defined $op_dhclient) { op_dhcp_command($op_dhclient, $dev); } sub is_ip_configured { my ($intf, $ip) = @_; @@ -99,54 +96,6 @@ sub is_ip_duplicate { } } -sub is_dhcp_running { - if (-f $dhcp_pid) { - my $pid = `cat $dhcp_pid`; - chomp $pid; - my $ps = `ps -p $pid -o comm=`; - - if (defined($ps) && $ps ne "") { - return 1; - } - } - return 0; -} - -sub dhcp_start_daemon { - my $cmd = "$dhcp_daemon -q -nw &"; - system($cmd); -} - -sub dhcp_stop_daemon { - if (is_dhcp_running()) { - my $pid = `cat $dhcp_pid`; - system("kill $pid"); - } - system("rm -f $dhcp_pid"); -} - -sub dhcp_restart_daemon { - # - # check if vyatta has generated the config file, otherwise - # an empty config will try to get new addresses for all - # interfaces - # - my $grep = `grep vyatta-interfaces.pl $dhcp_conf | wc -l`; - chomp $grep; - if (!defined $grep or $grep != 1) { - die "DHCP client not configured\n"; - } - if (is_dhcp_running()) { - dhcp_stop_daemon(); - } - dhcp_start_daemon(); -} - -sub dhcp_release_addr { - my $intf = shift; - my $cmd = "$dhcp_daemon -q -r $intf 2> /dev/null"; - system($cmd); -} sub dhcp_write_file { my ($file, $data) = @_; @@ -168,47 +117,25 @@ sub dhcp_conf_header { return $output; } -sub dhcp_get_interfaces { - my @dhcp_intfs; - - my $config = new VyattaConfig; - - $config->setLevel("interfaces ethernet"); - my @eths = $config->listNodes(); - foreach my $eth (@eths) { - $config->setLevel("interfaces ethernet $eth"); - if ($config->exists("address")) { - my @addrs = $config->returnValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - push @dhcp_intfs, $eth; - } - } - } - $config->setLevel("interfaces ethernet $eth vif"); - my @vifs = $config->listNodes(); - foreach my $vif (@vifs) { - $config->setLevel("interfaces ethernet $eth vif $vif"); - my @addrs = $config->returnValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - push @dhcp_intfs, "$eth.$vif"; - } - } - } - } - return @dhcp_intfs; -} - sub is_dhcp_enabled { my $intf = shift; my $config = new VyattaConfig; - if ($intf =~ m/(\w+)\.(\d)/) { - $config->setLevel("interfaces ethernet $1 vif $2"); + if ($intf =~ m/^eth/) { + if ($intf =~ m/(\w+)\.(\d+)/) { + $config->setLevel("interfaces ethernet $1 vif $2"); + } else { + $config->setLevel("interfaces ethernet $intf"); + } + } elsif ($intf =~ m/^br/) { + $config->setLevel("interfaces bridge $intf"); } else { - $config->setLevel("interfaces ethernet $intf"); + # + # currently we only support dhcp on ethernet + # and bridge interfaces. + # + return 0; } my @addrs = $config->returnOrigValues("address"); foreach my $addr (@addrs) { @@ -223,11 +150,18 @@ sub is_address_enabled { my $intf = shift; my $config = new VyattaConfig; - - if ($intf =~ m/(\w+)\.(\d)/) { - $config->setLevel("interfaces ethernet $1 vif $2"); + + if ($intf =~ m/^eth/) { + if ($intf =~ m/(\w+)\.(\d+)/) { + $config->setLevel("interfaces ethernet $1 vif $2"); + } else { + $config->setLevel("interfaces ethernet $intf"); + } + } elsif ($intf =~ m/^br/) { + $config->setLevel("interfaces bridge $intf"); } else { - $config->setLevel("interfaces ethernet $intf"); + print "unsupported dhcp interface [$intf]\n"; + exit 1; } my @addrs = $config->returnOrigValues("address"); foreach my $addr (@addrs) { @@ -246,34 +180,18 @@ sub get_hostname { } sub dhcp_update_config { + my ($conf_file, $intf) = @_; + my $output = dhcp_conf_header(); my $hostname = get_hostname(); - my $config = new VyattaConfig; - my $dhcp_instances = 0; - my @dhcp_intfs = dhcp_get_interfaces(); - foreach my $intf (@dhcp_intfs) { - $output .= "interface \"$intf\" {\n"; - if (defined($hostname)) { - $output .= "\tsend host-name \"$hostname\";\n"; - } - $output .= "}\n\n"; - $dhcp_instances++; + $output .= "interface \"$intf\" {\n"; + if (defined($hostname)) { + $output .= "\tsend host-name \"$hostname\";\n"; } + $output .= "}\n\n"; - if ($dhcp_instances > 0) { - my $conf_file = $dhcp_conf; - dhcp_write_file($conf_file, $output); - dhcp_restart_daemon(); - } - return $dhcp_instances; -} - -sub update_dhcp_client { - my $dhcp_instances = dhcp_update_config(); - if ($dhcp_instances == 0) { - dhcp_stop_daemon(); - } + dhcp_write_file($conf_file, $output); } sub is_ip_v4_or_v6 { @@ -299,11 +217,42 @@ sub is_ip_v4_or_v6 { return undef; } +sub generate_dhclient_intf_files { + my $intf = shift; + + $intf =~ s/\./_/g; + my $intf_config_file = $dhclient_dir . 'dhclient_' . $intf . '.conf'; + my $intf_process_id_file = $dhclient_dir . 'dhclient_' . $intf . '.pid'; + my $intf_leases_file = $dhclient_dir . 'dhclient_' . $intf . '.leases'; + return ($intf_config_file, $intf_process_id_file, $intf_leases_file); + +} + +sub run_dhclient { + my $intf = shift; + + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + dhcp_update_config($intf_config_file, $intf); + my $cmd = "$dhcp_daemon -q -nw -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file $intf 2> /dev/null &"; + # adding & at the end to make the process into a daemon immediately + system ($cmd); +} + +sub stop_dhclient { + my $intf = shift; + + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + my $cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; + system ($cmd); + system ("rm -f $intf_config_file"); +} + sub update_eth_addrs { my ($addr, $intf) = @_; if ($addr eq "dhcp") { - update_dhcp_client(); + run_dhclient($intf); + system ("touch /var/lib/dhcp3/$intf\;"); return; } my $version = is_ip_v4_or_v6($addr); @@ -348,9 +297,8 @@ sub delete_eth_addrs { my ($addr, $intf) = @_; if ($addr eq "dhcp") { - dhcp_release_addr($intf); - update_dhcp_client(); - system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease"); + stop_dhclient($intf); + system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease; rm -f /var/lib/dhcp3/$intf\; rm -f /var/lib/dhcp3/release_$intf\;"); exit 0; } my $version = is_ip_v4_or_v6($addr); @@ -442,6 +390,28 @@ sub is_valid_addr { exit 1; } + my $ip = NetAddr::IP->new($addr_net); + my $network = $ip->network(); + my $bcast = $ip->broadcast(); + + if ($ip->version == 4 and $ip->masklen() == 31) { + # + # RFC3021 allows for /31 to treat both address as host addresses + # + } elsif ($ip->masklen() != $ip->bits()) { + # + # allow /32 for ivp4 and /128 for ipv6 + # + if ($ip->addr() eq $network->addr()) { + print "Can not assign network address as the IP address\n"; + exit 1; + } + if ($ip->addr() eq $bcast->addr()) { + print "Can not assign broadcast address as the IP address\n"; + exit 1; + } + } + if (is_dhcp_enabled($intf)) { print "Error: remove dhcp before adding static addresses for $intf\n"; exit 1; @@ -465,6 +435,36 @@ sub is_valid_addr { exit 1; } +sub op_dhcp_command { + my ($op_command, $intf) = @_; + + if (!is_dhcp_enabled($intf)) { + print "$intf is not using DHCP to get an IP address\n"; + exit 1; + } + + my $release_file = $dhclient_dir . 'release_' . $intf; + if ($op_command eq "dhcp-release") { + if (-e $release_file) { + print "IP address for $intf has already been released.\n"; + exit 1; + } else { + print "Releasing DHCP lease on $intf ...\n"; + stop_dhclient($intf); + system ("touch $release_file\;"); + exit 0; + } + } elsif ($op_command eq "dhcp-renew") { + print "Renewing DHCP lease on $intf ...\n"; + run_dhclient($intf); + system ("rm -f $release_file\;"); + exit 0; + } + + exit 0; + +} + exit 0; # end of file diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 05323e3..29d4dec 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -28,21 +28,84 @@ use VyattaConfigLoad; my $etcdir = $ENV{vyatta_sysconfdir}; my $sbindir = $ENV{vyatta_sbindir}; my $bootpath = $etcdir . "/config"; +my $load_file = $bootpath . "/config.boot"; +my $url_tmp_file = $bootpath . "/config.boot.$$"; -if ($#ARGV != 0) { +if ($#ARGV > 0) { print "Usage: load <config_file_name>\n"; exit 1; } -my $load_file = $ARGV[0]; -if (!($load_file =~ /^\//)) { +my $mode = 'local'; +my $proto; + +if (defined($ARGV[0])) { + $load_file = $ARGV[0]; +} + +if ($load_file =~ /^[^\/]\w+:\//) { + if ($load_file =~ /^(\w+):\/\/\w/) { + $mode = 'url'; + $proto = lc($1); + if ($proto eq 'tftp') { + } elsif ($proto eq 'ftp') { + } elsif ($proto eq 'http') { + } elsif ($proto eq 'scp') { + } else { + print "Invalid url protocol [$proto]\n"; + exit 1; + } + } else { + print "Invalid url [$load_file]\n"; + exit 1; + } +} + +if ($mode eq 'local' and !($load_file =~ /^\//)) { # relative path $load_file = "$bootpath/$load_file"; } -if (!open(CFG, "<$load_file")) { - print "Cannot open configuration file $load_file\n"; - exit 1; +if ($mode eq 'local') { + if (!open(CFG, "<$load_file")) { + print "Cannot open configuration file $load_file\n"; + exit 1; + } +} elsif ($mode eq 'url') { + if (! -f '/usr/bin/curl') { + print "Package [curl] not installed\n"; + exit 1; + } + if ($proto eq 'http') { + # + # error codes are send back in html, so 1st try a header + # and look for "HTTP/1.1 200 OK" + # + my $rc = `curl -q -I $load_file 2>&1`; + if ($rc =~ /HTTP\/\d+\.?\d\s+(\d+)\s+(.*)$/mi) { + my $rc_code = $1; + my $rc_string = $2; + if ($rc_code == 200) { + # good resonse + } else { + print "http error: [$rc_code] $rc_string\n"; + exit 1; + } + } else { + print "Error: $rc\n"; + exit 1; + } + } + my $rc = system("curl -# -o $url_tmp_file $load_file"); + if ($rc) { + print "Can not open remote configuration file $load_file\n"; + exit 1; + } + if (!open(CFG, "<$url_tmp_file")) { + print "Cannot open configuration file $load_file\n"; + exit 1; + } + $load_file = $url_tmp_file; } while (<CFG>) { if (/\/\*XORP Configuration File, v1.0\*\//) { diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl index c759503..2c02766 100755 --- a/scripts/vyatta-save-config.pl +++ b/scripts/vyatta-save-config.pl @@ -26,6 +26,8 @@ use VyattaConfigOutput; my $etcdir = "/opt/vyatta/etc"; my $bootpath = $etcdir . "/config"; my $save_file = $bootpath . "/config.boot"; +my $url_tmp_file = $bootpath . "/config.boot.$$"; + if ($#ARGV > 0) { print "Usage: save [config_file_name]\n"; @@ -34,25 +36,68 @@ if ($#ARGV > 0) { if (defined($ARGV[0])) { $save_file = $ARGV[0]; - if (!($save_file =~ /^\//)) { - # relative path - $save_file = "$bootpath/$save_file"; +} + +my $mode = 'local'; +my $proto; + +if ($save_file =~ /^[^\/]\w+:\//) { + if ($save_file =~ /^(\w+):\/\/\w/) { + $mode = 'url'; + $proto = lc($1); + if ($proto eq 'tftp') { + } elsif ($proto eq 'ftp') { + } elsif ($proto eq 'scp') { + } else { + print "Invalid url protocol [$proto]\n"; + exit 1; + } + } else { + print "Invalid url [$save_file]\n"; + exit 1; } } -# this overwrites the file if it exists. we could create a backup first. -if (! open(SAVE, ">$save_file")) { - print "Cannot open file '$save_file': $!\n"; - exit 1; +if ($mode eq 'local' and !($save_file =~ /^\//)) { + # relative path + $save_file = "$bootpath/$save_file"; +} + +my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; +print "Saving configuration to '$save_file'...\n"; + +if ($mode eq 'local') { + # this overwrites the file if it exists. we could create a backup first. + if (! open(SAVE, ">$save_file")) { + print "Cannot open file '$save_file': $!\n"; + exit 1; + } +} elsif ($mode eq 'url') { + if (! -f '/usr/bin/curl') { + print "Package [curl] not installed\n"; + exit 1; + } + if (! open(SAVE, ">$url_tmp_file")) { + print "Cannot open file '$url_tmp_file': $!\n"; + exit 1; + } } -print "Saving configuration to '$save_file'..."; select SAVE; VyattaConfigOutput::set_show_all(1); VyattaConfigOutput::outputActiveConfig(); -my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; -print SAVE $version_str; -select STDOUT; -print "\nDone\n"; +print $version_str; close SAVE; +select STDOUT; + +if ($mode eq 'url') { + my $rc = system("curl -# -T $url_tmp_file $save_file"); + system("rm -f $url_tmp_file"); + if ($rc) { + print "Error saving $save_file\n"; + exit 1; + } +} + +print "Done\n"; exit 0; diff --git a/src/cli_def.l b/src/cli_def.l index 07c9c68..d73f1c4 100644 --- a/src/cli_def.l +++ b/src/cli_def.l @@ -19,8 +19,9 @@ static char str_delim = 0; static int eof_seen = 0; static int pre_str_state = 0; -static char *reg_fields[] = { "default", "tag", "type", "multi", NULL }; -static int reg_fields_t[] = { DEFAULT, TAG, TYPE, MULTI, 0 }; +static char *reg_fields[] = { "default", "tag", "type", "multi", "priority", + NULL }; +static int reg_fields_t[] = { DEFAULT, TAG, TYPE, MULTI, PRIORITY, 0 }; static char *act_fields[] = { "help", "syntax", "commit", "delete", "update", "activate", "create", "begin", "end", @@ -262,7 +263,7 @@ RE_OP_COND (==|!=|<|>|<=|>=|in) RE_OP_OTHER (pattern|exec|,|\|\||&&|=|!|\(|\)|;) /* template fields */ -RE_REG_FIELD (default|tag|type|multi) +RE_REG_FIELD (default|tag|type|multi|priority) RE_ACT_FIELD (help|syntax|commit|delete|update|activate|create|begin|end|comp_help|allowed) %% diff --git a/src/cli_new.c b/src/cli_new.c index 1ecbe83..26cc719 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -1435,7 +1435,7 @@ static int expand_string(char *stringp) if(clind_config_engine_apply_command_path(n_cfg_path, n_tmpl_path, n_cmd_path, - FALSE, + TRUE, &cv, get_cdirp(), get_tdirp(), diff --git a/src/cli_parse.y b/src/cli_parse.y index 6378bc9..dd3d7d2 100644 --- a/src/cli_parse.y +++ b/src/cli_parse.y @@ -1,8 +1,12 @@ %{ - #include <assert.h> #include <stdio.h> #include <string.h> +#include <errno.h> +#include <stdlib.h> + +#define __USE_ISOC99 +#include <limits.h> #include "cli_val.h" @@ -30,6 +34,7 @@ static void cli_deferror(const char *); %token TYPE %token HELP %token DEFAULT +%token PRIORITY %token PATTERN %token EXEC %token SYNTAX @@ -101,6 +106,7 @@ type: TYPE TYPE_DEF cause: help_cause | default_cause + | priority_stmt | syntax_cause | ACTION action { append(parse_defp->actions + $1, $2, 0);} | dummy_stmt @@ -126,6 +132,25 @@ default_cause: DEFAULT STRING parse_defp->def_default = $2; } +priority_stmt: PRIORITY VALUE + { + char *tmp = $2.val; + long long int cval = 0; + char *endp = NULL; + errno = 0; + cval = strtoll(tmp, &endp, 10); + if (($2.val_type != INT_TYPE) + || (errno == ERANGE + && (cval == LLONG_MAX || cval == LLONG_MIN)) + || (errno != 0 && cval == 0) + || (*endp != '\0') || (cval < 0) || (cval > UINT_MAX)) { + yy_cli_parse_error((const char *) + "Priority must be <u32>\n"); + } else { + parse_defp->def_priority = cval; + } + } + syntax_cause: SYNTAX exp {append(parse_defp->actions + syntax_act, $2, 0);} ; diff --git a/src/cli_val.h b/src/cli_val.h index edbda41..520fa8e 100644 --- a/src/cli_val.h +++ b/src/cli_val.h @@ -101,6 +101,7 @@ typedef struct { char *def_type_help; char *def_node_help; char *def_default; + unsigned int def_priority; boolean tag; boolean multi; vtw_list actions[top_act]; diff --git a/src/cli_val_engine.c b/src/cli_val_engine.c index adf40a4..a81f413 100644 --- a/src/cli_val_engine.c +++ b/src/cli_val_engine.c @@ -56,6 +56,9 @@ #include "cli_val_engine.h" + +static int is_multi_node(clind_path_ref tmpl_path); + /********************* * Data definitions * @@ -129,6 +132,13 @@ static char** clind_get_current_value(clind_path_ref cfg_path, int value_ref = 0; *ret_size=0; + + if (check_existence) { + if (is_multi_node(tmpl_path)) { + check_existence = FALSE; + } + } + DPRINT("get_current_value cfg[%s] tmpl[%s] chkexist=%d\n", clind_path_get_path_string(cfg_path), clind_path_get_path_string(tmpl_path), @@ -217,6 +227,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path, struct stat statbuf; /* Directory reference: */ + if(!check_existence || (lstat(cfg_path_string, &statbuf) == 0)) { ret=(char**)realloc(ret,sizeof(char*)*1); ret[0]=clind_unescape(cfg_end); diff --git a/src/commit.c b/src/commit.c index 534757c..3b4d9d3 100644 --- a/src/commit.c +++ b/src/commit.c @@ -15,6 +15,18 @@ #include "cli_parse.h" #include "cli_path_utils.h" +struct DirIndex { + int dirname_index; + int dirname_ct; + struct DirSort** dirname; +}; + +struct DirSort { + char name[255]; + unsigned long priority; +}; + + static char def_name[] = DEF_NAME; static char tag_name[] = TAG_NAME; static char opaque_name[] = OPQ_NAME; @@ -53,21 +65,101 @@ static void make_dir() } #endif -static struct dirent * -get_next_filtered_dirent(DIR *dp, int exclude_wh) +static int +compare_dirname(const void *p, const void *q) +{ + const struct DirSort *a = (const struct DirSort*)*(struct Dirsort **)p; + const struct DirSort *b = (const struct DirSort*)*(struct Dirsort **)q; + if (a->priority == b->priority) { + return strcmp(a->name,b->name); + } + return ((long)b->priority - (long)a->priority); +} + +static int +compare_dirname_reverse_priority(const void *p, const void *q) { - struct dirent *dirp = NULL; + const struct DirSort *a = (const struct DirSort*)*(struct Dirsort **)p; + const struct DirSort *b = (const struct DirSort*)*(struct Dirsort **)q; + if (a->priority == b->priority) { + return strcmp(a->name,b->name); + } + return ((long)a->priority - (long)b->priority); +} + +struct DirIndex* +init_next_filtered_dirname(DIR *dp, int sort_order, int exclude_wh) +{ + struct DirIndex *di = malloc(sizeof(struct DirIndex)); + di->dirname = malloc(1024 * sizeof(char*)); + di->dirname_ct = 0; + di->dirname_index = 0; + + struct dirent *dirp; while ((dirp = readdir(dp)) != NULL) { if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0 || strcmp(dirp->d_name, MOD_NAME) == 0 || strcmp(dirp->d_name, opaque_name) == 0 || (exclude_wh && strncmp(dirp->d_name, ".wh.", 4) == 0)) { continue; - } else { - return dirp; + } + else { + struct DirSort *d = malloc(sizeof(struct DirSort)); + if (strlen(dirp->d_name) >= 255) { + bye("configuration value exceeds 255 chars\n"); + } + strcpy(d->name,dirp->d_name); + d->priority = (unsigned long)0; + vtw_def def; + char *path; + path = malloc(strlen(t_path.path)+strlen(dirp->d_name)+2+8+1); + sprintf(path,"%s/%s/node.def",t_path.path,dirp->d_name); + struct stat s; + if ((lstat(path,&s) >= 0) && + ((s.st_mode & S_IFMT) == S_IFREG)) { + memset(&def, 0, sizeof(def)); + if (parse_def(&def,path,FALSE) == 0) { + d->priority = def.def_priority; + } + } + free(path); + di->dirname[di->dirname_ct++] = d; + if (di->dirname_ct % 1024 == 0) { + di->dirname = realloc(di->dirname, (di->dirname_ct+1024)*sizeof(char*)); + } } } - return dirp; + if (sort_order == 0) { + qsort(di->dirname, di->dirname_ct, sizeof(char*), compare_dirname); + } + else { + qsort(di->dirname, di->dirname_ct, sizeof(char*), compare_dirname_reverse_priority); + } + return di; +} + +static char* +get_next_filtered_dirname(struct DirIndex *di) +{ + if (di == NULL || di->dirname_index == di->dirname_ct) { + return NULL; + } + return di->dirname[di->dirname_index++]->name; +} + +void +release_dir_index(struct DirIndex *di) +{ + if (di != NULL) { + int i; + for (i = 0; i < di->dirname_ct; ++i) { + if (di->dirname[i] != NULL) { + free((struct DirSort*)di->dirname[i]); + } + } + free(di); + di = NULL; + } } /************************************************* @@ -88,7 +180,7 @@ static boolean validate_dir_for_commit() boolean value_present=FALSE; int subdirs_number=0; DIR *dp=NULL; - struct dirent *dirp=NULL; + char *dirname = NULL; char *cp=NULL; boolean ret=TRUE; char *uename = NULL; @@ -130,14 +222,14 @@ static boolean validate_dir_for_commit() if (def_present && def.tag) { push_path(&t_path, tag_name); /* PUSH 2a */ } - - while ((dirp = get_next_filtered_dirent(dp, 1)) != NULL) { + struct DirIndex *di = init_next_filtered_dirname(dp,0,1); + while ((dirname = get_next_filtered_dirname(di)) != NULL) { subdirs_number++; if(uename) my_free(uename); - uename = clind_unescape(dirp->d_name); + uename = clind_unescape(dirname); if (strcmp(uename, VAL_NAME) == 0) { @@ -197,6 +289,11 @@ static boolean validate_dir_for_commit() continue; } + if (strcmp(uename,"def") == 0) { + ret = TRUE; + continue; + } + push_path(&m_path, uename); /* PUSH 3 */ if (lstat(m_path.path, &statbuf) < 0) { printf("Can't read directory %s\n", @@ -251,6 +348,7 @@ static boolean validate_dir_for_commit() pop_path(&t_path); /* for PUSH 2b */ } // while + release_dir_index(di); status = closedir(dp); if (status) bye("Cannot close dir %s\n", m_path.path); @@ -960,16 +1058,18 @@ valstruct_append(valstruct *mvals, char *cp, vtw_type_e type) */ static void get_filtered_directory_listing(DIR *dp, valstruct *mvals, vtw_type_e type, - int exclude_wh) + int exclude_wh, int sort_order) { - struct dirent *dirp = NULL; + char *dname = NULL; char *cp = NULL; memset(mvals, 0, sizeof (valstruct)); - while ((dirp = get_next_filtered_dirent(dp, exclude_wh)) != NULL) { - cp = clind_unescape(dirp->d_name); + struct DirIndex *di = init_next_filtered_dirname(dp, sort_order, exclude_wh); + while ((dname = get_next_filtered_dirname(di)) != NULL) { + cp = clind_unescape(dname); valstruct_append(mvals, cp, type); } + release_dir_index(di); } /* check if a value is one of those in a valstruct. @@ -1073,19 +1173,19 @@ static boolean commit_delete_children(vtw_def *defp, boolean deleting, memset(&cur_sorted, 0, sizeof(vtw_sorted)); /* changes directory */ - get_filtered_directory_listing(dp, &mvals, type, 0); + get_filtered_directory_listing(dp, &mvals, type, 0, 1); if (closedir(dp) != 0) { INTERNAL; } if (adp && mdp) { /* active directory */ - get_filtered_directory_listing(adp, &valsA, type, 0); + get_filtered_directory_listing(adp, &valsA, type, 0, 1); if (closedir(adp) != 0) { INTERNAL; } /* modified directory */ - get_filtered_directory_listing(mdp, &valsM, type, 0); + get_filtered_directory_listing(mdp, &valsM, type, 0, 1); if (closedir(mdp) != 0) { INTERNAL; } @@ -1164,7 +1264,7 @@ static boolean commit_update_children(vtw_def *defp, boolean creating, if (type == ERROR_TYPE) type = TEXT_TYPE; - get_filtered_directory_listing(dp, &mvals, type, 0); + get_filtered_directory_listing(dp, &mvals, type, 0, 0); if (closedir(dp) != 0) { INTERNAL; } diff --git a/src/delete.c b/src/delete.c index bb36fd1..9bdb3ed 100644 --- a/src/delete.c +++ b/src/delete.c @@ -34,6 +34,53 @@ static void remove_rf(boolean do_umount) free(command); } } +static boolean has_default(char **def, int size) +{ + char *buf; + buf = malloc(1025); + char *buf_ptr; + FILE *fp = fopen(t_path.path, "r"); + if (fp) { + while (fgets(buf, 1024, fp)) { + if (strncmp(buf, "default:", 8) == 0) { + buf_ptr = index(buf,':'); + if (buf_ptr == NULL) { + break; + } + buf_ptr++; + if (size < strlen(buf_ptr)-1) { + bye("default buffer size is too small\n"); + } + memcpy(*def, buf_ptr, strlen(buf_ptr)-1); + fclose(fp); + free(buf); + return 0; + } + } + fclose(fp); + } + free(buf); + return 1; +} +static void reset_default(char *def_val) +{ + char *command,*def_cmd; + boolean has_default = 1; + if (def_val == NULL) { + return; + } + if (has_default) { + touch(); + command = my_malloc(strlen(m_path.path) + 100, "set"); + sprintf(command, "echo %s > %s/node.val", def_val, m_path.path); + system(command); + def_cmd = malloc(strlen(m_path.path) + 12); + sprintf(def_cmd, "touch %s/def",m_path.path); + system(def_cmd); + free(command); + free(def_cmd); + } +} /*************************************************** set_validate: validate value against definition @@ -139,6 +186,7 @@ int main(int argc, char **argv) fprintf(out_stream, "Nothing to delete\n"); bye("Nothing to delete at %s", m_path.path); } + remove_rf(FALSE); pop_path(&m_path); if ((dp = opendir(m_path.path)) == NULL){ @@ -187,7 +235,17 @@ int main(int argc, char **argv) } } /* else no defnition, remove it also */ - remove_rf(FALSE); + char *def_val; + def_val = malloc(1025); + if (has_default(&def_val,1024) == 0) { + reset_default(def_val); + free(def_val); + } + else { + remove_rf(FALSE); + } + + // remove_rf(FALSE); exit(0); } if(ai < argc -1 || last_tag) { @@ -267,6 +325,38 @@ int main(int argc, char **argv) remove_rf(FALSE); return 0; } + + /* + let's do a new check here: + -> if this is a leaf and there is a value look for a match of the value + -> make sure to check existing configuration as well as uncommitted config + */ + if (ai+1 == argc) { + //does this work up until the last value + pop_path(&m_path); + if(lstat(m_path.path, &statbuf) == 0) { + //now compare last value with that in the node.def file to determine whether to accept this delete + status = get_value(&cp, &m_path); + if (status != VTWERR_OK) { + bye("Cannot read old value %s\n", m_path.path); + } + if (!strcmp(cp,argv[argc - 1])) { + /* Also need to handle the case where the value is not specified. */ + char *def_val; + def_val = malloc(1025); + if (has_default(&def_val,1024) == 0) { + reset_default(def_val); + free(def_val); + } + else { + remove_rf(FALSE); + } + return 0; + } + } + } + + fprintf(out_stream, "The specified configuration node is not valid\n"); bye("There is no appropriate template for %s", m_path.path + strlen(get_mdirp())); @@ -245,6 +245,16 @@ int main(int argc, char **argv) pop_path(&m_path); } make_dir(); + + + if (!def.multi) { + char *path; + path= malloc(strlen(m_path.path)+5); + sprintf(path, "%s/def",m_path.path); + unlink(path); + free(path); + } + push_path(&m_path, VAL_NAME); if(not_new && !def.multi) { /* it is not multi and seen from M */ @@ -341,11 +351,22 @@ handle_default(vtw_path *mpath, vtw_path *tpath, char *exclude) } if (def.def_default) { push_path(mpath, uename); + push_path(mpath, VAL_NAME); if (lstat(mpath->path, &statbuf) < 0) { /* no value. add the default */ pop_path(mpath); touch_dir(mpath->path); /* make sure directory exist */ + + //create def marker + char *def_file; + def_file = malloc(strlen(mpath->path)+22); + sprintf(def_file,"touch %s/def",mpath->path); + system(def_file); + sprintf(def_file,"echo 'empty' > %s/def",mpath->path); + system(def_file); + free(def_file); + push_path(mpath, VAL_NAME); fp = fopen(mpath->path, "w"); if (fp == NULL) { @@ -356,6 +377,7 @@ handle_default(vtw_path *mpath, vtw_path *tpath, char *exclude) bye("Error writing file %s", mpath->path); } fclose(fp); + } pop_path(mpath); /* value */ pop_path(mpath); /* child */ diff --git a/templates/interfaces/ethernet/node.def b/templates/interfaces/ethernet/node.def index baf824b..1049f3e 100644 --- a/templates/interfaces/ethernet/node.def +++ b/templates/interfaces/ethernet/node.def @@ -1,6 +1,6 @@ tag: type: txt -help: Ethernet interface name +help: Set ethernet interface syntax:expression: exec " \ if [ -z \"`ip link | grep eth | egrep -v 'eth[0-9]+[.]' | grep $VAR(@)`\" ]; then \ echo Invalid ethernet interface [$VAR(@)]; \ @@ -11,7 +11,7 @@ update:expression: "${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" -c \"link-detect\"; " delete:expression: "sudo ip link set $VAR(@) down" ; "Error disabling dev $VAR(@)" allowed: for dev in /sys/class/net/*; - do if [[ -L $dev/device ]] + do if [[ -d $dev && -L $dev/device ]] then if [[ $(cat $dev/type) -eq 1 ]] then echo -n ${dev##*/} " " fi diff --git a/templates/interfaces/ethernet/node.tag/address/node.def b/templates/interfaces/ethernet/node.tag/address/node.def index 23b1262..0ff02c8 100644 --- a/templates/interfaces/ethernet/node.tag/address/node.def +++ b/templates/interfaces/ethernet/node.tag/address/node.def @@ -1,11 +1,11 @@ multi: type: txt -help: Configure an IP address for this interface +help: Set an IP address for this interface syntax:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr $VAR(@) --dev $VAR(../@)"; "Invalid IP address/prefix [$VAR(@)] for interface $VAR(../@)" update:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../@)"; "Error setting address $VAR(@) on interface $VAR(../@)" delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../@)"; "Error deleting address $VAR(@) on interface $VAR(../@)" allowed: echo "dhcp <>" comp_help:Possible completions: - <IP address>/<prefix length>\tSet the IP address and prefix length - dhcp\t\t\t\tSet the IP address and prefix length via DHCP + <x.x.x.x/x> Set the IP address and prefix length + dhcp Set the IP address and prefix length via DHCP diff --git a/templates/interfaces/ethernet/node.tag/description/node.def b/templates/interfaces/ethernet/node.tag/description/node.def index 835ad40..aeb40f0 100644 --- a/templates/interfaces/ethernet/node.tag/description/node.def +++ b/templates/interfaces/ethernet/node.tag/description/node.def @@ -1,2 +1,2 @@ type: txt -help: Description for this interface +help: Set description for this interface diff --git a/templates/interfaces/ethernet/node.tag/disable/node.def b/templates/interfaces/ethernet/node.tag/disable/node.def index 9c795c6..54090cc 100644 --- a/templates/interfaces/ethernet/node.tag/disable/node.def +++ b/templates/interfaces/ethernet/node.tag/disable/node.def @@ -1,3 +1,3 @@ -help: Disable interface +help: Set interface disabled update:expression: "sudo ip link set $VAR(../@) down"; "Error disabling dev $VAR(../@)" delete:expression: "sudo ip link set $VAR(../@) up"; "Error enabling dev $VAR(../@)" diff --git a/templates/interfaces/ethernet/node.tag/hw-id/node.def b/templates/interfaces/ethernet/node.tag/hw-id/node.def index f25692d..6c559f8 100644 --- a/templates/interfaces/ethernet/node.tag/hw-id/node.def +++ b/templates/interfaces/ethernet/node.tag/hw-id/node.def @@ -1,2 +1,2 @@ type: macaddr -help: Specify the MAC address of this interface +help: Set the Media Access Control (MAC) address of this interface diff --git a/templates/interfaces/ethernet/node.tag/mac/node.def b/templates/interfaces/ethernet/node.tag/mac/node.def index d25b378..abafa7a 100644 --- a/templates/interfaces/ethernet/node.tag/mac/node.def +++ b/templates/interfaces/ethernet/node.tag/mac/node.def @@ -1,5 +1,5 @@ type: macaddr -help: Set the MAC address of this interface +help: Set the Media Access Control (MAC) address of this interface syntax:expression: exec "\ /opt/vyatta/sbin/vyatta-interfaces.pl --dev $VAR(../@) --valid-mac $VAR(@)" update: /opt/vyatta/sbin/vyatta-interfaces.pl --dev $VAR(../@) --set-mac $VAR(@) diff --git a/templates/interfaces/ethernet/node.tag/mtu/node.def b/templates/interfaces/ethernet/node.tag/mtu/node.def index c3b05a7..07c102a 100644 --- a/templates/interfaces/ethernet/node.tag/mtu/node.def +++ b/templates/interfaces/ethernet/node.tag/mtu/node.def @@ -1,5 +1,5 @@ type: u32 -help: Set the MTU for this interface +help: Set the Maximum Transmission Unit (MTU) for this interface syntax:expression: $VAR(@) >= 68 && $VAR(@) <= 9000; "MTU must be between 68 and 9000" update:expression: "sudo ip link set $VAR(../@) mtu $VAR(@)"; "Error setting MTU on dev $VAR(../@)" delete:expression: "sudo ip link set $VAR(../@) mtu 1500"; "Error deleting MTU on dev $VAR(../@)" diff --git a/templates/interfaces/ethernet/node.tag/smp_affinity/node.def b/templates/interfaces/ethernet/node.tag/smp_affinity/node.def index 850d1c1..9d5d289 100644 --- a/templates/interfaces/ethernet/node.tag/smp_affinity/node.def +++ b/templates/interfaces/ethernet/node.tag/smp_affinity/node.def @@ -17,6 +17,16 @@ comp_help: Hexidecimal bitmask representing CPUs that this NIC will interrupt syntax:expression: exec "/opt/vyatta/sbin/vyatta-irqaffin check $VAR(../@) $VAR(@)" -create:expression: "sudo /opt/vyatta/sbin/vyatta-irqaffin set $VAR(../@) $VAR(@)"; "Error setting CPU affinity mask $VAR(@) on interface $VAR(../@)" +update: + sudo /opt/vyatta/sbin/vyatta-irqaffin set $VAR(../@) $VAR(@) + if [ $? -ne 0 ]; then + echo "Error setting CPU affinity mask $VAR(@) on interface $VAR(../@)" + exit 1 + fi -delete:expression: "sudo /opt/vyatta/sbin/vyatta-irqaffin reset $VAR(../@)"; "Error deleting CPU affinity mask on interface $VAR(../@)" +delete: + sudo /opt/vyatta/sbin/vyatta-irqaffin reset $VAR(../@) + if [ $? -ne 0 ]; then + echo "Error deleting CPU affinity mask on interface $VAR(../@)" + exit 1 + fi diff --git a/templates/interfaces/ethernet/node.tag/vif/node.def b/templates/interfaces/ethernet/node.tag/vif/node.def index 6a367f6..7ee3b50 100644 --- a/templates/interfaces/ethernet/node.tag/vif/node.def +++ b/templates/interfaces/ethernet/node.tag/vif/node.def @@ -1,6 +1,6 @@ tag: type: u32 -help: VLAN ID +help: Set Virtual Local Area Network (VLAN) ID syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 4094; "VLAN ID must be between 0 and 4094" create:expression: "sudo modprobe 8021q"; "Error loading 802.1q driver" create:expression: "sudo vconfig add $VAR(../@) $VAR(@)"; "Error adding VLAN id $VAR(@) to dev $VAR(../@)" 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 a33818f..cb9cedc 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 @@ -1,10 +1,10 @@ multi: type: txt -help: Configure an IP address for this interface +help: Set an IP address for this interface syntax:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr $VAR(@) --dev $VAR(../../@).$VAR(../@) "; "Invalid IP address/prefix [$VAR(@)] for interface $VAR(../../@).$VAR(../@)" create:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-update $VAR(@) --dev $VAR(../../@).$VAR(../@) "; "Error setting address $VAR(@) on dev $VAR(../../@).$VAR(../@) " delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete $VAR(@) --dev $VAR(../../@).$VAR(../@) "; "Error deleting address $VAR(@) on dev $VAR(../../@).$VAR(../@) " allowed: echo "dhcp <>" comp_help:Possible completions: - <IP address>/<prefix length> Set the IP address and prefix length - dhcp Set the IP address and prefix length via DHCP + <x.x.x.x/x> Set the IP address and prefix length + dhcp Set the IP address and prefix length via DHCP diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def index 835ad40..aeb40f0 100644 --- a/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def +++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def @@ -1,2 +1,2 @@ type: txt -help: Description for this interface +help: Set description for this interface diff --git a/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def b/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def index 3b2ae45..9599de3 100644 --- a/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def +++ b/templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def @@ -1,3 +1,3 @@ -help: Disable interface +help: Set interface disabled update:expression: "sudo ip link set $VAR(../../@).$VAR(../@) down"; "Error disabling dev $VAR(../../@).$VAR(../@)" delete:expression: "sudo ip link set $VAR(../../@).$VAR(../@) up"; "Error enabling dev $VAR(../../@).$VAR(../@)" diff --git a/templates/interfaces/loopback/node.def b/templates/interfaces/loopback/node.def index 72888fc..7b7a304 100644 --- a/templates/interfaces/loopback/node.def +++ b/templates/interfaces/loopback/node.def @@ -1,6 +1,6 @@ tag: type: txt -help: Loopback interface name +help: Set loopback interface syntax:expression: exec " \ if [ -z \"`ip addr | grep $VAR(@) `\" ]; then \ echo loopback interface $VAR(@) doesn\\'t exist on this system ; \ diff --git a/templates/interfaces/loopback/node.tag/address/node.def b/templates/interfaces/loopback/node.tag/address/node.def index 793c52c..03ead09 100644 --- a/templates/interfaces/loopback/node.tag/address/node.def +++ b/templates/interfaces/loopback/node.tag/address/node.def @@ -1,6 +1,6 @@ multi: type: txt -help: Configure an IP address for this interface +help: Set an IP address for this interface syntax:expression: exec "/opt/vyatta/sbin/vyatta-interfaces.pl --valid-addr $VAR(@) --dev $VAR(../@)"; \ "Invalid IP address/prefix [$VAR(@)] for interface $VAR(../@)" @@ -11,4 +11,4 @@ delete:expression: "sudo /opt/vyatta/sbin/vyatta-interfaces.pl --eth-addr-delete "Error deleting address $VAR(@) on interface $VAR(../@)" comp_help:Possible completions: - <IP address>/<prefix length>\tSet the IP address and prefix length + <x.x.x.x/x> Set the IP address and prefix length diff --git a/templates/interfaces/loopback/node.tag/description/node.def b/templates/interfaces/loopback/node.tag/description/node.def index 835ad40..aeb40f0 100644 --- a/templates/interfaces/loopback/node.tag/description/node.def +++ b/templates/interfaces/loopback/node.tag/description/node.def @@ -1,2 +1,2 @@ type: txt -help: Description for this interface +help: Set description for this interface diff --git a/templates/interfaces/node.def b/templates/interfaces/node.def index 7ab9990..5865af5 100644 --- a/templates/interfaces/node.def +++ b/templates/interfaces/node.def @@ -1 +1 @@ -help: Network interface configuration +help: Configure network interfaces |