Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 1 | /* OsmoHLR VTY implementation */ |
| 2 | |
| 3 | /* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 23 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 24 | #include <osmocom/vty/vty.h> |
| 25 | #include <osmocom/vty/command.h> |
| 26 | #include <osmocom/vty/logging.h> |
| 27 | |
| 28 | #include "hlr_vty.h" |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 29 | #include "hlr_vty_subscr.h" |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 30 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 31 | static struct hlr *g_hlr = NULL; |
| 32 | |
| 33 | struct cmd_node hlr_node = { |
| 34 | HLR_NODE, |
| 35 | "%s(config-hlr)# ", |
| 36 | 1, |
| 37 | }; |
| 38 | |
| 39 | DEFUN(cfg_hlr, |
| 40 | cfg_hlr_cmd, |
| 41 | "hlr", |
| 42 | "Configure the HLR") |
| 43 | { |
| 44 | vty->node = HLR_NODE; |
| 45 | return CMD_SUCCESS; |
| 46 | } |
| 47 | |
| 48 | struct cmd_node gsup_node = { |
| 49 | GSUP_NODE, |
| 50 | "%s(config-hlr-gsup)# ", |
| 51 | 1, |
| 52 | }; |
| 53 | |
| 54 | DEFUN(cfg_gsup, |
| 55 | cfg_gsup_cmd, |
| 56 | "gsup", |
| 57 | "Configure GSUP options") |
| 58 | { |
| 59 | vty->node = GSUP_NODE; |
| 60 | return CMD_SUCCESS; |
| 61 | } |
| 62 | |
| 63 | static int config_write_hlr(struct vty *vty) |
| 64 | { |
| 65 | vty_out(vty, "hlr%s", VTY_NEWLINE); |
| 66 | return CMD_SUCCESS; |
| 67 | } |
| 68 | |
| 69 | static int config_write_hlr_gsup(struct vty *vty) |
| 70 | { |
| 71 | vty_out(vty, " gsup%s", VTY_NEWLINE); |
| 72 | if (g_hlr->gsup_bind_addr) |
| 73 | vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE); |
| 74 | return CMD_SUCCESS; |
| 75 | } |
| 76 | |
| 77 | DEFUN(cfg_hlr_gsup_bind_ip, |
| 78 | cfg_hlr_gsup_bind_ip_cmd, |
| 79 | "bind ip A.B.C.D", |
| 80 | "Listen/Bind related socket option\n" |
| 81 | IP_STR |
| 82 | "IPv4 Address to bind the GSUP interface to\n") |
| 83 | { |
| 84 | if(g_hlr->gsup_bind_addr) |
| 85 | talloc_free(g_hlr->gsup_bind_addr); |
| 86 | g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]); |
| 87 | |
| 88 | return CMD_SUCCESS; |
| 89 | } |
| 90 | |
| 91 | int hlr_vty_go_parent(struct vty *vty) |
| 92 | { |
| 93 | switch (vty->node) { |
| 94 | case GSUP_NODE: |
| 95 | vty->node = HLR_NODE; |
| 96 | vty->index = NULL; |
| 97 | break; |
| 98 | default: |
| 99 | case HLR_NODE: |
| 100 | vty->node = CONFIG_NODE; |
| 101 | vty->index = NULL; |
| 102 | break; |
| 103 | case CONFIG_NODE: |
| 104 | vty->node = ENABLE_NODE; |
| 105 | vty->index = NULL; |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | return vty->node; |
| 110 | } |
| 111 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 112 | int hlr_vty_is_config_node(struct vty *vty, int node) |
| 113 | { |
| 114 | switch (node) { |
| 115 | /* add items that are not config */ |
| 116 | case CONFIG_NODE: |
| 117 | return 0; |
| 118 | |
| 119 | default: |
| 120 | return 1; |
| 121 | } |
| 122 | } |
| 123 | |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 124 | void hlr_vty_init(struct hlr *hlr, const struct log_info *cat) |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 125 | { |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 126 | g_hlr = hlr; |
| 127 | |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 128 | logging_vty_add_cmds(cat); |
Pau Espin Pedrol | ce9bc40 | 2017-05-31 13:19:22 +0200 | [diff] [blame] | 129 | |
| 130 | install_element(CONFIG_NODE, &cfg_hlr_cmd); |
| 131 | install_node(&hlr_node, config_write_hlr); |
| 132 | install_default(HLR_NODE); |
| 133 | |
| 134 | install_element(HLR_NODE, &cfg_gsup_cmd); |
| 135 | install_node(&gsup_node, config_write_hlr_gsup); |
| 136 | install_default(GSUP_NODE); |
| 137 | |
| 138 | install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd); |
Neels Hofmeyr | 183e700 | 2017-10-06 02:59:54 +0200 | [diff] [blame] | 139 | |
| 140 | hlr_vty_subscriber_init(hlr); |
Neels Hofmeyr | 7685a78 | 2017-01-30 23:30:26 +0100 | [diff] [blame] | 141 | } |