diff options
22 files changed, 257 insertions, 38 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_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/commit.c b/src/commit.c index 534757c..84e088f 100644 --- a/src/commit.c +++ b/src/commit.c @@ -15,6 +15,23 @@ #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 int g_dirname_index = 0; +static int g_dirname_ct = 0; +static struct DirSort** g_dirname = NULL; +*/ + static char def_name[] = DEF_NAME; static char tag_name[] = TAG_NAME; static char opaque_name[] = OPQ_NAME; @@ -52,17 +69,92 @@ static void make_dir() return; } #endif +/* +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 struct dirent * -get_next_filtered_dirent(DIR *dp, int exclude_wh) +void +init_next_filtered_dirname(DIR *dp, struct DirIndex *di, int exclude_wh) { - struct dirent *dirp = NULL; + // fprintf(out_stream,"\n"); + di->dirname = malloc(1024 * sizeof(char*)); + di->dirname_ct = 0; + di->dirname_index = 0; + + int i; + + //NOTE: need to free ct round up to next 1024 when shutting down commit + + 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 { + 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; + + //retreive priority now + vtw_def def; + char *path; + path = malloc(strlen(t_path.path)+strlen(dirp->d_name)+2+8); + 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) { + // fprintf(out_stream, "found(D): %s:%d\n",dirp->d_name, def.def_priority); + 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*)); + } + } + } + qsort(di->dirname, di->dirname_ct, sizeof(char*), compare_dirname); +} + +static char* +get_next_filtered_dirname(struct DirIndex *di) +{ + if (di->dirname_index == di->dirname_ct) { + return NULL; + } + //just return the collection ptr; + // fprintf(out_stream, "get_next: %s\n", di->dirname[di->dirname_index]->name); + return di->dirname[di->dirname_index++]->name; +} +*/ +static struct dirent * +get_next_filtered_dirent(DIR *dp, int exclude_wh) +{ + struct dirent *dirp = NULL; + 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; } @@ -89,6 +181,7 @@ static boolean validate_dir_for_commit() int subdirs_number=0; DIR *dp=NULL; struct dirent *dirp=NULL; + char *dirname = NULL; char *cp=NULL; boolean ret=TRUE; char *uename = NULL; @@ -130,8 +223,12 @@ 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 = malloc(sizeof(struct DirIndex)); + init_next_filtered_dirname(dp,di,1); + while ((dirname = get_next_filtered_dirname(di)) != NULL) { + */ + while ((dirp = get_next_filtered_dirent(dp,1)) != NULL) { subdirs_number++; if(uename) @@ -962,11 +1059,17 @@ static void get_filtered_directory_listing(DIR *dp, valstruct *mvals, vtw_type_e type, int exclude_wh) { - struct dirent *dirp = NULL; + char *dname = NULL; char *cp = NULL; + struct dirent *dirp = NULL; memset(mvals, 0, sizeof (valstruct)); - while ((dirp = get_next_filtered_dirent(dp, exclude_wh)) != NULL) { + /* + struct DirIndex *di = malloc(sizeof(struct DirIndex)); + init_next_filtered_dirname(dp,di,exclude_wh); + while ((dname = get_next_filtered_dirname(di)) != NULL) { + */ + while ((dirp = get_next_filtered_dirent(dp,exclude_wh)) != NULL) { cp = clind_unescape(dirp->d_name); valstruct_append(mvals, cp, type); } 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 baf824b..4c311fc 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(@)]; \ 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..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 |