aboutsummaryrefslogtreecommitdiffstats
path: root/vpp
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2015-12-15 04:31:07 -0500
committerDamjan Marion <damarion@cisco.com>2015-12-15 10:48:06 +0100
commit5e7ac9dc825d06b30bfb970860ccc7a3f2696c6e (patch)
tree48bda01b94a4d2110502f6c51bbc1360c2baee00 /vpp
parent3c6155c7b37c9674952ba62ba09b66d131007bb9 (diff)
load vpp startup config from file
Change-Id: I55c636059cda706a47758ad89e5518e959c85263 Signed-off-by: Matus Fabian <matfabia@cisco.com> Acked-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'vpp')
-rw-r--r--vpp/vnet/main.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/vpp/vnet/main.c b/vpp/vnet/main.c
index 09adfea3..da1ec9a4 100644
--- a/vpp/vnet/main.c
+++ b/vpp/vnet/main.c
@@ -143,6 +143,65 @@ int main (int argc, char * argv[])
u32 size;
void vlib_set_get_handoff_structure_cb (void *cb);
+ /*
+ * Load startup config from file.
+ * usage: vpe -c /etc/vpp/startup.conf
+ */
+ if ((argc == 3) && !strncmp(argv[1], "-c", 2))
+ {
+ FILE * fp;
+ char inbuf[4096];
+ int argc_ = 1;
+ char ** argv_ = NULL;
+ char * arg = NULL;
+ char * p;
+
+ fp = fopen (argv[2], "r");
+ if (fp == NULL)
+ {
+ fprintf(stderr, "open configuration file '%s' failed\n", argv[2]);
+ return 1;
+ }
+ argv_ = calloc(1, sizeof(char *));
+ if (argv_ == NULL)
+ return 1;
+ arg = strndup(argv[0], 1024);
+ if (arg == NULL)
+ return 1;
+ argv_[0] = arg;
+
+ while (1) {
+ if (fgets(inbuf, 4096, fp) == 0)
+ break;
+ p = strtok(inbuf, " \t\n");
+ while (p != NULL) {
+ if (*p == '#')
+ break;
+ argc_++;
+ char ** tmp = realloc(argv_, argc_ * sizeof(char *));
+ if (tmp == NULL)
+ return 1;
+ argv_ = tmp;
+ arg = strndup(p, 1024);
+ if (arg == NULL)
+ return 1;
+ argv_[argc_ - 1] = arg;
+ p = strtok(NULL, " \t\n");
+ }
+ }
+
+ fclose(fp);
+
+ char ** tmp = realloc(argv_, (argc_ + 1) * sizeof(char *));
+ if (tmp == NULL)
+ return 1;
+ argv_ = tmp;
+ argv_[argc_] = NULL;
+
+ argc = argc_;
+ argv = argv_;
+ }
+
/*
* Look for and parse the "heapsize" config parameter.
* Manual since none of the clib infra has been bootstrapped yet.