blob: a968bc01d3b7a5b8f12eb0a58b5e215e10051530 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file control_vty.c
2 * VTY configuration for Control interface. */
3/*
Neels Hofmeyrf81eb322016-02-24 00:10:41 +01004 * (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdlib.h>
Harald Weltef2899c62017-01-15 17:54:11 +010025#include <osmocom/core/talloc.h>
Neels Hofmeyrf81eb322016-02-24 00:10:41 +010026#include <osmocom/ctrl/control_vty.h>
27#include <osmocom/vty/command.h>
28
29static void *ctrl_vty_ctx = NULL;
30static const char *ctrl_vty_bind_addr = NULL;
31
32DEFUN(cfg_ctrl_bind_addr,
33 cfg_ctrl_bind_addr_cmd,
34 "bind A.B.C.D",
35 "Set bind address to listen for Control connections\n"
36 "Local IP address (default 127.0.0.1)\n")
37{
38 talloc_free((char*)ctrl_vty_bind_addr);
39 ctrl_vty_bind_addr = NULL;
40 ctrl_vty_bind_addr = talloc_strdup(ctrl_vty_ctx, argv[0]);
41 return CMD_SUCCESS;
42}
43
44const char *ctrl_vty_get_bind_addr(void)
45{
46 if (!ctrl_vty_bind_addr)
47 return "127.0.0.1";
48 return ctrl_vty_bind_addr;
49}
50
51static struct cmd_node ctrl_node = {
52 L_CTRL_NODE,
53 "%s(config-ctrl)# ",
54 1,
55};
56
57DEFUN(cfg_ctrl,
58 cfg_ctrl_cmd,
59 "ctrl", "Configure the Control Interface")
60{
61 vty->index = NULL;
62 vty->node = L_CTRL_NODE;
63
64 return CMD_SUCCESS;
65}
66
67static int config_write_ctrl(struct vty *vty)
68{
69 /* So far there's only one element. Omit the entire section if the bind
70 * element is omitted. */
71 if (!ctrl_vty_bind_addr)
72 return CMD_SUCCESS;
73
74 vty_out(vty, "ctrl%s", VTY_NEWLINE);
75 vty_out(vty, " bind %s%s", ctrl_vty_bind_addr, VTY_NEWLINE);
76
77 return CMD_SUCCESS;
78}
79
80int ctrl_vty_init(void *ctx)
81{
82 ctrl_vty_ctx = ctx;
83 install_element(CONFIG_NODE, &cfg_ctrl_cmd);
84 install_node(&ctrl_node, config_write_ctrl);
85
86 install_element(L_CTRL_NODE, &cfg_ctrl_bind_addr_cmd);
87 return 0;
88}
89