blob: 6910d4cc7d6deb1f1aca5dc34eee848c65945453 [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 *
Neels Hofmeyrf81eb322016-02-24 00:10:41 +010020 */
21
22#include <stdlib.h>
Harald Weltef2899c62017-01-15 17:54:11 +010023#include <osmocom/core/talloc.h>
Neels Hofmeyrf81eb322016-02-24 00:10:41 +010024#include <osmocom/ctrl/control_vty.h>
25#include <osmocom/vty/command.h>
26
27static void *ctrl_vty_ctx = NULL;
28static const char *ctrl_vty_bind_addr = NULL;
29
30DEFUN(cfg_ctrl_bind_addr,
31 cfg_ctrl_bind_addr_cmd,
32 "bind A.B.C.D",
33 "Set bind address to listen for Control connections\n"
34 "Local IP address (default 127.0.0.1)\n")
35{
36 talloc_free((char*)ctrl_vty_bind_addr);
37 ctrl_vty_bind_addr = NULL;
38 ctrl_vty_bind_addr = talloc_strdup(ctrl_vty_ctx, argv[0]);
39 return CMD_SUCCESS;
40}
41
42const char *ctrl_vty_get_bind_addr(void)
43{
44 if (!ctrl_vty_bind_addr)
45 return "127.0.0.1";
46 return ctrl_vty_bind_addr;
47}
48
49static struct cmd_node ctrl_node = {
50 L_CTRL_NODE,
51 "%s(config-ctrl)# ",
52 1,
53};
54
55DEFUN(cfg_ctrl,
56 cfg_ctrl_cmd,
57 "ctrl", "Configure the Control Interface")
58{
59 vty->index = NULL;
60 vty->node = L_CTRL_NODE;
61
62 return CMD_SUCCESS;
63}
64
65static int config_write_ctrl(struct vty *vty)
66{
67 /* So far there's only one element. Omit the entire section if the bind
68 * element is omitted. */
69 if (!ctrl_vty_bind_addr)
70 return CMD_SUCCESS;
71
72 vty_out(vty, "ctrl%s", VTY_NEWLINE);
73 vty_out(vty, " bind %s%s", ctrl_vty_bind_addr, VTY_NEWLINE);
74
75 return CMD_SUCCESS;
76}
77
78int ctrl_vty_init(void *ctx)
79{
80 ctrl_vty_ctx = ctx;
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +070081 install_lib_element(CONFIG_NODE, &cfg_ctrl_cmd);
Neels Hofmeyrf81eb322016-02-24 00:10:41 +010082 install_node(&ctrl_node, config_write_ctrl);
Neels Hofmeyrf81eb322016-02-24 00:10:41 +010083
Vadim Yanitskiy8e7c4962020-10-04 15:37:31 +070084 install_lib_element(L_CTRL_NODE, &cfg_ctrl_bind_addr_cmd);
Neels Hofmeyrf81eb322016-02-24 00:10:41 +010085 return 0;
86}
87