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