diff options
Diffstat (limited to 'openbsc/src/vty')
-rw-r--r-- | openbsc/src/vty/buffer.c | 6 | ||||
-rw-r--r-- | openbsc/src/vty/command.c | 20 | ||||
-rw-r--r-- | openbsc/src/vty/utils.c | 50 | ||||
-rw-r--r-- | openbsc/src/vty/vty.c | 19 |
4 files changed, 76 insertions, 19 deletions
diff --git a/openbsc/src/vty/buffer.c b/openbsc/src/vty/buffer.c index 195d06209..0bc1760cc 100644 --- a/openbsc/src/vty/buffer.c +++ b/openbsc/src/vty/buffer.c @@ -65,11 +65,11 @@ struct buffer_data { #define BUFFER_DATA_FREE(D) talloc_free((D)) /* Make new buffer. */ -struct buffer *buffer_new(size_t size) +struct buffer *buffer_new(void *ctx, size_t size) { struct buffer *b; - b = talloc_zero(tall_vty_ctx, struct buffer); + b = talloc_zero(ctx, struct buffer); if (size) b->size = size; @@ -138,7 +138,7 @@ static struct buffer_data *buffer_add(struct buffer *b) { struct buffer_data *d; - d = _talloc_zero(tall_vty_ctx, + d = _talloc_zero(b, offsetof(struct buffer_data, data[b->size]), "buffer_add"); if (!d) diff --git a/openbsc/src/vty/command.c b/openbsc/src/vty/command.c index a38ed0424..a1130b68e 100644 --- a/openbsc/src/vty/command.c +++ b/openbsc/src/vty/command.c @@ -478,6 +478,13 @@ void install_element(enum node_type ntype, struct cmd_element *cmd) cmd->cmdsize = cmd_cmdsize(cmd->strvec); } +/* Install a command into VIEW and ENABLE node */ +void install_element_ve(struct cmd_element *cmd) +{ + install_element(VIEW_NODE, cmd); + install_element(ENABLE_NODE, cmd); +} + #ifdef VTY_CRYPT_PW static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -2311,7 +2318,7 @@ DEFUN(disable, } /* Down vty node level. */ -DEFUN(config_exit, +gDEFUN(config_exit, config_exit_cmd, "exit", "Exit current mode and down to previous mode\n") { switch (vty->node) { @@ -2363,6 +2370,9 @@ DEFUN(config_exit, vty->node = CONFIG_NODE; break; case MGCP_NODE: + case GBPROXY_NODE: + case SGSN_NODE: + case NS_NODE: vty->node = CONFIG_NODE; vty->index = NULL; default: @@ -2372,11 +2382,11 @@ DEFUN(config_exit, } /* quit is alias of exit. */ -ALIAS(config_exit, +gALIAS(config_exit, config_quit_cmd, "quit", "Exit current mode and down to previous mode\n") /* End of configuration. */ - DEFUN(config_end, + gDEFUN(config_end, config_end_cmd, "end", "End current mode and change to enable mode.") { switch (vty->node) { @@ -2407,7 +2417,7 @@ DEFUN(show_version, } /* Help display function for all node. */ -DEFUN(config_help, +gDEFUN(config_help, config_help_cmd, "help", "Description of the interactive help system\n") { vty_out(vty, @@ -2428,7 +2438,7 @@ argument.%s\ } /* Help display function for all node. */ -DEFUN(config_list, config_list_cmd, "list", "Print command list\n") +gDEFUN(config_list, config_list_cmd, "list", "Print command list\n") { unsigned int i; struct cmd_node *cnode = vector_slot(cmdvec, vty->node); diff --git a/openbsc/src/vty/utils.c b/openbsc/src/vty/utils.c new file mode 100644 index 000000000..d8dfb8ef9 --- /dev/null +++ b/openbsc/src/vty/utils.c @@ -0,0 +1,50 @@ +/* utility routines for printing common objects in the Osmocom world */ + +/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include <stdint.h> +#include <inttypes.h> + +#include <osmocore/linuxlist.h> +#include <osmocore/talloc.h> +#include <osmocore/timer.h> +#include <osmocore/rate_ctr.h> + +#include <vty/vty.h> + +void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, + struct rate_ctr_group *ctrg) +{ + unsigned int i; + + vty_out(vty, "%s%s:%s", prefix, ctrg->desc->group_description, VTY_NEWLINE); + for (i = 0; i < ctrg->desc->num_ctr; i++) { + struct rate_ctr *ctr = &ctrg->ctr[i]; + vty_out(vty, " %s%s: %8" PRIu64 " " + "(%" PRIu64 "/s %" PRIu64 "/m %" PRIu64 "/h %" PRIu64 "/d)%s", + prefix, ctrg->desc->ctr_desc[i].description, ctr->current, + ctr->intv[RATE_CTR_INTV_SEC].rate, + ctr->intv[RATE_CTR_INTV_MIN].rate, + ctr->intv[RATE_CTR_INTV_HOUR].rate, + ctr->intv[RATE_CTR_INTV_DAY].rate, + VTY_NEWLINE); + }; +} diff --git a/openbsc/src/vty/vty.c b/openbsc/src/vty/vty.c index 0ac9530f5..08068560b 100644 --- a/openbsc/src/vty/vty.c +++ b/openbsc/src/vty/vty.c @@ -51,10 +51,10 @@ struct vty *vty_new() if (!new) goto out; - new->obuf = buffer_new(0); /* Use default buffer size. */ + new->obuf = buffer_new(new, 0); /* Use default buffer size. */ if (!new->obuf) goto out_new; - new->buf = _talloc_zero(tall_vty_ctx, VTY_BUFSIZ, "vty_new->buf"); + new->buf = _talloc_zero(new, VTY_BUFSIZ, "vty_new->buf"); if (!new->buf) goto out_obuf; @@ -170,8 +170,7 @@ void vty_close(struct vty *vty) /* Check configure. */ vty_config_unlock(vty); - /* FIXME: memory leak. We need to call telnet_close_client() but don't - * have bfd */ + /* VTY_CLOSED is handled by the telnet_interface */ vty_event(VTY_CLOSED, vty->fd, vty); /* OK free vty. */ @@ -211,7 +210,7 @@ int vty_out(struct vty *vty, const char *format, ...) else size = size * 2; - p = talloc_realloc_size(tall_vty_ctx, p, size); + p = talloc_realloc_size(vty, p, size); if (!p) return -1; @@ -358,7 +357,7 @@ static void vty_ensure(struct vty *vty, int length) { if (vty->max <= length) { vty->max *= 2; - vty->buf = talloc_realloc_size(tall_vty_ctx, vty->buf, vty->max); + vty->buf = talloc_realloc_size(vty, vty->buf, vty->max); // FIXME: check return } } @@ -459,7 +458,7 @@ static void vty_hist_add(struct vty *vty) /* Insert history entry. */ if (vty->hist[vty->hindex]) talloc_free(vty->hist[vty->hindex]); - vty->hist[vty->hindex] = talloc_strdup(tall_vty_ctx, vty->buf); + vty->hist[vty->hindex] = talloc_strdup(vty, vty->buf); /* History index rotation. */ vty->hindex++; @@ -916,7 +915,7 @@ static void vty_complete_command(struct vty *vty) vty_backward_pure_word(vty); vty_insert_word_overwrite(vty, matched[0]); vty_self_insert(vty, ' '); - //talloc_free(matched[0]); + talloc_free(matched[0]); break; case CMD_COMPLETE_MATCH: vty_prompt(vty); @@ -924,8 +923,6 @@ static void vty_complete_command(struct vty *vty) vty_backward_pure_word(vty); vty_insert_word_overwrite(vty, matched[0]); talloc_free(matched[0]); - vector_only_index_free(matched); - return; break; case CMD_COMPLETE_LIST_MATCH: for (i = 0; matched[i] != NULL; i++) { @@ -966,7 +963,7 @@ vty_describe_fold(struct vty *vty, int cmd_width, return; } - buf = _talloc_zero(tall_vty_ctx, strlen(desc->str) + 1, "describe_fold"); + buf = _talloc_zero(vty, strlen(desc->str) + 1, "describe_fold"); if (!buf) return; |