diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.c | 27 | ||||
| -rw-r--r-- | lib/command.h | 10 | ||||
| -rw-r--r-- | lib/hash.h | 13 | ||||
| -rw-r--r-- | lib/json.h | 9 |
4 files changed, 52 insertions, 7 deletions
diff --git a/lib/command.c b/lib/command.c index 9cf93ea192..ebdbf162d1 100644 --- a/lib/command.c +++ b/lib/command.c @@ -106,6 +106,21 @@ const char *cmd_domainname_get(void) return host.domainname; } +const char *cmd_system_get(void) +{ + return host.system; +} + +const char *cmd_release_get(void) +{ + return host.release; +} + +const char *cmd_version_get(void) +{ + return host.version; +} + static int root_on_exit(struct vty *vty); /* Standard command node structures. */ @@ -1398,8 +1413,9 @@ DEFUN (show_version, SHOW_STR "Displays zebra version\n") { - vty_out(vty, "%s %s (%s).\n", FRR_FULL_NAME, FRR_VERSION, - cmd_hostname_get() ? cmd_hostname_get() : ""); + vty_out(vty, "%s %s (%s) on %s(%s).\n", FRR_FULL_NAME, FRR_VERSION, + cmd_hostname_get() ? cmd_hostname_get() : "", cmd_system_get(), + cmd_release_get()); vty_out(vty, "%s%s\n", FRR_COPYRIGHT, GIT_INFO); #ifdef ENABLE_VERSION_BUILD_CONFIG vty_out(vty, "configured with:\n %s\n", FRR_CONFIG_ARGS); @@ -2445,6 +2461,10 @@ void cmd_init(int terminal) /* Default host value settings. */ host.name = XSTRDUP(MTYPE_HOST, names.nodename); + host.system = XSTRDUP(MTYPE_HOST, names.sysname); + host.release = XSTRDUP(MTYPE_HOST, names.release); + host.version = XSTRDUP(MTYPE_HOST, names.version); + #ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME if ((strcmp(names.domainname, "(none)") == 0)) host.domainname = NULL; @@ -2563,6 +2583,9 @@ void cmd_terminate(void) } XFREE(MTYPE_HOST, host.name); + XFREE(MTYPE_HOST, host.system); + XFREE(MTYPE_HOST, host.release); + XFREE(MTYPE_HOST, host.version); XFREE(MTYPE_HOST, host.domainname); XFREE(MTYPE_HOST, host.password); XFREE(MTYPE_HOST, host.password_encrypt); diff --git a/lib/command.h b/lib/command.h index c888356d61..a540bdc5c5 100644 --- a/lib/command.h +++ b/lib/command.h @@ -55,6 +55,13 @@ struct host { /* Domainname of this router */ char *domainname; + /* + * Some extra system data that is useful + */ + char *system; + char *release; + char *version; + /* Password for vty interface. */ char *password; char *password_encrypt; @@ -600,6 +607,9 @@ extern int cmd_domainname_set(const char *domainname); extern int cmd_hostname_set(const char *hostname); extern const char *cmd_hostname_get(void); extern const char *cmd_domainname_get(void); +extern const char *cmd_system_get(void); +extern const char *cmd_release_get(void); +extern const char *cmd_version_get(void); /* NOT safe for general use; call this only if DEV_BUILD! */ extern void grammar_sandbox_init(void); diff --git a/lib/hash.h b/lib/hash.h index f3b24f051b..91770d1813 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -235,9 +235,10 @@ extern void *hash_release(struct hash *hash, void *data); /* * Iterate over the elements in a hash table. * - * It is safe to delete items passed to the iteration function from the hash - * table during iteration. More than one item cannot be deleted during each - * iteration. Please note that adding entries to the hash + * The passed in arg to the handler function is the only safe + * item to delete from the hash. + * + * Please note that adding entries to the hash * during the walk will cause undefined behavior in that some new entries * will be walked and some will not. So do not do this. * @@ -258,8 +259,10 @@ extern void hash_iterate(struct hash *hash, /* * Iterate over the elements in a hash table, stopping on condition. * - * It is safe to delete items passed to the iteration function from the hash - * table during iteration. Please note that adding entries to the hash + * The passed in arg to the handler function is the only safe item + * to delete from the hash. + * + * Please note that adding entries to the hash * during the walk will cause undefined behavior in that some new entries * will be walked and some will not. So do not do this. * diff --git a/lib/json.h b/lib/json.h index 9d33ac7ae3..fcaa84c816 100644 --- a/lib/json.h +++ b/lib/json.h @@ -42,6 +42,15 @@ extern "C" { json_object_iter_equal(&(joi), &(join)) == 0; \ json_object_iter_next(&(joi))) +#define JSON_OBJECT_NEW_ARRAY(json_func, fields, n) \ + ({ \ + struct json_object *_json_array = json_object_new_array(); \ + for (int _i = 0; _i < (n); _i++) \ + json_object_array_add(_json_array, \ + (json_func)((fields)[_i])); \ + (_json_array); \ + }) + extern bool use_json(const int argc, struct cmd_token *argv[]); extern void json_object_string_add(struct json_object *obj, const char *key, const char *s); |
