diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-05-31 13:19:22 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-06-01 11:31:39 +0200 |
commit | ce9bc40846949cec5b64edf4d4afe344d8cb93a3 (patch) | |
tree | f66ee797cc3896267741f03fc5214e45b9d5130a | |
parent | 1790c8246abe74116129f56d1447bbb105fca398 (diff) |
VTY: Add hlr node and bind ip field
With this patch the address osmo-hlr binds to can be changed to
something else than 0.0.0.0
Change-Id: I79f7a300480f308b21116dd14d1698be38725afd
-rw-r--r-- | doc/examples/osmo-hlr.cfg | 3 | ||||
-rw-r--r-- | src/hlr.c | 7 | ||||
-rw-r--r-- | src/hlr.h | 3 | ||||
-rw-r--r-- | src/hlr_vty.c | 96 | ||||
-rw-r--r-- | src/hlr_vty.h | 10 |
5 files changed, 114 insertions, 5 deletions
diff --git a/doc/examples/osmo-hlr.cfg b/doc/examples/osmo-hlr.cfg index 2b49958..853d3c2 100644 --- a/doc/examples/osmo-hlr.cfg +++ b/doc/examples/osmo-hlr.cfg @@ -14,3 +14,6 @@ line vty bind 127.0.0.1 ctrl bind 127.0.0.1 +hlr + gsup + bind ip 127.0.0.1 @@ -415,6 +415,7 @@ static struct vty_app_info vty_info = { .version = PACKAGE_VERSION, .copyright = vlr_copyright, .is_config_node = hlr_vty_is_config_node, + .go_parent_cb = hlr_vty_go_parent, }; int main(int argc, char **argv) @@ -435,7 +436,7 @@ int main(int argc, char **argv) vty_init(&vty_info); ctrl_vty_init(hlr_ctx); handle_options(argc, argv); - hlr_vty_init(&hlr_log_info); + hlr_vty_init(g_hlr, &hlr_log_info); rc = vty_read_config_file(cmdline_opts.config_file, NULL); if (rc < 0) { @@ -465,8 +466,8 @@ int main(int argc, char **argv) exit(1); } - g_hlr->gs = osmo_gsup_server_create(hlr_ctx, NULL, 2222, read_cb, - &g_lu_ops); + g_hlr->gs = osmo_gsup_server_create(hlr_ctx, g_hlr->gsup_bind_addr, 2222, + read_cb, &g_lu_ops); if (!g_hlr->gs) { LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n"); exit(1); @@ -34,4 +34,7 @@ struct hlr { /* Control Interface */ struct ctrl_handle *ctrl; const char *ctrl_bind_addr; + + /* Local bind addr */ + char *gsup_bind_addr; }; diff --git a/src/hlr_vty.c b/src/hlr_vty.c index e4eef8f..946117e 100644 --- a/src/hlr_vty.c +++ b/src/hlr_vty.c @@ -20,12 +20,94 @@ * */ +#include <osmocom/core/talloc.h> #include <osmocom/vty/vty.h> #include <osmocom/vty/command.h> #include <osmocom/vty/logging.h> #include "hlr_vty.h" +static struct hlr *g_hlr = NULL; + +struct cmd_node hlr_node = { + HLR_NODE, + "%s(config-hlr)# ", + 1, +}; + +DEFUN(cfg_hlr, + cfg_hlr_cmd, + "hlr", + "Configure the HLR") +{ + vty->node = HLR_NODE; + return CMD_SUCCESS; +} + +struct cmd_node gsup_node = { + GSUP_NODE, + "%s(config-hlr-gsup)# ", + 1, +}; + +DEFUN(cfg_gsup, + cfg_gsup_cmd, + "gsup", + "Configure GSUP options") +{ + vty->node = GSUP_NODE; + return CMD_SUCCESS; +} + +static int config_write_hlr(struct vty *vty) +{ + vty_out(vty, "hlr%s", VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_hlr_gsup(struct vty *vty) +{ + vty_out(vty, " gsup%s", VTY_NEWLINE); + if (g_hlr->gsup_bind_addr) + vty_out(vty, " bind ip %s%s", g_hlr->gsup_bind_addr, VTY_NEWLINE); + return CMD_SUCCESS; +} + +DEFUN(cfg_hlr_gsup_bind_ip, + cfg_hlr_gsup_bind_ip_cmd, + "bind ip A.B.C.D", + "Listen/Bind related socket option\n" + IP_STR + "IPv4 Address to bind the GSUP interface to\n") +{ + if(g_hlr->gsup_bind_addr) + talloc_free(g_hlr->gsup_bind_addr); + g_hlr->gsup_bind_addr = talloc_strdup(g_hlr, argv[0]); + + return CMD_SUCCESS; +} + +int hlr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case GSUP_NODE: + vty->node = HLR_NODE; + vty->index = NULL; + break; + default: + case HLR_NODE: + vty->node = CONFIG_NODE; + vty->index = NULL; + break; + case CONFIG_NODE: + vty->node = ENABLE_NODE; + vty->index = NULL; + break; + } + + return vty->node; +} + int hlr_vty_is_config_node(struct vty *vty, int node) { switch (node) { @@ -38,7 +120,19 @@ int hlr_vty_is_config_node(struct vty *vty, int node) } } -void hlr_vty_init(const struct log_info *cat) +void hlr_vty_init(struct hlr *hlr, const struct log_info *cat) { + g_hlr = hlr; + logging_vty_add_cmds(cat); + + install_element(CONFIG_NODE, &cfg_hlr_cmd); + install_node(&hlr_node, config_write_hlr); + install_default(HLR_NODE); + + install_element(HLR_NODE, &cfg_gsup_cmd); + install_node(&gsup_node, config_write_hlr_gsup); + install_default(GSUP_NODE); + + install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd); } diff --git a/src/hlr_vty.h b/src/hlr_vty.h index abc9804..cd2ff73 100644 --- a/src/hlr_vty.h +++ b/src/hlr_vty.h @@ -24,6 +24,14 @@ #include <osmocom/core/logging.h> #include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> +#include "hlr.h" + +enum hlr_vty_node { + HLR_NODE = _LAST_OSMOVTY_NODE + 1, + GSUP_NODE, +}; int hlr_vty_is_config_node(struct vty *vty, int node); -void hlr_vty_init(const struct log_info *cat); +int hlr_vty_go_parent(struct vty *vty); +void hlr_vty_init(struct hlr *hlr, const struct log_info *cat); |