diff options
18 files changed, 122 insertions, 31 deletions
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 05323e3..9513ffa 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -28,16 +28,19 @@ use VyattaConfigLoad; my $etcdir = $ENV{vyatta_sysconfdir}; my $sbindir = $ENV{vyatta_sbindir}; my $bootpath = $etcdir . "/config"; +my $load_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 =~ /^\//)) { - # relative path - $load_file = "$bootpath/$load_file"; +if (defined($ARGV[0])) { + $load_file = $ARGV[0]; + if (!($load_file =~ /^\//)) { + # relative path + $load_file = "$bootpath/$load_file"; + } } if (!open(CFG, "<$load_file")) { diff --git a/src/cli_val_engine.c b/src/cli_val_engine.c index adf40a4..786c0cd 100644 --- a/src/cli_val_engine.c +++ b/src/cli_val_engine.c @@ -217,10 +217,12 @@ 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); - *ret_size=1; + if(!check_existence) { + if (lstat(cfg_path_string, &statbuf) == 0) { + ret=(char**)realloc(ret,sizeof(char*)*1); + ret[0]=clind_unescape(cfg_end); + *ret_size=1; + } } else { /* we are checking existence, and it doesn't exist */ /* return empty string */ @@ -230,7 +232,7 @@ static char** clind_get_current_value(clind_path_ref cfg_path, *ret_size = 1; } } - + if(ret) { if(tmpl_end && (strcmp(tmpl_end,NODE_TAG)==0)) { /* since it's a tag, it should be treated as a value */ diff --git a/src/delete.c b/src/delete.c index bb36fd1..aa83796 100644 --- a/src/delete.c +++ b/src/delete.c @@ -34,6 +34,49 @@ 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; + 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); + free(command); + } +} /*************************************************** set_validate: validate value against definition @@ -139,6 +182,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 +231,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 +321,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())); diff --git a/templates/interfaces/ethernet/node.def b/templates/interfaces/ethernet/node.def index eee64cd..444affe 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 name syntax:expression: exec " \ if [ -z \"`ip link | egrep -v 'eth[0-9]+[.]' | grep $VAR(@)`\" ]; then \ echo Invalid ethernet interface [$VAR(@)]; \ 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/vif/node.def b/templates/interfaces/ethernet/node.tag/vif/node.def index 73958be..5374761 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..cc59c27 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 name 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 |