summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/control1
-rwxr-xr-xetc/bash_completion.d/20vyatta-cfg1
-rwxr-xr-xscripts/VyattaConfigOutput.pm43
-rwxr-xr-xscripts/vyatta-interfaces.pl45
-rwxr-xr-xscripts/vyatta-load-config.pl13
-rw-r--r--src/cli_def.l7
-rw-r--r--src/cli_new.c2
-rw-r--r--src/cli_parse.y27
-rw-r--r--src/cli_val.h1
-rw-r--r--src/cli_val_engine.c11
-rw-r--r--src/commit.c136
-rw-r--r--src/delete.c92
-rw-r--r--src/set.c22
-rw-r--r--templates/interfaces/ethernet/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/address/node.def6
-rw-r--r--templates/interfaces/ethernet/node.tag/description/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/disable/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/hw-id/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/mac/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/mtu/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/vif/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/vif/node.tag/address/node.def6
-rw-r--r--templates/interfaces/ethernet/node.tag/vif/node.tag/description/node.def2
-rw-r--r--templates/interfaces/ethernet/node.tag/vif/node.tag/disable/node.def2
-rw-r--r--templates/interfaces/loopback/node.def2
-rw-r--r--templates/interfaces/loopback/node.tag/address/node.def4
-rw-r--r--templates/interfaces/loopback/node.tag/description/node.def2
-rw-r--r--templates/interfaces/node.def2
28 files changed, 380 insertions, 61 deletions
diff --git a/debian/control b/debian/control
index 2fdbcfe..8ba2bff 100644
--- a/debian/control
+++ b/debian/control
@@ -15,6 +15,7 @@ Depends: sed (>= 4.1.5),
vyatta-quagga | quagga,
vyatta-op,
vyatta-config-migrate,
+ 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..fb2b142 100755
--- a/etc/bash_completion.d/20vyatta-cfg
+++ b/etc/bash_completion.d/20vyatta-cfg
@@ -70,6 +70,7 @@ 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=''
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-interfaces.pl b/scripts/vyatta-interfaces.pl
index aa82b78..ec3a873 100755
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -197,6 +197,21 @@ sub dhcp_get_interfaces {
}
}
}
+
+ $config->setLevel("interfaces bridge");
+ my @brs = $config->listNodes();
+ foreach my $br (@brs) {
+ $config->setLevel("interfaces bridge $br");
+ if ($config->exists("address")) {
+ my @addrs = $config->returnValues("address");
+ foreach my $addr (@addrs) {
+ if (defined $addr && $addr eq "dhcp") {
+ push @dhcp_intfs, $br;
+ }
+ }
+ }
+ }
+
return @dhcp_intfs;
}
@@ -205,10 +220,20 @@ sub is_dhcp_enabled {
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 +248,17 @@ 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");
+ die "unsupported dhcp interface [$intf]";
}
my @addrs = $config->returnOrigValues("address");
foreach my $addr (@addrs) {
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/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()));
diff --git a/src/set.c b/src/set.c
index d961fb8..ed43267 100644
--- a/src/set.c
+++ b/src/set.c
@@ -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..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 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